PageRenderTime 137ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 1ms

/common/libraries/plugin/html2pdf/_tcpdf/tcpdf.php

https://bitbucket.org/renaatdemuynck/chamilo
PHP | 11975 lines | 7847 code | 475 blank | 3653 comment | 1168 complexity | 33edb21baeef4b607f392f3e9431e70d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Begin : 2002-08-03
  5. // Last Update : 2010-03-13
  6. // Author : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
  7. // Version : 4.8.038
  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. // * supports all ISO page formats;
  39. // * supports custom page formats, margins and units of measure;
  40. // * supports UTF-8 Unicode and Right-To-Left languages;
  41. // * supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  42. // * supports document encryption;
  43. // * includes methods to publish some XHTML code, including forms;
  44. // * includes graphic (geometric) and transformation methods;
  45. // * includes Javascript and Forms support;
  46. // * includes a method to print various barcode formats: 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;
  47. // * includes methods to set Bookmarks and print a Table of Content;
  48. // * includes methods to move and delete pages;
  49. // * includes methods for automatic page header and footer management;
  50. // * supports automatic page break;
  51. // * supports automatic page numbering and page groups;
  52. // * supports automatic line break and text justification;
  53. // * 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)
  54. // * supports stroke and clipping mode for text;
  55. // * supports clipping masks;
  56. // * supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  57. // * supports several annotations, including links, text and file attachments;
  58. // * supports page compression (requires zlib extension);
  59. // * supports text hyphenation.
  60. // * supports transactions to UNDO commands.
  61. // * supports signature certifications.
  62. //
  63. // -----------------------------------------------------------
  64. // THANKS TO:
  65. //
  66. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  67. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  68. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  69. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  70. // dullus for text Justification.
  71. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  72. // Patrick Benny for text stretch suggestion on Cell().
  73. // Johannes G�ntert for JavaScript support.
  74. // Denis Van Nuffelen for Dynamic Form.
  75. // Jacek Czekaj for multibyte justification
  76. // Anthony Ferrara for the reintroduction of legacy image methods.
  77. // Sourceforge user 1707880 (hucste) for line-trough mode.
  78. // Larry Stanbery for page groups.
  79. // Martin Hall-May for transparency.
  80. // Aaron C. Spike for Polycurve method.
  81. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  82. // Moritz Wagner and Andreas Wurmser for graphic functions.
  83. // Andrew Whitehead for core fonts support.
  84. // Esteban Jo�l Mar�n for OpenType font conversion.
  85. // Teus Hagen for several suggestions and fixes.
  86. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  87. // Kosmas Papachristos for some CSS improvements.
  88. // Marcel Partap for some fixes.
  89. // Won Kyu Park for several suggestions, fixes and patches.
  90. // Anyone that has reported a bug or sent a suggestion.
  91. //============================================================+
  92. /**
  93. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  94. * 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>
  95. * <h3>TCPDF main features are:</h3>
  96. * <ul>
  97. * <li>no external libraries are required for the basic functions;</li>
  98. * <li>supports all ISO page formats;</li>
  99. * <li>supports custom page formats, margins and units of measure;</li>
  100. * <li>supports UTF-8 Unicode and Right-To-Left languages;</li>
  101. * <li>supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  102. * <li>supports document encryption;</li>
  103. * <li>includes methods to publish some XHTML code, including forms;</li>
  104. * <li>includes graphic (geometric) and transformation methods;</li>
  105. * <li>includes Javascript and Forms support;</li>
  106. * <li>includes a method to print various barcode formats: 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</li>
  107. * <li>includes methods to set Bookmarks and print a Table of Content;</li>
  108. * <li>includes methods to move and delete pages;</li>
  109. * <li>includes methods for automatic page header and footer management;</li>
  110. * <li>supports automatic page break;</li>
  111. * <li>supports automatic page numbering and page groups;</li>
  112. * <li>supports automatic line break and text justification;</li>
  113. * <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>
  114. * <li>supports stroke and clipping mode for text;</li>
  115. * <li>supports clipping masks;</li>
  116. * <li>supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  117. * <li>supports several annotations, including links, text and file attachments;</li>
  118. * <li>supports page compression (requires zlib extension);</li>
  119. * <li>supports text hyphenation.</li>
  120. * <li>supports transactions to UNDO commands.</li>
  121. * <li>supports signature certifications.</li>
  122. * </ul>
  123. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  124. * @package com.tecnick.tcpdf
  125. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  126. * @author Nicola Asuni
  127. * @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
  128. * @link http://www.tcpdf.org
  129. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  130. * @version 4.8.038
  131. */
  132. /**
  133. * main configuration file
  134. */
  135. require_once (dirname(__FILE__) . '/config/tcpdf_config.php');
  136. // includes some support files
  137. /**
  138. * unicode data
  139. */
  140. require_once (dirname(__FILE__) . '/unicode_data.php');
  141. /**
  142. * html colors table
  143. */
  144. require_once (dirname(__FILE__) . '/htmlcolors.php');
  145. if (! class_exists('TCPDF', false))
  146. {
  147. /**
  148. * define default PDF document producer
  149. */
  150. define('PDF_PRODUCER', 'TCPDF 4.8.038 (http://www.tcpdf.org)');
  151. /**
  152. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  153. * 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>
  154. * @name TCPDF
  155. * @package com.tecnick.tcpdf
  156. * @version 4.8.038
  157. * @author Nicola Asuni - info@tecnick.com
  158. * @link http://www.tcpdf.org
  159. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  160. */
  161. class TCPDF
  162. {
  163. // protected or Protected properties
  164. /**
  165. * @var current page number
  166. * @access protected
  167. */
  168. protected $page;
  169. /**
  170. * @var current object number
  171. * @access protected
  172. */
  173. protected $n;
  174. /**
  175. * @var array of object offsets
  176. * @access protected
  177. */
  178. protected $offsets;
  179. /**
  180. * @var buffer holding in-memory PDF
  181. * @access protected
  182. */
  183. protected $buffer;
  184. /**
  185. * @var array containing pages
  186. * @access protected
  187. */
  188. protected $pages = array();
  189. /**
  190. * @var current document state
  191. * @access protected
  192. */
  193. protected $state;
  194. /**
  195. * @var compression flag
  196. * @access protected
  197. */
  198. protected $compress;
  199. /**
  200. * @var current page orientation (P = Portrait, L = Landscape)
  201. * @access protected
  202. */
  203. protected $CurOrientation;
  204. /**
  205. * @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>
  206. * @access protected
  207. */
  208. protected $pagedim = array();
  209. /**
  210. * @var scale factor (number of points in user unit)
  211. * @access protected
  212. */
  213. protected $k;
  214. /**
  215. * @var width of page format in points
  216. * @access protected
  217. */
  218. protected $fwPt;
  219. /**
  220. * @var height of page format in points
  221. * @access protected
  222. */
  223. protected $fhPt;
  224. /**
  225. * @var current width of page in points
  226. * @access protected
  227. */
  228. protected $wPt;
  229. /**
  230. * @var current height of page in points
  231. * @access protected
  232. */
  233. protected $hPt;
  234. /**
  235. * @var current width of page in user unit
  236. * @access protected
  237. */
  238. protected $w;
  239. /**
  240. * @var current height of page in user unit
  241. * @access protected
  242. */
  243. protected $h;
  244. /**
  245. * @var left margin
  246. * @access protected
  247. */
  248. protected $lMargin;
  249. /**
  250. * @var top margin
  251. * @access protected
  252. */
  253. protected $tMargin;
  254. /**
  255. * @var right margin
  256. * @access protected
  257. */
  258. protected $rMargin;
  259. /**
  260. * @var page break margin
  261. * @access protected
  262. */
  263. protected $bMargin;
  264. /**
  265. * @var cell internal padding
  266. * @access protected
  267. */
  268. //protected
  269. public $cMargin;
  270. /**
  271. * @var cell internal padding (previous value)
  272. * @access protected
  273. */
  274. protected $oldcMargin;
  275. /**
  276. * @var current horizontal position in user unit for cell positioning
  277. * @access protected
  278. */
  279. protected $x;
  280. /**
  281. * @var current vertical position in user unit for cell positioning
  282. * @access protected
  283. */
  284. protected $y;
  285. /**
  286. * @var height of last cell printed
  287. * @access protected
  288. */
  289. protected $lasth;
  290. /**
  291. * @var line width in user unit
  292. * @access protected
  293. */
  294. protected $LineWidth;
  295. /**
  296. * @var array of standard font names
  297. * @access protected
  298. */
  299. protected $CoreFonts;
  300. /**
  301. * @var array of used fonts
  302. * @access protected
  303. */
  304. protected $fonts = array();
  305. /**
  306. * @var array of font files
  307. * @access protected
  308. */
  309. protected $FontFiles = array();
  310. /**
  311. * @var array of encoding differences
  312. * @access protected
  313. */
  314. protected $diffs = array();
  315. /**
  316. * @var array of used images
  317. * @access protected
  318. */
  319. protected $images = array();
  320. /**
  321. * @var array of Annotations in pages
  322. * @access protected
  323. */
  324. protected $PageAnnots = array();
  325. /**
  326. * @var array of internal links
  327. * @access protected
  328. */
  329. protected $links = array();
  330. /**
  331. * @var current font family
  332. * @access protected
  333. */
  334. protected $FontFamily;
  335. /**
  336. * @var current font style
  337. * @access protected
  338. */
  339. protected $FontStyle;
  340. /**
  341. * @var current font ascent (distance between font top and baseline)
  342. * @access protected
  343. * @since 2.8.000 (2007-03-29)
  344. */
  345. protected $FontAscent;
  346. /**
  347. * @var current font descent (distance between font bottom and baseline)
  348. * @access protected
  349. * @since 2.8.000 (2007-03-29)
  350. */
  351. protected $FontDescent;
  352. /**
  353. * @var underlining flag
  354. * @access protected
  355. */
  356. protected $underline;
  357. /**
  358. * @var current font info
  359. * @access protected
  360. */
  361. protected $CurrentFont;
  362. /**
  363. * @var current font size in points
  364. * @access protected
  365. */
  366. protected $FontSizePt;
  367. /**
  368. * @var current font size in user unit
  369. * @access protected
  370. */
  371. protected $FontSize;
  372. /**
  373. * @var commands for drawing color
  374. * @access protected
  375. */
  376. protected $DrawColor;
  377. /**
  378. * @var commands for filling color
  379. * @access protected
  380. */
  381. protected $FillColor;
  382. /**
  383. * @var commands for text color
  384. * @access protected
  385. */
  386. protected $TextColor;
  387. /**
  388. * @var indicates whether fill and text colors are different
  389. * @access protected
  390. */
  391. protected $ColorFlag;
  392. /**
  393. * @var automatic page breaking
  394. * @access protected
  395. */
  396. protected $AutoPageBreak;
  397. /**
  398. * @var threshold used to trigger page breaks
  399. * @access protected
  400. */
  401. protected $PageBreakTrigger;
  402. /**
  403. * @var flag set when processing footer
  404. * @access protected
  405. */
  406. protected $InFooter = false;
  407. /**
  408. * @var zoom display mode
  409. * @access protected
  410. */
  411. protected $ZoomMode;
  412. /**
  413. * @var layout display mode
  414. * @access protected
  415. */
  416. protected $LayoutMode;
  417. /**
  418. * @var title
  419. * @access protected
  420. */
  421. protected $title = '';
  422. /**
  423. * @var subject
  424. * @access protected
  425. */
  426. protected $subject = '';
  427. /**
  428. * @var author
  429. * @access protected
  430. */
  431. protected $author = '';
  432. /**
  433. * @var keywords
  434. * @access protected
  435. */
  436. protected $keywords = '';
  437. /**
  438. * @var creator
  439. * @access protected
  440. */
  441. protected $creator = '';
  442. /**
  443. * @var alias for total number of pages
  444. * @access protected
  445. */
  446. protected $AliasNbPages = '{nb}';
  447. /**
  448. * @var alias for page number
  449. * @access protected
  450. */
  451. protected $AliasNumPage = '{pnb}';
  452. /**
  453. * @var right-bottom corner X coordinate of inserted image
  454. * @since 2002-07-31
  455. * @author Nicola Asuni
  456. * @access protected
  457. */
  458. protected $img_rb_x;
  459. /**
  460. * @var right-bottom corner Y coordinate of inserted image
  461. * @since 2002-07-31
  462. * @author Nicola Asuni
  463. * @access protected
  464. */
  465. protected $img_rb_y;
  466. /**
  467. * @var adjusting factor to convert pixels to user units.
  468. * @since 2004-06-14
  469. * @author Nicola Asuni
  470. * @access protected
  471. */
  472. protected $imgscale = 1;
  473. /**
  474. * @var boolean set to true when the input text is unicode (require unicode fonts)
  475. * @since 2005-01-02
  476. * @author Nicola Asuni
  477. * @access protected
  478. */
  479. protected $isunicode = false;
  480. /**
  481. * @var PDF version
  482. * @since 1.5.3
  483. * @access protected
  484. */
  485. protected $PDFVersion = '1.7';
  486. // ----------------------
  487. /**
  488. * @var Minimum distance between header and top page margin.
  489. * @access protected
  490. */
  491. protected $header_margin;
  492. /**
  493. * @var Minimum distance between footer and bottom page margin.
  494. * @access protected
  495. */
  496. protected $footer_margin;
  497. /**
  498. * @var original left margin value
  499. * @access protected
  500. * @since 1.53.0.TC013
  501. */
  502. protected $original_lMargin;
  503. /**
  504. * @var original right margin value
  505. * @access protected
  506. * @since 1.53.0.TC013
  507. */
  508. protected $original_rMargin;
  509. /**
  510. * @var Header font.
  511. * @access protected
  512. */
  513. protected $header_font;
  514. /**
  515. * @var Footer font.
  516. * @access protected
  517. */
  518. protected $footer_font;
  519. /**
  520. * @var Language templates.
  521. * @access protected
  522. */
  523. protected $l;
  524. /**
  525. * @var Barcode to print on page footer (only if set).
  526. * @access protected
  527. */
  528. protected $barcode = false;
  529. /**
  530. * @var If true prints header
  531. * @access protected
  532. */
  533. protected $print_header = true;
  534. /**
  535. * @var If true prints footer.
  536. * @access protected
  537. */
  538. protected $print_footer = true;
  539. /**
  540. * @var Header image logo.
  541. * @access protected
  542. */
  543. protected $header_logo = '';
  544. /**
  545. * @var Header image logo width in mm.
  546. * @access protected
  547. */
  548. protected $header_logo_width = 30;
  549. /**
  550. * @var String to print as title on document header.
  551. * @access protected
  552. */
  553. protected $header_title = '';
  554. /**
  555. * @var String to print on document header.
  556. * @access protected
  557. */
  558. protected $header_string = '';
  559. /**
  560. * @var Default number of columns for html table.
  561. * @access protected
  562. */
  563. protected $default_table_columns = 4;
  564. // variables for html parser
  565. /**
  566. * @var HTML PARSER: array to store current link and rendering styles.
  567. * @access protected
  568. */
  569. protected $HREF = array();
  570. /**
  571. * @var store a list of available fonts on filesystem.
  572. * @access protected
  573. */
  574. protected $fontlist = array();
  575. /**
  576. * @var current foreground color
  577. * @access protected
  578. */
  579. protected $fgcolor;
  580. /**
  581. * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  582. * @access protected
  583. */
  584. protected $listordered = array();
  585. /**
  586. * @var HTML PARSER: array count list items on nested lists.
  587. * @access protected
  588. */
  589. protected $listcount = array();
  590. /**
  591. * @var HTML PARSER: current list nesting level.
  592. * @access protected
  593. */
  594. protected $listnum = 0;
  595. /**
  596. * @var HTML PARSER: indent amount for lists.
  597. * @access protected
  598. */
  599. protected $listindent;
  600. /**
  601. * @var current background color
  602. * @access protected
  603. */
  604. protected $bgcolor;
  605. /**
  606. * @var Store temporary font size in points.
  607. * @access protected
  608. */
  609. protected $tempfontsize = 10;
  610. /**
  611. * @var spacer for LI tags.
  612. * @access protected
  613. */
  614. protected $lispacer = '';
  615. /**
  616. * @var default encoding
  617. * @access protected
  618. * @since 1.53.0.TC010
  619. */
  620. protected $encoding = 'UTF-8';
  621. /**
  622. * @var PHP internal encoding
  623. * @access protected
  624. * @since 1.53.0.TC016
  625. */
  626. protected $internal_encoding;
  627. /**
  628. * @var indicates if the document language is Right-To-Left
  629. * @access protected
  630. * @since 2.0.000
  631. */
  632. protected $rtl = false;
  633. /**
  634. * @var used to force RTL or LTR string inversion
  635. * @access protected
  636. * @since 2.0.000
  637. */
  638. protected $tmprtl = false;
  639. // --- Variables used for document encryption:
  640. /**
  641. * Indicates whether document is protected
  642. * @access protected
  643. * @since 2.0.000 (2008-01-02)
  644. */
  645. protected $encrypted;
  646. /**
  647. * U entry in pdf document
  648. * @access protected
  649. * @since 2.0.000 (2008-01-02)
  650. */
  651. protected $Uvalue;
  652. /**
  653. * O entry in pdf document
  654. * @access protected
  655. * @since 2.0.000 (2008-01-02)
  656. */
  657. protected $Ovalue;
  658. /**
  659. * P entry in pdf document
  660. * @access protected
  661. * @since 2.0.000 (2008-01-02)
  662. */
  663. protected $Pvalue;
  664. /**
  665. * encryption object id
  666. * @access protected
  667. * @since 2.0.000 (2008-01-02)
  668. */
  669. protected $enc_obj_id;
  670. /**
  671. * last RC4 key encrypted (cached for optimisation)
  672. * @access protected
  673. * @since 2.0.000 (2008-01-02)
  674. */
  675. protected $last_rc4_key;
  676. /**
  677. * last RC4 computed key
  678. * @access protected
  679. * @since 2.0.000 (2008-01-02)
  680. */
  681. protected $last_rc4_key_c;
  682. /**
  683. * RC4 padding
  684. * @access protected
  685. */
  686. 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";
  687. /**
  688. * RC4 encryption key
  689. * @access protected
  690. */
  691. protected $encryption_key;
  692. // --- bookmark ---
  693. /**
  694. * Outlines for bookmark
  695. * @access protected
  696. * @since 2.1.002 (2008-02-12)
  697. */
  698. protected $outlines = array();
  699. /**
  700. * Outline root for bookmark
  701. * @access protected
  702. * @since 2.1.002 (2008-02-12)
  703. */
  704. protected $OutlineRoot;
  705. // --- javascript and form ---
  706. /**
  707. * javascript code
  708. * @access protected
  709. * @since 2.1.002 (2008-02-12)
  710. */
  711. protected $javascript = '';
  712. /**
  713. * javascript counter
  714. * @access protected
  715. * @since 2.1.002 (2008-02-12)
  716. */
  717. protected $n_js;
  718. /**
  719. * line trough state
  720. * @access protected
  721. * @since 2.8.000 (2008-03-19)
  722. */
  723. protected $linethrough;
  724. // --- Variables used for User's Rights ---
  725. // See PDF reference chapter 8.7 Digital Signatures
  726. /**
  727. * If true enables user's rights on PDF reader
  728. * @access protected
  729. * @since 2.9.000 (2008-03-26)
  730. */
  731. protected $ur;
  732. /**
  733. * Names specifying additional document-wide usage rights for the document.
  734. * @access protected
  735. * @since 2.9.000 (2008-03-26)
  736. */
  737. protected $ur_document;
  738. /**
  739. * Names specifying additional annotation-related usage rights for the document.
  740. * @access protected
  741. * @since 2.9.000 (2008-03-26)
  742. */
  743. protected $ur_annots;
  744. /**
  745. * Names specifying additional form-field-related usage rights for the document.
  746. * @access protected
  747. * @since 2.9.000 (2008-03-26)
  748. */
  749. protected $ur_form;
  750. /**
  751. * Names specifying additional signature-related usage rights for the document.
  752. * @access protected
  753. * @since 2.9.000 (2008-03-26)
  754. */
  755. protected $ur_signature;
  756. /**
  757. * Dot Per Inch Document Resolution (do not change)
  758. * @access protected
  759. * @since 3.0.000 (2008-03-27)
  760. */
  761. protected $dpi = 72;
  762. /**
  763. * Array of page numbers were a new page group was started
  764. * @access protected
  765. * @since 3.0.000 (2008-03-27)
  766. */
  767. protected $newpagegroup = array();
  768. /**
  769. * Contains the number of pages of the groups
  770. * @access protected
  771. * @since 3.0.000 (2008-03-27)
  772. */
  773. protected $pagegroups;
  774. /**
  775. * Contains the alias of the current page group
  776. * @access protected
  777. * @since 3.0.000 (2008-03-27)
  778. */
  779. protected $currpagegroup;
  780. /**
  781. * Restrict the rendering of some elements to screen or printout.
  782. * @access protected
  783. * @since 3.0.000 (2008-03-27)
  784. */
  785. protected $visibility = 'all';
  786. /**
  787. * Print visibility.
  788. * @access protected
  789. * @since 3.0.000 (2008-03-27)
  790. */
  791. protected $n_ocg_print;
  792. /**
  793. * View visibility.
  794. * @access protected
  795. * @since 3.0.000 (2008-03-27)
  796. */
  797. protected $n_ocg_view;
  798. /**
  799. * Array of transparency objects and parameters.
  800. * @access protected
  801. * @since 3.0.000 (2008-03-27)
  802. */
  803. protected $extgstates;
  804. /**
  805. * Set the default JPEG compression quality (1-100)
  806. * @access protected
  807. * @since 3.0.000 (2008-03-27)
  808. */
  809. protected $jpeg_quality;
  810. /**
  811. * Default cell height ratio.
  812. * @access protected
  813. * @since 3.0.014 (2008-05-23)
  814. */
  815. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  816. /**
  817. * PDF viewer preferences.
  818. * @access protected
  819. * @since 3.1.000 (2008-06-09)
  820. */
  821. protected $viewer_preferences;
  822. /**
  823. * A name object specifying how the document should be displayed when opened.
  824. * @access protected
  825. * @since 3.1.000 (2008-06-09)
  826. */
  827. protected $PageMode;
  828. /**
  829. * Array for storing gradient information.
  830. * @access protected
  831. * @since 3.1.000 (2008-06-09)
  832. */
  833. protected $gradients = array();
  834. /**
  835. * Array used to store positions inside the pages buffer.
  836. * keys are the page numbers
  837. * @access protected
  838. * @since 3.2.000 (2008-06-26)
  839. */
  840. protected $intmrk = array();
  841. /**
  842. * Array used to store content positions inside the pages buffer.
  843. * keys are the page numbers
  844. * @access protected
  845. * @since 4.6.021 (2009-07-20)
  846. */
  847. protected $cntmrk = array();
  848. /**
  849. * Array used to store footer positions of each page.
  850. * @access protected
  851. * @since 3.2.000 (2008-07-01)
  852. */
  853. protected $footerpos = array();
  854. /**
  855. * Array used to store footer length of each page.
  856. * @access protected
  857. * @since 4.0.014 (2008-07-29)
  858. */
  859. protected $footerlen = array();
  860. /**
  861. * True if a newline is created.
  862. * @access protected
  863. * @since 3.2.000 (2008-07-01)
  864. */
  865. protected $newline = true;
  866. /**
  867. * End position of the latest inserted line
  868. * @access protected
  869. * @since 3.2.000 (2008-07-01)
  870. */
  871. protected $endlinex = 0;
  872. /**
  873. * PDF string for last line width
  874. * @access protected
  875. * @since 4.0.006 (2008-07-16)
  876. */
  877. protected $linestyleWidth = '';
  878. /**
  879. * PDF string for last line width
  880. * @access protected
  881. * @since 4.0.006 (2008-07-16)
  882. */
  883. protected $linestyleCap = '0 J';
  884. /**
  885. * PDF string for last line width
  886. * @access protected
  887. * @since 4.0.006 (2008-07-16)
  888. */
  889. protected $linestyleJoin = '0 j';
  890. /**
  891. * PDF string for last line width
  892. * @access protected
  893. * @since 4.0.006 (2008-07-16)
  894. */
  895. protected $linestyleDash = '[] 0 d';
  896. /**
  897. * True if marked-content sequence is open
  898. * @access protected
  899. * @since 4.0.013 (2008-07-28)
  900. */
  901. protected $openMarkedContent = false;
  902. /**
  903. * Count the latest inserted vertical spaces on HTML
  904. * @access protected
  905. * @since 4.0.021 (2008-08-24)
  906. */
  907. protected $htmlvspace = 0;
  908. /**
  909. * Array of Spot colors
  910. * @access protected
  911. * @since 4.0.024 (2008-09-12)
  912. */
  913. protected $spot_colors = array();
  914. /**
  915. * Symbol used for HTML unordered list items
  916. * @access protected
  917. * @since 4.0.028 (2008-09-26)
  918. */
  919. protected $lisymbol = '';
  920. /**
  921. * String used to mark the beginning and end of EPS image blocks
  922. * @access protected
  923. * @since 4.1.000 (2008-10-18)
  924. */
  925. protected $epsmarker = 'x#!#EPS#!#x';
  926. /**
  927. * Array of transformation matrix
  928. * @access protected
  929. * @since 4.2.000 (2008-10-29)
  930. */
  931. protected $transfmatrix = array();
  932. /**
  933. * Current key for transformation matrix
  934. * @access protected
  935. * @since 4.8.005 (2009-09-17)
  936. */
  937. protected $transfmatrix_key = 0;
  938. /**
  939. * Booklet mode for double-sided pages
  940. * @access protected
  941. * @since 4.2.000 (2008-10-29)
  942. */
  943. protected $booklet = false;
  944. /**
  945. * Epsilon value used for float calculations
  946. * @access protected
  947. * @since 4.2.000 (2008-10-29)
  948. */
  949. protected $feps = 0.005;
  950. /**
  951. * Array used for custom vertical spaces for HTML tags
  952. * @access protected
  953. * @since 4.2.001 (2008-10-30)
  954. */
  955. protected $tagvspaces = array();
  956. /**
  957. * @var HTML PARSER: custom indent amount for lists.
  958. * Negative value means disabled.
  959. * @access protected
  960. * @since 4.2.007 (2008-11-12)
  961. */
  962. protected $customlistindent = - 1;
  963. /**
  964. * @var if true keeps the border open for the cell sides that cross the page.
  965. * @access protected
  966. * @since 4.2.010 (2008-11-14)
  967. */
  968. protected $opencell = true;
  969. /**
  970. * @var array of files to embedd
  971. * @access protected
  972. * @since 4.4.000 (2008-12-07)
  973. */
  974. protected $embeddedfiles = array();
  975. /**
  976. * @var boolean true when inside html pre tag
  977. * @access protected
  978. * @since 4.4.001 (2008-12-08)
  979. */
  980. protected $premode = false;
  981. /**
  982. * Array used to store positions of graphics transformation blocks inside the page buffer.
  983. * keys are the page numbers
  984. * @access protected
  985. * @since 4.4.002 (2008-12-09)
  986. */
  987. protected $transfmrk = array();
  988. /**
  989. * Default color for html links
  990. * @access protected
  991. * @since 4.4.003 (2008-12-09)
  992. */
  993. protected $htmlLinkColorArray = array(0, 0, 255);
  994. /**
  995. * Default font style to add to html links
  996. * @access protected
  997. * @since 4.4.003 (2008-12-09)
  998. */
  999. protected $htmlLinkFontStyle = 'U';
  1000. /**
  1001. * Counts the number of pages.
  1002. * @access protected
  1003. * @since 4.5.000 (2008-12-31)
  1004. */
  1005. protected $numpages = 0;
  1006. /**
  1007. * Array containing page lengths in bytes.
  1008. * @access protected
  1009. * @since 4.5.000 (2008-12-31)
  1010. */
  1011. protected $pagelen = array();
  1012. /**
  1013. * Counts the number of pages.
  1014. * @access protected
  1015. * @since 4.5.000 (2008-12-31)
  1016. */
  1017. protected $numimages = 0;
  1018. /**
  1019. * Store the image keys.
  1020. * @access protected
  1021. * @since 4.5.000 (2008-12-31)
  1022. */
  1023. protected $imagekeys = array();
  1024. /**
  1025. * Length of the buffer in bytes.
  1026. * @access protected
  1027. * @since 4.5.000 (2008-12-31)
  1028. */
  1029. protected $bufferlen = 0;
  1030. /**
  1031. * If true enables disk caching.
  1032. * @access protected
  1033. * @since 4.5.000 (2008-12-31)
  1034. */
  1035. protected $diskcache = false;
  1036. /**
  1037. * Counts the number of fonts.
  1038. * @access protected
  1039. * @since 4.5.000 (2009-01-02)
  1040. */
  1041. protected $numfonts = 0;
  1042. /**
  1043. * Store the font keys.
  1044. * @access protected
  1045. * @since 4.5.000 (2009-01-02)
  1046. */
  1047. protected $fontkeys = array();
  1048. /**
  1049. * Store the font object IDs.
  1050. * @access protected
  1051. * @since 4.8.001 (2009-09-09)
  1052. */
  1053. protected $font_obj_ids = array();
  1054. /**
  1055. * Store the fage status (true when opened, false when closed).
  1056. * @access protected
  1057. * @since 4.5.000 (2009-01-02)
  1058. */
  1059. protected $pageopen = array();
  1060. /**
  1061. * Default monospaced font
  1062. * @access protected
  1063. * @since 4.5.025 (2009-03-10)
  1064. */
  1065. protected $default_monospaced_font = 'courier';
  1066. /**
  1067. * Used to store a cloned copy of the current class object
  1068. * @access protected
  1069. * @since 4.5.029 (2009-03-19)
  1070. */
  1071. protected $objcopy;
  1072. /**
  1073. * Array used to store the lengths of cache files
  1074. * @access protected
  1075. * @since 4.5.029 (2009-03-19)
  1076. */
  1077. protected $cache_file_length = array();
  1078. /**
  1079. * Table header content to be repeated on each new page
  1080. * @access protected
  1081. * @since 4.5.030 (2009-03-20)
  1082. */
  1083. protected $thead = '';
  1084. /**
  1085. * Margins used for table header.
  1086. * @access protected
  1087. * @since 4.5.030 (2009-03-20)
  1088. */
  1089. protected $theadMargins = array();
  1090. /**
  1091. * Cache array for UTF8StringToArray() method.
  1092. * @access protected
  1093. * @since 4.5.037 (2009-04-07)
  1094. */
  1095. protected $cache_UTF8StringToArray = array();
  1096. /**
  1097. * Maximum size of cache array used for UTF8StringToArray() method.
  1098. * @access protected
  1099. * @since 4.5.037 (2009-04-07)
  1100. */
  1101. protected $cache_maxsize_UTF8StringToArray = 8;
  1102. /**
  1103. * Current size of cache array used for UTF8StringToArray() method.
  1104. * @access protected
  1105. * @since 4.5.037 (2009-04-07)
  1106. */
  1107. protected $cache_size_UTF8StringToArray = 0;
  1108. /**
  1109. * If true enables document signing
  1110. * @access protected
  1111. * @since 4.6.005 (2009-04-24)
  1112. */
  1113. protected $sign = false;
  1114. /**
  1115. * Signature data
  1116. * @access protected
  1117. * @since 4.6.005 (2009-04-24)
  1118. */
  1119. protected $signature_data = array();
  1120. /**
  1121. * Signature max length
  1122. * @access protected
  1123. * @since 4.6.005 (2009-04-24)
  1124. */
  1125. protected $signature_max_length = 11742;
  1126. /**
  1127. * Regular expression used to find blank characters used for word-wrapping.
  1128. * @access protected
  1129. * @since 4.6.006 (2009-04-28)
  1130. */
  1131. protected $re_spaces = '/[\s]/';
  1132. /**
  1133. * Signature object ID
  1134. * @access protected
  1135. * @since 4.6.022 (2009-06-23)
  1136. */
  1137. protected $sig_obj_id = 0;
  1138. /**
  1139. * ByteRange placemark used during signature process.
  1140. * @access protected
  1141. * @since 4.6.028 (2009-08-25)
  1142. */
  1143. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1144. /**
  1145. * Placemark used during signature process.
  1146. * @access protected
  1147. * @since 4.6.028 (2009-08-25)
  1148. */
  1149. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1150. /**
  1151. * ID of page objects
  1152. * @access protected
  1153. * @since 4.7.000 (2009-08-29)
  1154. */
  1155. protected $page_obj_id = array();
  1156. /**
  1157. * Start ID for embedded file objects
  1158. * @access protected
  1159. * @since 4.7.000 (2009-08-29)
  1160. */
  1161. protected $embedded_start_obj_id = 100000;
  1162. /**
  1163. * Start ID for annotation objects
  1164. * @access protected
  1165. * @since 4.7.000 (2009-08-29)
  1166. */
  1167. protected $annots_start_obj_id = 200000;
  1168. /**
  1169. * Max ID of annotation object
  1170. * @access protected
  1171. * @since 4.7.000 (2009-08-29)
  1172. */
  1173. protected $annot_obj_id = 200000;
  1174. /**
  1175. * Current ID of annotation object
  1176. * @access protected
  1177. * @since 4.8.003 (2009-09-15)
  1178. */
  1179. protected $curr_annot_obj_id = 200000;
  1180. /**
  1181. * List of form annotations IDs
  1182. * @access protected
  1183. * @since 4.8.000 (2009-09-07)
  1184. */
  1185. protected $form_obj_id = array();
  1186. /**
  1187. * 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.
  1188. * @access protected
  1189. * @since 4.8.000 (2009-09-07)
  1190. */
  1191. protected $default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid',
  1192. '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. * True when we are printing the thead section on a new page
  1273. * @access protected
  1274. * @since 4.8.027 (2010-01-25)
  1275. */
  1276. protected $inthead = false;
  1277. //------------------------------------------------------------
  1278. // METHODS
  1279. //------------------------------------------------------------
  1280. /**
  1281. * This is the class constructor.
  1282. * It allows to set up the page format, the orientation and
  1283. * the measure unit used in all the methods (except for the font sizes).
  1284. * @since 1.0
  1285. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  1286. * @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.
  1287. * @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>
  1288. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1289. * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1290. * @param String $encoding charset encoding; default is UTF-8
  1291. * @access public
  1292. */
  1293. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false)
  1294. {
  1295. /* Set internal character encoding to ASCII */
  1296. if (function_exists('mb_internal_encoding') and mb_internal_encoding())
  1297. {
  1298. $this->internal_encoding = mb_internal_encoding();
  1299. mb_internal_encoding('ASCII');
  1300. }
  1301. // set disk caching
  1302. $this->diskcache = $diskcache ? true : false;
  1303. // set language direction
  1304. $this->rtl = false;
  1305. $this->tmprtl = false;
  1306. //Some checks
  1307. $this->_dochecks();
  1308. //Initialization of properties
  1309. $this->isunicode = $unicode;
  1310. $this->page = 0;
  1311. $this->transfmrk[0] = array();
  1312. $this->pagedim = array();
  1313. $this->n = 2;
  1314. $this->buffer = '';
  1315. $this->pages = array();
  1316. $this->state = 0;
  1317. $this->fonts = array();
  1318. $this->FontFiles = array();
  1319. $this->diffs = array();
  1320. $this->images = array();
  1321. $this->links = array();
  1322. $this->gradients = array();
  1323. $this->InFooter = false;
  1324. $this->lasth = 0;
  1325. $this->FontFamily = 'helvetica';
  1326. $this->FontStyle = '';
  1327. $this->FontSizePt = 12;
  1328. $this->underline = false;
  1329. $this->linethrough = false;
  1330. $this->DrawColor = '0 G';
  1331. $this->FillColor = '0 g';
  1332. $this->TextColor = '0 g';
  1333. $this->ColorFlag = false;
  1334. // encryption values
  1335. $this->encrypted = false;
  1336. $this->last_rc4_key = '';
  1337. $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";
  1338. //Standard Unicode fonts
  1339. $this->CoreFonts = array('courier' => 'Courier', 'courierB' => 'Courier-Bold',
  1340. 'courierI' => 'Courier-Oblique', 'courierBI' => 'Courier-BoldOblique', 'helvetica' => 'Helvetica',
  1341. 'helveticaB' => 'Helvetica-Bold', 'helveticaI' => 'Helvetica-Oblique',
  1342. 'helveticaBI' => 'Helvetica-BoldOblique', 'times' => 'Times-Roman', 'timesB' => 'Times-Bold',
  1343. 'timesI' => 'Times-Italic', 'timesBI' => 'Times-BoldItalic', 'symbol' => 'Symbol',
  1344. 'zapfdingbats' => 'ZapfDingbats');
  1345. //Set scale factor
  1346. $this->setPageUnit($unit);
  1347. // set page format and orientation
  1348. $this->setPageFormat($format, $orientation);
  1349. //Page margins (1 cm)
  1350. $margin = 28.35 / $this->k;
  1351. $this->SetMargins($margin, $margin);
  1352. //Interior cell margin
  1353. $this->cMargin = $margin / 10;
  1354. //Line width (0.2 mm)
  1355. $this->LineWidth = 0.57 / $this->k;
  1356. $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
  1357. $this->linestyleCap = '0 J';
  1358. $this->linestyleJoin = '0 j';
  1359. $this->linestyleDash = '[] 0 d';
  1360. //Automatic page break
  1361. $this->SetAutoPageBreak(true, (2 * $margin));
  1362. //Full width display mode
  1363. $this->SetDisplayMode('fullwidth');
  1364. //Compression
  1365. $this->SetCompression(true);
  1366. //Set default PDF version number
  1367. $this->PDFVersion = '1.7';
  1368. $this->encoding = $encoding;
  1369. $this->HREF = array();
  1370. $this->getFontsList();
  1371. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1372. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1373. $this->extgstates = array();
  1374. // user's rights
  1375. $this->sign = false;
  1376. $this->ur = false;
  1377. $this->ur_document = '/FullSave';
  1378. $this->ur_annots = '/Create/Delete/Modify/Copy/Import/Export';
  1379. $this->ur_form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1380. $this->ur_signature = '/Modify';
  1381. // set default JPEG quality
  1382. $this->jpeg_quality = 75;
  1383. // initialize some settings
  1384. $this->utf8Bidi(array(''), '');
  1385. // set default font
  1386. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1387. // check if PCRE Unicode support is enabled
  1388. if ($this->isunicode and (@preg_match('/\pL/u', 'a') == 1))
  1389. {
  1390. // PCRE unicode support is turned ON
  1391. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1392. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1393. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1394. //$this->re_spaces = '/[\s\p{Z}\p{Lo}]/u';
  1395. $this->re_spaces = '/[\s\p{Z}]/u';
  1396. }
  1397. else
  1398. {
  1399. // PCRE unicode support is turned OFF
  1400. $this->re_spaces = '/[\s]/';
  1401. }
  1402. $this->annot_obj_id = $this->annots_start_obj_id;
  1403. $this->curr_annot_obj_id = $this->annots_start_obj_id;
  1404. $this->apxo_obj_id = $this->apxo_start_obj_id;
  1405. $this->js_obj_id = $this->js_start_obj_id;
  1406. $this->default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid',
  1407. 'fillColor' => array(255, 255, 255), 'strokeColor' => array(128, 128, 128));
  1408. }
  1409. /**
  1410. * Default destructor.
  1411. * @access public
  1412. * @since 1.53.0.TC016
  1413. */
  1414. public function __destruct()
  1415. {
  1416. // restore internal encoding
  1417. if (isset($this->internal_encoding) and ! empty($this->internal_encoding))
  1418. {
  1419. mb_internal_encoding($this->internal_encoding);
  1420. }
  1421. // unset all class variables
  1422. $this->_destroy(true);
  1423. }
  1424. /**
  1425. * Set the units of measure for the document.
  1426. * @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.
  1427. * @access public
  1428. * @since 3.0.015 (2008-06-06)
  1429. */
  1430. public function setPageUnit($unit)
  1431. {
  1432. //Set scale factor
  1433. switch (strtolower($unit))
  1434. {
  1435. // points
  1436. case 'px' :
  1437. case 'pt' :
  1438. {
  1439. $this->k = 1;
  1440. break;
  1441. }
  1442. // millimeters
  1443. case 'mm' :
  1444. {
  1445. $this->k = $this->dpi / 25.4;
  1446. break;
  1447. }
  1448. // centimeters
  1449. case 'cm' :
  1450. {
  1451. $this->k = $this->dpi / 2.54;
  1452. break;
  1453. }
  1454. // inches
  1455. case 'in' :
  1456. {
  1457. $this->k = $this->dpi;
  1458. break;
  1459. }
  1460. // unsupported unit
  1461. default :
  1462. {
  1463. $this->Error('Incorrect unit: ' . $unit);
  1464. break;
  1465. }
  1466. }
  1467. if (isset($this->CurOrientation))
  1468. {
  1469. $this->setPageOrientation($this->CurOrientation);
  1470. }
  1471. }
  1472. /**
  1473. * Set the page format
  1474. * @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>
  1475. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1476. * @access public
  1477. * @since 3.0.015 (2008-06-06)
  1478. */
  1479. public function setPageFormat($format, $orientation = 'P')
  1480. {
  1481. //Page format
  1482. if (is_string($format))
  1483. {
  1484. // Page formats (45 standard ISO paper formats and 4 american common formats).
  1485. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  1486. switch (strtoupper($format))
  1487. {
  1488. case '4A0' :
  1489. {
  1490. $format = array(4767.87, 6740.79);
  1491. break;
  1492. }
  1493. case '2A0' :
  1494. {
  1495. $format = array(3370.39, 4767.87);
  1496. break;
  1497. }
  1498. case 'A0' :
  1499. {
  1500. $format = array(2383.94, 3370.39);
  1501. break;
  1502. }
  1503. case 'A1' :
  1504. {
  1505. $format = array(1683.78, 2383.94);
  1506. break;
  1507. }
  1508. case 'A2' :
  1509. {
  1510. $format = array(1190.55, 1683.78);
  1511. break;
  1512. }
  1513. case 'A3' :
  1514. {
  1515. $format = array(841.89, 1190.55);
  1516. break;
  1517. }
  1518. case 'A4' :
  1519. default :
  1520. {
  1521. $format = array(595.28, 841.89);
  1522. break;
  1523. }
  1524. case 'A5' :
  1525. {
  1526. $format = array(419.53, 595.28);
  1527. break;
  1528. }
  1529. case 'A6' :
  1530. {
  1531. $format = array(297.64, 419.53);
  1532. break;
  1533. }
  1534. case 'A7' :
  1535. {
  1536. $format = array(209.76, 297.64);
  1537. break;
  1538. }
  1539. case 'A8' :
  1540. {
  1541. $format = array(147.40, 209.76);
  1542. break;
  1543. }
  1544. case 'A9' :
  1545. {
  1546. $format = array(104.88, 147.40);
  1547. break;
  1548. }
  1549. case 'A10' :
  1550. {
  1551. $format = array(73.70, 104.88);
  1552. break;
  1553. }
  1554. case 'B0' :
  1555. {
  1556. $format = array(2834.65, 4008.19);
  1557. break;
  1558. }
  1559. case 'B1' :
  1560. {
  1561. $format = array(2004.09, 2834.65);
  1562. break;
  1563. }
  1564. case 'B2' :
  1565. {
  1566. $format = array(1417.32, 2004.09);
  1567. break;
  1568. }
  1569. case 'B3' :
  1570. {
  1571. $format = array(1000.63, 1417.32);
  1572. break;
  1573. }
  1574. case 'B4' :
  1575. {
  1576. $format = array(708.66, 1000.63);
  1577. break;
  1578. }
  1579. case 'B5' :
  1580. {
  1581. $format = array(498.90, 708.66);
  1582. break;
  1583. }
  1584. case 'B6' :
  1585. {
  1586. $format = array(354.33, 498.90);
  1587. break;
  1588. }
  1589. case 'B7' :
  1590. {
  1591. $format = array(249.45, 354.33);
  1592. break;
  1593. }
  1594. case 'B8' :
  1595. {
  1596. $format = array(175.75, 249.45);
  1597. break;
  1598. }
  1599. case 'B9' :
  1600. {
  1601. $format = array(124.72, 175.75);
  1602. break;
  1603. }
  1604. case 'B10' :
  1605. {
  1606. $format = array(87.87, 124.72);
  1607. break;
  1608. }
  1609. case 'C0' :
  1610. {
  1611. $format = array(2599.37, 3676.54);
  1612. break;
  1613. }
  1614. case 'C1' :
  1615. {
  1616. $format = array(1836.85, 2599.37);
  1617. break;
  1618. }
  1619. case 'C2' :
  1620. {
  1621. $format = array(1298.27, 1836.85);
  1622. break;
  1623. }
  1624. case 'C3' :
  1625. {
  1626. $format = array(918.43, 1298.27);
  1627. break;
  1628. }
  1629. case 'C4' :
  1630. {
  1631. $format = array(649.13, 918.43);
  1632. break;
  1633. }
  1634. case 'C5' :
  1635. {
  1636. $format = array(459.21, 649.13);
  1637. break;
  1638. }
  1639. case 'C6' :
  1640. {
  1641. $format = array(323.15, 459.21);
  1642. break;
  1643. }
  1644. case 'C7' :
  1645. {
  1646. $format = array(229.61, 323.15);
  1647. break;
  1648. }
  1649. case 'C8' :
  1650. {
  1651. $format = array(161.57, 229.61);
  1652. break;
  1653. }
  1654. case 'C9' :
  1655. {
  1656. $format = array(113.39, 161.57);
  1657. break;
  1658. }
  1659. case 'C10' :
  1660. {
  1661. $format = array(79.37, 113.39);
  1662. break;
  1663. }
  1664. case 'RA0' :
  1665. {
  1666. $format = array(2437.80, 3458.27);
  1667. break;
  1668. }
  1669. case 'RA1' :
  1670. {
  1671. $format = array(1729.13, 2437.80);
  1672. break;
  1673. }
  1674. case 'RA2' :
  1675. {
  1676. $format = array(1218.90, 1729.13);
  1677. break;
  1678. }
  1679. case 'RA3' :
  1680. {
  1681. $format = array(864.57, 1218.90);
  1682. break;
  1683. }
  1684. case 'RA4' :
  1685. {
  1686. $format = array(609.45, 864.57);
  1687. break;
  1688. }
  1689. case 'SRA0' :
  1690. {
  1691. $format = array(2551.18, 3628.35);
  1692. break;
  1693. }
  1694. case 'SRA1' :
  1695. {
  1696. $format = array(1814.17, 2551.18);
  1697. break;
  1698. }
  1699. case 'SRA2' :
  1700. {
  1701. $format = array(1275.59, 1814.17);
  1702. break;
  1703. }
  1704. case 'SRA3' :
  1705. {
  1706. $format = array(907.09, 1275.59);
  1707. break;
  1708. }
  1709. case 'SRA4' :
  1710. {
  1711. $format = array(637.80, 907.09);
  1712. break;
  1713. }
  1714. case 'LETTER' :
  1715. {
  1716. $format = array(612.00, 792.00);
  1717. break;
  1718. }
  1719. case 'LEGAL' :
  1720. {
  1721. $format = array(612.00, 1008.00);
  1722. break;
  1723. }
  1724. case 'EXECUTIVE' :
  1725. {
  1726. $format = array(521.86, 756.00);
  1727. break;
  1728. }
  1729. case 'FOLIO' :
  1730. {
  1731. $format = array(612.00, 936.00);
  1732. break;
  1733. }
  1734. }
  1735. $this->fwPt = $format[0];
  1736. $this->fhPt = $format[1];
  1737. }
  1738. else
  1739. {
  1740. $this->fwPt = $format[0] * $this->k;
  1741. $this->fhPt = $format[1] * $this->k;
  1742. }
  1743. $this->setPageOrientation($orientation);
  1744. }
  1745. /**
  1746. * Set page orientation.
  1747. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1748. * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1749. * @param float $bottommargin bottom margin of the page.
  1750. * @access public
  1751. * @since 3.0.015 (2008-06-06)
  1752. */
  1753. public function setPageOrientation($orientation, $autopagebreak = '', $bottommargin = '')
  1754. {
  1755. $orientation = strtoupper($orientation);
  1756. if (($orientation == 'P') or ($orientation == 'PORTRAIT'))
  1757. {
  1758. $this->CurOrientation = 'P';
  1759. $this->wPt = $this->fwPt;
  1760. $this->hPt = $this->fhPt;
  1761. }
  1762. elseif (($orientation == 'L') or ($orientation == 'LANDSCAPE'))
  1763. {
  1764. $this->CurOrientation = 'L';
  1765. $this->wPt = $this->fhPt;
  1766. $this->hPt = $this->fwPt;
  1767. }
  1768. else
  1769. {
  1770. $this->Error('Incorrect orientation: ' . $orientation);
  1771. }
  1772. $this->w = $this->wPt / $this->k;
  1773. $this->h = $this->hPt / $this->k;
  1774. if ($this->empty_string($autopagebreak))
  1775. {
  1776. if (isset($this->AutoPageBreak))
  1777. {
  1778. $autopagebreak = $this->AutoPageBreak;
  1779. }
  1780. else
  1781. {
  1782. $autopagebreak = true;
  1783. }
  1784. }
  1785. if ($this->empty_string($bottommargin))
  1786. {
  1787. if (isset($this->bMargin))
  1788. {
  1789. $bottommargin = $this->bMargin;
  1790. }
  1791. else
  1792. {
  1793. // default value = 2 cm
  1794. $bottommargin = 2 * 28.35 / $this->k;
  1795. }
  1796. }
  1797. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  1798. // store page dimensions
  1799. $this->pagedim[$this->page] = array('w' => $this->wPt, 'h' => $this->hPt, 'wk' => $this->w,
  1800. 'hk' => $this->h, 'tm' => $this->tMargin, 'bm' => $bottommargin, 'lm' => $this->lMargin,
  1801. 'rm' => $this->rMargin, 'pb' => $autopagebreak, 'or' => $this->CurOrientation,
  1802. 'olm' => $this->original_lMargin, 'orm' => $this->original_rMargin);
  1803. }
  1804. /**
  1805. * Set regular expression to detect withespaces or word separators.
  1806. * @param string $re regular expression (leave empty for default).
  1807. * @access public
  1808. * @since 4.6.016 (2009-06-15)
  1809. */
  1810. public function setSpacesRE($re = '/[\s]/')
  1811. {
  1812. // if PCRE unicode support is turned ON:
  1813. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1814. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1815. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1816. $this->re_spaces = $re;
  1817. }
  1818. /**
  1819. * Enable or disable Right-To-Left language mode
  1820. * @param Boolean $enable if true enable Right-To-Left language mode.
  1821. * @param Boolean $resetx if true reset the X position on direction change.
  1822. * @access public
  1823. * @since 2.0.000 (2008-01-03)
  1824. */
  1825. public function setRTL($enable, $resetx = true)
  1826. {
  1827. $enable = $enable ? true : false;
  1828. $resetx = ($resetx and ($enable != $this->rtl));
  1829. $this->rtl = $enable;
  1830. $this->tmprtl = false;
  1831. if ($resetx)
  1832. {
  1833. $this->Ln(0);
  1834. }
  1835. }
  1836. /**
  1837. * Return the RTL status
  1838. * @return boolean
  1839. * @access public
  1840. * @since 4.0.012 (2008-07-24)
  1841. */
  1842. public function getRTL()
  1843. {
  1844. return $this->rtl;
  1845. }
  1846. /**
  1847. * Force temporary RTL language direction
  1848. * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  1849. * @access public
  1850. * @since 2.1.000 (2008-01-09)
  1851. */
  1852. public function setTempRTL($mode)
  1853. {
  1854. $newmode = false;
  1855. switch ($mode)
  1856. {
  1857. case 'ltr' :
  1858. case 'LTR' :
  1859. case 'L' :
  1860. {
  1861. if ($this->rtl)
  1862. {
  1863. $newmode = 'L';
  1864. }
  1865. break;
  1866. }
  1867. case 'rtl' :
  1868. case 'RTL' :
  1869. case 'R' :
  1870. {
  1871. if (! $this->rtl)
  1872. {
  1873. $newmode = 'R';
  1874. }
  1875. break;
  1876. }
  1877. case false :
  1878. default :
  1879. {
  1880. $newmode = false;
  1881. break;
  1882. }
  1883. }
  1884. $this->tmprtl = $newmode;
  1885. }
  1886. /**
  1887. * Return the current temporary RTL status
  1888. * @return boolean
  1889. * @access public
  1890. * @since 4.8.014 (2009-11-04)
  1891. */
  1892. public function isRTLTextDir()
  1893. {
  1894. return ($this->rtl or ($this->tmprtl == 'R'));
  1895. }
  1896. /**
  1897. * Set the last cell height.
  1898. * @param float $h cell height.
  1899. * @author Nicola Asuni
  1900. * @access public
  1901. * @since 1.53.0.TC034
  1902. */
  1903. public function setLastH($h)
  1904. {
  1905. $this->lasth = $h;
  1906. }
  1907. /**
  1908. * Get the last cell height.
  1909. * @return last cell height
  1910. * @access public
  1911. * @since 4.0.017 (2008-08-05)
  1912. */
  1913. public function getLastH()
  1914. {
  1915. return $this->lasth;
  1916. }
  1917. /**
  1918. * Set the adjusting factor to convert pixels to user units.
  1919. * @param float $scale adjusting factor to convert pixels to user units.
  1920. * @author Nicola Asuni
  1921. * @access public
  1922. * @since 1.5.2
  1923. */
  1924. public function setImageScale($scale)
  1925. {
  1926. $this->imgscale = $scale;
  1927. }
  1928. /**
  1929. * Returns the adjusting factor to convert pixels to user units.
  1930. * @return float adjusting factor to convert pixels to user units.
  1931. * @author Nicola Asuni
  1932. * @access public
  1933. * @since 1.5.2
  1934. */
  1935. public function getImageScale()
  1936. {
  1937. return $this->imgscale;
  1938. }
  1939. /**
  1940. * Returns an array of page dimensions:
  1941. * <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>
  1942. * @param int $pagenum page number (empty = current page)
  1943. * @return array of page dimensions.
  1944. * @author Nicola Asuni
  1945. * @access public
  1946. * @since 4.5.027 (2009-03-16)
  1947. */
  1948. public function getPageDimensions($pagenum = '')
  1949. {
  1950. if (empty($pagenum))
  1951. {
  1952. $pagenum = $this->page;
  1953. }
  1954. return $this->pagedim[$pagenum];
  1955. }
  1956. /**
  1957. * Returns the page width in units.
  1958. * @param int $pagenum page number (empty = current page)
  1959. * @return int page width.
  1960. * @author Nicola Asuni
  1961. * @access public
  1962. * @since 1.5.2
  1963. * @see getPageDimensions()
  1964. */
  1965. public function getPageWidth($pagenum = '')
  1966. {
  1967. if (empty($pagenum))
  1968. {
  1969. return $this->w;
  1970. }
  1971. return $this->pagedim[$pagenum]['w'];
  1972. }
  1973. /**
  1974. * Returns the page height in units.
  1975. * @param int $pagenum page number (empty = current page)
  1976. * @return int page height.
  1977. * @author Nicola Asuni
  1978. * @access public
  1979. * @since 1.5.2
  1980. * @see getPageDimensions()
  1981. */
  1982. public function getPageHeight($pagenum = '')
  1983. {
  1984. if (empty($pagenum))
  1985. {
  1986. return $this->h;
  1987. }
  1988. return $this->pagedim[$pagenum]['h'];
  1989. }
  1990. /**
  1991. * Returns the page break margin.
  1992. * @param int $pagenum page number (empty = current page)
  1993. * @return int page break margin.
  1994. * @author Nicola Asuni
  1995. * @access public
  1996. * @since 1.5.2
  1997. * @see getPageDimensions()
  1998. */
  1999. public function getBreakMargin($pagenum = '')
  2000. {
  2001. if (empty($pagenum))
  2002. {
  2003. return $this->bMargin;
  2004. }
  2005. return $this->pagedim[$pagenum]['bm'];
  2006. }
  2007. /**
  2008. * Returns the scale factor (number of points in user unit).
  2009. * @return int scale factor.
  2010. * @author Nicola Asuni
  2011. * @access public
  2012. * @since 1.5.2
  2013. */
  2014. public function getScaleFactor()
  2015. {
  2016. return $this->k;
  2017. }
  2018. /**
  2019. * Defines the left, top and right margins.
  2020. * @param float $left Left margin.
  2021. * @param float $top Top margin.
  2022. * @param float $right Right margin. Default value is the left one.
  2023. * @param boolean $keepmargins if true overwrites the default page margins
  2024. * @access public
  2025. * @since 1.0
  2026. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2027. */
  2028. public function SetMargins($left, $top, $right = -1, $keepmargins = false)
  2029. {
  2030. //Set left, top and right margins
  2031. $this->lMargin = $left;
  2032. $this->tMargin = $top;
  2033. if ($right == - 1)
  2034. {
  2035. $right = $left;
  2036. }
  2037. $this->rMargin = $right;
  2038. if ($keepmargins)
  2039. {
  2040. // overwrite original values
  2041. $this->original_lMargin = $this->lMargin;
  2042. $this->original_rMargin = $this->rMargin;
  2043. }
  2044. }
  2045. /**
  2046. * 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.
  2047. * @param float $margin The margin.
  2048. * @access public
  2049. * @since 1.4
  2050. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2051. */
  2052. public function SetLeftMargin($margin)
  2053. {
  2054. //Set left margin
  2055. $this->lMargin = $margin;
  2056. if (($this->page > 0) and ($this->x < $margin))
  2057. {
  2058. $this->x = $margin;
  2059. }
  2060. }
  2061. /**
  2062. * Defines the top margin. The method can be called before creating the first page.
  2063. * @param float $margin The margin.
  2064. * @access public
  2065. * @since 1.5
  2066. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2067. */
  2068. public function SetTopMargin($margin)
  2069. {
  2070. //Set top margin
  2071. $this->tMargin = $margin;
  2072. if (($this->page > 0) and ($this->y < $margin))
  2073. {
  2074. $this->y = $margin;
  2075. }
  2076. }
  2077. /**
  2078. * Defines the right margin. The method can be called before creating the first page.
  2079. * @param float $margin The margin.
  2080. * @access public
  2081. * @since 1.5
  2082. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2083. */
  2084. public function SetRightMargin($margin)
  2085. {
  2086. $this->rMargin = $margin;
  2087. if (($this->page > 0) and ($this->x > ($this->w - $margin)))
  2088. {
  2089. $this->x = $this->w - $margin;
  2090. }
  2091. }
  2092. /**
  2093. * Set the internal Cell padding.
  2094. * @param float $pad internal padding.
  2095. * @access public
  2096. * @since 2.1.000 (2008-01-09)
  2097. * @see Cell(), SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2098. */
  2099. public function SetCellPadding($pad)
  2100. {
  2101. $this->cMargin = $pad;
  2102. }
  2103. /**
  2104. * 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.
  2105. * @param boolean $auto Boolean indicating if mode should be on or off.
  2106. * @param float $margin Distance from the bottom of the page.
  2107. * @access public
  2108. * @since 1.0
  2109. * @see Cell(), MultiCell(), AcceptPageBreak()
  2110. */
  2111. public function SetAutoPageBreak($auto, $margin = 0)
  2112. {
  2113. //Set auto page break mode and triggering margin
  2114. $this->AutoPageBreak = $auto;
  2115. $this->bMargin = $margin;
  2116. $this->PageBreakTrigger = $this->h - $margin;
  2117. }
  2118. /**
  2119. * Defines the way the document is to be displayed by the viewer.
  2120. * @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>
  2121. * @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>
  2122. * @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>
  2123. * @access public
  2124. * @since 1.2
  2125. */
  2126. public function SetDisplayMode($zoom, $layout = 'SinglePage', $mode = 'UseNone')
  2127. {
  2128. //Set display mode in viewer
  2129. if (($zoom == 'fullpage') or ($zoom == 'fullwidth') or ($zoom == 'real') or ($zoom == 'default') or (! is_string($zoom)))
  2130. {
  2131. $this->ZoomMode = $zoom;
  2132. }
  2133. else
  2134. {
  2135. $this->Error('Incorrect zoom display mode: ' . $zoom);
  2136. }
  2137. switch ($layout)
  2138. {
  2139. case 'default' :
  2140. case 'single' :
  2141. case 'SinglePage' :
  2142. {
  2143. $this->LayoutMode = 'SinglePage';
  2144. break;
  2145. }
  2146. case 'continuous' :
  2147. case 'OneColumn' :
  2148. {
  2149. $this->LayoutMode = 'OneColumn';
  2150. break;
  2151. }
  2152. case 'two' :
  2153. case 'TwoColumnLeft' :
  2154. {
  2155. $this->LayoutMode = 'TwoColumnLeft';
  2156. break;
  2157. }
  2158. case 'TwoColumnRight' :
  2159. {
  2160. $this->LayoutMode = 'TwoColumnRight';
  2161. break;
  2162. }
  2163. case 'TwoPageLeft' :
  2164. {
  2165. $this->LayoutMode = 'TwoPageLeft';
  2166. break;
  2167. }
  2168. case 'TwoPageRight' :
  2169. {
  2170. $this->LayoutMode = 'TwoPageRight';
  2171. break;
  2172. }
  2173. default :
  2174. {
  2175. $this->LayoutMode = 'SinglePage';
  2176. }
  2177. }
  2178. switch ($mode)
  2179. {
  2180. case 'UseNone' :
  2181. {
  2182. $this->PageMode = 'UseNone';
  2183. break;
  2184. }
  2185. case 'UseOutlines' :
  2186. {
  2187. $this->PageMode = 'UseOutlines';
  2188. break;
  2189. }
  2190. case 'UseThumbs' :
  2191. {
  2192. $this->PageMode = 'UseThumbs';
  2193. break;
  2194. }
  2195. case 'FullScreen' :
  2196. {
  2197. $this->PageMode = 'FullScreen';
  2198. break;
  2199. }
  2200. case 'UseOC' :
  2201. {
  2202. $this->PageMode = 'UseOC';
  2203. break;
  2204. }
  2205. case '' :
  2206. {
  2207. $this->PageMode = 'UseAttachments';
  2208. break;
  2209. }
  2210. default :
  2211. {
  2212. $this->PageMode = 'UseNone';
  2213. }
  2214. }
  2215. }
  2216. /**
  2217. * 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.
  2218. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2219. * @param boolean $compress Boolean indicating if compression must be enabled.
  2220. * @access public
  2221. * @since 1.4
  2222. */
  2223. public function SetCompression($compress)
  2224. {
  2225. //Set page compression
  2226. if (function_exists('gzcompress'))
  2227. {
  2228. $this->compress = $compress;
  2229. }
  2230. else
  2231. {
  2232. $this->compress = false;
  2233. }
  2234. }
  2235. /**
  2236. * Defines the title of the document.
  2237. * @param string $title The title.
  2238. * @access public
  2239. * @since 1.2
  2240. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2241. */
  2242. public function SetTitle($title)
  2243. {
  2244. //Title of document
  2245. $this->title = $title;
  2246. }
  2247. /**
  2248. * Defines the subject of the document.
  2249. * @param string $subject The subject.
  2250. * @access public
  2251. * @since 1.2
  2252. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2253. */
  2254. public function SetSubject($subject)
  2255. {
  2256. //Subject of document
  2257. $this->subject = $subject;
  2258. }
  2259. /**
  2260. * Defines the author of the document.
  2261. * @param string $author The name of the author.
  2262. * @access public
  2263. * @since 1.2
  2264. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2265. */
  2266. public function SetAuthor($author)
  2267. {
  2268. //Author of document
  2269. $this->author = $author;
  2270. }
  2271. /**
  2272. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2273. * @param string $keywords The list of keywords.
  2274. * @access public
  2275. * @since 1.2
  2276. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2277. */
  2278. public function SetKeywords($keywords)
  2279. {
  2280. //Keywords of document
  2281. $this->keywords = $keywords;
  2282. }
  2283. /**
  2284. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2285. * @param string $creator The name of the creator.
  2286. * @access public
  2287. * @since 1.2
  2288. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2289. */
  2290. public function SetCreator($creator)
  2291. {
  2292. //Creator of document
  2293. $this->creator = $creator;
  2294. }
  2295. /**
  2296. * 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.
  2297. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  2298. * @param string $msg The error message
  2299. * @access public
  2300. * @since 1.0
  2301. */
  2302. public function Error($msg)
  2303. {
  2304. // unset all class variables
  2305. $this->_destroy(true);
  2306. // exit program and print error
  2307. die('<strong>TCPDF ERROR: </strong>' . $msg);
  2308. }
  2309. /**
  2310. * This method begins the generation of the PDF document.
  2311. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2312. * Note: no page is created by this method
  2313. * @access public
  2314. * @since 1.0
  2315. * @see AddPage(), Close()
  2316. */
  2317. public function Open()
  2318. {
  2319. //Begin document
  2320. $this->state = 1;
  2321. }
  2322. /**
  2323. * Terminates the PDF document.
  2324. * It is not necessary to call this method explicitly because Output() does it automatically.
  2325. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2326. * @access public
  2327. * @since 1.0
  2328. * @see Open(), Output()
  2329. */
  2330. public function Close()
  2331. {
  2332. if ($this->state == 3)
  2333. {
  2334. return;
  2335. }
  2336. if ($this->page == 0)
  2337. {
  2338. $this->AddPage();
  2339. }
  2340. // close page
  2341. $this->endPage();
  2342. // close document
  2343. $this->_enddoc();
  2344. // unset all class variables (except critical ones)
  2345. $this->_destroy(false);
  2346. }
  2347. /**
  2348. * Move pointer at the specified document page and update page dimensions.
  2349. * @param int $pnum page number
  2350. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2351. * @access public
  2352. * @since 2.1.000 (2008-01-07)
  2353. * @see getPage(), lastpage(), getNumPages()
  2354. */
  2355. public function setPage($pnum, $resetmargins = false)
  2356. {
  2357. if ($pnum == $this->page)
  2358. {
  2359. return;
  2360. }
  2361. if (($pnum > 0) and ($pnum <= $this->numpages))
  2362. {
  2363. $this->state = 2;
  2364. // save current graphic settings
  2365. //$gvars = $this->getGraphicVars();
  2366. $oldpage = $this->page;
  2367. $this->page = $pnum;
  2368. $this->wPt = $this->pagedim[$this->page]['w'];
  2369. $this->hPt = $this->pagedim[$this->page]['h'];
  2370. $this->w = $this->wPt / $this->k;
  2371. $this->h = $this->hPt / $this->k;
  2372. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2373. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2374. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2375. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2376. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2377. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2378. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2379. // restore graphic settings
  2380. //$this->setGraphicVars($gvars);
  2381. if ($resetmargins)
  2382. {
  2383. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2384. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2385. $this->SetY($this->tMargin);
  2386. }
  2387. else
  2388. {
  2389. // account for booklet mode
  2390. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm'])
  2391. {
  2392. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2393. $this->lMargin += $deltam;
  2394. $this->rMargin -= $deltam;
  2395. }
  2396. }
  2397. }
  2398. else
  2399. {
  2400. $this->Error('Wrong page number on setPage() function.');
  2401. }
  2402. }
  2403. /**
  2404. * Reset pointer to the last document page.
  2405. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2406. * @access public
  2407. * @since 2.0.000 (2008-01-04)
  2408. * @see setPage(), getPage(), getNumPages()
  2409. */
  2410. public function lastPage($resetmargins = false)
  2411. {
  2412. $this->setPage($this->getNumPages(), $resetmargins);
  2413. }
  2414. /**
  2415. * Get current document page number.
  2416. * @return int page number
  2417. * @access public
  2418. * @since 2.1.000 (2008-01-07)
  2419. * @see setPage(), lastpage(), getNumPages()
  2420. */
  2421. public function getPage()
  2422. {
  2423. return $this->page;
  2424. }
  2425. /**
  2426. * Get the total number of insered pages.
  2427. * @return int number of pages
  2428. * @access public
  2429. * @since 2.1.000 (2008-01-07)
  2430. * @see setPage(), getPage(), lastpage()
  2431. */
  2432. public function getNumPages()
  2433. {
  2434. return $this->numpages;
  2435. }
  2436. /**
  2437. * 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).
  2438. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2439. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2440. * @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>
  2441. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2442. * @access public
  2443. * @since 1.0
  2444. * @see startPage(), endPage()
  2445. */
  2446. public function AddPage($orientation = '', $format = '', $keepmargins = false)
  2447. {
  2448. if (! isset($this->original_lMargin) or $keepmargins)
  2449. {
  2450. $this->original_lMargin = $this->lMargin;
  2451. }
  2452. if (! isset($this->original_rMargin) or $keepmargins)
  2453. {
  2454. $this->original_rMargin = $this->rMargin;
  2455. }
  2456. // terminate previous page
  2457. $this->endPage();
  2458. // start new page
  2459. $this->startPage($orientation, $format);
  2460. }
  2461. /**
  2462. * Terminate the current page
  2463. * @access protected
  2464. * @since 4.2.010 (2008-11-14)
  2465. * @see startPage(), AddPage()
  2466. */
  2467. protected function endPage()
  2468. {
  2469. // check if page is already closed
  2470. if (($this->page == 0) or ($this->numpages > $this->page) or (! $this->pageopen[$this->page]))
  2471. {
  2472. return;
  2473. }
  2474. $this->InFooter = true;
  2475. // print page footer
  2476. $this->setFooter();
  2477. // close page
  2478. $this->_endpage();
  2479. // mark page as closed
  2480. $this->pageopen[$this->page] = false;
  2481. $this->InFooter = false;
  2482. }
  2483. /**
  2484. * Starts a new page to the document. The page must be closed using the endPage() function.
  2485. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2486. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2487. * @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>
  2488. * @access protected
  2489. * @since 4.2.010 (2008-11-14)
  2490. * @see endPage(), AddPage()
  2491. */
  2492. protected function startPage($orientation = '', $format = '')
  2493. {
  2494. if ($this->numpages > $this->page)
  2495. {
  2496. // this page has been already added
  2497. $this->setPage($this->page + 1);
  2498. $this->SetY($this->tMargin);
  2499. return;
  2500. }
  2501. // start a new page
  2502. if ($this->state == 0)
  2503. {
  2504. $this->Open();
  2505. }
  2506. ++ $this->numpages;
  2507. $this->swapMargins($this->booklet);
  2508. // save current graphic settings
  2509. $gvars = $this->getGraphicVars();
  2510. // start new page
  2511. $this->_beginpage($orientation, $format);
  2512. // mark page as open
  2513. $this->pageopen[$this->page] = true;
  2514. // restore graphic settings
  2515. $this->setGraphicVars($gvars);
  2516. // mark this point
  2517. $this->setPageMark();
  2518. // print page header
  2519. $this->setHeader();
  2520. // restore graphic settings
  2521. $this->setGraphicVars($gvars);
  2522. // mark this point
  2523. $this->setPageMark();
  2524. // print table header (if any)
  2525. $this->setTableHeader();
  2526. }
  2527. /**
  2528. * Set start-writing mark on current page for multicell borders and fills.
  2529. * This function must be called after calling Image() function for a background image.
  2530. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2531. * @access public
  2532. * @since 4.0.016 (2008-07-30)
  2533. */
  2534. public function setPageMark()
  2535. {
  2536. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2537. $this->setContentMark();
  2538. }
  2539. /**
  2540. * Set start-writing mark on selected page.
  2541. * @param int $page page number (default is the current page)
  2542. * @access protected
  2543. * @since 4.6.021 (2009-07-20)
  2544. */
  2545. protected function setContentMark($page = 0)
  2546. {
  2547. if ($page <= 0)
  2548. {
  2549. $page = $this->page;
  2550. }
  2551. if (isset($this->footerlen[$page]))
  2552. {
  2553. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  2554. }
  2555. else
  2556. {
  2557. $this->cntmrk[$page] = $this->pagelen[$page];
  2558. }
  2559. }
  2560. /**
  2561. * Set header data.
  2562. * @param string $ln header image logo
  2563. * @param string $lw header image logo width in mm
  2564. * @param string $ht string to print as title on document header
  2565. * @param string $hs string to print on document header
  2566. * @access public
  2567. */
  2568. public function setHeaderData($ln = '', $lw = 0, $ht = '', $hs = '')
  2569. {
  2570. $this->header_logo = $ln;
  2571. $this->header_logo_width = $lw;
  2572. $this->header_title = $ht;
  2573. $this->header_string = $hs;
  2574. }
  2575. /**
  2576. * Returns header data:
  2577. * <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>
  2578. * @return array()
  2579. * @access public
  2580. * @since 4.0.012 (2008-07-24)
  2581. */
  2582. public function getHeaderData()
  2583. {
  2584. $ret = array();
  2585. $ret['logo'] = $this->header_logo;
  2586. $ret['logo_width'] = $this->header_logo_width;
  2587. $ret['title'] = $this->header_title;
  2588. $ret['string'] = $this->header_string;
  2589. return $ret;
  2590. }
  2591. /**
  2592. * Set header margin.
  2593. * (minimum distance between header and top page margin)
  2594. * @param int $hm distance in user units
  2595. * @access public
  2596. */
  2597. public function setHeaderMargin($hm = 10)
  2598. {
  2599. $this->header_margin = $hm;
  2600. }
  2601. /**
  2602. * Returns header margin in user units.
  2603. * @return float
  2604. * @since 4.0.012 (2008-07-24)
  2605. * @access public
  2606. */
  2607. public function getHeaderMargin()
  2608. {
  2609. return $this->header_margin;
  2610. }
  2611. /**
  2612. * Set footer margin.
  2613. * (minimum distance between footer and bottom page margin)
  2614. * @param int $fm distance in user units
  2615. * @access public
  2616. */
  2617. public function setFooterMargin($fm = 10)
  2618. {
  2619. $this->footer_margin = $fm;
  2620. }
  2621. /**
  2622. * Returns footer margin in user units.
  2623. * @return float
  2624. * @since 4.0.012 (2008-07-24)
  2625. * @access public
  2626. */
  2627. public function getFooterMargin()
  2628. {
  2629. return $this->footer_margin;
  2630. }
  2631. /**
  2632. * Set a flag to print page header.
  2633. * @param boolean $val set to true to print the page header (default), false otherwise.
  2634. * @access public
  2635. */
  2636. public function setPrintHeader($val = true)
  2637. {
  2638. $this->print_header = $val;
  2639. }
  2640. /**
  2641. * Set a flag to print page footer.
  2642. * @param boolean $value set to true to print the page footer (default), false otherwise.
  2643. * @access public
  2644. */
  2645. public function setPrintFooter($val = true)
  2646. {
  2647. $this->print_footer = $val;
  2648. }
  2649. /**
  2650. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  2651. * @return float
  2652. * @access public
  2653. */
  2654. public function getImageRBX()
  2655. {
  2656. return $this->img_rb_x;
  2657. }
  2658. /**
  2659. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  2660. * @return float
  2661. * @access public
  2662. */
  2663. public function getImageRBY()
  2664. {
  2665. return $this->img_rb_y;
  2666. }
  2667. /**
  2668. * This method is used to render the page header.
  2669. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2670. * @access public
  2671. */
  2672. public function Header()
  2673. {
  2674. $ormargins = $this->getOriginalMargins();
  2675. $headerfont = $this->getHeaderFont();
  2676. $headerdata = $this->getHeaderData();
  2677. if (($headerdata['logo']) and ($headerdata['logo'] != K_BLANK_IMAGE))
  2678. {
  2679. $this->Image(K_PATH_IMAGES . $headerdata['logo'], $this->GetX(), $this->getHeaderMargin(), $headerdata['logo_width']);
  2680. $imgy = $this->getImageRBY();
  2681. }
  2682. else
  2683. {
  2684. $imgy = $this->GetY();
  2685. }
  2686. $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
  2687. // set starting margin for text data cell
  2688. if ($this->getRTL())
  2689. {
  2690. $header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1);
  2691. }
  2692. else
  2693. {
  2694. $header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1);
  2695. }
  2696. $this->SetTextColor(0, 0, 0);
  2697. // header title
  2698. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  2699. $this->SetX($header_x);
  2700. $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  2701. // header string
  2702. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  2703. $this->SetX($header_x);
  2704. $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
  2705. // print an ending header line
  2706. $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt',
  2707. 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  2708. $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY()));
  2709. if ($this->getRTL())
  2710. {
  2711. $this->SetX($ormargins['right']);
  2712. }
  2713. else
  2714. {
  2715. $this->SetX($ormargins['left']);
  2716. }
  2717. $this->Cell(0, 0, '', 'T', 0, 'C');
  2718. }
  2719. /**
  2720. * This method is used to render the page footer.
  2721. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2722. * @access public
  2723. */
  2724. public function Footer()
  2725. {
  2726. $cur_y = $this->GetY();
  2727. $ormargins = $this->getOriginalMargins();
  2728. $this->SetTextColor(0, 0, 0);
  2729. //set style for cell border
  2730. $line_width = 0.85 / $this->getScaleFactor();
  2731. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0,
  2732. 'color' => array(0, 0, 0)));
  2733. //print document barcode
  2734. $barcode = $this->getBarcode();
  2735. if (! empty($barcode))
  2736. {
  2737. $this->Ln($line_width);
  2738. $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right']) / 3);
  2739. $this->write1DBarcode($barcode, 'C128B', $this->GetX(), $cur_y + $line_width, $barcode_width, (($this->getFooterMargin() / 3) - $line_width), 0.3, '', '');
  2740. }
  2741. if (empty($this->pagegroups))
  2742. {
  2743. $pagenumtxt = $this->l['w_page'] . ' ' . $this->getAliasNumPage() . ' / ' . $this->getAliasNbPages();
  2744. }
  2745. else
  2746. {
  2747. $pagenumtxt = $this->l['w_page'] . ' ' . $this->getPageNumGroupAlias() . ' / ' . $this->getPageGroupAlias();
  2748. }
  2749. $this->SetY($cur_y);
  2750. //Print page number
  2751. if ($this->getRTL())
  2752. {
  2753. $this->SetX($ormargins['right']);
  2754. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  2755. }
  2756. else
  2757. {
  2758. $this->SetX($ormargins['left']);
  2759. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
  2760. }
  2761. }
  2762. /**
  2763. * This method is used to render the page header.
  2764. * @access protected
  2765. * @since 4.0.012 (2008-07-24)
  2766. */
  2767. protected function setHeader()
  2768. {
  2769. if ($this->print_header)
  2770. {
  2771. $temp_thead = $this->thead;
  2772. $temp_theadMargins = $this->theadMargins;
  2773. $lasth = $this->lasth;
  2774. $this->_out('q');
  2775. $this->rMargin = $this->original_rMargin;
  2776. $this->lMargin = $this->original_lMargin;
  2777. $this->cMargin = 0;
  2778. //set current position
  2779. if ($this->rtl)
  2780. {
  2781. $this->SetXY($this->original_rMargin, $this->header_margin);
  2782. }
  2783. else
  2784. {
  2785. $this->SetXY($this->original_lMargin, $this->header_margin);
  2786. }
  2787. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  2788. $this->Header();
  2789. //restore position
  2790. if ($this->rtl)
  2791. {
  2792. $this->SetXY($this->original_rMargin, $this->tMargin);
  2793. }
  2794. else
  2795. {
  2796. $this->SetXY($this->original_lMargin, $this->tMargin);
  2797. }
  2798. $this->_out('Q');
  2799. $this->lasth = $lasth;
  2800. $this->thead = $temp_thead;
  2801. $this->theadMargins = $temp_theadMargins;
  2802. $this->newline = false;
  2803. }
  2804. }
  2805. /**
  2806. * This method is used to render the page footer.
  2807. * @access protected
  2808. * @since 4.0.012 (2008-07-24)
  2809. */
  2810. protected function setFooter()
  2811. {
  2812. //Page footer
  2813. // save current graphic settings
  2814. $gvars = $this->getGraphicVars();
  2815. // mark this point
  2816. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  2817. $this->_out("\n");
  2818. if ($this->print_footer)
  2819. {
  2820. $temp_thead = $this->thead;
  2821. $temp_theadMargins = $this->theadMargins;
  2822. $lasth = $this->lasth;
  2823. $this->_out('q');
  2824. $this->rMargin = $this->original_rMargin;
  2825. $this->lMargin = $this->original_lMargin;
  2826. $this->cMargin = 0;
  2827. //set current position
  2828. $footer_y = $this->h - $this->footer_margin;
  2829. if ($this->rtl)
  2830. {
  2831. $this->SetXY($this->original_rMargin, $footer_y);
  2832. }
  2833. else
  2834. {
  2835. $this->SetXY($this->original_lMargin, $footer_y);
  2836. }
  2837. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  2838. $this->Footer();
  2839. //restore position
  2840. if ($this->rtl)
  2841. {
  2842. $this->SetXY($this->original_rMargin, $this->tMargin);
  2843. }
  2844. else
  2845. {
  2846. $this->SetXY($this->original_lMargin, $this->tMargin);
  2847. }
  2848. $this->_out('Q');
  2849. $this->lasth = $lasth;
  2850. $this->thead = $temp_thead;
  2851. $this->theadMargins = $temp_theadMargins;
  2852. }
  2853. // restore graphic settings
  2854. $this->setGraphicVars($gvars);
  2855. // calculate footer length
  2856. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  2857. }
  2858. /**
  2859. * This method is used to render the table header on new page (if any).
  2860. * @access protected
  2861. * @since 4.5.030 (2009-03-25)
  2862. */
  2863. protected function setTableHeader()
  2864. {
  2865. if (isset($this->theadMargins['top']))
  2866. {
  2867. // restore the original top-margin
  2868. $this->tMargin = $this->theadMargins['top'];
  2869. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2870. $this->y = $this->tMargin;
  2871. }
  2872. if (! $this->empty_string($this->thead) and (! $this->inthead))
  2873. {
  2874. // set margins
  2875. $prev_lMargin = $this->lMargin;
  2876. $prev_rMargin = $this->rMargin;
  2877. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2878. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2879. $this->cMargin = $this->theadMargins['cmargin'];
  2880. // print table header
  2881. $this->writeHTML($this->thead, false, false, false, false, '');
  2882. // set new top margin to skip the table headers
  2883. if (! isset($this->theadMargins['top']))
  2884. {
  2885. $this->theadMargins['top'] = $this->tMargin;
  2886. }
  2887. $this->tMargin = $this->y;
  2888. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2889. $this->lasth = 0;
  2890. $this->lMargin = $prev_lMargin;
  2891. $this->rMargin = $prev_rMargin;
  2892. }
  2893. }
  2894. /**
  2895. * Returns the current page number.
  2896. * @return int page number
  2897. * @access public
  2898. * @since 1.0
  2899. * @see AliasNbPages(), getAliasNbPages()
  2900. */
  2901. public function PageNo()
  2902. {
  2903. return $this->page;
  2904. }
  2905. /**
  2906. * Defines a new spot color.
  2907. * It can be expressed in RGB components or gray scale.
  2908. * The method can be called before the first page is created and the value is retained from page to page.
  2909. * @param int $c Cyan color for CMYK. Value between 0 and 255
  2910. * @param int $m Magenta color for CMYK. Value between 0 and 255
  2911. * @param int $y Yellow color for CMYK. Value between 0 and 255
  2912. * @param int $k Key (Black) color for CMYK. Value between 0 and 255
  2913. * @access public
  2914. * @since 4.0.024 (2008-09-12)
  2915. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2916. */
  2917. public function AddSpotColor($name, $c, $m, $y, $k)
  2918. {
  2919. if (! isset($this->spot_colors[$name]))
  2920. {
  2921. $i = 1 + count($this->spot_colors);
  2922. $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
  2923. }
  2924. }
  2925. /**
  2926. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  2927. * It can be expressed in RGB components or gray scale.
  2928. * The method can be called before the first page is created and the value is retained from page to page.
  2929. * @param array $color array of colors
  2930. * @access public
  2931. * @since 3.1.000 (2008-06-11)
  2932. * @see SetDrawColor()
  2933. */
  2934. public function SetDrawColorArray($color)
  2935. {
  2936. if (isset($color))
  2937. {
  2938. $color = array_values($color);
  2939. $r = isset($color[0]) ? $color[0] : - 1;
  2940. $g = isset($color[1]) ? $color[1] : - 1;
  2941. $b = isset($color[2]) ? $color[2] : - 1;
  2942. $k = isset($color[3]) ? $color[3] : - 1;
  2943. if ($r >= 0)
  2944. {
  2945. $this->SetDrawColor($r, $g, $b, $k);
  2946. }
  2947. }
  2948. }
  2949. /**
  2950. * 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.
  2951. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2952. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2953. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2954. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2955. * @access public
  2956. * @since 1.3
  2957. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  2958. */
  2959. public function SetDrawColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1)
  2960. {
  2961. // set default values
  2962. if (! is_numeric($col1))
  2963. {
  2964. $col1 = 0;
  2965. }
  2966. if (! is_numeric($col2))
  2967. {
  2968. $col2 = - 1;
  2969. }
  2970. if (! is_numeric($col3))
  2971. {
  2972. $col3 = - 1;
  2973. }
  2974. if (! is_numeric($col4))
  2975. {
  2976. $col4 = - 1;
  2977. }
  2978. //Set color for all stroking operations
  2979. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  2980. {
  2981. // Grey scale
  2982. $this->DrawColor = sprintf('%.3F G', $col1 / 255);
  2983. }
  2984. elseif ($col4 == - 1)
  2985. {
  2986. // RGB
  2987. $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $col1 / 255, $col2 / 255, $col3 / 255);
  2988. }
  2989. else
  2990. {
  2991. // CMYK
  2992. $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  2993. }
  2994. if ($this->page > 0)
  2995. {
  2996. $this->_out($this->DrawColor);
  2997. }
  2998. }
  2999. /**
  3000. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3001. * @param string $name name of the spot color
  3002. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3003. * @access public
  3004. * @since 4.0.024 (2008-09-12)
  3005. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3006. */
  3007. public function SetDrawSpotColor($name, $tint = 100)
  3008. {
  3009. if (! isset($this->spot_colors[$name]))
  3010. {
  3011. $this->Error('Undefined spot color: ' . $name);
  3012. }
  3013. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], $tint / 100);
  3014. if ($this->page > 0)
  3015. {
  3016. $this->_out($this->DrawColor);
  3017. }
  3018. }
  3019. /**
  3020. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3021. * It can be expressed in RGB components or gray scale.
  3022. * The method can be called before the first page is created and the value is retained from page to page.
  3023. * @param array $color array of colors
  3024. * @access public
  3025. * @since 3.1.000 (2008-6-11)
  3026. * @see SetFillColor()
  3027. */
  3028. public function SetFillColorArray($color)
  3029. {
  3030. if (isset($color))
  3031. {
  3032. $color = array_values($color);
  3033. $r = isset($color[0]) ? $color[0] : - 1;
  3034. $g = isset($color[1]) ? $color[1] : - 1;
  3035. $b = isset($color[2]) ? $color[2] : - 1;
  3036. $k = isset($color[3]) ? $color[3] : - 1;
  3037. if ($r >= 0)
  3038. {
  3039. $this->SetFillColor($r, $g, $b, $k);
  3040. }
  3041. }
  3042. }
  3043. /**
  3044. * 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.
  3045. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  3046. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  3047. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  3048. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  3049. * @access public
  3050. * @since 1.3
  3051. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3052. */
  3053. public function SetFillColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1)
  3054. {
  3055. // set default values
  3056. if (! is_numeric($col1))
  3057. {
  3058. $col1 = 0;
  3059. }
  3060. if (! is_numeric($col2))
  3061. {
  3062. $col2 = - 1;
  3063. }
  3064. if (! is_numeric($col3))
  3065. {
  3066. $col3 = - 1;
  3067. }
  3068. if (! is_numeric($col4))
  3069. {
  3070. $col4 = - 1;
  3071. }
  3072. //Set color for all filling operations
  3073. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  3074. {
  3075. // Grey scale
  3076. $this->FillColor = sprintf('%.3F g', $col1 / 255);
  3077. $this->bgcolor = array('G' => $col1);
  3078. }
  3079. elseif ($col4 == - 1)
  3080. {
  3081. // RGB
  3082. $this->FillColor = sprintf('%.3F %.3F %.3F rg', $col1 / 255, $col2 / 255, $col3 / 255);
  3083. $this->bgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3084. }
  3085. else
  3086. {
  3087. // CMYK
  3088. $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  3089. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3090. }
  3091. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3092. if ($this->page > 0)
  3093. {
  3094. $this->_out($this->FillColor);
  3095. }
  3096. }
  3097. /**
  3098. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3099. * @param string $name name of the spot color
  3100. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3101. * @access public
  3102. * @since 4.0.024 (2008-09-12)
  3103. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3104. */
  3105. public function SetFillSpotColor($name, $tint = 100)
  3106. {
  3107. if (! isset($this->spot_colors[$name]))
  3108. {
  3109. $this->Error('Undefined spot color: ' . $name);
  3110. }
  3111. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint / 100);
  3112. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3113. if ($this->page > 0)
  3114. {
  3115. $this->_out($this->FillColor);
  3116. }
  3117. }
  3118. /**
  3119. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3120. * The method can be called before the first page is created and the value is retained from page to page.
  3121. * @param array $color array of colors
  3122. * @access public
  3123. * @since 3.1.000 (2008-6-11)
  3124. * @see SetFillColor()
  3125. */
  3126. public function SetTextColorArray($color)
  3127. {
  3128. if (isset($color))
  3129. {
  3130. $color = array_values($color);
  3131. $r = isset($color[0]) ? $color[0] : - 1;
  3132. $g = isset($color[1]) ? $color[1] : - 1;
  3133. $b = isset($color[2]) ? $color[2] : - 1;
  3134. $k = isset($color[3]) ? $color[3] : - 1;
  3135. if ($r >= 0)
  3136. {
  3137. $this->SetTextColor($r, $g, $b, $k);
  3138. }
  3139. }
  3140. }
  3141. /**
  3142. * 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.
  3143. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  3144. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  3145. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  3146. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  3147. * @access public
  3148. * @since 1.3
  3149. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3150. */
  3151. public function SetTextColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1)
  3152. {
  3153. // set default values
  3154. if (! is_numeric($col1))
  3155. {
  3156. $col1 = 0;
  3157. }
  3158. if (! is_numeric($col2))
  3159. {
  3160. $col2 = - 1;
  3161. }
  3162. if (! is_numeric($col3))
  3163. {
  3164. $col3 = - 1;
  3165. }
  3166. if (! is_numeric($col4))
  3167. {
  3168. $col4 = - 1;
  3169. }
  3170. //Set color for text
  3171. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  3172. {
  3173. // Grey scale
  3174. $this->TextColor = sprintf('%.3F g', $col1 / 255);
  3175. $this->fgcolor = array('G' => $col1);
  3176. }
  3177. elseif ($col4 == - 1)
  3178. {
  3179. // RGB
  3180. $this->TextColor = sprintf('%.3F %.3F %.3F rg', $col1 / 255, $col2 / 255, $col3 / 255);
  3181. $this->fgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3182. }
  3183. else
  3184. {
  3185. // CMYK
  3186. $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  3187. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3188. }
  3189. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3190. }
  3191. /**
  3192. * Defines the spot color used for text.
  3193. * @param string $name name of the spot color
  3194. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3195. * @access public
  3196. * @since 4.0.024 (2008-09-12)
  3197. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3198. */
  3199. public function SetTextSpotColor($name, $tint = 100)
  3200. {
  3201. if (! isset($this->spot_colors[$name]))
  3202. {
  3203. $this->Error('Undefined spot color: ' . $name);
  3204. }
  3205. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint / 100);
  3206. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3207. if ($this->page > 0)
  3208. {
  3209. $this->_out($this->TextColor);
  3210. }
  3211. }
  3212. /**
  3213. * Returns the length of a string in user unit. A font must be selected.<br>
  3214. * @param string $s The string whose length is to be computed
  3215. * @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.
  3216. * @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></ul> or any combination. The default value is regular.
  3217. * @param float $fontsize Font size in points. The default value is the current size.
  3218. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3219. * @return mixed int total string length or array of characted widths
  3220. * @author Nicola Asuni
  3221. * @access public
  3222. * @since 1.2
  3223. */
  3224. public function GetStringWidth($s, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  3225. {
  3226. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  3227. }
  3228. /**
  3229. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3230. * @param string $sa The array of chars whose total length is to be computed
  3231. * @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.
  3232. * @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></ul> or any combination. The default value is regular.
  3233. * @param float $fontsize Font size in points. The default value is the current size.
  3234. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3235. * @return mixed int total string length or array of characted widths
  3236. * @author Nicola Asuni
  3237. * @access public
  3238. * @since 2.4.000 (2008-03-06)
  3239. */
  3240. public function GetArrStringWidth($sa, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  3241. {
  3242. // store current values
  3243. if (! $this->empty_string($fontname))
  3244. {
  3245. $prev_FontFamily = $this->FontFamily;
  3246. $prev_FontStyle = $this->FontStyle;
  3247. $prev_FontSizePt = $this->FontSizePt;
  3248. $this->SetFont($fontname, $fontstyle, $fontsize);
  3249. }
  3250. // convert UTF-8 array to Latin1 if required
  3251. $sa = $this->UTF8ArrToLatin1($sa);
  3252. $w = 0; // total width
  3253. $wa = array(); // array of characters widths
  3254. foreach ($sa as $char)
  3255. {
  3256. // character width
  3257. $cw = $this->GetCharWidth($char);
  3258. $wa[] = $cw;
  3259. $w += $cw;
  3260. }
  3261. // restore previous values
  3262. if (! $this->empty_string($fontname))
  3263. {
  3264. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
  3265. }
  3266. if ($getarray)
  3267. {
  3268. return $wa;
  3269. }
  3270. return $w;
  3271. }
  3272. /**
  3273. * Returns the length of the char in user unit for the current font.
  3274. * @param int $char The char code whose length is to be returned
  3275. * @return int char width
  3276. * @author Nicola Asuni
  3277. * @access public
  3278. * @since 2.4.000 (2008-03-06)
  3279. */
  3280. public function GetCharWidth($char)
  3281. {
  3282. if ($char == 173)
  3283. {
  3284. // SHY character will not be printed
  3285. return (0);
  3286. }
  3287. $cw = &$this->CurrentFont['cw'];
  3288. if (isset($cw[$char]))
  3289. {
  3290. $w = $cw[$char];
  3291. }
  3292. elseif (isset($this->CurrentFont['dw']))
  3293. {
  3294. // default width
  3295. $w = $this->CurrentFont['dw'];
  3296. }
  3297. elseif (isset($cw[32]))
  3298. {
  3299. // default width
  3300. $dw = $cw[32];
  3301. }
  3302. else
  3303. {
  3304. $w = 600;
  3305. }
  3306. return ($w * $this->FontSize / 1000);
  3307. }
  3308. /**
  3309. * Returns the numbero of characters in a string.
  3310. * @param string $s The input string.
  3311. * @return int number of characters
  3312. * @access public
  3313. * @since 2.0.0001 (2008-01-07)
  3314. */
  3315. public function GetNumChars($s)
  3316. {
  3317. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') or ($this->CurrentFont['type'] == 'cidfont0'))
  3318. {
  3319. return count($this->UTF8StringToArray($s));
  3320. }
  3321. return strlen($s);
  3322. }
  3323. /**
  3324. * Fill the list of available fonts ($this->fontlist).
  3325. * @access protected
  3326. * @since 4.0.013 (2008-07-28)
  3327. */
  3328. protected function getFontsList()
  3329. {
  3330. $fontsdir = opendir($this->_getfontpath());
  3331. while (($file = readdir($fontsdir)) !== false)
  3332. {
  3333. if (substr($file, - 4) == '.php')
  3334. {
  3335. array_push($this->fontlist, strtolower(basename($file, '.php')));
  3336. }
  3337. }
  3338. closedir($fontsdir);
  3339. }
  3340. /**
  3341. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3342. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3343. * 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.
  3344. * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3345. * @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>
  3346. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3347. * @return array containing the font data, or false in case of error.
  3348. * @access public
  3349. * @since 1.5
  3350. * @see SetFont()
  3351. */
  3352. public function AddFont($family, $style = '', $fontfile = '')
  3353. {
  3354. if ($this->empty_string($family))
  3355. {
  3356. if (! $this->empty_string($this->FontFamily))
  3357. {
  3358. $family = $this->FontFamily;
  3359. }
  3360. else
  3361. {
  3362. $this->Error('Empty font family');
  3363. }
  3364. }
  3365. $family = strtolower($family);
  3366. if ((! $this->isunicode) and ($family == 'arial'))
  3367. {
  3368. $family = 'helvetica';
  3369. }
  3370. if (($family == 'symbol') or ($family == 'zapfdingbats'))
  3371. {
  3372. $style = '';
  3373. }
  3374. $tempstyle = strtoupper($style);
  3375. $style = '';
  3376. // underline
  3377. if (strpos($tempstyle, 'U') !== false)
  3378. {
  3379. $this->underline = true;
  3380. }
  3381. else
  3382. {
  3383. $this->underline = false;
  3384. }
  3385. // line through (deleted)
  3386. if (strpos($tempstyle, 'D') !== false)
  3387. {
  3388. $this->linethrough = true;
  3389. }
  3390. else
  3391. {
  3392. $this->linethrough = false;
  3393. }
  3394. // bold
  3395. if (strpos($tempstyle, 'B') !== false)
  3396. {
  3397. $style .= 'B';
  3398. }
  3399. // oblique
  3400. if (strpos($tempstyle, 'I') !== false)
  3401. {
  3402. $style .= 'I';
  3403. }
  3404. $bistyle = $style;
  3405. $fontkey = $family . $style;
  3406. $font_style = $style . ($this->underline ? 'U' : '') . ($this->linethrough ? 'D' : '');
  3407. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  3408. // check if the font has been already added
  3409. if ($this->getFontBuffer($fontkey) !== false)
  3410. {
  3411. return $fontdata;
  3412. }
  3413. if (isset($type))
  3414. {
  3415. unset($type);
  3416. }
  3417. if (isset($cw))
  3418. {
  3419. unset($cw);
  3420. }
  3421. // get specified font directory (if any)
  3422. $fontdir = '';
  3423. if (! $this->empty_string($fontfile))
  3424. {
  3425. $fontdir = dirname($fontfile);
  3426. if ($this->empty_string($fontdir) or ($fontdir == '.'))
  3427. {
  3428. $fontdir = '';
  3429. }
  3430. else
  3431. {
  3432. $fontdir .= '/';
  3433. }
  3434. }
  3435. // search and include font file
  3436. if ($this->empty_string($fontfile) or (! file_exists($fontfile)))
  3437. {
  3438. // build a standard filenames for specified font
  3439. $fontfile1 = str_replace(' ', '', $family) . strtolower($style) . '.php';
  3440. $fontfile2 = str_replace(' ', '', $family) . '.php';
  3441. // search files on various directories
  3442. if (file_exists($fontdir . $fontfile1))
  3443. {
  3444. $fontfile = $fontdir . $fontfile1;
  3445. }
  3446. elseif (file_exists($this->_getfontpath() . $fontfile1))
  3447. {
  3448. $fontfile = $this->_getfontpath() . $fontfile1;
  3449. }
  3450. elseif (file_exists($fontfile1))
  3451. {
  3452. $fontfile = $fontfile1;
  3453. }
  3454. elseif (file_exists($fontdir . $fontfile2))
  3455. {
  3456. $fontfile = $fontdir . $fontfile2;
  3457. }
  3458. elseif (file_exists($this->_getfontpath() . $fontfile2))
  3459. {
  3460. $fontfile = $this->_getfontpath() . $fontfile2;
  3461. }
  3462. else
  3463. {
  3464. $fontfile = $fontfile2;
  3465. }
  3466. }
  3467. // include font file
  3468. if (file_exists($fontfile))
  3469. {
  3470. include ($fontfile);
  3471. }
  3472. else
  3473. {
  3474. $this->Error('Could not include font definition file: ' . $family . '');
  3475. }
  3476. // check font parameters
  3477. if ((! isset($type)) or (! isset($cw)))
  3478. {
  3479. $this->Error('The font definition file has a bad format: ' . $fontfile . '');
  3480. }
  3481. // SET default parameters
  3482. if (! isset($file) or $this->empty_string($file))
  3483. {
  3484. $file = '';
  3485. }
  3486. if (! isset($enc) or $this->empty_string($enc))
  3487. {
  3488. $enc = '';
  3489. }
  3490. if (! isset($cidinfo) or $this->empty_string($cidinfo))
  3491. {
  3492. $cidinfo = array('Registry' => 'Adobe', 'Ordering' => 'Identity', 'Supplement' => 0);
  3493. $cidinfo['uni2cid'] = array();
  3494. }
  3495. if (! isset($ctg) or $this->empty_string($ctg))
  3496. {
  3497. $ctg = '';
  3498. }
  3499. if (! isset($desc) or $this->empty_string($desc))
  3500. {
  3501. $desc = array();
  3502. }
  3503. if (! isset($up) or $this->empty_string($up))
  3504. {
  3505. $up = - 100;
  3506. }
  3507. if (! isset($ut) or $this->empty_string($ut))
  3508. {
  3509. $ut = 50;
  3510. }
  3511. if (! isset($cw) or $this->empty_string($cw))
  3512. {
  3513. $cw = array();
  3514. }
  3515. if (! isset($dw) or $this->empty_string($dw))
  3516. {
  3517. // set default width
  3518. if (isset($desc['MissingWidth']) and ($desc['MissingWidth'] > 0))
  3519. {
  3520. $dw = $desc['MissingWidth'];
  3521. }
  3522. elseif (isset($cw[32]))
  3523. {
  3524. $dw = $cw[32];
  3525. }
  3526. else
  3527. {
  3528. $dw = 600;
  3529. }
  3530. }
  3531. ++ $this->numfonts;
  3532. if ($type == 'cidfont0')
  3533. {
  3534. // register CID font (all styles at once)
  3535. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  3536. $sname = $name . $styles[$bistyle];
  3537. if ((strpos($bistyle, 'B') !== false) and (isset($desc['StemV'])) and ($desc['StemV'] == 70))
  3538. {
  3539. $desc['StemV'] = 120;
  3540. }
  3541. }
  3542. elseif ($type == 'core')
  3543. {
  3544. $name = $this->CoreFonts[$fontkey];
  3545. }
  3546. elseif (($type == 'TrueType') or ($type == 'Type1'))
  3547. {
  3548. // ...
  3549. }
  3550. elseif ($type == 'TrueTypeUnicode')
  3551. {
  3552. $enc = 'Identity-H';
  3553. }
  3554. else
  3555. {
  3556. $this->Error('Unknow font type: ' . $type . '');
  3557. }
  3558. $this->setFontBuffer($fontkey, array('i' => $this->numfonts, 'type' => $type, 'name' => $name,
  3559. 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc,
  3560. 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg));
  3561. if (isset($diff) and (! empty($diff)))
  3562. {
  3563. //Search existing encodings
  3564. $d = 0;
  3565. $nb = count($this->diffs);
  3566. for($i = 1; $i <= $nb; ++ $i)
  3567. {
  3568. if ($this->diffs[$i] == $diff)
  3569. {
  3570. $d = $i;
  3571. break;
  3572. }
  3573. }
  3574. if ($d == 0)
  3575. {
  3576. $d = $nb + 1;
  3577. $this->diffs[$d] = $diff;
  3578. }
  3579. $this->setFontSubBuffer($fontkey, 'diff', $d);
  3580. }
  3581. if (! $this->empty_string($file))
  3582. {
  3583. if ((strcasecmp($type, 'TrueType') == 0) or (strcasecmp($type, 'TrueTypeUnicode') == 0))
  3584. {
  3585. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir);
  3586. }
  3587. elseif ($type != 'core')
  3588. {
  3589. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir);
  3590. }
  3591. }
  3592. return $fontdata;
  3593. }
  3594. /**
  3595. * Sets the font used to print character strings.
  3596. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  3597. * The method can be called before the first page is created and the font is retained from page to page.
  3598. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  3599. * 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 />
  3600. * @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.
  3601. * @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></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.
  3602. * @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
  3603. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3604. * @access public
  3605. * @since 1.0
  3606. * @see AddFont(), SetFontSize()
  3607. */
  3608. public function SetFont($family, $style = '', $size = 0, $fontfile = '')
  3609. {
  3610. //Select a font; size given in points
  3611. if ($size == 0)
  3612. {
  3613. $size = $this->FontSizePt;
  3614. }
  3615. // try to add font (if not already added)
  3616. $fontdata = $this->AddFont($family, $style, $fontfile);
  3617. $this->FontFamily = $fontdata['family'];
  3618. $this->FontStyle = $fontdata['style'];
  3619. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  3620. $this->SetFontSize($size);
  3621. }
  3622. /**
  3623. * Defines the size of the current font.
  3624. * @param float $size The size (in points)
  3625. * @access public
  3626. * @since 1.0
  3627. * @see SetFont()
  3628. */
  3629. public function SetFontSize($size)
  3630. {
  3631. //Set font size in points
  3632. $this->FontSizePt = $size;
  3633. $this->FontSize = $size / $this->k;
  3634. if (isset($this->CurrentFont['desc']['Ascent']) and ($this->CurrentFont['desc']['Ascent'] > 0))
  3635. {
  3636. $this->FontAscent = $this->CurrentFont['desc']['Ascent'] * $this->FontSize / 1000;
  3637. }
  3638. else
  3639. {
  3640. $this->FontAscent = 0.8 * $this->FontSize;
  3641. }
  3642. if (isset($this->CurrentFont['desc']['Descent']) and ($this->CurrentFont['desc']['Descent'] > 0))
  3643. {
  3644. $this->FontDescent = - $this->CurrentFont['desc']['Descent'] * $this->FontSize / 1000;
  3645. }
  3646. else
  3647. {
  3648. $this->FontDescent = 0.2 * $this->FontSize;
  3649. }
  3650. if (($this->page > 0) and (isset($this->CurrentFont['i'])))
  3651. {
  3652. $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  3653. }
  3654. }
  3655. /**
  3656. * Defines the default monospaced font.
  3657. * @param string $font Font name.
  3658. * @access public
  3659. * @since 4.5.025
  3660. */
  3661. public function SetDefaultMonospacedFont($font)
  3662. {
  3663. $this->default_monospaced_font = $font;
  3664. }
  3665. /**
  3666. * 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 />
  3667. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  3668. * @access public
  3669. * @since 1.5
  3670. * @see Cell(), Write(), Image(), Link(), SetLink()
  3671. */
  3672. public function AddLink()
  3673. {
  3674. //Create a new internal link
  3675. $n = count($this->links) + 1;
  3676. $this->links[$n] = array(0, 0);
  3677. return $n;
  3678. }
  3679. /**
  3680. * Defines the page and position a link points to.
  3681. * @param int $link The link identifier returned by AddLink()
  3682. * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  3683. * @param int $page Number of target page; -1 indicates the current page. This is the default value
  3684. * @access public
  3685. * @since 1.5
  3686. * @see AddLink()
  3687. */
  3688. public function SetLink($link, $y = 0, $page = -1)
  3689. {
  3690. if ($y == - 1)
  3691. {
  3692. $y = $this->y;
  3693. }
  3694. if ($page == - 1)
  3695. {
  3696. $page = $this->page;
  3697. }
  3698. $this->links[$link] = array($page, $y);
  3699. }
  3700. /**
  3701. * Puts a link on a rectangular area of the page.
  3702. * 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.
  3703. * @param float $x Abscissa of the upper-left corner of the rectangle
  3704. * @param float $y Ordinate of the upper-left corner of the rectangle
  3705. * @param float $w Width of the rectangle
  3706. * @param float $h Height of the rectangle
  3707. * @param mixed $link URL or identifier returned by AddLink()
  3708. * @param int $spaces number of spaces on the text to link
  3709. * @access public
  3710. * @since 1.5
  3711. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  3712. */
  3713. public function Link($x, $y, $w, $h, $link, $spaces = 0)
  3714. {
  3715. $this->Annotation($x, $y, $w, $h, $link, array('Subtype' => 'Link'), $spaces);
  3716. }
  3717. /**
  3718. * Puts a markup annotation on a rectangular area of the page.
  3719. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  3720. * @param float $x Abscissa of the upper-left corner of the rectangle
  3721. * @param float $y Ordinate of the upper-left corner of the rectangle
  3722. * @param float $w Width of the rectangle
  3723. * @param float $h Height of the rectangle
  3724. * @param string $text annotation text or alternate content
  3725. * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  3726. * @param int $spaces number of spaces on the text to link
  3727. * @access public
  3728. * @since 4.0.018 (2008-08-06)
  3729. */
  3730. public function Annotation($x = '', $y = '', $w, $h, $text, $opt = array('Subtype'=>'Text'), $spaces = 0)
  3731. {
  3732. if ($x === '')
  3733. {
  3734. $x = $this->x;
  3735. }
  3736. if ($y === '')
  3737. {
  3738. $y = $this->y;
  3739. }
  3740. // recalculate coordinates to account for graphic transformations
  3741. if (isset($this->transfmatrix))
  3742. {
  3743. for($i = $this->transfmatrix_key; $i > 0; -- $i)
  3744. {
  3745. $maxid = count($this->transfmatrix[$i]) - 1;
  3746. for($j = $maxid; $j >= 0; -- $j)
  3747. {
  3748. $ctm = $this->transfmatrix[$i][$j];
  3749. if (isset($ctm['a']))
  3750. {
  3751. $x = $x * $this->k;
  3752. $y = ($this->h - $y) * $this->k;
  3753. $w = $w * $this->k;
  3754. $h = $h * $this->k;
  3755. // top left
  3756. $xt = $x;
  3757. $yt = $y;
  3758. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3759. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3760. // top right
  3761. $xt = $x + $w;
  3762. $yt = $y;
  3763. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3764. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3765. // bottom left
  3766. $xt = $x;
  3767. $yt = $y - $h;
  3768. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3769. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3770. // bottom right
  3771. $xt = $x + $w;
  3772. $yt = $y - $h;
  3773. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  3774. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  3775. // new coordinates (rectangle area)
  3776. $x = min($x1, $x2, $x3, $x4);
  3777. $y = max($y1, $y2, $y3, $y4);
  3778. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  3779. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  3780. $x = $x / $this->k;
  3781. $y = $this->h - ($y / $this->k);
  3782. }
  3783. }
  3784. }
  3785. }
  3786. if ($this->page <= 0)
  3787. {
  3788. $page = 1;
  3789. }
  3790. else
  3791. {
  3792. $page = $this->page;
  3793. }
  3794. if (! isset($this->PageAnnots[$page]))
  3795. {
  3796. $this->PageAnnots[$page] = array();
  3797. }
  3798. $this->PageAnnots[$page][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text,
  3799. 'opt' => $opt, 'numspaces' => $spaces);
  3800. 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'])])))
  3801. {
  3802. $this->embeddedfiles[basename($opt['FS'])] = array('file' => $opt['FS'],
  3803. 'n' => (count($this->embeddedfiles) + $this->embedded_start_obj_id));
  3804. }
  3805. // Add widgets annotation's icons
  3806. if (isset($opt['mk']['i']) and file_exists($opt['mk']['i']))
  3807. {
  3808. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  3809. }
  3810. if (isset($opt['mk']['ri']) and file_exists($opt['mk']['ri']))
  3811. {
  3812. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  3813. }
  3814. if (isset($opt['mk']['ix']) and file_exists($opt['mk']['ix']))
  3815. {
  3816. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  3817. }
  3818. ++ $this->annot_obj_id;
  3819. }
  3820. /**
  3821. * Embedd the attached files.
  3822. * @since 4.4.000 (2008-12-07)
  3823. * @access protected
  3824. * @see Annotation()
  3825. */
  3826. protected function _putEmbeddedFiles()
  3827. {
  3828. reset($this->embeddedfiles);
  3829. foreach ($this->embeddedfiles as $filename => $filedata)
  3830. {
  3831. $data = file_get_contents($filedata['file']);
  3832. $filter = '';
  3833. if ($this->compress)
  3834. {
  3835. $data = gzcompress($data);
  3836. $filter = ' /Filter /FlateDecode';
  3837. }
  3838. $this->offsets[$filedata['n']] = $this->bufferlen;
  3839. $this->_out($filedata['n'] . ' 0 obj');
  3840. $this->_out('<</Type /EmbeddedFile' . $filter . ' /Length ' . strlen($data) . ' >>');
  3841. $this->_putstream($data);
  3842. $this->_out('endobj');
  3843. }
  3844. }
  3845. /**
  3846. * Prints a character string.
  3847. * The origin is on the left of the first charcter, on the baseline.
  3848. * This method allows to place a string precisely on the page.
  3849. * @param float $x Abscissa of the origin
  3850. * @param float $y Ordinate of the origin
  3851. * @param string $txt String to print
  3852. * @param int $stroke outline size in points (0 = disable)
  3853. * @param boolean $clip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  3854. * @access public
  3855. * @since 1.0
  3856. * @deprecated deprecated since version 4.3.005 (2008-11-25)
  3857. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  3858. */
  3859. public function Text($x, $y, $txt, $stroke = 0, $clip = false)
  3860. {
  3861. //Output a string
  3862. if ($this->rtl)
  3863. {
  3864. // bidirectional algorithm (some chars may be changed affecting the line length)
  3865. $s = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
  3866. $l = $this->GetArrStringWidth($s);
  3867. $xr = $this->w - $x - $l;
  3868. }
  3869. else
  3870. {
  3871. $xr = $x;
  3872. }
  3873. $opt = '';
  3874. if (($stroke > 0) and (! $clip))
  3875. {
  3876. $opt .= '1 Tr ' . intval($stroke) . ' w ';
  3877. }
  3878. elseif (($stroke > 0) and $clip)
  3879. {
  3880. $opt .= '5 Tr ' . intval($stroke) . ' w ';
  3881. }
  3882. elseif ($clip)
  3883. {
  3884. $opt .= '7 Tr ';
  3885. }
  3886. $s = sprintf('BT %.2F %.2F Td %s(%s) Tj ET 0 Tr', $xr * $this->k, ($this->h - $y) * $this->k, $opt, $this->_escapetext($txt));
  3887. if ($this->underline and ($txt != ''))
  3888. {
  3889. $s .= ' ' . $this->_dounderline($xr, $y, $txt);
  3890. }
  3891. if ($this->linethrough and ($txt != ''))
  3892. {
  3893. $s .= ' ' . $this->_dolinethrough($xr, $y, $txt);
  3894. }
  3895. if ($this->ColorFlag and (! $clip))
  3896. {
  3897. $s = 'q ' . $this->TextColor . ' ' . $s . ' Q';
  3898. }
  3899. $this->_out($s);
  3900. }
  3901. /**
  3902. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  3903. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  3904. * This method is called automatically and should not be called directly by the application.
  3905. * @return boolean
  3906. * @access public
  3907. * @since 1.4
  3908. * @see SetAutoPageBreak()
  3909. */
  3910. public function AcceptPageBreak()
  3911. {
  3912. return $this->AutoPageBreak;
  3913. }
  3914. /**
  3915. * Add page if needed.
  3916. * @param float $h Cell height. Default value: 0.
  3917. * @param mixed $y starting y position, leave empty for current position.
  3918. * @param boolean $addpage if true add a page, otherwise only return the true/false state
  3919. * @return boolean true in case of page break, false otherwise.
  3920. * @since 3.2.000 (2008-07-01)
  3921. * @access protected
  3922. */
  3923. protected function checkPageBreak($h = 0, $y = '', $addpage = true)
  3924. {
  3925. if ($this->empty_string($y))
  3926. {
  3927. $y = $this->y;
  3928. }
  3929. if ((($y + $h) > $this->PageBreakTrigger) and (! $this->InFooter) and ($this->AcceptPageBreak()))
  3930. {
  3931. if ($addpage)
  3932. {
  3933. //Automatic page break
  3934. $x = $this->x;
  3935. $this->AddPage($this->CurOrientation);
  3936. $this->y = $this->tMargin;
  3937. $oldpage = $this->page - 1;
  3938. if ($this->rtl)
  3939. {
  3940. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm'])
  3941. {
  3942. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  3943. }
  3944. else
  3945. {
  3946. $this->x = $x;
  3947. }
  3948. }
  3949. else
  3950. {
  3951. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm'])
  3952. {
  3953. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  3954. }
  3955. else
  3956. {
  3957. $this->x = $x;
  3958. }
  3959. }
  3960. }
  3961. return true;
  3962. }
  3963. return false;
  3964. }
  3965. /**
  3966. * 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 />
  3967. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3968. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3969. * @param float $h Cell height. Default value: 0.
  3970. * @param string $txt String to print. Default value: empty string.
  3971. * @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>
  3972. * @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>
  3973. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3974. * @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>
  3975. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3976. * @param mixed $link URL or identifier returned by AddLink().
  3977. * @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>
  3978. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3979. * @access public
  3980. * @since 1.0
  3981. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  3982. */
  3983. public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '', $stretch = 0, $ignore_min_height = false)
  3984. {
  3985. //$min_cell_height = $this->FontAscent + $this->FontDescent;
  3986. $min_cell_height = $this->FontSize * $this->cell_height_ratio;
  3987. if ($h < $min_cell_height)
  3988. {
  3989. $h = $min_cell_height;
  3990. }
  3991. $this->checkPageBreak($h);
  3992. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height));
  3993. }
  3994. /**
  3995. * Removes SHY characters from text.
  3996. * @param string $txt input string
  3997. * @return string without SHY characters.
  3998. * @access public
  3999. * @since (4.5.019) 2009-02-28
  4000. */
  4001. public function removeSHY($txt = '')
  4002. {
  4003. /*
  4004. * Unicode Data
  4005. * Name : SOFT HYPHEN, commonly abbreviated as SHY
  4006. * HTML Entity (decimal): &#173;
  4007. * HTML Entity (hex): &#xad;
  4008. * HTML Entity (named): &shy;
  4009. * How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]
  4010. * UTF-8 (hex): 0xC2 0xAD (c2ad)
  4011. * UTF-8 character: chr(194).chr(173)
  4012. */
  4013. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  4014. if (! $this->isunicode)
  4015. {
  4016. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  4017. }
  4018. return $txt;
  4019. }
  4020. /**
  4021. * 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 />
  4022. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4023. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  4024. * @param float $h Cell height. Default value: 0.
  4025. * @param string $txt String to print. Default value: empty string.
  4026. * @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>
  4027. * @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.
  4028. * @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>
  4029. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  4030. * @param mixed $link URL or identifier returned by AddLink().
  4031. * @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>
  4032. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4033. * @access protected
  4034. * @since 1.0
  4035. * @see Cell()
  4036. */
  4037. protected function getCellCode($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '', $stretch = 0, $ignore_min_height = false)
  4038. {
  4039. $txt = $this->removeSHY($txt);
  4040. $rs = ''; //string to be returned
  4041. if (! $ignore_min_height)
  4042. {
  4043. $min_cell_height = $this->FontSize * $this->cell_height_ratio;
  4044. if ($h < $min_cell_height)
  4045. {
  4046. $h = $min_cell_height;
  4047. }
  4048. }
  4049. $k = $this->k;
  4050. if ($this->empty_string($w) or ($w <= 0))
  4051. {
  4052. if ($this->rtl)
  4053. {
  4054. $w = $this->x - $this->lMargin;
  4055. }
  4056. else
  4057. {
  4058. $w = $this->w - $this->rMargin - $this->x;
  4059. }
  4060. }
  4061. $s = '';
  4062. // fill and borders
  4063. if (($fill == 1) or ($border == 1))
  4064. {
  4065. if ($fill == 1)
  4066. {
  4067. $op = ($border == 1) ? 'B' : 'f';
  4068. }
  4069. else
  4070. {
  4071. $op = 'S';
  4072. }
  4073. if ($this->rtl)
  4074. {
  4075. $xk = (($this->x - $w) * $k);
  4076. }
  4077. else
  4078. {
  4079. $xk = ($this->x * $k);
  4080. }
  4081. $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $this->y) * $k), ($w * $k), (- $h * $k), $op);
  4082. }
  4083. if (is_string($border))
  4084. {
  4085. $lm = ($this->LineWidth / 2);
  4086. $x = $this->x;
  4087. $y = $this->y;
  4088. if (strpos($border, 'L') !== false)
  4089. {
  4090. if ($this->rtl)
  4091. {
  4092. $xk = ($x - $w) * $k;
  4093. }
  4094. else
  4095. {
  4096. $xk = $x * $k;
  4097. }
  4098. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - $y + $lm) * $k), $xk, (($this->h - ($y + $h + $lm)) * $k));
  4099. }
  4100. if (strpos($border, 'T') !== false)
  4101. {
  4102. if ($this->rtl)
  4103. {
  4104. $xk = ($x - $w + $lm) * $k;
  4105. $xwk = ($x - $lm) * $k;
  4106. }
  4107. else
  4108. {
  4109. $xk = ($x - $lm) * $k;
  4110. $xwk = ($x + $w + $lm) * $k;
  4111. }
  4112. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - $y) * $k), $xwk, (($this->h - $y) * $k));
  4113. }
  4114. if (strpos($border, 'R') !== false)
  4115. {
  4116. if ($this->rtl)
  4117. {
  4118. $xk = $x * $k;
  4119. }
  4120. else
  4121. {
  4122. $xk = ($x + $w) * $k;
  4123. }
  4124. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - $y + $lm) * $k), $xk, (($this->h - ($y + $h + $lm)) * $k));
  4125. }
  4126. if (strpos($border, 'B') !== false)
  4127. {
  4128. if ($this->rtl)
  4129. {
  4130. $xk = ($x - $w + $lm) * $k;
  4131. $xwk = ($x - $lm) * $k;
  4132. }
  4133. else
  4134. {
  4135. $xk = ($x - $lm) * $k;
  4136. $xwk = ($x + $w + $lm) * $k;
  4137. }
  4138. $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - ($y + $h)) * $k), $xwk, (($this->h - ($y + $h)) * $k));
  4139. }
  4140. }
  4141. if ($txt != '')
  4142. {
  4143. $txt2 = $this->_escapetext($txt);
  4144. // text length
  4145. $txwidth = $this->GetStringWidth($txt);
  4146. $width = $txwidth;
  4147. // ratio between cell length and text length
  4148. if ($width <= 0)
  4149. {
  4150. $ratio = 1;
  4151. }
  4152. else
  4153. {
  4154. $ratio = ($w - (2 * $this->cMargin)) / $width;
  4155. }
  4156. // stretch text if required
  4157. if (($stretch > 0) and (($ratio < 1) or (($ratio > 1) and (($stretch % 2) == 0))))
  4158. {
  4159. if ($stretch > 2)
  4160. {
  4161. // spacing
  4162. //Calculate character spacing in points
  4163. $char_space = (($w - $width - (2 * $this->cMargin)) * $this->k) / max($this->GetNumChars($txt) - 1, 1);
  4164. //Set character spacing
  4165. $rs .= sprintf('BT %.2F Tc ET ', $char_space);
  4166. }
  4167. else
  4168. {
  4169. // scaling
  4170. //Calculate horizontal scaling
  4171. $horiz_scale = $ratio * 100.0;
  4172. //Set horizontal scaling
  4173. $rs .= sprintf('BT %.2F Tz ET ', $horiz_scale);
  4174. }
  4175. $align = '';
  4176. $width = $w - (2 * $this->cMargin);
  4177. }
  4178. else
  4179. {
  4180. $stretch == 0;
  4181. }
  4182. if ($this->ColorFlag)
  4183. {
  4184. $s .= 'q ' . $this->TextColor . ' ';
  4185. }
  4186. // count number of spaces
  4187. $ns = substr_count($txt, ' ');
  4188. // Justification
  4189. if (($align == 'J') and ($ns > 0))
  4190. {
  4191. if (($this->CurrentFont['type'] == 'TrueTypeUnicode') or ($this->CurrentFont['type'] == 'cidfont0'))
  4192. {
  4193. // get string width without spaces
  4194. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  4195. // calculate average space width
  4196. $spacewidth = - 1000 * ($w - $width - (2 * $this->cMargin)) / ($ns ? $ns : 1) / $this->FontSize;
  4197. // set word position to be used with TJ operator
  4198. $txt2 = str_replace(chr(0) . ' ', ') ' . ($spacewidth) . ' (', $txt2);
  4199. }
  4200. else
  4201. {
  4202. // get string width
  4203. $width = $txwidth;
  4204. $spacewidth = (($w - $width - (2 * $this->cMargin)) / ($ns ? $ns : 1)) * $this->k;
  4205. // set word spacing
  4206. $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
  4207. }
  4208. $width = $w - (2 * $this->cMargin);
  4209. }
  4210. switch ($align)
  4211. {
  4212. case 'C' :
  4213. {
  4214. $dx = ($w - $width) / 2;
  4215. break;
  4216. }
  4217. case 'R' :
  4218. {
  4219. if ($this->rtl)
  4220. {
  4221. $dx = $this->cMargin;
  4222. }
  4223. else
  4224. {
  4225. $dx = $w - $width - $this->cMargin;
  4226. }
  4227. break;
  4228. }
  4229. case 'L' :
  4230. {
  4231. if ($this->rtl)
  4232. {
  4233. $dx = $w - $width - $this->cMargin;
  4234. }
  4235. else
  4236. {
  4237. $dx = $this->cMargin;
  4238. }
  4239. break;
  4240. }
  4241. case 'J' :
  4242. default :
  4243. {
  4244. $dx = $this->cMargin;
  4245. break;
  4246. }
  4247. }
  4248. if ($this->rtl)
  4249. {
  4250. $xdx = $this->x - $dx - $width;
  4251. }
  4252. else
  4253. {
  4254. $xdx = $this->x + $dx;
  4255. }
  4256. $xdk = $xdx * $k;
  4257. // calculate approximate position of the font base line
  4258. //$basefonty = $this->y + (($h + $this->FontAscent - $this->FontDescent)/2);
  4259. $basefonty = $this->y + ($h / 2) + ($this->FontSize / 3);
  4260. // print text
  4261. $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  4262. if ($this->underline)
  4263. {
  4264. $s .= ' ' . $this->_dounderlinew($xdx, $basefonty, $width);
  4265. }
  4266. if ($this->linethrough)
  4267. {
  4268. $s .= ' ' . $this->_dolinethroughw($xdx, $basefonty, $width);
  4269. }
  4270. if ($this->ColorFlag)
  4271. {
  4272. $s .= ' Q';
  4273. }
  4274. if ($link)
  4275. {
  4276. $this->Link($xdx, $this->y + (($h - $this->FontSize) / 2), $width, $this->FontSize, $link, $ns);
  4277. }
  4278. }
  4279. // output cell
  4280. if ($s)
  4281. {
  4282. // output cell
  4283. $rs .= $s;
  4284. // reset text stretching
  4285. if ($stretch > 2)
  4286. {
  4287. //Reset character horizontal spacing
  4288. $rs .= ' BT 0 Tc ET';
  4289. }
  4290. elseif ($stretch > 0)
  4291. {
  4292. //Reset character horizontal scaling
  4293. $rs .= ' BT 100 Tz ET';
  4294. }
  4295. }
  4296. // reset word spacing
  4297. if (! (($this->CurrentFont['type'] == 'TrueTypeUnicode') or ($this->CurrentFont['type'] == 'cidfont0')) and ($align == 'J'))
  4298. {
  4299. $rs .= ' BT 0 Tw ET';
  4300. }
  4301. $this->lasth = $h;
  4302. if ($ln > 0)
  4303. {
  4304. //Go to the beginning of the next line
  4305. $this->y += $h;
  4306. if ($ln == 1)
  4307. {
  4308. if ($this->rtl)
  4309. {
  4310. $this->x = $this->w - $this->rMargin;
  4311. }
  4312. else
  4313. {
  4314. $this->x = $this->lMargin;
  4315. }
  4316. }
  4317. }
  4318. else
  4319. {
  4320. // go left or right by case
  4321. if ($this->rtl)
  4322. {
  4323. $this->x -= $w;
  4324. }
  4325. else
  4326. {
  4327. $this->x += $w;
  4328. }
  4329. }
  4330. $gstyles = '' . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ' . $this->FillColor . "\n";
  4331. $rs = $gstyles . $rs;
  4332. return $rs;
  4333. }
  4334. /**
  4335. * This method allows printing text with line breaks.
  4336. * 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 />
  4337. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  4338. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  4339. * @param float $h Cell minimum height. The cell extends automatically if needed.
  4340. * @param string $txt String to print
  4341. * @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>
  4342. * @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>
  4343. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  4344. * @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>
  4345. * @param float $x x position in user units
  4346. * @param float $y y position in user units
  4347. * @param boolean $reseth if true reset the last cell height (default true).
  4348. * @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>
  4349. * @param boolean $ishtml set to true if $txt is HTML content (default = false).
  4350. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  4351. * @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.
  4352. * @return int Return the number of cells or 1 for html mode.
  4353. * @access public
  4354. * @since 1.3
  4355. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  4356. */
  4357. 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)
  4358. {
  4359. if ($this->empty_string($this->lasth) or $reseth)
  4360. {
  4361. //set row height
  4362. $this->lasth = $this->FontSize * $this->cell_height_ratio;
  4363. }
  4364. if (! $this->empty_string($y))
  4365. {
  4366. $this->SetY($y);
  4367. }
  4368. else
  4369. {
  4370. $y = $this->GetY();
  4371. }
  4372. // check for page break
  4373. $this->checkPageBreak($h);
  4374. $y = $this->GetY();
  4375. // get current page number
  4376. $startpage = $this->page;
  4377. if (! $this->empty_string($x))
  4378. {
  4379. $this->SetX($x);
  4380. }
  4381. else
  4382. {
  4383. $x = $this->GetX();
  4384. }
  4385. if ($this->empty_string($w) or ($w <= 0))
  4386. {
  4387. if ($this->rtl)
  4388. {
  4389. $w = $this->x - $this->lMargin;
  4390. }
  4391. else
  4392. {
  4393. $w = $this->w - $this->rMargin - $this->x;
  4394. }
  4395. }
  4396. // store original margin values
  4397. $lMargin = $this->lMargin;
  4398. $rMargin = $this->rMargin;
  4399. if ($this->rtl)
  4400. {
  4401. $this->SetRightMargin($this->w - $this->x);
  4402. $this->SetLeftMargin($this->x - $w);
  4403. }
  4404. else
  4405. {
  4406. $this->SetLeftMargin($this->x);
  4407. $this->SetRightMargin($this->w - $this->x - $w);
  4408. }
  4409. $starty = $this->y;
  4410. if ($autopadding)
  4411. {
  4412. // Adjust internal padding
  4413. if ($this->cMargin < ($this->LineWidth / 2))
  4414. {
  4415. $this->cMargin = ($this->LineWidth / 2);
  4416. }
  4417. // Add top space if needed
  4418. if (($this->lasth - $this->FontSize) < $this->LineWidth)
  4419. {
  4420. $this->y += $this->LineWidth / 2;
  4421. }
  4422. // add top padding
  4423. $this->y += $this->cMargin;
  4424. }
  4425. if ($ishtml)
  4426. {
  4427. // ******* Write HTML text
  4428. $this->writeHTML($txt, true, 0, $reseth, true, $align);
  4429. $nl = 1;
  4430. }
  4431. else
  4432. {
  4433. // ******* Write text
  4434. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh);
  4435. }
  4436. if ($autopadding)
  4437. {
  4438. // add bottom padding
  4439. $this->y += $this->cMargin;
  4440. // Add bottom space if needed
  4441. if (($this->lasth - $this->FontSize) < $this->LineWidth)
  4442. {
  4443. $this->y += $this->LineWidth / 2;
  4444. }
  4445. }
  4446. // Get end-of-text Y position
  4447. $currentY = $this->y;
  4448. // get latest page number
  4449. $endpage = $this->page;
  4450. // check if a new page has been created
  4451. if ($endpage > $startpage)
  4452. {
  4453. // design borders around HTML cells.
  4454. for($page = $startpage; $page <= $endpage; ++ $page)
  4455. {
  4456. $this->setPage($page);
  4457. if ($page == $startpage)
  4458. {
  4459. $this->y = $starty; // put cursor at the beginning of cell on the first page
  4460. $h = $this->getPageHeight() - $starty - $this->getBreakMargin();
  4461. $cborder = $this->getBorderMode($border, $position = 'start');
  4462. }
  4463. elseif ($page == $endpage)
  4464. {
  4465. $this->y = $this->tMargin; // put cursor at the beginning of last page
  4466. $h = $currentY - $this->tMargin;
  4467. $cborder = $this->getBorderMode($border, $position = 'end');
  4468. }
  4469. else
  4470. {
  4471. $this->y = $this->tMargin; // put cursor at the beginning of the current page
  4472. $h = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin();
  4473. $cborder = $this->getBorderMode($border, $position = 'middle');
  4474. }
  4475. $nx = $x;
  4476. // account for margin changes
  4477. if ($page > $startpage)
  4478. {
  4479. if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm']))
  4480. {
  4481. $nx = $x + ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  4482. }
  4483. elseif ((! $this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm']))
  4484. {
  4485. $nx = $x + ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  4486. }
  4487. }
  4488. $this->SetX($nx);
  4489. $ccode = $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, false);
  4490. if ($cborder or $fill)
  4491. {
  4492. $pagebuff = $this->getPageBuffer($this->page);
  4493. $pstart = substr($pagebuff, 0, $this->intmrk[$this->page]);
  4494. $pend = substr($pagebuff, $this->intmrk[$this->page]);
  4495. $this->setPageBuffer($this->page, $pstart . $ccode . "\n" . $pend);
  4496. $this->intmrk[$this->page] += strlen($ccode . "\n");
  4497. }
  4498. }
  4499. }
  4500. else
  4501. {
  4502. $h = max($h, ($currentY - $y));
  4503. // put cursor at the beginning of text
  4504. $this->SetY($y);
  4505. $this->SetX($x);
  4506. // design a cell around the text
  4507. $ccode = $this->getCellCode($w, $h, '', $border, 1, '', $fill, '', 0, true);
  4508. if ($border or $fill)
  4509. {
  4510. if (end($this->transfmrk[$this->page]) !== false)
  4511. {
  4512. $pagemarkkey = key($this->transfmrk[$this->page]);
  4513. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  4514. }
  4515. elseif ($this->InFooter)
  4516. {
  4517. $pagemark = &$this->footerpos[$this->page];
  4518. }
  4519. else
  4520. {
  4521. $pagemark = &$this->intmrk[$this->page];
  4522. }
  4523. $pagebuff = $this->getPageBuffer($this->page);
  4524. $pstart = substr($pagebuff, 0, $pagemark);
  4525. $pend = substr($pagebuff, $pagemark);
  4526. $this->setPageBuffer($this->page, $pstart . $ccode . "\n" . $pend);
  4527. $pagemark += strlen($ccode . "\n");
  4528. }
  4529. }
  4530. // Get end-of-cell Y position
  4531. $currentY = $this->GetY();
  4532. // restore original margin values
  4533. $this->SetLeftMargin($lMargin);
  4534. $this->SetRightMargin($rMargin);
  4535. if ($ln > 0)
  4536. {
  4537. //Go to the beginning of the next line
  4538. $this->SetY($currentY);
  4539. if ($ln == 2)
  4540. {
  4541. $this->SetX($x + $w);
  4542. }
  4543. }
  4544. else
  4545. {
  4546. // go left or right by case
  4547. $this->setPage($startpage);
  4548. $this->y = $y;
  4549. $this->SetX($x + $w);
  4550. }
  4551. $this->setContentMark();
  4552. return $nl;
  4553. }
  4554. /**
  4555. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  4556. * @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>
  4557. * @param string multicell position: 'start', 'middle', 'end'
  4558. * @return border mode
  4559. * @access protected
  4560. * @since 4.4.002 (2008-12-09)
  4561. */
  4562. protected function getBorderMode($border, $position = 'start')
  4563. {
  4564. if ((! $this->opencell) and ($border == 1))
  4565. {
  4566. return 1;
  4567. }
  4568. $cborder = '';
  4569. switch ($position)
  4570. {
  4571. case 'start' :
  4572. {
  4573. if ($border == 1)
  4574. {
  4575. $cborder = 'LTR';
  4576. }
  4577. else
  4578. {
  4579. if (! (false === strpos($border, 'L')))
  4580. {
  4581. $cborder .= 'L';
  4582. }
  4583. if (! (false === strpos($border, 'T')))
  4584. {
  4585. $cborder .= 'T';
  4586. }
  4587. if (! (false === strpos($border, 'R')))
  4588. {
  4589. $cborder .= 'R';
  4590. }
  4591. if ((! $this->opencell) and (! (false === strpos($border, 'B'))))
  4592. {
  4593. $cborder .= 'B';
  4594. }
  4595. }
  4596. break;
  4597. }
  4598. case 'middle' :
  4599. {
  4600. if ($border == 1)
  4601. {
  4602. $cborder = 'LR';
  4603. }
  4604. else
  4605. {
  4606. if (! (false === strpos($border, 'L')))
  4607. {
  4608. $cborder .= 'L';
  4609. }
  4610. if ((! $this->opencell) and (! (false === strpos($border, 'T'))))
  4611. {
  4612. $cborder .= 'T';
  4613. }
  4614. if (! (false === strpos($border, 'R')))
  4615. {
  4616. $cborder .= 'R';
  4617. }
  4618. if ((! $this->opencell) and (! (false === strpos($border, 'B'))))
  4619. {
  4620. $cborder .= 'B';
  4621. }
  4622. }
  4623. break;
  4624. }
  4625. case 'end' :
  4626. {
  4627. if ($border == 1)
  4628. {
  4629. $cborder = 'LRB';
  4630. }
  4631. else
  4632. {
  4633. if (! (false === strpos($border, 'L')))
  4634. {
  4635. $cborder .= 'L';
  4636. }
  4637. if ((! $this->opencell) and (! (false === strpos($border, 'T'))))
  4638. {
  4639. $cborder .= 'T';
  4640. }
  4641. if (! (false === strpos($border, 'R')))
  4642. {
  4643. $cborder .= 'R';
  4644. }
  4645. if (! (false === strpos($border, 'B')))
  4646. {
  4647. $cborder .= 'B';
  4648. }
  4649. }
  4650. break;
  4651. }
  4652. default :
  4653. {
  4654. $cborder = $border;
  4655. break;
  4656. }
  4657. }
  4658. return $cborder;
  4659. }
  4660. /**
  4661. * This method returns the estimated number of lines required to print the text.
  4662. * @param string $txt text to print
  4663. * @param float $w width of cell. If 0, they extend up to the right margin of the page.
  4664. * @return int Return the estimated number of lines.
  4665. * @access public
  4666. * @since 4.5.011
  4667. */
  4668. public function getNumLines($txt, $w = 0)
  4669. {
  4670. $lines = 0;
  4671. if ($this->empty_string($w) or ($w <= 0))
  4672. {
  4673. if ($this->rtl)
  4674. {
  4675. $w = $this->x - $this->lMargin;
  4676. }
  4677. else
  4678. {
  4679. $w = $this->w - $this->rMargin - $this->x;
  4680. }
  4681. }
  4682. // max column width
  4683. $wmax = $w - (2 * $this->cMargin);
  4684. // remove carriage returns
  4685. $txt = str_replace("\r", '', $txt);
  4686. // remove last newline (if any)
  4687. if (substr($txt, - 1) == "\n")
  4688. {
  4689. $txt = substr($txt, 0, - 1);
  4690. }
  4691. // divide text in blocks
  4692. $txtblocks = explode("\n", $txt);
  4693. // for each text block
  4694. foreach ($txtblocks as $block)
  4695. {
  4696. // estimate the number of lines
  4697. $lines += $this->empty_string($block) ? 1 : (ceil($this->GetStringWidth($block) / $wmax));
  4698. }
  4699. // return the number of lines
  4700. return $lines;
  4701. }
  4702. /**
  4703. * This method prints text from the current position.<br />
  4704. * @param float $h Line height
  4705. * @param string $txt String to print
  4706. * @param mixed $link URL or identifier returned by AddLink()
  4707. * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  4708. * @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>
  4709. * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  4710. * @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>
  4711. * @param boolean $firstline if true prints only the first line and return the remaining string.
  4712. * @param boolean $firstblock if true the string is the starting of a line.
  4713. * @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.
  4714. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  4715. * @access public
  4716. * @since 1.5
  4717. */
  4718. public function Write($h, $txt, $link = '', $fill = 0, $align = '', $ln = false, $stretch = 0, $firstline = false, $firstblock = false, $maxh = 0)
  4719. {
  4720. if (strlen($txt) == 0)
  4721. {
  4722. $txt = ' ';
  4723. }
  4724. // remove carriage returns
  4725. $s = str_replace("\r", '', $txt);
  4726. // check if string contains arabic text
  4727. if (preg_match(K_RE_PATTERN_ARABIC, $s))
  4728. {
  4729. $arabic = true;
  4730. }
  4731. else
  4732. {
  4733. $arabic = false;
  4734. }
  4735. // check if string contains RTL text
  4736. if ($arabic or ($this->tmprtl == 'R') or preg_match(K_RE_PATTERN_RTL, $txt))
  4737. {
  4738. $rtlmode = true;
  4739. }
  4740. else
  4741. {
  4742. $rtlmode = false;
  4743. }
  4744. // get a char width
  4745. $chrwidth = $this->GetCharWidth('.');
  4746. // get array of unicode values
  4747. $chars = $this->UTF8StringToArray($s);
  4748. // get array of chars
  4749. $uchars = $this->UTF8ArrayToUniArray($chars);
  4750. // get the number of characters
  4751. $nb = count($chars);
  4752. // replacement for SHY character (minus symbol)
  4753. $shy_replacement = 45;
  4754. $shy_replacement_char = $this->unichr($shy_replacement);
  4755. // widht for SHY replacement
  4756. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  4757. // store current position
  4758. $prevx = $this->x;
  4759. $prevy = $this->y;
  4760. // max Y
  4761. $maxy = $this->y + $maxh - $h - (2 * $this->cMargin);
  4762. // calculate remaining line width ($w)
  4763. if ($this->rtl)
  4764. {
  4765. $w = $this->x - $this->lMargin;
  4766. }
  4767. else
  4768. {
  4769. $w = $this->w - $this->rMargin - $this->x;
  4770. }
  4771. // max column width
  4772. $wmax = $w - (2 * $this->cMargin);
  4773. if ((! $firstline) and (($chrwidth > $wmax) or ($this->GetCharWidth($chars[0]) > $wmax)))
  4774. {
  4775. // a single character do not fit on column
  4776. return '';
  4777. }
  4778. $i = 0; // character position
  4779. $j = 0; // current starting position
  4780. $sep = - 1; // position of the last blank space
  4781. $shy = false; // true if the last blank is a soft hypen (SHY)
  4782. $l = 0; // current string length
  4783. $nl = 0; //number of lines
  4784. $linebreak = false;
  4785. $pc = 0; // previous character
  4786. // for each character
  4787. while ($i < $nb)
  4788. {
  4789. if (($maxh > 0) and ($this->y >= $maxy))
  4790. {
  4791. break;
  4792. }
  4793. //Get the current character
  4794. $c = $chars[$i];
  4795. if ($c == 10)
  4796. { // 10 = "\n" = new line
  4797. //Explicit line break
  4798. if ($align == 'J')
  4799. {
  4800. if ($this->rtl)
  4801. {
  4802. $talign = 'R';
  4803. }
  4804. else
  4805. {
  4806. $talign = 'L';
  4807. }
  4808. }
  4809. else
  4810. {
  4811. $talign = $align;
  4812. }
  4813. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  4814. if ($firstline)
  4815. {
  4816. $startx = $this->x;
  4817. $tmparr = array_slice($chars, $j, ($i - $j));
  4818. if ($rtlmode)
  4819. {
  4820. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  4821. }
  4822. $linew = $this->GetArrStringWidth($tmparr);
  4823. unset($tmparr);
  4824. if ($this->rtl)
  4825. {
  4826. $this->endlinex = $startx - $linew;
  4827. }
  4828. else
  4829. {
  4830. $this->endlinex = $startx + $linew;
  4831. }
  4832. $w = $linew;
  4833. $tmpcmargin = $this->cMargin;
  4834. if ($maxh == 0)
  4835. {
  4836. $this->cMargin = 0;
  4837. }
  4838. }
  4839. if ($firstblock and $this->isRTLTextDir())
  4840. {
  4841. $tmpstr = rtrim($tmpstr);
  4842. }
  4843. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  4844. unset($tmpstr);
  4845. if ($firstline)
  4846. {
  4847. $this->cMargin = $tmpcmargin;
  4848. return ($this->UniArrSubString($uchars, $i));
  4849. }
  4850. ++ $nl;
  4851. $j = $i + 1;
  4852. $l = 0;
  4853. $sep = - 1;
  4854. $shy = false;
  4855. // account for margin changes
  4856. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and (! $this->InFooter))
  4857. {
  4858. // AcceptPageBreak() may be overriden on extended classed to include margin changes
  4859. $this->AcceptPageBreak();
  4860. }
  4861. $w = $this->getRemainingWidth();
  4862. $wmax = $w - (2 * $this->cMargin);
  4863. }
  4864. else
  4865. {
  4866. // 160 is the non-breaking space.
  4867. // 173 is SHY (Soft Hypen).
  4868. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  4869. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  4870. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  4871. if (($c != 160) and (($c == 173) or preg_match($this->re_spaces, $this->unichr($c))))
  4872. {
  4873. // update last blank space position
  4874. $sep = $i;
  4875. // check if is a SHY
  4876. if ($c == 173)
  4877. {
  4878. $shy = true;
  4879. if ($pc == 45)
  4880. {
  4881. $tmp_shy_replacement_width = 0;
  4882. $tmp_shy_replacement_char = '';
  4883. }
  4884. else
  4885. {
  4886. $tmp_shy_replacement_width = $shy_replacement_width;
  4887. $tmp_shy_replacement_char = $shy_replacement_char;
  4888. }
  4889. }
  4890. else
  4891. {
  4892. $shy = false;
  4893. }
  4894. }
  4895. // update string length
  4896. if ((($this->CurrentFont['type'] == 'TrueTypeUnicode') or ($this->CurrentFont['type'] == 'cidfont0')) and ($arabic))
  4897. {
  4898. // with bidirectional algorithm some chars may be changed affecting the line length
  4899. // *** very slow ***
  4900. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  4901. }
  4902. else
  4903. {
  4904. $l += $this->GetCharWidth($c);
  4905. }
  4906. if (($l > $wmax) or ($shy and (($l + $tmp_shy_replacement_width) > $wmax)))
  4907. {
  4908. // we have reached the end of column
  4909. if ($sep == - 1)
  4910. {
  4911. // check if the line was already started
  4912. if (($this->rtl and ($this->x <= ($this->w - $this->rMargin - $chrwidth))) or ((! $this->rtl) and ($this->x >= ($this->lMargin + $chrwidth))))
  4913. {
  4914. // print a void cell and go to next line
  4915. $this->Cell($w, $h, '', 0, 1);
  4916. $linebreak = true;
  4917. if ($firstline)
  4918. {
  4919. return ($this->UniArrSubString($uchars, $j));
  4920. }
  4921. }
  4922. else
  4923. {
  4924. // truncate the word because do not fit on column
  4925. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  4926. if ($firstline)
  4927. {
  4928. $startx = $this->x;
  4929. $tmparr = array_slice($chars, $j, ($i - $j));
  4930. if ($rtlmode)
  4931. {
  4932. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  4933. }
  4934. $linew = $this->GetArrStringWidth($tmparr);
  4935. unset($tmparr);
  4936. if ($this->rtl)
  4937. {
  4938. $this->endlinex = $startx - $linew;
  4939. }
  4940. else
  4941. {
  4942. $this->endlinex = $startx + $linew;
  4943. }
  4944. $w = $linew;
  4945. $tmpcmargin = $this->cMargin;
  4946. if ($maxh == 0)
  4947. {
  4948. $this->cMargin = 0;
  4949. }
  4950. }
  4951. if ($firstblock and $this->isRTLTextDir())
  4952. {
  4953. $tmpstr = rtrim($tmpstr);
  4954. }
  4955. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  4956. unset($tmpstr);
  4957. if ($firstline)
  4958. {
  4959. $this->cMargin = $tmpcmargin;
  4960. return ($this->UniArrSubString($uchars, $i));
  4961. }
  4962. $j = $i;
  4963. -- $i;
  4964. }
  4965. }
  4966. else
  4967. {
  4968. // word wrapping
  4969. if ($this->rtl and (! $firstblock))
  4970. {
  4971. $endspace = 1;
  4972. }
  4973. else
  4974. {
  4975. $endspace = 0;
  4976. }
  4977. if ($shy)
  4978. {
  4979. // add hypen (minus symbol) at the end of the line
  4980. $shy_width = $tmp_shy_replacement_width;
  4981. if ($this->rtl)
  4982. {
  4983. $shy_char_left = $tmp_shy_replacement_char;
  4984. $shy_char_right = '';
  4985. }
  4986. else
  4987. {
  4988. $shy_char_left = '';
  4989. $shy_char_right = $tmp_shy_replacement_char;
  4990. }
  4991. }
  4992. else
  4993. {
  4994. $shy_width = 0;
  4995. $shy_char_left = '';
  4996. $shy_char_right = '';
  4997. }
  4998. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  4999. if ($firstline)
  5000. {
  5001. $startx = $this->x;
  5002. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  5003. if ($rtlmode)
  5004. {
  5005. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  5006. }
  5007. $linew = $this->GetArrStringWidth($tmparr);
  5008. unset($tmparr);
  5009. if ($this->rtl)
  5010. {
  5011. $this->endlinex = $startx - $linew - $shy_width;
  5012. }
  5013. else
  5014. {
  5015. $this->endlinex = $startx + $linew + $shy_width;
  5016. }
  5017. $w = $linew;
  5018. $tmpcmargin = $this->cMargin;
  5019. if ($maxh == 0)
  5020. {
  5021. $this->cMargin = 0;
  5022. }
  5023. }
  5024. // print the line
  5025. if ($firstblock and $this->isRTLTextDir())
  5026. {
  5027. $tmpstr = rtrim($tmpstr);
  5028. }
  5029. $this->Cell($w, $h, $shy_char_left . $tmpstr . $shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  5030. unset($tmpstr);
  5031. if ($firstline)
  5032. {
  5033. // return the remaining text
  5034. $this->cMargin = $tmpcmargin;
  5035. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  5036. }
  5037. $i = $sep;
  5038. $sep = - 1;
  5039. $shy = false;
  5040. $j = ($i + 1);
  5041. }
  5042. // account for margin changes
  5043. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and (! $this->InFooter))
  5044. {
  5045. // AcceptPageBreak() may be overriden on extended classed to include margin changes
  5046. $this->AcceptPageBreak();
  5047. }
  5048. $w = $this->getRemainingWidth();
  5049. $wmax = $w - (2 * $this->cMargin);
  5050. if ($linebreak)
  5051. {
  5052. $linebreak = false;
  5053. }
  5054. else
  5055. {
  5056. ++ $nl;
  5057. $l = 0;
  5058. }
  5059. }
  5060. }
  5061. // save last character
  5062. $pc = $c;
  5063. ++ $i;
  5064. } // end while i < nb
  5065. // print last substring (if any)
  5066. if ($l > 0)
  5067. {
  5068. switch ($align)
  5069. {
  5070. case 'J' :
  5071. case 'C' :
  5072. {
  5073. $w = $w;
  5074. break;
  5075. }
  5076. case 'L' :
  5077. {
  5078. if ($this->rtl)
  5079. {
  5080. $w = $w;
  5081. }
  5082. else
  5083. {
  5084. $w = $l;
  5085. }
  5086. break;
  5087. }
  5088. case 'R' :
  5089. {
  5090. if ($this->rtl)
  5091. {
  5092. $w = $l;
  5093. }
  5094. else
  5095. {
  5096. $w = $w;
  5097. }
  5098. break;
  5099. }
  5100. default :
  5101. {
  5102. $w = $l;
  5103. break;
  5104. }
  5105. }
  5106. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  5107. if ($firstline)
  5108. {
  5109. $startx = $this->x;
  5110. $tmparr = array_slice($chars, $j, ($nb - $j));
  5111. if ($rtlmode)
  5112. {
  5113. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  5114. }
  5115. $linew = $this->GetArrStringWidth($tmparr);
  5116. unset($tmparr);
  5117. if ($this->rtl)
  5118. {
  5119. $this->endlinex = $startx - $linew;
  5120. }
  5121. else
  5122. {
  5123. $this->endlinex = $startx + $linew;
  5124. }
  5125. $w = $linew;
  5126. $tmpcmargin = $this->cMargin;
  5127. if ($maxh == 0)
  5128. {
  5129. $this->cMargin = 0;
  5130. }
  5131. }
  5132. if ($firstblock and $this->isRTLTextDir())
  5133. {
  5134. $tmpstr = rtrim($tmpstr);
  5135. }
  5136. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  5137. unset($tmpstr);
  5138. if ($firstline)
  5139. {
  5140. $this->cMargin = $tmpcmargin;
  5141. return ($this->UniArrSubString($uchars, $nb));
  5142. }
  5143. ++ $nl;
  5144. }
  5145. if ($firstline)
  5146. {
  5147. return '';
  5148. }
  5149. return $nl;
  5150. }
  5151. /**
  5152. * Returns the remaining width between the current position and margins.
  5153. * @return int Return the remaining width
  5154. * @access protected
  5155. */
  5156. protected function getRemainingWidth()
  5157. {
  5158. if ($this->rtl)
  5159. {
  5160. return ($this->x - $this->lMargin);
  5161. }
  5162. else
  5163. {
  5164. return ($this->w - $this->rMargin - $this->x);
  5165. }
  5166. }
  5167. /**
  5168. * Extract a slice of the $strarr array and return it as string.
  5169. * @param string $strarr The input array of characters.
  5170. * @param int $start the starting element of $strarr.
  5171. * @param int $end first element that will not be returned.
  5172. * @return Return part of a string
  5173. * @access public
  5174. */
  5175. public function UTF8ArrSubString($strarr, $start = '', $end = '')
  5176. {
  5177. if (strlen($start) == 0)
  5178. {
  5179. $start = 0;
  5180. }
  5181. if (strlen($end) == 0)
  5182. {
  5183. $end = count($strarr);
  5184. }
  5185. $string = '';
  5186. for($i = $start; $i < $end; ++ $i)
  5187. {
  5188. $string .= $this->unichr($strarr[$i]);
  5189. }
  5190. return $string;
  5191. }
  5192. /**
  5193. * Extract a slice of the $uniarr array and return it as string.
  5194. * @param string $uniarr The input array of characters.
  5195. * @param int $start the starting element of $strarr.
  5196. * @param int $end first element that will not be returned.
  5197. * @return Return part of a string
  5198. * @access public
  5199. * @since 4.5.037 (2009-04-07)
  5200. */
  5201. public function UniArrSubString($uniarr, $start = '', $end = '')
  5202. {
  5203. if (strlen($start) == 0)
  5204. {
  5205. $start = 0;
  5206. }
  5207. if (strlen($end) == 0)
  5208. {
  5209. $end = count($uniarr);
  5210. }
  5211. $string = '';
  5212. for($i = $start; $i < $end; ++ $i)
  5213. {
  5214. $string .= $uniarr[$i];
  5215. }
  5216. return $string;
  5217. }
  5218. /**
  5219. * Convert an array of UTF8 values to array of unicode characters
  5220. * @param string $ta The input array of UTF8 values.
  5221. * @return Return array of unicode characters
  5222. * @access public
  5223. * @since 4.5.037 (2009-04-07)
  5224. */
  5225. public function UTF8ArrayToUniArray($ta)
  5226. {
  5227. return array_map(array($this, 'unichr'), $ta);
  5228. }
  5229. /**
  5230. * Returns the unicode caracter specified by UTF-8 code
  5231. * @param int $c UTF-8 code
  5232. * @return Returns the specified character.
  5233. * @author Miguel Perez, Nicola Asuni
  5234. * @access public
  5235. * @since 2.3.000 (2008-03-05)
  5236. */
  5237. public function unichr($c)
  5238. {
  5239. if (! $this->isunicode)
  5240. {
  5241. return chr($c);
  5242. }
  5243. elseif ($c <= 0x7F)
  5244. {
  5245. // one byte
  5246. return chr($c);
  5247. }
  5248. elseif ($c <= 0x7FF)
  5249. {
  5250. // two bytes
  5251. return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
  5252. }
  5253. elseif ($c <= 0xFFFF)
  5254. {
  5255. // three bytes
  5256. return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  5257. }
  5258. elseif ($c <= 0x10FFFF)
  5259. {
  5260. // four bytes
  5261. return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  5262. }
  5263. else
  5264. {
  5265. return '';
  5266. }
  5267. }
  5268. /**
  5269. * Return the image type given the file name and path
  5270. * @param string $imgfile image file name
  5271. * @return string image type
  5272. * @since 4.8.017 (2009-11-27)
  5273. */
  5274. public function getImageFileType($imgfile)
  5275. {
  5276. $type = ''; // default type
  5277. $fileinfo = pathinfo($imgfile);
  5278. if (isset($fileinfo['extension']) and (! $this->empty_string($fileinfo['extension'])))
  5279. {
  5280. $type = strtolower($fileinfo['extension']);
  5281. }
  5282. if ($type == 'jpg')
  5283. {
  5284. $type = 'jpeg';
  5285. }
  5286. return $type;
  5287. }
  5288. /**
  5289. * Puts an image in the page.
  5290. * The upper-left corner must be given.
  5291. * The dimensions can be specified in different ways:<ul>
  5292. * <li>explicit width and height (expressed in user unit)</li>
  5293. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  5294. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  5295. * 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;
  5296. * The format can be specified explicitly or inferred from the file extension.<br />
  5297. * It is possible to put a link on the image.<br />
  5298. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  5299. * @param string $file Name of the file containing the image.
  5300. * @param float $x Abscissa of the upper-left corner.
  5301. * @param float $y Ordinate of the upper-left corner.
  5302. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5303. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5304. * @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.
  5305. * @param mixed $link URL or identifier returned by AddLink().
  5306. * @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>
  5307. * @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).
  5308. * @param int $dpi dot-per-inch resolution used on resize
  5309. * @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>
  5310. * @param boolean $ismask true if this image is a mask, false otherwise
  5311. * @param mixed $imgmask image object returned by this function or false
  5312. * @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>
  5313. * @param boolean $fitbox If true scale image dimensions proportionally to fit within the ($w, $h) box.
  5314. * @param boolean $hidden if true do not display the image.
  5315. * @return image information
  5316. * @access public
  5317. * @since 1.1
  5318. */
  5319. 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)
  5320. {
  5321. if ($x === '')
  5322. {
  5323. $x = $this->x;
  5324. }
  5325. if ($y === '')
  5326. {
  5327. $y = $this->y;
  5328. }
  5329. // get image dimensions
  5330. $imsize = @getimagesize($file);
  5331. if ($imsize === FALSE)
  5332. {
  5333. // encode spaces on filename
  5334. $file = str_replace(' ', '%20', $file);
  5335. $imsize = @getimagesize($file);
  5336. if ($imsize === FALSE)
  5337. {
  5338. $this->Error('[Image] No such file or directory in ' . $file);
  5339. }
  5340. }
  5341. // get original image width and height in pixels
  5342. list($pixw, $pixh) = $imsize;
  5343. // calculate image width and height on document
  5344. if (($w <= 0) and ($h <= 0))
  5345. {
  5346. // convert image size to document unit
  5347. $w = $this->pixelsToUnits($pixw);
  5348. $h = $this->pixelsToUnits($pixh);
  5349. }
  5350. elseif ($w <= 0)
  5351. {
  5352. $w = $h * $pixw / $pixh;
  5353. }
  5354. elseif ($h <= 0)
  5355. {
  5356. $h = $w * $pixh / $pixw;
  5357. }
  5358. elseif ($fitbox and ($w > 0) and ($h > 0))
  5359. {
  5360. // scale image dimensions proportionally to fit within the ($w, $h) box
  5361. if ((($w * $pixh) / ($h * $pixw)) < 1)
  5362. {
  5363. $h = $w * $pixh / $pixw;
  5364. }
  5365. else
  5366. {
  5367. $w = $h * $pixw / $pixh;
  5368. }
  5369. }
  5370. // resize image proportionally to be contained on a single page
  5371. if ($h > $this->h)
  5372. {
  5373. $h = $this->h;
  5374. $w = $h * $pixw / $pixh;
  5375. }
  5376. if ($w > $this->w)
  5377. {
  5378. $w = $this->w;
  5379. $h = $w * $pixh / $pixw;
  5380. }
  5381. // Check whether we need a new page first as this does not fit
  5382. $prev_x = $this->x;
  5383. if ($this->checkPageBreak($h, $y))
  5384. {
  5385. // resize image to vertically fit the available space
  5386. $h = $this->PageBreakTrigger - $y;
  5387. $w = $h * $pixw / $pixh;
  5388. $y = $this->GetY(); // + $this->cMargin;
  5389. if ($this->rtl)
  5390. {
  5391. $x += ($prev_x - $this->x);
  5392. }
  5393. else
  5394. {
  5395. $x += ($this->x - $prev_x);
  5396. }
  5397. }
  5398. // resize image proportionally to be contained on a single page
  5399. if (($x + $w) > $this->w)
  5400. {
  5401. $w = $this->w - $x;
  5402. $h = $w * $pixh / $pixw;
  5403. }
  5404. // calculate new minimum dimensions in pixels
  5405. $neww = round($w * $this->k * $dpi / $this->dpi);
  5406. $newh = round($h * $this->k * $dpi / $this->dpi);
  5407. // check if resize is necessary (resize is used only to reduce the image)
  5408. $newsize = ($neww * $newh);
  5409. $pixsize = ($pixw * $pixh);
  5410. if (intval($resize) == 2)
  5411. {
  5412. $resize = true;
  5413. }
  5414. elseif ($newsize >= $pixsize)
  5415. {
  5416. $resize = false;
  5417. }
  5418. // check if image has been already added on document
  5419. $newimage = true;
  5420. if (in_array($file, $this->imagekeys))
  5421. {
  5422. $newimage = false;
  5423. // get existing image data
  5424. $info = $this->getImageBuffer($file);
  5425. // check if the newer image is larger
  5426. $oldsize = ($info['w'] * $info['h']);
  5427. if ((($oldsize < $newsize) and ($resize)) or (($oldsize < $pixsize) and (! $resize)))
  5428. {
  5429. $newimage = true;
  5430. }
  5431. }
  5432. if ($newimage)
  5433. {
  5434. //First use of image, get info
  5435. if ($type == '')
  5436. {
  5437. $type = $this->getImageFileType($file);
  5438. }
  5439. $mqr = $this->get_mqr();
  5440. $this->set_mqr(false);
  5441. // Specific image handlers
  5442. $mtd = '_parse' . $type;
  5443. // GD image handler function
  5444. $gdfunction = 'imagecreatefrom' . $type;
  5445. $info = false;
  5446. if ((method_exists($this, $mtd)) and (! ($resize and function_exists($gdfunction))))
  5447. {
  5448. // TCPDF image functions
  5449. $info = $this->$mtd($file);
  5450. if ($info == 'pngalpha')
  5451. {
  5452. return $this->ImagePngAlpha($file, $x, $y, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign);
  5453. }
  5454. }
  5455. if (! $info)
  5456. {
  5457. if (function_exists($gdfunction))
  5458. {
  5459. // GD library
  5460. $img = $gdfunction($file);
  5461. if ($resize)
  5462. {
  5463. $imgr = imagecreatetruecolor($neww, $newh);
  5464. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  5465. $info = $this->_toJPEG($imgr);
  5466. }
  5467. else
  5468. {
  5469. $info = $this->_toJPEG($img);
  5470. }
  5471. }
  5472. elseif (extension_loaded('imagick'))
  5473. {
  5474. // ImageMagick library
  5475. $img = new Imagick();
  5476. $img->readImage($file);
  5477. if ($resize)
  5478. {
  5479. $img->resizeImage($neww, $newh, 10, 1, false);
  5480. }
  5481. $img->setCompressionQuality($this->jpeg_quality);
  5482. $img->setImageFormat('jpeg');
  5483. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  5484. $img->writeImage($tempname);
  5485. $info = $this->_parsejpeg($tempname);
  5486. unlink($tempname);
  5487. $img->destroy();
  5488. }
  5489. else
  5490. {
  5491. return;
  5492. }
  5493. }
  5494. if ($info === false)
  5495. {
  5496. //If false, we cannot process image
  5497. return;
  5498. }
  5499. $this->set_mqr($mqr);
  5500. if ($ismask)
  5501. {
  5502. // force grayscale
  5503. $info['cs'] = 'DeviceGray';
  5504. }
  5505. $info['i'] = $this->numimages;
  5506. if (! in_array($file, $this->imagekeys))
  5507. {
  5508. ++ $info['i'];
  5509. }
  5510. if ($imgmask !== false)
  5511. {
  5512. $info['masked'] = $imgmask;
  5513. }
  5514. // add image to document
  5515. $this->setImageBuffer($file, $info);
  5516. }
  5517. // set bottomcoordinates
  5518. $this->img_rb_y = $y + $h;
  5519. // set alignment
  5520. if ($this->rtl)
  5521. {
  5522. if ($palign == 'L')
  5523. {
  5524. $ximg = $this->lMargin;
  5525. // set right side coordinate
  5526. $this->img_rb_x = $ximg + $w;
  5527. }
  5528. elseif ($palign == 'C')
  5529. {
  5530. $ximg = ($this->w - $x - $w) / 2;
  5531. // set right side coordinate
  5532. $this->img_rb_x = $ximg + $w;
  5533. }
  5534. else
  5535. {
  5536. $ximg = $this->w - $x - $w;
  5537. // set left side coordinate
  5538. $this->img_rb_x = $ximg;
  5539. }
  5540. }
  5541. else
  5542. {
  5543. if ($palign == 'R')
  5544. {
  5545. $ximg = $this->w - $this->rMargin - $w;
  5546. // set left side coordinate
  5547. $this->img_rb_x = $ximg;
  5548. }
  5549. elseif ($palign == 'C')
  5550. {
  5551. $ximg = ($this->w - $x - $w) / 2;
  5552. // set right side coordinate
  5553. $this->img_rb_x = $ximg + $w;
  5554. }
  5555. else
  5556. {
  5557. $ximg = $x;
  5558. // set right side coordinate
  5559. $this->img_rb_x = $ximg + $w;
  5560. }
  5561. }
  5562. if ($ismask or $hidden)
  5563. {
  5564. // image is not displayed
  5565. return $info['i'];
  5566. }
  5567. $xkimg = $ximg * $this->k;
  5568. $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']));
  5569. if (! empty($border))
  5570. {
  5571. $bx = $x;
  5572. $by = $y;
  5573. $this->x = $ximg;
  5574. $this->y = $y;
  5575. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0);
  5576. $this->x = $bx;
  5577. $this->y = $by;
  5578. }
  5579. if ($link)
  5580. {
  5581. $this->Link($ximg, $y, $w, $h, $link, 0);
  5582. }
  5583. // set pointer to align the successive text/objects
  5584. switch ($align)
  5585. {
  5586. case 'T' :
  5587. {
  5588. $this->y = $y;
  5589. $this->x = $this->img_rb_x;
  5590. break;
  5591. }
  5592. case 'M' :
  5593. {
  5594. $this->y = $y + round($h / 2);
  5595. $this->x = $this->img_rb_x;
  5596. break;
  5597. }
  5598. case 'B' :
  5599. {
  5600. $this->y = $this->img_rb_y;
  5601. $this->x = $this->img_rb_x;
  5602. break;
  5603. }
  5604. case 'N' :
  5605. {
  5606. $this->SetY($this->img_rb_y);
  5607. break;
  5608. }
  5609. default :
  5610. {
  5611. break;
  5612. }
  5613. }
  5614. $this->endlinex = $this->img_rb_x;
  5615. return $info['i'];
  5616. }
  5617. /**
  5618. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  5619. * @param boolean $mqr FALSE for off, TRUE for on.
  5620. * @since 4.6.025 (2009-08-17)
  5621. */
  5622. public function set_mqr($mqr)
  5623. {
  5624. if (! defined('PHP_VERSION_ID'))
  5625. {
  5626. $version = PHP_VERSION;
  5627. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  5628. }
  5629. if (PHP_VERSION_ID < 50300)
  5630. {
  5631. @set_magic_quotes_runtime($mqr);
  5632. }
  5633. }
  5634. /**
  5635. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  5636. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  5637. * @since 4.6.025 (2009-08-17)
  5638. */
  5639. public function get_mqr()
  5640. {
  5641. if (! defined('PHP_VERSION_ID'))
  5642. {
  5643. $version = PHP_VERSION;
  5644. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  5645. }
  5646. if (PHP_VERSION_ID < 50300)
  5647. {
  5648. return @get_magic_quotes_runtime();
  5649. }
  5650. return 0;
  5651. }
  5652. /**
  5653. * Convert the loaded php image to a JPEG and then return a structure for the PDF creator.
  5654. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  5655. * @param string $file Image file name.
  5656. * @param image $image Image object.
  5657. * return image JPEG image object.
  5658. * @access protected
  5659. */
  5660. protected function _toJPEG($image)
  5661. {
  5662. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  5663. imagejpeg($image, $tempname, $this->jpeg_quality);
  5664. imagedestroy($image);
  5665. $retvars = $this->_parsejpeg($tempname);
  5666. // tidy up by removing temporary image
  5667. unlink($tempname);
  5668. return $retvars;
  5669. }
  5670. /**
  5671. * Extract info from a JPEG file without using the GD library.
  5672. * @param string $file image file to parse
  5673. * @return array structure containing the image data
  5674. * @access protected
  5675. */
  5676. protected function _parsejpeg($file)
  5677. {
  5678. $a = getimagesize($file);
  5679. if (empty($a))
  5680. {
  5681. $this->Error('Missing or incorrect image file: ' . $file);
  5682. }
  5683. if ($a[2] != 2)
  5684. {
  5685. $this->Error('Not a JPEG file: ' . $file);
  5686. }
  5687. if ((! isset($a['channels'])) or ($a['channels'] == 3))
  5688. {
  5689. $colspace = 'DeviceRGB';
  5690. }
  5691. elseif ($a['channels'] == 4)
  5692. {
  5693. $colspace = 'DeviceCMYK';
  5694. }
  5695. else
  5696. {
  5697. $colspace = 'DeviceGray';
  5698. }
  5699. $bpc = isset($a['bits']) ? $a['bits'] : 8;
  5700. $data = file_get_contents($file);
  5701. return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode',
  5702. 'data' => $data);
  5703. }
  5704. /**
  5705. * Extract info from a PNG file without using the GD library.
  5706. * @param string $file image file to parse
  5707. * @return array structure containing the image data
  5708. * @access protected
  5709. */
  5710. protected function _parsepng($file)
  5711. {
  5712. $f = fopen($file, 'rb');
  5713. if ($f === false)
  5714. {
  5715. $this->Error('Can\'t open image file: ' . $file);
  5716. }
  5717. //Check signature
  5718. if (fread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10))
  5719. {
  5720. $this->Error('Not a PNG file: ' . $file);
  5721. }
  5722. //Read header chunk
  5723. fread($f, 4);
  5724. if (fread($f, 4) != 'IHDR')
  5725. {
  5726. $this->Error('Incorrect PNG file: ' . $file);
  5727. }
  5728. $w = $this->_freadint($f);
  5729. $h = $this->_freadint($f);
  5730. $bpc = ord(fread($f, 1));
  5731. if ($bpc > 8)
  5732. {
  5733. //$this->Error('16-bit depth not supported: '.$file);
  5734. fclose($f);
  5735. return false;
  5736. }
  5737. $ct = ord(fread($f, 1));
  5738. if ($ct == 0)
  5739. {
  5740. $colspace = 'DeviceGray';
  5741. }
  5742. elseif ($ct == 2)
  5743. {
  5744. $colspace = 'DeviceRGB';
  5745. }
  5746. elseif ($ct == 3)
  5747. {
  5748. $colspace = 'Indexed';
  5749. }
  5750. else
  5751. {
  5752. // alpha channel
  5753. fclose($f);
  5754. return 'pngalpha';
  5755. }
  5756. if (ord(fread($f, 1)) != 0)
  5757. {
  5758. //$this->Error('Unknown compression method: '.$file);
  5759. fclose($f);
  5760. return false;
  5761. }
  5762. if (ord(fread($f, 1)) != 0)
  5763. {
  5764. //$this->Error('Unknown filter method: '.$file);
  5765. fclose($f);
  5766. return false;
  5767. }
  5768. if (ord(fread($f, 1)) != 0)
  5769. {
  5770. //$this->Error('Interlacing not supported: '.$file);
  5771. fclose($f);
  5772. return false;
  5773. }
  5774. fread($f, 4);
  5775. $parms = '/DecodeParms <</Predictor 15 /Colors ' . ($ct == 2 ? 3 : 1) . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . '>>';
  5776. //Scan chunks looking for palette, transparency and image data
  5777. $pal = '';
  5778. $trns = '';
  5779. $data = '';
  5780. do
  5781. {
  5782. $n = $this->_freadint($f);
  5783. $type = fread($f, 4);
  5784. if ($type == 'PLTE')
  5785. {
  5786. //Read palette
  5787. $pal = $this->rfread($f, $n);
  5788. fread($f, 4);
  5789. }
  5790. elseif ($type == 'tRNS')
  5791. {
  5792. //Read transparency info
  5793. $t = $this->rfread($f, $n);
  5794. if ($ct == 0)
  5795. {
  5796. $trns = array(ord(substr($t, 1, 1)));
  5797. }
  5798. elseif ($ct == 2)
  5799. {
  5800. $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
  5801. }
  5802. else
  5803. {
  5804. $pos = strpos($t, chr(0));
  5805. if ($pos !== false)
  5806. {
  5807. $trns = array($pos);
  5808. }
  5809. }
  5810. fread($f, 4);
  5811. }
  5812. elseif ($type == 'IDAT')
  5813. {
  5814. //Read image data block
  5815. $data .= $this->rfread($f, $n);
  5816. fread($f, 4);
  5817. }
  5818. elseif ($type == 'IEND')
  5819. {
  5820. break;
  5821. }
  5822. else
  5823. {
  5824. $this->rfread($f, $n + 4);
  5825. }
  5826. }
  5827. while ($n);
  5828. if (($colspace == 'Indexed') and (empty($pal)))
  5829. {
  5830. //$this->Error('Missing palette in '.$file);
  5831. fclose($f);
  5832. return false;
  5833. }
  5834. fclose($f);
  5835. return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode',
  5836. 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  5837. }
  5838. /**
  5839. * Binary-safe and URL-safe file read.
  5840. * 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.
  5841. * @param resource $handle
  5842. * @param int $length
  5843. * @return Returns the read string or FALSE in case of error.
  5844. * @author Nicola Asuni
  5845. * @access protected
  5846. * @since 4.5.027 (2009-03-16)
  5847. */
  5848. protected function rfread($handle, $length)
  5849. {
  5850. $data = fread($handle, $length);
  5851. if ($data === false)
  5852. {
  5853. return false;
  5854. }
  5855. $rest = $length - strlen($data);
  5856. if ($rest > 0)
  5857. {
  5858. $data .= $this->rfread($handle, $rest);
  5859. }
  5860. return $data;
  5861. }
  5862. /**
  5863. * Extract info from a PNG image with alpha channel using the GD library.
  5864. * @param string $file Name of the file containing the image.
  5865. * @param float $x Abscissa of the upper-left corner.
  5866. * @param float $y Ordinate of the upper-left corner.
  5867. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5868. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5869. * @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.
  5870. * @param mixed $link URL or identifier returned by AddLink().
  5871. * @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>
  5872. * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  5873. * @param int $dpi dot-per-inch resolution used on resize
  5874. * @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>
  5875. * @author Valentin Schmidt, Nicola Asuni
  5876. * @access protected
  5877. * @since 4.3.007 (2008-12-04)
  5878. * @see Image()
  5879. */
  5880. protected function ImagePngAlpha($file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300, $palign = '')
  5881. {
  5882. // get image size
  5883. list($wpx, $hpx) = getimagesize($file);
  5884. // generate images
  5885. $img = imagecreatefrompng($file);
  5886. $imgalpha = imagecreate($wpx, $hpx);
  5887. // generate gray scale pallete
  5888. for($c = 0; $c < 256; ++ $c)
  5889. {
  5890. ImageColorAllocate($imgalpha, $c, $c, $c);
  5891. }
  5892. // extract alpha channel
  5893. for($xpx = 0; $xpx < $wpx; ++ $xpx)
  5894. {
  5895. for($ypx = 0; $ypx < $hpx; ++ $ypx)
  5896. {
  5897. $colorindex = imagecolorat($img, $xpx, $ypx);
  5898. $col = imagecolorsforindex($img, $colorindex);
  5899. imagesetpixel($imgalpha, $xpx, $ypx, $this->getGDgamma((127 - $col['alpha']) * 255 / 127));
  5900. }
  5901. }
  5902. // create temp alpha file
  5903. $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_');
  5904. imagepng($imgalpha, $tempfile_alpha);
  5905. imagedestroy($imgalpha);
  5906. // extract image without alpha channel
  5907. $imgplain = imagecreatetruecolor($wpx, $hpx);
  5908. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  5909. // create temp image file
  5910. $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_');
  5911. imagepng($imgplain, $tempfile_plain);
  5912. imagedestroy($imgplain);
  5913. // embed mask image
  5914. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  5915. // embed image, masked with previously embedded mask
  5916. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  5917. // remove temp files
  5918. unlink($tempfile_alpha);
  5919. unlink($tempfile_plain);
  5920. }
  5921. /**
  5922. * Correct the gamma value to be used with GD library
  5923. * @param float $v the gamma value to be corrected
  5924. * @access protected
  5925. * @since 4.3.007 (2008-12-04)
  5926. */
  5927. protected function getGDgamma($v)
  5928. {
  5929. return (pow(($v / 255), 2.2) * 255);
  5930. }
  5931. /**
  5932. * Performs a line break.
  5933. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  5934. * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  5935. * @param boolean $cell if true add a cMargin to the x coordinate
  5936. * @access public
  5937. * @since 1.0
  5938. * @see Cell()
  5939. */
  5940. public function Ln($h = '', $cell = false)
  5941. {
  5942. //Line feed; default value is last cell height
  5943. if ($cell)
  5944. {
  5945. $cellmargin = $this->cMargin;
  5946. }
  5947. else
  5948. {
  5949. $cellmargin = 0;
  5950. }
  5951. if ($this->rtl)
  5952. {
  5953. $this->x = $this->w - $this->rMargin - $cellmargin;
  5954. }
  5955. else
  5956. {
  5957. $this->x = $this->lMargin + $cellmargin;
  5958. }
  5959. if (is_string($h))
  5960. {
  5961. $this->y += $this->lasth;
  5962. }
  5963. else
  5964. {
  5965. $this->y += $h;
  5966. }
  5967. $this->newline = true;
  5968. }
  5969. /**
  5970. * Returns the relative X value of current position.
  5971. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  5972. * @return float
  5973. * @access public
  5974. * @since 1.2
  5975. * @see SetX(), GetY(), SetY()
  5976. */
  5977. public function GetX()
  5978. {
  5979. //Get x position
  5980. if ($this->rtl)
  5981. {
  5982. return ($this->w - $this->x);
  5983. }
  5984. else
  5985. {
  5986. return $this->x;
  5987. }
  5988. }
  5989. /**
  5990. * Returns the absolute X value of current position.
  5991. * @return float
  5992. * @access public
  5993. * @since 1.2
  5994. * @see SetX(), GetY(), SetY()
  5995. */
  5996. public function GetAbsX()
  5997. {
  5998. return $this->x;
  5999. }
  6000. /**
  6001. * Returns the ordinate of the current position.
  6002. * @return float
  6003. * @access public
  6004. * @since 1.0
  6005. * @see SetY(), GetX(), SetX()
  6006. */
  6007. public function GetY()
  6008. {
  6009. //Get y position
  6010. return $this->y;
  6011. }
  6012. /**
  6013. * Defines the abscissa of the current position.
  6014. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  6015. * @param float $x The value of the abscissa.
  6016. * @access public
  6017. * @since 1.2
  6018. * @see GetX(), GetY(), SetY(), SetXY()
  6019. */
  6020. public function SetX($x)
  6021. {
  6022. //Set x position
  6023. if ($this->rtl)
  6024. {
  6025. if ($x >= 0)
  6026. {
  6027. $this->x = $this->w - $x;
  6028. }
  6029. else
  6030. {
  6031. $this->x = abs($x);
  6032. }
  6033. }
  6034. else
  6035. {
  6036. if ($x >= 0)
  6037. {
  6038. $this->x = $x;
  6039. }
  6040. else
  6041. {
  6042. $this->x = $this->w + $x;
  6043. }
  6044. }
  6045. if ($this->x < 0)
  6046. {
  6047. $this->x = 0;
  6048. }
  6049. if ($this->x > $this->w)
  6050. {
  6051. $this->x = $this->w;
  6052. }
  6053. }
  6054. /**
  6055. * Moves the current abscissa back to the left margin and sets the ordinate.
  6056. * If the passed value is negative, it is relative to the bottom of the page.
  6057. * @param float $y The value of the ordinate.
  6058. * @param bool $resetx if true (default) reset the X position.
  6059. * @access public
  6060. * @since 1.0
  6061. * @see GetX(), GetY(), SetY(), SetXY()
  6062. */
  6063. public function SetY($y, $resetx = true)
  6064. {
  6065. if ($resetx)
  6066. {
  6067. //reset x
  6068. if ($this->rtl)
  6069. {
  6070. $this->x = $this->w - $this->rMargin;
  6071. }
  6072. else
  6073. {
  6074. $this->x = $this->lMargin;
  6075. }
  6076. }
  6077. if ($y >= 0)
  6078. {
  6079. $this->y = $y;
  6080. }
  6081. else
  6082. {
  6083. $this->y = $this->h + $y;
  6084. }
  6085. if ($this->y < 0)
  6086. {
  6087. $this->y = 0;
  6088. }
  6089. if ($this->y > $this->h)
  6090. {
  6091. $this->y = $this->h;
  6092. }
  6093. }
  6094. /**
  6095. * Defines the abscissa and ordinate of the current position.
  6096. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  6097. * @param float $x The value of the abscissa
  6098. * @param float $y The value of the ordinate
  6099. * @access public
  6100. * @since 1.2
  6101. * @see SetX(), SetY()
  6102. */
  6103. public function SetXY($x, $y)
  6104. {
  6105. //Set x and y positions
  6106. $this->SetY($y);
  6107. $this->SetX($x);
  6108. }
  6109. /**
  6110. * Send the document to a given destination: string, local file or browser.
  6111. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  6112. * The method first calls Close() if necessary to terminate the document.
  6113. * @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.
  6114. * @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>
  6115. * @access public
  6116. * @since 1.0
  6117. * @see Close()
  6118. */
  6119. public function Output($name = 'doc.pdf', $dest = 'I')
  6120. {
  6121. //Output PDF to some destination
  6122. //Finish document if necessary
  6123. $this->lastpage();
  6124. if ($this->state < 3)
  6125. {
  6126. $this->Close();
  6127. }
  6128. //Normalize parameters
  6129. if (is_bool($dest))
  6130. {
  6131. $dest = $dest ? 'D' : 'F';
  6132. }
  6133. $dest = strtoupper($dest);
  6134. if ($dest != 'F')
  6135. {
  6136. $name = preg_replace('/[\s]+/', '_', $name);
  6137. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  6138. }
  6139. if ($this->sign)
  6140. {
  6141. // *** apply digital signature to the document ***
  6142. // get the document content
  6143. $pdfdoc = $this->getBuffer();
  6144. // remove last newline
  6145. $pdfdoc = substr($pdfdoc, 0, - 1);
  6146. // Remove the original buffer
  6147. if (isset($this->diskcache) and $this->diskcache)
  6148. {
  6149. // remove buffer file from cache
  6150. unlink($this->buffer);
  6151. }
  6152. unset($this->buffer);
  6153. // remove filler space
  6154. $byterange_string_len = strlen($this->byterange_string);
  6155. // define the ByteRange
  6156. $byte_range = array();
  6157. $byte_range[0] = 0;
  6158. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  6159. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  6160. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  6161. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . substr($pdfdoc, $byte_range[2]);
  6162. // replace the ByteRange
  6163. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  6164. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  6165. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  6166. // write the document to a temporary folder
  6167. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  6168. $f = fopen($tempdoc, 'wb');
  6169. if (! $f)
  6170. {
  6171. $this->Error('Unable to create temporary file: ' . $tempdoc);
  6172. }
  6173. $pdfdoc_length = strlen($pdfdoc);
  6174. fwrite($f, $pdfdoc, $pdfdoc_length);
  6175. fclose($f);
  6176. // get digital signature via openssl library
  6177. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  6178. if (empty($this->signature_data['extracerts']))
  6179. {
  6180. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array(
  6181. $this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  6182. }
  6183. else
  6184. {
  6185. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array(
  6186. $this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']);
  6187. }
  6188. unlink($tempdoc);
  6189. // read signature
  6190. $signature = file_get_contents($tempsign, false, null, $pdfdoc_length);
  6191. unlink($tempsign);
  6192. // extract signature
  6193. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  6194. $tmparr = explode("\n\n", $signature);
  6195. $signature = $tmparr[1];
  6196. unset($tmparr);
  6197. // decode signature
  6198. $signature = base64_decode(trim($signature));
  6199. // convert signature to hex
  6200. $signature = current(unpack('H*', $signature));
  6201. $signature = str_pad($signature, $this->signature_max_length, '0');
  6202. // Add signature to the document
  6203. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . '<' . $signature . '>' . substr($pdfdoc, ($byte_range[1]));
  6204. $this->diskcache = false;
  6205. $this->buffer = &$pdfdoc;
  6206. $this->bufferlen = strlen($pdfdoc);
  6207. }
  6208. switch ($dest)
  6209. {
  6210. case 'I' :
  6211. {
  6212. // Send PDF to the standard output
  6213. if (ob_get_contents())
  6214. {
  6215. $this->Error('Some data has already been output, can\'t send PDF file');
  6216. }
  6217. if (php_sapi_name() != 'cli')
  6218. {
  6219. //We send to a browser
  6220. header('Content-Type: application/pdf');
  6221. if (headers_sent())
  6222. {
  6223. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6224. }
  6225. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  6226. header('Pragma: public');
  6227. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  6228. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  6229. header('Content-Length: ' . $this->bufferlen);
  6230. header('Content-Disposition: inline; filename="' . basename($name) . '";');
  6231. }
  6232. echo $this->getBuffer();
  6233. break;
  6234. }
  6235. case 'D' :
  6236. {
  6237. // Download PDF as file
  6238. if (ob_get_contents())
  6239. {
  6240. $this->Error('Some data has already been output, can\'t send PDF file');
  6241. }
  6242. header('Content-Description: File Transfer');
  6243. if (headers_sent())
  6244. {
  6245. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6246. }
  6247. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  6248. header('Pragma: public');
  6249. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  6250. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  6251. // force download dialog
  6252. header('Content-Type: application/force-download');
  6253. header('Content-Type: application/octet-stream', false);
  6254. header('Content-Type: application/download', false);
  6255. header('Content-Type: application/pdf', false);
  6256. // use the Content-Disposition header to supply a recommended filename
  6257. header('Content-Disposition: attachment; filename="' . basename($name) . '";');
  6258. header('Content-Transfer-Encoding: binary');
  6259. header('Content-Length: ' . $this->bufferlen);
  6260. echo $this->getBuffer();
  6261. break;
  6262. }
  6263. case 'F' :
  6264. {
  6265. // Save PDF to a local file
  6266. if ($this->diskcache)
  6267. {
  6268. copy($this->buffer, $name);
  6269. }
  6270. else
  6271. {
  6272. $f = fopen($name, 'wb');
  6273. if (! $f)
  6274. {
  6275. $this->Error('Unable to create output file: ' . $name);
  6276. }
  6277. fwrite($f, $this->getBuffer(), $this->bufferlen);
  6278. fclose($f);
  6279. }
  6280. break;
  6281. }
  6282. case 'S' :
  6283. {
  6284. // Returns PDF as a string
  6285. return $this->getBuffer();
  6286. }
  6287. default :
  6288. {
  6289. $this->Error('Incorrect output destination: ' . $dest);
  6290. }
  6291. }
  6292. return '';
  6293. }
  6294. /**
  6295. * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  6296. * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  6297. * @param boolean $preserve_objcopy if true preserves the objcopy variable
  6298. * @access public
  6299. * @since 4.5.016 (2009-02-24)
  6300. */
  6301. public function _destroy($destroyall = false, $preserve_objcopy = false)
  6302. {
  6303. if ($destroyall and isset($this->diskcache) and $this->diskcache and (! $preserve_objcopy) and (! $this->empty_string($this->buffer)))
  6304. {
  6305. // remove buffer file from cache
  6306. unlink($this->buffer);
  6307. }
  6308. foreach (array_keys(get_object_vars($this)) as $val)
  6309. {
  6310. if ($destroyall or (($val != 'internal_encoding') and ($val != 'state') and ($val != 'bufferlen') and ($val != 'buffer') and ($val != 'diskcache') and ($val != 'sign') and ($val != 'signature_data') and ($val != 'signature_max_length') and ($val != 'byterange_string')))
  6311. {
  6312. if (! $preserve_objcopy or ($val != 'objcopy'))
  6313. {
  6314. unset($this->$val);
  6315. }
  6316. }
  6317. }
  6318. }
  6319. /**
  6320. * Check for locale-related bug
  6321. * @access protected
  6322. */
  6323. protected function _dochecks()
  6324. {
  6325. //Check for locale-related bug
  6326. if (1.1 == 1)
  6327. {
  6328. $this->Error('Don\'t alter the locale before including class file');
  6329. }
  6330. //Check for decimal separator
  6331. if (sprintf('%.1F', 1.0) != '1.0')
  6332. {
  6333. setlocale(LC_NUMERIC, 'C');
  6334. }
  6335. }
  6336. /**
  6337. * Return fonts path
  6338. * @return string
  6339. * @access protected
  6340. */
  6341. protected function _getfontpath()
  6342. {
  6343. if (! defined('K_PATH_FONTS') and is_dir(dirname(__FILE__) . '/fonts'))
  6344. {
  6345. define('K_PATH_FONTS', dirname(__FILE__) . '/fonts/');
  6346. }
  6347. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  6348. }
  6349. /**
  6350. * Output pages.
  6351. * @access protected
  6352. */
  6353. protected function _putpages()
  6354. {
  6355. $nb = $this->numpages;
  6356. if (! empty($this->AliasNbPages))
  6357. {
  6358. $nbs = $this->formatPageNumber($nb);
  6359. $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font
  6360. $alias_a = $this->_escape($this->AliasNbPages);
  6361. $alias_au = $this->_escape('{' . $this->AliasNbPages . '}');
  6362. if ($this->isunicode)
  6363. {
  6364. $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  6365. $alias_bu = $this->_escape($this->UTF8ToLatin1('{' . $this->AliasNbPages . '}'));
  6366. $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages, false, $this->tmprtl));
  6367. $alias_cu = $this->_escape($this->utf8StrRev('{' . $this->AliasNbPages . '}', false, $this->tmprtl));
  6368. }
  6369. }
  6370. if (! empty($this->AliasNumPage))
  6371. {
  6372. $alias_pa = $this->_escape($this->AliasNumPage);
  6373. $alias_pau = $this->_escape('{' . $this->AliasNumPage . '}');
  6374. if ($this->isunicode)
  6375. {
  6376. $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  6377. $alias_pbu = $this->_escape($this->UTF8ToLatin1('{' . $this->AliasNumPage . '}'));
  6378. $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage, false, $this->tmprtl));
  6379. $alias_pcu = $this->_escape($this->utf8StrRev('{' . $this->AliasNumPage . '}', false, $this->tmprtl));
  6380. }
  6381. }
  6382. $pagegroupnum = 0;
  6383. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  6384. for($n = 1; $n <= $nb; ++ $n)
  6385. {
  6386. $temppage = $this->getPageBuffer($n);
  6387. if (! empty($this->pagegroups))
  6388. {
  6389. if (isset($this->newpagegroup[$n]))
  6390. {
  6391. $pagegroupnum = 0;
  6392. }
  6393. ++ $pagegroupnum;
  6394. foreach ($this->pagegroups as $k => $v)
  6395. {
  6396. // replace total pages group numbers
  6397. $vs = $this->formatPageNumber($v);
  6398. $vu = $this->UTF8ToUTF16BE($vs, false);
  6399. $alias_ga = $this->_escape($k);
  6400. $alias_gau = $this->_escape('{' . $k . '}');
  6401. if ($this->isunicode)
  6402. {
  6403. $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
  6404. $alias_gbu = $this->_escape($this->UTF8ToLatin1('{' . $k . '}'));
  6405. $alias_gc = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  6406. $alias_gcu = $this->_escape($this->utf8StrRev('{' . $k . '}', false, $this->tmprtl));
  6407. }
  6408. $temppage = str_replace($alias_gau, $vu, $temppage);
  6409. if ($this->isunicode)
  6410. {
  6411. $temppage = str_replace($alias_gbu, $vu, $temppage);
  6412. $temppage = str_replace($alias_gcu, $vu, $temppage);
  6413. $temppage = str_replace($alias_gb, $vs, $temppage);
  6414. $temppage = str_replace($alias_gc, $vs, $temppage);
  6415. }
  6416. $temppage = str_replace($alias_ga, $vs, $temppage);
  6417. // replace page group numbers
  6418. $pvs = $this->formatPageNumber($pagegroupnum);
  6419. $pvu = $this->UTF8ToUTF16BE($pvs, false);
  6420. $pk = str_replace('{nb', '{pnb', $k);
  6421. $alias_pga = $this->_escape($pk);
  6422. $alias_pgau = $this->_escape('{' . $pk . '}');
  6423. if ($this->isunicode)
  6424. {
  6425. $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
  6426. $alias_pgbu = $this->_escape($this->UTF8ToLatin1('{' . $pk . '}'));
  6427. $alias_pgc = $this->_escape($this->utf8StrRev($pk, false, $this->tmprtl));
  6428. $alias_pgcu = $this->_escape($this->utf8StrRev('{' . $pk . '}', false, $this->tmprtl));
  6429. }
  6430. $temppage = str_replace($alias_pgau, $pvu, $temppage);
  6431. if ($this->isunicode)
  6432. {
  6433. $temppage = str_replace($alias_pgbu, $pvu, $temppage);
  6434. $temppage = str_replace($alias_pgcu, $pvu, $temppage);
  6435. $temppage = str_replace($alias_pgb, $pvs, $temppage);
  6436. $temppage = str_replace($alias_pgc, $pvs, $temppage);
  6437. }
  6438. $temppage = str_replace($alias_pga, $pvs, $temppage);
  6439. }
  6440. }
  6441. if (! empty($this->AliasNbPages))
  6442. {
  6443. // replace total pages number
  6444. $temppage = str_replace($alias_au, $nbu, $temppage);
  6445. if ($this->isunicode)
  6446. {
  6447. $temppage = str_replace($alias_bu, $nbu, $temppage);
  6448. $temppage = str_replace($alias_cu, $nbu, $temppage);
  6449. $temppage = str_replace($alias_b, $nbs, $temppage);
  6450. $temppage = str_replace($alias_c, $nbs, $temppage);
  6451. }
  6452. $temppage = str_replace($alias_a, $nbs, $temppage);
  6453. }
  6454. if (! empty($this->AliasNumPage))
  6455. {
  6456. // replace page number
  6457. $pnbs = $this->formatPageNumber($n);
  6458. $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font
  6459. $temppage = str_replace($alias_pau, $pnbu, $temppage);
  6460. if ($this->isunicode)
  6461. {
  6462. $temppage = str_replace($alias_pbu, $pnbu, $temppage);
  6463. $temppage = str_replace($alias_pcu, $pnbu, $temppage);
  6464. $temppage = str_replace($alias_pb, $pnbs, $temppage);
  6465. $temppage = str_replace($alias_pc, $pnbs, $temppage);
  6466. }
  6467. $temppage = str_replace($alias_pa, $pnbs, $temppage);
  6468. }
  6469. $temppage = str_replace($this->epsmarker, '', $temppage);
  6470. //Page
  6471. $this->page_obj_id[$n] = $this->_newobj();
  6472. $this->_out('<</Type /Page');
  6473. $this->_out('/Parent 1 0 R');
  6474. $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]', $this->pagedim[$n]['w'], $this->pagedim[$n]['h']));
  6475. $this->_out('/Resources 2 0 R');
  6476. $this->_putannotsrefs($n);
  6477. $this->_out('/Contents ' . ($this->n + 1) . ' 0 R>>');
  6478. $this->_out('endobj');
  6479. //Page content
  6480. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  6481. $this->_newobj();
  6482. $this->_out('<<' . $filter . '/Length ' . strlen($p) . '>>');
  6483. $this->_putstream($p);
  6484. $this->_out('endobj');
  6485. if ($this->diskcache)
  6486. {
  6487. // remove temporary files
  6488. unlink($this->pages[$n]);
  6489. }
  6490. }
  6491. //Pages root
  6492. $this->offsets[1] = $this->bufferlen;
  6493. $this->_out('1 0 obj');
  6494. $this->_out('<</Type /Pages');
  6495. $this->_out('/Kids [');
  6496. foreach ($this->page_obj_id as $page_obj)
  6497. {
  6498. $this->_out($page_obj . ' 0 R');
  6499. }
  6500. $this->_out(']');
  6501. $this->_out('/Count ' . $nb);
  6502. $this->_out('>>');
  6503. $this->_out('endobj');
  6504. }
  6505. /**
  6506. * Output referencees to page annotations
  6507. * @param int $n page number
  6508. * @access protected
  6509. * @author Nicola Asuni
  6510. * @since 4.7.000 (2008-08-29)
  6511. */
  6512. protected function _putannotsrefs($n)
  6513. {
  6514. if (! (isset($this->PageAnnots[$n]) or ($this->sign and isset($this->signature_data['cert_type']))))
  6515. {
  6516. return;
  6517. }
  6518. $this->_out('/Annots [');
  6519. if (isset($this->PageAnnots[$n]))
  6520. {
  6521. $num_annots = count($this->PageAnnots[$n]);
  6522. for($i = 0; $i < $num_annots; ++ $i)
  6523. {
  6524. ++ $this->curr_annot_obj_id;
  6525. if (! in_array($this->curr_annot_obj_id, $this->radio_groups))
  6526. {
  6527. $this->_out($this->curr_annot_obj_id . ' 0 R');
  6528. }
  6529. else
  6530. {
  6531. ++ $num_annots;
  6532. }
  6533. }
  6534. }
  6535. if (($n == 1) and $this->sign and isset($this->signature_data['cert_type']))
  6536. {
  6537. // set reference for signature object
  6538. $this->_out($this->sig_annot_ref);
  6539. }
  6540. $this->_out(']');
  6541. }
  6542. /**
  6543. * Output annotations objects for all pages.
  6544. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  6545. * See section 12.5 of PDF 32000_2008 reference.
  6546. * @access protected
  6547. * @author Nicola Asuni
  6548. * @since 4.0.018 (2008-08-06)
  6549. */
  6550. protected function _putannotsobjs()
  6551. {
  6552. // reset object counter
  6553. $this->annot_obj_id = $this->annots_start_obj_id;
  6554. for($n = 1; $n <= $this->numpages; ++ $n)
  6555. {
  6556. if (isset($this->PageAnnots[$n]))
  6557. {
  6558. // set page annotations
  6559. foreach ($this->PageAnnots[$n] as $key => $pl)
  6560. {
  6561. // create annotation object for grouping radiobuttons
  6562. if (isset($this->radiobutton_groups[$n][$pl['txt']]) and is_array($this->radiobutton_groups[$n][$pl['txt']]))
  6563. {
  6564. $annots = '<<';
  6565. $annots .= ' /Type /Annot';
  6566. $annots .= ' /Subtype /Widget';
  6567. $annots .= ' /T ' . $this->_dataannobjstring($pl['txt']);
  6568. $annots .= ' /FT /Btn';
  6569. $annots .= ' /Ff 49152';
  6570. $annots .= ' /Kids [';
  6571. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $data)
  6572. {
  6573. $annots .= ' ' . $data['kid'] . ' 0 R';
  6574. if ($data['def'] !== 'Off')
  6575. {
  6576. $defval = $data['def'];
  6577. }
  6578. }
  6579. $annots .= ' ]';
  6580. if (isset($defval))
  6581. {
  6582. $annots .= ' /V /' . $defval;
  6583. }
  6584. $annots .= ' >>';
  6585. ++ $this->annot_obj_id;
  6586. $this->offsets[$this->annot_obj_id] = $this->bufferlen;
  6587. $this->_out($this->annot_obj_id . ' 0 obj');
  6588. $this->_out($annots);
  6589. $this->_out('endobj');
  6590. $this->form_obj_id[] = $this->annot_obj_id;
  6591. // store object id to be used on Parent entry of Kids
  6592. $this->radiobutton_groups[$n][$pl['txt']] = $this->annot_obj_id;
  6593. }
  6594. $formfield = false;
  6595. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  6596. $a = $pl['x'] * $this->k;
  6597. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  6598. $c = $pl['w'] * $this->k;
  6599. $d = $pl['h'] * $this->k;
  6600. $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a + $c, $b + $d);
  6601. // create new annotation object
  6602. $annots = '<</Type /Annot';
  6603. $annots .= ' /Subtype /' . $pl['opt']['subtype'];
  6604. $annots .= ' /Rect [' . $rect . ']';
  6605. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  6606. if (isset($pl['opt']['ft']) and in_array($pl['opt']['ft'], $ft))
  6607. {
  6608. $annots .= ' /FT /' . $pl['opt']['ft'];
  6609. $formfield = true;
  6610. }
  6611. $annots .= ' /Contents ' . $this->_textstring($pl['txt']);
  6612. $annots .= ' /P ' . $this->page_obj_id[$n] . ' 0 R';
  6613. $annots .= ' /NM ' . $this->_dataannobjstring(sprintf('%04u-%04u', $n, $key));
  6614. $annots .= ' /M ' . $this->_datestring();
  6615. if (isset($pl['opt']['f']))
  6616. {
  6617. $val = 0;
  6618. if (is_array($pl['opt']['f']))
  6619. {
  6620. foreach ($pl['opt']['f'] as $f)
  6621. {
  6622. switch (strtolower($f))
  6623. {
  6624. case 'invisible' :
  6625. {
  6626. $val += 1 << 0;
  6627. break;
  6628. }
  6629. case 'hidden' :
  6630. {
  6631. $val += 1 << 1;
  6632. break;
  6633. }
  6634. case 'print' :
  6635. {
  6636. $val += 1 << 2;
  6637. break;
  6638. }
  6639. case 'nozoom' :
  6640. {
  6641. $val += 1 << 3;
  6642. break;
  6643. }
  6644. case 'norotate' :
  6645. {
  6646. $val += 1 << 4;
  6647. break;
  6648. }
  6649. case 'noview' :
  6650. {
  6651. $val += 1 << 5;
  6652. break;
  6653. }
  6654. case 'readonly' :
  6655. {
  6656. $val += 1 << 6;
  6657. break;
  6658. }
  6659. case 'locked' :
  6660. {
  6661. $val += 1 << 8;
  6662. break;
  6663. }
  6664. case 'togglenoview' :
  6665. {
  6666. $val += 1 << 9;
  6667. break;
  6668. }
  6669. case 'lockedcontents' :
  6670. {
  6671. $val += 1 << 10;
  6672. break;
  6673. }
  6674. default :
  6675. {
  6676. break;
  6677. }
  6678. }
  6679. }
  6680. }
  6681. else
  6682. {
  6683. $val = intval($pl['opt']['f']);
  6684. }
  6685. $annots .= ' /F ' . intval($val);
  6686. }
  6687. if (isset($pl['opt']['as']) and is_string($pl['opt']['as']))
  6688. {
  6689. $annots .= ' /AS /' . $pl['opt']['as'];
  6690. }
  6691. if (isset($pl['opt']['ap']))
  6692. {
  6693. // appearance stream
  6694. $annots .= ' /AP <<';
  6695. if (is_array($pl['opt']['ap']))
  6696. {
  6697. foreach ($pl['opt']['ap'] as $apmode => $apdef)
  6698. {
  6699. // $apmode can be: n = normal; r = rollover; d = down;
  6700. $annots .= ' /' . strtoupper($apmode);
  6701. if (is_array($apdef))
  6702. {
  6703. $annots .= ' <<';
  6704. foreach ($apdef as $apstate => $stream)
  6705. {
  6706. // reference to XObject that define the appearance for this mode-state
  6707. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  6708. $annots .= ' /' . $apstate . ' ' . $apsobjid . ' 0 R';
  6709. }
  6710. $annots .= ' >>';
  6711. }
  6712. else
  6713. {
  6714. // reference to XObject that define the appearance for this mode
  6715. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  6716. $annots .= ' ' . $apsobjid . ' 0 R';
  6717. }
  6718. }
  6719. }
  6720. else
  6721. {
  6722. $annots .= $pl['opt']['ap'];
  6723. }
  6724. $annots .= ' >>';
  6725. }
  6726. if (isset($pl['opt']['bs']) and (is_array($pl['opt']['bs'])))
  6727. {
  6728. $annots .= ' /BS <<';
  6729. $annots .= ' /Type /Border';
  6730. if (isset($pl['opt']['bs']['w']))
  6731. {
  6732. $annots .= ' /W ' . intval($pl['opt']['bs']['w']);
  6733. }
  6734. $bstyles = array('S', 'D', 'B', 'I', 'U');
  6735. if (isset($pl['opt']['bs']['s']) and in_array($pl['opt']['bs']['s'], $bstyles))
  6736. {
  6737. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  6738. }
  6739. if (isset($pl['opt']['bs']['d']) and (is_array($pl['opt']['bs']['d'])))
  6740. {
  6741. $annots .= ' /D [';
  6742. foreach ($pl['opt']['bs']['d'] as $cord)
  6743. {
  6744. $annots .= ' ' . intval($cord);
  6745. }
  6746. $annots .= ']';
  6747. }
  6748. $annots .= ' >>';
  6749. }
  6750. else
  6751. {
  6752. $annots .= ' /Border [';
  6753. if (isset($pl['opt']['border']) and (count($pl['opt']['border']) >= 3))
  6754. {
  6755. $annots .= intval($pl['opt']['border'][0]) . ' ';
  6756. $annots .= intval($pl['opt']['border'][1]) . ' ';
  6757. $annots .= intval($pl['opt']['border'][2]);
  6758. if (isset($pl['opt']['border'][3]) and is_array($pl['opt']['border'][3]))
  6759. {
  6760. $annots .= ' [';
  6761. foreach ($pl['opt']['border'][3] as $dash)
  6762. {
  6763. $annots .= intval($dash) . ' ';
  6764. }
  6765. $annots .= ']';
  6766. }
  6767. }
  6768. else
  6769. {
  6770. $annots .= '0 0 0';
  6771. }
  6772. $annots .= ']';
  6773. }
  6774. if (isset($pl['opt']['be']) and (is_array($pl['opt']['be'])))
  6775. {
  6776. $annots .= ' /BE <<';
  6777. $bstyles = array('S', 'C');
  6778. if (isset($pl['opt']['be']['s']) and in_array($pl['opt']['be']['s'], $markups))
  6779. {
  6780. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  6781. }
  6782. else
  6783. {
  6784. $annots .= ' /S /S';
  6785. }
  6786. if (isset($pl['opt']['be']['i']) and ($pl['opt']['be']['i'] >= 0) and ($pl['opt']['be']['i'] <= 2))
  6787. {
  6788. $annots .= ' /I ' . sprintf(' %.4F', $pl['opt']['be']['i']);
  6789. }
  6790. $annots .= '>>';
  6791. }
  6792. if (isset($pl['opt']['c']) and (is_array($pl['opt']['c'])) and ! empty($pl['opt']['c']))
  6793. {
  6794. $annots .= ' /C [';
  6795. foreach ($pl['opt']['c'] as $col)
  6796. {
  6797. $col = intval($col);
  6798. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  6799. $annots .= sprintf(' %.4F', $color);
  6800. }
  6801. $annots .= ']';
  6802. }
  6803. //$annots .= ' /StructParent ';
  6804. //$annots .= ' /OC ';
  6805. $markups = array('text', 'freetext', 'line',
  6806. 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly',
  6807. 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  6808. if (in_array(strtolower($pl['opt']['subtype']), $markups))
  6809. {
  6810. // this is a markup type
  6811. if (isset($pl['opt']['t']) and is_string($pl['opt']['t']))
  6812. {
  6813. $annots .= ' /T ' . $this->_textstring($pl['opt']['t']);
  6814. }
  6815. //$annots .= ' /Popup ';
  6816. if (isset($pl['opt']['ca']))
  6817. {
  6818. $annots .= ' /CA ' . sprintf('%.4F', floatval($pl['opt']['ca']));
  6819. }
  6820. if (isset($pl['opt']['rc']))
  6821. {
  6822. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc']);
  6823. }
  6824. $annots .= ' /CreationDate ' . $this->_datestring();
  6825. //$annots .= ' /IRT ';
  6826. if (isset($pl['opt']['subj']))
  6827. {
  6828. $annots .= ' /Subj ' . $this->_textstring($pl['opt']['subj']);
  6829. }
  6830. //$annots .= ' /RT ';
  6831. //$annots .= ' /IT ';
  6832. //$annots .= ' /ExData ';
  6833. }
  6834. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt',
  6835. 'ROpenArrow', 'RClosedArrow', 'Slash');
  6836. switch (strtolower($pl['opt']['subtype']))
  6837. {
  6838. case 'text' :
  6839. {
  6840. if (isset($pl['opt']['open']))
  6841. {
  6842. $annots .= ' /Open ' . (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  6843. }
  6844. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note',
  6845. 'Paragraph');
  6846. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  6847. {
  6848. $annots .= ' /Name /' . $pl['opt']['name'];
  6849. }
  6850. else
  6851. {
  6852. $annots .= ' /Name /Note';
  6853. }
  6854. $statemodels = array('Marked', 'Review');
  6855. if (isset($pl['opt']['statemodel']) and in_array($pl['opt']['statemodel'], $statemodels))
  6856. {
  6857. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  6858. }
  6859. else
  6860. {
  6861. $pl['opt']['statemodel'] = 'Marked';
  6862. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  6863. }
  6864. if ($pl['opt']['statemodel'] == 'Marked')
  6865. {
  6866. $states = array('Accepted', 'Unmarked');
  6867. }
  6868. else
  6869. {
  6870. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  6871. }
  6872. if (isset($pl['opt']['state']) and in_array($pl['opt']['state'], $states))
  6873. {
  6874. $annots .= ' /State /' . $pl['opt']['state'];
  6875. }
  6876. else
  6877. {
  6878. if ($pl['opt']['statemodel'] == 'Marked')
  6879. {
  6880. $annots .= ' /State /Unmarked';
  6881. }
  6882. else
  6883. {
  6884. $annots .= ' /State /None';
  6885. }
  6886. }
  6887. break;
  6888. }
  6889. case 'link' :
  6890. {
  6891. if (is_string($pl['txt']))
  6892. {
  6893. // external URI link
  6894. $annots .= ' /A <</S /URI /URI ' . $this->_dataannobjstring($this->unhtmlentities($pl['txt'])) . '>>';
  6895. }
  6896. else
  6897. {
  6898. // internal link
  6899. $l = $this->links[$pl['txt']];
  6900. $annots .= sprintf(' /Dest [%d 0 R /XYZ 0 %.2F null]', (1 + (2 * $l[0])), ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  6901. }
  6902. $hmodes = array('N', 'I', 'O', 'P');
  6903. if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmodes))
  6904. {
  6905. $annots .= ' /H /' . $pl['opt']['h'];
  6906. }
  6907. else
  6908. {
  6909. $annots .= ' /H /I';
  6910. }
  6911. //$annots .= ' /PA ';
  6912. //$annots .= ' /Quadpoints ';
  6913. break;
  6914. }
  6915. case 'freetext' :
  6916. {
  6917. if (isset($pl['opt']['da']) and ! empty($pl['opt']['da']))
  6918. {
  6919. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  6920. }
  6921. if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2))
  6922. {
  6923. $annots .= ' /Q ' . intval($pl['opt']['q']);
  6924. }
  6925. if (isset($pl['opt']['rc']))
  6926. {
  6927. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc']);
  6928. }
  6929. if (isset($pl['opt']['ds']))
  6930. {
  6931. $annots .= ' /DS ' . $this->_textstring($pl['opt']['ds']);
  6932. }
  6933. if (isset($pl['opt']['cl']) and is_array($pl['opt']['cl']))
  6934. {
  6935. $annots .= ' /CL [';
  6936. foreach ($pl['opt']['cl'] as $cl)
  6937. {
  6938. $annots .= sprintf('%.4F ', $cl * $this->k);
  6939. }
  6940. $annots .= ']';
  6941. }
  6942. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  6943. if (isset($pl['opt']['it']) and in_array($pl['opt']['it'], $tfit))
  6944. {
  6945. $annots .= ' /IT ' . $pl['opt']['it'];
  6946. }
  6947. if (isset($pl['opt']['rd']) and is_array($pl['opt']['rd']))
  6948. {
  6949. $l = $pl['opt']['rd'][0] * $this->k;
  6950. $r = $pl['opt']['rd'][1] * $this->k;
  6951. $t = $pl['opt']['rd'][2] * $this->k;
  6952. $b = $pl['opt']['rd'][3] * $this->k;
  6953. $annots .= ' /RD [' . sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b) . ']';
  6954. }
  6955. if (isset($pl['opt']['le']) and in_array($pl['opt']['le'], $lineendings))
  6956. {
  6957. $annots .= ' /LE /' . $pl['opt']['le'];
  6958. }
  6959. break;
  6960. }
  6961. case 'line' :
  6962. {
  6963. break;
  6964. }
  6965. case 'square' :
  6966. {
  6967. break;
  6968. }
  6969. case 'circle' :
  6970. {
  6971. break;
  6972. }
  6973. case 'polygon' :
  6974. {
  6975. break;
  6976. }
  6977. case 'polyline' :
  6978. {
  6979. break;
  6980. }
  6981. case 'highlight' :
  6982. {
  6983. break;
  6984. }
  6985. case 'underline' :
  6986. {
  6987. break;
  6988. }
  6989. case 'squiggly' :
  6990. {
  6991. break;
  6992. }
  6993. case 'strikeout' :
  6994. {
  6995. break;
  6996. }
  6997. case 'stamp' :
  6998. {
  6999. break;
  7000. }
  7001. case 'caret' :
  7002. {
  7003. break;
  7004. }
  7005. case 'ink' :
  7006. {
  7007. break;
  7008. }
  7009. case 'popup' :
  7010. {
  7011. break;
  7012. }
  7013. case 'fileattachment' :
  7014. {
  7015. if (! isset($pl['opt']['fs']))
  7016. {
  7017. break;
  7018. }
  7019. $filename = basename($pl['opt']['fs']);
  7020. if (isset($this->embeddedfiles[$filename]['n']))
  7021. {
  7022. $annots .= ' /FS <</Type /Filespec /F ' . $this->_dataannobjstring($filename) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  7023. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  7024. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  7025. {
  7026. $annots .= ' /Name /' . $pl['opt']['name'];
  7027. }
  7028. else
  7029. {
  7030. $annots .= ' /Name /PushPin';
  7031. }
  7032. }
  7033. break;
  7034. }
  7035. case 'sound' :
  7036. {
  7037. if (! isset($pl['opt']['fs']))
  7038. {
  7039. break;
  7040. }
  7041. $filename = basename($pl['opt']['fs']);
  7042. if (isset($this->embeddedfiles[$filename]['n']))
  7043. {
  7044. // ... TO BE COMPLETED ...
  7045. // /R /C /B /E /CO /CP
  7046. $annots .= ' /Sound <</Type /Filespec /F ' . $this->_dataannobjstring($filename) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  7047. $iconsapp = array('Speaker', 'Mic');
  7048. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  7049. {
  7050. $annots .= ' /Name /' . $pl['opt']['name'];
  7051. }
  7052. else
  7053. {
  7054. $annots .= ' /Name /Speaker';
  7055. }
  7056. }
  7057. break;
  7058. }
  7059. case 'movie' :
  7060. {
  7061. break;
  7062. }
  7063. case 'widget' :
  7064. {
  7065. $hmode = array('N', 'I', 'O', 'P', 'T');
  7066. if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmode))
  7067. {
  7068. $annots .= ' /H /' . $pl['opt']['h'];
  7069. }
  7070. if (isset($pl['opt']['mk']) and (is_array($pl['opt']['mk'])) and ! empty($pl['opt']['mk']))
  7071. {
  7072. $annots .= ' /MK <<';
  7073. if (isset($pl['opt']['mk']['r']))
  7074. {
  7075. $annots .= ' /R ' . $pl['opt']['mk']['r'];
  7076. }
  7077. if (isset($pl['opt']['mk']['bc']) and (is_array($pl['opt']['mk']['bc'])))
  7078. {
  7079. $annots .= ' /BC [';
  7080. foreach ($pl['opt']['mk']['bc'] as $col)
  7081. {
  7082. $col = intval($col);
  7083. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  7084. $annots .= ' ' . $color;
  7085. }
  7086. $annots .= ']';
  7087. }
  7088. if (isset($pl['opt']['mk']['bg']) and (is_array($pl['opt']['mk']['bg'])))
  7089. {
  7090. $annots .= ' /BG [';
  7091. foreach ($pl['opt']['mk']['bg'] as $col)
  7092. {
  7093. $col = intval($col);
  7094. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  7095. $annots .= ' ' . $color;
  7096. }
  7097. $annots .= ']';
  7098. }
  7099. if (isset($pl['opt']['mk']['ca']))
  7100. {
  7101. $annots .= ' /CA ' . $pl['opt']['mk']['ca'] . '';
  7102. }
  7103. if (isset($pl['opt']['mk']['rc']))
  7104. {
  7105. $annots .= ' /RC ' . $pl['opt']['mk']['ca'] . '';
  7106. }
  7107. if (isset($pl['opt']['mk']['ac']))
  7108. {
  7109. $annots .= ' /AC ' . $pl['opt']['mk']['ca'] . '';
  7110. }
  7111. if (isset($pl['opt']['mk']['i']))
  7112. {
  7113. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  7114. if ($info !== false)
  7115. {
  7116. $annots .= ' /I ' . $info['n'] . ' 0 R';
  7117. }
  7118. }
  7119. if (isset($pl['opt']['mk']['ri']))
  7120. {
  7121. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  7122. if ($info !== false)
  7123. {
  7124. $annots .= ' /RI ' . $info['n'] . ' 0 R';
  7125. }
  7126. }
  7127. if (isset($pl['opt']['mk']['ix']))
  7128. {
  7129. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  7130. if ($info !== false)
  7131. {
  7132. $annots .= ' /IX ' . $info['n'] . ' 0 R';
  7133. }
  7134. }
  7135. if (isset($pl['opt']['mk']['if']) and (is_array($pl['opt']['mk']['if'])) and ! empty($pl['opt']['mk']['if']))
  7136. {
  7137. $annots .= ' /IF <<';
  7138. $if_sw = array('A', 'B', 'S', 'N');
  7139. if (isset($pl['opt']['mk']['if']['sw']) and in_array($pl['opt']['mk']['if']['sw'], $if_sw))
  7140. {
  7141. $annots .= ' /SW /' . $pl['opt']['mk']['if']['sw'];
  7142. }
  7143. $if_s = array('A', 'P');
  7144. if (isset($pl['opt']['mk']['if']['s']) and in_array($pl['opt']['mk']['if']['s'], $if_s))
  7145. {
  7146. $annots .= ' /S /' . $pl['opt']['mk']['if']['s'];
  7147. }
  7148. if (isset($pl['opt']['mk']['if']['a']) and (is_array($pl['opt']['mk']['if']['a'])) and ! empty($pl['opt']['mk']['if']['a']))
  7149. {
  7150. $annots .= ' /A [' . $pl['opt']['mk']['if']['a'][0] . ' ' . $pl['opt']['mk']['if']['a'][1] . ']';
  7151. }
  7152. if (isset($pl['opt']['mk']['if']['fb']) and ($pl['opt']['mk']['if']['fb']))
  7153. {
  7154. $annots .= ' /FB true';
  7155. }
  7156. $annots .= '>>';
  7157. }
  7158. if (isset($pl['opt']['mk']['tp']) and ($pl['opt']['mk']['tp'] >= 0) and ($pl['opt']['mk']['tp'] <= 6))
  7159. {
  7160. $annots .= ' /TP ' . $pl['opt']['mk']['tp'];
  7161. }
  7162. else
  7163. {
  7164. $annots .= ' /TP 0';
  7165. }
  7166. $annots .= '>>';
  7167. } // end MK
  7168. // --- Entries for field dictionaries ---
  7169. if (isset($this->radiobutton_groups[$n][$pl['txt']]))
  7170. {
  7171. // set parent
  7172. $annots .= ' /Parent ' . $this->radiobutton_groups[$n][$pl['txt']] . ' 0 R';
  7173. }
  7174. if (isset($pl['opt']['t']) and is_string($pl['opt']['t']))
  7175. {
  7176. $annots .= ' /T ' . $this->_dataannobjstring($pl['opt']['t']);
  7177. }
  7178. if (isset($pl['opt']['tu']) and is_string($pl['opt']['tu']))
  7179. {
  7180. $annots .= ' /TU ' . $this->_dataannobjstring($pl['opt']['tu']);
  7181. }
  7182. if (isset($pl['opt']['tm']) and is_string($pl['opt']['tm']))
  7183. {
  7184. $annots .= ' /TM ' . $this->_dataannobjstring($pl['opt']['tm']);
  7185. }
  7186. if (isset($pl['opt']['ff']))
  7187. {
  7188. if (is_array($pl['opt']['ff']))
  7189. {
  7190. // array of bit settings
  7191. $flag = 0;
  7192. foreach ($pl['opt']['ff'] as $val)
  7193. {
  7194. $flag += 1 << ($val - 1);
  7195. }
  7196. }
  7197. else
  7198. {
  7199. $flag = intval($pl['opt']['ff']);
  7200. }
  7201. $annots .= ' /Ff ' . $flag;
  7202. }
  7203. if (isset($pl['opt']['maxlen']))
  7204. {
  7205. $annots .= ' /MaxLen ' . intval($pl['opt']['maxlen']);
  7206. }
  7207. if (isset($pl['opt']['v']))
  7208. {
  7209. $annots .= ' /V';
  7210. if (is_array($pl['opt']['v']))
  7211. {
  7212. foreach ($pl['opt']['v'] as $optval)
  7213. {
  7214. $annots .= ' ' . $optval;
  7215. }
  7216. }
  7217. else
  7218. {
  7219. $annots .= ' ' . $this->_textstring($pl['opt']['v']);
  7220. }
  7221. }
  7222. if (isset($pl['opt']['dv']) and is_string($pl['opt']['dv']))
  7223. {
  7224. $annots .= ' /DV';
  7225. if (is_array($pl['opt']['dv']))
  7226. {
  7227. foreach ($pl['opt']['dv'] as $optval)
  7228. {
  7229. $annots .= ' ' . $optval;
  7230. }
  7231. }
  7232. else
  7233. {
  7234. $annots .= ' ' . $this->_textstring($pl['opt']['dv']);
  7235. }
  7236. }
  7237. if (isset($pl['opt']['rv']) and is_string($pl['opt']['rv']))
  7238. {
  7239. $annots .= ' /RV';
  7240. if (is_array($pl['opt']['rv']))
  7241. {
  7242. foreach ($pl['opt']['rv'] as $optval)
  7243. {
  7244. $annots .= ' ' . $optval;
  7245. }
  7246. }
  7247. else
  7248. {
  7249. $annots .= ' ' . $this->_textstring($pl['opt']['rv']);
  7250. }
  7251. }
  7252. if (isset($pl['opt']['a']) and ! empty($pl['opt']['a']))
  7253. {
  7254. $annots .= ' /A << ' . $pl['opt']['a'] . ' >>';
  7255. }
  7256. if (isset($pl['opt']['aa']) and ! empty($pl['opt']['aa']))
  7257. {
  7258. $annots .= ' /AA << ' . $pl['opt']['aa'] . ' >>';
  7259. }
  7260. if (isset($pl['opt']['da']) and ! empty($pl['opt']['da']))
  7261. {
  7262. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  7263. }
  7264. if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2))
  7265. {
  7266. $annots .= ' /Q ' . intval($pl['opt']['q']);
  7267. }
  7268. if (isset($pl['opt']['opt']) and (is_array($pl['opt']['opt'])) and ! empty($pl['opt']['opt']))
  7269. {
  7270. $annots .= ' /Opt [';
  7271. foreach ($pl['opt']['opt'] as $copt)
  7272. {
  7273. if (is_array($copt))
  7274. {
  7275. $annots .= ' [' . $this->_textstring($copt[0]) . ' ' . $this->_textstring($copt[1]) . ']';
  7276. }
  7277. else
  7278. {
  7279. $annots .= ' ' . $this->_textstring($copt);
  7280. }
  7281. }
  7282. $annots .= ']';
  7283. }
  7284. if (isset($pl['opt']['ti']))
  7285. {
  7286. $annots .= ' /TI ' . intval($pl['opt']['ti']);
  7287. }
  7288. if (isset($pl['opt']['i']) and (is_array($pl['opt']['i'])) and ! empty($pl['opt']['i']))
  7289. {
  7290. $annots .= ' /I [';
  7291. foreach ($pl['opt']['i'] as $copt)
  7292. {
  7293. $annots .= intval($copt) . ' ';
  7294. }
  7295. $annots .= ']';
  7296. }
  7297. break;
  7298. }
  7299. case 'screen' :
  7300. {
  7301. break;
  7302. }
  7303. case 'printermark' :
  7304. {
  7305. break;
  7306. }
  7307. case 'trapnet' :
  7308. {
  7309. break;
  7310. }
  7311. case 'watermark' :
  7312. {
  7313. break;
  7314. }
  7315. case '3d' :
  7316. {
  7317. break;
  7318. }
  7319. default :
  7320. {
  7321. break;
  7322. }
  7323. }
  7324. $annots .= '>>';
  7325. // create new annotation object
  7326. ++ $this->annot_obj_id;
  7327. $this->offsets[$this->annot_obj_id] = $this->bufferlen;
  7328. $this->_out($this->annot_obj_id . ' 0 obj');
  7329. $this->_out($annots);
  7330. $this->_out('endobj');
  7331. if ($formfield and ! isset($this->radiobutton_groups[$n][$pl['txt']]))
  7332. {
  7333. // store reference of form object
  7334. $this->form_obj_id[] = $this->annot_obj_id;
  7335. }
  7336. }
  7337. }
  7338. } // end for each page
  7339. }
  7340. /**
  7341. * Put appearance streams XObject used to define annotation's appearance states
  7342. * @param int $w annotation width
  7343. * @param int $h annotation height
  7344. * @param string $stream appearance stream
  7345. * @return int object ID
  7346. * @access protected
  7347. * @since 4.8.001 (2009-09-09)
  7348. */
  7349. protected function _putAPXObject($w = 0, $h = 0, $stream = '')
  7350. {
  7351. $stream = trim($stream);
  7352. ++ $this->apxo_obj_id;
  7353. $this->offsets[$this->apxo_obj_id] = $this->bufferlen;
  7354. $this->_out($this->apxo_obj_id . ' 0 obj');
  7355. $this->_out('<<');
  7356. $this->_out('/Type /XObject');
  7357. $this->_out('/Subtype /Form');
  7358. $this->_out('/FormType 1');
  7359. if ($this->compress)
  7360. {
  7361. $stream = gzcompress($stream);
  7362. $this->_out('/Filter /FlateDecode');
  7363. }
  7364. $rect = sprintf('%.2F %.2F', $w, $h);
  7365. $this->_out('/BBox [0 0 ' . $rect . ']');
  7366. $this->_out('/Matrix [1 0 0 1 0 0]');
  7367. $this->_out('/Resources <</ProcSet [/PDF]>>');
  7368. $this->_out('/Length ' . strlen($stream));
  7369. $this->_out('>>');
  7370. $this->_putstream($stream);
  7371. $this->_out('endobj');
  7372. return $this->apxo_obj_id;
  7373. }
  7374. /**
  7375. * Output fonts.
  7376. * @access protected
  7377. */
  7378. protected function _putfonts()
  7379. {
  7380. $nf = $this->n;
  7381. foreach ($this->diffs as $diff)
  7382. {
  7383. //Encodings
  7384. $this->_newobj();
  7385. $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . ']>>');
  7386. $this->_out('endobj');
  7387. }
  7388. $mqr = $this->get_mqr();
  7389. $this->set_mqr(false);
  7390. foreach ($this->FontFiles as $file => $info)
  7391. {
  7392. // search and get font file to embedd
  7393. $fontdir = $info['fontdir'];
  7394. $file = strtolower($file);
  7395. $fontfile = '';
  7396. // search files on various directories
  7397. if (file_exists($fontdir . $file))
  7398. {
  7399. $fontfile = $fontdir . $file;
  7400. }
  7401. elseif (file_exists($this->_getfontpath() . $file))
  7402. {
  7403. $fontfile = $this->_getfontpath() . $file;
  7404. }
  7405. elseif (file_exists($file))
  7406. {
  7407. $fontfile = $file;
  7408. }
  7409. if (! $this->empty_string($fontfile))
  7410. {
  7411. $font = file_get_contents($fontfile);
  7412. $compressed = (substr($file, - 2) == '.z');
  7413. if ((! $compressed) and (isset($info['length2'])))
  7414. {
  7415. $header = (ord($font{0}) == 128);
  7416. if ($header)
  7417. {
  7418. //Strip first binary header
  7419. $font = substr($font, 6);
  7420. }
  7421. if ($header and (ord($font{$info['length1']}) == 128))
  7422. {
  7423. //Strip second binary header
  7424. $font = substr($font, 0, $info['length1']) . substr($font, ($info['length1'] + 6));
  7425. }
  7426. }
  7427. $this->_newobj();
  7428. $this->FontFiles[$file]['n'] = $this->n;
  7429. $this->_out('<</Length ' . strlen($font));
  7430. if ($compressed)
  7431. {
  7432. $this->_out('/Filter /FlateDecode');
  7433. }
  7434. $this->_out('/Length1 ' . $info['length1']);
  7435. if (isset($info['length2']))
  7436. {
  7437. $this->_out('/Length2 ' . $info['length2'] . ' /Length3 0');
  7438. }
  7439. $this->_out('>>');
  7440. $this->_putstream($font);
  7441. $this->_out('endobj');
  7442. }
  7443. }
  7444. $this->set_mqr($mqr);
  7445. foreach ($this->fontkeys as $k)
  7446. {
  7447. //Font objects
  7448. $this->setFontSubBuffer($k, 'n', $this->n + 1);
  7449. $font = $this->getFontBuffer($k);
  7450. $type = $font['type'];
  7451. $name = $font['name'];
  7452. if ($type == 'core')
  7453. {
  7454. //Standard font
  7455. $obj_id = $this->_newobj();
  7456. $this->_out('<</Type /Font');
  7457. $this->_out('/Subtype /Type1');
  7458. $this->_out('/BaseFont /' . $name);
  7459. $this->_out('/Name /F' . $font['i']);
  7460. if ((strtolower($name) != 'symbol') and (strtolower($name) != 'zapfdingbats'))
  7461. {
  7462. $this->_out('/Encoding /WinAnsiEncoding');
  7463. }
  7464. if (strtolower($name) == 'helvetica')
  7465. {
  7466. // add default font for annotations
  7467. $this->annotation_fonts['helvetica'] = $k;
  7468. }
  7469. $this->_out('>>');
  7470. $this->_out('endobj');
  7471. }
  7472. elseif (($type == 'Type1') or ($type == 'TrueType'))
  7473. {
  7474. //Additional Type1 or TrueType font
  7475. $obj_id = $this->_newobj();
  7476. $this->_out('<</Type /Font');
  7477. $this->_out('/Subtype /' . $type);
  7478. $this->_out('/BaseFont /' . $name);
  7479. $this->_out('/Name /F' . $font['i']);
  7480. $this->_out('/FirstChar 32 /LastChar 255');
  7481. $this->_out('/Widths ' . ($this->n + 1) . ' 0 R');
  7482. $this->_out('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
  7483. if ($font['enc'])
  7484. {
  7485. if (isset($font['diff']))
  7486. {
  7487. $this->_out('/Encoding ' . ($nf + $font['diff']) . ' 0 R');
  7488. }
  7489. else
  7490. {
  7491. $this->_out('/Encoding /WinAnsiEncoding');
  7492. }
  7493. }
  7494. $this->_out('>>');
  7495. $this->_out('endobj');
  7496. // Widths
  7497. $this->_newobj();
  7498. $cw = &$font['cw'];
  7499. $s = '[';
  7500. for($i = 32; $i < 256; ++ $i)
  7501. {
  7502. $s .= $cw[$i] . ' ';
  7503. }
  7504. $this->_out($s . ']');
  7505. $this->_out('endobj');
  7506. //Descriptor
  7507. $this->_newobj();
  7508. $s = '<</Type /FontDescriptor /FontName /' . $name;
  7509. foreach ($font['desc'] as $fdk => $fdv)
  7510. {
  7511. $s .= ' /' . $fdk . ' ' . $fdv . '';
  7512. }
  7513. if (! $this->empty_string($font['file']))
  7514. {
  7515. $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R';
  7516. }
  7517. $this->_out($s . '>>');
  7518. $this->_out('endobj');
  7519. }
  7520. else
  7521. {
  7522. //Allow for additional types
  7523. $mtd = '_put' . strtolower($type);
  7524. if (! method_exists($this, $mtd))
  7525. {
  7526. $this->Error('Unsupported font type: ' . $type);
  7527. }
  7528. $obj_id = $this->$mtd($font);
  7529. }
  7530. // store object ID for current font
  7531. $this->font_obj_ids[$k] = $obj_id;
  7532. }
  7533. }
  7534. /**
  7535. * Outputs font widths
  7536. * @parameter array $font font data
  7537. * @parameter int $cidoffset offset for CID values
  7538. * @author Nicola Asuni
  7539. * @access protected
  7540. * @since 4.4.000 (2008-12-07)
  7541. */
  7542. protected function _putfontwidths($font, $cidoffset = 0)
  7543. {
  7544. ksort($font['cw']);
  7545. $rangeid = 0;
  7546. $range = array();
  7547. $prevcid = - 2;
  7548. $prevwidth = - 1;
  7549. $interval = false;
  7550. // for each character
  7551. foreach ($font['cw'] as $cid => $width)
  7552. {
  7553. $cid -= $cidoffset;
  7554. if ($width != $font['dw'])
  7555. {
  7556. if ($cid == ($prevcid + 1))
  7557. {
  7558. // consecutive CID
  7559. if ($width == $prevwidth)
  7560. {
  7561. if ($width == $range[$rangeid][0])
  7562. {
  7563. $range[$rangeid][] = $width;
  7564. }
  7565. else
  7566. {
  7567. array_pop($range[$rangeid]);
  7568. // new range
  7569. $rangeid = $prevcid;
  7570. $range[$rangeid] = array();
  7571. $range[$rangeid][] = $prevwidth;
  7572. $range[$rangeid][] = $width;
  7573. }
  7574. $interval = true;
  7575. $range[$rangeid]['interval'] = true;
  7576. }
  7577. else
  7578. {
  7579. if ($interval)
  7580. {
  7581. // new range
  7582. $rangeid = $cid;
  7583. $range[$rangeid] = array();
  7584. $range[$rangeid][] = $width;
  7585. }
  7586. else
  7587. {
  7588. $range[$rangeid][] = $width;
  7589. }
  7590. $interval = false;
  7591. }
  7592. }
  7593. else
  7594. {
  7595. // new range
  7596. $rangeid = $cid;
  7597. $range[$rangeid] = array();
  7598. $range[$rangeid][] = $width;
  7599. $interval = false;
  7600. }
  7601. $prevcid = $cid;
  7602. $prevwidth = $width;
  7603. }
  7604. }
  7605. // optimize ranges
  7606. $prevk = - 1;
  7607. $nextk = - 1;
  7608. $prevint = false;
  7609. foreach ($range as $k => $ws)
  7610. {
  7611. $cws = count($ws);
  7612. if (($k == $nextk) and (! $prevint) and ((! isset($ws['interval'])) or ($cws < 4)))
  7613. {
  7614. if (isset($range[$k]['interval']))
  7615. {
  7616. unset($range[$k]['interval']);
  7617. }
  7618. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  7619. unset($range[$k]);
  7620. }
  7621. else
  7622. {
  7623. $prevk = $k;
  7624. }
  7625. $nextk = $k + $cws;
  7626. if (isset($ws['interval']))
  7627. {
  7628. if ($cws > 3)
  7629. {
  7630. $prevint = true;
  7631. }
  7632. else
  7633. {
  7634. $prevint = false;
  7635. }
  7636. unset($range[$k]['interval']);
  7637. -- $nextk;
  7638. }
  7639. else
  7640. {
  7641. $prevint = false;
  7642. }
  7643. }
  7644. // output data
  7645. $w = '';
  7646. foreach ($range as $k => $ws)
  7647. {
  7648. if (count(array_count_values($ws)) == 1)
  7649. {
  7650. // interval mode is more compact
  7651. $w .= ' ' . $k . ' ' . ($k + count($ws) - 1) . ' ' . $ws[0];
  7652. }
  7653. else
  7654. {
  7655. // range mode
  7656. $w .= ' ' . $k . ' [ ' . implode(' ', $ws) . ' ]';
  7657. }
  7658. }
  7659. $this->_out('/W [' . $w . ' ]');
  7660. }
  7661. /**
  7662. * Adds unicode fonts.<br>
  7663. * Based on PDF Reference 1.3 (section 5)
  7664. * @parameter array $font font data
  7665. * @return int font object ID
  7666. * @access protected
  7667. * @author Nicola Asuni
  7668. * @since 1.52.0.TC005 (2005-01-05)
  7669. */
  7670. protected function _puttruetypeunicode($font)
  7671. {
  7672. // Type0 Font
  7673. // A composite font composed of other fonts, organized hierarchically
  7674. $obj_id = $this->_newobj();
  7675. $this->_out('<</Type /Font');
  7676. $this->_out('/Subtype /Type0');
  7677. $this->_out('/BaseFont /' . $font['name'] . '');
  7678. $this->_out('/Name /F' . $font['i']);
  7679. $this->_out('/Encoding /' . $font['enc']);
  7680. $this->_out('/ToUnicode /Identity-H');
  7681. $this->_out('/DescendantFonts [' . ($this->n + 1) . ' 0 R]');
  7682. $this->_out('>>');
  7683. $this->_out('endobj');
  7684. // CIDFontType2
  7685. // A CIDFont whose glyph descriptions are based on TrueType font technology
  7686. $this->_newobj();
  7687. $this->_out('<</Type /Font');
  7688. $this->_out('/Subtype /CIDFontType2');
  7689. $this->_out('/BaseFont /' . $font['name'] . '');
  7690. // A dictionary containing entries that define the character collection of the CIDFont.
  7691. $cidinfo = '/Registry ' . $this->_datastring($font['cidinfo']['Registry']);
  7692. $cidinfo .= ' /Ordering ' . $this->_datastring($font['cidinfo']['Ordering']);
  7693. $cidinfo .= ' /Supplement ' . $font['cidinfo']['Supplement'];
  7694. $this->_out('/CIDSystemInfo <<' . $cidinfo . '>>');
  7695. $this->_out('/FontDescriptor ' . ($this->n + 1) . ' 0 R');
  7696. $this->_out('/DW ' . $font['dw'] . ''); // default width
  7697. $this->_putfontwidths($font, 0);
  7698. $this->_out('/CIDToGIDMap ' . ($this->n + 2) . ' 0 R');
  7699. $this->_out('>>');
  7700. $this->_out('endobj');
  7701. // Font descriptor
  7702. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  7703. $this->_newobj();
  7704. $this->_out('<</Type /FontDescriptor');
  7705. $this->_out('/FontName /' . $font['name']);
  7706. foreach ($font['desc'] as $key => $value)
  7707. {
  7708. $this->_out('/' . $key . ' ' . $value);
  7709. }
  7710. $fontdir = '';
  7711. if (! $this->empty_string($font['file']))
  7712. {
  7713. // A stream containing a TrueType font
  7714. $this->_out('/FontFile2 ' . $this->FontFiles[$font['file']]['n'] . ' 0 R');
  7715. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  7716. }
  7717. $this->_out('>>');
  7718. $this->_out('endobj');
  7719. $this->_newobj();
  7720. if (isset($font['ctg']) and (! $this->empty_string($font['ctg'])))
  7721. {
  7722. // Embed CIDToGIDMap
  7723. // A specification of the mapping from CIDs to glyph indices
  7724. // search and get CTG font file to embedd
  7725. $ctgfile = strtolower($font['ctg']);
  7726. // search and get ctg font file to embedd
  7727. $fontfile = '';
  7728. // search files on various directories
  7729. if (file_exists($fontdir . $ctgfile))
  7730. {
  7731. $fontfile = $fontdir . $ctgfile;
  7732. }
  7733. elseif (file_exists($this->_getfontpath() . $ctgfile))
  7734. {
  7735. $fontfile = $this->_getfontpath() . $ctgfile;
  7736. }
  7737. elseif (file_exists($ctgfile))
  7738. {
  7739. $fontfile = $ctgfile;
  7740. }
  7741. if ($this->empty_string($fontfile))
  7742. {
  7743. $this->Error('Font file not found: ' . $ctgfile);
  7744. }
  7745. $size = filesize($fontfile);
  7746. $this->_out('<</Length ' . $size . '');
  7747. if (substr($fontfile, - 2) == '.z')
  7748. { // check file extension
  7749. // Decompresses data encoded using the public-domain
  7750. // zlib/deflate compression method, reproducing the
  7751. // original text or binary data
  7752. $this->_out('/Filter /FlateDecode');
  7753. }
  7754. $this->_out('>>');
  7755. $this->_putstream(file_get_contents($fontfile));
  7756. }
  7757. $this->_out('endobj');
  7758. return $obj_id;
  7759. }
  7760. /**
  7761. * Output CID-0 fonts.
  7762. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  7763. * @param array $font font data
  7764. * @return int font object ID
  7765. * @access protected
  7766. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  7767. * @since 3.2.000 (2008-06-23)
  7768. */
  7769. protected function _putcidfont0($font)
  7770. {
  7771. $cidoffset = 0;
  7772. if (! isset($font['cw'][1]))
  7773. {
  7774. $cidoffset = 31;
  7775. }
  7776. if (isset($font['cidinfo']['uni2cid']))
  7777. {
  7778. // convert unicode to cid.
  7779. $uni2cid = $font['cidinfo']['uni2cid'];
  7780. $cw = array();
  7781. foreach ($font['cw'] as $uni => $width)
  7782. {
  7783. if (isset($uni2cid[$uni]))
  7784. {
  7785. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  7786. }
  7787. elseif ($uni < 256)
  7788. {
  7789. $cw[$uni] = $width;
  7790. } // else unknown character
  7791. }
  7792. $font = array_merge($font, array('cw' => $cw));
  7793. }
  7794. $name = $font['name'];
  7795. $enc = $font['enc'];
  7796. if ($enc)
  7797. {
  7798. $longname = $name . '-' . $enc;
  7799. }
  7800. else
  7801. {
  7802. $longname = $name;
  7803. }
  7804. $obj_id = $this->_newobj();
  7805. $this->_out('<</Type /Font');
  7806. $this->_out('/Subtype /Type0');
  7807. $this->_out('/BaseFont /' . $longname);
  7808. $this->_out('/Name /F' . $font['i']);
  7809. if ($enc)
  7810. {
  7811. $this->_out('/Encoding /' . $enc);
  7812. }
  7813. $this->_out('/DescendantFonts [' . ($this->n + 1) . ' 0 R]');
  7814. $this->_out('>>');
  7815. $this->_out('endobj');
  7816. $this->_newobj();
  7817. $this->_out('<</Type /Font');
  7818. $this->_out('/Subtype /CIDFontType0');
  7819. $this->_out('/BaseFont /' . $name);
  7820. $cidinfo = '/Registry ' . $this->_datastring($font['cidinfo']['Registry']);
  7821. $cidinfo .= ' /Ordering ' . $this->_datastring($font['cidinfo']['Ordering']);
  7822. $cidinfo .= ' /Supplement ' . $font['cidinfo']['Supplement'];
  7823. $this->_out('/CIDSystemInfo <<' . $cidinfo . '>>');
  7824. $this->_out('/FontDescriptor ' . ($this->n + 1) . ' 0 R');
  7825. $this->_out('/DW ' . $font['dw']);
  7826. $this->_putfontwidths($font, $cidoffset);
  7827. $this->_out('>>');
  7828. $this->_out('endobj');
  7829. $this->_newobj();
  7830. $s = '<</Type /FontDescriptor /FontName /' . $name;
  7831. foreach ($font['desc'] as $k => $v)
  7832. {
  7833. if ($k != 'Style')
  7834. {
  7835. $s .= ' /' . $k . ' ' . $v . '';
  7836. }
  7837. }
  7838. $this->_out($s . '>>');
  7839. $this->_out('endobj');
  7840. return $obj_id;
  7841. }
  7842. /**
  7843. * Output images.
  7844. * @access protected
  7845. */
  7846. protected function _putimages()
  7847. {
  7848. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7849. foreach ($this->imagekeys as $file)
  7850. {
  7851. $info = $this->getImageBuffer($file);
  7852. $this->_newobj();
  7853. $this->setImageSubBuffer($file, 'n', $this->n);
  7854. $this->_out('<</Type /XObject');
  7855. $this->_out('/Subtype /Image');
  7856. $this->_out('/Width ' . $info['w']);
  7857. $this->_out('/Height ' . $info['h']);
  7858. if (array_key_exists('masked', $info))
  7859. {
  7860. $this->_out('/SMask ' . ($this->n - 1) . ' 0 R');
  7861. }
  7862. if ($info['cs'] == 'Indexed')
  7863. {
  7864. $this->_out('/ColorSpace [/Indexed /DeviceRGB ' . ((strlen($info['pal']) / 3) - 1) . ' ' . ($this->n + 1) . ' 0 R]');
  7865. }
  7866. else
  7867. {
  7868. $this->_out('/ColorSpace /' . $info['cs']);
  7869. if ($info['cs'] == 'DeviceCMYK')
  7870. {
  7871. $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  7872. }
  7873. }
  7874. $this->_out('/BitsPerComponent ' . $info['bpc']);
  7875. if (isset($info['f']))
  7876. {
  7877. $this->_out('/Filter /' . $info['f']);
  7878. }
  7879. if (isset($info['parms']))
  7880. {
  7881. $this->_out($info['parms']);
  7882. }
  7883. if (isset($info['trns']) and is_array($info['trns']))
  7884. {
  7885. $trns = '';
  7886. $count_info = count($info['trns']);
  7887. for($i = 0; $i < $count_info; ++ $i)
  7888. {
  7889. $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' ';
  7890. }
  7891. $this->_out('/Mask [' . $trns . ']');
  7892. }
  7893. $this->_out('/Length ' . strlen($info['data']) . '>>');
  7894. $this->_putstream($info['data']);
  7895. $this->_out('endobj');
  7896. //Palette
  7897. if ($info['cs'] == 'Indexed')
  7898. {
  7899. $this->_newobj();
  7900. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  7901. $this->_out('<<' . $filter . '/Length ' . strlen($pal) . '>>');
  7902. $this->_putstream($pal);
  7903. $this->_out('endobj');
  7904. }
  7905. }
  7906. }
  7907. /**
  7908. * Output Spot Colors Resources.
  7909. * @access protected
  7910. * @since 4.0.024 (2008-09-12)
  7911. */
  7912. protected function _putspotcolors()
  7913. {
  7914. foreach ($this->spot_colors as $name => $color)
  7915. {
  7916. $this->_newobj();
  7917. $this->spot_colors[$name]['n'] = $this->n;
  7918. $this->_out('[/Separation /' . str_replace(' ', '#20', $name));
  7919. $this->_out('/DeviceCMYK <<');
  7920. $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  7921. $this->_out(sprintf('/C1 [%.4F %.4F %.4F %.4F] ', $color['c'] / 100, $color['m'] / 100, $color['y'] / 100, $color['k'] / 100));
  7922. $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  7923. $this->_out('endobj');
  7924. }
  7925. }
  7926. /**
  7927. * Output object dictionary for images.
  7928. * @access protected
  7929. */
  7930. protected function _putxobjectdict()
  7931. {
  7932. foreach ($this->imagekeys as $file)
  7933. {
  7934. $info = $this->getImageBuffer($file);
  7935. $this->_out('/I' . $info['i'] . ' ' . $info['n'] . ' 0 R');
  7936. }
  7937. }
  7938. /**
  7939. * Output Resources Dictionary.
  7940. * @access protected
  7941. */
  7942. protected function _putresourcedict()
  7943. {
  7944. $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  7945. $this->_out('/Font <<');
  7946. foreach ($this->fontkeys as $fontkey)
  7947. {
  7948. $font = $this->getFontBuffer($fontkey);
  7949. $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
  7950. }
  7951. $this->_out('>>');
  7952. $this->_out('/XObject <<');
  7953. $this->_putxobjectdict();
  7954. $this->_out('>>');
  7955. // visibility
  7956. $this->_out('/Properties <</OC1 ' . $this->n_ocg_print . ' 0 R /OC2 ' . $this->n_ocg_view . ' 0 R>>');
  7957. // transparency
  7958. $this->_out('/ExtGState <<');
  7959. foreach ($this->extgstates as $k => $extgstate)
  7960. {
  7961. $this->_out('/GS' . $k . ' ' . $extgstate['n'] . ' 0 R');
  7962. }
  7963. $this->_out('>>');
  7964. // gradients
  7965. if (isset($this->gradients) and (count($this->gradients) > 0))
  7966. {
  7967. $this->_out('/Shading <<');
  7968. foreach ($this->gradients as $id => $grad)
  7969. {
  7970. $this->_out('/Sh' . $id . ' ' . $grad['id'] . ' 0 R');
  7971. }
  7972. $this->_out('>>');
  7973. }
  7974. // spot colors
  7975. if (isset($this->spot_colors) and (count($this->spot_colors) > 0))
  7976. {
  7977. $this->_out('/ColorSpace <<');
  7978. foreach ($this->spot_colors as $color)
  7979. {
  7980. $this->_out('/CS' . $color['i'] . ' ' . $color['n'] . ' 0 R');
  7981. }
  7982. $this->_out('>>');
  7983. }
  7984. }
  7985. /**
  7986. * Output Resources.
  7987. * @access protected
  7988. */
  7989. protected function _putresources()
  7990. {
  7991. $this->_putextgstates();
  7992. $this->_putocg();
  7993. $this->_putfonts();
  7994. $this->_putimages();
  7995. $this->_putspotcolors();
  7996. $this->_putshaders();
  7997. //Resource dictionary
  7998. $this->offsets[2] = $this->bufferlen;
  7999. $this->_out('2 0 obj');
  8000. $this->_out('<<');
  8001. $this->_putresourcedict();
  8002. $this->_out('>>');
  8003. $this->_out('endobj');
  8004. $this->_putbookmarks();
  8005. $this->_putEmbeddedFiles();
  8006. $this->_putannotsobjs();
  8007. $this->_putjavascript();
  8008. // encryption
  8009. if ($this->encrypted)
  8010. {
  8011. $this->_newobj();
  8012. $this->enc_obj_id = $this->n;
  8013. $this->_out('<<');
  8014. $this->_putencryption();
  8015. $this->_out('>>');
  8016. $this->_out('endobj');
  8017. }
  8018. }
  8019. /**
  8020. * Adds some Metadata information (Document Information Dictionary)
  8021. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  8022. * @access protected
  8023. */
  8024. protected function _putinfo()
  8025. {
  8026. if (! $this->empty_string($this->title))
  8027. {
  8028. // The document's title.
  8029. $this->_out('/Title ' . $this->_textstring($this->title));
  8030. }
  8031. if (! $this->empty_string($this->author))
  8032. {
  8033. // The name of the person who created the document.
  8034. $this->_out('/Author ' . $this->_textstring($this->author));
  8035. }
  8036. if (! $this->empty_string($this->subject))
  8037. {
  8038. // The subject of the document.
  8039. $this->_out('/Subject ' . $this->_textstring($this->subject));
  8040. }
  8041. if (! $this->empty_string($this->keywords))
  8042. {
  8043. // Keywords associated with the document.
  8044. $this->_out('/Keywords ' . $this->_textstring($this->keywords));
  8045. }
  8046. if (! $this->empty_string($this->creator))
  8047. {
  8048. // 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.
  8049. $this->_out('/Creator ' . $this->_textstring($this->creator));
  8050. }
  8051. if (defined('PDF_PRODUCER'))
  8052. {
  8053. // If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF.
  8054. $this->_out('/Producer ' . $this->_textstring(PDF_PRODUCER));
  8055. }
  8056. else
  8057. {
  8058. // default producer
  8059. $this->_out('/Producer ' . $this->_textstring('TCPDF'));
  8060. }
  8061. // The date and time the document was created, in human-readable form
  8062. $this->_out('/CreationDate ' . $this->_datestring());
  8063. // The date and time the document was most recently modified, in human-readable form
  8064. $this->_out('/ModDate ' . $this->_datestring());
  8065. // A name object indicating whether the document has been modified to include trapping information
  8066. //$this->_out('/Trapped /False');
  8067. }
  8068. /**
  8069. * Output Catalog.
  8070. * @access protected
  8071. */
  8072. protected function _putcatalog()
  8073. {
  8074. $this->_out('/Type /Catalog');
  8075. $this->_out('/Pages 1 0 R');
  8076. if ($this->ZoomMode == 'fullpage')
  8077. {
  8078. $this->_out('/OpenAction [3 0 R /Fit]');
  8079. }
  8080. elseif ($this->ZoomMode == 'fullwidth')
  8081. {
  8082. $this->_out('/OpenAction [3 0 R /FitH null]');
  8083. }
  8084. elseif ($this->ZoomMode == 'real')
  8085. {
  8086. $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  8087. }
  8088. elseif (! is_string($this->ZoomMode))
  8089. {
  8090. $this->_out('/OpenAction [3 0 R /XYZ null null ' . ($this->ZoomMode / 100) . ']');
  8091. }
  8092. if (isset($this->LayoutMode) and (! $this->empty_string($this->LayoutMode)))
  8093. {
  8094. $this->_out('/PageLayout /' . $this->LayoutMode . '');
  8095. }
  8096. if (isset($this->PageMode) and (! $this->empty_string($this->PageMode)))
  8097. {
  8098. $this->_out('/PageMode /' . $this->PageMode);
  8099. }
  8100. if (isset($this->l['a_meta_language']))
  8101. {
  8102. $this->_out('/Lang /' . $this->l['a_meta_language']);
  8103. }
  8104. $this->_out('/Names <<');
  8105. if ((! empty($this->javascript)) or (! empty($this->js_objects)))
  8106. {
  8107. $this->_out('/JavaScript ' . ($this->n_js) . ' 0 R');
  8108. }
  8109. $this->_out('>>');
  8110. if (count($this->outlines) > 0)
  8111. {
  8112. $this->_out('/Outlines ' . $this->OutlineRoot . ' 0 R');
  8113. $this->_out('/PageMode /UseOutlines');
  8114. }
  8115. $this->_putviewerpreferences();
  8116. $p = $this->n_ocg_print . ' 0 R';
  8117. $v = $this->n_ocg_view . ' 0 R';
  8118. $as = '<</Event /Print /OCGs [' . $p . ' ' . $v . '] /Category [/Print]>> <</Event /View /OCGs [' . $p . ' ' . $v . '] /Category [/View]>>';
  8119. $this->_out('/OCProperties <</OCGs [' . $p . ' ' . $v . '] /D <</ON [' . $p . '] /OFF [' . $v . '] /AS [' . $as . ']>>>>');
  8120. // AcroForm
  8121. if (! empty($this->form_obj_id) or ($this->sign and isset($this->signature_data['cert_type'])))
  8122. {
  8123. $this->_out('/AcroForm<<');
  8124. $objrefs = '';
  8125. if ($this->sign and isset($this->signature_data['cert_type']))
  8126. {
  8127. $objrefs .= $this->sig_obj_id . ' 0 R';
  8128. }
  8129. if (! empty($this->form_obj_id))
  8130. {
  8131. foreach ($this->form_obj_id as $objid)
  8132. {
  8133. $objrefs .= ' ' . $objid . ' 0 R';
  8134. }
  8135. }
  8136. $this->_out('/Fields [' . $objrefs . ']');
  8137. $this->_out('/NeedAppearances ' . (empty($this->form_obj_id) ? 'false' : 'true'));
  8138. if ($this->sign and isset($this->signature_data['cert_type']))
  8139. {
  8140. $this->_out('/SigFlags 3');
  8141. }
  8142. //$this->_out('/CO ');
  8143. if (isset($this->annotation_fonts) and ! empty($this->annotation_fonts))
  8144. {
  8145. $this->_out('/DR <<');
  8146. $this->_out('/Font <<');
  8147. foreach ($this->annotation_fonts as $font => $fontkey)
  8148. {
  8149. $this->_out('/F' . ($fontkey + 1) . ' ' . $this->font_obj_ids[$font] . ' 0 R');
  8150. }
  8151. $this->_out('>>');
  8152. $this->_out('>>');
  8153. }
  8154. $this->_out('/DA (/F' . (array_search('helvetica', $this->fontkeys) + 1) . ' 0 Tf 0 g)');
  8155. $this->_out('/Q ' . (($this->rtl) ? '2' : '0'));
  8156. //$this->_out('/XFA ');
  8157. $this->_out('>>');
  8158. // signatures
  8159. if ($this->sign and isset($this->signature_data['cert_type']))
  8160. {
  8161. if ($this->signature_data['cert_type'] > 0)
  8162. {
  8163. $this->_out('/Perms<</DocMDP ' . ($this->sig_obj_id + 1) . ' 0 R>>');
  8164. }
  8165. else
  8166. {
  8167. $this->_out('/Perms<</UR3 ' . ($this->sig_obj_id + 1) . ' 0 R>>');
  8168. }
  8169. }
  8170. }
  8171. }
  8172. /**
  8173. * Output viewer preferences.
  8174. * @author Nicola asuni
  8175. * @since 3.1.000 (2008-06-09)
  8176. * @access protected
  8177. */
  8178. protected function _putviewerpreferences()
  8179. {
  8180. $this->_out('/ViewerPreferences<<');
  8181. if ($this->rtl)
  8182. {
  8183. $this->_out('/Direction /R2L');
  8184. }
  8185. else
  8186. {
  8187. $this->_out('/Direction /L2R');
  8188. }
  8189. if (isset($this->viewer_preferences['HideToolbar']) and ($this->viewer_preferences['HideToolbar']))
  8190. {
  8191. $this->_out('/HideToolbar true');
  8192. }
  8193. if (isset($this->viewer_preferences['HideMenubar']) and ($this->viewer_preferences['HideMenubar']))
  8194. {
  8195. $this->_out('/HideMenubar true');
  8196. }
  8197. if (isset($this->viewer_preferences['HideWindowUI']) and ($this->viewer_preferences['HideWindowUI']))
  8198. {
  8199. $this->_out('/HideWindowUI true');
  8200. }
  8201. if (isset($this->viewer_preferences['FitWindow']) and ($this->viewer_preferences['FitWindow']))
  8202. {
  8203. $this->_out('/FitWindow true');
  8204. }
  8205. if (isset($this->viewer_preferences['CenterWindow']) and ($this->viewer_preferences['CenterWindow']))
  8206. {
  8207. $this->_out('/CenterWindow true');
  8208. }
  8209. if (isset($this->viewer_preferences['DisplayDocTitle']) and ($this->viewer_preferences['DisplayDocTitle']))
  8210. {
  8211. $this->_out('/DisplayDocTitle true');
  8212. }
  8213. if (isset($this->viewer_preferences['NonFullScreenPageMode']))
  8214. {
  8215. $this->_out('/NonFullScreenPageMode /' . $this->viewer_preferences['NonFullScreenPageMode'] . '');
  8216. }
  8217. if (isset($this->viewer_preferences['ViewArea']))
  8218. {
  8219. $this->_out('/ViewArea /' . $this->viewer_preferences['ViewArea']);
  8220. }
  8221. if (isset($this->viewer_preferences['ViewClip']))
  8222. {
  8223. $this->_out('/ViewClip /' . $this->viewer_preferences['ViewClip']);
  8224. }
  8225. if (isset($this->viewer_preferences['PrintArea']))
  8226. {
  8227. $this->_out('/PrintArea /' . $this->viewer_preferences['PrintArea']);
  8228. }
  8229. if (isset($this->viewer_preferences['PrintClip']))
  8230. {
  8231. $this->_out('/PrintClip /' . $this->viewer_preferences['PrintClip']);
  8232. }
  8233. if (isset($this->viewer_preferences['PrintScaling']))
  8234. {
  8235. $this->_out('/PrintScaling /' . $this->viewer_preferences['PrintScaling']);
  8236. }
  8237. if (isset($this->viewer_preferences['Duplex']) and (! $this->empty_string($this->viewer_preferences['Duplex'])))
  8238. {
  8239. $this->_out('/Duplex /' . $this->viewer_preferences['Duplex']);
  8240. }
  8241. if (isset($this->viewer_preferences['PickTrayByPDFSize']))
  8242. {
  8243. if ($this->viewer_preferences['PickTrayByPDFSize'])
  8244. {
  8245. $this->_out('/PickTrayByPDFSize true');
  8246. }
  8247. else
  8248. {
  8249. $this->_out('/PickTrayByPDFSize false');
  8250. }
  8251. }
  8252. if (isset($this->viewer_preferences['PrintPageRange']))
  8253. {
  8254. $PrintPageRangeNum = '';
  8255. foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v)
  8256. {
  8257. $PrintPageRangeNum .= ' ' . ($v - 1) . '';
  8258. }
  8259. $this->_out('/PrintPageRange [' . substr($PrintPageRangeNum, 1) . ']');
  8260. }
  8261. if (isset($this->viewer_preferences['NumCopies']))
  8262. {
  8263. $this->_out('/NumCopies ' . intval($this->viewer_preferences['NumCopies']));
  8264. }
  8265. $this->_out('>>');
  8266. }
  8267. /**
  8268. * Output trailer.
  8269. * @access protected
  8270. */
  8271. protected function _puttrailer()
  8272. {
  8273. $this->_out('/Size ' . ($this->n + 1));
  8274. $this->_out('/Root ' . $this->n . ' 0 R');
  8275. $this->_out('/Info ' . ($this->n - 1) . ' 0 R');
  8276. if ($this->encrypted)
  8277. {
  8278. $this->_out('/Encrypt ' . $this->enc_obj_id . ' 0 R');
  8279. $this->_out('/ID [()()]');
  8280. }
  8281. }
  8282. /**
  8283. * Output PDF header.
  8284. * @access protected
  8285. */
  8286. protected function _putheader()
  8287. {
  8288. $this->_out('%PDF-' . $this->PDFVersion);
  8289. }
  8290. /**
  8291. * Output end of document (EOF).
  8292. * @access protected
  8293. */
  8294. protected function _enddoc()
  8295. {
  8296. $this->state = 1;
  8297. $this->_putheader();
  8298. $this->_putpages();
  8299. $this->_putresources();
  8300. // Signature
  8301. if ($this->sign and isset($this->signature_data['cert_type']))
  8302. {
  8303. // widget annotation for signature
  8304. $this->sig_obj_id = $this->_newobj();
  8305. // --- replace signature ID on the first page ---
  8306. // get the document content
  8307. $pdfdoc = $this->getBuffer();
  8308. // Remove the original buffer
  8309. if (isset($this->diskcache) and $this->diskcache)
  8310. {
  8311. // remove buffer file from cache
  8312. unlink($this->buffer);
  8313. }
  8314. unset($this->buffer);
  8315. $signature_widget_ref = sprintf('%u 0 R', $this->sig_obj_id);
  8316. $signature_widget_ref .= str_repeat(' ', (strlen($this->sig_annot_ref) - strlen($signature_widget_ref)));
  8317. $pdfdoc = str_replace($this->sig_annot_ref, $signature_widget_ref, $pdfdoc);
  8318. $this->diskcache = false;
  8319. $this->buffer = &$pdfdoc;
  8320. $this->bufferlen = strlen($pdfdoc);
  8321. // ---
  8322. $this->_out('<<');
  8323. $this->_out('/Type /Annot /Subtype /Widget /Rect [0 0 0 0]');
  8324. $this->_out('/P 3 0 R'); // link to first page object
  8325. $this->_out('/FT /Sig');
  8326. $this->_out('/T ' . $this->_textstring('Signature'));
  8327. $this->_out('/Ff 0');
  8328. $this->_out('/V ' . ($this->sig_obj_id + 1) . ' 0 R');
  8329. $this->_out('>>');
  8330. $this->_out('endobj');
  8331. // signature
  8332. $this->_newobj();
  8333. $this->_out('<<');
  8334. $this->_putsignature();
  8335. $this->_out('>>');
  8336. $this->_out('endobj');
  8337. }
  8338. // Info
  8339. $this->_newobj();
  8340. $this->_out('<<');
  8341. $this->_putinfo();
  8342. $this->_out('>>');
  8343. $this->_out('endobj');
  8344. // Catalog
  8345. $this->_newobj();
  8346. $this->_out('<<');
  8347. $this->_putcatalog();
  8348. $this->_out('>>');
  8349. $this->_out('endobj');
  8350. // Cross-ref
  8351. $o = $this->bufferlen;
  8352. $this->_out('xref');
  8353. $this->_out('0 ' . ($this->n + 1));
  8354. $this->_out('0000000000 65535 f ');
  8355. for($i = 1; $i <= $this->n; ++ $i)
  8356. {
  8357. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  8358. }
  8359. // Embedded Files
  8360. if (isset($this->embeddedfiles) and count($this->embeddedfiles) > 0)
  8361. {
  8362. $this->_out($this->embedded_start_obj_id . ' ' . count($this->embeddedfiles));
  8363. foreach ($this->embeddedfiles as $filename => $filedata)
  8364. {
  8365. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$filedata['n']]));
  8366. }
  8367. }
  8368. // Annotation Objects
  8369. if ($this->annot_obj_id > $this->annots_start_obj_id)
  8370. {
  8371. $this->_out(($this->annots_start_obj_id + 1) . ' ' . ($this->annot_obj_id - $this->annots_start_obj_id));
  8372. for($i = ($this->annots_start_obj_id + 1); $i <= $this->annot_obj_id; ++ $i)
  8373. {
  8374. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  8375. }
  8376. }
  8377. // Javascript Objects
  8378. if ($this->js_obj_id > $this->js_start_obj_id)
  8379. {
  8380. $this->_out(($this->js_start_obj_id + 1) . ' ' . ($this->js_obj_id - $this->js_start_obj_id));
  8381. for($i = ($this->js_start_obj_id + 1); $i <= $this->js_obj_id; ++ $i)
  8382. {
  8383. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  8384. }
  8385. }
  8386. // Appearance streams XObjects
  8387. if ($this->apxo_obj_id > $this->apxo_start_obj_id)
  8388. {
  8389. $this->_out(($this->apxo_start_obj_id + 1) . ' ' . ($this->apxo_obj_id - $this->apxo_start_obj_id));
  8390. for($i = ($this->apxo_start_obj_id + 1); $i <= $this->apxo_obj_id; ++ $i)
  8391. {
  8392. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  8393. }
  8394. }
  8395. //Trailer
  8396. $this->_out('trailer');
  8397. $this->_out('<<');
  8398. $this->_puttrailer();
  8399. $this->_out('>>');
  8400. $this->_out('startxref');
  8401. $this->_out($o);
  8402. $this->_out('%%EOF');
  8403. $this->state = 3; // end-of-doc
  8404. if ($this->diskcache)
  8405. {
  8406. // remove temporary files used for images
  8407. foreach ($this->imagekeys as $key)
  8408. {
  8409. // remove temporary files
  8410. unlink($this->images[$key]);
  8411. }
  8412. foreach ($this->fontkeys as $key)
  8413. {
  8414. // remove temporary files
  8415. unlink($this->fonts[$key]);
  8416. }
  8417. }
  8418. }
  8419. /**
  8420. * Initialize a new page.
  8421. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  8422. * @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>
  8423. * @access protected
  8424. */
  8425. protected function _beginpage($orientation = '', $format = '')
  8426. {
  8427. ++ $this->page;
  8428. $this->setPageBuffer($this->page, '');
  8429. // initialize array for graphics tranformation positions inside a page buffer
  8430. $this->transfmrk[$this->page] = array();
  8431. $this->state = 2;
  8432. if ($this->empty_string($orientation))
  8433. {
  8434. if (isset($this->CurOrientation))
  8435. {
  8436. $orientation = $this->CurOrientation;
  8437. }
  8438. else
  8439. {
  8440. $orientation = 'P';
  8441. }
  8442. }
  8443. if ($this->empty_string($format))
  8444. {
  8445. $this->setPageOrientation($orientation);
  8446. }
  8447. else
  8448. {
  8449. $this->setPageFormat($format, $orientation);
  8450. }
  8451. if ($this->rtl)
  8452. {
  8453. $this->x = $this->w - $this->rMargin;
  8454. }
  8455. else
  8456. {
  8457. $this->x = $this->lMargin;
  8458. }
  8459. $this->y = $this->tMargin;
  8460. if (isset($this->newpagegroup[$this->page]))
  8461. {
  8462. // start a new group
  8463. $n = sizeof($this->pagegroups) + 1;
  8464. $alias = '{nb' . $n . '}';
  8465. $this->pagegroups[$alias] = 1;
  8466. $this->currpagegroup = $alias;
  8467. }
  8468. elseif ($this->currpagegroup)
  8469. {
  8470. ++ $this->pagegroups[$this->currpagegroup];
  8471. }
  8472. }
  8473. /**
  8474. * Mark end of page.
  8475. * @access protected
  8476. */
  8477. protected function _endpage()
  8478. {
  8479. $this->setVisibility('all');
  8480. $this->state = 1;
  8481. }
  8482. /**
  8483. * Begin a new object and return the object number.
  8484. * @return int object number
  8485. * @access protected
  8486. */
  8487. protected function _newobj()
  8488. {
  8489. ++ $this->n;
  8490. $this->offsets[$this->n] = $this->bufferlen;
  8491. $this->_out($this->n . ' 0 obj');
  8492. return $this->n;
  8493. }
  8494. /**
  8495. * Underline text.
  8496. * @param int $x X coordinate
  8497. * @param int $y Y coordinate
  8498. * @param string $txt text to underline
  8499. * @access protected
  8500. */
  8501. protected function _dounderline($x, $y, $txt)
  8502. {
  8503. $w = $this->GetStringWidth($txt);
  8504. return $this->_dounderlinew($x, $y, $w);
  8505. }
  8506. /**
  8507. * Line through text.
  8508. * @param int $x X coordinate
  8509. * @param int $y Y coordinate
  8510. * @param string $txt text to linethrough
  8511. * @access protected
  8512. */
  8513. protected function _dolinethrough($x, $y, $txt)
  8514. {
  8515. $w = $this->GetStringWidth($txt);
  8516. return $this->_dolinethroughw($x, $y, $w);
  8517. }
  8518. /**
  8519. * Underline for rectangular text area.
  8520. * @param int $x X coordinate
  8521. * @param int $y Y coordinate
  8522. * @param int $w width to underline
  8523. * @access protected
  8524. * @since 4.8.008 (2009-09-29)
  8525. */
  8526. protected function _dounderlinew($x, $y, $w)
  8527. {
  8528. $up = $this->CurrentFont['up'];
  8529. $ut = $this->CurrentFont['ut'];
  8530. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, - $ut / 1000 * $this->FontSizePt);
  8531. }
  8532. /**
  8533. * Line through for rectangular text area.
  8534. * @param int $x X coordinate
  8535. * @param int $y Y coordinate
  8536. * @param string $txt text to linethrough
  8537. * @access protected
  8538. * @since 4.8.008 (2009-09-29)
  8539. */
  8540. protected function _dolinethroughw($x, $y, $w)
  8541. {
  8542. $up = $this->CurrentFont['up'];
  8543. $ut = $this->CurrentFont['ut'];
  8544. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - ($y - ($this->FontSize / 2) - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, - $ut / 1000 * $this->FontSizePt);
  8545. }
  8546. /**
  8547. * Read a 4-byte integer from file.
  8548. * @param string $f file name.
  8549. * @return 4-byte integer
  8550. * @access protected
  8551. */
  8552. protected function _freadint($f)
  8553. {
  8554. $a = unpack('Ni', fread($f, 4));
  8555. return $a['i'];
  8556. }
  8557. /**
  8558. * Add "\" before "\", "(" and ")"
  8559. * @param string $s string to escape.
  8560. * @return string escaped string.
  8561. * @access protected
  8562. */
  8563. protected function _escape($s)
  8564. {
  8565. // the chr(13) substitution fixes the Bugs item #1421290.
  8566. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  8567. }
  8568. /**
  8569. * Format a data string for meta information
  8570. * @param string $s data string to escape.
  8571. * @return string escaped string.
  8572. * @access protected
  8573. */
  8574. protected function _datastring($s)
  8575. {
  8576. if ($this->encrypted)
  8577. {
  8578. $s = $this->_RC4($this->_objectkey($this->n), $s);
  8579. }
  8580. return '(' . $this->_escape($s) . ')';
  8581. }
  8582. /**
  8583. * Format a data string for annotation objects
  8584. * @param string $s data string to escape.
  8585. * @return string escaped string.
  8586. * @access protected
  8587. */
  8588. protected function _dataannobjstring($s)
  8589. {
  8590. if ($this->encrypted)
  8591. {
  8592. $s = $this->_RC4($this->_objectkey($this->annot_obj_id + 1), $s);
  8593. }
  8594. return '(' . $this->_escape($s) . ')';
  8595. }
  8596. /**
  8597. * Returns a formatted date for meta information
  8598. * @return string escaped date string.
  8599. * @access protected
  8600. * @since 4.6.028 (2009-08-25)
  8601. */
  8602. protected function _datestring()
  8603. {
  8604. $current_time = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0) . '\'';
  8605. return $this->_datastring('D:' . $current_time);
  8606. }
  8607. /**
  8608. * Format a text string for meta information
  8609. * @param string $s string to escape.
  8610. * @return string escaped string.
  8611. * @access protected
  8612. */
  8613. protected function _textstring($s)
  8614. {
  8615. if ($this->isunicode)
  8616. {
  8617. //Convert string to UTF-16BE
  8618. $s = $this->UTF8ToUTF16BE($s, true);
  8619. }
  8620. return $this->_datastring($s);
  8621. }
  8622. /**
  8623. * Format a text string
  8624. * @param string $s string to escape.
  8625. * @return string escaped string.
  8626. * @access protected
  8627. */
  8628. protected function _escapetext($s)
  8629. {
  8630. if ($this->isunicode)
  8631. {
  8632. if (($this->CurrentFont['type'] == 'core') or ($this->CurrentFont['type'] == 'TrueType') or ($this->CurrentFont['type'] == 'Type1'))
  8633. {
  8634. $s = $this->UTF8ToLatin1($s);
  8635. }
  8636. else
  8637. {
  8638. //Convert string to UTF-16BE and reverse RTL language
  8639. $s = $this->utf8StrRev($s, false, $this->tmprtl);
  8640. }
  8641. }
  8642. return $this->_escape($s);
  8643. }
  8644. /**
  8645. * Output a stream.
  8646. * @param string $s string to output.
  8647. * @access protected
  8648. */
  8649. protected function _putstream($s)
  8650. {
  8651. if ($this->encrypted)
  8652. {
  8653. $s = $this->_RC4($this->_objectkey($this->n), $s);
  8654. }
  8655. $this->_out('stream');
  8656. $this->_out($s);
  8657. $this->_out('endstream');
  8658. }
  8659. /**
  8660. * Output a string to the document.
  8661. * @param string $s string to output.
  8662. * @access protected
  8663. */
  8664. protected function _out($s)
  8665. {
  8666. if ($this->state == 2)
  8667. {
  8668. if ((! $this->InFooter) and isset($this->footerlen[$this->page]) and ($this->footerlen[$this->page] > 0))
  8669. {
  8670. // puts data before page footer
  8671. $pagebuff = $this->getPageBuffer($this->page);
  8672. $page = substr($pagebuff, 0, - $this->footerlen[$this->page]);
  8673. $footer = substr($pagebuff, - $this->footerlen[$this->page]);
  8674. $this->setPageBuffer($this->page, $page . $s . "\n" . $footer);
  8675. // update footer position
  8676. $this->footerpos[$this->page] += strlen($s . "\n");
  8677. }
  8678. else
  8679. {
  8680. $this->setPageBuffer($this->page, $s . "\n", true);
  8681. }
  8682. }
  8683. else
  8684. {
  8685. $this->setBuffer($s . "\n");
  8686. }
  8687. }
  8688. /**
  8689. * Converts UTF-8 strings to codepoints array.<br>
  8690. * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  8691. * Based on: http://www.faqs.org/rfcs/rfc3629.html
  8692. * <pre>
  8693. * Char. number range | UTF-8 octet sequence
  8694. * (hexadecimal) | (binary)
  8695. * --------------------+-----------------------------------------------
  8696. * 0000 0000-0000 007F | 0xxxxxxx
  8697. * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  8698. * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  8699. * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  8700. * ---------------------------------------------------------------------
  8701. *
  8702. * ABFN notation:
  8703. * ---------------------------------------------------------------------
  8704. * UTF8-octets = *( UTF8-char )
  8705. * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  8706. * UTF8-1 = %x00-7F
  8707. * UTF8-2 = %xC2-DF UTF8-tail
  8708. *
  8709. * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  8710. * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  8711. * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  8712. * %xF4 %x80-8F 2( UTF8-tail )
  8713. * UTF8-tail = %x80-BF
  8714. * ---------------------------------------------------------------------
  8715. * </pre>
  8716. * @param string $str string to process.
  8717. * @return array containing codepoints (UTF-8 characters values)
  8718. * @access protected
  8719. * @author Nicola Asuni
  8720. * @since 1.53.0.TC005 (2005-01-05)
  8721. */
  8722. protected function UTF8StringToArray($str)
  8723. {
  8724. if (isset($this->cache_UTF8StringToArray['_' . $str]))
  8725. {
  8726. // return cached value
  8727. return ($this->cache_UTF8StringToArray['_' . $str]);
  8728. }
  8729. // check cache size
  8730. if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray)
  8731. {
  8732. // remove first element
  8733. array_shift($this->cache_UTF8StringToArray);
  8734. }
  8735. ++ $this->cache_size_UTF8StringToArray;
  8736. if (! $this->isunicode)
  8737. {
  8738. // split string into array of equivalent codes
  8739. $strarr = array();
  8740. $strlen = strlen($str);
  8741. for($i = 0; $i < $strlen; ++ $i)
  8742. {
  8743. $strarr[] = ord($str{$i});
  8744. }
  8745. // insert new value on cache
  8746. $this->cache_UTF8StringToArray['_' . $str] = $strarr;
  8747. return $strarr;
  8748. }
  8749. $unicode = array(); // array containing unicode values
  8750. $bytes = array(); // array containing single character byte sequences
  8751. $numbytes = 1; // number of octetc needed to represent the UTF-8 character
  8752. $str .= ''; // force $str to be a string
  8753. $length = strlen($str);
  8754. for($i = 0; $i < $length; ++ $i)
  8755. {
  8756. $char = ord($str{$i}); // get one string character at time
  8757. if (count($bytes) == 0)
  8758. { // get starting octect
  8759. if ($char <= 0x7F)
  8760. {
  8761. $unicode[] = $char; // use the character "as is" because is ASCII
  8762. $numbytes = 1;
  8763. }
  8764. elseif (($char >> 0x05) == 0x06)
  8765. { // 2 bytes character (0x06 = 110 BIN)
  8766. $bytes[] = ($char - 0xC0) << 0x06;
  8767. $numbytes = 2;
  8768. }
  8769. elseif (($char >> 0x04) == 0x0E)
  8770. { // 3 bytes character (0x0E = 1110 BIN)
  8771. $bytes[] = ($char - 0xE0) << 0x0C;
  8772. $numbytes = 3;
  8773. }
  8774. elseif (($char >> 0x03) == 0x1E)
  8775. { // 4 bytes character (0x1E = 11110 BIN)
  8776. $bytes[] = ($char - 0xF0) << 0x12;
  8777. $numbytes = 4;
  8778. }
  8779. else
  8780. {
  8781. // use replacement character for other invalid sequences
  8782. $unicode[] = 0xFFFD;
  8783. $bytes = array();
  8784. $numbytes = 1;
  8785. }
  8786. }
  8787. elseif (($char >> 0x06) == 0x02)
  8788. { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  8789. $bytes[] = $char - 0x80;
  8790. if (count($bytes) == $numbytes)
  8791. {
  8792. // compose UTF-8 bytes to a single unicode value
  8793. $char = $bytes[0];
  8794. for($j = 1; $j < $numbytes; ++ $j)
  8795. {
  8796. $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
  8797. }
  8798. if ((($char >= 0xD800) and ($char <= 0xDFFF)) or ($char >= 0x10FFFF))
  8799. {
  8800. /* The definition of UTF-8 prohibits encoding character numbers between
  8801. U+D800 and U+DFFF, which are reserved for use with the UTF-16
  8802. encoding form (as surrogate pairs) and do not directly represent
  8803. characters. */
  8804. $unicode[] = 0xFFFD; // use replacement character
  8805. }
  8806. else
  8807. {
  8808. $unicode[] = $char; // add char to array
  8809. }
  8810. // reset data for next char
  8811. $bytes = array();
  8812. $numbytes = 1;
  8813. }
  8814. }
  8815. else
  8816. {
  8817. // use replacement character for other invalid sequences
  8818. $unicode[] = 0xFFFD;
  8819. $bytes = array();
  8820. $numbytes = 1;
  8821. }
  8822. }
  8823. // insert new value on cache
  8824. $this->cache_UTF8StringToArray['_' . $str] = $unicode;
  8825. return $unicode;
  8826. }
  8827. /**
  8828. * Converts UTF-8 strings to UTF16-BE.<br>
  8829. * @param string $str string to process.
  8830. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  8831. * @return string
  8832. * @access protected
  8833. * @author Nicola Asuni
  8834. * @since 1.53.0.TC005 (2005-01-05)
  8835. * @uses UTF8StringToArray(), arrUTF8ToUTF16BE()
  8836. */
  8837. protected function UTF8ToUTF16BE($str, $setbom = true)
  8838. {
  8839. if (! $this->isunicode)
  8840. {
  8841. return $str; // string is not in unicode
  8842. }
  8843. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  8844. return $this->arrUTF8ToUTF16BE($unicode, $setbom);
  8845. }
  8846. /**
  8847. * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  8848. * @param string $str string to process.
  8849. * @return string
  8850. * @author Andrew Whitehead, Nicola Asuni
  8851. * @access protected
  8852. * @since 3.2.000 (2008-06-23)
  8853. */
  8854. protected function UTF8ToLatin1($str)
  8855. {
  8856. global $utf8tolatin;
  8857. if (! $this->isunicode)
  8858. {
  8859. return $str; // string is not in unicode
  8860. }
  8861. $outstr = ''; // string to be returned
  8862. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  8863. foreach ($unicode as $char)
  8864. {
  8865. if ($char < 256)
  8866. {
  8867. $outstr .= chr($char);
  8868. }
  8869. elseif (array_key_exists($char, $utf8tolatin))
  8870. {
  8871. // map from UTF-8
  8872. $outstr .= chr($utf8tolatin[$char]);
  8873. }
  8874. elseif ($char == 0xFFFD)
  8875. {
  8876. // skip
  8877. }
  8878. else
  8879. {
  8880. $outstr .= '?';
  8881. }
  8882. }
  8883. return $outstr;
  8884. }
  8885. /**
  8886. * Converts UTF-8 characters array to Latin1<br>
  8887. * @param array $unicode array containing UTF-8 unicode values
  8888. * @return array
  8889. * @author Nicola Asuni
  8890. * @access protected
  8891. * @since 4.8.023 (2010-01-15)
  8892. */
  8893. protected function UTF8ArrToLatin1($unicode)
  8894. {
  8895. global $utf8tolatin;
  8896. if ((! $this->isunicode) or ($this->CurrentFont['type'] == 'TrueTypeUnicode') or ($this->CurrentFont['type'] == 'cidfont0'))
  8897. {
  8898. return $unicode; // string is not in unicode
  8899. }
  8900. $outarr = array(); // array to be returned
  8901. foreach ($unicode as $char)
  8902. {
  8903. if ($char < 256)
  8904. {
  8905. $outarr[] = $char;
  8906. }
  8907. elseif (array_key_exists($char, $utf8tolatin))
  8908. {
  8909. // map from UTF-8
  8910. $outarr[] = $utf8tolatin[$char];
  8911. }
  8912. elseif ($char == 0xFFFD)
  8913. {
  8914. // skip
  8915. }
  8916. else
  8917. {
  8918. $outarr[] = 63; // '?' character
  8919. }
  8920. }
  8921. return $outarr;
  8922. }
  8923. /**
  8924. * Converts array of UTF-8 characters to UTF16-BE string.<br>
  8925. * Based on: http://www.faqs.org/rfcs/rfc2781.html
  8926. * <pre>
  8927. * Encoding UTF-16:
  8928. *
  8929. * Encoding of a single character from an ISO 10646 character value to
  8930. * UTF-16 proceeds as follows. Let U be the character number, no greater
  8931. * than 0x10FFFF.
  8932. *
  8933. * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  8934. * terminate.
  8935. *
  8936. * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  8937. * U' must be less than or equal to 0xFFFFF. That is, U' can be
  8938. * represented in 20 bits.
  8939. *
  8940. * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  8941. * 0xDC00, respectively. These integers each have 10 bits free to
  8942. * encode the character value, for a total of 20 bits.
  8943. *
  8944. * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  8945. * bits of W1 and the 10 low-order bits of U' to the 10 low-order
  8946. * bits of W2. Terminate.
  8947. *
  8948. * Graphically, steps 2 through 4 look like:
  8949. * U' = yyyyyyyyyyxxxxxxxxxx
  8950. * W1 = 110110yyyyyyyyyy
  8951. * W2 = 110111xxxxxxxxxx
  8952. * </pre>
  8953. * @param array $unicode array containing UTF-8 unicode values
  8954. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  8955. * @return string
  8956. * @access protected
  8957. * @author Nicola Asuni
  8958. * @since 2.1.000 (2008-01-08)
  8959. * @see UTF8ToUTF16BE()
  8960. */
  8961. protected function arrUTF8ToUTF16BE($unicode, $setbom = true)
  8962. {
  8963. $outstr = ''; // string to be returned
  8964. if ($setbom)
  8965. {
  8966. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  8967. }
  8968. foreach ($unicode as $char)
  8969. {
  8970. if ($char == 0xFFFD)
  8971. {
  8972. $outstr .= "\xFF\xFD"; // replacement character
  8973. }
  8974. elseif ($char < 0x10000)
  8975. {
  8976. $outstr .= chr($char >> 0x08);
  8977. $outstr .= chr($char & 0xFF);
  8978. }
  8979. else
  8980. {
  8981. $char -= 0x10000;
  8982. $w1 = 0xD800 | ($char >> 0x10);
  8983. $w2 = 0xDC00 | ($char & 0x3FF);
  8984. $outstr .= chr($w1 >> 0x08);
  8985. $outstr .= chr($w1 & 0xFF);
  8986. $outstr .= chr($w2 >> 0x08);
  8987. $outstr .= chr($w2 & 0xFF);
  8988. }
  8989. }
  8990. return $outstr;
  8991. }
  8992. // ====================================================
  8993. /**
  8994. * Set header font.
  8995. * @param array $font font
  8996. * @access public
  8997. * @since 1.1
  8998. */
  8999. public function setHeaderFont($font)
  9000. {
  9001. $this->header_font = $font;
  9002. }
  9003. /**
  9004. * Get header font.
  9005. * @return array()
  9006. * @access public
  9007. * @since 4.0.012 (2008-07-24)
  9008. */
  9009. public function getHeaderFont()
  9010. {
  9011. return $this->header_font;
  9012. }
  9013. /**
  9014. * Set footer font.
  9015. * @param array $font font
  9016. * @access public
  9017. * @since 1.1
  9018. */
  9019. public function setFooterFont($font)
  9020. {
  9021. $this->footer_font = $font;
  9022. }
  9023. /**
  9024. * Get Footer font.
  9025. * @return array()
  9026. * @access public
  9027. * @since 4.0.012 (2008-07-24)
  9028. */
  9029. public function getFooterFont()
  9030. {
  9031. return $this->footer_font;
  9032. }
  9033. /**
  9034. * Set language array.
  9035. * @param array $language
  9036. * @access public
  9037. * @since 1.1
  9038. */
  9039. public function setLanguageArray($language)
  9040. {
  9041. $this->l = $language;
  9042. if (isset($this->l['a_meta_dir']))
  9043. {
  9044. $this->rtl = $this->l['a_meta_dir'] == 'rtl' ? true : false;
  9045. }
  9046. else
  9047. {
  9048. $this->rtl = false;
  9049. }
  9050. }
  9051. /**
  9052. * Returns the PDF data.
  9053. * @access public
  9054. */
  9055. public function getPDFData()
  9056. {
  9057. if ($this->state < 3)
  9058. {
  9059. $this->Close();
  9060. }
  9061. return $this->buffer;
  9062. }
  9063. /**
  9064. * Output anchor link.
  9065. * @param string $url link URL or internal link (i.e.: &lt;a href="#23"&gt;link to page 23&lt;/a&gt;)
  9066. * @param string $name link name
  9067. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  9068. * @param boolean $firstline if true prints only the first line and return the remaining string.
  9069. * @param array $color array of RGB text color
  9070. * @param string $style font style (U, D, B, I)
  9071. * @param boolean $firstblock if true the string is the starting of a line.
  9072. * @return the number of cells used or the remaining text if $firstline = true;
  9073. * @access public
  9074. */
  9075. public function addHtmlLink($url, $name, $fill = 0, $firstline = false, $color = '', $style = -1, $firstblock = false)
  9076. {
  9077. if (! $this->empty_string($url) and ($url{0} == '#'))
  9078. {
  9079. // convert url to internal link
  9080. $page = intval(substr($url, 1));
  9081. $url = $this->AddLink();
  9082. $this->SetLink($url, 0, $page);
  9083. }
  9084. // store current settings
  9085. $prevcolor = $this->fgcolor;
  9086. $prevstyle = $this->FontStyle;
  9087. if (empty($color))
  9088. {
  9089. $this->SetTextColorArray($this->htmlLinkColorArray);
  9090. }
  9091. else
  9092. {
  9093. $this->SetTextColorArray($color);
  9094. }
  9095. if ($style == - 1)
  9096. {
  9097. $this->SetFont('', $this->FontStyle . $this->htmlLinkFontStyle);
  9098. }
  9099. else
  9100. {
  9101. $this->SetFont('', $this->FontStyle . $style);
  9102. }
  9103. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  9104. // restore settings
  9105. $this->SetFont('', $prevstyle);
  9106. $this->SetTextColorArray($prevcolor);
  9107. return $ret;
  9108. }
  9109. /**
  9110. * 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).
  9111. * @param string $color html color
  9112. * @return array RGB color or false in case of error.
  9113. * @access public
  9114. */
  9115. public function convertHTMLColorToDec($color = '#FFFFFF')
  9116. {
  9117. global $webcolor;
  9118. $returncolor = false;
  9119. $color = preg_replace('/[\s]*/', '', $color); // remove extra spaces
  9120. $color = strtolower($color);
  9121. if (($dotpos = strpos($color, '.')) !== false)
  9122. {
  9123. // remove class parent (i.e.: color.red)
  9124. $color = substr($color, ($dotpos + 1));
  9125. }
  9126. if (strlen($color) == 0)
  9127. {
  9128. return false;
  9129. }
  9130. if (substr($color, 0, 3) == 'rgb')
  9131. {
  9132. $codes = substr($color, 4);
  9133. $codes = str_replace(')', '', $codes);
  9134. $returncolor = explode(',', $codes, 3);
  9135. return $returncolor;
  9136. }
  9137. if (substr($color, 0, 1) != '#')
  9138. {
  9139. // decode color name
  9140. if (isset($webcolor[$color]))
  9141. {
  9142. $color_code = $webcolor[$color];
  9143. }
  9144. else
  9145. {
  9146. return false;
  9147. }
  9148. }
  9149. else
  9150. {
  9151. $color_code = substr($color, 1);
  9152. }
  9153. switch (strlen($color_code))
  9154. {
  9155. case 3 :
  9156. {
  9157. // three-digit hexadecimal representation
  9158. $r = substr($color_code, 0, 1);
  9159. $g = substr($color_code, 1, 1);
  9160. $b = substr($color_code, 2, 1);
  9161. $returncolor['R'] = hexdec($r . $r);
  9162. $returncolor['G'] = hexdec($g . $g);
  9163. $returncolor['B'] = hexdec($b . $b);
  9164. break;
  9165. }
  9166. case 6 :
  9167. {
  9168. // six-digit hexadecimal representation
  9169. $returncolor['R'] = hexdec(substr($color_code, 0, 2));
  9170. $returncolor['G'] = hexdec(substr($color_code, 2, 2));
  9171. $returncolor['B'] = hexdec(substr($color_code, 4, 2));
  9172. break;
  9173. }
  9174. }
  9175. return $returncolor;
  9176. }
  9177. /**
  9178. * Converts pixels to User's Units.
  9179. * @param int $px pixels
  9180. * @return float value in user's unit
  9181. * @access public
  9182. * @see setImageScale(), getImageScale()
  9183. */
  9184. public function pixelsToUnits($px)
  9185. {
  9186. return ($px / ($this->imgscale * $this->k));
  9187. }
  9188. /**
  9189. * Reverse function for htmlentities.
  9190. * Convert entities in UTF-8.
  9191. * @param $text_to_convert Text to convert.
  9192. * @return string converted
  9193. * @access public
  9194. */
  9195. public function unhtmlentities($text_to_convert)
  9196. {
  9197. return html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  9198. }
  9199. // ENCRYPTION METHODS ----------------------------------
  9200. // SINCE 2.0.000 (2008-01-02)
  9201. /**
  9202. * Compute encryption key depending on object number where the encrypted data is stored
  9203. * @param int $n object number
  9204. * @access protected
  9205. * @since 2.0.000 (2008-01-02)
  9206. */
  9207. protected function _objectkey($n)
  9208. {
  9209. return substr($this->_md5_16($this->encryption_key . pack('VXxx', $n)), 0, 10);
  9210. }
  9211. /**
  9212. * Put encryption on PDF document.
  9213. * @access protected
  9214. * @since 2.0.000 (2008-01-02)
  9215. */
  9216. protected function _putencryption()
  9217. {
  9218. $this->_out('/Filter /Standard');
  9219. $this->_out('/V 1');
  9220. $this->_out('/R 2');
  9221. $this->_out('/O (' . $this->_escape($this->Ovalue) . ')');
  9222. $this->_out('/U (' . $this->_escape($this->Uvalue) . ')');
  9223. $this->_out('/P ' . $this->Pvalue);
  9224. }
  9225. /**
  9226. * Returns the input text exrypted using RC4 algorithm and the specified key.
  9227. * RC4 is the standard encryption algorithm used in PDF format
  9228. * @param string $key encryption key
  9229. * @param String $text input text to be encrypted
  9230. * @return String encrypted text
  9231. * @access protected
  9232. * @since 2.0.000 (2008-01-02)
  9233. * @author Klemen Vodopivec
  9234. */
  9235. protected function _RC4($key, $text)
  9236. {
  9237. if ($this->last_rc4_key != $key)
  9238. {
  9239. $k = str_repeat($key, ((256 / strlen($key)) + 1));
  9240. $rc4 = range(0, 255);
  9241. $j = 0;
  9242. for($i = 0; $i < 256; ++ $i)
  9243. {
  9244. $t = $rc4[$i];
  9245. $j = ($j + $t + ord($k{$i})) % 256;
  9246. $rc4[$i] = $rc4[$j];
  9247. $rc4[$j] = $t;
  9248. }
  9249. $this->last_rc4_key = $key;
  9250. $this->last_rc4_key_c = $rc4;
  9251. }
  9252. else
  9253. {
  9254. $rc4 = $this->last_rc4_key_c;
  9255. }
  9256. $len = strlen($text);
  9257. $a = 0;
  9258. $b = 0;
  9259. $out = '';
  9260. for($i = 0; $i < $len; ++ $i)
  9261. {
  9262. $a = ($a + 1) % 256;
  9263. $t = $rc4[$a];
  9264. $b = ($b + $t) % 256;
  9265. $rc4[$a] = $rc4[$b];
  9266. $rc4[$b] = $t;
  9267. $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
  9268. $out .= chr(ord($text{$i}) ^ $k);
  9269. }
  9270. return $out;
  9271. }
  9272. /**
  9273. * Encrypts a string using MD5 and returns it's value as a binary string.
  9274. * @param string $str input string
  9275. * @return String MD5 encrypted binary string
  9276. * @access protected
  9277. * @since 2.0.000 (2008-01-02)
  9278. * @author Klemen Vodopivec
  9279. */
  9280. protected function _md5_16($str)
  9281. {
  9282. return pack('H*', md5($str));
  9283. }
  9284. /**
  9285. * Compute O value (used for RC4 encryption)
  9286. * @param String $user_pass user password
  9287. * @param String $owner_pass user password
  9288. * @return String O value
  9289. * @access protected
  9290. * @since 2.0.000 (2008-01-02)
  9291. * @author Klemen Vodopivec
  9292. */
  9293. protected function _Ovalue($user_pass, $owner_pass)
  9294. {
  9295. $tmp = $this->_md5_16($owner_pass);
  9296. $owner_RC4_key = substr($tmp, 0, 5);
  9297. return $this->_RC4($owner_RC4_key, $user_pass);
  9298. }
  9299. /**
  9300. * Compute U value (used for RC4 encryption)
  9301. * @return String U value
  9302. * @access protected
  9303. * @since 2.0.000 (2008-01-02)
  9304. * @author Klemen Vodopivec
  9305. */
  9306. protected function _Uvalue()
  9307. {
  9308. return $this->_RC4($this->encryption_key, $this->padding);
  9309. }
  9310. /**
  9311. * Compute encryption key
  9312. * @param String $user_pass user password
  9313. * @param String $owner_pass user password
  9314. * @param String $protection protection type
  9315. * @access protected
  9316. * @since 2.0.000 (2008-01-02)
  9317. * @author Klemen Vodopivec
  9318. */
  9319. protected function _generateencryptionkey($user_pass, $owner_pass, $protection)
  9320. {
  9321. // Pad passwords
  9322. $user_pass = substr($user_pass . $this->padding, 0, 32);
  9323. $owner_pass = substr($owner_pass . $this->padding, 0, 32);
  9324. // Compute O value
  9325. $this->Ovalue = $this->_Ovalue($user_pass, $owner_pass);
  9326. // Compute encyption key
  9327. $tmp = $this->_md5_16($user_pass . $this->Ovalue . chr($protection) . "\xFF\xFF\xFF");
  9328. $this->encryption_key = substr($tmp, 0, 5);
  9329. // Compute U value
  9330. $this->Uvalue = $this->_Uvalue();
  9331. // Compute P value
  9332. $this->Pvalue = - (($protection ^ 255) + 1);
  9333. }
  9334. /**
  9335. * Set document protection
  9336. * The permission array is composed of values taken from the following ones:
  9337. * - copy: copy text and images to the clipboard
  9338. * - print: print the document
  9339. * - modify: modify it (except for annotations and forms)
  9340. * - annot-forms: add annotations and forms
  9341. * Remark: the protection against modification is for people who have the full Acrobat product.
  9342. * 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.
  9343. * 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.
  9344. * @param Array $permissions the set of permissions. Empty by default (only viewing is allowed). (print, modify, copy, annot-forms)
  9345. * @param String $user_pass user password. Empty by default.
  9346. * @param String $owner_pass owner password. If not specified, a random value is used.
  9347. * @access public
  9348. * @since 2.0.000 (2008-01-02)
  9349. * @author Klemen Vodopivec
  9350. */
  9351. public function SetProtection($permissions = array(), $user_pass = '', $owner_pass = null)
  9352. {
  9353. $options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32);
  9354. $protection = 192;
  9355. foreach ($permissions as $permission)
  9356. {
  9357. if (! isset($options[$permission]))
  9358. {
  9359. $this->Error('Incorrect permission: ' . $permission);
  9360. }
  9361. $protection += $options[$permission];
  9362. }
  9363. if ($owner_pass === null)
  9364. {
  9365. $owner_pass = uniqid(rand());
  9366. }
  9367. $this->encrypted = true;
  9368. $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
  9369. }
  9370. // END OF ENCRYPTION FUNCTIONS -------------------------
  9371. // START TRANSFORMATIONS SECTION -----------------------
  9372. /**
  9373. * Starts a 2D tranformation saving current graphic state.
  9374. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  9375. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  9376. * @access public
  9377. * @since 2.1.000 (2008-01-07)
  9378. * @see StartTransform(), StopTransform()
  9379. */
  9380. public function StartTransform()
  9381. {
  9382. $this->_out('q');
  9383. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  9384. ++ $this->transfmatrix_key;
  9385. $this->transfmatrix[$this->transfmatrix_key] = array();
  9386. }
  9387. /**
  9388. * Stops a 2D tranformation restoring previous graphic state.
  9389. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  9390. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  9391. * @access public
  9392. * @since 2.1.000 (2008-01-07)
  9393. * @see StartTransform(), StopTransform()
  9394. */
  9395. public function StopTransform()
  9396. {
  9397. $this->_out('Q');
  9398. if (isset($this->transfmatrix[$this->transfmatrix_key]))
  9399. {
  9400. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  9401. -- $this->transfmatrix_key;
  9402. }
  9403. array_pop($this->transfmrk[$this->page]);
  9404. }
  9405. /**
  9406. * Horizontal Scaling.
  9407. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  9408. * @param int $x abscissa of the scaling center. Default is current x position
  9409. * @param int $y ordinate of the scaling center. Default is current y position
  9410. * @access public
  9411. * @since 2.1.000 (2008-01-07)
  9412. * @see StartTransform(), StopTransform()
  9413. */
  9414. public function ScaleX($s_x, $x = '', $y = '')
  9415. {
  9416. $this->Scale($s_x, 100, $x, $y);
  9417. }
  9418. /**
  9419. * Vertical Scaling.
  9420. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  9421. * @param int $x abscissa of the scaling center. Default is current x position
  9422. * @param int $y ordinate of the scaling center. Default is current y position
  9423. * @access public
  9424. * @since 2.1.000 (2008-01-07)
  9425. * @see StartTransform(), StopTransform()
  9426. */
  9427. public function ScaleY($s_y, $x = '', $y = '')
  9428. {
  9429. $this->Scale(100, $s_y, $x, $y);
  9430. }
  9431. /**
  9432. * Vertical and horizontal proportional Scaling.
  9433. * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  9434. * @param int $x abscissa of the scaling center. Default is current x position
  9435. * @param int $y ordinate of the scaling center. Default is current y position
  9436. * @access public
  9437. * @since 2.1.000 (2008-01-07)
  9438. * @see StartTransform(), StopTransform()
  9439. */
  9440. public function ScaleXY($s, $x = '', $y = '')
  9441. {
  9442. $this->Scale($s, $s, $x, $y);
  9443. }
  9444. /**
  9445. * Vertical and horizontal non-proportional Scaling.
  9446. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  9447. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  9448. * @param int $x abscissa of the scaling center. Default is current x position
  9449. * @param int $y ordinate of the scaling center. Default is current y position
  9450. * @access public
  9451. * @since 2.1.000 (2008-01-07)
  9452. * @see StartTransform(), StopTransform()
  9453. */
  9454. public function Scale($s_x, $s_y, $x = '', $y = '')
  9455. {
  9456. if ($x === '')
  9457. {
  9458. $x = $this->x;
  9459. }
  9460. if ($y === '')
  9461. {
  9462. $y = $this->y;
  9463. }
  9464. if ($this->rtl)
  9465. {
  9466. $x = $this->w - $x;
  9467. }
  9468. if (($s_x == 0) or ($s_y == 0))
  9469. {
  9470. $this->Error('Please do not use values equal to zero for scaling');
  9471. }
  9472. $y = ($this->h - $y) * $this->k;
  9473. $x *= $this->k;
  9474. //calculate elements of transformation matrix
  9475. $s_x /= 100;
  9476. $s_y /= 100;
  9477. $tm[0] = $s_x;
  9478. $tm[1] = 0;
  9479. $tm[2] = 0;
  9480. $tm[3] = $s_y;
  9481. $tm[4] = $x * (1 - $s_x);
  9482. $tm[5] = $y * (1 - $s_y);
  9483. //scale the coordinate system
  9484. $this->Transform($tm);
  9485. }
  9486. /**
  9487. * Horizontal Mirroring.
  9488. * @param int $x abscissa of the point. Default is current x position
  9489. * @access public
  9490. * @since 2.1.000 (2008-01-07)
  9491. * @see StartTransform(), StopTransform()
  9492. */
  9493. public function MirrorH($x = '')
  9494. {
  9495. $this->Scale(- 100, 100, $x);
  9496. }
  9497. /**
  9498. * Verical Mirroring.
  9499. * @param int $y ordinate of the point. Default is current y position
  9500. * @access public
  9501. * @since 2.1.000 (2008-01-07)
  9502. * @see StartTransform(), StopTransform()
  9503. */
  9504. public function MirrorV($y = '')
  9505. {
  9506. $this->Scale(100, - 100, '', $y);
  9507. }
  9508. /**
  9509. * Point reflection mirroring.
  9510. * @param int $x abscissa of the point. Default is current x position
  9511. * @param int $y ordinate of the point. Default is current y position
  9512. * @access public
  9513. * @since 2.1.000 (2008-01-07)
  9514. * @see StartTransform(), StopTransform()
  9515. */
  9516. public function MirrorP($x = '', $y = '')
  9517. {
  9518. $this->Scale(- 100, - 100, $x, $y);
  9519. }
  9520. /**
  9521. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  9522. * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  9523. * @param int $x abscissa of the point. Default is current x position
  9524. * @param int $y ordinate of the point. Default is current y position
  9525. * @access public
  9526. * @since 2.1.000 (2008-01-07)
  9527. * @see StartTransform(), StopTransform()
  9528. */
  9529. public function MirrorL($angle = 0, $x = '', $y = '')
  9530. {
  9531. $this->Scale(- 100, 100, $x, $y);
  9532. $this->Rotate(- 2 * ($angle - 90), $x, $y);
  9533. }
  9534. /**
  9535. * Translate graphic object horizontally.
  9536. * @param int $t_x movement to the right (or left for RTL)
  9537. * @access public
  9538. * @since 2.1.000 (2008-01-07)
  9539. * @see StartTransform(), StopTransform()
  9540. */
  9541. public function TranslateX($t_x)
  9542. {
  9543. $this->Translate($t_x, 0);
  9544. }
  9545. /**
  9546. * Translate graphic object vertically.
  9547. * @param int $t_y movement to the bottom
  9548. * @access public
  9549. * @since 2.1.000 (2008-01-07)
  9550. * @see StartTransform(), StopTransform()
  9551. */
  9552. public function TranslateY($t_y)
  9553. {
  9554. $this->Translate(0, $t_y);
  9555. }
  9556. /**
  9557. * Translate graphic object horizontally and vertically.
  9558. * @param int $t_x movement to the right
  9559. * @param int $t_y movement to the bottom
  9560. * @access public
  9561. * @since 2.1.000 (2008-01-07)
  9562. * @see StartTransform(), StopTransform()
  9563. */
  9564. public function Translate($t_x, $t_y)
  9565. {
  9566. if ($this->rtl)
  9567. {
  9568. $t_x = - $t_x;
  9569. }
  9570. //calculate elements of transformation matrix
  9571. $tm[0] = 1;
  9572. $tm[1] = 0;
  9573. $tm[2] = 0;
  9574. $tm[3] = 1;
  9575. $tm[4] = $t_x * $this->k;
  9576. $tm[5] = - $t_y * $this->k;
  9577. //translate the coordinate system
  9578. $this->Transform($tm);
  9579. }
  9580. /**
  9581. * Rotate object.
  9582. * @param float $angle angle in degrees for counter-clockwise rotation
  9583. * @param int $x abscissa of the rotation center. Default is current x position
  9584. * @param int $y ordinate of the rotation center. Default is current y position
  9585. * @access public
  9586. * @since 2.1.000 (2008-01-07)
  9587. * @see StartTransform(), StopTransform()
  9588. */
  9589. public function Rotate($angle, $x = '', $y = '')
  9590. {
  9591. if ($x === '')
  9592. {
  9593. $x = $this->x;
  9594. }
  9595. if ($y === '')
  9596. {
  9597. $y = $this->y;
  9598. }
  9599. if ($this->rtl)
  9600. {
  9601. $x = $this->w - $x;
  9602. $angle = - $angle;
  9603. }
  9604. $y = ($this->h - $y) * $this->k;
  9605. $x *= $this->k;
  9606. //calculate elements of transformation matrix
  9607. $tm[0] = cos(deg2rad($angle));
  9608. $tm[1] = sin(deg2rad($angle));
  9609. $tm[2] = - $tm[1];
  9610. $tm[3] = $tm[0];
  9611. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  9612. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  9613. //rotate the coordinate system around ($x,$y)
  9614. $this->Transform($tm);
  9615. }
  9616. /**
  9617. * Skew horizontally.
  9618. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  9619. * @param int $x abscissa of the skewing center. default is current x position
  9620. * @param int $y ordinate of the skewing center. default is current y position
  9621. * @access public
  9622. * @since 2.1.000 (2008-01-07)
  9623. * @see StartTransform(), StopTransform()
  9624. */
  9625. public function SkewX($angle_x, $x = '', $y = '')
  9626. {
  9627. $this->Skew($angle_x, 0, $x, $y);
  9628. }
  9629. /**
  9630. * Skew vertically.
  9631. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  9632. * @param int $x abscissa of the skewing center. default is current x position
  9633. * @param int $y ordinate of the skewing center. default is current y position
  9634. * @access public
  9635. * @since 2.1.000 (2008-01-07)
  9636. * @see StartTransform(), StopTransform()
  9637. */
  9638. public function SkewY($angle_y, $x = '', $y = '')
  9639. {
  9640. $this->Skew(0, $angle_y, $x, $y);
  9641. }
  9642. /**
  9643. * Skew.
  9644. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  9645. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  9646. * @param int $x abscissa of the skewing center. default is current x position
  9647. * @param int $y ordinate of the skewing center. default is current y position
  9648. * @access public
  9649. * @since 2.1.000 (2008-01-07)
  9650. * @see StartTransform(), StopTransform()
  9651. */
  9652. public function Skew($angle_x, $angle_y, $x = '', $y = '')
  9653. {
  9654. if ($x === '')
  9655. {
  9656. $x = $this->x;
  9657. }
  9658. if ($y === '')
  9659. {
  9660. $y = $this->y;
  9661. }
  9662. if ($this->rtl)
  9663. {
  9664. $x = $this->w - $x;
  9665. $angle_x = - $angle_x;
  9666. }
  9667. if (($angle_x <= - 90) or ($angle_x >= 90) or ($angle_y <= - 90) or ($angle_y >= 90))
  9668. {
  9669. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  9670. }
  9671. $x *= $this->k;
  9672. $y = ($this->h - $y) * $this->k;
  9673. //calculate elements of transformation matrix
  9674. $tm[0] = 1;
  9675. $tm[1] = tan(deg2rad($angle_y));
  9676. $tm[2] = tan(deg2rad($angle_x));
  9677. $tm[3] = 1;
  9678. $tm[4] = - $tm[2] * $y;
  9679. $tm[5] = - $tm[1] * $x;
  9680. //skew the coordinate system
  9681. $this->Transform($tm);
  9682. }
  9683. /**
  9684. * Apply graphic transformations.
  9685. * @access protected
  9686. * @since 2.1.000 (2008-01-07)
  9687. * @see StartTransform(), StopTransform()
  9688. */
  9689. protected function Transform($tm)
  9690. {
  9691. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  9692. // add tranformation matrix
  9693. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1],
  9694. 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  9695. // update tranformation mark
  9696. if (end($this->transfmrk[$this->page]) !== false)
  9697. {
  9698. $key = key($this->transfmrk[$this->page]);
  9699. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  9700. }
  9701. }
  9702. // END TRANSFORMATIONS SECTION -------------------------
  9703. // START GRAPHIC FUNCTIONS SECTION ---------------------
  9704. // The following section is based on the code provided by David Hernandez Sanz
  9705. /**
  9706. * 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.
  9707. * @param float $width The width.
  9708. * @access public
  9709. * @since 1.0
  9710. * @see Line(), Rect(), Cell(), MultiCell()
  9711. */
  9712. public function SetLineWidth($width)
  9713. {
  9714. //Set line width
  9715. $this->LineWidth = $width;
  9716. $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k));
  9717. if ($this->page > 0)
  9718. {
  9719. $this->_out($this->linestyleWidth);
  9720. }
  9721. }
  9722. /**
  9723. * Returns the current the line width.
  9724. * @return int Line width
  9725. * @access public
  9726. * @since 2.1.000 (2008-01-07)
  9727. * @see Line(), SetLineWidth()
  9728. */
  9729. public function GetLineWidth()
  9730. {
  9731. return $this->LineWidth;
  9732. }
  9733. /**
  9734. * Set line style.
  9735. * @param array $style Line style. Array with keys among the following:
  9736. * <ul>
  9737. * <li>width (float): Width of the line in user units.</li>
  9738. * <li>cap (string): Type of cap to put on the line. Possible values are:
  9739. * butt, round, square. The difference between "square" and "butt" is that
  9740. * "square" projects a flat end past the end of the line.</li>
  9741. * <li>join (string): Type of join. Possible values are: miter, round,
  9742. * bevel.</li>
  9743. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  9744. * series of length values, which are the lengths of the on and off dashes.
  9745. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  9746. * 1 off, 2 on, 1 off, ...</li>
  9747. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  9748. * the point at which the pattern starts.</li>
  9749. * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
  9750. * </ul>
  9751. * @access public
  9752. * @since 2.1.000 (2008-01-08)
  9753. */
  9754. public function SetLineStyle($style)
  9755. {
  9756. if (! is_array($style))
  9757. {
  9758. return;
  9759. }
  9760. extract($style);
  9761. if (isset($width))
  9762. {
  9763. $width_prev = $this->LineWidth;
  9764. $this->SetLineWidth($width);
  9765. $this->LineWidth = $width_prev;
  9766. }
  9767. if (isset($cap))
  9768. {
  9769. $ca = array('butt' => 0, 'round' => 1, 'square' => 2);
  9770. if (isset($ca[$cap]))
  9771. {
  9772. $this->linestyleCap = $ca[$cap] . ' J';
  9773. $this->_out($this->linestyleCap);
  9774. }
  9775. }
  9776. if (isset($join))
  9777. {
  9778. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  9779. if (isset($ja[$join]))
  9780. {
  9781. $this->linestyleJoin = $ja[$join] . ' j';
  9782. $this->_out($this->linestyleJoin);
  9783. }
  9784. }
  9785. if (isset($dash))
  9786. {
  9787. $dash_string = '';
  9788. if ($dash)
  9789. {
  9790. if (preg_match('/^.+,/', $dash) > 0)
  9791. {
  9792. $tab = explode(',', $dash);
  9793. }
  9794. else
  9795. {
  9796. $tab = array($dash);
  9797. }
  9798. $dash_string = '';
  9799. foreach ($tab as $i => $v)
  9800. {
  9801. if ($i)
  9802. {
  9803. $dash_string .= ' ';
  9804. }
  9805. $dash_string .= sprintf('%.2F', $v);
  9806. }
  9807. }
  9808. if (! isset($phase) or ! $dash)
  9809. {
  9810. $phase = 0;
  9811. }
  9812. $this->linestyleDash = sprintf('[%s] %.2F d', $dash_string, $phase);
  9813. $this->_out($this->linestyleDash);
  9814. }
  9815. if (isset($color))
  9816. {
  9817. $this->SetDrawColorArray($color);
  9818. }
  9819. }
  9820. /**
  9821. * Set a draw point.
  9822. * @param float $x Abscissa of point.
  9823. * @param float $y Ordinate of point.
  9824. * @access protected
  9825. * @since 2.1.000 (2008-01-08)
  9826. */
  9827. protected function _outPoint($x, $y)
  9828. {
  9829. if ($this->rtl)
  9830. {
  9831. $x = $this->w - $x;
  9832. }
  9833. $this->_out(sprintf('%.2F %.2F m', $x * $this->k, ($this->h - $y) * $this->k));
  9834. }
  9835. /**
  9836. * Draws a line from last draw point.
  9837. * @param float $x Abscissa of end point.
  9838. * @param float $y Ordinate of end point.
  9839. * @access protected
  9840. * @since 2.1.000 (2008-01-08)
  9841. */
  9842. protected function _outLine($x, $y)
  9843. {
  9844. if ($this->rtl)
  9845. {
  9846. $x = $this->w - $x;
  9847. }
  9848. $this->_out(sprintf('%.2F %.2F l', $x * $this->k, ($this->h - $y) * $this->k));
  9849. }
  9850. /**
  9851. * Draws a rectangle.
  9852. * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  9853. * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  9854. * @param float $w Width.
  9855. * @param float $h Height.
  9856. * @param string $op options
  9857. * @access protected
  9858. * @since 2.1.000 (2008-01-08)
  9859. */
  9860. protected function _outRect($x, $y, $w, $h, $op)
  9861. {
  9862. if ($this->rtl)
  9863. {
  9864. $x = $this->w - $x - $w;
  9865. }
  9866. $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, - $h * $this->k, $op));
  9867. }
  9868. /**
  9869. * Draws a Bezier curve from last draw point.
  9870. * The Bezier curve is a tangent to the line between the control points at either end of the curve.
  9871. * @param float $x1 Abscissa of control point 1.
  9872. * @param float $y1 Ordinate of control point 1.
  9873. * @param float $x2 Abscissa of control point 2.
  9874. * @param float $y2 Ordinate of control point 2.
  9875. * @param float $x3 Abscissa of end point.
  9876. * @param float $y3 Ordinate of end point.
  9877. * @access protected
  9878. * @since 2.1.000 (2008-01-08)
  9879. */
  9880. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3)
  9881. {
  9882. if ($this->rtl)
  9883. {
  9884. $x1 = $this->w - $x1;
  9885. $x2 = $this->w - $x2;
  9886. $x3 = $this->w - $x3;
  9887. }
  9888. $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));
  9889. }
  9890. /**
  9891. * Draws a line between two points.
  9892. * @param float $x1 Abscissa of first point.
  9893. * @param float $y1 Ordinate of first point.
  9894. * @param float $x2 Abscissa of second point.
  9895. * @param float $y2 Ordinate of second point.
  9896. * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  9897. * @access public
  9898. * @since 1.0
  9899. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  9900. */
  9901. public function Line($x1, $y1, $x2, $y2, $style = array())
  9902. {
  9903. if (is_array($style))
  9904. {
  9905. $this->SetLineStyle($style);
  9906. }
  9907. $this->_outPoint($x1, $y1);
  9908. $this->_outLine($x2, $y2);
  9909. $this->_out(' S');
  9910. }
  9911. /**
  9912. * Draws a rectangle.
  9913. * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  9914. * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  9915. * @param float $w Width.
  9916. * @param float $h Height.
  9917. * @param string $style Style of rendering. Possible values are:
  9918. * <ul>
  9919. * <li>D or empty string: Draw (default).</li>
  9920. * <li>F: Fill.</li>
  9921. * <li>DF or FD: Draw and fill.</li>
  9922. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9923. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9924. * </ul>
  9925. * @param array $border_style Border style of rectangle. Array with keys among the following:
  9926. * <ul>
  9927. * <li>all: Line style of all borders. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9928. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9929. * </ul>
  9930. * If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  9931. * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  9932. * @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).
  9933. * @access public
  9934. * @since 1.0
  9935. * @see SetLineStyle()
  9936. */
  9937. public function Rect($x, $y, $w, $h, $style = '', $border_style = array(), $fill_color = array())
  9938. {
  9939. if (! (false === strpos($style, 'F')) and isset($fill_color))
  9940. {
  9941. $this->SetFillColorArray($fill_color);
  9942. }
  9943. switch ($style)
  9944. {
  9945. case 'F' :
  9946. {
  9947. $op = 'f';
  9948. $border_style = array();
  9949. $this->_outRect($x, $y, $w, $h, $op);
  9950. break;
  9951. }
  9952. case 'DF' :
  9953. case 'FD' :
  9954. {
  9955. if ((! $border_style) or (isset($border_style['all'])))
  9956. {
  9957. $op = 'B';
  9958. if (isset($border_style['all']))
  9959. {
  9960. $this->SetLineStyle($border_style['all']);
  9961. $border_style = array();
  9962. }
  9963. }
  9964. else
  9965. {
  9966. $op = 'f';
  9967. }
  9968. $this->_outRect($x, $y, $w, $h, $op);
  9969. break;
  9970. }
  9971. case 'CNZ' :
  9972. {
  9973. $op = 'W n';
  9974. $this->_outRect($x, $y, $w, $h, $op);
  9975. break;
  9976. }
  9977. case 'CEO' :
  9978. {
  9979. $op = 'W* n';
  9980. $this->_outRect($x, $y, $w, $h, $op);
  9981. break;
  9982. }
  9983. default :
  9984. {
  9985. $op = 'S';
  9986. if ((! $border_style) or (isset($border_style['all'])))
  9987. {
  9988. if (isset($border_style['all']) and $border_style['all'])
  9989. {
  9990. $this->SetLineStyle($border_style['all']);
  9991. $border_style = array();
  9992. }
  9993. $this->_outRect($x, $y, $w, $h, $op);
  9994. }
  9995. break;
  9996. }
  9997. }
  9998. if ($border_style)
  9999. {
  10000. $border_style2 = array();
  10001. foreach ($border_style as $line => $value)
  10002. {
  10003. $length = strlen($line);
  10004. for($i = 0; $i < $length; ++ $i)
  10005. {
  10006. $border_style2[$line[$i]] = $value;
  10007. }
  10008. }
  10009. $border_style = $border_style2;
  10010. if (isset($border_style['L']) and $border_style['L'])
  10011. {
  10012. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  10013. }
  10014. if (isset($border_style['T']) and $border_style['T'])
  10015. {
  10016. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  10017. }
  10018. if (isset($border_style['R']) and $border_style['R'])
  10019. {
  10020. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  10021. }
  10022. if (isset($border_style['B']) and $border_style['B'])
  10023. {
  10024. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  10025. }
  10026. }
  10027. }
  10028. /**
  10029. * Draws a Bezier curve.
  10030. * The Bezier curve is a tangent to the line between the control points at
  10031. * either end of the curve.
  10032. * @param float $x0 Abscissa of start point.
  10033. * @param float $y0 Ordinate of start point.
  10034. * @param float $x1 Abscissa of control point 1.
  10035. * @param float $y1 Ordinate of control point 1.
  10036. * @param float $x2 Abscissa of control point 2.
  10037. * @param float $y2 Ordinate of control point 2.
  10038. * @param float $x3 Abscissa of end point.
  10039. * @param float $y3 Ordinate of end point.
  10040. * @param string $style Style of rendering. Possible values are:
  10041. * <ul>
  10042. * <li>D or empty string: Draw (default).</li>
  10043. * <li>F: Fill.</li>
  10044. * <li>DF or FD: Draw and fill.</li>
  10045. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10046. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10047. * </ul>
  10048. * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  10049. * @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).
  10050. * @access public
  10051. * @see SetLineStyle()
  10052. * @since 2.1.000 (2008-01-08)
  10053. */
  10054. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style = '', $line_style = array(), $fill_color = array())
  10055. {
  10056. if (! (false === strpos($style, 'F')) and isset($fill_color))
  10057. {
  10058. $this->SetFillColorArray($fill_color);
  10059. }
  10060. switch ($style)
  10061. {
  10062. case 'F' :
  10063. {
  10064. $op = 'f';
  10065. $line_style = array();
  10066. break;
  10067. }
  10068. case 'FD' :
  10069. case 'DF' :
  10070. {
  10071. $op = 'B';
  10072. break;
  10073. }
  10074. case 'CNZ' :
  10075. {
  10076. $op = 'W n';
  10077. break;
  10078. }
  10079. case 'CEO' :
  10080. {
  10081. $op = 'W* n';
  10082. break;
  10083. }
  10084. default :
  10085. {
  10086. $op = 'S';
  10087. break;
  10088. }
  10089. }
  10090. if ($line_style)
  10091. {
  10092. $this->SetLineStyle($line_style);
  10093. }
  10094. $this->_outPoint($x0, $y0);
  10095. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  10096. $this->_out($op);
  10097. }
  10098. /**
  10099. * Draws a poly-Bezier curve.
  10100. * Each Bezier curve segment is a tangent to the line between the control points at
  10101. * either end of the curve.
  10102. * @param float $x0 Abscissa of start point.
  10103. * @param float $y0 Ordinate of start point.
  10104. * @param float $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  10105. * @param string $style Style of rendering. Possible values are:
  10106. * <ul>
  10107. * <li>D or empty string: Draw (default).</li>
  10108. * <li>F: Fill.</li>
  10109. * <li>DF or FD: Draw and fill.</li>
  10110. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10111. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10112. * </ul>
  10113. * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  10114. * @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).
  10115. * @access public
  10116. * @see SetLineStyle()
  10117. * @since 3.0008 (2008-05-12)
  10118. */
  10119. public function Polycurve($x0, $y0, $segments, $style = '', $line_style = array(), $fill_color = array())
  10120. {
  10121. if (! (false === strpos($style, 'F')) and isset($fill_color))
  10122. {
  10123. $this->SetFillColorArray($fill_color);
  10124. }
  10125. switch ($style)
  10126. {
  10127. case 'F' :
  10128. {
  10129. $op = 'f';
  10130. $line_style = array();
  10131. break;
  10132. }
  10133. case 'FD' :
  10134. case 'DF' :
  10135. {
  10136. $op = 'B';
  10137. break;
  10138. }
  10139. case 'CNZ' :
  10140. {
  10141. $op = 'W n';
  10142. break;
  10143. }
  10144. case 'CEO' :
  10145. {
  10146. $op = 'W* n';
  10147. break;
  10148. }
  10149. default :
  10150. {
  10151. $op = 'S';
  10152. break;
  10153. }
  10154. }
  10155. if ($line_style)
  10156. {
  10157. $this->SetLineStyle($line_style);
  10158. }
  10159. $this->_outPoint($x0, $y0);
  10160. foreach ($segments as $segment)
  10161. {
  10162. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  10163. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  10164. }
  10165. $this->_out($op);
  10166. }
  10167. /**
  10168. * Draws an ellipse.
  10169. * An ellipse is formed from n Bezier curves.
  10170. * @param float $x0 Abscissa of center point.
  10171. * @param float $y0 Ordinate of center point.
  10172. * @param float $rx Horizontal radius.
  10173. * @param float $ry Vertical radius (if ry = 0 then is a circle, see {@link Circle Circle}). Default value: 0.
  10174. * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  10175. * @param float $astart: Angle start of draw line. Default value: 0.
  10176. * @param float $afinish: Angle finish of draw line. Default value: 360.
  10177. * @param string $style Style of rendering. Possible values are:
  10178. * <ul>
  10179. * <li>D or empty string: Draw (default).</li>
  10180. * <li>F: Fill.</li>
  10181. * <li>DF or FD: Draw and fill.</li>
  10182. * <li>C: Draw close.</li>
  10183. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10184. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10185. * </ul>
  10186. * @param array $line_style Line style of ellipse. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  10187. * @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).
  10188. * @param integer $nc Number of curves used in ellipse. Default value: 8.
  10189. * @access public
  10190. * @since 2.1.000 (2008-01-08)
  10191. */
  10192. public function Ellipse($x0, $y0, $rx, $ry = 0, $angle = 0, $astart = 0, $afinish = 360, $style = '', $line_style = array(), $fill_color = array(), $nc = 8)
  10193. {
  10194. if ($angle)
  10195. {
  10196. $this->StartTransform();
  10197. $this->Rotate($angle, $x0, $y0);
  10198. $this->Ellipse($x0, $y0, $rx, $ry, 0, $astart, $afinish, $style, $line_style, $fill_color, $nc);
  10199. $this->StopTransform();
  10200. return;
  10201. }
  10202. if ($rx)
  10203. {
  10204. if (! (false === strpos($style, 'F')) and isset($fill_color))
  10205. {
  10206. $this->SetFillColorArray($fill_color);
  10207. }
  10208. switch ($style)
  10209. {
  10210. case 'F' :
  10211. {
  10212. $op = 'f';
  10213. $line_style = array();
  10214. break;
  10215. }
  10216. case 'FD' :
  10217. case 'DF' :
  10218. {
  10219. $op = 'B';
  10220. break;
  10221. }
  10222. case 'C' :
  10223. {
  10224. $op = 's'; // Small 's' signifies closing the path as well
  10225. break;
  10226. }
  10227. case 'CNZ' :
  10228. {
  10229. $op = 'W n';
  10230. break;
  10231. }
  10232. case 'CEO' :
  10233. {
  10234. $op = 'W* n';
  10235. break;
  10236. }
  10237. default :
  10238. {
  10239. $op = 'S';
  10240. break;
  10241. }
  10242. }
  10243. if ($line_style)
  10244. {
  10245. $this->SetLineStyle($line_style);
  10246. }
  10247. if (! $ry)
  10248. {
  10249. $ry = $rx;
  10250. }
  10251. $rx *= $this->k;
  10252. $ry *= $this->k;
  10253. if ($nc < 2)
  10254. {
  10255. $nc = 2;
  10256. }
  10257. $astart = deg2rad((float) $astart);
  10258. $afinish = deg2rad((float) $afinish);
  10259. $total_angle = $afinish - $astart;
  10260. $dt = $total_angle / $nc;
  10261. $dtm = $dt / 3;
  10262. $x0 *= $this->k;
  10263. $y0 = ($this->h - $y0) * $this->k;
  10264. $t1 = $astart;
  10265. $a0 = $x0 + ($rx * cos($t1));
  10266. $b0 = $y0 + ($ry * sin($t1));
  10267. $c0 = - $rx * sin($t1);
  10268. $d0 = $ry * cos($t1);
  10269. $this->_outPoint($a0 / $this->k, $this->h - ($b0 / $this->k));
  10270. for($i = 1; $i <= $nc; ++ $i)
  10271. {
  10272. // Draw this bit of the total curve
  10273. $t1 = ($i * $dt) + $astart;
  10274. $a1 = $x0 + ($rx * cos($t1));
  10275. $b1 = $y0 + ($ry * sin($t1));
  10276. $c1 = - $rx * sin($t1);
  10277. $d1 = $ry * cos($t1);
  10278. $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));
  10279. $a0 = $a1;
  10280. $b0 = $b1;
  10281. $c0 = $c1;
  10282. $d0 = $d1;
  10283. }
  10284. $this->_out($op);
  10285. }
  10286. }
  10287. /**
  10288. * Draws a circle.
  10289. * A circle is formed from n Bezier curves.
  10290. * @param float $x0 Abscissa of center point.
  10291. * @param float $y0 Ordinate of center point.
  10292. * @param float $r Radius.
  10293. * @param float $astart: Angle start of draw line. Default value: 0.
  10294. * @param float $afinish: Angle finish of draw line. Default value: 360.
  10295. * @param string $style Style of rendering. Possible values are:
  10296. * <ul>
  10297. * <li>D or empty string: Draw (default).</li>
  10298. * <li>F: Fill.</li>
  10299. * <li>DF or FD: Draw and fill.</li>
  10300. * <li>C: Draw close.</li>
  10301. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10302. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10303. * </ul>
  10304. * @param array $line_style Line style of circle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  10305. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  10306. * @param integer $nc Number of curves used in circle. Default value: 8.
  10307. * @access public
  10308. * @since 2.1.000 (2008-01-08)
  10309. */
  10310. public function Circle($x0, $y0, $r, $astart = 0, $afinish = 360, $style = '', $line_style = array(), $fill_color = array(), $nc = 8)
  10311. {
  10312. $this->Ellipse($x0, $y0, $r, 0, 0, $astart, $afinish, $style, $line_style, $fill_color, $nc);
  10313. }
  10314. /**
  10315. * Draws a polygonal line
  10316. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  10317. * @param string $style Style of rendering. Possible values are:
  10318. * <ul>
  10319. * <li>D or empty string: Draw (default).</li>
  10320. * <li>F: Fill.</li>
  10321. * <li>DF or FD: Draw and fill.</li>
  10322. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10323. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10324. * </ul>
  10325. * @param array $line_style Line style of polygon. Array with keys among the following:
  10326. * <ul>
  10327. * <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  10328. * <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  10329. * </ul>
  10330. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  10331. * @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).
  10332. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  10333. * @access public
  10334. * @since 4.8.003 (2009-09-15)
  10335. */
  10336. public function PolyLine($p, $style = '', $line_style = array(), $fill_color = array())
  10337. {
  10338. $this->Polygon($p, $style, $line_style, $fill_color, false);
  10339. }
  10340. /**
  10341. * Draws a polygon.
  10342. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  10343. * @param string $style Style of rendering. Possible values are:
  10344. * <ul>
  10345. * <li>D or empty string: Draw (default).</li>
  10346. * <li>F: Fill.</li>
  10347. * <li>DF or FD: Draw and fill.</li>
  10348. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10349. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10350. * </ul>
  10351. * @param array $line_style Line style of polygon. Array with keys among the following:
  10352. * <ul>
  10353. * <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  10354. * <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  10355. * </ul>
  10356. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  10357. * @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).
  10358. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  10359. * @access public
  10360. * @since 2.1.000 (2008-01-08)
  10361. */
  10362. public function Polygon($p, $style = '', $line_style = array(), $fill_color = array(), $closed = true)
  10363. {
  10364. $nc = count($p); // number of coordinates
  10365. $np = $nc / 2; // number of points
  10366. if ($closed)
  10367. {
  10368. // close polygon by adding the first 2 points at the end (one line)
  10369. for($i = 0; $i < 4; ++ $i)
  10370. {
  10371. $p[$nc + $i] = $p[$i];
  10372. }
  10373. // copy style for the last added line
  10374. if (isset($line_style[0]))
  10375. {
  10376. $line_style[$np] = $line_style[0];
  10377. }
  10378. $nc += 4;
  10379. }
  10380. if (! (false === strpos($style, 'F')) and isset($fill_color))
  10381. {
  10382. $this->SetFillColorArray($fill_color);
  10383. }
  10384. switch ($style)
  10385. {
  10386. case 'F' :
  10387. {
  10388. $line_style = array();
  10389. $op = 'f';
  10390. break;
  10391. }
  10392. case 'FD' :
  10393. case 'DF' :
  10394. {
  10395. $op = 'B';
  10396. break;
  10397. }
  10398. case 'CNZ' :
  10399. {
  10400. $op = 'W n';
  10401. break;
  10402. }
  10403. case 'CEO' :
  10404. {
  10405. $op = 'W* n';
  10406. break;
  10407. }
  10408. default :
  10409. {
  10410. $op = 'S';
  10411. break;
  10412. }
  10413. }
  10414. $draw = true;
  10415. if ($line_style)
  10416. {
  10417. if (isset($line_style['all']))
  10418. {
  10419. $this->SetLineStyle($line_style['all']);
  10420. }
  10421. else
  10422. {
  10423. $draw = false;
  10424. if ($op == 'B')
  10425. {
  10426. // draw fill
  10427. $op = 'f';
  10428. $this->_outPoint($p[0], $p[1]);
  10429. for($i = 2; $i < $nc; $i = $i + 2)
  10430. {
  10431. $this->_outLine($p[$i], $p[$i + 1]);
  10432. }
  10433. $this->_out($op);
  10434. }
  10435. // draw outline
  10436. $this->_outPoint($p[0], $p[1]);
  10437. for($i = 2; $i < $nc; $i = $i + 2)
  10438. {
  10439. $line_num = ($i / 2) - 1;
  10440. if (isset($line_style[$line_num]))
  10441. {
  10442. if ($line_style[$line_num] != 0)
  10443. {
  10444. if (is_array($line_style[$line_num]))
  10445. {
  10446. $this->_out('S');
  10447. $this->SetLineStyle($line_style[$line_num]);
  10448. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  10449. $this->_outLine($p[$i], $p[$i + 1]);
  10450. $this->_out('S');
  10451. $this->_outPoint($p[$i], $p[$i + 1]);
  10452. }
  10453. else
  10454. {
  10455. $this->_outLine($p[$i], $p[$i + 1]);
  10456. }
  10457. }
  10458. }
  10459. else
  10460. {
  10461. $this->_outLine($p[$i], $p[$i + 1]);
  10462. }
  10463. }
  10464. $this->_out($op);
  10465. }
  10466. }
  10467. if ($draw)
  10468. {
  10469. $this->_outPoint($p[0], $p[1]);
  10470. for($i = 2; $i < $nc; $i = $i + 2)
  10471. {
  10472. $this->_outLine($p[$i], $p[$i + 1]);
  10473. }
  10474. $this->_out($op);
  10475. }
  10476. }
  10477. /**
  10478. * Draws a regular polygon.
  10479. * @param float $x0 Abscissa of center point.
  10480. * @param float $y0 Ordinate of center point.
  10481. * @param float $r: Radius of inscribed circle.
  10482. * @param integer $ns Number of sides.
  10483. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  10484. * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  10485. * @param string $style Style of rendering. Possible values are:
  10486. * <ul>
  10487. * <li>D or empty string: Draw (default).</li>
  10488. * <li>F: Fill.</li>
  10489. * <li>DF or FD: Draw and fill.</li>
  10490. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10491. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10492. * </ul>
  10493. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  10494. * <ul>
  10495. * <li>all: Line style of all sides. Array like for {@link SetLineStyle SetLineStyle}.</li>
  10496. * <li>0 to ($ns - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  10497. * </ul>
  10498. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  10499. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  10500. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  10501. * <ul>
  10502. * <li>D or empty string: Draw (default).</li>
  10503. * <li>F: Fill.</li>
  10504. * <li>DF or FD: Draw and fill.</li>
  10505. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10506. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10507. * </ul>
  10508. * @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).
  10509. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  10510. * @access public
  10511. * @since 2.1.000 (2008-01-08)
  10512. */
  10513. 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())
  10514. {
  10515. if (3 > $ns)
  10516. {
  10517. $ns = 3;
  10518. }
  10519. if ($draw_circle)
  10520. {
  10521. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  10522. }
  10523. $p = array();
  10524. for($i = 0; $i < $ns; ++ $i)
  10525. {
  10526. $a = $angle + ($i * 360 / $ns);
  10527. $a_rad = deg2rad((float) $a);
  10528. $p[] = $x0 + ($r * sin($a_rad));
  10529. $p[] = $y0 + ($r * cos($a_rad));
  10530. }
  10531. $this->Polygon($p, $style, $line_style, $fill_color);
  10532. }
  10533. /**
  10534. * Draws a star polygon
  10535. * @param float $x0 Abscissa of center point.
  10536. * @param float $y0 Ordinate of center point.
  10537. * @param float $r Radius of inscribed circle.
  10538. * @param integer $nv Number of vertices.
  10539. * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  10540. * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  10541. * @param boolean $draw_circle: Draw inscribed circle or not. Default value is false.
  10542. * @param string $style Style of rendering. Possible values are:
  10543. * <ul>
  10544. * <li>D or empty string: Draw (default).</li>
  10545. * <li>F: Fill.</li>
  10546. * <li>DF or FD: Draw and fill.</li>
  10547. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10548. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10549. * </ul>
  10550. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  10551. * <ul>
  10552. * <li>all: Line style of all sides. Array like for
  10553. * {@link SetLineStyle SetLineStyle}.</li>
  10554. * <li>0 to (n - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  10555. * </ul>
  10556. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  10557. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  10558. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  10559. * <ul>
  10560. * <li>D or empty string: Draw (default).</li>
  10561. * <li>F: Fill.</li>
  10562. * <li>DF or FD: Draw and fill.</li>
  10563. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10564. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10565. * </ul>
  10566. * @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).
  10567. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  10568. * @access public
  10569. * @since 2.1.000 (2008-01-08)
  10570. */
  10571. 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())
  10572. {
  10573. if ($nv < 2)
  10574. {
  10575. $nv = 2;
  10576. }
  10577. if ($draw_circle)
  10578. {
  10579. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  10580. }
  10581. $p2 = array();
  10582. $visited = array();
  10583. for($i = 0; $i < $nv; ++ $i)
  10584. {
  10585. $a = $angle + ($i * 360 / $nv);
  10586. $a_rad = deg2rad((float) $a);
  10587. $p2[] = $x0 + ($r * sin($a_rad));
  10588. $p2[] = $y0 + ($r * cos($a_rad));
  10589. $visited[] = false;
  10590. }
  10591. $p = array();
  10592. $i = 0;
  10593. do
  10594. {
  10595. $p[] = $p2[$i * 2];
  10596. $p[] = $p2[($i * 2) + 1];
  10597. $visited[$i] = true;
  10598. $i += $ng;
  10599. $i %= $nv;
  10600. }
  10601. while (! $visited[$i]);
  10602. $this->Polygon($p, $style, $line_style, $fill_color);
  10603. }
  10604. /**
  10605. * Draws a rounded rectangle.
  10606. * @param float $x Abscissa of upper-left corner.
  10607. * @param float $y Ordinate of upper-left corner.
  10608. * @param float $w Width.
  10609. * @param float $h Height.
  10610. * @param float $r Radius of the rounded corners.
  10611. * @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").
  10612. * @param string $style Style of rendering. Possible values are:
  10613. * <ul>
  10614. * <li>D or empty string: Draw (default).</li>
  10615. * <li>F: Fill.</li>
  10616. * <li>DF or FD: Draw and fill.</li>
  10617. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  10618. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  10619. * </ul>
  10620. * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  10621. * @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).
  10622. * @access public
  10623. * @since 2.1.000 (2008-01-08)
  10624. */
  10625. public function RoundedRect($x, $y, $w, $h, $r, $round_corner = '1111', $style = '', $border_style = array(), $fill_color = array())
  10626. {
  10627. if ('0000' == $round_corner)
  10628. { // Not rounded
  10629. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  10630. }
  10631. else
  10632. { // Rounded
  10633. if (! (false === strpos($style, 'F')) and isset($fill_color))
  10634. {
  10635. $this->SetFillColorArray($fill_color);
  10636. }
  10637. switch ($style)
  10638. {
  10639. case 'F' :
  10640. {
  10641. $border_style = array();
  10642. $op = 'f';
  10643. break;
  10644. }
  10645. case 'FD' :
  10646. case 'DF' :
  10647. {
  10648. $op = 'B';
  10649. break;
  10650. }
  10651. case 'CNZ' :
  10652. {
  10653. $op = 'W n';
  10654. break;
  10655. }
  10656. case 'CEO' :
  10657. {
  10658. $op = 'W* n';
  10659. break;
  10660. }
  10661. default :
  10662. {
  10663. $op = 'S';
  10664. break;
  10665. }
  10666. }
  10667. if ($border_style)
  10668. {
  10669. $this->SetLineStyle($border_style);
  10670. }
  10671. $MyArc = 4 / 3 * (sqrt(2) - 1);
  10672. $this->_outPoint($x + $r, $y);
  10673. $xc = $x + $w - $r;
  10674. $yc = $y + $r;
  10675. $this->_outLine($xc, $y);
  10676. if ($round_corner[0])
  10677. {
  10678. $this->_outCurve($xc + ($r * $MyArc), $yc - $r, $xc + $r, $yc - ($r * $MyArc), $xc + $r, $yc);
  10679. }
  10680. else
  10681. {
  10682. $this->_outLine($x + $w, $y);
  10683. }
  10684. $xc = $x + $w - $r;
  10685. $yc = $y + $h - $r;
  10686. $this->_outLine($x + $w, $yc);
  10687. if ($round_corner[1])
  10688. {
  10689. $this->_outCurve($xc + $r, $yc + ($r * $MyArc), $xc + ($r * $MyArc), $yc + $r, $xc, $yc + $r);
  10690. }
  10691. else
  10692. {
  10693. $this->_outLine($x + $w, $y + $h);
  10694. }
  10695. $xc = $x + $r;
  10696. $yc = $y + $h - $r;
  10697. $this->_outLine($xc, $y + $h);
  10698. if ($round_corner[2])
  10699. {
  10700. $this->_outCurve($xc - ($r * $MyArc), $yc + $r, $xc - $r, $yc + ($r * $MyArc), $xc - $r, $yc);
  10701. }
  10702. else
  10703. {
  10704. $this->_outLine($x, $y + $h);
  10705. }
  10706. $xc = $x + $r;
  10707. $yc = $y + $r;
  10708. $this->_outLine($x, $yc);
  10709. if ($round_corner[3])
  10710. {
  10711. $this->_outCurve($xc - $r, $yc - ($r * $MyArc), $xc - ($r * $MyArc), $yc - $r, $xc, $yc - $r);
  10712. }
  10713. else
  10714. {
  10715. $this->_outLine($x, $y);
  10716. $this->_outLine($x + $r, $y);
  10717. }
  10718. $this->_out($op);
  10719. }
  10720. }
  10721. /**
  10722. * Draws a grahic arrow.
  10723. * @parameter float $x0 Abscissa of first point.
  10724. * @parameter float $y0 Ordinate of first point.
  10725. * @parameter float $x0 Abscissa of second point.
  10726. * @parameter float $y1 Ordinate of second point.
  10727. * @parameter int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  10728. * @parameter float $arm_size length of arrowhead arms
  10729. * @parameter int $arm_angle angle between an arm and the shaft
  10730. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  10731. * @since 4.6.018 (2009-07-10)
  10732. */
  10733. public function Arrow($x0, $y0, $x1, $y1, $head_style = 0, $arm_size = 5, $arm_angle = 15)
  10734. {
  10735. // getting arrow direction angle
  10736. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  10737. $dir_angle = rad2deg(atan2(($y0 - $y1), ($x0 - $x1)));
  10738. $sx1 = $x1;
  10739. $sy1 = $y1;
  10740. if ($head_style > 0)
  10741. {
  10742. // calculate the stopping point for the arrow shaft
  10743. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos(deg2rad($dir_angle)));
  10744. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin(deg2rad($dir_angle)));
  10745. }
  10746. // main arrow line / shaft
  10747. $this->Line($x0, $y0, $sx1, $sy1);
  10748. // left arrowhead arm tip
  10749. $x2L = $x1 + ($arm_size * cos(deg2rad($dir_angle + $arm_angle)));
  10750. $y2L = $y1 + ($arm_size * sin(deg2rad($dir_angle + $arm_angle)));
  10751. // right arrowhead arm tip
  10752. $x2R = $x1 + ($arm_size * cos(deg2rad($dir_angle - $arm_angle)));
  10753. $y2R = $y1 + ($arm_size * sin(deg2rad($dir_angle - $arm_angle)));
  10754. $mode = 'D';
  10755. $style = array();
  10756. switch ($head_style)
  10757. {
  10758. case 0 :
  10759. {
  10760. // draw only arrowhead arms
  10761. $mode = 'D';
  10762. $style = array(1, 1, 0);
  10763. break;
  10764. }
  10765. case 1 :
  10766. {
  10767. // draw closed arrowhead, but no fill
  10768. $mode = 'D';
  10769. break;
  10770. }
  10771. case 2 :
  10772. {
  10773. // closed and filled arrowhead
  10774. $mode = 'DF';
  10775. break;
  10776. }
  10777. case 3 :
  10778. {
  10779. // filled arrowhead
  10780. $mode = 'F';
  10781. break;
  10782. }
  10783. }
  10784. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  10785. }
  10786. // END GRAPHIC FUNCTIONS SECTION -----------------------
  10787. // BIDIRECTIONAL TEXT SECTION --------------------------
  10788. /**
  10789. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  10790. * @param string $str string to manipulate.
  10791. * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  10792. * @return string
  10793. * @access protected
  10794. * @author Nicola Asuni
  10795. * @since 2.1.000 (2008-01-08)
  10796. */
  10797. protected function utf8StrRev($str, $setbom = false, $forcertl = false)
  10798. {
  10799. return $this->arrUTF8ToUTF16BE($this->utf8Bidi($this->UTF8StringToArray($str), $str, $forcertl), $setbom);
  10800. }
  10801. /**
  10802. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  10803. * @param array $ta array of characters composing the string.
  10804. * @param string $str string to process
  10805. * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  10806. * @return string
  10807. * @author Nicola Asuni
  10808. * @access protected
  10809. * @since 2.4.000 (2008-03-06)
  10810. */
  10811. protected function utf8Bidi($ta, $str = '', $forcertl = false)
  10812. {
  10813. global $unicode, $unicode_mirror, $unicode_arlet, $laa_array, $diacritics;
  10814. // paragraph embedding level
  10815. $pel = 0;
  10816. // max level
  10817. $maxlevel = 0;
  10818. if ($this->empty_string($str))
  10819. {
  10820. // create string from array
  10821. $str = $this->UTF8ArrSubString($ta);
  10822. }
  10823. // check if string contains arabic text
  10824. if (preg_match(K_RE_PATTERN_ARABIC, $str))
  10825. {
  10826. $arabic = true;
  10827. }
  10828. else
  10829. {
  10830. $arabic = false;
  10831. }
  10832. // check if string contains RTL text
  10833. if (! ($forcertl or $arabic or preg_match(K_RE_PATTERN_RTL, $str)))
  10834. {
  10835. return $ta;
  10836. }
  10837. // get number of chars
  10838. $numchars = count($ta);
  10839. if ($forcertl == 'R')
  10840. {
  10841. $pel = 1;
  10842. }
  10843. elseif ($forcertl == 'L')
  10844. {
  10845. $pel = 0;
  10846. }
  10847. else
  10848. {
  10849. // P2. In each paragraph, find the first character of type L, AL, or R.
  10850. // 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.
  10851. for($i = 0; $i < $numchars; ++ $i)
  10852. {
  10853. $type = $unicode[$ta[$i]];
  10854. if ($type == 'L')
  10855. {
  10856. $pel = 0;
  10857. break;
  10858. }
  10859. elseif (($type == 'AL') or ($type == 'R'))
  10860. {
  10861. $pel = 1;
  10862. break;
  10863. }
  10864. }
  10865. }
  10866. // Current Embedding Level
  10867. $cel = $pel;
  10868. // directional override status
  10869. $dos = 'N';
  10870. $remember = array();
  10871. // start-of-level-run
  10872. $sor = $pel % 2 ? 'R' : 'L';
  10873. $eor = $sor;
  10874. // Array of characters data
  10875. $chardata = Array();
  10876. // 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.
  10877. // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  10878. for($i = 0; $i < $numchars; ++ $i)
  10879. {
  10880. if ($ta[$i] == K_RLE)
  10881. {
  10882. // X2. With each RLE, compute the least greater odd embedding level.
  10883. // 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.
  10884. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  10885. $next_level = $cel + ($cel % 2) + 1;
  10886. if ($next_level < 62)
  10887. {
  10888. $remember[] = array('num' => K_RLE, 'cel' => $cel, 'dos' => $dos);
  10889. $cel = $next_level;
  10890. $dos = 'N';
  10891. $sor = $eor;
  10892. $eor = $cel % 2 ? 'R' : 'L';
  10893. }
  10894. }
  10895. elseif ($ta[$i] == K_LRE)
  10896. {
  10897. // X3. With each LRE, compute the least greater even embedding level.
  10898. // 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.
  10899. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  10900. $next_level = $cel + 2 - ($cel % 2);
  10901. if ($next_level < 62)
  10902. {
  10903. $remember[] = array('num' => K_LRE, 'cel' => $cel, 'dos' => $dos);
  10904. $cel = $next_level;
  10905. $dos = 'N';
  10906. $sor = $eor;
  10907. $eor = $cel % 2 ? 'R' : 'L';
  10908. }
  10909. }
  10910. elseif ($ta[$i] == K_RLO)
  10911. {
  10912. // X4. With each RLO, compute the least greater odd embedding level.
  10913. // 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.
  10914. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  10915. $next_level = $cel + ($cel % 2) + 1;
  10916. if ($next_level < 62)
  10917. {
  10918. $remember[] = array('num' => K_RLO, 'cel' => $cel, 'dos' => $dos);
  10919. $cel = $next_level;
  10920. $dos = 'R';
  10921. $sor = $eor;
  10922. $eor = $cel % 2 ? 'R' : 'L';
  10923. }
  10924. }
  10925. elseif ($ta[$i] == K_LRO)
  10926. {
  10927. // X5. With each LRO, compute the least greater even embedding level.
  10928. // 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.
  10929. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  10930. $next_level = $cel + 2 - ($cel % 2);
  10931. if ($next_level < 62)
  10932. {
  10933. $remember[] = array('num' => K_LRO, 'cel' => $cel, 'dos' => $dos);
  10934. $cel = $next_level;
  10935. $dos = 'L';
  10936. $sor = $eor;
  10937. $eor = $cel % 2 ? 'R' : 'L';
  10938. }
  10939. }
  10940. elseif ($ta[$i] == K_PDF)
  10941. {
  10942. // 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.
  10943. if (count($remember))
  10944. {
  10945. $last = count($remember) - 1;
  10946. if (($remember[$last]['num'] == K_RLE) or ($remember[$last]['num'] == K_LRE) or ($remember[$last]['num'] == K_RLO) or ($remember[$last]['num'] == K_LRO))
  10947. {
  10948. $match = array_pop($remember);
  10949. $cel = $match['cel'];
  10950. $dos = $match['dos'];
  10951. $sor = $eor;
  10952. $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
  10953. }
  10954. }
  10955. }
  10956. elseif (($ta[$i] != K_RLE) and ($ta[$i] != K_LRE) and ($ta[$i] != K_RLO) and ($ta[$i] != K_LRO) and ($ta[$i] != K_PDF))
  10957. {
  10958. // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  10959. // a. Set the level of the current character to the current embedding level.
  10960. // b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  10961. if ($dos != 'N')
  10962. {
  10963. $chardir = $dos;
  10964. }
  10965. else
  10966. {
  10967. if (isset($unicode[$ta[$i]]))
  10968. {
  10969. $chardir = $unicode[$ta[$i]];
  10970. }
  10971. else
  10972. {
  10973. $chardir = 'L';
  10974. }
  10975. }
  10976. // stores string characters and other information
  10977. $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir,
  10978. 'sor' => $sor, 'eor' => $eor);
  10979. }
  10980. } // end for each char
  10981. // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  10982. // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  10983. // 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.
  10984. // 3.3.3 Resolving Weak Types
  10985. // 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.
  10986. // Nonspacing marks are now resolved based on the previous characters.
  10987. $numchars = count($chardata);
  10988. // 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.
  10989. $prevlevel = - 1; // track level changes
  10990. $levcount = 0; // counts consecutive chars at the same level
  10991. for($i = 0; $i < $numchars; ++ $i)
  10992. {
  10993. if ($chardata[$i]['type'] == 'NSM')
  10994. {
  10995. if ($levcount)
  10996. {
  10997. $chardata[$i]['type'] = $chardata[$i]['sor'];
  10998. }
  10999. elseif ($i > 0)
  11000. {
  11001. $chardata[$i]['type'] = $chardata[($i - 1)]['type'];
  11002. }
  11003. }
  11004. if ($chardata[$i]['level'] != $prevlevel)
  11005. {
  11006. $levcount = 0;
  11007. }
  11008. else
  11009. {
  11010. ++ $levcount;
  11011. }
  11012. $prevlevel = $chardata[$i]['level'];
  11013. }
  11014. // 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.
  11015. $prevlevel = - 1;
  11016. $levcount = 0;
  11017. for($i = 0; $i < $numchars; ++ $i)
  11018. {
  11019. if ($chardata[$i]['char'] == 'EN')
  11020. {
  11021. for($j = $levcount; $j >= 0; $j --)
  11022. {
  11023. if ($chardata[$j]['type'] == 'AL')
  11024. {
  11025. $chardata[$i]['type'] = 'AN';
  11026. }
  11027. elseif (($chardata[$j]['type'] == 'L') or ($chardata[$j]['type'] == 'R'))
  11028. {
  11029. break;
  11030. }
  11031. }
  11032. }
  11033. if ($chardata[$i]['level'] != $prevlevel)
  11034. {
  11035. $levcount = 0;
  11036. }
  11037. else
  11038. {
  11039. ++ $levcount;
  11040. }
  11041. $prevlevel = $chardata[$i]['level'];
  11042. }
  11043. // W3. Change all ALs to R.
  11044. for($i = 0; $i < $numchars; ++ $i)
  11045. {
  11046. if ($chardata[$i]['type'] == 'AL')
  11047. {
  11048. $chardata[$i]['type'] = 'R';
  11049. }
  11050. }
  11051. // 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.
  11052. $prevlevel = - 1;
  11053. $levcount = 0;
  11054. for($i = 0; $i < $numchars; ++ $i)
  11055. {
  11056. if (($levcount > 0) and (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] == $prevlevel))
  11057. {
  11058. if (($chardata[$i]['type'] == 'ES') and ($chardata[($i - 1)]['type'] == 'EN') and ($chardata[($i + 1)]['type'] == 'EN'))
  11059. {
  11060. $chardata[$i]['type'] = 'EN';
  11061. }
  11062. elseif (($chardata[$i]['type'] == 'CS') and ($chardata[($i - 1)]['type'] == 'EN') and ($chardata[($i + 1)]['type'] == 'EN'))
  11063. {
  11064. $chardata[$i]['type'] = 'EN';
  11065. }
  11066. elseif (($chardata[$i]['type'] == 'CS') and ($chardata[($i - 1)]['type'] == 'AN') and ($chardata[($i + 1)]['type'] == 'AN'))
  11067. {
  11068. $chardata[$i]['type'] = 'AN';
  11069. }
  11070. }
  11071. if ($chardata[$i]['level'] != $prevlevel)
  11072. {
  11073. $levcount = 0;
  11074. }
  11075. else
  11076. {
  11077. ++ $levcount;
  11078. }
  11079. $prevlevel = $chardata[$i]['level'];
  11080. }
  11081. // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  11082. $prevlevel = - 1;
  11083. $levcount = 0;
  11084. for($i = 0; $i < $numchars; ++ $i)
  11085. {
  11086. if ($chardata[$i]['type'] == 'ET')
  11087. {
  11088. if (($levcount > 0) and ($chardata[($i - 1)]['type'] == 'EN'))
  11089. {
  11090. $chardata[$i]['type'] = 'EN';
  11091. }
  11092. else
  11093. {
  11094. $j = $i + 1;
  11095. while (($j < $numchars) and ($chardata[$j]['level'] == $prevlevel))
  11096. {
  11097. if ($chardata[$j]['type'] == 'EN')
  11098. {
  11099. $chardata[$i]['type'] = 'EN';
  11100. break;
  11101. }
  11102. elseif ($chardata[$j]['type'] != 'ET')
  11103. {
  11104. break;
  11105. }
  11106. ++ $j;
  11107. }
  11108. }
  11109. }
  11110. if ($chardata[$i]['level'] != $prevlevel)
  11111. {
  11112. $levcount = 0;
  11113. }
  11114. else
  11115. {
  11116. ++ $levcount;
  11117. }
  11118. $prevlevel = $chardata[$i]['level'];
  11119. }
  11120. // W6. Otherwise, separators and terminators change to Other Neutral.
  11121. $prevlevel = - 1;
  11122. $levcount = 0;
  11123. for($i = 0; $i < $numchars; ++ $i)
  11124. {
  11125. if (($chardata[$i]['type'] == 'ET') or ($chardata[$i]['type'] == 'ES') or ($chardata[$i]['type'] == 'CS'))
  11126. {
  11127. $chardata[$i]['type'] = 'ON';
  11128. }
  11129. if ($chardata[$i]['level'] != $prevlevel)
  11130. {
  11131. $levcount = 0;
  11132. }
  11133. else
  11134. {
  11135. ++ $levcount;
  11136. }
  11137. $prevlevel = $chardata[$i]['level'];
  11138. }
  11139. //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.
  11140. $prevlevel = - 1;
  11141. $levcount = 0;
  11142. for($i = 0; $i < $numchars; ++ $i)
  11143. {
  11144. if ($chardata[$i]['char'] == 'EN')
  11145. {
  11146. for($j = $levcount; $j >= 0; $j --)
  11147. {
  11148. if ($chardata[$j]['type'] == 'L')
  11149. {
  11150. $chardata[$i]['type'] = 'L';
  11151. }
  11152. elseif ($chardata[$j]['type'] == 'R')
  11153. {
  11154. break;
  11155. }
  11156. }
  11157. }
  11158. if ($chardata[$i]['level'] != $prevlevel)
  11159. {
  11160. $levcount = 0;
  11161. }
  11162. else
  11163. {
  11164. ++ $levcount;
  11165. }
  11166. $prevlevel = $chardata[$i]['level'];
  11167. }
  11168. // 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.
  11169. $prevlevel = - 1;
  11170. $levcount = 0;
  11171. for($i = 0; $i < $numchars; ++ $i)
  11172. {
  11173. if (($levcount > 0) and (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] == $prevlevel))
  11174. {
  11175. if (($chardata[$i]['type'] == 'N') and ($chardata[($i - 1)]['type'] == 'L') and ($chardata[($i + 1)]['type'] == 'L'))
  11176. {
  11177. $chardata[$i]['type'] = 'L';
  11178. }
  11179. elseif (($chardata[$i]['type'] == 'N') and (($chardata[($i - 1)]['type'] == 'R') or ($chardata[($i - 1)]['type'] == 'EN') or ($chardata[($i - 1)]['type'] == 'AN')) and (($chardata[($i + 1)]['type'] == 'R') or ($chardata[($i + 1)]['type'] == 'EN') or ($chardata[($i + 1)]['type'] == 'AN')))
  11180. {
  11181. $chardata[$i]['type'] = 'R';
  11182. }
  11183. elseif ($chardata[$i]['type'] == 'N')
  11184. {
  11185. // N2. Any remaining neutrals take the embedding direction
  11186. $chardata[$i]['type'] = $chardata[$i]['sor'];
  11187. }
  11188. }
  11189. elseif (($levcount == 0) and (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] == $prevlevel))
  11190. {
  11191. // first char
  11192. if (($chardata[$i]['type'] == 'N') and ($chardata[$i]['sor'] == 'L') and ($chardata[($i + 1)]['type'] == 'L'))
  11193. {
  11194. $chardata[$i]['type'] = 'L';
  11195. }
  11196. elseif (($chardata[$i]['type'] == 'N') and (($chardata[$i]['sor'] == 'R') or ($chardata[$i]['sor'] == 'EN') or ($chardata[$i]['sor'] == 'AN')) and (($chardata[($i + 1)]['type'] == 'R') or ($chardata[($i + 1)]['type'] == 'EN') or ($chardata[($i + 1)]['type'] == 'AN')))
  11197. {
  11198. $chardata[$i]['type'] = 'R';
  11199. }
  11200. elseif ($chardata[$i]['type'] == 'N')
  11201. {
  11202. // N2. Any remaining neutrals take the embedding direction
  11203. $chardata[$i]['type'] = $chardata[$i]['sor'];
  11204. }
  11205. }
  11206. elseif (($levcount > 0) and ((($i + 1) == $numchars) or (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] != $prevlevel)))
  11207. {
  11208. //last char
  11209. if (($chardata[$i]['type'] == 'N') and ($chardata[($i - 1)]['type'] == 'L') and ($chardata[$i]['eor'] == 'L'))
  11210. {
  11211. $chardata[$i]['type'] = 'L';
  11212. }
  11213. elseif (($chardata[$i]['type'] == 'N') and (($chardata[($i - 1)]['type'] == 'R') or ($chardata[($i - 1)]['type'] == 'EN') or ($chardata[($i - 1)]['type'] == 'AN')) and (($chardata[$i]['eor'] == 'R') or ($chardata[$i]['eor'] == 'EN') or ($chardata[$i]['eor'] == 'AN')))
  11214. {
  11215. $chardata[$i]['type'] = 'R';
  11216. }
  11217. elseif ($chardata[$i]['type'] == 'N')
  11218. {
  11219. // N2. Any remaining neutrals take the embedding direction
  11220. $chardata[$i]['type'] = $chardata[$i]['sor'];
  11221. }
  11222. }
  11223. elseif ($chardata[$i]['type'] == 'N')
  11224. {
  11225. // N2. Any remaining neutrals take the embedding direction
  11226. $chardata[$i]['type'] = $chardata[$i]['sor'];
  11227. }
  11228. if ($chardata[$i]['level'] != $prevlevel)
  11229. {
  11230. $levcount = 0;
  11231. }
  11232. else
  11233. {
  11234. ++ $levcount;
  11235. }
  11236. $prevlevel = $chardata[$i]['level'];
  11237. }
  11238. // 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.
  11239. // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  11240. for($i = 0; $i < $numchars; ++ $i)
  11241. {
  11242. $odd = $chardata[$i]['level'] % 2;
  11243. if ($odd)
  11244. {
  11245. if (($chardata[$i]['type'] == 'L') or ($chardata[$i]['type'] == 'AN') or ($chardata[$i]['type'] == 'EN'))
  11246. {
  11247. $chardata[$i]['level'] += 1;
  11248. }
  11249. }
  11250. else
  11251. {
  11252. if ($chardata[$i]['type'] == 'R')
  11253. {
  11254. $chardata[$i]['level'] += 1;
  11255. }
  11256. elseif (($chardata[$i]['type'] == 'AN') or ($chardata[$i]['type'] == 'EN'))
  11257. {
  11258. $chardata[$i]['level'] += 2;
  11259. }
  11260. }
  11261. $maxlevel = max($chardata[$i]['level'], $maxlevel);
  11262. }
  11263. // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  11264. // 1. Segment separators,
  11265. // 2. Paragraph separators,
  11266. // 3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  11267. // 4. Any sequence of white space characters at the end of the line.
  11268. for($i = 0; $i < $numchars; ++ $i)
  11269. {
  11270. if (($chardata[$i]['type'] == 'B') or ($chardata[$i]['type'] == 'S'))
  11271. {
  11272. $chardata[$i]['level'] = $pel;
  11273. }
  11274. elseif ($chardata[$i]['type'] == 'WS')
  11275. {
  11276. $j = $i + 1;
  11277. while ($j < $numchars)
  11278. {
  11279. if ((($chardata[$j]['type'] == 'B') or ($chardata[$j]['type'] == 'S')) or (($j == ($numchars - 1)) and ($chardata[$j]['type'] == 'WS')))
  11280. {
  11281. $chardata[$i]['level'] = $pel;
  11282. break;
  11283. }
  11284. elseif ($chardata[$j]['type'] != 'WS')
  11285. {
  11286. break;
  11287. }
  11288. ++ $j;
  11289. }
  11290. }
  11291. }
  11292. // Arabic Shaping
  11293. // 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.
  11294. if ($arabic)
  11295. {
  11296. $endedletter = array(1569, 1570, 1571, 1572, 1573, 1575, 1577, 1583, 1584, 1585, 1586, 1608, 1688);
  11297. $alfletter = array(1570, 1571, 1573, 1575);
  11298. $chardata2 = $chardata;
  11299. $laaletter = false;
  11300. $charAL = array();
  11301. $x = 0;
  11302. for($i = 0; $i < $numchars; ++ $i)
  11303. {
  11304. if (($unicode[$chardata[$i]['char']] == 'AL') or ($chardata[$i]['char'] == 32) or ($chardata[$i]['char'] == 8204))
  11305. {
  11306. $charAL[$x] = $chardata[$i];
  11307. $charAL[$x]['i'] = $i;
  11308. $chardata[$i]['x'] = $x;
  11309. ++ $x;
  11310. }
  11311. }
  11312. $numAL = $x;
  11313. for($i = 0; $i < $numchars; ++ $i)
  11314. {
  11315. $thischar = $chardata[$i];
  11316. if ($i > 0)
  11317. {
  11318. $prevchar = $chardata[($i - 1)];
  11319. }
  11320. else
  11321. {
  11322. $prevchar = false;
  11323. }
  11324. if (($i + 1) < $numchars)
  11325. {
  11326. $nextchar = $chardata[($i + 1)];
  11327. }
  11328. else
  11329. {
  11330. $nextchar = false;
  11331. }
  11332. if ($unicode[$thischar['char']] == 'AL')
  11333. {
  11334. $x = $thischar['x'];
  11335. if ($x > 0)
  11336. {
  11337. $prevchar = $charAL[($x - 1)];
  11338. }
  11339. else
  11340. {
  11341. $prevchar = false;
  11342. }
  11343. if (($x + 1) < $numAL)
  11344. {
  11345. $nextchar = $charAL[($x + 1)];
  11346. }
  11347. else
  11348. {
  11349. $nextchar = false;
  11350. }
  11351. // if laa letter
  11352. if (($prevchar !== false) and ($prevchar['char'] == 1604) and (in_array($thischar['char'], $alfletter)))
  11353. {
  11354. $arabicarr = $laa_array;
  11355. $laaletter = true;
  11356. if ($x > 1)
  11357. {
  11358. $prevchar = $charAL[($x - 2)];
  11359. }
  11360. else
  11361. {
  11362. $prevchar = false;
  11363. }
  11364. }
  11365. else
  11366. {
  11367. $arabicarr = $unicode_arlet;
  11368. $laaletter = false;
  11369. }
  11370. if (($prevchar !== false) and ($nextchar !== false) and (($unicode[$prevchar['char']] == 'AL') or ($unicode[$prevchar['char']] == 'NSM')) and (($unicode[$nextchar['char']] == 'AL') or ($unicode[$nextchar['char']] == 'NSM')) and ($prevchar['type'] == $thischar['type']) and ($nextchar['type'] == $thischar['type']) and ($nextchar['char'] != 1567))
  11371. {
  11372. if (in_array($prevchar['char'], $endedletter))
  11373. {
  11374. if (isset($arabicarr[$thischar['char']][2]))
  11375. {
  11376. // initial
  11377. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  11378. }
  11379. }
  11380. else
  11381. {
  11382. if (isset($arabicarr[$thischar['char']][3]))
  11383. {
  11384. // medial
  11385. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
  11386. }
  11387. }
  11388. }
  11389. elseif (($nextchar !== false) and (($unicode[$nextchar['char']] == 'AL') or ($unicode[$nextchar['char']] == 'NSM')) and ($nextchar['type'] == $thischar['type']) and ($nextchar['char'] != 1567))
  11390. {
  11391. if (isset($arabicarr[$chardata[$i]['char']][2]))
  11392. {
  11393. // initial
  11394. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  11395. }
  11396. }
  11397. elseif ((($prevchar !== false) and (($unicode[$prevchar['char']] == 'AL') or ($unicode[$prevchar['char']] == 'NSM')) and ($prevchar['type'] == $thischar['type'])) or (($nextchar !== false) and ($nextchar['char'] == 1567)))
  11398. {
  11399. // final
  11400. if (($i > 1) and ($thischar['char'] == 1607) and ($chardata[$i - 1]['char'] == 1604) and ($chardata[$i - 2]['char'] == 1604))
  11401. {
  11402. //Allah Word
  11403. // mark characters to delete with false
  11404. $chardata2[$i - 2]['char'] = false;
  11405. $chardata2[$i - 1]['char'] = false;
  11406. $chardata2[$i]['char'] = 65010;
  11407. }
  11408. else
  11409. {
  11410. if (($prevchar !== false) and in_array($prevchar['char'], $endedletter))
  11411. {
  11412. if (isset($arabicarr[$thischar['char']][0]))
  11413. {
  11414. // isolated
  11415. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  11416. }
  11417. }
  11418. else
  11419. {
  11420. if (isset($arabicarr[$thischar['char']][1]))
  11421. {
  11422. // final
  11423. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
  11424. }
  11425. }
  11426. }
  11427. }
  11428. elseif (isset($arabicarr[$thischar['char']][0]))
  11429. {
  11430. // isolated
  11431. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  11432. }
  11433. // if laa letter
  11434. if ($laaletter)
  11435. {
  11436. // mark characters to delete with false
  11437. $chardata2[($charAL[($x - 1)]['i'])]['char'] = false;
  11438. }
  11439. } // end if AL (Arabic Letter)
  11440. } // end for each char
  11441. /*
  11442. * Combining characters that can occur with Shadda (0651 HEX, 1617 DEC) are placed in UE586-UE594.
  11443. * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  11444. */
  11445. $cw = &$this->CurrentFont['cw'];
  11446. for($i = 0; $i < ($numchars - 1); ++ $i)
  11447. {
  11448. if (($chardata2[$i]['char'] == 1617) and (isset($diacritics[($chardata2[$i + 1]['char'])])))
  11449. {
  11450. // check if the subtitution font is defined on current font
  11451. if (isset($cw[($diacritics[($chardata2[$i + 1]['char'])])]))
  11452. {
  11453. $chardata2[$i]['char'] = false;
  11454. $chardata2[$i + 1]['char'] = $diacritics[($chardata2[$i + 1]['char'])];
  11455. }
  11456. }
  11457. }
  11458. // remove marked characters
  11459. foreach ($chardata2 as $key => $value)
  11460. {
  11461. if ($value['char'] === false)
  11462. {
  11463. unset($chardata2[$key]);
  11464. }
  11465. }
  11466. $chardata = array_values($chardata2);
  11467. $numchars = count($chardata);
  11468. unset($chardata2);
  11469. unset($arabicarr);
  11470. unset($laaletter);
  11471. unset($charAL);
  11472. }
  11473. // 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.
  11474. for($j = $maxlevel; $j > 0; $j --)
  11475. {
  11476. $ordarray = Array();
  11477. $revarr = Array();
  11478. $onlevel = false;
  11479. for($i = 0; $i < $numchars; ++ $i)
  11480. {
  11481. if ($chardata[$i]['level'] >= $j)
  11482. {
  11483. $onlevel = true;
  11484. if (isset($unicode_mirror[$chardata[$i]['char']]))
  11485. {
  11486. // 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.
  11487. $chardata[$i]['char'] = $unicode_mirror[$chardata[$i]['char']];
  11488. }
  11489. $revarr[] = $chardata[$i];
  11490. }
  11491. else
  11492. {
  11493. if ($onlevel)
  11494. {
  11495. $revarr = array_reverse($revarr);
  11496. $ordarray = array_merge($ordarray, $revarr);
  11497. $revarr = Array();
  11498. $onlevel = false;
  11499. }
  11500. $ordarray[] = $cha