PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 3ms

/htdocs/includes/tcpdf/tcpdf.php

https://bitbucket.org/speedealing/speedealing
PHP | 11722 lines | 7221 code | 447 blank | 4054 comment | 1322 complexity | 9193fd2ec123c86131319bf50134a328 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 5.9.203
  5. // Begin : 2002-08-03
  6. // Last Update : 2013-01-22
  7. // Author : Nicola Asuni - Tecnick.com LTD - Manor Coach House, Church Hill, Aldershot, Hants, GU12 4RQ, UK - www.tecnick.com - info@tecnick.com
  8. // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2013 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. // This is a PHP class for generating PDF documents without requiring external extensions.
  33. //
  34. // NOTE:
  35. // This class was originally derived in 2002 from the Public
  36. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  37. // but now is almost entirely rewritten and contains thousands of
  38. // new lines of code and hundreds new features.
  39. //
  40. // Main features:
  41. // * no external libraries are required for the basic functions;
  42. // * all standard page formats, custom page formats, custom margins and units of measure;
  43. // * UTF-8 Unicode and Right-To-Left languages;
  44. // * TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  45. // * font subsetting;
  46. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  47. // * images, graphic (geometric figures) and transformation methods;
  48. // * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)
  49. // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  50. // * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  51. // * automatic page header and footer management;
  52. // * document encryption up to 256 bit and digital signature certifications;
  53. // * transactions to UNDO commands;
  54. // * PDF annotations, including links, text and file attachments;
  55. // * text rendering modes (fill, stroke and clipping);
  56. // * multiple columns mode;
  57. // * no-write page regions;
  58. // * bookmarks, named destinations and table of content;
  59. // * text hyphenation;
  60. // * text stretching and spacing (tracking);
  61. // * automatic page break, line break and text alignments including justification;
  62. // * automatic page numbering and page groups;
  63. // * move and delete pages;
  64. // * page compression (requires php-zlib extension);
  65. // * XOBject Templates;
  66. // * Layers and object visibility.
  67. // * PDF/A-1b support.
  68. //
  69. // -----------------------------------------------------------
  70. // THANKS TO:
  71. //
  72. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  73. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  74. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  75. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  76. // dullus for text Justification.
  77. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  78. // Patrick Benny for text stretch suggestion on Cell().
  79. // Johannes G�ntert for JavaScript support.
  80. // Denis Van Nuffelen for Dynamic Form.
  81. // Jacek Czekaj for multibyte justification
  82. // Anthony Ferrara for the reintroduction of legacy image methods.
  83. // Sourceforge user 1707880 (hucste) for line-trough mode.
  84. // Larry Stanbery for page groups.
  85. // Martin Hall-May for transparency.
  86. // Aaron C. Spike for Polycurve method.
  87. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  88. // Moritz Wagner and Andreas Wurmser for graphic functions.
  89. // Andrew Whitehead for core fonts support.
  90. // Esteban Jo�l Mar�n for OpenType font conversion.
  91. // Teus Hagen for several suggestions and fixes.
  92. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  93. // Kosmas Papachristos for some CSS improvements.
  94. // Marcel Partap for some fixes.
  95. // Won Kyu Park for several suggestions, fixes and patches.
  96. // Dominik Dzienia for QR-code support.
  97. // Laurent Minguet for some suggestions.
  98. // Christian Deligant for some suggestions and fixes.
  99. // Travis Harris for crop mark suggestion.
  100. // Aleksey Kuznetsov for some suggestions and text shadows.
  101. // Jim Hanlon for several suggestions and patches.
  102. // Anyone else that has reported a bug or sent a suggestion.
  103. //============================================================+
  104. /**
  105. * @file
  106. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  107. * 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>
  108. * <h3>TCPDF main features are:</h3>
  109. * <ul>
  110. * <li>no external libraries are required for the basic functions;</li>
  111. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  112. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  113. * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  114. * <li>font subsetting;</li>
  115. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  116. * <li>images, graphic (geometric figures) and transformation methods;
  117. * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)</li>
  118. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;</li>
  119. * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  120. * <li>automatic page header and footer management;</li>
  121. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  122. * <li>transactions to UNDO commands;</li>
  123. * <li>PDF annotations, including links, text and file attachments;</li>
  124. * <li>text rendering modes (fill, stroke and clipping);</li>
  125. * <li>multiple columns mode;</li>
  126. * <li>no-write page regions;</li>
  127. * <li>bookmarks, named destinations and table of content;</li>
  128. * <li>text hyphenation;</li>
  129. * <li>text stretching and spacing (tracking);</li>
  130. * <li>automatic page break, line break and text alignments including justification;</li>
  131. * <li>automatic page numbering and page groups;</li>
  132. * <li>move and delete pages;</li>
  133. * <li>page compression (requires php-zlib extension);</li>
  134. * <li>XOBject Templates;</li>
  135. * <li>Layers and object visibility;</li>
  136. * <li>PDF/A-1b support.</li>
  137. * </ul>
  138. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  139. * @package com.tecnick.tcpdf
  140. * @author Nicola Asuni
  141. * @version 5.9.203
  142. */
  143. // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file.
  144. require_once(dirname(__FILE__) . '/config/tcpdf_config.php');
  145. /**
  146. * @class TCPDF
  147. * PHP class for generating PDF documents without requiring external extensions.
  148. * 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>
  149. * @package com.tecnick.tcpdf
  150. * @brief PHP class for generating PDF documents without requiring external extensions.
  151. * @version 5.9.203
  152. * @author Nicola Asuni - info@tecnick.com
  153. */
  154. class TCPDF {
  155. // private properties
  156. /**
  157. * Current TCPDF version.
  158. * @private
  159. */
  160. private $tcpdf_version = '5.9.203';
  161. // Protected properties
  162. /**
  163. * Current page number.
  164. * @protected
  165. */
  166. protected $page;
  167. /**
  168. * Current object number.
  169. * @protected
  170. */
  171. protected $n;
  172. /**
  173. * Array of object offsets.
  174. * @protected
  175. */
  176. protected $offsets = array();
  177. /**
  178. * Array of object IDs for each page.
  179. * @protected
  180. */
  181. protected $pageobjects = array();
  182. /**
  183. * Buffer holding in-memory PDF.
  184. * @protected
  185. */
  186. protected $buffer;
  187. /**
  188. * Array containing pages.
  189. * @protected
  190. */
  191. protected $pages = array();
  192. /**
  193. * Current document state.
  194. * @protected
  195. */
  196. protected $state;
  197. /**
  198. * Compression flag.
  199. * @protected
  200. */
  201. protected $compress;
  202. /**
  203. * Current page orientation (P = Portrait, L = Landscape).
  204. * @protected
  205. */
  206. protected $CurOrientation;
  207. /**
  208. * Page dimensions.
  209. * @protected
  210. */
  211. protected $pagedim = array();
  212. /**
  213. * Scale factor (number of points in user unit).
  214. * @protected
  215. */
  216. protected $k;
  217. /**
  218. * Width of page format in points.
  219. * @protected
  220. */
  221. protected $fwPt;
  222. /**
  223. * Height of page format in points.
  224. * @protected
  225. */
  226. protected $fhPt;
  227. /**
  228. * Current width of page in points.
  229. * @protected
  230. */
  231. protected $wPt;
  232. /**
  233. * Current height of page in points.
  234. * @protected
  235. */
  236. protected $hPt;
  237. /**
  238. * Current width of page in user unit.
  239. * @protected
  240. */
  241. protected $w;
  242. /**
  243. * Current height of page in user unit.
  244. * @protected
  245. */
  246. protected $h;
  247. /**
  248. * Left margin.
  249. * @protected
  250. */
  251. protected $lMargin;
  252. /**
  253. * Right margin.
  254. * @protected
  255. */
  256. protected $rMargin;
  257. /**
  258. * Cell left margin (used by regions).
  259. * @protected
  260. */
  261. protected $clMargin;
  262. /**
  263. * Cell right margin (used by regions).
  264. * @protected
  265. */
  266. protected $crMargin;
  267. /**
  268. * Top margin.
  269. * @protected
  270. */
  271. protected $tMargin;
  272. /**
  273. * Page break margin.
  274. * @protected
  275. */
  276. protected $bMargin;
  277. /**
  278. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  279. * @since 5.9.000 (2010-10-03)
  280. * @protected
  281. */
  282. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  283. /**
  284. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  285. * @since 5.9.000 (2010-10-04)
  286. * @protected
  287. */
  288. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  289. /**
  290. * Current horizontal position in user unit for cell positioning.
  291. * @protected
  292. */
  293. protected $x;
  294. /**
  295. * Current vertical position in user unit for cell positioning.
  296. * @protected
  297. */
  298. protected $y;
  299. /**
  300. * Height of last cell printed.
  301. * @protected
  302. */
  303. protected $lasth;
  304. /**
  305. * Line width in user unit.
  306. * @protected
  307. */
  308. protected $LineWidth;
  309. /**
  310. * Array of standard font names.
  311. * @protected
  312. */
  313. protected $CoreFonts;
  314. /**
  315. * Array of used fonts.
  316. * @protected
  317. */
  318. protected $fonts = array();
  319. /**
  320. * Array of font files.
  321. * @protected
  322. */
  323. protected $FontFiles = array();
  324. /**
  325. * Array of encoding differences.
  326. * @protected
  327. */
  328. protected $diffs = array();
  329. /**
  330. * Array of used images.
  331. * @protected
  332. */
  333. protected $images = array();
  334. /**
  335. * Array of cached files.
  336. * @protected
  337. */
  338. protected $cached_files = array();
  339. /**
  340. * Array of Annotations in pages.
  341. * @protected
  342. */
  343. protected $PageAnnots = array();
  344. /**
  345. * Array of internal links.
  346. * @protected
  347. */
  348. protected $links = array();
  349. /**
  350. * Current font family.
  351. * @protected
  352. */
  353. protected $FontFamily;
  354. /**
  355. * Current font style.
  356. * @protected
  357. */
  358. protected $FontStyle;
  359. /**
  360. * Current font ascent (distance between font top and baseline).
  361. * @protected
  362. * @since 2.8.000 (2007-03-29)
  363. */
  364. protected $FontAscent;
  365. /**
  366. * Current font descent (distance between font bottom and baseline).
  367. * @protected
  368. * @since 2.8.000 (2007-03-29)
  369. */
  370. protected $FontDescent;
  371. /**
  372. * Underlining flag.
  373. * @protected
  374. */
  375. protected $underline;
  376. /**
  377. * Overlining flag.
  378. * @protected
  379. */
  380. protected $overline;
  381. /**
  382. * Current font info.
  383. * @protected
  384. */
  385. protected $CurrentFont;
  386. /**
  387. * Current font size in points.
  388. * @protected
  389. */
  390. protected $FontSizePt;
  391. /**
  392. * Current font size in user unit.
  393. * @protected
  394. */
  395. protected $FontSize;
  396. /**
  397. * Commands for drawing color.
  398. * @protected
  399. */
  400. protected $DrawColor;
  401. /**
  402. * Commands for filling color.
  403. * @protected
  404. */
  405. protected $FillColor;
  406. /**
  407. * Commands for text color.
  408. * @protected
  409. */
  410. protected $TextColor;
  411. /**
  412. * Indicates whether fill and text colors are different.
  413. * @protected
  414. */
  415. protected $ColorFlag;
  416. /**
  417. * Automatic page breaking.
  418. * @protected
  419. */
  420. protected $AutoPageBreak;
  421. /**
  422. * Threshold used to trigger page breaks.
  423. * @protected
  424. */
  425. protected $PageBreakTrigger;
  426. /**
  427. * Flag set when processing page header.
  428. * @protected
  429. */
  430. protected $InHeader = false;
  431. /**
  432. * Flag set when processing page footer.
  433. * @protected
  434. */
  435. protected $InFooter = false;
  436. /**
  437. * Zoom display mode.
  438. * @protected
  439. */
  440. protected $ZoomMode;
  441. /**
  442. * Layout display mode.
  443. * @protected
  444. */
  445. protected $LayoutMode;
  446. /**
  447. * If true set the document information dictionary in Unicode.
  448. * @protected
  449. */
  450. protected $docinfounicode = true;
  451. /**
  452. * Document title.
  453. * @protected
  454. */
  455. protected $title = '';
  456. /**
  457. * Document subject.
  458. * @protected
  459. */
  460. protected $subject = '';
  461. /**
  462. * Document author.
  463. * @protected
  464. */
  465. protected $author = '';
  466. /**
  467. * Document keywords.
  468. * @protected
  469. */
  470. protected $keywords = '';
  471. /**
  472. * Document creator.
  473. * @protected
  474. */
  475. protected $creator = '';
  476. /**
  477. * Starting page number.
  478. * @protected
  479. */
  480. protected $starting_page_number = 1;
  481. /**
  482. * String alias for total number of pages.
  483. * @protected
  484. */
  485. protected $alias_tot_pages = '{:ptp:}';
  486. /**
  487. * String alias for page number.
  488. * @protected
  489. */
  490. protected $alias_num_page = '{:pnp:}';
  491. /**
  492. * String alias for total number of pages in a single group.
  493. * @protected
  494. */
  495. protected $alias_group_tot_pages = '{:ptg:}';
  496. /**
  497. * String alias for group page number.
  498. * @protected
  499. */
  500. protected $alias_group_num_page = '{:png:}';
  501. /**
  502. * String alias for right shift compensation used to correctly align page numbers on the right.
  503. * @protected
  504. */
  505. protected $alias_right_shift = '{rsc:';
  506. /**
  507. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  508. * @since 2002-07-31
  509. * @author Nicola Asuni
  510. * @protected
  511. */
  512. protected $img_rb_x;
  513. /**
  514. * The right-bottom corner Y coordinate of last inserted image.
  515. * @since 2002-07-31
  516. * @author Nicola Asuni
  517. * @protected
  518. */
  519. protected $img_rb_y;
  520. /**
  521. * Adjusting factor to convert pixels to user units.
  522. * @since 2004-06-14
  523. * @author Nicola Asuni
  524. * @protected
  525. */
  526. protected $imgscale = 1;
  527. /**
  528. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  529. * @since 2005-01-02
  530. * @author Nicola Asuni
  531. * @protected
  532. */
  533. protected $isunicode = false;
  534. /**
  535. * Object containing unicode data.
  536. * @since 5.9.004 (2010-10-18)
  537. * @author Nicola Asuni
  538. * @protected
  539. */
  540. protected $unicode;
  541. /**
  542. * Object containing font encoding maps.
  543. * @since 5.9.123 (2011-10-01)
  544. * @author Nicola Asuni
  545. * @protected
  546. */
  547. protected $encmaps;
  548. /**
  549. * PDF version.
  550. * @since 1.5.3
  551. * @protected
  552. */
  553. protected $PDFVersion = '1.7';
  554. /**
  555. * ID of the stored default header template (-1 = not set).
  556. * @protected
  557. */
  558. protected $header_xobjid = -1;
  559. /**
  560. * If true reset the Header Xobject template at each page
  561. * @protected
  562. */
  563. protected $header_xobj_autoreset = false;
  564. /**
  565. * Minimum distance between header and top page margin.
  566. * @protected
  567. */
  568. protected $header_margin;
  569. /**
  570. * Minimum distance between footer and bottom page margin.
  571. * @protected
  572. */
  573. protected $footer_margin;
  574. /**
  575. * Original left margin value.
  576. * @protected
  577. * @since 1.53.0.TC013
  578. */
  579. protected $original_lMargin;
  580. /**
  581. * Original right margin value.
  582. * @protected
  583. * @since 1.53.0.TC013
  584. */
  585. protected $original_rMargin;
  586. /**
  587. * Default font used on page header.
  588. * @protected
  589. */
  590. protected $header_font;
  591. /**
  592. * Default font used on page footer.
  593. * @protected
  594. */
  595. protected $footer_font;
  596. /**
  597. * Language templates.
  598. * @protected
  599. */
  600. protected $l;
  601. /**
  602. * Barcode to print on page footer (only if set).
  603. * @protected
  604. */
  605. protected $barcode = false;
  606. /**
  607. * Boolean flag to print/hide page header.
  608. * @protected
  609. */
  610. protected $print_header = true;
  611. /**
  612. * Boolean flag to print/hide page footer.
  613. * @protected
  614. */
  615. protected $print_footer = true;
  616. /**
  617. * Header image logo.
  618. * @protected
  619. */
  620. protected $header_logo = '';
  621. /**
  622. * Width of header image logo in user units.
  623. * @protected
  624. */
  625. protected $header_logo_width = 30;
  626. /**
  627. * Title to be printed on default page header.
  628. * @protected
  629. */
  630. protected $header_title = '';
  631. /**
  632. * String to pring on page header after title.
  633. * @protected
  634. */
  635. protected $header_string = '';
  636. /**
  637. * Color for header text (RGB array).
  638. * @since 5.9.174 (2012-07-25)
  639. * @protected
  640. */
  641. protected $header_text_color = array(0, 0, 0);
  642. /**
  643. * Color for header line (RGB array).
  644. * @since 5.9.174 (2012-07-25)
  645. * @protected
  646. */
  647. protected $header_line_color = array(0, 0, 0);
  648. /**
  649. * Color for footer text (RGB array).
  650. * @since 5.9.174 (2012-07-25)
  651. * @protected
  652. */
  653. protected $footer_text_color = array(0, 0, 0);
  654. /**
  655. * Color for footer line (RGB array).
  656. * @since 5.9.174 (2012-07-25)
  657. * @protected
  658. */
  659. protected $footer_line_color = array(0, 0, 0);
  660. /**
  661. * Text shadow data array.
  662. * @since 5.9.174 (2012-07-25)
  663. * @protected
  664. */
  665. protected $txtshadow = array('enabled' => false, 'depth_w' => 0, 'depth_h' => 0, 'color' => false, 'opacity' => 1, 'blend_mode' => 'Normal');
  666. /**
  667. * Default number of columns for html table.
  668. * @protected
  669. */
  670. protected $default_table_columns = 4;
  671. // variables for html parser
  672. /**
  673. * HTML PARSER: array to store current link and rendering styles.
  674. * @protected
  675. */
  676. protected $HREF = array();
  677. /**
  678. * List of available fonts on filesystem.
  679. * @protected
  680. */
  681. protected $fontlist = array();
  682. /**
  683. * Current foreground color.
  684. * @protected
  685. */
  686. protected $fgcolor;
  687. /**
  688. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  689. * @protected
  690. */
  691. protected $listordered = array();
  692. /**
  693. * HTML PARSER: array count list items on nested lists.
  694. * @protected
  695. */
  696. protected $listcount = array();
  697. /**
  698. * HTML PARSER: current list nesting level.
  699. * @protected
  700. */
  701. protected $listnum = 0;
  702. /**
  703. * HTML PARSER: indent amount for lists.
  704. * @protected
  705. */
  706. protected $listindent = 0;
  707. /**
  708. * HTML PARSER: current list indententation level.
  709. * @protected
  710. */
  711. protected $listindentlevel = 0;
  712. /**
  713. * Current background color.
  714. * @protected
  715. */
  716. protected $bgcolor;
  717. /**
  718. * Temporary font size in points.
  719. * @protected
  720. */
  721. protected $tempfontsize = 10;
  722. /**
  723. * Spacer string for LI tags.
  724. * @protected
  725. */
  726. protected $lispacer = '';
  727. /**
  728. * Default encoding.
  729. * @protected
  730. * @since 1.53.0.TC010
  731. */
  732. protected $encoding = 'UTF-8';
  733. /**
  734. * PHP internal encoding.
  735. * @protected
  736. * @since 1.53.0.TC016
  737. */
  738. protected $internal_encoding;
  739. /**
  740. * Boolean flag to indicate if the document language is Right-To-Left.
  741. * @protected
  742. * @since 2.0.000
  743. */
  744. protected $rtl = false;
  745. /**
  746. * Boolean flag used to force RTL or LTR string direction.
  747. * @protected
  748. * @since 2.0.000
  749. */
  750. protected $tmprtl = false;
  751. // --- Variables used for document encryption:
  752. /**
  753. * IBoolean flag indicating whether document is protected.
  754. * @protected
  755. * @since 2.0.000 (2008-01-02)
  756. */
  757. protected $encrypted;
  758. /**
  759. * Array containing encryption settings.
  760. * @protected
  761. * @since 5.0.005 (2010-05-11)
  762. */
  763. protected $encryptdata = array();
  764. /**
  765. * Last RC4 key encrypted (cached for optimisation).
  766. * @protected
  767. * @since 2.0.000 (2008-01-02)
  768. */
  769. protected $last_enc_key;
  770. /**
  771. * Last RC4 computed key.
  772. * @protected
  773. * @since 2.0.000 (2008-01-02)
  774. */
  775. protected $last_enc_key_c;
  776. /**
  777. * Encryption padding string.
  778. * @protected
  779. */
  780. protected $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  781. /**
  782. * File ID (used on document trailer).
  783. * @protected
  784. * @since 5.0.005 (2010-05-12)
  785. */
  786. protected $file_id;
  787. // --- bookmark ---
  788. /**
  789. * Outlines for bookmark.
  790. * @protected
  791. * @since 2.1.002 (2008-02-12)
  792. */
  793. protected $outlines = array();
  794. /**
  795. * Outline root for bookmark.
  796. * @protected
  797. * @since 2.1.002 (2008-02-12)
  798. */
  799. protected $OutlineRoot;
  800. // --- javascript and form ---
  801. /**
  802. * Javascript code.
  803. * @protected
  804. * @since 2.1.002 (2008-02-12)
  805. */
  806. protected $javascript = '';
  807. /**
  808. * Javascript counter.
  809. * @protected
  810. * @since 2.1.002 (2008-02-12)
  811. */
  812. protected $n_js;
  813. /**
  814. * line trough state
  815. * @protected
  816. * @since 2.8.000 (2008-03-19)
  817. */
  818. protected $linethrough;
  819. /**
  820. * Array with additional document-wide usage rights for the document.
  821. * @protected
  822. * @since 5.8.014 (2010-08-23)
  823. */
  824. protected $ur = array();
  825. /**
  826. * DPI (Dot Per Inch) Document Resolution (do not change).
  827. * @protected
  828. * @since 3.0.000 (2008-03-27)
  829. */
  830. protected $dpi = 72;
  831. /**
  832. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  833. * @protected
  834. * @since 3.0.000 (2008-03-27)
  835. */
  836. protected $newpagegroup = array();
  837. /**
  838. * Array that contains the number of pages in each page group.
  839. * @protected
  840. * @since 3.0.000 (2008-03-27)
  841. */
  842. protected $pagegroups = array();
  843. /**
  844. * Current page group number.
  845. * @protected
  846. * @since 3.0.000 (2008-03-27)
  847. */
  848. protected $currpagegroup = 0;
  849. /**
  850. * Array of transparency objects and parameters.
  851. * @protected
  852. * @since 3.0.000 (2008-03-27)
  853. */
  854. protected $extgstates;
  855. /**
  856. * Set the default JPEG compression quality (1-100).
  857. * @protected
  858. * @since 3.0.000 (2008-03-27)
  859. */
  860. protected $jpeg_quality;
  861. /**
  862. * Default cell height ratio.
  863. * @protected
  864. * @since 3.0.014 (2008-05-23)
  865. */
  866. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  867. /**
  868. * PDF viewer preferences.
  869. * @protected
  870. * @since 3.1.000 (2008-06-09)
  871. */
  872. protected $viewer_preferences;
  873. /**
  874. * A name object specifying how the document should be displayed when opened.
  875. * @protected
  876. * @since 3.1.000 (2008-06-09)
  877. */
  878. protected $PageMode;
  879. /**
  880. * Array for storing gradient information.
  881. * @protected
  882. * @since 3.1.000 (2008-06-09)
  883. */
  884. protected $gradients = array();
  885. /**
  886. * Array used to store positions inside the pages buffer (keys are the page numbers).
  887. * @protected
  888. * @since 3.2.000 (2008-06-26)
  889. */
  890. protected $intmrk = array();
  891. /**
  892. * Array used to store positions inside the pages buffer (keys are the page numbers).
  893. * @protected
  894. * @since 5.7.000 (2010-08-03)
  895. */
  896. protected $bordermrk = array();
  897. /**
  898. * Array used to store page positions to track empty pages (keys are the page numbers).
  899. * @protected
  900. * @since 5.8.007 (2010-08-18)
  901. */
  902. protected $emptypagemrk = array();
  903. /**
  904. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  905. * @protected
  906. * @since 4.6.021 (2009-07-20)
  907. */
  908. protected $cntmrk = array();
  909. /**
  910. * Array used to store footer positions of each page.
  911. * @protected
  912. * @since 3.2.000 (2008-07-01)
  913. */
  914. protected $footerpos = array();
  915. /**
  916. * Array used to store footer length of each page.
  917. * @protected
  918. * @since 4.0.014 (2008-07-29)
  919. */
  920. protected $footerlen = array();
  921. /**
  922. * Boolean flag to indicate if a new line is created.
  923. * @protected
  924. * @since 3.2.000 (2008-07-01)
  925. */
  926. protected $newline = true;
  927. /**
  928. * End position of the latest inserted line.
  929. * @protected
  930. * @since 3.2.000 (2008-07-01)
  931. */
  932. protected $endlinex = 0;
  933. /**
  934. * PDF string for width value of the last line.
  935. * @protected
  936. * @since 4.0.006 (2008-07-16)
  937. */
  938. protected $linestyleWidth = '';
  939. /**
  940. * PDF string for CAP value of the last line.
  941. * @protected
  942. * @since 4.0.006 (2008-07-16)
  943. */
  944. protected $linestyleCap = '0 J';
  945. /**
  946. * PDF string for join value of the last line.
  947. * @protected
  948. * @since 4.0.006 (2008-07-16)
  949. */
  950. protected $linestyleJoin = '0 j';
  951. /**
  952. * PDF string for dash value of the last line.
  953. * @protected
  954. * @since 4.0.006 (2008-07-16)
  955. */
  956. protected $linestyleDash = '[] 0 d';
  957. /**
  958. * Boolean flag to indicate if marked-content sequence is open.
  959. * @protected
  960. * @since 4.0.013 (2008-07-28)
  961. */
  962. protected $openMarkedContent = false;
  963. /**
  964. * Count the latest inserted vertical spaces on HTML.
  965. * @protected
  966. * @since 4.0.021 (2008-08-24)
  967. */
  968. protected $htmlvspace = 0;
  969. /**
  970. * Array of Spot colors.
  971. * @protected
  972. * @since 4.0.024 (2008-09-12)
  973. */
  974. protected $spot_colors = array();
  975. /**
  976. * Symbol used for HTML unordered list items.
  977. * @protected
  978. * @since 4.0.028 (2008-09-26)
  979. */
  980. protected $lisymbol = '';
  981. /**
  982. * String used to mark the beginning and end of EPS image blocks.
  983. * @protected
  984. * @since 4.1.000 (2008-10-18)
  985. */
  986. protected $epsmarker = 'x#!#EPS#!#x';
  987. /**
  988. * Array of transformation matrix.
  989. * @protected
  990. * @since 4.2.000 (2008-10-29)
  991. */
  992. protected $transfmatrix = array();
  993. /**
  994. * Current key for transformation matrix.
  995. * @protected
  996. * @since 4.8.005 (2009-09-17)
  997. */
  998. protected $transfmatrix_key = 0;
  999. /**
  1000. * Booklet mode for double-sided pages.
  1001. * @protected
  1002. * @since 4.2.000 (2008-10-29)
  1003. */
  1004. protected $booklet = false;
  1005. /**
  1006. * Epsilon value used for float calculations.
  1007. * @protected
  1008. * @since 4.2.000 (2008-10-29)
  1009. */
  1010. protected $feps = 0.005;
  1011. /**
  1012. * Array used for custom vertical spaces for HTML tags.
  1013. * @protected
  1014. * @since 4.2.001 (2008-10-30)
  1015. */
  1016. protected $tagvspaces = array();
  1017. /**
  1018. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  1019. * @protected
  1020. * @since 4.2.007 (2008-11-12)
  1021. */
  1022. protected $customlistindent = -1;
  1023. /**
  1024. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  1025. * @protected
  1026. * @since 4.2.010 (2008-11-14)
  1027. */
  1028. protected $opencell = true;
  1029. /**
  1030. * Array of files to embedd.
  1031. * @protected
  1032. * @since 4.4.000 (2008-12-07)
  1033. */
  1034. protected $embeddedfiles = array();
  1035. /**
  1036. * Boolean flag to indicate if we are inside a PRE tag.
  1037. * @protected
  1038. * @since 4.4.001 (2008-12-08)
  1039. */
  1040. protected $premode = false;
  1041. /**
  1042. * Array used to store positions of graphics transformation blocks inside the page buffer.
  1043. * keys are the page numbers
  1044. * @protected
  1045. * @since 4.4.002 (2008-12-09)
  1046. */
  1047. protected $transfmrk = array();
  1048. /**
  1049. * Default color for html links.
  1050. * @protected
  1051. * @since 4.4.003 (2008-12-09)
  1052. */
  1053. protected $htmlLinkColorArray = array(0, 0, 255);
  1054. /**
  1055. * Default font style to add to html links.
  1056. * @protected
  1057. * @since 4.4.003 (2008-12-09)
  1058. */
  1059. protected $htmlLinkFontStyle = 'U';
  1060. /**
  1061. * Counts the number of pages.
  1062. * @protected
  1063. * @since 4.5.000 (2008-12-31)
  1064. */
  1065. protected $numpages = 0;
  1066. /**
  1067. * Array containing page lengths in bytes.
  1068. * @protected
  1069. * @since 4.5.000 (2008-12-31)
  1070. */
  1071. protected $pagelen = array();
  1072. /**
  1073. * Counts the number of pages.
  1074. * @protected
  1075. * @since 4.5.000 (2008-12-31)
  1076. */
  1077. protected $numimages = 0;
  1078. /**
  1079. * Store the image keys.
  1080. * @protected
  1081. * @since 4.5.000 (2008-12-31)
  1082. */
  1083. protected $imagekeys = array();
  1084. /**
  1085. * Length of the buffer in bytes.
  1086. * @protected
  1087. * @since 4.5.000 (2008-12-31)
  1088. */
  1089. protected $bufferlen = 0;
  1090. /**
  1091. * If true enables disk caching.
  1092. * @protected
  1093. * @since 4.5.000 (2008-12-31)
  1094. */
  1095. protected $diskcache = false;
  1096. /**
  1097. * Counts the number of fonts.
  1098. * @protected
  1099. * @since 4.5.000 (2009-01-02)
  1100. */
  1101. protected $numfonts = 0;
  1102. /**
  1103. * Store the font keys.
  1104. * @protected
  1105. * @since 4.5.000 (2009-01-02)
  1106. */
  1107. protected $fontkeys = array();
  1108. /**
  1109. * Store the font object IDs.
  1110. * @protected
  1111. * @since 4.8.001 (2009-09-09)
  1112. */
  1113. protected $font_obj_ids = array();
  1114. /**
  1115. * Store the fage status (true when opened, false when closed).
  1116. * @protected
  1117. * @since 4.5.000 (2009-01-02)
  1118. */
  1119. protected $pageopen = array();
  1120. /**
  1121. * Default monospace font.
  1122. * @protected
  1123. * @since 4.5.025 (2009-03-10)
  1124. */
  1125. protected $default_monospaced_font = 'courier';
  1126. /**
  1127. * Cloned copy of the current class object.
  1128. * @protected
  1129. * @since 4.5.029 (2009-03-19)
  1130. */
  1131. protected $objcopy;
  1132. /**
  1133. * Array used to store the lengths of cache files.
  1134. * @protected
  1135. * @since 4.5.029 (2009-03-19)
  1136. */
  1137. protected $cache_file_length = array();
  1138. /**
  1139. * Table header content to be repeated on each new page.
  1140. * @protected
  1141. * @since 4.5.030 (2009-03-20)
  1142. */
  1143. protected $thead = '';
  1144. /**
  1145. * Margins used for table header.
  1146. * @protected
  1147. * @since 4.5.030 (2009-03-20)
  1148. */
  1149. protected $theadMargins = array();
  1150. /**
  1151. * Cache array for UTF8StringToArray() method.
  1152. * @protected
  1153. * @since 4.5.037 (2009-04-07)
  1154. */
  1155. protected $cache_UTF8StringToArray = array();
  1156. /**
  1157. * Maximum size of cache array used for UTF8StringToArray() method.
  1158. * @protected
  1159. * @since 4.5.037 (2009-04-07)
  1160. */
  1161. protected $cache_maxsize_UTF8StringToArray = 8;
  1162. /**
  1163. * Current size of cache array used for UTF8StringToArray() method.
  1164. * @protected
  1165. * @since 4.5.037 (2009-04-07)
  1166. */
  1167. protected $cache_size_UTF8StringToArray = 0;
  1168. /**
  1169. * Boolean flag to enable document digital signature.
  1170. * @protected
  1171. * @since 4.6.005 (2009-04-24)
  1172. */
  1173. protected $sign = false;
  1174. /**
  1175. * Digital signature data.
  1176. * @protected
  1177. * @since 4.6.005 (2009-04-24)
  1178. */
  1179. protected $signature_data = array();
  1180. /**
  1181. * Digital signature max length.
  1182. * @protected
  1183. * @since 4.6.005 (2009-04-24)
  1184. */
  1185. protected $signature_max_length = 11742;
  1186. /**
  1187. * Data for digital signature appearance.
  1188. * @protected
  1189. * @since 5.3.011 (2010-06-16)
  1190. */
  1191. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1192. /**
  1193. * Array of empty digital signature appearances.
  1194. * @protected
  1195. * @since 5.9.101 (2011-07-06)
  1196. */
  1197. protected $empty_signature_appearance = array();
  1198. /**
  1199. * Regular expression used to find blank characters (required for word-wrapping).
  1200. * @protected
  1201. * @since 4.6.006 (2009-04-28)
  1202. */
  1203. protected $re_spaces = '/[^\S\xa0]/';
  1204. /**
  1205. * Array of $re_spaces parts.
  1206. * @protected
  1207. * @since 5.5.011 (2010-07-09)
  1208. */
  1209. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1210. /**
  1211. * Digital signature object ID.
  1212. * @protected
  1213. * @since 4.6.022 (2009-06-23)
  1214. */
  1215. protected $sig_obj_id = 0;
  1216. /**
  1217. * ByteRange placemark used during digital signature process.
  1218. * @protected
  1219. * @since 4.6.028 (2009-08-25)
  1220. */
  1221. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1222. /**
  1223. * Placemark used during digital signature process.
  1224. * @protected
  1225. * @since 4.6.028 (2009-08-25)
  1226. */
  1227. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1228. /**
  1229. * ID of page objects.
  1230. * @protected
  1231. * @since 4.7.000 (2009-08-29)
  1232. */
  1233. protected $page_obj_id = array();
  1234. /**
  1235. * List of form annotations IDs.
  1236. * @protected
  1237. * @since 4.8.000 (2009-09-07)
  1238. */
  1239. protected $form_obj_id = array();
  1240. /**
  1241. * 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.
  1242. * @protected
  1243. * @since 4.8.000 (2009-09-07)
  1244. */
  1245. protected $default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 255), 'strokeColor' => array(128, 128, 128));
  1246. /**
  1247. * Javascript objects array.
  1248. * @protected
  1249. * @since 4.8.000 (2009-09-07)
  1250. */
  1251. protected $js_objects = array();
  1252. /**
  1253. * Current form action (used during XHTML rendering).
  1254. * @protected
  1255. * @since 4.8.000 (2009-09-07)
  1256. */
  1257. protected $form_action = '';
  1258. /**
  1259. * Current form encryption type (used during XHTML rendering).
  1260. * @protected
  1261. * @since 4.8.000 (2009-09-07)
  1262. */
  1263. protected $form_enctype = 'application/x-www-form-urlencoded';
  1264. /**
  1265. * Current method to submit forms.
  1266. * @protected
  1267. * @since 4.8.000 (2009-09-07)
  1268. */
  1269. protected $form_mode = 'post';
  1270. /**
  1271. * List of fonts used on form fields (fontname => fontkey).
  1272. * @protected
  1273. * @since 4.8.001 (2009-09-09)
  1274. */
  1275. protected $annotation_fonts = array();
  1276. /**
  1277. * List of radio buttons parent objects.
  1278. * @protected
  1279. * @since 4.8.001 (2009-09-09)
  1280. */
  1281. protected $radiobutton_groups = array();
  1282. /**
  1283. * List of radio group objects IDs.
  1284. * @protected
  1285. * @since 4.8.001 (2009-09-09)
  1286. */
  1287. protected $radio_groups = array();
  1288. /**
  1289. * Text indentation value (used for text-indent CSS attribute).
  1290. * @protected
  1291. * @since 4.8.006 (2009-09-23)
  1292. */
  1293. protected $textindent = 0;
  1294. /**
  1295. * Store page number when startTransaction() is called.
  1296. * @protected
  1297. * @since 4.8.006 (2009-09-23)
  1298. */
  1299. protected $start_transaction_page = 0;
  1300. /**
  1301. * Store Y position when startTransaction() is called.
  1302. * @protected
  1303. * @since 4.9.001 (2010-03-28)
  1304. */
  1305. protected $start_transaction_y = 0;
  1306. /**
  1307. * True when we are printing the thead section on a new page.
  1308. * @protected
  1309. * @since 4.8.027 (2010-01-25)
  1310. */
  1311. protected $inthead = false;
  1312. /**
  1313. * Array of column measures (width, space, starting Y position).
  1314. * @protected
  1315. * @since 4.9.001 (2010-03-28)
  1316. */
  1317. protected $columns = array();
  1318. /**
  1319. * Number of colums.
  1320. * @protected
  1321. * @since 4.9.001 (2010-03-28)
  1322. */
  1323. protected $num_columns = 1;
  1324. /**
  1325. * Current column number.
  1326. * @protected
  1327. * @since 4.9.001 (2010-03-28)
  1328. */
  1329. protected $current_column = 0;
  1330. /**
  1331. * Starting page for columns.
  1332. * @protected
  1333. * @since 4.9.001 (2010-03-28)
  1334. */
  1335. protected $column_start_page = 0;
  1336. /**
  1337. * Maximum page and column selected.
  1338. * @protected
  1339. * @since 5.8.000 (2010-08-11)
  1340. */
  1341. protected $maxselcol = array('page' => 0, 'column' => 0);
  1342. /**
  1343. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1344. * @protected
  1345. * @since 5.8.000 (2010-08-11)
  1346. */
  1347. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1348. /**
  1349. * Text rendering mode: 0 = Fill text; 1 = Stroke text; 2 = Fill, then stroke text; 3 = Neither fill nor stroke text (invisible); 4 = Fill text and add to path for clipping; 5 = Stroke text and add to path for clipping; 6 = Fill, then stroke text and add to path for clipping; 7 = Add text to path for clipping.
  1350. * @protected
  1351. * @since 4.9.008 (2010-04-03)
  1352. */
  1353. protected $textrendermode = 0;
  1354. /**
  1355. * Text stroke width in doc units.
  1356. * @protected
  1357. * @since 4.9.008 (2010-04-03)
  1358. */
  1359. protected $textstrokewidth = 0;
  1360. /**
  1361. * Current stroke color.
  1362. * @protected
  1363. * @since 4.9.008 (2010-04-03)
  1364. */
  1365. protected $strokecolor;
  1366. /**
  1367. * Default unit of measure for document.
  1368. * @protected
  1369. * @since 5.0.000 (2010-04-22)
  1370. */
  1371. protected $pdfunit = 'mm';
  1372. /**
  1373. * Boolean flag true when we are on TOC (Table Of Content) page.
  1374. * @protected
  1375. */
  1376. protected $tocpage = false;
  1377. /**
  1378. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1379. * @protected
  1380. * @since 5.0.000 (2010-04-26)
  1381. */
  1382. protected $rasterize_vector_images = false;
  1383. /**
  1384. * Boolean flag: if true enables font subsetting by default.
  1385. * @protected
  1386. * @since 5.3.002 (2010-06-07)
  1387. */
  1388. protected $font_subsetting = true;
  1389. /**
  1390. * Array of default graphic settings.
  1391. * @protected
  1392. * @since 5.5.008 (2010-07-02)
  1393. */
  1394. protected $default_graphic_vars = array();
  1395. /**
  1396. * Array of XObjects.
  1397. * @protected
  1398. * @since 5.8.014 (2010-08-23)
  1399. */
  1400. protected $xobjects = array();
  1401. /**
  1402. * Boolean value true when we are inside an XObject.
  1403. * @protected
  1404. * @since 5.8.017 (2010-08-24)
  1405. */
  1406. protected $inxobj = false;
  1407. /**
  1408. * Current XObject ID.
  1409. * @protected
  1410. * @since 5.8.017 (2010-08-24)
  1411. */
  1412. protected $xobjid = '';
  1413. /**
  1414. * Percentage of character stretching.
  1415. * @protected
  1416. * @since 5.9.000 (2010-09-29)
  1417. */
  1418. protected $font_stretching = 100;
  1419. /**
  1420. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1421. * @protected
  1422. * @since 5.9.000 (2010-09-29)
  1423. */
  1424. protected $font_spacing = 0;
  1425. /**
  1426. * Array of no-write regions.
  1427. * ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right)
  1428. * @protected
  1429. * @since 5.9.003 (2010-10-14)
  1430. */
  1431. protected $page_regions = array();
  1432. /**
  1433. * Boolean value true when page region check is active.
  1434. * @protected
  1435. */
  1436. protected $check_page_regions = true;
  1437. /**
  1438. * Array containing HTML color names and values.
  1439. * @protected
  1440. * @since 5.9.004 (2010-10-18)
  1441. */
  1442. protected $webcolor = array();
  1443. /**
  1444. * Array containing spot color names and values.
  1445. * @protected
  1446. * @since 5.9.012 (2010-11-11)
  1447. */
  1448. protected $spotcolor = array();
  1449. /**
  1450. * Array of PDF layers data.
  1451. * @protected
  1452. * @since 5.9.102 (2011-07-13)
  1453. */
  1454. protected $pdflayers = array();
  1455. /**
  1456. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1457. * @protected
  1458. * @since 5.9.097 (2011-06-23)
  1459. */
  1460. protected $dests = array();
  1461. /**
  1462. * Object ID for Named Destinations
  1463. * @protected
  1464. * @since 5.9.097 (2011-06-23)
  1465. */
  1466. protected $n_dests;
  1467. /**
  1468. * Directory used for the last SVG image.
  1469. * @protected
  1470. * @since 5.0.000 (2010-05-05)
  1471. */
  1472. protected $svgdir = '';
  1473. /**
  1474. * Deafult unit of measure for SVG.
  1475. * @protected
  1476. * @since 5.0.000 (2010-05-02)
  1477. */
  1478. protected $svgunit = 'px';
  1479. /**
  1480. * Array of SVG gradients.
  1481. * @protected
  1482. * @since 5.0.000 (2010-05-02)
  1483. */
  1484. protected $svggradients = array();
  1485. /**
  1486. * ID of last SVG gradient.
  1487. * @protected
  1488. * @since 5.0.000 (2010-05-02)
  1489. */
  1490. protected $svggradientid = 0;
  1491. /**
  1492. * Boolean value true when in SVG defs group.
  1493. * @protected
  1494. * @since 5.0.000 (2010-05-02)
  1495. */
  1496. protected $svgdefsmode = false;
  1497. /**
  1498. * Array of SVG defs.
  1499. * @protected
  1500. * @since 5.0.000 (2010-05-02)
  1501. */
  1502. protected $svgdefs = array();
  1503. /**
  1504. * Boolean value true when in SVG clipPath tag.
  1505. * @protected
  1506. * @since 5.0.000 (2010-04-26)
  1507. */
  1508. protected $svgclipmode = false;
  1509. /**
  1510. * Array of SVG clipPath commands.
  1511. * @protected
  1512. * @since 5.0.000 (2010-05-02)
  1513. */
  1514. protected $svgclippaths = array();
  1515. /**
  1516. * Array of SVG clipPath tranformation matrix.
  1517. * @protected
  1518. * @since 5.8.022 (2010-08-31)
  1519. */
  1520. protected $svgcliptm = array();
  1521. /**
  1522. * ID of last SVG clipPath.
  1523. * @protected
  1524. * @since 5.0.000 (2010-05-02)
  1525. */
  1526. protected $svgclipid = 0;
  1527. /**
  1528. * SVG text.
  1529. * @protected
  1530. * @since 5.0.000 (2010-05-02)
  1531. */
  1532. protected $svgtext = '';
  1533. /**
  1534. * SVG text properties.
  1535. * @protected
  1536. * @since 5.8.013 (2010-08-23)
  1537. */
  1538. protected $svgtextmode = array();
  1539. /**
  1540. * Array of hinheritable SVG properties.
  1541. * @protected
  1542. * @since 5.0.000 (2010-05-02)
  1543. */
  1544. protected $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode');
  1545. /**
  1546. * Array of SVG properties.
  1547. * @protected
  1548. * @since 5.0.000 (2010-05-02)
  1549. */
  1550. protected $svgstyles = array(array(
  1551. 'alignment-baseline' => 'auto',
  1552. 'baseline-shift' => 'baseline',
  1553. 'clip' => 'auto',
  1554. 'clip-path' => 'none',
  1555. 'clip-rule' => 'nonzero',
  1556. 'color' => 'black',
  1557. 'color-interpolation' => 'sRGB',
  1558. 'color-interpolation-filters' => 'linearRGB',
  1559. 'color-profile' => 'auto',
  1560. 'color-rendering' => 'auto',
  1561. 'cursor' => 'auto',
  1562. 'direction' => 'ltr',
  1563. 'display' => 'inline',
  1564. 'dominant-baseline' => 'auto',
  1565. 'enable-background' => 'accumulate',
  1566. 'fill' => 'black',
  1567. 'fill-opacity' => 1,
  1568. 'fill-rule' => 'nonzero',
  1569. 'filter' => 'none',
  1570. 'flood-color' => 'black',
  1571. 'flood-opacity' => 1,
  1572. 'font' => '',
  1573. 'font-family' => 'helvetica',
  1574. 'font-size' => 'medium',
  1575. 'font-size-adjust' => 'none',
  1576. 'font-stretch' => 'normal',
  1577. 'font-style' => 'normal',
  1578. 'font-variant' => 'normal',
  1579. 'font-weight' => 'normal',
  1580. 'glyph-orientation-horizontal' => '0deg',
  1581. 'glyph-orientation-vertical' => 'auto',
  1582. 'image-rendering' => 'auto',
  1583. 'kerning' => 'auto',
  1584. 'letter-spacing' => 'normal',
  1585. 'lighting-color' => 'white',
  1586. 'marker' => '',
  1587. 'marker-end' => 'none',
  1588. 'marker-mid' => 'none',
  1589. 'marker-start' => 'none',
  1590. 'mask' => 'none',
  1591. 'opacity' => 1,
  1592. 'overflow' => 'auto',
  1593. 'pointer-events' => 'visiblePainted',
  1594. 'shape-rendering' => 'auto',
  1595. 'stop-color' => 'black',
  1596. 'stop-opacity' => 1,
  1597. 'stroke' => 'none',
  1598. 'stroke-dasharray' => 'none',
  1599. 'stroke-dashoffset' => 0,
  1600. 'stroke-linecap' => 'butt',
  1601. 'stroke-linejoin' => 'miter',
  1602. 'stroke-miterlimit' => 4,
  1603. 'stroke-opacity' => 1,
  1604. 'stroke-width' => 1,
  1605. 'text-anchor' => 'start',
  1606. 'text-decoration' => 'none',
  1607. 'text-rendering' => 'auto',
  1608. 'unicode-bidi' => 'normal',
  1609. 'visibility' => 'visible',
  1610. 'word-spacing' => 'normal',
  1611. 'writing-mode' => 'lr-tb',
  1612. 'text-color' => 'black',
  1613. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1614. ));
  1615. /**
  1616. * If true force sRGB color profile for all document.
  1617. * @protected
  1618. * @since 5.9.121 (2011-09-28)
  1619. */
  1620. protected $force_srgb = false;
  1621. /**
  1622. * If true set the document to PDF/A mode.
  1623. * @protected
  1624. * @since 5.9.121 (2011-09-27)
  1625. */
  1626. protected $pdfa_mode = false;
  1627. /**
  1628. * Document creation date-time
  1629. * @protected
  1630. * @since 5.9.152 (2012-03-22)
  1631. */
  1632. protected $doc_creation_timestamp;
  1633. /**
  1634. * Document modification date-time
  1635. * @protected
  1636. * @since 5.9.152 (2012-03-22)
  1637. */
  1638. protected $doc_modification_timestamp;
  1639. /**
  1640. * Custom XMP data.
  1641. * @protected
  1642. * @since 5.9.128 (2011-10-06)
  1643. */
  1644. protected $custom_xmp = '';
  1645. /**
  1646. * Overprint mode array.
  1647. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1648. * @protected
  1649. * @since 5.9.152 (2012-03-23)
  1650. */
  1651. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1652. /**
  1653. * Alpha mode array.
  1654. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1655. * @protected
  1656. * @since 5.9.152 (2012-03-23)
  1657. */
  1658. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1659. /**
  1660. * Define the page boundaries boxes to be set on document.
  1661. * @protected
  1662. * @since 5.9.152 (2012-03-23)
  1663. */
  1664. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1665. /**
  1666. * Set the document producer metadata.
  1667. * @protected
  1668. * @since 5.9.152 (2012-03-23)
  1669. */
  1670. protected $pdfproducer;
  1671. /**
  1672. * If true print TCPDF meta link.
  1673. * @protected
  1674. * @since 5.9.152 (2012-03-23)
  1675. */
  1676. protected $tcpdflink = true;
  1677. /**
  1678. * Cache array for computed GD gamma values.
  1679. * @protected
  1680. * @since 5.9.1632 (2012-06-05)
  1681. */
  1682. protected $gdgammacache = array();
  1683. //------------------------------------------------------------
  1684. // METHODS
  1685. //------------------------------------------------------------
  1686. /**
  1687. * This is the class constructor.
  1688. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1689. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1690. * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1691. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  1692. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1693. * @param $encoding (string) Charset encoding; default is UTF-8.
  1694. * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1695. * @param $pdfa (boolean) If TRUE set the document to PDF/A mode.
  1696. * @public
  1697. * @see getPageSizeFromFormat(), setPageFormat()
  1698. */
  1699. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false) {
  1700. /* Set internal character encoding to ASCII */
  1701. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1702. $this->internal_encoding = mb_internal_encoding();
  1703. mb_internal_encoding('ASCII');
  1704. }
  1705. // get array of HTML colors
  1706. require(dirname(__FILE__) . '/htmlcolors.php');
  1707. $this->webcolor = $webcolor;
  1708. // get array of custom spot colors
  1709. if (file_exists(dirname(__FILE__) . '/spotcolors.php')) {
  1710. require(dirname(__FILE__) . '/spotcolors.php');
  1711. $this->spotcolor = $spotcolor;
  1712. } else {
  1713. $this->spotcolor = array();
  1714. }
  1715. require_once(dirname(__FILE__) . '/unicode_data.php');
  1716. $this->unicode = new TCPDF_UNICODE_DATA();
  1717. require_once(dirname(__FILE__) . '/encodings_maps.php');
  1718. $this->encmaps = new TCPDF_ENCODING_MAPS();
  1719. $this->font_obj_ids = array();
  1720. $this->page_obj_id = array();
  1721. $this->form_obj_id = array();
  1722. // set pdf/a mode
  1723. $this->pdfa_mode = $pdfa;
  1724. $this->force_srgb = false;
  1725. // set disk caching
  1726. $this->diskcache = $diskcache ? true : false;
  1727. // set language direction
  1728. $this->rtl = false;
  1729. $this->tmprtl = false;
  1730. // some checks
  1731. $this->_dochecks();
  1732. // initialization of properties
  1733. $this->isunicode = $unicode;
  1734. $this->page = 0;
  1735. $this->transfmrk[0] = array();
  1736. $this->pagedim = array();
  1737. $this->n = 2;
  1738. $this->buffer = '';
  1739. $this->pages = array();
  1740. $this->state = 0;
  1741. $this->fonts = array();
  1742. $this->FontFiles = array();
  1743. $this->diffs = array();
  1744. $this->images = array();
  1745. $this->links = array();
  1746. $this->gradients = array();
  1747. $this->InFooter = false;
  1748. $this->lasth = 0;
  1749. $this->FontFamily = defined('PDF_FONT_NAME_MAIN') ? PDF_FONT_NAME_MAIN : 'helvetica';
  1750. $this->FontStyle = '';
  1751. $this->FontSizePt = 12;
  1752. $this->underline = false;
  1753. $this->overline = false;
  1754. $this->linethrough = false;
  1755. $this->DrawColor = '0 G';
  1756. $this->FillColor = '0 g';
  1757. $this->TextColor = '0 g';
  1758. $this->ColorFlag = false;
  1759. $this->pdflayers = array();
  1760. // encryption values
  1761. $this->encrypted = false;
  1762. $this->last_enc_key = '';
  1763. // standard Unicode fonts
  1764. $this->CoreFonts = array(
  1765. 'courier' => 'Courier',
  1766. 'courierB' => 'Courier-Bold',
  1767. 'courierI' => 'Courier-Oblique',
  1768. 'courierBI' => 'Courier-BoldOblique',
  1769. 'helvetica' => 'Helvetica',
  1770. 'helveticaB' => 'Helvetica-Bold',
  1771. 'helveticaI' => 'Helvetica-Oblique',
  1772. 'helveticaBI' => 'Helvetica-BoldOblique',
  1773. 'times' => 'Times-Roman',
  1774. 'timesB' => 'Times-Bold',
  1775. 'timesI' => 'Times-Italic',
  1776. 'timesBI' => 'Times-BoldItalic',
  1777. 'symbol' => 'Symbol',
  1778. 'zapfdingbats' => 'ZapfDingbats'
  1779. );
  1780. // set scale factor
  1781. $this->setPageUnit($unit);
  1782. // set page format and orientation
  1783. $this->setPageFormat($format, $orientation);
  1784. // page margins (1 cm)
  1785. $margin = 28.35 / $this->k;
  1786. $this->SetMargins($margin, $margin);
  1787. $this->clMargin = $this->lMargin;
  1788. $this->crMargin = $this->rMargin;
  1789. // internal cell padding
  1790. $cpadding = $margin / 10;
  1791. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1792. // cell margins
  1793. $this->setCellMargins(0, 0, 0, 0);
  1794. // line width (0.2 mm)
  1795. $this->LineWidth = 0.57 / $this->k;
  1796. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1797. $this->linestyleCap = '0 J';
  1798. $this->linestyleJoin = '0 j';
  1799. $this->linestyleDash = '[] 0 d';
  1800. // automatic page break
  1801. $this->SetAutoPageBreak(true, (2 * $margin));
  1802. // full width display mode
  1803. $this->SetDisplayMode('fullwidth');
  1804. // compression
  1805. $this->SetCompression();
  1806. // set default PDF version number
  1807. $this->setPDFVersion();
  1808. $this->pdfproducer = "\x54\x43\x50\x44\x46\x20" . $this->tcpdf_version . "\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
  1809. $this->tcpdflink = true;
  1810. $this->encoding = $encoding;
  1811. $this->HREF = array();
  1812. $this->getFontsList();
  1813. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1814. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1815. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1816. $this->extgstates = array();
  1817. $this->setTextShadow();
  1818. // user's rights
  1819. $this->sign = false;
  1820. $this->ur['enabled'] = false;
  1821. $this->ur['document'] = '/FullSave';
  1822. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1823. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1824. $this->ur['signature'] = '/Modify';
  1825. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1826. $this->ur['formex'] = '';
  1827. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1828. $this->empty_signature_appearance = array();
  1829. // set default JPEG quality
  1830. $this->jpeg_quality = 75;
  1831. // initialize some settings
  1832. $this->utf8Bidi(array(''), '');
  1833. // set default font
  1834. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1835. // check if PCRE Unicode support is enabled
  1836. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1837. // PCRE unicode support is turned ON
  1838. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1839. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1840. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1841. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1842. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1843. } else {
  1844. // PCRE unicode support is turned OFF
  1845. $this->setSpacesRE('/[^\S\xa0]/');
  1846. }
  1847. $this->default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 255), 'strokeColor' => array(128, 128, 128));
  1848. // set file ID for trailer
  1849. $serformat = (is_array($format) ? serialize($format) : $format);
  1850. $this->file_id = md5($this->getRandomSeed('TCPDF' . $orientation . $unit . $serformat . $encoding));
  1851. // set document creation and modification timestamp
  1852. $this->doc_creation_timestamp = time();
  1853. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1854. // get default graphic vars
  1855. $this->default_graphic_vars = $this->getGraphicVars();
  1856. $this->header_xobj_autoreset = false;
  1857. $this->custom_xmp = '';
  1858. }
  1859. /**
  1860. * Default destructor.
  1861. * @public
  1862. * @since 1.53.0.TC016
  1863. */
  1864. public function __destruct() {
  1865. // restore internal encoding
  1866. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1867. mb_internal_encoding($this->internal_encoding);
  1868. }
  1869. // unset all class variables
  1870. $this->_destroy(true);
  1871. }
  1872. /**
  1873. * Return the current TCPDF version.
  1874. * @return TCPDF version string
  1875. * @public
  1876. * @since 5.9.012 (2010-11-10)
  1877. */
  1878. public function getTCPDFVersion() {
  1879. return $this->tcpdf_version;
  1880. }
  1881. /**
  1882. * Set the units of measure for the document.
  1883. * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1884. * @public
  1885. * @since 3.0.015 (2008-06-06)
  1886. */
  1887. public function setPageUnit($unit) {
  1888. $unit = strtolower($unit);
  1889. //Set scale factor
  1890. switch ($unit) {
  1891. // points
  1892. case 'px':
  1893. case 'pt': {
  1894. $this->k = 1;
  1895. break;
  1896. }
  1897. // millimeters
  1898. case 'mm': {
  1899. $this->k = $this->dpi / 25.4;
  1900. break;
  1901. }
  1902. // centimeters
  1903. case 'cm': {
  1904. $this->k = $this->dpi / 2.54;
  1905. break;
  1906. }
  1907. // inches
  1908. case 'in': {
  1909. $this->k = $this->dpi;
  1910. break;
  1911. }
  1912. // unsupported unit
  1913. default : {
  1914. $this->Error('Incorrect unit: ' . $unit);
  1915. break;
  1916. }
  1917. }
  1918. $this->pdfunit = $unit;
  1919. if (isset($this->CurOrientation)) {
  1920. $this->setPageOrientation($this->CurOrientation);
  1921. }
  1922. }
  1923. /**
  1924. * Get page dimensions from format name.
  1925. * @param $format (mixed) The format name. It can be: <ul>
  1926. * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
  1927. * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
  1928. * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
  1929. * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
  1930. * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
  1931. * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
  1932. * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
  1933. * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
  1934. * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
  1935. * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
  1936. * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
  1937. * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
  1938. * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
  1939. * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
  1940. * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
  1941. * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
  1942. * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
  1943. * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
  1944. * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
  1945. * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
  1946. * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
  1947. * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
  1948. * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
  1949. * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
  1950. * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
  1951. * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
  1952. * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
  1953. * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
  1954. * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
  1955. * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
  1956. * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
  1957. * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
  1958. * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
  1959. * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
  1960. * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
  1961. * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
  1962. * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
  1963. * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
  1964. * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
  1965. * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
  1966. * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
  1967. * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
  1968. * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
  1969. * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
  1970. * <li><b>SIS 014711 E Series</b></li>
  1971. * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
  1972. * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
  1973. * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
  1974. * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
  1975. * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
  1976. * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
  1977. * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
  1978. * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
  1979. * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
  1980. * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
  1981. * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
  1982. * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
  1983. * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
  1984. * <li><b>SIS 014711 G Series</b></li>
  1985. * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
  1986. * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
  1987. * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
  1988. * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
  1989. * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
  1990. * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
  1991. * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
  1992. * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
  1993. * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
  1994. * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
  1995. * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
  1996. * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
  1997. * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
  1998. * <li><b>ISO Press</b></li>
  1999. * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
  2000. * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
  2001. * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
  2002. * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
  2003. * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
  2004. * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
  2005. * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
  2006. * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
  2007. * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
  2008. * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
  2009. * <li><b>German DIN 476</b></li>
  2010. * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
  2011. * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
  2012. * <li><b>Variations on the ISO Standard</b></li>
  2013. * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
  2014. * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
  2015. * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
  2016. * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
  2017. * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
  2018. * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
  2019. * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
  2020. * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
  2021. * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
  2022. * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
  2023. * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
  2024. * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
  2025. * <li><b>ANSI Series</b></li>
  2026. * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
  2027. * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
  2028. * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
  2029. * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
  2030. * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
  2031. * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
  2032. * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
  2033. * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
  2034. * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
  2035. * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
  2036. * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
  2037. * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
  2038. * <li><b>Other North American Paper Sizes</b></li>
  2039. * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
  2040. * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
  2041. * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
  2042. * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
  2043. * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
  2044. * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
  2045. * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
  2046. * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
  2047. * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
  2048. * <li><b>Canadian standard CAN 2-9.60M</b></li>
  2049. * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
  2050. * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
  2051. * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
  2052. * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
  2053. * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
  2054. * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
  2055. * <li><b>North American Architectural Sizes</b></li>
  2056. * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
  2057. * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
  2058. * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
  2059. * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
  2060. * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
  2061. * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
  2062. * <li><b>Announcement Envelopes</b></li>
  2063. * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
  2064. * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
  2065. * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
  2066. * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
  2067. * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
  2068. * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
  2069. * <li><b>Commercial Envelopes</b></li>
  2070. * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
  2071. * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
  2072. * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
  2073. * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
  2074. * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
  2075. * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
  2076. * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
  2077. * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
  2078. * <li><b>Catalogue Envelopes</b></li>
  2079. * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
  2080. * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
  2081. * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
  2082. * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
  2083. * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
  2084. * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
  2085. * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
  2086. * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
  2087. * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
  2088. * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
  2089. * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
  2090. * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
  2091. * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
  2092. * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
  2093. * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
  2094. * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
  2095. * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
  2096. * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
  2097. * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
  2098. * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
  2099. * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
  2100. * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
  2101. * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
  2102. * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
  2103. * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
  2104. * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
  2105. * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
  2106. * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
  2107. * <li><b>PA Series</b></li>
  2108. * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
  2109. * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
  2110. * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
  2111. * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
  2112. * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
  2113. * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
  2114. * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
  2115. * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
  2116. * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
  2117. * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
  2118. * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
  2119. * <li><b>Standard Photographic Print Sizes</b></li>
  2120. * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
  2121. * <li>E (82x120 mm ; 3.25x4.72 in)</li>
  2122. * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
  2123. * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
  2124. * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
  2125. * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
  2126. * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
  2127. * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
  2128. * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
  2129. * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
  2130. * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
  2131. * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
  2132. * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
  2133. * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
  2134. * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
  2135. * <li><b>Common Newspaper Sizes</b></li>
  2136. * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
  2137. * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
  2138. * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
  2139. * <li><b>Business Cards</b></li>
  2140. * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
  2141. * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
  2142. * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
  2143. * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
  2144. * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
  2145. * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
  2146. * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
  2147. * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
  2148. * <li><b>Billboards</b></li>
  2149. * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
  2150. * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
  2151. * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
  2152. * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
  2153. * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
  2154. * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
  2155. * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
  2156. * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
  2157. * <li><b>Old Imperial English (some are still used in USA)</b></li>
  2158. * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
  2159. * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
  2160. * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
  2161. * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
  2162. * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
  2163. * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
  2164. * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
  2165. * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
  2166. * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
  2167. * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
  2168. * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
  2169. * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
  2170. * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
  2171. * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
  2172. * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
  2173. * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
  2174. * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
  2175. * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
  2176. * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
  2177. * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
  2178. * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
  2179. * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
  2180. * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
  2181. * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
  2182. * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
  2183. * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
  2184. * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
  2185. * <li><b>Old Imperial Belgian</b></li>
  2186. * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
  2187. * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
  2188. * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
  2189. * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
  2190. * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
  2191. * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
  2192. * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
  2193. * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  2194. * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
  2195. * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
  2196. * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
  2197. * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
  2198. * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
  2199. * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
  2200. * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
  2201. * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
  2202. * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
  2203. * <li><b>Old Imperial French</b></li>
  2204. * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
  2205. * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
  2206. * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
  2207. * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
  2208. * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
  2209. * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
  2210. * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
  2211. * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
  2212. * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
  2213. * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
  2214. * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
  2215. * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
  2216. * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
  2217. * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
  2218. * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
  2219. * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
  2220. * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  2221. * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
  2222. * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
  2223. * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
  2224. * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
  2225. * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
  2226. * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
  2227. * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
  2228. * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
  2229. * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
  2230. * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
  2231. * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
  2232. * </ul>
  2233. * @return array containing page width and height in points
  2234. * @public
  2235. * @since 5.0.010 (2010-05-17)
  2236. */
  2237. public function getPageSizeFromFormat($format) {
  2238. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
  2239. switch (strtoupper($format)) {
  2240. // ISO 216 A Series + 2 SIS 014711 extensions
  2241. case 'A0' : {
  2242. $pf = array(2383.937, 3370.394);
  2243. break;
  2244. }
  2245. case 'A1' : {
  2246. $pf = array(1683.780, 2383.937);
  2247. break;
  2248. }
  2249. case 'A2' : {
  2250. $pf = array(1190.551, 1683.780);
  2251. break;
  2252. }
  2253. case 'A3' : {
  2254. $pf = array(841.890, 1190.551);
  2255. break;
  2256. }
  2257. case 'A4' : {
  2258. $pf = array(595.276, 841.890);
  2259. break;
  2260. }
  2261. case 'A5' : {
  2262. $pf = array(419.528, 595.276);
  2263. break;
  2264. }
  2265. case 'A6' : {
  2266. $pf = array(297.638, 419.528);
  2267. break;
  2268. }
  2269. case 'A7' : {
  2270. $pf = array(209.764, 297.638);
  2271. break;
  2272. }
  2273. case 'A8' : {
  2274. $pf = array(147.402, 209.764);
  2275. break;
  2276. }
  2277. case 'A9' : {
  2278. $pf = array(104.882, 147.402);
  2279. break;
  2280. }
  2281. case 'A10': {
  2282. $pf = array(73.701, 104.882);
  2283. break;
  2284. }
  2285. case 'A11': {
  2286. $pf = array(51.024, 73.701);
  2287. break;
  2288. }
  2289. case 'A12': {
  2290. $pf = array(36.850, 51.024);
  2291. break;
  2292. }
  2293. // ISO 216 B Series + 2 SIS 014711 extensions
  2294. case 'B0' : {
  2295. $pf = array(2834.646, 4008.189);
  2296. break;
  2297. }
  2298. case 'B1' : {
  2299. $pf = array(2004.094, 2834.646);
  2300. break;
  2301. }
  2302. case 'B2' : {
  2303. $pf = array(1417.323, 2004.094);
  2304. break;
  2305. }
  2306. case 'B3' : {
  2307. $pf = array(1000.630, 1417.323);
  2308. break;
  2309. }
  2310. case 'B4' : {
  2311. $pf = array(708.661, 1000.630);
  2312. break;
  2313. }
  2314. case 'B5' : {
  2315. $pf = array(498.898, 708.661);
  2316. break;
  2317. }
  2318. case 'B6' : {
  2319. $pf = array(354.331, 498.898);
  2320. break;
  2321. }
  2322. case 'B7' : {
  2323. $pf = array(249.449, 354.331);
  2324. break;
  2325. }
  2326. case 'B8' : {
  2327. $pf = array(175.748, 249.449);
  2328. break;
  2329. }
  2330. case 'B9' : {
  2331. $pf = array(124.724, 175.748);
  2332. break;
  2333. }
  2334. case 'B10': {
  2335. $pf = array(87.874, 124.724);
  2336. break;
  2337. }
  2338. case 'B11': {
  2339. $pf = array(62.362, 87.874);
  2340. break;
  2341. }
  2342. case 'B12': {
  2343. $pf = array(42.520, 62.362);
  2344. break;
  2345. }
  2346. // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
  2347. case 'C0' : {
  2348. $pf = array(2599.370, 3676.535);
  2349. break;
  2350. }
  2351. case 'C1' : {
  2352. $pf = array(1836.850, 2599.370);
  2353. break;
  2354. }
  2355. case 'C2' : {
  2356. $pf = array(1298.268, 1836.850);
  2357. break;
  2358. }
  2359. case 'C3' : {
  2360. $pf = array(918.425, 1298.268);
  2361. break;
  2362. }
  2363. case 'C4' : {
  2364. $pf = array(649.134, 918.425);
  2365. break;
  2366. }
  2367. case 'C5' : {
  2368. $pf = array(459.213, 649.134);
  2369. break;
  2370. }
  2371. case 'C6' : {
  2372. $pf = array(323.150, 459.213);
  2373. break;
  2374. }
  2375. case 'C7' : {
  2376. $pf = array(229.606, 323.150);
  2377. break;
  2378. }
  2379. case 'C8' : {
  2380. $pf = array(161.575, 229.606);
  2381. break;
  2382. }
  2383. case 'C9' : {
  2384. $pf = array(113.386, 161.575);
  2385. break;
  2386. }
  2387. case 'C10': {
  2388. $pf = array(79.370, 113.386);
  2389. break;
  2390. }
  2391. case 'C11': {
  2392. $pf = array(56.693, 79.370);
  2393. break;
  2394. }
  2395. case 'C12': {
  2396. $pf = array(39.685, 56.693);
  2397. break;
  2398. }
  2399. case 'C76': {
  2400. $pf = array(229.606, 459.213);
  2401. break;
  2402. }
  2403. case 'DL' : {
  2404. $pf = array(311.811, 623.622);
  2405. break;
  2406. }
  2407. // SIS 014711 E Series
  2408. case 'E0' : {
  2409. $pf = array(2491.654, 3517.795);
  2410. break;
  2411. }
  2412. case 'E1' : {
  2413. $pf = array(1757.480, 2491.654);
  2414. break;
  2415. }
  2416. case 'E2' : {
  2417. $pf = array(1247.244, 1757.480);
  2418. break;
  2419. }
  2420. case 'E3' : {
  2421. $pf = array(878.740, 1247.244);
  2422. break;
  2423. }
  2424. case 'E4' : {
  2425. $pf = array(623.622, 878.740);
  2426. break;
  2427. }
  2428. case 'E5' : {
  2429. $pf = array(439.370, 623.622);
  2430. break;
  2431. }
  2432. case 'E6' : {
  2433. $pf = array(311.811, 439.370);
  2434. break;
  2435. }
  2436. case 'E7' : {
  2437. $pf = array(221.102, 311.811);
  2438. break;
  2439. }
  2440. case 'E8' : {
  2441. $pf = array(155.906, 221.102);
  2442. break;
  2443. }
  2444. case 'E9' : {
  2445. $pf = array(110.551, 155.906);
  2446. break;
  2447. }
  2448. case 'E10': {
  2449. $pf = array(76.535, 110.551);
  2450. break;
  2451. }
  2452. case 'E11': {
  2453. $pf = array(53.858, 76.535);
  2454. break;
  2455. }
  2456. case 'E12': {
  2457. $pf = array(36.850, 53.858);
  2458. break;
  2459. }
  2460. // SIS 014711 G Series
  2461. case 'G0' : {
  2462. $pf = array(2715.591, 3838.110);
  2463. break;
  2464. }
  2465. case 'G1' : {
  2466. $pf = array(1919.055, 2715.591);
  2467. break;
  2468. }
  2469. case 'G2' : {
  2470. $pf = array(1357.795, 1919.055);
  2471. break;
  2472. }
  2473. case 'G3' : {
  2474. $pf = array(958.110, 1357.795);
  2475. break;
  2476. }
  2477. case 'G4' : {
  2478. $pf = array(677.480, 958.110);
  2479. break;
  2480. }
  2481. case 'G5' : {
  2482. $pf = array(479.055, 677.480);
  2483. break;
  2484. }
  2485. case 'G6' : {
  2486. $pf = array(337.323, 479.055);
  2487. break;
  2488. }
  2489. case 'G7' : {
  2490. $pf = array(238.110, 337.323);
  2491. break;
  2492. }
  2493. case 'G8' : {
  2494. $pf = array(167.244, 238.110);
  2495. break;
  2496. }
  2497. case 'G9' : {
  2498. $pf = array(119.055, 167.244);
  2499. break;
  2500. }
  2501. case 'G10': {
  2502. $pf = array(82.205, 119.055);
  2503. break;
  2504. }
  2505. case 'G11': {
  2506. $pf = array(59.528, 82.205);
  2507. break;
  2508. }
  2509. case 'G12': {
  2510. $pf = array(39.685, 59.528);
  2511. break;
  2512. }
  2513. // ISO Press
  2514. case 'RA0': {
  2515. $pf = array(2437.795, 3458.268);
  2516. break;
  2517. }
  2518. case 'RA1': {
  2519. $pf = array(1729.134, 2437.795);
  2520. break;
  2521. }
  2522. case 'RA2': {
  2523. $pf = array(1218.898, 1729.134);
  2524. break;
  2525. }
  2526. case 'RA3': {
  2527. $pf = array(864.567, 1218.898);
  2528. break;
  2529. }
  2530. case 'RA4': {
  2531. $pf = array(609.449, 864.567);
  2532. break;
  2533. }
  2534. case 'SRA0': {
  2535. $pf = array(2551.181, 3628.346);
  2536. break;
  2537. }
  2538. case 'SRA1': {
  2539. $pf = array(1814.173, 2551.181);
  2540. break;
  2541. }
  2542. case 'SRA2': {
  2543. $pf = array(1275.591, 1814.173);
  2544. break;
  2545. }
  2546. case 'SRA3': {
  2547. $pf = array(907.087, 1275.591);
  2548. break;
  2549. }
  2550. case 'SRA4': {
  2551. $pf = array(637.795, 907.087);
  2552. break;
  2553. }
  2554. // German DIN 476
  2555. case '4A0': {
  2556. $pf = array(4767.874, 6740.787);
  2557. break;
  2558. }
  2559. case '2A0': {
  2560. $pf = array(3370.394, 4767.874);
  2561. break;
  2562. }
  2563. // Variations on the ISO Standard
  2564. case 'A2_EXTRA' : {
  2565. $pf = array(1261.417, 1754.646);
  2566. break;
  2567. }
  2568. case 'A3+' : {
  2569. $pf = array(932.598, 1369.134);
  2570. break;
  2571. }
  2572. case 'A3_EXTRA' : {
  2573. $pf = array(912.756, 1261.417);
  2574. break;
  2575. }
  2576. case 'A3_SUPER' : {
  2577. $pf = array(864.567, 1440.000);
  2578. break;
  2579. }
  2580. case 'SUPER_A3' : {
  2581. $pf = array(864.567, 1380.472);
  2582. break;
  2583. }
  2584. case 'A4_EXTRA' : {
  2585. $pf = array(666.142, 912.756);
  2586. break;
  2587. }
  2588. case 'A4_SUPER' : {
  2589. $pf = array(649.134, 912.756);
  2590. break;
  2591. }
  2592. case 'SUPER_A4' : {
  2593. $pf = array(643.465, 1009.134);
  2594. break;
  2595. }
  2596. case 'A4_LONG' : {
  2597. $pf = array(595.276, 986.457);
  2598. break;
  2599. }
  2600. case 'F4' : {
  2601. $pf = array(595.276, 935.433);
  2602. break;
  2603. }
  2604. case 'SO_B5_EXTRA': {
  2605. $pf = array(572.598, 782.362);
  2606. break;
  2607. }
  2608. case 'A5_EXTRA' : {
  2609. $pf = array(490.394, 666.142);
  2610. break;
  2611. }
  2612. // ANSI Series
  2613. case 'ANSI_E': {
  2614. $pf = array(2448.000, 3168.000);
  2615. break;
  2616. }
  2617. case 'ANSI_D': {
  2618. $pf = array(1584.000, 2448.000);
  2619. break;
  2620. }
  2621. case 'ANSI_C': {
  2622. $pf = array(1224.000, 1584.000);
  2623. break;
  2624. }
  2625. case 'ANSI_B': {
  2626. $pf = array(792.000, 1224.000);
  2627. break;
  2628. }
  2629. case 'ANSI_A': {
  2630. $pf = array(612.000, 792.000);
  2631. break;
  2632. }
  2633. // Traditional 'Loose' North American Paper Sizes
  2634. case 'USLEDGER':
  2635. case 'LEDGER' : {
  2636. $pf = array(1224.000, 792.000);
  2637. break;
  2638. }
  2639. case 'ORGANIZERK':
  2640. case 'BIBLE':
  2641. case 'USTABLOID':
  2642. case 'TABLOID': {
  2643. $pf = array(792.000, 1224.000);
  2644. break;
  2645. }
  2646. case 'ORGANIZERM':
  2647. case 'USLETTER':
  2648. case 'LETTER' : {
  2649. $pf = array(612.000, 792.000);
  2650. break;
  2651. }
  2652. case 'USLEGAL':
  2653. case 'LEGAL' : {
  2654. $pf = array(612.000, 1008.000);
  2655. break;
  2656. }
  2657. case 'GOVERNMENTLETTER':
  2658. case 'GLETTER': {
  2659. $pf = array(576.000, 756.000);
  2660. break;
  2661. }
  2662. case 'JUNIORLEGAL':
  2663. case 'JLEGAL' : {
  2664. $pf = array(576.000, 360.000);
  2665. break;
  2666. }
  2667. // Other North American Paper Sizes
  2668. case 'QUADDEMY': {
  2669. $pf = array(2520.000, 3240.000);
  2670. break;
  2671. }
  2672. case 'SUPER_B': {
  2673. $pf = array(936.000, 1368.000);
  2674. break;
  2675. }
  2676. case 'QUARTO': {
  2677. $pf = array(648.000, 792.000);
  2678. break;
  2679. }
  2680. case 'GOVERNMENTLEGAL':
  2681. case 'FOLIO': {
  2682. $pf = array(612.000, 936.000);
  2683. break;
  2684. }
  2685. case 'MONARCH':
  2686. case 'EXECUTIVE': {
  2687. $pf = array(522.000, 756.000);
  2688. break;
  2689. }
  2690. case 'ORGANIZERL':
  2691. case 'STATEMENT':
  2692. case 'MEMO': {
  2693. $pf = array(396.000, 612.000);
  2694. break;
  2695. }
  2696. case 'FOOLSCAP': {
  2697. $pf = array(595.440, 936.000);
  2698. break;
  2699. }
  2700. case 'COMPACT': {
  2701. $pf = array(306.000, 486.000);
  2702. break;
  2703. }
  2704. case 'ORGANIZERJ': {
  2705. $pf = array(198.000, 360.000);
  2706. break;
  2707. }
  2708. // Canadian standard CAN 2-9.60M
  2709. case 'P1': {
  2710. $pf = array(1587.402, 2437.795);
  2711. break;
  2712. }
  2713. case 'P2': {
  2714. $pf = array(1218.898, 1587.402);
  2715. break;
  2716. }
  2717. case 'P3': {
  2718. $pf = array(793.701, 1218.898);
  2719. break;
  2720. }
  2721. case 'P4': {
  2722. $pf = array(609.449, 793.701);
  2723. break;
  2724. }
  2725. case 'P5': {
  2726. $pf = array(396.850, 609.449);
  2727. break;
  2728. }
  2729. case 'P6': {
  2730. $pf = array(303.307, 396.850);
  2731. break;
  2732. }
  2733. // North American Architectural Sizes
  2734. case 'ARCH_E' : {
  2735. $pf = array(2592.000, 3456.000);
  2736. break;
  2737. }
  2738. case 'ARCH_E1': {
  2739. $pf = array(2160.000, 3024.000);
  2740. break;
  2741. }
  2742. case 'ARCH_D' : {
  2743. $pf = array(1728.000, 2592.000);
  2744. break;
  2745. }
  2746. case 'BROADSHEET':
  2747. case 'ARCH_C' : {
  2748. $pf = array(1296.000, 1728.000);
  2749. break;
  2750. }
  2751. case 'ARCH_B' : {
  2752. $pf = array(864.000, 1296.000);
  2753. break;
  2754. }
  2755. case 'ARCH_A' : {
  2756. $pf = array(648.000, 864.000);
  2757. break;
  2758. }
  2759. // --- North American Envelope Sizes ---
  2760. // - Announcement Envelopes
  2761. case 'ANNENV_A2' : {
  2762. $pf = array(314.640, 414.000);
  2763. break;
  2764. }
  2765. case 'ANNENV_A6' : {
  2766. $pf = array(342.000, 468.000);
  2767. break;
  2768. }
  2769. case 'ANNENV_A7' : {
  2770. $pf = array(378.000, 522.000);
  2771. break;
  2772. }
  2773. case 'ANNENV_A8' : {
  2774. $pf = array(396.000, 584.640);
  2775. break;
  2776. }
  2777. case 'ANNENV_A10' : {
  2778. $pf = array(450.000, 692.640);
  2779. break;
  2780. }
  2781. case 'ANNENV_SLIM': {
  2782. $pf = array(278.640, 638.640);
  2783. break;
  2784. }
  2785. // - Commercial Envelopes
  2786. case 'COMMENV_N6_1/4': {
  2787. $pf = array(252.000, 432.000);
  2788. break;
  2789. }
  2790. case 'COMMENV_N6_3/4': {
  2791. $pf = array(260.640, 468.000);
  2792. break;
  2793. }
  2794. case 'COMMENV_N8' : {
  2795. $pf = array(278.640, 540.000);
  2796. break;
  2797. }
  2798. case 'COMMENV_N9' : {
  2799. $pf = array(278.640, 638.640);
  2800. break;
  2801. }
  2802. case 'COMMENV_N10' : {
  2803. $pf = array(296.640, 684.000);
  2804. break;
  2805. }
  2806. case 'COMMENV_N11' : {
  2807. $pf = array(324.000, 746.640);
  2808. break;
  2809. }
  2810. case 'COMMENV_N12' : {
  2811. $pf = array(342.000, 792.000);
  2812. break;
  2813. }
  2814. case 'COMMENV_N14' : {
  2815. $pf = array(360.000, 828.000);
  2816. break;
  2817. }
  2818. // - Catalogue Envelopes
  2819. case 'CATENV_N1' : {
  2820. $pf = array(432.000, 648.000);
  2821. break;
  2822. }
  2823. case 'CATENV_N1_3/4' : {
  2824. $pf = array(468.000, 684.000);
  2825. break;
  2826. }
  2827. case 'CATENV_N2' : {
  2828. $pf = array(468.000, 720.000);
  2829. break;
  2830. }
  2831. case 'CATENV_N3' : {
  2832. $pf = array(504.000, 720.000);
  2833. break;
  2834. }
  2835. case 'CATENV_N6' : {
  2836. $pf = array(540.000, 756.000);
  2837. break;
  2838. }
  2839. case 'CATENV_N7' : {
  2840. $pf = array(576.000, 792.000);
  2841. break;
  2842. }
  2843. case 'CATENV_N8' : {
  2844. $pf = array(594.000, 810.000);
  2845. break;
  2846. }
  2847. case 'CATENV_N9_1/2' : {
  2848. $pf = array(612.000, 756.000);
  2849. break;
  2850. }
  2851. case 'CATENV_N9_3/4' : {
  2852. $pf = array(630.000, 810.000);
  2853. break;
  2854. }
  2855. case 'CATENV_N10_1/2': {
  2856. $pf = array(648.000, 864.000);
  2857. break;
  2858. }
  2859. case 'CATENV_N12_1/2': {
  2860. $pf = array(684.000, 900.000);
  2861. break;
  2862. }
  2863. case 'CATENV_N13_1/2': {
  2864. $pf = array(720.000, 936.000);
  2865. break;
  2866. }
  2867. case 'CATENV_N14_1/4': {
  2868. $pf = array(810.000, 882.000);
  2869. break;
  2870. }
  2871. case 'CATENV_N14_1/2': {
  2872. $pf = array(828.000, 1044.000);
  2873. break;
  2874. }
  2875. // Japanese (JIS P 0138-61) Standard B-Series
  2876. case 'JIS_B0' : {
  2877. $pf = array(2919.685, 4127.244);
  2878. break;
  2879. }
  2880. case 'JIS_B1' : {
  2881. $pf = array(2063.622, 2919.685);
  2882. break;
  2883. }
  2884. case 'JIS_B2' : {
  2885. $pf = array(1459.843, 2063.622);
  2886. break;
  2887. }
  2888. case 'JIS_B3' : {
  2889. $pf = array(1031.811, 1459.843);
  2890. break;
  2891. }
  2892. case 'JIS_B4' : {
  2893. $pf = array(728.504, 1031.811);
  2894. break;
  2895. }
  2896. case 'JIS_B5' : {
  2897. $pf = array(515.906, 728.504);
  2898. break;
  2899. }
  2900. case 'JIS_B6' : {
  2901. $pf = array(362.835, 515.906);
  2902. break;
  2903. }
  2904. case 'JIS_B7' : {
  2905. $pf = array(257.953, 362.835);
  2906. break;
  2907. }
  2908. case 'JIS_B8' : {
  2909. $pf = array(181.417, 257.953);
  2910. break;
  2911. }
  2912. case 'JIS_B9' : {
  2913. $pf = array(127.559, 181.417);
  2914. break;
  2915. }
  2916. case 'JIS_B10': {
  2917. $pf = array(90.709, 127.559);
  2918. break;
  2919. }
  2920. case 'JIS_B11': {
  2921. $pf = array(62.362, 90.709);
  2922. break;
  2923. }
  2924. case 'JIS_B12': {
  2925. $pf = array(45.354, 62.362);
  2926. break;
  2927. }
  2928. // PA Series
  2929. case 'PA0' : {
  2930. $pf = array(2381.102, 3174.803,);
  2931. break;
  2932. }
  2933. case 'PA1' : {
  2934. $pf = array(1587.402, 2381.102);
  2935. break;
  2936. }
  2937. case 'PA2' : {
  2938. $pf = array(1190.551, 1587.402);
  2939. break;
  2940. }
  2941. case 'PA3' : {
  2942. $pf = array(793.701, 1190.551);
  2943. break;
  2944. }
  2945. case 'PA4' : {
  2946. $pf = array(595.276, 793.701);
  2947. break;
  2948. }
  2949. case 'PA5' : {
  2950. $pf = array(396.850, 595.276);
  2951. break;
  2952. }
  2953. case 'PA6' : {
  2954. $pf = array(297.638, 396.850);
  2955. break;
  2956. }
  2957. case 'PA7' : {
  2958. $pf = array(198.425, 297.638);
  2959. break;
  2960. }
  2961. case 'PA8' : {
  2962. $pf = array(147.402, 198.425);
  2963. break;
  2964. }
  2965. case 'PA9' : {
  2966. $pf = array(99.213, 147.402);
  2967. break;
  2968. }
  2969. case 'PA10': {
  2970. $pf = array(73.701, 99.213);
  2971. break;
  2972. }
  2973. // Standard Photographic Print Sizes
  2974. case 'PASSPORT_PHOTO': {
  2975. $pf = array(99.213, 127.559);
  2976. break;
  2977. }
  2978. case 'E' : {
  2979. $pf = array(233.858, 340.157);
  2980. break;
  2981. }
  2982. case 'L':
  2983. case '3R' : {
  2984. $pf = array(252.283, 360.000);
  2985. break;
  2986. }
  2987. case 'KG':
  2988. case '4R' : {
  2989. $pf = array(289.134, 430.866);
  2990. break;
  2991. }
  2992. case '4D' : {
  2993. $pf = array(340.157, 430.866);
  2994. break;
  2995. }
  2996. case '2L':
  2997. case '5R' : {
  2998. $pf = array(360.000, 504.567);
  2999. break;
  3000. }
  3001. case '8P':
  3002. case '6R' : {
  3003. $pf = array(430.866, 575.433);
  3004. break;
  3005. }
  3006. case '6P':
  3007. case '8R' : {
  3008. $pf = array(575.433, 720.000);
  3009. break;
  3010. }
  3011. case '6PW':
  3012. case 'S8R' : {
  3013. $pf = array(575.433, 864.567);
  3014. break;
  3015. }
  3016. case '4P':
  3017. case '10R' : {
  3018. $pf = array(720.000, 864.567);
  3019. break;
  3020. }
  3021. case '4PW':
  3022. case 'S10R': {
  3023. $pf = array(720.000, 1080.000);
  3024. break;
  3025. }
  3026. case '11R' : {
  3027. $pf = array(790.866, 1009.134);
  3028. break;
  3029. }
  3030. case 'S11R': {
  3031. $pf = array(790.866, 1224.567);
  3032. break;
  3033. }
  3034. case '12R' : {
  3035. $pf = array(864.567, 1080.000);
  3036. break;
  3037. }
  3038. case 'S12R': {
  3039. $pf = array(864.567, 1292.598);
  3040. break;
  3041. }
  3042. // Common Newspaper Sizes
  3043. case 'NEWSPAPER_BROADSHEET': {
  3044. $pf = array(2125.984, 1700.787);
  3045. break;
  3046. }
  3047. case 'NEWSPAPER_BERLINER' : {
  3048. $pf = array(1332.283, 892.913);
  3049. break;
  3050. }
  3051. case 'NEWSPAPER_TABLOID':
  3052. case 'NEWSPAPER_COMPACT' : {
  3053. $pf = array(1218.898, 793.701);
  3054. break;
  3055. }
  3056. // Business Cards
  3057. case 'CREDIT_CARD':
  3058. case 'BUSINESS_CARD':
  3059. case 'BUSINESS_CARD_ISO7810': {
  3060. $pf = array(153.014, 242.646);
  3061. break;
  3062. }
  3063. case 'BUSINESS_CARD_ISO216' : {
  3064. $pf = array(147.402, 209.764);
  3065. break;
  3066. }
  3067. case 'BUSINESS_CARD_IT':
  3068. case 'BUSINESS_CARD_UK':
  3069. case 'BUSINESS_CARD_FR':
  3070. case 'BUSINESS_CARD_DE':
  3071. case 'BUSINESS_CARD_ES' : {
  3072. $pf = array(155.906, 240.945);
  3073. break;
  3074. }
  3075. case 'BUSINESS_CARD_CA':
  3076. case 'BUSINESS_CARD_US' : {
  3077. $pf = array(144.567, 252.283);
  3078. break;
  3079. }
  3080. case 'BUSINESS_CARD_JP' : {
  3081. $pf = array(155.906, 257.953);
  3082. break;
  3083. }
  3084. case 'BUSINESS_CARD_HK' : {
  3085. $pf = array(153.071, 255.118);
  3086. break;
  3087. }
  3088. case 'BUSINESS_CARD_AU':
  3089. case 'BUSINESS_CARD_DK':
  3090. case 'BUSINESS_CARD_SE' : {
  3091. $pf = array(155.906, 255.118);
  3092. break;
  3093. }
  3094. case 'BUSINESS_CARD_RU':
  3095. case 'BUSINESS_CARD_CZ':
  3096. case 'BUSINESS_CARD_FI':
  3097. case 'BUSINESS_CARD_HU':
  3098. case 'BUSINESS_CARD_IL' : {
  3099. $pf = array(141.732, 255.118);
  3100. break;
  3101. }
  3102. // Billboards
  3103. case '4SHEET' : {
  3104. $pf = array(2880.000, 4320.000);
  3105. break;
  3106. }
  3107. case '6SHEET' : {
  3108. $pf = array(3401.575, 5102.362);
  3109. break;
  3110. }
  3111. case '12SHEET': {
  3112. $pf = array(8640.000, 4320.000);
  3113. break;
  3114. }
  3115. case '16SHEET': {
  3116. $pf = array(5760.000, 8640.000);
  3117. break;
  3118. }
  3119. case '32SHEET': {
  3120. $pf = array(11520.000, 8640.000);
  3121. break;
  3122. }
  3123. case '48SHEET': {
  3124. $pf = array(17280.000, 8640.000);
  3125. break;
  3126. }
  3127. case '64SHEET': {
  3128. $pf = array(23040.000, 8640.000);
  3129. break;
  3130. }
  3131. case '96SHEET': {
  3132. $pf = array(34560.000, 8640.000);
  3133. break;
  3134. }
  3135. // Old European Sizes
  3136. // - Old Imperial English Sizes
  3137. case 'EN_EMPEROR' : {
  3138. $pf = array(3456.000, 5184.000);
  3139. break;
  3140. }
  3141. case 'EN_ANTIQUARIAN' : {
  3142. $pf = array(2232.000, 3816.000);
  3143. break;
  3144. }
  3145. case 'EN_GRAND_EAGLE' : {
  3146. $pf = array(2070.000, 3024.000);
  3147. break;
  3148. }
  3149. case 'EN_DOUBLE_ELEPHANT' : {
  3150. $pf = array(1926.000, 2880.000);
  3151. break;
  3152. }
  3153. case 'EN_ATLAS' : {
  3154. $pf = array(1872.000, 2448.000);
  3155. break;
  3156. }
  3157. case 'EN_COLOMBIER' : {
  3158. $pf = array(1692.000, 2484.000);
  3159. break;
  3160. }
  3161. case 'EN_ELEPHANT' : {
  3162. $pf = array(1656.000, 2016.000);
  3163. break;
  3164. }
  3165. case 'EN_DOUBLE_DEMY' : {
  3166. $pf = array(1620.000, 2556.000);
  3167. break;
  3168. }
  3169. case 'EN_IMPERIAL' : {
  3170. $pf = array(1584.000, 2160.000);
  3171. break;
  3172. }
  3173. case 'EN_PRINCESS' : {
  3174. $pf = array(1548.000, 2016.000);
  3175. break;
  3176. }
  3177. case 'EN_CARTRIDGE' : {
  3178. $pf = array(1512.000, 1872.000);
  3179. break;
  3180. }
  3181. case 'EN_DOUBLE_LARGE_POST': {
  3182. $pf = array(1512.000, 2376.000);
  3183. break;
  3184. }
  3185. case 'EN_ROYAL' : {
  3186. $pf = array(1440.000, 1800.000);
  3187. break;
  3188. }
  3189. case 'EN_SHEET':
  3190. case 'EN_HALF_POST' : {
  3191. $pf = array(1404.000, 1692.000);
  3192. break;
  3193. }
  3194. case 'EN_SUPER_ROYAL' : {
  3195. $pf = array(1368.000, 1944.000);
  3196. break;
  3197. }
  3198. case 'EN_DOUBLE_POST' : {
  3199. $pf = array(1368.000, 2196.000);
  3200. break;
  3201. }
  3202. case 'EN_MEDIUM' : {
  3203. $pf = array(1260.000, 1656.000);
  3204. break;
  3205. }
  3206. case 'EN_DEMY' : {
  3207. $pf = array(1260.000, 1620.000);
  3208. break;
  3209. }
  3210. case 'EN_LARGE_POST' : {
  3211. $pf = array(1188.000, 1512.000);
  3212. break;
  3213. }
  3214. case 'EN_COPY_DRAUGHT' : {
  3215. $pf = array(1152.000, 1440.000);
  3216. break;
  3217. }
  3218. case 'EN_POST' : {
  3219. $pf = array(1116.000, 1386.000);
  3220. break;
  3221. }
  3222. case 'EN_CROWN' : {
  3223. $pf = array(1080.000, 1440.000);
  3224. break;
  3225. }
  3226. case 'EN_PINCHED_POST' : {
  3227. $pf = array(1062.000, 1332.000);
  3228. break;
  3229. }
  3230. case 'EN_BRIEF' : {
  3231. $pf = array(972.000, 1152.000);
  3232. break;
  3233. }
  3234. case 'EN_FOOLSCAP' : {
  3235. $pf = array(972.000, 1224.000);
  3236. break;
  3237. }
  3238. case 'EN_SMALL_FOOLSCAP' : {
  3239. $pf = array(954.000, 1188.000);
  3240. break;
  3241. }
  3242. case 'EN_POTT' : {
  3243. $pf = array(900.000, 1080.000);
  3244. break;
  3245. }
  3246. // - Old Imperial Belgian Sizes
  3247. case 'BE_GRAND_AIGLE' : {
  3248. $pf = array(1984.252, 2948.031);
  3249. break;
  3250. }
  3251. case 'BE_COLOMBIER' : {
  3252. $pf = array(1757.480, 2409.449);
  3253. break;
  3254. }
  3255. case 'BE_DOUBLE_CARRE': {
  3256. $pf = array(1757.480, 2607.874);
  3257. break;
  3258. }
  3259. case 'BE_ELEPHANT' : {
  3260. $pf = array(1746.142, 2182.677);
  3261. break;
  3262. }
  3263. case 'BE_PETIT_AIGLE' : {
  3264. $pf = array(1700.787, 2381.102);
  3265. break;
  3266. }
  3267. case 'BE_GRAND_JESUS' : {
  3268. $pf = array(1559.055, 2069.291);
  3269. break;
  3270. }
  3271. case 'BE_JESUS' : {
  3272. $pf = array(1530.709, 2069.291);
  3273. break;
  3274. }
  3275. case 'BE_RAISIN' : {
  3276. $pf = array(1417.323, 1842.520);
  3277. break;
  3278. }
  3279. case 'BE_GRAND_MEDIAN': {
  3280. $pf = array(1303.937, 1714.961);
  3281. break;
  3282. }
  3283. case 'BE_DOUBLE_POSTE': {
  3284. $pf = array(1233.071, 1601.575);
  3285. break;
  3286. }
  3287. case 'BE_COQUILLE' : {
  3288. $pf = array(1218.898, 1587.402);
  3289. break;
  3290. }
  3291. case 'BE_PETIT_MEDIAN': {
  3292. $pf = array(1176.378, 1502.362);
  3293. break;
  3294. }
  3295. case 'BE_RUCHE' : {
  3296. $pf = array(1020.472, 1303.937);
  3297. break;
  3298. }
  3299. case 'BE_PROPATRIA' : {
  3300. $pf = array(977.953, 1218.898);
  3301. break;
  3302. }
  3303. case 'BE_LYS' : {
  3304. $pf = array(898.583, 1125.354);
  3305. break;
  3306. }
  3307. case 'BE_POT' : {
  3308. $pf = array(870.236, 1088.504);
  3309. break;
  3310. }
  3311. case 'BE_ROSETTE' : {
  3312. $pf = array(765.354, 983.622);
  3313. break;
  3314. }
  3315. // - Old Imperial French Sizes
  3316. case 'FR_UNIVERS' : {
  3317. $pf = array(2834.646, 3685.039);
  3318. break;
  3319. }
  3320. case 'FR_DOUBLE_COLOMBIER' : {
  3321. $pf = array(2551.181, 3571.654);
  3322. break;
  3323. }
  3324. case 'FR_GRANDE_MONDE' : {
  3325. $pf = array(2551.181, 3571.654);
  3326. break;
  3327. }
  3328. case 'FR_DOUBLE_SOLEIL' : {
  3329. $pf = array(2267.717, 3401.575);
  3330. break;
  3331. }
  3332. case 'FR_DOUBLE_JESUS' : {
  3333. $pf = array(2154.331, 3174.803);
  3334. break;
  3335. }
  3336. case 'FR_GRAND_AIGLE' : {
  3337. $pf = array(2125.984, 3004.724);
  3338. break;
  3339. }
  3340. case 'FR_PETIT_AIGLE' : {
  3341. $pf = array(1984.252, 2664.567);
  3342. break;
  3343. }
  3344. case 'FR_DOUBLE_RAISIN' : {
  3345. $pf = array(1842.520, 2834.646);
  3346. break;
  3347. }
  3348. case 'FR_JOURNAL' : {
  3349. $pf = array(1842.520, 2664.567);
  3350. break;
  3351. }
  3352. case 'FR_COLOMBIER_AFFICHE': {
  3353. $pf = array(1785.827, 2551.181);
  3354. break;
  3355. }
  3356. case 'FR_DOUBLE_CAVALIER' : {
  3357. $pf = array(1757.480, 2607.874);
  3358. break;
  3359. }
  3360. case 'FR_CLOCHE' : {
  3361. $pf = array(1700.787, 2267.717);
  3362. break;
  3363. }
  3364. case 'FR_SOLEIL' : {
  3365. $pf = array(1700.787, 2267.717);
  3366. break;
  3367. }
  3368. case 'FR_DOUBLE_CARRE' : {
  3369. $pf = array(1587.402, 2551.181);
  3370. break;
  3371. }
  3372. case 'FR_DOUBLE_COQUILLE' : {
  3373. $pf = array(1587.402, 2494.488);
  3374. break;
  3375. }
  3376. case 'FR_JESUS' : {
  3377. $pf = array(1587.402, 2154.331);
  3378. break;
  3379. }
  3380. case 'FR_RAISIN' : {
  3381. $pf = array(1417.323, 1842.520);
  3382. break;
  3383. }
  3384. case 'FR_CAVALIER' : {
  3385. $pf = array(1303.937, 1757.480);
  3386. break;
  3387. }
  3388. case 'FR_DOUBLE_COURONNE' : {
  3389. $pf = array(1303.937, 2040.945);
  3390. break;
  3391. }
  3392. case 'FR_CARRE' : {
  3393. $pf = array(1275.591, 1587.402);
  3394. break;
  3395. }
  3396. case 'FR_COQUILLE' : {
  3397. $pf = array(1247.244, 1587.402);
  3398. break;
  3399. }
  3400. case 'FR_DOUBLE_TELLIERE' : {
  3401. $pf = array(1247.244, 1927.559);
  3402. break;
  3403. }
  3404. case 'FR_DOUBLE_CLOCHE' : {
  3405. $pf = array(1133.858, 1700.787);
  3406. break;
  3407. }
  3408. case 'FR_DOUBLE_POT' : {
  3409. $pf = array(1133.858, 1757.480);
  3410. break;
  3411. }
  3412. case 'FR_ECU' : {
  3413. $pf = array(1133.858, 1474.016);
  3414. break;
  3415. }
  3416. case 'FR_COURONNE' : {
  3417. $pf = array(1020.472, 1303.937);
  3418. break;
  3419. }
  3420. case 'FR_TELLIERE' : {
  3421. $pf = array(963.780, 1247.244);
  3422. break;
  3423. }
  3424. case 'FR_POT' : {
  3425. $pf = array(878.740, 1133.858);
  3426. break;
  3427. }
  3428. // DEFAULT ISO A4
  3429. default: {
  3430. $pf = array(595.276, 841.890);
  3431. break;
  3432. }
  3433. }
  3434. return $pf;
  3435. }
  3436. /**
  3437. * Change the format of the current page
  3438. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numners (width, height) or an array containing the following measures and options:<ul>
  3439. * <li>['format'] = page format name (one of the above);</li>
  3440. * <li>['Rotate'] : The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li>
  3441. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  3442. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  3443. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  3444. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  3445. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  3446. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  3447. * <li>['CropBox'] : the visible region of default user space:</li>
  3448. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  3449. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  3450. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  3451. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  3452. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  3453. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  3454. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  3455. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  3456. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  3457. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  3458. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  3459. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  3460. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  3461. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  3462. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  3463. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  3464. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  3465. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  3466. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  3467. * <li>['BoxColorInfo'] :specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for each of the possible page boundaries other than the MediaBox:</li>
  3468. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  3469. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  3470. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  3471. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  3472. * <li>['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation</li>
  3473. * <li>['trans']['Dur'] : The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li>
  3474. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  3475. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  3476. * <li>['trans']['Dm'] : (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li>
  3477. * <li>['trans']['M'] : (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li>
  3478. * <li>['trans']['Di'] : (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li>
  3479. * <li>['trans']['SS'] : (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0.</li>
  3480. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  3481. * </ul>
  3482. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  3483. * <li>P or Portrait (default)</li>
  3484. * <li>L or Landscape</li>
  3485. * <li>'' (empty string) for automatic orientation</li>
  3486. * </ul>
  3487. * @protected
  3488. * @since 3.0.015 (2008-06-06)
  3489. * @see getPageSizeFromFormat()
  3490. */
  3491. protected function setPageFormat($format, $orientation = 'P') {
  3492. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  3493. // remove inherited values
  3494. unset($this->pagedim[$this->page]);
  3495. }
  3496. if (is_string($format)) {
  3497. // get page measures from format name
  3498. $pf = $this->getPageSizeFromFormat($format);
  3499. $this->fwPt = $pf[0];
  3500. $this->fhPt = $pf[1];
  3501. } else {
  3502. // the boundaries of the physical medium on which the page shall be displayed or printed
  3503. if (isset($format['MediaBox'])) {
  3504. $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
  3505. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  3506. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  3507. } else {
  3508. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  3509. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  3510. } else {
  3511. if (!isset($format['format'])) {
  3512. // default value
  3513. $format['format'] = 'A4';
  3514. }
  3515. $pf = $this->getPageSizeFromFormat($format['format']);
  3516. }
  3517. $this->fwPt = $pf[0];
  3518. $this->fhPt = $pf[1];
  3519. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  3520. }
  3521. // the visible region of default user space
  3522. if (isset($format['CropBox'])) {
  3523. $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
  3524. }
  3525. // the region to which the contents of the page shall be clipped when output in a production environment
  3526. if (isset($format['BleedBox'])) {
  3527. $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
  3528. }
  3529. // the intended dimensions of the finished page after trimming
  3530. if (isset($format['TrimBox'])) {
  3531. $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
  3532. }
  3533. // the page's meaningful content (including potential white space)
  3534. if (isset($format['ArtBox'])) {
  3535. $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
  3536. }
  3537. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  3538. if (isset($format['BoxColorInfo'])) {
  3539. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  3540. }
  3541. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  3542. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  3543. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  3544. }
  3545. if (isset($format['PZ'])) {
  3546. // The page's preferred zoom (magnification) factor
  3547. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  3548. }
  3549. if (isset($format['trans'])) {
  3550. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  3551. if (isset($format['trans']['Dur'])) {
  3552. // The page's display duration
  3553. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  3554. }
  3555. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  3556. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  3557. // The transition style that shall be used when moving to this page from another during a presentation
  3558. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  3559. $valid_effect = array('Split', 'Blinds');
  3560. $valid_vals = array('H', 'V');
  3561. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  3562. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  3563. }
  3564. $valid_effect = array('Split', 'Box', 'Fly');
  3565. $valid_vals = array('I', 'O');
  3566. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  3567. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  3568. }
  3569. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  3570. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  3571. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  3572. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  3573. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  3574. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  3575. }
  3576. }
  3577. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  3578. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  3579. }
  3580. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  3581. $this->pagedim[$this->page]['trans']['B'] = 'true';
  3582. }
  3583. } else {
  3584. $this->pagedim[$this->page]['trans']['S'] = 'R';
  3585. }
  3586. if (isset($format['trans']['D'])) {
  3587. // The duration of the transition effect, in seconds
  3588. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  3589. } else {
  3590. $this->pagedim[$this->page]['trans']['D'] = 1;
  3591. }
  3592. }
  3593. }
  3594. $this->setPageOrientation($orientation);
  3595. }
  3596. /**
  3597. * Set page boundaries.
  3598. * @param $page (int) page number
  3599. * @param $type (string) valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
  3600. * @param $llx (float) lower-left x coordinate in user units
  3601. * @param $lly (float) lower-left y coordinate in user units
  3602. * @param $urx (float) upper-right x coordinate in user units
  3603. * @param $ury (float) upper-right y coordinate in user units
  3604. * @param $points (boolean) if true uses user units as unit of measure, otherwise uses PDF points
  3605. * @public
  3606. * @since 5.0.010 (2010-05-17)
  3607. */
  3608. public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points = false) {
  3609. if (!isset($this->pagedim[$page])) {
  3610. // initialize array
  3611. $this->pagedim[$page] = array();
  3612. }
  3613. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  3614. if (!in_array($type, $pageboxes)) {
  3615. return;
  3616. }
  3617. if ($points) {
  3618. $k = 1;
  3619. } else {
  3620. $k = $this->k;
  3621. }
  3622. $this->pagedim[$page][$type]['llx'] = ($llx * $k);
  3623. $this->pagedim[$page][$type]['lly'] = ($lly * $k);
  3624. $this->pagedim[$page][$type]['urx'] = ($urx * $k);
  3625. $this->pagedim[$page][$type]['ury'] = ($ury * $k);
  3626. }
  3627. /**
  3628. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  3629. * @param $page (int) page number
  3630. * @protected
  3631. * @since 5.0.010 (2010-05-17)
  3632. */
  3633. protected function swapPageBoxCoordinates($page) {
  3634. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  3635. foreach ($pageboxes as $type) {
  3636. // swap X and Y coordinates
  3637. if (isset($this->pagedim[$page][$type])) {
  3638. $tmp = $this->pagedim[$page][$type]['llx'];
  3639. $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly'];
  3640. $this->pagedim[$page][$type]['lly'] = $tmp;
  3641. $tmp = $this->pagedim[$page][$type]['urx'];
  3642. $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury'];
  3643. $this->pagedim[$page][$type]['ury'] = $tmp;
  3644. }
  3645. }
  3646. }
  3647. /**
  3648. * Set page orientation.
  3649. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  3650. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  3651. * @param $bottommargin (float) bottom margin of the page.
  3652. * @public
  3653. * @since 3.0.015 (2008-06-06)
  3654. */
  3655. public function setPageOrientation($orientation, $autopagebreak = '', $bottommargin = '') {
  3656. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  3657. // the boundaries of the physical medium on which the page shall be displayed or printed
  3658. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  3659. }
  3660. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  3661. // the visible region of default user space
  3662. $this->setPageBoxes($this->page, 'CropBox', $this->pagedim[$this->page]['MediaBox']['llx'], $this->pagedim[$this->page]['MediaBox']['lly'], $this->pagedim[$this->page]['MediaBox']['urx'], $this->pagedim[$this->page]['MediaBox']['ury'], true);
  3663. }
  3664. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  3665. // the region to which the contents of the page shall be clipped when output in a production environment
  3666. $this->setPageBoxes($this->page, 'BleedBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
  3667. }
  3668. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  3669. // the intended dimensions of the finished page after trimming
  3670. $this->setPageBoxes($this->page, 'TrimBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
  3671. }
  3672. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  3673. // the page's meaningful content (including potential white space)
  3674. $this->setPageBoxes($this->page, 'ArtBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
  3675. }
  3676. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  3677. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  3678. $this->pagedim[$this->page]['Rotate'] = 0;
  3679. }
  3680. if (!isset($this->pagedim[$this->page]['PZ'])) {
  3681. // The page's preferred zoom (magnification) factor
  3682. $this->pagedim[$this->page]['PZ'] = 1;
  3683. }
  3684. if ($this->fwPt > $this->fhPt) {
  3685. // landscape
  3686. $default_orientation = 'L';
  3687. } else {
  3688. // portrait
  3689. $default_orientation = 'P';
  3690. }
  3691. $valid_orientations = array('P', 'L');
  3692. if (empty($orientation)) {
  3693. $orientation = $default_orientation;
  3694. } else {
  3695. $orientation = strtoupper($orientation{0});
  3696. }
  3697. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  3698. $this->CurOrientation = $orientation;
  3699. $this->wPt = $this->fhPt;
  3700. $this->hPt = $this->fwPt;
  3701. } else {
  3702. $this->CurOrientation = $default_orientation;
  3703. $this->wPt = $this->fwPt;
  3704. $this->hPt = $this->fhPt;
  3705. }
  3706. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)) {
  3707. // swap X and Y coordinates (change page orientation)
  3708. $this->swapPageBoxCoordinates($this->page);
  3709. }
  3710. $this->w = ($this->wPt / $this->k);
  3711. $this->h = ($this->hPt / $this->k);
  3712. if ($this->empty_string($autopagebreak)) {
  3713. if (isset($this->AutoPageBreak)) {
  3714. $autopagebreak = $this->AutoPageBreak;
  3715. } else {
  3716. $autopagebreak = true;
  3717. }
  3718. }
  3719. if ($this->empty_string($bottommargin)) {
  3720. if (isset($this->bMargin)) {
  3721. $bottommargin = $this->bMargin;
  3722. } else {
  3723. // default value = 2 cm
  3724. $bottommargin = 2 * 28.35 / $this->k;
  3725. }
  3726. }
  3727. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  3728. // store page dimensions
  3729. $this->pagedim[$this->page]['w'] = $this->wPt;
  3730. $this->pagedim[$this->page]['h'] = $this->hPt;
  3731. $this->pagedim[$this->page]['wk'] = $this->w;
  3732. $this->pagedim[$this->page]['hk'] = $this->h;
  3733. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3734. $this->pagedim[$this->page]['bm'] = $bottommargin;
  3735. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  3736. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  3737. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  3738. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  3739. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  3740. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  3741. }
  3742. /**
  3743. * Set regular expression to detect withespaces or word separators.
  3744. * The pattern delimiter must be the forward-slash character "/".
  3745. * Some example patterns are:
  3746. * <pre>
  3747. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  3748. * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
  3749. * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
  3750. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  3751. * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
  3752. * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  3753. * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
  3754. * </pre>
  3755. * @param $re (string) regular expression (leave empty for default).
  3756. * @public
  3757. * @since 4.6.016 (2009-06-15)
  3758. */
  3759. public function setSpacesRE($re = '/[^\S\xa0]/') {
  3760. $this->re_spaces = $re;
  3761. $re_parts = explode('/', $re);
  3762. // get pattern parts
  3763. $this->re_space = array();
  3764. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  3765. $this->re_space['p'] = $re_parts[1];
  3766. } else {
  3767. $this->re_space['p'] = '[\s]';
  3768. }
  3769. // set pattern modifiers
  3770. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  3771. $this->re_space['m'] = $re_parts[2];
  3772. } else {
  3773. $this->re_space['m'] = '';
  3774. }
  3775. }
  3776. /**
  3777. * Enable or disable Right-To-Left language mode
  3778. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  3779. * @param $resetx (Boolean) if true reset the X position on direction change.
  3780. * @public
  3781. * @since 2.0.000 (2008-01-03)
  3782. */
  3783. public function setRTL($enable, $resetx = true) {
  3784. $enable = $enable ? true : false;
  3785. $resetx = ($resetx AND ($enable != $this->rtl));
  3786. $this->rtl = $enable;
  3787. $this->tmprtl = false;
  3788. if ($resetx) {
  3789. $this->Ln(0);
  3790. }
  3791. }
  3792. /**
  3793. * Return the RTL status
  3794. * @return boolean
  3795. * @public
  3796. * @since 4.0.012 (2008-07-24)
  3797. */
  3798. public function getRTL() {
  3799. return $this->rtl;
  3800. }
  3801. /**
  3802. * Force temporary RTL language direction
  3803. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  3804. * @public
  3805. * @since 2.1.000 (2008-01-09)
  3806. */
  3807. public function setTempRTL($mode) {
  3808. $newmode = false;
  3809. switch (strtoupper($mode)) {
  3810. case 'LTR':
  3811. case 'L': {
  3812. if ($this->rtl) {
  3813. $newmode = 'L';
  3814. }
  3815. break;
  3816. }
  3817. case 'RTL':
  3818. case 'R': {
  3819. if (!$this->rtl) {
  3820. $newmode = 'R';
  3821. }
  3822. break;
  3823. }
  3824. case false:
  3825. default: {
  3826. $newmode = false;
  3827. break;
  3828. }
  3829. }
  3830. $this->tmprtl = $newmode;
  3831. }
  3832. /**
  3833. * Return the current temporary RTL status
  3834. * @return boolean
  3835. * @public
  3836. * @since 4.8.014 (2009-11-04)
  3837. */
  3838. public function isRTLTextDir() {
  3839. return ($this->rtl OR ($this->tmprtl == 'R'));
  3840. }
  3841. /**
  3842. * Set the last cell height.
  3843. * @param $h (float) cell height.
  3844. * @author Nicola Asuni
  3845. * @public
  3846. * @since 1.53.0.TC034
  3847. */
  3848. public function setLastH($h) {
  3849. $this->lasth = $h;
  3850. }
  3851. /**
  3852. * Reset the last cell height.
  3853. * @public
  3854. * @since 5.9.000 (2010-10-03)
  3855. */
  3856. public function resetLastH() {
  3857. $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  3858. }
  3859. /**
  3860. * Get the last cell height.
  3861. * @return last cell height
  3862. * @public
  3863. * @since 4.0.017 (2008-08-05)
  3864. */
  3865. public function getLastH() {
  3866. return $this->lasth;
  3867. }
  3868. /**
  3869. * Set the adjusting factor to convert pixels to user units.
  3870. * @param $scale (float) adjusting factor to convert pixels to user units.
  3871. * @author Nicola Asuni
  3872. * @public
  3873. * @since 1.5.2
  3874. */
  3875. public function setImageScale($scale) {
  3876. $this->imgscale = $scale;
  3877. }
  3878. /**
  3879. * Returns the adjusting factor to convert pixels to user units.
  3880. * @return float adjusting factor to convert pixels to user units.
  3881. * @author Nicola Asuni
  3882. * @public
  3883. * @since 1.5.2
  3884. */
  3885. public function getImageScale() {
  3886. return $this->imgscale;
  3887. }
  3888. /**
  3889. * Returns an array of page dimensions:
  3890. * <ul><li>$this->pagedim[$this->page]['w'] = page width in points</li><li>$this->pagedim[$this->page]['h'] = height in points</li><li>$this->pagedim[$this->page]['wk'] = page width in user units</li><li>$this->pagedim[$this->page]['hk'] = page height in user units</li><li>$this->pagedim[$this->page]['tm'] = top margin</li><li>$this->pagedim[$this->page]['bm'] = bottom margin</li><li>$this->pagedim[$this->page]['lm'] = left margin</li><li>$this->pagedim[$this->page]['rm'] = right margin</li><li>$this->pagedim[$this->page]['pb'] = auto page break</li><li>$this->pagedim[$this->page]['or'] = page orientation</li><li>$this->pagedim[$this->page]['olm'] = original left margin</li><li>$this->pagedim[$this->page]['orm'] = original right margin</li><li>$this->pagedim[$this->page]['Rotate'] = The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li><li>$this->pagedim[$this->page]['PZ'] = The page's preferred zoom (magnification) factor.</li><li>$this->pagedim[$this->page]['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation<ul><li>$this->pagedim[$this->page]['trans']['Dur'] = The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li><li>$this->pagedim[$this->page]['trans']['S'] = transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li><li>$this->pagedim[$this->page]['trans']['D'] = The duration of the transition effect, in seconds.</li><li>$this->pagedim[$this->page]['trans']['Dm'] = (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li><li>$this->pagedim[$this->page]['trans']['M'] = (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li><li>$this->pagedim[$this->page]['trans']['Di'] = (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li><li>$this->pagedim[$this->page]['trans']['SS'] = (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0. </li><li>$this->pagedim[$this->page]['trans']['B'] = (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li></ul></li><li>$this->pagedim[$this->page]['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed<ul><li>$this->pagedim[$this->page]['MediaBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['CropBox'] : the visible region of default user space<ul><li>$this->pagedim[$this->page]['CropBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment<ul><li>$this->pagedim[$this->page]['BleedBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['TrimBox'] : the intended dimensions of the finished page after trimming<ul><li>$this->pagedim[$this->page]['TrimBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['ArtBox'] : the extent of the page's meaningful content<ul><li>$this->pagedim[$this->page]['ArtBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['ury'] = upper-right y coordinate in points</li></ul></li></ul>
  3891. * @param $pagenum (int) page number (empty = current page)
  3892. * @return array of page dimensions.
  3893. * @author Nicola Asuni
  3894. * @public
  3895. * @since 4.5.027 (2009-03-16)
  3896. */
  3897. public function getPageDimensions($pagenum = '') {
  3898. if (empty($pagenum)) {
  3899. $pagenum = $this->page;
  3900. }
  3901. return $this->pagedim[$pagenum];
  3902. }
  3903. /**
  3904. * Returns the page width in units.
  3905. * @param $pagenum (int) page number (empty = current page)
  3906. * @return int page width.
  3907. * @author Nicola Asuni
  3908. * @public
  3909. * @since 1.5.2
  3910. * @see getPageDimensions()
  3911. */
  3912. public function getPageWidth($pagenum = '') {
  3913. if (empty($pagenum)) {
  3914. return $this->w;
  3915. }
  3916. return $this->pagedim[$pagenum]['w'];
  3917. }
  3918. /**
  3919. * Returns the page height in units.
  3920. * @param $pagenum (int) page number (empty = current page)
  3921. * @return int page height.
  3922. * @author Nicola Asuni
  3923. * @public
  3924. * @since 1.5.2
  3925. * @see getPageDimensions()
  3926. */
  3927. public function getPageHeight($pagenum = '') {
  3928. if (empty($pagenum)) {
  3929. return $this->h;
  3930. }
  3931. return $this->pagedim[$pagenum]['h'];
  3932. }
  3933. /**
  3934. * Returns the page break margin.
  3935. * @param $pagenum (int) page number (empty = current page)
  3936. * @return int page break margin.
  3937. * @author Nicola Asuni
  3938. * @public
  3939. * @since 1.5.2
  3940. * @see getPageDimensions()
  3941. */
  3942. public function getBreakMargin($pagenum = '') {
  3943. if (empty($pagenum)) {
  3944. return $this->bMargin;
  3945. }
  3946. return $this->pagedim[$pagenum]['bm'];
  3947. }
  3948. /**
  3949. * Returns the scale factor (number of points in user unit).
  3950. * @return int scale factor.
  3951. * @author Nicola Asuni
  3952. * @public
  3953. * @since 1.5.2
  3954. */
  3955. public function getScaleFactor() {
  3956. return $this->k;
  3957. }
  3958. /**
  3959. * Defines the left, top and right margins.
  3960. * @param $left (float) Left margin.
  3961. * @param $top (float) Top margin.
  3962. * @param $right (float) Right margin. Default value is the left one.
  3963. * @param $keepmargins (boolean) if true overwrites the default page margins
  3964. * @public
  3965. * @since 1.0
  3966. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  3967. */
  3968. public function SetMargins($left, $top, $right = -1, $keepmargins = false) {
  3969. //Set left, top and right margins
  3970. $this->lMargin = $left;
  3971. $this->tMargin = $top;
  3972. if ($right == -1) {
  3973. $right = $left;
  3974. }
  3975. $this->rMargin = $right;
  3976. if ($keepmargins) {
  3977. // overwrite original values
  3978. $this->original_lMargin = $this->lMargin;
  3979. $this->original_rMargin = $this->rMargin;
  3980. }
  3981. }
  3982. /**
  3983. * 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.
  3984. * @param $margin (float) The margin.
  3985. * @public
  3986. * @since 1.4
  3987. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  3988. */
  3989. public function SetLeftMargin($margin) {
  3990. //Set left margin
  3991. $this->lMargin = $margin;
  3992. if (($this->page > 0) AND ($this->x < $margin)) {
  3993. $this->x = $margin;
  3994. }
  3995. }
  3996. /**
  3997. * Defines the top margin. The method can be called before creating the first page.
  3998. * @param $margin (float) The margin.
  3999. * @public
  4000. * @since 1.5
  4001. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  4002. */
  4003. public function SetTopMargin($margin) {
  4004. //Set top margin
  4005. $this->tMargin = $margin;
  4006. if (($this->page > 0) AND ($this->y < $margin)) {
  4007. $this->y = $margin;
  4008. }
  4009. }
  4010. /**
  4011. * Defines the right margin. The method can be called before creating the first page.
  4012. * @param $margin (float) The margin.
  4013. * @public
  4014. * @since 1.5
  4015. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  4016. */
  4017. public function SetRightMargin($margin) {
  4018. $this->rMargin = $margin;
  4019. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  4020. $this->x = $this->w - $margin;
  4021. }
  4022. }
  4023. /**
  4024. * Set the same internal Cell padding for top, right, bottom, left-
  4025. * @param $pad (float) internal padding.
  4026. * @public
  4027. * @since 2.1.000 (2008-01-09)
  4028. * @see getCellPaddings(), setCellPaddings()
  4029. */
  4030. public function SetCellPadding($pad) {
  4031. if ($pad >= 0) {
  4032. $this->cell_padding['L'] = $pad;
  4033. $this->cell_padding['T'] = $pad;
  4034. $this->cell_padding['R'] = $pad;
  4035. $this->cell_padding['B'] = $pad;
  4036. }
  4037. }
  4038. /**
  4039. * Set the internal Cell paddings.
  4040. * @param $left (float) left padding
  4041. * @param $top (float) top padding
  4042. * @param $right (float) right padding
  4043. * @param $bottom (float) bottom padding
  4044. * @public
  4045. * @since 5.9.000 (2010-10-03)
  4046. * @see getCellPaddings(), SetCellPadding()
  4047. */
  4048. public function setCellPaddings($left = '', $top = '', $right = '', $bottom = '') {
  4049. if (($left !== '') AND ($left >= 0)) {
  4050. $this->cell_padding['L'] = $left;
  4051. }
  4052. if (($top !== '') AND ($top >= 0)) {
  4053. $this->cell_padding['T'] = $top;
  4054. }
  4055. if (($right !== '') AND ($right >= 0)) {
  4056. $this->cell_padding['R'] = $right;
  4057. }
  4058. if (($bottom !== '') AND ($bottom >= 0)) {
  4059. $this->cell_padding['B'] = $bottom;
  4060. }
  4061. }
  4062. /**
  4063. * Get the internal Cell padding array.
  4064. * @return array of padding values
  4065. * @public
  4066. * @since 5.9.000 (2010-10-03)
  4067. * @see setCellPaddings(), SetCellPadding()
  4068. */
  4069. public function getCellPaddings() {
  4070. return $this->cell_padding;
  4071. }
  4072. /**
  4073. * Set the internal Cell margins.
  4074. * @param $left (float) left margin
  4075. * @param $top (float) top margin
  4076. * @param $right (float) right margin
  4077. * @param $bottom (float) bottom margin
  4078. * @public
  4079. * @since 5.9.000 (2010-10-03)
  4080. * @see getCellMargins()
  4081. */
  4082. public function setCellMargins($left = '', $top = '', $right = '', $bottom = '') {
  4083. if (($left !== '') AND ($left >= 0)) {
  4084. $this->cell_margin['L'] = $left;
  4085. }
  4086. if (($top !== '') AND ($top >= 0)) {
  4087. $this->cell_margin['T'] = $top;
  4088. }
  4089. if (($right !== '') AND ($right >= 0)) {
  4090. $this->cell_margin['R'] = $right;
  4091. }
  4092. if (($bottom !== '') AND ($bottom >= 0)) {
  4093. $this->cell_margin['B'] = $bottom;
  4094. }
  4095. }
  4096. /**
  4097. * Get the internal Cell margin array.
  4098. * @return array of margin values
  4099. * @public
  4100. * @since 5.9.000 (2010-10-03)
  4101. * @see setCellMargins()
  4102. */
  4103. public function getCellMargins() {
  4104. return $this->cell_margin;
  4105. }
  4106. /**
  4107. * Adjust the internal Cell padding array to take account of the line width.
  4108. * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4109. * @return array of adjustments
  4110. * @public
  4111. * @since 5.9.000 (2010-10-03)
  4112. */
  4113. protected function adjustCellPadding($brd = 0) {
  4114. if (empty($brd)) {
  4115. return;
  4116. }
  4117. if (is_string($brd)) {
  4118. // convert string to array
  4119. $slen = strlen($brd);
  4120. $newbrd = array();
  4121. for ($i = 0; $i < $slen; ++$i) {
  4122. $newbrd[$brd[$i]] = true;
  4123. }
  4124. $brd = $newbrd;
  4125. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  4126. $brd = array('LRTB' => true);
  4127. }
  4128. if (!is_array($brd)) {
  4129. return;
  4130. }
  4131. // store current cell padding
  4132. $cp = $this->cell_padding;
  4133. // select border mode
  4134. if (isset($brd['mode'])) {
  4135. $mode = $brd['mode'];
  4136. unset($brd['mode']);
  4137. } else {
  4138. $mode = 'normal';
  4139. }
  4140. // process borders
  4141. foreach ($brd as $border => $style) {
  4142. $line_width = $this->LineWidth;
  4143. if (is_array($style) AND isset($style['width'])) {
  4144. // get border width
  4145. $line_width = $style['width'];
  4146. }
  4147. $adj = 0; // line width inside the cell
  4148. switch ($mode) {
  4149. case 'ext': {
  4150. $adj = 0;
  4151. break;
  4152. }
  4153. case 'int': {
  4154. $adj = $line_width;
  4155. break;
  4156. }
  4157. case 'normal':
  4158. default: {
  4159. $adj = ($line_width / 2);
  4160. break;
  4161. }
  4162. }
  4163. // correct internal cell padding if required to avoid overlap between text and lines
  4164. if ((strpos($border, 'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  4165. $this->cell_padding['T'] = $adj;
  4166. }
  4167. if ((strpos($border, 'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  4168. $this->cell_padding['R'] = $adj;
  4169. }
  4170. if ((strpos($border, 'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  4171. $this->cell_padding['B'] = $adj;
  4172. }
  4173. if ((strpos($border, 'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  4174. $this->cell_padding['L'] = $adj;
  4175. }
  4176. }
  4177. return array('T' => ($this->cell_padding['T'] - $cp['T']), 'R' => ($this->cell_padding['R'] - $cp['R']), 'B' => ($this->cell_padding['B'] - $cp['B']), 'L' => ($this->cell_padding['L'] - $cp['L']));
  4178. }
  4179. /**
  4180. * 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.
  4181. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  4182. * @param $margin (float) Distance from the bottom of the page.
  4183. * @public
  4184. * @since 1.0
  4185. * @see Cell(), MultiCell(), AcceptPageBreak()
  4186. */
  4187. public function SetAutoPageBreak($auto, $margin = 0) {
  4188. $this->AutoPageBreak = $auto ? true : false;
  4189. $this->bMargin = $margin;
  4190. $this->PageBreakTrigger = $this->h - $margin;
  4191. }
  4192. /**
  4193. * Return the auto-page-break mode (true or false).
  4194. * @return boolean auto-page-break mode
  4195. * @public
  4196. * @since 5.9.088
  4197. */
  4198. public function getAutoPageBreak() {
  4199. return $this->AutoPageBreak;
  4200. }
  4201. /**
  4202. * Defines the way the document is to be displayed by the viewer.
  4203. * @param $zoom (mixed) The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  4204. * @param $layout (string) The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  4205. * @param $mode (string) A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  4206. * @public
  4207. * @since 1.2
  4208. */
  4209. public function SetDisplayMode($zoom, $layout = 'SinglePage', $mode = 'UseNone') {
  4210. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  4211. $this->ZoomMode = $zoom;
  4212. } else {
  4213. $this->Error('Incorrect zoom display mode: ' . $zoom);
  4214. }
  4215. switch ($layout) {
  4216. case 'default':
  4217. case 'single':
  4218. case 'SinglePage': {
  4219. $this->LayoutMode = 'SinglePage';
  4220. break;
  4221. }
  4222. case 'continuous':
  4223. case 'OneColumn': {
  4224. $this->LayoutMode = 'OneColumn';
  4225. break;
  4226. }
  4227. case 'two':
  4228. case 'TwoColumnLeft': {
  4229. $this->LayoutMode = 'TwoColumnLeft';
  4230. break;
  4231. }
  4232. case 'TwoColumnRight': {
  4233. $this->LayoutMode = 'TwoColumnRight';
  4234. break;
  4235. }
  4236. case 'TwoPageLeft': {
  4237. $this->LayoutMode = 'TwoPageLeft';
  4238. break;
  4239. }
  4240. case 'TwoPageRight': {
  4241. $this->LayoutMode = 'TwoPageRight';
  4242. break;
  4243. }
  4244. default: {
  4245. $this->LayoutMode = 'SinglePage';
  4246. }
  4247. }
  4248. switch ($mode) {
  4249. case 'UseNone': {
  4250. $this->PageMode = 'UseNone';
  4251. break;
  4252. }
  4253. case 'UseOutlines': {
  4254. $this->PageMode = 'UseOutlines';
  4255. break;
  4256. }
  4257. case 'UseThumbs': {
  4258. $this->PageMode = 'UseThumbs';
  4259. break;
  4260. }
  4261. case 'FullScreen': {
  4262. $this->PageMode = 'FullScreen';
  4263. break;
  4264. }
  4265. case 'UseOC': {
  4266. $this->PageMode = 'UseOC';
  4267. break;
  4268. }
  4269. case '': {
  4270. $this->PageMode = 'UseAttachments';
  4271. break;
  4272. }
  4273. default: {
  4274. $this->PageMode = 'UseNone';
  4275. }
  4276. }
  4277. }
  4278. /**
  4279. * 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.
  4280. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  4281. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  4282. * @public
  4283. * @since 1.4
  4284. */
  4285. public function SetCompression($compress = true) {
  4286. if (function_exists('gzcompress')) {
  4287. $this->compress = $compress ? true : false;
  4288. } else {
  4289. $this->compress = false;
  4290. }
  4291. }
  4292. /**
  4293. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  4294. * @param $mode (boolean) If true force sRGB output intent.
  4295. * @public
  4296. * @since 5.9.121 (2011-09-28)
  4297. */
  4298. public function setSRGBmode($mode = false) {
  4299. $this->force_srgb = $mode ? true : false;
  4300. }
  4301. /**
  4302. * Turn on/off Unicode mode for document information dictionary (meta tags).
  4303. * This has effect only when unicode mode is set to false.
  4304. * @param $unicode (boolean) if true set the meta information in Unicode
  4305. * @since 5.9.027 (2010-12-01)
  4306. * @public
  4307. */
  4308. public function SetDocInfoUnicode($unicode = true) {
  4309. $this->docinfounicode = $unicode ? true : false;
  4310. }
  4311. /**
  4312. * Defines the title of the document.
  4313. * @param $title (string) The title.
  4314. * @public
  4315. * @since 1.2
  4316. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  4317. */
  4318. public function SetTitle($title) {
  4319. $this->title = $title;
  4320. }
  4321. /**
  4322. * Defines the subject of the document.
  4323. * @param $subject (string) The subject.
  4324. * @public
  4325. * @since 1.2
  4326. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  4327. */
  4328. public function SetSubject($subject) {
  4329. $this->subject = $subject;
  4330. }
  4331. /**
  4332. * Defines the author of the document.
  4333. * @param $author (string) The name of the author.
  4334. * @public
  4335. * @since 1.2
  4336. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  4337. */
  4338. public function SetAuthor($author) {
  4339. $this->author = $author;
  4340. }
  4341. /**
  4342. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  4343. * @param $keywords (string) The list of keywords.
  4344. * @public
  4345. * @since 1.2
  4346. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  4347. */
  4348. public function SetKeywords($keywords) {
  4349. $this->keywords = $keywords;
  4350. }
  4351. /**
  4352. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  4353. * @param $creator (string) The name of the creator.
  4354. * @public
  4355. * @since 1.2
  4356. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  4357. */
  4358. public function SetCreator($creator) {
  4359. $this->creator = $creator;
  4360. }
  4361. /**
  4362. * 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.
  4363. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  4364. * @param $msg (string) The error message
  4365. * @public
  4366. * @since 1.0
  4367. */
  4368. public function Error($msg) {
  4369. // unset all class variables
  4370. $this->_destroy(true);
  4371. // exit program and print error
  4372. die('<strong>TCPDF ERROR: </strong>' . $msg);
  4373. }
  4374. /**
  4375. * This method begins the generation of the PDF document.
  4376. * It is not necessary to call it explicitly because AddPage() does it automatically.
  4377. * Note: no page is created by this method
  4378. * @public
  4379. * @since 1.0
  4380. * @see AddPage(), Close()
  4381. */
  4382. public function Open() {
  4383. $this->state = 1;
  4384. }
  4385. /**
  4386. * Terminates the PDF document.
  4387. * It is not necessary to call this method explicitly because Output() does it automatically.
  4388. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  4389. * @public
  4390. * @since 1.0
  4391. * @see Open(), Output()
  4392. */
  4393. public function Close() {
  4394. if ($this->state == 3) {
  4395. return;
  4396. }
  4397. if ($this->page == 0) {
  4398. $this->AddPage();
  4399. }
  4400. $this->endLayer();
  4401. if ($this->tcpdflink) {
  4402. // save current graphic settings
  4403. $gvars = $this->getGraphicVars();
  4404. $this->setEqualColumns();
  4405. $this->lastpage(true);
  4406. $this->SetAutoPageBreak(false);
  4407. $this->x = 0;
  4408. $this->y = $this->h - (1 / $this->k);
  4409. $this->lMargin = 0;
  4410. $this->_out('q');
  4411. $font = defined('PDF_FONT_NAME_MAIN') ? PDF_FONT_NAME_MAIN : 'helvetica';
  4412. $this->SetFont($font, '', 1);
  4413. $this->setTextRenderingMode(0, false, false);
  4414. $msg = "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
  4415. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  4416. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  4417. $this->_out('Q');
  4418. // restore graphic settings
  4419. $this->setGraphicVars($gvars);
  4420. }
  4421. // close page
  4422. $this->endPage();
  4423. // close document
  4424. $this->_enddoc();
  4425. // unset all class variables (except critical ones)
  4426. $this->_destroy(false);
  4427. }
  4428. /**
  4429. * Move pointer at the specified document page and update page dimensions.
  4430. * @param $pnum (int) page number (1 ... numpages)
  4431. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  4432. * @public
  4433. * @since 2.1.000 (2008-01-07)
  4434. * @see getPage(), lastpage(), getNumPages()
  4435. */
  4436. public function setPage($pnum, $resetmargins = false) {
  4437. if (($pnum == $this->page) AND ($this->state == 2)) {
  4438. return;
  4439. }
  4440. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  4441. $this->state = 2;
  4442. // save current graphic settings
  4443. //$gvars = $this->getGraphicVars();
  4444. $oldpage = $this->page;
  4445. $this->page = $pnum;
  4446. $this->wPt = $this->pagedim[$this->page]['w'];
  4447. $this->hPt = $this->pagedim[$this->page]['h'];
  4448. $this->w = $this->pagedim[$this->page]['wk'];
  4449. $this->h = $this->pagedim[$this->page]['hk'];
  4450. $this->tMargin = $this->pagedim[$this->page]['tm'];
  4451. $this->bMargin = $this->pagedim[$this->page]['bm'];
  4452. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  4453. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  4454. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  4455. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  4456. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  4457. // restore graphic settings
  4458. //$this->setGraphicVars($gvars);
  4459. if ($resetmargins) {
  4460. $this->lMargin = $this->pagedim[$this->page]['olm'];
  4461. $this->rMargin = $this->pagedim[$this->page]['orm'];
  4462. $this->SetY($this->tMargin);
  4463. } else {
  4464. // account for booklet mode
  4465. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4466. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  4467. $this->lMargin += $deltam;
  4468. $this->rMargin -= $deltam;
  4469. }
  4470. }
  4471. } else {
  4472. $this->Error('Wrong page number on setPage() function: ' . $pnum);
  4473. }
  4474. }
  4475. /**
  4476. * Reset pointer to the last document page.
  4477. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  4478. * @public
  4479. * @since 2.0.000 (2008-01-04)
  4480. * @see setPage(), getPage(), getNumPages()
  4481. */
  4482. public function lastPage($resetmargins = false) {
  4483. $this->setPage($this->getNumPages(), $resetmargins);
  4484. }
  4485. /**
  4486. * Get current document page number.
  4487. * @return int page number
  4488. * @public
  4489. * @since 2.1.000 (2008-01-07)
  4490. * @see setPage(), lastpage(), getNumPages()
  4491. */
  4492. public function getPage() {
  4493. return $this->page;
  4494. }
  4495. /**
  4496. * Get the total number of insered pages.
  4497. * @return int number of pages
  4498. * @public
  4499. * @since 2.1.000 (2008-01-07)
  4500. * @see setPage(), getPage(), lastpage()
  4501. */
  4502. public function getNumPages() {
  4503. return $this->numpages;
  4504. }
  4505. /**
  4506. * Adds a new TOC (Table Of Content) page to the document.
  4507. * @param $orientation (string) page orientation.
  4508. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  4509. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  4510. * @public
  4511. * @since 5.0.001 (2010-05-06)
  4512. * @see AddPage(), startPage(), endPage(), endTOCPage()
  4513. */
  4514. public function addTOCPage($orientation = '', $format = '', $keepmargins = false) {
  4515. $this->AddPage($orientation, $format, $keepmargins, true);
  4516. }
  4517. /**
  4518. * Terminate the current TOC (Table Of Content) page
  4519. * @public
  4520. * @since 5.0.001 (2010-05-06)
  4521. * @see AddPage(), startPage(), endPage(), addTOCPage()
  4522. */
  4523. public function endTOCPage() {
  4524. $this->endPage(true);
  4525. }
  4526. /**
  4527. * 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).
  4528. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  4529. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  4530. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  4531. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  4532. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  4533. * @public
  4534. * @since 1.0
  4535. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  4536. */
  4537. public function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false) {
  4538. if ($this->inxobj) {
  4539. // we are inside an XObject template
  4540. return;
  4541. }
  4542. if (!isset($this->original_lMargin) OR $keepmargins) {
  4543. $this->original_lMargin = $this->lMargin;
  4544. }
  4545. if (!isset($this->original_rMargin) OR $keepmargins) {
  4546. $this->original_rMargin = $this->rMargin;
  4547. }
  4548. // terminate previous page
  4549. $this->endPage();
  4550. // start new page
  4551. $this->startPage($orientation, $format, $tocpage);
  4552. }
  4553. /**
  4554. * Terminate the current page
  4555. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  4556. * @public
  4557. * @since 4.2.010 (2008-11-14)
  4558. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  4559. */
  4560. public function endPage($tocpage = false) {
  4561. // check if page is already closed
  4562. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  4563. return;
  4564. }
  4565. // print page footer
  4566. $this->setFooter();
  4567. // close page
  4568. $this->_endpage();
  4569. // mark page as closed
  4570. $this->pageopen[$this->page] = false;
  4571. if ($tocpage) {
  4572. $this->tocpage = false;
  4573. }
  4574. }
  4575. /**
  4576. * Starts a new page to the document. The page must be closed using the endPage() function.
  4577. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  4578. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  4579. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  4580. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  4581. * @since 4.2.010 (2008-11-14)
  4582. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  4583. * @public
  4584. */
  4585. public function startPage($orientation = '', $format = '', $tocpage = false) {
  4586. if ($tocpage) {
  4587. $this->tocpage = true;
  4588. }
  4589. // move page numbers of documents to be attached
  4590. if ($this->tocpage) {
  4591. // move reference to unexistent pages (used for page attachments)
  4592. // adjust outlines
  4593. $tmpoutlines = $this->outlines;
  4594. foreach ($tmpoutlines as $key => $outline) {
  4595. if ($outline['p'] > $this->numpages) {
  4596. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  4597. }
  4598. }
  4599. // adjust dests
  4600. $tmpdests = $this->dests;
  4601. foreach ($tmpdests as $key => $dest) {
  4602. if ($dest['p'] > $this->numpages) {
  4603. $this->dests[$key]['p'] = ($dest['p'] + 1);
  4604. }
  4605. }
  4606. // adjust links
  4607. $tmplinks = $this->links;
  4608. foreach ($tmplinks as $key => $link) {
  4609. if ($link[0] > $this->numpages) {
  4610. $this->links[$key][0] = ($link[0] + 1);
  4611. }
  4612. }
  4613. }
  4614. if ($this->numpages > $this->page) {
  4615. // this page has been already added
  4616. $this->setPage($this->page + 1);
  4617. $this->SetY($this->tMargin);
  4618. return;
  4619. }
  4620. // start a new page
  4621. if ($this->state == 0) {
  4622. $this->Open();
  4623. }
  4624. ++$this->numpages;
  4625. $this->swapMargins($this->booklet);
  4626. // save current graphic settings
  4627. $gvars = $this->getGraphicVars();
  4628. // start new page
  4629. $this->_beginpage($orientation, $format);
  4630. // mark page as open
  4631. $this->pageopen[$this->page] = true;
  4632. // restore graphic settings
  4633. $this->setGraphicVars($gvars);
  4634. // mark this point
  4635. $this->setPageMark();
  4636. // print page header
  4637. $this->setHeader();
  4638. // restore graphic settings
  4639. $this->setGraphicVars($gvars);
  4640. // mark this point
  4641. $this->setPageMark();
  4642. // print table header (if any)
  4643. $this->setTableHeader();
  4644. // set mark for empty page check
  4645. $this->emptypagemrk[$this->page] = $this->pagelen[$this->page];
  4646. }
  4647. /**
  4648. * Set start-writing mark on current page stream used to put borders and fills.
  4649. * Borders and fills are always created after content and inserted on the position marked by this method.
  4650. * This function must be called after calling Image() function for a background image.
  4651. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  4652. * @public
  4653. * @since 4.0.016 (2008-07-30)
  4654. */
  4655. public function setPageMark() {
  4656. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  4657. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  4658. $this->setContentMark();
  4659. }
  4660. /**
  4661. * Set start-writing mark on selected page.
  4662. * Borders and fills are always created after content and inserted on the position marked by this method.
  4663. * @param $page (int) page number (default is the current page)
  4664. * @protected
  4665. * @since 4.6.021 (2009-07-20)
  4666. */
  4667. protected function setContentMark($page = 0) {
  4668. if ($page <= 0) {
  4669. $page = $this->page;
  4670. }
  4671. if (isset($this->footerlen[$page])) {
  4672. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  4673. } else {
  4674. $this->cntmrk[$page] = $this->pagelen[$page];
  4675. }
  4676. }
  4677. /**
  4678. * Set header data.
  4679. * @param $ln (string) header image logo
  4680. * @param $lw (string) header image logo width in mm
  4681. * @param $ht (string) string to print as title on document header
  4682. * @param $hs (string) string to print on document header
  4683. * @param $tc (array) RGB array color for text.
  4684. * @param $lc (array) RGB array color for line.
  4685. * @public
  4686. */
  4687. public function setHeaderData($ln = '', $lw = 0, $ht = '', $hs = '', $tc = array(0, 0, 0), $lc = array(0, 0, 0)) {
  4688. $this->header_logo = $ln;
  4689. $this->header_logo_width = $lw;
  4690. $this->header_title = $ht;
  4691. $this->header_string = $hs;
  4692. $this->header_text_color = $tc;
  4693. $this->header_line_color = $lc;
  4694. }
  4695. /**
  4696. * Set footer data.
  4697. * @param $tc (array) RGB array color for text.
  4698. * @param $lc (array) RGB array color for line.
  4699. * @public
  4700. */
  4701. public function setFooterData($tc = array(0, 0, 0), $lc = array(0, 0, 0)) {
  4702. $this->footer_text_color = $tc;
  4703. $this->footer_line_color = $lc;
  4704. }
  4705. /**
  4706. * Returns header data:
  4707. * <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>
  4708. * @return array()
  4709. * @public
  4710. * @since 4.0.012 (2008-07-24)
  4711. */
  4712. public function getHeaderData() {
  4713. $ret = array();
  4714. $ret['logo'] = $this->header_logo;
  4715. $ret['logo_width'] = $this->header_logo_width;
  4716. $ret['title'] = $this->header_title;
  4717. $ret['string'] = $this->header_string;
  4718. $ret['text_color'] = $this->header_text_color;
  4719. $ret['line_color'] = $this->header_line_color;
  4720. return $ret;
  4721. }
  4722. /**
  4723. * Set header margin.
  4724. * (minimum distance between header and top page margin)
  4725. * @param $hm (int) distance in user units
  4726. * @public
  4727. */
  4728. public function setHeaderMargin($hm = 10) {
  4729. $this->header_margin = $hm;
  4730. }
  4731. /**
  4732. * Returns header margin in user units.
  4733. * @return float
  4734. * @since 4.0.012 (2008-07-24)
  4735. * @public
  4736. */
  4737. public function getHeaderMargin() {
  4738. return $this->header_margin;
  4739. }
  4740. /**
  4741. * Set footer margin.
  4742. * (minimum distance between footer and bottom page margin)
  4743. * @param $fm (int) distance in user units
  4744. * @public
  4745. */
  4746. public function setFooterMargin($fm = 10) {
  4747. $this->footer_margin = $fm;
  4748. }
  4749. /**
  4750. * Returns footer margin in user units.
  4751. * @return float
  4752. * @since 4.0.012 (2008-07-24)
  4753. * @public
  4754. */
  4755. public function getFooterMargin() {
  4756. return $this->footer_margin;
  4757. }
  4758. /**
  4759. * Set a flag to print page header.
  4760. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  4761. * @public
  4762. */
  4763. public function setPrintHeader($val = true) {
  4764. $this->print_header = $val ? true : false;
  4765. }
  4766. /**
  4767. * Set a flag to print page footer.
  4768. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  4769. * @public
  4770. */
  4771. public function setPrintFooter($val = true) {
  4772. $this->print_footer = $val ? true : false;
  4773. }
  4774. /**
  4775. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  4776. * @return float
  4777. * @public
  4778. */
  4779. public function getImageRBX() {
  4780. return $this->img_rb_x;
  4781. }
  4782. /**
  4783. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  4784. * @return float
  4785. * @public
  4786. */
  4787. public function getImageRBY() {
  4788. return $this->img_rb_y;
  4789. }
  4790. /**
  4791. * Reset the xobject template used by Header() method.
  4792. * @public
  4793. */
  4794. public function resetHeaderTemplate() {
  4795. $this->header_xobjid = -1;
  4796. }
  4797. /**
  4798. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  4799. * @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
  4800. * @public
  4801. */
  4802. public function setHeaderTemplateAutoreset($val = true) {
  4803. $this->header_xobj_autoreset = $val ? true : false;
  4804. }
  4805. /**
  4806. * This method is used to render the page header.
  4807. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  4808. * @public
  4809. */
  4810. public function Header() {
  4811. if ($this->header_xobjid < 0) {
  4812. // start a new XObject Template
  4813. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  4814. $headerfont = $this->getHeaderFont();
  4815. $headerdata = $this->getHeaderData();
  4816. $this->y = $this->header_margin;
  4817. if ($this->rtl) {
  4818. $this->x = $this->w - $this->original_rMargin;
  4819. } else {
  4820. $this->x = $this->original_lMargin;
  4821. }
  4822. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  4823. $imgtype = $this->getImageFileType(K_PATH_IMAGES . $headerdata['logo']);
  4824. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  4825. $this->ImageEps(K_PATH_IMAGES . $headerdata['logo'], '', '', $headerdata['logo_width']);
  4826. } elseif ($imgtype == 'svg') {
  4827. $this->ImageSVG(K_PATH_IMAGES . $headerdata['logo'], '', '', $headerdata['logo_width']);
  4828. } else {
  4829. $this->Image(K_PATH_IMAGES . $headerdata['logo'], '', '', $headerdata['logo_width']);
  4830. }
  4831. $imgy = $this->getImageRBY();
  4832. } else {
  4833. $imgy = $this->y;
  4834. }
  4835. $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2);
  4836. // set starting margin for text data cell
  4837. if ($this->getRTL()) {
  4838. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  4839. } else {
  4840. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  4841. }
  4842. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  4843. $this->SetTextColorArray($this->header_text_color);
  4844. // header title
  4845. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  4846. $this->SetX($header_x);
  4847. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  4848. // header string
  4849. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  4850. $this->SetX($header_x);
  4851. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  4852. // print an ending header line
  4853. $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  4854. $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
  4855. if ($this->rtl) {
  4856. $this->SetX($this->original_rMargin);
  4857. } else {
  4858. $this->SetX($this->original_lMargin);
  4859. }
  4860. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  4861. $this->endTemplate();
  4862. }
  4863. // print header template
  4864. $x = 0;
  4865. $dx = 0;
  4866. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  4867. // adjust margins for booklet mode
  4868. $dx = ($this->original_lMargin - $this->original_rMargin);
  4869. }
  4870. if ($this->rtl) {
  4871. $x = $this->w + $dx;
  4872. } else {
  4873. $x = 0 + $dx;
  4874. }
  4875. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  4876. if ($this->header_xobj_autoreset) {
  4877. // reset header xobject template at each page
  4878. $this->header_xobjid = -1;
  4879. }
  4880. }
  4881. /**
  4882. * This method is used to render the page footer.
  4883. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  4884. * @public
  4885. */
  4886. public function Footer() {
  4887. $cur_y = $this->y;
  4888. $this->SetTextColorArray($this->footer_text_color);
  4889. //set style for cell border
  4890. $line_width = (0.85 / $this->k);
  4891. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  4892. //print document barcode
  4893. $barcode = $this->getBarcode();
  4894. if (!empty($barcode)) {
  4895. $this->Ln($line_width);
  4896. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  4897. $style = array(
  4898. 'position' => $this->rtl ? 'R' : 'L',
  4899. 'align' => $this->rtl ? 'R' : 'L',
  4900. 'stretch' => false,
  4901. 'fitwidth' => true,
  4902. 'cellfitalign' => '',
  4903. 'border' => false,
  4904. 'padding' => 0,
  4905. 'fgcolor' => array(0, 0, 0),
  4906. 'bgcolor' => false,
  4907. 'text' => false
  4908. );
  4909. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  4910. }
  4911. $w_page = isset($this->l['w_page']) ? $this->l['w_page'] . ' ' : '';
  4912. if (empty($this->pagegroups)) {
  4913. $pagenumtxt = $w_page . $this->getAliasNumPage() . ' / ' . $this->getAliasNbPages();
  4914. } else {
  4915. $pagenumtxt = $w_page . $this->getPageNumGroupAlias() . ' / ' . $this->getPageGroupAlias();
  4916. }
  4917. $this->SetY($cur_y);
  4918. //Print page number
  4919. if ($this->getRTL()) {
  4920. $this->SetX($this->original_rMargin);
  4921. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  4922. } else {
  4923. $this->SetX($this->original_lMargin);
  4924. $this->Cell(0, 0, $this->getAliasRightShift() . $pagenumtxt, 'T', 0, 'R');
  4925. }
  4926. }
  4927. /**
  4928. * This method is used to render the page header.
  4929. * @protected
  4930. * @since 4.0.012 (2008-07-24)
  4931. */
  4932. protected function setHeader() {
  4933. if (!$this->print_header OR ($this->state != 2)) {
  4934. return;
  4935. }
  4936. $this->InHeader = true;
  4937. $this->setGraphicVars($this->default_graphic_vars);
  4938. $temp_thead = $this->thead;
  4939. $temp_theadMargins = $this->theadMargins;
  4940. $lasth = $this->lasth;
  4941. $this->_out('q');
  4942. $this->rMargin = $this->original_rMargin;
  4943. $this->lMargin = $this->original_lMargin;
  4944. $this->SetCellPadding(0);
  4945. //set current position
  4946. if ($this->rtl) {
  4947. $this->SetXY($this->original_rMargin, $this->header_margin);
  4948. } else {
  4949. $this->SetXY($this->original_lMargin, $this->header_margin);
  4950. }
  4951. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  4952. $this->Header();
  4953. //restore position
  4954. if ($this->rtl) {
  4955. $this->SetXY($this->original_rMargin, $this->tMargin);
  4956. } else {
  4957. $this->SetXY($this->original_lMargin, $this->tMargin);
  4958. }
  4959. $this->_out('Q');
  4960. $this->lasth = $lasth;
  4961. $this->thead = $temp_thead;
  4962. $this->theadMargins = $temp_theadMargins;
  4963. $this->newline = false;
  4964. $this->InHeader = false;
  4965. }
  4966. /**
  4967. * This method is used to render the page footer.
  4968. * @protected
  4969. * @since 4.0.012 (2008-07-24)
  4970. */
  4971. protected function setFooter() {
  4972. if ($this->state != 2) {
  4973. return;
  4974. }
  4975. $this->InFooter = true;
  4976. // save current graphic settings
  4977. $gvars = $this->getGraphicVars();
  4978. // mark this point
  4979. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  4980. $this->_out("\n");
  4981. if ($this->print_footer) {
  4982. $this->setGraphicVars($this->default_graphic_vars);
  4983. $this->current_column = 0;
  4984. $this->num_columns = 1;
  4985. $temp_thead = $this->thead;
  4986. $temp_theadMargins = $this->theadMargins;
  4987. $lasth = $this->lasth;
  4988. $this->_out('q');
  4989. $this->rMargin = $this->original_rMargin;
  4990. $this->lMargin = $this->original_lMargin;
  4991. $this->SetCellPadding(0);
  4992. //set current position
  4993. $footer_y = $this->h - $this->footer_margin;
  4994. if ($this->rtl) {
  4995. $this->SetXY($this->original_rMargin, $footer_y);
  4996. } else {
  4997. $this->SetXY($this->original_lMargin, $footer_y);
  4998. }
  4999. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  5000. $this->Footer();
  5001. //restore position
  5002. if ($this->rtl) {
  5003. $this->SetXY($this->original_rMargin, $this->tMargin);
  5004. } else {
  5005. $this->SetXY($this->original_lMargin, $this->tMargin);
  5006. }
  5007. $this->_out('Q');
  5008. $this->lasth = $lasth;
  5009. $this->thead = $temp_thead;
  5010. $this->theadMargins = $temp_theadMargins;
  5011. }
  5012. // restore graphic settings
  5013. $this->setGraphicVars($gvars);
  5014. $this->current_column = $gvars['current_column'];
  5015. $this->num_columns = $gvars['num_columns'];
  5016. // calculate footer length
  5017. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  5018. $this->InFooter = false;
  5019. }
  5020. /**
  5021. * Check if we are on the page body (excluding page header and footer).
  5022. * @return true if we are not in page header nor in page footer, false otherwise.
  5023. * @protected
  5024. * @since 5.9.091 (2011-06-15)
  5025. */
  5026. protected function inPageBody() {
  5027. return (($this->InHeader === false) AND ($this->InFooter === false));
  5028. }
  5029. /**
  5030. * This method is used to render the table header on new page (if any).
  5031. * @protected
  5032. * @since 4.5.030 (2009-03-25)
  5033. */
  5034. protected function setTableHeader() {
  5035. if ($this->num_columns > 1) {
  5036. // multi column mode
  5037. return;
  5038. }
  5039. if (isset($this->theadMargins['top'])) {
  5040. // restore the original top-margin
  5041. $this->tMargin = $this->theadMargins['top'];
  5042. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  5043. $this->y = $this->tMargin;
  5044. }
  5045. if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  5046. // set margins
  5047. $prev_lMargin = $this->lMargin;
  5048. $prev_rMargin = $this->rMargin;
  5049. $prev_cell_padding = $this->cell_padding;
  5050. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  5051. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  5052. $this->cell_padding = $this->theadMargins['cell_padding'];
  5053. if ($this->rtl) {
  5054. $this->x = $this->w - $this->rMargin;
  5055. } else {
  5056. $this->x = $this->lMargin;
  5057. }
  5058. // account for special "cell" mode
  5059. if ($this->theadMargins['cell']) {
  5060. if ($this->rtl) {
  5061. $this->x -= $this->cell_padding['R'];
  5062. } else {
  5063. $this->x += $this->cell_padding['L'];
  5064. }
  5065. }
  5066. // print table header
  5067. $this->writeHTML($this->thead, false, false, false, false, '');
  5068. // set new top margin to skip the table headers
  5069. if (!isset($this->theadMargins['top'])) {
  5070. $this->theadMargins['top'] = $this->tMargin;
  5071. }
  5072. // store end of header position
  5073. if (!isset($this->columns[0]['th'])) {
  5074. $this->columns[0]['th'] = array();
  5075. }
  5076. $this->columns[0]['th']['\'' . $this->page . '\''] = $this->y;
  5077. $this->tMargin = $this->y;
  5078. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  5079. $this->lasth = 0;
  5080. $this->lMargin = $prev_lMargin;
  5081. $this->rMargin = $prev_rMargin;
  5082. $this->cell_padding = $prev_cell_padding;
  5083. }
  5084. }
  5085. /**
  5086. * Returns the current page number.
  5087. * @return int page number
  5088. * @public
  5089. * @since 1.0
  5090. * @see getAliasNbPages()
  5091. */
  5092. public function PageNo() {
  5093. return $this->page;
  5094. }
  5095. /**
  5096. * Defines a new spot color.
  5097. * It can be expressed in RGB components or gray scale.
  5098. * The method can be called before the first page is created and the value is retained from page to page.
  5099. * @param $name (string) Full name of the spot color.
  5100. * @param $c (float) Cyan color for CMYK. Value between 0 and 100.
  5101. * @param $m (float) Magenta color for CMYK. Value between 0 and 100.
  5102. * @param $y (float) Yellow color for CMYK. Value between 0 and 100.
  5103. * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100.
  5104. * @public
  5105. * @since 4.0.024 (2008-09-12)
  5106. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  5107. */
  5108. public function AddSpotColor($name, $c, $m, $y, $k) {
  5109. if (!isset($this->spot_colors[$name])) {
  5110. $i = (1 + count($this->spot_colors));
  5111. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  5112. }
  5113. }
  5114. /**
  5115. * Return the Spot color array.
  5116. * @param $name (string) Name of the spot color.
  5117. * @return (array) Spot color array or false if not defined.
  5118. * @public
  5119. * @since 5.9.125 (2011-10-03)
  5120. */
  5121. public function getSpotColor($name) {
  5122. if (isset($this->spot_colors[$name])) {
  5123. return $this->spot_colors[$name];
  5124. }
  5125. $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
  5126. $color = strtolower($color);
  5127. if (isset($this->spotcolor[$color])) {
  5128. $this->AddSpotColor($this->spotcolor[$color][4], $this->spotcolor[$color][0], $this->spotcolor[$color][1], $this->spotcolor[$color][2], $this->spotcolor[$color][3]);
  5129. return $this->spot_colors[$this->spotcolor[$color][4]];
  5130. }
  5131. return false;
  5132. }
  5133. /**
  5134. * Set the spot color for the specified type ('draw', 'fill', 'text').
  5135. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  5136. * @param $name (string) Name of the spot color.
  5137. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5138. * @return (string) PDF color command.
  5139. * @public
  5140. * @since 5.9.125 (2011-10-03)
  5141. */
  5142. public function setSpotColor($type, $name, $tint = 100) {
  5143. $spotcolor = $this->getSpotColor($name);
  5144. if ($spotcolor === false) {
  5145. $this->Error('Undefined spot color: ' . $name . ', you must add it on the spotcolors.php file.');
  5146. }
  5147. $tint = (max(0, min(100, $tint)) / 100);
  5148. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  5149. switch ($type) {
  5150. case 'draw': {
  5151. $pdfcolor .= sprintf('CS %F SCN', $tint);
  5152. $this->DrawColor = $pdfcolor;
  5153. $this->strokecolor = $spotcolor;
  5154. break;
  5155. }
  5156. case 'fill': {
  5157. $pdfcolor .= sprintf('cs %F scn', $tint);
  5158. $this->FillColor = $pdfcolor;
  5159. $this->bgcolor = $spotcolor;
  5160. break;
  5161. }
  5162. case 'text': {
  5163. $pdfcolor .= sprintf('cs %F scn', $tint);
  5164. $this->TextColor = $pdfcolor;
  5165. $this->fgcolor = $spotcolor;
  5166. break;
  5167. }
  5168. }
  5169. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5170. if ($this->state == 2) {
  5171. $this->_out($pdfcolor);
  5172. }
  5173. if ($this->inxobj) {
  5174. // we are inside an XObject template
  5175. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  5176. }
  5177. return $pdfcolor;
  5178. }
  5179. /**
  5180. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  5181. * @param $name (string) Name of the spot color.
  5182. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5183. * @public
  5184. * @since 4.0.024 (2008-09-12)
  5185. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  5186. */
  5187. public function SetDrawSpotColor($name, $tint = 100) {
  5188. $this->setSpotColor('draw', $name, $tint);
  5189. }
  5190. /**
  5191. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  5192. * @param $name (string) Name of the spot color.
  5193. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5194. * @public
  5195. * @since 4.0.024 (2008-09-12)
  5196. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  5197. */
  5198. public function SetFillSpotColor($name, $tint = 100) {
  5199. $this->setSpotColor('fill', $name, $tint);
  5200. }
  5201. /**
  5202. * Defines the spot color used for text.
  5203. * @param $name (string) Name of the spot color.
  5204. * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5205. * @public
  5206. * @since 4.0.024 (2008-09-12)
  5207. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  5208. */
  5209. public function SetTextSpotColor($name, $tint = 100) {
  5210. $this->setSpotColor('text', $name, $tint);
  5211. }
  5212. /**
  5213. * Set the color array for the specified type ('draw', 'fill', 'text').
  5214. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  5215. * The method can be called before the first page is created and the value is retained from page to page.
  5216. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  5217. * @param $color (array) Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  5218. * @param $ret (boolean) If true do not send the PDF command.
  5219. * @return (string) The PDF command or empty string.
  5220. * @public
  5221. * @since 3.1.000 (2008-06-11)
  5222. */
  5223. public function setColorArray($type, $color, $ret = false) {
  5224. if (is_array($color)) {
  5225. $color = array_values($color);
  5226. // component: grey, RGB red or CMYK cyan
  5227. $c = isset($color[0]) ? $color[0] : -1;
  5228. // component: RGB green or CMYK magenta
  5229. $m = isset($color[1]) ? $color[1] : -1;
  5230. // component: RGB blue or CMYK yellow
  5231. $y = isset($color[2]) ? $color[2] : -1;
  5232. // component: CMYK black
  5233. $k = isset($color[3]) ? $color[3] : -1;
  5234. // color name
  5235. $name = isset($color[4]) ? $color[4] : '';
  5236. if ($c >= 0) {
  5237. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  5238. }
  5239. }
  5240. return '';
  5241. }
  5242. /**
  5243. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  5244. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  5245. * The method can be called before the first page is created and the value is retained from page to page.
  5246. * @param $color (array) Array of colors (1, 3 or 4 values).
  5247. * @param $ret (boolean) If true do not send the PDF command.
  5248. * @return string the PDF command
  5249. * @public
  5250. * @since 3.1.000 (2008-06-11)
  5251. * @see SetDrawColor()
  5252. */
  5253. public function SetDrawColorArray($color, $ret = false) {
  5254. return $this->setColorArray('draw', $color, $ret);
  5255. }
  5256. /**
  5257. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  5258. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  5259. * The method can be called before the first page is created and the value is retained from page to page.
  5260. * @param $color (array) Array of colors (1, 3 or 4 values).
  5261. * @param $ret (boolean) If true do not send the PDF command.
  5262. * @public
  5263. * @since 3.1.000 (2008-6-11)
  5264. * @see SetFillColor()
  5265. */
  5266. public function SetFillColorArray($color, $ret = false) {
  5267. return $this->setColorArray('fill', $color, $ret);
  5268. }
  5269. /**
  5270. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  5271. * The method can be called before the first page is created and the value is retained from page to page.
  5272. * @param $color (array) Array of colors (1, 3 or 4 values).
  5273. * @param $ret (boolean) If true do not send the PDF command.
  5274. * @public
  5275. * @since 3.1.000 (2008-6-11)
  5276. * @see SetFillColor()
  5277. */
  5278. public function SetTextColorArray($color, $ret = false) {
  5279. return $this->setColorArray('text', $color, $ret);
  5280. }
  5281. /**
  5282. * Defines the color used by the specified type ('draw', 'fill', 'text').
  5283. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  5284. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  5285. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  5286. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  5287. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  5288. * @param $ret (boolean) If true do not send the command.
  5289. * @param $name (string) spot color name (if any)
  5290. * @return (string) The PDF command or empty string.
  5291. * @public
  5292. * @since 5.9.125 (2011-10-03)
  5293. */
  5294. public function setColor($type, $col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '') {
  5295. // set default values
  5296. if (!is_numeric($col1)) {
  5297. $col1 = 0;
  5298. }
  5299. if (!is_numeric($col2)) {
  5300. $col2 = -1;
  5301. }
  5302. if (!is_numeric($col3)) {
  5303. $col3 = -1;
  5304. }
  5305. if (!is_numeric($col4)) {
  5306. $col4 = -1;
  5307. }
  5308. // set color by case
  5309. $suffix = '';
  5310. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  5311. // Grey scale
  5312. $col1 = max(0, min(255, $col1));
  5313. $intcolor = array('G' => $col1);
  5314. $pdfcolor = sprintf('%F ', ($col1 / 255));
  5315. $suffix = 'g';
  5316. } elseif ($col4 == -1) {
  5317. // RGB
  5318. $col1 = max(0, min(255, $col1));
  5319. $col2 = max(0, min(255, $col2));
  5320. $col3 = max(0, min(255, $col3));
  5321. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  5322. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  5323. $suffix = 'rg';
  5324. } else {
  5325. $col1 = max(0, min(100, $col1));
  5326. $col2 = max(0, min(100, $col2));
  5327. $col3 = max(0, min(100, $col3));
  5328. $col4 = max(0, min(100, $col4));
  5329. if (empty($name)) {
  5330. // CMYK
  5331. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  5332. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  5333. $suffix = 'k';
  5334. } else {
  5335. // SPOT COLOR
  5336. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  5337. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  5338. $pdfcolor = $this->setSpotColor($type, $name, 100);
  5339. }
  5340. }
  5341. switch ($type) {
  5342. case 'draw': {
  5343. $pdfcolor .= strtoupper($suffix);
  5344. $this->DrawColor = $pdfcolor;
  5345. $this->strokecolor = $intcolor;
  5346. break;
  5347. }
  5348. case 'fill': {
  5349. $pdfcolor .= $suffix;
  5350. $this->FillColor = $pdfcolor;
  5351. $this->bgcolor = $intcolor;
  5352. break;
  5353. }
  5354. case 'text': {
  5355. $pdfcolor .= $suffix;
  5356. $this->TextColor = $pdfcolor;
  5357. $this->fgcolor = $intcolor;
  5358. break;
  5359. }
  5360. }
  5361. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5362. if (($type != 'text') AND ($this->state == 2)) {
  5363. if (!$ret) {
  5364. $this->_out($pdfcolor);
  5365. }
  5366. return $pdfcolor;
  5367. }
  5368. return '';
  5369. }
  5370. /**
  5371. * Convert a color array into a string representation.
  5372. * @param $c (array) Array of colors.
  5373. * @return (string) The color array representation.
  5374. * @protected
  5375. * @since 5.9.137 (2011-12-01)
  5376. */
  5377. protected function getColorStringFromArray($c) {
  5378. $c = array_values($c);
  5379. $color = '[';
  5380. switch (count($c)) {
  5381. case 4: {
  5382. // CMYK
  5383. $color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0]))) / 100), (max(0, min(100, floatval($c[1]))) / 100), (max(0, min(100, floatval($c[2]))) / 100), (max(0, min(100, floatval($c[3]))) / 100));
  5384. break;
  5385. }
  5386. case 3: {
  5387. // RGB
  5388. $color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0]))) / 255), (max(0, min(255, floatval($c[1]))) / 255), (max(0, min(255, floatval($c[2]))) / 255));
  5389. break;
  5390. }
  5391. case 1: {
  5392. // grayscale
  5393. $color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255));
  5394. break;
  5395. }
  5396. }
  5397. $color .= ']';
  5398. return $color;
  5399. }
  5400. /**
  5401. * 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.
  5402. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  5403. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  5404. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  5405. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  5406. * @param $ret (boolean) If true do not send the command.
  5407. * @param $name (string) spot color name (if any)
  5408. * @return string the PDF command
  5409. * @public
  5410. * @since 1.3
  5411. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  5412. */
  5413. public function SetDrawColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '') {
  5414. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  5415. }
  5416. /**
  5417. * 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.
  5418. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  5419. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  5420. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  5421. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  5422. * @param $ret (boolean) If true do not send the command.
  5423. * @param $name (string) Spot color name (if any).
  5424. * @return (string) The PDF command.
  5425. * @public
  5426. * @since 1.3
  5427. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  5428. */
  5429. public function SetFillColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '') {
  5430. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  5431. }
  5432. /**
  5433. * 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.
  5434. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  5435. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  5436. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  5437. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  5438. * @param $ret (boolean) If true do not send the command.
  5439. * @param $name (string) Spot color name (if any).
  5440. * @return (string) Empty string.
  5441. * @public
  5442. * @since 1.3
  5443. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  5444. */
  5445. public function SetTextColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '') {
  5446. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  5447. }
  5448. /**
  5449. * Returns the length of a string in user unit. A font must be selected.<br>
  5450. * @param $s (string) The string whose length is to be computed
  5451. * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  5452. * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line-trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  5453. * @param $fontsize (float) Font size in points. The default value is the current size.
  5454. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  5455. * @return mixed int total string length or array of characted widths
  5456. * @author Nicola Asuni
  5457. * @public
  5458. * @since 1.2
  5459. */
  5460. public function GetStringWidth($s, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false) {
  5461. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  5462. }
  5463. /**
  5464. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  5465. * @param $sa (string) The array of chars whose total length is to be computed
  5466. * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  5467. * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  5468. * @param $fontsize (float) Font size in points. The default value is the current size.
  5469. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  5470. * @return mixed int total string length or array of characted widths
  5471. * @author Nicola Asuni
  5472. * @public
  5473. * @since 2.4.000 (2008-03-06)
  5474. */
  5475. public function GetArrStringWidth($sa, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false) {
  5476. // store current values
  5477. if (!$this->empty_string($fontname)) {
  5478. $prev_FontFamily = $this->FontFamily;
  5479. $prev_FontStyle = $this->FontStyle;
  5480. $prev_FontSizePt = $this->FontSizePt;
  5481. $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  5482. }
  5483. // convert UTF-8 array to Latin1 if required
  5484. $sa = $this->UTF8ArrToLatin1($sa);
  5485. $w = 0; // total width
  5486. $wa = array(); // array of characters widths
  5487. foreach ($sa as $ck => $char) {
  5488. // character width
  5489. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  5490. $wa[] = $cw;
  5491. $w += $cw;
  5492. }
  5493. // restore previous values
  5494. if (!$this->empty_string($fontname)) {
  5495. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  5496. }
  5497. if ($getarray) {
  5498. return $wa;
  5499. }
  5500. return $w;
  5501. }
  5502. /**
  5503. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  5504. * @param $char (int) The char code whose length is to be returned
  5505. * @param $notlast (boolean) If false ignore the font-spacing.
  5506. * @return float char width
  5507. * @author Nicola Asuni
  5508. * @public
  5509. * @since 2.4.000 (2008-03-06)
  5510. */
  5511. public function GetCharWidth($char, $notlast = true) {
  5512. // get raw width
  5513. $chw = $this->getRawCharWidth($char);
  5514. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  5515. // increase/decrease font spacing
  5516. $chw += $this->font_spacing;
  5517. }
  5518. if ($this->font_stretching != 100) {
  5519. // fixed stretching mode
  5520. $chw *= ($this->font_stretching / 100);
  5521. }
  5522. return $chw;
  5523. }
  5524. /**
  5525. * Returns the length of the char in user unit for the current font.
  5526. * @param $char (int) The char code whose length is to be returned
  5527. * @return float char width
  5528. * @author Nicola Asuni
  5529. * @public
  5530. * @since 5.9.000 (2010-09-28)
  5531. */
  5532. public function getRawCharWidth($char) {
  5533. if ($char == 173) {
  5534. // SHY character will not be printed
  5535. return (0);
  5536. }
  5537. if (isset($this->CurrentFont['cw'][$char])) {
  5538. $w = $this->CurrentFont['cw'][$char];
  5539. } elseif (isset($this->CurrentFont['dw'])) {
  5540. // default width
  5541. $w = $this->CurrentFont['dw'];
  5542. } elseif (isset($this->CurrentFont['cw'][32])) {
  5543. // default width
  5544. $w = $this->CurrentFont['cw'][32];
  5545. } else {
  5546. $w = 600;
  5547. }
  5548. return $this->getAbsFontMeasure($w);
  5549. }
  5550. /**
  5551. * Returns the numbero of characters in a string.
  5552. * @param $s (string) The input string.
  5553. * @return int number of characters
  5554. * @public
  5555. * @since 2.0.0001 (2008-01-07)
  5556. */
  5557. public function GetNumChars($s) {
  5558. if ($this->isUnicodeFont()) {
  5559. return count($this->UTF8StringToArray($s));
  5560. }
  5561. return strlen($s);
  5562. }
  5563. /**
  5564. * Fill the list of available fonts ($this->fontlist).
  5565. * @protected
  5566. * @since 4.0.013 (2008-07-28)
  5567. */
  5568. protected function getFontsList() {
  5569. $fontsdir = opendir($this->_getfontpath());
  5570. while (($file = readdir($fontsdir)) !== false) {
  5571. if (substr($file, -4) == '.php') {
  5572. array_push($this->fontlist, strtolower(basename($file, '.php')));
  5573. }
  5574. }
  5575. closedir($fontsdir);
  5576. }
  5577. /**
  5578. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  5579. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  5580. * 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.
  5581. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  5582. * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  5583. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  5584. * @return array containing the font data, or false in case of error.
  5585. * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  5586. * @public
  5587. * @since 1.5
  5588. * @see SetFont(), setFontSubsetting()
  5589. */
  5590. public function AddFont($family, $style = '', $fontfile = '', $subset = 'default') {
  5591. if ($subset === 'default') {
  5592. $subset = $this->font_subsetting;
  5593. }
  5594. if ($this->pdfa_mode) {
  5595. $subset = false;
  5596. }
  5597. if ($this->empty_string($family)) {
  5598. if (!$this->empty_string($this->FontFamily)) {
  5599. $family = $this->FontFamily;
  5600. } else {
  5601. $this->Error('Empty font family');
  5602. }
  5603. }
  5604. // move embedded styles on $style
  5605. if (substr($family, -1) == 'I') {
  5606. $style .= 'I';
  5607. $family = substr($family, 0, -1);
  5608. }
  5609. if (substr($family, -1) == 'B') {
  5610. $style .= 'B';
  5611. $family = substr($family, 0, -1);
  5612. }
  5613. // normalize family name
  5614. $family = strtolower($family);
  5615. if ((!$this->isunicode) AND ($family == 'arial')) {
  5616. $family = 'helvetica';
  5617. }
  5618. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  5619. $style = '';
  5620. }
  5621. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  5622. // all fonts must be embedded
  5623. $family = 'pdfa' . $family;
  5624. }
  5625. $tempstyle = strtoupper($style);
  5626. $style = '';
  5627. // underline
  5628. if (strpos($tempstyle, 'U') !== false) {
  5629. $this->underline = true;
  5630. } else {
  5631. $this->underline = false;
  5632. }
  5633. // line-through (deleted)
  5634. if (strpos($tempstyle, 'D') !== false) {
  5635. $this->linethrough = true;
  5636. } else {
  5637. $this->linethrough = false;
  5638. }
  5639. // overline
  5640. if (strpos($tempstyle, 'O') !== false) {
  5641. $this->overline = true;
  5642. } else {
  5643. $this->overline = false;
  5644. }
  5645. // bold
  5646. if (strpos($tempstyle, 'B') !== false) {
  5647. $style .= 'B';
  5648. }
  5649. // oblique
  5650. if (strpos($tempstyle, 'I') !== false) {
  5651. $style .= 'I';
  5652. }
  5653. $bistyle = $style;
  5654. $fontkey = $family . $style;
  5655. $font_style = $style . ($this->underline ? 'U' : '') . ($this->linethrough ? 'D' : '') . ($this->overline ? 'O' : '');
  5656. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  5657. // check if the font has been already added
  5658. $fb = $this->getFontBuffer($fontkey);
  5659. if ($fb !== false) {
  5660. if ($this->inxobj) {
  5661. // we are inside an XObject template
  5662. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  5663. }
  5664. return $fontdata;
  5665. }
  5666. if (isset($type)) {
  5667. unset($type);
  5668. }
  5669. if (isset($cw)) {
  5670. unset($cw);
  5671. }
  5672. // get specified font directory (if any)
  5673. $fontdir = false;
  5674. if (!$this->empty_string($fontfile)) {
  5675. $fontdir = dirname($fontfile);
  5676. if ($this->empty_string($fontdir) OR ($fontdir == '.')) {
  5677. $fontdir = '';
  5678. } else {
  5679. $fontdir .= '/';
  5680. }
  5681. }
  5682. $missing_style = false; // true when the font style variation is missing
  5683. // search and include font file
  5684. if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
  5685. // build a standard filenames for specified font
  5686. $tmp_fontfile = str_replace(' ', '', $family) . strtolower($style) . '.php';
  5687. // search files on various directories
  5688. if (($fontdir !== false) AND file_exists($fontdir . $tmp_fontfile)) {
  5689. $fontfile = $fontdir . $tmp_fontfile;
  5690. } elseif (file_exists($this->_getfontpath() . $tmp_fontfile)) {
  5691. $fontfile = $this->_getfontpath() . $tmp_fontfile;
  5692. } elseif (file_exists($tmp_fontfile)) {
  5693. $fontfile = $tmp_fontfile;
  5694. } elseif (!$this->empty_string($style)) {
  5695. $missing_style = true;
  5696. // try to remove the style part
  5697. $tmp_fontfile = str_replace(' ', '', $family) . '.php';
  5698. if (($fontdir !== false) AND file_exists($fontdir . $tmp_fontfile)) {
  5699. $fontfile = $fontdir . $tmp_fontfile;
  5700. } elseif (file_exists($this->_getfontpath() . $tmp_fontfile)) {
  5701. $fontfile = $this->_getfontpath() . $tmp_fontfile;
  5702. } else {
  5703. $fontfile = $tmp_fontfile;
  5704. }
  5705. }
  5706. }
  5707. // include font file
  5708. if (file_exists($fontfile)) {
  5709. include($fontfile);
  5710. } else {
  5711. $this->Error('Could not include font definition file: ' . $family . '');
  5712. }
  5713. // check font parameters
  5714. if ((!isset($type)) OR (!isset($cw))) {
  5715. $this->Error('The font definition file has a bad format: ' . $fontfile . '');
  5716. }
  5717. // SET default parameters
  5718. if (!isset($file) OR $this->empty_string($file)) {
  5719. $file = '';
  5720. }
  5721. if (!isset($enc) OR $this->empty_string($enc)) {
  5722. $enc = '';
  5723. }
  5724. if (!isset($cidinfo) OR $this->empty_string($cidinfo)) {
  5725. $cidinfo = array('Registry' => 'Adobe', 'Ordering' => 'Identity', 'Supplement' => 0);
  5726. $cidinfo['uni2cid'] = array();
  5727. }
  5728. if (!isset($ctg) OR $this->empty_string($ctg)) {
  5729. $ctg = '';
  5730. }
  5731. if (!isset($desc) OR $this->empty_string($desc)) {
  5732. $desc = array();
  5733. }
  5734. if (!isset($up) OR $this->empty_string($up)) {
  5735. $up = -100;
  5736. }
  5737. if (!isset($ut) OR $this->empty_string($ut)) {
  5738. $ut = 50;
  5739. }
  5740. if (!isset($cw) OR $this->empty_string($cw)) {
  5741. $cw = array();
  5742. }
  5743. if (!isset($dw) OR $this->empty_string($dw)) {
  5744. // set default width
  5745. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  5746. $dw = $desc['MissingWidth'];
  5747. } elseif (isset($cw[32])) {
  5748. $dw = $cw[32];
  5749. } else {
  5750. $dw = 600;
  5751. }
  5752. }
  5753. ++$this->numfonts;
  5754. if ($type == 'core') {
  5755. $name = $this->CoreFonts[$fontkey];
  5756. $subset = false;
  5757. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  5758. $subset = false;
  5759. } elseif ($type == 'TrueTypeUnicode') {
  5760. $enc = 'Identity-H';
  5761. } elseif ($type == 'cidfont0') {
  5762. if ($this->pdfa_mode) {
  5763. $this->Error('All fonts must be embedded in PDF/A mode!');
  5764. }
  5765. } else {
  5766. $this->Error('Unknow font type: ' . $type . '');
  5767. }
  5768. // set name if unset
  5769. if (!isset($name) OR empty($name)) {
  5770. $name = $fontkey;
  5771. }
  5772. // create artificial font style variations if missing (only works with non-embedded fonts)
  5773. if (($type != 'core') AND $missing_style) {
  5774. // style variations
  5775. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  5776. $name .= $styles[$bistyle];
  5777. // artificial bold
  5778. if (strpos($bistyle, 'B') !== false) {
  5779. if (isset($desc['StemV'])) {
  5780. // from normal to bold
  5781. $desc['StemV'] = round($desc['StemV'] * 1.75);
  5782. } else {
  5783. // bold
  5784. $desc['StemV'] = 123;
  5785. }
  5786. }
  5787. // artificial italic
  5788. if (strpos($bistyle, 'I') !== false) {
  5789. if (isset($desc['ItalicAngle'])) {
  5790. $desc['ItalicAngle'] -= 11;
  5791. } else {
  5792. $desc['ItalicAngle'] = -11;
  5793. }
  5794. if (isset($desc['Flags'])) {
  5795. $desc['Flags'] |= 64; //bit 7
  5796. } else {
  5797. $desc['Flags'] = 64;
  5798. }
  5799. }
  5800. }
  5801. // check if the array of characters bounding boxes is defined
  5802. if (!isset($cbbox)) {
  5803. $cbbox = array();
  5804. }
  5805. // initialize subsetchars
  5806. $subsetchars = array_fill(0, 255, true);
  5807. $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'cbbox' => $cbbox, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
  5808. if ($this->inxobj) {
  5809. // we are inside an XObject template
  5810. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  5811. }
  5812. if (isset($diff) AND (!empty($diff))) {
  5813. //Search existing encodings
  5814. $d = 0;
  5815. $nb = count($this->diffs);
  5816. for ($i = 1; $i <= $nb; ++$i) {
  5817. if ($this->diffs[$i] == $diff) {
  5818. $d = $i;
  5819. break;
  5820. }
  5821. }
  5822. if ($d == 0) {
  5823. $d = $nb + 1;
  5824. $this->diffs[$d] = $diff;
  5825. }
  5826. $this->setFontSubBuffer($fontkey, 'diff', $d);
  5827. }
  5828. if (!$this->empty_string($file)) {
  5829. if (!isset($this->FontFiles[$file])) {
  5830. if ((strcasecmp($type, 'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  5831. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  5832. } elseif ($type != 'core') {
  5833. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  5834. }
  5835. } else {
  5836. // update fontkeys that are sharing this font file
  5837. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  5838. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  5839. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  5840. }
  5841. }
  5842. }
  5843. return $fontdata;
  5844. }
  5845. /**
  5846. * Sets the font used to print character strings.
  5847. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  5848. * The method can be called before the first page is created and the font is retained from page to page.
  5849. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  5850. * 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 />
  5851. * @param $family (string) Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
  5852. * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li><li>O: overline</li></ul> or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
  5853. * @param $size (float) Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
  5854. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  5855. * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  5856. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  5857. * @author Nicola Asuni
  5858. * @public
  5859. * @since 1.0
  5860. * @see AddFont(), SetFontSize()
  5861. */
  5862. public function SetFont($family, $style = '', $size = null, $fontfile = '', $subset = 'default', $out = true) {
  5863. //Select a font; size given in points
  5864. if ($size === null) {
  5865. $size = $this->FontSizePt;
  5866. }
  5867. if ($size < 0) {
  5868. $size = 0;
  5869. }
  5870. // try to add font (if not already added)
  5871. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  5872. $this->FontFamily = $fontdata['family'];
  5873. $this->FontStyle = $fontdata['style'];
  5874. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  5875. $this->SetFontSize($size, $out);
  5876. }
  5877. /**
  5878. * Defines the size of the current font.
  5879. * @param $size (float) The font size in points.
  5880. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  5881. * @public
  5882. * @since 1.0
  5883. * @see SetFont()
  5884. */
  5885. public function SetFontSize($size, $out = true) {
  5886. // font size in points
  5887. $this->FontSizePt = $size;
  5888. // font size in user units
  5889. $this->FontSize = $size / $this->k;
  5890. // calculate some font metrics
  5891. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  5892. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  5893. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  5894. } else {
  5895. $font_height = $size * 1.219;
  5896. }
  5897. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  5898. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  5899. }
  5900. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  5901. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  5902. }
  5903. if (!isset($font_ascent) AND !isset($font_descent)) {
  5904. // core font
  5905. $font_ascent = 0.76 * $font_height;
  5906. $font_descent = $font_height - $font_ascent;
  5907. } elseif (!isset($font_descent)) {
  5908. $font_descent = $font_height - $font_ascent;
  5909. } elseif (!isset($font_ascent)) {
  5910. $font_ascent = $font_height - $font_descent;
  5911. }
  5912. $this->FontAscent = ($font_ascent / $this->k);
  5913. $this->FontDescent = ($font_descent / $this->k);
  5914. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  5915. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  5916. }
  5917. }
  5918. /**
  5919. * Returns the bounding box of the current font in user units.
  5920. * @return array
  5921. * @public
  5922. * @since 5.9.152 (2012-03-23)
  5923. */
  5924. public function getFontBBox() {
  5925. $fbbox = array();
  5926. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  5927. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  5928. $fbbox = array_map(array($this, 'getAbsFontMeasure'), $tmpbbox);
  5929. } else {
  5930. // Find max width
  5931. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  5932. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  5933. } else {
  5934. $maxw = 0;
  5935. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  5936. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  5937. }
  5938. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  5939. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  5940. }
  5941. if (isset($this->CurrentFont['dw'])) {
  5942. $maxw = max($maxw, $this->CurrentFont['dw']);
  5943. }
  5944. foreach ($this->CurrentFont['cw'] as $char => $w) {
  5945. $maxw = max($maxw, $w);
  5946. }
  5947. if ($maxw == 0) {
  5948. $maxw = 600;
  5949. }
  5950. $maxw = $this->getAbsFontMeasure($maxw);
  5951. }
  5952. $fbbox = array(0, -$this->FontDescent, $maxw, $this->FontAscent);
  5953. }
  5954. return $fbbox;
  5955. }
  5956. /**
  5957. * Convert a relative font measure into absolute value.
  5958. * @param $s (int) Font measure.
  5959. * @return float Absolute measure.
  5960. * @since 5.9.186 (2012-09-13)
  5961. */
  5962. public function getAbsFontMeasure($s) {
  5963. return ($s * $this->FontSize / 1000);
  5964. }
  5965. /**
  5966. * Returns the glyph bounding box of the specified character in the current font in user units.
  5967. * @param $char (int) Input character code.
  5968. * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  5969. * @since 5.9.186 (2012-09-13)
  5970. */
  5971. public function getCharBBox($char) {
  5972. if (isset($this->CurrentFont['cbbox'][$char])) {
  5973. return array_map(array($this, 'getAbsFontMeasure'), $this->CurrentFont['cbbox'][intval($char)]);
  5974. }
  5975. return false;
  5976. }
  5977. /**
  5978. * Return the font descent value
  5979. * @param $font (string) font name
  5980. * @param $style (string) font style
  5981. * @param $size (float) The size (in points)
  5982. * @return int font descent
  5983. * @public
  5984. * @author Nicola Asuni
  5985. * @since 4.9.003 (2010-03-30)
  5986. */
  5987. public function getFontDescent($font, $style = '', $size = 0) {
  5988. $fontdata = $this->AddFont($font, $style);
  5989. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  5990. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  5991. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  5992. } else {
  5993. $descent = (1.219 * 0.24 * $size);
  5994. }
  5995. return ($descent / $this->k);
  5996. }
  5997. /**
  5998. * Return the font ascent value.
  5999. * @param $font (string) font name
  6000. * @param $style (string) font style
  6001. * @param $size (float) The size (in points)
  6002. * @return int font ascent
  6003. * @public
  6004. * @author Nicola Asuni
  6005. * @since 4.9.003 (2010-03-30)
  6006. */
  6007. public function getFontAscent($font, $style = '', $size = 0) {
  6008. $fontdata = $this->AddFont($font, $style);
  6009. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  6010. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  6011. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  6012. } else {
  6013. $ascent = 1.219 * 0.76 * $size;
  6014. }
  6015. return ($ascent / $this->k);
  6016. }
  6017. /**
  6018. * Return true in the character is present in the specified font.
  6019. * @param $char (mixed) Character to check (integer value or string)
  6020. * @param $font (string) Font name (family name).
  6021. * @param $style (string) Font style.
  6022. * @return (boolean) true if the char is defined, false otherwise.
  6023. * @public
  6024. * @since 5.9.153 (2012-03-28)
  6025. */
  6026. public function isCharDefined($char, $font = '', $style = '') {
  6027. if (is_string($char)) {
  6028. // get character code
  6029. $char = $this->UTF8StringToArray($char);
  6030. $char = $char[0];
  6031. }
  6032. if ($this->empty_string($font)) {
  6033. if ($this->empty_string($style)) {
  6034. return (isset($this->CurrentFont['cw'][intval($char)]));
  6035. }
  6036. $font = $this->FontFamily;
  6037. }
  6038. $fontdata = $this->AddFont($font, $style);
  6039. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  6040. return (isset($fontinfo['cw'][intval($char)]));
  6041. }
  6042. /**
  6043. * Replace missing font characters on selected font with specified substitutions.
  6044. * @param $text (string) Text to process.
  6045. * @param $font (string) Font name (family name).
  6046. * @param $style (string) Font style.
  6047. * @param $subs (array) Array of possible character substitutions. The key is the character to check (integer value) and the value is a single intege value or an array of possible substitutes.
  6048. * @return (string) Processed text.
  6049. * @public
  6050. * @since 5.9.153 (2012-03-28)
  6051. */
  6052. public function replaceMissingChars($text, $font = '', $style = '', $subs = array()) {
  6053. if (empty($subs)) {
  6054. return $text;
  6055. }
  6056. if ($this->empty_string($font)) {
  6057. $font = $this->FontFamily;
  6058. }
  6059. $fontdata = $this->AddFont($font, $style);
  6060. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  6061. $uniarr = $this->UTF8StringToArray($text);
  6062. foreach ($uniarr as $k => $chr) {
  6063. if (!isset($fontinfo['cw'][$chr])) {
  6064. // this character is missing on the selected font
  6065. if (isset($subs[$chr])) {
  6066. // we have available substitutions
  6067. if (is_array($subs[$chr])) {
  6068. foreach ($subs[$chr] as $s) {
  6069. if (isset($fontinfo['cw'][$s])) {
  6070. $uniarr[$k] = $s;
  6071. break;
  6072. }
  6073. }
  6074. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  6075. $uniarr[$k] = $subs[$chr];
  6076. }
  6077. }
  6078. }
  6079. }
  6080. return $this->UniArrSubString($this->UTF8ArrayToUniArray($uniarr));
  6081. }
  6082. /**
  6083. * Defines the default monospaced font.
  6084. * @param $font (string) Font name.
  6085. * @public
  6086. * @since 4.5.025
  6087. */
  6088. public function SetDefaultMonospacedFont($font) {
  6089. $this->default_monospaced_font = $font;
  6090. }
  6091. /**
  6092. * 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 />
  6093. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  6094. * @public
  6095. * @since 1.5
  6096. * @see Cell(), Write(), Image(), Link(), SetLink()
  6097. */
  6098. public function AddLink() {
  6099. //Create a new internal link
  6100. $n = count($this->links) + 1;
  6101. $this->links[$n] = array(0, 0);
  6102. return $n;
  6103. }
  6104. /**
  6105. * Defines the page and position a link points to.
  6106. * @param $link (int) The link identifier returned by AddLink()
  6107. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  6108. * @param $page (int) Number of target page; -1 indicates the current page. This is the default value
  6109. * @public
  6110. * @since 1.5
  6111. * @see AddLink()
  6112. */
  6113. public function SetLink($link, $y = 0, $page = -1) {
  6114. if ($y == -1) {
  6115. $y = $this->y;
  6116. }
  6117. if ($page == -1) {
  6118. $page = $this->page;
  6119. }
  6120. $this->links[$link] = array($page, $y);
  6121. }
  6122. /**
  6123. * Puts a link on a rectangular area of the page.
  6124. * 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.
  6125. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  6126. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  6127. * @param $w (float) Width of the rectangle
  6128. * @param $h (float) Height of the rectangle
  6129. * @param $link (mixed) URL or identifier returned by AddLink()
  6130. * @param $spaces (int) number of spaces on the text to link
  6131. * @public
  6132. * @since 1.5
  6133. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  6134. */
  6135. public function Link($x, $y, $w, $h, $link, $spaces = 0) {
  6136. $this->Annotation($x, $y, $w, $h, $link, array('Subtype' => 'Link'), $spaces);
  6137. }
  6138. /**
  6139. * Puts a markup annotation on a rectangular area of the page.
  6140. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  6141. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  6142. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  6143. * @param $w (float) Width of the rectangle
  6144. * @param $h (float) Height of the rectangle
  6145. * @param $text (string) annotation text or alternate content
  6146. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  6147. * @param $spaces (int) number of spaces on the text to link
  6148. * @public
  6149. * @since 4.0.018 (2008-08-06)
  6150. */
  6151. public function Annotation($x, $y, $w, $h, $text, $opt = array('Subtype' => 'Text'), $spaces = 0) {
  6152. if ($this->inxobj) {
  6153. // store parameters for later use on template
  6154. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  6155. return;
  6156. }
  6157. if ($x === '') {
  6158. $x = $this->x;
  6159. }
  6160. if ($y === '') {
  6161. $y = $this->y;
  6162. }
  6163. // check page for no-write regions and adapt page margins if necessary
  6164. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  6165. // recalculate coordinates to account for graphic transformations
  6166. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  6167. for ($i = $this->transfmatrix_key; $i > 0; --$i) {
  6168. $maxid = count($this->transfmatrix[$i]) - 1;
  6169. for ($j = $maxid; $j >= 0; --$j) {
  6170. $ctm = $this->transfmatrix[$i][$j];
  6171. if (isset($ctm['a'])) {
  6172. $x = $x * $this->k;
  6173. $y = ($this->h - $y) * $this->k;
  6174. $w = $w * $this->k;
  6175. $h = $h * $this->k;
  6176. // top left
  6177. $xt = $x;
  6178. $yt = $y;
  6179. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6180. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6181. // top right
  6182. $xt = $x + $w;
  6183. $yt = $y;
  6184. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6185. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6186. // bottom left
  6187. $xt = $x;
  6188. $yt = $y - $h;
  6189. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6190. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6191. // bottom right
  6192. $xt = $x + $w;
  6193. $yt = $y - $h;
  6194. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6195. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6196. // new coordinates (rectangle area)
  6197. $x = min($x1, $x2, $x3, $x4);
  6198. $y = max($y1, $y2, $y3, $y4);
  6199. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  6200. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  6201. $x = $x / $this->k;
  6202. $y = $this->h - ($y / $this->k);
  6203. }
  6204. }
  6205. }
  6206. }
  6207. if ($this->page <= 0) {
  6208. $page = 1;
  6209. } else {
  6210. $page = $this->page;
  6211. }
  6212. if (!isset($this->PageAnnots[$page])) {
  6213. $this->PageAnnots[$page] = array();
  6214. }
  6215. ++$this->n;
  6216. $this->PageAnnots[$page][] = array('n' => $this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  6217. if (!$this->pdfa_mode) {
  6218. 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'])]))) {
  6219. ++$this->n;
  6220. $this->embeddedfiles[basename($opt['FS'])] = array('n' => $this->n, 'file' => $opt['FS']);
  6221. }
  6222. }
  6223. // Add widgets annotation's icons
  6224. if (isset($opt['mk']['i']) AND file_exists($opt['mk']['i'])) {
  6225. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  6226. }
  6227. if (isset($opt['mk']['ri']) AND file_exists($opt['mk']['ri'])) {
  6228. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  6229. }
  6230. if (isset($opt['mk']['ix']) AND file_exists($opt['mk']['ix'])) {
  6231. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  6232. }
  6233. }
  6234. /**
  6235. * Embedd the attached files.
  6236. * @since 4.4.000 (2008-12-07)
  6237. * @protected
  6238. * @see Annotation()
  6239. */
  6240. protected function _putEmbeddedFiles() {
  6241. if ($this->pdfa_mode) {
  6242. // embedded files are not allowed in PDF/A mode
  6243. return;
  6244. }
  6245. reset($this->embeddedfiles);
  6246. foreach ($this->embeddedfiles as $filename => $filedata) {
  6247. $data = file_get_contents($filedata['file']);
  6248. $filter = '';
  6249. if ($this->compress) {
  6250. $data = gzcompress($data);
  6251. $filter = ' /Filter /FlateDecode';
  6252. }
  6253. $stream = $this->_getrawstream($data, $filedata['n']);
  6254. $out = $this->_getobj($filedata['n']) . "\n";
  6255. $out .= '<< /Type /EmbeddedFile' . $filter . ' /Length ' . strlen($stream) . ' >>';
  6256. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  6257. $out .= "\n" . 'endobj';
  6258. $this->_out($out);
  6259. }
  6260. }
  6261. /**
  6262. * Prints a text cell at the specified position.
  6263. * This method allows to place a string precisely on the page.
  6264. * @param $x (float) Abscissa of the cell origin
  6265. * @param $y (float) Ordinate of the cell origin
  6266. * @param $txt (string) String to print
  6267. * @param $fstroke (int) outline size in user units (false = disable)
  6268. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  6269. * @param $ffill (boolean) if true fills the text
  6270. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6271. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6272. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6273. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6274. * @param $link (mixed) URL or identifier returned by AddLink().
  6275. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6276. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  6277. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li><li>B : cell bottom</li></ul>
  6278. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  6279. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  6280. * @public
  6281. * @since 1.0
  6282. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  6283. */
  6284. public function Text($x, $y, $txt, $fstroke = false, $fclip = false, $ffill = true, $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M', $rtloff = false) {
  6285. $textrendermode = $this->textrendermode;
  6286. $textstrokewidth = $this->textstrokewidth;
  6287. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  6288. $this->SetXY($x, $y, $rtloff);
  6289. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  6290. // restore previous rendering mode
  6291. $this->textrendermode = $textrendermode;
  6292. $this->textstrokewidth = $textstrokewidth;
  6293. }
  6294. /**
  6295. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  6296. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  6297. * This method is called automatically and should not be called directly by the application.
  6298. * @return boolean
  6299. * @public
  6300. * @since 1.4
  6301. * @see SetAutoPageBreak()
  6302. */
  6303. public function AcceptPageBreak() {
  6304. if ($this->num_columns > 1) {
  6305. // multi column mode
  6306. if ($this->current_column < ($this->num_columns - 1)) {
  6307. // go to next column
  6308. $this->selectColumn($this->current_column + 1);
  6309. } elseif ($this->AutoPageBreak) {
  6310. // add a new page
  6311. $this->AddPage();
  6312. // set first column
  6313. $this->selectColumn(0);
  6314. }
  6315. // avoid page breaking from checkPageBreak()
  6316. return false;
  6317. }
  6318. return $this->AutoPageBreak;
  6319. }
  6320. /**
  6321. * Add page if needed.
  6322. * @param $h (float) Cell height. Default value: 0.
  6323. * @param $y (mixed) starting y position, leave empty for current position.
  6324. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  6325. * @return boolean true in case of page break, false otherwise.
  6326. * @since 3.2.000 (2008-07-01)
  6327. * @protected
  6328. */
  6329. protected function checkPageBreak($h = 0, $y = '', $addpage = true) {
  6330. if ($this->empty_string($y)) {
  6331. $y = $this->y;
  6332. }
  6333. $current_page = $this->page;
  6334. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  6335. if ($addpage) {
  6336. //Automatic page break
  6337. $x = $this->x;
  6338. $this->AddPage($this->CurOrientation);
  6339. $this->y = $this->tMargin;
  6340. $oldpage = $this->page - 1;
  6341. if ($this->rtl) {
  6342. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  6343. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  6344. } else {
  6345. $this->x = $x;
  6346. }
  6347. } else {
  6348. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  6349. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  6350. } else {
  6351. $this->x = $x;
  6352. }
  6353. }
  6354. }
  6355. return true;
  6356. }
  6357. if ($current_page != $this->page) {
  6358. // account for columns mode
  6359. return true;
  6360. }
  6361. return false;
  6362. }
  6363. /**
  6364. * Removes SHY characters from text.
  6365. * Unicode Data:<ul>
  6366. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  6367. * <li>HTML Entity (decimal): "&amp;#173;"</li>
  6368. * <li>HTML Entity (hex): "&amp;#xad;"</li>
  6369. * <li>HTML Entity (named): "&amp;shy;"</li>
  6370. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  6371. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  6372. * <li>UTF-8 character: chr(194).chr(173)</li>
  6373. * </ul>
  6374. * @param $txt (string) input string
  6375. * @return string without SHY characters.
  6376. * @public
  6377. * @since (4.5.019) 2009-02-28
  6378. */
  6379. public function removeSHY($txt = '') {
  6380. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  6381. if (!$this->isunicode) {
  6382. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  6383. }
  6384. return $txt;
  6385. }
  6386. /**
  6387. * 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 />
  6388. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  6389. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  6390. * @param $h (float) Cell height. Default value: 0.
  6391. * @param $txt (string) String to print. Default value: empty string.
  6392. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6393. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6394. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6395. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6396. * @param $link (mixed) URL or identifier returned by AddLink().
  6397. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6398. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  6399. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  6400. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  6401. * @public
  6402. * @since 1.0
  6403. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  6404. */
  6405. public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M') {
  6406. $prev_cell_margin = $this->cell_margin;
  6407. $prev_cell_padding = $this->cell_padding;
  6408. $this->adjustCellPadding($border);
  6409. if (!$ignore_min_height) {
  6410. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  6411. if ($h < $min_cell_height) {
  6412. $h = $min_cell_height;
  6413. }
  6414. }
  6415. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  6416. // apply text shadow if enabled
  6417. if ($this->txtshadow['enabled']) {
  6418. // save data
  6419. $x = $this->x;
  6420. $y = $this->y;
  6421. $bc = $this->bgcolor;
  6422. $fc = $this->fgcolor;
  6423. $sc = $this->strokecolor;
  6424. $alpha = $this->alpha;
  6425. // print shadow
  6426. $this->x += $this->txtshadow['depth_w'];
  6427. $this->y += $this->txtshadow['depth_h'];
  6428. $this->SetFillColorArray($this->txtshadow['color']);
  6429. $this->SetTextColorArray($this->txtshadow['color']);
  6430. $this->SetDrawColorArray($this->txtshadow['color']);
  6431. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  6432. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  6433. }
  6434. if ($this->state == 2) {
  6435. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  6436. }
  6437. //restore data
  6438. $this->x = $x;
  6439. $this->y = $y;
  6440. $this->SetFillColorArray($bc);
  6441. $this->SetTextColorArray($fc);
  6442. $this->SetDrawColorArray($sc);
  6443. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  6444. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  6445. }
  6446. }
  6447. if ($this->state == 2) {
  6448. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  6449. }
  6450. $this->cell_padding = $prev_cell_padding;
  6451. $this->cell_margin = $prev_cell_margin;
  6452. }
  6453. /**
  6454. * 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 />
  6455. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  6456. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  6457. * @param $h (float) Cell height. Default value: 0.
  6458. * @param $txt (string) String to print. Default value: empty string.
  6459. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6460. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6461. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6462. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6463. * @param $link (mixed) URL or identifier returned by AddLink().
  6464. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6465. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  6466. * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  6467. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  6468. * @return string containing cell code
  6469. * @protected
  6470. * @since 1.0
  6471. * @see Cell()
  6472. */
  6473. protected function getCellCode($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M') {
  6474. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  6475. $txt = str_replace($this->unichr(160), ' ', $txt);
  6476. $prev_cell_margin = $this->cell_margin;
  6477. $prev_cell_padding = $this->cell_padding;
  6478. $txt = $this->removeSHY($txt);
  6479. $rs = ''; //string to be returned
  6480. $this->adjustCellPadding($border);
  6481. if (!$ignore_min_height) {
  6482. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  6483. if ($h < $min_cell_height) {
  6484. $h = $min_cell_height;
  6485. }
  6486. }
  6487. $k = $this->k;
  6488. // check page for no-write regions and adapt page margins if necessary
  6489. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  6490. if ($this->rtl) {
  6491. $x = $this->x - $this->cell_margin['R'];
  6492. } else {
  6493. $x = $this->x + $this->cell_margin['L'];
  6494. }
  6495. $y = $this->y + $this->cell_margin['T'];
  6496. $prev_font_stretching = $this->font_stretching;
  6497. $prev_font_spacing = $this->font_spacing;
  6498. // cell vertical alignment
  6499. switch ($calign) {
  6500. case 'A': {
  6501. // font top
  6502. switch ($valign) {
  6503. case 'T': {
  6504. // top
  6505. $y -= $this->cell_padding['T'];
  6506. break;
  6507. }
  6508. case 'B': {
  6509. // bottom
  6510. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  6511. break;
  6512. }
  6513. default:
  6514. case 'C':
  6515. case 'M': {
  6516. // center
  6517. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  6518. break;
  6519. }
  6520. }
  6521. break;
  6522. }
  6523. case 'L': {
  6524. // font baseline
  6525. switch ($valign) {
  6526. case 'T': {
  6527. // top
  6528. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  6529. break;
  6530. }
  6531. case 'B': {
  6532. // bottom
  6533. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  6534. break;
  6535. }
  6536. default:
  6537. case 'C':
  6538. case 'M': {
  6539. // center
  6540. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  6541. break;
  6542. }
  6543. }
  6544. break;
  6545. }
  6546. case 'D': {
  6547. // font bottom
  6548. switch ($valign) {
  6549. case 'T': {
  6550. // top
  6551. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  6552. break;
  6553. }
  6554. case 'B': {
  6555. // bottom
  6556. $y -= ($h - $this->cell_padding['B']);
  6557. break;
  6558. }
  6559. default:
  6560. case 'C':
  6561. case 'M': {
  6562. // center
  6563. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  6564. break;
  6565. }
  6566. }
  6567. break;
  6568. }
  6569. case 'B': {
  6570. // cell bottom
  6571. $y -= $h;
  6572. break;
  6573. }
  6574. case 'C':
  6575. case 'M': {
  6576. // cell center
  6577. $y -= ($h / 2);
  6578. break;
  6579. }
  6580. default:
  6581. case 'T': {
  6582. // cell top
  6583. break;
  6584. }
  6585. }
  6586. // text vertical alignment
  6587. switch ($valign) {
  6588. case 'T': {
  6589. // top
  6590. $yt = $y + $this->cell_padding['T'];
  6591. break;
  6592. }
  6593. case 'B': {
  6594. // bottom
  6595. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  6596. break;
  6597. }
  6598. default:
  6599. case 'C':
  6600. case 'M': {
  6601. // center
  6602. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  6603. break;
  6604. }
  6605. }
  6606. $basefonty = $yt + $this->FontAscent;
  6607. if ($this->empty_string($w) OR ($w <= 0)) {
  6608. if ($this->rtl) {
  6609. $w = $x - $this->lMargin;
  6610. } else {
  6611. $w = $this->w - $this->rMargin - $x;
  6612. }
  6613. }
  6614. $s = '';
  6615. // fill and borders
  6616. if (is_string($border) AND (strlen($border) == 4)) {
  6617. // full border
  6618. $border = 1;
  6619. }
  6620. if ($fill OR ($border == 1)) {
  6621. if ($fill) {
  6622. $op = ($border == 1) ? 'B' : 'f';
  6623. } else {
  6624. $op = 'S';
  6625. }
  6626. if ($this->rtl) {
  6627. $xk = (($x - $w) * $k);
  6628. } else {
  6629. $xk = ($x * $k);
  6630. }
  6631. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  6632. }
  6633. // draw borders
  6634. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  6635. if ($txt != '') {
  6636. $txt2 = $txt;
  6637. if ($this->isunicode) {
  6638. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  6639. $txt2 = $this->UTF8ToLatin1($txt2);
  6640. } else {
  6641. $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
  6642. $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
  6643. // replace thai chars (if any)
  6644. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  6645. // number of chars
  6646. $numchars = count($unicode);
  6647. // po pla, for far, for fan
  6648. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  6649. // do chada, to patak
  6650. $lowtail = array(0x0e0e, 0x0e0f);
  6651. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  6652. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  6653. // mai ek, mai tho, mai tri, mai chattawa, karan
  6654. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  6655. // sara u, sara uu, pinthu
  6656. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  6657. $output = array();
  6658. for ($i = 0; $i < $numchars; $i++) {
  6659. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  6660. $ch0 = $unicode[$i];
  6661. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  6662. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  6663. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  6664. if (in_array($ch0, $tonemark)) {
  6665. if ($chn == 0x0e33) {
  6666. // sara um
  6667. if (in_array($ch1, $longtail)) {
  6668. // tonemark at upper left
  6669. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  6670. } else {
  6671. // tonemark at upper right (normal position)
  6672. $output[] = $ch0;
  6673. }
  6674. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  6675. // tonemark at lower left
  6676. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  6677. } elseif (in_array($ch1, $upvowel)) {
  6678. if (in_array($ch2, $longtail)) {
  6679. // tonemark at upper left
  6680. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  6681. } else {
  6682. // tonemark at upper right (normal position)
  6683. $output[] = $ch0;
  6684. }
  6685. } else {
  6686. // tonemark at lower right
  6687. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  6688. }
  6689. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  6690. // add lower left nikhahit and sara aa
  6691. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  6692. $output[] = 0xf711;
  6693. $this->CurrentFont['subsetchars'][0xf711] = true;
  6694. $output[] = 0x0e32;
  6695. $this->CurrentFont['subsetchars'][0x0e32] = true;
  6696. } else {
  6697. $output[] = $ch0;
  6698. }
  6699. } elseif (in_array($ch1, $longtail)) {
  6700. if ($ch0 == 0x0e31) {
  6701. // lower left mai hun arkad
  6702. $output[] = $this->replaceChar($ch0, 0xf710);
  6703. } elseif (in_array($ch0, $upvowel)) {
  6704. // lower left
  6705. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  6706. } elseif ($ch0 == 0x0e47) {
  6707. // lower left mai tai koo
  6708. $output[] = $this->replaceChar($ch0, 0xf712);
  6709. } else {
  6710. // normal character
  6711. $output[] = $ch0;
  6712. }
  6713. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  6714. // lower vowel
  6715. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  6716. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  6717. // yo ying without lower part
  6718. $output[] = $this->replaceChar($ch0, 0xf70f);
  6719. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  6720. // tho santan without lower part
  6721. $output[] = $this->replaceChar($ch0, 0xf700);
  6722. } else {
  6723. $output[] = $ch0;
  6724. }
  6725. } else {
  6726. // non-thai character
  6727. $output[] = $unicode[$i];
  6728. }
  6729. }
  6730. $unicode = $output;
  6731. // update font subsetchars
  6732. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  6733. } // end of K_THAI_TOPCHARS
  6734. $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
  6735. }
  6736. }
  6737. $txt2 = $this->_escape($txt2);
  6738. // get current text width (considering general font stretching and spacing)
  6739. $txwidth = $this->GetStringWidth($txt);
  6740. $width = $txwidth;
  6741. // check for stretch mode
  6742. if ($stretch > 0) {
  6743. // calculate ratio between cell width and text width
  6744. if ($width <= 0) {
  6745. $ratio = 1;
  6746. } else {
  6747. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  6748. }
  6749. // check if stretching is required
  6750. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  6751. // the text will be stretched to fit cell width
  6752. if ($stretch > 2) {
  6753. // set new character spacing
  6754. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  6755. } else {
  6756. // set new horizontal stretching
  6757. $this->font_stretching *= $ratio;
  6758. }
  6759. // recalculate text width (the text fills the entire cell)
  6760. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6761. // reset alignment
  6762. $align = '';
  6763. }
  6764. }
  6765. if ($this->font_stretching != 100) {
  6766. // apply font stretching
  6767. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  6768. }
  6769. if ($this->font_spacing != 0) {
  6770. // increase/decrease font spacing
  6771. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  6772. }
  6773. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  6774. $s .= 'q ' . $this->TextColor . ' ';
  6775. }
  6776. // rendering mode
  6777. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  6778. // count number of spaces
  6779. $ns = substr_count($txt, chr(32));
  6780. // Justification
  6781. $spacewidth = 0;
  6782. if (($align == 'J') AND ($ns > 0)) {
  6783. if ($this->isUnicodeFont()) {
  6784. // get string width without spaces
  6785. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  6786. // calculate average space width
  6787. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1) / $this->FontSize;
  6788. if ($this->font_stretching != 100) {
  6789. // word spacing is affected by stretching
  6790. $spacewidth /= ($this->font_stretching / 100);
  6791. }
  6792. // set word position to be used with TJ operator
  6793. $txt2 = str_replace(chr(0) . chr(32), ') ' . sprintf('%F', $spacewidth) . ' (', $txt2);
  6794. $unicode_justification = true;
  6795. } else {
  6796. // get string width
  6797. $width = $txwidth;
  6798. // new space width
  6799. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1)) * $this->k;
  6800. if ($this->font_stretching != 100) {
  6801. // word spacing (Tw) is affected by stretching
  6802. $spacewidth /= ($this->font_stretching / 100);
  6803. }
  6804. // set word spacing
  6805. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  6806. }
  6807. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6808. }
  6809. // replace carriage return characters
  6810. $txt2 = str_replace("\r", ' ', $txt2);
  6811. switch ($align) {
  6812. case 'C': {
  6813. $dx = ($w - $width) / 2;
  6814. break;
  6815. }
  6816. case 'R': {
  6817. if ($this->rtl) {
  6818. $dx = $this->cell_padding['R'];
  6819. } else {
  6820. $dx = $w - $width - $this->cell_padding['R'];
  6821. }
  6822. break;
  6823. }
  6824. case 'L': {
  6825. if ($this->rtl) {
  6826. $dx = $w - $width - $this->cell_padding['L'];
  6827. } else {
  6828. $dx = $this->cell_padding['L'];
  6829. }
  6830. break;
  6831. }
  6832. case 'J':
  6833. default: {
  6834. if ($this->rtl) {
  6835. $dx = $this->cell_padding['R'];
  6836. } else {
  6837. $dx = $this->cell_padding['L'];
  6838. }
  6839. break;
  6840. }
  6841. }
  6842. if ($this->rtl) {
  6843. $xdx = $x - $dx - $width;
  6844. } else {
  6845. $xdx = $x + $dx;
  6846. }
  6847. $xdk = $xdx * $k;
  6848. // print text
  6849. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  6850. if (isset($uniblock)) {
  6851. // print overlapping characters as separate string
  6852. $xshift = 0; // horizontal shift
  6853. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  6854. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1));
  6855. foreach ($uniblock as $uk => $uniarr) {
  6856. if (($uk % 2) == 0) {
  6857. // x space to skip
  6858. if ($spacewidth != 0) {
  6859. // justification shift
  6860. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  6861. }
  6862. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  6863. } else {
  6864. // character to print
  6865. $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
  6866. $topchr = $this->_escape($topchr);
  6867. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  6868. }
  6869. }
  6870. }
  6871. if ($this->underline) {
  6872. $s .= ' ' . $this->_dounderlinew($xdx, $basefonty, $width);
  6873. }
  6874. if ($this->linethrough) {
  6875. $s .= ' ' . $this->_dolinethroughw($xdx, $basefonty, $width);
  6876. }
  6877. if ($this->overline) {
  6878. $s .= ' ' . $this->_dooverlinew($xdx, $basefonty, $width);
  6879. }
  6880. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  6881. $s .= ' Q';
  6882. }
  6883. if ($link) {
  6884. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  6885. }
  6886. }
  6887. // output cell
  6888. if ($s) {
  6889. // output cell
  6890. $rs .= $s;
  6891. if ($this->font_spacing != 0) {
  6892. // reset font spacing mode
  6893. $rs .= ' BT 0 Tc ET';
  6894. }
  6895. if ($this->font_stretching != 100) {
  6896. // reset font stretching mode
  6897. $rs .= ' BT 100 Tz ET';
  6898. }
  6899. }
  6900. // reset word spacing
  6901. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  6902. $rs .= ' BT 0 Tw ET';
  6903. }
  6904. // reset stretching and spacing
  6905. $this->font_stretching = $prev_font_stretching;
  6906. $this->font_spacing = $prev_font_spacing;
  6907. $this->lasth = $h;
  6908. if ($ln > 0) {
  6909. //Go to the beginning of the next line
  6910. $this->y = $y + $h + $this->cell_margin['B'];
  6911. if ($ln == 1) {
  6912. if ($this->rtl) {
  6913. $this->x = $this->w - $this->rMargin;
  6914. } else {
  6915. $this->x = $this->lMargin;
  6916. }
  6917. }
  6918. } else {
  6919. // go left or right by case
  6920. if ($this->rtl) {
  6921. $this->x = $x - $w - $this->cell_margin['L'];
  6922. } else {
  6923. $this->x = $x + $w + $this->cell_margin['R'];
  6924. }
  6925. }
  6926. $gstyles = '' . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ' . $this->FillColor . "\n";
  6927. $rs = $gstyles . $rs;
  6928. $this->cell_padding = $prev_cell_padding;
  6929. $this->cell_margin = $prev_cell_margin;
  6930. return $rs;
  6931. }
  6932. /**
  6933. * Replace a char if is defined on the current font.
  6934. * @param $oldchar (int) Integer code (unicode) of the character to replace.
  6935. * @param $newchar (int) Integer code (unicode) of the new character.
  6936. * @return int the replaced char or the old char in case the new char i not defined
  6937. * @protected
  6938. * @since 5.9.167 (2012-06-22)
  6939. */
  6940. protected function replaceChar($oldchar, $newchar) {
  6941. if ($this->isCharDefined($newchar)) {
  6942. // add the new char on the subset list
  6943. $this->CurrentFont['subsetchars'][$newchar] = true;
  6944. // return the new character
  6945. return $newchar;
  6946. }
  6947. // return the old char
  6948. return $oldchar;
  6949. }
  6950. /**
  6951. * Returns the code to draw the cell border
  6952. * @param $x (float) X coordinate.
  6953. * @param $y (float) Y coordinate.
  6954. * @param $w (float) Cell width.
  6955. * @param $h (float) Cell height.
  6956. * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6957. * @return string containing cell border code
  6958. * @protected
  6959. * @see SetLineStyle()
  6960. * @since 5.7.000 (2010-08-02)
  6961. */
  6962. protected function getCellBorder($x, $y, $w, $h, $brd) {
  6963. $s = ''; // string to be returned
  6964. if (empty($brd)) {
  6965. return $s;
  6966. }
  6967. if ($brd == 1) {
  6968. $brd = array('LRTB' => true);
  6969. }
  6970. // calculate coordinates for border
  6971. $k = $this->k;
  6972. if ($this->rtl) {
  6973. $xeL = ($x - $w) * $k;
  6974. $xeR = $x * $k;
  6975. } else {
  6976. $xeL = $x * $k;
  6977. $xeR = ($x + $w) * $k;
  6978. }
  6979. $yeL = (($this->h - ($y + $h)) * $k);
  6980. $yeT = (($this->h - $y) * $k);
  6981. $xeT = $xeL;
  6982. $xeB = $xeR;
  6983. $yeR = $yeT;
  6984. $yeB = $yeL;
  6985. if (is_string($brd)) {
  6986. // convert string to array
  6987. $slen = strlen($brd);
  6988. $newbrd = array();
  6989. for ($i = 0; $i < $slen; ++$i) {
  6990. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  6991. }
  6992. $brd = $newbrd;
  6993. }
  6994. if (isset($brd['mode'])) {
  6995. $mode = $brd['mode'];
  6996. unset($brd['mode']);
  6997. } else {
  6998. $mode = 'normal';
  6999. }
  7000. foreach ($brd as $border => $style) {
  7001. if (is_array($style) AND !empty($style)) {
  7002. // apply border style
  7003. $prev_style = $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ';
  7004. $s .= $this->SetLineStyle($style, true) . "\n";
  7005. }
  7006. switch ($mode) {
  7007. case 'ext': {
  7008. $off = (($this->LineWidth / 2) * $k);
  7009. $xL = $xeL - $off;
  7010. $xR = $xeR + $off;
  7011. $yT = $yeT + $off;
  7012. $yL = $yeL - $off;
  7013. $xT = $xL;
  7014. $xB = $xR;
  7015. $yR = $yT;
  7016. $yB = $yL;
  7017. $w += $this->LineWidth;
  7018. $h += $this->LineWidth;
  7019. break;
  7020. }
  7021. case 'int': {
  7022. $off = ($this->LineWidth / 2) * $k;
  7023. $xL = $xeL + $off;
  7024. $xR = $xeR - $off;
  7025. $yT = $yeT - $off;
  7026. $yL = $yeL + $off;
  7027. $xT = $xL;
  7028. $xB = $xR;
  7029. $yR = $yT;
  7030. $yB = $yL;
  7031. $w -= $this->LineWidth;
  7032. $h -= $this->LineWidth;
  7033. break;
  7034. }
  7035. case 'normal':
  7036. default: {
  7037. $xL = $xeL;
  7038. $xT = $xeT;
  7039. $xB = $xeB;
  7040. $xR = $xeR;
  7041. $yL = $yeL;
  7042. $yT = $yeT;
  7043. $yB = $yeB;
  7044. $yR = $yeR;
  7045. break;
  7046. }
  7047. }
  7048. // draw borders by case
  7049. if (strlen($border) == 4) {
  7050. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  7051. } elseif (strlen($border) == 3) {
  7052. if (strpos($border, 'B') === false) { // LTR
  7053. $s .= sprintf('%F %F m ', $xL, $yL);
  7054. $s .= sprintf('%F %F l ', $xT, $yT);
  7055. $s .= sprintf('%F %F l ', $xR, $yR);
  7056. $s .= sprintf('%F %F l ', $xB, $yB);
  7057. $s .= 'S ';
  7058. } elseif (strpos($border, 'L') === false) { // TRB
  7059. $s .= sprintf('%F %F m ', $xT, $yT);
  7060. $s .= sprintf('%F %F l ', $xR, $yR);
  7061. $s .= sprintf('%F %F l ', $xB, $yB);
  7062. $s .= sprintf('%F %F l ', $xL, $yL);
  7063. $s .= 'S ';
  7064. } elseif (strpos($border, 'T') === false) { // RBL
  7065. $s .= sprintf('%F %F m ', $xR, $yR);
  7066. $s .= sprintf('%F %F l ', $xB, $yB);
  7067. $s .= sprintf('%F %F l ', $xL, $yL);
  7068. $s .= sprintf('%F %F l ', $xT, $yT);
  7069. $s .= 'S ';
  7070. } elseif (strpos($border, 'R') === false) { // BLT
  7071. $s .= sprintf('%F %F m ', $xB, $yB);
  7072. $s .= sprintf('%F %F l ', $xL, $yL);
  7073. $s .= sprintf('%F %F l ', $xT, $yT);
  7074. $s .= sprintf('%F %F l ', $xR, $yR);
  7075. $s .= 'S ';
  7076. }
  7077. } elseif (strlen($border) == 2) {
  7078. if ((strpos($border, 'L') !== false) AND (strpos($border, 'T') !== false)) { // LT
  7079. $s .= sprintf('%F %F m ', $xL, $yL);
  7080. $s .= sprintf('%F %F l ', $xT, $yT);
  7081. $s .= sprintf('%F %F l ', $xR, $yR);
  7082. $s .= 'S ';
  7083. } elseif ((strpos($border, 'T') !== false) AND (strpos($border, 'R') !== false)) { // TR
  7084. $s .= sprintf('%F %F m ', $xT, $yT);
  7085. $s .= sprintf('%F %F l ', $xR, $yR);
  7086. $s .= sprintf('%F %F l ', $xB, $yB);
  7087. $s .= 'S ';
  7088. } elseif ((strpos($border, 'R') !== false) AND (strpos($border, 'B') !== false)) { // RB
  7089. $s .= sprintf('%F %F m ', $xR, $yR);
  7090. $s .= sprintf('%F %F l ', $xB, $yB);
  7091. $s .= sprintf('%F %F l ', $xL, $yL);
  7092. $s .= 'S ';
  7093. } elseif ((strpos($border, 'B') !== false) AND (strpos($border, 'L') !== false)) { // BL
  7094. $s .= sprintf('%F %F m ', $xB, $yB);
  7095. $s .= sprintf('%F %F l ', $xL, $yL);
  7096. $s .= sprintf('%F %F l ', $xT, $yT);
  7097. $s .= 'S ';
  7098. } elseif ((strpos($border, 'L') !== false) AND (strpos($border, 'R') !== false)) { // LR
  7099. $s .= sprintf('%F %F m ', $xL, $yL);
  7100. $s .= sprintf('%F %F l ', $xT, $yT);
  7101. $s .= 'S ';
  7102. $s .= sprintf('%F %F m ', $xR, $yR);
  7103. $s .= sprintf('%F %F l ', $xB, $yB);
  7104. $s .= 'S ';
  7105. } elseif ((strpos($border, 'T') !== false) AND (strpos($border, 'B') !== false)) { // TB
  7106. $s .= sprintf('%F %F m ', $xT, $yT);
  7107. $s .= sprintf('%F %F l ', $xR, $yR);
  7108. $s .= 'S ';
  7109. $s .= sprintf('%F %F m ', $xB, $yB);
  7110. $s .= sprintf('%F %F l ', $xL, $yL);
  7111. $s .= 'S ';
  7112. }
  7113. } else { // strlen($border) == 1
  7114. if (strpos($border, 'L') !== false) { // L
  7115. $s .= sprintf('%F %F m ', $xL, $yL);
  7116. $s .= sprintf('%F %F l ', $xT, $yT);
  7117. $s .= 'S ';
  7118. } elseif (strpos($border, 'T') !== false) { // T
  7119. $s .= sprintf('%F %F m ', $xT, $yT);
  7120. $s .= sprintf('%F %F l ', $xR, $yR);
  7121. $s .= 'S ';
  7122. } elseif (strpos($border, 'R') !== false) { // R
  7123. $s .= sprintf('%F %F m ', $xR, $yR);
  7124. $s .= sprintf('%F %F l ', $xB, $yB);
  7125. $s .= 'S ';
  7126. } elseif (strpos($border, 'B') !== false) { // B
  7127. $s .= sprintf('%F %F m ', $xB, $yB);
  7128. $s .= sprintf('%F %F l ', $xL, $yL);
  7129. $s .= 'S ';
  7130. }
  7131. }
  7132. if (is_array($style) AND !empty($style)) {
  7133. // reset border style to previous value
  7134. $s .= "\n" . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . "\n";
  7135. }
  7136. }
  7137. return $s;
  7138. }
  7139. /**
  7140. * This method allows printing text with line breaks.
  7141. * 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 />
  7142. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  7143. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  7144. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  7145. * @param $txt (string) String to print
  7146. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7147. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
  7148. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  7149. * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  7150. * @param $x (float) x position in user units
  7151. * @param $y (float) y position in user units
  7152. * @param $reseth (boolean) if true reset the last cell height (default true).
  7153. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  7154. * @param $ishtml (boolean) INTERNAL USE ONLY -- set to true if $txt is HTML content (default = false). Never set this parameter to true, use instead writeHTMLCell() or writeHTML() methods.
  7155. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  7156. * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false.
  7157. * @param $valign (string) Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false and the cell must fit in a single page.
  7158. * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode).
  7159. * @return int Return the number of cells or 1 for html mode.
  7160. * @public
  7161. * @since 1.3
  7162. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  7163. */
  7164. public function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = false, $ln = 1, $x = '', $y = '', $reseth = true, $stretch = 0, $ishtml = false, $autopadding = true, $maxh = 0, $valign = 'T', $fitcell = false) {
  7165. $prev_cell_margin = $this->cell_margin;
  7166. $prev_cell_padding = $this->cell_padding;
  7167. // adjust internal padding
  7168. $this->adjustCellPadding($border);
  7169. $mc_padding = $this->cell_padding;
  7170. $mc_margin = $this->cell_margin;
  7171. $this->cell_padding['T'] = 0;
  7172. $this->cell_padding['B'] = 0;
  7173. $this->setCellMargins(0, 0, 0, 0);
  7174. if ($this->empty_string($this->lasth) OR $reseth) {
  7175. // reset row height
  7176. $this->resetLastH();
  7177. }
  7178. if (!$this->empty_string($y)) {
  7179. $this->SetY($y);
  7180. } else {
  7181. $y = $this->GetY();
  7182. }
  7183. $resth = 0;
  7184. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  7185. // spit cell in more pages/columns
  7186. $newh = ($this->PageBreakTrigger - $y);
  7187. $resth = ($h - $newh); // cell to be printed on the next page/column
  7188. $h = $newh;
  7189. }
  7190. // get current page number
  7191. $startpage = $this->page;
  7192. // get current column
  7193. $startcolumn = $this->current_column;
  7194. if (!$this->empty_string($x)) {
  7195. $this->SetX($x);
  7196. } else {
  7197. $x = $this->GetX();
  7198. }
  7199. // check page for no-write regions and adapt page margins if necessary
  7200. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  7201. // apply margins
  7202. $oy = $y + $mc_margin['T'];
  7203. if ($this->rtl) {
  7204. $ox = ($this->w - $x - $mc_margin['R']);
  7205. } else {
  7206. $ox = ($x + $mc_margin['L']);
  7207. }
  7208. $this->x = $ox;
  7209. $this->y = $oy;
  7210. // set width
  7211. if ($this->empty_string($w) OR ($w <= 0)) {
  7212. if ($this->rtl) {
  7213. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  7214. } else {
  7215. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  7216. }
  7217. }
  7218. // store original margin values
  7219. $lMargin = $this->lMargin;
  7220. $rMargin = $this->rMargin;
  7221. if ($this->rtl) {
  7222. $this->rMargin = ($this->w - $this->x);
  7223. $this->lMargin = ($this->x - $w);
  7224. } else {
  7225. $this->lMargin = ($this->x);
  7226. $this->rMargin = ($this->w - $this->x - $w);
  7227. }
  7228. $this->clMargin = $this->lMargin;
  7229. $this->crMargin = $this->rMargin;
  7230. if ($autopadding) {
  7231. // add top padding
  7232. $this->y += $mc_padding['T'];
  7233. }
  7234. if ($ishtml) { // ******* Write HTML text
  7235. $this->writeHTML($txt, true, false, $reseth, true, $align);
  7236. $nl = 1;
  7237. } else { // ******* Write simple text
  7238. $prev_FontSizePt = $this->FontSizePt;
  7239. // vertical alignment
  7240. if ($maxh > 0) {
  7241. // get text height
  7242. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  7243. if ($fitcell) {
  7244. // try to reduce font size to fit text on cell (use a quick search algorithm)
  7245. $fmin = 1;
  7246. $fmax = $this->FontSizePt;
  7247. $prev_text_height = $text_height;
  7248. $maxit = 100; // max number of iterations
  7249. while ($maxit > 0) {
  7250. $fmid = (($fmax + $fmin) / 2);
  7251. $this->SetFontSize($fmid, false);
  7252. $this->resetLastH();
  7253. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  7254. if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
  7255. break;
  7256. } elseif ($text_height < $maxh) {
  7257. $fmin = $fmid;
  7258. } else {
  7259. $fmax = $fmid;
  7260. }
  7261. --$maxit;
  7262. }
  7263. $this->SetFontSize($this->FontSizePt);
  7264. }
  7265. if ($text_height < $maxh) {
  7266. if ($valign == 'M') {
  7267. // text vertically centered
  7268. $this->y += (($maxh - $text_height) / 2);
  7269. } elseif ($valign == 'B') {
  7270. // text vertically aligned on bottom
  7271. $this->y += ($maxh - $text_height);
  7272. }
  7273. }
  7274. }
  7275. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  7276. if ($fitcell) {
  7277. // restore font size
  7278. $this->SetFontSize($prev_FontSizePt);
  7279. }
  7280. }
  7281. if ($autopadding) {
  7282. // add bottom padding
  7283. $this->y += $mc_padding['B'];
  7284. }
  7285. // Get end-of-text Y position
  7286. $currentY = $this->y;
  7287. // get latest page number
  7288. $endpage = $this->page;
  7289. if ($resth > 0) {
  7290. $skip = ($endpage - $startpage);
  7291. $tmpresth = $resth;
  7292. while ($tmpresth > 0) {
  7293. if ($skip <= 0) {
  7294. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  7295. $this->checkPageBreak($this->PageBreakTrigger + 1);
  7296. }
  7297. if ($this->num_columns > 1) {
  7298. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  7299. } else {
  7300. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  7301. }
  7302. --$skip;
  7303. }
  7304. $currentY = $this->y;
  7305. $endpage = $this->page;
  7306. }
  7307. // get latest column
  7308. $endcolumn = $this->current_column;
  7309. if ($this->num_columns == 0) {
  7310. $this->num_columns = 1;
  7311. }
  7312. // disable page regions check
  7313. $check_page_regions = $this->check_page_regions;
  7314. $this->check_page_regions = false;
  7315. // get border modes
  7316. $border_start = $this->getBorderMode($border, $position = 'start');
  7317. $border_end = $this->getBorderMode($border, $position = 'end');
  7318. $border_middle = $this->getBorderMode($border, $position = 'middle');
  7319. // design borders around HTML cells.
  7320. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  7321. $ccode = '';
  7322. $this->setPage($page);
  7323. if ($this->num_columns < 2) {
  7324. // single-column mode
  7325. $this->SetX($x);
  7326. $this->y = $this->tMargin;
  7327. }
  7328. // account for margin changes
  7329. if ($page > $startpage) {
  7330. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  7331. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  7332. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  7333. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  7334. }
  7335. }
  7336. if ($startpage == $endpage) {
  7337. // single page
  7338. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  7339. $this->selectColumn($column);
  7340. if ($this->rtl) {
  7341. $this->x -= $mc_margin['R'];
  7342. } else {
  7343. $this->x += $mc_margin['L'];
  7344. }
  7345. if ($startcolumn == $endcolumn) { // single column
  7346. $cborder = $border;
  7347. $h = max($h, ($currentY - $oy));
  7348. $this->y = $oy;
  7349. } elseif ($column == $startcolumn) { // first column
  7350. $cborder = $border_start;
  7351. $this->y = $oy;
  7352. $h = $this->h - $this->y - $this->bMargin;
  7353. } elseif ($column == $endcolumn) { // end column
  7354. $cborder = $border_end;
  7355. $h = $currentY - $this->y;
  7356. if ($resth > $h) {
  7357. $h = $resth;
  7358. }
  7359. } else { // middle column
  7360. $cborder = $border_middle;
  7361. $h = $this->h - $this->y - $this->bMargin;
  7362. $resth -= $h;
  7363. }
  7364. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7365. } // end for each column
  7366. } elseif ($page == $startpage) { // first page
  7367. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  7368. $this->selectColumn($column);
  7369. if ($this->rtl) {
  7370. $this->x -= $mc_margin['R'];
  7371. } else {
  7372. $this->x += $mc_margin['L'];
  7373. }
  7374. if ($column == $startcolumn) { // first column
  7375. $cborder = $border_start;
  7376. $this->y = $oy;
  7377. $h = $this->h - $this->y - $this->bMargin;
  7378. } else { // middle column
  7379. $cborder = $border_middle;
  7380. $h = $this->h - $this->y - $this->bMargin;
  7381. $resth -= $h;
  7382. }
  7383. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7384. } // end for each column
  7385. } elseif ($page == $endpage) { // last page
  7386. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  7387. $this->selectColumn($column);
  7388. if ($this->rtl) {
  7389. $this->x -= $mc_margin['R'];
  7390. } else {
  7391. $this->x += $mc_margin['L'];
  7392. }
  7393. if ($column == $endcolumn) {
  7394. // end column
  7395. $cborder = $border_end;
  7396. $h = $currentY - $this->y;
  7397. if ($resth > $h) {
  7398. $h = $resth;
  7399. }
  7400. } else {
  7401. // middle column
  7402. $cborder = $border_middle;
  7403. $h = $this->h - $this->y - $this->bMargin;
  7404. $resth -= $h;
  7405. }
  7406. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7407. } // end for each column
  7408. } else { // middle page
  7409. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  7410. $this->selectColumn($column);
  7411. if ($this->rtl) {
  7412. $this->x -= $mc_margin['R'];
  7413. } else {
  7414. $this->x += $mc_margin['L'];
  7415. }
  7416. $cborder = $border_middle;
  7417. $h = $this->h - $this->y - $this->bMargin;
  7418. $resth -= $h;
  7419. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7420. } // end for each column
  7421. }
  7422. if ($cborder OR $fill) {
  7423. $offsetlen = strlen($ccode);
  7424. // draw border and fill
  7425. if ($this->inxobj) {
  7426. // we are inside an XObject template
  7427. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  7428. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  7429. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  7430. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  7431. } else {
  7432. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  7433. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  7434. }
  7435. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  7436. $pstart = substr($pagebuff, 0, $pagemark);
  7437. $pend = substr($pagebuff, $pagemark);
  7438. $this->xobjects[$this->xobjid]['outdata'] = $pstart . $ccode . $pend;
  7439. } else {
  7440. if (end($this->transfmrk[$this->page]) !== false) {
  7441. $pagemarkkey = key($this->transfmrk[$this->page]);
  7442. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  7443. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  7444. } elseif ($this->InFooter) {
  7445. $pagemark = $this->footerpos[$this->page];
  7446. $this->footerpos[$this->page] += $offsetlen;
  7447. } else {
  7448. $pagemark = $this->intmrk[$this->page];
  7449. $this->intmrk[$this->page] += $offsetlen;
  7450. }
  7451. $pagebuff = $this->getPageBuffer($this->page);
  7452. $pstart = substr($pagebuff, 0, $pagemark);
  7453. $pend = substr($pagebuff, $pagemark);
  7454. $this->setPageBuffer($this->page, $pstart . $ccode . $pend);
  7455. }
  7456. }
  7457. } // end for each page
  7458. // restore page regions check
  7459. $this->check_page_regions = $check_page_regions;
  7460. // Get end-of-cell Y position
  7461. $currentY = $this->GetY();
  7462. // restore previous values
  7463. if ($this->num_columns > 1) {
  7464. $this->selectColumn();
  7465. } else {
  7466. // restore original margins
  7467. $this->lMargin = $lMargin;
  7468. $this->rMargin = $rMargin;
  7469. if ($this->page > $startpage) {
  7470. // check for margin variations between pages (i.e. booklet mode)
  7471. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  7472. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  7473. if (($dl != 0) OR ($dr != 0)) {
  7474. $this->lMargin += $dl;
  7475. $this->rMargin += $dr;
  7476. }
  7477. }
  7478. }
  7479. if ($ln > 0) {
  7480. //Go to the beginning of the next line
  7481. $this->SetY($currentY + $mc_margin['B']);
  7482. if ($ln == 2) {
  7483. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  7484. }
  7485. } else {
  7486. // go left or right by case
  7487. $this->setPage($startpage);
  7488. $this->y = $y;
  7489. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  7490. }
  7491. $this->setContentMark();
  7492. $this->cell_padding = $prev_cell_padding;
  7493. $this->cell_margin = $prev_cell_margin;
  7494. $this->clMargin = $this->lMargin;
  7495. $this->crMargin = $this->rMargin;
  7496. return $nl;
  7497. }
  7498. /**
  7499. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  7500. * @param $brd (mixed) Indicates if borders must be drawn around the cell block. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7501. * @param $position (string) multicell position: 'start', 'middle', 'end'
  7502. * @return border mode array
  7503. * @protected
  7504. * @since 4.4.002 (2008-12-09)
  7505. */
  7506. protected function getBorderMode($brd, $position = 'start') {
  7507. if ((!$this->opencell) OR empty($brd)) {
  7508. return $brd;
  7509. }
  7510. if ($brd == 1) {
  7511. $brd = 'LTRB';
  7512. }
  7513. if (is_string($brd)) {
  7514. // convert string to array
  7515. $slen = strlen($brd);
  7516. $newbrd = array();
  7517. for ($i = 0; $i < $slen; ++$i) {
  7518. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  7519. }
  7520. $brd = $newbrd;
  7521. }
  7522. foreach ($brd as $border => $style) {
  7523. switch ($position) {
  7524. case 'start': {
  7525. if (strpos($border, 'B') !== false) {
  7526. // remove bottom line
  7527. $newkey = str_replace('B', '', $border);
  7528. if (strlen($newkey) > 0) {
  7529. $brd[$newkey] = $style;
  7530. }
  7531. unset($brd[$border]);
  7532. }
  7533. break;
  7534. }
  7535. case 'middle': {
  7536. if (strpos($border, 'B') !== false) {
  7537. // remove bottom line
  7538. $newkey = str_replace('B', '', $border);
  7539. if (strlen($newkey) > 0) {
  7540. $brd[$newkey] = $style;
  7541. }
  7542. unset($brd[$border]);
  7543. $border = $newkey;
  7544. }
  7545. if (strpos($border, 'T') !== false) {
  7546. // remove bottom line
  7547. $newkey = str_replace('T', '', $border);
  7548. if (strlen($newkey) > 0) {
  7549. $brd[$newkey] = $style;
  7550. }
  7551. unset($brd[$border]);
  7552. }
  7553. break;
  7554. }
  7555. case 'end': {
  7556. if (strpos($border, 'T') !== false) {
  7557. // remove bottom line
  7558. $newkey = str_replace('T', '', $border);
  7559. if (strlen($newkey) > 0) {
  7560. $brd[$newkey] = $style;
  7561. }
  7562. unset($brd[$border]);
  7563. }
  7564. break;
  7565. }
  7566. }
  7567. }
  7568. return $brd;
  7569. }
  7570. /**
  7571. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  7572. * @param $txt (string) String for calculating his height
  7573. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  7574. * @param $reseth (boolean) if true reset the last cell height (default false).
  7575. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  7576. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  7577. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7578. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  7579. * @author Alexander Escalona Fern�ndez, Nicola Asuni
  7580. * @public
  7581. * @since 4.5.011
  7582. */
  7583. public function getNumLines($txt, $w = 0, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0) {
  7584. if ($txt === '') {
  7585. // empty string
  7586. return 1;
  7587. }
  7588. // adjust internal padding
  7589. $prev_cell_padding = $this->cell_padding;
  7590. $prev_lasth = $this->lasth;
  7591. if (is_array($cellpadding)) {
  7592. $this->cell_padding = $cellpadding;
  7593. }
  7594. $this->adjustCellPadding($border);
  7595. if ($this->empty_string($w) OR ($w <= 0)) {
  7596. if ($this->rtl) {
  7597. $w = $this->x - $this->lMargin;
  7598. } else {
  7599. $w = $this->w - $this->rMargin - $this->x;
  7600. }
  7601. }
  7602. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  7603. if ($reseth) {
  7604. // reset row height
  7605. $this->resetLastH();
  7606. }
  7607. $lines = 1;
  7608. $sum = 0;
  7609. $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
  7610. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  7611. $length = count($chars);
  7612. $lastSeparator = -1;
  7613. for ($i = 0; $i < $length; ++$i) {
  7614. $charWidth = $charsWidth[$i];
  7615. if (preg_match($this->re_spaces, $this->unichr($chars[$i]))) {
  7616. $lastSeparator = $i;
  7617. }
  7618. if ((($sum + $charWidth) > $wmax) OR ($chars[$i] == 10)) {
  7619. ++$lines;
  7620. if ($chars[$i] == 10) {
  7621. $lastSeparator = -1;
  7622. $sum = 0;
  7623. } elseif ($lastSeparator != -1) {
  7624. $i = $lastSeparator;
  7625. $lastSeparator = -1;
  7626. $sum = 0;
  7627. } else {
  7628. $sum = $charWidth;
  7629. }
  7630. } else {
  7631. $sum += $charWidth;
  7632. }
  7633. }
  7634. if ($chars[($length - 1)] == 10) {
  7635. --$lines;
  7636. }
  7637. $this->cell_padding = $prev_cell_padding;
  7638. $this->lasth = $prev_lasth;
  7639. return $lines;
  7640. }
  7641. /**
  7642. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  7643. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  7644. * @pre
  7645. * // store current object
  7646. * $pdf->startTransaction();
  7647. * // store starting values
  7648. * $start_y = $pdf->GetY();
  7649. * $start_page = $pdf->getPage();
  7650. * // call your printing functions with your parameters
  7651. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7652. * $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
  7653. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7654. * // get the new Y
  7655. * $end_y = $pdf->GetY();
  7656. * $end_page = $pdf->getPage();
  7657. * // calculate height
  7658. * $height = 0;
  7659. * if ($end_page == $start_page) {
  7660. * $height = $end_y - $start_y;
  7661. * } else {
  7662. * for ($page=$start_page; $page <= $end_page; ++$page) {
  7663. * $this->setPage($page);
  7664. * if ($page == $start_page) {
  7665. * // first page
  7666. * $height = $this->h - $start_y - $this->bMargin;
  7667. * } elseif ($page == $end_page) {
  7668. * // last page
  7669. * $height = $end_y - $this->tMargin;
  7670. * } else {
  7671. * $height = $this->h - $this->tMargin - $this->bMargin;
  7672. * }
  7673. * }
  7674. * }
  7675. * // restore previous object
  7676. * $pdf = $pdf->rollbackTransaction();
  7677. *
  7678. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  7679. * @param $txt (string) String for calculating his height
  7680. * @param $reseth (boolean) if true reset the last cell height (default false).
  7681. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  7682. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  7683. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7684. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  7685. * @author Nicola Asuni, Alexander Escalona Fern�ndez
  7686. * @public
  7687. */
  7688. public function getStringHeight($w, $txt, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0) {
  7689. // adjust internal padding
  7690. $prev_cell_padding = $this->cell_padding;
  7691. $prev_lasth = $this->lasth;
  7692. if (is_array($cellpadding)) {
  7693. $this->cell_padding = $cellpadding;
  7694. }
  7695. $this->adjustCellPadding($border);
  7696. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  7697. $height = $lines * ($this->FontSize * $this->cell_height_ratio);
  7698. if ($autopadding) {
  7699. // add top and bottom padding
  7700. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  7701. }
  7702. $this->cell_padding = $prev_cell_padding;
  7703. $this->lasth = $prev_lasth;
  7704. return $height;
  7705. }
  7706. /**
  7707. * This method prints text from the current position.<br />
  7708. * @param $h (float) Line height
  7709. * @param $txt (string) String to print
  7710. * @param $link (mixed) URL or identifier returned by AddLink()
  7711. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  7712. * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  7713. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  7714. * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  7715. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  7716. * @param $firstblock (boolean) if true the string is the starting of a line.
  7717. * @param $maxh (float) 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.
  7718. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  7719. * @param $margin (array) margin array of the parent container
  7720. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  7721. * @public
  7722. * @since 1.5
  7723. */
  7724. public function Write($h, $txt, $link = '', $fill = false, $align = '', $ln = false, $stretch = 0, $firstline = false, $firstblock = false, $maxh = 0, $wadj = 0, $margin = '') {
  7725. // check page for no-write regions and adapt page margins if necessary
  7726. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  7727. if (strlen($txt) == 0) {
  7728. // fix empty text
  7729. $txt = ' ';
  7730. }
  7731. if ($margin === '') {
  7732. // set default margins
  7733. $margin = $this->cell_margin;
  7734. }
  7735. // remove carriage returns
  7736. $s = str_replace("\r", '', $txt);
  7737. // check if string contains arabic text
  7738. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s)) {
  7739. $arabic = true;
  7740. } else {
  7741. $arabic = false;
  7742. }
  7743. // check if string contains RTL text
  7744. if ($arabic OR ($this->tmprtl == 'R') OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $s)) {
  7745. $rtlmode = true;
  7746. } else {
  7747. $rtlmode = false;
  7748. }
  7749. // get a char width
  7750. $chrwidth = $this->GetCharWidth(46); // dot character
  7751. // get array of unicode values
  7752. $chars = $this->UTF8StringToArray($s);
  7753. // calculate maximum width for a single character on string
  7754. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  7755. array_walk($chrw, array($this, 'getRawCharWidth'));
  7756. $maxchwidth = max($chrw);
  7757. // get array of chars
  7758. $uchars = $this->UTF8ArrayToUniArray($chars);
  7759. // get the number of characters
  7760. $nb = count($chars);
  7761. // replacement for SHY character (minus symbol)
  7762. $shy_replacement = 45;
  7763. $shy_replacement_char = $this->unichr($shy_replacement);
  7764. // widht for SHY replacement
  7765. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  7766. // max Y
  7767. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  7768. // page width
  7769. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  7770. // calculate remaining line width ($w)
  7771. if ($this->rtl) {
  7772. $w = $this->x - $this->lMargin;
  7773. } else {
  7774. $w = $this->w - $this->rMargin - $this->x;
  7775. }
  7776. // max column width
  7777. $wmax = ($w - $wadj);
  7778. if (!$firstline) {
  7779. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  7780. }
  7781. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  7782. // the maximum width character do not fit on column
  7783. return '';
  7784. }
  7785. // minimum row height
  7786. $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
  7787. $start_page = $this->page;
  7788. $i = 0; // character position
  7789. $j = 0; // current starting position
  7790. $sep = -1; // position of the last blank space
  7791. $shy = false; // true if the last blank is a soft hypen (SHY)
  7792. $l = 0; // current string length
  7793. $nl = 0; //number of lines
  7794. $linebreak = false;
  7795. $pc = 0; // previous character
  7796. // for each character
  7797. while ($i < $nb) {
  7798. if (($maxh > 0) AND ($this->y >= $maxy)) {
  7799. break;
  7800. }
  7801. //Get the current character
  7802. $c = $chars[$i];
  7803. if ($c == 10) { // 10 = "\n" = new line
  7804. //Explicit line break
  7805. if ($align == 'J') {
  7806. if ($this->rtl) {
  7807. $talign = 'R';
  7808. } else {
  7809. $talign = 'L';
  7810. }
  7811. } else {
  7812. $talign = $align;
  7813. }
  7814. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  7815. if ($firstline) {
  7816. $startx = $this->x;
  7817. $tmparr = array_slice($chars, $j, ($i - $j));
  7818. if ($rtlmode) {
  7819. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7820. }
  7821. $linew = $this->GetArrStringWidth($tmparr);
  7822. unset($tmparr);
  7823. if ($this->rtl) {
  7824. $this->endlinex = $startx - $linew;
  7825. } else {
  7826. $this->endlinex = $startx + $linew;
  7827. }
  7828. $w = $linew;
  7829. $tmpcellpadding = $this->cell_padding;
  7830. if ($maxh == 0) {
  7831. $this->SetCellPadding(0);
  7832. }
  7833. }
  7834. if ($firstblock AND $this->isRTLTextDir()) {
  7835. $tmpstr = $this->stringRightTrim($tmpstr);
  7836. }
  7837. // Skip newlines at the begining of a page or column
  7838. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  7839. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  7840. }
  7841. unset($tmpstr);
  7842. if ($firstline) {
  7843. $this->cell_padding = $tmpcellpadding;
  7844. return ($this->UniArrSubString($uchars, $i));
  7845. }
  7846. ++$nl;
  7847. $j = $i + 1;
  7848. $l = 0;
  7849. $sep = -1;
  7850. $shy = false;
  7851. // account for margin changes
  7852. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  7853. $this->AcceptPageBreak();
  7854. if ($this->rtl) {
  7855. $this->x -= $margin['R'];
  7856. } else {
  7857. $this->x += $margin['L'];
  7858. }
  7859. $this->lMargin += $margin['L'];
  7860. $this->rMargin += $margin['R'];
  7861. }
  7862. $w = $this->getRemainingWidth();
  7863. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  7864. } else {
  7865. // 160 is the non-breaking space.
  7866. // 173 is SHY (Soft Hypen).
  7867. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  7868. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  7869. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  7870. if (($c != 160)
  7871. AND (($c == 173)
  7872. OR preg_match($this->re_spaces, $this->unichr($c))
  7873. OR (($c == 45)
  7874. AND ($i < ($nb - 1))
  7875. AND @preg_match('/[\p{L}]/' . $this->re_space['m'], $this->unichr($pc))
  7876. AND @preg_match('/[\p{L}]/' . $this->re_space['m'], $this->unichr($chars[($i + 1)]))
  7877. )
  7878. )
  7879. ) {
  7880. // update last blank space position
  7881. $sep = $i;
  7882. // check if is a SHY
  7883. if (($c == 173) OR ($c == 45)) {
  7884. $shy = true;
  7885. if ($pc == 45) {
  7886. $tmp_shy_replacement_width = 0;
  7887. $tmp_shy_replacement_char = '';
  7888. } else {
  7889. $tmp_shy_replacement_width = $shy_replacement_width;
  7890. $tmp_shy_replacement_char = $shy_replacement_char;
  7891. }
  7892. } else {
  7893. $shy = false;
  7894. }
  7895. }
  7896. // update string length
  7897. if ($this->isUnicodeFont() AND ($arabic)) {
  7898. // with bidirectional algorithm some chars may be changed affecting the line length
  7899. // *** very slow ***
  7900. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  7901. } else {
  7902. $l += $this->GetCharWidth($c);
  7903. }
  7904. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax))) {
  7905. // we have reached the end of column
  7906. if ($sep == -1) {
  7907. // check if the line was already started
  7908. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  7909. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  7910. // print a void cell and go to next line
  7911. $this->Cell($w, $h, '', 0, 1);
  7912. $linebreak = true;
  7913. if ($firstline) {
  7914. return ($this->UniArrSubString($uchars, $j));
  7915. }
  7916. } else {
  7917. // truncate the word because do not fit on column
  7918. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  7919. if ($firstline) {
  7920. $startx = $this->x;
  7921. $tmparr = array_slice($chars, $j, ($i - $j));
  7922. if ($rtlmode) {
  7923. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7924. }
  7925. $linew = $this->GetArrStringWidth($tmparr);
  7926. unset($tmparr);
  7927. if ($this->rtl) {
  7928. $this->endlinex = $startx - $linew;
  7929. } else {
  7930. $this->endlinex = $startx + $linew;
  7931. }
  7932. $w = $linew;
  7933. $tmpcellpadding = $this->cell_padding;
  7934. if ($maxh == 0) {
  7935. $this->SetCellPadding(0);
  7936. }
  7937. }
  7938. if ($firstblock AND $this->isRTLTextDir()) {
  7939. $tmpstr = $this->stringRightTrim($tmpstr);
  7940. }
  7941. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  7942. unset($tmpstr);
  7943. if ($firstline) {
  7944. $this->cell_padding = $tmpcellpadding;
  7945. return ($this->UniArrSubString($uchars, $i));
  7946. }
  7947. $j = $i;
  7948. --$i;
  7949. }
  7950. } else {
  7951. // word wrapping
  7952. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  7953. $endspace = 1;
  7954. } else {
  7955. $endspace = 0;
  7956. }
  7957. // check the length of the next string
  7958. $strrest = $this->UniArrSubString($uchars, ($sep + $endspace));
  7959. $nextstr = preg_split('/' . $this->re_space['p'] . '/' . $this->re_space['m'], $this->stringTrim($strrest));
  7960. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  7961. // truncate the word because do not fit on a full page width
  7962. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  7963. if ($firstline) {
  7964. $startx = $this->x;
  7965. $tmparr = array_slice($chars, $j, ($i - $j));
  7966. if ($rtlmode) {
  7967. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  7968. }
  7969. $linew = $this->GetArrStringWidth($tmparr);
  7970. unset($tmparr);
  7971. if ($this->rtl) {
  7972. $this->endlinex = ($startx - $linew);
  7973. } else {
  7974. $this->endlinex = ($startx + $linew);
  7975. }
  7976. $w = $linew;
  7977. $tmpcellpadding = $this->cell_padding;
  7978. if ($maxh == 0) {
  7979. $this->SetCellPadding(0);
  7980. }
  7981. }
  7982. if ($firstblock AND $this->isRTLTextDir()) {
  7983. $tmpstr = $this->stringRightTrim($tmpstr);
  7984. }
  7985. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  7986. unset($tmpstr);
  7987. if ($firstline) {
  7988. $this->cell_padding = $tmpcellpadding;
  7989. return ($this->UniArrSubString($uchars, $i));
  7990. }
  7991. $j = $i;
  7992. --$i;
  7993. } else {
  7994. // word wrapping
  7995. if ($shy) {
  7996. // add hypen (minus symbol) at the end of the line
  7997. $shy_width = $tmp_shy_replacement_width;
  7998. if ($this->rtl) {
  7999. $shy_char_left = $tmp_shy_replacement_char;
  8000. $shy_char_right = '';
  8001. } else {
  8002. $shy_char_left = '';
  8003. $shy_char_right = $tmp_shy_replacement_char;
  8004. }
  8005. } else {
  8006. $shy_width = 0;
  8007. $shy_char_left = '';
  8008. $shy_char_right = '';
  8009. }
  8010. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  8011. if ($firstline) {
  8012. $startx = $this->x;
  8013. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  8014. if ($rtlmode) {
  8015. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8016. }
  8017. $linew = $this->GetArrStringWidth($tmparr);
  8018. unset($tmparr);
  8019. if ($this->rtl) {
  8020. $this->endlinex = $startx - $linew - $shy_width;
  8021. } else {
  8022. $this->endlinex = $startx + $linew + $shy_width;
  8023. }
  8024. $w = $linew;
  8025. $tmpcellpadding = $this->cell_padding;
  8026. if ($maxh == 0) {
  8027. $this->SetCellPadding(0);
  8028. }
  8029. }
  8030. // print the line
  8031. if ($firstblock AND $this->isRTLTextDir()) {
  8032. $tmpstr = $this->stringRightTrim($tmpstr);
  8033. }
  8034. $this->Cell($w, $h, $shy_char_left . $tmpstr . $shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  8035. unset($tmpstr);
  8036. if ($firstline) {
  8037. if ($chars[$sep] == 45) {
  8038. $endspace += 1;
  8039. }
  8040. // return the remaining text
  8041. $this->cell_padding = $tmpcellpadding;
  8042. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  8043. }
  8044. $i = $sep;
  8045. $sep = -1;
  8046. $shy = false;
  8047. $j = ($i + 1);
  8048. }
  8049. }
  8050. // account for margin changes
  8051. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  8052. $this->AcceptPageBreak();
  8053. if ($this->rtl) {
  8054. $this->x -= $margin['R'];
  8055. } else {
  8056. $this->x += $margin['L'];
  8057. }
  8058. $this->lMargin += $margin['L'];
  8059. $this->rMargin += $margin['R'];
  8060. }
  8061. $w = $this->getRemainingWidth();
  8062. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  8063. if ($linebreak) {
  8064. $linebreak = false;
  8065. } else {
  8066. ++$nl;
  8067. $l = 0;
  8068. }
  8069. }
  8070. }
  8071. // save last character
  8072. $pc = $c;
  8073. ++$i;
  8074. } // end while i < nb
  8075. // print last substring (if any)
  8076. if ($l > 0) {
  8077. switch ($align) {
  8078. case 'J':
  8079. case 'C': {
  8080. $w = $w;
  8081. break;
  8082. }
  8083. case 'L': {
  8084. if ($this->rtl) {
  8085. $w = $w;
  8086. } else {
  8087. $w = $l;
  8088. }
  8089. break;
  8090. }
  8091. case 'R': {
  8092. if ($this->rtl) {
  8093. $w = $l;
  8094. } else {
  8095. $w = $w;
  8096. }
  8097. break;
  8098. }
  8099. default: {
  8100. $w = $l;
  8101. break;
  8102. }
  8103. }
  8104. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  8105. if ($firstline) {
  8106. $startx = $this->x;
  8107. $tmparr = array_slice($chars, $j, ($nb - $j));
  8108. if ($rtlmode) {
  8109. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8110. }
  8111. $linew = $this->GetArrStringWidth($tmparr);
  8112. unset($tmparr);
  8113. if ($this->rtl) {
  8114. $this->endlinex = $startx - $linew;
  8115. } else {
  8116. $this->endlinex = $startx + $linew;
  8117. }
  8118. $w = $linew;
  8119. $tmpcellpadding = $this->cell_padding;
  8120. if ($maxh == 0) {
  8121. $this->SetCellPadding(0);
  8122. }
  8123. }
  8124. if ($firstblock AND $this->isRTLTextDir()) {
  8125. $tmpstr = $this->stringRightTrim($tmpstr);
  8126. }
  8127. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  8128. unset($tmpstr);
  8129. if ($firstline) {
  8130. $this->cell_padding = $tmpcellpadding;
  8131. return ($this->UniArrSubString($uchars, $nb));
  8132. }
  8133. ++$nl;
  8134. }
  8135. if ($firstline) {
  8136. return '';
  8137. }
  8138. return $nl;
  8139. }
  8140. /**
  8141. * Returns the remaining width between the current position and margins.
  8142. * @return int Return the remaining width
  8143. * @protected
  8144. */
  8145. protected function getRemainingWidth() {
  8146. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  8147. if ($this->rtl) {
  8148. return ($this->x - $this->lMargin);
  8149. } else {
  8150. return ($this->w - $this->rMargin - $this->x);
  8151. }
  8152. }
  8153. /**
  8154. * Extract a slice of the $strarr array and return it as string.
  8155. * @param $strarr (string) The input array of characters.
  8156. * @param $start (int) the starting element of $strarr.
  8157. * @param $end (int) first element that will not be returned.
  8158. * @return Return part of a string
  8159. * @public
  8160. */
  8161. public function UTF8ArrSubString($strarr, $start = '', $end = '') {
  8162. if (strlen($start) == 0) {
  8163. $start = 0;
  8164. }
  8165. if (strlen($end) == 0) {
  8166. $end = count($strarr);
  8167. }
  8168. $string = '';
  8169. for ($i = $start; $i < $end; ++$i) {
  8170. $string .= $this->unichr($strarr[$i]);
  8171. }
  8172. return $string;
  8173. }
  8174. /**
  8175. * Extract a slice of the $uniarr array and return it as string.
  8176. * @param $uniarr (string) The input array of characters.
  8177. * @param $start (int) the starting element of $strarr.
  8178. * @param $end (int) first element that will not be returned.
  8179. * @return Return part of a string
  8180. * @public
  8181. * @since 4.5.037 (2009-04-07)
  8182. */
  8183. public function UniArrSubString($uniarr, $start = '', $end = '') {
  8184. if (strlen($start) == 0) {
  8185. $start = 0;
  8186. }
  8187. if (strlen($end) == 0) {
  8188. $end = count($uniarr);
  8189. }
  8190. $string = '';
  8191. for ($i = $start; $i < $end; ++$i) {
  8192. $string .= $uniarr[$i];
  8193. }
  8194. return $string;
  8195. }
  8196. /**
  8197. * Convert an array of UTF8 values to array of unicode characters
  8198. * @param $ta (string) The input array of UTF8 values.
  8199. * @return Return array of unicode characters
  8200. * @public
  8201. * @since 4.5.037 (2009-04-07)
  8202. */
  8203. public function UTF8ArrayToUniArray($ta) {
  8204. return array_map(array($this, 'unichr'), $ta);
  8205. }
  8206. /**
  8207. * Returns the unicode caracter specified by UTF-8 value
  8208. * @param $c (int) UTF-8 value
  8209. * @return Returns the specified character.
  8210. * @author Miguel Perez, Nicola Asuni
  8211. * @public
  8212. * @since 2.3.000 (2008-03-05)
  8213. */
  8214. public function unichr($c) {
  8215. if (!$this->isunicode) {
  8216. return chr($c);
  8217. } elseif ($c <= 0x7F) {
  8218. // one byte
  8219. return chr($c);
  8220. } elseif ($c <= 0x7FF) {
  8221. // two bytes
  8222. return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
  8223. } elseif ($c <= 0xFFFF) {
  8224. // three bytes
  8225. return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  8226. } elseif ($c <= 0x10FFFF) {
  8227. // four bytes
  8228. return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  8229. } else {
  8230. return '';
  8231. }
  8232. }
  8233. /**
  8234. * Return the image type given the file name or array returned by getimagesize() function.
  8235. * @param $imgfile (string) image file name
  8236. * @param $iminfo (array) array of image information returned by getimagesize() function.
  8237. * @return string image type
  8238. * @since 4.8.017 (2009-11-27)
  8239. */
  8240. public function getImageFileType($imgfile, $iminfo = array()) {
  8241. $type = '';
  8242. if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
  8243. $mime = explode('/', $iminfo['mime']);
  8244. if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
  8245. $type = strtolower(trim($mime[1]));
  8246. }
  8247. }
  8248. if (empty($type)) {
  8249. $fileinfo = pathinfo($imgfile);
  8250. if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) {
  8251. $type = strtolower(trim($fileinfo['extension']));
  8252. }
  8253. }
  8254. if ($type == 'jpg') {
  8255. $type = 'jpeg';
  8256. }
  8257. return $type;
  8258. }
  8259. /**
  8260. * Set the block dimensions accounting for page breaks and page/column fitting
  8261. * @param $w (float) width
  8262. * @param $h (float) height
  8263. * @param $x (float) X coordinate
  8264. * @param $y (float) Y coodiante
  8265. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  8266. * @return array($w, $h, $x, $y)
  8267. * @protected
  8268. * @since 5.5.009 (2010-07-05)
  8269. */
  8270. protected function fitBlock($w, $h, $x, $y, $fitonpage = false) {
  8271. if ($w <= 0) {
  8272. // set maximum width
  8273. $w = ($this->w - $this->lMargin - $this->rMargin);
  8274. }
  8275. if ($h <= 0) {
  8276. // set maximum height
  8277. $h = ($this->PageBreakTrigger - $this->tMargin);
  8278. }
  8279. // resize the block to be vertically contained on a single page or single column
  8280. if ($fitonpage OR $this->AutoPageBreak) {
  8281. $ratio_wh = ($w / $h);
  8282. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  8283. $h = $this->PageBreakTrigger - $this->tMargin;
  8284. $w = ($h * $ratio_wh);
  8285. }
  8286. // resize the block to be horizontally contained on a single page or single column
  8287. if ($fitonpage) {
  8288. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  8289. if ($w > $maxw) {
  8290. $w = $maxw;
  8291. $h = ($w / $ratio_wh);
  8292. }
  8293. }
  8294. }
  8295. // Check whether we need a new page or new column first as this does not fit
  8296. $prev_x = $this->x;
  8297. $prev_y = $this->y;
  8298. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  8299. $y = $this->y;
  8300. if ($this->rtl) {
  8301. $x += ($prev_x - $this->x);
  8302. } else {
  8303. $x += ($this->x - $prev_x);
  8304. }
  8305. $this->newline = true;
  8306. }
  8307. // resize the block to be contained on the remaining available page or column space
  8308. if ($fitonpage) {
  8309. $ratio_wh = ($w / $h);
  8310. if (($y + $h) > $this->PageBreakTrigger) {
  8311. $h = $this->PageBreakTrigger - $y;
  8312. $w = ($h * $ratio_wh);
  8313. }
  8314. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  8315. $w = $this->w - $this->rMargin - $x;
  8316. $h = ($w / $ratio_wh);
  8317. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  8318. $w = $x - $this->lMargin;
  8319. $h = ($w / $ratio_wh);
  8320. }
  8321. }
  8322. return array($w, $h, $x, $y);
  8323. }
  8324. /**
  8325. * Puts an image in the page.
  8326. * The upper-left corner must be given.
  8327. * The dimensions can be specified in different ways:<ul>
  8328. * <li>explicit width and height (expressed in user unit)</li>
  8329. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  8330. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  8331. * 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;
  8332. * The format can be specified explicitly or inferred from the file extension.<br />
  8333. * It is possible to put a link on the image.<br />
  8334. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  8335. * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string. To link an image without embedding it on the document, set an asterisk character before the URL (i.e.: '*http://www.example.com/image.jpg').
  8336. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  8337. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  8338. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8339. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8340. * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  8341. * @param $link (mixed) URL or identifier returned by AddLink().
  8342. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  8343. * @param $resize (mixed) If true resize (reduce) the image to fit $w and $h (requires GD or ImageMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
  8344. * @param $dpi (int) dot-per-inch resolution used on resize
  8345. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  8346. * @param $ismask (boolean) true if this image is a mask, false otherwise
  8347. * @param $imgmask (mixed) image object returned by this function or false
  8348. * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  8349. * @param $fitbox (mixed) If not false scale image dimensions proportionally to fit within the ($w, $h) box. $fitbox can be true or a 2 characters string indicating the image alignment inside the box. The first character indicate the horizontal alignment (L = left, C = center, R = right) the second character indicate the vertical algnment (T = top, M = middle, B = bottom).
  8350. * @param $hidden (boolean) If true do not display the image.
  8351. * @param $fitonpage (boolean) If true the image is resized to not exceed page dimensions.
  8352. * @param $alt (boolean) If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  8353. * @param $altimgs (array) Array of alternate images IDs. Each alternative image must be an array with two values: an integer representing the image ID (the value returned by the Image method) and a boolean value to indicate if the image is the default for printing.
  8354. * @return image information
  8355. * @public
  8356. * @since 1.1
  8357. */
  8358. public function Image($file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false, $hidden = false, $fitonpage = false, $alt = false, $altimgs = array()) {
  8359. if ($this->state != 2) {
  8360. return;
  8361. }
  8362. if ($x === '') {
  8363. $x = $this->x;
  8364. }
  8365. if ($y === '') {
  8366. $y = $this->y;
  8367. }
  8368. // check page for no-write regions and adapt page margins if necessary
  8369. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  8370. $exurl = ''; // external streams
  8371. // check if we are passing an image as file or string
  8372. if ($file[0] === '@') {
  8373. // image from string
  8374. $imgdata = substr($file, 1);
  8375. $file = $this->getObjFilename('img');
  8376. $fp = fopen($file, 'w');
  8377. fwrite($fp, $imgdata);
  8378. fclose($fp);
  8379. unset($imgdata);
  8380. $imsize = @getimagesize($file);
  8381. if ($imsize === FALSE) {
  8382. unlink($file);
  8383. } else {
  8384. $this->cached_files[] = $file;
  8385. }
  8386. } else { // image file
  8387. if ($file{0} === '*') {
  8388. // image as external stream
  8389. $file = substr($file, 1);
  8390. $exurl = $file;
  8391. }
  8392. // check if is local file
  8393. if (!@file_exists($file)) {
  8394. // encode spaces on filename (file is probably an URL)
  8395. $file = str_replace(' ', '%20', $file);
  8396. }
  8397. if (@file_exists($file)) {
  8398. // get image dimensions
  8399. $imsize = @getimagesize($file);
  8400. } else {
  8401. $imsize = false;
  8402. }
  8403. if ($imsize === FALSE) {
  8404. if (function_exists('curl_init')) {
  8405. // try to get remote file data using cURL
  8406. $cs = curl_init(); // curl session
  8407. curl_setopt($cs, CURLOPT_URL, $file);
  8408. curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
  8409. curl_setopt($cs, CURLOPT_FAILONERROR, true);
  8410. curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
  8411. if ((ini_get('open_basedir') == '') AND (!ini_get('safe_mode'))) {
  8412. curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);
  8413. }
  8414. curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
  8415. curl_setopt($cs, CURLOPT_TIMEOUT, 30);
  8416. curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, false);
  8417. curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, false);
  8418. curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF');
  8419. $imgdata = curl_exec($cs);
  8420. curl_close($cs);
  8421. if ($imgdata !== FALSE) {
  8422. // copy image to cache
  8423. $file = $this->getObjFilename('img');
  8424. $fp = fopen($file, 'w');
  8425. fwrite($fp, $imgdata);
  8426. fclose($fp);
  8427. unset($imgdata);
  8428. $imsize = @getimagesize($file);
  8429. if ($imsize === FALSE) {
  8430. unlink($file);
  8431. } else {
  8432. $this->cached_files[] = $file;
  8433. }
  8434. }
  8435. } elseif (($w > 0) AND ($h > 0)) {
  8436. // get measures from specified data
  8437. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8438. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8439. $imsize = array($pw, $ph);
  8440. }
  8441. }
  8442. }
  8443. if ($imsize === FALSE) {
  8444. if (substr($file, 0, -34) == K_PATH_CACHE . 'msk') { // mask file
  8445. // get measures from specified data
  8446. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8447. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8448. $imsize = array($pw, $ph);
  8449. } else {
  8450. $this->Error('[Image] Unable to get image: ' . $file);
  8451. }
  8452. }
  8453. // file hash
  8454. $filehash = md5($this->file_id . $file);
  8455. // get original image width and height in pixels
  8456. list($pixw, $pixh) = $imsize;
  8457. // calculate image width and height on document
  8458. if (($w <= 0) AND ($h <= 0)) {
  8459. // convert image size to document unit
  8460. $w = $this->pixelsToUnits($pixw);
  8461. $h = $this->pixelsToUnits($pixh);
  8462. } elseif ($w <= 0) {
  8463. $w = $h * $pixw / $pixh;
  8464. } elseif ($h <= 0) {
  8465. $h = $w * $pixh / $pixw;
  8466. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  8467. if (strlen($fitbox) !== 2) {
  8468. // set default alignment
  8469. $fitbox = '--';
  8470. }
  8471. // scale image dimensions proportionally to fit within the ($w, $h) box
  8472. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  8473. // store current height
  8474. $oldh = $h;
  8475. // calculate new height
  8476. $h = $w * $pixh / $pixw;
  8477. // height difference
  8478. $hdiff = ($oldh - $h);
  8479. // vertical alignment
  8480. switch (strtoupper($fitbox{1})) {
  8481. case 'T': {
  8482. break;
  8483. }
  8484. case 'M': {
  8485. $y += ($hdiff / 2);
  8486. break;
  8487. }
  8488. case 'B': {
  8489. $y += $hdiff;
  8490. break;
  8491. }
  8492. }
  8493. } else {
  8494. // store current width
  8495. $oldw = $w;
  8496. // calculate new width
  8497. $w = $h * $pixw / $pixh;
  8498. // width difference
  8499. $wdiff = ($oldw - $w);
  8500. // horizontal alignment
  8501. switch (strtoupper($fitbox{0})) {
  8502. case 'L': {
  8503. if ($this->rtl) {
  8504. $x -= $wdiff;
  8505. }
  8506. break;
  8507. }
  8508. case 'C': {
  8509. if ($this->rtl) {
  8510. $x -= ($wdiff / 2);
  8511. } else {
  8512. $x += ($wdiff / 2);
  8513. }
  8514. break;
  8515. }
  8516. case 'R': {
  8517. if (!$this->rtl) {
  8518. $x += $wdiff;
  8519. }
  8520. break;
  8521. }
  8522. }
  8523. }
  8524. }
  8525. // fit the image on available space
  8526. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  8527. // calculate new minimum dimensions in pixels
  8528. $neww = round($w * $this->k * $dpi / $this->dpi);
  8529. $newh = round($h * $this->k * $dpi / $this->dpi);
  8530. // check if resize is necessary (resize is used only to reduce the image)
  8531. $newsize = ($neww * $newh);
  8532. $pixsize = ($pixw * $pixh);
  8533. if (intval($resize) == 2) {
  8534. $resize = true;
  8535. } elseif ($newsize >= $pixsize) {
  8536. $resize = false;
  8537. }
  8538. // check if image has been already added on document
  8539. $newimage = true;
  8540. if (in_array($file, $this->imagekeys)) {
  8541. $newimage = false;
  8542. // get existing image data
  8543. $info = $this->getImageBuffer($file);
  8544. if (substr($file, 0, -34) != K_PATH_CACHE . 'msk') {
  8545. // check if the newer image is larger
  8546. $oldsize = ($info['w'] * $info['h']);
  8547. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  8548. $newimage = true;
  8549. }
  8550. }
  8551. } elseif (substr($file, 0, -34) != K_PATH_CACHE . 'msk') {
  8552. // check for cached images with alpha channel
  8553. $tempfile_plain = K_PATH_CACHE . 'mskp_' . $filehash;
  8554. $tempfile_alpha = K_PATH_CACHE . 'mska_' . $filehash;
  8555. if (in_array($tempfile_plain, $this->imagekeys)) {
  8556. // get existing image data
  8557. $info = $this->getImageBuffer($tempfile_plain);
  8558. // check if the newer image is larger
  8559. $oldsize = ($info['w'] * $info['h']);
  8560. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  8561. $newimage = true;
  8562. } else {
  8563. $newimage = false;
  8564. // embed mask image
  8565. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  8566. // embed image, masked with previously embedded mask
  8567. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  8568. }
  8569. }
  8570. }
  8571. if ($newimage) {
  8572. //First use of image, get info
  8573. $type = strtolower($type);
  8574. if ($type == '') {
  8575. $type = $this->getImageFileType($file, $imsize);
  8576. } elseif ($type == 'jpg') {
  8577. $type = 'jpeg';
  8578. }
  8579. $mqr = $this->get_mqr();
  8580. $this->set_mqr(false);
  8581. // Specific image handlers
  8582. $mtd = '_parse' . $type;
  8583. // GD image handler function
  8584. $gdfunction = 'imagecreatefrom' . $type;
  8585. $info = false;
  8586. if ((method_exists($this, $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  8587. // TCPDF image functions
  8588. $info = $this->$mtd($file);
  8589. if ($info == 'pngalpha') {
  8590. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  8591. }
  8592. }
  8593. if (!$info) {
  8594. if (function_exists($gdfunction)) {
  8595. // GD library
  8596. $img = $gdfunction($file);
  8597. if ($resize) {
  8598. $imgr = imagecreatetruecolor($neww, $newh);
  8599. if (($type == 'gif') OR ($type == 'png')) {
  8600. $imgr = $this->_setGDImageTransparency($imgr, $img);
  8601. }
  8602. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  8603. if (($type == 'gif') OR ($type == 'png')) {
  8604. $info = $this->_toPNG($imgr);
  8605. } else {
  8606. $info = $this->_toJPEG($imgr);
  8607. }
  8608. } else {
  8609. if (($type == 'gif') OR ($type == 'png')) {
  8610. $info = $this->_toPNG($img);
  8611. } else {
  8612. $info = $this->_toJPEG($img);
  8613. }
  8614. }
  8615. } elseif (extension_loaded('imagick')) {
  8616. // ImageMagick library
  8617. $img = new Imagick();
  8618. if ($type == 'SVG') {
  8619. // get SVG file content
  8620. $svgimg = file_get_contents($file);
  8621. // get width and height
  8622. $regs = array();
  8623. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  8624. $svgtag = $regs[1];
  8625. $tmp = array();
  8626. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  8627. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  8628. $owu = sprintf('%F', ($ow * $dpi / 72)) . $this->pdfunit;
  8629. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="' . $owu . '"', $svgtag, 1);
  8630. } else {
  8631. $ow = $w;
  8632. }
  8633. $tmp = array();
  8634. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  8635. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  8636. $ohu = sprintf('%F', ($oh * $dpi / 72)) . $this->pdfunit;
  8637. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="' . $ohu . '"', $svgtag, 1);
  8638. } else {
  8639. $oh = $h;
  8640. }
  8641. $tmp = array();
  8642. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  8643. $vbw = ($ow * $this->imgscale * $this->k);
  8644. $vbh = ($oh * $this->imgscale * $this->k);
  8645. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  8646. $svgtag = $vbox . $svgtag;
  8647. }
  8648. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg' . $svgtag . '>', $svgimg, 1);
  8649. }
  8650. $img->readImageBlob($svgimg);
  8651. } else {
  8652. $img->readImage($file);
  8653. }
  8654. if ($resize) {
  8655. $img->resizeImage($neww, $newh, 10, 1, false);
  8656. }
  8657. $img->setCompressionQuality($this->jpeg_quality);
  8658. $img->setImageFormat('jpeg');
  8659. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  8660. $img->writeImage($tempname);
  8661. $info = $this->_parsejpeg($tempname);
  8662. unlink($tempname);
  8663. $img->destroy();
  8664. } else {
  8665. return;
  8666. }
  8667. }
  8668. if ($info === false) {
  8669. //If false, we cannot process image
  8670. return;
  8671. }
  8672. $this->set_mqr($mqr);
  8673. if ($ismask) {
  8674. // force grayscale
  8675. $info['cs'] = 'DeviceGray';
  8676. }
  8677. if ($imgmask !== false) {
  8678. $info['masked'] = $imgmask;
  8679. }
  8680. if (!empty($exurl)) {
  8681. $info['exurl'] = $exurl;
  8682. }
  8683. // array of alternative images
  8684. $info['altimgs'] = $altimgs;
  8685. // add image to document
  8686. $info['i'] = $this->setImageBuffer($file, $info);
  8687. }
  8688. // set alignment
  8689. $this->img_rb_y = $y + $h;
  8690. // set alignment
  8691. if ($this->rtl) {
  8692. if ($palign == 'L') {
  8693. $ximg = $this->lMargin;
  8694. } elseif ($palign == 'C') {
  8695. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  8696. } elseif ($palign == 'R') {
  8697. $ximg = $this->w - $this->rMargin - $w;
  8698. } else {
  8699. $ximg = $x - $w;
  8700. }
  8701. $this->img_rb_x = $ximg;
  8702. } else {
  8703. if ($palign == 'L') {
  8704. $ximg = $this->lMargin;
  8705. } elseif ($palign == 'C') {
  8706. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  8707. } elseif ($palign == 'R') {
  8708. $ximg = $this->w - $this->rMargin - $w;
  8709. } else {
  8710. $ximg = $x;
  8711. }
  8712. $this->img_rb_x = $ximg + $w;
  8713. }
  8714. if ($ismask OR $hidden) {
  8715. // image is not displayed
  8716. return $info['i'];
  8717. }
  8718. $xkimg = $ximg * $this->k;
  8719. if (!$alt) {
  8720. // only non-alternative immages will be set
  8721. $this->_out(sprintf('q %F 0 0 %F %F %F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  8722. }
  8723. if (!empty($border)) {
  8724. $bx = $this->x;
  8725. $by = $this->y;
  8726. $this->x = $ximg;
  8727. if ($this->rtl) {
  8728. $this->x += $w;
  8729. }
  8730. $this->y = $y;
  8731. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  8732. $this->x = $bx;
  8733. $this->y = $by;
  8734. }
  8735. if ($link) {
  8736. $this->Link($ximg, $y, $w, $h, $link, 0);
  8737. }
  8738. // set pointer to align the next text/objects
  8739. switch ($align) {
  8740. case 'T': {
  8741. $this->y = $y;
  8742. $this->x = $this->img_rb_x;
  8743. break;
  8744. }
  8745. case 'M': {
  8746. $this->y = $y + round($h / 2);
  8747. $this->x = $this->img_rb_x;
  8748. break;
  8749. }
  8750. case 'B': {
  8751. $this->y = $this->img_rb_y;
  8752. $this->x = $this->img_rb_x;
  8753. break;
  8754. }
  8755. case 'N': {
  8756. $this->SetY($this->img_rb_y);
  8757. break;
  8758. }
  8759. default: {
  8760. break;
  8761. }
  8762. }
  8763. $this->endlinex = $this->img_rb_x;
  8764. if ($this->inxobj) {
  8765. // we are inside an XObject template
  8766. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  8767. }
  8768. return $info['i'];
  8769. }
  8770. /**
  8771. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  8772. * @param $mqr (boolean) FALSE for off, TRUE for on.
  8773. * @since 4.6.025 (2009-08-17)
  8774. */
  8775. public function set_mqr($mqr) {
  8776. if (!defined('PHP_VERSION_ID')) {
  8777. $version = PHP_VERSION;
  8778. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  8779. }
  8780. if (PHP_VERSION_ID < 50300) {
  8781. @set_magic_quotes_runtime($mqr);
  8782. }
  8783. }
  8784. /**
  8785. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  8786. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  8787. * @since 4.6.025 (2009-08-17)
  8788. */
  8789. public function get_mqr() {
  8790. if (!defined('PHP_VERSION_ID')) {
  8791. $version = PHP_VERSION;
  8792. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  8793. }
  8794. if (PHP_VERSION_ID < 50300) {
  8795. return @get_magic_quotes_runtime();
  8796. }
  8797. return 0;
  8798. }
  8799. /**
  8800. * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
  8801. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  8802. * @param $image (image) Image object.
  8803. * return image JPEG image object.
  8804. * @protected
  8805. */
  8806. protected function _toJPEG($image) {
  8807. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  8808. imagejpeg($image, $tempname, $this->jpeg_quality);
  8809. imagedestroy($image);
  8810. $retvars = $this->_parsejpeg($tempname);
  8811. // tidy up by removing temporary image
  8812. unlink($tempname);
  8813. return $retvars;
  8814. }
  8815. /**
  8816. * Convert the loaded image to a PNG and then return a structure for the PDF creator.
  8817. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  8818. * @param $image (image) Image object.
  8819. * return image PNG image object.
  8820. * @protected
  8821. * @since 4.9.016 (2010-04-20)
  8822. */
  8823. protected function _toPNG($image) {
  8824. // set temporary image file name
  8825. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  8826. // turn off interlaced mode
  8827. imageinterlace($image, 0);
  8828. // create temporary PNG image
  8829. imagepng($image, $tempname);
  8830. // remove image from memory
  8831. imagedestroy($image);
  8832. // get PNG image data
  8833. $retvars = $this->_parsepng($tempname);
  8834. // tidy up by removing temporary image
  8835. unlink($tempname);
  8836. return $retvars;
  8837. }
  8838. /**
  8839. * Set the transparency for the given GD image.
  8840. * @param $new_image (image) GD image object
  8841. * @param $image (image) GD image object.
  8842. * return GD image object.
  8843. * @protected
  8844. * @since 4.9.016 (2010-04-20)
  8845. */
  8846. protected function _setGDImageTransparency($new_image, $image) {
  8847. // transparency index
  8848. $tid = imagecolortransparent($image);
  8849. // default transparency color
  8850. $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
  8851. if ($tid >= 0) {
  8852. // get the colors for the transparency index
  8853. $tcol = imagecolorsforindex($image, $tid);
  8854. }
  8855. $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
  8856. imagefill($new_image, 0, 0, $tid);
  8857. imagecolortransparent($new_image, $tid);
  8858. return $new_image;
  8859. }
  8860. /**
  8861. * Extract info from a JPEG file without using the GD library.
  8862. * @param $file (string) image file to parse
  8863. * @return array structure containing the image data
  8864. * @protected
  8865. */
  8866. protected function _parsejpeg($file) {
  8867. $a = getimagesize($file);
  8868. if (empty($a)) {
  8869. $this->Error('Missing or incorrect image file: ' . $file);
  8870. }
  8871. if ($a[2] != 2) {
  8872. $this->Error('Not a JPEG file: ' . $file);
  8873. }
  8874. // bits per pixel
  8875. $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
  8876. // number of image channels
  8877. if (!isset($a['channels'])) {
  8878. $channels = 3;
  8879. } else {
  8880. $channels = intval($a['channels']);
  8881. }
  8882. // default colour space
  8883. switch ($channels) {
  8884. case 1: {
  8885. $colspace = 'DeviceGray';
  8886. break;
  8887. }
  8888. case 3: {
  8889. $colspace = 'DeviceRGB';
  8890. break;
  8891. }
  8892. case 4: {
  8893. $colspace = 'DeviceCMYK';
  8894. break;
  8895. }
  8896. default: {
  8897. $channels = 3;
  8898. $colspace = 'DeviceRGB';
  8899. break;
  8900. }
  8901. }
  8902. // get file content
  8903. $data = file_get_contents($file);
  8904. // check for embedded ICC profile
  8905. $icc = array();
  8906. $offset = 0;
  8907. while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
  8908. // get ICC sequence length
  8909. $length = ($this->_getUSHORT($data, ($pos - 2)) - 16);
  8910. // marker sequence number
  8911. $msn = max(1, ord($data[($pos + 12)]));
  8912. // number of markers (total of APP2 used)
  8913. $nom = max(1, ord($data[($pos + 13)]));
  8914. // get sequence segment
  8915. $icc[($msn - 1)] = substr($data, ($pos + 14), $length);
  8916. // move forward to next sequence
  8917. $offset = ($pos + 14 + $length);
  8918. }
  8919. // order and compact ICC segments
  8920. if (count($icc) > 0) {
  8921. ksort($icc);
  8922. $icc = implode('', $icc);
  8923. if ((ord($icc{36}) != 0x61) OR (ord($icc{37}) != 0x63) OR (ord($icc{38}) != 0x73) OR (ord($icc{39}) != 0x70)) {
  8924. // invalid ICC profile
  8925. $icc = false;
  8926. }
  8927. } else {
  8928. $icc = false;
  8929. }
  8930. return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
  8931. }
  8932. /**
  8933. * Extract info from a PNG file without using the GD library.
  8934. * @param $file (string) image file to parse
  8935. * @return array structure containing the image data
  8936. * @protected
  8937. */
  8938. protected function _parsepng($file) {
  8939. $f = fopen($file, 'rb');
  8940. if ($f === false) {
  8941. $this->Error('Can\'t open image file: ' . $file);
  8942. }
  8943. //Check signature
  8944. if (fread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10)) {
  8945. $this->Error('Not a PNG file: ' . $file);
  8946. }
  8947. //Read header chunk
  8948. fread($f, 4);
  8949. if (fread($f, 4) != 'IHDR') {
  8950. $this->Error('Incorrect PNG file: ' . $file);
  8951. }
  8952. $w = $this->_freadint($f);
  8953. $h = $this->_freadint($f);
  8954. $bpc = ord(fread($f, 1));
  8955. if ($bpc > 8) {
  8956. //$this->Error('16-bit depth not supported: '.$file);
  8957. fclose($f);
  8958. return false;
  8959. }
  8960. $ct = ord(fread($f, 1));
  8961. if ($ct == 0) {
  8962. $colspace = 'DeviceGray';
  8963. } elseif ($ct == 2) {
  8964. $colspace = 'DeviceRGB';
  8965. } elseif ($ct == 3) {
  8966. $colspace = 'Indexed';
  8967. } else {
  8968. // alpha channel
  8969. fclose($f);
  8970. return 'pngalpha';
  8971. }
  8972. if (ord(fread($f, 1)) != 0) {
  8973. //$this->Error('Unknown compression method: '.$file);
  8974. fclose($f);
  8975. return false;
  8976. }
  8977. if (ord(fread($f, 1)) != 0) {
  8978. //$this->Error('Unknown filter method: '.$file);
  8979. fclose($f);
  8980. return false;
  8981. }
  8982. if (ord(fread($f, 1)) != 0) {
  8983. //$this->Error('Interlacing not supported: '.$file);
  8984. fclose($f);
  8985. return false;
  8986. }
  8987. fread($f, 4);
  8988. $channels = ($ct == 2 ? 3 : 1);
  8989. $parms = '/DecodeParms << /Predictor 15 /Colors ' . $channels . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . ' >>';
  8990. //Scan chunks looking for palette, transparency and image data
  8991. $pal = '';
  8992. $trns = '';
  8993. $data = '';
  8994. $icc = false;
  8995. do {
  8996. $n = $this->_freadint($f);
  8997. $type = fread($f, 4);
  8998. if ($type == 'PLTE') {
  8999. // read palette
  9000. $pal = $this->rfread($f, $n);
  9001. fread($f, 4);
  9002. } elseif ($type == 'tRNS') {
  9003. // read transparency info
  9004. $t = $this->rfread($f, $n);
  9005. if ($ct == 0) {
  9006. $trns = array(ord($t{1}));
  9007. } elseif ($ct == 2) {
  9008. $trns = array(ord($t{1}), ord($t{3}), ord($t{5}));
  9009. } else {
  9010. $pos = strpos($t, chr(0));
  9011. if ($pos !== false) {
  9012. $trns = array($pos);
  9013. }
  9014. }
  9015. fread($f, 4);
  9016. } elseif ($type == 'IDAT') {
  9017. // read image data block
  9018. $data .= $this->rfread($f, $n);
  9019. fread($f, 4);
  9020. } elseif ($type == 'iCCP') {
  9021. // skip profile name
  9022. $len = 0;
  9023. while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
  9024. ++$len;
  9025. }
  9026. // skip null separator
  9027. fread($f, 1);
  9028. // get compression method
  9029. if (ord(fread($f, 1)) != 0) {
  9030. //$this->Error('Unknown filter method: '.$file);
  9031. fclose($f);
  9032. return false;
  9033. }
  9034. // read ICC Color Profile
  9035. $icc = $this->rfread($f, ($n - $len - 2));
  9036. // decompress profile
  9037. $icc = gzuncompress($icc);
  9038. fread($f, 4);
  9039. } elseif ($type == 'IEND') {
  9040. break;
  9041. } else {
  9042. $this->rfread($f, $n + 4);
  9043. }
  9044. } while ($n);
  9045. if (($colspace == 'Indexed') AND (empty($pal))) {
  9046. //$this->Error('Missing palette in '.$file);
  9047. fclose($f);
  9048. return false;
  9049. }
  9050. fclose($f);
  9051. return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  9052. }
  9053. /**
  9054. * Binary-safe and URL-safe file read.
  9055. * 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.
  9056. * @param $handle (resource)
  9057. * @param $length (int)
  9058. * @return Returns the read string or FALSE in case of error.
  9059. * @author Nicola Asuni
  9060. * @protected
  9061. * @since 4.5.027 (2009-03-16)
  9062. */
  9063. protected function rfread($handle, $length) {
  9064. $data = fread($handle, $length);
  9065. if ($data === false) {
  9066. return false;
  9067. }
  9068. $rest = $length - strlen($data);
  9069. if ($rest > 0) {
  9070. $data .= $this->rfread($handle, $rest);
  9071. }
  9072. return $data;
  9073. }
  9074. /**
  9075. * Extract info from a PNG image with alpha channel using the GD library.
  9076. * @param $file (string) Name of the file containing the image.
  9077. * @param $x (float) Abscissa of the upper-left corner.
  9078. * @param $y (float) Ordinate of the upper-left corner.
  9079. * @param $wpx (float) Original width of the image in pixels.
  9080. * @param $hpx (float) original height of the image in pixels.
  9081. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9082. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9083. * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  9084. * @param $link (mixed) URL or identifier returned by AddLink().
  9085. * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  9086. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  9087. * @param $dpi (int) dot-per-inch resolution used on resize
  9088. * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  9089. * @param $filehash (string) File hash used to build unique file names.
  9090. * @author Nicola Asuni
  9091. * @protected
  9092. * @since 4.3.007 (2008-12-04)
  9093. * @see Image()
  9094. */
  9095. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash = '') {
  9096. if (empty($filehash)) {
  9097. $filehash = md5($this->file_id . $file);
  9098. }
  9099. // create temp image file (without alpha channel)
  9100. $tempfile_plain = K_PATH_CACHE . 'mskp_' . $filehash;
  9101. // create temp alpha file
  9102. $tempfile_alpha = K_PATH_CACHE . 'mska_' . $filehash;
  9103. if (extension_loaded('imagick')) { // ImageMagick extension
  9104. // ImageMagick library
  9105. $img = new Imagick();
  9106. $img->readImage($file);
  9107. // clone image object
  9108. $imga = $this->objclone($img);
  9109. // extract alpha channel
  9110. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  9111. $img->negateImage(true);
  9112. $img->setImageFormat('png');
  9113. $img->writeImage($tempfile_alpha);
  9114. // remove alpha channel
  9115. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  9116. $imga->setImageFormat('png');
  9117. $imga->writeImage($tempfile_plain);
  9118. } elseif (function_exists('imagecreatefrompng')) { // GD extension
  9119. // generate images
  9120. $img = imagecreatefrompng($file);
  9121. $imgalpha = imagecreate($wpx, $hpx);
  9122. // generate gray scale palette (0 -> 255)
  9123. for ($c = 0; $c < 256; ++$c) {
  9124. ImageColorAllocate($imgalpha, $c, $c, $c);
  9125. }
  9126. // extract alpha channel
  9127. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  9128. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  9129. $color = imagecolorat($img, $xpx, $ypx);
  9130. $alpha = $this->getGDgamma($color); // correct gamma
  9131. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  9132. }
  9133. }
  9134. imagepng($imgalpha, $tempfile_alpha);
  9135. imagedestroy($imgalpha);
  9136. // extract image without alpha channel
  9137. $imgplain = imagecreatetruecolor($wpx, $hpx);
  9138. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  9139. imagepng($imgplain, $tempfile_plain);
  9140. imagedestroy($imgplain);
  9141. } else {
  9142. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  9143. }
  9144. // embed mask image
  9145. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  9146. // embed image, masked with previously embedded mask
  9147. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  9148. // remove temp files
  9149. unlink($tempfile_alpha);
  9150. unlink($tempfile_plain);
  9151. }
  9152. /**
  9153. * Get the GD-corrected PNG gamma value from alpha color
  9154. * @param $c (int) alpha color
  9155. * @protected
  9156. * @since 4.3.007 (2008-12-04)
  9157. */
  9158. protected function getGDgamma($c) {
  9159. if (!isset($this->gdgammacache["'" . $c . "'"])) {
  9160. // shifts off the first 24 bits (where 8x3 are used for each color),
  9161. // and returns the remaining 7 allocated bits (commonly used for alpha)
  9162. $alpha = ($c >> 24);
  9163. // GD alpha is only 7 bit (0 -> 127)
  9164. $alpha = (((127 - $alpha) / 127) * 255);
  9165. // correct gamma
  9166. $this->gdgammacache["'" . $c . "'"] = (pow(($alpha / 255), 2.2) * 255);
  9167. // store the latest values on cache to improve performances
  9168. if (count($this->gdgammacache) > 8) {
  9169. // remove one element from the cache array
  9170. array_shift($this->gdgammacache);
  9171. }
  9172. }
  9173. return $this->gdgammacache["'" . $c . "'"];
  9174. }
  9175. /**
  9176. * Performs a line break.
  9177. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  9178. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  9179. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  9180. * @public
  9181. * @since 1.0
  9182. * @see Cell()
  9183. */
  9184. public function Ln($h = '', $cell = false) {
  9185. if (($this->num_columns > 1) AND ($this->y == $this->columns[$this->current_column]['y']) AND isset($this->columns[$this->current_column]['x']) AND ($this->x == $this->columns[$this->current_column]['x'])) {
  9186. // revove vertical space from the top of the column
  9187. return;
  9188. }
  9189. if ($cell) {
  9190. if ($this->rtl) {
  9191. $cellpadding = $this->cell_padding['R'];
  9192. } else {
  9193. $cellpadding = $this->cell_padding['L'];
  9194. }
  9195. } else {
  9196. $cellpadding = 0;
  9197. }
  9198. if ($this->rtl) {
  9199. $this->x = $this->w - $this->rMargin - $cellpadding;
  9200. } else {
  9201. $this->x = $this->lMargin + $cellpadding;
  9202. }
  9203. if (is_string($h)) {
  9204. $this->y += $this->lasth;
  9205. } else {
  9206. $this->y += $h;
  9207. }
  9208. $this->newline = true;
  9209. }
  9210. /**
  9211. * Returns the relative X value of current position.
  9212. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  9213. * @return float
  9214. * @public
  9215. * @since 1.2
  9216. * @see SetX(), GetY(), SetY()
  9217. */
  9218. public function GetX() {
  9219. //Get x position
  9220. if ($this->rtl) {
  9221. return ($this->w - $this->x);
  9222. } else {
  9223. return $this->x;
  9224. }
  9225. }
  9226. /**
  9227. * Returns the absolute X value of current position.
  9228. * @return float
  9229. * @public
  9230. * @since 1.2
  9231. * @see SetX(), GetY(), SetY()
  9232. */
  9233. public function GetAbsX() {
  9234. return $this->x;
  9235. }
  9236. /**
  9237. * Returns the ordinate of the current position.
  9238. * @return float
  9239. * @public
  9240. * @since 1.0
  9241. * @see SetY(), GetX(), SetX()
  9242. */
  9243. public function GetY() {
  9244. return $this->y;
  9245. }
  9246. /**
  9247. * Defines the abscissa of the current position.
  9248. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  9249. * @param $x (float) The value of the abscissa in user units.
  9250. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  9251. * @public
  9252. * @since 1.2
  9253. * @see GetX(), GetY(), SetY(), SetXY()
  9254. */
  9255. public function SetX($x, $rtloff = false) {
  9256. $x = floatval($x);
  9257. if (!$rtloff AND $this->rtl) {
  9258. if ($x >= 0) {
  9259. $this->x = $this->w - $x;
  9260. } else {
  9261. $this->x = abs($x);
  9262. }
  9263. } else {
  9264. if ($x >= 0) {
  9265. $this->x = $x;
  9266. } else {
  9267. $this->x = $this->w + $x;
  9268. }
  9269. }
  9270. if ($this->x < 0) {
  9271. $this->x = 0;
  9272. }
  9273. if ($this->x > $this->w) {
  9274. $this->x = $this->w;
  9275. }
  9276. }
  9277. /**
  9278. * Moves the current abscissa back to the left margin and sets the ordinate.
  9279. * If the passed value is negative, it is relative to the bottom of the page.
  9280. * @param $y (float) The value of the ordinate in user units.
  9281. * @param $resetx (bool) if true (default) reset the X position.
  9282. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  9283. * @public
  9284. * @since 1.0
  9285. * @see GetX(), GetY(), SetY(), SetXY()
  9286. */
  9287. public function SetY($y, $resetx = true, $rtloff = false) {
  9288. $y = floatval($y);
  9289. if ($resetx) {
  9290. //reset x
  9291. if (!$rtloff AND $this->rtl) {
  9292. $this->x = $this->w - $this->rMargin;
  9293. } else {
  9294. $this->x = $this->lMargin;
  9295. }
  9296. }
  9297. if ($y >= 0) {
  9298. $this->y = $y;
  9299. } else {
  9300. $this->y = $this->h + $y;
  9301. }
  9302. if ($this->y < 0) {
  9303. $this->y = 0;
  9304. }
  9305. if ($this->y > $this->h) {
  9306. $this->y = $this->h;
  9307. }
  9308. }
  9309. /**
  9310. * Defines the abscissa and ordinate of the current position.
  9311. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  9312. * @param $x (float) The value of the abscissa.
  9313. * @param $y (float) The value of the ordinate.
  9314. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  9315. * @public
  9316. * @since 1.2
  9317. * @see SetX(), SetY()
  9318. */
  9319. public function SetXY($x, $y, $rtloff = false) {
  9320. $this->SetY($y, false, $rtloff);
  9321. $this->SetX($x, $rtloff);
  9322. }
  9323. /**
  9324. * Set the absolute X coordinate of the current pointer.
  9325. * @param $x (float) The value of the abscissa in user units.
  9326. * @public
  9327. * @since 5.9.186 (2012-09-13)
  9328. * @see setAbsX(), setAbsY(), SetAbsXY()
  9329. */
  9330. public function SetAbsX($x) {
  9331. $this->x = floatval($x);
  9332. }
  9333. /**
  9334. * Set the absolute Y coordinate of the current pointer.
  9335. * @param $y (float) (float) The value of the ordinate in user units.
  9336. * @public
  9337. * @since 5.9.186 (2012-09-13)
  9338. * @see setAbsX(), setAbsY(), SetAbsXY()
  9339. */
  9340. public function SetAbsY($y) {
  9341. $this->y = floatval($y);
  9342. }
  9343. /**
  9344. * Set the absolute X and Y coordinates of the current pointer.
  9345. * @param $x (float) The value of the abscissa in user units.
  9346. * @param $y (float) (float) The value of the ordinate in user units.
  9347. * @public
  9348. * @since 5.9.186 (2012-09-13)
  9349. * @see setAbsX(), setAbsY(), SetAbsXY()
  9350. */
  9351. public function SetAbsXY($x, $y) {
  9352. $this->SetAbsX($x);
  9353. $this->SetAbsY($y);
  9354. }
  9355. /**
  9356. * Ouput input data and compress it if possible.
  9357. * @param $data (string) Data to output.
  9358. * @param $length (int) Data length in bytes.
  9359. * @protected
  9360. * @since 5.9.086
  9361. */
  9362. protected function sendOutputData($data, $length) {
  9363. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  9364. // the content length may vary if the server is using compression
  9365. header('Content-Length: ' . $length);
  9366. }
  9367. echo $data;
  9368. }
  9369. /**
  9370. * Send the document to a given destination: string, local file or browser.
  9371. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  9372. * The method first calls Close() if necessary to terminate the document.
  9373. * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  9374. * @param $dest (string) Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string (name is ignored).</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li><li>E: return the document as base64 mime multi-part email attachment (RFC 2045)</li></ul>
  9375. * @public
  9376. * @since 1.0
  9377. * @see Close()
  9378. */
  9379. public function Output($name = 'doc.pdf', $dest = 'I') {
  9380. //Output PDF to some destination
  9381. //Finish document if necessary
  9382. if ($this->state < 3) {
  9383. $this->Close();
  9384. }
  9385. //Normalize parameters
  9386. if (is_bool($dest)) {
  9387. $dest = $dest ? 'D' : 'F';
  9388. }
  9389. $dest = strtoupper($dest);
  9390. if ($dest{0} != 'F') {
  9391. $name = preg_replace('/[\s]+/', '_', $name);
  9392. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  9393. }
  9394. if ($this->sign) {
  9395. // *** apply digital signature to the document ***
  9396. // get the document content
  9397. $pdfdoc = $this->getBuffer();
  9398. // remove last newline
  9399. $pdfdoc = substr($pdfdoc, 0, -1);
  9400. // Remove the original buffer
  9401. if (isset($this->diskcache) AND $this->diskcache) {
  9402. // remove buffer file from cache
  9403. unlink($this->buffer);
  9404. }
  9405. unset($this->buffer);
  9406. // remove filler space
  9407. $byterange_string_len = strlen($this->byterange_string);
  9408. // define the ByteRange
  9409. $byte_range = array();
  9410. $byte_range[0] = 0;
  9411. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  9412. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  9413. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  9414. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . substr($pdfdoc, $byte_range[2]);
  9415. // replace the ByteRange
  9416. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  9417. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  9418. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  9419. // write the document to a temporary folder
  9420. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  9421. $f = fopen($tempdoc, 'wb');
  9422. if (!$f) {
  9423. $this->Error('Unable to create temporary file: ' . $tempdoc);
  9424. }
  9425. $pdfdoc_length = strlen($pdfdoc);
  9426. fwrite($f, $pdfdoc, $pdfdoc_length);
  9427. fclose($f);
  9428. // get digital signature via openssl library
  9429. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  9430. if (empty($this->signature_data['extracerts'])) {
  9431. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  9432. } else {
  9433. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']);
  9434. }
  9435. unlink($tempdoc);
  9436. // read signature
  9437. $signature = file_get_contents($tempsign);
  9438. unlink($tempsign);
  9439. // extract signature
  9440. $signature = substr($signature, $pdfdoc_length);
  9441. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  9442. $tmparr = explode("\n\n", $signature);
  9443. $signature = $tmparr[1];
  9444. unset($tmparr);
  9445. // decode signature
  9446. $signature = base64_decode(trim($signature));
  9447. // convert signature to hex
  9448. $signature = current(unpack('H*', $signature));
  9449. $signature = str_pad($signature, $this->signature_max_length, '0');
  9450. // disable disk caching
  9451. $this->diskcache = false;
  9452. // Add signature to the document
  9453. $this->buffer = substr($pdfdoc, 0, $byte_range[1]) . '<' . $signature . '>' . substr($pdfdoc, $byte_range[1]);
  9454. $this->bufferlen = strlen($this->buffer);
  9455. }
  9456. switch ($dest) {
  9457. case 'I': {
  9458. // Send PDF to the standard output
  9459. if (ob_get_contents()) {
  9460. $this->Error('Some data has already been output, can\'t send PDF file');
  9461. }
  9462. if (php_sapi_name() != 'cli') {
  9463. // send output to a browser
  9464. header('Content-Type: application/pdf');
  9465. if (headers_sent()) {
  9466. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9467. }
  9468. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  9469. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9470. header('Pragma: public');
  9471. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9472. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9473. header('Content-Disposition: inline; filename="' . basename($name) . '"');
  9474. $this->sendOutputData($this->getBuffer(), $this->bufferlen);
  9475. } else {
  9476. echo $this->getBuffer();
  9477. }
  9478. break;
  9479. }
  9480. case 'D': {
  9481. // download PDF as file
  9482. if (ob_get_contents()) {
  9483. $this->Error('Some data has already been output, can\'t send PDF file');
  9484. }
  9485. header('Content-Description: File Transfer');
  9486. if (headers_sent()) {
  9487. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9488. }
  9489. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  9490. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9491. header('Pragma: public');
  9492. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9493. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9494. // force download dialog
  9495. if (strpos(php_sapi_name(), 'cgi') === false) {
  9496. header('Content-Type: application/force-download');
  9497. header('Content-Type: application/octet-stream', false);
  9498. header('Content-Type: application/download', false);
  9499. header('Content-Type: application/pdf', false);
  9500. } else {
  9501. header('Content-Type: application/pdf');
  9502. }
  9503. // use the Content-Disposition header to supply a recommended filename
  9504. header('Content-Disposition: attachment; filename="' . basename($name) . '"');
  9505. header('Content-Transfer-Encoding: binary');
  9506. $this->sendOutputData($this->getBuffer(), $this->bufferlen);
  9507. break;
  9508. }
  9509. case 'F':
  9510. case 'FI':
  9511. case 'FD': {
  9512. // save PDF to a local file
  9513. if ($this->diskcache) {
  9514. copy($this->buffer, $name);
  9515. } else {
  9516. $f = fopen($name, 'wb');
  9517. if (!$f) {
  9518. $this->Error('Unable to create output file: ' . $name);
  9519. }
  9520. fwrite($f, $this->getBuffer(), $this->bufferlen);
  9521. fclose($f);
  9522. }
  9523. if ($dest == 'FI') {
  9524. // send headers to browser
  9525. header('Content-Type: application/pdf');
  9526. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  9527. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9528. header('Pragma: public');
  9529. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9530. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9531. header('Content-Disposition: inline; filename="' . basename($name) . '"');
  9532. $this->sendOutputData(file_get_contents($name), filesize($name));
  9533. } elseif ($dest == 'FD') {
  9534. // send headers to browser
  9535. if (ob_get_contents()) {
  9536. $this->Error('Some data has already been output, can\'t send PDF file');
  9537. }
  9538. header('Content-Description: File Transfer');
  9539. if (headers_sent()) {
  9540. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9541. }
  9542. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  9543. header('Pragma: public');
  9544. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9545. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9546. // force download dialog
  9547. if (strpos(php_sapi_name(), 'cgi') === false) {
  9548. header('Content-Type: application/force-download');
  9549. header('Content-Type: application/octet-stream', false);
  9550. header('Content-Type: application/download', false);
  9551. header('Content-Type: application/pdf', false);
  9552. } else {
  9553. header('Content-Type: application/pdf');
  9554. }
  9555. // use the Content-Disposition header to supply a recommended filename
  9556. header('Content-Disposition: attachment; filename="' . basename($name) . '"');
  9557. header('Content-Transfer-Encoding: binary');
  9558. $this->sendOutputData(file_get_contents($name), filesize($name));
  9559. }
  9560. break;
  9561. }
  9562. case 'E': {
  9563. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  9564. $retval = 'Content-Type: application/pdf;' . "\r\n";
  9565. $retval .= ' name="' . $name . '"' . "\r\n";
  9566. $retval .= 'Content-Transfer-Encoding: base64' . "\r\n";
  9567. $retval .= 'Content-Disposition: attachment;' . "\r\n";
  9568. $retval .= ' filename="' . $name . '"' . "\r\n\r\n";
  9569. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  9570. return $retval;
  9571. }
  9572. case 'S': {
  9573. // returns PDF as a string
  9574. return $this->getBuffer();
  9575. }
  9576. default: {
  9577. $this->Error('Incorrect output destination: ' . $dest);
  9578. }
  9579. }
  9580. return '';
  9581. }
  9582. /**
  9583. * Unset all class variables except the following critical variables.
  9584. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  9585. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  9586. * @public
  9587. * @since 4.5.016 (2009-02-24)
  9588. */
  9589. public function _destroy($destroyall = false, $preserve_objcopy = false) {
  9590. if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) {
  9591. // remove buffer file from cache
  9592. unlink($this->buffer);
  9593. }
  9594. if ($destroyall AND isset($this->cached_files) AND !empty($this->cached_files)) {
  9595. // remove cached files
  9596. foreach ($this->cached_files as $cachefile) {
  9597. if (is_file($cachefile)) {
  9598. unlink($cachefile);
  9599. }
  9600. }
  9601. unset($this->cached_files);
  9602. }
  9603. foreach (array_keys(get_object_vars($this)) as $val) {
  9604. if ($destroyall OR (
  9605. ($val != 'internal_encoding')
  9606. AND ($val != 'state')
  9607. AND ($val != 'bufferlen')
  9608. AND ($val != 'buffer')
  9609. AND ($val != 'diskcache')
  9610. AND ($val != 'cached_files')
  9611. AND ($val != 'sign')
  9612. AND ($val != 'signature_data')
  9613. AND ($val != 'signature_max_length')
  9614. AND ($val != 'byterange_string')
  9615. )) {
  9616. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
  9617. unset($this->$val);
  9618. }
  9619. }
  9620. }
  9621. }
  9622. /**
  9623. * Check for locale-related bug
  9624. * @protected
  9625. */
  9626. protected function _dochecks() {
  9627. //Check for locale-related bug
  9628. if (1.1 == 1) {
  9629. $this->Error('Don\'t alter the locale before including class file');
  9630. }
  9631. //Check for decimal separator
  9632. if (sprintf('%.1F', 1.0) != '1.0') {
  9633. setlocale(LC_NUMERIC, 'C');
  9634. }
  9635. }
  9636. /**
  9637. * Return fonts path
  9638. * @return string
  9639. * @protected
  9640. */
  9641. protected function _getfontpath() {
  9642. if (!defined('K_PATH_FONTS') AND is_dir(dirname(__FILE__) . '/fonts')) {
  9643. define('K_PATH_FONTS', dirname(__FILE__) . '/fonts/');
  9644. }
  9645. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  9646. }
  9647. /**
  9648. * Return an array containing variations for the basic page number alias.
  9649. * @param $a (string) Base alias.
  9650. * @return array of page number aliases
  9651. * @protected
  9652. */
  9653. protected function getInternalPageNumberAliases($a = '') {
  9654. $alias = array();
  9655. // build array of Unicode + ASCII variants (the order is important)
  9656. $alias = array('u' => array(), 'a' => array());
  9657. $u = '{' . $a . '}';
  9658. $alias['u'][] = $this->_escape($u);
  9659. if ($this->isunicode) {
  9660. $alias['u'][] = $this->_escape($this->UTF8ToLatin1($u));
  9661. $alias['u'][] = $this->_escape($this->utf8StrRev($u, false, $this->tmprtl));
  9662. $alias['a'][] = $this->_escape($this->UTF8ToLatin1($a));
  9663. $alias['a'][] = $this->_escape($this->utf8StrRev($a, false, $this->tmprtl));
  9664. }
  9665. $alias['a'][] = $this->_escape($a);
  9666. return $alias;
  9667. }
  9668. /**
  9669. * Return an array containing all internal page aliases.
  9670. * @return array of page number aliases
  9671. * @protected
  9672. */
  9673. protected function getAllInternalPageNumberAliases() {
  9674. $basic_alias = array($this->alias_tot_pages, $this->alias_num_page, $this->alias_group_tot_pages, $this->alias_group_num_page, $this->alias_right_shift);
  9675. $pnalias = array();
  9676. foreach ($basic_alias as $k => $a) {
  9677. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  9678. }
  9679. return $pnalias;
  9680. }
  9681. /**
  9682. * Replace page number aliases with number.
  9683. * @param $page (string) Page content.
  9684. * @param $replace (array) Array of replacements (array keys are replacement strings, values are alias arrays).
  9685. * @param $diff (int) If passed, this will be set to the total char number difference between alias and replacements.
  9686. * @return replaced page content and updated $diff parameter as array.
  9687. * @protected
  9688. */
  9689. protected function replacePageNumAliases($page, $replace, $diff = 0) {
  9690. foreach ($replace as $rep) {
  9691. foreach ($rep[3] as $a) {
  9692. if (strpos($page, $a) !== false) {
  9693. $page = str_replace($a, $rep[0], $page);
  9694. $diff += ($rep[2] - $rep[1]);
  9695. }
  9696. }
  9697. }
  9698. return array($page, $diff);
  9699. }
  9700. /**
  9701. * Replace right shift page number aliases with spaces to correct right alignment.
  9702. * This works perfectly only when using monospaced fonts.
  9703. * @param $page (string) Page content.
  9704. * @param $aliases (array) Array of page aliases.
  9705. * @param $diff (int) initial difference to add.
  9706. * @return replaced page content.
  9707. * @protected
  9708. */
  9709. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
  9710. foreach ($aliases as $type => $alias) {
  9711. foreach ($alias as $a) {
  9712. // find position of compensation factor
  9713. $startnum = (strpos($a, ':') + 1);
  9714. $a = substr($a, 0, $startnum);
  9715. if (($pos = strpos($page, $a)) !== false) {
  9716. // end of alias
  9717. $endnum = strpos($page, '}', $pos);
  9718. // string to be replaced
  9719. $aa = substr($page, $pos, ($endnum - $pos + 1));
  9720. // get compensation factor
  9721. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  9722. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  9723. $ratio = floatval($ratio);
  9724. if ($type == 'u') {
  9725. $chrdiff = floor(($diff + 12) * $ratio);
  9726. $shift = str_repeat(' ', $chrdiff);
  9727. $shift = $this->UTF8ToUTF16BE($shift, false);
  9728. } else {
  9729. $chrdiff = floor(($diff + 11) * $ratio);
  9730. $shift = str_repeat(' ', $chrdiff);
  9731. }
  9732. $page = str_replace($aa, $shift, $page);
  9733. }
  9734. }
  9735. }
  9736. return $page;
  9737. }
  9738. /**
  9739. * Set page boxes to be included on page descriptions.
  9740. * @param $boxes (array) Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  9741. * @protected
  9742. */
  9743. protected function setPageBoxTypes($boxes) {
  9744. $validboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  9745. $this->page_boxes = array();
  9746. foreach ($boxes as $box) {
  9747. if (in_array($box, $validboxes)) {
  9748. $this->page_boxes[] = $box;
  9749. }
  9750. }
  9751. }
  9752. /**
  9753. * Output pages (and replace page number aliases).
  9754. * @protected
  9755. */
  9756. protected function _putpages() {
  9757. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  9758. // get internal aliases for page numbers
  9759. $pnalias = $this->getAllInternalPageNumberAliases();
  9760. $num_pages = $this->numpages;
  9761. $ptpa = $this->formatPageNumber(($this->starting_page_number + $num_pages - 1));
  9762. $ptpu = $this->UTF8ToUTF16BE($ptpa, false);
  9763. $ptp_num_chars = $this->GetNumChars($ptpa);
  9764. $pagegroupnum = 0;
  9765. $groupnum = 0;
  9766. $ptgu = 1;
  9767. $ptga = 1;
  9768. for ($n = 1; $n <= $num_pages; ++$n) {
  9769. // get current page
  9770. $temppage = $this->getPageBuffer($n);
  9771. $pagelen = strlen($temppage);
  9772. // set replacements for total pages number
  9773. $pnpa = $this->formatPageNumber(($this->starting_page_number + $n - 1));
  9774. $pnpu = $this->UTF8ToUTF16BE($pnpa, false);
  9775. $pnp_num_chars = $this->GetNumChars($pnpa);
  9776. $pdiff = 0; // difference used for right shift alignment of page numbers
  9777. $gdiff = 0; // difference used for right shift alignment of page group numbers
  9778. if (!empty($this->pagegroups)) {
  9779. if (isset($this->newpagegroup[$n])) {
  9780. $pagegroupnum = 0;
  9781. ++$groupnum;
  9782. $ptga = $this->formatPageNumber($this->pagegroups[$groupnum]);
  9783. $ptgu = $this->UTF8ToUTF16BE($ptga, false);
  9784. $ptg_num_chars = $this->GetNumChars($ptga);
  9785. }
  9786. ++$pagegroupnum;
  9787. $pnga = $this->formatPageNumber($pagegroupnum);
  9788. $pngu = $this->UTF8ToUTF16BE($pnga, false);
  9789. $png_num_chars = $this->GetNumChars($pnga);
  9790. // replace page numbers
  9791. $replace = array();
  9792. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  9793. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  9794. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  9795. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  9796. list($temppage, $gdiff) = $this->replacePageNumAliases($temppage, $replace, $gdiff);
  9797. }
  9798. // replace page numbers
  9799. $replace = array();
  9800. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  9801. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  9802. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  9803. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  9804. list($temppage, $pdiff) = $this->replacePageNumAliases($temppage, $replace, $pdiff);
  9805. // replace right shift alias
  9806. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  9807. // replace EPS marker
  9808. $temppage = str_replace($this->epsmarker, '', $temppage);
  9809. //Page
  9810. $this->page_obj_id[$n] = $this->_newobj();
  9811. $out = '<<';
  9812. $out .= ' /Type /Page';
  9813. $out .= ' /Parent 1 0 R';
  9814. $out .= ' /LastModified ' . $this->_datestring(0, $this->doc_modification_timestamp);
  9815. $out .= ' /Resources 2 0 R';
  9816. foreach ($this->page_boxes as $box) {
  9817. $out .= ' /' . $box;
  9818. $out .= sprintf(' [%F %F %F %F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  9819. }
  9820. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  9821. $out .= ' /BoxColorInfo <<';
  9822. foreach ($this->page_boxes as $box) {
  9823. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  9824. $out .= ' /' . $box . ' <<';
  9825. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  9826. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  9827. $out .= ' /C [';
  9828. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  9829. $out .= ' ]';
  9830. }
  9831. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  9832. $out .= ' /W ' . ($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  9833. }
  9834. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  9835. $out .= ' /S /' . $this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  9836. }
  9837. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  9838. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  9839. $out .= ' /D [';
  9840. foreach ($dashes as $dash) {
  9841. $out .= sprintf(' %F', ($dash * $this->k));
  9842. }
  9843. $out .= ' ]';
  9844. }
  9845. $out .= ' >>';
  9846. }
  9847. }
  9848. $out .= ' >>';
  9849. }
  9850. $out .= ' /Contents ' . ($this->n + 1) . ' 0 R';
  9851. $out .= ' /Rotate ' . $this->pagedim[$n]['Rotate'];
  9852. if (!$this->pdfa_mode) {
  9853. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  9854. }
  9855. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  9856. // page transitions
  9857. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  9858. $out .= ' /Dur ' . $this->pagedim[$n]['trans']['Dur'];
  9859. }
  9860. $out .= ' /Trans <<';
  9861. $out .= ' /Type /Trans';
  9862. if (isset($this->pagedim[$n]['trans']['S'])) {
  9863. $out .= ' /S /' . $this->pagedim[$n]['trans']['S'];
  9864. }
  9865. if (isset($this->pagedim[$n]['trans']['D'])) {
  9866. $out .= ' /D ' . $this->pagedim[$n]['trans']['D'];
  9867. }
  9868. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  9869. $out .= ' /Dm /' . $this->pagedim[$n]['trans']['Dm'];
  9870. }
  9871. if (isset($this->pagedim[$n]['trans']['M'])) {
  9872. $out .= ' /M /' . $this->pagedim[$n]['trans']['M'];
  9873. }
  9874. if (isset($this->pagedim[$n]['trans']['Di'])) {
  9875. $out .= ' /Di ' . $this->pagedim[$n]['trans']['Di'];
  9876. }
  9877. if (isset($this->pagedim[$n]['trans']['SS'])) {
  9878. $out .= ' /SS ' . $this->pagedim[$n]['trans']['SS'];
  9879. }
  9880. if (isset($this->pagedim[$n]['trans']['B'])) {
  9881. $out .= ' /B ' . $this->pagedim[$n]['trans']['B'];
  9882. }
  9883. $out .= ' >>';
  9884. }
  9885. $out .= $this->_getannotsrefs($n);
  9886. $out .= ' /PZ ' . $this->pagedim[$n]['PZ'];
  9887. $out .= ' >>';
  9888. $out .= "\n" . 'endobj';
  9889. $this->_out($out);
  9890. //Page content
  9891. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  9892. $this->_newobj();
  9893. $p = $this->_getrawstream($p);
  9894. $this->_out('<<' . $filter . '/Length ' . strlen($p) . '>> stream' . "\n" . $p . "\n" . 'endstream' . "\n" . 'endobj');
  9895. if ($this->diskcache) {
  9896. // remove temporary files
  9897. unlink($this->pages[$n]);
  9898. }
  9899. }
  9900. //Pages root
  9901. $out = $this->_getobj(1) . "\n";
  9902. $out .= '<< /Type /Pages /Kids [';
  9903. foreach ($this->page_obj_id as $page_obj) {
  9904. $out .= ' ' . $page_obj . ' 0 R';
  9905. }
  9906. $out .= ' ] /Count ' . $num_pages . ' >>';
  9907. $out .= "\n" . 'endobj';
  9908. $this->_out($out);
  9909. }
  9910. /**
  9911. * Output references to page annotations
  9912. * @param $n (int) page number
  9913. * @protected
  9914. * @author Nicola Asuni
  9915. * @since 4.7.000 (2008-08-29)
  9916. * @deprecated
  9917. */
  9918. protected function _putannotsrefs($n) {
  9919. $this->_out($this->_getannotsrefs($n));
  9920. }
  9921. /**
  9922. * Get references to page annotations.
  9923. * @param $n (int) page number
  9924. * @return string
  9925. * @protected
  9926. * @author Nicola Asuni
  9927. * @since 5.0.010 (2010-05-17)
  9928. */
  9929. protected function _getannotsrefs($n) {
  9930. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  9931. return '';
  9932. }
  9933. $out = ' /Annots [';
  9934. if (isset($this->PageAnnots[$n])) {
  9935. foreach ($this->PageAnnots[$n] as $key => $val) {
  9936. if (!in_array($val['n'], $this->radio_groups)) {
  9937. $out .= ' ' . $val['n'] . ' 0 R';
  9938. }
  9939. }
  9940. // add radiobutton groups
  9941. if (isset($this->radiobutton_groups[$n])) {
  9942. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  9943. if (isset($data['n'])) {
  9944. $out .= ' ' . $data['n'] . ' 0 R';
  9945. }
  9946. }
  9947. }
  9948. }
  9949. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  9950. // set reference for signature object
  9951. $out .= ' ' . $this->sig_obj_id . ' 0 R';
  9952. }
  9953. if (!empty($this->empty_signature_appearance)) {
  9954. foreach ($this->empty_signature_appearance as $esa) {
  9955. if ($esa['page'] == $n) {
  9956. // set reference for empty signature objects
  9957. $out .= ' ' . $esa['objid'] . ' 0 R';
  9958. }
  9959. }
  9960. }
  9961. $out .= ' ]';
  9962. return $out;
  9963. }
  9964. /**
  9965. * Output annotations objects for all pages.
  9966. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  9967. * See section 12.5 of PDF 32000_2008 reference.
  9968. * @protected
  9969. * @author Nicola Asuni
  9970. * @since 4.0.018 (2008-08-06)
  9971. */
  9972. protected function _putannotsobjs() {
  9973. // reset object counter
  9974. for ($n = 1; $n <= $this->numpages; ++$n) {
  9975. if (isset($this->PageAnnots[$n])) {
  9976. // set page annotations
  9977. foreach ($this->PageAnnots[$n] as $key => $pl) {
  9978. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  9979. // create annotation object for grouping radiobuttons
  9980. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  9981. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  9982. $annots = '<<';
  9983. $annots .= ' /Type /Annot';
  9984. $annots .= ' /Subtype /Widget';
  9985. $annots .= ' /Rect [0 0 0 0]';
  9986. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  9987. // read only
  9988. $annots .= ' /F 68';
  9989. $annots .= ' /Ff 49153';
  9990. } else {
  9991. $annots .= ' /F 4'; // default print for PDF/A
  9992. $annots .= ' /Ff 49152';
  9993. }
  9994. $annots .= ' /T ' . $this->_datastring($pl['txt'], $radio_button_obj_id);
  9995. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  9996. $annots .= ' /TU ' . $this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  9997. }
  9998. $annots .= ' /FT /Btn';
  9999. $annots .= ' /Kids [';
  10000. $defval = '';
  10001. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  10002. if (isset($data['kid'])) {
  10003. $annots .= ' ' . $data['kid'] . ' 0 R';
  10004. if ($data['def'] !== 'Off') {
  10005. $defval = $data['def'];
  10006. }
  10007. }
  10008. }
  10009. $annots .= ' ]';
  10010. if (!empty($defval)) {
  10011. $annots .= ' /V /' . $defval;
  10012. }
  10013. $annots .= ' >>';
  10014. $this->_out($this->_getobj($radio_button_obj_id) . "\n" . $annots . "\n" . 'endobj');
  10015. $this->form_obj_id[] = $radio_button_obj_id;
  10016. // store object id to be used on Parent entry of Kids
  10017. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  10018. }
  10019. $formfield = false;
  10020. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  10021. $a = $pl['x'] * $this->k;
  10022. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  10023. $c = $pl['w'] * $this->k;
  10024. $d = $pl['h'] * $this->k;
  10025. $rect = sprintf('%F %F %F %F', $a, $b, $a + $c, $b + $d);
  10026. // create new annotation object
  10027. $annots = '<</Type /Annot';
  10028. $annots .= ' /Subtype /' . $pl['opt']['subtype'];
  10029. $annots .= ' /Rect [' . $rect . ']';
  10030. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  10031. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  10032. $annots .= ' /FT /' . $pl['opt']['ft'];
  10033. $formfield = true;
  10034. }
  10035. $annots .= ' /Contents ' . $this->_textstring($pl['txt'], $annot_obj_id);
  10036. $annots .= ' /P ' . $this->page_obj_id[$n] . ' 0 R';
  10037. $annots .= ' /NM ' . $this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  10038. $annots .= ' /M ' . $this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  10039. if (isset($pl['opt']['f'])) {
  10040. $fval = 0;
  10041. if (is_array($pl['opt']['f'])) {
  10042. foreach ($pl['opt']['f'] as $f) {
  10043. switch (strtolower($f)) {
  10044. case 'invisible': {
  10045. $fval += 1 << 0;
  10046. break;
  10047. }
  10048. case 'hidden': {
  10049. $fval += 1 << 1;
  10050. break;
  10051. }
  10052. case 'print': {
  10053. $fval += 1 << 2;
  10054. break;
  10055. }
  10056. case 'nozoom': {
  10057. $fval += 1 << 3;
  10058. break;
  10059. }
  10060. case 'norotate': {
  10061. $fval += 1 << 4;
  10062. break;
  10063. }
  10064. case 'noview': {
  10065. $fval += 1 << 5;
  10066. break;
  10067. }
  10068. case 'readonly': {
  10069. $fval += 1 << 6;
  10070. break;
  10071. }
  10072. case 'locked': {
  10073. $fval += 1 << 8;
  10074. break;
  10075. }
  10076. case 'togglenoview': {
  10077. $fval += 1 << 9;
  10078. break;
  10079. }
  10080. case 'lockedcontents': {
  10081. $fval += 1 << 10;
  10082. break;
  10083. }
  10084. default: {
  10085. break;
  10086. }
  10087. }
  10088. }
  10089. } else {
  10090. $fval = intval($pl['opt']['f']);
  10091. }
  10092. } else {
  10093. $fval = 4;
  10094. }
  10095. if ($this->pdfa_mode) {
  10096. // force print flag for PDF/A mode
  10097. $fval |= 4;
  10098. }
  10099. $annots .= ' /F ' . intval($fval);
  10100. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  10101. $annots .= ' /AS /' . $pl['opt']['as'];
  10102. }
  10103. if (isset($pl['opt']['ap'])) {
  10104. // appearance stream
  10105. $annots .= ' /AP <<';
  10106. if (is_array($pl['opt']['ap'])) {
  10107. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  10108. // $apmode can be: n = normal; r = rollover; d = down;
  10109. $annots .= ' /' . strtoupper($apmode);
  10110. if (is_array($apdef)) {
  10111. $annots .= ' <<';
  10112. foreach ($apdef as $apstate => $stream) {
  10113. // reference to XObject that define the appearance for this mode-state
  10114. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  10115. $annots .= ' /' . $apstate . ' ' . $apsobjid . ' 0 R';
  10116. }
  10117. $annots .= ' >>';
  10118. } else {
  10119. // reference to XObject that define the appearance for this mode
  10120. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  10121. $annots .= ' ' . $apsobjid . ' 0 R';
  10122. }
  10123. }
  10124. } else {
  10125. $annots .= $pl['opt']['ap'];
  10126. }
  10127. $annots .= ' >>';
  10128. }
  10129. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  10130. $annots .= ' /BS <<';
  10131. $annots .= ' /Type /Border';
  10132. if (isset($pl['opt']['bs']['w'])) {
  10133. $annots .= ' /W ' . intval($pl['opt']['bs']['w']);
  10134. }
  10135. $bstyles = array('S', 'D', 'B', 'I', 'U');
  10136. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  10137. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  10138. }
  10139. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  10140. $annots .= ' /D [';
  10141. foreach ($pl['opt']['bs']['d'] as $cord) {
  10142. $annots .= ' ' . intval($cord);
  10143. }
  10144. $annots .= ']';
  10145. }
  10146. $annots .= ' >>';
  10147. } else {
  10148. $annots .= ' /Border [';
  10149. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  10150. $annots .= intval($pl['opt']['border'][0]) . ' ';
  10151. $annots .= intval($pl['opt']['border'][1]) . ' ';
  10152. $annots .= intval($pl['opt']['border'][2]);
  10153. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  10154. $annots .= ' [';
  10155. foreach ($pl['opt']['border'][3] as $dash) {
  10156. $annots .= intval($dash) . ' ';
  10157. }
  10158. $annots .= ']';
  10159. }
  10160. } else {
  10161. $annots .= '0 0 0';
  10162. }
  10163. $annots .= ']';
  10164. }
  10165. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  10166. $annots .= ' /BE <<';
  10167. $bstyles = array('S', 'C');
  10168. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  10169. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  10170. } else {
  10171. $annots .= ' /S /S';
  10172. }
  10173. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  10174. $annots .= ' /I ' . sprintf(' %F', $pl['opt']['be']['i']);
  10175. }
  10176. $annots .= '>>';
  10177. }
  10178. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  10179. $annots .= ' /C ' . $this->getColorStringFromArray($pl['opt']['c']);
  10180. }
  10181. //$annots .= ' /StructParent ';
  10182. //$annots .= ' /OC ';
  10183. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  10184. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  10185. // this is a markup type
  10186. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  10187. $annots .= ' /T ' . $this->_textstring($pl['opt']['t'], $annot_obj_id);
  10188. }
  10189. //$annots .= ' /Popup ';
  10190. if (isset($pl['opt']['ca'])) {
  10191. $annots .= ' /CA ' . sprintf('%F', floatval($pl['opt']['ca']));
  10192. }
  10193. if (isset($pl['opt']['rc'])) {
  10194. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc'], $annot_obj_id);
  10195. }
  10196. $annots .= ' /CreationDate ' . $this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  10197. //$annots .= ' /IRT ';
  10198. if (isset($pl['opt']['subj'])) {
  10199. $annots .= ' /Subj ' . $this->_textstring($pl['opt']['subj'], $annot_obj_id);
  10200. }
  10201. //$annots .= ' /RT ';
  10202. //$annots .= ' /IT ';
  10203. //$annots .= ' /ExData ';
  10204. }
  10205. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  10206. // Annotation types
  10207. switch (strtolower($pl['opt']['subtype'])) {
  10208. case 'text': {
  10209. if (isset($pl['opt']['open'])) {
  10210. $annots .= ' /Open ' . (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  10211. }
  10212. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  10213. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  10214. $annots .= ' /Name /' . $pl['opt']['name'];
  10215. } else {
  10216. $annots .= ' /Name /Note';
  10217. }
  10218. $statemodels = array('Marked', 'Review');
  10219. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  10220. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  10221. } else {
  10222. $pl['opt']['statemodel'] = 'Marked';
  10223. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  10224. }
  10225. if ($pl['opt']['statemodel'] == 'Marked') {
  10226. $states = array('Accepted', 'Unmarked');
  10227. } else {
  10228. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  10229. }
  10230. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  10231. $annots .= ' /State /' . $pl['opt']['state'];
  10232. } else {
  10233. if ($pl['opt']['statemodel'] == 'Marked') {
  10234. $annots .= ' /State /Unmarked';
  10235. } else {
  10236. $annots .= ' /State /None';
  10237. }
  10238. }
  10239. break;
  10240. }
  10241. case 'link': {
  10242. if (is_string($pl['txt'])) {
  10243. if ($pl['txt'][0] == '#') {
  10244. // internal destination
  10245. $annots .= ' /Dest /' . $this->encodeNameObject(substr($pl['txt'], 1));
  10246. } else {
  10247. // external URI link
  10248. $annots .= ' /A <</S /URI /URI ' . $this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id) . '>>';
  10249. }
  10250. } else {
  10251. // internal link
  10252. if (isset($this->links[$pl['txt']])) {
  10253. $l = $this->links[$pl['txt']];
  10254. if (isset($this->page_obj_id[($l[0])])) {
  10255. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  10256. }
  10257. }
  10258. }
  10259. $hmodes = array('N', 'I', 'O', 'P');
  10260. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  10261. $annots .= ' /H /' . $pl['opt']['h'];
  10262. } else {
  10263. $annots .= ' /H /I';
  10264. }
  10265. //$annots .= ' /PA ';
  10266. //$annots .= ' /Quadpoints ';
  10267. break;
  10268. }
  10269. case 'freetext': {
  10270. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  10271. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  10272. }
  10273. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  10274. $annots .= ' /Q ' . intval($pl['opt']['q']);
  10275. }
  10276. if (isset($pl['opt']['rc'])) {
  10277. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc'], $annot_obj_id);
  10278. }
  10279. if (isset($pl['opt']['ds'])) {
  10280. $annots .= ' /DS ' . $this->_textstring($pl['opt']['ds'], $annot_obj_id);
  10281. }
  10282. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  10283. $annots .= ' /CL [';
  10284. foreach ($pl['opt']['cl'] as $cl) {
  10285. $annots .= sprintf('%F ', $cl * $this->k);
  10286. }
  10287. $annots .= ']';
  10288. }
  10289. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  10290. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  10291. $annots .= ' /IT /' . $pl['opt']['it'];
  10292. }
  10293. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  10294. $l = $pl['opt']['rd'][0] * $this->k;
  10295. $r = $pl['opt']['rd'][1] * $this->k;
  10296. $t = $pl['opt']['rd'][2] * $this->k;
  10297. $b = $pl['opt']['rd'][3] * $this->k;
  10298. $annots .= ' /RD [' . sprintf('%F %F %F %F', $l, $r, $t, $b) . ']';
  10299. }
  10300. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  10301. $annots .= ' /LE /' . $pl['opt']['le'];
  10302. }
  10303. break;
  10304. }
  10305. case 'line': {
  10306. break;
  10307. }
  10308. case 'square': {
  10309. break;
  10310. }
  10311. case 'circle': {
  10312. break;
  10313. }
  10314. case 'polygon': {
  10315. break;
  10316. }
  10317. case 'polyline': {
  10318. break;
  10319. }
  10320. case 'highlight': {
  10321. break;
  10322. }
  10323. case 'underline': {
  10324. break;
  10325. }
  10326. case 'squiggly': {
  10327. break;
  10328. }
  10329. case 'strikeout': {
  10330. break;
  10331. }
  10332. case 'stamp': {
  10333. break;
  10334. }
  10335. case 'caret': {
  10336. break;
  10337. }
  10338. case 'ink': {
  10339. break;
  10340. }
  10341. case 'popup': {
  10342. break;
  10343. }
  10344. case 'fileattachment': {
  10345. if ($this->pdfa_mode) {
  10346. // embedded files are not allowed in PDF/A mode
  10347. break;
  10348. }
  10349. if (!isset($pl['opt']['fs'])) {
  10350. break;
  10351. }
  10352. $filename = basename($pl['opt']['fs']);
  10353. if (isset($this->embeddedfiles[$filename]['n'])) {
  10354. $annots .= ' /FS <</Type /Filespec /F ' . $this->_datastring($filename, $annot_obj_id) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  10355. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  10356. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  10357. $annots .= ' /Name /' . $pl['opt']['name'];
  10358. } else {
  10359. $annots .= ' /Name /PushPin';
  10360. }
  10361. }
  10362. break;
  10363. }
  10364. case 'sound': {
  10365. if (!isset($pl['opt']['fs'])) {
  10366. break;
  10367. }
  10368. $filename = basename($pl['opt']['fs']);
  10369. if (isset($this->embeddedfiles[$filename]['n'])) {
  10370. // ... TO BE COMPLETED ...
  10371. // /R /C /B /E /CO /CP
  10372. $annots .= ' /Sound <</Type /Filespec /F ' . $this->_datastring($filename, $annot_obj_id) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  10373. $iconsapp = array('Speaker', 'Mic');
  10374. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  10375. $annots .= ' /Name /' . $pl['opt']['name'];
  10376. } else {
  10377. $annots .= ' /Name /Speaker';
  10378. }
  10379. }
  10380. break;
  10381. }
  10382. case 'movie': {
  10383. break;
  10384. }
  10385. case 'widget': {
  10386. $hmode = array('N', 'I', 'O', 'P', 'T');
  10387. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  10388. $annots .= ' /H /' . $pl['opt']['h'];
  10389. }
  10390. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  10391. $annots .= ' /MK <<';
  10392. if (isset($pl['opt']['mk']['r'])) {
  10393. $annots .= ' /R ' . $pl['opt']['mk']['r'];
  10394. }
  10395. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  10396. $annots .= ' /BC ' . $this->getColorStringFromArray($pl['opt']['mk']['bc']);
  10397. }
  10398. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  10399. $annots .= ' /BG ' . $this->getColorStringFromArray($pl['opt']['mk']['bg']);
  10400. }
  10401. if (isset($pl['opt']['mk']['ca'])) {
  10402. $annots .= ' /CA ' . $pl['opt']['mk']['ca'];
  10403. }
  10404. if (isset($pl['opt']['mk']['rc'])) {
  10405. $annots .= ' /RC ' . $pl['opt']['mk']['rc'];
  10406. }
  10407. if (isset($pl['opt']['mk']['ac'])) {
  10408. $annots .= ' /AC ' . $pl['opt']['mk']['ac'];
  10409. }
  10410. if (isset($pl['opt']['mk']['i'])) {
  10411. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  10412. if ($info !== false) {
  10413. $annots .= ' /I ' . $info['n'] . ' 0 R';
  10414. }
  10415. }
  10416. if (isset($pl['opt']['mk']['ri'])) {
  10417. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  10418. if ($info !== false) {
  10419. $annots .= ' /RI ' . $info['n'] . ' 0 R';
  10420. }
  10421. }
  10422. if (isset($pl['opt']['mk']['ix'])) {
  10423. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  10424. if ($info !== false) {
  10425. $annots .= ' /IX ' . $info['n'] . ' 0 R';
  10426. }
  10427. }
  10428. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  10429. $annots .= ' /IF <<';
  10430. $if_sw = array('A', 'B', 'S', 'N');
  10431. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  10432. $annots .= ' /SW /' . $pl['opt']['mk']['if']['sw'];
  10433. }
  10434. $if_s = array('A', 'P');
  10435. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  10436. $annots .= ' /S /' . $pl['opt']['mk']['if']['s'];
  10437. }
  10438. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  10439. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  10440. }
  10441. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  10442. $annots .= ' /FB true';
  10443. }
  10444. $annots .= '>>';
  10445. }
  10446. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  10447. $annots .= ' /TP ' . intval($pl['opt']['mk']['tp']);
  10448. }
  10449. $annots .= '>>';
  10450. } // end MK
  10451. // --- Entries for field dictionaries ---
  10452. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  10453. // set parent
  10454. $annots .= ' /Parent ' . $this->radiobutton_groups[$n][$pl['txt']] . ' 0 R';
  10455. }
  10456. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  10457. $annots .= ' /T ' . $this->_datastring($pl['opt']['t'], $annot_obj_id);
  10458. }
  10459. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  10460. $annots .= ' /TU ' . $this->_datastring($pl['opt']['tu'], $annot_obj_id);
  10461. }
  10462. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  10463. $annots .= ' /TM ' . $this->_datastring($pl['opt']['tm'], $annot_obj_id);
  10464. }
  10465. if (isset($pl['opt']['ff'])) {
  10466. if (is_array($pl['opt']['ff'])) {
  10467. // array of bit settings
  10468. $flag = 0;
  10469. foreach ($pl['opt']['ff'] as $val) {
  10470. $flag += 1 << ($val - 1);
  10471. }
  10472. } else {
  10473. $flag = intval($pl['opt']['ff']);
  10474. }
  10475. $annots .= ' /Ff ' . $flag;
  10476. }
  10477. if (isset($pl['opt']['maxlen'])) {
  10478. $annots .= ' /MaxLen ' . intval($pl['opt']['maxlen']);
  10479. }
  10480. if (isset($pl['opt']['v'])) {
  10481. $annots .= ' /V';
  10482. if (is_array($pl['opt']['v'])) {
  10483. foreach ($pl['opt']['v'] AS $optval) {
  10484. if (is_float($optval)) {
  10485. $optval = sprintf('%F', $optval);
  10486. }
  10487. $annots .= ' ' . $optval;
  10488. }
  10489. } else {
  10490. $annots .= ' ' . $this->_textstring($pl['opt']['v'], $annot_obj_id);
  10491. }
  10492. }
  10493. if (isset($pl['opt']['dv'])) {
  10494. $annots .= ' /DV';
  10495. if (is_array($pl['opt']['dv'])) {
  10496. foreach ($pl['opt']['dv'] AS $optval) {
  10497. if (is_float($optval)) {
  10498. $optval = sprintf('%F', $optval);
  10499. }
  10500. $annots .= ' ' . $optval;
  10501. }
  10502. } else {
  10503. $annots .= ' ' . $this->_textstring($pl['opt']['dv'], $annot_obj_id);
  10504. }
  10505. }
  10506. if (isset($pl['opt']['rv'])) {
  10507. $annots .= ' /RV';
  10508. if (is_array($pl['opt']['rv'])) {
  10509. foreach ($pl['opt']['rv'] AS $optval) {
  10510. if (is_float($optval)) {
  10511. $optval = sprintf('%F', $optval);
  10512. }
  10513. $annots .= ' ' . $optval;
  10514. }
  10515. } else {
  10516. $annots .= ' ' . $this->_textstring($pl['opt']['rv'], $annot_obj_id);
  10517. }
  10518. }
  10519. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  10520. $annots .= ' /A << ' . $pl['opt']['a'] . ' >>';
  10521. }
  10522. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  10523. $annots .= ' /AA << ' . $pl['opt']['aa'] . ' >>';
  10524. }
  10525. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  10526. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  10527. }
  10528. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  10529. $annots .= ' /Q ' . intval($pl['opt']['q']);
  10530. }
  10531. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  10532. $annots .= ' /Opt [';
  10533. foreach ($pl['opt']['opt'] AS $copt) {
  10534. if (is_array($copt)) {
  10535. $annots .= ' [' . $this->_textstring($copt[0], $annot_obj_id) . ' ' . $this->_textstring($copt[1], $annot_obj_id) . ']';
  10536. } else {
  10537. $annots .= ' ' . $this->_textstring($copt, $annot_obj_id);
  10538. }
  10539. }
  10540. $annots .= ']';
  10541. }
  10542. if (isset($pl['opt']['ti'])) {
  10543. $annots .= ' /TI ' . intval($pl['opt']['ti']);
  10544. }
  10545. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  10546. $annots .= ' /I [';
  10547. foreach ($pl['opt']['i'] AS $copt) {
  10548. $annots .= intval($copt) . ' ';
  10549. }
  10550. $annots .= ']';
  10551. }
  10552. break;
  10553. }
  10554. case 'screen': {
  10555. break;
  10556. }
  10557. case 'printermark': {
  10558. break;
  10559. }
  10560. case 'trapnet': {
  10561. break;
  10562. }
  10563. case 'watermark': {
  10564. break;
  10565. }
  10566. case '3d': {
  10567. break;
  10568. }
  10569. default: {
  10570. break;
  10571. }
  10572. }
  10573. $annots .= '>>';
  10574. // create new annotation object
  10575. $this->_out($this->_getobj($annot_obj_id) . "\n" . $annots . "\n" . 'endobj');
  10576. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  10577. // store reference of form object
  10578. $this->form_obj_id[] = $annot_obj_id;
  10579. }
  10580. }
  10581. }
  10582. } // end for each page
  10583. }
  10584. /**
  10585. * Put appearance streams XObject used to define annotation's appearance states.
  10586. * @param $w (int) annotation width
  10587. * @param $h (int) annotation height
  10588. * @param $stream (string) appearance stream
  10589. * @return int object ID
  10590. * @protected
  10591. * @since 4.8.001 (2009-09-09)
  10592. */
  10593. protected function _putAPXObject($w = 0, $h = 0, $stream = '') {
  10594. $stream = trim($stream);
  10595. $out = $this->_getobj() . "\n";
  10596. $this->xobjects['AX' . $this->n] = array('n' => $this->n);
  10597. $out .= '<<';
  10598. $out .= ' /Type /XObject';
  10599. $out .= ' /Subtype /Form';
  10600. $out .= ' /FormType 1';
  10601. if ($this->compress) {
  10602. $stream = gzcompress($stream);
  10603. $out .= ' /Filter /FlateDecode';
  10604. }
  10605. $rect = sprintf('%F %F', $w, $h);
  10606. $out .= ' /BBox [0 0 ' . $rect . ']';
  10607. $out .= ' /Matrix [1 0 0 1 0 0]';
  10608. $out .= ' /Resources 2 0 R';
  10609. $stream = $this->_getrawstream($stream);
  10610. $out .= ' /Length ' . strlen($stream);
  10611. $out .= ' >>';
  10612. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  10613. $out .= "\n" . 'endobj';
  10614. $this->_out($out);
  10615. return $this->n;
  10616. }
  10617. /**
  10618. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  10619. * @param $str (string) string from where to extract value
  10620. * @param $offset (int) point from where to read the data
  10621. * @return int 32 bit value
  10622. * @author Nicola Asuni
  10623. * @protected
  10624. * @since 5.2.000 (2010-06-02)
  10625. */
  10626. protected function _getULONG($str, $offset) {
  10627. $v = unpack('Ni', substr($str, $offset, 4));
  10628. return $v['i'];
  10629. }
  10630. /**
  10631. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  10632. * @param $str (string) string from where to extract value
  10633. * @param $offset (int) point from where to read the data
  10634. * @return int 16 bit value
  10635. * @author Nicola Asuni
  10636. * @protected
  10637. * @since 5.2.000 (2010-06-02)
  10638. */
  10639. protected function _getUSHORT($str, $offset) {
  10640. $v = unpack('ni', substr($str, $offset, 2));
  10641. return $v['i'];
  10642. }
  10643. /**
  10644. * Get SHORT from string (Big Endian 16-bit signed integer).
  10645. * @param $str (string) String from where to extract value.
  10646. * @param $offset (int) Point from where to read the data.
  10647. * @return int 16 bit value
  10648. * @author Nicola Asuni
  10649. * @protected
  10650. * @since 5.2.000 (2010-06-02)
  10651. */
  10652. protected function _getSHORT($str, $offset) {
  10653. $v = unpack('si', substr($str, $offset, 2));
  10654. return $v['i'];
  10655. }
  10656. /**
  10657. * Get FWORD from string (Big Endian 16-bit signed integer).
  10658. * @param $str (string) String from where to extract value.
  10659. * @param $offset (int) Point from where to read the data.
  10660. * @return int 16 bit value
  10661. * @author Nicola Asuni
  10662. * @protected
  10663. * @since 5.9.123 (2011-09-30)
  10664. */
  10665. protected function _getFWORD($str, $offset) {
  10666. $v = $this->_getUSHORT($str, $offset);
  10667. if ($v > 0x7fff) {
  10668. $v -= 0x10000;
  10669. }
  10670. return $v;
  10671. }
  10672. /**
  10673. * Get UFWORD from string (Big Endian 16-bit unsigned integer).
  10674. * @param $str (string) string from where to extract value
  10675. * @param $offset (int) point from where to read the data
  10676. * @return int 16 bit value
  10677. * @author Nicola Asuni
  10678. * @protected
  10679. * @since 5.9.123 (2011-09-30)
  10680. */
  10681. protected function _getUFWORD($str, $offset) {
  10682. $v = $this->_getUSHORT($str, $offset);
  10683. return $v;
  10684. }
  10685. /**
  10686. * Get FIXED from string (32-bit signed fixed-point number (16.16).
  10687. * @param $str (string) string from where to extract value
  10688. * @param $offset (int) point from where to read the data
  10689. * @return int 16 bit value
  10690. * @author Nicola Asuni
  10691. * @protected
  10692. * @since 5.9.123 (2011-09-30)
  10693. */
  10694. protected function _getFIXED($str, $offset) {
  10695. // mantissa
  10696. $m = $this->_getFWORD($str, $offset);
  10697. // fraction
  10698. $f = $this->_getUSHORT($str, ($offset + 2));
  10699. $v = floatval('' . $m . '.' . $f . '');
  10700. return $v;
  10701. }
  10702. /**
  10703. * Get BYTE from string (8-bit unsigned integer).
  10704. * @param $str (string) String from where to extract value.
  10705. * @param $offset (int) Point from where to read the data.
  10706. * @return int 8 bit value
  10707. * @author Nicola Asuni
  10708. * @protected
  10709. * @since 5.2.000 (2010-06-02)
  10710. */
  10711. protected function _getBYTE($str, $offset) {
  10712. $v = unpack('Ci', substr($str, $offset, 1));
  10713. return $v['i'];
  10714. }
  10715. /**
  10716. * Update the CIDToGIDMap string with a new value.
  10717. * @param $map (string) CIDToGIDMap.
  10718. * @param $cid (int) CID value.
  10719. * @param $gid (int) GID value.
  10720. * @return (string) CIDToGIDMap.
  10721. * @author Nicola Asuni
  10722. * @protected
  10723. * @since 5.9.123 (2011-09-29)
  10724. */
  10725. protected function updateCIDtoGIDmap($map, $cid, $gid) {
  10726. if (($cid >= 0) AND ($cid <= 0xFFFF) AND ($gid >= 0)) {
  10727. if ($gid > 0xFFFF) {
  10728. $gid -= 0x10000;
  10729. }
  10730. $map[($cid * 2)] = chr($gid >> 8);
  10731. $map[(($cid * 2) + 1)] = chr($gid & 0xFF);
  10732. }
  10733. return $map;
  10734. }
  10735. /**
  10736. * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).
  10737. * @param $fontfile (string) Font file (full path).
  10738. * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
  10739. * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
  10740. * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
  10741. * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
  10742. * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
  10743. * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
  10744. * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
  10745. * @return (string) TCPDF font name.
  10746. * @author Nicola Asuni
  10747. * @public
  10748. * @since 5.9.123 (2010-09-30)
  10749. */
  10750. public function addTTFfont($fontfile, $fonttype = '', $enc = '', $flags = 32, $outpath = '', $platid = 3, $encid = 1, $addcbbox = false) {
  10751. if (!file_exists($fontfile)) {
  10752. $this->Error('Could not find file: ' . $fontfile . '');
  10753. }
  10754. // font metrics
  10755. $fmetric = array();
  10756. // build new font name for TCPDF compatibility
  10757. $font_path_parts = pathinfo($fontfile);
  10758. if (!isset($font_path_parts['filename'])) {
  10759. $font_path_parts['filename'] = substr($font_path_parts['basename'], 0, -(strlen($font_path_parts['extension']) + 1));
  10760. }
  10761. $font_name = strtolower($font_path_parts['filename']);
  10762. $font_name = preg_replace('/[^a-z0-9_]/', '', $font_name);
  10763. $search = array('bold', 'oblique', 'italic', 'regular');
  10764. $replace = array('b', 'i', 'i', '');
  10765. $font_name = str_replace($search, $replace, $font_name);
  10766. if (empty($font_name)) {
  10767. // set generic name
  10768. $font_name = 'tcpdffont';
  10769. }
  10770. // set output path
  10771. if (empty($outpath)) {
  10772. $outpath = $this->_getfontpath();
  10773. }
  10774. // check if this font already exist
  10775. if (file_exists($outpath . $font_name . '.php')) {
  10776. // this font already exist (delete it from fonts folder to rebuild it)
  10777. return $font_name;
  10778. }
  10779. $fmetric['file'] = $font_name . '.z';
  10780. $fmetric['ctg'] = $font_name . '.ctg.z';
  10781. // get font data
  10782. $font = file_get_contents($fontfile);
  10783. $fmetric['originalsize'] = strlen($font);
  10784. // autodetect font type
  10785. if (empty($fonttype)) {
  10786. if ($this->_getULONG($font, 0) == 0x10000) {
  10787. // True Type (Unicode or not)
  10788. $fonttype = 'TrueTypeUnicode';
  10789. } elseif (substr($font, 0, 4) == 'OTTO') {
  10790. // Open Type (Unicode or not)
  10791. $this->Error('Unsupported font format: OpenType with CFF data.');
  10792. } else {
  10793. // Type 1
  10794. $fonttype = 'Type1';
  10795. }
  10796. }
  10797. // set font type
  10798. switch ($fonttype) {
  10799. case 'CID0CT':
  10800. case 'CID0CS':
  10801. case 'CID0KR':
  10802. case 'CID0JP': {
  10803. $fmetric['type'] = 'cidfont0';
  10804. break;
  10805. }
  10806. case 'Type1': {
  10807. $fmetric['type'] = 'Type1';
  10808. if (empty($enc) AND (($flags & 4) == 0)) {
  10809. $enc = 'cp1252';
  10810. }
  10811. break;
  10812. }
  10813. case 'TrueType': {
  10814. $fmetric['type'] = 'TrueType';
  10815. break;
  10816. }
  10817. case 'TrueTypeUnicode':
  10818. default: {
  10819. $fmetric['type'] = 'TrueTypeUnicode';
  10820. break;
  10821. }
  10822. }
  10823. // set encoding maps (if any)
  10824. $fmetric['enc'] = preg_replace('/[^A-Za-z0-9_\-]/', '', $enc);
  10825. $fmetric['diff'] = '';
  10826. if (($fmetric['type'] == 'TrueType') OR ($fmetric['type'] == 'Type1')) {
  10827. if (!empty($enc) AND ($enc != 'cp1252') AND isset($this->encmaps->encmap[$enc])) {
  10828. // build differences from reference encoding
  10829. $enc_ref = $this->encmaps->encmap['cp1252'];
  10830. $enc_target = $this->encmaps->encmap[$enc];
  10831. $last = 0;
  10832. for ($i = 32; $i <= 255; ++$i) {
  10833. if ($enc_target != $enc_ref[$i]) {
  10834. if ($i != ($last + 1)) {
  10835. $fmetric['diff'] .= $i . ' ';
  10836. }
  10837. $last = $i;
  10838. $fmetric['diff'] .= '/' . $enc_target[$i] . ' ';
  10839. }
  10840. }
  10841. }
  10842. }
  10843. // parse the font by type
  10844. if ($fmetric['type'] == 'Type1') {
  10845. // ---------- TYPE 1 ----------
  10846. // read first segment
  10847. $a = unpack('Cmarker/Ctype/Vsize', substr($font, 0, 6));
  10848. if ($a['marker'] != 128) {
  10849. $this->Error('Font file is not a valid binary Type1');
  10850. }
  10851. $fmetric['size1'] = $a['size'];
  10852. $data = substr($font, 6, $fmetric['size1']);
  10853. // read second segment
  10854. $a = unpack('Cmarker/Ctype/Vsize', substr($font, (6 + $fmetric['size1']), 6));
  10855. if ($a['marker'] != 128) {
  10856. $this->Error('Font file is not a valid binary Type1');
  10857. }
  10858. $fmetric['size2'] = $a['size'];
  10859. $encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']);
  10860. $data .= $encrypted;
  10861. // store compressed font
  10862. $fp = fopen($outpath . $fmetric['file'], 'wb');
  10863. fwrite($fp, gzcompress($data));
  10864. fclose($fp);
  10865. // get font info
  10866. $fmetric['Flags'] = $flags;
  10867. preg_match('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
  10868. $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
  10869. preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
  10870. $fmetric['bbox'] = trim($matches[1]);
  10871. $bv = explode(' ', $fmetric['bbox']);
  10872. $fmetric['Ascent'] = intval($bv[3]);
  10873. $fmetric['Descent'] = intval($bv[1]);
  10874. preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches);
  10875. $fmetric['italicAngle'] = intval($matches[1]);
  10876. if ($fmetric['italicAngle'] != 0) {
  10877. $fmetric['Flags'] |= 64;
  10878. }
  10879. preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches);
  10880. $fmetric['underlinePosition'] = intval($matches[1]);
  10881. preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches);
  10882. $fmetric['underlineThickness'] = intval($matches[1]);
  10883. preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches);
  10884. if ($matches[1] == 'true') {
  10885. $fmetric['Flags'] |= 1;
  10886. }
  10887. // get internal map
  10888. $imap = array();
  10889. if (preg_match_all('#dup[\s]([0-9]+)[\s]*/([^\s]*)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) {
  10890. foreach ($fmap as $v) {
  10891. $imap[$v[2]] = $v[1];
  10892. }
  10893. }
  10894. // decrypt eexec encrypted part
  10895. $r = 55665; // eexec encryption constant
  10896. $c1 = 52845;
  10897. $c2 = 22719;
  10898. $elen = strlen($encrypted);
  10899. $eplain = '';
  10900. for ($i = 0; $i < $elen; ++$i) {
  10901. $chr = ord($encrypted[$i]);
  10902. $eplain .= chr($chr ^ ($r >> 8));
  10903. $r = ((($chr + $r) * $c1 + $c2) % 65536);
  10904. }
  10905. if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) {
  10906. if ($matches[1] == 'true') {
  10907. $fmetric['Flags'] |= 0x40000;
  10908. }
  10909. }
  10910. if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
  10911. $fmetric['StemV'] = intval($matches[1]);
  10912. } else {
  10913. $fmetric['StemV'] = 70;
  10914. }
  10915. if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
  10916. $fmetric['StemH'] = intval($matches[1]);
  10917. } else {
  10918. $fmetric['StemH'] = 30;
  10919. }
  10920. if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
  10921. $bv = explode(' ', $matches[1]);
  10922. if (count($bv) >= 6) {
  10923. $v1 = intval($bv[2]);
  10924. $v2 = intval($bv[4]);
  10925. if ($v1 <= $v2) {
  10926. $fmetric['XHeight'] = $v1;
  10927. $fmetric['CapHeight'] = $v2;
  10928. } else {
  10929. $fmetric['XHeight'] = $v2;
  10930. $fmetric['CapHeight'] = $v1;
  10931. }
  10932. } else {
  10933. $fmetric['XHeight'] = 450;
  10934. $fmetric['CapHeight'] = 700;
  10935. }
  10936. } else {
  10937. $fmetric['XHeight'] = 450;
  10938. $fmetric['CapHeight'] = 700;
  10939. }
  10940. // get the number of random bytes at the beginning of charstrings
  10941. if (preg_match('#/lenIV[\s]*([0-9]*)#', $eplain, $matches) > 0) {
  10942. $lenIV = intval($matches[1]);
  10943. } else {
  10944. $lenIV = 4;
  10945. }
  10946. $fmetric['Leading'] = 0;
  10947. // get charstring data
  10948. $eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1));
  10949. preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER);
  10950. if (!empty($enc) AND isset($this->encmaps->encmap[$enc])) {
  10951. $enc_map = $this->encmaps->encmap[$enc];
  10952. } else {
  10953. $enc_map = false;
  10954. }
  10955. $fmetric['cw'] = '';
  10956. $fmetric['MaxWidth'] = 0;
  10957. $cwidths = array();
  10958. foreach ($matches as $k => $v) {
  10959. $cid = 0;
  10960. if (isset($imap[$v[1]])) {
  10961. $cid = $imap[$v[1]];
  10962. } elseif ($enc_map !== false) {
  10963. $cid = array_search($v[1], $enc_map);
  10964. if ($cid === false) {
  10965. $cid = 0;
  10966. } elseif ($cid > 1000) {
  10967. $cid -= 1000;
  10968. }
  10969. }
  10970. // decrypt charstring encrypted part
  10971. $r = 4330; // charstring encryption constant
  10972. $c1 = 52845;
  10973. $c2 = 22719;
  10974. $cd = $v[2];
  10975. $clen = strlen($cd);
  10976. $ccom = array();
  10977. for ($i = 0; $i < $clen; ++$i) {
  10978. $chr = ord($cd[$i]);
  10979. $ccom[] = ($chr ^ ($r >> 8));
  10980. $r = ((($chr + $r) * $c1 + $c2) % 65536);
  10981. }
  10982. // decode numbers
  10983. $cdec = array();
  10984. $ck = 0;
  10985. $i = $lenIV;
  10986. while ($i < $clen) {
  10987. if ($ccom[$i] < 32) {
  10988. $cdec[$ck] = $ccom[$i];
  10989. if (($ck > 0) AND ($cdec[$ck] == 13)) {
  10990. // hsbw command: update width
  10991. $cwidths[$cid] = $cdec[($ck - 1)];
  10992. }
  10993. ++$i;
  10994. } elseif (($ccom[$i] >= 32) AND ($ccom[$i] <= 246)) {
  10995. $cdec[$ck] = ($ccom[$i] - 139);
  10996. ++$i;
  10997. } elseif (($ccom[$i] >= 247) AND ($ccom[$i] <= 250)) {
  10998. $cdec[$ck] = ((($ccom[$i] - 247) * 256) + $ccom[($i + 1)] + 108);
  10999. $i += 2;
  11000. } elseif (($ccom[$i] >= 251) AND ($ccom[$i] <= 254)) {
  11001. $cdec[$ck] = ((-($ccom[$i] - 251) * 256) - $ccom[($i + 1)] - 108);
  11002. $i += 2;
  11003. } elseif ($ccom[$i] == 255) {
  11004. $sval = chr($ccom[($i + 1)]) . chr($ccom[($i + 2)]) . chr($ccom[($i + 3)]) . chr($ccom[($i + 4)]);
  11005. $vsval = unpack('li', $sval);
  11006. $cdec[$ck] = $vsval['i'];
  11007. $i += 5;
  11008. }
  11009. ++$ck;
  11010. }
  11011. } // end for each matches
  11012. $fmetric['MissingWidth'] = $cwidths[0];
  11013. $fmetric['MaxWidth'] = $fmetric['MissingWidth'];
  11014. $fmetric['AvgWidth'] = 0;
  11015. // set chars widths
  11016. for ($cid = 0; $cid <= 255; ++$cid) {
  11017. if (isset($cwidths[$cid])) {
  11018. if ($cwidths[$cid] > $fmetric['MaxWidth']) {
  11019. $fmetric['MaxWidth'] = $cwidths[$cid];
  11020. }
  11021. $fmetric['AvgWidth'] += $cwidths[$cid];
  11022. $fmetric['cw'] .= ',' . $cid . '=>' . $cwidths[$cid];
  11023. } else {
  11024. $fmetric['cw'] .= ',' . $cid . '=>' . $fmetric['MissingWidth'];
  11025. }
  11026. }
  11027. $fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths));
  11028. } else {
  11029. // ---------- TRUE TYPE ----------
  11030. if ($fmetric['type'] != 'cidfont0') {
  11031. // store compressed font
  11032. $fp = fopen($outpath . $fmetric['file'], 'wb');
  11033. fwrite($fp, gzcompress($font));
  11034. fclose($fp);
  11035. }
  11036. $offset = 0; // offset position of the font data
  11037. if ($this->_getULONG($font, $offset) != 0x10000) {
  11038. // sfnt version must be 0x00010000 for TrueType version 1.0.
  11039. return $font;
  11040. }
  11041. $offset += 4;
  11042. // get number of tables
  11043. $numTables = $this->_getUSHORT($font, $offset);
  11044. $offset += 2;
  11045. // skip searchRange, entrySelector and rangeShift
  11046. $offset += 6;
  11047. // tables array
  11048. $table = array();
  11049. // ---------- get tables ----------
  11050. for ($i = 0; $i < $numTables; ++$i) {
  11051. // get table info
  11052. $tag = substr($font, $offset, 4);
  11053. $offset += 4;
  11054. $table[$tag] = array();
  11055. $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
  11056. $offset += 4;
  11057. $table[$tag]['offset'] = $this->_getULONG($font, $offset);
  11058. $offset += 4;
  11059. $table[$tag]['length'] = $this->_getULONG($font, $offset);
  11060. $offset += 4;
  11061. }
  11062. // check magicNumber
  11063. $offset = $table['head']['offset'] + 12;
  11064. if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
  11065. // magicNumber must be 0x5F0F3CF5
  11066. return $font;
  11067. }
  11068. $offset += 4;
  11069. $offset += 2; // skip flags
  11070. // get FUnits
  11071. $fmetric['unitsPerEm'] = $this->_getUSHORT($font, $offset);
  11072. $offset += 2;
  11073. // units ratio constant
  11074. $urk = (1000 / $fmetric['unitsPerEm']);
  11075. $offset += 16; // skip created, modified
  11076. $xMin = round($this->_getFWORD($font, $offset) * $urk);
  11077. $offset += 2;
  11078. $yMin = round($this->_getFWORD($font, $offset) * $urk);
  11079. $offset += 2;
  11080. $xMax = round($this->_getFWORD($font, $offset) * $urk);
  11081. $offset += 2;
  11082. $yMax = round($this->_getFWORD($font, $offset) * $urk);
  11083. $offset += 2;
  11084. $fmetric['bbox'] = '' . $xMin . ' ' . $yMin . ' ' . $xMax . ' ' . $yMax . '';
  11085. $macStyle = $this->_getUSHORT($font, $offset);
  11086. $offset += 2;
  11087. // PDF font flags
  11088. $fmetric['Flags'] = $flags;
  11089. if (($macStyle & 2) == 2) {
  11090. // italic flag
  11091. $fmetric['Flags'] |= 64;
  11092. }
  11093. // get offset mode (indexToLocFormat : 0 = short, 1 = long)
  11094. $offset = $table['head']['offset'] + 50;
  11095. $short_offset = ($this->_getSHORT($font, $offset) == 0);
  11096. $offset += 2;
  11097. // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
  11098. $indexToLoc = array();
  11099. $offset = $table['loca']['offset'];
  11100. if ($short_offset) {
  11101. // short version
  11102. $tot_num_glyphs = ($table['loca']['length'] / 2); // numGlyphs + 1
  11103. for ($i = 0; $i < $tot_num_glyphs; ++$i) {
  11104. $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
  11105. $offset += 2;
  11106. }
  11107. } else {
  11108. // long version
  11109. $tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1
  11110. for ($i = 0; $i < $tot_num_glyphs; ++$i) {
  11111. $indexToLoc[$i] = $this->_getULONG($font, $offset);
  11112. $offset += 4;
  11113. }
  11114. }
  11115. // get glyphs indexes of chars from cmap table
  11116. $offset = $table['cmap']['offset'] + 2;
  11117. $numEncodingTables = $this->_getUSHORT($font, $offset);
  11118. $offset += 2;
  11119. $encodingTables = array();
  11120. for ($i = 0; $i < $numEncodingTables; ++$i) {
  11121. $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
  11122. $offset += 2;
  11123. $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
  11124. $offset += 2;
  11125. $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
  11126. $offset += 4;
  11127. }
  11128. // ---------- get os/2 metrics ----------
  11129. $offset = $table['OS/2']['offset'];
  11130. $offset += 2; // skip version
  11131. // xAvgCharWidth
  11132. $fmetric['AvgWidth'] = round($this->_getFWORD($font, $offset) * $urk);
  11133. $offset += 2;
  11134. // usWeightClass
  11135. $usWeightClass = round($this->_getUFWORD($font, $offset) * $urk);
  11136. // estimate StemV and StemH (400 = usWeightClass for Normal - Regular font)
  11137. $fmetric['StemV'] = round((70 * $usWeightClass) / 400);
  11138. $fmetric['StemH'] = round((30 * $usWeightClass) / 400);
  11139. $offset += 2;
  11140. $offset += 2; // usWidthClass
  11141. $fsType = $this->_getSHORT($font, $offset);
  11142. $offset += 2;
  11143. if ($fsType == 2) {
  11144. $this->Error('This Font cannot be modified, embedded or exchanged in any manner without first obtaining permission of the legal owner.');
  11145. }
  11146. // ---------- get font name ----------
  11147. $fmetric['name'] = '';
  11148. $offset = $table['name']['offset'];
  11149. $offset += 2; // skip Format selector (=0).
  11150. // Number of NameRecords that follow n.
  11151. $numNameRecords = $this->_getUSHORT($font, $offset);
  11152. $offset += 2;
  11153. // Offset to start of string storage (from start of table).
  11154. $stringStorageOffset = $this->_getUSHORT($font, $offset);
  11155. $offset += 2;
  11156. for ($i = 0; $i < $numNameRecords; ++$i) {
  11157. $offset += 6; // skip Platform ID, Platform-specific encoding ID, Language ID.
  11158. // Name ID.
  11159. $nameID = $this->_getUSHORT($font, $offset);
  11160. $offset += 2;
  11161. if ($nameID == 6) {
  11162. // String length (in bytes).
  11163. $stringLength = $this->_getUSHORT($font, $offset);
  11164. $offset += 2;
  11165. // String offset from start of storage area (in bytes).
  11166. $stringOffset = $this->_getUSHORT($font, $offset);
  11167. $offset += 2;
  11168. $offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset);
  11169. $fmetric['name'] = substr($font, $offset, $stringLength);
  11170. $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']);
  11171. break;
  11172. } else {
  11173. $offset += 4; // skip String length, String offset
  11174. }
  11175. }
  11176. if (empty($fmetric['name'])) {
  11177. $fmetric['name'] = $font_name;
  11178. }
  11179. // ---------- get post data ----------
  11180. $offset = $table['post']['offset'];
  11181. $offset += 4; // skip Format Type
  11182. $fmetric['italicAngle'] = $this->_getFIXED($font, $offset);
  11183. $offset += 4;
  11184. $fmetric['underlinePosition'] = round($this->_getFWORD($font, $offset) * $urk);
  11185. $offset += 2;
  11186. $fmetric['underlineThickness'] = round($this->_getFWORD($font, $offset) * $urk);
  11187. $offset += 2;
  11188. $isFixedPitch = ($this->_getULONG($font, $offset) == 0) ? false : true;
  11189. $offset += 2;
  11190. if ($isFixedPitch) {
  11191. $fmetric['Flags'] |= 1;
  11192. }
  11193. // ---------- get hhea data ----------
  11194. $offset = $table['hhea']['offset'];
  11195. $offset += 4; // skip Table version number
  11196. // Ascender
  11197. $fmetric['Ascent'] = round($this->_getFWORD($font, $offset) * $urk);
  11198. $offset += 2;
  11199. // Descender
  11200. $fmetric['Descent'] = round($this->_getFWORD($font, $offset) * $urk);
  11201. $offset += 2;
  11202. // LineGap
  11203. $fmetric['Leading'] = round($this->_getFWORD($font, $offset) * $urk);
  11204. $offset += 2;
  11205. // advanceWidthMax
  11206. $fmetric['MaxWidth'] = round($this->_getUFWORD($font, $offset) * $urk);
  11207. $offset += 2;
  11208. $offset += 22; // skip some values
  11209. // get the number of hMetric entries in hmtx table
  11210. $numberOfHMetrics = $this->_getUSHORT($font, $offset);
  11211. // ---------- get maxp data ----------
  11212. $offset = $table['maxp']['offset'];
  11213. $offset += 4; // skip Table version number
  11214. // get the the number of glyphs in the font.
  11215. $numGlyphs = $this->_getUSHORT($font, $offset);
  11216. // ---------- get CIDToGIDMap ----------
  11217. $ctg = array();
  11218. foreach ($encodingTables as $enctable) {
  11219. // get only specified Platform ID and Encoding ID
  11220. if (($enctable['platformID'] == $platid) AND ($enctable['encodingID'] == $encid)) {
  11221. $offset = $table['cmap']['offset'] + $enctable['offset'];
  11222. $format = $this->_getUSHORT($font, $offset);
  11223. $offset += 2;
  11224. switch ($format) {
  11225. case 0: { // Format 0: Byte encoding table
  11226. $offset += 4; // skip length and version/language
  11227. for ($c = 0; $c < 256; ++$c) {
  11228. $g = $this->_getBYTE($font, $offset);
  11229. $ctg[$c] = $g;
  11230. ++$offset;
  11231. }
  11232. break;
  11233. }
  11234. case 2: { // Format 2: High-byte mapping through table
  11235. $offset += 4; // skip length and version/language
  11236. $numSubHeaders = 0;
  11237. for ($i = 0; $i < 256; ++$i) {
  11238. // Array that maps high bytes to subHeaders: value is subHeader index * 8.
  11239. $subHeaderKeys[$i] = ($this->_getUSHORT($font, $offset) / 8);
  11240. $offset += 2;
  11241. if ($numSubHeaders < $subHeaderKeys[$i]) {
  11242. $numSubHeaders = $subHeaderKeys[$i];
  11243. }
  11244. }
  11245. // the number of subHeaders is equal to the max of subHeaderKeys + 1
  11246. ++$numSubHeaders;
  11247. // read subHeader structures
  11248. $subHeaders = array();
  11249. $numGlyphIndexArray = 0;
  11250. for ($k = 0; $k < $numSubHeaders; ++$k) {
  11251. $subHeaders[$k]['firstCode'] = $this->_getUSHORT($font, $offset);
  11252. $offset += 2;
  11253. $subHeaders[$k]['entryCount'] = $this->_getUSHORT($font, $offset);
  11254. $offset += 2;
  11255. $subHeaders[$k]['idDelta'] = $this->_getUSHORT($font, $offset);
  11256. $offset += 2;
  11257. $subHeaders[$k]['idRangeOffset'] = $this->_getUSHORT($font, $offset);
  11258. $offset += 2;
  11259. $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
  11260. $subHeaders[$k]['idRangeOffset'] /= 2;
  11261. $numGlyphIndexArray += $subHeaders[$k]['entryCount'];
  11262. }
  11263. for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
  11264. $glyphIndexArray[$k] = $this->_getUSHORT($font, $offset);
  11265. $offset += 2;
  11266. }
  11267. for ($i = 0; $i < 256; ++$i) {
  11268. $k = $subHeaderKeys[$i];
  11269. if ($k == 0) {
  11270. // one byte code
  11271. $c = $i;
  11272. $g = $glyphIndexArray[0];
  11273. $ctg[$c] = $g;
  11274. } else {
  11275. // two bytes cod