PageRenderTime 157ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 2ms

/libs/tcpdf/tcpdf.php

https://github.com/al3jandro/Braggi
PHP | 14076 lines | 8723 code | 555 blank | 4798 comment | 1962 complexity | 177d671c23a1defdba0a49e45a17c5c9 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Begin : 2002-08-03
  5. // Last Update : 2010-04-21
  6. // Author : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
  7. // Version : 4.9.018
  8. // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. // ----------------------------------------------------------------------------
  10. // Copyright (C) 2002-2010 Nicola Asuni - Tecnick.com S.r.l.
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU Lesser General Public License as published by
  14. // the Free Software Foundation, either version 2.1 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU Lesser General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU Lesser General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. // See LICENSE.TXT file for more information.
  26. // ----------------------------------------------------------------------------
  27. //
  28. // Description : This is a PHP class for generating PDF documents without
  29. // requiring external extensions.
  30. //
  31. // NOTE:
  32. // This class was originally derived in 2002 from the Public
  33. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  34. // but now is almost entirely rewritten.
  35. //
  36. // Main features:
  37. // * no external libraries are required for the basic functions;
  38. // * all ISO page formats, custom page formats, custom margins and units of measure;
  39. // * UTF-8 Unicode and Right-To-Left languages;
  40. // * TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  41. // * methods to publish some XHTML code, Javascript and Forms;
  42. // * images, graphic (geometric figures) and transformation methods;
  43. // * supports JPEG and PNG 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)
  44. // * 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;
  45. // * Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  46. // * automatic page header and footer management;
  47. // * document encryption and digital signature certifications;
  48. // * transactions to UNDO commands;
  49. // * PDF annotations, including links, text and file attachments;
  50. // * text rendering modes (fill, stroke and clipping);
  51. // * multiple columns mode;
  52. // * bookmarks and table of content;
  53. // * text hyphenation;
  54. // * automatic page break, line break and text alignments including justification;
  55. // * automatic page numbering and page groups;
  56. // * move and delete pages;
  57. // * page compression (requires php-zlib extension);
  58. //
  59. // -----------------------------------------------------------
  60. // THANKS TO:
  61. //
  62. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  63. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  64. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  65. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  66. // dullus for text Justification.
  67. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  68. // Patrick Benny for text stretch suggestion on Cell().
  69. // Johannes Güntert for JavaScript support.
  70. // Denis Van Nuffelen for Dynamic Form.
  71. // Jacek Czekaj for multibyte justification
  72. // Anthony Ferrara for the reintroduction of legacy image methods.
  73. // Sourceforge user 1707880 (hucste) for line-trough mode.
  74. // Larry Stanbery for page groups.
  75. // Martin Hall-May for transparency.
  76. // Aaron C. Spike for Polycurve method.
  77. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  78. // Moritz Wagner and Andreas Wurmser for graphic functions.
  79. // Andrew Whitehead for core fonts support.
  80. // Esteban Joël Marín for OpenType font conversion.
  81. // Teus Hagen for several suggestions and fixes.
  82. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  83. // Kosmas Papachristos for some CSS improvements.
  84. // Marcel Partap for some fixes.
  85. // Won Kyu Park for several suggestions, fixes and patches.
  86. // Dominik Dzienia for QR-code support.
  87. // Anyone that has reported a bug or sent a suggestion.
  88. //============================================================+
  89. /**
  90. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  91. * 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>
  92. * <h3>TCPDF main features are:</h3>
  93. * <ul>
  94. * <li>no external libraries are required for the basic functions;</li>
  95. * <li>all ISO page formats, custom page formats, custom margins and units of measure;</li>
  96. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  97. * <li>TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  98. * <li>methods to publish some XHTML code, Javascript and Forms;</li>
  99. * <li>images, graphic (geometric figures) and transformation methods;
  100. * <li>supports JPEG and PNG 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>
  101. * <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;</li>
  102. * <li>Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  103. * <li>automatic page header and footer management;</li>
  104. * <li>document encryption and digital signature certifications;</li>
  105. * <li>transactions to UNDO commands;</li>
  106. * <li>PDF annotations, including links, text and file attachments;</li>
  107. * <li>text rendering modes (fill, stroke and clipping);</li>
  108. * <li>multiple columns mode;</li>
  109. * <li>bookmarks and table of content;</li>
  110. * <li>text hyphenation;</li>
  111. * <li>automatic page break, line break and text alignments including justification;</li>
  112. * <li>automatic page numbering and page groups;</li>
  113. * <li>move and delete pages;</li>
  114. * <li>page compression (requires php-zlib extension);</li>
  115. * </ul>
  116. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  117. * @package com.tecnick.tcpdf
  118. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  119. * @author Nicola Asuni
  120. * @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
  121. * @link http://www.tcpdf.org
  122. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  123. * @version 4.9.018
  124. */
  125. /**
  126. * main configuration file
  127. */
  128. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  129. // includes some support files
  130. /**
  131. * unicode data
  132. */
  133. require_once(dirname(__FILE__).'/unicode_data.php');
  134. /**
  135. * html colors table
  136. */
  137. require_once(dirname(__FILE__).'/htmlcolors.php');
  138. if (!class_exists('TCPDF', false)) {
  139. /**
  140. * define default PDF document producer
  141. */
  142. define('PDF_PRODUCER', 'TCPDF 4.9.018 (http://www.tcpdf.org)');
  143. /**
  144. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  145. * 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>
  146. * @name TCPDF
  147. * @package com.tecnick.tcpdf
  148. * @version 4.9.018
  149. * @author Nicola Asuni - info@tecnick.com
  150. * @link http://www.tcpdf.org
  151. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  152. */
  153. class TCPDF {
  154. // protected or Protected properties
  155. /**
  156. * @var current page number
  157. * @access protected
  158. */
  159. protected $page;
  160. /**
  161. * @var current object number
  162. * @access protected
  163. */
  164. protected $n;
  165. /**
  166. * @var array of object offsets
  167. * @access protected
  168. */
  169. protected $offsets;
  170. /**
  171. * @var buffer holding in-memory PDF
  172. * @access protected
  173. */
  174. protected $buffer;
  175. /**
  176. * @var array containing pages
  177. * @access protected
  178. */
  179. protected $pages = array();
  180. /**
  181. * @var current document state
  182. * @access protected
  183. */
  184. protected $state;
  185. /**
  186. * @var compression flag
  187. * @access protected
  188. */
  189. protected $compress;
  190. /**
  191. * @var current page orientation (P = Portrait, L = Landscape)
  192. * @access protected
  193. */
  194. protected $CurOrientation;
  195. /**
  196. * @var array that stores page dimensions and graphic status.<ul><li>$this->pagedim[$this->page]['w'] => page_width_in_points</li><li>$this->pagedim[$this->page]['h'] => height in points</li><li>$this->pagedim[$this->page]['wk'] => page_width_in_points</li><li>$this->pagedim[$this->page]['hk'] => height</li><li>$this->pagedim[$this->page]['tm'] => top_margin</li><li>$this->pagedim[$this->page]['bm'] => bottom_margin</li><li>$this->pagedim[$this->page]['lm'] => left_margin</li><li>$this->pagedim[$this->page]['rm'] => right_margin</li><li>$this->pagedim[$this->page]['pb'] => auto_page_break</li><li>$this->pagedim[$this->page]['or'] => page_orientation</li><li>$this->pagedim[$this->page]['olm'] => original_left_margin</li><li>$this->pagedim[$this->page]['orm'] => original_right_margin</li></ul>
  197. * @access protected
  198. */
  199. protected $pagedim = array();
  200. /**
  201. * @var scale factor (number of points in user unit)
  202. * @access protected
  203. */
  204. protected $k;
  205. /**
  206. * @var width of page format in points
  207. * @access protected
  208. */
  209. protected $fwPt;
  210. /**
  211. * @var height of page format in points
  212. * @access protected
  213. */
  214. protected $fhPt;
  215. /**
  216. * @var current width of page in points
  217. * @access protected
  218. */
  219. protected $wPt;
  220. /**
  221. * @var current height of page in points
  222. * @access protected
  223. */
  224. protected $hPt;
  225. /**
  226. * @var current width of page in user unit
  227. * @access protected
  228. */
  229. protected $w;
  230. /**
  231. * @var current height of page in user unit
  232. * @access protected
  233. */
  234. protected $h;
  235. /**
  236. * @var left margin
  237. * @access protected
  238. */
  239. protected $lMargin;
  240. /**
  241. * @var top margin
  242. * @access protected
  243. */
  244. protected $tMargin;
  245. /**
  246. * @var right margin
  247. * @access protected
  248. */
  249. protected $rMargin;
  250. /**
  251. * @var page break margin
  252. * @access protected
  253. */
  254. protected $bMargin;
  255. /**
  256. * @var cell internal padding
  257. * @access protected
  258. */
  259. //protected
  260. public $cMargin;
  261. /**
  262. * @var cell internal padding (previous value)
  263. * @access protected
  264. */
  265. protected $oldcMargin;
  266. /**
  267. * @var current horizontal position in user unit for cell positioning
  268. * @access protected
  269. */
  270. protected $x;
  271. /**
  272. * @var current vertical position in user unit for cell positioning
  273. * @access protected
  274. */
  275. protected $y;
  276. /**
  277. * @var height of last cell printed
  278. * @access protected
  279. */
  280. protected $lasth;
  281. /**
  282. * @var line width in user unit
  283. * @access protected
  284. */
  285. protected $LineWidth;
  286. /**
  287. * @var array of standard font names
  288. * @access protected
  289. */
  290. protected $CoreFonts;
  291. /**
  292. * @var array of used fonts
  293. * @access protected
  294. */
  295. protected $fonts = array();
  296. /**
  297. * @var array of font files
  298. * @access protected
  299. */
  300. protected $FontFiles = array();
  301. /**
  302. * @var array of encoding differences
  303. * @access protected
  304. */
  305. protected $diffs = array();
  306. /**
  307. * @var array of used images
  308. * @access protected
  309. */
  310. protected $images = array();
  311. /**
  312. * @var array of Annotations in pages
  313. * @access protected
  314. */
  315. protected $PageAnnots = array();
  316. /**
  317. * @var array of internal links
  318. * @access protected
  319. */
  320. protected $links = array();
  321. /**
  322. * @var current font family
  323. * @access protected
  324. */
  325. protected $FontFamily;
  326. /**
  327. * @var current font style
  328. * @access protected
  329. */
  330. protected $FontStyle;
  331. /**
  332. * @var current font ascent (distance between font top and baseline)
  333. * @access protected
  334. * @since 2.8.000 (2007-03-29)
  335. */
  336. protected $FontAscent;
  337. /**
  338. * @var current font descent (distance between font bottom and baseline)
  339. * @access protected
  340. * @since 2.8.000 (2007-03-29)
  341. */
  342. protected $FontDescent;
  343. /**
  344. * @var underlining flag
  345. * @access protected
  346. */
  347. protected $underline;
  348. /**
  349. * @var overlining flag
  350. * @access protected
  351. */
  352. protected $overline;
  353. /**
  354. * @var current font info
  355. * @access protected
  356. */
  357. protected $CurrentFont;
  358. /**
  359. * @var current font size in points
  360. * @access protected
  361. */
  362. protected $FontSizePt;
  363. /**
  364. * @var current font size in user unit
  365. * @access protected
  366. */
  367. protected $FontSize;
  368. /**
  369. * @var commands for drawing color
  370. * @access protected
  371. */
  372. protected $DrawColor;
  373. /**
  374. * @var commands for filling color
  375. * @access protected
  376. */
  377. protected $FillColor;
  378. /**
  379. * @var commands for text color
  380. * @access protected
  381. */
  382. protected $TextColor;
  383. /**
  384. * @var indicates whether fill and text colors are different
  385. * @access protected
  386. */
  387. protected $ColorFlag;
  388. /**
  389. * @var automatic page breaking
  390. * @access protected
  391. */
  392. protected $AutoPageBreak;
  393. /**
  394. * @var threshold used to trigger page breaks
  395. * @access protected
  396. */
  397. protected $PageBreakTrigger;
  398. /**
  399. * @var flag set when processing footer
  400. * @access protected
  401. */
  402. protected $InFooter = false;
  403. /**
  404. * @var zoom display mode
  405. * @access protected
  406. */
  407. protected $ZoomMode;
  408. /**
  409. * @var layout display mode
  410. * @access protected
  411. */
  412. protected $LayoutMode;
  413. /**
  414. * @var title
  415. * @access protected
  416. */
  417. protected $title = '';
  418. /**
  419. * @var subject
  420. * @access protected
  421. */
  422. protected $subject = '';
  423. /**
  424. * @var author
  425. * @access protected
  426. */
  427. protected $author = '';
  428. /**
  429. * @var keywords
  430. * @access protected
  431. */
  432. protected $keywords = '';
  433. /**
  434. * @var creator
  435. * @access protected
  436. */
  437. protected $creator = '';
  438. /**
  439. * @var alias for total number of pages
  440. * @access protected
  441. */
  442. protected $AliasNbPages = '{nb}';
  443. /**
  444. * @var alias for page number
  445. * @access protected
  446. */
  447. protected $AliasNumPage = '{pnb}';
  448. /**
  449. * @var right-bottom corner X coordinate of inserted image
  450. * @since 2002-07-31
  451. * @author Nicola Asuni
  452. * @access protected
  453. */
  454. protected $img_rb_x;
  455. /**
  456. * @var right-bottom corner Y coordinate of inserted image
  457. * @since 2002-07-31
  458. * @author Nicola Asuni
  459. * @access protected
  460. */
  461. protected $img_rb_y;
  462. /**
  463. * @var adjusting factor to convert pixels to user units.
  464. * @since 2004-06-14
  465. * @author Nicola Asuni
  466. * @access protected
  467. */
  468. protected $imgscale = 1;
  469. /**
  470. * @var boolean set to true when the input text is unicode (require unicode fonts)
  471. * @since 2005-01-02
  472. * @author Nicola Asuni
  473. * @access protected
  474. */
  475. protected $isunicode = false;
  476. /**
  477. * @var PDF version
  478. * @since 1.5.3
  479. * @access protected
  480. */
  481. protected $PDFVersion = '1.7';
  482. // ----------------------
  483. /**
  484. * @var Minimum distance between header and top page margin.
  485. * @access protected
  486. */
  487. protected $header_margin;
  488. /**
  489. * @var Minimum distance between footer and bottom page margin.
  490. * @access protected
  491. */
  492. protected $footer_margin;
  493. /**
  494. * @var original left margin value
  495. * @access protected
  496. * @since 1.53.0.TC013
  497. */
  498. protected $original_lMargin;
  499. /**
  500. * @var original right margin value
  501. * @access protected
  502. * @since 1.53.0.TC013
  503. */
  504. protected $original_rMargin;
  505. /**
  506. * @var Header font.
  507. * @access protected
  508. */
  509. protected $header_font;
  510. /**
  511. * @var Footer font.
  512. * @access protected
  513. */
  514. protected $footer_font;
  515. /**
  516. * @var Language templates.
  517. * @access protected
  518. */
  519. protected $l;
  520. /**
  521. * @var Barcode to print on page footer (only if set).
  522. * @access protected
  523. */
  524. protected $barcode = false;
  525. /**
  526. * @var If true prints header
  527. * @access protected
  528. */
  529. protected $print_header = true;
  530. /**
  531. * @var If true prints footer.
  532. * @access protected
  533. */
  534. protected $print_footer = true;
  535. /**
  536. * @var Header image logo.
  537. * @access protected
  538. */
  539. protected $header_logo = '';
  540. /**
  541. * @var Header image logo width in mm.
  542. * @access protected
  543. */
  544. protected $header_logo_width = 30;
  545. /**
  546. * @var String to print as title on document header.
  547. * @access protected
  548. */
  549. protected $header_title = '';
  550. /**
  551. * @var String to print on document header.
  552. * @access protected
  553. */
  554. protected $header_string = '';
  555. /**
  556. * @var Default number of columns for html table.
  557. * @access protected
  558. */
  559. protected $default_table_columns = 4;
  560. // variables for html parser
  561. /**
  562. * @var HTML PARSER: array to store current link and rendering styles.
  563. * @access protected
  564. */
  565. protected $HREF = array();
  566. /**
  567. * @var store a list of available fonts on filesystem.
  568. * @access protected
  569. */
  570. protected $fontlist = array();
  571. /**
  572. * @var current foreground color
  573. * @access protected
  574. */
  575. protected $fgcolor;
  576. /**
  577. * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  578. * @access protected
  579. */
  580. protected $listordered = array();
  581. /**
  582. * @var HTML PARSER: array count list items on nested lists.
  583. * @access protected
  584. */
  585. protected $listcount = array();
  586. /**
  587. * @var HTML PARSER: current list nesting level.
  588. * @access protected
  589. */
  590. protected $listnum = 0;
  591. /**
  592. * @var HTML PARSER: indent amount for lists.
  593. * @access protected
  594. */
  595. protected $listindent = 0;
  596. /**
  597. * @var HTML PARSER: current list indententation level.
  598. * @access protected
  599. */
  600. protected $listindentlevel = 0;
  601. /**
  602. * @var current background color
  603. * @access protected
  604. */
  605. protected $bgcolor;
  606. /**
  607. * @var Store temporary font size in points.
  608. * @access protected
  609. */
  610. protected $tempfontsize = 10;
  611. /**
  612. * @var spacer for LI tags.
  613. * @access protected
  614. */
  615. protected $lispacer = '';
  616. /**
  617. * @var default encoding
  618. * @access protected
  619. * @since 1.53.0.TC010
  620. */
  621. protected $encoding = 'UTF-8';
  622. /**
  623. * @var PHP internal encoding
  624. * @access protected
  625. * @since 1.53.0.TC016
  626. */
  627. protected $internal_encoding;
  628. /**
  629. * @var indicates if the document language is Right-To-Left
  630. * @access protected
  631. * @since 2.0.000
  632. */
  633. protected $rtl = false;
  634. /**
  635. * @var used to force RTL or LTR string inversion
  636. * @access protected
  637. * @since 2.0.000
  638. */
  639. protected $tmprtl = false;
  640. // --- Variables used for document encryption:
  641. /**
  642. * Indicates whether document is protected
  643. * @access protected
  644. * @since 2.0.000 (2008-01-02)
  645. */
  646. protected $encrypted;
  647. /**
  648. * U entry in pdf document
  649. * @access protected
  650. * @since 2.0.000 (2008-01-02)
  651. */
  652. protected $Uvalue;
  653. /**
  654. * O entry in pdf document
  655. * @access protected
  656. * @since 2.0.000 (2008-01-02)
  657. */
  658. protected $Ovalue;
  659. /**
  660. * P entry in pdf document
  661. * @access protected
  662. * @since 2.0.000 (2008-01-02)
  663. */
  664. protected $Pvalue;
  665. /**
  666. * encryption object id
  667. * @access protected
  668. * @since 2.0.000 (2008-01-02)
  669. */
  670. protected $enc_obj_id;
  671. /**
  672. * last RC4 key encrypted (cached for optimisation)
  673. * @access protected
  674. * @since 2.0.000 (2008-01-02)
  675. */
  676. protected $last_rc4_key;
  677. /**
  678. * last RC4 computed key
  679. * @access protected
  680. * @since 2.0.000 (2008-01-02)
  681. */
  682. protected $last_rc4_key_c;
  683. /**
  684. * RC4 padding
  685. * @access protected
  686. */
  687. protected $padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  688. /**
  689. * RC4 encryption key
  690. * @access protected
  691. */
  692. protected $encryption_key;
  693. // --- bookmark ---
  694. /**
  695. * Outlines for bookmark
  696. * @access protected
  697. * @since 2.1.002 (2008-02-12)
  698. */
  699. protected $outlines = array();
  700. /**
  701. * Outline root for bookmark
  702. * @access protected
  703. * @since 2.1.002 (2008-02-12)
  704. */
  705. protected $OutlineRoot;
  706. // --- javascript and form ---
  707. /**
  708. * javascript code
  709. * @access protected
  710. * @since 2.1.002 (2008-02-12)
  711. */
  712. protected $javascript = '';
  713. /**
  714. * javascript counter
  715. * @access protected
  716. * @since 2.1.002 (2008-02-12)
  717. */
  718. protected $n_js;
  719. /**
  720. * line trough state
  721. * @access protected
  722. * @since 2.8.000 (2008-03-19)
  723. */
  724. protected $linethrough;
  725. // --- Variables used for User's Rights ---
  726. // See PDF reference chapter 8.7 Digital Signatures
  727. /**
  728. * If true enables user's rights on PDF reader
  729. * @access protected
  730. * @since 2.9.000 (2008-03-26)
  731. */
  732. protected $ur;
  733. /**
  734. * Names specifying additional document-wide usage rights for the document.
  735. * @access protected
  736. * @since 2.9.000 (2008-03-26)
  737. */
  738. protected $ur_document;
  739. /**
  740. * Names specifying additional annotation-related usage rights for the document.
  741. * @access protected
  742. * @since 2.9.000 (2008-03-26)
  743. */
  744. protected $ur_annots;
  745. /**
  746. * Names specifying additional form-field-related usage rights for the document.
  747. * @access protected
  748. * @since 2.9.000 (2008-03-26)
  749. */
  750. protected $ur_form;
  751. /**
  752. * Names specifying additional signature-related usage rights for the document.
  753. * @access protected
  754. * @since 2.9.000 (2008-03-26)
  755. */
  756. protected $ur_signature;
  757. /**
  758. * Dot Per Inch Document Resolution (do not change)
  759. * @access protected
  760. * @since 3.0.000 (2008-03-27)
  761. */
  762. protected $dpi = 72;
  763. /**
  764. * Array of page numbers were a new page group was started
  765. * @access protected
  766. * @since 3.0.000 (2008-03-27)
  767. */
  768. protected $newpagegroup = array();
  769. /**
  770. * Contains the number of pages of the groups
  771. * @access protected
  772. * @since 3.0.000 (2008-03-27)
  773. */
  774. protected $pagegroups;
  775. /**
  776. * Contains the alias of the current page group
  777. * @access protected
  778. * @since 3.0.000 (2008-03-27)
  779. */
  780. protected $currpagegroup;
  781. /**
  782. * Restrict the rendering of some elements to screen or printout.
  783. * @access protected
  784. * @since 3.0.000 (2008-03-27)
  785. */
  786. protected $visibility = 'all';
  787. /**
  788. * Print visibility.
  789. * @access protected
  790. * @since 3.0.000 (2008-03-27)
  791. */
  792. protected $n_ocg_print;
  793. /**
  794. * View visibility.
  795. * @access protected
  796. * @since 3.0.000 (2008-03-27)
  797. */
  798. protected $n_ocg_view;
  799. /**
  800. * Array of transparency objects and parameters.
  801. * @access protected
  802. * @since 3.0.000 (2008-03-27)
  803. */
  804. protected $extgstates;
  805. /**
  806. * Set the default JPEG compression quality (1-100)
  807. * @access protected
  808. * @since 3.0.000 (2008-03-27)
  809. */
  810. protected $jpeg_quality;
  811. /**
  812. * Default cell height ratio.
  813. * @access protected
  814. * @since 3.0.014 (2008-05-23)
  815. */
  816. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  817. /**
  818. * PDF viewer preferences.
  819. * @access protected
  820. * @since 3.1.000 (2008-06-09)
  821. */
  822. protected $viewer_preferences;
  823. /**
  824. * A name object specifying how the document should be displayed when opened.
  825. * @access protected
  826. * @since 3.1.000 (2008-06-09)
  827. */
  828. protected $PageMode;
  829. /**
  830. * Array for storing gradient information.
  831. * @access protected
  832. * @since 3.1.000 (2008-06-09)
  833. */
  834. protected $gradients = array();
  835. /**
  836. * Array used to store positions inside the pages buffer.
  837. * keys are the page numbers
  838. * @access protected
  839. * @since 3.2.000 (2008-06-26)
  840. */
  841. protected $intmrk = array();
  842. /**
  843. * Array used to store content positions inside the pages buffer.
  844. * keys are the page numbers
  845. * @access protected
  846. * @since 4.6.021 (2009-07-20)
  847. */
  848. protected $cntmrk = array();
  849. /**
  850. * Array used to store footer positions of each page.
  851. * @access protected
  852. * @since 3.2.000 (2008-07-01)
  853. */
  854. protected $footerpos = array();
  855. /**
  856. * Array used to store footer length of each page.
  857. * @access protected
  858. * @since 4.0.014 (2008-07-29)
  859. */
  860. protected $footerlen = array();
  861. /**
  862. * True if a newline is created.
  863. * @access protected
  864. * @since 3.2.000 (2008-07-01)
  865. */
  866. protected $newline = true;
  867. /**
  868. * End position of the latest inserted line
  869. * @access protected
  870. * @since 3.2.000 (2008-07-01)
  871. */
  872. protected $endlinex = 0;
  873. /**
  874. * PDF string for last line width
  875. * @access protected
  876. * @since 4.0.006 (2008-07-16)
  877. */
  878. protected $linestyleWidth = '';
  879. /**
  880. * PDF string for last line width
  881. * @access protected
  882. * @since 4.0.006 (2008-07-16)
  883. */
  884. protected $linestyleCap = '0 J';
  885. /**
  886. * PDF string for last line width
  887. * @access protected
  888. * @since 4.0.006 (2008-07-16)
  889. */
  890. protected $linestyleJoin = '0 j';
  891. /**
  892. * PDF string for last line width
  893. * @access protected
  894. * @since 4.0.006 (2008-07-16)
  895. */
  896. protected $linestyleDash = '[] 0 d';
  897. /**
  898. * True if marked-content sequence is open
  899. * @access protected
  900. * @since 4.0.013 (2008-07-28)
  901. */
  902. protected $openMarkedContent = false;
  903. /**
  904. * Count the latest inserted vertical spaces on HTML
  905. * @access protected
  906. * @since 4.0.021 (2008-08-24)
  907. */
  908. protected $htmlvspace = 0;
  909. /**
  910. * Array of Spot colors
  911. * @access protected
  912. * @since 4.0.024 (2008-09-12)
  913. */
  914. protected $spot_colors = array();
  915. /**
  916. * Symbol used for HTML unordered list items
  917. * @access protected
  918. * @since 4.0.028 (2008-09-26)
  919. */
  920. protected $lisymbol = '';
  921. /**
  922. * String used to mark the beginning and end of EPS image blocks
  923. * @access protected
  924. * @since 4.1.000 (2008-10-18)
  925. */
  926. protected $epsmarker = 'x#!#EPS#!#x';
  927. /**
  928. * Array of transformation matrix
  929. * @access protected
  930. * @since 4.2.000 (2008-10-29)
  931. */
  932. protected $transfmatrix = array();
  933. /**
  934. * Current key for transformation matrix
  935. * @access protected
  936. * @since 4.8.005 (2009-09-17)
  937. */
  938. protected $transfmatrix_key = 0;
  939. /**
  940. * Booklet mode for double-sided pages
  941. * @access protected
  942. * @since 4.2.000 (2008-10-29)
  943. */
  944. protected $booklet = false;
  945. /**
  946. * Epsilon value used for float calculations
  947. * @access protected
  948. * @since 4.2.000 (2008-10-29)
  949. */
  950. protected $feps = 0.005;
  951. /**
  952. * Array used for custom vertical spaces for HTML tags
  953. * @access protected
  954. * @since 4.2.001 (2008-10-30)
  955. */
  956. protected $tagvspaces = array();
  957. /**
  958. * @var HTML PARSER: custom indent amount for lists.
  959. * Negative value means disabled.
  960. * @access protected
  961. * @since 4.2.007 (2008-11-12)
  962. */
  963. protected $customlistindent = -1;
  964. /**
  965. * @var if true keeps the border open for the cell sides that cross the page.
  966. * @access protected
  967. * @since 4.2.010 (2008-11-14)
  968. */
  969. protected $opencell = true;
  970. /**
  971. * @var array of files to embedd
  972. * @access protected
  973. * @since 4.4.000 (2008-12-07)
  974. */
  975. protected $embeddedfiles = array();
  976. /**
  977. * @var boolean true when inside html pre tag
  978. * @access protected
  979. * @since 4.4.001 (2008-12-08)
  980. */
  981. protected $premode = false;
  982. /**
  983. * Array used to store positions of graphics transformation blocks inside the page buffer.
  984. * keys are the page numbers
  985. * @access protected
  986. * @since 4.4.002 (2008-12-09)
  987. */
  988. protected $transfmrk = array();
  989. /**
  990. * Default color for html links
  991. * @access protected
  992. * @since 4.4.003 (2008-12-09)
  993. */
  994. protected $htmlLinkColorArray = array(0, 0, 255);
  995. /**
  996. * Default font style to add to html links
  997. * @access protected
  998. * @since 4.4.003 (2008-12-09)
  999. */
  1000. protected $htmlLinkFontStyle = 'U';
  1001. /**
  1002. * Counts the number of pages.
  1003. * @access protected
  1004. * @since 4.5.000 (2008-12-31)
  1005. */
  1006. protected $numpages = 0;
  1007. /**
  1008. * Array containing page lengths in bytes.
  1009. * @access protected
  1010. * @since 4.5.000 (2008-12-31)
  1011. */
  1012. protected $pagelen = array();
  1013. /**
  1014. * Counts the number of pages.
  1015. * @access protected
  1016. * @since 4.5.000 (2008-12-31)
  1017. */
  1018. protected $numimages = 0;
  1019. /**
  1020. * Store the image keys.
  1021. * @access protected
  1022. * @since 4.5.000 (2008-12-31)
  1023. */
  1024. protected $imagekeys = array();
  1025. /**
  1026. * Length of the buffer in bytes.
  1027. * @access protected
  1028. * @since 4.5.000 (2008-12-31)
  1029. */
  1030. protected $bufferlen = 0;
  1031. /**
  1032. * If true enables disk caching.
  1033. * @access protected
  1034. * @since 4.5.000 (2008-12-31)
  1035. */
  1036. protected $diskcache = false;
  1037. /**
  1038. * Counts the number of fonts.
  1039. * @access protected
  1040. * @since 4.5.000 (2009-01-02)
  1041. */
  1042. protected $numfonts = 0;
  1043. /**
  1044. * Store the font keys.
  1045. * @access protected
  1046. * @since 4.5.000 (2009-01-02)
  1047. */
  1048. protected $fontkeys = array();
  1049. /**
  1050. * Store the font object IDs.
  1051. * @access protected
  1052. * @since 4.8.001 (2009-09-09)
  1053. */
  1054. protected $font_obj_ids = array();
  1055. /**
  1056. * Store the fage status (true when opened, false when closed).
  1057. * @access protected
  1058. * @since 4.5.000 (2009-01-02)
  1059. */
  1060. protected $pageopen = array();
  1061. /**
  1062. * Default monospaced font
  1063. * @access protected
  1064. * @since 4.5.025 (2009-03-10)
  1065. */
  1066. protected $default_monospaced_font = 'courier';
  1067. /**
  1068. * Used to store a cloned copy of the current class object
  1069. * @access protected
  1070. * @since 4.5.029 (2009-03-19)
  1071. */
  1072. protected $objcopy;
  1073. /**
  1074. * Array used to store the lengths of cache files
  1075. * @access protected
  1076. * @since 4.5.029 (2009-03-19)
  1077. */
  1078. protected $cache_file_length = array();
  1079. /**
  1080. * Table header content to be repeated on each new page
  1081. * @access protected
  1082. * @since 4.5.030 (2009-03-20)
  1083. */
  1084. protected $thead = '';
  1085. /**
  1086. * Margins used for table header.
  1087. * @access protected
  1088. * @since 4.5.030 (2009-03-20)
  1089. */
  1090. protected $theadMargins = array();
  1091. /**
  1092. * Cache array for UTF8StringToArray() method.
  1093. * @access protected
  1094. * @since 4.5.037 (2009-04-07)
  1095. */
  1096. protected $cache_UTF8StringToArray = array();
  1097. /**
  1098. * Maximum size of cache array used for UTF8StringToArray() method.
  1099. * @access protected
  1100. * @since 4.5.037 (2009-04-07)
  1101. */
  1102. protected $cache_maxsize_UTF8StringToArray = 8;
  1103. /**
  1104. * Current size of cache array used for UTF8StringToArray() method.
  1105. * @access protected
  1106. * @since 4.5.037 (2009-04-07)
  1107. */
  1108. protected $cache_size_UTF8StringToArray = 0;
  1109. /**
  1110. * If true enables document signing
  1111. * @access protected
  1112. * @since 4.6.005 (2009-04-24)
  1113. */
  1114. protected $sign = false;
  1115. /**
  1116. * Signature data
  1117. * @access protected
  1118. * @since 4.6.005 (2009-04-24)
  1119. */
  1120. protected $signature_data = array();
  1121. /**
  1122. * Signature max length
  1123. * @access protected
  1124. * @since 4.6.005 (2009-04-24)
  1125. */
  1126. protected $signature_max_length = 11742;
  1127. /**
  1128. * Regular expression used to find blank characters used for word-wrapping.
  1129. * @access protected
  1130. * @since 4.6.006 (2009-04-28)
  1131. */
  1132. protected $re_spaces = '/[\s]/';
  1133. /**
  1134. * Signature object ID
  1135. * @access protected
  1136. * @since 4.6.022 (2009-06-23)
  1137. */
  1138. protected $sig_obj_id = 0;
  1139. /**
  1140. * ByteRange placemark used during signature process.
  1141. * @access protected
  1142. * @since 4.6.028 (2009-08-25)
  1143. */
  1144. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1145. /**
  1146. * Placemark used during signature process.
  1147. * @access protected
  1148. * @since 4.6.028 (2009-08-25)
  1149. */
  1150. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1151. /**
  1152. * ID of page objects
  1153. * @access protected
  1154. * @since 4.7.000 (2009-08-29)
  1155. */
  1156. protected $page_obj_id = array();
  1157. /**
  1158. * Start ID for embedded file objects
  1159. * @access protected
  1160. * @since 4.7.000 (2009-08-29)
  1161. */
  1162. protected $embedded_start_obj_id = 100000;
  1163. /**
  1164. * Start ID for annotation objects
  1165. * @access protected
  1166. * @since 4.7.000 (2009-08-29)
  1167. */
  1168. protected $annots_start_obj_id = 200000;
  1169. /**
  1170. * Max ID of annotation object
  1171. * @access protected
  1172. * @since 4.7.000 (2009-08-29)
  1173. */
  1174. protected $annot_obj_id = 200000;
  1175. /**
  1176. * Current ID of annotation object
  1177. * @access protected
  1178. * @since 4.8.003 (2009-09-15)
  1179. */
  1180. protected $curr_annot_obj_id = 200000;
  1181. /**
  1182. * List of form annotations IDs
  1183. * @access protected
  1184. * @since 4.8.000 (2009-09-07)
  1185. */
  1186. protected $form_obj_id = array();
  1187. /**
  1188. * 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.
  1189. * @access protected
  1190. * @since 4.8.000 (2009-09-07)
  1191. */
  1192. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1193. /**
  1194. * Javascript objects array
  1195. * @access protected
  1196. * @since 4.8.000 (2009-09-07)
  1197. */
  1198. protected $js_objects = array();
  1199. /**
  1200. * Start ID for javascript objects
  1201. * @access protected
  1202. * @since 4.8.000 (2009-09-07)
  1203. */
  1204. protected $js_start_obj_id = 300000;
  1205. /**
  1206. * Current ID of javascript object
  1207. * @access protected
  1208. * @since 4.8.000 (2009-09-07)
  1209. */
  1210. protected $js_obj_id = 300000;
  1211. /**
  1212. * Current form action (used during XHTML rendering)
  1213. * @access protected
  1214. * @since 4.8.000 (2009-09-07)
  1215. */
  1216. protected $form_action = '';
  1217. /**
  1218. * Current form encryption type (used during XHTML rendering)
  1219. * @access protected
  1220. * @since 4.8.000 (2009-09-07)
  1221. */
  1222. protected $form_enctype = 'application/x-www-form-urlencoded';
  1223. /**
  1224. * Current method to submit forms.
  1225. * @access protected
  1226. * @since 4.8.000 (2009-09-07)
  1227. */
  1228. protected $form_mode = 'post';
  1229. /**
  1230. * Start ID for appearance streams XObjects
  1231. * @access protected
  1232. * @since 4.8.001 (2009-09-09)
  1233. */
  1234. protected $apxo_start_obj_id = 400000;
  1235. /**
  1236. * Current ID of appearance streams XObjects
  1237. * @access protected
  1238. * @since 4.8.001 (2009-09-09)
  1239. */
  1240. protected $apxo_obj_id = 400000;
  1241. /**
  1242. * List of fonts used on form fields (fontname => fontkey).
  1243. * @access protected
  1244. * @since 4.8.001 (2009-09-09)
  1245. */
  1246. protected $annotation_fonts = array();
  1247. /**
  1248. * List of radio buttons parent objects.
  1249. * @access protected
  1250. * @since 4.8.001 (2009-09-09)
  1251. */
  1252. protected $radiobutton_groups = array();
  1253. /**
  1254. * List of radio group objects IDs
  1255. * @access protected
  1256. * @since 4.8.001 (2009-09-09)
  1257. */
  1258. protected $radio_groups = array();
  1259. /**
  1260. * Text indentation value (used for text-indent CSS attribute)
  1261. * @access protected
  1262. * @since 4.8.006 (2009-09-23)
  1263. */
  1264. protected $textindent = 0;
  1265. /**
  1266. * Store page number when startTransaction() is called.
  1267. * @access protected
  1268. * @since 4.8.006 (2009-09-23)
  1269. */
  1270. protected $start_transaction_page = 0;
  1271. /**
  1272. * Store Y position when startTransaction() is called.
  1273. * @access protected
  1274. * @since 4.9.001 (2010-03-28)
  1275. */
  1276. protected $start_transaction_y = 0;
  1277. /**
  1278. * True when we are printing the thead section on a new page
  1279. * @access protected
  1280. * @since 4.8.027 (2010-01-25)
  1281. */
  1282. protected $inthead = false;
  1283. /**
  1284. * Array of column measures (width, space, starting Y position)
  1285. * @access protected
  1286. * @since 4.9.001 (2010-03-28)
  1287. */
  1288. protected $columns = array();
  1289. /**
  1290. * Number of colums
  1291. * @access protected
  1292. * @since 4.9.001 (2010-03-28)
  1293. */
  1294. protected $num_columns = 0;
  1295. /**
  1296. * Current column number
  1297. * @access protected
  1298. * @since 4.9.001 (2010-03-28)
  1299. */
  1300. protected $current_column = 0;
  1301. /**
  1302. * Starting page for columns
  1303. * @access protected
  1304. * @since 4.9.001 (2010-03-28)
  1305. */
  1306. protected $column_start_page = 0;
  1307. /**
  1308. * 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.
  1309. * @access protected
  1310. * @since 4.9.008 (2010-04-03)
  1311. */
  1312. protected $textrendermode = 0;
  1313. /**
  1314. * Text stroke width in doc units
  1315. * @access protected
  1316. * @since 4.9.008 (2010-04-03)
  1317. */
  1318. protected $textstrokewidth = 0;
  1319. /**
  1320. * @var current stroke color
  1321. * @access protected
  1322. * @since 4.9.008 (2010-04-03)
  1323. */
  1324. protected $strokecolor;
  1325. //------------------------------------------------------------
  1326. // METHODS
  1327. //------------------------------------------------------------
  1328. /**
  1329. * This is the class constructor.
  1330. * It allows to set up the page format, the orientation and
  1331. * the measure unit used in all the methods (except for the font sizes).
  1332. * @since 1.0
  1333. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  1334. * @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.
  1335. * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1336. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1337. * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1338. * @param String $encoding charset encoding; default is UTF-8
  1339. * @access public
  1340. */
  1341. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false) {
  1342. /* Set internal character encoding to ASCII */
  1343. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1344. $this->internal_encoding = mb_internal_encoding();
  1345. mb_internal_encoding('ASCII');
  1346. }
  1347. // set disk caching
  1348. $this->diskcache = $diskcache ? true : false;
  1349. // set language direction
  1350. $this->rtl = false;
  1351. $this->tmprtl = false;
  1352. //Some checks
  1353. $this->_dochecks();
  1354. //Initialization of properties
  1355. $this->isunicode = $unicode;
  1356. $this->page = 0;
  1357. $this->transfmrk[0] = array();
  1358. $this->pagedim = array();
  1359. $this->n = 2;
  1360. $this->buffer = '';
  1361. $this->pages = array();
  1362. $this->state = 0;
  1363. $this->fonts = array();
  1364. $this->FontFiles = array();
  1365. $this->diffs = array();
  1366. $this->images = array();
  1367. $this->links = array();
  1368. $this->gradients = array();
  1369. $this->InFooter = false;
  1370. $this->lasth = 0;
  1371. $this->FontFamily = 'helvetica';
  1372. $this->FontStyle = '';
  1373. $this->FontSizePt = 12;
  1374. $this->underline = false;
  1375. $this->overline = false;
  1376. $this->linethrough = false;
  1377. $this->DrawColor = '0 G';
  1378. $this->FillColor = '0 g';
  1379. $this->TextColor = '0 g';
  1380. $this->ColorFlag = false;
  1381. // encryption values
  1382. $this->encrypted = false;
  1383. $this->last_rc4_key = '';
  1384. $this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  1385. //Standard Unicode fonts
  1386. $this->CoreFonts = array(
  1387. 'courier'=>'Courier',
  1388. 'courierB'=>'Courier-Bold',
  1389. 'courierI'=>'Courier-Oblique',
  1390. 'courierBI'=>'Courier-BoldOblique',
  1391. 'helvetica'=>'Helvetica',
  1392. 'helveticaB'=>'Helvetica-Bold',
  1393. 'helveticaI'=>'Helvetica-Oblique',
  1394. 'helveticaBI'=>'Helvetica-BoldOblique',
  1395. 'times'=>'Times-Roman',
  1396. 'timesB'=>'Times-Bold',
  1397. 'timesI'=>'Times-Italic',
  1398. 'timesBI'=>'Times-BoldItalic',
  1399. 'symbol'=>'Symbol',
  1400. 'zapfdingbats'=>'ZapfDingbats'
  1401. );
  1402. //Set scale factor
  1403. $this->setPageUnit($unit);
  1404. // set page format and orientation
  1405. $this->setPageFormat($format, $orientation);
  1406. //Page margins (1 cm)
  1407. $margin = 28.35 / $this->k;
  1408. $this->SetMargins($margin, $margin);
  1409. //Interior cell margin
  1410. $this->cMargin = $margin / 10;
  1411. //Line width (0.2 mm)
  1412. $this->LineWidth = 0.57 / $this->k;
  1413. $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
  1414. $this->linestyleCap = '0 J';
  1415. $this->linestyleJoin = '0 j';
  1416. $this->linestyleDash = '[] 0 d';
  1417. //Automatic page break
  1418. $this->SetAutoPageBreak(true, (2 * $margin));
  1419. //Full width display mode
  1420. $this->SetDisplayMode('fullwidth');
  1421. //Compression
  1422. $this->SetCompression(true);
  1423. //Set default PDF version number
  1424. $this->PDFVersion = '1.7';
  1425. $this->encoding = $encoding;
  1426. $this->HREF = array();
  1427. $this->getFontsList();
  1428. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1429. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1430. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1431. $this->extgstates = array();
  1432. // user's rights
  1433. $this->sign = false;
  1434. $this->ur = false;
  1435. $this->ur_document = '/FullSave';
  1436. $this->ur_annots = '/Create/Delete/Modify/Copy/Import/Export';
  1437. $this->ur_form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1438. $this->ur_signature = '/Modify';
  1439. // set default JPEG quality
  1440. $this->jpeg_quality = 75;
  1441. // initialize some settings
  1442. $this->utf8Bidi(array(''), '');
  1443. // set default font
  1444. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1445. // check if PCRE Unicode support is enabled
  1446. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1447. // PCRE unicode support is turned ON
  1448. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1449. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1450. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1451. //$this->re_spaces = '/[\s\p{Z}\p{Lo}]/u';
  1452. $this->re_spaces = '/[\s\p{Z}]/u';
  1453. } else {
  1454. // PCRE unicode support is turned OFF
  1455. $this->re_spaces = '/[\s]/';
  1456. }
  1457. $this->annot_obj_id = $this->annots_start_obj_id;
  1458. $this->curr_annot_obj_id = $this->annots_start_obj_id;
  1459. $this->apxo_obj_id = $this->apxo_start_obj_id;
  1460. $this->js_obj_id = $this->js_start_obj_id;
  1461. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1462. }
  1463. /**
  1464. * Default destructor.
  1465. * @access public
  1466. * @since 1.53.0.TC016
  1467. */
  1468. public function __destruct() {
  1469. // restore internal encoding
  1470. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1471. mb_internal_encoding($this->internal_encoding);
  1472. }
  1473. // unset all class variables
  1474. $this->_destroy(true);
  1475. }
  1476. /**
  1477. * Set the units of measure for the document.
  1478. * @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.
  1479. * @access public
  1480. * @since 3.0.015 (2008-06-06)
  1481. */
  1482. public function setPageUnit($unit) {
  1483. //Set scale factor
  1484. switch (strtolower($unit)) {
  1485. // points
  1486. case 'px':
  1487. case 'pt': {
  1488. $this->k = 1;
  1489. break;
  1490. }
  1491. // millimeters
  1492. case 'mm': {
  1493. $this->k = $this->dpi / 25.4;
  1494. break;
  1495. }
  1496. // centimeters
  1497. case 'cm': {
  1498. $this->k = $this->dpi / 2.54;
  1499. break;
  1500. }
  1501. // inches
  1502. case 'in': {
  1503. $this->k = $this->dpi;
  1504. break;
  1505. }
  1506. // unsupported unit
  1507. default : {
  1508. $this->Error('Incorrect unit: '.$unit);
  1509. break;
  1510. }
  1511. }
  1512. if (isset($this->CurOrientation)) {
  1513. $this->setPageOrientation($this->CurOrientation);
  1514. }
  1515. }
  1516. /**
  1517. * Set the page format
  1518. * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1519. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1520. * @access public
  1521. * @since 3.0.015 (2008-06-06)
  1522. */
  1523. public function setPageFormat($format, $orientation='P') {
  1524. //Page format
  1525. if (is_string($format)) {
  1526. // Page formats (45 standard ISO paper formats and 4 american common formats).
  1527. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  1528. switch (strtoupper($format)) {
  1529. case '4A0': {$format = array(4767.87,6740.79); break;}
  1530. case '2A0': {$format = array(3370.39,4767.87); break;}
  1531. case 'A0': {$format = array(2383.94,3370.39); break;}
  1532. case 'A1': {$format = array(1683.78,2383.94); break;}
  1533. case 'A2': {$format = array(1190.55,1683.78); break;}
  1534. case 'A3': {$format = array(841.89,1190.55); break;}
  1535. case 'A4': default: {$format = array(595.28,841.89); break;}
  1536. case 'A5': {$format = array(419.53,595.28); break;}
  1537. case 'A6': {$format = array(297.64,419.53); break;}
  1538. case 'A7': {$format = array(209.76,297.64); break;}
  1539. case 'A8': {$format = array(147.40,209.76); break;}
  1540. case 'A9': {$format = array(104.88,147.40); break;}
  1541. case 'A10': {$format = array(73.70,104.88); break;}
  1542. case 'B0': {$format = array(2834.65,4008.19); break;}
  1543. case 'B1': {$format = array(2004.09,2834.65); break;}
  1544. case 'B2': {$format = array(1417.32,2004.09); break;}
  1545. case 'B3': {$format = array(1000.63,1417.32); break;}
  1546. case 'B4': {$format = array(708.66,1000.63); break;}
  1547. case 'B5': {$format = array(498.90,708.66); break;}
  1548. case 'B6': {$format = array(354.33,498.90); break;}
  1549. case 'B7': {$format = array(249.45,354.33); break;}
  1550. case 'B8': {$format = array(175.75,249.45); break;}
  1551. case 'B9': {$format = array(124.72,175.75); break;}
  1552. case 'B10': {$format = array(87.87,124.72); break;}
  1553. case 'C0': {$format = array(2599.37,3676.54); break;}
  1554. case 'C1': {$format = array(1836.85,2599.37); break;}
  1555. case 'C2': {$format = array(1298.27,1836.85); break;}
  1556. case 'C3': {$format = array(918.43,1298.27); break;}
  1557. case 'C4': {$format = array(649.13,918.43); break;}
  1558. case 'C5': {$format = array(459.21,649.13); break;}
  1559. case 'C6': {$format = array(323.15,459.21); break;}
  1560. case 'C7': {$format = array(229.61,323.15); break;}
  1561. case 'C8': {$format = array(161.57,229.61); break;}
  1562. case 'C9': {$format = array(113.39,161.57); break;}
  1563. case 'C10': {$format = array(79.37,113.39); break;}
  1564. case 'RA0': {$format = array(2437.80,3458.27); break;}
  1565. case 'RA1': {$format = array(1729.13,2437.80); break;}
  1566. case 'RA2': {$format = array(1218.90,1729.13); break;}
  1567. case 'RA3': {$format = array(864.57,1218.90); break;}
  1568. case 'RA4': {$format = array(609.45,864.57); break;}
  1569. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  1570. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  1571. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  1572. case 'SRA3': {$format = array(907.09,1275.59); break;}
  1573. case 'SRA4': {$format = array(637.80,907.09); break;}
  1574. case 'LETTER': {$format = array(612.00,792.00); break;}
  1575. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  1576. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  1577. case 'FOLIO': {$format = array(612.00,936.00); break;}
  1578. }
  1579. $this->fwPt = $format[0];
  1580. $this->fhPt = $format[1];
  1581. } else {
  1582. $this->fwPt = $format[0] * $this->k;
  1583. $this->fhPt = $format[1] * $this->k;
  1584. }
  1585. $this->setPageOrientation($orientation);
  1586. }
  1587. /**
  1588. * Set page orientation.
  1589. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1590. * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1591. * @param float $bottommargin bottom margin of the page.
  1592. * @access public
  1593. * @since 3.0.015 (2008-06-06)
  1594. */
  1595. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  1596. if ($this->fwPt > $this->fhPt) {
  1597. // landscape
  1598. $default_orientation = 'L';
  1599. } else {
  1600. // portrait
  1601. $default_orientation = 'P';
  1602. }
  1603. $valid_orientations = array('P', 'L');
  1604. if (empty($orientation)) {
  1605. $orientation = $default_orientation;
  1606. } else {
  1607. $orientation = $orientation{0};
  1608. $orientation = strtoupper($orientation);
  1609. }
  1610. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  1611. $this->CurOrientation = $orientation;
  1612. $this->wPt = $this->fhPt;
  1613. $this->hPt = $this->fwPt;
  1614. } else {
  1615. $this->CurOrientation = $default_orientation;
  1616. $this->wPt = $this->fwPt;
  1617. $this->hPt = $this->fhPt;
  1618. }
  1619. $this->w = $this->wPt / $this->k;
  1620. $this->h = $this->hPt / $this->k;
  1621. if ($this->empty_string($autopagebreak)) {
  1622. if (isset($this->AutoPageBreak)) {
  1623. $autopagebreak = $this->AutoPageBreak;
  1624. } else {
  1625. $autopagebreak = true;
  1626. }
  1627. }
  1628. if ($this->empty_string($bottommargin)) {
  1629. if (isset($this->bMargin)) {
  1630. $bottommargin = $this->bMargin;
  1631. } else {
  1632. // default value = 2 cm
  1633. $bottommargin = 2 * 28.35 / $this->k;
  1634. }
  1635. }
  1636. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  1637. // store page dimensions
  1638. $this->pagedim[$this->page] = array('w' => $this->wPt, 'h' => $this->hPt, 'wk' => $this->w, 'hk' => $this->h, 'tm' => $this->tMargin, 'bm' => $bottommargin, 'lm' => $this->lMargin, 'rm' => $this->rMargin, 'pb' => $autopagebreak, 'or' => $this->CurOrientation, 'olm' => $this->original_lMargin, 'orm' => $this->original_rMargin);
  1639. }
  1640. /**
  1641. * Set regular expression to detect withespaces or word separators.
  1642. * @param string $re regular expression (leave empty for default).
  1643. * @access public
  1644. * @since 4.6.016 (2009-06-15)
  1645. */
  1646. public function setSpacesRE($re='/[\s]/') {
  1647. // if PCRE unicode support is turned ON:
  1648. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1649. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1650. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1651. $this->re_spaces = $re;
  1652. }
  1653. /**
  1654. * Enable or disable Right-To-Left language mode
  1655. * @param Boolean $enable if true enable Right-To-Left language mode.
  1656. * @param Boolean $resetx if true reset the X position on direction change.
  1657. * @access public
  1658. * @since 2.0.000 (2008-01-03)
  1659. */
  1660. public function setRTL($enable, $resetx=true) {
  1661. $enable = $enable ? true : false;
  1662. $resetx = ($resetx AND ($enable != $this->rtl));
  1663. $this->rtl = $enable;
  1664. $this->tmprtl = false;
  1665. if ($resetx) {
  1666. $this->Ln(0);
  1667. }
  1668. }
  1669. /**
  1670. * Return the RTL status
  1671. * @return boolean
  1672. * @access public
  1673. * @since 4.0.012 (2008-07-24)
  1674. */
  1675. public function getRTL() {
  1676. return $this->rtl;
  1677. }
  1678. /**
  1679. * Force temporary RTL language direction
  1680. * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  1681. * @access public
  1682. * @since 2.1.000 (2008-01-09)
  1683. */
  1684. public function setTempRTL($mode) {
  1685. $newmode = false;
  1686. switch ($mode) {
  1687. case 'ltr':
  1688. case 'LTR':
  1689. case 'L': {
  1690. if ($this->rtl) {
  1691. $newmode = 'L';
  1692. }
  1693. break;
  1694. }
  1695. case 'rtl':
  1696. case 'RTL':
  1697. case 'R': {
  1698. if (!$this->rtl) {
  1699. $newmode = 'R';
  1700. }
  1701. break;
  1702. }
  1703. case false:
  1704. default: {
  1705. $newmode = false;
  1706. break;
  1707. }
  1708. }
  1709. $this->tmprtl = $newmode;
  1710. }
  1711. /**
  1712. * Return the current temporary RTL status
  1713. * @return boolean
  1714. * @access public
  1715. * @since 4.8.014 (2009-11-04)
  1716. */
  1717. public function isRTLTextDir() {
  1718. return ($this->rtl OR ($this->tmprtl == 'R'));
  1719. }
  1720. /**
  1721. * Set the last cell height.
  1722. * @param float $h cell height.
  1723. * @author Nicola Asuni
  1724. * @access public
  1725. * @since 1.53.0.TC034
  1726. */
  1727. public function setLastH($h) {
  1728. $this->lasth = $h;
  1729. }
  1730. /**
  1731. * Get the last cell height.
  1732. * @return last cell height
  1733. * @access public
  1734. * @since 4.0.017 (2008-08-05)
  1735. */
  1736. public function getLastH() {
  1737. return $this->lasth;
  1738. }
  1739. /**
  1740. * Set the adjusting factor to convert pixels to user units.
  1741. * @param float $scale adjusting factor to convert pixels to user units.
  1742. * @author Nicola Asuni
  1743. * @access public
  1744. * @since 1.5.2
  1745. */
  1746. public function setImageScale($scale) {
  1747. $this->imgscale = $scale;
  1748. }
  1749. /**
  1750. * Returns the adjusting factor to convert pixels to user units.
  1751. * @return float adjusting factor to convert pixels to user units.
  1752. * @author Nicola Asuni
  1753. * @access public
  1754. * @since 1.5.2
  1755. */
  1756. public function getImageScale() {
  1757. return $this->imgscale;
  1758. }
  1759. /**
  1760. * Returns an array of page dimensions:
  1761. * <ul><li>$this->pagedim[$this->page]['w'] => page_width_in_points</li><li>$this->pagedim[$this->page]['h'] => height in points</li><li>$this->pagedim[$this->page]['wk'] => page_width_in_points</li><li>$this->pagedim[$this->page]['hk'] => height</li><li>$this->pagedim[$this->page]['tm'] => top_margin</li><li>$this->pagedim[$this->page]['bm'] => bottom_margin</li><li>$this->pagedim[$this->page]['lm'] => left_margin</li><li>$this->pagedim[$this->page]['rm'] => right_margin</li><li>$this->pagedim[$this->page]['pb'] => auto_page_break</li><li>$this->pagedim[$this->page]['or'] => page_orientation</li><li>$this->pagedim[$this->page]['olm'] => original_left_margin</li><li>$this->pagedim[$this->page]['orm'] => original_right_margin</li></ul>
  1762. * @param int $pagenum page number (empty = current page)
  1763. * @return array of page dimensions.
  1764. * @author Nicola Asuni
  1765. * @access public
  1766. * @since 4.5.027 (2009-03-16)
  1767. */
  1768. public function getPageDimensions($pagenum='') {
  1769. if (empty($pagenum)) {
  1770. $pagenum = $this->page;
  1771. }
  1772. return $this->pagedim[$pagenum];
  1773. }
  1774. /**
  1775. * Returns the page width in units.
  1776. * @param int $pagenum page number (empty = current page)
  1777. * @return int page width.
  1778. * @author Nicola Asuni
  1779. * @access public
  1780. * @since 1.5.2
  1781. * @see getPageDimensions()
  1782. */
  1783. public function getPageWidth($pagenum='') {
  1784. if (empty($pagenum)) {
  1785. return $this->w;
  1786. }
  1787. return $this->pagedim[$pagenum]['w'];
  1788. }
  1789. /**
  1790. * Returns the page height in units.
  1791. * @param int $pagenum page number (empty = current page)
  1792. * @return int page height.
  1793. * @author Nicola Asuni
  1794. * @access public
  1795. * @since 1.5.2
  1796. * @see getPageDimensions()
  1797. */
  1798. public function getPageHeight($pagenum='') {
  1799. if (empty($pagenum)) {
  1800. return $this->h;
  1801. }
  1802. return $this->pagedim[$pagenum]['h'];
  1803. }
  1804. /**
  1805. * Returns the page break margin.
  1806. * @param int $pagenum page number (empty = current page)
  1807. * @return int page break margin.
  1808. * @author Nicola Asuni
  1809. * @access public
  1810. * @since 1.5.2
  1811. * @see getPageDimensions()
  1812. */
  1813. public function getBreakMargin($pagenum='') {
  1814. if (empty($pagenum)) {
  1815. return $this->bMargin;
  1816. }
  1817. return $this->pagedim[$pagenum]['bm'];
  1818. }
  1819. /**
  1820. * Returns the scale factor (number of points in user unit).
  1821. * @return int scale factor.
  1822. * @author Nicola Asuni
  1823. * @access public
  1824. * @since 1.5.2
  1825. */
  1826. public function getScaleFactor() {
  1827. return $this->k;
  1828. }
  1829. /**
  1830. * Defines the left, top and right margins.
  1831. * @param float $left Left margin.
  1832. * @param float $top Top margin.
  1833. * @param float $right Right margin. Default value is the left one.
  1834. * @param boolean $keepmargins if true overwrites the default page margins
  1835. * @access public
  1836. * @since 1.0
  1837. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  1838. */
  1839. public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
  1840. //Set left, top and right margins
  1841. $this->lMargin = $left;
  1842. $this->tMargin = $top;
  1843. if ($right == -1) {
  1844. $right = $left;
  1845. }
  1846. $this->rMargin = $right;
  1847. if ($keepmargins) {
  1848. // overwrite original values
  1849. $this->original_lMargin = $this->lMargin;
  1850. $this->original_rMargin = $this->rMargin;
  1851. }
  1852. }
  1853. /**
  1854. * 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.
  1855. * @param float $margin The margin.
  1856. * @access public
  1857. * @since 1.4
  1858. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1859. */
  1860. public function SetLeftMargin($margin) {
  1861. //Set left margin
  1862. $this->lMargin=$margin;
  1863. if (($this->page > 0) AND ($this->x < $margin)) {
  1864. $this->x = $margin;
  1865. }
  1866. }
  1867. /**
  1868. * Defines the top margin. The method can be called before creating the first page.
  1869. * @param float $margin The margin.
  1870. * @access public
  1871. * @since 1.5
  1872. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1873. */
  1874. public function SetTopMargin($margin) {
  1875. //Set top margin
  1876. $this->tMargin=$margin;
  1877. if (($this->page > 0) AND ($this->y < $margin)) {
  1878. $this->y = $margin;
  1879. }
  1880. }
  1881. /**
  1882. * Defines the right margin. The method can be called before creating the first page.
  1883. * @param float $margin The margin.
  1884. * @access public
  1885. * @since 1.5
  1886. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1887. */
  1888. public function SetRightMargin($margin) {
  1889. $this->rMargin=$margin;
  1890. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  1891. $this->x = $this->w - $margin;
  1892. }
  1893. }
  1894. /**
  1895. * Set the internal Cell padding.
  1896. * @param float $pad internal padding.
  1897. * @access public
  1898. * @since 2.1.000 (2008-01-09)
  1899. * @see Cell(), SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1900. */
  1901. public function SetCellPadding($pad) {
  1902. $this->cMargin = $pad;
  1903. }
  1904. /**
  1905. * 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.
  1906. * @param boolean $auto Boolean indicating if mode should be on or off.
  1907. * @param float $margin Distance from the bottom of the page.
  1908. * @access public
  1909. * @since 1.0
  1910. * @see Cell(), MultiCell(), AcceptPageBreak()
  1911. */
  1912. public function SetAutoPageBreak($auto, $margin=0) {
  1913. //Set auto page break mode and triggering margin
  1914. $this->AutoPageBreak = $auto;
  1915. $this->bMargin = $margin;
  1916. $this->PageBreakTrigger = $this->h - $margin;
  1917. }
  1918. /**
  1919. * Defines the way the document is to be displayed by the viewer.
  1920. * @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>
  1921. * @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>
  1922. * @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>
  1923. * @access public
  1924. * @since 1.2
  1925. */
  1926. public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  1927. //Set display mode in viewer
  1928. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  1929. $this->ZoomMode = $zoom;
  1930. } else {
  1931. $this->Error('Incorrect zoom display mode: '.$zoom);
  1932. }
  1933. switch ($layout) {
  1934. case 'default':
  1935. case 'single':
  1936. case 'SinglePage': {
  1937. $this->LayoutMode = 'SinglePage';
  1938. break;
  1939. }
  1940. case 'continuous':
  1941. case 'OneColumn': {
  1942. $this->LayoutMode = 'OneColumn';
  1943. break;
  1944. }
  1945. case 'two':
  1946. case 'TwoColumnLeft': {
  1947. $this->LayoutMode = 'TwoColumnLeft';
  1948. break;
  1949. }
  1950. case 'TwoColumnRight': {
  1951. $this->LayoutMode = 'TwoColumnRight';
  1952. break;
  1953. }
  1954. case 'TwoPageLeft': {
  1955. $this->LayoutMode = 'TwoPageLeft';
  1956. break;
  1957. }
  1958. case 'TwoPageRight': {
  1959. $this->LayoutMode = 'TwoPageRight';
  1960. break;
  1961. }
  1962. default: {
  1963. $this->LayoutMode = 'SinglePage';
  1964. }
  1965. }
  1966. switch ($mode) {
  1967. case 'UseNone': {
  1968. $this->PageMode = 'UseNone';
  1969. break;
  1970. }
  1971. case 'UseOutlines': {
  1972. $this->PageMode = 'UseOutlines';
  1973. break;
  1974. }
  1975. case 'UseThumbs': {
  1976. $this->PageMode = 'UseThumbs';
  1977. break;
  1978. }
  1979. case 'FullScreen': {
  1980. $this->PageMode = 'FullScreen';
  1981. break;
  1982. }
  1983. case 'UseOC': {
  1984. $this->PageMode = 'UseOC';
  1985. break;
  1986. }
  1987. case '': {
  1988. $this->PageMode = 'UseAttachments';
  1989. break;
  1990. }
  1991. default: {
  1992. $this->PageMode = 'UseNone';
  1993. }
  1994. }
  1995. }
  1996. /**
  1997. * 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.
  1998. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  1999. * @param boolean $compress Boolean indicating if compression must be enabled.
  2000. * @access public
  2001. * @since 1.4
  2002. */
  2003. public function SetCompression($compress) {
  2004. //Set page compression
  2005. if (function_exists('gzcompress')) {
  2006. $this->compress = $compress;
  2007. } else {
  2008. $this->compress = false;
  2009. }
  2010. }
  2011. /**
  2012. * Defines the title of the document.
  2013. * @param string $title The title.
  2014. * @access public
  2015. * @since 1.2
  2016. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2017. */
  2018. public function SetTitle($title) {
  2019. //Title of document
  2020. $this->title = $title;
  2021. }
  2022. /**
  2023. * Defines the subject of the document.
  2024. * @param string $subject The subject.
  2025. * @access public
  2026. * @since 1.2
  2027. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2028. */
  2029. public function SetSubject($subject) {
  2030. //Subject of document
  2031. $this->subject = $subject;
  2032. }
  2033. /**
  2034. * Defines the author of the document.
  2035. * @param string $author The name of the author.
  2036. * @access public
  2037. * @since 1.2
  2038. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2039. */
  2040. public function SetAuthor($author) {
  2041. //Author of document
  2042. $this->author = $author;
  2043. }
  2044. /**
  2045. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2046. * @param string $keywords The list of keywords.
  2047. * @access public
  2048. * @since 1.2
  2049. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2050. */
  2051. public function SetKeywords($keywords) {
  2052. //Keywords of document
  2053. $this->keywords = $keywords;
  2054. }
  2055. /**
  2056. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2057. * @param string $creator The name of the creator.
  2058. * @access public
  2059. * @since 1.2
  2060. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2061. */
  2062. public function SetCreator($creator) {
  2063. //Creator of document
  2064. $this->creator = $creator;
  2065. }
  2066. /**
  2067. * 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.
  2068. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  2069. * @param string $msg The error message
  2070. * @access public
  2071. * @since 1.0
  2072. */
  2073. public function Error($msg) {
  2074. // unset all class variables
  2075. $this->_destroy(true);
  2076. // exit program and print error
  2077. die('<strong>TCPDF ERROR: </strong>'.$msg);
  2078. }
  2079. /**
  2080. * This method begins the generation of the PDF document.
  2081. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2082. * Note: no page is created by this method
  2083. * @access public
  2084. * @since 1.0
  2085. * @see AddPage(), Close()
  2086. */
  2087. public function Open() {
  2088. //Begin document
  2089. $this->state = 1;
  2090. }
  2091. /**
  2092. * Terminates the PDF document.
  2093. * It is not necessary to call this method explicitly because Output() does it automatically.
  2094. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2095. * @access public
  2096. * @since 1.0
  2097. * @see Open(), Output()
  2098. */
  2099. public function Close() {
  2100. if ($this->state == 3) {
  2101. return;
  2102. }
  2103. if ($this->page == 0) {
  2104. $this->AddPage();
  2105. }
  2106. // close page
  2107. $this->endPage();
  2108. // close document
  2109. $this->_enddoc();
  2110. // unset all class variables (except critical ones)
  2111. $this->_destroy(false);
  2112. }
  2113. /**
  2114. * Move pointer at the specified document page and update page dimensions.
  2115. * @param int $pnum page number (1 ... numpages)
  2116. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2117. * @access public
  2118. * @since 2.1.000 (2008-01-07)
  2119. * @see getPage(), lastpage(), getNumPages()
  2120. */
  2121. public function setPage($pnum, $resetmargins=false) {
  2122. if ($pnum == $this->page) {
  2123. return;
  2124. }
  2125. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  2126. $this->state = 2;
  2127. // save current graphic settings
  2128. //$gvars = $this->getGraphicVars();
  2129. $oldpage = $this->page;
  2130. $this->page = $pnum;
  2131. $this->wPt = $this->pagedim[$this->page]['w'];
  2132. $this->hPt = $this->pagedim[$this->page]['h'];
  2133. $this->w = $this->wPt / $this->k;
  2134. $this->h = $this->hPt / $this->k;
  2135. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2136. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2137. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2138. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2139. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2140. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2141. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2142. // restore graphic settings
  2143. //$this->setGraphicVars($gvars);
  2144. if ($resetmargins) {
  2145. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2146. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2147. $this->SetY($this->tMargin);
  2148. } else {
  2149. // account for booklet mode
  2150. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2151. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2152. $this->lMargin += $deltam;
  2153. $this->rMargin -= $deltam;
  2154. }
  2155. }
  2156. } else {
  2157. $this->Error('Wrong page number on setPage() function.');
  2158. }
  2159. }
  2160. /**
  2161. * Reset pointer to the last document page.
  2162. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2163. * @access public
  2164. * @since 2.0.000 (2008-01-04)
  2165. * @see setPage(), getPage(), getNumPages()
  2166. */
  2167. public function lastPage($resetmargins=false) {
  2168. $this->setPage($this->getNumPages(), $resetmargins);
  2169. }
  2170. /**
  2171. * Get current document page number.
  2172. * @return int page number
  2173. * @access public
  2174. * @since 2.1.000 (2008-01-07)
  2175. * @see setPage(), lastpage(), getNumPages()
  2176. */
  2177. public function getPage() {
  2178. return $this->page;
  2179. }
  2180. /**
  2181. * Get the total number of insered pages.
  2182. * @return int number of pages
  2183. * @access public
  2184. * @since 2.1.000 (2008-01-07)
  2185. * @see setPage(), getPage(), lastpage()
  2186. */
  2187. public function getNumPages() {
  2188. return $this->numpages;
  2189. }
  2190. /**
  2191. * 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).
  2192. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2193. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2194. * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  2195. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2196. * @access public
  2197. * @since 1.0
  2198. * @see startPage(), endPage()
  2199. */
  2200. public function AddPage($orientation='', $format='', $keepmargins=false) {
  2201. if (!isset($this->original_lMargin) OR $keepmargins) {
  2202. $this->original_lMargin = $this->lMargin;
  2203. }
  2204. if (!isset($this->original_rMargin) OR $keepmargins) {
  2205. $this->original_rMargin = $this->rMargin;
  2206. }
  2207. // terminate previous page
  2208. $this->endPage();
  2209. // start new page
  2210. $this->startPage($orientation, $format);
  2211. }
  2212. /**
  2213. * Terminate the current page
  2214. * @access protected
  2215. * @since 4.2.010 (2008-11-14)
  2216. * @see startPage(), AddPage()
  2217. */
  2218. protected function endPage() {
  2219. // check if page is already closed
  2220. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  2221. return;
  2222. }
  2223. $this->InFooter = true;
  2224. // print page footer
  2225. $this->setFooter();
  2226. // close page
  2227. $this->_endpage();
  2228. // mark page as closed
  2229. $this->pageopen[$this->page] = false;
  2230. $this->InFooter = false;
  2231. }
  2232. /**
  2233. * Starts a new page to the document. The page must be closed using the endPage() function.
  2234. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2235. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2236. * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  2237. * @access protected
  2238. * @since 4.2.010 (2008-11-14)
  2239. * @see endPage(), AddPage()
  2240. */
  2241. protected function startPage($orientation='', $format='') {
  2242. if ($this->numpages > $this->page) {
  2243. // this page has been already added
  2244. $this->setPage($this->page + 1);
  2245. $this->SetY($this->tMargin);
  2246. return;
  2247. }
  2248. // start a new page
  2249. if ($this->state == 0) {
  2250. $this->Open();
  2251. }
  2252. ++$this->numpages;
  2253. $this->swapMargins($this->booklet);
  2254. // save current graphic settings
  2255. $gvars = $this->getGraphicVars();
  2256. // start new page
  2257. $this->_beginpage($orientation, $format);
  2258. // mark page as open
  2259. $this->pageopen[$this->page] = true;
  2260. // restore graphic settings
  2261. $this->setGraphicVars($gvars);
  2262. // mark this point
  2263. $this->setPageMark();
  2264. // print page header
  2265. $this->setHeader();
  2266. // restore graphic settings
  2267. $this->setGraphicVars($gvars);
  2268. // mark this point
  2269. $this->setPageMark();
  2270. // print table header (if any)
  2271. $this->setTableHeader();
  2272. }
  2273. /**
  2274. * Set start-writing mark on current page stream used to put borders and fills.
  2275. * Borders and fills are always created after content and inserted on the position marked by this method.
  2276. * This function must be called after calling Image() function for a background image.
  2277. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2278. * @access public
  2279. * @since 4.0.016 (2008-07-30)
  2280. */
  2281. public function setPageMark() {
  2282. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2283. $this->setContentMark();
  2284. }
  2285. /**
  2286. * Set start-writing mark on selected page.
  2287. * Borders and fills are always created after content and inserted on the position marked by this method.
  2288. * @param int $page page number (default is the current page)
  2289. * @access protected
  2290. * @since 4.6.021 (2009-07-20)
  2291. */
  2292. protected function setContentMark($page=0) {
  2293. if ($page <= 0) {
  2294. $page = $this->page;
  2295. }
  2296. if (isset($this->footerlen[$page])) {
  2297. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  2298. } else {
  2299. $this->cntmrk[$page] = $this->pagelen[$page];
  2300. }
  2301. }
  2302. /**
  2303. * Set header data.
  2304. * @param string $ln header image logo
  2305. * @param string $lw header image logo width in mm
  2306. * @param string $ht string to print as title on document header
  2307. * @param string $hs string to print on document header
  2308. * @access public
  2309. */
  2310. public function setHeaderData($ln='', $lw=0, $ht='', $hs='') {
  2311. $this->header_logo = $ln;
  2312. $this->header_logo_width = $lw;
  2313. $this->header_title = $ht;
  2314. $this->header_string = $hs;
  2315. }
  2316. /**
  2317. * Returns header data:
  2318. * <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>
  2319. * @return array()
  2320. * @access public
  2321. * @since 4.0.012 (2008-07-24)
  2322. */
  2323. public function getHeaderData() {
  2324. $ret = array();
  2325. $ret['logo'] = $this->header_logo;
  2326. $ret['logo_width'] = $this->header_logo_width;
  2327. $ret['title'] = $this->header_title;
  2328. $ret['string'] = $this->header_string;
  2329. return $ret;
  2330. }
  2331. /**
  2332. * Set header margin.
  2333. * (minimum distance between header and top page margin)
  2334. * @param int $hm distance in user units
  2335. * @access public
  2336. */
  2337. public function setHeaderMargin($hm=10) {
  2338. $this->header_margin = $hm;
  2339. }
  2340. /**
  2341. * Returns header margin in user units.
  2342. * @return float
  2343. * @since 4.0.012 (2008-07-24)
  2344. * @access public
  2345. */
  2346. public function getHeaderMargin() {
  2347. return $this->header_margin;
  2348. }
  2349. /**
  2350. * Set footer margin.
  2351. * (minimum distance between footer and bottom page margin)
  2352. * @param int $fm distance in user units
  2353. * @access public
  2354. */
  2355. public function setFooterMargin($fm=10) {
  2356. $this->footer_margin = $fm;
  2357. }
  2358. /**
  2359. * Returns footer margin in user units.
  2360. * @return float
  2361. * @since 4.0.012 (2008-07-24)
  2362. * @access public
  2363. */
  2364. public function getFooterMargin() {
  2365. return $this->footer_margin;
  2366. }
  2367. /**
  2368. * Set a flag to print page header.
  2369. * @param boolean $val set to true to print the page header (default), false otherwise.
  2370. * @access public
  2371. */
  2372. public function setPrintHeader($val=true) {
  2373. $this->print_header = $val;
  2374. }
  2375. /**
  2376. * Set a flag to print page footer.
  2377. * @param boolean $value set to true to print the page footer (default), false otherwise.
  2378. * @access public
  2379. */
  2380. public function setPrintFooter($val=true) {
  2381. $this->print_footer = $val;
  2382. }
  2383. /**
  2384. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  2385. * @return float
  2386. * @access public
  2387. */
  2388. public function getImageRBX() {
  2389. return $this->img_rb_x;
  2390. }
  2391. /**
  2392. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  2393. * @return float
  2394. * @access public
  2395. */
  2396. public function getImageRBY() {
  2397. return $this->img_rb_y;
  2398. }
  2399. /**
  2400. * This method is used to render the page header.
  2401. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2402. * @access public
  2403. */
  2404. public function Header() {
  2405. $ormargins = $this->getOriginalMargins();
  2406. $headerfont = $this->getHeaderFont();
  2407. $headerdata = $this->getHeaderData();
  2408. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  2409. $this->Image(K_PATH_IMAGES.$headerdata['logo'], $this->GetX(), $this->getHeaderMargin(), $headerdata['logo_width']);
  2410. $imgy = $this->getImageRBY();
  2411. } else {
  2412. $imgy = $this->GetY();
  2413. }
  2414. $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
  2415. // set starting margin for text data cell
  2416. if ($this->getRTL()) {
  2417. $header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1);
  2418. } else {
  2419. $header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1);
  2420. }
  2421. $this->SetTextColor(0, 0, 0);
  2422. // header title
  2423. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  2424. $this->SetX($header_x);
  2425. $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  2426. // header string
  2427. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  2428. $this->SetX($header_x);
  2429. $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
  2430. // print an ending header line
  2431. $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  2432. $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY()));
  2433. if ($this->getRTL()) {
  2434. $this->SetX($ormargins['right']);
  2435. } else {
  2436. $this->SetX($ormargins['left']);
  2437. }
  2438. $this->Cell(0, 0, '', 'T', 0, 'C');
  2439. }
  2440. /**
  2441. * This method is used to render the page footer.
  2442. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2443. * @access public
  2444. */
  2445. public function Footer() {
  2446. $cur_y = $this->GetY();
  2447. $ormargins = $this->getOriginalMargins();
  2448. $this->SetTextColor(0, 0, 0);
  2449. //set style for cell border
  2450. $line_width = 0.85 / $this->getScaleFactor();
  2451. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  2452. //print document barcode
  2453. $barcode = $this->getBarcode();
  2454. if (!empty($barcode)) {
  2455. $this->Ln($line_width);
  2456. $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right'])/3);
  2457. $this->write1DBarcode($barcode, 'C128B', $this->GetX(), $cur_y + $line_width, $barcode_width, (($this->getFooterMargin() / 3) - $line_width), 0.3, '', '');
  2458. }
  2459. if (empty($this->pagegroups)) {
  2460. $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  2461. } else {
  2462. $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  2463. }
  2464. $this->SetY($cur_y);
  2465. //Print page number
  2466. if ($this->getRTL()) {
  2467. $this->SetX($ormargins['right']);
  2468. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  2469. } else {
  2470. $this->SetX($ormargins['left']);
  2471. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
  2472. }
  2473. }
  2474. /**
  2475. * This method is used to render the page header.
  2476. * @access protected
  2477. * @since 4.0.012 (2008-07-24)
  2478. */
  2479. protected function setHeader() {
  2480. if ($this->print_header) {
  2481. $temp_thead = $this->thead;
  2482. $temp_theadMargins = $this->theadMargins;
  2483. $lasth = $this->lasth;
  2484. $this->_out('q');
  2485. $this->rMargin = $this->original_rMargin;
  2486. $this->lMargin = $this->original_lMargin;
  2487. $this->cMargin = 0;
  2488. //set current position
  2489. if ($this->rtl) {
  2490. $this->SetXY($this->original_rMargin, $this->header_margin);
  2491. } else {
  2492. $this->SetXY($this->original_lMargin, $this->header_margin);
  2493. }
  2494. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  2495. $this->Header();
  2496. //restore position
  2497. if ($this->rtl) {
  2498. $this->SetXY($this->original_rMargin, $this->tMargin);
  2499. } else {
  2500. $this->SetXY($this->original_lMargin, $this->tMargin);
  2501. }
  2502. $this->_out('Q');
  2503. $this->lasth = $lasth;
  2504. $this->thead = $temp_thead;
  2505. $this->theadMargins = $temp_theadMargins;
  2506. $this->newline = false;
  2507. }
  2508. }
  2509. /**
  2510. * This method is used to render the page footer.
  2511. * @access protected
  2512. * @since 4.0.012 (2008-07-24)
  2513. */
  2514. protected function setFooter() {
  2515. //Page footer
  2516. // save current graphic settings
  2517. $gvars = $this->getGraphicVars();
  2518. // mark this point
  2519. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  2520. $this->_out("\n");
  2521. if ($this->print_footer) {
  2522. $temp_thead = $this->thead;
  2523. $temp_theadMargins = $this->theadMargins;
  2524. $lasth = $this->lasth;
  2525. $this->_out('q');
  2526. $this->rMargin = $this->original_rMargin;
  2527. $this->lMargin = $this->original_lMargin;
  2528. $this->cMargin = 0;
  2529. //set current position
  2530. $footer_y = $this->h - $this->footer_margin;
  2531. if ($this->rtl) {
  2532. $this->SetXY($this->original_rMargin, $footer_y);
  2533. } else {
  2534. $this->SetXY($this->original_lMargin, $footer_y);
  2535. }
  2536. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  2537. $this->Footer();
  2538. //restore position
  2539. if ($this->rtl) {
  2540. $this->SetXY($this->original_rMargin, $this->tMargin);
  2541. } else {
  2542. $this->SetXY($this->original_lMargin, $this->tMargin);
  2543. }
  2544. $this->_out('Q');
  2545. $this->lasth = $lasth;
  2546. $this->thead = $temp_thead;
  2547. $this->theadMargins = $temp_theadMargins;
  2548. }
  2549. // restore graphic settings
  2550. $this->setGraphicVars($gvars);
  2551. // calculate footer length
  2552. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  2553. }
  2554. /**
  2555. * This method is used to render the table header on new page (if any).
  2556. * @access protected
  2557. * @since 4.5.030 (2009-03-25)
  2558. */
  2559. protected function setTableHeader() {
  2560. if ($this->num_columns > 1) {
  2561. // multi column mode
  2562. return;
  2563. }
  2564. if (isset($this->theadMargins['top'])) {
  2565. // restore the original top-margin
  2566. $this->tMargin = $this->theadMargins['top'];
  2567. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2568. $this->y = $this->tMargin;
  2569. }
  2570. if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  2571. // set margins
  2572. $prev_lMargin = $this->lMargin;
  2573. $prev_rMargin = $this->rMargin;
  2574. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2575. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2576. $this->cMargin = $this->theadMargins['cmargin'];
  2577. // print table header
  2578. $this->writeHTML($this->thead, false, false, false, false, '');
  2579. // set new top margin to skip the table headers
  2580. if (!isset($this->theadMargins['top'])) {
  2581. $this->theadMargins['top'] = $this->tMargin;
  2582. }
  2583. $this->tMargin = $this->y;
  2584. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2585. $this->lasth = 0;
  2586. $this->lMargin = $prev_lMargin;
  2587. $this->rMargin = $prev_rMargin;
  2588. }
  2589. }
  2590. /**
  2591. * Returns the current page number.
  2592. * @return int page number
  2593. * @access public
  2594. * @since 1.0
  2595. * @see AliasNbPages(), getAliasNbPages()
  2596. */
  2597. public function PageNo() {
  2598. return $this->page;
  2599. }
  2600. /**
  2601. * Defines a new spot color.
  2602. * It can be expressed in RGB components or gray scale.
  2603. * The method can be called before the first page is created and the value is retained from page to page.
  2604. * @param int $c Cyan color for CMYK. Value between 0 and 255
  2605. * @param int $m Magenta color for CMYK. Value between 0 and 255
  2606. * @param int $y Yellow color for CMYK. Value between 0 and 255
  2607. * @param int $k Key (Black) color for CMYK. Value between 0 and 255
  2608. * @access public
  2609. * @since 4.0.024 (2008-09-12)
  2610. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2611. */
  2612. public function AddSpotColor($name, $c, $m, $y, $k) {
  2613. if (!isset($this->spot_colors[$name])) {
  2614. $i = 1 + count($this->spot_colors);
  2615. $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
  2616. }
  2617. }
  2618. /**
  2619. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  2620. * It can be expressed in RGB components or gray scale.
  2621. * The method can be called before the first page is created and the value is retained from page to page.
  2622. * @param array $color array of colors
  2623. * @access public
  2624. * @since 3.1.000 (2008-06-11)
  2625. * @see SetDrawColor()
  2626. */
  2627. public function SetDrawColorArray($color) {
  2628. if (isset($color)) {
  2629. $color = array_values($color);
  2630. $r = isset($color[0]) ? $color[0] : -1;
  2631. $g = isset($color[1]) ? $color[1] : -1;
  2632. $b = isset($color[2]) ? $color[2] : -1;
  2633. $k = isset($color[3]) ? $color[3] : -1;
  2634. if ($r >= 0) {
  2635. $this->SetDrawColor($r, $g, $b, $k);
  2636. }
  2637. }
  2638. }
  2639. /**
  2640. * 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.
  2641. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2642. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2643. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2644. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2645. * @access public
  2646. * @since 1.3
  2647. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  2648. */
  2649. public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1) {
  2650. // set default values
  2651. if (!is_numeric($col1)) {
  2652. $col1 = 0;
  2653. }
  2654. if (!is_numeric($col2)) {
  2655. $col2 = -1;
  2656. }
  2657. if (!is_numeric($col3)) {
  2658. $col3 = -1;
  2659. }
  2660. if (!is_numeric($col4)) {
  2661. $col4 = -1;
  2662. }
  2663. //Set color for all stroking operations
  2664. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  2665. // Grey scale
  2666. $this->DrawColor = sprintf('%.3F G', $col1/255);
  2667. $this->strokecolor = array('G' => $col1);
  2668. } elseif ($col4 == -1) {
  2669. // RGB
  2670. $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $col1/255, $col2/255, $col3/255);
  2671. $this->strokecolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  2672. } else {
  2673. // CMYK
  2674. $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K', $col1/100, $col2/100, $col3/100, $col4/100);
  2675. $this->strokecolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  2676. }
  2677. if ($this->page > 0) {
  2678. $this->_out($this->DrawColor);
  2679. }
  2680. }
  2681. /**
  2682. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  2683. * @param string $name name of the spot color
  2684. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2685. * @access public
  2686. * @since 4.0.024 (2008-09-12)
  2687. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2688. */
  2689. public function SetDrawSpotColor($name, $tint=100) {
  2690. if (!isset($this->spot_colors[$name])) {
  2691. $this->Error('Undefined spot color: '.$name);
  2692. }
  2693. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], $tint/100);
  2694. if ($this->page > 0) {
  2695. $this->_out($this->DrawColor);
  2696. }
  2697. }
  2698. /**
  2699. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  2700. * It can be expressed in RGB components or gray scale.
  2701. * The method can be called before the first page is created and the value is retained from page to page.
  2702. * @param array $color array of colors
  2703. * @access public
  2704. * @since 3.1.000 (2008-6-11)
  2705. * @see SetFillColor()
  2706. */
  2707. public function SetFillColorArray($color) {
  2708. if (isset($color)) {
  2709. $color = array_values($color);
  2710. $r = isset($color[0]) ? $color[0] : -1;
  2711. $g = isset($color[1]) ? $color[1] : -1;
  2712. $b = isset($color[2]) ? $color[2] : -1;
  2713. $k = isset($color[3]) ? $color[3] : -1;
  2714. if ($r >= 0) {
  2715. $this->SetFillColor($r, $g, $b, $k);
  2716. }
  2717. }
  2718. }
  2719. /**
  2720. * 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.
  2721. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2722. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2723. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2724. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2725. * @access public
  2726. * @since 1.3
  2727. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  2728. */
  2729. public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1) {
  2730. // set default values
  2731. if (!is_numeric($col1)) {
  2732. $col1 = 0;
  2733. }
  2734. if (!is_numeric($col2)) {
  2735. $col2 = -1;
  2736. }
  2737. if (!is_numeric($col3)) {
  2738. $col3 = -1;
  2739. }
  2740. if (!is_numeric($col4)) {
  2741. $col4 = -1;
  2742. }
  2743. //Set color for all filling operations
  2744. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  2745. // Grey scale
  2746. $this->FillColor = sprintf('%.3F g', $col1/255);
  2747. $this->bgcolor = array('G' => $col1);
  2748. } elseif ($col4 == -1) {
  2749. // RGB
  2750. $this->FillColor = sprintf('%.3F %.3F %.3F rg', $col1/255, $col2/255, $col3/255);
  2751. $this->bgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  2752. } else {
  2753. // CMYK
  2754. $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k', $col1/100, $col2/100, $col3/100, $col4/100);
  2755. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  2756. }
  2757. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2758. if ($this->page > 0) {
  2759. $this->_out($this->FillColor);
  2760. }
  2761. }
  2762. /**
  2763. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  2764. * @param string $name name of the spot color
  2765. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2766. * @access public
  2767. * @since 4.0.024 (2008-09-12)
  2768. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  2769. */
  2770. public function SetFillSpotColor($name, $tint=100) {
  2771. if (!isset($this->spot_colors[$name])) {
  2772. $this->Error('Undefined spot color: '.$name);
  2773. }
  2774. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint/100);
  2775. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2776. if ($this->page > 0) {
  2777. $this->_out($this->FillColor);
  2778. }
  2779. }
  2780. /**
  2781. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  2782. * The method can be called before the first page is created and the value is retained from page to page.
  2783. * @param array $color array of colors
  2784. * @access public
  2785. * @since 3.1.000 (2008-6-11)
  2786. * @see SetFillColor()
  2787. */
  2788. public function SetTextColorArray($color) {
  2789. if (isset($color)) {
  2790. $color = array_values($color);
  2791. $r = isset($color[0]) ? $color[0] : -1;
  2792. $g = isset($color[1]) ? $color[1] : -1;
  2793. $b = isset($color[2]) ? $color[2] : -1;
  2794. $k = isset($color[3]) ? $color[3] : -1;
  2795. if ($r >= 0) {
  2796. $this->SetTextColor($r, $g, $b, $k);
  2797. }
  2798. }
  2799. }
  2800. /**
  2801. * 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.
  2802. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2803. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2804. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2805. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2806. * @access public
  2807. * @since 1.3
  2808. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  2809. */
  2810. public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1) {
  2811. // set default values
  2812. if (!is_numeric($col1)) {
  2813. $col1 = 0;
  2814. }
  2815. if (!is_numeric($col2)) {
  2816. $col2 = -1;
  2817. }
  2818. if (!is_numeric($col3)) {
  2819. $col3 = -1;
  2820. }
  2821. if (!is_numeric($col4)) {
  2822. $col4 = -1;
  2823. }
  2824. //Set color for text
  2825. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  2826. // Grey scale
  2827. $this->TextColor = sprintf('%.3F g', $col1/255);
  2828. $this->fgcolor = array('G' => $col1);
  2829. } elseif ($col4 == -1) {
  2830. // RGB
  2831. $this->TextColor = sprintf('%.3F %.3F %.3F rg', $col1/255, $col2/255, $col3/255);
  2832. $this->fgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  2833. } else {
  2834. // CMYK
  2835. $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k', $col1/100, $col2/100, $col3/100, $col4/100);
  2836. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  2837. }
  2838. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2839. }
  2840. /**
  2841. * Defines the spot color used for text.
  2842. * @param string $name name of the spot color
  2843. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2844. * @access public
  2845. * @since 4.0.024 (2008-09-12)
  2846. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  2847. */
  2848. public function SetTextSpotColor($name, $tint=100) {
  2849. if (!isset($this->spot_colors[$name])) {
  2850. $this->Error('Undefined spot color: '.$name);
  2851. }
  2852. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint/100);
  2853. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2854. if ($this->page > 0) {
  2855. $this->_out($this->TextColor);
  2856. }
  2857. }
  2858. /**
  2859. * Returns the length of a string in user unit. A font must be selected.<br>
  2860. * @param string $s The string whose length is to be computed
  2861. * @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.
  2862. * @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.
  2863. * @param float $fontsize Font size in points. The default value is the current size.
  2864. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  2865. * @return mixed int total string length or array of characted widths
  2866. * @author Nicola Asuni
  2867. * @access public
  2868. * @since 1.2
  2869. */
  2870. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  2871. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  2872. }
  2873. /**
  2874. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  2875. * @param string $sa The array of chars whose total length is to be computed
  2876. * @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.
  2877. * @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.
  2878. * @param float $fontsize Font size in points. The default value is the current size.
  2879. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  2880. * @return mixed int total string length or array of characted widths
  2881. * @author Nicola Asuni
  2882. * @access public
  2883. * @since 2.4.000 (2008-03-06)
  2884. */
  2885. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  2886. // store current values
  2887. if (!$this->empty_string($fontname)) {
  2888. $prev_FontFamily = $this->FontFamily;
  2889. $prev_FontStyle = $this->FontStyle;
  2890. $prev_FontSizePt = $this->FontSizePt;
  2891. $this->SetFont($fontname, $fontstyle, $fontsize);
  2892. }
  2893. // convert UTF-8 array to Latin1 if required
  2894. $sa = $this->UTF8ArrToLatin1($sa);
  2895. $w = 0; // total width
  2896. $wa = array(); // array of characters widths
  2897. foreach ($sa as $char) {
  2898. // character width
  2899. $cw = $this->GetCharWidth($char);
  2900. $wa[] = $cw;
  2901. $w += $cw;
  2902. }
  2903. // restore previous values
  2904. if (!$this->empty_string($fontname)) {
  2905. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
  2906. }
  2907. if ($getarray) {
  2908. return $wa;
  2909. }
  2910. return $w;
  2911. }
  2912. /**
  2913. * Returns the length of the char in user unit for the current font.
  2914. * @param int $char The char code whose length is to be returned
  2915. * @return int char width
  2916. * @author Nicola Asuni
  2917. * @access public
  2918. * @since 2.4.000 (2008-03-06)
  2919. */
  2920. public function GetCharWidth($char) {
  2921. if ($char == 173) {
  2922. // SHY character will not be printed
  2923. return (0);
  2924. }
  2925. $cw = &$this->CurrentFont['cw'];
  2926. if (isset($cw[$char])) {
  2927. $w = $cw[$char];
  2928. } elseif (isset($this->CurrentFont['dw'])) {
  2929. // default width
  2930. $w = $this->CurrentFont['dw'];
  2931. } elseif (isset($cw[32])) {
  2932. // default width
  2933. $w = $cw[32];
  2934. } else {
  2935. $w = 600;
  2936. }
  2937. return ($w * $this->FontSize / 1000);
  2938. }
  2939. /**
  2940. * Returns the numbero of characters in a string.
  2941. * @param string $s The input string.
  2942. * @return int number of characters
  2943. * @access public
  2944. * @since 2.0.0001 (2008-01-07)
  2945. */
  2946. public function GetNumChars($s) {
  2947. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  2948. return count($this->UTF8StringToArray($s));
  2949. }
  2950. return strlen($s);
  2951. }
  2952. /**
  2953. * Fill the list of available fonts ($this->fontlist).
  2954. * @access protected
  2955. * @since 4.0.013 (2008-07-28)
  2956. */
  2957. protected function getFontsList() {
  2958. $fontsdir = opendir($this->_getfontpath());
  2959. while (($file = readdir($fontsdir)) !== false) {
  2960. if (substr($file, -4) == '.php') {
  2961. array_push($this->fontlist, strtolower(basename($file, '.php')));
  2962. }
  2963. }
  2964. closedir($fontsdir);
  2965. }
  2966. /**
  2967. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  2968. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  2969. * 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.
  2970. * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  2971. * @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>
  2972. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  2973. * @return array containing the font data, or false in case of error.
  2974. * @access public
  2975. * @since 1.5
  2976. * @see SetFont()
  2977. */
  2978. public function AddFont($family, $style='', $fontfile='') {
  2979. if ($this->empty_string($family)) {
  2980. if (!$this->empty_string($this->FontFamily)) {
  2981. $family = $this->FontFamily;
  2982. } else {
  2983. $this->Error('Empty font family');
  2984. }
  2985. }
  2986. $family = strtolower($family);
  2987. if ((!$this->isunicode) AND ($family == 'arial')) {
  2988. $family = 'helvetica';
  2989. }
  2990. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  2991. $style = '';
  2992. }
  2993. $tempstyle = strtoupper($style);
  2994. $style = '';
  2995. // underline
  2996. if (strpos($tempstyle, 'U') !== false) {
  2997. $this->underline = true;
  2998. } else {
  2999. $this->underline = false;
  3000. }
  3001. // line-through (deleted)
  3002. if (strpos($tempstyle, 'D') !== false) {
  3003. $this->linethrough = true;
  3004. } else {
  3005. $this->linethrough = false;
  3006. }
  3007. // overline
  3008. if (strpos($tempstyle, 'O') !== false) {
  3009. $this->overline = true;
  3010. } else {
  3011. $this->overline = false;
  3012. }
  3013. // bold
  3014. if (strpos($tempstyle, 'B') !== false) {
  3015. $style .= 'B';
  3016. }
  3017. // oblique
  3018. if (strpos($tempstyle, 'I') !== false) {
  3019. $style .= 'I';
  3020. }
  3021. $bistyle = $style;
  3022. $fontkey = $family.$style;
  3023. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  3024. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  3025. // check if the font has been already added
  3026. if ($this->getFontBuffer($fontkey) !== false) {
  3027. return $fontdata;
  3028. }
  3029. if (isset($type)) {
  3030. unset($type);
  3031. }
  3032. if (isset($cw)) {
  3033. unset($cw);
  3034. }
  3035. // get specified font directory (if any)
  3036. $fontdir = false;
  3037. if (!$this->empty_string($fontfile)) {
  3038. $fontdir = dirname($fontfile);
  3039. if ($this->empty_string($fontdir) OR ($fontdir == '.')) {
  3040. $fontdir = '';
  3041. } else {
  3042. $fontdir .= '/';
  3043. }
  3044. }
  3045. // search and include font file
  3046. if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
  3047. // build a standard filenames for specified font
  3048. $fontfile1 = str_replace(' ', '', $family).strtolower($style).'.php';
  3049. $fontfile2 = str_replace(' ', '', $family).'.php';
  3050. // search files on various directories
  3051. if (($fontdir !== false) AND file_exists($fontdir.$fontfile1)) {
  3052. $fontfile = $fontdir.$fontfile1;
  3053. } elseif (file_exists($this->_getfontpath().$fontfile1)) {
  3054. $fontfile = $this->_getfontpath().$fontfile1;
  3055. } elseif (file_exists($fontfile1)) {
  3056. $fontfile = $fontfile1;
  3057. } elseif (($fontdir !== false) AND file_exists($fontdir.$fontfile2)) {
  3058. $fontfile = $fontdir.$fontfile2;
  3059. } elseif (file_exists($this->_getfontpath().$fontfile2)) {
  3060. $fontfile = $this->_getfontpath().$fontfile2;
  3061. } else {
  3062. $fontfile = $fontfile2;
  3063. }
  3064. }
  3065. // include font file
  3066. if (file_exists($fontfile)) {
  3067. include($fontfile);
  3068. } else {
  3069. $this->Error('Could not include font definition file: '.$family.'');
  3070. }
  3071. // check font parameters
  3072. if ((!isset($type)) OR (!isset($cw))) {
  3073. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  3074. }
  3075. // SET default parameters
  3076. if (!isset($file) OR $this->empty_string($file)) {
  3077. $file = '';
  3078. }
  3079. if (!isset($enc) OR $this->empty_string($enc)) {
  3080. $enc = '';
  3081. }
  3082. if (!isset($cidinfo) OR $this->empty_string($cidinfo)) {
  3083. $cidinfo = array('Registry'=>'Adobe','Ordering'=>'Identity','Supplement'=>0);
  3084. $cidinfo['uni2cid'] = array();
  3085. }
  3086. if (!isset($ctg) OR $this->empty_string($ctg)) {
  3087. $ctg = '';
  3088. }
  3089. if (!isset($desc) OR $this->empty_string($desc)) {
  3090. $desc = array();
  3091. }
  3092. if (!isset($up) OR $this->empty_string($up)) {
  3093. $up = -100;
  3094. }
  3095. if (!isset($ut) OR $this->empty_string($ut)) {
  3096. $ut = 50;
  3097. }
  3098. if (!isset($cw) OR $this->empty_string($cw)) {
  3099. $cw = array();
  3100. }
  3101. if (!isset($dw) OR $this->empty_string($dw)) {
  3102. // set default width
  3103. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  3104. $dw = $desc['MissingWidth'];
  3105. } elseif (isset($cw[32])) {
  3106. $dw = $cw[32];
  3107. } else {
  3108. $dw = 600;
  3109. }
  3110. }
  3111. ++$this->numfonts;
  3112. if ($type == 'cidfont0') {
  3113. // register CID font (all styles at once)
  3114. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  3115. $sname = $name.$styles[$bistyle];
  3116. // artificial bold
  3117. if (strpos($bistyle, 'B') !== false) {
  3118. if (isset($desc['StemV'])) {
  3119. $desc['StemV'] *= 2;
  3120. } else {
  3121. $desc['StemV'] = 120;
  3122. }
  3123. }
  3124. // artificial italic
  3125. if (strpos($bistyle, 'I') !== false) {
  3126. if (isset($desc['ItalicAngle'])) {
  3127. $desc['ItalicAngle'] -= 11;
  3128. } else {
  3129. $desc['ItalicAngle'] = -11;
  3130. }
  3131. }
  3132. } elseif ($type == 'core') {
  3133. $name = $this->CoreFonts[$fontkey];
  3134. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  3135. // ...
  3136. } elseif ($type == 'TrueTypeUnicode') {
  3137. $enc = 'Identity-H';
  3138. } else {
  3139. $this->Error('Unknow font type: '.$type.'');
  3140. }
  3141. $this->setFontBuffer($fontkey, array('i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg));
  3142. if (isset($diff) AND (!empty($diff))) {
  3143. //Search existing encodings
  3144. $d = 0;
  3145. $nb = count($this->diffs);
  3146. for ($i=1; $i <= $nb; ++$i) {
  3147. if ($this->diffs[$i] == $diff) {
  3148. $d = $i;
  3149. break;
  3150. }
  3151. }
  3152. if ($d == 0) {
  3153. $d = $nb + 1;
  3154. $this->diffs[$d] = $diff;
  3155. }
  3156. $this->setFontSubBuffer($fontkey, 'diff', $d);
  3157. }
  3158. if (!$this->empty_string($file)) {
  3159. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  3160. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir);
  3161. } elseif ($type != 'core') {
  3162. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir);
  3163. }
  3164. }
  3165. return $fontdata;
  3166. }
  3167. /**
  3168. * Sets the font used to print character strings.
  3169. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  3170. * The method can be called before the first page is created and the font is retained from page to page.
  3171. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  3172. * 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 />
  3173. * @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.
  3174. * @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.
  3175. * @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
  3176. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3177. * @access public
  3178. * @since 1.0
  3179. * @see AddFont(), SetFontSize()
  3180. */
  3181. public function SetFont($family, $style='', $size=0, $fontfile='') {
  3182. //Select a font; size given in points
  3183. if ($size == 0) {
  3184. $size = $this->FontSizePt;
  3185. }
  3186. // try to add font (if not already added)
  3187. $fontdata = $this->AddFont($family, $style, $fontfile);
  3188. $this->FontFamily = $fontdata['family'];
  3189. $this->FontStyle = $fontdata['style'];
  3190. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  3191. $this->SetFontSize($size);
  3192. }
  3193. /**
  3194. * Defines the size of the current font.
  3195. * @param float $size The size (in points)
  3196. * @access public
  3197. * @since 1.0
  3198. * @see SetFont()
  3199. */
  3200. public function SetFontSize($size) {
  3201. //Set font size in points
  3202. $this->FontSizePt = $size;
  3203. $this->FontSize = $size / $this->k;
  3204. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  3205. $this->FontAscent = $this->CurrentFont['desc']['Ascent'] * $this->FontSize / 1000;
  3206. } else {
  3207. $this->FontAscent = 0.85 * $this->FontSize;
  3208. }
  3209. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  3210. $this->FontDescent = - $this->CurrentFont['desc']['Descent'] * $this->FontSize / 1000;
  3211. } else {
  3212. $this->FontDescent = 0.15 * $this->FontSize;
  3213. }
  3214. if (($this->page > 0) AND (isset($this->CurrentFont['i']))) {
  3215. $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  3216. }
  3217. }
  3218. /**
  3219. * Return the font descent value
  3220. * @param string $font font name
  3221. * @param string $style font style
  3222. * @param float $size The size (in points)
  3223. * @return int font descent
  3224. * @access public
  3225. * @since 4.9.003 (2010-03-30)
  3226. */
  3227. public function getFontDescent($font, $style='', $size=0) {
  3228. //Set font size in points
  3229. $sizek = $size / $this->k;
  3230. $fontdata = $this->AddFont($font, $style);
  3231. if (isset($fontdata['desc']['Descent']) AND ($fontdata['desc']['Descent'] <= 0)) {
  3232. $descent = - $fontdata['desc']['Descent'] * $sizek / 1000;
  3233. } else {
  3234. $descent = 0.15 * $sizek;
  3235. }
  3236. return $descent;
  3237. }
  3238. /**
  3239. * Return the font ascent value
  3240. * @param string $font font name
  3241. * @param string $style font style
  3242. * @param float $size The size (in points)
  3243. * @return int font ascent
  3244. * @access public
  3245. * @since 4.9.003 (2010-03-30)
  3246. */
  3247. public function getFontAscent($font, $style='', $size=0) {
  3248. //Set font size in points
  3249. $sizek = $size / $this->k;
  3250. $fontdata = $this->AddFont($font, $style);
  3251. if (isset($fontdata['desc']['Ascent']) AND ($fontdata['desc']['Ascent'] > 0)) {
  3252. $ascent = $fontdata['desc']['Ascent'] * $sizek / 1000;
  3253. } else {
  3254. $ascent = 0.85 * $sizek;
  3255. }
  3256. return $ascent;
  3257. }
  3258. /**
  3259. * Defines the default monospaced font.
  3260. * @param string $font Font name.
  3261. * @access public
  3262. * @since 4.5.025
  3263. */
  3264. public function SetDefaultMonospacedFont($font) {
  3265. $this->default_monospaced_font = $font;
  3266. }
  3267. /**
  3268. * 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 />
  3269. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  3270. * @access public
  3271. * @since 1.5
  3272. * @see Cell(), Write(), Image(), Link(), SetLink()
  3273. */
  3274. public function AddLink() {
  3275. //Create a new internal link
  3276. $n = count($this->links) + 1;
  3277. $this->links[$n] = array(0, 0);
  3278. return $n;
  3279. }
  3280. /**
  3281. * Defines the page and position a link points to.
  3282. * @param int $link The link identifier returned by AddLink()
  3283. * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  3284. * @param int $page Number of target page; -1 indicates the current page. This is the default value
  3285. * @access public
  3286. * @since 1.5
  3287. * @see AddLink()
  3288. */
  3289. public function SetLink($link, $y=0, $page=-1) {
  3290. if ($y == -1) {
  3291. $y = $this->y;
  3292. }
  3293. if ($page == -1) {
  3294. $page = $this->page;
  3295. }
  3296. $this->links[$link] = array($page, $y);
  3297. }
  3298. /**
  3299. * Puts a link on a rectangular area of the page.
  3300. * 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.
  3301. * @param float $x Abscissa of the upper-left corner of the rectangle
  3302. * @param float $y Ordinate of the upper-left corner of the rectangle
  3303. * @param float $w Width of the rectangle
  3304. * @param float $h Height of the rectangle
  3305. * @param mixed $link URL or identifier returned by AddLink()
  3306. * @param int $spaces number of spaces on the text to link
  3307. * @access public
  3308. * @since 1.5
  3309. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  3310. */
  3311. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  3312. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  3313. }
  3314. /**
  3315. * Puts a markup annotation on a rectangular area of the page.
  3316. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  3317. * @param float $x Abscissa of the upper-left corner of the rectangle
  3318. * @param float $y Ordinate of the upper-left corner of the rectangle
  3319. * @param float $w Width of the rectangle
  3320. * @param float $h Height of the rectangle
  3321. * @param string $text annotation text or alternate content
  3322. * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  3323. * @param int $spaces number of spaces on the text to link
  3324. * @access public
  3325. * @since 4.0.018 (2008-08-06)
  3326. */
  3327. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  3328. if ($x === '') {
  3329. $x = $this->x;
  3330. }
  3331. if ($y === '') {
  3332. $y = $this->y;
  3333. }
  3334. // recalculate coordinates to account for graphic transformations
  3335. if (isset($this->transfmatrix)) {
  3336. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  3337. $maxid = count($this->transfmatrix[$i]) - 1;
  3338. for ($j=$maxid; $j >= 0; --$j) {
  3339. $ctm = $this->transfmatrix[$i][$j];
  3340. if (isset($ctm['a'])) {
  3341. $x = $x * $this->k;
  3342. $y = ($this->h - $y) * $this->k;
  3343. $w = $w * $this->k;
  3344. $h = $h * $this->k;
  3345. // top left
  3346. $xt = $x;
  3347. $yt = $y;
  3348. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3349. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3350. // top right
  3351. $xt = $x + $w;
  3352. $yt = $y;
  3353. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3354. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3355. // bottom left
  3356. $xt = $x;
  3357. $yt = $y - $h;
  3358. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3359. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3360. // bottom right
  3361. $xt = $x + $w;
  3362. $yt = $y - $h;
  3363. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3364. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3365. // new coordinates (rectangle area)
  3366. $x = min($x1, $x2, $x3, $x4);
  3367. $y = max($y1, $y2, $y3, $y4);
  3368. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  3369. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  3370. $x = $x / $this->k;
  3371. $y = $this->h - ($y / $this->k);
  3372. }
  3373. }
  3374. }
  3375. }
  3376. if ($this->page <= 0) {
  3377. $page = 1;
  3378. } else {
  3379. $page = $this->page;
  3380. }
  3381. if (!isset($this->PageAnnots[$page])) {
  3382. $this->PageAnnots[$page] = array();
  3383. }
  3384. $this->PageAnnots[$page][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  3385. 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'])]))) {
  3386. $this->embeddedfiles[basename($opt['FS'])] = array('file' => $opt['FS'], 'n' => (count($this->embeddedfiles) + $this->embedded_start_obj_id));
  3387. }
  3388. // Add widgets annotation's icons
  3389. if (isset($opt['mk']['i']) AND file_exists($opt['mk']['i'])) {
  3390. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  3391. }
  3392. if (isset($opt['mk']['ri']) AND file_exists($opt['mk']['ri'])) {
  3393. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  3394. }
  3395. if (isset($opt['mk']['ix']) AND file_exists($opt['mk']['ix'])) {
  3396. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  3397. }
  3398. ++$this->annot_obj_id;
  3399. }
  3400. /**
  3401. * Embedd the attached files.
  3402. * @since 4.4.000 (2008-12-07)
  3403. * @access protected
  3404. * @see Annotation()
  3405. */
  3406. protected function _putEmbeddedFiles() {
  3407. reset($this->embeddedfiles);
  3408. foreach ($this->embeddedfiles as $filename => $filedata) {
  3409. $data = file_get_contents($filedata['file']);
  3410. $filter = '';
  3411. if ($this->compress) {
  3412. $data = gzcompress($data);
  3413. $filter = ' /Filter /FlateDecode';
  3414. }
  3415. $this->offsets[$filedata['n']] = $this->bufferlen;
  3416. $this->_out($filedata['n'].' 0 obj');
  3417. $this->_out('<</Type /EmbeddedFile'.$filter.' /Length '.strlen($data).' >>');
  3418. $this->_putstream($data, $filedata['n']);
  3419. $this->_out('endobj');
  3420. }
  3421. }
  3422. /**
  3423. * Prints a text cell at the specified position.
  3424. * The origin is on the left of the first charcter, on the baseline.
  3425. * This method allows to place a string precisely on the page.
  3426. * @param float $x Abscissa of the cell origin
  3427. * @param float $y Ordinate of the cell origin
  3428. * @param string $txt String to print
  3429. * @param int $fstroke outline size in user units (false = disable)
  3430. * @param boolean $fclip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  3431. * @param boolean $ffill if true fills the text
  3432. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3433. * @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.
  3434. * @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>
  3435. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3436. * @param mixed $link URL or identifier returned by AddLink().
  3437. * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3438. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3439. * @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>
  3440. * @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>
  3441. * @access public
  3442. * @since 1.0
  3443. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  3444. */
  3445. public function Text($x, $y, $txt, $fstroke=false, $fclip=false, $ffill=true, $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
  3446. $textrendermode = $this->textrendermode;
  3447. $textstrokewidth = $this->textstrokewidth;
  3448. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  3449. $this->SetXY($x, $y);
  3450. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  3451. // restore previous rendering mode
  3452. $this->textrendermode = $textrendermode;
  3453. $this->textstrokewidth = $textstrokewidth;
  3454. }
  3455. /**
  3456. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  3457. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  3458. * This method is called automatically and should not be called directly by the application.
  3459. * @return boolean
  3460. * @access public
  3461. * @since 1.4
  3462. * @see SetAutoPageBreak()
  3463. */
  3464. public function AcceptPageBreak() {
  3465. if ($this->num_columns > 1) {
  3466. // multi column mode
  3467. if($this->current_column < ($this->num_columns - 1)) {
  3468. // go to next column
  3469. $this->selectColumn($this->current_column + 1);
  3470. } else {
  3471. // add a new page
  3472. $this->AddPage();
  3473. // set first column
  3474. $this->selectColumn(0);
  3475. }
  3476. // avoid page breaking from checkPageBreak()
  3477. return false;
  3478. }
  3479. return $this->AutoPageBreak;
  3480. }
  3481. /**
  3482. * Add page if needed.
  3483. * @param float $h Cell height. Default value: 0.
  3484. * @param mixed $y starting y position, leave empty for current position.
  3485. * @param boolean $addpage if true add a page, otherwise only return the true/false state
  3486. * @return boolean true in case of page break, false otherwise.
  3487. * @since 3.2.000 (2008-07-01)
  3488. * @access protected
  3489. */
  3490. protected function checkPageBreak($h=0, $y='', $addpage=true) {
  3491. if ($this->empty_string($y)) {
  3492. $y = $this->y;
  3493. }
  3494. if ((($y + $h) > $this->PageBreakTrigger) AND (!$this->InFooter) AND ($this->AcceptPageBreak())) {
  3495. if ($addpage) {
  3496. //Automatic page break
  3497. $x = $this->x;
  3498. $this->AddPage($this->CurOrientation);
  3499. $this->y = $this->tMargin;
  3500. $oldpage = $this->page - 1;
  3501. if ($this->rtl) {
  3502. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  3503. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  3504. } else {
  3505. $this->x = $x;
  3506. }
  3507. } else {
  3508. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  3509. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  3510. } else {
  3511. $this->x = $x;
  3512. }
  3513. }
  3514. }
  3515. return true;
  3516. }
  3517. return false;
  3518. }
  3519. /**
  3520. * 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 />
  3521. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3522. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3523. * @param float $h Cell height. Default value: 0.
  3524. * @param string $txt String to print. Default value: empty string.
  3525. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3526. * @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>
  3527. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3528. * @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>
  3529. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3530. * @param mixed $link URL or identifier returned by AddLink().
  3531. * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3532. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3533. * @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>
  3534. * @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>
  3535. * @access public
  3536. * @since 1.0
  3537. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  3538. */
  3539. public function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
  3540. if (!$ignore_min_height) {
  3541. $min_cell_height = $this->FontSize * $this->cell_height_ratio;
  3542. if ($h < $min_cell_height) {
  3543. $h = $min_cell_height;
  3544. }
  3545. }
  3546. $this->checkPageBreak($h);
  3547. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign));
  3548. }
  3549. /**
  3550. * Removes SHY characters from text.
  3551. * @param string $txt input string
  3552. * @return string without SHY characters.
  3553. * @access public
  3554. * @since (4.5.019) 2009-02-28
  3555. */
  3556. public function removeSHY($txt='') {
  3557. /*
  3558. * Unicode Data
  3559. * Name : SOFT HYPHEN, commonly abbreviated as SHY
  3560. * HTML Entity (decimal): &#173;
  3561. * HTML Entity (hex): &#xad;
  3562. * HTML Entity (named): &shy;
  3563. * How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]
  3564. * UTF-8 (hex): 0xC2 0xAD (c2ad)
  3565. * UTF-8 character: chr(194).chr(173)
  3566. */
  3567. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  3568. if (!$this->isunicode) {
  3569. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  3570. }
  3571. return $txt;
  3572. }
  3573. /**
  3574. * 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 />
  3575. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3576. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3577. * @param float $h Cell height. Default value: 0.
  3578. * @param string $txt String to print. Default value: empty string.
  3579. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3580. * @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.
  3581. * @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>
  3582. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3583. * @param mixed $link URL or identifier returned by AddLink().
  3584. * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3585. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3586. * @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>
  3587. * @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>
  3588. * @access protected
  3589. * @since 1.0
  3590. * @see Cell()
  3591. */
  3592. protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
  3593. $txt = $this->removeSHY($txt);
  3594. $rs = ''; //string to be returned
  3595. if (!$ignore_min_height) {
  3596. $min_cell_height = $this->FontSize * $this->cell_height_ratio;
  3597. if ($h < $min_cell_height) {
  3598. $h = $min_cell_height;
  3599. }
  3600. }
  3601. $k = $this->k;
  3602. $x = $this->x;
  3603. $y = $this->y;
  3604. // cell vertical alignment
  3605. switch ($calign) {
  3606. case 'A': {
  3607. // font top
  3608. switch ($valign) {
  3609. case 'T': {
  3610. // top
  3611. $y -= ($this->LineWidth / 2);
  3612. break;
  3613. }
  3614. case 'B': {
  3615. // bottom
  3616. $y -= ($h - $this->FontAscent - $this->FontDescent - ($this->LineWidth / 2));
  3617. break;
  3618. }
  3619. default:
  3620. case 'M': {
  3621. // center
  3622. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  3623. break;
  3624. }
  3625. }
  3626. break;
  3627. }
  3628. case 'L': {
  3629. // font baseline
  3630. switch ($valign) {
  3631. case 'T': {
  3632. // top
  3633. $y -= ($this->FontAscent + ($this->LineWidth / 2));
  3634. break;
  3635. }
  3636. case 'B': {
  3637. // bottom
  3638. $y -= ($h - $this->FontDescent - ($this->LineWidth / 2));
  3639. break;
  3640. }
  3641. default:
  3642. case 'M': {
  3643. // center
  3644. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  3645. break;
  3646. }
  3647. }
  3648. break;
  3649. }
  3650. case 'D': {
  3651. // font bottom
  3652. switch ($valign) {
  3653. case 'T': {
  3654. // top
  3655. $y -= ($this->FontAscent + $this->FontDescent + ($this->LineWidth / 2));
  3656. break;
  3657. }
  3658. case 'B': {
  3659. // bottom
  3660. $y -= ($h - ($this->LineWidth / 2));
  3661. break;
  3662. }
  3663. default:
  3664. case 'M': {
  3665. // center
  3666. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  3667. break;
  3668. }
  3669. }
  3670. break;
  3671. }
  3672. case 'B': {
  3673. // cell bottom
  3674. $y -= $h;
  3675. break;
  3676. }
  3677. case 'C': {
  3678. // cell center
  3679. $y -= ($h / 2);
  3680. break;
  3681. }
  3682. default:
  3683. case 'T': {
  3684. // cell top
  3685. break;
  3686. }
  3687. }
  3688. // text vertical alignment
  3689. switch ($valign) {
  3690. case 'T': {
  3691. // top
  3692. $basefonty = $y + $this->FontAscent + ($this->LineWidth / 2);
  3693. break;
  3694. }
  3695. case 'B': {
  3696. // bottom
  3697. $basefonty = $y + $h - $this->FontDescent - ($this->LineWidth / 2);
  3698. break;
  3699. }
  3700. default:
  3701. case 'M': {
  3702. // center
  3703. $basefonty = $y + (($h + $this->FontAscent - $this->FontDescent) / 2);
  3704. break;
  3705. }
  3706. }
  3707. if ($this->empty_string($w) OR ($w <= 0)) {
  3708. if ($this->rtl) {
  3709. $w = $x - $this->lMargin;
  3710. } else {
  3711. $w = $this->w - $this->rMargin - $x;
  3712. }
  3713. }
  3714. $s = '';
  3715. // fill and borders
  3716. if (($fill == 1) OR ($border == 1)) {
  3717. if ($fill == 1) {
  3718. $op = ($border == 1) ? 'B' : 'f';
  3719. } else {
  3720. $op = 'S';
  3721. }
  3722. if ($this->rtl) {
  3723. $xk = (($this->x - $w) * $k);
  3724. } else {
  3725. $xk = ($this->x * $k);
  3726. }
  3727. $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  3728. }
  3729. if (is_string($border)) {
  3730. $lm = ($this->LineWidth / 2);
  3731. if (strpos($border,'L') !== false) {
  3732. if ($this->rtl) {
  3733. $xk = ($x - $w) * $k;
  3734. } else {
  3735. $xk = $x * $k;
  3736. }
  3737. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - $y + $lm) * $k), $xk, (($this->h - ($y + $h + $lm)) * $k));
  3738. }
  3739. if (strpos($border,'T') !== false) {
  3740. if ($this->rtl) {
  3741. $xk = ($x - $w + $lm) * $k;
  3742. $xwk = ($x - $lm) * $k;
  3743. } else {
  3744. $xk = ($x - $lm) * $k;
  3745. $xwk = ($x + $w + $lm) * $k;
  3746. }
  3747. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - $y) * $k), $xwk, (($this->h - $y) * $k));
  3748. }
  3749. if (strpos($border,'R') !== false) {
  3750. if ($this->rtl) {
  3751. $xk = $x * $k;
  3752. } else {
  3753. $xk = ($x + $w) * $k;
  3754. }
  3755. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - $y + $lm) * $k), $xk, (($this->h - ($y + $h + $lm))* $k));
  3756. }
  3757. if (strpos($border,'B') !== false) {
  3758. if ($this->rtl) {
  3759. $xk = ($x - $w + $lm) * $k;
  3760. $xwk = ($x - $lm) * $k;
  3761. } else {
  3762. $xk = ($x - $lm) * $k;
  3763. $xwk = ($x + $w + $lm) * $k;
  3764. }
  3765. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - ($y + $h)) * $k), $xwk, (($this->h - ($y + $h)) * $k));
  3766. }
  3767. }
  3768. if ($txt != '') {
  3769. $txt2 = $txt;
  3770. if ($this->isunicode) {
  3771. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  3772. $txt2 = $this->UTF8ToLatin1($txt2);
  3773. } else {
  3774. $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
  3775. $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
  3776. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  3777. // ---- Fix for bug #2977340 "Incorrect Thai characters position arrangement" ----
  3778. // NOTE: this doesn't work with HTML justification
  3779. // Symbols that could overlap on the font top (only works in LTR)
  3780. $topchar = array(3611, 3613, 3615, 3650, 3651, 3652); // chars that extends on top
  3781. $topsym = array(3633, 3636, 3637, 3638, 3639, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662); // symbols with top position
  3782. $numchars = count($unicode); // number of chars
  3783. $unik = 0;
  3784. $uniblock = array();
  3785. $uniblock[$unik] = array();
  3786. $uniblock[$unik][] = $unicode[0];
  3787. // resolve overlapping conflicts by splitting the string in several parts
  3788. for ($i = 1; $i < $numchars; ++$i) {
  3789. // check if symbols overlaps at top
  3790. if (in_array($unicode[$i], $topsym) AND (in_array($unicode[($i - 1)], $topsym) OR in_array($unicode[($i - 1)], $topchar))) {
  3791. // move symbols to another array
  3792. ++$unik;
  3793. $uniblock[$unik] = array();
  3794. $uniblock[$unik][] = $unicode[$i];
  3795. ++$unik;
  3796. $uniblock[$unik] = array();
  3797. $unicode[$i] = 8203; // Unicode Character 'ZERO WIDTH SPACE' (U+200B)
  3798. } else {
  3799. $uniblock[$unik][] = $unicode[$i];
  3800. }
  3801. }
  3802. // ---- END OF Fix for bug #2977340
  3803. }
  3804. $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
  3805. }
  3806. }
  3807. $txt2 = $this->_escape($txt2);
  3808. // text length
  3809. $txwidth = $this->GetStringWidth($txt);
  3810. $width = $txwidth;
  3811. // ratio between cell length and text length
  3812. if ($width <= 0) {
  3813. $ratio = 1;
  3814. } else {
  3815. $ratio = ($w - (2 * $this->cMargin)) / $width;
  3816. }
  3817. // stretch text if required
  3818. if (($stretch > 0) AND (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0)))) {
  3819. if ($stretch > 2) {
  3820. // spacing
  3821. //Calculate character spacing in points
  3822. $char_space = (($w - $width - (2 * $this->cMargin)) * $this->k) / max($this->GetNumChars($txt)-1,1);
  3823. //Set character spacing
  3824. $rs .= sprintf('BT %.2F Tc ET ', $char_space);
  3825. } else {
  3826. // scaling
  3827. //Calculate horizontal scaling
  3828. $horiz_scale = $ratio * 100.0;
  3829. //Set horizontal scaling
  3830. $rs .= sprintf('BT %.2F Tz ET ', $horiz_scale);
  3831. }
  3832. $align = '';
  3833. $width = $w - (2 * $this->cMargin);
  3834. } else {
  3835. $stretch == 0;
  3836. }
  3837. if ($this->ColorFlag) {
  3838. $s .= 'q '.$this->TextColor.' ';
  3839. }
  3840. // rendering mode
  3841. $s .= sprintf('BT %d Tr %.2F w ET ', $this->textrendermode, $this->textstrokewidth);
  3842. // count number of spaces
  3843. $ns = substr_count($txt, ' ');
  3844. // Justification
  3845. $spacewidth = 0;
  3846. if (($align == 'J') AND ($ns > 0)) {
  3847. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  3848. // get string width without spaces
  3849. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  3850. // calculate average space width
  3851. $spacewidth = -1000 * ($w - $width - (2 * $this->cMargin)) / ($ns?$ns:1) / $this->FontSize;
  3852. // set word position to be used with TJ operator
  3853. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%.3F', $spacewidth).' (', $txt2);
  3854. $unicode_justification = true;
  3855. } else {
  3856. // get string width
  3857. $width = $txwidth;
  3858. $spacewidth = (($w - $width - (2 * $this->cMargin)) / ($ns?$ns:1)) * $this->k;
  3859. // set word spacing
  3860. $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
  3861. }
  3862. $width = $w - (2 * $this->cMargin);
  3863. }
  3864. // replace carriage return characters
  3865. $txt2 = str_replace("\r", ' ', $txt2);
  3866. switch ($align) {
  3867. case 'C': {
  3868. $dx = ($w - $width) / 2;
  3869. break;
  3870. }
  3871. case 'R': {
  3872. if ($this->rtl) {
  3873. $dx = $this->cMargin;
  3874. } else {
  3875. $dx = $w - $width - $this->cMargin;
  3876. }
  3877. break;
  3878. }
  3879. case 'L': {
  3880. if ($this->rtl) {
  3881. $dx = $w - $width - $this->cMargin;
  3882. } else {
  3883. $dx = $this->cMargin;
  3884. }
  3885. break;
  3886. }
  3887. case 'J':
  3888. default: {
  3889. $dx = $this->cMargin;
  3890. break;
  3891. }
  3892. }
  3893. if ($this->rtl) {
  3894. $xdx = $this->x - $dx - $width;
  3895. } else {
  3896. $xdx = $this->x + $dx;
  3897. }
  3898. $xdk = $xdx * $k;
  3899. // print text
  3900. $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  3901. if (isset($uniblock)) {
  3902. // print overlapping characters as separate string
  3903. $xshift = 0; // horizontal shift
  3904. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  3905. $spw = (($w - $txwidth - (2 * $this->cMargin)) / ($ns?$ns:1));
  3906. foreach ($uniblock as $uk => $uniarr) {
  3907. if (($uk % 2) == 0) {
  3908. // x space to skip
  3909. if ($spacewidth != 0) {
  3910. // justification shift
  3911. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  3912. }
  3913. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  3914. } else {
  3915. // character to print
  3916. $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
  3917. $topchr = $this->_escape($topchr);
  3918. $s .= sprintf(' BT %.2F %.2F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  3919. }
  3920. }
  3921. }
  3922. if ($this->underline) {
  3923. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  3924. }
  3925. if ($this->linethrough) {
  3926. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  3927. }
  3928. if ($this->overline) {
  3929. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  3930. }
  3931. if ($this->ColorFlag) {
  3932. $s .= ' Q';
  3933. }
  3934. if ($link) {
  3935. $this->Link($xdx, $y + (($h - $this->FontSize)/2), $width, $this->FontSize, $link, $ns);
  3936. }
  3937. }
  3938. // output cell
  3939. if ($s) {
  3940. // output cell
  3941. $rs .= $s;
  3942. // reset text stretching
  3943. if ($stretch > 2) {
  3944. //Reset character horizontal spacing
  3945. $rs .= ' BT 0 Tc ET';
  3946. } elseif ($stretch > 0) {
  3947. //Reset character horizontal scaling
  3948. $rs .= ' BT 100 Tz ET';
  3949. }
  3950. }
  3951. // reset word spacing
  3952. if (!(($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) AND ($align == 'J')) {
  3953. $rs .= ' BT 0 Tw ET';
  3954. }
  3955. $this->lasth = $h;
  3956. if ($ln > 0) {
  3957. //Go to the beginning of the next line
  3958. $this->y = $y + $h;
  3959. if ($ln == 1) {
  3960. if ($this->rtl) {
  3961. $this->x = $this->w - $this->rMargin;
  3962. } else {
  3963. $this->x = $this->lMargin;
  3964. }
  3965. }
  3966. } else {
  3967. // go left or right by case
  3968. if ($this->rtl) {
  3969. $this->x -= $w;
  3970. } else {
  3971. $this->x += $w;
  3972. }
  3973. }
  3974. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  3975. $rs = $gstyles.$rs;
  3976. return $rs;
  3977. }
  3978. /**
  3979. * This method allows printing text with line breaks.
  3980. * 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 />
  3981. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  3982. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  3983. * @param float $h Cell minimum height. The cell extends automatically if needed.
  3984. * @param string $txt String to print
  3985. * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3986. * @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>
  3987. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3988. * @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>
  3989. * @param float $x x position in user units
  3990. * @param float $y y position in user units
  3991. * @param boolean $reseth if true reset the last cell height (default true).
  3992. * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3993. * @param boolean $ishtml set to true if $txt is HTML content (default = false).
  3994. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  3995. * @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.
  3996. * @return int Return the number of cells or 1 for html mode.
  3997. * @access public
  3998. * @since 1.3
  3999. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  4000. */
  4001. public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0) {
  4002. if ($this->empty_string($this->lasth) OR $reseth) {
  4003. //set row height
  4004. $this->lasth = $this->FontSize * $this->cell_height_ratio;
  4005. }
  4006. if (!$this->empty_string($y)) {
  4007. $this->SetY($y);
  4008. } else {
  4009. $y = $this->GetY();
  4010. }
  4011. // check for page break
  4012. $this->checkPageBreak($h);
  4013. $y = $this->GetY();
  4014. // get current page number
  4015. $startpage = $this->page;
  4016. if (!$this->empty_string($x)) {
  4017. $this->SetX($x);
  4018. } else {
  4019. $x = $this->GetX();
  4020. }
  4021. if ($this->empty_string($w) OR ($w <= 0)) {
  4022. if ($this->rtl) {
  4023. $w = $this->x - $this->lMargin;
  4024. } else {
  4025. $w = $this->w - $this->rMargin - $this->x;
  4026. }
  4027. }
  4028. // store original margin values
  4029. $lMargin = $this->lMargin;
  4030. $rMargin = $this->rMargin;
  4031. if ($this->rtl) {
  4032. $this->SetRightMargin($this->w - $this->x);
  4033. $this->SetLeftMargin($this->x - $w);
  4034. } else {
  4035. $this->SetLeftMargin($this->x);
  4036. $this->SetRightMargin($this->w - $this->x - $w);
  4037. }
  4038. $starty = $this->y;
  4039. if ($autopadding) {
  4040. // Adjust internal padding
  4041. if ($this->cMargin < ($this->LineWidth / 2)) {
  4042. $this->cMargin = ($this->LineWidth / 2);
  4043. }
  4044. // Add top space if needed
  4045. if (($this->lasth - $this->FontSize) < $this->LineWidth) {
  4046. $this->y += $this->LineWidth / 2;
  4047. }
  4048. // add top padding
  4049. $this->y += $this->cMargin;
  4050. }
  4051. if ($ishtml) {
  4052. // ******* Write HTML text
  4053. $this->writeHTML($txt, true, 0, $reseth, true, $align);
  4054. $nl = 1;
  4055. } else {
  4056. // ******* Write text
  4057. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh);
  4058. }
  4059. if ($autopadding) {
  4060. // add bottom padding
  4061. $this->y += $this->cMargin;
  4062. // Add bottom space if needed
  4063. if (($this->lasth - $this->FontSize) < $this->LineWidth) {
  4064. $this->y += $this->LineWidth / 2;
  4065. }
  4066. }
  4067. // Get end-of-text Y position
  4068. $currentY = $this->y;
  4069. // get latest page number
  4070. $endpage = $this->page;
  4071. // check if a new page has been created
  4072. if ($endpage > $startpage) {
  4073. // design borders around HTML cells.
  4074. for ($page=$startpage; $page <= $endpage; ++$page) {
  4075. $this->setPage($page);
  4076. if ($page == $startpage) {
  4077. $this->y = $starty; // put cursor at the beginning of cell on the first page
  4078. $h = $this->getPageHeight() - $starty - $this->getBreakMargin();
  4079. $cborder = $this->getBorderMode($border, $position='start');
  4080. } elseif ($page == $endpage) {
  4081. $this->y = $this->tMargin; // put cursor at the beginning of last page
  4082. $h = $currentY - $this->tMargin;
  4083. $cborder = $this->getBorderMode($border, $position='end');
  4084. } else {
  4085. $this->y = $this->tMargin; // put cursor at the beginning of the current page
  4086. $h = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin();
  4087. $cborder = $this->getBorderMode($border, $position='middle');
  4088. }
  4089. $nx = $x;
  4090. // account for margin changes
  4091. if ($page > $startpage) {
  4092. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  4093. $nx = $x + ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  4094. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  4095. $nx = $x + ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  4096. }
  4097. }
  4098. $this->SetX($nx);
  4099. $ccode = $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, false);
  4100. if ($cborder OR $fill) {
  4101. $pagebuff = $this->getPageBuffer($this->page);
  4102. $pstart = substr($pagebuff, 0, $this->intmrk[$this->page]);
  4103. $pend = substr($pagebuff, $this->intmrk[$this->page]);
  4104. $this->setPageBuffer($this->page, $pstart.$ccode."\n".$pend);
  4105. $this->intmrk[$this->page] += strlen($ccode."\n");
  4106. }
  4107. }
  4108. } else {
  4109. $h = max($h, ($currentY - $y));
  4110. // put cursor at the beginning of text
  4111. $this->SetY($y);
  4112. $this->SetX($x);
  4113. // design a cell around the text
  4114. $ccode = $this->getCellCode($w, $h, '', $border, 1, '', $fill, '', 0, true);
  4115. if ($border OR $fill) {
  4116. if (end($this->transfmrk[$this->page]) !== false) {
  4117. $pagemarkkey = key($this->transfmrk[$this->page]);
  4118. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  4119. } elseif ($this->InFooter) {
  4120. $pagemark = &$this->footerpos[$this->page];
  4121. } else {
  4122. $pagemark = &$this->intmrk[$this->page];
  4123. }
  4124. $pagebuff = $this->getPageBuffer($this->page);
  4125. $pstart = substr($pagebuff, 0, $pagemark);
  4126. $pend = substr($pagebuff, $pagemark);
  4127. $this->setPageBuffer($this->page, $pstart.$ccode."\n".$pend);
  4128. $pagemark += strlen($ccode."\n");
  4129. }
  4130. }
  4131. // Get end-of-cell Y position
  4132. $currentY = $this->GetY();
  4133. // restore original margin values
  4134. $this->SetLeftMargin($lMargin);
  4135. $this->SetRightMargin($rMargin);
  4136. if ($ln > 0) {
  4137. //Go to the beginning of the next line
  4138. $this->SetY($currentY);
  4139. if ($ln == 2) {
  4140. $this->SetX($x + $w);
  4141. }
  4142. } else {
  4143. // go left or right by case
  4144. $this->setPage($startpage);
  4145. $this->y = $y;
  4146. $this->SetX($x + $w);
  4147. }
  4148. $this->setContentMark();
  4149. return $nl;
  4150. }
  4151. /**
  4152. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  4153. * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  4154. * @param string multicell position: 'start', 'middle', 'end'
  4155. * @return border mode
  4156. * @access protected
  4157. * @since 4.4.002 (2008-12-09)
  4158. */
  4159. protected function getBorderMode($border, $position='start') {
  4160. if ((!$this->opencell) AND ($border == 1)) {
  4161. return 1;
  4162. }
  4163. $cborder = '';
  4164. switch ($position) {
  4165. case 'start': {
  4166. if ($border == 1) {
  4167. $cborder = 'LTR';
  4168. } else {
  4169. if (!(false === strpos($border, 'L'))) {
  4170. $cborder .= 'L';
  4171. }
  4172. if (!(false === strpos($border, 'T'))) {
  4173. $cborder .= 'T';
  4174. }
  4175. if (!(false === strpos($border, 'R'))) {
  4176. $cborder .= 'R';
  4177. }
  4178. if ((!$this->opencell) AND (!(false === strpos($border, 'B')))) {
  4179. $cborder .= 'B';
  4180. }
  4181. }
  4182. break;
  4183. }
  4184. case 'middle': {
  4185. if ($border == 1) {
  4186. $cborder = 'LR';
  4187. } else {
  4188. if (!(false === strpos($border, 'L'))) {
  4189. $cborder .= 'L';
  4190. }
  4191. if ((!$this->opencell) AND (!(false === strpos($border, 'T')))) {
  4192. $cborder .= 'T';
  4193. }
  4194. if (!(false === strpos($border, 'R'))) {
  4195. $cborder .= 'R';
  4196. }
  4197. if ((!$this->opencell) AND (!(false === strpos($border, 'B')))) {
  4198. $cborder .= 'B';
  4199. }
  4200. }
  4201. break;
  4202. }
  4203. case 'end': {
  4204. if ($border == 1) {
  4205. $cborder = 'LRB';
  4206. } else {
  4207. if (!(false === strpos($border, 'L'))) {
  4208. $cborder .= 'L';
  4209. }
  4210. if ((!$this->opencell) AND (!(false === strpos($border, 'T')))) {
  4211. $cborder .= 'T';
  4212. }
  4213. if (!(false === strpos($border, 'R'))) {
  4214. $cborder .= 'R';
  4215. }
  4216. if (!(false === strpos($border, 'B'))) {
  4217. $cborder .= 'B';
  4218. }
  4219. }
  4220. break;
  4221. }
  4222. default: {
  4223. $cborder = $border;
  4224. break;
  4225. }
  4226. }
  4227. return $cborder;
  4228. }
  4229. /**
  4230. * This method returns the estimated number of lines required to print the text (not the real number just a quick estimation).
  4231. * If you want o know the exact number of lines you have to use the following technique:
  4232. * <pre>
  4233. * // store current object
  4234. * $pdf->startTransaction();
  4235. * // get the number of lines for multicell
  4236. * $lines = $pdf->MultiCell($w, 0, $txt, 0, 'L', 0, 0, '', '', true, 0, false, true, 0);
  4237. * // restore previous object
  4238. * $pdf = $pdf->rollbackTransaction();
  4239. * </pre>
  4240. * @param string $txt text to print
  4241. * @param float $w width of cell. If 0, they extend up to the right margin of the page.
  4242. * @return int Return the estimated number of lines.
  4243. * @access public
  4244. * @since 4.5.011
  4245. */
  4246. public function getNumLines($txt, $w=0) {
  4247. $lines = 0;
  4248. if ($this->empty_string($w) OR ($w <= 0)) {
  4249. if ($this->rtl) {
  4250. $w = $this->x - $this->lMargin;
  4251. } else {
  4252. $w = $this->w - $this->rMargin - $this->x;
  4253. }
  4254. }
  4255. // max column width
  4256. $wmax = $w - (2 * $this->cMargin);
  4257. // remove carriage returns
  4258. $txt = str_replace("\r", '', $txt);
  4259. // remove last newline (if any)
  4260. if (substr($txt,-1) == "\n") {
  4261. $txt = substr($txt, 0, -1);
  4262. }
  4263. // divide text in blocks
  4264. $txtblocks = explode("\n", $txt);
  4265. // for each text block
  4266. foreach ($txtblocks as $block) {
  4267. // estimate the number of lines
  4268. $lines += $this->empty_string($block) ? 1 : (ceil($this->GetStringWidth($block) / $wmax));
  4269. }
  4270. // return the number of lines
  4271. return $lines;
  4272. }
  4273. /**
  4274. * This method prints text from the current position.<br />
  4275. * @param float $h Line height
  4276. * @param string $txt String to print
  4277. * @param mixed $link URL or identifier returned by AddLink()
  4278. * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  4279. * @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>
  4280. * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  4281. * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  4282. * @param boolean $firstline if true prints only the first line and return the remaining string.
  4283. * @param boolean $firstblock if true the string is the starting of a line.
  4284. * @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.
  4285. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  4286. * @access public
  4287. * @since 1.5
  4288. */
  4289. public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0) {
  4290. if (strlen($txt) == 0) {
  4291. $txt = ' ';
  4292. }
  4293. // remove carriage returns
  4294. $s = str_replace("\r", '', $txt);
  4295. // check if string contains arabic text
  4296. if (preg_match(K_RE_PATTERN_ARABIC, $s)) {
  4297. $arabic = true;
  4298. } else {
  4299. $arabic = false;
  4300. }
  4301. // check if string contains RTL text
  4302. if ($arabic OR ($this->tmprtl == 'R') OR preg_match(K_RE_PATTERN_RTL, $txt)) {
  4303. $rtlmode = true;
  4304. } else {
  4305. $rtlmode = false;
  4306. }
  4307. // get a char width
  4308. $chrwidth = $this->GetCharWidth('.');
  4309. // get array of unicode values
  4310. $chars = $this->UTF8StringToArray($s);
  4311. // get array of chars
  4312. $uchars = $this->UTF8ArrayToUniArray($chars);
  4313. // get the number of characters
  4314. $nb = count($chars);
  4315. // replacement for SHY character (minus symbol)
  4316. $shy_replacement = 45;
  4317. $shy_replacement_char = $this->unichr($shy_replacement);
  4318. // widht for SHY replacement
  4319. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  4320. // store current position
  4321. $prevx = $this->x;
  4322. $prevy = $this->y;
  4323. // max Y
  4324. $maxy = $this->y + $maxh - $h - (2 * $this->cMargin);
  4325. // calculate remaining line width ($w)
  4326. if ($this->rtl) {
  4327. $w = $this->x - $this->lMargin;
  4328. } else {
  4329. $w = $this->w - $this->rMargin - $this->x;
  4330. }
  4331. // max column width
  4332. $wmax = $w - (2 * $this->cMargin);
  4333. if ((!$firstline) AND (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax))) {
  4334. // a single character do not fit on column
  4335. return '';
  4336. }
  4337. $i = 0; // character position
  4338. $j = 0; // current starting position
  4339. $sep = -1; // position of the last blank space
  4340. $shy = false; // true if the last blank is a soft hypen (SHY)
  4341. $l = 0; // current string length
  4342. $nl = 0; //number of lines
  4343. $linebreak = false;
  4344. $pc = 0; // previous character
  4345. // for each character
  4346. while ($i < $nb) {
  4347. if (($maxh > 0) AND ($this->y >= $maxy) ) {
  4348. break;
  4349. }
  4350. //Get the current character
  4351. $c = $chars[$i];
  4352. if ($c == 10) { // 10 = "\n" = new line
  4353. //Explicit line break
  4354. if ($align == 'J') {
  4355. if ($this->rtl) {
  4356. $talign = 'R';
  4357. } else {
  4358. $talign = 'L';
  4359. }
  4360. } else {
  4361. $talign = $align;
  4362. }
  4363. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  4364. if ($firstline) {
  4365. $startx = $this->x;
  4366. $tmparr = array_slice($chars, $j, ($i - $j));
  4367. if ($rtlmode) {
  4368. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  4369. }
  4370. $linew = $this->GetArrStringWidth($tmparr);
  4371. unset($tmparr);
  4372. if ($this->rtl) {
  4373. $this->endlinex = $startx - $linew;
  4374. } else {
  4375. $this->endlinex = $startx + $linew;
  4376. }
  4377. $w = $linew;
  4378. $tmpcmargin = $this->cMargin;
  4379. if ($maxh == 0) {
  4380. $this->cMargin = 0;
  4381. }
  4382. }
  4383. if ($firstblock AND $this->isRTLTextDir()) {
  4384. $tmpstr = rtrim($tmpstr);
  4385. }
  4386. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  4387. unset($tmpstr);
  4388. if ($firstline) {
  4389. $this->cMargin = $tmpcmargin;
  4390. return ($this->UniArrSubString($uchars, $i));
  4391. }
  4392. ++$nl;
  4393. $j = $i + 1;
  4394. $l = 0;
  4395. $sep = -1;
  4396. $shy = false;
  4397. // account for margin changes
  4398. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
  4399. // AcceptPageBreak() may be overriden on extended classed to include margin changes
  4400. $this->AcceptPageBreak();
  4401. }
  4402. $w = $this->getRemainingWidth();
  4403. $wmax = $w - (2 * $this->cMargin);
  4404. } else {
  4405. // 160 is the non-breaking space.
  4406. // 173 is SHY (Soft Hypen).
  4407. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  4408. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  4409. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  4410. if (($c != 160) AND (($c == 173) OR preg_match($this->re_spaces, $this->unichr($c)))) {
  4411. // update last blank space position
  4412. $sep = $i;
  4413. // check if is a SHY
  4414. if ($c == 173) {
  4415. $shy = true;
  4416. if ($pc == 45) {
  4417. $tmp_shy_replacement_width = 0;
  4418. $tmp_shy_replacement_char = '';
  4419. } else {
  4420. $tmp_shy_replacement_width = $shy_replacement_width;
  4421. $tmp_shy_replacement_char = $shy_replacement_char;
  4422. }
  4423. } else {
  4424. $shy = false;
  4425. }
  4426. }
  4427. // update string length
  4428. if ((($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) AND ($arabic)) {
  4429. // with bidirectional algorithm some chars may be changed affecting the line length
  4430. // *** very slow ***
  4431. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  4432. } else {
  4433. $l += $this->GetCharWidth($c);
  4434. }
  4435. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) {
  4436. // we have reached the end of column
  4437. if ($sep == -1) {
  4438. // check if the line was already started
  4439. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
  4440. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $chrwidth)))) {
  4441. // print a void cell and go to next line
  4442. $this->Cell($w, $h, '', 0, 1);
  4443. $linebreak = true;
  4444. if ($firstline) {
  4445. return ($this->UniArrSubString($uchars, $j));
  4446. }
  4447. } else {
  4448. // truncate the word because do not fit on column
  4449. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  4450. if ($firstline) {
  4451. $startx = $this->x;
  4452. $tmparr = array_slice($chars, $j, ($i - $j));
  4453. if ($rtlmode) {
  4454. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  4455. }
  4456. $linew = $this->GetArrStringWidth($tmparr);
  4457. unset($tmparr);
  4458. if ($this->rtl) {
  4459. $this->endlinex = $startx - $linew;
  4460. } else {
  4461. $this->endlinex = $startx + $linew;
  4462. }
  4463. $w = $linew;
  4464. $tmpcmargin = $this->cMargin;
  4465. if ($maxh == 0) {
  4466. $this->cMargin = 0;
  4467. }
  4468. }
  4469. if ($firstblock AND $this->isRTLTextDir()) {
  4470. $tmpstr = rtrim($tmpstr);
  4471. }
  4472. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  4473. unset($tmpstr);
  4474. if ($firstline) {
  4475. $this->cMargin = $tmpcmargin;
  4476. return ($this->UniArrSubString($uchars, $i));
  4477. }
  4478. $j = $i;
  4479. --$i;
  4480. }
  4481. } else {
  4482. // word wrapping
  4483. if ($this->rtl AND (!$firstblock)) {
  4484. $endspace = 1;
  4485. } else {
  4486. $endspace = 0;
  4487. }
  4488. if ($shy) {
  4489. // add hypen (minus symbol) at the end of the line
  4490. $shy_width = $tmp_shy_replacement_width;
  4491. if ($this->rtl) {
  4492. $shy_char_left = $tmp_shy_replacement_char;
  4493. $shy_char_right = '';
  4494. } else {
  4495. $shy_char_left = '';
  4496. $shy_char_right = $tmp_shy_replacement_char;
  4497. }
  4498. } else {
  4499. $shy_width = 0;
  4500. $shy_char_left = '';
  4501. $shy_char_right = '';
  4502. }
  4503. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  4504. if ($firstline) {
  4505. $startx = $this->x;
  4506. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  4507. if ($rtlmode) {
  4508. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  4509. }
  4510. $linew = $this->GetArrStringWidth($tmparr);
  4511. unset($tmparr);
  4512. if ($this->rtl) {
  4513. $this->endlinex = $startx - $linew - $shy_width;
  4514. } else {
  4515. $this->endlinex = $startx + $linew + $shy_width;
  4516. }
  4517. $w = $linew;
  4518. $tmpcmargin = $this->cMargin;
  4519. if ($maxh == 0) {
  4520. $this->cMargin = 0;
  4521. }
  4522. }
  4523. // print the line
  4524. if ($firstblock AND $this->isRTLTextDir()) {
  4525. $tmpstr = rtrim($tmpstr);
  4526. }
  4527. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  4528. unset($tmpstr);
  4529. if ($firstline) {
  4530. // return the remaining text
  4531. $this->cMargin = $tmpcmargin;
  4532. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  4533. }
  4534. $i = $sep;
  4535. $sep = -1;
  4536. $shy = false;
  4537. $j = ($i+1);
  4538. }
  4539. // account for margin changes
  4540. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
  4541. // AcceptPageBreak() may be overriden on extended classed to include margin changes
  4542. $this->AcceptPageBreak();
  4543. }
  4544. $w = $this->getRemainingWidth();
  4545. $wmax = $w - (2 * $this->cMargin);
  4546. if ($linebreak) {
  4547. $linebreak = false;
  4548. } else {
  4549. ++$nl;
  4550. $l = 0;
  4551. }
  4552. }
  4553. }
  4554. // save last character
  4555. $pc = $c;
  4556. ++$i;
  4557. } // end while i < nb
  4558. // print last substring (if any)
  4559. if ($l > 0) {
  4560. switch ($align) {
  4561. case 'J':
  4562. case 'C': {
  4563. $w = $w;
  4564. break;
  4565. }
  4566. case 'L': {
  4567. if ($this->rtl) {
  4568. $w = $w;
  4569. } else {
  4570. $w = $l;
  4571. }
  4572. break;
  4573. }
  4574. case 'R': {
  4575. if ($this->rtl) {
  4576. $w = $l;
  4577. } else {
  4578. $w = $w;
  4579. }
  4580. break;
  4581. }
  4582. default: {
  4583. $w = $l;
  4584. break;
  4585. }
  4586. }
  4587. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  4588. if ($firstline) {
  4589. $startx = $this->x;
  4590. $tmparr = array_slice($chars, $j, ($nb - $j));
  4591. if ($rtlmode) {
  4592. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  4593. }
  4594. $linew = $this->GetArrStringWidth($tmparr);
  4595. unset($tmparr);
  4596. if ($this->rtl) {
  4597. $this->endlinex = $startx - $linew;
  4598. } else {
  4599. $this->endlinex = $startx + $linew;
  4600. }
  4601. $w = $linew;
  4602. $tmpcmargin = $this->cMargin;
  4603. if ($maxh == 0) {
  4604. $this->cMargin = 0;
  4605. }
  4606. }
  4607. if ($firstblock AND $this->isRTLTextDir()) {
  4608. $tmpstr = rtrim($tmpstr);
  4609. }
  4610. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  4611. unset($tmpstr);
  4612. if ($firstline) {
  4613. $this->cMargin = $tmpcmargin;
  4614. return ($this->UniArrSubString($uchars, $nb));
  4615. }
  4616. ++$nl;
  4617. }
  4618. if ($firstline) {
  4619. return '';
  4620. }
  4621. return $nl;
  4622. }
  4623. /**
  4624. * Returns the remaining width between the current position and margins.
  4625. * @return int Return the remaining width
  4626. * @access protected
  4627. */
  4628. protected function getRemainingWidth() {
  4629. if ($this->rtl) {
  4630. return ($this->x - $this->lMargin);
  4631. } else {
  4632. return ($this->w - $this->rMargin - $this->x);
  4633. }
  4634. }
  4635. /**
  4636. * Extract a slice of the $strarr array and return it as string.
  4637. * @param string $strarr The input array of characters.
  4638. * @param int $start the starting element of $strarr.
  4639. * @param int $end first element that will not be returned.
  4640. * @return Return part of a string
  4641. * @access public
  4642. */
  4643. public function UTF8ArrSubString($strarr, $start='', $end='') {
  4644. if (strlen($start) == 0) {
  4645. $start = 0;
  4646. }
  4647. if (strlen($end) == 0) {
  4648. $end = count($strarr);
  4649. }
  4650. $string = '';
  4651. for ($i=$start; $i < $end; ++$i) {
  4652. $string .= $this->unichr($strarr[$i]);
  4653. }
  4654. return $string;
  4655. }
  4656. /**
  4657. * Extract a slice of the $uniarr array and return it as string.
  4658. * @param string $uniarr The input array of characters.
  4659. * @param int $start the starting element of $strarr.
  4660. * @param int $end first element that will not be returned.
  4661. * @return Return part of a string
  4662. * @access public
  4663. * @since 4.5.037 (2009-04-07)
  4664. */
  4665. public function UniArrSubString($uniarr, $start='', $end='') {
  4666. if (strlen($start) == 0) {
  4667. $start = 0;
  4668. }
  4669. if (strlen($end) == 0) {
  4670. $end = count($uniarr);
  4671. }
  4672. $string = '';
  4673. for ($i=$start; $i < $end; ++$i) {
  4674. $string .= $uniarr[$i];
  4675. }
  4676. return $string;
  4677. }
  4678. /**
  4679. * Convert an array of UTF8 values to array of unicode characters
  4680. * @param string $ta The input array of UTF8 values.
  4681. * @return Return array of unicode characters
  4682. * @access public
  4683. * @since 4.5.037 (2009-04-07)
  4684. */
  4685. public function UTF8ArrayToUniArray($ta) {
  4686. return array_map(array($this, 'unichr'), $ta);
  4687. }
  4688. /**
  4689. * Returns the unicode caracter specified by UTF-8 value
  4690. * @param int $c UTF-8 value
  4691. * @return Returns the specified character.
  4692. * @author Miguel Perez, Nicola Asuni
  4693. * @access public
  4694. * @since 2.3.000 (2008-03-05)
  4695. */
  4696. public function unichr($c) {
  4697. if (!$this->isunicode) {
  4698. return chr($c);
  4699. } elseif ($c <= 0x7F) {
  4700. // one byte
  4701. return chr($c);
  4702. } elseif ($c <= 0x7FF) {
  4703. // two bytes
  4704. return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
  4705. } elseif ($c <= 0xFFFF) {
  4706. // three bytes
  4707. return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  4708. } elseif ($c <= 0x10FFFF) {
  4709. // four bytes
  4710. return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  4711. } else {
  4712. return '';
  4713. }
  4714. }
  4715. /**
  4716. * Return the image type given the file name or array returned by getimagesize() function.
  4717. * @param string $imgfile image file name
  4718. * @param array $iminfo array of image information returned by getimagesize() function.
  4719. * @return string image type
  4720. * @since 4.8.017 (2009-11-27)
  4721. */
  4722. public function getImageFileType($imgfile, $iminfo=array()) {
  4723. if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
  4724. $mime = explode('/', $iminfo['mime']);
  4725. if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
  4726. return trim($mime[1]);
  4727. }
  4728. }
  4729. $type = '';
  4730. $fileinfo = pathinfo($imgfile);
  4731. if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) {
  4732. $type = strtolower(trim($fileinfo['extension']));
  4733. }
  4734. if ($type == 'jpg') {
  4735. $type = 'jpeg';
  4736. }
  4737. return $type;
  4738. }
  4739. /**
  4740. * Puts an image in the page.
  4741. * The upper-left corner must be given.
  4742. * The dimensions can be specified in different ways:<ul>
  4743. * <li>explicit width and height (expressed in user unit)</li>
  4744. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  4745. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  4746. * 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;
  4747. * The format can be specified explicitly or inferred from the file extension.<br />
  4748. * It is possible to put a link on the image.<br />
  4749. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  4750. * @param string $file Name of the file containing the image.
  4751. * @param float $x Abscissa of the upper-left corner.
  4752. * @param float $y Ordinate of the upper-left corner.
  4753. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4754. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4755. * @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.
  4756. * @param mixed $link URL or identifier returned by AddLink().
  4757. * @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>
  4758. * @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).
  4759. * @param int $dpi dot-per-inch resolution used on resize
  4760. * @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>
  4761. * @param boolean $ismask true if this image is a mask, false otherwise
  4762. * @param mixed $imgmask image object returned by this function or false
  4763. * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  4764. * @param boolean $fitbox If true scale image dimensions proportionally to fit within the ($w, $h) box.
  4765. * @param boolean $hidden if true do not display the image.
  4766. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  4767. * @return image information
  4768. * @access public
  4769. * @since 1.1
  4770. */
  4771. 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) {
  4772. if ($x === '') {
  4773. $x = $this->x;
  4774. }
  4775. if ($y === '') {
  4776. $y = $this->y;
  4777. }
  4778. // get image dimensions
  4779. $imsize = @getimagesize($file);
  4780. if ($imsize === FALSE) {
  4781. // encode spaces on filename
  4782. $file = str_replace(' ', '%20', $file);
  4783. $imsize = @getimagesize($file);
  4784. if ($imsize === FALSE) {
  4785. $this->Error('[Image] No such file or directory in '.$file);
  4786. }
  4787. }
  4788. // get original image width and height in pixels
  4789. list($pixw, $pixh) = $imsize;
  4790. // calculate image width and height on document
  4791. if (($w <= 0) AND ($h <= 0)) {
  4792. // convert image size to document unit
  4793. $w = $this->pixelsToUnits($pixw);
  4794. $h = $this->pixelsToUnits($pixh);
  4795. } elseif ($w <= 0) {
  4796. $w = $h * $pixw / $pixh;
  4797. } elseif ($h <= 0) {
  4798. $h = $w * $pixh / $pixw;
  4799. } elseif ($fitbox AND ($w > 0) AND ($h > 0)) {
  4800. // scale image dimensions proportionally to fit within the ($w, $h) box
  4801. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  4802. $h = $w * $pixh / $pixw;
  4803. } else {
  4804. $w = $h * $pixw / $pixh;
  4805. }
  4806. }
  4807. // Check whether we need a new page first as this does not fit
  4808. $prev_x = $this->x;
  4809. if ($this->checkPageBreak($h, $y)) {
  4810. $y = $this->y;
  4811. if ($this->rtl) {
  4812. $x += ($prev_x - $this->x);
  4813. } else {
  4814. $x += ($this->x - $prev_x);
  4815. }
  4816. }
  4817. // resize image to be contained on a single page
  4818. if ($fitonpage) {
  4819. $ratio_wh = $w / $h;
  4820. if (($y + $h) > $this->PageBreakTrigger) {
  4821. $h = $this->PageBreakTrigger - $y;
  4822. $w = $h * $ratio_wh;
  4823. }
  4824. if (($x + $w) > ($this->w - $this->rMargin)) {
  4825. $w = $this->w - $this->rMargin - $x;
  4826. $h = $w / $ratio_wh;
  4827. }
  4828. }
  4829. // calculate new minimum dimensions in pixels
  4830. $neww = round($w * $this->k * $dpi / $this->dpi);
  4831. $newh = round($h * $this->k * $dpi / $this->dpi);
  4832. // check if resize is necessary (resize is used only to reduce the image)
  4833. $newsize = ($neww * $newh);
  4834. $pixsize = ($pixw * $pixh);
  4835. if (intval($resize) == 2) {
  4836. $resize = true;
  4837. } elseif ($newsize >= $pixsize) {
  4838. $resize = false;
  4839. }
  4840. // check if image has been already added on document
  4841. $newimage = true;
  4842. if (in_array($file, $this->imagekeys)) {
  4843. $newimage = false;
  4844. // get existing image data
  4845. $info = $this->getImageBuffer($file);
  4846. // check if the newer image is larger
  4847. $oldsize = ($info['w'] * $info['h']);
  4848. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  4849. $newimage = true;
  4850. }
  4851. }
  4852. if ($newimage) {
  4853. //First use of image, get info
  4854. if ($type == '') {
  4855. $type = $this->getImageFileType($file, $imsize);
  4856. }
  4857. $mqr = $this->get_mqr();
  4858. $this->set_mqr(false);
  4859. // Specific image handlers
  4860. $mtd = '_parse'.$type;
  4861. // GD image handler function
  4862. $gdfunction = 'imagecreatefrom'.$type;
  4863. $info = false;
  4864. if ((method_exists($this, $mtd)) AND (!($resize AND function_exists($gdfunction)))) {
  4865. // TCPDF image functions
  4866. $info = $this->$mtd($file);
  4867. if ($info == 'pngalpha') {
  4868. return $this->ImagePngAlpha($file, $x, $y, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign);
  4869. }
  4870. }
  4871. if (!$info) {
  4872. if (function_exists($gdfunction)) {
  4873. // GD library
  4874. $img = $gdfunction($file);
  4875. if ($resize) {
  4876. $imgr = imagecreatetruecolor($neww, $newh);
  4877. if (($type == 'gif') OR ($type == 'png')) {
  4878. $imgr = $this->_setGDImageTransparency($imgr, $img);
  4879. }
  4880. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  4881. if (($type == 'gif') OR ($type == 'png')) {
  4882. $info = $this->_toPNG($imgr);
  4883. } else {
  4884. $info = $this->_toJPEG($imgr);
  4885. }
  4886. } else {
  4887. if (($type == 'gif') OR ($type == 'png')) {
  4888. $info = $this->_toPNG($img);
  4889. } else {
  4890. $info = $this->_toJPEG($img);
  4891. }
  4892. }
  4893. } elseif (extension_loaded('imagick')) {
  4894. // ImageMagick library
  4895. $img = new Imagick();
  4896. $img->readImage($file);
  4897. if ($resize) {
  4898. $img->resizeImage($neww, $newh, 10, 1, false);
  4899. }
  4900. $img->setCompressionQuality($this->jpeg_quality);
  4901. $img->setImageFormat('jpeg');
  4902. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  4903. $img->writeImage($tempname);
  4904. $info = $this->_parsejpeg($tempname);
  4905. unlink($tempname);
  4906. $img->destroy();
  4907. } else {
  4908. return;
  4909. }
  4910. }
  4911. if ($info === false) {
  4912. //If false, we cannot process image
  4913. return;
  4914. }
  4915. $this->set_mqr($mqr);
  4916. if ($ismask) {
  4917. // force grayscale
  4918. $info['cs'] = 'DeviceGray';
  4919. }
  4920. $info['i'] = $this->numimages;
  4921. if (!in_array($file, $this->imagekeys)) {
  4922. ++$info['i'];
  4923. }
  4924. if ($imgmask !== false) {
  4925. $info['masked'] = $imgmask;
  4926. }
  4927. // add image to document
  4928. $this->setImageBuffer($file, $info);
  4929. }
  4930. // set bottomcoordinates
  4931. $this->img_rb_y = $y + $h;
  4932. // set alignment
  4933. if ($this->rtl) {
  4934. if ($palign == 'L') {
  4935. $ximg = $this->lMargin;
  4936. // set right side coordinate
  4937. $this->img_rb_x = $ximg + $w;
  4938. } elseif ($palign == 'C') {
  4939. $ximg = ($this->w - $x - $w) / 2;
  4940. // set right side coordinate
  4941. $this->img_rb_x = $ximg + $w;
  4942. } else {
  4943. $ximg = $this->w - $x - $w;
  4944. // set left side coordinate
  4945. $this->img_rb_x = $ximg;
  4946. }
  4947. } else {
  4948. if ($palign == 'R') {
  4949. $ximg = $this->w - $this->rMargin - $w;
  4950. // set left side coordinate
  4951. $this->img_rb_x = $ximg;
  4952. } elseif ($palign == 'C') {
  4953. $ximg = ($this->w - $x - $w) / 2;
  4954. // set right side coordinate
  4955. $this->img_rb_x = $ximg + $w;
  4956. } else {
  4957. $ximg = $x;
  4958. // set right side coordinate
  4959. $this->img_rb_x = $ximg + $w;
  4960. }
  4961. }
  4962. if ($ismask OR $hidden) {
  4963. // image is not displayed
  4964. return $info['i'];
  4965. }
  4966. $xkimg = $ximg * $this->k;
  4967. $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  4968. if (!empty($border)) {
  4969. $bx = $x;
  4970. $by = $y;
  4971. $this->x = $ximg;
  4972. $this->y = $y;
  4973. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0);
  4974. $this->x = $bx;
  4975. $this->y = $by;
  4976. }
  4977. if ($link) {
  4978. $this->Link($ximg, $y, $w, $h, $link, 0);
  4979. }
  4980. // set pointer to align the successive text/objects
  4981. switch($align) {
  4982. case 'T': {
  4983. $this->y = $y;
  4984. $this->x = $this->img_rb_x;
  4985. break;
  4986. }
  4987. case 'M': {
  4988. $this->y = $y + round($h/2);
  4989. $this->x = $this->img_rb_x;
  4990. break;
  4991. }
  4992. case 'B': {
  4993. $this->y = $this->img_rb_y;
  4994. $this->x = $this->img_rb_x;
  4995. break;
  4996. }
  4997. case 'N': {
  4998. $this->SetY($this->img_rb_y);
  4999. break;
  5000. }
  5001. default:{
  5002. break;
  5003. }
  5004. }
  5005. $this->endlinex = $this->img_rb_x;
  5006. return $info['i'];
  5007. }
  5008. /**
  5009. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  5010. * @param boolean $mqr FALSE for off, TRUE for on.
  5011. * @since 4.6.025 (2009-08-17)
  5012. */
  5013. public function set_mqr($mqr) {
  5014. if(!defined('PHP_VERSION_ID')) {
  5015. $version = PHP_VERSION;
  5016. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  5017. }
  5018. if (PHP_VERSION_ID < 50300) {
  5019. @set_magic_quotes_runtime($mqr);
  5020. }
  5021. }
  5022. /**
  5023. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  5024. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  5025. * @since 4.6.025 (2009-08-17)
  5026. */
  5027. public function get_mqr() {
  5028. if(!defined('PHP_VERSION_ID')) {
  5029. $version = PHP_VERSION;
  5030. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  5031. }
  5032. if (PHP_VERSION_ID < 50300) {
  5033. return @get_magic_quotes_runtime();
  5034. }
  5035. return 0;
  5036. }
  5037. /**
  5038. * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
  5039. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  5040. * @param string $file Image file name.
  5041. * @param image $image Image object.
  5042. * return image JPEG image object.
  5043. * @access protected
  5044. */
  5045. protected function _toJPEG($image) {
  5046. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  5047. imagejpeg($image, $tempname, $this->jpeg_quality);
  5048. imagedestroy($image);
  5049. $retvars = $this->_parsejpeg($tempname);
  5050. // tidy up by removing temporary image
  5051. unlink($tempname);
  5052. return $retvars;
  5053. }
  5054. /**
  5055. * Convert the loaded image to a PNG and then return a structure for the PDF creator.
  5056. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  5057. * @param string $file Image file name.
  5058. * @param image $image Image object.
  5059. * return image PNG image object.
  5060. * @access protected
  5061. * @since 4.9.016 (2010-04-20)
  5062. */
  5063. protected function _toPNG($image) {
  5064. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  5065. imagepng($image, $tempname);
  5066. imagedestroy($image);
  5067. $retvars = $this->_parsepng($tempname);
  5068. // tidy up by removing temporary image
  5069. unlink($tempname);
  5070. return $retvars;
  5071. }
  5072. /**
  5073. * Set the transparency for the given GD image.
  5074. * @param image $new_image GD image object
  5075. * @param image $image GD image object.
  5076. * return GD image object.
  5077. * @access protected
  5078. * @since 4.9.016 (2010-04-20)
  5079. */
  5080. protected function _setGDImageTransparency($new_image, $image) {
  5081. // transparency index
  5082. $tid = imagecolortransparent($image);
  5083. // default transparency color
  5084. $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
  5085. if ($tid >= 0) {
  5086. // get the colors for the transparency index
  5087. $tcol = imagecolorsforindex($image, $tid);
  5088. }
  5089. $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
  5090. imagefill($new_image, 0, 0, $tid);
  5091. imagecolortransparent($new_image, $tid);
  5092. return $new_image;
  5093. }
  5094. /**
  5095. * Extract info from a JPEG file without using the GD library.
  5096. * @param string $file image file to parse
  5097. * @return array structure containing the image data
  5098. * @access protected
  5099. */
  5100. protected function _parsejpeg($file) {
  5101. $a = getimagesize($file);
  5102. if (empty($a)) {
  5103. $this->Error('Missing or incorrect image file: '.$file);
  5104. }
  5105. if ($a[2] != 2) {
  5106. $this->Error('Not a JPEG file: '.$file);
  5107. }
  5108. if ((!isset($a['channels'])) OR ($a['channels'] == 3)) {
  5109. $colspace = 'DeviceRGB';
  5110. } elseif ($a['channels'] == 4) {
  5111. $colspace = 'DeviceCMYK';
  5112. } else {
  5113. $colspace = 'DeviceGray';
  5114. }
  5115. $bpc = isset($a['bits']) ? $a['bits'] : 8;
  5116. $data = file_get_contents($file);
  5117. return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
  5118. }
  5119. /**
  5120. * Extract info from a PNG file without using the GD library.
  5121. * @param string $file image file to parse
  5122. * @return array structure containing the image data
  5123. * @access protected
  5124. */
  5125. protected function _parsepng($file) {
  5126. $f = fopen($file, 'rb');
  5127. if ($f === false) {
  5128. $this->Error('Can\'t open image file: '.$file);
  5129. }
  5130. //Check signature
  5131. if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  5132. $this->Error('Not a PNG file: '.$file);
  5133. }
  5134. //Read header chunk
  5135. fread($f, 4);
  5136. if (fread($f, 4) != 'IHDR') {
  5137. $this->Error('Incorrect PNG file: '.$file);
  5138. }
  5139. $w = $this->_freadint($f);
  5140. $h = $this->_freadint($f);
  5141. $bpc = ord(fread($f, 1));
  5142. if ($bpc > 8) {
  5143. //$this->Error('16-bit depth not supported: '.$file);
  5144. fclose($f);
  5145. return false;
  5146. }
  5147. $ct = ord(fread($f, 1));
  5148. if ($ct == 0) {
  5149. $colspace = 'DeviceGray';
  5150. } elseif ($ct == 2) {
  5151. $colspace = 'DeviceRGB';
  5152. } elseif ($ct == 3) {
  5153. $colspace = 'Indexed';
  5154. } else {
  5155. // alpha channel
  5156. fclose($f);
  5157. return 'pngalpha';
  5158. }
  5159. if (ord(fread($f, 1)) != 0) {
  5160. //$this->Error('Unknown compression method: '.$file);
  5161. fclose($f);
  5162. return false;
  5163. }
  5164. if (ord(fread($f, 1)) != 0) {
  5165. //$this->Error('Unknown filter method: '.$file);
  5166. fclose($f);
  5167. return false;
  5168. }
  5169. if (ord(fread($f, 1)) != 0) {
  5170. //$this->Error('Interlacing not supported: '.$file);
  5171. fclose($f);
  5172. return false;
  5173. }
  5174. fread($f, 4);
  5175. $parms = '/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  5176. //Scan chunks looking for palette, transparency and image data
  5177. $pal = '';
  5178. $trns = '';
  5179. $data = '';
  5180. do {
  5181. $n = $this->_freadint($f);
  5182. $type = fread($f, 4);
  5183. if ($type == 'PLTE') {
  5184. //Read palette
  5185. $pal = $this->rfread($f, $n);
  5186. fread($f, 4);
  5187. } elseif ($type == 'tRNS') {
  5188. //Read transparency info
  5189. $t = $this->rfread($f, $n);
  5190. if ($ct == 0) {
  5191. $trns = array(ord(substr($t, 1, 1)));
  5192. } elseif ($ct == 2) {
  5193. $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
  5194. } else {
  5195. $pos = strpos($t, chr(0));
  5196. if ($pos !== false) {
  5197. $trns = array($pos);
  5198. }
  5199. }
  5200. fread($f, 4);
  5201. } elseif ($type == 'IDAT') {
  5202. //Read image data block
  5203. $data .= $this->rfread($f, $n);
  5204. fread($f, 4);
  5205. } elseif ($type == 'IEND') {
  5206. break;
  5207. } else {
  5208. $this->rfread($f, $n + 4);
  5209. }
  5210. } while ($n);
  5211. if (($colspace == 'Indexed') AND (empty($pal))) {
  5212. //$this->Error('Missing palette in '.$file);
  5213. fclose($f);
  5214. return false;
  5215. }
  5216. fclose($f);
  5217. return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  5218. }
  5219. /**
  5220. * Binary-safe and URL-safe file read.
  5221. * 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.
  5222. * @param resource $handle
  5223. * @param int $length
  5224. * @return Returns the read string or FALSE in case of error.
  5225. * @author Nicola Asuni
  5226. * @access protected
  5227. * @since 4.5.027 (2009-03-16)
  5228. */
  5229. protected function rfread($handle, $length) {
  5230. $data = fread($handle, $length);
  5231. if ($data === false) {
  5232. return false;
  5233. }
  5234. $rest = $length - strlen($data);
  5235. if ($rest > 0) {
  5236. $data .= $this->rfread($handle, $rest);
  5237. }
  5238. return $data;
  5239. }
  5240. /**
  5241. * Extract info from a PNG image with alpha channel using the GD library.
  5242. * @param string $file Name of the file containing the image.
  5243. * @param float $x Abscissa of the upper-left corner.
  5244. * @param float $y Ordinate of the upper-left corner.
  5245. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5246. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5247. * @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.
  5248. * @param mixed $link URL or identifier returned by AddLink().
  5249. * @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>
  5250. * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  5251. * @param int $dpi dot-per-inch resolution used on resize
  5252. * @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>
  5253. * @author Valentin Schmidt, Nicola Asuni
  5254. * @access protected
  5255. * @since 4.3.007 (2008-12-04)
  5256. * @see Image()
  5257. */
  5258. protected function ImagePngAlpha($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='') {
  5259. // get image size
  5260. list($wpx, $hpx) = getimagesize($file);
  5261. // generate images
  5262. $img = imagecreatefrompng($file);
  5263. $imgalpha = imagecreate($wpx, $hpx);
  5264. // generate gray scale pallete
  5265. for ($c = 0; $c < 256; ++$c) {
  5266. ImageColorAllocate($imgalpha, $c, $c, $c);
  5267. }
  5268. // extract alpha channel
  5269. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  5270. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  5271. $colorindex = imagecolorat($img, $xpx, $ypx);
  5272. $col = imagecolorsforindex($img, $colorindex);
  5273. imagesetpixel($imgalpha, $xpx, $ypx, $this->getGDgamma((127 - $col['alpha']) * 255 / 127));
  5274. }
  5275. }
  5276. // create temp alpha file
  5277. $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_');
  5278. imagepng($imgalpha, $tempfile_alpha);
  5279. imagedestroy($imgalpha);
  5280. // extract image without alpha channel
  5281. $imgplain = imagecreatetruecolor($wpx, $hpx);
  5282. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  5283. // create temp image file
  5284. $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_');
  5285. imagepng($imgplain, $tempfile_plain);
  5286. imagedestroy($imgplain);
  5287. // embed mask image
  5288. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  5289. // embed image, masked with previously embedded mask
  5290. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  5291. // remove temp files
  5292. unlink($tempfile_alpha);
  5293. unlink($tempfile_plain);
  5294. }
  5295. /**
  5296. * Correct the gamma value to be used with GD library
  5297. * @param float $v the gamma value to be corrected
  5298. * @access protected
  5299. * @since 4.3.007 (2008-12-04)
  5300. */
  5301. protected function getGDgamma($v) {
  5302. return (pow(($v / 255), 2.2) * 255);
  5303. }
  5304. /**
  5305. * Performs a line break.
  5306. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  5307. * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  5308. * @param boolean $cell if true add a cMargin to the x coordinate
  5309. * @access public
  5310. * @since 1.0
  5311. * @see Cell()
  5312. */
  5313. public function Ln($h='', $cell=false) {
  5314. if (($this->num_columns > 0) 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'])) {
  5315. // revove vertical space from the top of the column
  5316. return;
  5317. }
  5318. if ($cell) {
  5319. $cellmargin = $this->cMargin;
  5320. } else {
  5321. $cellmargin = 0;
  5322. }
  5323. if ($this->rtl) {
  5324. $this->x = $this->w - $this->rMargin - $cellmargin;
  5325. } else {
  5326. $this->x = $this->lMargin + $cellmargin;
  5327. }
  5328. if (is_string($h)) {
  5329. $this->y += $this->lasth;
  5330. } else {
  5331. $this->y += $h;
  5332. }
  5333. $this->newline = true;
  5334. }
  5335. /**
  5336. * Returns the relative X value of current position.
  5337. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  5338. * @return float
  5339. * @access public
  5340. * @since 1.2
  5341. * @see SetX(), GetY(), SetY()
  5342. */
  5343. public function GetX() {
  5344. //Get x position
  5345. if ($this->rtl) {
  5346. return ($this->w - $this->x);
  5347. } else {
  5348. return $this->x;
  5349. }
  5350. }
  5351. /**
  5352. * Returns the absolute X value of current position.
  5353. * @return float
  5354. * @access public
  5355. * @since 1.2
  5356. * @see SetX(), GetY(), SetY()
  5357. */
  5358. public function GetAbsX() {
  5359. return $this->x;
  5360. }
  5361. /**
  5362. * Returns the ordinate of the current position.
  5363. * @return float
  5364. * @access public
  5365. * @since 1.0
  5366. * @see SetY(), GetX(), SetX()
  5367. */
  5368. public function GetY() {
  5369. return $this->y;
  5370. }
  5371. /**
  5372. * Defines the abscissa of the current position.
  5373. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  5374. * @param float $x The value of the abscissa.
  5375. * @access public
  5376. * @since 1.2
  5377. * @see GetX(), GetY(), SetY(), SetXY()
  5378. */
  5379. public function SetX($x) {
  5380. if ($this->rtl) {
  5381. if ($x >= 0) {
  5382. $this->x = $this->w - $x;
  5383. } else {
  5384. $this->x = abs($x);
  5385. }
  5386. } else {
  5387. if ($x >= 0) {
  5388. $this->x = $x;
  5389. } else {
  5390. $this->x = $this->w + $x;
  5391. }
  5392. }
  5393. if ($this->x < 0) {
  5394. $this->x = 0;
  5395. }
  5396. if ($this->x > $this->w) {
  5397. $this->x = $this->w;
  5398. }
  5399. }
  5400. /**
  5401. * Moves the current abscissa back to the left margin and sets the ordinate.
  5402. * If the passed value is negative, it is relative to the bottom of the page.
  5403. * @param float $y The value of the ordinate.
  5404. * @param bool $resetx if true (default) reset the X position.
  5405. * @access public
  5406. * @since 1.0
  5407. * @see GetX(), GetY(), SetY(), SetXY()
  5408. */
  5409. public function SetY($y, $resetx=true) {
  5410. if ($resetx) {
  5411. //reset x
  5412. if ($this->rtl) {
  5413. $this->x = $this->w - $this->rMargin;
  5414. } else {
  5415. $this->x = $this->lMargin;
  5416. }
  5417. }
  5418. if ($y >= 0) {
  5419. $this->y = $y;
  5420. } else {
  5421. $this->y = $this->h + $y;
  5422. }
  5423. if ($this->y < 0) {
  5424. $this->y = 0;
  5425. }
  5426. if ($this->y > $this->h) {
  5427. $this->y = $this->h;
  5428. }
  5429. }
  5430. /**
  5431. * Defines the abscissa and ordinate of the current position.
  5432. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  5433. * @param float $x The value of the abscissa
  5434. * @param float $y The value of the ordinate
  5435. * @access public
  5436. * @since 1.2
  5437. * @see SetX(), SetY()
  5438. */
  5439. public function SetXY($x, $y) {
  5440. $this->SetY($y, false);
  5441. $this->SetX($x);
  5442. }
  5443. /**
  5444. * Send the document to a given destination: string, local file or browser.
  5445. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  5446. * The method first calls Close() if necessary to terminate the document.
  5447. * @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.
  5448. * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li></ul>
  5449. * @access public
  5450. * @since 1.0
  5451. * @see Close()
  5452. */
  5453. public function Output($name='doc.pdf', $dest='I') {
  5454. //Output PDF to some destination
  5455. //Finish document if necessary
  5456. $this->lastpage();
  5457. if ($this->state < 3) {
  5458. $this->Close();
  5459. }
  5460. //Normalize parameters
  5461. if (is_bool($dest)) {
  5462. $dest = $dest ? 'D' : 'F';
  5463. }
  5464. $dest = strtoupper($dest);
  5465. if ($dest != 'F') {
  5466. $name = preg_replace('/[\s]+/', '_', $name);
  5467. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  5468. }
  5469. if ($this->sign) {
  5470. // *** apply digital signature to the document ***
  5471. // get the document content
  5472. $pdfdoc = $this->getBuffer();
  5473. // remove last newline
  5474. $pdfdoc = substr($pdfdoc, 0, -1);
  5475. // Remove the original buffer
  5476. if (isset($this->diskcache) AND $this->diskcache) {
  5477. // remove buffer file from cache
  5478. unlink($this->buffer);
  5479. }
  5480. unset($this->buffer);
  5481. // remove filler space
  5482. $byterange_string_len = strlen($this->byterange_string);
  5483. // define the ByteRange
  5484. $byte_range = array();
  5485. $byte_range[0] = 0;
  5486. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  5487. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  5488. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  5489. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  5490. // replace the ByteRange
  5491. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  5492. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  5493. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  5494. // write the document to a temporary folder
  5495. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  5496. $f = fopen($tempdoc, 'wb');
  5497. if (!$f) {
  5498. $this->Error('Unable to create temporary file: '.$tempdoc);
  5499. }
  5500. $pdfdoc_length = strlen($pdfdoc);
  5501. fwrite($f, $pdfdoc, $pdfdoc_length);
  5502. fclose($f);
  5503. // get digital signature via openssl library
  5504. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  5505. if (empty($this->signature_data['extracerts'])) {
  5506. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  5507. } else {
  5508. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']);
  5509. }
  5510. unlink($tempdoc);
  5511. // read signature
  5512. $signature = file_get_contents($tempsign, false, null, $pdfdoc_length);
  5513. unlink($tempsign);
  5514. // extract signature
  5515. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  5516. $tmparr = explode("\n\n", $signature);
  5517. $signature = $tmparr[1];
  5518. unset($tmparr);
  5519. // decode signature
  5520. $signature = base64_decode(trim($signature));
  5521. // convert signature to hex
  5522. $signature = current(unpack('H*', $signature));
  5523. $signature = str_pad($signature, $this->signature_max_length, '0');
  5524. // Add signature to the document
  5525. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, ($byte_range[1]));
  5526. $this->diskcache = false;
  5527. $this->buffer = &$pdfdoc;
  5528. $this->bufferlen = strlen($pdfdoc);
  5529. }
  5530. switch($dest) {
  5531. case 'I': {
  5532. // Send PDF to the standard output
  5533. if (ob_get_contents()) {
  5534. $this->Error('Some data has already been output, can\'t send PDF file');
  5535. }
  5536. if (php_sapi_name() != 'cli') {
  5537. //We send to a browser
  5538. header('Content-Type: application/pdf');
  5539. if (headers_sent()) {
  5540. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  5541. }
  5542. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  5543. header('Pragma: public');
  5544. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  5545. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  5546. header('Content-Length: '.$this->bufferlen);
  5547. header('Content-Disposition: inline; filename="'.basename($name).'";');
  5548. }
  5549. echo $this->getBuffer();
  5550. break;
  5551. }
  5552. case 'D': {
  5553. // Download PDF as file
  5554. if (ob_get_contents()) {
  5555. $this->Error('Some data has already been output, can\'t send PDF file');
  5556. }
  5557. header('Content-Description: File Transfer');
  5558. if (headers_sent()) {
  5559. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  5560. }
  5561. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  5562. header('Pragma: public');
  5563. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  5564. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  5565. // force download dialog
  5566. header('Content-Type: application/force-download');
  5567. header('Content-Type: application/octet-stream', false);
  5568. header('Content-Type: application/download', false);
  5569. header('Content-Type: application/pdf', false);
  5570. // use the Content-Disposition header to supply a recommended filename
  5571. header('Content-Disposition: attachment; filename="'.basename($name).'";');
  5572. header('Content-Transfer-Encoding: binary');
  5573. header('Content-Length: '.$this->bufferlen);
  5574. echo $this->getBuffer();
  5575. break;
  5576. }
  5577. case 'F': {
  5578. // Save PDF to a local file
  5579. if ($this->diskcache) {
  5580. copy($this->buffer, $name);
  5581. } else {
  5582. $f = fopen($name, 'wb');
  5583. if (!$f) {
  5584. $this->Error('Unable to create output file: '.$name);
  5585. }
  5586. fwrite($f, $this->getBuffer(), $this->bufferlen);
  5587. fclose($f);
  5588. }
  5589. break;
  5590. }
  5591. case 'S': {
  5592. // Returns PDF as a string
  5593. return $this->getBuffer();
  5594. }
  5595. default: {
  5596. $this->Error('Incorrect output destination: '.$dest);
  5597. }
  5598. }
  5599. return '';
  5600. }
  5601. /**
  5602. * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  5603. * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  5604. * @param boolean $preserve_objcopy if true preserves the objcopy variable
  5605. * @access public
  5606. * @since 4.5.016 (2009-02-24)
  5607. */
  5608. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  5609. if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) {
  5610. // remove buffer file from cache
  5611. unlink($this->buffer);
  5612. }
  5613. foreach (array_keys(get_object_vars($this)) as $val) {
  5614. if ($destroyall OR (
  5615. ($val != 'internal_encoding')
  5616. AND ($val != 'state')
  5617. AND ($val != 'bufferlen')
  5618. AND ($val != 'buffer')
  5619. AND ($val != 'diskcache')
  5620. AND ($val != 'sign')
  5621. AND ($val != 'signature_data')
  5622. AND ($val != 'signature_max_length')
  5623. AND ($val != 'byterange_string')
  5624. )) {
  5625. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
  5626. unset($this->$val);
  5627. }
  5628. }
  5629. }
  5630. }
  5631. /**
  5632. * Check for locale-related bug
  5633. * @access protected
  5634. */
  5635. protected function _dochecks() {
  5636. //Check for locale-related bug
  5637. if (1.1 == 1) {
  5638. $this->Error('Don\'t alter the locale before including class file');
  5639. }
  5640. //Check for decimal separator
  5641. if (sprintf('%.1F', 1.0) != '1.0') {
  5642. setlocale(LC_NUMERIC, 'C');
  5643. }
  5644. }
  5645. /**
  5646. * Return fonts path
  5647. * @return string
  5648. * @access protected
  5649. */
  5650. protected function _getfontpath() {
  5651. if (!defined('K_PATH_FONTS') AND is_dir(dirname(__FILE__).'/fonts')) {
  5652. define('K_PATH_FONTS', dirname(__FILE__).'/fonts/');
  5653. }
  5654. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  5655. }
  5656. /**
  5657. * Output pages.
  5658. * @access protected
  5659. */
  5660. protected function _putpages() {
  5661. $nb = $this->numpages;
  5662. if (!empty($this->AliasNbPages)) {
  5663. $nbs = $this->formatPageNumber($nb);
  5664. $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font
  5665. $alias_a = $this->_escape($this->AliasNbPages);
  5666. $alias_au = $this->_escape('{'.$this->AliasNbPages.'}');
  5667. if ($this->isunicode) {
  5668. $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  5669. $alias_bu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNbPages.'}'));
  5670. $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages, false, $this->tmprtl));
  5671. $alias_cu = $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages.'}', false, $this->tmprtl));
  5672. }
  5673. }
  5674. if (!empty($this->AliasNumPage)) {
  5675. $alias_pa = $this->_escape($this->AliasNumPage);
  5676. $alias_pau = $this->_escape('{'.$this->AliasNumPage.'}');
  5677. if ($this->isunicode) {
  5678. $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  5679. $alias_pbu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNumPage.'}'));
  5680. $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage, false, $this->tmprtl));
  5681. $alias_pcu = $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage.'}', false, $this->tmprtl));
  5682. }
  5683. }
  5684. $pagegroupnum = 0;
  5685. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  5686. for ($n=1; $n <= $nb; ++$n) {
  5687. $temppage = $this->getPageBuffer($n);
  5688. if (!empty($this->pagegroups)) {
  5689. if(isset($this->newpagegroup[$n])) {
  5690. $pagegroupnum = 0;
  5691. }
  5692. ++$pagegroupnum;
  5693. foreach ($this->pagegroups as $k => $v) {
  5694. // replace total pages group numbers
  5695. $vs = $this->formatPageNumber($v);
  5696. $vu = $this->UTF8ToUTF16BE($vs, false);
  5697. $alias_ga = $this->_escape($k);
  5698. $alias_gau = $this->_escape('{'.$k.'}');
  5699. if ($this->isunicode) {
  5700. $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
  5701. $alias_gbu = $this->_escape($this->UTF8ToLatin1('{'.$k.'}'));
  5702. $alias_gc = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  5703. $alias_gcu = $this->_escape($this->utf8StrRev('{'.$k.'}', false, $this->tmprtl));
  5704. }
  5705. $temppage = str_replace($alias_gau, $vu, $temppage);
  5706. if ($this->isunicode) {
  5707. $temppage = str_replace($alias_gbu, $vu, $temppage);
  5708. $temppage = str_replace($alias_gcu, $vu, $temppage);
  5709. $temppage = str_replace($alias_gb, $vs, $temppage);
  5710. $temppage = str_replace($alias_gc, $vs, $temppage);
  5711. }
  5712. $temppage = str_replace($alias_ga, $vs, $temppage);
  5713. // replace page group numbers
  5714. $pvs = $this->formatPageNumber($pagegroupnum);
  5715. $pvu = $this->UTF8ToUTF16BE($pvs, false);
  5716. $pk = str_replace('{nb', '{pnb', $k);
  5717. $alias_pga = $this->_escape($pk);
  5718. $alias_pgau = $this->_escape('{'.$pk.'}');
  5719. if ($this->isunicode) {
  5720. $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
  5721. $alias_pgbu = $this->_escape($this->UTF8ToLatin1('{'.$pk.'}'));
  5722. $alias_pgc = $this->_escape($this->utf8StrRev($pk, false, $this->tmprtl));
  5723. $alias_pgcu = $this->_escape($this->utf8StrRev('{'.$pk.'}', false, $this->tmprtl));
  5724. }
  5725. $temppage = str_replace($alias_pgau, $pvu, $temppage);
  5726. if ($this->isunicode) {
  5727. $temppage = str_replace($alias_pgbu, $pvu, $temppage);
  5728. $temppage = str_replace($alias_pgcu, $pvu, $temppage);
  5729. $temppage = str_replace($alias_pgb, $pvs, $temppage);
  5730. $temppage = str_replace($alias_pgc, $pvs, $temppage);
  5731. }
  5732. $temppage = str_replace($alias_pga, $pvs, $temppage);
  5733. }
  5734. }
  5735. if (!empty($this->AliasNbPages)) {
  5736. // replace total pages number
  5737. $temppage = str_replace($alias_au, $nbu, $temppage);
  5738. if ($this->isunicode) {
  5739. $temppage = str_replace($alias_bu, $nbu, $temppage);
  5740. $temppage = str_replace($alias_cu, $nbu, $temppage);
  5741. $temppage = str_replace($alias_b, $nbs, $temppage);
  5742. $temppage = str_replace($alias_c, $nbs, $temppage);
  5743. }
  5744. $temppage = str_replace($alias_a, $nbs, $temppage);
  5745. }
  5746. if (!empty($this->AliasNumPage)) {
  5747. // replace page number
  5748. $pnbs = $this->formatPageNumber($n);
  5749. $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font
  5750. $temppage = str_replace($alias_pau, $pnbu, $temppage);
  5751. if ($this->isunicode) {
  5752. $temppage = str_replace($alias_pbu, $pnbu, $temppage);
  5753. $temppage = str_replace($alias_pcu, $pnbu, $temppage);
  5754. $temppage = str_replace($alias_pb, $pnbs, $temppage);
  5755. $temppage = str_replace($alias_pc, $pnbs, $temppage);
  5756. }
  5757. $temppage = str_replace($alias_pa, $pnbs, $temppage);
  5758. }
  5759. $temppage = str_replace($this->epsmarker, '', $temppage);
  5760. //Page
  5761. $this->page_obj_id[$n] = $this->_newobj();
  5762. $this->_out('<</Type /Page');
  5763. $this->_out('/Parent 1 0 R');
  5764. $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]', $this->pagedim[$n]['w'], $this->pagedim[$n]['h']));
  5765. $this->_out('/Resources 2 0 R');
  5766. $this->_putannotsrefs($n);
  5767. $this->_out('/Contents '.($this->n + 1).' 0 R>>');
  5768. $this->_out('endobj');
  5769. //Page content
  5770. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  5771. $this->_newobj();
  5772. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  5773. $this->_putstream($p);
  5774. $this->_out('endobj');
  5775. if ($this->diskcache) {
  5776. // remove temporary files
  5777. unlink($this->pages[$n]);
  5778. }
  5779. }
  5780. //Pages root
  5781. $this->offsets[1] = $this->bufferlen;
  5782. $this->_out('1 0 obj');
  5783. $this->_out('<</Type /Pages');
  5784. $this->_out('/Kids [');
  5785. foreach($this->page_obj_id as $page_obj) {
  5786. $this->_out($page_obj.' 0 R');
  5787. }
  5788. $this->_out(']');
  5789. $this->_out('/Count '.$nb);
  5790. $this->_out('>>');
  5791. $this->_out('endobj');
  5792. }
  5793. /**
  5794. * Output references to page annotations
  5795. * @param int $n page number
  5796. * @access protected
  5797. * @author Nicola Asuni
  5798. * @since 4.7.000 (2008-08-29)
  5799. */
  5800. protected function _putannotsrefs($n) {
  5801. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  5802. return;
  5803. }
  5804. $this->_out('/Annots [');
  5805. if (isset($this->PageAnnots[$n])) {
  5806. $num_annots = count($this->PageAnnots[$n]);
  5807. for ($i = 0; $i < $num_annots; ++$i) {
  5808. ++$this->curr_annot_obj_id;
  5809. if (!in_array($this->curr_annot_obj_id, $this->radio_groups)) {
  5810. $this->_out($this->curr_annot_obj_id.' 0 R');
  5811. } else {
  5812. ++$num_annots;
  5813. }
  5814. }
  5815. }
  5816. if (($n==1) AND $this->sign AND isset($this->signature_data['cert_type'])) {
  5817. // set reference for signature object
  5818. $this->_out($this->sig_annot_ref);
  5819. }
  5820. $this->_out(']');
  5821. }
  5822. /**
  5823. * Output annotations objects for all pages.
  5824. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  5825. * See section 12.5 of PDF 32000_2008 reference.
  5826. * @access protected
  5827. * @author Nicola Asuni
  5828. * @since 4.0.018 (2008-08-06)
  5829. */
  5830. protected function _putannotsobjs() {
  5831. // reset object counter
  5832. $this->annot_obj_id = $this->annots_start_obj_id;
  5833. for ($n=1; $n <= $this->numpages; ++$n) {
  5834. if (isset($this->PageAnnots[$n])) {
  5835. // set page annotations
  5836. foreach ($this->PageAnnots[$n] as $key => $pl) {
  5837. // create annotation object for grouping radiobuttons
  5838. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  5839. $annots = '<<';
  5840. $annots .= ' /Type /Annot';
  5841. $annots .= ' /Subtype /Widget';
  5842. $annots .= ' /T '.$this->_dataannobjstring($pl['txt']);
  5843. $annots .= ' /FT /Btn';
  5844. $annots .= ' /Ff 49152';
  5845. $annots .= ' /Kids [';
  5846. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $data) {
  5847. $annots .= ' '.$data['kid'].' 0 R';
  5848. if ($data['def'] !== 'Off') {
  5849. $defval = $data['def'];
  5850. }
  5851. }
  5852. $annots .= ' ]';
  5853. if (isset($defval)) {
  5854. $annots .= ' /V /'.$defval;
  5855. }
  5856. $annots .= ' >>';
  5857. ++$this->annot_obj_id;
  5858. $this->offsets[$this->annot_obj_id] = $this->bufferlen;
  5859. $this->_out($this->annot_obj_id.' 0 obj');
  5860. $this->_out($annots);
  5861. $this->_out('endobj');
  5862. $this->form_obj_id[] = $this->annot_obj_id;
  5863. // store object id to be used on Parent entry of Kids
  5864. $this->radiobutton_groups[$n][$pl['txt']] = $this->annot_obj_id;
  5865. }
  5866. $formfield = false;
  5867. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  5868. $a = $pl['x'] * $this->k;
  5869. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  5870. $c = $pl['w'] * $this->k;
  5871. $d = $pl['h'] * $this->k;
  5872. $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b+$d);
  5873. // create new annotation object
  5874. $annots = '<</Type /Annot';
  5875. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  5876. $annots .= ' /Rect ['.$rect.']';
  5877. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  5878. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  5879. $annots .= ' /FT /'.$pl['opt']['ft'];
  5880. $formfield = true;
  5881. }
  5882. $annots .= ' /Contents '.$this->_textannobjstring($pl['txt']);
  5883. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  5884. $annots .= ' /NM '.$this->_dataannobjstring(sprintf('%04u-%04u', $n, $key));
  5885. $annots .= ' /M '.$this->_datestring();
  5886. if (isset($pl['opt']['f'])) {
  5887. $val = 0;
  5888. if (is_array($pl['opt']['f'])) {
  5889. foreach ($pl['opt']['f'] as $f) {
  5890. switch (strtolower($f)) {
  5891. case 'invisible': {
  5892. $val += 1 << 0;
  5893. break;
  5894. }
  5895. case 'hidden': {
  5896. $val += 1 << 1;
  5897. break;
  5898. }
  5899. case 'print': {
  5900. $val += 1 << 2;
  5901. break;
  5902. }
  5903. case 'nozoom': {
  5904. $val += 1 << 3;
  5905. break;
  5906. }
  5907. case 'norotate': {
  5908. $val += 1 << 4;
  5909. break;
  5910. }
  5911. case 'noview': {
  5912. $val += 1 << 5;
  5913. break;
  5914. }
  5915. case 'readonly': {
  5916. $val += 1 << 6;
  5917. break;
  5918. }
  5919. case 'locked': {
  5920. $val += 1 << 8;
  5921. break;
  5922. }
  5923. case 'togglenoview': {
  5924. $val += 1 << 9;
  5925. break;
  5926. }
  5927. case 'lockedcontents': {
  5928. $val += 1 << 10;
  5929. break;
  5930. }
  5931. default: {
  5932. break;
  5933. }
  5934. }
  5935. }
  5936. } else {
  5937. $val = intval($pl['opt']['f']);
  5938. }
  5939. $annots .= ' /F '.intval($val);
  5940. }
  5941. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  5942. $annots .= ' /AS /'.$pl['opt']['as'];
  5943. }
  5944. if (isset($pl['opt']['ap'])) {
  5945. // appearance stream
  5946. $annots .= ' /AP <<';
  5947. if (is_array($pl['opt']['ap'])) {
  5948. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  5949. // $apmode can be: n = normal; r = rollover; d = down;
  5950. $annots .= ' /'.strtoupper($apmode);
  5951. if (is_array($apdef)) {
  5952. $annots .= ' <<';
  5953. foreach ($apdef as $apstate => $stream) {
  5954. // reference to XObject that define the appearance for this mode-state
  5955. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  5956. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  5957. }
  5958. $annots .= ' >>';
  5959. } else {
  5960. // reference to XObject that define the appearance for this mode
  5961. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  5962. $annots .= ' '.$apsobjid.' 0 R';
  5963. }
  5964. }
  5965. } else {
  5966. $annots .= $pl['opt']['ap'];
  5967. }
  5968. $annots .= ' >>';
  5969. }
  5970. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  5971. $annots .= ' /BS <<';
  5972. $annots .= ' /Type /Border';
  5973. if (isset($pl['opt']['bs']['w'])) {
  5974. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  5975. }
  5976. $bstyles = array('S', 'D', 'B', 'I', 'U');
  5977. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  5978. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  5979. }
  5980. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  5981. $annots .= ' /D [';
  5982. foreach ($pl['opt']['bs']['d'] as $cord) {
  5983. $annots .= ' '.intval($cord);
  5984. }
  5985. $annots .= ']';
  5986. }
  5987. $annots .= ' >>';
  5988. } else {
  5989. $annots .= ' /Border [';
  5990. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  5991. $annots .= intval($pl['opt']['border'][0]).' ';
  5992. $annots .= intval($pl['opt']['border'][1]).' ';
  5993. $annots .= intval($pl['opt']['border'][2]);
  5994. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  5995. $annots .= ' [';
  5996. foreach ($pl['opt']['border'][3] as $dash) {
  5997. $annots .= intval($dash).' ';
  5998. }
  5999. $annots .= ']';
  6000. }
  6001. } else {
  6002. $annots .= '0 0 0';
  6003. }
  6004. $annots .= ']';
  6005. }
  6006. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  6007. $annots .= ' /BE <<';
  6008. $bstyles = array('S', 'C');
  6009. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $markups)) {
  6010. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  6011. } else {
  6012. $annots .= ' /S /S';
  6013. }
  6014. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  6015. $annots .= ' /I '.sprintf(' %.4F', $pl['opt']['be']['i']);
  6016. }
  6017. $annots .= '>>';
  6018. }
  6019. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  6020. $annots .= ' /C [';
  6021. foreach ($pl['opt']['c'] as $col) {
  6022. $col = intval($col);
  6023. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  6024. $annots .= sprintf(' %.4F', $color);
  6025. }
  6026. $annots .= ']';
  6027. }
  6028. //$annots .= ' /StructParent ';
  6029. //$annots .= ' /OC ';
  6030. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  6031. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  6032. // this is a markup type
  6033. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  6034. $annots .= ' /T '.$this->_textannobjstring($pl['opt']['t']);
  6035. }
  6036. //$annots .= ' /Popup ';
  6037. if (isset($pl['opt']['ca'])) {
  6038. $annots .= ' /CA '.sprintf('%.4F', floatval($pl['opt']['ca']));
  6039. }
  6040. if (isset($pl['opt']['rc'])) {
  6041. $annots .= ' /RC '.$this->_textannobjstring($pl['opt']['rc']);
  6042. }
  6043. $annots .= ' /CreationDate '.$this->_datestring();
  6044. //$annots .= ' /IRT ';
  6045. if (isset($pl['opt']['subj'])) {
  6046. $annots .= ' /Subj '.$this->_textannobjstring($pl['opt']['subj']);
  6047. }
  6048. //$annots .= ' /RT ';
  6049. //$annots .= ' /IT ';
  6050. //$annots .= ' /ExData ';
  6051. }
  6052. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  6053. switch (strtolower($pl['opt']['subtype'])) {
  6054. case 'text': {
  6055. if (isset($pl['opt']['open'])) {
  6056. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  6057. }
  6058. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  6059. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  6060. $annots .= ' /Name /'.$pl['opt']['name'];
  6061. } else {
  6062. $annots .= ' /Name /Note';
  6063. }
  6064. $statemodels = array('Marked', 'Review');
  6065. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  6066. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  6067. } else {
  6068. $pl['opt']['statemodel'] = 'Marked';
  6069. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  6070. }
  6071. if ($pl['opt']['statemodel'] == 'Marked') {
  6072. $states = array('Accepted', 'Unmarked');
  6073. } else {
  6074. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  6075. }
  6076. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  6077. $annots .= ' /State /'.$pl['opt']['state'];
  6078. } else {
  6079. if ($pl['opt']['statemodel'] == 'Marked') {
  6080. $annots .= ' /State /Unmarked';
  6081. } else {
  6082. $annots .= ' /State /None';
  6083. }
  6084. }
  6085. break;
  6086. }
  6087. case 'link': {
  6088. if(is_string($pl['txt'])) {
  6089. // external URI link
  6090. $annots .= ' /A <</S /URI /URI '.$this->_dataannobjstring($this->unhtmlentities($pl['txt'])).'>>';
  6091. } else {
  6092. // internal link
  6093. $l = $this->links[$pl['txt']];
  6094. $annots .= sprintf(' /Dest [%d 0 R /XYZ 0 %.2F null]', (1 + (2 * $l[0])), ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  6095. }
  6096. $hmodes = array('N', 'I', 'O', 'P');
  6097. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  6098. $annots .= ' /H /'.$pl['opt']['h'];
  6099. } else {
  6100. $annots .= ' /H /I';
  6101. }
  6102. //$annots .= ' /PA ';
  6103. //$annots .= ' /Quadpoints ';
  6104. break;
  6105. }
  6106. case 'freetext': {
  6107. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  6108. $annots .= ' /DA ('.$pl['opt']['da'].')';
  6109. }
  6110. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  6111. $annots .= ' /Q '.intval($pl['opt']['q']);
  6112. }
  6113. if (isset($pl['opt']['rc'])) {
  6114. $annots .= ' /RC '.$this->_textannobjstring($pl['opt']['rc']);
  6115. }
  6116. if (isset($pl['opt']['ds'])) {
  6117. $annots .= ' /DS '.$this->_textannobjstring($pl['opt']['ds']);
  6118. }
  6119. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  6120. $annots .= ' /CL [';
  6121. foreach ($pl['opt']['cl'] as $cl) {
  6122. $annots .= sprintf('%.4F ', $cl * $this->k);
  6123. }
  6124. $annots .= ']';
  6125. }
  6126. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  6127. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  6128. $annots .= ' /IT '.$pl['opt']['it'];
  6129. }
  6130. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  6131. $l = $pl['opt']['rd'][0] * $this->k;
  6132. $r = $pl['opt']['rd'][1] * $this->k;
  6133. $t = $pl['opt']['rd'][2] * $this->k;
  6134. $b = $pl['opt']['rd'][3] * $this->k;
  6135. $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b).']';
  6136. }
  6137. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  6138. $annots .= ' /LE /'.$pl['opt']['le'];
  6139. }
  6140. break;
  6141. }
  6142. case 'line': {
  6143. break;
  6144. }
  6145. case 'square': {
  6146. break;
  6147. }
  6148. case 'circle': {
  6149. break;
  6150. }
  6151. case 'polygon': {
  6152. break;
  6153. }
  6154. case 'polyline': {
  6155. break;
  6156. }
  6157. case 'highlight': {
  6158. break;
  6159. }
  6160. case 'underline': {
  6161. break;
  6162. }
  6163. case 'squiggly': {
  6164. break;
  6165. }
  6166. case 'strikeout': {
  6167. break;
  6168. }
  6169. case 'stamp': {
  6170. break;
  6171. }
  6172. case 'caret': {
  6173. break;
  6174. }
  6175. case 'ink': {
  6176. break;
  6177. }
  6178. case 'popup': {
  6179. break;
  6180. }
  6181. case 'fileattachment': {
  6182. if (!isset($pl['opt']['fs'])) {
  6183. break;
  6184. }
  6185. $filename = basename($pl['opt']['fs']);
  6186. if (isset($this->embeddedfiles[$filename]['n'])) {
  6187. $annots .= ' /FS <</Type /Filespec /F '.$this->_dataannobjstring($filename).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  6188. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  6189. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  6190. $annots .= ' /Name /'.$pl['opt']['name'];
  6191. } else {
  6192. $annots .= ' /Name /PushPin';
  6193. }
  6194. }
  6195. break;
  6196. }
  6197. case 'sound': {
  6198. if (!isset($pl['opt']['fs'])) {
  6199. break;
  6200. }
  6201. $filename = basename($pl['opt']['fs']);
  6202. if (isset($this->embeddedfiles[$filename]['n'])) {
  6203. // ... TO BE COMPLETED ...
  6204. // /R /C /B /E /CO /CP
  6205. $annots .= ' /Sound <</Type /Filespec /F '.$this->_dataannobjstring($filename).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  6206. $iconsapp = array('Speaker', 'Mic');
  6207. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  6208. $annots .= ' /Name /'.$pl['opt']['name'];
  6209. } else {
  6210. $annots .= ' /Name /Speaker';
  6211. }
  6212. }
  6213. break;
  6214. }
  6215. case 'movie': {
  6216. break;
  6217. }
  6218. case 'widget': {
  6219. $hmode = array('N', 'I', 'O', 'P', 'T');
  6220. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  6221. $annots .= ' /H /'.$pl['opt']['h'];
  6222. }
  6223. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  6224. $annots .= ' /MK <<';
  6225. if (isset($pl['opt']['mk']['r'])) {
  6226. $annots .= ' /R '.$pl['opt']['mk']['r'];
  6227. }
  6228. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  6229. $annots .= ' /BC [';
  6230. foreach($pl['opt']['mk']['bc'] AS $col) {
  6231. $col = intval($col);
  6232. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  6233. $annots .= sprintf(' %.2F', $color);
  6234. }
  6235. $annots .= ']';
  6236. }
  6237. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  6238. $annots .= ' /BG [';
  6239. foreach($pl['opt']['mk']['bg'] AS $col) {
  6240. $col = intval($col);
  6241. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  6242. $annots .= sprintf(' %.2F', $color);
  6243. }
  6244. $annots .= ']';
  6245. }
  6246. if (isset($pl['opt']['mk']['ca'])) {
  6247. $annots .= ' /CA '.$pl['opt']['mk']['ca'].'';
  6248. }
  6249. if (isset($pl['opt']['mk']['rc'])) {
  6250. $annots .= ' /RC '.$pl['opt']['mk']['ca'].'';
  6251. }
  6252. if (isset($pl['opt']['mk']['ac'])) {
  6253. $annots .= ' /AC '.$pl['opt']['mk']['ca'].'';
  6254. }
  6255. if (isset($pl['opt']['mk']['i'])) {
  6256. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  6257. if ($info !== false) {
  6258. $annots .= ' /I '.$info['n'].' 0 R';
  6259. }
  6260. }
  6261. if (isset($pl['opt']['mk']['ri'])) {
  6262. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  6263. if ($info !== false) {
  6264. $annots .= ' /RI '.$info['n'].' 0 R';
  6265. }
  6266. }
  6267. if (isset($pl['opt']['mk']['ix'])) {
  6268. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  6269. if ($info !== false) {
  6270. $annots .= ' /IX '.$info['n'].' 0 R';
  6271. }
  6272. }
  6273. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  6274. $annots .= ' /IF <<';
  6275. $if_sw = array('A', 'B', 'S', 'N');
  6276. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  6277. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  6278. }
  6279. $if_s = array('A', 'P');
  6280. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  6281. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  6282. }
  6283. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  6284. $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  6285. }
  6286. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  6287. $annots .= ' /FB true';
  6288. }
  6289. $annots .= '>>';
  6290. }
  6291. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  6292. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  6293. } else {
  6294. $annots .= ' /TP 0';
  6295. }
  6296. $annots .= '>>';
  6297. } // end MK
  6298. // --- Entries for field dictionaries ---
  6299. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  6300. // set parent
  6301. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  6302. }
  6303. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  6304. $annots .= ' /T '.$this->_dataannobjstring($pl['opt']['t']);
  6305. }
  6306. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  6307. $annots .= ' /TU '.$this->_dataannobjstring($pl['opt']['tu']);
  6308. }
  6309. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  6310. $annots .= ' /TM '.$this->_dataannobjstring($pl['opt']['tm']);
  6311. }
  6312. if (isset($pl['opt']['ff'])) {
  6313. if (is_array($pl['opt']['ff'])) {
  6314. // array of bit settings
  6315. $flag = 0;
  6316. foreach($pl['opt']['ff'] as $val) {
  6317. $flag += 1 << ($val - 1);
  6318. }
  6319. } else {
  6320. $flag = intval($pl['opt']['ff']);
  6321. }
  6322. $annots .= ' /Ff '.$flag;
  6323. }
  6324. if (isset($pl['opt']['maxlen'])) {
  6325. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  6326. }
  6327. if (isset($pl['opt']['v'])) {
  6328. $annots .= ' /V';
  6329. if (is_array($pl['opt']['v'])) {
  6330. foreach ($pl['opt']['v'] AS $optval) {
  6331. if (is_float($optval)) {
  6332. $optval = sprintf('%.2F', $optval);
  6333. }
  6334. $annots .= ' '.$optval;
  6335. }
  6336. } else {
  6337. $annots .= ' '.$this->_textannobjstring($pl['opt']['v']);
  6338. }
  6339. }
  6340. if (isset($pl['opt']['dv'])) {
  6341. $annots .= ' /DV';
  6342. if (is_array($pl['opt']['dv'])) {
  6343. foreach ($pl['opt']['dv'] AS $optval) {
  6344. if (is_float($optval)) {
  6345. $optval = sprintf('%.2F', $optval);
  6346. }
  6347. $annots .= ' '.$optval;
  6348. }
  6349. } else {
  6350. $annots .= ' '.$this->_textannobjstring($pl['opt']['dv']);
  6351. }
  6352. }
  6353. if (isset($pl['opt']['rv'])) {
  6354. $annots .= ' /RV';
  6355. if (is_array($pl['opt']['rv'])) {
  6356. foreach ($pl['opt']['rv'] AS $optval) {
  6357. if (is_float($optval)) {
  6358. $optval = sprintf('%.2F', $optval);
  6359. }
  6360. $annots .= ' '.$optval;
  6361. }
  6362. } else {
  6363. $annots .= ' '.$this->_textannobjstring($pl['opt']['rv']);
  6364. }
  6365. }
  6366. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  6367. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  6368. }
  6369. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  6370. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  6371. }
  6372. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  6373. $annots .= ' /DA ('.$pl['opt']['da'].')';
  6374. }
  6375. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  6376. $annots .= ' /Q '.intval($pl['opt']['q']);
  6377. }
  6378. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  6379. $annots .= ' /Opt [';
  6380. foreach($pl['opt']['opt'] AS $copt) {
  6381. if (is_array($copt)) {
  6382. $annots .= ' ['.$this->_textannobjstring($copt[0]).' '.$this->_textannobjstring($copt[1]).']';
  6383. } else {
  6384. $annots .= ' '.$this->_textannobjstring($copt);
  6385. }
  6386. }
  6387. $annots .= ']';
  6388. }
  6389. if (isset($pl['opt']['ti'])) {
  6390. $annots .= ' /TI '.intval($pl['opt']['ti']);
  6391. }
  6392. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  6393. $annots .= ' /I [';
  6394. foreach($pl['opt']['i'] AS $copt) {
  6395. $annots .= intval($copt).' ';
  6396. }
  6397. $annots .= ']';
  6398. }
  6399. break;
  6400. }
  6401. case 'screen': {
  6402. break;
  6403. }
  6404. case 'printermark': {
  6405. break;
  6406. }
  6407. case 'trapnet': {
  6408. break;
  6409. }
  6410. case 'watermark': {
  6411. break;
  6412. }
  6413. case '3d': {
  6414. break;
  6415. }
  6416. default: {
  6417. break;
  6418. }
  6419. }
  6420. $annots .= '>>';
  6421. // create new annotation object
  6422. ++$this->annot_obj_id;
  6423. $this->offsets[$this->annot_obj_id] = $this->bufferlen;
  6424. $this->_out($this->annot_obj_id.' 0 obj');
  6425. $this->_out($annots);
  6426. $this->_out('endobj');
  6427. if ($formfield AND ! isset($this->radiobutton_groups[$n][$pl['txt']])) {
  6428. // store reference of form object
  6429. $this->form_obj_id[] = $this->annot_obj_id;
  6430. }
  6431. }
  6432. }
  6433. } // end for each page
  6434. }
  6435. /**
  6436. * Put appearance streams XObject used to define annotation's appearance states
  6437. * @param int $w annotation width
  6438. * @param int $h annotation height
  6439. * @param string $stream appearance stream
  6440. * @return int object ID
  6441. * @access protected
  6442. * @since 4.8.001 (2009-09-09)
  6443. */
  6444. protected function _putAPXObject($w=0, $h=0, $stream='') {
  6445. $stream = trim($stream);
  6446. ++$this->apxo_obj_id;
  6447. $this->offsets[$this->apxo_obj_id] = $this->bufferlen;
  6448. $this->_out($this->apxo_obj_id.' 0 obj');
  6449. $this->_out('<<');
  6450. $this->_out('/Type /XObject');
  6451. $this->_out('/Subtype /Form');
  6452. $this->_out('/FormType 1');
  6453. if ($this->compress) {
  6454. $stream = gzcompress($stream);
  6455. $this->_out('/Filter /FlateDecode');
  6456. }
  6457. $rect = sprintf('%.2F %.2F', $w, $h);
  6458. $this->_out('/BBox [0 0 '.$rect.']');
  6459. $this->_out('/Matrix [1 0 0 1 0 0]');
  6460. $this->_out('/Resources <</ProcSet [/PDF]>>');
  6461. $this->_out('/Length '.strlen($stream));
  6462. $this->_out('>>');
  6463. $this->_putstream($stream);
  6464. $this->_out('endobj');
  6465. return $this->apxo_obj_id;
  6466. }
  6467. /**
  6468. * Output fonts.
  6469. * @access protected
  6470. */
  6471. protected function _putfonts() {
  6472. $nf = $this->n;
  6473. foreach ($this->diffs as $diff) {
  6474. //Encodings
  6475. $this->_newobj();
  6476. $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  6477. $this->_out('endobj');
  6478. }
  6479. $mqr = $this->get_mqr();
  6480. $this->set_mqr(false);
  6481. foreach ($this->FontFiles as $file => $info) {
  6482. // search and get font file to embedd
  6483. $fontdir = $info['fontdir'];
  6484. $file = strtolower($file);
  6485. $fontfile = '';
  6486. // search files on various directories
  6487. if (($fontdir !== false) AND file_exists($fontdir.$file)) {
  6488. $fontfile = $fontdir.$file;
  6489. } elseif (file_exists($this->_getfontpath().$file)) {
  6490. $fontfile = $this->_getfontpath().$file;
  6491. } elseif (file_exists($file)) {
  6492. $fontfile = $file;
  6493. }
  6494. if (!$this->empty_string($fontfile)) {
  6495. $font = file_get_contents($fontfile);
  6496. $compressed = (substr($file, -2) == '.z');
  6497. if ((!$compressed) AND (isset($info['length2']))) {
  6498. $header = (ord($font{0}) == 128);
  6499. if ($header) {
  6500. //Strip first binary header
  6501. $font = substr($font, 6);
  6502. }
  6503. if ($header AND (ord($font{$info['length1']}) == 128)) {
  6504. //Strip second binary header
  6505. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  6506. }
  6507. }
  6508. $this->_newobj();
  6509. $this->FontFiles[$file]['n'] = $this->n;
  6510. $this->_out('<</Length '.strlen($font));
  6511. if ($compressed) {
  6512. $this->_out('/Filter /FlateDecode');
  6513. }
  6514. $this->_out('/Length1 '.$info['length1']);
  6515. if (isset($info['length2'])) {
  6516. $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  6517. }
  6518. $this->_out('>>');
  6519. $this->_putstream($font);
  6520. $this->_out('endobj');
  6521. }
  6522. }
  6523. $this->set_mqr($mqr);
  6524. foreach ($this->fontkeys as $k) {
  6525. //Font objects
  6526. $this->setFontSubBuffer($k, 'n', $this->n + 1);
  6527. $font = $this->getFontBuffer($k);
  6528. $type = $font['type'];
  6529. $name = $font['name'];
  6530. if ($type == 'core') {
  6531. //Standard font
  6532. $obj_id = $this->_newobj();
  6533. $this->_out('<</Type /Font');
  6534. $this->_out('/Subtype /Type1');
  6535. $this->_out('/BaseFont /'.$name);
  6536. $this->_out('/Name /F'.$font['i']);
  6537. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  6538. $this->_out('/Encoding /WinAnsiEncoding');
  6539. }
  6540. if (strtolower($name) == 'helvetica') {
  6541. // add default font for annotations
  6542. $this->annotation_fonts['helvetica'] = $k;
  6543. }
  6544. $this->_out('>>');
  6545. $this->_out('endobj');
  6546. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  6547. //Additional Type1 or TrueType font
  6548. $obj_id = $this->_newobj();
  6549. $this->_out('<</Type /Font');
  6550. $this->_out('/Subtype /'.$type);
  6551. $this->_out('/BaseFont /'.$name);
  6552. $this->_out('/Name /F'.$font['i']);
  6553. $this->_out('/FirstChar 32 /LastChar 255');
  6554. $this->_out('/Widths '.($this->n + 1).' 0 R');
  6555. $this->_out('/FontDescriptor '.($this->n + 2).' 0 R');
  6556. if ($font['enc']) {
  6557. if (isset($font['diff'])) {
  6558. $this->_out('/Encoding '.($nf + $font['diff']).' 0 R');
  6559. } else {
  6560. $this->_out('/Encoding /WinAnsiEncoding');
  6561. }
  6562. }
  6563. $this->_out('>>');
  6564. $this->_out('endobj');
  6565. // Widths
  6566. $this->_newobj();
  6567. $cw = &$font['cw'];
  6568. $s = '[';
  6569. for ($i = 32; $i < 256; ++$i) {
  6570. $s .= $cw[$i].' ';
  6571. }
  6572. $this->_out($s.']');
  6573. $this->_out('endobj');
  6574. //Descriptor
  6575. $this->_newobj();
  6576. $s = '<</Type /FontDescriptor /FontName /'.$name;
  6577. foreach ($font['desc'] as $fdk => $fdv) {
  6578. if(is_float($fdv)) {
  6579. $fdv = sprintf('%.3F', $fdv);
  6580. }
  6581. $s .= ' /'.$fdk.' '.$fdv.'';
  6582. }
  6583. if (!$this->empty_string($font['file'])) {
  6584. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  6585. }
  6586. $this->_out($s.'>>');
  6587. $this->_out('endobj');
  6588. } else {
  6589. //Allow for additional types
  6590. $mtd = '_put'.strtolower($type);
  6591. if (!method_exists($this, $mtd)) {
  6592. $this->Error('Unsupported font type: '.$type);
  6593. }
  6594. $obj_id = $this->$mtd($font);
  6595. }
  6596. // store object ID for current font
  6597. $this->font_obj_ids[$k] = $obj_id;
  6598. }
  6599. }
  6600. /**
  6601. * Outputs font widths
  6602. * @parameter array $font font data
  6603. * @parameter int $cidoffset offset for CID values
  6604. * @author Nicola Asuni
  6605. * @access protected
  6606. * @since 4.4.000 (2008-12-07)
  6607. */
  6608. protected function _putfontwidths($font, $cidoffset=0) {
  6609. ksort($font['cw']);
  6610. $rangeid = 0;
  6611. $range = array();
  6612. $prevcid = -2;
  6613. $prevwidth = -1;
  6614. $interval = false;
  6615. // for each character
  6616. foreach ($font['cw'] as $cid => $width) {
  6617. $cid -= $cidoffset;
  6618. if ($width != $font['dw']) {
  6619. if ($cid == ($prevcid + 1)) {
  6620. // consecutive CID
  6621. if ($width == $prevwidth) {
  6622. if ($width == $range[$rangeid][0]) {
  6623. $range[$rangeid][] = $width;
  6624. } else {
  6625. array_pop($range[$rangeid]);
  6626. // new range
  6627. $rangeid = $prevcid;
  6628. $range[$rangeid] = array();
  6629. $range[$rangeid][] = $prevwidth;
  6630. $range[$rangeid][] = $width;
  6631. }
  6632. $interval = true;
  6633. $range[$rangeid]['interval'] = true;
  6634. } else {
  6635. if ($interval) {
  6636. // new range
  6637. $rangeid = $cid;
  6638. $range[$rangeid] = array();
  6639. $range[$rangeid][] = $width;
  6640. } else {
  6641. $range[$rangeid][] = $width;
  6642. }
  6643. $interval = false;
  6644. }
  6645. } else {
  6646. // new range
  6647. $rangeid = $cid;
  6648. $range[$rangeid] = array();
  6649. $range[$rangeid][] = $width;
  6650. $interval = false;
  6651. }
  6652. $prevcid = $cid;
  6653. $prevwidth = $width;
  6654. }
  6655. }
  6656. // optimize ranges
  6657. $prevk = -1;
  6658. $nextk = -1;
  6659. $prevint = false;
  6660. foreach ($range as $k => $ws) {
  6661. $cws = count($ws);
  6662. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  6663. if (isset($range[$k]['interval'])) {
  6664. unset($range[$k]['interval']);
  6665. }
  6666. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  6667. unset($range[$k]);
  6668. } else {
  6669. $prevk = $k;
  6670. }
  6671. $nextk = $k + $cws;
  6672. if (isset($ws['interval'])) {
  6673. if ($cws > 3) {
  6674. $prevint = true;
  6675. } else {
  6676. $prevint = false;
  6677. }
  6678. unset($range[$k]['interval']);
  6679. --$nextk;
  6680. } else {
  6681. $prevint = false;
  6682. }
  6683. }
  6684. // output data
  6685. $w = '';
  6686. foreach ($range as $k => $ws) {
  6687. if (count(array_count_values($ws)) == 1) {
  6688. // interval mode is more compact
  6689. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  6690. } else {
  6691. // range mode
  6692. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
  6693. }
  6694. }
  6695. $this->_out('/W ['.$w.' ]');
  6696. }
  6697. /**
  6698. * Adds unicode fonts.<br>
  6699. * Based on PDF Reference 1.3 (section 5)
  6700. * @parameter array $font font data
  6701. * @return int font object ID
  6702. * @access protected
  6703. * @author Nicola Asuni
  6704. * @since 1.52.0.TC005 (2005-01-05)
  6705. */
  6706. protected function _puttruetypeunicode($font) {
  6707. // Type0 Font
  6708. // A composite font composed of other fonts, organized hierarchically
  6709. $obj_id = $this->_newobj();
  6710. $this->_out('<</Type /Font');
  6711. $this->_out('/Subtype /Type0');
  6712. $this->_out('/BaseFont /'.$font['name'].'');
  6713. $this->_out('/Name /F'.$font['i']);
  6714. $this->_out('/Encoding /'.$font['enc']);
  6715. $this->_out('/ToUnicode /Identity-H');
  6716. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  6717. $this->_out('>>');
  6718. $this->_out('endobj');
  6719. // CIDFontType2
  6720. // A CIDFont whose glyph descriptions are based on TrueType font technology
  6721. $this->_newobj();
  6722. $this->_out('<</Type /Font');
  6723. $this->_out('/Subtype /CIDFontType2');
  6724. $this->_out('/BaseFont /'.$font['name'].'');
  6725. // A dictionary containing entries that define the character collection of the CIDFont.
  6726. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry']);
  6727. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']);
  6728. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  6729. $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  6730. $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  6731. $this->_out('/DW '.$font['dw'].''); // default width
  6732. $this->_putfontwidths($font, 0);
  6733. $this->_out('/CIDToGIDMap '.($this->n + 2).' 0 R');
  6734. $this->_out('>>');
  6735. $this->_out('endobj');
  6736. // Font descriptor
  6737. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  6738. $this->_newobj();
  6739. $this->_out('<</Type /FontDescriptor');
  6740. $this->_out('/FontName /'.$font['name']);
  6741. foreach ($font['desc'] as $key => $value) {
  6742. if(is_float($value)) {
  6743. $value = sprintf('%.3F', $value);
  6744. }
  6745. $this->_out('/'.$key.' '.$value.'');
  6746. }
  6747. $fontdir = false;
  6748. if (!$this->empty_string($font['file'])) {
  6749. // A stream containing a TrueType font
  6750. $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
  6751. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  6752. }
  6753. $this->_out('>>');
  6754. $this->_out('endobj');
  6755. $this->_newobj();
  6756. if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
  6757. // Embed CIDToGIDMap
  6758. // A specification of the mapping from CIDs to glyph indices
  6759. // search and get CTG font file to embedd
  6760. $ctgfile = strtolower($font['ctg']);
  6761. // search and get ctg font file to embedd
  6762. $fontfile = '';
  6763. // search files on various directories
  6764. if (($fontdir !== false) AND file_exists($fontdir.$ctgfile)) {
  6765. $fontfile = $fontdir.$ctgfile;
  6766. } elseif (file_exists($this->_getfontpath().$ctgfile)) {
  6767. $fontfile = $this->_getfontpath().$ctgfile;
  6768. } elseif (file_exists($ctgfile)) {
  6769. $fontfile = $ctgfile;
  6770. }
  6771. if ($this->empty_string($fontfile)) {
  6772. $this->Error('Font file not found: '.$ctgfile);
  6773. }
  6774. $size = filesize($fontfile);
  6775. $this->_out('<</Length '.$size.'');
  6776. if (substr($fontfile, -2) == '.z') { // check file extension
  6777. // Decompresses data encoded using the public-domain
  6778. // zlib/deflate compression method, reproducing the
  6779. // original text or binary data
  6780. $this->_out('/Filter /FlateDecode');
  6781. }
  6782. $this->_out('>>');
  6783. $this->_putstream(file_get_contents($fontfile));
  6784. }
  6785. $this->_out('endobj');
  6786. return $obj_id;
  6787. }
  6788. /**
  6789. * Output CID-0 fonts.
  6790. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  6791. * @param array $font font data
  6792. * @return int font object ID
  6793. * @access protected
  6794. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  6795. * @since 3.2.000 (2008-06-23)
  6796. */
  6797. protected function _putcidfont0($font) {
  6798. $cidoffset = 0;
  6799. if (!isset($font['cw'][1])) {
  6800. $cidoffset = 31;
  6801. }
  6802. if (isset($font['cidinfo']['uni2cid'])) {
  6803. // convert unicode to cid.
  6804. $uni2cid = $font['cidinfo']['uni2cid'];
  6805. $cw = array();
  6806. foreach ($font['cw'] as $uni => $width) {
  6807. if (isset($uni2cid[$uni])) {
  6808. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  6809. } elseif ($uni < 256) {
  6810. $cw[$uni] = $width;
  6811. } // else unknown character
  6812. }
  6813. $font = array_merge($font, array('cw' => $cw));
  6814. }
  6815. $name = $font['name'];
  6816. $enc = $font['enc'];
  6817. if ($enc) {
  6818. $longname = $name.'-'.$enc;
  6819. } else {
  6820. $longname = $name;
  6821. }
  6822. $obj_id = $this->_newobj();
  6823. $this->_out('<</Type /Font');
  6824. $this->_out('/Subtype /Type0');
  6825. $this->_out('/BaseFont /'.$longname);
  6826. $this->_out('/Name /F'.$font['i']);
  6827. if ($enc) {
  6828. $this->_out('/Encoding /'.$enc);
  6829. }
  6830. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  6831. $this->_out('>>');
  6832. $this->_out('endobj');
  6833. $this->_newobj();
  6834. $this->_out('<</Type /Font');
  6835. $this->_out('/Subtype /CIDFontType0');
  6836. $this->_out('/BaseFont /'.$name);
  6837. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry']);
  6838. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']);
  6839. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  6840. $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  6841. $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  6842. $this->_out('/DW '.$font['dw']);
  6843. $this->_putfontwidths($font, $cidoffset);
  6844. $this->_out('>>');
  6845. $this->_out('endobj');
  6846. $this->_newobj();
  6847. $s = '<</Type /FontDescriptor /FontName /'.$name;
  6848. foreach ($font['desc'] as $k => $v) {
  6849. if ($k != 'Style') {
  6850. if(is_float($v)) {
  6851. $v = sprintf('%.3F', $v);
  6852. }
  6853. $s .= ' /'.$k.' '.$v.'';
  6854. }
  6855. }
  6856. $this->_out($s.'>>');
  6857. $this->_out('endobj');
  6858. return $obj_id;
  6859. }
  6860. /**
  6861. * Output images.
  6862. * @access protected
  6863. */
  6864. protected function _putimages() {
  6865. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  6866. foreach ($this->imagekeys as $file) {
  6867. $info = $this->getImageBuffer($file);
  6868. $this->_newobj();
  6869. $this->setImageSubBuffer($file, 'n', $this->n);
  6870. $this->_out('<</Type /XObject');
  6871. $this->_out('/Subtype /Image');
  6872. $this->_out('/Width '.$info['w']);
  6873. $this->_out('/Height '.$info['h']);
  6874. if (array_key_exists('masked', $info)) {
  6875. $this->_out('/SMask '.($this->n - 1).' 0 R');
  6876. }
  6877. if ($info['cs'] == 'Indexed') {
  6878. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]');
  6879. } else {
  6880. $this->_out('/ColorSpace /'.$info['cs']);
  6881. if ($info['cs'] == 'DeviceCMYK') {
  6882. $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  6883. }
  6884. }
  6885. $this->_out('/BitsPerComponent '.$info['bpc']);
  6886. if (isset($info['f'])) {
  6887. $this->_out('/Filter /'.$info['f']);
  6888. }
  6889. if (isset($info['parms'])) {
  6890. $this->_out($info['parms']);
  6891. }
  6892. if (isset($info['trns']) AND is_array($info['trns'])) {
  6893. $trns='';
  6894. $count_info = count($info['trns']);
  6895. for ($i=0; $i < $count_info; ++$i) {
  6896. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  6897. }
  6898. $this->_out('/Mask ['.$trns.']');
  6899. }
  6900. $this->_out('/Length '.strlen($info['data']).'>>');
  6901. $this->_putstream($info['data']);
  6902. $this->_out('endobj');
  6903. //Palette
  6904. if ($info['cs'] == 'Indexed') {
  6905. $this->_newobj();
  6906. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  6907. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  6908. $this->_putstream($pal);
  6909. $this->_out('endobj');
  6910. }
  6911. }
  6912. }
  6913. /**
  6914. * Output Spot Colors Resources.
  6915. * @access protected
  6916. * @since 4.0.024 (2008-09-12)
  6917. */
  6918. protected function _putspotcolors() {
  6919. foreach ($this->spot_colors as $name => $color) {
  6920. $this->_newobj();
  6921. $this->spot_colors[$name]['n'] = $this->n;
  6922. $this->_out('[/Separation /'.str_replace(' ', '#20', $name));
  6923. $this->_out('/DeviceCMYK <<');
  6924. $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  6925. $this->_out(sprintf('/C1 [%.4F %.4F %.4F %.4F] ', $color['c']/100, $color['m']/100, $color['y']/100, $color['k']/100));
  6926. $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  6927. $this->_out('endobj');
  6928. }
  6929. }
  6930. /**
  6931. * Output object dictionary for images.
  6932. * @access protected
  6933. */
  6934. protected function _putxobjectdict() {
  6935. foreach ($this->imagekeys as $file) {
  6936. $info = $this->getImageBuffer($file);
  6937. $this->_out('/I'.$info['i'].' '.$info['n'].' 0 R');
  6938. }
  6939. }
  6940. /**
  6941. * Output Resources Dictionary.
  6942. * @access protected
  6943. */
  6944. protected function _putresourcedict() {
  6945. $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  6946. $this->_out('/Font <<');
  6947. foreach ($this->fontkeys as $fontkey) {
  6948. $font = $this->getFontBuffer($fontkey);
  6949. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  6950. }
  6951. $this->_out('>>');
  6952. $this->_out('/XObject <<');
  6953. $this->_putxobjectdict();
  6954. $this->_out('>>');
  6955. // visibility
  6956. $this->_out('/Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R>>');
  6957. // transparency
  6958. $this->_out('/ExtGState <<');
  6959. foreach ($this->extgstates as $k => $extgstate) {
  6960. $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  6961. }
  6962. $this->_out('>>');
  6963. // gradients
  6964. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  6965. $this->_out('/Shading <<');
  6966. foreach ($this->gradients as $id => $grad) {
  6967. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  6968. }
  6969. $this->_out('>>');
  6970. }
  6971. // spot colors
  6972. if (isset($this->spot_colors) AND (count($this->spot_colors) > 0)) {
  6973. $this->_out('/ColorSpace <<');
  6974. foreach ($this->spot_colors as $color) {
  6975. $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  6976. }
  6977. $this->_out('>>');
  6978. }
  6979. }
  6980. /**
  6981. * Output Resources.
  6982. * @access protected
  6983. */
  6984. protected function _putresources() {
  6985. $this->_putextgstates();
  6986. $this->_putocg();
  6987. $this->_putfonts();
  6988. $this->_putimages();
  6989. $this->_putspotcolors();
  6990. $this->_putshaders();
  6991. //Resource dictionary
  6992. $this->offsets[2] = $this->bufferlen;
  6993. $this->_out('2 0 obj');
  6994. $this->_out('<<');
  6995. $this->_putresourcedict();
  6996. $this->_out('>>');
  6997. $this->_out('endobj');
  6998. $this->_putbookmarks();
  6999. $this->_putEmbeddedFiles();
  7000. $this->_putannotsobjs();
  7001. $this->_putjavascript();
  7002. // encryption
  7003. if ($this->encrypted) {
  7004. $this->_newobj();
  7005. $this->enc_obj_id = $this->n;
  7006. $this->_out('<<');
  7007. $this->_putencryption();
  7008. $this->_out('>>');
  7009. $this->_out('endobj');
  7010. }
  7011. }
  7012. /**
  7013. * Adds some Metadata information (Document Information Dictionary)
  7014. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  7015. * @access protected
  7016. */
  7017. protected function _putinfo() {
  7018. if (!$this->empty_string($this->title)) {
  7019. // The document's title.
  7020. $this->_out('/Title '.$this->_textstring($this->title));
  7021. }
  7022. if (!$this->empty_string($this->author)) {
  7023. // The name of the person who created the document.
  7024. $this->_out('/Author '.$this->_textstring($this->author));
  7025. }
  7026. if (!$this->empty_string($this->subject)) {
  7027. // The subject of the document.
  7028. $this->_out('/Subject '.$this->_textstring($this->subject));
  7029. }
  7030. if (!$this->empty_string($this->keywords)) {
  7031. // Keywords associated with the document.
  7032. $this->_out('/Keywords '.$this->_textstring($this->keywords.' TCPDF'));
  7033. }
  7034. if (!$this->empty_string($this->creator)) {
  7035. // 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.
  7036. $this->_out('/Creator '.$this->_textstring($this->creator));
  7037. }
  7038. if (defined('PDF_PRODUCER')) {
  7039. // If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF.
  7040. $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER.' (TCPDF)'));
  7041. } else {
  7042. // default producer
  7043. $this->_out('/Producer '.$this->_textstring('TCPDF'));
  7044. }
  7045. // The date and time the document was created, in human-readable form
  7046. $this->_out('/CreationDate '.$this->_datestring());
  7047. // The date and time the document was most recently modified, in human-readable form
  7048. $this->_out('/ModDate '.$this->_datestring());
  7049. // A name object indicating whether the document has been modified to include trapping information
  7050. //$this->_out('/Trapped /False');
  7051. }
  7052. /**
  7053. * Output Catalog.
  7054. * @access protected
  7055. */
  7056. protected function _putcatalog() {
  7057. $this->_out('/Type /Catalog');
  7058. $this->_out('/Pages 1 0 R');
  7059. if ($this->ZoomMode == 'fullpage') {
  7060. $this->_out('/OpenAction [3 0 R /Fit]');
  7061. } elseif ($this->ZoomMode == 'fullwidth') {
  7062. $this->_out('/OpenAction [3 0 R /FitH null]');
  7063. } elseif ($this->ZoomMode == 'real') {
  7064. $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  7065. } elseif (!is_string($this->ZoomMode)) {
  7066. $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode / 100).']');
  7067. }
  7068. if (isset($this->LayoutMode) AND (!$this->empty_string($this->LayoutMode))) {
  7069. $this->_out('/PageLayout /'.$this->LayoutMode.'');
  7070. }
  7071. if (isset($this->PageMode) AND (!$this->empty_string($this->PageMode))) {
  7072. $this->_out('/PageMode /'.$this->PageMode);
  7073. }
  7074. if (isset($this->l['a_meta_language'])) {
  7075. $this->_out('/Lang /'.$this->l['a_meta_language']);
  7076. }
  7077. $this->_out('/Names <<');
  7078. if ((!empty($this->javascript)) OR (!empty($this->js_objects))) {
  7079. $this->_out('/JavaScript '.($this->n_js).' 0 R');
  7080. }
  7081. $this->_out('>>');
  7082. if (count($this->outlines) > 0) {
  7083. $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  7084. $this->_out('/PageMode /UseOutlines');
  7085. }
  7086. $this->_putviewerpreferences();
  7087. $p = $this->n_ocg_print.' 0 R';
  7088. $v = $this->n_ocg_view.' 0 R';
  7089. $as = '<</Event /Print /OCGs ['.$p.' '.$v.'] /Category [/Print]>> <</Event /View /OCGs ['.$p.' '.$v.'] /Category [/View]>>';
  7090. $this->_out('/OCProperties <</OCGs ['.$p.' '.$v.'] /D <</ON ['.$p.'] /OFF ['.$v.'] /AS ['.$as.']>>>>');
  7091. // AcroForm
  7092. if (!empty($this->form_obj_id) OR ($this->sign AND isset($this->signature_data['cert_type']))) {
  7093. $this->_out('/AcroForm<<');
  7094. $objrefs = '';
  7095. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  7096. $objrefs .= $this->sig_obj_id.' 0 R';
  7097. }
  7098. if (!empty($this->form_obj_id)) {
  7099. foreach($this->form_obj_id as $objid) {
  7100. $objrefs .= ' '.$objid.' 0 R';
  7101. }
  7102. }
  7103. $this->_out('/Fields ['.$objrefs.']');
  7104. $this->_out('/NeedAppearances '.(empty($this->form_obj_id)?'false':'true'));
  7105. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  7106. $this->_out('/SigFlags 3');
  7107. }
  7108. //$this->_out('/CO ');
  7109. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  7110. $this->_out('/DR <<');
  7111. $this->_out('/Font <<');
  7112. foreach ($this->annotation_fonts as $font => $fontkey) {
  7113. $this->_out('/F'.($fontkey + 1).' '.$this->font_obj_ids[$font].' 0 R');
  7114. }
  7115. $this->_out('>>');
  7116. $this->_out('>>');
  7117. }
  7118. $this->_out('/DA (/F'.(array_search('helvetica', $this->fontkeys) + 1).' 0 Tf 0 g)');
  7119. $this->_out('/Q '.(($this->rtl)?'2':'0'));
  7120. //$this->_out('/XFA ');
  7121. $this->_out('>>');
  7122. // signatures
  7123. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  7124. if ($this->signature_data['cert_type'] > 0) {
  7125. $this->_out('/Perms<</DocMDP '.($this->sig_obj_id + 1).' 0 R>>');
  7126. } else {
  7127. $this->_out('/Perms<</UR3 '.($this->sig_obj_id + 1).' 0 R>>');
  7128. }
  7129. }
  7130. }
  7131. }
  7132. /**
  7133. * Output viewer preferences.
  7134. * @author Nicola asuni
  7135. * @since 3.1.000 (2008-06-09)
  7136. * @access protected
  7137. */
  7138. protected function _putviewerpreferences() {
  7139. $this->_out('/ViewerPreferences<<');
  7140. if ($this->rtl) {
  7141. $this->_out('/Direction /R2L');
  7142. } else {
  7143. $this->_out('/Direction /L2R');
  7144. }
  7145. if (isset($this->viewer_preferences['HideToolbar']) AND ($this->viewer_preferences['HideToolbar'])) {
  7146. $this->_out('/HideToolbar true');
  7147. }
  7148. if (isset($this->viewer_preferences['HideMenubar']) AND ($this->viewer_preferences['HideMenubar'])) {
  7149. $this->_out('/HideMenubar true');
  7150. }
  7151. if (isset($this->viewer_preferences['HideWindowUI']) AND ($this->viewer_preferences['HideWindowUI'])) {
  7152. $this->_out('/HideWindowUI true');
  7153. }
  7154. if (isset($this->viewer_preferences['FitWindow']) AND ($this->viewer_preferences['FitWindow'])) {
  7155. $this->_out('/FitWindow true');
  7156. }
  7157. if (isset($this->viewer_preferences['CenterWindow']) AND ($this->viewer_preferences['CenterWindow'])) {
  7158. $this->_out('/CenterWindow true');
  7159. }
  7160. if (isset($this->viewer_preferences['DisplayDocTitle']) AND ($this->viewer_preferences['DisplayDocTitle'])) {
  7161. $this->_out('/DisplayDocTitle true');
  7162. }
  7163. if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
  7164. $this->_out('/NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'].'');
  7165. }
  7166. if (isset($this->viewer_preferences['ViewArea'])) {
  7167. $this->_out('/ViewArea /'.$this->viewer_preferences['ViewArea']);
  7168. }
  7169. if (isset($this->viewer_preferences['ViewClip'])) {
  7170. $this->_out('/ViewClip /'.$this->viewer_preferences['ViewClip']);
  7171. }
  7172. if (isset($this->viewer_preferences['PrintArea'])) {
  7173. $this->_out('/PrintArea /'.$this->viewer_preferences['PrintArea']);
  7174. }
  7175. if (isset($this->viewer_preferences['PrintClip'])) {
  7176. $this->_out('/PrintClip /'.$this->viewer_preferences['PrintClip']);
  7177. }
  7178. if (isset($this->viewer_preferences['PrintScaling'])) {
  7179. $this->_out('/PrintScaling /'.$this->viewer_preferences['PrintScaling']);
  7180. }
  7181. if (isset($this->viewer_preferences['Duplex']) AND (!$this->empty_string($this->viewer_preferences['Duplex']))) {
  7182. $this->_out('/Duplex /'.$this->viewer_preferences['Duplex']);
  7183. }
  7184. if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
  7185. if ($this->viewer_preferences['PickTrayByPDFSize']) {
  7186. $this->_out('/PickTrayByPDFSize true');
  7187. } else {
  7188. $this->_out('/PickTrayByPDFSize false');
  7189. }
  7190. }
  7191. if (isset($this->viewer_preferences['PrintPageRange'])) {
  7192. $PrintPageRangeNum = '';
  7193. foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v) {
  7194. $PrintPageRangeNum .= ' '.($v - 1).'';
  7195. }
  7196. $this->_out('/PrintPageRange ['.substr($PrintPageRangeNum,1).']');
  7197. }
  7198. if (isset($this->viewer_preferences['NumCopies'])) {
  7199. $this->_out('/NumCopies '.intval($this->viewer_preferences['NumCopies']));
  7200. }
  7201. $this->_out('>>');
  7202. }
  7203. /**
  7204. * Output trailer.
  7205. * @access protected
  7206. */
  7207. protected function _puttrailer() {
  7208. $this->_out('/Size '.($this->n + 1));
  7209. $this->_out('/Root '.$this->n.' 0 R');
  7210. $this->_out('/Info '.($this->n - 1).' 0 R');
  7211. if ($this->encrypted) {
  7212. $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  7213. $this->_out('/ID [()()]');
  7214. }
  7215. }
  7216. /**
  7217. * Output PDF header.
  7218. * @access protected
  7219. */
  7220. protected function _putheader() {
  7221. $this->_out('%PDF-'.$this->PDFVersion);
  7222. }
  7223. /**
  7224. * Output end of document (EOF).
  7225. * @access protected
  7226. */
  7227. protected function _enddoc() {
  7228. $this->state = 1;
  7229. $this->_putheader();
  7230. $this->_putpages();
  7231. $this->_putresources();
  7232. // Signature
  7233. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  7234. // widget annotation for signature
  7235. $this->sig_obj_id = $this->_newobj();
  7236. // --- replace signature ID on the first page ---
  7237. // get the document content
  7238. $pdfdoc = $this->getBuffer();
  7239. // Remove the original buffer
  7240. if (isset($this->diskcache) AND $this->diskcache) {
  7241. // remove buffer file from cache
  7242. unlink($this->buffer);
  7243. }
  7244. unset($this->buffer);
  7245. $signature_widget_ref = sprintf('%u 0 R', $this->sig_obj_id);
  7246. $signature_widget_ref .= str_repeat(' ', (strlen($this->sig_annot_ref) - strlen($signature_widget_ref)));
  7247. $pdfdoc = str_replace($this->sig_annot_ref, $signature_widget_ref, $pdfdoc);
  7248. $this->diskcache = false;
  7249. $this->buffer = &$pdfdoc;
  7250. $this->bufferlen = strlen($pdfdoc);
  7251. // ---
  7252. $this->_out('<<');
  7253. $this->_out('/Type /Annot /Subtype /Widget /Rect [0 0 0 0]');
  7254. $this->_out('/P 3 0 R'); // link to first page object
  7255. $this->_out('/FT /Sig');
  7256. $this->_out('/T '.$this->_textstring('Signature'));
  7257. $this->_out('/Ff 0');
  7258. $this->_out('/V '.($this->sig_obj_id + 1).' 0 R');
  7259. $this->_out('>>');
  7260. $this->_out('endobj');
  7261. // signature
  7262. $this->_newobj();
  7263. $this->_out('<<');
  7264. $this->_putsignature();
  7265. $this->_out('>>');
  7266. $this->_out('endobj');
  7267. }
  7268. // Info
  7269. $this->_newobj();
  7270. $this->_out('<<');
  7271. $this->_putinfo();
  7272. $this->_out('>>');
  7273. $this->_out('endobj');
  7274. // Catalog
  7275. $this->_newobj();
  7276. $this->_out('<<');
  7277. $this->_putcatalog();
  7278. $this->_out('>>');
  7279. $this->_out('endobj');
  7280. // Cross-ref
  7281. $o = $this->bufferlen;
  7282. $this->_out('xref');
  7283. $this->_out('0 '.($this->n + 1));
  7284. $this->_out('0000000000 65535 f ');
  7285. for ($i=1; $i <= $this->n; ++$i) {
  7286. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  7287. }
  7288. // Embedded Files
  7289. if (isset($this->embeddedfiles) AND count($this->embeddedfiles) > 0) {
  7290. $this->_out($this->embedded_start_obj_id.' '.count($this->embeddedfiles));
  7291. foreach ($this->embeddedfiles as $filename => $filedata) {
  7292. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$filedata['n']]));
  7293. }
  7294. }
  7295. // Annotation Objects
  7296. if ($this->annot_obj_id > $this->annots_start_obj_id) {
  7297. $this->_out(($this->annots_start_obj_id + 1).' '.($this->annot_obj_id - $this->annots_start_obj_id));
  7298. for ($i = ($this->annots_start_obj_id + 1); $i <= $this->annot_obj_id; ++$i) {
  7299. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  7300. }
  7301. }
  7302. // Javascript Objects
  7303. if ($this->js_obj_id > $this->js_start_obj_id) {
  7304. $this->_out(($this->js_start_obj_id + 1).' '.($this->js_obj_id - $this->js_start_obj_id));
  7305. for ($i = ($this->js_start_obj_id + 1); $i <= $this->js_obj_id; ++$i) {
  7306. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  7307. }
  7308. }
  7309. // Appearance streams XObjects
  7310. if ($this->apxo_obj_id > $this->apxo_start_obj_id) {
  7311. $this->_out(($this->apxo_start_obj_id + 1).' '.($this->apxo_obj_id - $this->apxo_start_obj_id));
  7312. for ($i = ($this->apxo_start_obj_id + 1); $i <= $this->apxo_obj_id; ++$i) {
  7313. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  7314. }
  7315. }
  7316. //Trailer
  7317. $this->_out('trailer');
  7318. $this->_out('<<');
  7319. $this->_puttrailer();
  7320. $this->_out('>>');
  7321. $this->_out('startxref');
  7322. $this->_out($o);
  7323. $this->_out('%%EOF');
  7324. $this->state = 3; // end-of-doc
  7325. if ($this->diskcache) {
  7326. // remove temporary files used for images
  7327. foreach ($this->imagekeys as $key) {
  7328. // remove temporary files
  7329. unlink($this->images[$key]);
  7330. }
  7331. foreach ($this->fontkeys as $key) {
  7332. // remove temporary files
  7333. unlink($this->fonts[$key]);
  7334. }
  7335. }
  7336. }
  7337. /**
  7338. * Initialize a new page.
  7339. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  7340. * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  7341. * @access protected
  7342. */
  7343. protected function _beginpage($orientation='', $format='') {
  7344. ++$this->page;
  7345. $this->setPageBuffer($this->page, '');
  7346. // initialize array for graphics tranformation positions inside a page buffer
  7347. $this->transfmrk[$this->page] = array();
  7348. $this->state = 2;
  7349. if ($this->empty_string($orientation)) {
  7350. if (isset($this->CurOrientation)) {
  7351. $orientation = $this->CurOrientation;
  7352. } else {
  7353. $orientation = 'P';
  7354. }
  7355. }
  7356. if ($this->empty_string($format)) {
  7357. $this->setPageOrientation($orientation);
  7358. } else {
  7359. $this->setPageFormat($format, $orientation);
  7360. }
  7361. if ($this->rtl) {
  7362. $this->x = $this->w - $this->rMargin;
  7363. } else {
  7364. $this->x = $this->lMargin;
  7365. }
  7366. $this->y = $this->tMargin;
  7367. if (isset($this->newpagegroup[$this->page])) {
  7368. // start a new group
  7369. $n = sizeof($this->pagegroups) + 1;
  7370. $alias = '{nb'.$n.'}';
  7371. $this->pagegroups[$alias] = 1;
  7372. $this->currpagegroup = $alias;
  7373. } elseif ($this->currpagegroup) {
  7374. ++$this->pagegroups[$this->currpagegroup];
  7375. }
  7376. }
  7377. /**
  7378. * Mark end of page.
  7379. * @access protected
  7380. */
  7381. protected function _endpage() {
  7382. $this->setVisibility('all');
  7383. $this->state = 1;
  7384. }
  7385. /**
  7386. * Begin a new object and return the object number.
  7387. * @return int object number
  7388. * @access protected
  7389. */
  7390. protected function _newobj() {
  7391. ++$this->n;
  7392. $this->offsets[$this->n] = $this->bufferlen;
  7393. $this->_out($this->n.' 0 obj');
  7394. return $this->n;
  7395. }
  7396. /**
  7397. * Underline text.
  7398. * @param int $x X coordinate
  7399. * @param int $y Y coordinate
  7400. * @param string $txt text to underline
  7401. * @access protected
  7402. */
  7403. protected function _dounderline($x, $y, $txt) {
  7404. $w = $this->GetStringWidth($txt);
  7405. return $this->_dounderlinew($x, $y, $w);
  7406. }
  7407. /**
  7408. * Underline for rectangular text area.
  7409. * @param int $x X coordinate
  7410. * @param int $y Y coordinate
  7411. * @param int $w width to underline
  7412. * @access protected
  7413. * @since 4.8.008 (2009-09-29)
  7414. */
  7415. protected function _dounderlinew($x, $y, $w) {
  7416. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  7417. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - $y + ($linew / 2)) * $this->k, $w * $this->k, $linew);
  7418. }
  7419. /**
  7420. * Line through text.
  7421. * @param int $x X coordinate
  7422. * @param int $y Y coordinate
  7423. * @param string $txt text to linethrough
  7424. * @access protected
  7425. */
  7426. protected function _dolinethrough($x, $y, $txt) {
  7427. $w = $this->GetStringWidth($txt);
  7428. return $this->_dolinethroughw($x, $y, $w);
  7429. }
  7430. /**
  7431. * Line through for rectangular text area.
  7432. * @param int $x X coordinate
  7433. * @param int $y Y coordinate
  7434. * @param string $txt text to linethrough
  7435. * @access protected
  7436. * @since 4.9.008 (2009-09-29)
  7437. */
  7438. protected function _dolinethroughw($x, $y, $w) {
  7439. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  7440. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - $y + ($this->FontSize / 3) + ($linew / 2)) * $this->k, $w * $this->k, $linew);
  7441. }
  7442. /**
  7443. * Overline text.
  7444. * @param int $x X coordinate
  7445. * @param int $y Y coordinate
  7446. * @param string $txt text to overline
  7447. * @access protected
  7448. * @since 4.9.015 (2010-04-19)
  7449. */
  7450. protected function _dooverline($x, $y, $txt) {
  7451. $w = $this->GetStringWidth($txt);
  7452. return $this->_dooverlinew($x, $y, $w);
  7453. }
  7454. /**
  7455. * Overline for rectangular text area.
  7456. * @param int $x X coordinate
  7457. * @param int $y Y coordinate
  7458. * @param int $w width to overline
  7459. * @access protected
  7460. * @since 4.9.015 (2010-04-19)
  7461. */
  7462. protected function _dooverlinew($x, $y, $w) {
  7463. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  7464. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - $y + $this->FontAscent - ($linew / 2)) * $this->k, $w * $this->k, $linew);
  7465. }
  7466. /**
  7467. * Read a 4-byte integer from file.
  7468. * @param string $f file name.
  7469. * @return 4-byte integer
  7470. * @access protected
  7471. */
  7472. protected function _freadint($f) {
  7473. $a = unpack('Ni', fread($f, 4));
  7474. return $a['i'];
  7475. }
  7476. /**
  7477. * Add "\" before "\", "(" and ")"
  7478. * @param string $s string to escape.
  7479. * @return string escaped string.
  7480. * @access protected
  7481. */
  7482. protected function _escape($s) {
  7483. // the chr(13) substitution fixes the Bugs item #1421290.
  7484. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  7485. }
  7486. /**
  7487. * Format a data string for meta information
  7488. * @param string $s data string to escape.
  7489. * @return string escaped string.
  7490. * @access protected
  7491. */
  7492. protected function _datastring($s) {
  7493. if ($this->encrypted) {
  7494. $s = $this->_RC4($this->_objectkey($this->n), $s);
  7495. }
  7496. return '('. $this->_escape($s).')';
  7497. }
  7498. /**
  7499. * Format a data string for annotation objects
  7500. * @param string $s data string to escape.
  7501. * @return string escaped string.
  7502. * @access protected
  7503. */
  7504. protected function _dataannobjstring($s) {
  7505. if ($this->encrypted) {
  7506. $s = $this->_RC4($this->_objectkey($this->annot_obj_id + 1), $s);
  7507. }
  7508. return '('. $this->_escape($s).')';
  7509. }
  7510. /**
  7511. * Returns a formatted date for meta information
  7512. * @return string escaped date string.
  7513. * @access protected
  7514. * @since 4.6.028 (2009-08-25)
  7515. */
  7516. protected function _datestring() {
  7517. $current_time = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0).'\'';
  7518. return $this->_datastring('D:'.$current_time);
  7519. }
  7520. /**
  7521. * Format a text string for meta information
  7522. * @param string $s string to escape.
  7523. * @return string escaped string.
  7524. * @access protected
  7525. */
  7526. protected function _textstring($s) {
  7527. if ($this->isunicode) {
  7528. //Convert string to UTF-16BE
  7529. $s = $this->UTF8ToUTF16BE($s, true);
  7530. }
  7531. return $this->_datastring($s);
  7532. }
  7533. /**
  7534. * Format a UTF-8 text string for meta information on annotations
  7535. * @param string $s string to escape.
  7536. * @return string escaped string.
  7537. * @access protected
  7538. */
  7539. protected function _textannobjstring($s) {
  7540. if ($this->isunicode) {
  7541. //Convert string to UTF-16BE
  7542. $s = $this->UTF8ToUTF16BE($s, true);
  7543. }
  7544. return $this->_dataannobjstring($s);
  7545. }
  7546. /**
  7547. * Format a text string
  7548. * @param string $s string to escape.
  7549. * @return string escaped string.
  7550. * @access protected
  7551. */
  7552. protected function _escapetext($s) {
  7553. if ($this->isunicode) {
  7554. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  7555. $s = $this->UTF8ToLatin1($s);
  7556. } else {
  7557. //Convert string to UTF-16BE and reverse RTL language
  7558. $s = $this->utf8StrRev($s, false, $this->tmprtl);
  7559. }
  7560. }
  7561. return $this->_escape($s);
  7562. }
  7563. /**
  7564. * Output a stream.
  7565. * @param string $s string to output.
  7566. * @param int $n object reference for encryption mode
  7567. * @access protected
  7568. */
  7569. protected function _putstream($s, $n=0) {
  7570. if ($this->encrypted) {
  7571. if ($n <= 0) {
  7572. // default to current object
  7573. $n = $this->n;
  7574. }
  7575. $s = $this->_RC4($this->_objectkey($n), $s);
  7576. }
  7577. $this->_out('stream');
  7578. $this->_out($s);
  7579. $this->_out('endstream');
  7580. }
  7581. /**
  7582. * Output a string to the document.
  7583. * @param string $s string to output.
  7584. * @access protected
  7585. */
  7586. protected function _out($s) {
  7587. if ($this->state == 2) {
  7588. if ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  7589. // puts data before page footer
  7590. $pagebuff = $this->getPageBuffer($this->page);
  7591. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  7592. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  7593. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  7594. // update footer position
  7595. $this->footerpos[$this->page] += strlen($s."\n");
  7596. } else {
  7597. $this->setPageBuffer($this->page, $s."\n", true);
  7598. }
  7599. } else {
  7600. $this->setBuffer($s."\n");
  7601. }
  7602. }
  7603. /**
  7604. * Converts UTF-8 strings to codepoints array.<br>
  7605. * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  7606. * Based on: http://www.faqs.org/rfcs/rfc3629.html
  7607. * <pre>
  7608. * Char. number range | UTF-8 octet sequence
  7609. * (hexadecimal) | (binary)
  7610. * --------------------+-----------------------------------------------
  7611. * 0000 0000-0000 007F | 0xxxxxxx
  7612. * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  7613. * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  7614. * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  7615. * ---------------------------------------------------------------------
  7616. *
  7617. * ABFN notation:
  7618. * ---------------------------------------------------------------------
  7619. * UTF8-octets = *( UTF8-char )
  7620. * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  7621. * UTF8-1 = %x00-7F
  7622. * UTF8-2 = %xC2-DF UTF8-tail
  7623. *
  7624. * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  7625. * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  7626. * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  7627. * %xF4 %x80-8F 2( UTF8-tail )
  7628. * UTF8-tail = %x80-BF
  7629. * ---------------------------------------------------------------------
  7630. * </pre>
  7631. * @param string $str string to process.
  7632. * @return array containing codepoints (UTF-8 characters values)
  7633. * @access protected
  7634. * @author Nicola Asuni
  7635. * @since 1.53.0.TC005 (2005-01-05)
  7636. */
  7637. protected function UTF8StringToArray($str) {
  7638. if (isset($this->cache_UTF8StringToArray['_'.$str])) {
  7639. // return cached value
  7640. return($this->cache_UTF8StringToArray['_'.$str]);
  7641. }
  7642. // check cache size
  7643. if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) {
  7644. // remove first element
  7645. array_shift($this->cache_UTF8StringToArray);
  7646. }
  7647. ++$this->cache_size_UTF8StringToArray;
  7648. if (!$this->isunicode) {
  7649. // split string into array of equivalent codes
  7650. $strarr = array();
  7651. $strlen = strlen($str);
  7652. for ($i=0; $i < $strlen; ++$i) {
  7653. $strarr[] = ord($str{$i});
  7654. }
  7655. // insert new value on cache
  7656. $this->cache_UTF8StringToArray['_'.$str] = $strarr;
  7657. return $strarr;
  7658. }
  7659. $unicode = array(); // array containing unicode values
  7660. $bytes = array(); // array containing single character byte sequences
  7661. $numbytes = 1; // number of octetc needed to represent the UTF-8 character
  7662. $str .= ''; // force $str to be a string
  7663. $length = strlen($str);
  7664. for ($i = 0; $i < $length; ++$i) {
  7665. $char = ord($str{$i}); // get one string character at time
  7666. if (count($bytes) == 0) { // get starting octect
  7667. if ($char <= 0x7F) {
  7668. $unicode[] = $char; // use the character "as is" because is ASCII
  7669. $numbytes = 1;
  7670. } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
  7671. $bytes[] = ($char - 0xC0) << 0x06;
  7672. $numbytes = 2;
  7673. } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
  7674. $bytes[] = ($char - 0xE0) << 0x0C;
  7675. $numbytes = 3;
  7676. } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
  7677. $bytes[] = ($char - 0xF0) << 0x12;
  7678. $numbytes = 4;
  7679. } else {
  7680. // use replacement character for other invalid sequences
  7681. $unicode[] = 0xFFFD;
  7682. $bytes = array();
  7683. $numbytes = 1;
  7684. }
  7685. } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  7686. $bytes[] = $char - 0x80;
  7687. if (count($bytes) == $numbytes) {
  7688. // compose UTF-8 bytes to a single unicode value
  7689. $char = $bytes[0];
  7690. for ($j = 1; $j < $numbytes; ++$j) {
  7691. $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
  7692. }
  7693. if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  7694. /* The definition of UTF-8 prohibits encoding character numbers between
  7695. U+D800 and U+DFFF, which are reserved for use with the UTF-16
  7696. encoding form (as surrogate pairs) and do not directly represent
  7697. characters. */
  7698. $unicode[] = 0xFFFD; // use replacement character
  7699. } else {
  7700. $unicode[] = $char; // add char to array
  7701. }
  7702. // reset data for next char
  7703. $bytes = array();
  7704. $numbytes = 1;
  7705. }
  7706. } else {
  7707. // use replacement character for other invalid sequences
  7708. $unicode[] = 0xFFFD;
  7709. $bytes = array();
  7710. $numbytes = 1;
  7711. }
  7712. }
  7713. // insert new value on cache
  7714. $this->cache_UTF8StringToArray['_'.$str] = $unicode;
  7715. return $unicode;
  7716. }
  7717. /**
  7718. * Converts UTF-8 strings to UTF16-BE.<br>
  7719. * @param string $str string to process.
  7720. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  7721. * @return string
  7722. * @access protected
  7723. * @author Nicola Asuni
  7724. * @since 1.53.0.TC005 (2005-01-05)
  7725. * @uses UTF8StringToArray(), arrUTF8ToUTF16BE()
  7726. */
  7727. protected function UTF8ToUTF16BE($str, $setbom=true) {
  7728. if (!$this->isunicode) {
  7729. return $str; // string is not in unicode
  7730. }
  7731. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  7732. return $this->arrUTF8ToUTF16BE($unicode, $setbom);
  7733. }
  7734. /**
  7735. * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  7736. * @param string $str string to process.
  7737. * @return string
  7738. * @author Andrew Whitehead, Nicola Asuni
  7739. * @access protected
  7740. * @since 3.2.000 (2008-06-23)
  7741. */
  7742. protected function UTF8ToLatin1($str) {
  7743. global $utf8tolatin;
  7744. if (!$this->isunicode) {
  7745. return $str; // string is not in unicode
  7746. }
  7747. $outstr = ''; // string to be returned
  7748. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  7749. foreach ($unicode as $char) {
  7750. if ($char < 256) {
  7751. $outstr .= chr($char);
  7752. } elseif (array_key_exists($char, $utf8tolatin)) {
  7753. // map from UTF-8
  7754. $outstr .= chr($utf8tolatin[$char]);
  7755. } elseif ($char == 0xFFFD) {
  7756. // skip
  7757. } else {
  7758. $outstr .= '?';
  7759. }
  7760. }
  7761. return $outstr;
  7762. }
  7763. /**
  7764. * Converts UTF-8 characters array to array of Latin1 characters<br>
  7765. * @param array $unicode array containing UTF-8 unicode values
  7766. * @return array
  7767. * @author Nicola Asuni
  7768. * @access protected
  7769. * @since 4.8.023 (2010-01-15)
  7770. */
  7771. protected function UTF8ArrToLatin1($unicode) {
  7772. global $utf8tolatin;
  7773. if ((!$this->isunicode) OR ($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  7774. return $unicode; // string is not in unicode
  7775. }
  7776. $outarr = array(); // array to be returned
  7777. foreach ($unicode as $char) {
  7778. if ($char < 256) {
  7779. $outarr[] = $char;
  7780. } elseif (array_key_exists($char, $utf8tolatin)) {
  7781. // map from UTF-8
  7782. $outarr[] = $utf8tolatin[$char];
  7783. } elseif ($char == 0xFFFD) {
  7784. // skip
  7785. } else {
  7786. $outarr[] = 63; // '?' character
  7787. }
  7788. }
  7789. return $outarr;
  7790. }
  7791. /**
  7792. * Converts array of UTF-8 characters to UTF16-BE string.<br>
  7793. * Based on: http://www.faqs.org/rfcs/rfc2781.html
  7794. * <pre>
  7795. * Encoding UTF-16:
  7796. *
  7797. * Encoding of a single character from an ISO 10646 character value to
  7798. * UTF-16 proceeds as follows. Let U be the character number, no greater
  7799. * than 0x10FFFF.
  7800. *
  7801. * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  7802. * terminate.
  7803. *
  7804. * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  7805. * U' must be less than or equal to 0xFFFFF. That is, U' can be
  7806. * represented in 20 bits.
  7807. *
  7808. * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  7809. * 0xDC00, respectively. These integers each have 10 bits free to
  7810. * encode the character value, for a total of 20 bits.
  7811. *
  7812. * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  7813. * bits of W1 and the 10 low-order bits of U' to the 10 low-order
  7814. * bits of W2. Terminate.
  7815. *
  7816. * Graphically, steps 2 through 4 look like:
  7817. * U' = yyyyyyyyyyxxxxxxxxxx
  7818. * W1 = 110110yyyyyyyyyy
  7819. * W2 = 110111xxxxxxxxxx
  7820. * </pre>
  7821. * @param array $unicode array containing UTF-8 unicode values
  7822. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  7823. * @return string
  7824. * @access protected
  7825. * @author Nicola Asuni
  7826. * @since 2.1.000 (2008-01-08)
  7827. * @see UTF8ToUTF16BE()
  7828. */
  7829. protected function arrUTF8ToUTF16BE($unicode, $setbom=true) {
  7830. $outstr = ''; // string to be returned
  7831. if ($setbom) {
  7832. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  7833. }
  7834. foreach ($unicode as $char) {
  7835. if ($char == 0xFFFD) {
  7836. $outstr .= "\xFF\xFD"; // replacement character
  7837. } elseif ($char < 0x10000) {
  7838. $outstr .= chr($char >> 0x08);
  7839. $outstr .= chr($char & 0xFF);
  7840. } else {
  7841. $char -= 0x10000;
  7842. $w1 = 0xD800 | ($char >> 0x10);
  7843. $w2 = 0xDC00 | ($char & 0x3FF);
  7844. $outstr .= chr($w1 >> 0x08);
  7845. $outstr .= chr($w1 & 0xFF);
  7846. $outstr .= chr($w2 >> 0x08);
  7847. $outstr .= chr($w2 & 0xFF);
  7848. }
  7849. }
  7850. return $outstr;
  7851. }
  7852. // ====================================================
  7853. /**
  7854. * Set header font.
  7855. * @param array $font font
  7856. * @access public
  7857. * @since 1.1
  7858. */
  7859. public function setHeaderFont($font) {
  7860. $this->header_font = $font;
  7861. }
  7862. /**
  7863. * Get header font.
  7864. * @return array()
  7865. * @access public
  7866. * @since 4.0.012 (2008-07-24)
  7867. */
  7868. public function getHeaderFont() {
  7869. return $this->header_font;
  7870. }
  7871. /**
  7872. * Set footer font.
  7873. * @param array $font font
  7874. * @access public
  7875. * @since 1.1
  7876. */
  7877. public function setFooterFont($font) {
  7878. $this->footer_font = $font;
  7879. }
  7880. /**
  7881. * Get Footer font.
  7882. * @return array()
  7883. * @access public
  7884. * @since 4.0.012 (2008-07-24)
  7885. */
  7886. public function getFooterFont() {
  7887. return $this->footer_font;
  7888. }
  7889. /**
  7890. * Set language array.
  7891. * @param array $language
  7892. * @access public
  7893. * @since 1.1
  7894. */
  7895. public function setLanguageArray($language) {
  7896. $this->l = $language;
  7897. if (isset($this->l['a_meta_dir'])) {
  7898. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  7899. } else {
  7900. $this->rtl = false;
  7901. }
  7902. }
  7903. /**
  7904. * Returns the PDF data.
  7905. * @access public
  7906. */
  7907. public function getPDFData() {
  7908. if ($this->state < 3) {
  7909. $this->Close();
  7910. }
  7911. return $this->buffer;
  7912. }
  7913. /**
  7914. * Output anchor link.
  7915. * @param string $url link URL or internal link (i.e.: &lt;a href="#23"&gt;link to page 23&lt;/a&gt;)
  7916. * @param string $name link name
  7917. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  7918. * @param boolean $firstline if true prints only the first line and return the remaining string.
  7919. * @param array $color array of RGB text color
  7920. * @param string $style font style (U, D, B, I)
  7921. * @param boolean $firstblock if true the string is the starting of a line.
  7922. * @return the number of cells used or the remaining text if $firstline = true;
  7923. * @access public
  7924. */
  7925. public function addHtmlLink($url, $name, $fill=0, $firstline=false, $color='', $style=-1, $firstblock=false) {
  7926. if (!$this->empty_string($url) AND ($url{0} == '#')) {
  7927. // convert url to internal link
  7928. $page = intval(substr($url, 1));
  7929. $url = $this->AddLink();
  7930. $this->SetLink($url, 0, $page);
  7931. }
  7932. // store current settings
  7933. $prevcolor = $this->fgcolor;
  7934. $prevstyle = $this->FontStyle;
  7935. if (empty($color)) {
  7936. $this->SetTextColorArray($this->htmlLinkColorArray);
  7937. } else {
  7938. $this->SetTextColorArray($color);
  7939. }
  7940. if ($style == -1) {
  7941. $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  7942. } else {
  7943. $this->SetFont('', $this->FontStyle.$style);
  7944. }
  7945. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  7946. // restore settings
  7947. $this->SetFont('', $prevstyle);
  7948. $this->SetTextColorArray($prevcolor);
  7949. return $ret;
  7950. }
  7951. /**
  7952. * 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).
  7953. * @param string $color html color
  7954. * @return array RGB color or false in case of error.
  7955. * @access public
  7956. */
  7957. public function convertHTMLColorToDec($color='#FFFFFF') {
  7958. global $webcolor;
  7959. $returncolor = false;
  7960. $color = preg_replace('/[\s]*/', '', $color); // remove extra spaces
  7961. $color = strtolower($color);
  7962. if (($dotpos = strpos($color, '.')) !== false) {
  7963. // remove class parent (i.e.: color.red)
  7964. $color = substr($color, ($dotpos + 1));
  7965. }
  7966. if (strlen($color) == 0) {
  7967. return false;
  7968. }
  7969. if (substr($color, 0, 3) == 'rgb') {
  7970. $codes = substr($color, 4);
  7971. $codes = str_replace(')', '', $codes);
  7972. $returncolor = explode(',', $codes, 3);
  7973. return $returncolor;
  7974. }
  7975. if (substr($color, 0, 1) != '#') {
  7976. // decode color name
  7977. if (isset($webcolor[$color])) {
  7978. $color_code = $webcolor[$color];
  7979. } else {
  7980. return false;
  7981. }
  7982. } else {
  7983. $color_code = substr($color, 1);
  7984. }
  7985. switch (strlen($color_code)) {
  7986. case 3: {
  7987. // three-digit hexadecimal representation
  7988. $r = substr($color_code, 0, 1);
  7989. $g = substr($color_code, 1, 1);
  7990. $b = substr($color_code, 2, 1);
  7991. $returncolor['R'] = hexdec($r.$r);
  7992. $returncolor['G'] = hexdec($g.$g);
  7993. $returncolor['B'] = hexdec($b.$b);
  7994. break;
  7995. }
  7996. case 6: {
  7997. // six-digit hexadecimal representation
  7998. $returncolor['R'] = hexdec(substr($color_code, 0, 2));
  7999. $returncolor['G'] = hexdec(substr($color_code, 2, 2));
  8000. $returncolor['B'] = hexdec(substr($color_code, 4, 2));
  8001. break;
  8002. }
  8003. }
  8004. return $returncolor;
  8005. }
  8006. /**
  8007. * Converts pixels to User's Units.
  8008. * @param int $px pixels
  8009. * @return float value in user's unit
  8010. * @access public
  8011. * @see setImageScale(), getImageScale()
  8012. */
  8013. public function pixelsToUnits($px) {
  8014. return ($px / ($this->imgscale * $this->k));
  8015. }
  8016. /**
  8017. * Reverse function for htmlentities.
  8018. * Convert entities in UTF-8.
  8019. * @param $text_to_convert Text to convert.
  8020. * @return string converted
  8021. * @access public
  8022. */
  8023. public function unhtmlentities($text_to_convert) {
  8024. return html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  8025. }
  8026. // ENCRYPTION METHODS ----------------------------------
  8027. // SINCE 2.0.000 (2008-01-02)
  8028. /**
  8029. * Compute encryption key depending on object number where the encrypted data is stored
  8030. * @param int $n object number
  8031. * @access protected
  8032. * @since 2.0.000 (2008-01-02)
  8033. */
  8034. protected function _objectkey($n) {
  8035. return substr($this->_md5_16($this->encryption_key.pack('VXxx', $n)), 0, 10);
  8036. }
  8037. /**
  8038. * Put encryption on PDF document.
  8039. * @access protected
  8040. * @since 2.0.000 (2008-01-02)
  8041. */
  8042. protected function _putencryption() {
  8043. $this->_out('/Filter /Standard');
  8044. $this->_out('/V 1');
  8045. $this->_out('/R 2');
  8046. $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  8047. $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  8048. $this->_out('/P '.$this->Pvalue);
  8049. }
  8050. /**
  8051. * Returns the input text exrypted using RC4 algorithm and the specified key.
  8052. * RC4 is the standard encryption algorithm used in PDF format
  8053. * @param string $key encryption key
  8054. * @param String $text input text to be encrypted
  8055. * @return String encrypted text
  8056. * @access protected
  8057. * @since 2.0.000 (2008-01-02)
  8058. * @author Klemen Vodopivec
  8059. */
  8060. protected function _RC4($key, $text) {
  8061. if ($this->last_rc4_key != $key) {
  8062. $k = str_repeat($key, ((256 / strlen($key)) + 1));
  8063. $rc4 = range(0, 255);
  8064. $j = 0;
  8065. for ($i = 0; $i < 256; ++$i) {
  8066. $t = $rc4[$i];
  8067. $j = ($j + $t + ord($k{$i})) % 256;
  8068. $rc4[$i] = $rc4[$j];
  8069. $rc4[$j] = $t;
  8070. }
  8071. $this->last_rc4_key = $key;
  8072. $this->last_rc4_key_c = $rc4;
  8073. } else {
  8074. $rc4 = $this->last_rc4_key_c;
  8075. }
  8076. $len = strlen($text);
  8077. $a = 0;
  8078. $b = 0;
  8079. $out = '';
  8080. for ($i = 0; $i < $len; ++$i) {
  8081. $a = ($a + 1) % 256;
  8082. $t = $rc4[$a];
  8083. $b = ($b + $t) % 256;
  8084. $rc4[$a] = $rc4[$b];
  8085. $rc4[$b] = $t;
  8086. $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
  8087. $out .= chr(ord($text{$i}) ^ $k);
  8088. }
  8089. return $out;
  8090. }
  8091. /**
  8092. * Encrypts a string using MD5 and returns it's value as a binary string.
  8093. * @param string $str input string
  8094. * @return String MD5 encrypted binary string
  8095. * @access protected
  8096. * @since 2.0.000 (2008-01-02)
  8097. * @author Klemen Vodopivec
  8098. */
  8099. protected function _md5_16($str) {
  8100. return pack('H*', md5($str));
  8101. }
  8102. /**
  8103. * Compute O value (used for RC4 encryption)
  8104. * @param String $user_pass user password
  8105. * @param String $owner_pass user password
  8106. * @return String O value
  8107. * @access protected
  8108. * @since 2.0.000 (2008-01-02)
  8109. * @author Klemen Vodopivec
  8110. */
  8111. protected function _Ovalue($user_pass, $owner_pass) {
  8112. $tmp = $this->_md5_16($owner_pass);
  8113. $owner_RC4_key = substr($tmp, 0, 5);
  8114. return $this->_RC4($owner_RC4_key, $user_pass);
  8115. }
  8116. /**
  8117. * Compute U value (used for RC4 encryption)
  8118. * @return String U value
  8119. * @access protected
  8120. * @since 2.0.000 (2008-01-02)
  8121. * @author Klemen Vodopivec
  8122. */
  8123. protected function _Uvalue() {
  8124. return $this->_RC4($this->encryption_key, $this->padding);
  8125. }
  8126. /**
  8127. * Compute encryption key
  8128. * @param String $user_pass user password
  8129. * @param String $owner_pass user password
  8130. * @param String $protection protection type
  8131. * @access protected
  8132. * @since 2.0.000 (2008-01-02)
  8133. * @author Klemen Vodopivec
  8134. */
  8135. protected function _generateencryptionkey($user_pass, $owner_pass, $protection) {
  8136. // Pad passwords
  8137. $user_pass = substr($user_pass.$this->padding, 0, 32);
  8138. $owner_pass = substr($owner_pass.$this->padding, 0, 32);
  8139. // Compute O value
  8140. $this->Ovalue = $this->_Ovalue($user_pass, $owner_pass);
  8141. // Compute encyption key
  8142. $tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
  8143. $this->encryption_key = substr($tmp, 0, 5);
  8144. // Compute U value
  8145. $this->Uvalue = $this->_Uvalue();
  8146. // Compute P value
  8147. $this->Pvalue = -(($protection^255) + 1);
  8148. }
  8149. /**
  8150. * Set document protection
  8151. * The permission array is composed of values taken from the following ones:
  8152. * - copy: copy text and images to the clipboard
  8153. * - print: print the document
  8154. * - modify: modify it (except for annotations and forms)
  8155. * - annot-forms: add annotations and forms
  8156. * Remark: the protection against modification is for people who have the full Acrobat product.
  8157. * 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.
  8158. * 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.
  8159. * @param Array $permissions the set of permissions. Empty by default (only viewing is allowed). (print, modify, copy, annot-forms)
  8160. * @param String $user_pass user password. Empty by default.
  8161. * @param String $owner_pass owner password. If not specified, a random value is used.
  8162. * @access public
  8163. * @since 2.0.000 (2008-01-02)
  8164. * @author Klemen Vodopivec
  8165. */
  8166. public function SetProtection($permissions=array(), $user_pass='', $owner_pass=null) {
  8167. $options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32);
  8168. $protection = 192;
  8169. foreach ($permissions as $permission) {
  8170. if (!isset($options[$permission])) {
  8171. $this->Error('Incorrect permission: '.$permission);
  8172. }
  8173. $protection += $options[$permission];
  8174. }
  8175. if ($owner_pass === null) {
  8176. $owner_pass = uniqid(rand());
  8177. }
  8178. $this->encrypted = true;
  8179. $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
  8180. }
  8181. // END OF ENCRYPTION FUNCTIONS -------------------------
  8182. // START TRANSFORMATIONS SECTION -----------------------
  8183. /**
  8184. * Starts a 2D tranformation saving current graphic state.
  8185. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  8186. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  8187. * @access public
  8188. * @since 2.1.000 (2008-01-07)
  8189. * @see StartTransform(), StopTransform()
  8190. */
  8191. public function StartTransform() {
  8192. $this->_out('q');
  8193. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  8194. ++$this->transfmatrix_key;
  8195. $this->transfmatrix[$this->transfmatrix_key] = array();
  8196. }
  8197. /**
  8198. * Stops a 2D tranformation restoring previous graphic state.
  8199. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  8200. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  8201. * @access public
  8202. * @since 2.1.000 (2008-01-07)
  8203. * @see StartTransform(), StopTransform()
  8204. */
  8205. public function StopTransform() {
  8206. $this->_out('Q');
  8207. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  8208. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  8209. --$this->transfmatrix_key;
  8210. }
  8211. array_pop($this->transfmrk[$this->page]);
  8212. }
  8213. /**
  8214. * Horizontal Scaling.
  8215. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  8216. * @param int $x abscissa of the scaling center. Default is current x position
  8217. * @param int $y ordinate of the scaling center. Default is current y position
  8218. * @access public
  8219. * @since 2.1.000 (2008-01-07)
  8220. * @see StartTransform(), StopTransform()
  8221. */
  8222. public function ScaleX($s_x, $x='', $y='') {
  8223. $this->Scale($s_x, 100, $x, $y);
  8224. }
  8225. /**
  8226. * Vertical Scaling.
  8227. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  8228. * @param int $x abscissa of the scaling center. Default is current x position
  8229. * @param int $y ordinate of the scaling center. Default is current y position
  8230. * @access public
  8231. * @since 2.1.000 (2008-01-07)
  8232. * @see StartTransform(), StopTransform()
  8233. */
  8234. public function ScaleY($s_y, $x='', $y='') {
  8235. $this->Scale(100, $s_y, $x, $y);
  8236. }
  8237. /**
  8238. * Vertical and horizontal proportional Scaling.
  8239. * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  8240. * @param int $x abscissa of the scaling center. Default is current x position
  8241. * @param int $y ordinate of the scaling center. Default is current y position
  8242. * @access public
  8243. * @since 2.1.000 (2008-01-07)
  8244. * @see StartTransform(), StopTransform()
  8245. */
  8246. public function ScaleXY($s, $x='', $y='') {
  8247. $this->Scale($s, $s, $x, $y);
  8248. }
  8249. /**
  8250. * Vertical and horizontal non-proportional Scaling.
  8251. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  8252. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  8253. * @param int $x abscissa of the scaling center. Default is current x position
  8254. * @param int $y ordinate of the scaling center. Default is current y position
  8255. * @access public
  8256. * @since 2.1.000 (2008-01-07)
  8257. * @see StartTransform(), StopTransform()
  8258. */
  8259. public function Scale($s_x, $s_y, $x='', $y='') {
  8260. if ($x === '') {
  8261. $x = $this->x;
  8262. }
  8263. if ($y === '') {
  8264. $y = $this->y;
  8265. }
  8266. if ($this->rtl) {
  8267. $x = $this->w - $x;
  8268. }
  8269. if (($s_x == 0) OR ($s_y == 0)) {
  8270. $this->Error('Please do not use values equal to zero for scaling');
  8271. }
  8272. $y = ($this->h - $y) * $this->k;
  8273. $x *= $this->k;
  8274. //calculate elements of transformation matrix
  8275. $s_x /= 100;
  8276. $s_y /= 100;
  8277. $tm[0] = $s_x;
  8278. $tm[1] = 0;
  8279. $tm[2] = 0;
  8280. $tm[3] = $s_y;
  8281. $tm[4] = $x * (1 - $s_x);
  8282. $tm[5] = $y * (1 - $s_y);
  8283. //scale the coordinate system
  8284. $this->Transform($tm);
  8285. }
  8286. /**
  8287. * Horizontal Mirroring.
  8288. * @param int $x abscissa of the point. Default is current x position
  8289. * @access public
  8290. * @since 2.1.000 (2008-01-07)
  8291. * @see StartTransform(), StopTransform()
  8292. */
  8293. public function MirrorH($x='') {
  8294. $this->Scale(-100, 100, $x);
  8295. }
  8296. /**
  8297. * Verical Mirroring.
  8298. * @param int $y ordinate of the point. Default is current y position
  8299. * @access public
  8300. * @since 2.1.000 (2008-01-07)
  8301. * @see StartTransform(), StopTransform()
  8302. */
  8303. public function MirrorV($y='') {
  8304. $this->Scale(100, -100, '', $y);
  8305. }
  8306. /**
  8307. * Point reflection mirroring.
  8308. * @param int $x abscissa of the point. Default is current x position
  8309. * @param int $y ordinate of the point. Default is current y position
  8310. * @access public
  8311. * @since 2.1.000 (2008-01-07)
  8312. * @see StartTransform(), StopTransform()
  8313. */
  8314. public function MirrorP($x='',$y='') {
  8315. $this->Scale(-100, -100, $x, $y);
  8316. }
  8317. /**
  8318. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  8319. * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  8320. * @param int $x abscissa of the point. Default is current x position
  8321. * @param int $y ordinate of the point. Default is current y position
  8322. * @access public
  8323. * @since 2.1.000 (2008-01-07)
  8324. * @see StartTransform(), StopTransform()
  8325. */
  8326. public function MirrorL($angle=0, $x='',$y='') {
  8327. $this->Scale(-100, 100, $x, $y);
  8328. $this->Rotate(-2*($angle-90), $x, $y);
  8329. }
  8330. /**
  8331. * Translate graphic object horizontally.
  8332. * @param int $t_x movement to the right (or left for RTL)
  8333. * @access public
  8334. * @since 2.1.000 (2008-01-07)
  8335. * @see StartTransform(), StopTransform()
  8336. */
  8337. public function TranslateX($t_x) {
  8338. $this->Translate($t_x, 0);
  8339. }
  8340. /**
  8341. * Translate graphic object vertically.
  8342. * @param int $t_y movement to the bottom
  8343. * @access public
  8344. * @since 2.1.000 (2008-01-07)
  8345. * @see StartTransform(), StopTransform()
  8346. */
  8347. public function TranslateY($t_y) {
  8348. $this->Translate(0, $t_y);
  8349. }
  8350. /**
  8351. * Translate graphic object horizontally and vertically.
  8352. * @param int $t_x movement to the right
  8353. * @param int $t_y movement to the bottom
  8354. * @access public
  8355. * @since 2.1.000 (2008-01-07)
  8356. * @see StartTransform(), StopTransform()
  8357. */
  8358. public function Translate($t_x, $t_y) {
  8359. if ($this->rtl) {
  8360. $t_x = -$t_x;
  8361. }
  8362. //calculate elements of transformation matrix
  8363. $tm[0] = 1;
  8364. $tm[1] = 0;
  8365. $tm[2] = 0;
  8366. $tm[3] = 1;
  8367. $tm[4] = $t_x * $this->k;
  8368. $tm[5] = -$t_y * $this->k;
  8369. //translate the coordinate system
  8370. $this->Transform($tm);
  8371. }
  8372. /**
  8373. * Rotate object.
  8374. * @param float $angle angle in degrees for counter-clockwise rotation
  8375. * @param int $x abscissa of the rotation center. Default is current x position
  8376. * @param int $y ordinate of the rotation center. Default is current y position
  8377. * @access public
  8378. * @since 2.1.000 (2008-01-07)
  8379. * @see StartTransform(), StopTransform()
  8380. */
  8381. public function Rotate($angle, $x='', $y='') {
  8382. if ($x === '') {
  8383. $x = $this->x;
  8384. }
  8385. if ($y === '') {
  8386. $y = $this->y;
  8387. }
  8388. if ($this->rtl) {
  8389. $x = $this->w - $x;
  8390. $angle = -$angle;
  8391. }
  8392. $y = ($this->h - $y) * $this->k;
  8393. $x *= $this->k;
  8394. //calculate elements of transformation matrix
  8395. $tm[0] = cos(deg2rad($angle));
  8396. $tm[1] = sin(deg2rad($angle));
  8397. $tm[2] = -$tm[1];
  8398. $tm[3] = $tm[0];
  8399. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  8400. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  8401. //rotate the coordinate system around ($x,$y)
  8402. $this->Transform($tm);
  8403. }
  8404. /**
  8405. * Skew horizontally.
  8406. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  8407. * @param int $x abscissa of the skewing center. default is current x position
  8408. * @param int $y ordinate of the skewing center. default is current y position
  8409. * @access public
  8410. * @since 2.1.000 (2008-01-07)
  8411. * @see StartTransform(), StopTransform()
  8412. */
  8413. public function SkewX($angle_x, $x='', $y='') {
  8414. $this->Skew($angle_x, 0, $x, $y);
  8415. }
  8416. /**
  8417. * Skew vertically.
  8418. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  8419. * @param int $x abscissa of the skewing center. default is current x position
  8420. * @param int $y ordinate of the skewing center. default is current y position
  8421. * @access public
  8422. * @since 2.1.000 (2008-01-07)
  8423. * @see StartTransform(), StopTransform()
  8424. */
  8425. public function SkewY($angle_y, $x='', $y='') {
  8426. $this->Skew(0, $angle_y, $x, $y);
  8427. }
  8428. /**
  8429. * Skew.
  8430. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  8431. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  8432. * @param int $x abscissa of the skewing center. default is current x position
  8433. * @param int $y ordinate of the skewing center. default is current y position
  8434. * @access public
  8435. * @since 2.1.000 (2008-01-07)
  8436. * @see StartTransform(), StopTransform()
  8437. */
  8438. public function Skew($angle_x, $angle_y, $x='', $y='') {
  8439. if ($x === '') {
  8440. $x = $this->x;
  8441. }
  8442. if ($y === '') {
  8443. $y = $this->y;
  8444. }
  8445. if ($this->rtl) {
  8446. $x = $this->w - $x;
  8447. $angle_x = -$angle_x;
  8448. }
  8449. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  8450. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  8451. }
  8452. $x *= $this->k;
  8453. $y = ($this->h - $y) * $this->k;
  8454. //calculate elements of transformation matrix
  8455. $tm[0] = 1;
  8456. $tm[1] = tan(deg2rad($angle_y));
  8457. $tm[2] = tan(deg2rad($angle_x));
  8458. $tm[3] = 1;
  8459. $tm[4] = -$tm[2] * $y;
  8460. $tm[5] = -$tm[1] * $x;
  8461. //skew the coordinate system
  8462. $this->Transform($tm);
  8463. }
  8464. /**
  8465. * Apply graphic transformations.
  8466. * @access protected
  8467. * @since 2.1.000 (2008-01-07)
  8468. * @see StartTransform(), StopTransform()
  8469. */
  8470. protected function Transform($tm) {
  8471. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  8472. // add tranformation matrix
  8473. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  8474. // update tranformation mark
  8475. if (end($this->transfmrk[$this->page]) !== false) {
  8476. $key = key($this->transfmrk[$this->page]);
  8477. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  8478. }
  8479. }
  8480. // END TRANSFORMATIONS SECTION -------------------------
  8481. // START GRAPHIC FUNCTIONS SECTION ---------------------
  8482. // The following section is based on the code provided by David Hernandez Sanz
  8483. /**
  8484. * 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.
  8485. * @param float $width The width.
  8486. * @access public
  8487. * @since 1.0
  8488. * @see Line(), Rect(), Cell(), MultiCell()
  8489. */
  8490. public function SetLineWidth($width) {
  8491. //Set line width
  8492. $this->LineWidth = $width;
  8493. $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k));
  8494. if ($this->page > 0) {
  8495. $this->_out($this->linestyleWidth);
  8496. }
  8497. }
  8498. /**
  8499. * Returns the current the line width.
  8500. * @return int Line width
  8501. * @access public
  8502. * @since 2.1.000 (2008-01-07)
  8503. * @see Line(), SetLineWidth()
  8504. */
  8505. public function GetLineWidth() {
  8506. return $this->LineWidth;
  8507. }
  8508. /**
  8509. * Set line style.
  8510. * @param array $style Line style. Array with keys among the following:
  8511. * <ul>
  8512. * <li>width (float): Width of the line in user units.</li>
  8513. * <li>cap (string): Type of cap to put on the line. Possible values are:
  8514. * butt, round, square. The difference between "square" and "butt" is that
  8515. * "square" projects a flat end past the end of the line.</li>
  8516. * <li>join (string): Type of join. Possible values are: miter, round,
  8517. * bevel.</li>
  8518. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  8519. * series of length values, which are the lengths of the on and off dashes.
  8520. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  8521. * 1 off, 2 on, 1 off, ...</li>
  8522. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  8523. * the point at which the pattern starts.</li>
  8524. * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
  8525. * </ul>
  8526. * @access public
  8527. * @since 2.1.000 (2008-01-08)
  8528. */
  8529. public function SetLineStyle($style) {
  8530. if (!is_array($style)) {
  8531. return;
  8532. }
  8533. extract($style);
  8534. if (isset($width)) {
  8535. $width_prev = $this->LineWidth;
  8536. $this->SetLineWidth($width);
  8537. $this->LineWidth = $width_prev;
  8538. }
  8539. if (isset($cap)) {
  8540. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  8541. if (isset($ca[$cap])) {
  8542. $this->linestyleCap = $ca[$cap].' J';
  8543. $this->_out($this->linestyleCap);
  8544. }
  8545. }
  8546. if (isset($join)) {
  8547. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  8548. if (isset($ja[$join])) {
  8549. $this->linestyleJoin = $ja[$join].' j';
  8550. $this->_out($this->linestyleJoin);
  8551. }
  8552. }
  8553. if (isset($dash)) {
  8554. $dash_string = '';
  8555. if ($dash) {
  8556. if (preg_match('/^.+,/', $dash) > 0) {
  8557. $tab = explode(',', $dash);
  8558. } else {
  8559. $tab = array($dash);
  8560. }
  8561. $dash_string = '';
  8562. foreach ($tab as $i => $v) {
  8563. if ($i) {
  8564. $dash_string .= ' ';
  8565. }
  8566. $dash_string .= sprintf('%.2F', $v);
  8567. }
  8568. }
  8569. if (!isset($phase) OR !$dash) {
  8570. $phase = 0;
  8571. }
  8572. $this->linestyleDash = sprintf('[%s] %.2F d', $dash_string, $phase);
  8573. $this->_out($this->linestyleDash);
  8574. }
  8575. if (isset($color)) {
  8576. $this->SetDrawColorArray($color);
  8577. }
  8578. }
  8579. /**
  8580. * Set a draw point.
  8581. * @param float $x Abscissa of point.
  8582. * @param float $y Ordinate of point.
  8583. * @access protected
  8584. * @since 2.1.000 (2008-01-08)
  8585. */
  8586. protected function _outPoint($x, $y) {
  8587. if ($this->rtl) {
  8588. $x = $this->w - $x;
  8589. }
  8590. $this->_out(sprintf('%.2F %.2F m', $x * $this->k, ($this->h - $y) * $this->k));
  8591. }
  8592. /**
  8593. * Draws a line from last draw point.
  8594. * @param float $x Abscissa of end point.
  8595. * @param float $y Ordinate of end point.
  8596. * @access protected
  8597. * @since 2.1.000 (2008-01-08)
  8598. */
  8599. protected function _outLine($x, $y) {
  8600. if ($this->rtl) {
  8601. $x = $this->w - $x;
  8602. }
  8603. $this->_out(sprintf('%.2F %.2F l', $x * $this->k, ($this->h - $y) * $this->k));
  8604. }
  8605. /**
  8606. * Draws a rectangle.
  8607. * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  8608. * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  8609. * @param float $w Width.
  8610. * @param float $h Height.
  8611. * @param string $op options
  8612. * @access protected
  8613. * @since 2.1.000 (2008-01-08)
  8614. */
  8615. protected function _outRect($x, $y, $w, $h, $op) {
  8616. if ($this->rtl) {
  8617. $x = $this->w - $x - $w;
  8618. }
  8619. $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op));
  8620. }
  8621. /**
  8622. * Draws a Bezier curve from last draw point.
  8623. * The Bezier curve is a tangent to the line between the control points at either end of the curve.
  8624. * @param float $x1 Abscissa of control point 1.
  8625. * @param float $y1 Ordinate of control point 1.
  8626. * @param float $x2 Abscissa of control point 2.
  8627. * @param float $y2 Ordinate of control point 2.
  8628. * @param float $x3 Abscissa of end point.
  8629. * @param float $y3 Ordinate of end point.
  8630. * @access protected
  8631. * @since 2.1.000 (2008-01-08)
  8632. */
  8633. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  8634. if ($this->rtl) {
  8635. $x1 = $this->w - $x1;
  8636. $x2 = $this->w - $x2;
  8637. $x3 = $this->w - $x3;
  8638. }
  8639. $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));
  8640. }
  8641. /**
  8642. * Draws a line between two points.
  8643. * @param float $x1 Abscissa of first point.
  8644. * @param float $y1 Ordinate of first point.
  8645. * @param float $x2 Abscissa of second point.
  8646. * @param float $y2 Ordinate of second point.
  8647. * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8648. * @access public
  8649. * @since 1.0
  8650. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  8651. */
  8652. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  8653. if (is_array($style)) {
  8654. $this->SetLineStyle($style);
  8655. }
  8656. $this->_outPoint($x1, $y1);
  8657. $this->_outLine($x2, $y2);
  8658. $this->_out(' S');
  8659. }
  8660. /**
  8661. * Draws a rectangle.
  8662. * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  8663. * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  8664. * @param float $w Width.
  8665. * @param float $h Height.
  8666. * @param string $style Style of rendering. Possible values are:
  8667. * <ul>
  8668. * <li>D or empty string: Draw (default).</li>
  8669. * <li>F: Fill.</li>
  8670. * <li>DF or FD: Draw and fill.</li>
  8671. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8672. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8673. * </ul>
  8674. * @param array $border_style Border style of rectangle. Array with keys among the following:
  8675. * <ul>
  8676. * <li>all: Line style of all borders. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8677. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8678. * </ul>
  8679. * If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  8680. * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8681. * @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).
  8682. * @access public
  8683. * @since 1.0
  8684. * @see SetLineStyle()
  8685. */
  8686. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  8687. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  8688. $this->SetFillColorArray($fill_color);
  8689. }
  8690. switch ($style) {
  8691. case 'F': {
  8692. $op = 'f';
  8693. $border_style = array();
  8694. $this->_outRect($x, $y, $w, $h, $op);
  8695. break;
  8696. }
  8697. case 'DF':
  8698. case 'FD': {
  8699. if ((!$border_style) OR (isset($border_style['all']))) {
  8700. $op = 'B';
  8701. if (isset($border_style['all'])) {
  8702. $this->SetLineStyle($border_style['all']);
  8703. $border_style = array();
  8704. }
  8705. } else {
  8706. $op = 'f';
  8707. }
  8708. $this->_outRect($x, $y, $w, $h, $op);
  8709. break;
  8710. }
  8711. case 'CNZ': {
  8712. $op = 'W n';
  8713. $this->_outRect($x, $y, $w, $h, $op);
  8714. break;
  8715. }
  8716. case 'CEO': {
  8717. $op = 'W* n';
  8718. $this->_outRect($x, $y, $w, $h, $op);
  8719. break;
  8720. }
  8721. default: {
  8722. $op = 'S';
  8723. if ((!$border_style) OR (isset($border_style['all']))) {
  8724. if (isset($border_style['all']) AND $border_style['all']) {
  8725. $this->SetLineStyle($border_style['all']);
  8726. $border_style = array();
  8727. }
  8728. $this->_outRect($x, $y, $w, $h, $op);
  8729. }
  8730. break;
  8731. }
  8732. }
  8733. if ($border_style) {
  8734. $border_style2 = array();
  8735. foreach ($border_style as $line => $value) {
  8736. $length = strlen($line);
  8737. for ($i = 0; $i < $length; ++$i) {
  8738. $border_style2[$line[$i]] = $value;
  8739. }
  8740. }
  8741. $border_style = $border_style2;
  8742. if (isset($border_style['L']) AND $border_style['L']) {
  8743. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  8744. }
  8745. if (isset($border_style['T']) AND $border_style['T']) {
  8746. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  8747. }
  8748. if (isset($border_style['R']) AND $border_style['R']) {
  8749. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  8750. }
  8751. if (isset($border_style['B']) AND $border_style['B']) {
  8752. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  8753. }
  8754. }
  8755. }
  8756. /**
  8757. * Draws a Bezier curve.
  8758. * The Bezier curve is a tangent to the line between the control points at
  8759. * either end of the curve.
  8760. * @param float $x0 Abscissa of start point.
  8761. * @param float $y0 Ordinate of start point.
  8762. * @param float $x1 Abscissa of control point 1.
  8763. * @param float $y1 Ordinate of control point 1.
  8764. * @param float $x2 Abscissa of control point 2.
  8765. * @param float $y2 Ordinate of control point 2.
  8766. * @param float $x3 Abscissa of end point.
  8767. * @param float $y3 Ordinate of end point.
  8768. * @param string $style Style of rendering. Possible values are:
  8769. * <ul>
  8770. * <li>D or empty string: Draw (default).</li>
  8771. * <li>F: Fill.</li>
  8772. * <li>DF or FD: Draw and fill.</li>
  8773. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8774. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8775. * </ul>
  8776. * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8777. * @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).
  8778. * @access public
  8779. * @see SetLineStyle()
  8780. * @since 2.1.000 (2008-01-08)
  8781. */
  8782. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  8783. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  8784. $this->SetFillColorArray($fill_color);
  8785. }
  8786. switch ($style) {
  8787. case 'F': {
  8788. $op = 'f';
  8789. $line_style = array();
  8790. break;
  8791. }
  8792. case 'FD':
  8793. case 'DF': {
  8794. $op = 'B';
  8795. break;
  8796. }
  8797. case 'CNZ': {
  8798. $op = 'W n';
  8799. break;
  8800. }
  8801. case 'CEO': {
  8802. $op = 'W* n';
  8803. break;
  8804. }
  8805. default: {
  8806. $op = 'S';
  8807. break;
  8808. }
  8809. }
  8810. if ($line_style) {
  8811. $this->SetLineStyle($line_style);
  8812. }
  8813. $this->_outPoint($x0, $y0);
  8814. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  8815. $this->_out($op);
  8816. }
  8817. /**
  8818. * Draws a poly-Bezier curve.
  8819. * Each Bezier curve segment is a tangent to the line between the control points at
  8820. * either end of the curve.
  8821. * @param float $x0 Abscissa of start point.
  8822. * @param float $y0 Ordinate of start point.
  8823. * @param float $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  8824. * @param string $style Style of rendering. Possible values are:
  8825. * <ul>
  8826. * <li>D or empty string: Draw (default).</li>
  8827. * <li>F: Fill.</li>
  8828. * <li>DF or FD: Draw and fill.</li>
  8829. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8830. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8831. * </ul>
  8832. * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8833. * @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).
  8834. * @access public
  8835. * @see SetLineStyle()
  8836. * @since 3.0008 (2008-05-12)
  8837. */
  8838. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  8839. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  8840. $this->SetFillColorArray($fill_color);
  8841. }
  8842. switch ($style) {
  8843. case 'F': {
  8844. $op = 'f';
  8845. $line_style = array();
  8846. break;
  8847. }
  8848. case 'FD':
  8849. case 'DF': {
  8850. $op = 'B';
  8851. break;
  8852. }
  8853. case 'CNZ': {
  8854. $op = 'W n';
  8855. break;
  8856. }
  8857. case 'CEO': {
  8858. $op = 'W* n';
  8859. break;
  8860. }
  8861. default: {
  8862. $op = 'S';
  8863. break;
  8864. }
  8865. }
  8866. if ($line_style) {
  8867. $this->SetLineStyle($line_style);
  8868. }
  8869. $this->_outPoint($x0, $y0);
  8870. foreach ($segments as $segment) {
  8871. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  8872. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  8873. }
  8874. $this->_out($op);
  8875. }
  8876. /**
  8877. * Draws an ellipse.
  8878. * An ellipse is formed from n Bezier curves.
  8879. * @param float $x0 Abscissa of center point.
  8880. * @param float $y0 Ordinate of center point.
  8881. * @param float $rx Horizontal radius.
  8882. * @param float $ry Vertical radius (if ry = 0 then is a circle, see {@link Circle Circle}). Default value: 0.
  8883. * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  8884. * @param float $astart: Angle start of draw line. Default value: 0.
  8885. * @param float $afinish: Angle finish of draw line. Default value: 360.
  8886. * @param string $style Style of rendering. Possible values are:
  8887. * <ul>
  8888. * <li>D or empty string: Draw (default).</li>
  8889. * <li>F: Fill.</li>
  8890. * <li>DF or FD: Draw and fill.</li>
  8891. * <li>C: Draw close.</li>
  8892. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8893. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8894. * </ul>
  8895. * @param array $line_style Line style of ellipse. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8896. * @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).
  8897. * @param integer $nc Number of curves used in ellipse. Default value: 8.
  8898. * @access public
  8899. * @since 2.1.000 (2008-01-08)
  8900. */
  8901. public function Ellipse($x0, $y0, $rx, $ry=0, $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=8) {
  8902. if ($angle) {
  8903. $this->StartTransform();
  8904. $this->Rotate($angle, $x0, $y0);
  8905. $this->Ellipse($x0, $y0, $rx, $ry, 0, $astart, $afinish, $style, $line_style, $fill_color, $nc);
  8906. $this->StopTransform();
  8907. return;
  8908. }
  8909. if ($rx) {
  8910. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  8911. $this->SetFillColorArray($fill_color);
  8912. }
  8913. switch ($style) {
  8914. case 'F': {
  8915. $op = 'f';
  8916. $line_style = array();
  8917. break;
  8918. }
  8919. case 'FD':
  8920. case 'DF': {
  8921. $op = 'B';
  8922. break;
  8923. }
  8924. case 'C': {
  8925. $op = 's'; // Small 's' signifies closing the path as well
  8926. break;
  8927. }
  8928. case 'CNZ': {
  8929. $op = 'W n';
  8930. break;
  8931. }
  8932. case 'CEO': {
  8933. $op = 'W* n';
  8934. break;
  8935. }
  8936. default: {
  8937. $op = 'S';
  8938. break;
  8939. }
  8940. }
  8941. if ($line_style) {
  8942. $this->SetLineStyle($line_style);
  8943. }
  8944. if (!$ry) {
  8945. $ry = $rx;
  8946. }
  8947. $rx *= $this->k;
  8948. $ry *= $this->k;
  8949. if ($nc < 2) {
  8950. $nc = 2;
  8951. }
  8952. $astart = deg2rad((float) $astart);
  8953. $afinish = deg2rad((float) $afinish);
  8954. $total_angle = $afinish - $astart;
  8955. $dt = $total_angle / $nc;
  8956. $dtm = $dt / 3;
  8957. $x0 *= $this->k;
  8958. $y0 = ($this->h - $y0) * $this->k;
  8959. $t1 = $astart;
  8960. $a0 = $x0 + ($rx * cos($t1));
  8961. $b0 = $y0 + ($ry * sin($t1));
  8962. $c0 = -$rx * sin($t1);
  8963. $d0 = $ry * cos($t1);
  8964. $this->_outPoint($a0 / $this->k, $this->h - ($b0 / $this->k));
  8965. for ($i = 1; $i <= $nc; ++$i) {
  8966. // Draw this bit of the total curve
  8967. $t1 = ($i * $dt) + $astart;
  8968. $a1 = $x0 + ($rx * cos($t1));
  8969. $b1 = $y0 + ($ry * sin($t1));
  8970. $c1 = -$rx * sin($t1);
  8971. $d1 = $ry * cos($t1);
  8972. $this->_outCurve(($a0 + ($c0 * $dtm)) / $this->k, $this->h - (($b0 + ($d0 * $dtm)) / $this->k), ($a1 - ($c1 * $dtm)) / $this->k, $this->h - (($b1 - ($d1 * $dtm)) / $this->k), $a1 / $this->k, $this->h - ($b1 / $this->k));
  8973. $a0 = $a1;
  8974. $b0 = $b1;
  8975. $c0 = $c1;
  8976. $d0 = $d1;
  8977. }
  8978. $this->_out($op);
  8979. }
  8980. }
  8981. /**
  8982. * Draws a circle.
  8983. * A circle is formed from n Bezier curves.
  8984. * @param float $x0 Abscissa of center point.
  8985. * @param float $y0 Ordinate of center point.
  8986. * @param float $r Radius.
  8987. * @param float $astart: Angle start of draw line. Default value: 0.
  8988. * @param float $afinish: Angle finish of draw line. Default value: 360.
  8989. * @param string $style Style of rendering. Possible values are:
  8990. * <ul>
  8991. * <li>D or empty string: Draw (default).</li>
  8992. * <li>F: Fill.</li>
  8993. * <li>DF or FD: Draw and fill.</li>
  8994. * <li>C: Draw close.</li>
  8995. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8996. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8997. * </ul>
  8998. * @param array $line_style Line style of circle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8999. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  9000. * @param integer $nc Number of curves used in circle. Default value: 8.
  9001. * @access public
  9002. * @since 2.1.000 (2008-01-08)
  9003. */
  9004. public function Circle($x0, $y0, $r, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=8) {
  9005. $this->Ellipse($x0, $y0, $r, 0, 0, $astart, $afinish, $style, $line_style, $fill_color, $nc);
  9006. }
  9007. /**
  9008. * Draws a polygonal line
  9009. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  9010. * @param string $style Style of rendering. Possible values are:
  9011. * <ul>
  9012. * <li>D or empty string: Draw (default).</li>
  9013. * <li>F: Fill.</li>
  9014. * <li>DF or FD: Draw and fill.</li>
  9015. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9016. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9017. * </ul>
  9018. * @param array $line_style Line style of polygon. Array with keys among the following:
  9019. * <ul>
  9020. * <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9021. * <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9022. * </ul>
  9023. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  9024. * @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).
  9025. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  9026. * @access public
  9027. * @since 4.8.003 (2009-09-15)
  9028. */
  9029. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  9030. $this->Polygon($p, $style, $line_style, $fill_color, false);
  9031. }
  9032. /**
  9033. * Draws a polygon.
  9034. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  9035. * @param string $style Style of rendering. Possible values are:
  9036. * <ul>
  9037. * <li>D or empty string: Draw (default).</li>
  9038. * <li>F: Fill.</li>
  9039. * <li>DF or FD: Draw and fill.</li>
  9040. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9041. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9042. * </ul>
  9043. * @param array $line_style Line style of polygon. Array with keys among the following:
  9044. * <ul>
  9045. * <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9046. * <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9047. * </ul>
  9048. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  9049. * @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).
  9050. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  9051. * @access public
  9052. * @since 2.1.000 (2008-01-08)
  9053. */
  9054. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  9055. $nc = count($p); // number of coordinates
  9056. $np = $nc / 2; // number of points
  9057. if ($closed) {
  9058. // close polygon by adding the first 2 points at the end (one line)
  9059. for ($i = 0; $i < 4; ++$i) {
  9060. $p[$nc + $i] = $p[$i];
  9061. }
  9062. // copy style for the last added line
  9063. if (isset($line_style[0])) {
  9064. $line_style[$np] = $line_style[0];
  9065. }
  9066. $nc += 4;
  9067. }
  9068. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  9069. $this->SetFillColorArray($fill_color);
  9070. }
  9071. switch ($style) {
  9072. case 'F': {
  9073. $line_style = array();
  9074. $op = 'f';
  9075. break;
  9076. }
  9077. case 'FD':
  9078. case 'DF': {
  9079. $op = 'B';
  9080. break;
  9081. }
  9082. case 'CNZ': {
  9083. $op = 'W n';
  9084. break;
  9085. }
  9086. case 'CEO': {
  9087. $op = 'W* n';
  9088. break;
  9089. }
  9090. default: {
  9091. $op = 'S';
  9092. break;
  9093. }
  9094. }
  9095. $draw = true;
  9096. if ($line_style) {
  9097. if (isset($line_style['all'])) {
  9098. $this->SetLineStyle($line_style['all']);
  9099. } else {
  9100. $draw = false;
  9101. if ($op == 'B') {
  9102. // draw fill
  9103. $op = 'f';
  9104. $this->_outPoint($p[0], $p[1]);
  9105. for ($i = 2; $i < $nc; $i = $i + 2) {
  9106. $this->_outLine($p[$i], $p[$i + 1]);
  9107. }
  9108. $this->_out($op);
  9109. }
  9110. // draw outline
  9111. $this->_outPoint($p[0], $p[1]);
  9112. for ($i = 2; $i < $nc; $i = $i + 2) {
  9113. $line_num = ($i / 2) - 1;
  9114. if (isset($line_style[$line_num])) {
  9115. if ($line_style[$line_num] != 0) {
  9116. if (is_array($line_style[$line_num])) {
  9117. $this->_out('S');
  9118. $this->SetLineStyle($line_style[$line_num]);
  9119. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  9120. $this->_outLine($p[$i], $p[$i + 1]);
  9121. $this->_out('S');
  9122. $this->_outPoint($p[$i], $p[$i + 1]);
  9123. } else {
  9124. $this->_outLine($p[$i], $p[$i + 1]);
  9125. }
  9126. }
  9127. } else {
  9128. $this->_outLine($p[$i], $p[$i + 1]);
  9129. }
  9130. }
  9131. $this->_out($op);
  9132. }
  9133. }
  9134. if ($draw) {
  9135. $this->_outPoint($p[0], $p[1]);
  9136. for ($i = 2; $i < $nc; $i = $i + 2) {
  9137. $this->_outLine($p[$i], $p[$i + 1]);
  9138. }
  9139. $this->_out($op);
  9140. }
  9141. }
  9142. /**
  9143. * Draws a regular polygon.
  9144. * @param float $x0 Abscissa of center point.
  9145. * @param float $y0 Ordinate of center point.
  9146. * @param float $r: Radius of inscribed circle.
  9147. * @param integer $ns Number of sides.
  9148. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  9149. * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  9150. * @param string $style Style of rendering. Possible values are:
  9151. * <ul>
  9152. * <li>D or empty string: Draw (default).</li>
  9153. * <li>F: Fill.</li>
  9154. * <li>DF or FD: Draw and fill.</li>
  9155. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9156. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9157. * </ul>
  9158. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  9159. * <ul>
  9160. * <li>all: Line style of all sides. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9161. * <li>0 to ($ns - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9162. * </ul>
  9163. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  9164. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  9165. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  9166. * <ul>
  9167. * <li>D or empty string: Draw (default).</li>
  9168. * <li>F: Fill.</li>
  9169. * <li>DF or FD: Draw and fill.</li>
  9170. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9171. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9172. * </ul>
  9173. * @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).
  9174. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  9175. * @access public
  9176. * @since 2.1.000 (2008-01-08)
  9177. */
  9178. 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()) {
  9179. if (3 > $ns) {
  9180. $ns = 3;
  9181. }
  9182. if ($draw_circle) {
  9183. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  9184. }
  9185. $p = array();
  9186. for ($i = 0; $i < $ns; ++$i) {
  9187. $a = $angle + ($i * 360 / $ns);
  9188. $a_rad = deg2rad((float) $a);
  9189. $p[] = $x0 + ($r * sin($a_rad));
  9190. $p[] = $y0 + ($r * cos($a_rad));
  9191. }
  9192. $this->Polygon($p, $style, $line_style, $fill_color);
  9193. }
  9194. /**
  9195. * Draws a star polygon
  9196. * @param float $x0 Abscissa of center point.
  9197. * @param float $y0 Ordinate of center point.
  9198. * @param float $r Radius of inscribed circle.
  9199. * @param integer $nv Number of vertices.
  9200. * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  9201. * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  9202. * @param boolean $draw_circle: Draw inscribed circle or not. Default value is false.
  9203. * @param string $style Style of rendering. Possible values are:
  9204. * <ul>
  9205. * <li>D or empty string: Draw (default).</li>
  9206. * <li>F: Fill.</li>
  9207. * <li>DF or FD: Draw and fill.</li>
  9208. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9209. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9210. * </ul>
  9211. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  9212. * <ul>
  9213. * <li>all: Line style of all sides. Array like for
  9214. * {@link SetLineStyle SetLineStyle}.</li>
  9215. * <li>0 to (n - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9216. * </ul>
  9217. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  9218. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  9219. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  9220. * <ul>
  9221. * <li>D or empty string: Draw (default).</li>
  9222. * <li>F: Fill.</li>
  9223. * <li>DF or FD: Draw and fill.</li>
  9224. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9225. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9226. * </ul>
  9227. * @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).
  9228. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  9229. * @access public
  9230. * @since 2.1.000 (2008-01-08)
  9231. */
  9232. 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()) {
  9233. if ($nv < 2) {
  9234. $nv = 2;
  9235. }
  9236. if ($draw_circle) {
  9237. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  9238. }
  9239. $p2 = array();
  9240. $visited = array();
  9241. for ($i = 0; $i < $nv; ++$i) {
  9242. $a = $angle + ($i * 360 / $nv);
  9243. $a_rad = deg2rad((float) $a);
  9244. $p2[] = $x0 + ($r * sin($a_rad));
  9245. $p2[] = $y0 + ($r * cos($a_rad));
  9246. $visited[] = false;
  9247. }
  9248. $p = array();
  9249. $i = 0;
  9250. do {
  9251. $p[] = $p2[$i * 2];
  9252. $p[] = $p2[($i * 2) + 1];
  9253. $visited[$i] = true;
  9254. $i += $ng;
  9255. $i %= $nv;
  9256. } while (!$visited[$i]);
  9257. $this->Polygon($p, $style, $line_style, $fill_color);
  9258. }
  9259. /**
  9260. * Draws a rounded rectangle.
  9261. * @param float $x Abscissa of upper-left corner.
  9262. * @param float $y Ordinate of upper-left corner.
  9263. * @param float $w Width.
  9264. * @param float $h Height.
  9265. * @param float $r Radius of the rounded corners.
  9266. * @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").
  9267. * @param string $style Style of rendering. Possible values are:
  9268. * <ul>
  9269. * <li>D or empty string: Draw (default).</li>
  9270. * <li>F: Fill.</li>
  9271. * <li>DF or FD: Draw and fill.</li>
  9272. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9273. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9274. * </ul>
  9275. * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  9276. * @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).
  9277. * @access public
  9278. * @since 2.1.000 (2008-01-08)
  9279. */
  9280. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  9281. if ('0000' == $round_corner) { // Not rounded
  9282. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  9283. } else { // Rounded
  9284. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  9285. $this->SetFillColorArray($fill_color);
  9286. }
  9287. switch ($style) {
  9288. case 'F': {
  9289. $border_style = array();
  9290. $op = 'f';
  9291. break;
  9292. }
  9293. case 'FD':
  9294. case 'DF': {
  9295. $op = 'B';
  9296. break;
  9297. }
  9298. case 'CNZ': {
  9299. $op = 'W n';
  9300. break;
  9301. }
  9302. case 'CEO': {
  9303. $op = 'W* n';
  9304. break;
  9305. }
  9306. default: {
  9307. $op = 'S';
  9308. break;
  9309. }
  9310. }
  9311. if ($border_style) {
  9312. $this->SetLineStyle($border_style);
  9313. }
  9314. $MyArc = 4 / 3 * (sqrt(2) - 1);
  9315. $this->_outPoint($x + $r, $y);
  9316. $xc = $x + $w - $r;
  9317. $yc = $y + $r;
  9318. $this->_outLine($xc, $y);
  9319. if ($round_corner[0]) {
  9320. $this->_outCurve($xc + ($r * $MyArc), $yc - $r, $xc + $r, $yc - ($r * $MyArc), $xc + $r, $yc);
  9321. } else {
  9322. $this->_outLine($x + $w, $y);
  9323. }
  9324. $xc = $x + $w - $r;
  9325. $yc = $y + $h - $r;
  9326. $this->_outLine($x + $w, $yc);
  9327. if ($round_corner[1]) {
  9328. $this->_outCurve($xc + $r, $yc + ($r * $MyArc), $xc + ($r * $MyArc), $yc + $r, $xc, $yc + $r);
  9329. } else {
  9330. $this->_outLine($x + $w, $y + $h);
  9331. }
  9332. $xc = $x + $r;
  9333. $yc = $y + $h - $r;
  9334. $this->_outLine($xc, $y + $h);
  9335. if ($round_corner[2]) {
  9336. $this->_outCurve($xc - ($r * $MyArc), $yc + $r, $xc - $r, $yc + ($r * $MyArc), $xc - $r, $yc);
  9337. } else {
  9338. $this->_outLine($x, $y + $h);
  9339. }
  9340. $xc = $x + $r;
  9341. $yc = $y + $r;
  9342. $this->_outLine($x, $yc);
  9343. if ($round_corner[3]) {
  9344. $this->_outCurve($xc - $r, $yc - ($r * $MyArc), $xc - ($r * $MyArc), $yc - $r, $xc, $yc - $r);
  9345. } else {
  9346. $this->_outLine($x, $y);
  9347. $this->_outLine($x + $r, $y);
  9348. }
  9349. $this->_out($op);
  9350. }
  9351. }
  9352. /**
  9353. * Draws a grahic arrow.
  9354. * @parameter float $x0 Abscissa of first point.
  9355. * @parameter float $y0 Ordinate of first point.
  9356. * @parameter float $x0 Abscissa of second point.
  9357. * @parameter float $y1 Ordinate of second point.
  9358. * @parameter int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  9359. * @parameter float $arm_size length of arrowhead arms
  9360. * @parameter int $arm_angle angle between an arm and the shaft
  9361. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  9362. * @since 4.6.018 (2009-07-10)
  9363. */
  9364. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  9365. // getting arrow direction angle
  9366. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  9367. $dir_angle = rad2deg(atan2(($y0 - $y1), ($x0 - $x1)));
  9368. $sx1 = $x1;
  9369. $sy1 = $y1;
  9370. if ($head_style > 0) {
  9371. // calculate the stopping point for the arrow shaft
  9372. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos(deg2rad($dir_angle)));
  9373. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin(deg2rad($dir_angle)));
  9374. }
  9375. // main arrow line / shaft
  9376. $this->Line($x0, $y0, $sx1, $sy1);
  9377. // left arrowhead arm tip
  9378. $x2L = $x1 + ($arm_size * cos(deg2rad($dir_angle + $arm_angle)));
  9379. $y2L = $y1 + ($arm_size * sin(deg2rad($dir_angle + $arm_angle)));
  9380. // right arrowhead arm tip
  9381. $x2R = $x1 + ($arm_size * cos(deg2rad($dir_angle - $arm_angle)));
  9382. $y2R = $y1 + ($arm_size * sin(deg2rad($dir_angle - $arm_angle)));
  9383. $mode = 'D';
  9384. $style = array();
  9385. switch ($head_style) {
  9386. case 0: {
  9387. // draw only arrowhead arms
  9388. $mode = 'D';
  9389. $style = array(1, 1, 0);
  9390. break;
  9391. }
  9392. case 1: {
  9393. // draw closed arrowhead, but no fill
  9394. $mode = 'D';
  9395. break;
  9396. }
  9397. case 2: {
  9398. // closed and filled arrowhead
  9399. $mode = 'DF';
  9400. break;
  9401. }
  9402. case 3: {
  9403. // filled arrowhead
  9404. $mode = 'F';
  9405. break;
  9406. }
  9407. }
  9408. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  9409. }
  9410. // END GRAPHIC FUNCTIONS SECTION -----------------------
  9411. // BIDIRECTIONAL TEXT SECTION --------------------------
  9412. /**
  9413. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  9414. * @param string $str string to manipulate.
  9415. * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  9416. * @param bool $forcertl if true forces RTL text direction
  9417. * @return string
  9418. * @access protected
  9419. * @author Nicola Asuni
  9420. * @since 2.1.000 (2008-01-08)
  9421. */
  9422. protected function utf8StrRev($str, $setbom=false, $forcertl=false) {
  9423. return $this->utf8StrArrRev($this->UTF8StringToArray($str), $str, $setbom, $forcertl);
  9424. }
  9425. /**
  9426. * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  9427. * @param array $arr array of unicode values.
  9428. * @param string $str string to manipulate (or empty value).
  9429. * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  9430. * @param bool $forcertl if true forces RTL text direction
  9431. * @return string
  9432. * @access protected
  9433. * @author Nicola Asuni
  9434. * @since 4.9.000 (2010-03-27)
  9435. */
  9436. protected function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false) {
  9437. return $this->arrUTF8ToUTF16BE($this->utf8Bidi($arr, $str, $forcertl), $setbom);
  9438. }
  9439. /**
  9440. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  9441. * @param array $ta array of characters composing the string.
  9442. * @param string $str string to process
  9443. * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  9444. * @return array of unicode chars
  9445. * @author Nicola Asuni
  9446. * @access protected
  9447. * @since 2.4.000 (2008-03-06)
  9448. */
  9449. protected function utf8Bidi($ta, $str='', $forcertl=false) {
  9450. global $unicode, $unicode_mirror, $unicode_arlet, $laa_array, $diacritics;
  9451. // paragraph embedding level
  9452. $pel = 0;
  9453. // max level
  9454. $maxlevel = 0;
  9455. if ($this->empty_string($str)) {
  9456. // create string from array
  9457. $str = $this->UTF8ArrSubString($ta);
  9458. }
  9459. // check if string contains arabic text
  9460. if (preg_match(K_RE_PATTERN_ARABIC, $str)) {
  9461. $arabic = true;
  9462. } else {
  9463. $arabic = false;
  9464. }
  9465. // check if string contains RTL text
  9466. if (!($forcertl OR $arabic OR preg_match(K_RE_PATTERN_RTL, $str))) {
  9467. return $ta;
  9468. }
  9469. // get number of chars
  9470. $numchars = count($ta);
  9471. if ($forcertl == 'R') {
  9472. $pel = 1;
  9473. } elseif ($forcertl == 'L') {
  9474. $pel = 0;
  9475. } else {
  9476. // P2. In each paragraph, find the first character of type L, AL, or R.
  9477. // 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.
  9478. for ($i=0; $i < $numchars; ++$i) {
  9479. $type = $unicode[$ta[$i]];
  9480. if ($type == 'L') {
  9481. $pel = 0;
  9482. break;
  9483. } elseif (($type == 'AL') OR ($type == 'R')) {
  9484. $pel = 1;
  9485. break;
  9486. }
  9487. }
  9488. }
  9489. // Current Embedding Level
  9490. $cel = $pel;
  9491. // directional override status
  9492. $dos = 'N';
  9493. $remember = array();
  9494. // start-of-level-run
  9495. $sor = $pel % 2 ? 'R' : 'L';
  9496. $eor = $sor;
  9497. // Array of characters data
  9498. $chardata = Array();
  9499. // 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.
  9500. // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  9501. for ($i=0; $i < $numchars; ++$i) {
  9502. if ($ta[$i] == K_RLE) {
  9503. // X2. With each RLE, compute the least greater odd embedding level.
  9504. // 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.
  9505. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9506. $next_level = $cel + ($cel % 2) + 1;
  9507. if ($next_level < 62) {
  9508. $remember[] = array('num' => K_RLE, 'cel' => $cel, 'dos' => $dos);
  9509. $cel = $next_level;
  9510. $dos = 'N';
  9511. $sor = $eor;
  9512. $eor = $cel % 2 ? 'R' : 'L';
  9513. }
  9514. } elseif ($ta[$i] == K_LRE) {
  9515. // X3. With each LRE, compute the least greater even embedding level.
  9516. // 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.
  9517. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9518. $next_level = $cel + 2 - ($cel % 2);
  9519. if ( $next_level < 62 ) {
  9520. $remember[] = array('num' => K_LRE, 'cel' => $cel, 'dos' => $dos);
  9521. $cel = $next_level;
  9522. $dos = 'N';
  9523. $sor = $eor;
  9524. $eor = $cel % 2 ? 'R' : 'L';
  9525. }
  9526. } elseif ($ta[$i] == K_RLO) {
  9527. // X4. With each RLO, compute the least greater odd embedding level.
  9528. // 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.
  9529. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9530. $next_level = $cel + ($cel % 2) + 1;
  9531. if ($next_level < 62) {
  9532. $remember[] = array('num' => K_RLO, 'cel' => $cel, 'dos' => $dos);
  9533. $cel = $next_level;
  9534. $dos = 'R';
  9535. $sor = $eor;
  9536. $eor = $cel % 2 ? 'R' : 'L';
  9537. }
  9538. } elseif ($ta[$i] == K_LRO) {
  9539. // X5. With each LRO, compute the least greater even embedding level.
  9540. // 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.
  9541. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9542. $next_level = $cel + 2 - ($cel % 2);
  9543. if ( $next_level < 62 ) {
  9544. $remember[] = array('num' => K_LRO, 'cel' => $cel, 'dos' => $dos);
  9545. $cel = $next_level;
  9546. $dos = 'L';
  9547. $sor = $eor;
  9548. $eor = $cel % 2 ? 'R' : 'L';
  9549. }
  9550. } elseif ($ta[$i] == K_PDF) {
  9551. // 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.
  9552. if (count($remember)) {
  9553. $last = count($remember ) - 1;
  9554. if (($remember[$last]['num'] == K_RLE) OR
  9555. ($remember[$last]['num'] == K_LRE) OR
  9556. ($remember[$last]['num'] == K_RLO) OR
  9557. ($remember[$last]['num'] == K_LRO)) {
  9558. $match = array_pop($remember);
  9559. $cel = $match['cel'];
  9560. $dos = $match['dos'];
  9561. $sor = $eor;
  9562. $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
  9563. }
  9564. }
  9565. } elseif (($ta[$i] != K_RLE) AND
  9566. ($ta[$i] != K_LRE) AND
  9567. ($ta[$i] != K_RLO) AND
  9568. ($ta[$i] != K_LRO) AND
  9569. ($ta[$i] != K_PDF)) {
  9570. // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  9571. // a. Set the level of the current character to the current embedding level.
  9572. // b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  9573. if ($dos != 'N') {
  9574. $chardir = $dos;
  9575. } else {
  9576. if (isset($unicode[$ta[$i]])) {
  9577. $chardir = $unicode[$ta[$i]];
  9578. } else {
  9579. $chardir = 'L';
  9580. }
  9581. }
  9582. // stores string characters and other information
  9583. $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor);
  9584. }
  9585. } // end for each char
  9586. // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  9587. // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  9588. // 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.
  9589. // 3.3.3 Resolving Weak Types
  9590. // 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.
  9591. // Nonspacing marks are now resolved based on the previous characters.
  9592. $numchars = count($chardata);
  9593. // 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.
  9594. $prevlevel = -1; // track level changes
  9595. $levcount = 0; // counts consecutive chars at the same level
  9596. for ($i=0; $i < $numchars; ++$i) {
  9597. if ($chardata[$i]['type'] == 'NSM') {
  9598. if ($levcount) {
  9599. $chardata[$i]['type'] = $chardata[$i]['sor'];
  9600. } elseif ($i > 0) {
  9601. $chardata[$i]['type'] = $chardata[($i-1)]['type'];
  9602. }
  9603. }
  9604. if ($chardata[$i]['level'] != $prevlevel) {
  9605. $levcount = 0;
  9606. } else {
  9607. ++$levcount;
  9608. }
  9609. $prevlevel = $chardata[$i]['level'];
  9610. }
  9611. // 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.
  9612. $prevlevel = -1;
  9613. $levcount = 0;
  9614. for ($i=0; $i < $numchars; ++$i) {
  9615. if ($chardata[$i]['char'] == 'EN') {
  9616. for ($j=$levcount; $j >= 0; $j--) {
  9617. if ($chardata[$j]['type'] == 'AL') {
  9618. $chardata[$i]['type'] = 'AN';
  9619. } elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
  9620. break;
  9621. }
  9622. }
  9623. }
  9624. if ($chardata[$i]['level'] != $prevlevel) {
  9625. $levcount = 0;
  9626. } else {
  9627. ++$levcount;
  9628. }
  9629. $prevlevel = $chardata[$i]['level'];
  9630. }
  9631. // W3. Change all ALs to R.
  9632. for ($i=0; $i < $numchars; ++$i) {
  9633. if ($chardata[$i]['type'] == 'AL') {
  9634. $chardata[$i]['type'] = 'R';
  9635. }
  9636. }
  9637. // 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.
  9638. $prevlevel = -1;
  9639. $levcount = 0;
  9640. for ($i=0; $i < $numchars; ++$i) {
  9641. if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  9642. if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
  9643. $chardata[$i]['type'] = 'EN';
  9644. } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
  9645. $chardata[$i]['type'] = 'EN';
  9646. } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+1)]['type'] == 'AN')) {
  9647. $chardata[$i]['type'] = 'AN';
  9648. }
  9649. }
  9650. if ($chardata[$i]['level'] != $prevlevel) {
  9651. $levcount = 0;
  9652. } else {
  9653. ++$levcount;
  9654. }
  9655. $prevlevel = $chardata[$i]['level'];
  9656. }
  9657. // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  9658. $prevlevel = -1;
  9659. $levcount = 0;
  9660. for ($i=0; $i < $numchars; ++$i) {
  9661. if ($chardata[$i]['type'] == 'ET') {
  9662. if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
  9663. $chardata[$i]['type'] = 'EN';
  9664. } else {
  9665. $j = $i+1;
  9666. while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
  9667. if ($chardata[$j]['type'] == 'EN') {
  9668. $chardata[$i]['type'] = 'EN';
  9669. break;
  9670. } elseif ($chardata[$j]['type'] != 'ET') {
  9671. break;
  9672. }
  9673. ++$j;
  9674. }
  9675. }
  9676. }
  9677. if ($chardata[$i]['level'] != $prevlevel) {
  9678. $levcount = 0;
  9679. } else {
  9680. ++$levcount;
  9681. }
  9682. $prevlevel = $chardata[$i]['level'];
  9683. }
  9684. // W6. Otherwise, separators and terminators change to Other Neutral.
  9685. $prevlevel = -1;
  9686. $levcount = 0;
  9687. for ($i=0; $i < $numchars; ++$i) {
  9688. if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
  9689. $chardata[$i]['type'] = 'ON';
  9690. }
  9691. if ($chardata[$i]['level'] != $prevlevel) {
  9692. $levcount = 0;
  9693. } else {
  9694. ++$levcount;
  9695. }
  9696. $prevlevel = $chardata[$i]['level'];
  9697. }
  9698. //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.
  9699. $prevlevel = -1;
  9700. $levcount = 0;
  9701. for ($i=0; $i < $numchars; ++$i) {
  9702. if ($chardata[$i]['char'] == 'EN') {
  9703. for ($j=$levcount; $j >= 0; $j--) {
  9704. if ($chardata[$j]['type'] == 'L') {
  9705. $chardata[$i]['type'] = 'L';
  9706. } elseif ($chardata[$j]['type'] == 'R') {
  9707. break;
  9708. }
  9709. }
  9710. }
  9711. if ($chardata[$i]['level'] != $prevlevel) {
  9712. $levcount = 0;
  9713. } else {
  9714. ++$levcount;
  9715. }
  9716. $prevlevel = $chardata[$i]['level'];
  9717. }
  9718. // 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.
  9719. $prevlevel = -1;
  9720. $levcount = 0;
  9721. for ($i=0; $i < $numchars; ++$i) {
  9722. if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  9723. if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
  9724. $chardata[$i]['type'] = 'L';
  9725. } elseif (($chardata[$i]['type'] == 'N') AND
  9726. (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
  9727. (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
  9728. $chardata[$i]['type'] = 'R';
  9729. } elseif ($chardata[$i]['type'] == 'N') {
  9730. // N2. Any remaining neutrals take the embedding direction
  9731. $chardata[$i]['type'] = $chardata[$i]['sor'];
  9732. }
  9733. } elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
  9734. // first char
  9735. if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
  9736. $chardata[$i]['type'] = 'L';
  9737. } elseif (($chardata[$i]['type'] == 'N') AND
  9738. (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
  9739. (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
  9740. $chardata[$i]['type'] = 'R';
  9741. } elseif ($chardata[$i]['type'] == 'N') {
  9742. // N2. Any remaining neutrals take the embedding direction
  9743. $chardata[$i]['type'] = $chardata[$i]['sor'];
  9744. }
  9745. } elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] != $prevlevel))) {
  9746. //last char
  9747. if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
  9748. $chardata[$i]['type'] = 'L';
  9749. } elseif (($chardata[$i]['type'] == 'N') AND
  9750. (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
  9751. (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
  9752. $chardata[$i]['type'] = 'R';
  9753. } elseif ($chardata[$i]['type'] == 'N') {
  9754. // N2. Any remaining neutrals take the embedding direction
  9755. $chardata[$i]['type'] = $chardata[$i]['sor'];
  9756. }
  9757. } elseif ($chardata[$i]['type'] == 'N') {
  9758. // N2. Any remaining neutrals take the embedding direction
  9759. $chardata[$i]['type'] = $chardata[$i]['sor'];
  9760. }
  9761. if ($chardata[$i]['level'] != $prevlevel) {
  9762. $levcount = 0;
  9763. } else {
  9764. ++$levcount;
  9765. }
  9766. $prevlevel = $chardata[$i]['level'];
  9767. }
  9768. // 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.
  9769. // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  9770. for ($i=0; $i < $numchars; ++$i) {
  9771. $odd = $chardata[$i]['level'] % 2;
  9772. if ($odd) {
  9773. if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
  9774. $chardata[$i]['level'] += 1;
  9775. }
  9776. } else {
  9777. if ($chardata[$i]['type'] == 'R') {
  9778. $chardata[$i]['level'] += 1;
  9779. } elseif (($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
  9780. $chardata[$i]['level'] += 2;
  9781. }
  9782. }
  9783. $maxlevel = max($chardata[$i]['level'],$maxlevel);
  9784. }
  9785. // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  9786. // 1. Segment separators,
  9787. // 2. Paragraph separators,
  9788. // 3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  9789. // 4. Any sequence of white space characters at the end of the line.
  9790. for ($i=0; $i < $numchars; ++$i) {
  9791. if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
  9792. $chardata[$i]['level'] = $pel;
  9793. } elseif ($chardata[$i]['type'] == 'WS') {
  9794. $j = $i+1;
  9795. while ($j < $numchars) {
  9796. if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
  9797. (($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
  9798. $chardata[$i]['level'] = $pel;
  9799. break;
  9800. } elseif ($chardata[$j]['type'] != 'WS') {
  9801. break;
  9802. }
  9803. ++$j;
  9804. }
  9805. }
  9806. }
  9807. // Arabic Shaping
  9808. // 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.
  9809. if ($arabic) {
  9810. $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
  9811. $alfletter = array(1570,1571,1573,1575);
  9812. $chardata2 = $chardata;
  9813. $laaletter = false;
  9814. $charAL = array();
  9815. $x = 0;
  9816. for ($i=0; $i < $numchars; ++$i) {
  9817. if (($unicode[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
  9818. $charAL[$x] = $chardata[$i];
  9819. $charAL[$x]['i'] = $i;
  9820. $chardata[$i]['x'] = $x;
  9821. ++$x;
  9822. }
  9823. }
  9824. $numAL = $x;
  9825. for ($i=0; $i < $numchars; ++$i) {
  9826. $thischar = $chardata[$i];
  9827. if ($i > 0) {
  9828. $prevchar = $chardata[($i-1)];
  9829. } else {
  9830. $prevchar = false;
  9831. }
  9832. if (($i+1) < $numchars) {
  9833. $nextchar = $chardata[($i+1)];
  9834. } else {
  9835. $nextchar = false;
  9836. }
  9837. if ($unicode[$thischar['char']] == 'AL') {
  9838. $x = $thischar['x'];
  9839. if ($x > 0) {
  9840. $prevchar = $charAL[($x-1)];
  9841. } else {
  9842. $prevchar = false;
  9843. }
  9844. if (($x+1) < $numAL) {
  9845. $nextchar = $charAL[($x+1)];
  9846. } else {
  9847. $nextchar = false;
  9848. }
  9849. // if laa letter
  9850. if (($prevchar !== false) AND ($prevchar['char'] == 1604) AND (in_array($thischar['char'], $alfletter))) {
  9851. $arabicarr = $laa_array;
  9852. $laaletter = true;
  9853. if ($x > 1) {
  9854. $prevchar = $charAL[($x-2)];
  9855. } else {
  9856. $prevchar = false;
  9857. }
  9858. } else {
  9859. $arabicarr = $unicode_arlet;
  9860. $laaletter = false;
  9861. }
  9862. if (($prevchar !== false) AND ($nextchar !== false) AND
  9863. (($unicode[$prevchar['char']] == 'AL') OR ($unicode[$prevchar['char']] == 'NSM')) AND
  9864. (($unicode[$nextchar['char']] == 'AL') OR ($unicode[$nextchar['char']] == 'NSM')) AND
  9865. ($prevchar['type'] == $thischar['type']) AND
  9866. ($nextchar['type'] == $thischar['type']) AND
  9867. ($nextchar['char'] != 1567)) {
  9868. if (in_array($prevchar['char'], $endedletter)) {
  9869. if (isset($arabicarr[$thischar['char']][2])) {
  9870. // initial
  9871. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  9872. }
  9873. } else {
  9874. if (isset($arabicarr[$thischar['char']][3])) {
  9875. // medial
  9876. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
  9877. }
  9878. }
  9879. } elseif (($nextchar !== false) AND
  9880. (($unicode[$nextchar['char']] == 'AL') OR ($unicode[$nextchar['char']] == 'NSM')) AND
  9881. ($nextchar['type'] == $thischar['type']) AND
  9882. ($nextchar['char'] != 1567)) {
  9883. if (isset($arabicarr[$chardata[$i]['char']][2])) {
  9884. // initial
  9885. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  9886. }
  9887. } elseif ((($prevchar !== false) AND
  9888. (($unicode[$prevchar['char']] == 'AL') OR ($unicode[$prevchar['char']] == 'NSM')) AND
  9889. ($prevchar['type'] == $thischar['type'])) OR
  9890. (($nextchar !== false) AND ($nextchar['char'] == 1567))) {
  9891. // final
  9892. if (($i > 1) AND ($thischar['char'] == 1607) AND
  9893. ($chardata[$i-1]['char'] == 1604) AND
  9894. ($chardata[$i-2]['char'] == 1604)) {
  9895. //Allah Word
  9896. // mark characters to delete with false
  9897. $chardata2[$i-2]['char'] = false;
  9898. $chardata2[$i-1]['char'] = false;
  9899. $chardata2[$i]['char'] = 65010;
  9900. } else {
  9901. if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
  9902. if (isset($arabicarr[$thischar['char']][0])) {
  9903. // isolated
  9904. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  9905. }
  9906. } else {
  9907. if (isset($arabicarr[$thischar['char']][1])) {
  9908. // final
  9909. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
  9910. }
  9911. }
  9912. }
  9913. } elseif (isset($arabicarr[$thischar['char']][0])) {
  9914. // isolated
  9915. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  9916. }
  9917. // if laa letter
  9918. if ($laaletter) {
  9919. // mark characters to delete with false
  9920. $chardata2[($charAL[($x-1)]['i'])]['char'] = false;
  9921. }
  9922. } // end if AL (Arabic Letter)
  9923. } // end for each char
  9924. /*
  9925. * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced.
  9926. * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  9927. */
  9928. $cw = &$this->CurrentFont['cw'];
  9929. for ($i = 0; $i < ($numchars-1); ++$i) {
  9930. if (($chardata2[$i]['char'] == 1617) AND (isset($diacritics[($chardata2[$i+1]['char'])]))) {
  9931. // check if the subtitution font is defined on current font
  9932. if (isset($cw[($diacritics[($chardata2[$i+1]['char'])])])) {
  9933. $chardata2[$i]['char'] = false;
  9934. $chardata2[$i+1]['char'] = $diacritics[($chardata2[$i+1]['char'])];
  9935. }
  9936. }
  9937. }
  9938. // remove marked characters
  9939. foreach ($chardata2 as $key => $value) {
  9940. if ($value['char'] === false) {
  9941. unset($chardata2[$key]);
  9942. }
  9943. }
  9944. $chardata = array_values($chardata2);
  9945. $numchars = count($chardata);
  9946. unset($chardata2);
  9947. unset($arabicarr);
  9948. unset($laaletter);
  9949. unset($charAL);
  9950. }
  9951. // 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.
  9952. for ($j=$maxlevel; $j > 0; $j--) {
  9953. $ordarray = Array();
  9954. $revarr = Array();
  9955. $onlevel = false;
  9956. for ($i=0; $i < $numchars; ++$i) {
  9957. if ($chardata[$i]['level'] >= $j) {
  9958. $onlevel = true;
  9959. if (isset($unicode_mirror[$chardata[$i]['char']])) {
  9960. // 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.
  9961. $chardata[$i]['char'] = $unicode_mirror[$chardata[$i]['char']];
  9962. }
  9963. $revarr[] = $chardata[$i];
  9964. } else {
  9965. if ($onlevel) {
  9966. $revarr = array_reverse($revarr);
  9967. $ordarray = array_merge($ordarray, $revarr);
  9968. $revarr = Array();
  9969. $onlevel = false;
  9970. }
  9971. $ordarray[] = $chardata[$i];
  9972. }
  9973. }
  9974. if ($onlevel) {
  9975. $revarr = array_reverse($revarr);
  9976. $ordarray = array_merge($ordarray, $revarr);
  9977. }
  9978. $chardata = $ordarray;
  9979. }
  9980. $ordarray = array();
  9981. for ($i=0; $i < $numchars; ++$i) {
  9982. $ordarray[] = $chardata[$i]['char'];
  9983. }
  9984. return $ordarray;
  9985. }
  9986. // END OF BIDIRECTIONAL TEXT SECTION -------------------
  9987. /**
  9988. * Adds a bookmark.
  9989. * @param string $txt bookmark description.
  9990. * @param int $level bookmark level (minimum value is 0).
  9991. * @param float $y Ordinate of the boorkmark position (default = -1 = current position).
  9992. * @param int $page target page number (leave empty for current page).
  9993. * @access public
  9994. * @author Olivier Plathey, Nicola Asuni
  9995. * @since 2.1.002 (2008-02-12)
  9996. */
  9997. public function Bookmark($txt, $level=0, $y=-1, $page='') {
  9998. if ($level < 0) {
  9999. $level = 0;
  10000. }
  10001. if (isset($this->outlines[0])) {
  10002. $lastoutline = end($this->outlines);
  10003. $maxlevel = $lastoutline['l'] + 1;
  10004. } else {
  10005. $maxlevel = 0;
  10006. }
  10007. if ($level > $maxlevel) {
  10008. $level = $maxlevel;
  10009. }
  10010. if ($y == -1) {
  10011. $y = $this->GetY();
  10012. }
  10013. if (empty($page)) {
  10014. $page = $this->PageNo();
  10015. }
  10016. $this->outlines[] = array('t' => $txt, 'l' => $level, 'y' => $y, 'p' => $page);
  10017. }
  10018. /**
  10019. * Create a bookmark PDF string.
  10020. * @access protected
  10021. * @author Olivier Plathey, Nicola Asuni
  10022. * @since 2.1.002 (2008-02-12)
  10023. */
  10024. protected function _putbookmarks() {
  10025. $nb = count($this->outlines);
  10026. if ($nb == 0) {
  10027. return;
  10028. }
  10029. // get sorting columns
  10030. $outline_p = array();
  10031. $outline_y = array();
  10032. foreach ($this->outlines as $key => $row) {
  10033. $outline_p[$key] = $row['p'];
  10034. $outline_k[$key] = $key;
  10035. }
  10036. // sort outlines by page and original position
  10037. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  10038. $lru = array();
  10039. $level = 0;
  10040. foreach ($this->outlines as $i => $o) {
  10041. if ($o['l'] > 0) {
  10042. $parent = $lru[($o['l'] - 1)];
  10043. //Set parent and last pointers
  10044. $this->outlines[$i]['parent'] = $parent;
  10045. $this->outlines[$parent]['last'] = $i;
  10046. if ($o['l'] > $level) {
  10047. //Level increasing: set first pointer
  10048. $this->outlines[$parent]['first'] = $i;
  10049. }
  10050. } else {
  10051. $this->outlines[$i]['parent'] = $nb;
  10052. }
  10053. if (($o['l'] <= $level) AND ($i > 0)) {
  10054. //Set prev and next pointers
  10055. $prev = $lru[$o['l']];
  10056. $this->outlines[$prev]['next'] = $i;
  10057. $this->outlines[$i]['prev'] = $prev;
  10058. }
  10059. $lru[$o['l']] = $i;
  10060. $level = $o['l'];
  10061. }
  10062. //Outline items
  10063. $n = $this->n + 1;
  10064. foreach ($this->outlines as $i => $o) {
  10065. $this->_newobj();
  10066. $this->_out('<</Title '.$this->_textstring($o['t']));
  10067. $this->_out('/Parent '.($n + $o['parent']).' 0 R');
  10068. if (isset($o['prev']))
  10069. $this->_out('/Prev '.($n + $o['prev']).' 0 R');
  10070. if (isset($o['next']))
  10071. $this->_out('/Next '.($n + $o['next']).' 0 R');
  10072. if (isset($o['first']))
  10073. $this->_out('/First '.($n + $o['first']).' 0 R');
  10074. if (isset($o['last']))
  10075. $this->_out('/Last '.($n + $o['last']).' 0 R');
  10076. $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]', (1 + (2 * $o['p'])), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k))));
  10077. $this->_out('/Count 0>>');
  10078. $this->_out('endobj');
  10079. }
  10080. //Outline root
  10081. $this->_newobj();
  10082. $this->OutlineRoot = $this->n;
  10083. $this->_out('<</Type /Outlines /First '.$n.' 0 R');
  10084. $this->_out('/Last '.($n + $lru[0]).' 0 R>>');
  10085. $this->_out('endobj');
  10086. }
  10087. // --- JAVASCRIPT ------------------------------------------------------
  10088. /**
  10089. * Adds a javascript
  10090. * @param string $script Javascript code
  10091. * @access public
  10092. * @author Johannes Güntert, Nicola Asuni
  10093. * @since 2.1.002 (2008-02-12)
  10094. */
  10095. public function IncludeJS($script) {
  10096. $this->javascript .= $script;
  10097. }
  10098. /**
  10099. * Adds a javascript object and return object ID
  10100. * @param string $script Javascript code
  10101. * @param boolean $onload if true executes this object when opening the document
  10102. * @return int internal object ID
  10103. * @access public
  10104. * @author Nicola Asuni
  10105. * @since 4.8.000 (2009-09-07)
  10106. */
  10107. public function addJavascriptObject($script, $onload=false) {
  10108. ++$this->js_obj_id;
  10109. $this->js_objects[$this->js_obj_id] = array('js' => $script, 'onload' => $onload);
  10110. return $this->js_obj_id;
  10111. }
  10112. /**
  10113. * Create a javascript PDF string.
  10114. * @access protected
  10115. * @author Johannes Güntert, Nicola Asuni
  10116. * @since 2.1.002 (2008-02-12)
  10117. */
  10118. protected function _putjavascript() {
  10119. if (empty($this->javascript) AND empty($this->js_objects)) {
  10120. return;
  10121. }
  10122. if (strpos($this->javascript, 'this.addField') > 0) {
  10123. if (!$this->ur) {
  10124. //$this->setUserRights();
  10125. }
  10126. // the following two lines are used to avoid form fields duplication after saving
  10127. // The addField method only works on Acrobat Writer, unless the document is signed with Adobe private key (UR3)
  10128. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  10129. $jsb = "getField('tcpdfdocsaved').value='saved';";
  10130. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  10131. }
  10132. $this->n_js = $this->_newobj();
  10133. $this->_out('<<');
  10134. $this->_out('/Names [');
  10135. if (!empty($this->javascript)) {
  10136. $this->_out('(EmbeddedJS) '.($this->n + 1).' 0 R');
  10137. }
  10138. if (!empty($this->js_objects)) {
  10139. foreach ($this->js_objects as $key => $val) {
  10140. if ($val['onload']) {
  10141. $this->_out('(JS'.$key.') '.$key.' 0 R');
  10142. }
  10143. }
  10144. }
  10145. $this->_out(']');
  10146. $this->_out('>>');
  10147. $this->_out('endobj');
  10148. // default Javascript object
  10149. if (!empty($this->javascript)) {
  10150. $this->_newobj();
  10151. $this->_out('<<');
  10152. $this->_out('/S /JavaScript');
  10153. $this->_out('/JS '.$this->_textstring($this->javascript));
  10154. $this->_out('>>');
  10155. $this->_out('endobj');
  10156. }
  10157. // additional Javascript objects
  10158. if (!empty($this->js_objects)) {
  10159. foreach ($this->js_objects as $key => $val) {
  10160. $this->offsets[$key] = $this->bufferlen;
  10161. $this->_out($key.' 0 obj');
  10162. $this->_out('<<');
  10163. $this->_out('/S /JavaScript');
  10164. $this->_out('/JS '.$this->_textstring($val['js']));
  10165. $this->_out('>>');
  10166. $this->_out('endobj');
  10167. }
  10168. }
  10169. }
  10170. /**
  10171. * Convert color to javascript color.
  10172. * @param string $color color name or #RRGGBB
  10173. * @access protected
  10174. * @author Denis Van Nuffelen, Nicola Asuni
  10175. * @since 2.1.002 (2008-02-12)
  10176. */
  10177. protected function _JScolor($color) {
  10178. static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
  10179. if (substr($color,0,1) == '#') {
  10180. return sprintf("['RGB',%.3F,%.3F,%.3F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255);
  10181. }
  10182. if (!in_array($color,$aColors)) {
  10183. $this->Error('Invalid color: '.$color);
  10184. }
  10185. return 'color.'.$color;
  10186. }
  10187. /**
  10188. * Adds a javascript form field.
  10189. * @param string $type field type
  10190. * @param string $name field name
  10191. * @param int $x horizontal position
  10192. * @param int $y vertical position
  10193. * @param int $w width
  10194. * @param int $h height
  10195. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10196. * @access protected
  10197. * @author Denis Van Nuffelen, Nicola Asuni
  10198. * @since 2.1.002 (2008-02-12)
  10199. */
  10200. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  10201. if ($this->rtl) {
  10202. $x = $x - $w;
  10203. }
  10204. // the followind avoid fields duplication after saving the document
  10205. $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {";
  10206. $k = $this->k;
  10207. $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
  10208. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  10209. while (list($key, $val) = each($prop)) {
  10210. if (strcmp(substr($key, -5), 'Color') == 0) {
  10211. $val = $this->_JScolor($val);
  10212. } else {
  10213. $val = "'".$val."'";
  10214. }
  10215. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  10216. }
  10217. if ($this->rtl) {
  10218. $this->x -= $w;
  10219. } else {
  10220. $this->x += $w;
  10221. }
  10222. $this->javascript .= '}';
  10223. }
  10224. // --- FORM FIELDS -----------------------------------------------------
  10225. /**
  10226. * Convert JavaScript form fields properties array to Annotation Properties array.
  10227. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10228. * @return array of annotation properties
  10229. * @access protected
  10230. * @author Nicola Asuni
  10231. * @since 4.8.000 (2009-09-06)
  10232. */
  10233. protected function getAnnotOptFromJSProp($prop) {
  10234. if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
  10235. // the annotation options area lready defined
  10236. return $prop['aopt'];
  10237. }
  10238. $opt = array(); // value to be returned
  10239. // alignment: Controls how the text is laid out within the text field.
  10240. if (isset($prop['alignment'])) {
  10241. switch ($prop['alignment']) {
  10242. case 'left': {
  10243. $opt['q'] = 0;
  10244. break;
  10245. }
  10246. case 'center': {
  10247. $opt['q'] = 1;
  10248. break;
  10249. }
  10250. case 'right': {
  10251. $opt['q'] = 2;
  10252. break;
  10253. }
  10254. default: {
  10255. $opt['q'] = ($this->rtl)?2:0;
  10256. break;
  10257. }
  10258. }
  10259. }
  10260. // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
  10261. if (isset($prop['lineWidth'])) {
  10262. $linewidth = intval($prop['lineWidth']);
  10263. } else {
  10264. $linewidth = 1;
  10265. }
  10266. // borderStyle: The border style for a field.
  10267. if (isset($prop['borderStyle'])) {
  10268. switch ($prop['borderStyle']) {
  10269. case 'border.d':
  10270. case 'dashed': {
  10271. $opt['border'] = array(0, 0, $linewidth, array(3, 2));
  10272. $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
  10273. break;
  10274. }
  10275. case 'border.b':
  10276. case 'beveled': {
  10277. $opt['border'] = array(0, 0, $linewidth);
  10278. $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
  10279. break;
  10280. }
  10281. case 'border.i':
  10282. case 'inset': {
  10283. $opt['border'] = array(0, 0, $linewidth);
  10284. $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
  10285. break;
  10286. }
  10287. case 'border.u':
  10288. case 'underline': {
  10289. $opt['border'] = array(0, 0, $linewidth);
  10290. $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
  10291. break;
  10292. }
  10293. default:
  10294. case 'border.s':
  10295. case 'solid': {
  10296. $opt['border'] = array(0, 0, $linewidth);
  10297. $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
  10298. break;
  10299. }
  10300. }
  10301. }
  10302. if (isset($prop['border']) AND is_array($prop['border'])) {
  10303. $opt['border'] = $prop['border'];
  10304. }
  10305. if (!isset($opt['mk'])) {
  10306. $opt['mk'] = array();
  10307. }
  10308. if (!isset($opt['mk']['if'])) {
  10309. $opt['mk']['if'] = array();
  10310. }
  10311. $opt['mk']['if']['a'] = array(0.5, 0.5);
  10312. // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
  10313. if (isset($prop['buttonAlignX'])) {
  10314. $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
  10315. }
  10316. // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
  10317. if (isset($prop['buttonAlignY'])) {
  10318. $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
  10319. }
  10320. // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
  10321. if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
  10322. $opt['mk']['if']['fb'] = true;
  10323. }
  10324. // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
  10325. if (isset($prop['buttonScaleHow'])) {
  10326. switch ($prop['buttonScaleHow']) {
  10327. case 'scaleHow.proportional': {
  10328. $opt['mk']['if']['s'] = 'P';
  10329. break;
  10330. }
  10331. case 'scaleHow.anamorphic': {
  10332. $opt['mk']['if']['s'] = 'A';
  10333. break;
  10334. }
  10335. }
  10336. }
  10337. // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
  10338. if (isset($prop['buttonScaleWhen'])) {
  10339. switch ($prop['buttonScaleWhen']) {
  10340. case 'scaleWhen.always': {
  10341. $opt['mk']['if']['sw'] = 'A';
  10342. break;
  10343. }
  10344. case 'scaleWhen.never': {
  10345. $opt['mk']['if']['sw'] = 'N';
  10346. break;
  10347. }
  10348. case 'scaleWhen.tooBig': {
  10349. $opt['mk']['if']['sw'] = 'B';
  10350. break;
  10351. }
  10352. case 'scaleWhen.tooSmall': {
  10353. $opt['mk']['if']['sw'] = 'S';
  10354. break;
  10355. }
  10356. }
  10357. }
  10358. // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
  10359. if (isset($prop['buttonPosition'])) {
  10360. switch ($prop['buttonPosition']) {
  10361. case 0:
  10362. case 'position.textOnly': {
  10363. $opt['mk']['tp'] = 0;
  10364. break;
  10365. }
  10366. case 1:
  10367. case 'position.iconOnly': {
  10368. $opt['mk']['tp'] = 1;
  10369. break;
  10370. }
  10371. case 2:
  10372. case 'position.iconTextV': {
  10373. $opt['mk']['tp'] = 2;
  10374. break;
  10375. }
  10376. case 3:
  10377. case 'position.textIconV': {
  10378. $opt['mk']['tp'] = 3;
  10379. break;
  10380. }
  10381. case 4:
  10382. case 'position.iconTextH': {
  10383. $opt['mk']['tp'] = 4;
  10384. break;
  10385. }
  10386. case 5:
  10387. case 'position.textIconH': {
  10388. $opt['mk']['tp'] = 5;
  10389. break;
  10390. }
  10391. case 6:
  10392. case 'position.overlay': {
  10393. $opt['mk']['tp'] = 6;
  10394. break;
  10395. }
  10396. }
  10397. }
  10398. // fillColor: Specifies the background color for a field.
  10399. if (isset($prop['fillColor'])) {
  10400. if (is_array($prop['fillColor'])) {
  10401. $opt['mk']['bg'] = $prop['fillColor'];
  10402. } else {
  10403. $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']);
  10404. }
  10405. }
  10406. // 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.
  10407. if (isset($prop['strokeColor'])) {
  10408. if (is_array($prop['strokeColor'])) {
  10409. $opt['mk']['bc'] = $prop['strokeColor'];
  10410. } else {
  10411. $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']);
  10412. }
  10413. }
  10414. // rotation: The rotation of a widget in counterclockwise increments.
  10415. if (isset($prop['rotation'])) {
  10416. $opt['mk']['r'] = $prop['rotation'];
  10417. }
  10418. // charLimit: Limits the number of characters that a user can type into a text field.
  10419. if (isset($prop['charLimit'])) {
  10420. $opt['maxlen'] = intval($prop['charLimit']);
  10421. }
  10422. if (!isset($ff)) {
  10423. $ff = 0;
  10424. }
  10425. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  10426. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  10427. $ff += 1 << 0;
  10428. }
  10429. // required: Specifies whether a field requires a value.
  10430. if (isset($prop['required']) AND ($prop['required'] == 'true')) {
  10431. $ff += 1 << 1;
  10432. }
  10433. // multiline: Controls how text is wrapped within the field.
  10434. if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
  10435. $ff += 1 << 12;
  10436. }
  10437. // password: Specifies whether the field should display asterisks when data is entered in the field.
  10438. if (isset($prop['password']) AND ($prop['password'] == 'true')) {
  10439. $ff += 1 << 13;
  10440. }
  10441. // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
  10442. if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
  10443. $ff += 1 << 14;
  10444. }
  10445. // Radio: If set, the field is a set of radio buttons.
  10446. if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
  10447. $ff += 1 << 15;
  10448. }
  10449. // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
  10450. if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
  10451. $ff += 1 << 16;
  10452. }
  10453. // Combo: If set, the field is a combo box; if clear, the field is a list box.
  10454. if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
  10455. $ff += 1 << 17;
  10456. }
  10457. // editable: Controls whether a combo box is editable.
  10458. if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
  10459. $ff += 1 << 18;
  10460. }
  10461. // Sort: If set, the field's option items shall be sorted alphabetically.
  10462. if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
  10463. $ff += 1 << 19;
  10464. }
  10465. // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
  10466. if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
  10467. $ff += 1 << 20;
  10468. }
  10469. // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
  10470. if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
  10471. $ff += 1 << 21;
  10472. }
  10473. // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
  10474. if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
  10475. $ff += 1 << 22;
  10476. }
  10477. // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
  10478. if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
  10479. $ff += 1 << 23;
  10480. }
  10481. // 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.
  10482. if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
  10483. $ff += 1 << 24;
  10484. }
  10485. // 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.
  10486. if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
  10487. $ff += 1 << 25;
  10488. }
  10489. // richText: If true, the field allows rich text formatting.
  10490. if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
  10491. $ff += 1 << 25;
  10492. }
  10493. // commitOnSelChange: Controls whether a field value is committed after a selection change.
  10494. if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
  10495. $ff += 1 << 26;
  10496. }
  10497. $opt['ff'] = $ff;
  10498. // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
  10499. if (isset($prop['defaultValue'])) {
  10500. $opt['dv'] = $prop['defaultValue'];
  10501. }
  10502. $f = 4; // default value for annotation flags
  10503. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  10504. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  10505. $f += 1 << 6;
  10506. }
  10507. // display: Controls whether the field is hidden or visible on screen and in print.
  10508. if (isset($prop['display'])) {
  10509. if ($prop['display'] == 'display.visible') {
  10510. //
  10511. } elseif ($prop['display'] == 'display.hidden') {
  10512. $f += 1 << 1;
  10513. } elseif ($prop['display'] == 'display.noPrint') {
  10514. $f -= 1 << 2;
  10515. } elseif ($prop['display'] == 'display.noView') {
  10516. $f += 1 << 5;
  10517. }
  10518. }
  10519. $opt['f'] = $f;
  10520. // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
  10521. if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
  10522. $opt['i'] = $prop['currentValueIndices'];
  10523. }
  10524. // value: The value of the field data that the user has entered.
  10525. if (isset($prop['value'])) {
  10526. if (is_array($prop['value'])) {
  10527. $opt['opt'] = array();
  10528. foreach ($prop['value'] AS $key => $optval) {
  10529. // exportValues: An array of strings representing the export values for the field.
  10530. if (isset($prop['exportValues'][$key])) {
  10531. $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
  10532. } else {
  10533. $opt['opt'][$key] = $prop['value'][$key];
  10534. }
  10535. }
  10536. } else {
  10537. $opt['v'] = $prop['value'];
  10538. }
  10539. }
  10540. // richValue: This property specifies the text contents and formatting of a rich text field.
  10541. if (isset($prop['richValue'])) {
  10542. $opt['rv'] = $prop['richValue'];
  10543. }
  10544. // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
  10545. if (isset($prop['submitName'])) {
  10546. $opt['tm'] = $prop['submitName'];
  10547. }
  10548. // name: Fully qualified field name.
  10549. if (isset($prop['name'])) {
  10550. $opt['t'] = $prop['name'];
  10551. }
  10552. // userName: The user name (short description string) of the field.
  10553. if (isset($prop['userName'])) {
  10554. $opt['tu'] = $prop['userName'];
  10555. }
  10556. // highlight: Defines how a button reacts when a user clicks it.
  10557. if (isset($prop['highlight'])) {
  10558. switch ($prop['highlight']) {
  10559. case 'none':
  10560. case 'highlight.n': {
  10561. $opt['h'] = 'N';
  10562. break;
  10563. }
  10564. case 'invert':
  10565. case 'highlight.i': {
  10566. $opt['h'] = 'i';
  10567. break;
  10568. }
  10569. case 'push':
  10570. case 'highlight.p': {
  10571. $opt['h'] = 'P';
  10572. break;
  10573. }
  10574. case 'outline':
  10575. case 'highlight.o': {
  10576. $opt['h'] = 'O';
  10577. break;
  10578. }
  10579. }
  10580. }
  10581. // Unsupported options:
  10582. // - calcOrderIndex: Changes the calculation order of fields in the document.
  10583. // - delay: Delays the redrawing of a field's appearance.
  10584. // - defaultStyle: This property defines the default style attributes for the form field.
  10585. // - style: Allows the user to set the glyph style of a check box or radio button.
  10586. // - textColor, textFont, textSize
  10587. return $opt;
  10588. }
  10589. /**
  10590. * Set default properties for form fields.
  10591. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10592. * @access public
  10593. * @author Nicola Asuni
  10594. * @since 4.8.000 (2009-09-06)
  10595. */
  10596. public function setFormDefaultProp($prop=array()) {
  10597. $this->default_form_prop = $prop;
  10598. }
  10599. /**
  10600. * Return the default properties for form fields.
  10601. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10602. * @access public
  10603. * @author Nicola Asuni
  10604. * @since 4.8.000 (2009-09-06)
  10605. */
  10606. public function getFormDefaultProp() {
  10607. return $this->default_form_prop;
  10608. }
  10609. /**
  10610. * Creates a text field
  10611. * @param string $name field name
  10612. * @param float $w Width of the rectangle
  10613. * @param float $h Height of the rectangle
  10614. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10615. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10616. * @param float $x Abscissa of the upper-left corner of the rectangle
  10617. * @param float $y Ordinate of the upper-left corner of the rectangle
  10618. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10619. * @access public
  10620. * @author Nicola Asuni
  10621. * @since 4.8.000 (2009-09-07)
  10622. */
  10623. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  10624. if ($x === '') {
  10625. $x = $this->x;
  10626. }
  10627. if ($y === '') {
  10628. $y = $this->y;
  10629. }
  10630. if ($js) {
  10631. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  10632. return;
  10633. }
  10634. // get default style
  10635. $prop = array_merge($this->getFormDefaultProp(), $prop);
  10636. // get annotation data
  10637. $popt = $this->getAnnotOptFromJSProp($prop);
  10638. // set default appearance stream
  10639. $font = $this->FontFamily;
  10640. $fontkey = array_search($font, $this->fontkeys);
  10641. if (!in_array($fontkey, $this->annotation_fonts)) {
  10642. $this->annotation_fonts[$font] = $fontkey;
  10643. }
  10644. $fontstyle = sprintf('/F%d %.2F Tf %s', ($fontkey + 1), $this->FontSizePt, $this->TextColor);
  10645. $popt['da'] = $fontstyle;
  10646. $popt['ap'] = array();
  10647. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  10648. // merge options
  10649. $opt = array_merge($popt, $opt);
  10650. // remove some conflicting options
  10651. unset($opt['bs']);
  10652. // set remaining annotation data
  10653. $opt['Subtype'] = 'Widget';
  10654. $opt['ft'] = 'Tx';
  10655. $opt['t'] = $name;
  10656. /*
  10657. Additional annotation's parameters (check _putannotsobj() method):
  10658. //$opt['f']
  10659. //$opt['ap']
  10660. //$opt['as']
  10661. //$opt['bs']
  10662. //$opt['be']
  10663. //$opt['c']
  10664. //$opt['border']
  10665. //$opt['h']
  10666. //$opt['mk']
  10667. //$opt['mk']['r']
  10668. //$opt['mk']['bc']
  10669. //$opt['mk']['bg']
  10670. //$opt['mk']['ca']
  10671. //$opt['mk']['rc']
  10672. //$opt['mk']['ac']
  10673. //$opt['mk']['i']
  10674. //$opt['mk']['ri']
  10675. //$opt['mk']['ix']
  10676. //$opt['mk']['if']
  10677. //$opt['mk']['if']['sw']
  10678. //$opt['mk']['if']['s']
  10679. //$opt['mk']['if']['a']
  10680. //$opt['mk']['if']['fb']
  10681. //$opt['mk']['tp']
  10682. //$opt['tu']
  10683. //$opt['tm']
  10684. //$opt['ff']
  10685. //$opt['v']
  10686. //$opt['dv']
  10687. //$opt['a']
  10688. //$opt['aa']
  10689. //$opt['q']
  10690. */
  10691. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  10692. if ($this->rtl) {
  10693. $this->x -= $w;
  10694. } else {
  10695. $this->x += $w;
  10696. }
  10697. }
  10698. /**
  10699. * Creates a RadioButton field
  10700. * @param string $name field name
  10701. * @param int $w width
  10702. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10703. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10704. * @param string $onvalue value to be returned if selected.
  10705. * @param boolean $checked define the initial state.
  10706. * @param float $x Abscissa of the upper-left corner of the rectangle
  10707. * @param float $y Ordinate of the upper-left corner of the rectangle
  10708. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10709. * @access public
  10710. * @author Nicola Asuni
  10711. * @since 4.8.000 (2009-09-07)
  10712. */
  10713. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
  10714. if ($x === '') {
  10715. $x = $this->x;
  10716. }
  10717. if ($y === '') {
  10718. $y = $this->y;
  10719. }
  10720. if ($js) {
  10721. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  10722. return;
  10723. }
  10724. if ($this->empty_string($onvalue)) {
  10725. $onvalue = 'On';
  10726. }
  10727. if ($checked) {
  10728. $defval = $onvalue;
  10729. } else {
  10730. $defval = 'Off';
  10731. }
  10732. // set data for parent group
  10733. if (!isset($this->radiobutton_groups[$this->page])) {
  10734. $this->radiobutton_groups[$this->page] = array();
  10735. }
  10736. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  10737. $this->radiobutton_groups[$this->page][$name] = array();
  10738. ++$this->annot_obj_id;
  10739. $this->radio_groups[] = $this->annot_obj_id;
  10740. }
  10741. // save object ID to be added on Kids entry on parent object
  10742. $this->radiobutton_groups[$this->page][$name][] = array('kid' => ($this->annot_obj_id + 1), 'def' => $defval);
  10743. // get default style
  10744. $prop = array_merge($this->getFormDefaultProp(), $prop);
  10745. $prop['NoToggleToOff'] = 'true';
  10746. $prop['Radio'] = 'true';
  10747. $prop['borderStyle'] = 'inset';
  10748. // get annotation data
  10749. $popt = $this->getAnnotOptFromJSProp($prop);
  10750. // set additional default values
  10751. $font = 'zapfdingbats';
  10752. $this->AddFont($font);
  10753. $fontkey = array_search($font, $this->fontkeys);
  10754. if (!in_array($fontkey, $this->annotation_fonts)) {
  10755. $this->annotation_fonts[$font] = $fontkey;
  10756. }
  10757. $fontstyle = sprintf('/F%d %.2F Tf %s', ($fontkey + 1), $this->FontSizePt, $this->TextColor);
  10758. $popt['da'] = $fontstyle;
  10759. $popt['ap'] = array();
  10760. $popt['ap']['n'] = array();
  10761. $popt['ap']['n'][$onvalue] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10762. $popt['ap']['n']['Off'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10763. if (!isset($popt['mk'])) {
  10764. $popt['mk'] = array();
  10765. }
  10766. $popt['mk']['ca'] = '(l)';
  10767. // merge options
  10768. $opt = array_merge($popt, $opt);
  10769. // set remaining annotation data
  10770. $opt['Subtype'] = 'Widget';
  10771. $opt['ft'] = 'Btn';
  10772. if ($checked) {
  10773. $opt['v'] = array('/'.$onvalue);
  10774. $opt['as'] = $onvalue;
  10775. } else {
  10776. $opt['as'] = 'Off';
  10777. }
  10778. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  10779. if ($this->rtl) {
  10780. $this->x -= $w;
  10781. } else {
  10782. $this->x += $w;
  10783. }
  10784. }
  10785. /**
  10786. * Creates a List-box field
  10787. * @param string $name field name
  10788. * @param int $w width
  10789. * @param int $h height
  10790. * @param array $values array containing the list of values.
  10791. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10792. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10793. * @param float $x Abscissa of the upper-left corner of the rectangle
  10794. * @param float $y Ordinate of the upper-left corner of the rectangle
  10795. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10796. * @access public
  10797. * @author Nicola Asuni
  10798. * @since 4.8.000 (2009-09-07)
  10799. */
  10800. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  10801. if ($x === '') {
  10802. $x = $this->x;
  10803. }
  10804. if ($y === '') {
  10805. $y = $this->y;
  10806. }
  10807. if ($js) {
  10808. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  10809. $s = '';
  10810. foreach ($values as $value) {
  10811. $s .= "'".addslashes($value)."',";
  10812. }
  10813. $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
  10814. return;
  10815. }
  10816. // get default style
  10817. $prop = array_merge($this->getFormDefaultProp(), $prop);
  10818. // get annotation data
  10819. $popt = $this->getAnnotOptFromJSProp($prop);
  10820. // set additional default values
  10821. $font = $this->FontFamily;
  10822. $fontkey = array_search($font, $this->fontkeys);
  10823. if (!in_array($fontkey, $this->annotation_fonts)) {
  10824. $this->annotation_fonts[$font] = $fontkey;
  10825. }
  10826. $fontstyle = sprintf('/F%d %.2F Tf %s', ($fontkey + 1), $this->FontSizePt, $this->TextColor);
  10827. $popt['da'] = $fontstyle;
  10828. $popt['ap'] = array();
  10829. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  10830. // merge options
  10831. $opt = array_merge($popt, $opt);
  10832. // set remaining annotation data
  10833. $opt['Subtype'] = 'Widget';
  10834. $opt['ft'] = 'Ch';
  10835. $opt['t'] = $name;
  10836. $opt['opt'] = $values;
  10837. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  10838. if ($this->rtl) {
  10839. $this->x -= $w;
  10840. } else {
  10841. $this->x += $w;
  10842. }
  10843. }
  10844. /**
  10845. * Creates a Combo-box field
  10846. * @param string $name field name
  10847. * @param int $w width
  10848. * @param int $h height
  10849. * @param array $values array containing the list of values.
  10850. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10851. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10852. * @param float $x Abscissa of the upper-left corner of the rectangle
  10853. * @param float $y Ordinate of the upper-left corner of the rectangle
  10854. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10855. * @access public
  10856. * @author Nicola Asuni
  10857. * @since 4.8.000 (2009-09-07)
  10858. */
  10859. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  10860. if ($x === '') {
  10861. $x = $this->x;
  10862. }
  10863. if ($y === '') {
  10864. $y = $this->y;
  10865. }
  10866. if ($js) {
  10867. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  10868. $s = '';
  10869. foreach ($values as $value) {
  10870. $s .= "'".addslashes($value)."',";
  10871. }
  10872. $this->javascript .= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
  10873. return;
  10874. }
  10875. // get default style
  10876. $prop = array_merge($this->getFormDefaultProp(), $prop);
  10877. $prop['Combo'] = true;
  10878. // get annotation data
  10879. $popt = $this->getAnnotOptFromJSProp($prop);
  10880. // set additional default options
  10881. $font = $this->FontFamily;
  10882. $fontkey = array_search($font, $this->fontkeys);
  10883. if (!in_array($fontkey, $this->annotation_fonts)) {
  10884. $this->annotation_fonts[$font] = $fontkey;
  10885. }
  10886. $fontstyle = sprintf('/F%d %.2F Tf %s', ($fontkey + 1), $this->FontSizePt, $this->TextColor);
  10887. $popt['da'] = $fontstyle;
  10888. $popt['ap'] = array();
  10889. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  10890. // merge options
  10891. $opt = array_merge($popt, $opt);
  10892. // set remaining annotation data
  10893. $opt['Subtype'] = 'Widget';
  10894. $opt['ft'] = 'Ch';
  10895. $opt['t'] = $name;
  10896. $opt['opt'] = $values;
  10897. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  10898. if ($this->rtl) {
  10899. $this->x -= $w;
  10900. } else {
  10901. $this->x += $w;
  10902. }
  10903. }
  10904. /**
  10905. * Creates a CheckBox field
  10906. * @param string $name field name
  10907. * @param int $w width
  10908. * @param boolean $checked define the initial state.
  10909. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10910. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10911. * @param string $onvalue value to be returned if selected.
  10912. * @param float $x Abscissa of the upper-left corner of the rectangle
  10913. * @param float $y Ordinate of the upper-left corner of the rectangle
  10914. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10915. * @access public
  10916. * @author Nicola Asuni
  10917. * @since 4.8.000 (2009-09-07)
  10918. */
  10919. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
  10920. if ($x === '') {
  10921. $x = $this->x;
  10922. }
  10923. if ($y === '') {
  10924. $y = $this->y;
  10925. }
  10926. if ($js) {
  10927. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  10928. return;
  10929. }
  10930. if (!isset($prop['value'])) {
  10931. $prop['value'] = array('Yes');
  10932. }
  10933. // get default style
  10934. $prop = array_merge($this->getFormDefaultProp(), $prop);
  10935. $prop['borderStyle'] = 'inset';
  10936. // get annotation data
  10937. $popt = $this->getAnnotOptFromJSProp($prop);
  10938. // set additional default options
  10939. $font = 'zapfdingbats';
  10940. $this->AddFont($font);
  10941. $fontkey = array_search($font, $this->fontkeys);
  10942. if (!in_array($fontkey, $this->annotation_fonts)) {
  10943. $this->annotation_fonts[$font] = $fontkey;
  10944. }
  10945. $fontstyle = sprintf('/F%d %.2F Tf %s', ($fontkey + 1), $this->FontSizePt, $this->TextColor);
  10946. $popt['da'] = $fontstyle;
  10947. $popt['ap'] = array();
  10948. $popt['ap']['n'] = array();
  10949. $popt['ap']['n']['Yes'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10950. $popt['ap']['n']['Off'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10951. // merge options
  10952. $opt = array_merge($popt, $opt);
  10953. // set remaining annotation data
  10954. $opt['Subtype'] = 'Widget';
  10955. $opt['ft'] = 'Btn';
  10956. $opt['t'] = $name;
  10957. $opt['opt'] = array($onvalue);
  10958. if ($checked) {
  10959. $opt['v'] = array('/0');
  10960. $opt['as'] = 'Yes';
  10961. } else {
  10962. $opt['v'] = array('/Off');
  10963. $opt['as'] = 'Off';
  10964. }
  10965. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  10966. if ($this->rtl) {
  10967. $this->x -= $w;
  10968. } else {
  10969. $this->x += $w;
  10970. }
  10971. }
  10972. /**
  10973. * Creates a button field
  10974. * @param string $name field name
  10975. * @param int $w width
  10976. * @param int $h height
  10977. * @param string $caption caption.
  10978. * @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.
  10979. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10980. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10981. * @param float $x Abscissa of the upper-left corner of the rectangle
  10982. * @param float $y Ordinate of the upper-left corner of the rectangle
  10983. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10984. * @access public
  10985. * @author Nicola Asuni
  10986. * @since 4.8.000 (2009-09-07)
  10987. */
  10988. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  10989. if ($x === '') {
  10990. $x = $this->x;
  10991. }
  10992. if ($y === '') {
  10993. $y = $this->y;
  10994. }
  10995. if ($js) {
  10996. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  10997. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  10998. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  10999. $this->javascript .= 'f'.$name.".highlight='push';\n";
  11000. $this->javascript .= 'f'.$name.".print=false;\n";
  11001. return;
  11002. }
  11003. // get default style
  11004. $prop = array_merge($this->getFormDefaultProp(), $prop);
  11005. $prop['Pushbutton'] = 'true';
  11006. $prop['highlight'] = 'push';
  11007. $prop['display'] = 'display.noPrint';
  11008. // get annotation data
  11009. $popt = $this->getAnnotOptFromJSProp($prop);
  11010. // set additional default options
  11011. if (!isset($popt['mk'])) {
  11012. $popt['mk'] = array();
  11013. }
  11014. $popt['mk']['ca'] = $this->_textstring($caption);
  11015. $popt['mk']['rc'] = $this->_textstring($caption);
  11016. $popt['mk']['ac'] = $this->_textstring($caption);
  11017. $font = $this->FontFamily;
  11018. $fontkey = array_search($font, $this->fontkeys);
  11019. if (!in_array($fontkey, $this->annotation_fonts)) {
  11020. $this->annotation_fonts[$font] = $fontkey;
  11021. }
  11022. $fontstyle = sprintf('/F%d %.2F Tf %s', ($fontkey + 1), $this->FontSizePt, $this->TextColor);
  11023. $popt['da'] = $fontstyle;
  11024. $popt['ap'] = array();
  11025. $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
  11026. // merge options
  11027. $opt = array_merge($popt, $opt);
  11028. // set remaining annotation data
  11029. $opt['Subtype'] = 'Widget';
  11030. $opt['ft'] = 'Btn';
  11031. $opt['t'] = $caption;
  11032. $opt['v'] = $name;
  11033. if (!empty($action)) {
  11034. if (is_array($action)) {
  11035. // form action options as on section 12.7.5 of PDF32000_2008.
  11036. $opt['aa'] = '/D <<';
  11037. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  11038. foreach ($action AS $key => $val) {
  11039. if (($key == 'S') AND in_array($val, $bmode)) {
  11040. $opt['aa'] .= ' /S /'.$val;
  11041. } elseif (($key == 'F') AND (!empty($val))) {
  11042. $opt['aa'] .= ' /F '.$this->_datastring($val);
  11043. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  11044. $opt['aa'] .= ' /Fields [';
  11045. foreach ($val AS $field) {
  11046. $opt['aa'] .= ' '.$this->_textstring($field);
  11047. }
  11048. $opt['aa'] .= ']';
  11049. } elseif (($key == 'Flags')) {
  11050. $ff = 0;
  11051. if (is_array($val)) {
  11052. foreach ($val AS $flag) {
  11053. switch ($flag) {
  11054. case 'Include/Exclude': {
  11055. $ff += 1 << 0;
  11056. break;
  11057. }
  11058. case 'IncludeNoValueFields': {
  11059. $ff += 1 << 1;
  11060. break;
  11061. }
  11062. case 'ExportFormat': {
  11063. $ff += 1 << 2;
  11064. break;
  11065. }
  11066. case 'GetMethod': {
  11067. $ff += 1 << 3;
  11068. break;
  11069. }
  11070. case 'SubmitCoordinates': {
  11071. $ff += 1 << 4;
  11072. break;
  11073. }
  11074. case 'XFDF': {
  11075. $ff += 1 << 5;
  11076. break;
  11077. }
  11078. case 'IncludeAppendSaves': {
  11079. $ff += 1 << 6;
  11080. break;
  11081. }
  11082. case 'IncludeAnnotations': {
  11083. $ff += 1 << 7;
  11084. break;
  11085. }
  11086. case 'SubmitPDF': {
  11087. $ff += 1 << 8;
  11088. break;
  11089. }
  11090. case 'CanonicalFormat': {
  11091. $ff += 1 << 9;
  11092. break;
  11093. }
  11094. case 'ExclNonUserAnnots': {
  11095. $ff += 1 << 10;
  11096. break;
  11097. }
  11098. case 'ExclFKey': {
  11099. $ff += 1 << 11;
  11100. break;
  11101. }
  11102. case 'EmbedForm': {
  11103. $ff += 1 << 13;
  11104. break;
  11105. }
  11106. }
  11107. }
  11108. } else {
  11109. $ff = intval($val);
  11110. }
  11111. $opt['aa'] .= ' /Flags '.$ff;
  11112. }
  11113. }
  11114. $opt['aa'] .= ' >>';
  11115. } else {
  11116. // Javascript action or raw action command
  11117. $js_obj_id = $this->addJavascriptObject($action);
  11118. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  11119. }
  11120. }
  11121. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  11122. if ($this->rtl) {
  11123. $this->x -= $w;
  11124. } else {
  11125. $this->x += $w;
  11126. }
  11127. }
  11128. // --- END FORMS FIELDS ------------------------------------------------
  11129. /**
  11130. * Add certification signature (DocMDP or UR3)
  11131. * You can set only one signature type
  11132. * @access protected
  11133. * @author Nicola Asuni
  11134. * @since 4.6.008 (2009-05-07)
  11135. */
  11136. protected function _putsignature() {
  11137. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  11138. return;
  11139. }
  11140. $this->_out('/Type /Sig');
  11141. $this->_out('/Filter /Adobe.PPKLite');
  11142. $this->_out('/SubFilter /adbe.pkcs7.detached');
  11143. $this->_out($this->byterange_string);
  11144. $this->_out('/Contents<>'.str_repeat(' ', $this->signature_max_length));
  11145. $this->_out('/Reference');
  11146. $this->_out('[');
  11147. $this->_out('<<');
  11148. $this->_out('/Type /SigRef');
  11149. if ($this->signature_data['cert_type'] > 0) {
  11150. $this->_out('/TransformMethod /DocMDP');
  11151. $this->_out('/TransformParams');
  11152. $this->_out('<<');
  11153. $this->_out('/Type /TransformParams');
  11154. $this->_out('/V /1.2');
  11155. $this->_out('/P '.$this->signature_data['cert_type'].'');
  11156. } else {
  11157. $this->_out('/TransformMethod /UR3');
  11158. $this->_out('/TransformParams');
  11159. $this->_out('<<');
  11160. $this->_out('/Type /TransformParams');
  11161. $this->_out('/V /2.2');
  11162. if (!$this->empty_string($this->ur_document)) {
  11163. $this->_out('/Document['.$this->ur_document.']');
  11164. }
  11165. if (!$this->empty_string($this->ur_annots)) {
  11166. $this->_out('/Annots['.$this->ur_annots.']');
  11167. }
  11168. if (!$this->empty_string($this->ur_form)) {
  11169. $this->_out('/Form['.$this->ur_form.']');
  11170. }
  11171. if (!$this->empty_string($this->ur_signature)) {
  11172. $this->_out('/Signature['.$this->ur_signature.']');
  11173. }
  11174. }
  11175. $this->_out('>>');
  11176. $this->_out('>>');
  11177. $this->_out(']');
  11178. if (isset($this->signature_data['info']['Name']) AND !$this->empty_string($this->signature_data['info']['Name'])) {
  11179. $this->_out('/Name '.$this->_textstring($this->signature_data['info']['Name']).'');
  11180. }
  11181. if (isset($this->signature_data['info']['Location']) AND !$this->empty_string($this->signature_data['info']['Location'])) {
  11182. $this->_out('/Location '.$this->_textstring($this->signature_data['info']['Location']).'');
  11183. }
  11184. if (isset($this->signature_data['info']['Reason']) AND !$this->empty_string($this->signature_data['info']['Reason'])) {
  11185. $this->_out('/Reason '.$this->_textstring($this->signature_data['info']['Reason']).'');
  11186. }
  11187. if (isset($this->signature_data['info']['ContactInfo']) AND !$this->empty_string($this->signature_data['info']['ContactInfo'])) {
  11188. $this->_out('/ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo']).'');
  11189. }
  11190. $this->_out('/M '.$this->_datestring());
  11191. }
  11192. /**
  11193. * Set User's Rights for PDF Reader
  11194. * WARNING: This works only using the Adobe private key with the setSignature() method!.
  11195. * Check the PDF Reference 8.7.1 Transform Methods,
  11196. * Table 8.105 Entries in the UR transform parameters dictionary
  11197. * @param boolean $enable if true enable user's rights on PDF reader
  11198. * @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.
  11199. * @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.
  11200. * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  11201. * @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.
  11202. * @access public
  11203. * @author Nicola Asuni
  11204. * @since 2.9.000 (2008-03-26)
  11205. */
  11206. public function setUserRights(
  11207. $enable=true,
  11208. $document='/FullSave',
  11209. $annots='/Create/Delete/Modify/Copy/Import/Export',
  11210. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  11211. $signature='/Modify') {
  11212. $this->ur = $enable;
  11213. $this->ur_document = $document;
  11214. $this->ur_annots = $annots;
  11215. $this->ur_form = $form;
  11216. $this->ur_signature = $signature;
  11217. if (!$this->sign) {
  11218. // This signature only works using the Adobe Private key that is unavailable!
  11219. $this->setSignature('', '', '', '', 0, array());
  11220. }
  11221. }
  11222. /**
  11223. * Enable document signature (requires the OpenSSL Library).
  11224. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  11225. * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://')
  11226. * @param mixed $private_key private key (string or filename prefixed with 'file://')
  11227. * @param string $private_key_password password
  11228. * @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.
  11229. * @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.
  11230. * @param array $info array of option information: Name, Location, Reason, ContactInfo.
  11231. * @access public
  11232. * @author Nicola Asuni
  11233. * @since 4.6.005 (2009-04-24)
  11234. */
  11235. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) {
  11236. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  11237. // to convert pfx certificate to pem: openssl
  11238. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  11239. $this->sign = true;
  11240. $this->signature_data = array();
  11241. if (strlen($signing_cert) == 0) {
  11242. $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.crt';
  11243. $private_key_password = 'tcpdfdemo';
  11244. }
  11245. if (strlen($private_key) == 0) {
  11246. $private_key = $signing_cert;
  11247. }
  11248. $this->signature_data['signcert'] = $signing_cert;
  11249. $this->signature_data['privkey'] = $private_key;
  11250. $this->signature_data['password'] = $private_key_password;
  11251. $this->signature_data['extracerts'] = $extracerts;
  11252. $this->signature_data['cert_type'] = $cert_type;
  11253. $this->signature_data['info'] = $info;
  11254. }
  11255. /**
  11256. * Create a new page group.
  11257. * NOTE: call this function before calling AddPage()
  11258. * @param int $page starting group page (leave empty for next page).
  11259. * @access public
  11260. * @since 3.0.000 (2008-03-27)
  11261. */
  11262. public function startPageGroup($page='') {
  11263. if (empty($page)) {
  11264. $page = $this->page + 1;
  11265. }
  11266. $this->newpagegroup[$page] = true;
  11267. }
  11268. /**
  11269. * Defines an alias for the total number of pages.
  11270. * It will be substituted as the document is closed.
  11271. * @param string $alias The alias.
  11272. * @access public
  11273. * @since 1.4
  11274. * @see getAliasNbPages(), PageNo(), Footer()
  11275. */
  11276. public function AliasNbPages($alias='{nb}') {
  11277. $this->AliasNbPages = $alias;
  11278. }
  11279. /**
  11280. * Returns the string alias used for the total number of pages.
  11281. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11282. * @return string
  11283. * @access public
  11284. * @since 4.0.018 (2008-08-08)
  11285. * @see AliasNbPages(), PageNo(), Footer()
  11286. */
  11287. public function getAliasNbPages() {
  11288. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  11289. return '{'.$this->AliasNbPages.'}';
  11290. }
  11291. return $this->AliasNbPages;
  11292. }
  11293. /**
  11294. * Defines an alias for the page number.
  11295. * It will be substituted as the document is closed.
  11296. * @param string $alias The alias.
  11297. * @access public
  11298. * @since 4.5.000 (2009-01-02)
  11299. * @see getAliasNbPages(), PageNo(), Footer()
  11300. */
  11301. public function AliasNumPage($alias='{pnb}') {
  11302. //Define an alias for total number of pages
  11303. $this->AliasNumPage = $alias;
  11304. }
  11305. /**
  11306. * Returns the string alias used for the page number.
  11307. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11308. * @return string
  11309. * @access public
  11310. * @since 4.5.000 (2009-01-02)
  11311. * @see AliasNbPages(), PageNo(), Footer()
  11312. */
  11313. public function getAliasNumPage() {
  11314. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  11315. return '{'.$this->AliasNumPage.'}';
  11316. }
  11317. return $this->AliasNumPage;
  11318. }
  11319. /**
  11320. * Return the current page in the group.
  11321. * @return current page in the group
  11322. * @access public
  11323. * @since 3.0.000 (2008-03-27)
  11324. */
  11325. public function getGroupPageNo() {
  11326. return $this->pagegroups[$this->currpagegroup];
  11327. }
  11328. /**
  11329. * Returns the current group page number formatted as a string.
  11330. * @access public
  11331. * @since 4.3.003 (2008-11-18)
  11332. * @see PaneNo(), formatPageNumber()
  11333. */
  11334. public function getGroupPageNoFormatted() {
  11335. return $this->formatPageNumber($this->getGroupPageNo());
  11336. }
  11337. /**
  11338. * Return the alias of the current page group
  11339. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11340. * (will be replaced by the total number of pages in this group).
  11341. * @return alias of the current page group
  11342. * @access public
  11343. * @since 3.0.000 (2008-03-27)
  11344. */
  11345. public function getPageGroupAlias() {
  11346. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  11347. return '{'.$this->currpagegroup.'}';
  11348. }
  11349. return $this->currpagegroup;
  11350. }
  11351. /**
  11352. * Return the alias for the page number on the current page group
  11353. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11354. * (will be replaced by the total number of pages in this group).
  11355. * @return alias of the current page group
  11356. * @access public
  11357. * @since 4.5.000 (2009-01-02)
  11358. */
  11359. public function getPageNumGroupAlias() {
  11360. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  11361. return '{'.str_replace('{nb', '{pnb', $this->currpagegroup).'}';
  11362. }
  11363. return str_replace('{nb', '{pnb', $this->currpagegroup);
  11364. }
  11365. /**
  11366. * Format the page numbers.
  11367. * This method can be overriden for custom formats.
  11368. * @param int $num page number
  11369. * @access protected
  11370. * @since 4.2.005 (2008-11-06)
  11371. */
  11372. protected function formatPageNumber($num) {
  11373. return number_format((float)$num, 0, '', '.');
  11374. }
  11375. /**
  11376. * Format the page numbers on the Table Of Content.
  11377. * This method can be overriden for custom formats.
  11378. * @param int $num page number
  11379. * @access protected
  11380. * @since 4.5.001 (2009-01-04)
  11381. * @see addTOC()
  11382. */
  11383. protected function formatTOCPageNumber($num) {
  11384. return number_format((float)$num, 0, '', '.');
  11385. }
  11386. /**
  11387. * Returns the current page number formatted as a string.
  11388. * @access public
  11389. * @since 4.2.005 (2008-11-06)
  11390. * @see PaneNo(), formatPageNumber()
  11391. */
  11392. public function PageNoFormatted() {
  11393. return $this->formatPageNumber($this->PageNo());
  11394. }
  11395. /**
  11396. * Put visibility settings.
  11397. * @access protected
  11398. * @since 3.0.000 (2008-03-27)
  11399. */
  11400. protected function _putocg() {
  11401. $this->_newobj();
  11402. $this->n_ocg_print = $this->n;
  11403. $this->_out('<</Type /OCG /Name '.$this->_textstring('print'));
  11404. $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
  11405. $this->_out('endobj');
  11406. $this->_newobj();
  11407. $this->n_ocg_view = $this->n;
  11408. $this->_out('<</Type /OCG /Name '.$this->_textstring('view'));
  11409. $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
  11410. $this->_out('endobj');
  11411. }
  11412. /**
  11413. * Set the visibility of the successive elements.
  11414. * This can be useful, for instance, to put a background
  11415. * image or color that will show on screen but won't print.
  11416. * @param string $v visibility mode. Legal values are: all, print, screen.
  11417. * @access public
  11418. * @since 3.0.000 (2008-03-27)
  11419. */
  11420. public function setVisibility($v) {
  11421. if ($this->openMarkedContent) {
  11422. // close existing open marked-content
  11423. $this->_out('EMC');
  11424. $this->openMarkedContent = false;
  11425. }
  11426. switch($v) {
  11427. case 'print': {
  11428. $this->_out('/OC /OC1 BDC');
  11429. $this->openMarkedContent = true;
  11430. break;
  11431. }
  11432. case 'screen': {
  11433. $this->_out('/OC /OC2 BDC');
  11434. $this->openMarkedContent = true;
  11435. break;
  11436. }
  11437. case 'all': {
  11438. $this->_out('');
  11439. break;
  11440. }
  11441. default: {
  11442. $this->Error('Incorrect visibility: '.$v);
  11443. break;
  11444. }
  11445. }
  11446. $this->visibility = $v;
  11447. }
  11448. /**
  11449. * Add transparency parameters to the current extgstate
  11450. * @param array $params parameters
  11451. * @return the number of extgstates
  11452. * @access protected
  11453. * @since 3.0.000 (2008-03-27)
  11454. */
  11455. protected function addExtGState($parms) {
  11456. $n = count($this->extgstates) + 1;
  11457. // check if this ExtGState already exist
  11458. for ($i = 1; $i < $n; ++$i) {
  11459. if ($this->extgstates[$i]['parms'] == $parms) {
  11460. // return reference to existing ExtGState
  11461. return $i;
  11462. }
  11463. }
  11464. $this->extgstates[$n]['parms'] = $parms;
  11465. return $n;
  11466. }
  11467. /**
  11468. * Add an extgstate
  11469. * @param array $gs extgstate
  11470. * @access protected
  11471. * @since 3.0.000 (2008-03-27)
  11472. */
  11473. protected function setExtGState($gs) {
  11474. $this->_out(sprintf('/GS%d gs', $gs));
  11475. }
  11476. /**
  11477. * Put extgstates for object transparency
  11478. * @param array $gs extgstate
  11479. * @access protected
  11480. * @since 3.0.000 (2008-03-27)
  11481. */
  11482. protected function _putextgstates() {
  11483. $ne = count($this->extgstates);
  11484. for ($i = 1; $i <= $ne; ++$i) {
  11485. $this->_newobj();
  11486. $this->extgstates[$i]['n'] = $this->n;
  11487. $this->_out('<</Type /ExtGState');
  11488. foreach ($this->extgstates[$i]['parms'] as $k => $v) {
  11489. if (is_float($v)) {
  11490. $v = sprintf('%.2F', $v);
  11491. }
  11492. $this->_out('/'.$k.' '.$v);
  11493. }
  11494. $this->_out('>>');
  11495. $this->_out('endobj');
  11496. }
  11497. }
  11498. /**
  11499. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  11500. * @param float $alpha real value from 0 (transparent) to 1 (opaque)
  11501. * @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
  11502. * @access public
  11503. * @since 3.0.000 (2008-03-27)
  11504. */
  11505. public function setAlpha($alpha, $bm='Normal') {
  11506. $gs = $this->addExtGState(array('ca' => $alpha, 'CA' => $alpha, 'BM' => '/'.$bm));
  11507. $this->setExtGState($gs);
  11508. }
  11509. /**
  11510. * Set the default JPEG compression quality (1-100)
  11511. * @param int $quality JPEG quality, integer between 1 and 100
  11512. * @access public
  11513. * @since 3.0.000 (2008-03-27)
  11514. */
  11515. public function setJPEGQuality($quality) {
  11516. if (($quality < 1) OR ($quality > 100)) {
  11517. $quality = 75;
  11518. }
  11519. $this->jpeg_quality = intval($quality);
  11520. }
  11521. /**
  11522. * Set the default number of columns in a row for HTML tables.
  11523. * @param int $cols number of columns
  11524. * @access public
  11525. * @since 3.0.014 (2008-06-04)
  11526. */
  11527. public function setDefaultTableColumns($cols=4) {
  11528. $this->default_table_columns = intval($cols);
  11529. }
  11530. /**
  11531. * Set the height of the cell (line height) respect the font height.
  11532. * @param int $h cell proportion respect font height (typical value = 1.25).
  11533. * @access public
  11534. * @since 3.0.014 (2008-06-04)
  11535. */
  11536. public function setCellHeightRatio($h) {
  11537. $this->cell_height_ratio = $h;
  11538. }
  11539. /**
  11540. * return the height of cell repect font height.
  11541. * @access public
  11542. * @since 4.0.012 (2008-07-24)
  11543. */
  11544. public function getCellHeightRatio() {
  11545. return $this->cell_height_ratio;
  11546. }
  11547. /**
  11548. * Set the PDF version (check PDF reference for valid values).
  11549. * Default value is 1.t
  11550. * @access public
  11551. * @since 3.1.000 (2008-06-09)
  11552. */
  11553. public function setPDFVersion($version='1.7') {
  11554. $this->PDFVersion = $version;
  11555. }
  11556. /**
  11557. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  11558. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  11559. * <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>
  11560. * @param array $preferences array of options.
  11561. * @author Nicola Asuni
  11562. * @access public
  11563. * @since 3.1.000 (2008-06-09)
  11564. */
  11565. public function setViewerPreferences($preferences) {
  11566. $this->viewer_preferences = $preferences;
  11567. }
  11568. /**
  11569. * Paints color transition registration bars
  11570. * @param float $x abscissa of the top left corner of the rectangle.
  11571. * @param float $y ordinate of the top left corner of the rectangle.
  11572. * @param float $w width of the rectangle.
  11573. * @param float $h height of the rectangle.
  11574. * @param boolean $transition if true prints tcolor transitions to white.
  11575. * @param boolean $vertical if true prints bar vertically.
  11576. * @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.
  11577. * @author Nicola Asuni
  11578. * @since 4.9.000 (2010-03-26)
  11579. * @access public
  11580. */
  11581. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  11582. $bars = explode(',', $colors);
  11583. $numbars = count($bars); // number of bars to print
  11584. // set bar measures
  11585. if ($vertical) {
  11586. $coords = array(0, 0, 0, 1);
  11587. $wb = $w / $numbars; // bar width
  11588. $hb = $h; // bar height
  11589. $xd = $wb; // delta x
  11590. $yd = 0; // delta y
  11591. } else {
  11592. $coords = array(1, 0, 0, 0);
  11593. $wb = $w; // bar width
  11594. $hb = $h / $numbars; // bar height
  11595. $xd = 0; // delta x
  11596. $yd = $hb; // delta y
  11597. }
  11598. $xb = $x;
  11599. $yb = $y;
  11600. foreach ($bars as $col) {
  11601. switch ($col) {
  11602. // set transition colors
  11603. case 'A': { // BLACK
  11604. $col_a = array(255);
  11605. $col_b = array(0);
  11606. break;
  11607. }
  11608. case 'W': { // WHITE
  11609. $col_a = array(0);
  11610. $col_b = array(255);
  11611. break;
  11612. }
  11613. case 'R': { // R
  11614. $col_a = array(255,255,255);
  11615. $col_b = array(255,0,0);
  11616. break;
  11617. }
  11618. case 'G': { // G
  11619. $col_a = array(255,255,255);
  11620. $col_b = array(0,255,0);
  11621. break;
  11622. }
  11623. case 'B': { // B
  11624. $col_a = array(255,255,255);
  11625. $col_b = array(0,0,255);
  11626. break;
  11627. }
  11628. case 'C': { // C
  11629. $col_a = array(0,0,0,0);
  11630. $col_b = array(100,0,0,0);
  11631. break;
  11632. }
  11633. case 'M': { // M
  11634. $col_a = array(0,0,0,0);
  11635. $col_b = array(0,100,0,0);
  11636. break;
  11637. }
  11638. case 'Y': { // Y
  11639. $col_a = array(0,0,0,0);
  11640. $col_b = array(0,0,100,0);
  11641. break;
  11642. }
  11643. case 'K': { // K
  11644. $col_a = array(0,0,0,0);
  11645. $col_b = array(0,0,0,100);
  11646. break;
  11647. }
  11648. default: { // GRAY
  11649. $col_a = array(255);
  11650. $col_b = array(0);
  11651. break;
  11652. }
  11653. }
  11654. if ($transition) {
  11655. // color gradient
  11656. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  11657. } else {
  11658. // color rectangle
  11659. $this->SetFillColorArray($col_b);
  11660. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  11661. }
  11662. $xb += $xd;
  11663. $yb += $yd;
  11664. }
  11665. }
  11666. /**
  11667. * Paints crop mark
  11668. * @param float $x abscissa of the crop mark center.
  11669. * @param float $y ordinate of the crop mark center.
  11670. * @param float $w width of the crop mark.
  11671. * @param float $h height of the crop mark.
  11672. * @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.
  11673. * @param array $color crop mark color (default black).
  11674. * @author Nicola Asuni
  11675. * @since 4.9.000 (2010-03-26)
  11676. * @access public
  11677. */
  11678. public function cropMark($x, $y, $w, $h, $type='A,B,C,D', $color=array(0,0,0)) {
  11679. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  11680. $crops = explode(',', $type);
  11681. $numcrops = count($crops); // number of crop marks to print
  11682. $dw = $w / 4; // horizontal space to leave before the intersection point
  11683. $dh = $h / 4; // vertical space to leave before the intersection point
  11684. foreach ($crops as $crop) {
  11685. switch ($crop) {
  11686. case 'A': {
  11687. $x1 = $x;
  11688. $y1 = $y - $h;
  11689. $x2 = $x;
  11690. $y2 = $y - $dh;
  11691. $x3 = $x - $w;
  11692. $y3 = $y;
  11693. $x4 = $x - $dw;
  11694. $y4 = $y;
  11695. break;
  11696. }
  11697. case 'B': {
  11698. $x1 = $x;
  11699. $y1 = $y - $h;
  11700. $x2 = $x;
  11701. $y2 = $y - $dh;
  11702. $x3 = $x + $dw;
  11703. $y3 = $y;
  11704. $x4 = $x + $w;
  11705. $y4 = $y;
  11706. break;
  11707. }
  11708. case 'C': {
  11709. $x1 = $x - $w;
  11710. $y1 = $y;
  11711. $x2 = $x - $dw;
  11712. $y2 = $y;
  11713. $x3 = $x;
  11714. $y3 = $y + $dh;
  11715. $x4 = $x;
  11716. $y4 = $y + $h;
  11717. break;
  11718. }
  11719. case 'D': {
  11720. $x1 = $x + $dw;
  11721. $y1 = $y;
  11722. $x2 = $x + $w;
  11723. $y2 = $y;
  11724. $x3 = $x;
  11725. $y3 = $y + $dh;
  11726. $x4 = $x;
  11727. $y4 = $y + $h;
  11728. break;
  11729. }
  11730. }
  11731. $this->Line($x1, $y1, $x2, $y2);
  11732. $this->Line($x3, $y3, $x4, $y4);
  11733. }
  11734. }
  11735. /**
  11736. * Paints a registration mark
  11737. * @param float $x abscissa of the registration mark center.
  11738. * @param float $y ordinate of the registration mark center.
  11739. * @param float $r radius of the crop mark.
  11740. * @param boolean $double if true print two concentric crop marks.
  11741. * @param array $cola crop mark color (default black).
  11742. * @param array $colb second crop mark color.
  11743. * @author Nicola Asuni
  11744. * @since 4.9.000 (2010-03-26)
  11745. * @access public
  11746. */
  11747. public function registrationMark($x, $y, $r, $double=false, $cola=array(0,0,0), $colb=array(255,255,255)) {
  11748. $line_style = array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  11749. $this->SetFillColorArray($cola);
  11750. $this->PieSector($x, $y, $r, 90, 180, 'F');
  11751. $this->PieSector($x, $y, $r, 270, 360, 'F');
  11752. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  11753. if ($double) {
  11754. $r2 = $r * 0.5;
  11755. $this->SetFillColorArray($colb);
  11756. $this->PieSector($x, $y, $r2, 90, 180, 'F');
  11757. $this->PieSector($x, $y, $r2, 270, 360, 'F');
  11758. $this->SetFillColorArray($cola);
  11759. $this->PieSector($x, $y, $r2, 0, 90, 'F');
  11760. $this->PieSector($x, $y, $r2, 180, 270, 'F');
  11761. $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8);
  11762. }
  11763. }
  11764. /**
  11765. * Paints a linear colour gradient.
  11766. * @param float $x abscissa of the top left corner of the rectangle.
  11767. * @param float $y ordinate of the top left corner of the rectangle.
  11768. * @param float $w width of the rectangle.
  11769. * @param float $h height of the rectangle.
  11770. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  11771. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  11772. * @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).
  11773. * @author Andreas Würmser, Nicola Asuni
  11774. * @since 3.1.000 (2008-06-09)
  11775. * @access public
  11776. */
  11777. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  11778. $this->Clip($x, $y, $w, $h);
  11779. $this->Gradient(2, $col1, $col2, $coords);
  11780. }
  11781. /**
  11782. * Paints a radial colour gradient.
  11783. * @param float $x abscissa of the top left corner of the rectangle.
  11784. * @param float $y ordinate of the top left corner of the rectangle.
  11785. * @param float $w width of the rectangle.
  11786. * @param float $h height of the rectangle.
  11787. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  11788. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  11789. * @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.
  11790. * @author Andreas Würmser, Nicola Asuni
  11791. * @since 3.1.000 (2008-06-09)
  11792. * @access public
  11793. */
  11794. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  11795. $this->Clip($x, $y, $w, $h);
  11796. $this->Gradient(3, $col1, $col2, $coords);
  11797. }
  11798. /**
  11799. * Paints a coons patch mesh.
  11800. * @param float $x abscissa of the top left corner of the rectangle.
  11801. * @param float $y ordinate of the top left corner of the rectangle.
  11802. * @param float $w width of the rectangle.
  11803. * @param float $h height of the rectangle.
  11804. * @param array $col1 first color (lower left corner) (RGB components).
  11805. * @param array $col2 second color (lower right corner) (RGB components).
  11806. * @param array $col3 third color (upper right corner) (RGB components).
  11807. * @param array $col4 fourth color (upper left corner) (RGB components).
  11808. * @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>
  11809. * @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
  11810. * @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
  11811. * @author Andreas Würmser, Nicola Asuni
  11812. * @since 3.1.000 (2008-06-09)
  11813. * @access public
  11814. */
  11815. 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) {
  11816. $this->Clip($x, $y, $w, $h);
  11817. $n = count($this->gradients) + 1;
  11818. $this->gradients[$n]['type'] = 6; //coons patch mesh
  11819. //check the coords array if it is the simple array or the multi patch array
  11820. if (!isset($coords[0]['f'])) {
  11821. //simple array -> convert to multi patch array
  11822. if (!isset($col1[1])) {
  11823. $col1[1] = $col1[2] = $col1[0];
  11824. }
  11825. if (!isset($col2[1])) {
  11826. $col2[1] = $col2[2] = $col2[0];
  11827. }
  11828. if (!isset($col3[1])) {
  11829. $col3[1] = $col3[2] = $col3[0];
  11830. }
  11831. if (!isset($col4[1])) {
  11832. $col4[1] = $col4[2] = $col4[0];
  11833. }
  11834. $patch_array[0]['f'] = 0;
  11835. $patch_array[0]['points'] = $coords;
  11836. $patch_array[0]['colors'][0]['r'] = $col1[0];
  11837. $patch_array[0]['colors'][0]['g'] = $col1[1];
  11838. $patch_array[0]['colors'][0]['b'] = $col1[2];
  11839. $patch_array[0]['colors'][1]['r'] = $col2[0];
  11840. $patch_array[0]['colors'][1]['g'] = $col2[1];
  11841. $patch_array[0]['colors'][1]['b'] = $col2[2];
  11842. $patch_array[0]['colors'][2]['r'] = $col3[0];
  11843. $patch_array[0]['colors'][2]['g'] = $col3[1];
  11844. $patch_array[0]['colors'][2]['b'] = $col3[2];
  11845. $patch_array[0]['colors'][3]['r'] = $col4[0];
  11846. $patch_array[0]['colors'][3]['g'] = $col4[1];
  11847. $patch_array[0]['colors'][3]['b'] = $col4[2];
  11848. } else {
  11849. //multi patch array
  11850. $patch_array = $coords;
  11851. }
  11852. $bpcd = 65535; //16 BitsPerCoordinate
  11853. //build the data stream
  11854. $this->gradients[$n]['stream'] = '';
  11855. $count_patch = count($patch_array);
  11856. for ($i=0; $i < $count_patch; ++$i) {
  11857. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  11858. $count_points = count($patch_array[$i]['points']);
  11859. for ($j=0; $j < $count_points; ++$j) {
  11860. //each point as 16 bit
  11861. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  11862. if ($patch_array[$i]['points'][$j] < 0) {
  11863. $patch_array[$i]['points'][$j] = 0;
  11864. }
  11865. if ($patch_array[$i]['points'][$j] > $bpcd) {
  11866. $patch_array[$i]['points'][$j] = $bpcd;
  11867. }
  11868. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  11869. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  11870. }
  11871. $count_cols = count($patch_array[$i]['colors']);
  11872. for ($j=0; $j < $count_cols; ++$j) {
  11873. //each color component as 8 bit
  11874. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  11875. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  11876. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  11877. }
  11878. }
  11879. //paint the gradient
  11880. $this->_out('/Sh'.$n.' sh');
  11881. //restore previous Graphic State
  11882. $this->_out('Q');
  11883. }
  11884. /**
  11885. * Set a rectangular clipping area.
  11886. * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  11887. * @param float $y ordinate of the top left corner of the rectangle.
  11888. * @param float $w width of the rectangle.
  11889. * @param float $h height of the rectangle.
  11890. * @author Andreas Würmser, Nicola Asuni
  11891. * @since 3.1.000 (2008-06-09)
  11892. * @access protected
  11893. */
  11894. protected function Clip($x, $y, $w, $h) {
  11895. if ($this->rtl) {
  11896. $x = $this->w - $x - $w;
  11897. }
  11898. //save current Graphic State
  11899. $s = 'q';
  11900. //set clipping area
  11901. $s .= sprintf(' %.2F %.2F %.2F %.2F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  11902. //set up transformation matrix for gradient
  11903. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  11904. $this->_out($s);
  11905. }
  11906. /**
  11907. * Output gradient.
  11908. * @param int $type type of gradient.
  11909. * @param array $col1 first color array (GRAY, RGB or CMYK)
  11910. * @param array $col2 second color array (GRAY, RGB or CMYK) - must be the same color type as $col1
  11911. * @param array $coords array of coordinates.
  11912. * @author Andreas Würmser, Nicola Asuni
  11913. * @since 3.1.000 (2008-06-09)
  11914. * @access protected
  11915. */
  11916. protected function Gradient($type, $col1, $col2, $coords) {
  11917. $n = count($this->gradients) + 1;
  11918. $this->gradients[$n]['type'] = $type;
  11919. switch(count($col1)) {
  11920. case 4: { // CMYK
  11921. $this->gradients[$n]['col1'] = sprintf('%.3F %.3F %.3F %.3F', $col1[0]/100, $col1[1]/100, $col1[2]/100, $col1[3]/100);
  11922. $this->gradients[$n]['col2'] = sprintf('%.3F %.3F %.3F %.3F', $col2[0]/100, $col2[1]/100, $col2[2]/100, $col2[3]/100);
  11923. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  11924. break;
  11925. }
  11926. case 3: { // RGB
  11927. $this->gradients[$n]['col1'] = sprintf('%.3F %.3F %.3F', $col1[0]/255, $col1[1]/255, $col1[2]/255);
  11928. $this->gradients[$n]['col2'] = sprintf('%.3F %.3F %.3F', $col2[0]/255, $col2[1]/255, $col2[2]/255);
  11929. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  11930. break;
  11931. }
  11932. case 1: { // Gray scale
  11933. $this->gradients[$n]['col1'] = sprintf('%.3F', $col1[0]/255);
  11934. $this->gradients[$n]['col2'] = sprintf('%.3F', $col2[0]/255);
  11935. $this->gradients[$n]['colspace'] = 'DeviceGray';
  11936. }
  11937. }
  11938. $this->gradients[$n]['coords'] = $coords;
  11939. //paint the gradient
  11940. $this->_out('/Sh'.$n.' sh');
  11941. //restore previous Graphic State
  11942. $this->_out('Q');
  11943. }
  11944. /**
  11945. * Output shaders.
  11946. * @author Andreas Würmser, Nicola Asuni
  11947. * @since 3.1.000 (2008-06-09)
  11948. * @access protected
  11949. */
  11950. function _putshaders() {
  11951. foreach ($this->gradients as $id => $grad) {
  11952. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  11953. $this->_newobj();
  11954. $this->_out('<<');
  11955. $this->_out('/FunctionType 2');
  11956. $this->_out('/Domain [0.0 1.0]');
  11957. $this->_out('/C0 ['.$grad['col1'].']');
  11958. $this->_out('/C1 ['.$grad['col2'].']');
  11959. $this->_out('/N 1');
  11960. $this->_out('>>');
  11961. $this->_out('endobj');
  11962. $f1 = $this->n;
  11963. }
  11964. $this->_newobj();
  11965. $this->_out('<<');
  11966. $this->_out('/ShadingType '.$grad['type']);
  11967. if (isset($grad['colspace'])) {
  11968. $this->_out('/ColorSpace /'.$grad['colspace']);
  11969. } else {
  11970. $this->_out('/ColorSpace /DeviceRGB');
  11971. }
  11972. if ($grad['type'] == 2) {
  11973. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  11974. $this->_out('/Function '.$f1.' 0 R');
  11975. $this->_out('/Extend [true true] ');
  11976. $this->_out('>>');
  11977. } elseif ($grad['type'] == 3) {
  11978. //x0, y0, r0, x1, y1, r1
  11979. //at this this time radius of inner circle is 0
  11980. $this->_out(sprintf('/Coords [%.3F %.3F 0 %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]));
  11981. $this->_out('/Function '.$f1.' 0 R');
  11982. $this->_out('/Extend [true true] ');
  11983. $this->_out('>>');
  11984. } elseif ($grad['type'] == 6) {
  11985. $this->_out('/BitsPerCoordinate 16');
  11986. $this->_out('/BitsPerComponent 8');
  11987. $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]');
  11988. $this->_out('/BitsPerFlag 8');
  11989. $this->_out('/Length '.strlen($grad['stream']));
  11990. $this->_out('>>');
  11991. $this->_putstream($grad['stream']);
  11992. }
  11993. $this->_out('endobj');
  11994. $this->gradients[$id]['id'] = $this->n;
  11995. }
  11996. }
  11997. /**
  11998. * Output an arc
  11999. * @author Maxime Delorme, Nicola Asuni
  12000. * @since 3.1.000 (2008-06-09)
  12001. * @access protected
  12002. */
  12003. protected function _outarc($x1, $y1, $x2, $y2, $x3, $y3) {
  12004. $h = $this->h;
  12005. $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1*$this->k, ($h-$y1)*$this->k, $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
  12006. }
  12007. /**
  12008. * Draw the sector of a circle.
  12009. * It can be used for instance to render pie charts.
  12010. * @param float $xc abscissa of the center.
  12011. * @param float $yc ordinate of the center.
  12012. * @param float $r radius.
  12013. * @param float $a start angle (in degrees).
  12014. * @param float $b end angle (in degrees).
  12015. * @param string $style: D, F, FD or DF (draw, fill, fill and draw). Default: FD.
  12016. * @param float $cw: indicates whether to go clockwise (default: true).
  12017. * @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.
  12018. * @author Maxime Delorme, Nicola Asuni
  12019. * @since 3.1.000 (2008-06-09)
  12020. * @access public
  12021. */
  12022. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  12023. if ($this->rtl) {
  12024. $xc = $this->w - $xc;
  12025. }
  12026. if ($cw) {
  12027. $d = $b;
  12028. $b = $o - $a;
  12029. $a = $o - $d;
  12030. } else {
  12031. $b += $o;
  12032. $a += $o;
  12033. }
  12034. $a = ($a % 360) + 360;
  12035. $b = ($b % 360) + 360;
  12036. if ($a > $b) {
  12037. $b +=360;
  12038. }
  12039. $b = $b / 360 * 2 * M_PI;
  12040. $a = $a / 360 * 2 * M_PI;
  12041. $d = $b - $a;
  12042. if ($d == 0 ) {
  12043. $d = 2 * M_PI;
  12044. }
  12045. $k = $this->k;
  12046. $hp = $this->h;
  12047. if ($style=='F') {
  12048. $op = 'f';
  12049. } elseif ($style=='FD' or $style=='DF') {
  12050. $op = 'b';
  12051. } else {
  12052. $op = 's';
  12053. }
  12054. if (sin($d/2)) {
  12055. $MyArc = 4/3 * (1 - cos($d/2)) / sin($d/2) * $r;
  12056. }
  12057. //first put the center
  12058. $this->_out(sprintf('%.2F %.2F m', ($xc)*$k, ($hp-$yc)*$k));
  12059. //put the first point
  12060. $this->_out(sprintf('%.2F %.2F l', ($xc+$r*cos($a))*$k, (($hp-($yc-$r*sin($a)))*$k)));
  12061. //draw the arc
  12062. if ($d < (M_PI/2)) {
  12063. $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
  12064. } else {
  12065. $b = $a + $d/4;
  12066. $MyArc = 4/3*(1-cos($d/8))/sin($d/8)*$r;
  12067. $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
  12068. $a = $b;
  12069. $b = $a + $d/4;
  12070. $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
  12071. $a = $b;
  12072. $b = $a + $d/4;
  12073. $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b) );
  12074. $a = $b;
  12075. $b = $a + $d/4;
  12076. $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
  12077. }
  12078. //terminate drawing
  12079. $this->_out($op);
  12080. }
  12081. /**
  12082. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  12083. * Only vector drawing is supported, not text or bitmap.
  12084. * 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).
  12085. * @param string $file Name of the file containing the image.
  12086. * @param float $x Abscissa of the upper-left corner.
  12087. * @param float $y Ordinate of the upper-left corner.
  12088. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  12089. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  12090. * @param mixed $link URL or identifier returned by AddLink().
  12091. * @param boolean useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  12092. * @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>
  12093. * @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>
  12094. * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  12095. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  12096. * @author Valentin Schmidt, Nicola Asuni
  12097. * @since 3.1.000 (2008-06-09)
  12098. * @access public
  12099. */
  12100. public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false) {
  12101. if ($x === '') {
  12102. $x = $this->x;
  12103. }
  12104. if ($y === '') {
  12105. $y = $this->y;
  12106. }
  12107. $k = $this->k;
  12108. $data = file_get_contents($file);
  12109. if ($data === false) {
  12110. $this->Error('EPS file not found: '.$file);
  12111. }
  12112. $regs = array();
  12113. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  12114. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  12115. if (count($regs) > 1) {
  12116. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  12117. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  12118. $versexp = explode(' ', $version_str);
  12119. $version = (float)array_pop($versexp);
  12120. if ($version >= 9) {
  12121. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  12122. }
  12123. }
  12124. }
  12125. // strip binary bytes in front of PS-header
  12126. $start = strpos($data, '%!PS-Adobe');
  12127. if ($start > 0) {
  12128. $data = substr($data, $start);
  12129. }
  12130. // find BoundingBox params
  12131. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  12132. if (count($regs) > 1) {
  12133. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  12134. } else {
  12135. $this->Error('No BoundingBox found in EPS file: '.$file);
  12136. }
  12137. $start = strpos($data, '%%EndSetup');
  12138. if ($start === false) {
  12139. $start = strpos($data, '%%EndProlog');
  12140. }
  12141. if ($start === false) {
  12142. $start = strpos($data, '%%BoundingBox');
  12143. }
  12144. $data = substr($data, $start);
  12145. $end = strpos($data, '%%PageTrailer');
  12146. if ($end===false) {
  12147. $end = strpos($data, 'showpage');
  12148. }
  12149. if ($end) {
  12150. $data = substr($data, 0, $end);
  12151. }
  12152. // calculate image width and height on document
  12153. if (($w <= 0) AND ($h <= 0)) {
  12154. $w = ($x2 - $x1) / $k;
  12155. $h = ($y2 - $y1) / $k;
  12156. } elseif ($w <= 0) {
  12157. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  12158. } elseif ($h <= 0) {
  12159. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  12160. }
  12161. // Check whether we need a new page first as this does not fit
  12162. $prev_x = $this->x;
  12163. if ($this->checkPageBreak($h, $y)) {
  12164. $y = $this->y;
  12165. if ($this->rtl) {
  12166. $x += ($prev_x - $this->x);
  12167. } else {
  12168. $x += ($this->x - $prev_x);
  12169. }
  12170. }
  12171. // resize image to be contained on a single page
  12172. if ($fitonpage) {
  12173. $ratio_wh = $w / $h;
  12174. if (($y + $h) > $this->PageBreakTrigger) {
  12175. $h = $this->PageBreakTrigger - $y;
  12176. $w = $h * $ratio_wh;
  12177. }
  12178. if (($x + $w) > ($this->w - $this->rMargin)) {
  12179. $w = $this->w - $this->rMargin - $x;
  12180. $h = $w / $ratio_wh;
  12181. }
  12182. }
  12183. // set scaling factors
  12184. $scale_x = $w / (($x2 - $x1) / $k);
  12185. $scale_y = $h / (($y2 - $y1) / $k);
  12186. // set bottomcoordinates
  12187. $this->img_rb_y = $y + $h;
  12188. // set alignment
  12189. if ($this->rtl) {
  12190. if ($palign == 'L') {
  12191. $ximg = $this->lMargin;
  12192. // set right side coordinate
  12193. $this->img_rb_x = $ximg + $w;
  12194. } elseif ($palign == 'C') {
  12195. $ximg = ($this->w - $x - $w) / 2;
  12196. // set right side coordinate
  12197. $this->img_rb_x = $ximg + $w;
  12198. } else {
  12199. $ximg = $this->w - $x - $w;
  12200. // set left side coordinate
  12201. $this->img_rb_x = $ximg;
  12202. }
  12203. } else {
  12204. if ($palign == 'R') {
  12205. $ximg = $this->w - $this->rMargin - $w;
  12206. // set left side coordinate
  12207. $this->img_rb_x = $ximg;
  12208. } elseif ($palign == 'C') {
  12209. $ximg = ($this->w - $x - $w) / 2;
  12210. // set right side coordinate
  12211. $this->img_rb_x = $ximg + $w;
  12212. } else {
  12213. $ximg = $x;
  12214. // set right side coordinate
  12215. $this->img_rb_x = $ximg + $w;
  12216. }
  12217. }
  12218. if ($useBoundingBox) {
  12219. $dx = $ximg * $k - $x1;
  12220. $dy = $y * $k - $y1;
  12221. } else {
  12222. $dx = $ximg * $k;
  12223. $dy = $y * $k;
  12224. }
  12225. // save the current graphic state
  12226. $this->_out('q'.$this->epsmarker);
  12227. // translate
  12228. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  12229. // scale
  12230. if (isset($scale_x)) {
  12231. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  12232. }
  12233. // handle pc/unix/mac line endings
  12234. preg_match('/[\r\n]+/s', $data, $regs);
  12235. $lines = explode($regs[0], $data);
  12236. $u=0;
  12237. $cnt = count($lines);
  12238. for ($i=0; $i < $cnt; ++$i) {
  12239. $line = $lines[$i];
  12240. if (($line == '') OR ($line{0} == '%')) {
  12241. continue;
  12242. }
  12243. $len = strlen($line);
  12244. $chunks = explode(' ', $line);
  12245. $cmd = array_pop($chunks);
  12246. // RGB
  12247. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  12248. $b = array_pop($chunks);
  12249. $g = array_pop($chunks);
  12250. $r = array_pop($chunks);
  12251. $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!
  12252. continue;
  12253. }
  12254. switch ($cmd) {
  12255. case 'm':
  12256. case 'l':
  12257. case 'v':
  12258. case 'y':
  12259. case 'c':
  12260. case 'k':
  12261. case 'K':
  12262. case 'g':
  12263. case 'G':
  12264. case 's':
  12265. case 'S':
  12266. case 'J':
  12267. case 'j':
  12268. case 'w':
  12269. case 'M':
  12270. case 'd':
  12271. case 'n': {
  12272. $this->_out($line);
  12273. break;
  12274. }
  12275. case 'x': {// custom fill color
  12276. list($c,$m,$y,$k) = $chunks;
  12277. $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' k');
  12278. break;
  12279. }
  12280. case 'X': { // custom stroke color
  12281. list($c,$m,$y,$k) = $chunks;
  12282. $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' K');
  12283. break;
  12284. }
  12285. case 'Y':
  12286. case 'N':
  12287. case 'V':
  12288. case 'L':
  12289. case 'C': {
  12290. $line{$len-1} = strtolower($cmd);
  12291. $this->_out($line);
  12292. break;
  12293. }
  12294. case 'b':
  12295. case 'B': {
  12296. $this->_out($cmd . '*');
  12297. break;
  12298. }
  12299. case 'f':
  12300. case 'F': {
  12301. if ($u > 0) {
  12302. $isU = false;
  12303. $max = min($i+5, $cnt);
  12304. for ($j=$i+1; $j < $max; ++$j)
  12305. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  12306. if ($isU) {
  12307. $this->_out('f*');
  12308. }
  12309. } else {
  12310. $this->_out('f*');
  12311. }
  12312. break;
  12313. }
  12314. case '*u': {
  12315. ++$u;
  12316. break;
  12317. }
  12318. case '*U': {
  12319. --$u;
  12320. break;
  12321. }
  12322. }
  12323. }
  12324. // restore previous graphic state
  12325. $this->_out($this->epsmarker.'Q');
  12326. if (!empty($border)) {
  12327. $bx = $x;
  12328. $by = $y;
  12329. $this->x = $x;
  12330. $this->y = $y;
  12331. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0);
  12332. $this->x = $bx;
  12333. $this->y = $by;
  12334. }
  12335. if ($link) {
  12336. $this->Link($ximg, $y, $w, $h, $link, 0);
  12337. }
  12338. // set pointer to align the successive text/objects
  12339. switch($align) {
  12340. case 'T':{
  12341. $this->y = $y;
  12342. $this->x = $this->img_rb_x;
  12343. break;
  12344. }
  12345. case 'M':{
  12346. $this->y = $y + round($h/2);
  12347. $this->x = $this->img_rb_x;
  12348. break;
  12349. }
  12350. case 'B':{
  12351. $this->y = $this->img_rb_y;
  12352. $this->x = $this->img_rb_x;
  12353. break;
  12354. }
  12355. case 'N':{
  12356. $this->SetY($this->img_rb_y);
  12357. break;
  12358. }
  12359. default:{
  12360. break;
  12361. }
  12362. }
  12363. $this->endlinex = $this->img_rb_x;
  12364. }
  12365. /**
  12366. * Set document barcode.
  12367. * @param string $bc barcode
  12368. * @access public
  12369. */
  12370. public function setBarcode($bc='') {
  12371. $this->barcode = $bc;
  12372. }
  12373. /**
  12374. * Get current barcode.
  12375. * @return string
  12376. * @access public
  12377. * @since 4.0.012 (2008-07-24)
  12378. */
  12379. public function getBarcode() {
  12380. return $this->barcode;
  12381. }
  12382. /**
  12383. * Print a Linear Barcode.
  12384. * @param string $code code to print
  12385. * @param string $type type of barcode (see barcodes.php for supported formats).
  12386. * @param int $x x position in user units
  12387. * @param int $y y position in user units
  12388. * @param int $w width in user units
  12389. * @param int $h height in user units
  12390. * @param float $xres width of the smallest bar in user units
  12391. * @param array $style array of options:<ul><li>string $style['position'] barcode position inside the specified width: L = left (default for LTR); C = center; R = right (default for RTL); S = stretch</li><li>boolean $style['border'] if true prints a border around the barcode</li><li>int $style['padding'] padding to leave around the barcode in user units</li><li>array $style['fgcolor'] color array for bars and text</li><li>mixed $style['bgcolor'] color array for background or false for transparent</li><li>boolean $style["text"] boolean if true prints text below the barcode</li><li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li><li>int $style['stretchtext']: 0 = disabled; 1 = horizontal scaling only if necessary; 2 = forced horizontal scaling; 3 = character spacing only if necessary; 4 = forced character spacing</li></ul>
  12392. * @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>
  12393. * @author Nicola Asuni
  12394. * @since 3.1.000 (2008-06-09)
  12395. * @access public
  12396. */
  12397. public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres=0.4, $style='', $align='') {
  12398. if ($this->empty_string($code)) {
  12399. return;
  12400. }
  12401. require_once(dirname(__FILE__).'/barcodes.php');
  12402. // save current graphic settings
  12403. $gvars = $this->getGraphicVars();
  12404. // create new barcode object
  12405. $barcodeobj = new TCPDFBarcode($code, $type);
  12406. $arrcode = $barcodeobj->getBarcodeArray();
  12407. if ($arrcode === false) {
  12408. $this->Error('Error in 1D barcode string');
  12409. }
  12410. // set default values
  12411. if (!isset($style['position'])) {
  12412. if ($this->rtl) {
  12413. $style['position'] = 'R';
  12414. } else {
  12415. $style['position'] = 'L';
  12416. }
  12417. }
  12418. if (!isset($style['padding'])) {
  12419. $style['padding'] = 0;
  12420. }
  12421. if (!isset($style['fgcolor'])) {
  12422. $style['fgcolor'] = array(0,0,0); // default black
  12423. }
  12424. if (!isset($style['bgcolor'])) {
  12425. $style['bgcolor'] = false; // default transparent
  12426. }
  12427. if (!isset($style['border'])) {
  12428. $style['border'] = false;
  12429. }
  12430. $fontsize = 0;
  12431. if (!isset($style['text'])) {
  12432. $style['text'] = false;
  12433. }
  12434. if ($style['text'] AND isset($style['font'])) {
  12435. if (isset($style['fontsize'])) {
  12436. $fontsize = $style['fontsize'];
  12437. }
  12438. $this->SetFont($style['font'], '', $fontsize);
  12439. }
  12440. if (!isset($style['stretchtext'])) {
  12441. $style['stretchtext'] = 4;
  12442. }
  12443. // set foreground color
  12444. $this->SetDrawColorArray($style['fgcolor']);
  12445. $this->SetTextColorArray($style['fgcolor']);
  12446. if ($this->empty_string($w) OR ($w <= 0)) {
  12447. if ($this->rtl) {
  12448. $w = $this->x - $this->lMargin;
  12449. } else {
  12450. $w = $this->w - $this->rMargin - $this->x;
  12451. }
  12452. }
  12453. if ($this->empty_string($x)) {
  12454. $x = $this->GetX();
  12455. }
  12456. if ($this->rtl) {
  12457. $x = $this->w - $x;
  12458. }
  12459. if ($this->empty_string($y)) {
  12460. $y = $this->GetY();
  12461. }
  12462. if ($this->empty_string($xres)) {
  12463. $xres = 0.4;
  12464. }
  12465. $fbw = ($arrcode['maxw'] * $xres) + (2 * $style['padding']);
  12466. $extraspace = ($this->cell_height_ratio * $fontsize / $this->k) + (2 * $style['padding']);
  12467. if ($this->empty_string($h) OR ($h <= 0)) {
  12468. $h = 10 + $extraspace;
  12469. }
  12470. $prev_x = $this->x;
  12471. if ($this->checkPageBreak($h, $y)) {
  12472. $y = $this->GetY() + $this->cMargin;
  12473. if ($this->rtl) {
  12474. $x += ($prev_x - $this->x);
  12475. } else {
  12476. $x += ($this->x - $prev_x);
  12477. }
  12478. }
  12479. // maximum bar height
  12480. $barh = $h - $extraspace;
  12481. switch ($style['position']) {
  12482. case 'L': { // left
  12483. if ($this->rtl) {
  12484. $xpos = $x - $w;
  12485. } else {
  12486. $xpos = $x;
  12487. }
  12488. break;
  12489. }
  12490. case 'C': { // center
  12491. $xdiff = (($w - $fbw) / 2);
  12492. if ($this->rtl) {
  12493. $xpos = $x - $w + $xdiff;
  12494. } else {
  12495. $xpos = $x + $xdiff;
  12496. }
  12497. break;
  12498. }
  12499. case 'R': { // right
  12500. if ($this->rtl) {
  12501. $xpos = $x - $fbw;
  12502. } else {
  12503. $xpos = $x + $w - $fbw;
  12504. }
  12505. break;
  12506. }
  12507. case 'S': { // stretch
  12508. $fbw = $w;
  12509. $xres = ($w - (2 * $style['padding'])) / $arrcode['maxw'];
  12510. if ($this->rtl) {
  12511. $xpos = $x - $w;
  12512. } else {
  12513. $xpos = $x;
  12514. }
  12515. break;
  12516. }
  12517. }
  12518. $xpos_rect = $xpos;
  12519. $xpos = $xpos_rect + $style['padding'];
  12520. $xpos_text = $xpos;
  12521. // barcode is always printed in LTR direction
  12522. $tempRTL = $this->rtl;
  12523. $this->rtl = false;
  12524. // print background color
  12525. if ($style['bgcolor']) {
  12526. $this->Rect($xpos_rect, $y, $fbw, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  12527. } elseif ($style['border']) {
  12528. $this->Rect($xpos_rect, $y, $fbw, $h, 'D');
  12529. }
  12530. // print bars
  12531. if ($arrcode !== false) {
  12532. foreach ($arrcode['bcode'] as $k => $v) {
  12533. $bw = ($v['w'] * $xres);
  12534. if ($v['t']) {
  12535. // draw a vertical bar
  12536. $ypos = $y + $style['padding'] + ($v['p'] * $barh / $arrcode['maxh']);
  12537. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  12538. }
  12539. $xpos += $bw;
  12540. }
  12541. }
  12542. // print text
  12543. if ($style['text']) {
  12544. // print text
  12545. $this->x = $xpos_text;
  12546. $this->y = $y + $style['padding'] + $barh;
  12547. $this->Cell(($arrcode['maxw'] * $xres), ($this->cell_height_ratio * $fontsize / $this->k), $code, 0, 0, 'C', 0, '', $style['stretchtext']);
  12548. }
  12549. // restore original direction
  12550. $this->rtl = $tempRTL;
  12551. // restore previous settings
  12552. $this->setGraphicVars($gvars);
  12553. // set bottomcoordinates
  12554. $this->img_rb_y = $y + $h;
  12555. if ($this->rtl) {
  12556. // set left side coordinate
  12557. $this->img_rb_x = ($this->w - $x - $w);
  12558. } else {
  12559. // set right side coordinate
  12560. $this->img_rb_x = $x + $w;
  12561. }
  12562. // set pointer to align the successive text/objects
  12563. switch($align) {
  12564. case 'T':{
  12565. $this->y = $y;
  12566. $this->x = $this->img_rb_x;
  12567. break;
  12568. }
  12569. case 'M':{
  12570. $this->y = $y + round($h/2);
  12571. $this->x = $this->img_rb_x;
  12572. break;
  12573. }
  12574. case 'B':{
  12575. $this->y = $this->img_rb_y;
  12576. $this->x = $this->img_rb_x;
  12577. break;
  12578. }
  12579. case 'N':{
  12580. $this->SetY($this->img_rb_y);
  12581. break;
  12582. }
  12583. default:{
  12584. break;
  12585. }
  12586. }
  12587. }
  12588. /**
  12589. * This function is DEPRECATED, please use the new write1DBarcode() function.
  12590. * @param int $x x position in user units
  12591. * @param int $y y position in user units
  12592. * @param int $w width in user units
  12593. * @param int $h height position in user units
  12594. * @param string $type type of barcode (I25, C128A, C128B, C128C, C39)
  12595. * @param string $style barcode style
  12596. * @param string $font font for text
  12597. * @param int $xres x resolution
  12598. * @param string $code code to print
  12599. * @deprecated deprecated since version 3.1.000 (2008-06-10)
  12600. * @access public
  12601. * @see write1DBarcode()
  12602. */
  12603. public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) {
  12604. // convert old settings for the new write1DBarcode() function.
  12605. $xres = 1 / $xres;
  12606. $newstyle = array(
  12607. 'position' => 'L',
  12608. 'border' => false,
  12609. 'padding' => 0,
  12610. 'fgcolor' => array(0,0,0),
  12611. 'bgcolor' => false,
  12612. 'text' => true,
  12613. 'font' => $font,
  12614. 'fontsize' => 8,
  12615. 'stretchtext' => 4
  12616. );
  12617. if ($style & 1) {
  12618. $newstyle['border'] = true;
  12619. }
  12620. if ($style & 2) {
  12621. $newstyle['bgcolor'] = false;
  12622. }
  12623. if ($style & 4) {
  12624. $newstyle['position'] = 'C';
  12625. } elseif ($style & 8) {
  12626. $newstyle['position'] = 'L';
  12627. } elseif ($style & 16) {
  12628. $newstyle['position'] = 'R';
  12629. }
  12630. if ($style & 128) {
  12631. $newstyle['text'] = true;
  12632. }
  12633. if ($style & 256) {
  12634. $newstyle['stretchtext'] = 4;
  12635. }
  12636. $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, '');
  12637. }
  12638. /**
  12639. * Print 2D Barcode.
  12640. * @param string $code code to print
  12641. * @param string $type type of barcode (see 2dbarcodes.php for supported formats).
  12642. * @param int $x x position in user units
  12643. * @param int $y y position in user units
  12644. * @param int $w width in user units
  12645. * @param int $h height in user units
  12646. * @param array $style array of options:<ul><li>boolean $style['border'] if true prints a border around the barcode</li><li>int $style['padding'] padding to leave around the barcode in user units</li><li>array $style['fgcolor'] color array for bars and text</li><li>mixed $style['bgcolor'] color array for background or false for transparent</li></ul>
  12647. * @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>
  12648. * @author Nicola Asuni
  12649. * @since 4.5.037 (2009-04-07)
  12650. * @access public
  12651. */
  12652. public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='') {
  12653. if ($this->empty_string($code)) {
  12654. return;
  12655. }
  12656. require_once(dirname(__FILE__).'/2dbarcodes.php');
  12657. // save current graphic settings
  12658. $gvars = $this->getGraphicVars();
  12659. // create new barcode object
  12660. $barcodeobj = new TCPDF2DBarcode($code, $type);
  12661. $arrcode = $barcodeobj->getBarcodeArray();
  12662. if ($arrcode === false) {
  12663. $this->Error('Error in 2D barcode string');
  12664. }
  12665. // set default values
  12666. if (!isset($style['padding'])) {
  12667. $style['padding'] = 0;
  12668. }
  12669. if (!isset($style['fgcolor'])) {
  12670. $style['fgcolor'] = array(0,0,0); // default black
  12671. }
  12672. if (!isset($style['bgcolor'])) {
  12673. $style['bgcolor'] = false; // default transparent
  12674. }
  12675. if (!isset($style['border'])) {
  12676. $style['border'] = false;
  12677. }
  12678. // set foreground color
  12679. $this->SetDrawColorArray($style['fgcolor']);
  12680. if ($this->empty_string($x)) {
  12681. $x = $this->GetX();
  12682. }
  12683. if ($this->rtl) {
  12684. $x = $this->w - $x;
  12685. }
  12686. if ($this->empty_string($y)) {
  12687. $y = $this->GetY();
  12688. }
  12689. if ($this->empty_string($w) OR ($w <= 0)) {
  12690. if ($this->rtl) {
  12691. $w = $x - $this->lMargin;
  12692. } else {
  12693. $w = $this->w - $this->rMargin - $x;
  12694. }
  12695. }
  12696. if ($this->empty_string($h) OR ($h <= 0)) {
  12697. // 2d barcodes are square by default
  12698. $h = $w;
  12699. }
  12700. $prev_x = $this->x;
  12701. if ($this->checkPageBreak($h, $y)) {
  12702. $y = $this->GetY() + $this->cMargin;
  12703. if ($this->rtl) {
  12704. $x += ($prev_x - $this->x);
  12705. } else {
  12706. $x += ($this->x - $prev_x);
  12707. }
  12708. }
  12709. // calculate barcode size (excluding padding)
  12710. $bw = $w - (2 * $style['padding']);
  12711. $bh = $h - (2 * $style['padding']);
  12712. // calculate starting coordinates
  12713. if ($this->rtl) {
  12714. $xpos = $x - $w;
  12715. } else {
  12716. $xpos = $x;
  12717. }
  12718. $xpos += $style['padding'];
  12719. $ypos = $y + $style['padding'];
  12720. // barcode is always printed in LTR direction
  12721. $tempRTL = $this->rtl;
  12722. $this->rtl = false;
  12723. // print background color
  12724. if ($style['bgcolor']) {
  12725. $this->Rect($x, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  12726. } elseif ($style['border']) {
  12727. $this->Rect($x, $y, $w, $h, 'D');
  12728. }
  12729. // print barcode cells
  12730. if ($arrcode !== false) {
  12731. $rows = $arrcode['num_rows'];
  12732. $cols = $arrcode['num_cols'];
  12733. // calculate dimension of single barcode cell
  12734. $cw = $bw / $cols;
  12735. $ch = $bh / $rows;
  12736. // for each row
  12737. for ($r = 0; $r < $rows; ++$r) {
  12738. $xr = $xpos;
  12739. // for each column
  12740. for ($c = 0; $c < $cols; ++$c) {
  12741. if ($arrcode['bcode'][$r][$c] == 1) {
  12742. // draw a single barcode cell
  12743. $this->Rect($xr, $ypos, $cw, $ch, 'F', array(), $style['fgcolor']);
  12744. }
  12745. $xr += $cw;
  12746. }
  12747. $ypos += $ch;
  12748. }
  12749. }
  12750. // restore original direction
  12751. $this->rtl = $tempRTL;
  12752. // restore previous settings
  12753. $this->setGraphicVars($gvars);
  12754. // set bottomcoordinates
  12755. $this->img_rb_y = $y + $h;
  12756. if ($this->rtl) {
  12757. // set left side coordinate
  12758. $this->img_rb_x = ($this->w - $x - $w);
  12759. } else {
  12760. // set right side coordinate
  12761. $this->img_rb_x = $x + $w;
  12762. }
  12763. // set pointer to align the successive text/objects
  12764. switch($align) {
  12765. case 'T':{
  12766. $this->y = $y;
  12767. $this->x = $this->img_rb_x;
  12768. break;
  12769. }
  12770. case 'M':{
  12771. $this->y = $y + round($h/2);
  12772. $this->x = $this->img_rb_x;
  12773. break;
  12774. }
  12775. case 'B':{
  12776. $this->y = $this->img_rb_y;
  12777. $this->x = $this->img_rb_x;
  12778. break;
  12779. }
  12780. case 'N':{
  12781. $this->SetY($this->img_rb_y);
  12782. break;
  12783. }
  12784. default:{
  12785. break;
  12786. }
  12787. }
  12788. }
  12789. /**
  12790. * Returns an array containing current margins:
  12791. * <ul>
  12792. <li>$ret['left'] = left margin</li>
  12793. <li>$ret['right'] = right margin</li>
  12794. <li>$ret['top'] = top margin</li>
  12795. <li>$ret['bottom'] = bottom margin</li>
  12796. <li>$ret['header'] = header margin</li>
  12797. <li>$ret['footer'] = footer margin</li>
  12798. <li>$ret['cell'] = cell margin</li>
  12799. * </ul>
  12800. * @return array containing all margins measures
  12801. * @access public
  12802. * @since 3.2.000 (2008-06-23)
  12803. */
  12804. public function getMargins() {
  12805. $ret = array(
  12806. 'left' => $this->lMargin,
  12807. 'right' => $this->rMargin,
  12808. 'top' => $this->tMargin,
  12809. 'bottom' => $this->bMargin,
  12810. 'header' => $this->header_margin,
  12811. 'footer' => $this->footer_margin,
  12812. 'cell' => $this->cMargin,
  12813. );
  12814. return $ret;
  12815. }
  12816. /**
  12817. * Returns an array containing original margins:
  12818. * <ul>
  12819. <li>$ret['left'] = left margin</li>
  12820. <li>$ret['right'] = right margin</li>
  12821. * </ul>
  12822. * @return array containing all margins measures
  12823. * @access public
  12824. * @since 4.0.012 (2008-07-24)
  12825. */
  12826. public function getOriginalMargins() {
  12827. $ret = array(
  12828. 'left' => $this->original_lMargin,
  12829. 'right' => $this->original_rMargin
  12830. );
  12831. return $ret;
  12832. }
  12833. /**
  12834. * Returns the current font size.
  12835. * @return current font size
  12836. * @access public
  12837. * @since 3.2.000 (2008-06-23)
  12838. */
  12839. public function getFontSize() {
  12840. return $this->FontSize;
  12841. }
  12842. /**
  12843. * Returns the current font size in points unit.
  12844. * @return current font size in points unit
  12845. * @access public
  12846. * @since 3.2.000 (2008-06-23)
  12847. */
  12848. public function getFontSizePt() {
  12849. return $this->FontSizePt;
  12850. }
  12851. /**
  12852. * Returns the current font family name.
  12853. * @return string current font family name
  12854. * @access public
  12855. * @since 4.3.008 (2008-12-05)
  12856. */
  12857. public function getFontFamily() {
  12858. return $this->FontFamily;
  12859. }
  12860. /**
  12861. * Returns the current font style.
  12862. * @return string current font style
  12863. * @access public
  12864. * @since 4.3.008 (2008-12-05)
  12865. */
  12866. public function getFontStyle() {
  12867. return $this->FontStyle;
  12868. }
  12869. /**
  12870. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  12871. * 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 />
  12872. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  12873. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  12874. * @param float $h Cell minimum height. The cell extends automatically if needed.
  12875. * @param float $x upper-left corner X coordinate
  12876. * @param float $y upper-left corner Y coordinate
  12877. * @param string $html html text to print. Default value: empty string.
  12878. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  12879. * @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>
  12880. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  12881. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  12882. * @param boolean $reseth if true reset the last cell height (default true).
  12883. * @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>
  12884. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  12885. * @access public
  12886. * @uses MultiCell()
  12887. * @see Multicell(), writeHTML()
  12888. */
  12889. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true) {
  12890. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0);
  12891. }
  12892. /**
  12893. * Returns the HTML DOM array.
  12894. * <ul><li>$dom[$key]['tag'] = true if tag, false otherwise;</li><li>$dom[$key]['value'] = tag name or text;</li><li>$dom[$key]['opening'] = true if opening tag, false otherwise;</li><li>$dom[$key]['attribute'] = array of attributes (attribute name is the key);</li><li>$dom[$key]['style'] = array of style attributes (attribute name is the key);</li><li>$dom[$key]['parent'] = id of parent element;</li><li>$dom[$key]['fontname'] = font family name;</li><li>$dom[$key]['fontstyle'] = font style;</li><li>$dom[$key]['fontsize'] = font size in points;</li><li>$dom[$key]['bgcolor'] = RGB array of background color;</li><li>$dom[$key]['fgcolor'] = RGB array of foreground color;</li><li>$dom[$key]['width'] = width in pixels;</li><li>$dom[$key]['height'] = height in pixels;</li><li>$dom[$key]['align'] = text alignment;</li><li>$dom[$key]['cols'] = number of colums in table;</li><li>$dom[$key]['rows'] = number of rows in table;</li></ul>
  12895. * @param string $html html code
  12896. * @return array
  12897. * @access protected
  12898. * @since 3.2.000 (2008-06-20)
  12899. */
  12900. protected function getHtmlDomArray($html) {
  12901. // define block tags
  12902. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  12903. // remove all unsupported tags (the line below lists all supported tags)
  12904. $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><i><img><input><label><li><ol><option><p><pre><select><small><span><strong><sub><sup><table><tablehead><tcpdf><td><textarea><th><thead><tr><tt><u><ul>');
  12905. //replace some blank characters
  12906. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  12907. $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);
  12908. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  12909. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  12910. $html = strtr($html, $repTable);
  12911. $offset = 0;
  12912. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  12913. $html_a = substr($html, 0, $offset);
  12914. $html_b = substr($html, $offset, ($pos - $offset + 6));
  12915. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  12916. // preserve newlines on <pre> tag
  12917. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  12918. }
  12919. $html = $html_a.$html_b.substr($html, $pos + 6);
  12920. $offset = strlen($html_a.$html_b);
  12921. }
  12922. $offset = 0;
  12923. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  12924. $html_a = substr($html, 0, $offset);
  12925. $html_b = substr($html, $offset, ($pos - $offset + 11));
  12926. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  12927. // preserve newlines on <textarea> tag
  12928. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  12929. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  12930. }
  12931. $html = $html_a.$html_b.substr($html, $pos + 11);
  12932. $offset = strlen($html_a.$html_b);
  12933. }
  12934. $html = preg_replace("'([\s]*)<option'si", "<option", $html);
  12935. $html = preg_replace("'</option>([\s]*)'si", "</option>", $html);
  12936. $offset = 0;
  12937. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  12938. $html_a = substr($html, 0, $offset);
  12939. $html_b = substr($html, $offset, ($pos - $offset + 9));
  12940. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  12941. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2\t\\4\r", $html_b);
  12942. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2\r", $html_b);
  12943. }
  12944. $html = $html_a.$html_b.substr($html, $pos + 9);
  12945. $offset = strlen($html_a.$html_b);
  12946. }
  12947. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  12948. $html = preg_replace("'([\s]+)</select>'si", "\" />", $html);
  12949. $html = str_replace("\n", ' ', $html);
  12950. // restore textarea newlines
  12951. $html = str_replace('<TBR>', "\n", $html);
  12952. // remove extra spaces from code
  12953. $html = preg_replace('/[\s]+<\/(table|tr|td|th|ul|ol|li|dl|dt|dd)>/', '</\\1>', $html);
  12954. $html = preg_replace('/[\s]+<(tr|td|th|ul|ol|li|dl|dt|dd|br)/', '<\\1', $html);
  12955. $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);
  12956. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  12957. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  12958. $html = preg_replace('/[\s]*<img/', ' <img', $html);
  12959. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  12960. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  12961. $html = preg_replace('/<textarea([^\>]*)>/xi', '<textarea\\1 value="', $html);
  12962. $html = preg_replace('/<\/textarea>/', '" />', $html);
  12963. // trim string
  12964. $html = preg_replace('/^[\s]+/', '', $html);
  12965. $html = preg_replace('/[\s]+$/', '', $html);
  12966. // pattern for generic tag
  12967. $tagpattern = '/(<[^>]+>)/';
  12968. // explodes the string
  12969. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  12970. // count elements
  12971. $maxel = count($a);
  12972. $elkey = 0;
  12973. $key = 0;
  12974. // create an array of elements
  12975. $dom = array();
  12976. $dom[$key] = array();
  12977. // set first void element
  12978. $dom[$key]['tag'] = false;
  12979. $dom[$key]['block'] = false;
  12980. $dom[$key]['value'] = '';
  12981. $dom[$key]['parent'] = 0;
  12982. $dom[$key]['fontname'] = $this->FontFamily;
  12983. $dom[$key]['fontstyle'] = $this->FontStyle;
  12984. $dom[$key]['fontsize'] = $this->FontSizePt;
  12985. $dom[$key]['stroke'] = $this->textstrokewidth;
  12986. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  12987. $dom[$key]['clip'] = ($this->textrendermode > 3);
  12988. $dom[$key]['line-height'] = $this->cell_height_ratio;
  12989. $dom[$key]['bgcolor'] = false;
  12990. $dom[$key]['fgcolor'] = $this->fgcolor;
  12991. $dom[$key]['strokecolor'] = $this->strokecolor;
  12992. $dom[$key]['align'] = '';
  12993. $dom[$key]['listtype'] = '';
  12994. $dom[$key]['text-indent'] = 0;
  12995. $thead = false; // true when we are inside the THEAD tag
  12996. ++$key;
  12997. $level = array();
  12998. array_push($level, 0); // root
  12999. while ($elkey < $maxel) {
  13000. $dom[$key] = array();
  13001. $element = $a[$elkey];
  13002. $dom[$key]['elkey'] = $elkey;
  13003. if (preg_match($tagpattern, $element)) {
  13004. // html tag
  13005. $element = substr($element, 1, -1);
  13006. // get tag name
  13007. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  13008. $tagname = strtolower($tag[1]);
  13009. // check if we are inside a table header
  13010. if ($tagname == 'thead') {
  13011. if ($element{0} == '/') {
  13012. $thead = false;
  13013. } else {
  13014. $thead = true;
  13015. }
  13016. ++$elkey;
  13017. continue;
  13018. }
  13019. $dom[$key]['tag'] = true;
  13020. $dom[$key]['value'] = $tagname;
  13021. if (in_array($dom[$key]['value'], $blocktags)) {
  13022. $dom[$key]['block'] = true;
  13023. } else {
  13024. $dom[$key]['block'] = false;
  13025. }
  13026. if ($element{0} == '/') {
  13027. // *** closing html tag
  13028. $dom[$key]['opening'] = false;
  13029. $dom[$key]['parent'] = end($level);
  13030. array_pop($level);
  13031. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  13032. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  13033. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  13034. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  13035. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  13036. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  13037. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  13038. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  13039. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  13040. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  13041. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  13042. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  13043. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  13044. }
  13045. // set the number of columns in table tag
  13046. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  13047. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  13048. }
  13049. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  13050. $dom[($dom[$key]['parent'])]['content'] = '';
  13051. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  13052. $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
  13053. }
  13054. $key = $i;
  13055. // mark nested tables
  13056. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  13057. // remove thead sections from nested tables
  13058. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  13059. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  13060. }
  13061. // store header rows on a new table
  13062. if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
  13063. if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  13064. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  13065. }
  13066. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  13067. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  13068. }
  13069. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  13070. $dom[($dom[$key]['parent'])]['attribute'] = array();
  13071. }
  13072. // header elements must be always contained in a single page
  13073. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  13074. }
  13075. if (($dom[$key]['value'] == 'table') AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  13076. // remove the nobr attributes from the table header
  13077. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  13078. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  13079. }
  13080. } else {
  13081. // *** opening html tag
  13082. $dom[$key]['opening'] = true;
  13083. $dom[$key]['parent'] = end($level);
  13084. if (substr($element, -1, 1) != '/') {
  13085. // not self-closing tag
  13086. array_push($level, $key);
  13087. $dom[$key]['self'] = false;
  13088. } else {
  13089. $dom[$key]['self'] = true;
  13090. }
  13091. // copy some values from parent
  13092. $parentkey = 0;
  13093. if ($key > 0) {
  13094. $parentkey = $dom[$key]['parent'];
  13095. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  13096. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  13097. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  13098. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  13099. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  13100. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  13101. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  13102. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  13103. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  13104. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  13105. $dom[$key]['align'] = $dom[$parentkey]['align'];
  13106. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  13107. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  13108. }
  13109. // get attributes
  13110. preg_match_all('/([^=\s]*)=["]?([^"]*)["]?/', $element, $attr_array, PREG_PATTERN_ORDER);
  13111. $dom[$key]['attribute'] = array(); // reset attribute array
  13112. while (list($id, $name) = each($attr_array[1])) {
  13113. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  13114. }
  13115. // split style attributes
  13116. if (isset($dom[$key]['attribute']['style'])) {
  13117. // get style attributes
  13118. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  13119. $dom[$key]['style'] = array(); // reset style attribute array
  13120. while (list($id, $name) = each($style_array[1])) {
  13121. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  13122. }
  13123. // --- get some style attributes ---
  13124. if (isset($dom[$key]['style']['font-family'])) {
  13125. // font family
  13126. if (isset($dom[$key]['style']['font-family'])) {
  13127. $fontslist = preg_split('/[,]/', strtolower($dom[$key]['style']['font-family']));
  13128. foreach ($fontslist as $font) {
  13129. $font = trim(strtolower($font));
  13130. if (in_array($font, $this->fontlist) OR in_array($font, $this->fontkeys)) {
  13131. $dom[$key]['fontname'] = $font;
  13132. break;
  13133. }
  13134. }
  13135. }
  13136. }
  13137. // list-style-type
  13138. if (isset($dom[$key]['style']['list-style-type'])) {
  13139. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  13140. if ($dom[$key]['listtype'] == 'inherit') {
  13141. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  13142. }
  13143. }
  13144. // text-indent
  13145. if (isset($dom[$key]['style']['text-indent'])) {
  13146. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  13147. if ($dom[$key]['text-indent'] == 'inherit') {
  13148. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  13149. }
  13150. }
  13151. // font size
  13152. if (isset($dom[$key]['style']['font-size'])) {
  13153. $fsize = trim($dom[$key]['style']['font-size']);
  13154. switch ($fsize) {
  13155. // absolute-size
  13156. case 'xx-small': {
  13157. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4;
  13158. break;
  13159. }
  13160. case 'x-small': {
  13161. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3;
  13162. break;
  13163. }
  13164. case 'small': {
  13165. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2;
  13166. break;
  13167. }
  13168. case 'medium': {
  13169. $dom[$key]['fontsize'] = $dom[0]['fontsize'];
  13170. break;
  13171. }
  13172. case 'large': {
  13173. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2;
  13174. break;
  13175. }
  13176. case 'x-large': {
  13177. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4;
  13178. break;
  13179. }
  13180. case 'xx-large': {
  13181. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6;
  13182. break;
  13183. }
  13184. // relative-size
  13185. case 'smaller': {
  13186. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3;
  13187. break;
  13188. }
  13189. case 'larger': {
  13190. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3;
  13191. break;
  13192. }
  13193. default: {
  13194. $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true);
  13195. }
  13196. }
  13197. }
  13198. // line-height
  13199. if (isset($dom[$key]['style']['line-height'])) {
  13200. $lineheight = trim($dom[$key]['style']['line-height']);
  13201. switch ($lineheight) {
  13202. // A normal line height. This is default
  13203. case 'normal': {
  13204. $dom[$key]['line-height'] = $dom[0]['line-height'];
  13205. break;
  13206. }
  13207. default: {
  13208. if (is_numeric($lineheight)) {
  13209. $lineheight = $lineheight * 100;
  13210. }
  13211. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  13212. }
  13213. }
  13214. }
  13215. // font style
  13216. if (isset($dom[$key]['style']['font-weight']) AND (strtolower($dom[$key]['style']['font-weight']{0}) == 'b')) {
  13217. $dom[$key]['fontstyle'] .= 'B';
  13218. }
  13219. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) {
  13220. $dom[$key]['fontstyle'] .= 'I';
  13221. }
  13222. // font color
  13223. if (isset($dom[$key]['style']['color']) AND (!$this->empty_string($dom[$key]['style']['color']))) {
  13224. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']);
  13225. }
  13226. // background color
  13227. if (isset($dom[$key]['style']['background-color']) AND (!$this->empty_string($dom[$key]['style']['background-color']))) {
  13228. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
  13229. }
  13230. // text-decoration
  13231. if (isset($dom[$key]['style']['text-decoration'])) {
  13232. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  13233. foreach ($decors as $dec) {
  13234. $dec = trim($dec);
  13235. if (!$this->empty_string($dec)) {
  13236. if ($dec{0} == 'u') {
  13237. // underline
  13238. $dom[$key]['fontstyle'] .= 'U';
  13239. } elseif ($dec{0} == 'l') {
  13240. // line-trough
  13241. $dom[$key]['fontstyle'] .= 'D';
  13242. } elseif ($dec{0} == 'o') {
  13243. // overline
  13244. $dom[$key]['fontstyle'] .= 'O';
  13245. }
  13246. }
  13247. }
  13248. }
  13249. // check for width attribute
  13250. if (isset($dom[$key]['style']['width'])) {
  13251. $dom[$key]['width'] = $dom[$key]['style']['width'];
  13252. }
  13253. // check for height attribute
  13254. if (isset($dom[$key]['style']['height'])) {
  13255. $dom[$key]['height'] = $dom[$key]['style']['height'];
  13256. }
  13257. // check for text alignment
  13258. if (isset($dom[$key]['style']['text-align'])) {
  13259. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
  13260. }
  13261. // check for border attribute
  13262. if (isset($dom[$key]['style']['border'])) {
  13263. $dom[$key]['attribute']['border'] = $dom[$key]['style']['border'];
  13264. }
  13265. // page-break-inside
  13266. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  13267. $dom[$key]['attribute']['nobr'] = 'true';
  13268. }
  13269. // page-break-before
  13270. if (isset($dom[$key]['style']['page-break-before'])) {
  13271. if ($dom[$key]['style']['page-break-before'] == 'always') {
  13272. $dom[$key]['attribute']['pagebreak'] = 'true';
  13273. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  13274. $dom[$key]['attribute']['pagebreak'] = 'left';
  13275. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  13276. $dom[$key]['attribute']['pagebreak'] = 'right';
  13277. }
  13278. }
  13279. // page-break-after
  13280. if (isset($dom[$key]['style']['page-break-after'])) {
  13281. if ($dom[$key]['style']['page-break-after'] == 'always') {
  13282. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  13283. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  13284. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  13285. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  13286. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  13287. }
  13288. }
  13289. }
  13290. // check for font tag
  13291. if ($dom[$key]['value'] == 'font') {
  13292. // font family
  13293. if (isset($dom[$key]['attribute']['face'])) {
  13294. $fontslist = preg_split('/[,]/', strtolower($dom[$key]['attribute']['face']));
  13295. foreach ($fontslist as $font) {
  13296. $font = trim(strtolower($font));
  13297. if (in_array($font, $this->fontlist) OR in_array($font, $this->fontkeys)) {
  13298. $dom[$key]['fontname'] = $font;
  13299. break;
  13300. }
  13301. }
  13302. }
  13303. // font size
  13304. if (isset($dom[$key]['attribute']['size'])) {
  13305. if ($key > 0) {
  13306. if ($dom[$key]['attribute']['size']{0} == '+') {
  13307. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  13308. } elseif ($dom[$key]['attribute']['size']{0} == '-') {
  13309. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  13310. } else {
  13311. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  13312. }
  13313. } else {
  13314. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  13315. }
  13316. }
  13317. }
  13318. // force natural alignment for lists
  13319. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  13320. AND (!isset($dom[$key]['align']) OR $this->empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  13321. if ($this->rtl) {
  13322. $dom[$key]['align'] = 'R';
  13323. } else {
  13324. $dom[$key]['align'] = 'L';
  13325. }
  13326. }
  13327. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  13328. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  13329. }
  13330. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  13331. $dom[$key]['fontstyle'] .= 'B';
  13332. }
  13333. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  13334. $dom[$key]['fontstyle'] .= 'I';
  13335. }
  13336. if ($dom[$key]['value'] == 'u') {
  13337. $dom[$key]['fontstyle'] .= 'U';
  13338. }
  13339. if ($dom[$key]['value'] == 'del') {
  13340. $dom[$key]['fontstyle'] .= 'D';
  13341. }
  13342. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  13343. $dom[$key]['fontname'] = $this->default_monospaced_font;
  13344. }
  13345. if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
  13346. $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
  13347. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  13348. $dom[$key]['fontstyle'] .= 'B';
  13349. }
  13350. if (($dom[$key]['value'] == 'table')) {
  13351. $dom[$key]['rows'] = 0; // number of rows
  13352. $dom[$key]['trids'] = array(); // IDs of TR elements
  13353. $dom[$key]['thead'] = ''; // table header rows
  13354. }
  13355. if (($dom[$key]['value'] == 'tr')) {
  13356. $dom[$key]['cols'] = 0;
  13357. if ($thead) {
  13358. $dom[$key]['thead'] = true;
  13359. // rows on thead block are printed as a separate table
  13360. } else {
  13361. $dom[$key]['thead'] = false;
  13362. // store the number of rows on table element
  13363. ++$dom[($dom[$key]['parent'])]['rows'];
  13364. // store the TR elements IDs on table element
  13365. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  13366. }
  13367. }
  13368. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  13369. if (isset($dom[$key]['attribute']['colspan'])) {
  13370. $colspan = intval($dom[$key]['attribute']['colspan']);
  13371. } else {
  13372. $colspan = 1;
  13373. }
  13374. $dom[$key]['attribute']['colspan'] = $colspan;
  13375. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  13376. }
  13377. // set foreground color attribute
  13378. if (isset($dom[$key]['attribute']['color']) AND (!$this->empty_string($dom[$key]['attribute']['color']))) {
  13379. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
  13380. }
  13381. // set background color attribute
  13382. if (isset($dom[$key]['attribute']['bgcolor']) AND (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) {
  13383. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
  13384. }
  13385. // set stroke color attribute
  13386. if (isset($dom[$key]['attribute']['strokecolor']) AND (!$this->empty_string($dom[$key]['attribute']['strokecolor']))) {
  13387. $dom[$key]['strokecolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['strokecolor']);
  13388. }
  13389. // check for width attribute
  13390. if (isset($dom[$key]['attribute']['width'])) {
  13391. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  13392. }
  13393. // check for height attribute
  13394. if (isset($dom[$key]['attribute']['height'])) {
  13395. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  13396. }
  13397. // check for text alignment
  13398. if (isset($dom[$key]['attribute']['align']) AND (!$this->empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  13399. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
  13400. }
  13401. // check for text rendering mode (the following attributes do not exist in HTML)
  13402. if (isset($dom[$key]['attribute']['stroke'])) {
  13403. // font stroke width
  13404. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  13405. }
  13406. if (isset($dom[$key]['attribute']['fill'])) {
  13407. // font fill
  13408. if ($dom[$key]['attribute']['fill'] == 'true') {
  13409. $dom[$key]['fill'] = true;
  13410. } else {
  13411. $dom[$key]['fill'] = false;
  13412. }
  13413. }
  13414. if (isset($dom[$key]['attribute']['clip'])) {
  13415. // clipping mode
  13416. if ($dom[$key]['attribute']['clip'] == 'true') {
  13417. $dom[$key]['clip'] = true;
  13418. } else {
  13419. $dom[$key]['clip'] = false;
  13420. }
  13421. }
  13422. } // end opening tag
  13423. } else {
  13424. // text
  13425. $dom[$key]['tag'] = false;
  13426. $dom[$key]['block'] = false;
  13427. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  13428. $dom[$key]['parent'] = end($level);
  13429. }
  13430. ++$elkey;
  13431. ++$key;
  13432. }
  13433. return $dom;
  13434. }
  13435. /**
  13436. * Returns the string used to find spaces
  13437. * @return string
  13438. * @access protected
  13439. * @author Nicola Asuni
  13440. * @since 4.8.024 (2010-01-15)
  13441. */
  13442. protected function getSpaceString() {
  13443. $spacestr = chr(32);
  13444. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) {
  13445. $spacestr = chr(0).chr(32);
  13446. }
  13447. return $spacestr;
  13448. }
  13449. /**
  13450. * Allows to preserve some HTML formatting (limited support).<br />
  13451. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  13452. * 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
  13453. * @param string $html text to display
  13454. * @param boolean $ln if true add a new line after text (default = true)
  13455. * @param int $fill Indicates if the background must be painted (true) or transparent (false).
  13456. * @param boolean $reseth if true reset the last cell height (default false).
  13457. * @param boolean $cell if true add the default cMargin space to each Write (default false).
  13458. * @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>
  13459. * @access public
  13460. */
  13461. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  13462. $gvars = $this->getGraphicVars();
  13463. // store current values
  13464. $prevPage = $this->page;
  13465. $prevlMargin = $this->lMargin;
  13466. $prevrMargin = $this->rMargin;
  13467. $curfontname = $this->FontFamily;
  13468. $curfontstyle = $this->FontStyle;
  13469. $curfontsize = $this->FontSizePt;
  13470. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  13471. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  13472. $this->newline = true;
  13473. $startlinepage = $this->page;
  13474. $minstartliney = $this->y;
  13475. $maxbottomliney = 0;
  13476. $startlinex = $this->x;
  13477. $startliney = $this->y;
  13478. $yshift = 0;
  13479. $newline = true;
  13480. $loop = 0;
  13481. $curpos = 0;
  13482. $this_method_vars = array();
  13483. $undo = false;
  13484. $fontaligned = false;
  13485. $this->premode = false;
  13486. if (isset($this->PageAnnots[$this->page])) {
  13487. $pask = count($this->PageAnnots[$this->page]);
  13488. } else {
  13489. $pask = 0;
  13490. }
  13491. if (!$this->InFooter) {
  13492. if (isset($this->footerlen[$this->page])) {
  13493. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  13494. } else {
  13495. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  13496. }
  13497. $startlinepos = $this->footerpos[$this->page];
  13498. } else {
  13499. $startlinepos = $this->pagelen[$this->page];
  13500. }
  13501. $lalign = $align;
  13502. $plalign = $align;
  13503. if ($this->rtl) {
  13504. $w = $this->x - $this->lMargin;
  13505. } else {
  13506. $w = $this->w - $this->rMargin - $this->x;
  13507. }
  13508. $w -= (2 * $this->cMargin);
  13509. if ($cell) {
  13510. if ($this->rtl) {
  13511. $this->x -= $this->cMargin;
  13512. } else {
  13513. $this->x += $this->cMargin;
  13514. }
  13515. }
  13516. if ($this->customlistindent >= 0) {
  13517. $this->listindent = $this->customlistindent;
  13518. } else {
  13519. $this->listindent = $this->GetStringWidth('0000');
  13520. }
  13521. $this->listin