PageRenderTime 67ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 1ms

/phpmyadmin/libraries/tcpdf/tcpdf.php

https://bitbucket.org/kylestlb/cse360site
PHP | 11454 lines | 7006 code | 436 blank | 4012 comment | 1361 complexity | a8d65bd5f1e854e90fc7d70345f00527 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 5.9.039
  5. // Begin : 2002-08-03
  6. // Last Update : 2011-01-12
  7. // Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  8. // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS.
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2011 Nicola Asuni - Tecnick.com S.r.l.
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version. Additionally,
  18. // YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE
  19. // GENERATED PDF DOCUMENTS.
  20. //
  21. // TCPDF is distributed in the hope that it will be useful, but
  22. // WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. // See the GNU Lesser General Public License for more details.
  25. //
  26. // You should have received a copy of the License
  27. // along with TCPDF. If not, see
  28. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  29. //
  30. // See LICENSE.TXT file for more information.
  31. // -------------------------------------------------------------------
  32. //
  33. // Description : This is a PHP class for generating PDF documents without
  34. // requiring external extensions.
  35. //
  36. // NOTE:
  37. // This class was originally derived in 2002 from the Public
  38. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  39. // but now is almost entirely rewritten and contains thousands of
  40. // new lines of code and hundreds new features.
  41. //
  42. // Main features:
  43. // * no external libraries are required for the basic functions;
  44. // * all standard page formats, custom page formats, custom margins and units of measure;
  45. // * UTF-8 Unicode and Right-To-Left languages;
  46. // * TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  47. // * font subsetting;
  48. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  49. // * images, graphic (geometric figures) and transformation methods;
  50. // * 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)
  51. // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, QR-Code, PDF417;
  52. // * Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  53. // * automatic page header and footer management;
  54. // * document encryption up to 256 bit and digital signature certifications;
  55. // * transactions to UNDO commands;
  56. // * PDF annotations, including links, text and file attachments;
  57. // * text rendering modes (fill, stroke and clipping);
  58. // * multiple columns mode;
  59. // * no-write page regions;
  60. // * bookmarks and table of content;
  61. // * text hyphenation;
  62. // * text stretching and spacing (tracking/kerning);
  63. // * automatic page break, line break and text alignments including justification;
  64. // * automatic page numbering and page groups;
  65. // * move and delete pages;
  66. // * page compression (requires php-zlib extension);
  67. // * XOBject Templates;
  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. // Anyone that has reported a bug or sent a suggestion.
  100. //============================================================+
  101. /**
  102. * @file
  103. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  104. * 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>
  105. * <h3>TCPDF main features are:</h3>
  106. * <ul>
  107. * <li>no external libraries are required for the basic functions;</li>
  108. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  109. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  110. * <li>TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  111. * <li>font subsetting;</li>
  112. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  113. * <li>images, graphic (geometric figures) and transformation methods;
  114. * <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>
  115. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, QR-Code, PDF417;</li>
  116. * <li>Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  117. * <li>automatic page header and footer management;</li>
  118. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  119. * <li>transactions to UNDO commands;</li>
  120. * <li>PDF annotations, including links, text and file attachments;</li>
  121. * <li>text rendering modes (fill, stroke and clipping);</li>
  122. * <li>multiple columns mode;</li>
  123. * <li>no-write page regions;</li>
  124. * <li>bookmarks and table of content;</li>
  125. * <li>text hyphenation;</li>
  126. * <li>text stretching and spacing (tracking/kerning);</li>
  127. * <li>automatic page break, line break and text alignments including justification;</li>
  128. * <li>automatic page numbering and page groups;</li>
  129. * <li>move and delete pages;</li>
  130. * <li>page compression (requires php-zlib extension);</li>
  131. * <li>XOBject Templates;</li>
  132. * </ul>
  133. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  134. * @package com.tecnick.tcpdf
  135. * @author Nicola Asuni
  136. * @version 5.9.039
  137. */
  138. // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file.
  139. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  140. /**
  141. * @class TCPDF
  142. * PHP class for generating PDF documents without requiring external extensions.
  143. * 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>
  144. * @package com.tecnick.tcpdf
  145. * @brief PHP class for generating PDF documents without requiring external extensions.
  146. * @version 5.9.039
  147. * @author Nicola Asuni - info@tecnick.com
  148. */
  149. class TCPDF {
  150. // private properties
  151. /**
  152. * Current TCPDF version.
  153. * @private
  154. */
  155. private $tcpdf_version = '5.9.039';
  156. // Protected properties
  157. /**
  158. * Current page number.
  159. * @protected
  160. */
  161. protected $page;
  162. /**
  163. * Current object number.
  164. * @protected
  165. */
  166. protected $n;
  167. /**
  168. * Array of object offsets.
  169. * @protected
  170. */
  171. protected $offsets;
  172. /**
  173. * Buffer holding in-memory PDF.
  174. * @protected
  175. */
  176. protected $buffer;
  177. /**
  178. * Array containing pages.
  179. * @protected
  180. */
  181. protected $pages = array();
  182. /**
  183. * Current document state.
  184. * @protected
  185. */
  186. protected $state;
  187. /**
  188. * Compression flag.
  189. * @protected
  190. */
  191. protected $compress;
  192. /**
  193. * Current page orientation (P = Portrait, L = Landscape).
  194. * @protected
  195. */
  196. protected $CurOrientation;
  197. /**
  198. * Page dimensions.
  199. * @protected
  200. */
  201. protected $pagedim = array();
  202. /**
  203. * Scale factor (number of points in user unit).
  204. * @protected
  205. */
  206. protected $k;
  207. /**
  208. * Width of page format in points.
  209. * @protected
  210. */
  211. protected $fwPt;
  212. /**
  213. * Height of page format in points.
  214. * @protected
  215. */
  216. protected $fhPt;
  217. /**
  218. * Current width of page in points.
  219. * @protected
  220. */
  221. protected $wPt;
  222. /**
  223. * Current height of page in points.
  224. * @protected
  225. */
  226. protected $hPt;
  227. /**
  228. * Current width of page in user unit.
  229. * @protected
  230. */
  231. protected $w;
  232. /**
  233. * Current height of page in user unit.
  234. * @protected
  235. */
  236. protected $h;
  237. /**
  238. * Left margin.
  239. * @protected
  240. */
  241. protected $lMargin;
  242. /**
  243. * Top margin.
  244. * @protected
  245. */
  246. protected $tMargin;
  247. /**
  248. * Right margin.
  249. * @protected
  250. */
  251. protected $rMargin;
  252. /**
  253. * Page break margin.
  254. * @protected
  255. */
  256. protected $bMargin;
  257. /**
  258. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  259. * @since 5.9.000 (2010-10-03)
  260. * @protected
  261. */
  262. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  263. /**
  264. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  265. * @since 5.9.000 (2010-10-04)
  266. * @protected
  267. */
  268. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  269. /**
  270. * Current horizontal position in user unit for cell positioning.
  271. * @protected
  272. */
  273. protected $x;
  274. /**
  275. * Current vertical position in user unit for cell positioning.
  276. * @protected
  277. */
  278. protected $y;
  279. /**
  280. * Height of last cell printed.
  281. * @protected
  282. */
  283. protected $lasth;
  284. /**
  285. * Line width in user unit.
  286. * @protected
  287. */
  288. protected $LineWidth;
  289. /**
  290. * Array of standard font names.
  291. * @protected
  292. */
  293. protected $CoreFonts;
  294. /**
  295. * Array of used fonts.
  296. * @protected
  297. */
  298. protected $fonts = array();
  299. /**
  300. * Array of font files.
  301. * @protected
  302. */
  303. protected $FontFiles = array();
  304. /**
  305. * Array of encoding differences.
  306. * @protected
  307. */
  308. protected $diffs = array();
  309. /**
  310. * Array of used images.
  311. * @protected
  312. */
  313. protected $images = array();
  314. /**
  315. * Array of Annotations in pages.
  316. * @protected
  317. */
  318. protected $PageAnnots = array();
  319. /**
  320. * Array of internal links.
  321. * @protected
  322. */
  323. protected $links = array();
  324. /**
  325. * Current font family.
  326. * @protected
  327. */
  328. protected $FontFamily;
  329. /**
  330. * Current font style.
  331. * @protected
  332. */
  333. protected $FontStyle;
  334. /**
  335. * Current font ascent (distance between font top and baseline).
  336. * @protected
  337. * @since 2.8.000 (2007-03-29)
  338. */
  339. protected $FontAscent;
  340. /**
  341. * Current font descent (distance between font bottom and baseline).
  342. * @protected
  343. * @since 2.8.000 (2007-03-29)
  344. */
  345. protected $FontDescent;
  346. /**
  347. * Underlining flag.
  348. * @protected
  349. */
  350. protected $underline;
  351. /**
  352. * Overlining flag.
  353. * @protected
  354. */
  355. protected $overline;
  356. /**
  357. * Current font info.
  358. * @protected
  359. */
  360. protected $CurrentFont;
  361. /**
  362. * Current font size in points.
  363. * @protected
  364. */
  365. protected $FontSizePt;
  366. /**
  367. * Current font size in user unit.
  368. * @protected
  369. */
  370. protected $FontSize;
  371. /**
  372. * Commands for drawing color.
  373. * @protected
  374. */
  375. protected $DrawColor;
  376. /**
  377. * Commands for filling color.
  378. * @protected
  379. */
  380. protected $FillColor;
  381. /**
  382. * Commands for text color.
  383. * @protected
  384. */
  385. protected $TextColor;
  386. /**
  387. * Indicates whether fill and text colors are different.
  388. * @protected
  389. */
  390. protected $ColorFlag;
  391. /**
  392. * Automatic page breaking.
  393. * @protected
  394. */
  395. protected $AutoPageBreak;
  396. /**
  397. * Threshold used to trigger page breaks.
  398. * @protected
  399. */
  400. protected $PageBreakTrigger;
  401. /**
  402. * Flag set when processing footer.
  403. * @protected
  404. */
  405. protected $InFooter = false;
  406. /**
  407. * Zoom display mode.
  408. * @protected
  409. */
  410. protected $ZoomMode;
  411. /**
  412. * Layout display mode.
  413. * @protected
  414. */
  415. protected $LayoutMode;
  416. /**
  417. * If true set the document information dictionary in Unicode.
  418. * @protected
  419. */
  420. protected $docinfounicode = true;
  421. /**
  422. * Document title.
  423. * @protected
  424. */
  425. protected $title = '';
  426. /**
  427. * Document subject.
  428. * @protected
  429. */
  430. protected $subject = '';
  431. /**
  432. * Document author.
  433. * @protected
  434. */
  435. protected $author = '';
  436. /**
  437. * Document keywords.
  438. * @protected
  439. */
  440. protected $keywords = '';
  441. /**
  442. * Document creator.
  443. * @protected
  444. */
  445. protected $creator = '';
  446. /**
  447. * String alias for total number of pages.
  448. * @protected
  449. */
  450. protected $AliasNbPages = '{nb}';
  451. /**
  452. * String alias for page number.
  453. * @protected
  454. */
  455. protected $AliasNumPage = '{pnb}';
  456. /**
  457. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  458. * @since 2002-07-31
  459. * @author Nicola Asuni
  460. * @protected
  461. */
  462. protected $img_rb_x;
  463. /**
  464. * The right-bottom corner Y coordinate of last inserted image.
  465. * @since 2002-07-31
  466. * @author Nicola Asuni
  467. * @protected
  468. */
  469. protected $img_rb_y;
  470. /**
  471. * Adjusting factor to convert pixels to user units.
  472. * @since 2004-06-14
  473. * @author Nicola Asuni
  474. * @protected
  475. */
  476. protected $imgscale = 1;
  477. /**
  478. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  479. * @since 2005-01-02
  480. * @author Nicola Asuni
  481. * @protected
  482. */
  483. protected $isunicode = false;
  484. /**
  485. * Object containing unicode data.
  486. * @since 5.9.004 (2010-10-18)
  487. * @author Nicola Asuni
  488. * @protected
  489. */
  490. protected $unicode;
  491. /**
  492. * PDF version.
  493. * @since 1.5.3
  494. * @protected
  495. */
  496. protected $PDFVersion = '1.7';
  497. /**
  498. * Minimum distance between header and top page margin.
  499. * @protected
  500. */
  501. protected $header_margin;
  502. /**
  503. * Minimum distance between footer and bottom page margin.
  504. * @protected
  505. */
  506. protected $footer_margin;
  507. /**
  508. * Original left margin value.
  509. * @protected
  510. * @since 1.53.0.TC013
  511. */
  512. protected $original_lMargin;
  513. /**
  514. * Original right margin value.
  515. * @protected
  516. * @since 1.53.0.TC013
  517. */
  518. protected $original_rMargin;
  519. /**
  520. * Default font used on page header.
  521. * @protected
  522. */
  523. protected $header_font;
  524. /**
  525. * Default font used on page footer.
  526. * @protected
  527. */
  528. protected $footer_font;
  529. /**
  530. * Language templates.
  531. * @protected
  532. */
  533. protected $l;
  534. /**
  535. * Barcode to print on page footer (only if set).
  536. * @protected
  537. */
  538. protected $barcode = false;
  539. /**
  540. * Boolean flag to print/hide page header.
  541. * @protected
  542. */
  543. protected $print_header = true;
  544. /**
  545. * Boolean flag to print/hide page footer.
  546. * @protected
  547. */
  548. protected $print_footer = true;
  549. /**
  550. * Header image logo.
  551. * @protected
  552. */
  553. protected $header_logo = '';
  554. /**
  555. * Width of header image logo in user units.
  556. * @protected
  557. */
  558. protected $header_logo_width = 30;
  559. /**
  560. * Title to be printed on default page header.
  561. * @protected
  562. */
  563. protected $header_title = '';
  564. /**
  565. * String to pring on page header after title.
  566. * @protected
  567. */
  568. protected $header_string = '';
  569. /**
  570. * Default number of columns for html table.
  571. * @protected
  572. */
  573. protected $default_table_columns = 4;
  574. // variables for html parser
  575. /**
  576. * HTML PARSER: array to store current link and rendering styles.
  577. * @protected
  578. */
  579. protected $HREF = array();
  580. /**
  581. * List of available fonts on filesystem.
  582. * @protected
  583. */
  584. protected $fontlist = array();
  585. /**
  586. * Current foreground color.
  587. * @protected
  588. */
  589. protected $fgcolor;
  590. /**
  591. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  592. * @protected
  593. */
  594. protected $listordered = array();
  595. /**
  596. * HTML PARSER: array count list items on nested lists.
  597. * @protected
  598. */
  599. protected $listcount = array();
  600. /**
  601. * HTML PARSER: current list nesting level.
  602. * @protected
  603. */
  604. protected $listnum = 0;
  605. /**
  606. * HTML PARSER: indent amount for lists.
  607. * @protected
  608. */
  609. protected $listindent = 0;
  610. /**
  611. * HTML PARSER: current list indententation level.
  612. * @protected
  613. */
  614. protected $listindentlevel = 0;
  615. /**
  616. * Current background color.
  617. * @protected
  618. */
  619. protected $bgcolor;
  620. /**
  621. * Temporary font size in points.
  622. * @protected
  623. */
  624. protected $tempfontsize = 10;
  625. /**
  626. * Spacer string for LI tags.
  627. * @protected
  628. */
  629. protected $lispacer = '';
  630. /**
  631. * Default encoding.
  632. * @protected
  633. * @since 1.53.0.TC010
  634. */
  635. protected $encoding = 'UTF-8';
  636. /**
  637. * PHP internal encoding.
  638. * @protected
  639. * @since 1.53.0.TC016
  640. */
  641. protected $internal_encoding;
  642. /**
  643. * Boolean flag to indicate if the document language is Right-To-Left.
  644. * @protected
  645. * @since 2.0.000
  646. */
  647. protected $rtl = false;
  648. /**
  649. * Boolean flag used to force RTL or LTR string direction.
  650. * @protected
  651. * @since 2.0.000
  652. */
  653. protected $tmprtl = false;
  654. // --- Variables used for document encryption:
  655. /**
  656. * IBoolean flag indicating whether document is protected.
  657. * @protected
  658. * @since 2.0.000 (2008-01-02)
  659. */
  660. protected $encrypted;
  661. /**
  662. * Array containing encryption settings.
  663. * @protected
  664. * @since 5.0.005 (2010-05-11)
  665. */
  666. protected $encryptdata = array();
  667. /**
  668. * Last RC4 key encrypted (cached for optimisation).
  669. * @protected
  670. * @since 2.0.000 (2008-01-02)
  671. */
  672. protected $last_enc_key;
  673. /**
  674. * Last RC4 computed key.
  675. * @protected
  676. * @since 2.0.000 (2008-01-02)
  677. */
  678. protected $last_enc_key_c;
  679. /**
  680. * Encryption padding string.
  681. * @protected
  682. */
  683. 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";
  684. /**
  685. * File ID (used on document trailer).
  686. * @protected
  687. * @since 5.0.005 (2010-05-12)
  688. */
  689. protected $file_id;
  690. // --- bookmark ---
  691. /**
  692. * Outlines for bookmark.
  693. * @protected
  694. * @since 2.1.002 (2008-02-12)
  695. */
  696. protected $outlines = array();
  697. /**
  698. * Outline root for bookmark.
  699. * @protected
  700. * @since 2.1.002 (2008-02-12)
  701. */
  702. protected $OutlineRoot;
  703. // --- javascript and form ---
  704. /**
  705. * Javascript code.
  706. * @protected
  707. * @since 2.1.002 (2008-02-12)
  708. */
  709. protected $javascript = '';
  710. /**
  711. * Javascript counter.
  712. * @protected
  713. * @since 2.1.002 (2008-02-12)
  714. */
  715. protected $n_js;
  716. /**
  717. * line trough state
  718. * @protected
  719. * @since 2.8.000 (2008-03-19)
  720. */
  721. protected $linethrough;
  722. /**
  723. * Array with additional document-wide usage rights for the document.
  724. * @protected
  725. * @since 5.8.014 (2010-08-23)
  726. */
  727. protected $ur = array();
  728. /**
  729. * DPI (Dot Per Inch) Document Resolution (do not change).
  730. * @protected
  731. * @since 3.0.000 (2008-03-27)
  732. */
  733. protected $dpi = 72;
  734. /**
  735. * Array of page numbers were a new page group was started.
  736. * @protected
  737. * @since 3.0.000 (2008-03-27)
  738. */
  739. protected $newpagegroup = array();
  740. /**
  741. * Contains the number of pages of the groups.
  742. * @protected
  743. * @since 3.0.000 (2008-03-27)
  744. */
  745. protected $pagegroups;
  746. /**
  747. * Contains the alias of the current page group.
  748. * @protected
  749. * @since 3.0.000 (2008-03-27)
  750. */
  751. protected $currpagegroup;
  752. /**
  753. * Restrict the rendering of some elements to screen or printout.
  754. * @protected
  755. * @since 3.0.000 (2008-03-27)
  756. */
  757. protected $visibility = 'all';
  758. /**
  759. * Print visibility.
  760. * @protected
  761. * @since 3.0.000 (2008-03-27)
  762. */
  763. protected $n_ocg_print;
  764. /**
  765. * View visibility.
  766. * @protected
  767. * @since 3.0.000 (2008-03-27)
  768. */
  769. protected $n_ocg_view;
  770. /**
  771. * Array of transparency objects and parameters.
  772. * @protected
  773. * @since 3.0.000 (2008-03-27)
  774. */
  775. protected $extgstates;
  776. /**
  777. * Set the default JPEG compression quality (1-100).
  778. * @protected
  779. * @since 3.0.000 (2008-03-27)
  780. */
  781. protected $jpeg_quality;
  782. /**
  783. * Default cell height ratio.
  784. * @protected
  785. * @since 3.0.014 (2008-05-23)
  786. */
  787. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  788. /**
  789. * PDF viewer preferences.
  790. * @protected
  791. * @since 3.1.000 (2008-06-09)
  792. */
  793. protected $viewer_preferences;
  794. /**
  795. * A name object specifying how the document should be displayed when opened.
  796. * @protected
  797. * @since 3.1.000 (2008-06-09)
  798. */
  799. protected $PageMode;
  800. /**
  801. * Array for storing gradient information.
  802. * @protected
  803. * @since 3.1.000 (2008-06-09)
  804. */
  805. protected $gradients = array();
  806. /**
  807. * Array used to store positions inside the pages buffer (keys are the page numbers).
  808. * @protected
  809. * @since 3.2.000 (2008-06-26)
  810. */
  811. protected $intmrk = array();
  812. /**
  813. * Array used to store positions inside the pages buffer (keys are the page numbers).
  814. * @protected
  815. * @since 5.7.000 (2010-08-03)
  816. */
  817. protected $bordermrk = array();
  818. /**
  819. * Array used to store page positions to track empty pages (keys are the page numbers).
  820. * @protected
  821. * @since 5.8.007 (2010-08-18)
  822. */
  823. protected $emptypagemrk = array();
  824. /**
  825. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  826. * @protected
  827. * @since 4.6.021 (2009-07-20)
  828. */
  829. protected $cntmrk = array();
  830. /**
  831. * Array used to store footer positions of each page.
  832. * @protected
  833. * @since 3.2.000 (2008-07-01)
  834. */
  835. protected $footerpos = array();
  836. /**
  837. * Array used to store footer length of each page.
  838. * @protected
  839. * @since 4.0.014 (2008-07-29)
  840. */
  841. protected $footerlen = array();
  842. /**
  843. * Boolean flag to indicate if a new line is created.
  844. * @protected
  845. * @since 3.2.000 (2008-07-01)
  846. */
  847. protected $newline = true;
  848. /**
  849. * End position of the latest inserted line.
  850. * @protected
  851. * @since 3.2.000 (2008-07-01)
  852. */
  853. protected $endlinex = 0;
  854. /**
  855. * PDF string for width value of the last line.
  856. * @protected
  857. * @since 4.0.006 (2008-07-16)
  858. */
  859. protected $linestyleWidth = '';
  860. /**
  861. * PDF string for CAP value of the last line.
  862. * @protected
  863. * @since 4.0.006 (2008-07-16)
  864. */
  865. protected $linestyleCap = '0 J';
  866. /**
  867. * PDF string for join value of the last line.
  868. * @protected
  869. * @since 4.0.006 (2008-07-16)
  870. */
  871. protected $linestyleJoin = '0 j';
  872. /**
  873. * PDF string for dash value of the last line.
  874. * @protected
  875. * @since 4.0.006 (2008-07-16)
  876. */
  877. protected $linestyleDash = '[] 0 d';
  878. /**
  879. * Boolean flag to indicate if marked-content sequence is open.
  880. * @protected
  881. * @since 4.0.013 (2008-07-28)
  882. */
  883. protected $openMarkedContent = false;
  884. /**
  885. * Count the latest inserted vertical spaces on HTML.
  886. * @protected
  887. * @since 4.0.021 (2008-08-24)
  888. */
  889. protected $htmlvspace = 0;
  890. /**
  891. * Array of Spot colors.
  892. * @protected
  893. * @since 4.0.024 (2008-09-12)
  894. */
  895. protected $spot_colors = array();
  896. /**
  897. * Symbol used for HTML unordered list items.
  898. * @protected
  899. * @since 4.0.028 (2008-09-26)
  900. */
  901. protected $lisymbol = '';
  902. /**
  903. * String used to mark the beginning and end of EPS image blocks.
  904. * @protected
  905. * @since 4.1.000 (2008-10-18)
  906. */
  907. protected $epsmarker = 'x#!#EPS#!#x';
  908. /**
  909. * Array of transformation matrix.
  910. * @protected
  911. * @since 4.2.000 (2008-10-29)
  912. */
  913. protected $transfmatrix = array();
  914. /**
  915. * Current key for transformation matrix.
  916. * @protected
  917. * @since 4.8.005 (2009-09-17)
  918. */
  919. protected $transfmatrix_key = 0;
  920. /**
  921. * Booklet mode for double-sided pages.
  922. * @protected
  923. * @since 4.2.000 (2008-10-29)
  924. */
  925. protected $booklet = false;
  926. /**
  927. * Epsilon value used for float calculations.
  928. * @protected
  929. * @since 4.2.000 (2008-10-29)
  930. */
  931. protected $feps = 0.005;
  932. /**
  933. * Array used for custom vertical spaces for HTML tags.
  934. * @protected
  935. * @since 4.2.001 (2008-10-30)
  936. */
  937. protected $tagvspaces = array();
  938. /**
  939. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  940. * @protected
  941. * @since 4.2.007 (2008-11-12)
  942. */
  943. protected $customlistindent = -1;
  944. /**
  945. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  946. * @protected
  947. * @since 4.2.010 (2008-11-14)
  948. */
  949. protected $opencell = true;
  950. /**
  951. * Array of files to embedd.
  952. * @protected
  953. * @since 4.4.000 (2008-12-07)
  954. */
  955. protected $embeddedfiles = array();
  956. /**
  957. * Boolean flag to indicate if we are inside a PRE tag.
  958. * @protected
  959. * @since 4.4.001 (2008-12-08)
  960. */
  961. protected $premode = false;
  962. /**
  963. * Array used to store positions of graphics transformation blocks inside the page buffer.
  964. * keys are the page numbers
  965. * @protected
  966. * @since 4.4.002 (2008-12-09)
  967. */
  968. protected $transfmrk = array();
  969. /**
  970. * Default color for html links.
  971. * @protected
  972. * @since 4.4.003 (2008-12-09)
  973. */
  974. protected $htmlLinkColorArray = array(0, 0, 255);
  975. /**
  976. * Default font style to add to html links.
  977. * @protected
  978. * @since 4.4.003 (2008-12-09)
  979. */
  980. protected $htmlLinkFontStyle = 'U';
  981. /**
  982. * Counts the number of pages.
  983. * @protected
  984. * @since 4.5.000 (2008-12-31)
  985. */
  986. protected $numpages = 0;
  987. /**
  988. * Array containing page lengths in bytes.
  989. * @protected
  990. * @since 4.5.000 (2008-12-31)
  991. */
  992. protected $pagelen = array();
  993. /**
  994. * Counts the number of pages.
  995. * @protected
  996. * @since 4.5.000 (2008-12-31)
  997. */
  998. protected $numimages = 0;
  999. /**
  1000. * Store the image keys.
  1001. * @protected
  1002. * @since 4.5.000 (2008-12-31)
  1003. */
  1004. protected $imagekeys = array();
  1005. /**
  1006. * Length of the buffer in bytes.
  1007. * @protected
  1008. * @since 4.5.000 (2008-12-31)
  1009. */
  1010. protected $bufferlen = 0;
  1011. /**
  1012. * If true enables disk caching.
  1013. * @protected
  1014. * @since 4.5.000 (2008-12-31)
  1015. */
  1016. protected $diskcache = false;
  1017. /**
  1018. * Counts the number of fonts.
  1019. * @protected
  1020. * @since 4.5.000 (2009-01-02)
  1021. */
  1022. protected $numfonts = 0;
  1023. /**
  1024. * Store the font keys.
  1025. * @protected
  1026. * @since 4.5.000 (2009-01-02)
  1027. */
  1028. protected $fontkeys = array();
  1029. /**
  1030. * Store the font object IDs.
  1031. * @protected
  1032. * @since 4.8.001 (2009-09-09)
  1033. */
  1034. protected $font_obj_ids = array();
  1035. /**
  1036. * Store the fage status (true when opened, false when closed).
  1037. * @protected
  1038. * @since 4.5.000 (2009-01-02)
  1039. */
  1040. protected $pageopen = array();
  1041. /**
  1042. * Default monospace font.
  1043. * @protected
  1044. * @since 4.5.025 (2009-03-10)
  1045. */
  1046. protected $default_monospaced_font = 'courier';
  1047. /**
  1048. * Cloned copy of the current class object.
  1049. * @protected
  1050. * @since 4.5.029 (2009-03-19)
  1051. */
  1052. protected $objcopy;
  1053. /**
  1054. * Array used to store the lengths of cache files.
  1055. * @protected
  1056. * @since 4.5.029 (2009-03-19)
  1057. */
  1058. protected $cache_file_length = array();
  1059. /**
  1060. * Table header content to be repeated on each new page.
  1061. * @protected
  1062. * @since 4.5.030 (2009-03-20)
  1063. */
  1064. protected $thead = '';
  1065. /**
  1066. * Margins used for table header.
  1067. * @protected
  1068. * @since 4.5.030 (2009-03-20)
  1069. */
  1070. protected $theadMargins = array();
  1071. /**
  1072. * Cache array for UTF8StringToArray() method.
  1073. * @protected
  1074. * @since 4.5.037 (2009-04-07)
  1075. */
  1076. protected $cache_UTF8StringToArray = array();
  1077. /**
  1078. * Maximum size of cache array used for UTF8StringToArray() method.
  1079. * @protected
  1080. * @since 4.5.037 (2009-04-07)
  1081. */
  1082. protected $cache_maxsize_UTF8StringToArray = 8;
  1083. /**
  1084. * Current size of cache array used for UTF8StringToArray() method.
  1085. * @protected
  1086. * @since 4.5.037 (2009-04-07)
  1087. */
  1088. protected $cache_size_UTF8StringToArray = 0;
  1089. /**
  1090. * Boolean flag to enable document digital signature.
  1091. * @protected
  1092. * @since 4.6.005 (2009-04-24)
  1093. */
  1094. protected $sign = false;
  1095. /**
  1096. * Digital signature data.
  1097. * @protected
  1098. * @since 4.6.005 (2009-04-24)
  1099. */
  1100. protected $signature_data = array();
  1101. /**
  1102. * Digital signature max length.
  1103. * @protected
  1104. * @since 4.6.005 (2009-04-24)
  1105. */
  1106. protected $signature_max_length = 11742;
  1107. /**
  1108. * Data for digital signature appearance.
  1109. * @protected
  1110. * @since 5.3.011 (2010-06-16)
  1111. */
  1112. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1113. /**
  1114. * Regular expression used to find blank characters (required for word-wrapping).
  1115. * @protected
  1116. * @since 4.6.006 (2009-04-28)
  1117. */
  1118. protected $re_spaces = '/[^\S\xa0]/';
  1119. /**
  1120. * Array of $re_spaces parts.
  1121. * @protected
  1122. * @since 5.5.011 (2010-07-09)
  1123. */
  1124. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1125. /**
  1126. * Digital signature object ID.
  1127. * @protected
  1128. * @since 4.6.022 (2009-06-23)
  1129. */
  1130. protected $sig_obj_id = 0;
  1131. /**
  1132. * ByteRange placemark used during digital signature process.
  1133. * @protected
  1134. * @since 4.6.028 (2009-08-25)
  1135. */
  1136. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1137. /**
  1138. * Placemark used during digital signature process.
  1139. * @protected
  1140. * @since 4.6.028 (2009-08-25)
  1141. */
  1142. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1143. /**
  1144. * ID of page objects.
  1145. * @protected
  1146. * @since 4.7.000 (2009-08-29)
  1147. */
  1148. protected $page_obj_id = array();
  1149. /**
  1150. * List of form annotations IDs.
  1151. * @protected
  1152. * @since 4.8.000 (2009-09-07)
  1153. */
  1154. protected $form_obj_id = array();
  1155. /**
  1156. * 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.
  1157. * @protected
  1158. * @since 4.8.000 (2009-09-07)
  1159. */
  1160. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1161. /**
  1162. * Javascript objects array.
  1163. * @protected
  1164. * @since 4.8.000 (2009-09-07)
  1165. */
  1166. protected $js_objects = array();
  1167. /**
  1168. * Current form action (used during XHTML rendering).
  1169. * @protected
  1170. * @since 4.8.000 (2009-09-07)
  1171. */
  1172. protected $form_action = '';
  1173. /**
  1174. * Current form encryption type (used during XHTML rendering).
  1175. * @protected
  1176. * @since 4.8.000 (2009-09-07)
  1177. */
  1178. protected $form_enctype = 'application/x-www-form-urlencoded';
  1179. /**
  1180. * Current method to submit forms.
  1181. * @protected
  1182. * @since 4.8.000 (2009-09-07)
  1183. */
  1184. protected $form_mode = 'post';
  1185. /**
  1186. * List of fonts used on form fields (fontname => fontkey).
  1187. * @protected
  1188. * @since 4.8.001 (2009-09-09)
  1189. */
  1190. protected $annotation_fonts = array();
  1191. /**
  1192. * List of radio buttons parent objects.
  1193. * @protected
  1194. * @since 4.8.001 (2009-09-09)
  1195. */
  1196. protected $radiobutton_groups = array();
  1197. /**
  1198. * List of radio group objects IDs.
  1199. * @protected
  1200. * @since 4.8.001 (2009-09-09)
  1201. */
  1202. protected $radio_groups = array();
  1203. /**
  1204. * Text indentation value (used for text-indent CSS attribute).
  1205. * @protected
  1206. * @since 4.8.006 (2009-09-23)
  1207. */
  1208. protected $textindent = 0;
  1209. /**
  1210. * Store page number when startTransaction() is called.
  1211. * @protected
  1212. * @since 4.8.006 (2009-09-23)
  1213. */
  1214. protected $start_transaction_page = 0;
  1215. /**
  1216. * Store Y position when startTransaction() is called.
  1217. * @protected
  1218. * @since 4.9.001 (2010-03-28)
  1219. */
  1220. protected $start_transaction_y = 0;
  1221. /**
  1222. * True when we are printing the thead section on a new page.
  1223. * @protected
  1224. * @since 4.8.027 (2010-01-25)
  1225. */
  1226. protected $inthead = false;
  1227. /**
  1228. * Array of column measures (width, space, starting Y position).
  1229. * @protected
  1230. * @since 4.9.001 (2010-03-28)
  1231. */
  1232. protected $columns = array();
  1233. /**
  1234. * Number of colums.
  1235. * @protected
  1236. * @since 4.9.001 (2010-03-28)
  1237. */
  1238. protected $num_columns = 1;
  1239. /**
  1240. * Current column number.
  1241. * @protected
  1242. * @since 4.9.001 (2010-03-28)
  1243. */
  1244. protected $current_column = 0;
  1245. /**
  1246. * Starting page for columns.
  1247. * @protected
  1248. * @since 4.9.001 (2010-03-28)
  1249. */
  1250. protected $column_start_page = 0;
  1251. /**
  1252. * Maximum page and column selected.
  1253. * @protected
  1254. * @since 5.8.000 (2010-08-11)
  1255. */
  1256. protected $maxselcol = array('page' => 0, 'column' => 0);
  1257. /**
  1258. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1259. * @protected
  1260. * @since 5.8.000 (2010-08-11)
  1261. */
  1262. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1263. /**
  1264. * 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.
  1265. * @protected
  1266. * @since 4.9.008 (2010-04-03)
  1267. */
  1268. protected $textrendermode = 0;
  1269. /**
  1270. * Text stroke width in doc units.
  1271. * @protected
  1272. * @since 4.9.008 (2010-04-03)
  1273. */
  1274. protected $textstrokewidth = 0;
  1275. /**
  1276. * Current stroke color.
  1277. * @protected
  1278. * @since 4.9.008 (2010-04-03)
  1279. */
  1280. protected $strokecolor;
  1281. /**
  1282. * Default unit of measure for document.
  1283. * @protected
  1284. * @since 5.0.000 (2010-04-22)
  1285. */
  1286. protected $pdfunit = 'mm';
  1287. /**
  1288. * Boolean flag true when we are on TOC (Table Of Content) page.
  1289. * @protected
  1290. */
  1291. protected $tocpage = false;
  1292. /**
  1293. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1294. * @protected
  1295. * @since 5.0.000 (2010-04-26)
  1296. */
  1297. protected $rasterize_vector_images = false;
  1298. /**
  1299. * Boolean flag: if true enables font subsetting by default.
  1300. * @protected
  1301. * @since 5.3.002 (2010-06-07)
  1302. */
  1303. protected $font_subsetting = true;
  1304. /**
  1305. * Array of default graphic settings.
  1306. * @protected
  1307. * @since 5.5.008 (2010-07-02)
  1308. */
  1309. protected $default_graphic_vars = array();
  1310. /**
  1311. * Array of XObjects.
  1312. * @protected
  1313. * @since 5.8.014 (2010-08-23)
  1314. */
  1315. protected $xobjects = array();
  1316. /**
  1317. * Boolean value true when we are inside an XObject.
  1318. * @protected
  1319. * @since 5.8.017 (2010-08-24)
  1320. */
  1321. protected $inxobj = false;
  1322. /**
  1323. * Current XObject ID.
  1324. * @protected
  1325. * @since 5.8.017 (2010-08-24)
  1326. */
  1327. protected $xobjid = '';
  1328. /**
  1329. * Percentage of character stretching.
  1330. * @protected
  1331. * @since 5.9.000 (2010-09-29)
  1332. */
  1333. protected $font_stretching = 100;
  1334. /**
  1335. * Increases or decreases the space between characters in a text by the specified amount (tracking/kerning).
  1336. * @protected
  1337. * @since 5.9.000 (2010-09-29)
  1338. */
  1339. protected $font_spacing = 0;
  1340. /**
  1341. * Array of no-write regions.
  1342. * ('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)
  1343. * @protected
  1344. * @since 5.9.003 (2010-10-14)
  1345. */
  1346. protected $page_regions = array();
  1347. /**
  1348. * Array containing HTML color names and values.
  1349. * @protected
  1350. * @since 5.9.004 (2010-10-18)
  1351. */
  1352. protected $webcolor = array();
  1353. /**
  1354. * Array containing spot color names and values.
  1355. * @protected
  1356. * @since 5.9.012 (2010-11-11)
  1357. */
  1358. protected $spotcolor = array();
  1359. /**
  1360. * Directory used for the last SVG image.
  1361. * @protected
  1362. * @since 5.0.000 (2010-05-05)
  1363. */
  1364. protected $svgdir = '';
  1365. /**
  1366. * Deafult unit of measure for SVG.
  1367. * @protected
  1368. * @since 5.0.000 (2010-05-02)
  1369. */
  1370. protected $svgunit = 'px';
  1371. /**
  1372. * Array of SVG gradients.
  1373. * @protected
  1374. * @since 5.0.000 (2010-05-02)
  1375. */
  1376. protected $svggradients = array();
  1377. /**
  1378. * ID of last SVG gradient.
  1379. * @protected
  1380. * @since 5.0.000 (2010-05-02)
  1381. */
  1382. protected $svggradientid = 0;
  1383. /**
  1384. * Boolean value true when in SVG defs group.
  1385. * @protected
  1386. * @since 5.0.000 (2010-05-02)
  1387. */
  1388. protected $svgdefsmode = false;
  1389. /**
  1390. * Array of SVG defs.
  1391. * @protected
  1392. * @since 5.0.000 (2010-05-02)
  1393. */
  1394. protected $svgdefs = array();
  1395. /**
  1396. * Boolean value true when in SVG clipPath tag.
  1397. * @protected
  1398. * @since 5.0.000 (2010-04-26)
  1399. */
  1400. protected $svgclipmode = false;
  1401. /**
  1402. * Array of SVG clipPath commands.
  1403. * @protected
  1404. * @since 5.0.000 (2010-05-02)
  1405. */
  1406. protected $svgclippaths = array();
  1407. /**
  1408. * Array of SVG clipPath tranformation matrix.
  1409. * @protected
  1410. * @since 5.8.022 (2010-08-31)
  1411. */
  1412. protected $svgcliptm = array();
  1413. /**
  1414. * ID of last SVG clipPath.
  1415. * @protected
  1416. * @since 5.0.000 (2010-05-02)
  1417. */
  1418. protected $svgclipid = 0;
  1419. /**
  1420. * SVG text.
  1421. * @protected
  1422. * @since 5.0.000 (2010-05-02)
  1423. */
  1424. protected $svgtext = '';
  1425. /**
  1426. * SVG text properties.
  1427. * @protected
  1428. * @since 5.8.013 (2010-08-23)
  1429. */
  1430. protected $svgtextmode = array();
  1431. /**
  1432. * Array of hinheritable SVG properties.
  1433. * @protected
  1434. * @since 5.0.000 (2010-05-02)
  1435. */
  1436. 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');
  1437. /**
  1438. * Array of SVG properties.
  1439. * @protected
  1440. * @since 5.0.000 (2010-05-02)
  1441. */
  1442. protected $svgstyles = array(array(
  1443. 'alignment-baseline' => 'auto',
  1444. 'baseline-shift' => 'baseline',
  1445. 'clip' => 'auto',
  1446. 'clip-path' => 'none',
  1447. 'clip-rule' => 'nonzero',
  1448. 'color' => 'black',
  1449. 'color-interpolation' => 'sRGB',
  1450. 'color-interpolation-filters' => 'linearRGB',
  1451. 'color-profile' => 'auto',
  1452. 'color-rendering' => 'auto',
  1453. 'cursor' => 'auto',
  1454. 'direction' => 'ltr',
  1455. 'display' => 'inline',
  1456. 'dominant-baseline' => 'auto',
  1457. 'enable-background' => 'accumulate',
  1458. 'fill' => 'black',
  1459. 'fill-opacity' => 1,
  1460. 'fill-rule' => 'nonzero',
  1461. 'filter' => 'none',
  1462. 'flood-color' => 'black',
  1463. 'flood-opacity' => 1,
  1464. 'font' => '',
  1465. 'font-family' => 'helvetica',
  1466. 'font-size' => 'medium',
  1467. 'font-size-adjust' => 'none',
  1468. 'font-stretch' => 'normal',
  1469. 'font-style' => 'normal',
  1470. 'font-variant' => 'normal',
  1471. 'font-weight' => 'normal',
  1472. 'glyph-orientation-horizontal' => '0deg',
  1473. 'glyph-orientation-vertical' => 'auto',
  1474. 'image-rendering' => 'auto',
  1475. 'kerning' => 'auto',
  1476. 'letter-spacing' => 'normal',
  1477. 'lighting-color' => 'white',
  1478. 'marker' => '',
  1479. 'marker-end' => 'none',
  1480. 'marker-mid' => 'none',
  1481. 'marker-start' => 'none',
  1482. 'mask' => 'none',
  1483. 'opacity' => 1,
  1484. 'overflow' => 'auto',
  1485. 'pointer-events' => 'visiblePainted',
  1486. 'shape-rendering' => 'auto',
  1487. 'stop-color' => 'black',
  1488. 'stop-opacity' => 1,
  1489. 'stroke' => 'none',
  1490. 'stroke-dasharray' => 'none',
  1491. 'stroke-dashoffset' => 0,
  1492. 'stroke-linecap' => 'butt',
  1493. 'stroke-linejoin' => 'miter',
  1494. 'stroke-miterlimit' => 4,
  1495. 'stroke-opacity' => 1,
  1496. 'stroke-width' => 1,
  1497. 'text-anchor' => 'start',
  1498. 'text-decoration' => 'none',
  1499. 'text-rendering' => 'auto',
  1500. 'unicode-bidi' => 'normal',
  1501. 'visibility' => 'visible',
  1502. 'word-spacing' => 'normal',
  1503. 'writing-mode' => 'lr-tb',
  1504. 'text-color' => 'black',
  1505. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1506. ));
  1507. //------------------------------------------------------------
  1508. // METHODS
  1509. //------------------------------------------------------------
  1510. /**
  1511. * This is the class constructor.
  1512. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1513. * @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>
  1514. * @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.
  1515. * @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().
  1516. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1517. * @param $diskcache (boolean) if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1518. * @param $encoding (string) charset encoding; default is UTF-8
  1519. * @public
  1520. * @see getPageSizeFromFormat(), setPageFormat()
  1521. */
  1522. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false) {
  1523. /* Set internal character encoding to ASCII */
  1524. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1525. $this->internal_encoding = mb_internal_encoding();
  1526. mb_internal_encoding('ASCII');
  1527. }
  1528. // get array of HTML colors
  1529. require(dirname(__FILE__).'/htmlcolors.php');
  1530. $this->webcolor = $webcolor;
  1531. // get array of custom spot colors
  1532. if (file_exists(dirname(__FILE__).'/spotcolors.php')) {
  1533. require(dirname(__FILE__).'/spotcolors.php');
  1534. $this->spotcolor = $spotcolor;
  1535. } else {
  1536. $this->spotcolor = array();
  1537. }
  1538. require_once(dirname(__FILE__).'/unicode_data.php');
  1539. $this->unicode = new TCPDF_UNICODE_DATA();
  1540. $this->font_obj_ids = array();
  1541. $this->page_obj_id = array();
  1542. $this->form_obj_id = array();
  1543. // set disk caching
  1544. $this->diskcache = $diskcache ? true : false;
  1545. // set language direction
  1546. $this->rtl = false;
  1547. $this->tmprtl = false;
  1548. // some checks
  1549. $this->_dochecks();
  1550. // initialization of properties
  1551. $this->isunicode = $unicode;
  1552. $this->page = 0;
  1553. $this->transfmrk[0] = array();
  1554. $this->pagedim = array();
  1555. $this->n = 2;
  1556. $this->buffer = '';
  1557. $this->pages = array();
  1558. $this->state = 0;
  1559. $this->fonts = array();
  1560. $this->FontFiles = array();
  1561. $this->diffs = array();
  1562. $this->images = array();
  1563. $this->links = array();
  1564. $this->gradients = array();
  1565. $this->InFooter = false;
  1566. $this->lasth = 0;
  1567. $this->FontFamily = 'helvetica';
  1568. $this->FontStyle = '';
  1569. $this->FontSizePt = 12;
  1570. $this->underline = false;
  1571. $this->overline = false;
  1572. $this->linethrough = false;
  1573. $this->DrawColor = '0 G';
  1574. $this->FillColor = '0 g';
  1575. $this->TextColor = '0 g';
  1576. $this->ColorFlag = false;
  1577. // encryption values
  1578. $this->encrypted = false;
  1579. $this->last_enc_key = '';
  1580. // standard Unicode fonts
  1581. $this->CoreFonts = array(
  1582. 'courier'=>'Courier',
  1583. 'courierB'=>'Courier-Bold',
  1584. 'courierI'=>'Courier-Oblique',
  1585. 'courierBI'=>'Courier-BoldOblique',
  1586. 'helvetica'=>'Helvetica',
  1587. 'helveticaB'=>'Helvetica-Bold',
  1588. 'helveticaI'=>'Helvetica-Oblique',
  1589. 'helveticaBI'=>'Helvetica-BoldOblique',
  1590. 'times'=>'Times-Roman',
  1591. 'timesB'=>'Times-Bold',
  1592. 'timesI'=>'Times-Italic',
  1593. 'timesBI'=>'Times-BoldItalic',
  1594. 'symbol'=>'Symbol',
  1595. 'zapfdingbats'=>'ZapfDingbats'
  1596. );
  1597. // set scale factor
  1598. $this->setPageUnit($unit);
  1599. // set page format and orientation
  1600. $this->setPageFormat($format, $orientation);
  1601. // page margins (1 cm)
  1602. $margin = 28.35 / $this->k;
  1603. $this->SetMargins($margin, $margin);
  1604. // internal cell padding
  1605. $cpadding = $margin / 10;
  1606. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1607. // cell margins
  1608. $this->setCellMargins(0, 0, 0, 0);
  1609. // line width (0.2 mm)
  1610. $this->LineWidth = 0.57 / $this->k;
  1611. $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
  1612. $this->linestyleCap = '0 J';
  1613. $this->linestyleJoin = '0 j';
  1614. $this->linestyleDash = '[] 0 d';
  1615. // automatic page break
  1616. $this->SetAutoPageBreak(true, (2 * $margin));
  1617. // full width display mode
  1618. $this->SetDisplayMode('fullwidth');
  1619. // compression
  1620. $this->SetCompression(true);
  1621. // set default PDF version number
  1622. $this->PDFVersion = '1.7';
  1623. $this->encoding = $encoding;
  1624. $this->HREF = array();
  1625. $this->getFontsList();
  1626. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1627. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1628. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1629. $this->extgstates = array();
  1630. // user's rights
  1631. $this->sign = false;
  1632. $this->ur['enabled'] = false;
  1633. $this->ur['document'] = '/FullSave';
  1634. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1635. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1636. $this->ur['signature'] = '/Modify';
  1637. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1638. $this->ur['formex'] = '';
  1639. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1640. // set default JPEG quality
  1641. $this->jpeg_quality = 75;
  1642. // initialize some settings
  1643. $this->utf8Bidi(array(''), '');
  1644. // set default font
  1645. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1646. // check if PCRE Unicode support is enabled
  1647. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1648. // PCRE unicode support is turned ON
  1649. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1650. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1651. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1652. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1653. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1654. } else {
  1655. // PCRE unicode support is turned OFF
  1656. $this->setSpacesRE('/[^\S\xa0]/');
  1657. }
  1658. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1659. // set file ID for trailer
  1660. $this->file_id = md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$format.$encoding));
  1661. // get default graphic vars
  1662. $this->default_graphic_vars = $this->getGraphicVars();
  1663. }
  1664. /**
  1665. * Default destructor.
  1666. * @public
  1667. * @since 1.53.0.TC016
  1668. */
  1669. public function __destruct() {
  1670. // restore internal encoding
  1671. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1672. mb_internal_encoding($this->internal_encoding);
  1673. }
  1674. // unset all class variables
  1675. $this->_destroy(true);
  1676. }
  1677. /**
  1678. * Return the current TCPDF version.
  1679. * @return TCPDF version string
  1680. * @public
  1681. * @since 5.9.012 (2010-11-10)
  1682. */
  1683. public function getTCPDFVersion() {
  1684. return $this->tcpdf_version;
  1685. }
  1686. /**
  1687. * Set the units of measure for the document.
  1688. * @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.
  1689. * @public
  1690. * @since 3.0.015 (2008-06-06)
  1691. */
  1692. public function setPageUnit($unit) {
  1693. $unit = strtolower($unit);
  1694. //Set scale factor
  1695. switch ($unit) {
  1696. // points
  1697. case 'px':
  1698. case 'pt': {
  1699. $this->k = 1;
  1700. break;
  1701. }
  1702. // millimeters
  1703. case 'mm': {
  1704. $this->k = $this->dpi / 25.4;
  1705. break;
  1706. }
  1707. // centimeters
  1708. case 'cm': {
  1709. $this->k = $this->dpi / 2.54;
  1710. break;
  1711. }
  1712. // inches
  1713. case 'in': {
  1714. $this->k = $this->dpi;
  1715. break;
  1716. }
  1717. // unsupported unit
  1718. default : {
  1719. $this->Error('Incorrect unit: '.$unit);
  1720. break;
  1721. }
  1722. }
  1723. $this->pdfunit = $unit;
  1724. if (isset($this->CurOrientation)) {
  1725. $this->setPageOrientation($this->CurOrientation);
  1726. }
  1727. }
  1728. /**
  1729. * Get page dimensions from format name.
  1730. * @param $format (mixed) The format name. It can be: <ul>
  1731. * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
  1732. * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
  1733. * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
  1734. * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
  1735. * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
  1736. * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
  1737. * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
  1738. * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
  1739. * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
  1740. * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
  1741. * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
  1742. * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
  1743. * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
  1744. * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
  1745. * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
  1746. * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
  1747. * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
  1748. * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
  1749. * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
  1750. * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
  1751. * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
  1752. * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
  1753. * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
  1754. * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
  1755. * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
  1756. * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
  1757. * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
  1758. * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
  1759. * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
  1760. * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
  1761. * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
  1762. * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
  1763. * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
  1764. * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
  1765. * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
  1766. * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
  1767. * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
  1768. * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
  1769. * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
  1770. * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
  1771. * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
  1772. * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
  1773. * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
  1774. * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
  1775. * <li><b>SIS 014711 E Series</b></li>
  1776. * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
  1777. * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
  1778. * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
  1779. * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
  1780. * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
  1781. * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
  1782. * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
  1783. * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
  1784. * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
  1785. * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
  1786. * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
  1787. * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
  1788. * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
  1789. * <li><b>SIS 014711 G Series</b></li>
  1790. * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
  1791. * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
  1792. * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
  1793. * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
  1794. * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
  1795. * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
  1796. * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
  1797. * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
  1798. * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
  1799. * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
  1800. * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
  1801. * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
  1802. * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
  1803. * <li><b>ISO Press</b></li>
  1804. * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
  1805. * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
  1806. * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
  1807. * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
  1808. * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
  1809. * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
  1810. * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
  1811. * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
  1812. * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
  1813. * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
  1814. * <li><b>German DIN 476</b></li>
  1815. * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
  1816. * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
  1817. * <li><b>Variations on the ISO Standard</b></li>
  1818. * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
  1819. * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
  1820. * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
  1821. * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
  1822. * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
  1823. * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
  1824. * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
  1825. * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
  1826. * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
  1827. * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
  1828. * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
  1829. * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
  1830. * <li><b>ANSI Series</b></li>
  1831. * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
  1832. * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
  1833. * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
  1834. * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
  1835. * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
  1836. * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
  1837. * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
  1838. * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
  1839. * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
  1840. * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
  1841. * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
  1842. * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
  1843. * <li><b>Other North American Paper Sizes</b></li>
  1844. * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
  1845. * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
  1846. * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
  1847. * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
  1848. * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
  1849. * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
  1850. * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
  1851. * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
  1852. * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
  1853. * <li><b>Canadian standard CAN 2-9.60M</b></li>
  1854. * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
  1855. * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
  1856. * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
  1857. * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
  1858. * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
  1859. * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
  1860. * <li><b>North American Architectural Sizes</b></li>
  1861. * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
  1862. * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
  1863. * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
  1864. * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
  1865. * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
  1866. * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
  1867. * <li><b>Announcement Envelopes</b></li>
  1868. * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
  1869. * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
  1870. * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
  1871. * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
  1872. * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
  1873. * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
  1874. * <li><b>Commercial Envelopes</b></li>
  1875. * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
  1876. * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
  1877. * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
  1878. * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
  1879. * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
  1880. * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
  1881. * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
  1882. * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
  1883. * <li><b>Catalogue Envelopes</b></li>
  1884. * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
  1885. * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
  1886. * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
  1887. * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
  1888. * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
  1889. * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
  1890. * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
  1891. * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
  1892. * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
  1893. * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
  1894. * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
  1895. * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
  1896. * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
  1897. * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
  1898. * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
  1899. * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
  1900. * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
  1901. * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
  1902. * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
  1903. * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
  1904. * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
  1905. * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
  1906. * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
  1907. * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
  1908. * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
  1909. * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
  1910. * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
  1911. * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
  1912. * <li><b>PA Series</b></li>
  1913. * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
  1914. * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
  1915. * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
  1916. * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
  1917. * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
  1918. * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
  1919. * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
  1920. * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
  1921. * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
  1922. * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
  1923. * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
  1924. * <li><b>Standard Photographic Print Sizes</b></li>
  1925. * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
  1926. * <li>E (82x120 mm ; 3.25x4.72 in)</li>
  1927. * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
  1928. * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
  1929. * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
  1930. * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
  1931. * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
  1932. * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
  1933. * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
  1934. * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
  1935. * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
  1936. * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
  1937. * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
  1938. * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
  1939. * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
  1940. * <li><b>Common Newspaper Sizes</b></li>
  1941. * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
  1942. * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
  1943. * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
  1944. * <li><b>Business Cards</b></li>
  1945. * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
  1946. * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
  1947. * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
  1948. * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
  1949. * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
  1950. * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
  1951. * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
  1952. * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
  1953. * <li><b>Billboards</b></li>
  1954. * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
  1955. * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
  1956. * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
  1957. * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
  1958. * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
  1959. * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
  1960. * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
  1961. * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
  1962. * <li><b>Old Imperial English (some are still used in USA)</b></li>
  1963. * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
  1964. * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
  1965. * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
  1966. * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
  1967. * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
  1968. * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
  1969. * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
  1970. * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
  1971. * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
  1972. * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
  1973. * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
  1974. * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
  1975. * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
  1976. * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
  1977. * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
  1978. * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
  1979. * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
  1980. * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
  1981. * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
  1982. * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
  1983. * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
  1984. * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
  1985. * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
  1986. * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
  1987. * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
  1988. * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
  1989. * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
  1990. * <li><b>Old Imperial Belgian</b></li>
  1991. * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
  1992. * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
  1993. * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
  1994. * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
  1995. * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
  1996. * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
  1997. * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
  1998. * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  1999. * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
  2000. * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
  2001. * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
  2002. * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
  2003. * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
  2004. * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
  2005. * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
  2006. * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
  2007. * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
  2008. * <li><b>Old Imperial French</b></li>
  2009. * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
  2010. * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
  2011. * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
  2012. * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
  2013. * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
  2014. * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
  2015. * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
  2016. * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
  2017. * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
  2018. * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
  2019. * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
  2020. * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
  2021. * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
  2022. * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
  2023. * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
  2024. * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
  2025. * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  2026. * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
  2027. * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
  2028. * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
  2029. * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
  2030. * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
  2031. * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
  2032. * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
  2033. * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
  2034. * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
  2035. * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
  2036. * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
  2037. * </ul>
  2038. * @return array containing page width and height in points
  2039. * @public
  2040. * @since 5.0.010 (2010-05-17)
  2041. */
  2042. public function getPageSizeFromFormat($format) {
  2043. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
  2044. switch (strtoupper($format)) {
  2045. // ISO 216 A Series + 2 SIS 014711 extensions
  2046. case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
  2047. case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
  2048. case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
  2049. case 'A3' : {$pf = array( 841.890, 1190.551); break;}
  2050. case 'A4' : {$pf = array( 595.276, 841.890); break;}
  2051. case 'A5' : {$pf = array( 419.528, 595.276); break;}
  2052. case 'A6' : {$pf = array( 297.638, 419.528); break;}
  2053. case 'A7' : {$pf = array( 209.764, 297.638); break;}
  2054. case 'A8' : {$pf = array( 147.402, 209.764); break;}
  2055. case 'A9' : {$pf = array( 104.882, 147.402); break;}
  2056. case 'A10': {$pf = array( 73.701, 104.882); break;}
  2057. case 'A11': {$pf = array( 51.024, 73.701); break;}
  2058. case 'A12': {$pf = array( 36.850, 51.024); break;}
  2059. // ISO 216 B Series + 2 SIS 014711 extensions
  2060. case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
  2061. case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
  2062. case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
  2063. case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
  2064. case 'B4' : {$pf = array( 708.661, 1000.630); break;}
  2065. case 'B5' : {$pf = array( 498.898, 708.661); break;}
  2066. case 'B6' : {$pf = array( 354.331, 498.898); break;}
  2067. case 'B7' : {$pf = array( 249.449, 354.331); break;}
  2068. case 'B8' : {$pf = array( 175.748, 249.449); break;}
  2069. case 'B9' : {$pf = array( 124.724, 175.748); break;}
  2070. case 'B10': {$pf = array( 87.874, 124.724); break;}
  2071. case 'B11': {$pf = array( 62.362, 87.874); break;}
  2072. case 'B12': {$pf = array( 42.520, 62.362); break;}
  2073. // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
  2074. case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
  2075. case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
  2076. case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
  2077. case 'C3' : {$pf = array( 918.425, 1298.268); break;}
  2078. case 'C4' : {$pf = array( 649.134, 918.425); break;}
  2079. case 'C5' : {$pf = array( 459.213, 649.134); break;}
  2080. case 'C6' : {$pf = array( 323.150, 459.213); break;}
  2081. case 'C7' : {$pf = array( 229.606, 323.150); break;}
  2082. case 'C8' : {$pf = array( 161.575, 229.606); break;}
  2083. case 'C9' : {$pf = array( 113.386, 161.575); break;}
  2084. case 'C10': {$pf = array( 79.370, 113.386); break;}
  2085. case 'C11': {$pf = array( 56.693, 79.370); break;}
  2086. case 'C12': {$pf = array( 39.685, 56.693); break;}
  2087. case 'C76': {$pf = array( 229.606, 459.213); break;}
  2088. case 'DL' : {$pf = array( 311.811, 623.622); break;}
  2089. // SIS 014711 E Series
  2090. case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
  2091. case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
  2092. case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
  2093. case 'E3' : {$pf = array( 878.740, 1247.244); break;}
  2094. case 'E4' : {$pf = array( 623.622, 878.740); break;}
  2095. case 'E5' : {$pf = array( 439.370, 623.622); break;}
  2096. case 'E6' : {$pf = array( 311.811, 439.370); break;}
  2097. case 'E7' : {$pf = array( 221.102, 311.811); break;}
  2098. case 'E8' : {$pf = array( 155.906, 221.102); break;}
  2099. case 'E9' : {$pf = array( 110.551, 155.906); break;}
  2100. case 'E10': {$pf = array( 76.535, 110.551); break;}
  2101. case 'E11': {$pf = array( 53.858, 76.535); break;}
  2102. case 'E12': {$pf = array( 36.850, 53.858); break;}
  2103. // SIS 014711 G Series
  2104. case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
  2105. case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
  2106. case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
  2107. case 'G3' : {$pf = array( 958.110, 1357.795); break;}
  2108. case 'G4' : {$pf = array( 677.480, 958.110); break;}
  2109. case 'G5' : {$pf = array( 479.055, 677.480); break;}
  2110. case 'G6' : {$pf = array( 337.323, 479.055); break;}
  2111. case 'G7' : {$pf = array( 238.110, 337.323); break;}
  2112. case 'G8' : {$pf = array( 167.244, 238.110); break;}
  2113. case 'G9' : {$pf = array( 119.055, 167.244); break;}
  2114. case 'G10': {$pf = array( 82.205, 119.055); break;}
  2115. case 'G11': {$pf = array( 59.528, 82.205); break;}
  2116. case 'G12': {$pf = array( 39.685, 59.528); break;}
  2117. // ISO Press
  2118. case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
  2119. case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
  2120. case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
  2121. case 'RA3': {$pf = array( 864.567, 1218.898); break;}
  2122. case 'RA4': {$pf = array( 609.449, 864.567); break;}
  2123. case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
  2124. case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
  2125. case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
  2126. case 'SRA3': {$pf = array( 907.087, 1275.591); break;}
  2127. case 'SRA4': {$pf = array( 637.795, 907.087); break;}
  2128. // German DIN 476
  2129. case '4A0': {$pf = array( 4767.874, 6740.787); break;}
  2130. case '2A0': {$pf = array( 3370.394, 4767.874); break;}
  2131. // Variations on the ISO Standard
  2132. case 'A2_EXTRA' : {$pf = array( 1261.417, 1754.646); break;}
  2133. case 'A3+' : {$pf = array( 932.598, 1369.134); break;}
  2134. case 'A3_EXTRA' : {$pf = array( 912.756, 1261.417); break;}
  2135. case 'A3_SUPER' : {$pf = array( 864.567, 1440.000); break;}
  2136. case 'SUPER_A3' : {$pf = array( 864.567, 1380.472); break;}
  2137. case 'A4_EXTRA' : {$pf = array( 666.142, 912.756); break;}
  2138. case 'A4_SUPER' : {$pf = array( 649.134, 912.756); break;}
  2139. case 'SUPER_A4' : {$pf = array( 643.465, 1009.134); break;}
  2140. case 'A4_LONG' : {$pf = array( 595.276, 986.457); break;}
  2141. case 'F4' : {$pf = array( 595.276, 935.433); break;}
  2142. case 'SO_B5_EXTRA': {$pf = array( 572.598, 782.362); break;}
  2143. case 'A5_EXTRA' : {$pf = array( 490.394, 666.142); break;}
  2144. // ANSI Series
  2145. case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
  2146. case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
  2147. case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
  2148. case 'ANSI_B': {$pf = array( 792.000, 1224.000); break;}
  2149. case 'ANSI_A': {$pf = array( 612.000, 792.000); break;}
  2150. // Traditional 'Loose' North American Paper Sizes
  2151. case 'USLEDGER':
  2152. case 'LEDGER' : {$pf = array( 1224.000, 792.000); break;}
  2153. case 'ORGANIZERK':
  2154. case 'BIBLE':
  2155. case 'USTABLOID':
  2156. case 'TABLOID': {$pf = array( 792.000, 1224.000); break;}
  2157. case 'ORGANIZERM':
  2158. case 'USLETTER':
  2159. case 'LETTER' : {$pf = array( 612.000, 792.000); break;}
  2160. case 'USLEGAL':
  2161. case 'LEGAL' : {$pf = array( 612.000, 1008.000); break;}
  2162. case 'GOVERNMENTLETTER':
  2163. case 'GLETTER': {$pf = array( 576.000, 756.000); break;}
  2164. case 'JUNIORLEGAL':
  2165. case 'JLEGAL' : {$pf = array( 576.000, 360.000); break;}
  2166. // Other North American Paper Sizes
  2167. case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
  2168. case 'SUPER_B': {$pf = array( 936.000, 1368.000); break;}
  2169. case 'QUARTO': {$pf = array( 648.000, 792.000); break;}
  2170. case 'GOVERNMENTLEGAL':
  2171. case 'FOLIO': {$pf = array( 612.000, 936.000); break;}
  2172. case 'MONARCH':
  2173. case 'EXECUTIVE': {$pf = array( 522.000, 756.000); break;}
  2174. case 'ORGANIZERL':
  2175. case 'STATEMENT':
  2176. case 'MEMO': {$pf = array( 396.000, 612.000); break;}
  2177. case 'FOOLSCAP': {$pf = array( 595.440, 936.000); break;}
  2178. case 'COMPACT': {$pf = array( 306.000, 486.000); break;}
  2179. case 'ORGANIZERJ': {$pf = array( 198.000, 360.000); break;}
  2180. // Canadian standard CAN 2-9.60M
  2181. case 'P1': {$pf = array( 1587.402, 2437.795); break;}
  2182. case 'P2': {$pf = array( 1218.898, 1587.402); break;}
  2183. case 'P3': {$pf = array( 793.701, 1218.898); break;}
  2184. case 'P4': {$pf = array( 609.449, 793.701); break;}
  2185. case 'P5': {$pf = array( 396.850, 609.449); break;}
  2186. case 'P6': {$pf = array( 303.307, 396.850); break;}
  2187. // North American Architectural Sizes
  2188. case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
  2189. case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
  2190. case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
  2191. case 'BROADSHEET':
  2192. case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
  2193. case 'ARCH_B' : {$pf = array( 864.000, 1296.000); break;}
  2194. case 'ARCH_A' : {$pf = array( 648.000, 864.000); break;}
  2195. // --- North American Envelope Sizes ---
  2196. // - Announcement Envelopes
  2197. case 'ANNENV_A2' : {$pf = array( 314.640, 414.000); break;}
  2198. case 'ANNENV_A6' : {$pf = array( 342.000, 468.000); break;}
  2199. case 'ANNENV_A7' : {$pf = array( 378.000, 522.000); break;}
  2200. case 'ANNENV_A8' : {$pf = array( 396.000, 584.640); break;}
  2201. case 'ANNENV_A10' : {$pf = array( 450.000, 692.640); break;}
  2202. case 'ANNENV_SLIM': {$pf = array( 278.640, 638.640); break;}
  2203. // - Commercial Envelopes
  2204. case 'COMMENV_N6_1/4': {$pf = array( 252.000, 432.000); break;}
  2205. case 'COMMENV_N6_3/4': {$pf = array( 260.640, 468.000); break;}
  2206. case 'COMMENV_N8' : {$pf = array( 278.640, 540.000); break;}
  2207. case 'COMMENV_N9' : {$pf = array( 278.640, 638.640); break;}
  2208. case 'COMMENV_N10' : {$pf = array( 296.640, 684.000); break;}
  2209. case 'COMMENV_N11' : {$pf = array( 324.000, 746.640); break;}
  2210. case 'COMMENV_N12' : {$pf = array( 342.000, 792.000); break;}
  2211. case 'COMMENV_N14' : {$pf = array( 360.000, 828.000); break;}
  2212. // - Catalogue Envelopes
  2213. case 'CATENV_N1' : {$pf = array( 432.000, 648.000); break;}
  2214. case 'CATENV_N1_3/4' : {$pf = array( 468.000, 684.000); break;}
  2215. case 'CATENV_N2' : {$pf = array( 468.000, 720.000); break;}
  2216. case 'CATENV_N3' : {$pf = array( 504.000, 720.000); break;}
  2217. case 'CATENV_N6' : {$pf = array( 540.000, 756.000); break;}
  2218. case 'CATENV_N7' : {$pf = array( 576.000, 792.000); break;}
  2219. case 'CATENV_N8' : {$pf = array( 594.000, 810.000); break;}
  2220. case 'CATENV_N9_1/2' : {$pf = array( 612.000, 756.000); break;}
  2221. case 'CATENV_N9_3/4' : {$pf = array( 630.000, 810.000); break;}
  2222. case 'CATENV_N10_1/2': {$pf = array( 648.000, 864.000); break;}
  2223. case 'CATENV_N12_1/2': {$pf = array( 684.000, 900.000); break;}
  2224. case 'CATENV_N13_1/2': {$pf = array( 720.000, 936.000); break;}
  2225. case 'CATENV_N14_1/4': {$pf = array( 810.000, 882.000); break;}
  2226. case 'CATENV_N14_1/2': {$pf = array( 828.000, 1044.000); break;}
  2227. // Japanese (JIS P 0138-61) Standard B-Series
  2228. case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
  2229. case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
  2230. case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
  2231. case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
  2232. case 'JIS_B4' : {$pf = array( 728.504, 1031.811); break;}
  2233. case 'JIS_B5' : {$pf = array( 515.906, 728.504); break;}
  2234. case 'JIS_B6' : {$pf = array( 362.835, 515.906); break;}
  2235. case 'JIS_B7' : {$pf = array( 257.953, 362.835); break;}
  2236. case 'JIS_B8' : {$pf = array( 181.417, 257.953); break;}
  2237. case 'JIS_B9' : {$pf = array( 127.559, 181.417); break;}
  2238. case 'JIS_B10': {$pf = array( 90.709, 127.559); break;}
  2239. case 'JIS_B11': {$pf = array( 62.362, 90.709); break;}
  2240. case 'JIS_B12': {$pf = array( 45.354, 62.362); break;}
  2241. // PA Series
  2242. case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
  2243. case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
  2244. case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
  2245. case 'PA3' : {$pf = array( 793.701, 1190.551); break;}
  2246. case 'PA4' : {$pf = array( 595.276, 793.701); break;}
  2247. case 'PA5' : {$pf = array( 396.850, 595.276); break;}
  2248. case 'PA6' : {$pf = array( 297.638, 396.850); break;}
  2249. case 'PA7' : {$pf = array( 198.425, 297.638); break;}
  2250. case 'PA8' : {$pf = array( 147.402, 198.425); break;}
  2251. case 'PA9' : {$pf = array( 99.213, 147.402); break;}
  2252. case 'PA10': {$pf = array( 73.701, 99.213); break;}
  2253. // Standard Photographic Print Sizes
  2254. case 'PASSPORT_PHOTO': {$pf = array( 99.213, 127.559); break;}
  2255. case 'E' : {$pf = array( 233.858, 340.157); break;}
  2256. case 'L':
  2257. case '3R' : {$pf = array( 252.283, 360.000); break;}
  2258. case 'KG':
  2259. case '4R' : {$pf = array( 289.134, 430.866); break;}
  2260. case '4D' : {$pf = array( 340.157, 430.866); break;}
  2261. case '2L':
  2262. case '5R' : {$pf = array( 360.000, 504.567); break;}
  2263. case '8P':
  2264. case '6R' : {$pf = array( 430.866, 575.433); break;}
  2265. case '6P':
  2266. case '8R' : {$pf = array( 575.433, 720.000); break;}
  2267. case '6PW':
  2268. case 'S8R' : {$pf = array( 575.433, 864.567); break;}
  2269. case '4P':
  2270. case '10R' : {$pf = array( 720.000, 864.567); break;}
  2271. case '4PW':
  2272. case 'S10R': {$pf = array( 720.000, 1080.000); break;}
  2273. case '11R' : {$pf = array( 790.866, 1009.134); break;}
  2274. case 'S11R': {$pf = array( 790.866, 1224.567); break;}
  2275. case '12R' : {$pf = array( 864.567, 1080.000); break;}
  2276. case 'S12R': {$pf = array( 864.567, 1292.598); break;}
  2277. // Common Newspaper Sizes
  2278. case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
  2279. case 'NEWSPAPER_BERLINER' : {$pf = array( 1332.283, 892.913); break;}
  2280. case 'NEWSPAPER_TABLOID':
  2281. case 'NEWSPAPER_COMPACT' : {$pf = array( 1218.898, 793.701); break;}
  2282. // Business Cards
  2283. case 'CREDIT_CARD':
  2284. case 'BUSINESS_CARD':
  2285. case 'BUSINESS_CARD_ISO7810': {$pf = array( 153.014, 242.646); break;}
  2286. case 'BUSINESS_CARD_ISO216' : {$pf = array( 147.402, 209.764); break;}
  2287. case 'BUSINESS_CARD_IT':
  2288. case 'BUSINESS_CARD_UK':
  2289. case 'BUSINESS_CARD_FR':
  2290. case 'BUSINESS_CARD_DE':
  2291. case 'BUSINESS_CARD_ES' : {$pf = array( 155.906, 240.945); break;}
  2292. case 'BUSINESS_CARD_CA':
  2293. case 'BUSINESS_CARD_US' : {$pf = array( 144.567, 252.283); break;}
  2294. case 'BUSINESS_CARD_JP' : {$pf = array( 155.906, 257.953); break;}
  2295. case 'BUSINESS_CARD_HK' : {$pf = array( 153.071, 255.118); break;}
  2296. case 'BUSINESS_CARD_AU':
  2297. case 'BUSINESS_CARD_DK':
  2298. case 'BUSINESS_CARD_SE' : {$pf = array( 155.906, 255.118); break;}
  2299. case 'BUSINESS_CARD_RU':
  2300. case 'BUSINESS_CARD_CZ':
  2301. case 'BUSINESS_CARD_FI':
  2302. case 'BUSINESS_CARD_HU':
  2303. case 'BUSINESS_CARD_IL' : {$pf = array( 141.732, 255.118); break;}
  2304. // Billboards
  2305. case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
  2306. case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
  2307. case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
  2308. case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
  2309. case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
  2310. case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
  2311. case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
  2312. case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
  2313. // Old European Sizes
  2314. // - Old Imperial English Sizes
  2315. case 'EN_EMPEROR' : {$pf = array( 3456.000, 5184.000); break;}
  2316. case 'EN_ANTIQUARIAN' : {$pf = array( 2232.000, 3816.000); break;}
  2317. case 'EN_GRAND_EAGLE' : {$pf = array( 2070.000, 3024.000); break;}
  2318. case 'EN_DOUBLE_ELEPHANT' : {$pf = array( 1926.000, 2880.000); break;}
  2319. case 'EN_ATLAS' : {$pf = array( 1872.000, 2448.000); break;}
  2320. case 'EN_COLOMBIER' : {$pf = array( 1692.000, 2484.000); break;}
  2321. case 'EN_ELEPHANT' : {$pf = array( 1656.000, 2016.000); break;}
  2322. case 'EN_DOUBLE_DEMY' : {$pf = array( 1620.000, 2556.000); break;}
  2323. case 'EN_IMPERIAL' : {$pf = array( 1584.000, 2160.000); break;}
  2324. case 'EN_PRINCESS' : {$pf = array( 1548.000, 2016.000); break;}
  2325. case 'EN_CARTRIDGE' : {$pf = array( 1512.000, 1872.000); break;}
  2326. case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
  2327. case 'EN_ROYAL' : {$pf = array( 1440.000, 1800.000); break;}
  2328. case 'EN_SHEET':
  2329. case 'EN_HALF_POST' : {$pf = array( 1404.000, 1692.000); break;}
  2330. case 'EN_SUPER_ROYAL' : {$pf = array( 1368.000, 1944.000); break;}
  2331. case 'EN_DOUBLE_POST' : {$pf = array( 1368.000, 2196.000); break;}
  2332. case 'EN_MEDIUM' : {$pf = array( 1260.000, 1656.000); break;}
  2333. case 'EN_DEMY' : {$pf = array( 1260.000, 1620.000); break;}
  2334. case 'EN_LARGE_POST' : {$pf = array( 1188.000, 1512.000); break;}
  2335. case 'EN_COPY_DRAUGHT' : {$pf = array( 1152.000, 1440.000); break;}
  2336. case 'EN_POST' : {$pf = array( 1116.000, 1386.000); break;}
  2337. case 'EN_CROWN' : {$pf = array( 1080.000, 1440.000); break;}
  2338. case 'EN_PINCHED_POST' : {$pf = array( 1062.000, 1332.000); break;}
  2339. case 'EN_BRIEF' : {$pf = array( 972.000, 1152.000); break;}
  2340. case 'EN_FOOLSCAP' : {$pf = array( 972.000, 1224.000); break;}
  2341. case 'EN_SMALL_FOOLSCAP' : {$pf = array( 954.000, 1188.000); break;}
  2342. case 'EN_POTT' : {$pf = array( 900.000, 1080.000); break;}
  2343. // - Old Imperial Belgian Sizes
  2344. case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
  2345. case 'BE_COLOMBIER' : {$pf = array( 1757.480, 2409.449); break;}
  2346. case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
  2347. case 'BE_ELEPHANT' : {$pf = array( 1746.142, 2182.677); break;}
  2348. case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
  2349. case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
  2350. case 'BE_JESUS' : {$pf = array( 1530.709, 2069.291); break;}
  2351. case 'BE_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
  2352. case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
  2353. case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
  2354. case 'BE_COQUILLE' : {$pf = array( 1218.898, 1587.402); break;}
  2355. case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
  2356. case 'BE_RUCHE' : {$pf = array( 1020.472, 1303.937); break;}
  2357. case 'BE_PROPATRIA' : {$pf = array( 977.953, 1218.898); break;}
  2358. case 'BE_LYS' : {$pf = array( 898.583, 1125.354); break;}
  2359. case 'BE_POT' : {$pf = array( 870.236, 1088.504); break;}
  2360. case 'BE_ROSETTE' : {$pf = array( 765.354, 983.622); break;}
  2361. // - Old Imperial French Sizes
  2362. case 'FR_UNIVERS' : {$pf = array( 2834.646, 3685.039); break;}
  2363. case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
  2364. case 'FR_GRANDE_MONDE' : {$pf = array( 2551.181, 3571.654); break;}
  2365. case 'FR_DOUBLE_SOLEIL' : {$pf = array( 2267.717, 3401.575); break;}
  2366. case 'FR_DOUBLE_JESUS' : {$pf = array( 2154.331, 3174.803); break;}
  2367. case 'FR_GRAND_AIGLE' : {$pf = array( 2125.984, 3004.724); break;}
  2368. case 'FR_PETIT_AIGLE' : {$pf = array( 1984.252, 2664.567); break;}
  2369. case 'FR_DOUBLE_RAISIN' : {$pf = array( 1842.520, 2834.646); break;}
  2370. case 'FR_JOURNAL' : {$pf = array( 1842.520, 2664.567); break;}
  2371. case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
  2372. case 'FR_DOUBLE_CAVALIER' : {$pf = array( 1757.480, 2607.874); break;}
  2373. case 'FR_CLOCHE' : {$pf = array( 1700.787, 2267.717); break;}
  2374. case 'FR_SOLEIL' : {$pf = array( 1700.787, 2267.717); break;}
  2375. case 'FR_DOUBLE_CARRE' : {$pf = array( 1587.402, 2551.181); break;}
  2376. case 'FR_DOUBLE_COQUILLE' : {$pf = array( 1587.402, 2494.488); break;}
  2377. case 'FR_JESUS' : {$pf = array( 1587.402, 2154.331); break;}
  2378. case 'FR_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
  2379. case 'FR_CAVALIER' : {$pf = array( 1303.937, 1757.480); break;}
  2380. case 'FR_DOUBLE_COURONNE' : {$pf = array( 1303.937, 2040.945); break;}
  2381. case 'FR_CARRE' : {$pf = array( 1275.591, 1587.402); break;}
  2382. case 'FR_COQUILLE' : {$pf = array( 1247.244, 1587.402); break;}
  2383. case 'FR_DOUBLE_TELLIERE' : {$pf = array( 1247.244, 1927.559); break;}
  2384. case 'FR_DOUBLE_CLOCHE' : {$pf = array( 1133.858, 1700.787); break;}
  2385. case 'FR_DOUBLE_POT' : {$pf = array( 1133.858, 1757.480); break;}
  2386. case 'FR_ECU' : {$pf = array( 1133.858, 1474.016); break;}
  2387. case 'FR_COURONNE' : {$pf = array( 1020.472, 1303.937); break;}
  2388. case 'FR_TELLIERE' : {$pf = array( 963.780, 1247.244); break;}
  2389. case 'FR_POT' : {$pf = array( 878.740, 1133.858); break;}
  2390. // DEFAULT ISO A4
  2391. default: {$pf = array( 595.276, 841.890); break;}
  2392. }
  2393. return $pf;
  2394. }
  2395. /**
  2396. * Change the format of the current page
  2397. * @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>
  2398. * <li>['format'] = page format name (one of the above);</li>
  2399. * <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>
  2400. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  2401. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  2402. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  2403. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  2404. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  2405. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  2406. * <li>['CropBox'] : the visible region of default user space:</li>
  2407. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  2408. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  2409. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  2410. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  2411. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  2412. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  2413. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  2414. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  2415. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  2416. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  2417. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  2418. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  2419. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  2420. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  2421. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  2422. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  2423. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  2424. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  2425. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  2426. * <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>
  2427. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  2428. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  2429. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  2430. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  2431. * <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>
  2432. * <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>
  2433. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  2434. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  2435. * <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>
  2436. * <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>
  2437. * <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>
  2438. * <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>
  2439. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  2440. * </ul>
  2441. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  2442. * <li>P or Portrait (default)</li>
  2443. * <li>L or Landscape</li>
  2444. * <li>'' (empty string) for automatic orientation</li>
  2445. * </ul>
  2446. * @protected
  2447. * @since 3.0.015 (2008-06-06)
  2448. * @see getPageSizeFromFormat()
  2449. */
  2450. protected function setPageFormat($format, $orientation='P') {
  2451. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  2452. // remove inherited values
  2453. unset($this->pagedim[$this->page]);
  2454. }
  2455. if (is_string($format)) {
  2456. // get page measures from format name
  2457. $pf = $this->getPageSizeFromFormat($format);
  2458. $this->fwPt = $pf[0];
  2459. $this->fhPt = $pf[1];
  2460. } else {
  2461. // the boundaries of the physical medium on which the page shall be displayed or printed
  2462. if (isset($format['MediaBox'])) {
  2463. $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
  2464. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  2465. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  2466. } else {
  2467. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  2468. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  2469. } else {
  2470. if (!isset($format['format'])) {
  2471. // default value
  2472. $format['format'] = 'A4';
  2473. }
  2474. $pf = $this->getPageSizeFromFormat($format['format']);
  2475. }
  2476. $this->fwPt = $pf[0];
  2477. $this->fhPt = $pf[1];
  2478. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  2479. }
  2480. // the visible region of default user space
  2481. if (isset($format['CropBox'])) {
  2482. $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
  2483. }
  2484. // the region to which the contents of the page shall be clipped when output in a production environment
  2485. if (isset($format['BleedBox'])) {
  2486. $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
  2487. }
  2488. // the intended dimensions of the finished page after trimming
  2489. if (isset($format['TrimBox'])) {
  2490. $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
  2491. }
  2492. // the page's meaningful content (including potential white space)
  2493. if (isset($format['ArtBox'])) {
  2494. $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
  2495. }
  2496. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  2497. if (isset($format['BoxColorInfo'])) {
  2498. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  2499. }
  2500. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  2501. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2502. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  2503. }
  2504. if (isset($format['PZ'])) {
  2505. // The page's preferred zoom (magnification) factor
  2506. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  2507. }
  2508. if (isset($format['trans'])) {
  2509. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  2510. if (isset($format['trans']['Dur'])) {
  2511. // The page's display duration
  2512. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  2513. }
  2514. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  2515. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  2516. // The transition style that shall be used when moving to this page from another during a presentation
  2517. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  2518. $valid_effect = array('Split', 'Blinds');
  2519. $valid_vals = array('H', 'V');
  2520. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  2521. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  2522. }
  2523. $valid_effect = array('Split', 'Box', 'Fly');
  2524. $valid_vals = array('I', 'O');
  2525. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  2526. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  2527. }
  2528. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  2529. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  2530. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  2531. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  2532. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  2533. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  2534. }
  2535. }
  2536. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  2537. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  2538. }
  2539. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  2540. $this->pagedim[$this->page]['trans']['B'] = 'true';
  2541. }
  2542. } else {
  2543. $this->pagedim[$this->page]['trans']['S'] = 'R';
  2544. }
  2545. if (isset($format['trans']['D'])) {
  2546. // The duration of the transition effect, in seconds
  2547. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  2548. } else {
  2549. $this->pagedim[$this->page]['trans']['D'] = 1;
  2550. }
  2551. }
  2552. }
  2553. $this->setPageOrientation($orientation);
  2554. }
  2555. /**
  2556. * Set page boundaries.
  2557. * @param $page (int) page number
  2558. * @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>
  2559. * @param $llx (float) lower-left x coordinate in user units
  2560. * @param $lly (float) lower-left y coordinate in user units
  2561. * @param $urx (float) upper-right x coordinate in user units
  2562. * @param $ury (float) upper-right y coordinate in user units
  2563. * @param $points (boolean) if true uses user units as unit of measure, otherwise uses PDF points
  2564. * @public
  2565. * @since 5.0.010 (2010-05-17)
  2566. */
  2567. public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false) {
  2568. if (!isset($this->pagedim[$page])) {
  2569. // initialize array
  2570. $this->pagedim[$page] = array();
  2571. }
  2572. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  2573. if (!in_array($type, $pageboxes)) {
  2574. return;
  2575. }
  2576. if ($points) {
  2577. $k = 1;
  2578. } else {
  2579. $k = $this->k;
  2580. }
  2581. $this->pagedim[$page][$type]['llx'] = ($llx * $k);
  2582. $this->pagedim[$page][$type]['lly'] = ($lly * $k);
  2583. $this->pagedim[$page][$type]['urx'] = ($urx * $k);
  2584. $this->pagedim[$page][$type]['ury'] = ($ury * $k);
  2585. }
  2586. /**
  2587. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  2588. * @param $page (int) page number
  2589. * @protected
  2590. * @since 5.0.010 (2010-05-17)
  2591. */
  2592. protected function swapPageBoxCoordinates($page) {
  2593. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  2594. foreach ($pageboxes as $type) {
  2595. // swap X and Y coordinates
  2596. if (isset($this->pagedim[$page][$type])) {
  2597. $tmp = $this->pagedim[$page][$type]['llx'];
  2598. $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly'];
  2599. $this->pagedim[$page][$type]['lly'] = $tmp;
  2600. $tmp = $this->pagedim[$page][$type]['urx'];
  2601. $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury'];
  2602. $this->pagedim[$page][$type]['ury'] = $tmp;
  2603. }
  2604. }
  2605. }
  2606. /**
  2607. * Set page orientation.
  2608. * @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>
  2609. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  2610. * @param $bottommargin (float) bottom margin of the page.
  2611. * @public
  2612. * @since 3.0.015 (2008-06-06)
  2613. */
  2614. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  2615. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  2616. // the boundaries of the physical medium on which the page shall be displayed or printed
  2617. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  2618. }
  2619. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  2620. // the visible region of default user space
  2621. $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);
  2622. }
  2623. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  2624. // the region to which the contents of the page shall be clipped when output in a production environment
  2625. $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);
  2626. }
  2627. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  2628. // the intended dimensions of the finished page after trimming
  2629. $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);
  2630. }
  2631. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  2632. // the page's meaningful content (including potential white space)
  2633. $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);
  2634. }
  2635. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  2636. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2637. $this->pagedim[$this->page]['Rotate'] = 0;
  2638. }
  2639. if (!isset($this->pagedim[$this->page]['PZ'])) {
  2640. // The page's preferred zoom (magnification) factor
  2641. $this->pagedim[$this->page]['PZ'] = 1;
  2642. }
  2643. if ($this->fwPt > $this->fhPt) {
  2644. // landscape
  2645. $default_orientation = 'L';
  2646. } else {
  2647. // portrait
  2648. $default_orientation = 'P';
  2649. }
  2650. $valid_orientations = array('P', 'L');
  2651. if (empty($orientation)) {
  2652. $orientation = $default_orientation;
  2653. } else {
  2654. $orientation = strtoupper($orientation{0});
  2655. }
  2656. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  2657. $this->CurOrientation = $orientation;
  2658. $this->wPt = $this->fhPt;
  2659. $this->hPt = $this->fwPt;
  2660. } else {
  2661. $this->CurOrientation = $default_orientation;
  2662. $this->wPt = $this->fwPt;
  2663. $this->hPt = $this->fhPt;
  2664. }
  2665. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2666. // swap X and Y coordinates (change page orientation)
  2667. $this->swapPageBoxCoordinates($this->page);
  2668. }
  2669. $this->w = $this->wPt / $this->k;
  2670. $this->h = $this->hPt / $this->k;
  2671. if ($this->empty_string($autopagebreak)) {
  2672. if (isset($this->AutoPageBreak)) {
  2673. $autopagebreak = $this->AutoPageBreak;
  2674. } else {
  2675. $autopagebreak = true;
  2676. }
  2677. }
  2678. if ($this->empty_string($bottommargin)) {
  2679. if (isset($this->bMargin)) {
  2680. $bottommargin = $this->bMargin;
  2681. } else {
  2682. // default value = 2 cm
  2683. $bottommargin = 2 * 28.35 / $this->k;
  2684. }
  2685. }
  2686. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  2687. // store page dimensions
  2688. $this->pagedim[$this->page]['w'] = $this->wPt;
  2689. $this->pagedim[$this->page]['h'] = $this->hPt;
  2690. $this->pagedim[$this->page]['wk'] = $this->w;
  2691. $this->pagedim[$this->page]['hk'] = $this->h;
  2692. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2693. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2694. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2695. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2696. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2697. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2698. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2699. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2700. }
  2701. /**
  2702. * Set regular expression to detect withespaces or word separators.
  2703. * The pattern delimiter must be the forward-slash character "/".
  2704. * Some example patterns are:
  2705. * <pre>
  2706. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2707. * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
  2708. * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
  2709. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2710. * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
  2711. * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  2712. * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
  2713. * </pre>
  2714. * @param $re (string) regular expression (leave empty for default).
  2715. * @public
  2716. * @since 4.6.016 (2009-06-15)
  2717. */
  2718. public function setSpacesRE($re='/[^\S\xa0]/') {
  2719. $this->re_spaces = $re;
  2720. $re_parts = explode('/', $re);
  2721. // get pattern parts
  2722. $this->re_space = array();
  2723. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2724. $this->re_space['p'] = $re_parts[1];
  2725. } else {
  2726. $this->re_space['p'] = '[\s]';
  2727. }
  2728. // set pattern modifiers
  2729. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2730. $this->re_space['m'] = $re_parts[2];
  2731. } else {
  2732. $this->re_space['m'] = '';
  2733. }
  2734. }
  2735. /**
  2736. * Enable or disable Right-To-Left language mode
  2737. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  2738. * @param $resetx (Boolean) if true reset the X position on direction change.
  2739. * @public
  2740. * @since 2.0.000 (2008-01-03)
  2741. */
  2742. public function setRTL($enable, $resetx=true) {
  2743. $enable = $enable ? true : false;
  2744. $resetx = ($resetx AND ($enable != $this->rtl));
  2745. $this->rtl = $enable;
  2746. $this->tmprtl = false;
  2747. if ($resetx) {
  2748. $this->Ln(0);
  2749. }
  2750. }
  2751. /**
  2752. * Return the RTL status
  2753. * @return boolean
  2754. * @public
  2755. * @since 4.0.012 (2008-07-24)
  2756. */
  2757. public function getRTL() {
  2758. return $this->rtl;
  2759. }
  2760. /**
  2761. * Force temporary RTL language direction
  2762. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  2763. * @public
  2764. * @since 2.1.000 (2008-01-09)
  2765. */
  2766. public function setTempRTL($mode) {
  2767. $newmode = false;
  2768. switch (strtoupper($mode)) {
  2769. case 'LTR':
  2770. case 'L': {
  2771. if ($this->rtl) {
  2772. $newmode = 'L';
  2773. }
  2774. break;
  2775. }
  2776. case 'RTL':
  2777. case 'R': {
  2778. if (!$this->rtl) {
  2779. $newmode = 'R';
  2780. }
  2781. break;
  2782. }
  2783. case false:
  2784. default: {
  2785. $newmode = false;
  2786. break;
  2787. }
  2788. }
  2789. $this->tmprtl = $newmode;
  2790. }
  2791. /**
  2792. * Return the current temporary RTL status
  2793. * @return boolean
  2794. * @public
  2795. * @since 4.8.014 (2009-11-04)
  2796. */
  2797. public function isRTLTextDir() {
  2798. return ($this->rtl OR ($this->tmprtl == 'R'));
  2799. }
  2800. /**
  2801. * Set the last cell height.
  2802. * @param $h (float) cell height.
  2803. * @author Nicola Asuni
  2804. * @public
  2805. * @since 1.53.0.TC034
  2806. */
  2807. public function setLastH($h) {
  2808. $this->lasth = $h;
  2809. }
  2810. /**
  2811. * Reset the last cell height.
  2812. * @public
  2813. * @since 5.9.000 (2010-10-03)
  2814. */
  2815. public function resetLastH() {
  2816. $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  2817. }
  2818. /**
  2819. * Get the last cell height.
  2820. * @return last cell height
  2821. * @public
  2822. * @since 4.0.017 (2008-08-05)
  2823. */
  2824. public function getLastH() {
  2825. return $this->lasth;
  2826. }
  2827. /**
  2828. * Set the adjusting factor to convert pixels to user units.
  2829. * @param $scale (float) adjusting factor to convert pixels to user units.
  2830. * @author Nicola Asuni
  2831. * @public
  2832. * @since 1.5.2
  2833. */
  2834. public function setImageScale($scale) {
  2835. $this->imgscale = $scale;
  2836. }
  2837. /**
  2838. * Returns the adjusting factor to convert pixels to user units.
  2839. * @return float adjusting factor to convert pixels to user units.
  2840. * @author Nicola Asuni
  2841. * @public
  2842. * @since 1.5.2
  2843. */
  2844. public function getImageScale() {
  2845. return $this->imgscale;
  2846. }
  2847. /**
  2848. * Returns an array of page dimensions:
  2849. * <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>
  2850. * @param $pagenum (int) page number (empty = current page)
  2851. * @return array of page dimensions.
  2852. * @author Nicola Asuni
  2853. * @public
  2854. * @since 4.5.027 (2009-03-16)
  2855. */
  2856. public function getPageDimensions($pagenum='') {
  2857. if (empty($pagenum)) {
  2858. $pagenum = $this->page;
  2859. }
  2860. return $this->pagedim[$pagenum];
  2861. }
  2862. /**
  2863. * Returns the page width in units.
  2864. * @param $pagenum (int) page number (empty = current page)
  2865. * @return int page width.
  2866. * @author Nicola Asuni
  2867. * @public
  2868. * @since 1.5.2
  2869. * @see getPageDimensions()
  2870. */
  2871. public function getPageWidth($pagenum='') {
  2872. if (empty($pagenum)) {
  2873. return $this->w;
  2874. }
  2875. return $this->pagedim[$pagenum]['w'];
  2876. }
  2877. /**
  2878. * Returns the page height in units.
  2879. * @param $pagenum (int) page number (empty = current page)
  2880. * @return int page height.
  2881. * @author Nicola Asuni
  2882. * @public
  2883. * @since 1.5.2
  2884. * @see getPageDimensions()
  2885. */
  2886. public function getPageHeight($pagenum='') {
  2887. if (empty($pagenum)) {
  2888. return $this->h;
  2889. }
  2890. return $this->pagedim[$pagenum]['h'];
  2891. }
  2892. /**
  2893. * Returns the page break margin.
  2894. * @param $pagenum (int) page number (empty = current page)
  2895. * @return int page break margin.
  2896. * @author Nicola Asuni
  2897. * @public
  2898. * @since 1.5.2
  2899. * @see getPageDimensions()
  2900. */
  2901. public function getBreakMargin($pagenum='') {
  2902. if (empty($pagenum)) {
  2903. return $this->bMargin;
  2904. }
  2905. return $this->pagedim[$pagenum]['bm'];
  2906. }
  2907. /**
  2908. * Returns the scale factor (number of points in user unit).
  2909. * @return int scale factor.
  2910. * @author Nicola Asuni
  2911. * @public
  2912. * @since 1.5.2
  2913. */
  2914. public function getScaleFactor() {
  2915. return $this->k;
  2916. }
  2917. /**
  2918. * Defines the left, top and right margins.
  2919. * @param $left (float) Left margin.
  2920. * @param $top (float) Top margin.
  2921. * @param $right (float) Right margin. Default value is the left one.
  2922. * @param $keepmargins (boolean) if true overwrites the default page margins
  2923. * @public
  2924. * @since 1.0
  2925. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2926. */
  2927. public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
  2928. //Set left, top and right margins
  2929. $this->lMargin = $left;
  2930. $this->tMargin = $top;
  2931. if ($right == -1) {
  2932. $right = $left;
  2933. }
  2934. $this->rMargin = $right;
  2935. if ($keepmargins) {
  2936. // overwrite original values
  2937. $this->original_lMargin = $this->lMargin;
  2938. $this->original_rMargin = $this->rMargin;
  2939. }
  2940. }
  2941. /**
  2942. * 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.
  2943. * @param $margin (float) The margin.
  2944. * @public
  2945. * @since 1.4
  2946. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2947. */
  2948. public function SetLeftMargin($margin) {
  2949. //Set left margin
  2950. $this->lMargin = $margin;
  2951. if (($this->page > 0) AND ($this->x < $margin)) {
  2952. $this->x = $margin;
  2953. }
  2954. }
  2955. /**
  2956. * Defines the top margin. The method can be called before creating the first page.
  2957. * @param $margin (float) The margin.
  2958. * @public
  2959. * @since 1.5
  2960. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2961. */
  2962. public function SetTopMargin($margin) {
  2963. //Set top margin
  2964. $this->tMargin = $margin;
  2965. if (($this->page > 0) AND ($this->y < $margin)) {
  2966. $this->y = $margin;
  2967. }
  2968. }
  2969. /**
  2970. * Defines the right margin. The method can be called before creating the first page.
  2971. * @param $margin (float) The margin.
  2972. * @public
  2973. * @since 1.5
  2974. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2975. */
  2976. public function SetRightMargin($margin) {
  2977. $this->rMargin = $margin;
  2978. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2979. $this->x = $this->w - $margin;
  2980. }
  2981. }
  2982. /**
  2983. * Set the same internal Cell padding for top, right, bottom, left-
  2984. * @param $pad (float) internal padding.
  2985. * @public
  2986. * @since 2.1.000 (2008-01-09)
  2987. * @see getCellPaddings(), setCellPaddings()
  2988. */
  2989. public function SetCellPadding($pad) {
  2990. if ($pad >= 0) {
  2991. $this->cell_padding['L'] = $pad;
  2992. $this->cell_padding['T'] = $pad;
  2993. $this->cell_padding['R'] = $pad;
  2994. $this->cell_padding['B'] = $pad;
  2995. }
  2996. }
  2997. /**
  2998. * Set the internal Cell paddings.
  2999. * @param $left (float) left padding
  3000. * @param $top (float) top padding
  3001. * @param $right (float) right padding
  3002. * @param $bottom (float) bottom padding
  3003. * @public
  3004. * @since 5.9.000 (2010-10-03)
  3005. * @see getCellPaddings(), SetCellPadding()
  3006. */
  3007. public function setCellPaddings($left='', $top='', $right='', $bottom='') {
  3008. if (($left !== '') AND ($left >= 0)) {
  3009. $this->cell_padding['L'] = $left;
  3010. }
  3011. if (($top !== '') AND ($top >= 0)) {
  3012. $this->cell_padding['T'] = $top;
  3013. }
  3014. if (($right !== '') AND ($right >= 0)) {
  3015. $this->cell_padding['R'] = $right;
  3016. }
  3017. if (($bottom !== '') AND ($bottom >= 0)) {
  3018. $this->cell_padding['B'] = $bottom;
  3019. }
  3020. }
  3021. /**
  3022. * Get the internal Cell padding array.
  3023. * @return array of padding values
  3024. * @public
  3025. * @since 5.9.000 (2010-10-03)
  3026. * @see setCellPaddings(), SetCellPadding()
  3027. */
  3028. public function getCellPaddings() {
  3029. return $this->cell_padding;
  3030. }
  3031. /**
  3032. * Set the internal Cell margins.
  3033. * @param $left (float) left margin
  3034. * @param $top (float) top margin
  3035. * @param $right (float) right margin
  3036. * @param $bottom (float) bottom margin
  3037. * @public
  3038. * @since 5.9.000 (2010-10-03)
  3039. * @see getCellMargins()
  3040. */
  3041. public function setCellMargins($left='', $top='', $right='', $bottom='') {
  3042. if (($left !== '') AND ($left >= 0)) {
  3043. $this->cell_margin['L'] = $left;
  3044. }
  3045. if (($top !== '') AND ($top >= 0)) {
  3046. $this->cell_margin['T'] = $top;
  3047. }
  3048. if (($right !== '') AND ($right >= 0)) {
  3049. $this->cell_margin['R'] = $right;
  3050. }
  3051. if (($bottom !== '') AND ($bottom >= 0)) {
  3052. $this->cell_margin['B'] = $bottom;
  3053. }
  3054. }
  3055. /**
  3056. * Get the internal Cell margin array.
  3057. * @return array of margin values
  3058. * @public
  3059. * @since 5.9.000 (2010-10-03)
  3060. * @see setCellMargins()
  3061. */
  3062. public function getCellMargins() {
  3063. return $this->cell_margin;
  3064. }
  3065. /**
  3066. * Adjust the internal Cell padding array to take account of the line width.
  3067. * @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)))
  3068. * @return array of adjustments
  3069. * @public
  3070. * @since 5.9.000 (2010-10-03)
  3071. */
  3072. protected function adjustCellPadding($brd=0) {
  3073. if (empty($brd)) {
  3074. return;
  3075. }
  3076. if (is_string($brd)) {
  3077. // convert string to array
  3078. $slen = strlen($brd);
  3079. $newbrd = array();
  3080. for ($i = 0; $i < $slen; ++$i) {
  3081. $newbrd[$brd{$i}] = true;
  3082. }
  3083. $brd = $newbrd;
  3084. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  3085. $brd = array('LRTB' => true);
  3086. }
  3087. if (!is_array($brd)) {
  3088. return;
  3089. }
  3090. // store current cell padding
  3091. $cp = $this->cell_padding;
  3092. // select border mode
  3093. if (isset($brd['mode'])) {
  3094. $mode = $brd['mode'];
  3095. unset($brd['mode']);
  3096. } else {
  3097. $mode = 'normal';
  3098. }
  3099. // process borders
  3100. foreach ($brd as $border => $style) {
  3101. $line_width = $this->LineWidth;
  3102. if (is_array($style) AND isset($style['width'])) {
  3103. // get border width
  3104. $line_width = $style['width'];
  3105. }
  3106. $adj = 0; // line width inside the cell
  3107. switch ($mode) {
  3108. case 'ext': {
  3109. $adj = 0;
  3110. break;
  3111. }
  3112. case 'int': {
  3113. $adj = $line_width;
  3114. break;
  3115. }
  3116. case 'normal':
  3117. default: {
  3118. $adj = ($line_width / 2);
  3119. break;
  3120. }
  3121. }
  3122. // correct internal cell padding if required to avoid overlap between text and lines
  3123. if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  3124. $this->cell_padding['T'] = $adj;
  3125. }
  3126. if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  3127. $this->cell_padding['R'] = $adj;
  3128. }
  3129. if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  3130. $this->cell_padding['B'] = $adj;
  3131. }
  3132. if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  3133. $this->cell_padding['L'] = $adj;
  3134. }
  3135. }
  3136. 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']));
  3137. }
  3138. /**
  3139. * 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.
  3140. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  3141. * @param $margin (float) Distance from the bottom of the page.
  3142. * @public
  3143. * @since 1.0
  3144. * @see Cell(), MultiCell(), AcceptPageBreak()
  3145. */
  3146. public function SetAutoPageBreak($auto, $margin=0) {
  3147. $this->AutoPageBreak = $auto;
  3148. $this->bMargin = $margin;
  3149. $this->PageBreakTrigger = $this->h - $margin;
  3150. }
  3151. /**
  3152. * Defines the way the document is to be displayed by the viewer.
  3153. * @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>
  3154. * @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>
  3155. * @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>
  3156. * @public
  3157. * @since 1.2
  3158. */
  3159. public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  3160. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  3161. $this->ZoomMode = $zoom;
  3162. } else {
  3163. $this->Error('Incorrect zoom display mode: '.$zoom);
  3164. }
  3165. switch ($layout) {
  3166. case 'default':
  3167. case 'single':
  3168. case 'SinglePage': {
  3169. $this->LayoutMode = 'SinglePage';
  3170. break;
  3171. }
  3172. case 'continuous':
  3173. case 'OneColumn': {
  3174. $this->LayoutMode = 'OneColumn';
  3175. break;
  3176. }
  3177. case 'two':
  3178. case 'TwoColumnLeft': {
  3179. $this->LayoutMode = 'TwoColumnLeft';
  3180. break;
  3181. }
  3182. case 'TwoColumnRight': {
  3183. $this->LayoutMode = 'TwoColumnRight';
  3184. break;
  3185. }
  3186. case 'TwoPageLeft': {
  3187. $this->LayoutMode = 'TwoPageLeft';
  3188. break;
  3189. }
  3190. case 'TwoPageRight': {
  3191. $this->LayoutMode = 'TwoPageRight';
  3192. break;
  3193. }
  3194. default: {
  3195. $this->LayoutMode = 'SinglePage';
  3196. }
  3197. }
  3198. switch ($mode) {
  3199. case 'UseNone': {
  3200. $this->PageMode = 'UseNone';
  3201. break;
  3202. }
  3203. case 'UseOutlines': {
  3204. $this->PageMode = 'UseOutlines';
  3205. break;
  3206. }
  3207. case 'UseThumbs': {
  3208. $this->PageMode = 'UseThumbs';
  3209. break;
  3210. }
  3211. case 'FullScreen': {
  3212. $this->PageMode = 'FullScreen';
  3213. break;
  3214. }
  3215. case 'UseOC': {
  3216. $this->PageMode = 'UseOC';
  3217. break;
  3218. }
  3219. case '': {
  3220. $this->PageMode = 'UseAttachments';
  3221. break;
  3222. }
  3223. default: {
  3224. $this->PageMode = 'UseNone';
  3225. }
  3226. }
  3227. }
  3228. /**
  3229. * 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.
  3230. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  3231. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  3232. * @public
  3233. * @since 1.4
  3234. */
  3235. public function SetCompression($compress) {
  3236. if (function_exists('gzcompress')) {
  3237. $this->compress = $compress ? true : false;
  3238. } else {
  3239. $this->compress = false;
  3240. }
  3241. }
  3242. /**
  3243. * Turn on/off Unicode mode for document information dictionary (meta tags).
  3244. * This has effect only when unicode mode is set to false.
  3245. * @param $unicode (boolean) if true set the meta information in Unicode
  3246. * @since 5.9.027 (2010-12-01)
  3247. * @public
  3248. */
  3249. public function SetDocInfoUnicode($unicode=true) {
  3250. $this->docinfounicode = $unicode ? true : false;
  3251. }
  3252. /**
  3253. * Defines the title of the document.
  3254. * @param $title (string) The title.
  3255. * @public
  3256. * @since 1.2
  3257. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  3258. */
  3259. public function SetTitle($title) {
  3260. $this->title = $title;
  3261. }
  3262. /**
  3263. * Defines the subject of the document.
  3264. * @param $subject (string) The subject.
  3265. * @public
  3266. * @since 1.2
  3267. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  3268. */
  3269. public function SetSubject($subject) {
  3270. $this->subject = $subject;
  3271. }
  3272. /**
  3273. * Defines the author of the document.
  3274. * @param $author (string) The name of the author.
  3275. * @public
  3276. * @since 1.2
  3277. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  3278. */
  3279. public function SetAuthor($author) {
  3280. $this->author = $author;
  3281. }
  3282. /**
  3283. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  3284. * @param $keywords (string) The list of keywords.
  3285. * @public
  3286. * @since 1.2
  3287. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  3288. */
  3289. public function SetKeywords($keywords) {
  3290. $this->keywords = $keywords;
  3291. }
  3292. /**
  3293. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  3294. * @param $creator (string) The name of the creator.
  3295. * @public
  3296. * @since 1.2
  3297. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  3298. */
  3299. public function SetCreator($creator) {
  3300. $this->creator = $creator;
  3301. }
  3302. /**
  3303. * 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.
  3304. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  3305. * @param $msg (string) The error message
  3306. * @public
  3307. * @since 1.0
  3308. */
  3309. public function Error($msg) {
  3310. // unset all class variables
  3311. $this->_destroy(true);
  3312. // exit program and print error
  3313. die('<strong>TCPDF ERROR: </strong>'.$msg);
  3314. }
  3315. /**
  3316. * This method begins the generation of the PDF document.
  3317. * It is not necessary to call it explicitly because AddPage() does it automatically.
  3318. * Note: no page is created by this method
  3319. * @public
  3320. * @since 1.0
  3321. * @see AddPage(), Close()
  3322. */
  3323. public function Open() {
  3324. $this->state = 1;
  3325. }
  3326. /**
  3327. * Terminates the PDF document.
  3328. * It is not necessary to call this method explicitly because Output() does it automatically.
  3329. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  3330. * @public
  3331. * @since 1.0
  3332. * @see Open(), Output()
  3333. */
  3334. public function Close() {
  3335. if ($this->state == 3) {
  3336. return;
  3337. }
  3338. if ($this->page == 0) {
  3339. $this->AddPage();
  3340. }
  3341. // save current graphic settings
  3342. $gvars = $this->getGraphicVars();
  3343. $this->setEqualColumns();
  3344. $this->lastpage(true);
  3345. $this->SetAutoPageBreak(false);
  3346. $this->x = 0;
  3347. $this->y = $this->h - (1 / $this->k);
  3348. $this->lMargin = 0;
  3349. $this->_out('q');
  3350. $this->SetFont('helvetica', '', 1);
  3351. $this->setTextRenderingMode(0, false, false);
  3352. $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";
  3353. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  3354. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  3355. $this->_out('Q');
  3356. // restore graphic settings
  3357. $this->setGraphicVars($gvars);
  3358. // close page
  3359. $this->endPage();
  3360. // close document
  3361. $this->_enddoc();
  3362. // unset all class variables (except critical ones)
  3363. $this->_destroy(false);
  3364. }
  3365. /**
  3366. * Move pointer at the specified document page and update page dimensions.
  3367. * @param $pnum (int) page number (1 ... numpages)
  3368. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  3369. * @public
  3370. * @since 2.1.000 (2008-01-07)
  3371. * @see getPage(), lastpage(), getNumPages()
  3372. */
  3373. public function setPage($pnum, $resetmargins=false) {
  3374. if (($pnum == $this->page) AND ($this->state == 2)) {
  3375. return;
  3376. }
  3377. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  3378. $this->state = 2;
  3379. // save current graphic settings
  3380. //$gvars = $this->getGraphicVars();
  3381. $oldpage = $this->page;
  3382. $this->page = $pnum;
  3383. $this->wPt = $this->pagedim[$this->page]['w'];
  3384. $this->hPt = $this->pagedim[$this->page]['h'];
  3385. $this->w = $this->pagedim[$this->page]['wk'];
  3386. $this->h = $this->pagedim[$this->page]['hk'];
  3387. $this->tMargin = $this->pagedim[$this->page]['tm'];
  3388. $this->bMargin = $this->pagedim[$this->page]['bm'];
  3389. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  3390. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  3391. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  3392. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  3393. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  3394. // restore graphic settings
  3395. //$this->setGraphicVars($gvars);
  3396. if ($resetmargins) {
  3397. $this->lMargin = $this->pagedim[$this->page]['olm'];
  3398. $this->rMargin = $this->pagedim[$this->page]['orm'];
  3399. $this->SetY($this->tMargin);
  3400. } else {
  3401. // account for booklet mode
  3402. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  3403. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  3404. $this->lMargin += $deltam;
  3405. $this->rMargin -= $deltam;
  3406. }
  3407. }
  3408. } else {
  3409. $this->Error('Wrong page number on setPage() function: '.$pnum);
  3410. }
  3411. }
  3412. /**
  3413. * Reset pointer to the last document page.
  3414. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  3415. * @public
  3416. * @since 2.0.000 (2008-01-04)
  3417. * @see setPage(), getPage(), getNumPages()
  3418. */
  3419. public function lastPage($resetmargins=false) {
  3420. $this->setPage($this->getNumPages(), $resetmargins);
  3421. }
  3422. /**
  3423. * Get current document page number.
  3424. * @return int page number
  3425. * @public
  3426. * @since 2.1.000 (2008-01-07)
  3427. * @see setPage(), lastpage(), getNumPages()
  3428. */
  3429. public function getPage() {
  3430. return $this->page;
  3431. }
  3432. /**
  3433. * Get the total number of insered pages.
  3434. * @return int number of pages
  3435. * @public
  3436. * @since 2.1.000 (2008-01-07)
  3437. * @see setPage(), getPage(), lastpage()
  3438. */
  3439. public function getNumPages() {
  3440. return $this->numpages;
  3441. }
  3442. /**
  3443. * Adds a new TOC (Table Of Content) page to the document.
  3444. * @param $orientation (string) page orientation.
  3445. * @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().
  3446. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  3447. * @public
  3448. * @since 5.0.001 (2010-05-06)
  3449. * @see AddPage(), startPage(), endPage(), endTOCPage()
  3450. */
  3451. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  3452. $this->AddPage($orientation, $format, $keepmargins, true);
  3453. }
  3454. /**
  3455. * Terminate the current TOC (Table Of Content) page
  3456. * @public
  3457. * @since 5.0.001 (2010-05-06)
  3458. * @see AddPage(), startPage(), endPage(), addTOCPage()
  3459. */
  3460. public function endTOCPage() {
  3461. $this->endPage(true);
  3462. }
  3463. /**
  3464. * 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).
  3465. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  3466. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  3467. * @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().
  3468. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  3469. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  3470. * @public
  3471. * @since 1.0
  3472. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  3473. */
  3474. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  3475. if ($this->inxobj) {
  3476. // we are inside an XObject template
  3477. return;
  3478. }
  3479. if (!isset($this->original_lMargin) OR $keepmargins) {
  3480. $this->original_lMargin = $this->lMargin;
  3481. }
  3482. if (!isset($this->original_rMargin) OR $keepmargins) {
  3483. $this->original_rMargin = $this->rMargin;
  3484. }
  3485. // terminate previous page
  3486. $this->endPage();
  3487. // start new page
  3488. $this->startPage($orientation, $format, $tocpage);
  3489. }
  3490. /**
  3491. * Terminate the current page
  3492. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  3493. * @public
  3494. * @since 4.2.010 (2008-11-14)
  3495. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  3496. */
  3497. public function endPage($tocpage=false) {
  3498. // check if page is already closed
  3499. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  3500. return;
  3501. }
  3502. $this->InFooter = true;
  3503. // print page footer
  3504. $this->setFooter();
  3505. // close page
  3506. $this->_endpage();
  3507. // mark page as closed
  3508. $this->pageopen[$this->page] = false;
  3509. $this->InFooter = false;
  3510. if ($tocpage) {
  3511. $this->tocpage = false;
  3512. }
  3513. }
  3514. /**
  3515. * Starts a new page to the document. The page must be closed using the endPage() function.
  3516. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  3517. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  3518. * @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().
  3519. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  3520. * @since 4.2.010 (2008-11-14)
  3521. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  3522. * @public
  3523. */
  3524. public function startPage($orientation='', $format='', $tocpage=false) {
  3525. if ($tocpage) {
  3526. $this->tocpage = true;
  3527. }
  3528. if ($this->numpages > $this->page) {
  3529. // this page has been already added
  3530. $this->setPage($this->page + 1);
  3531. $this->SetY($this->tMargin);
  3532. return;
  3533. }
  3534. // start a new page
  3535. if ($this->state == 0) {
  3536. $this->Open();
  3537. }
  3538. ++$this->numpages;
  3539. $this->swapMargins($this->booklet);
  3540. // save current graphic settings
  3541. $gvars = $this->getGraphicVars();
  3542. // start new page
  3543. $this->_beginpage($orientation, $format);
  3544. // mark page as open
  3545. $this->pageopen[$this->page] = true;
  3546. // restore graphic settings
  3547. $this->setGraphicVars($gvars);
  3548. // mark this point
  3549. $this->setPageMark();
  3550. // print page header
  3551. $this->setHeader();
  3552. // restore graphic settings
  3553. $this->setGraphicVars($gvars);
  3554. // mark this point
  3555. $this->setPageMark();
  3556. // print table header (if any)
  3557. $this->setTableHeader();
  3558. // set mark for empty page check
  3559. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  3560. }
  3561. /**
  3562. * Set start-writing mark on current page stream used to put borders and fills.
  3563. * Borders and fills are always created after content and inserted on the position marked by this method.
  3564. * This function must be called after calling Image() function for a background image.
  3565. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  3566. * @public
  3567. * @since 4.0.016 (2008-07-30)
  3568. */
  3569. public function setPageMark() {
  3570. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  3571. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  3572. $this->setContentMark();
  3573. }
  3574. /**
  3575. * Set start-writing mark on selected page.
  3576. * Borders and fills are always created after content and inserted on the position marked by this method.
  3577. * @param $page (int) page number (default is the current page)
  3578. * @protected
  3579. * @since 4.6.021 (2009-07-20)
  3580. */
  3581. protected function setContentMark($page=0) {
  3582. if ($page <= 0) {
  3583. $page = $this->page;
  3584. }
  3585. if (isset($this->footerlen[$page])) {
  3586. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  3587. } else {
  3588. $this->cntmrk[$page] = $this->pagelen[$page];
  3589. }
  3590. }
  3591. /**
  3592. * Set header data.
  3593. * @param $ln (string) header image logo
  3594. * @param $lw (string) header image logo width in mm
  3595. * @param $ht (string) string to print as title on document header
  3596. * @param $hs (string) string to print on document header
  3597. * @public
  3598. */
  3599. public function setHeaderData($ln='', $lw=0, $ht='', $hs='') {
  3600. $this->header_logo = $ln;
  3601. $this->header_logo_width = $lw;
  3602. $this->header_title = $ht;
  3603. $this->header_string = $hs;
  3604. }
  3605. /**
  3606. * Returns header data:
  3607. * <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>
  3608. * @return array()
  3609. * @public
  3610. * @since 4.0.012 (2008-07-24)
  3611. */
  3612. public function getHeaderData() {
  3613. $ret = array();
  3614. $ret['logo'] = $this->header_logo;
  3615. $ret['logo_width'] = $this->header_logo_width;
  3616. $ret['title'] = $this->header_title;
  3617. $ret['string'] = $this->header_string;
  3618. return $ret;
  3619. }
  3620. /**
  3621. * Set header margin.
  3622. * (minimum distance between header and top page margin)
  3623. * @param $hm (int) distance in user units
  3624. * @public
  3625. */
  3626. public function setHeaderMargin($hm=10) {
  3627. $this->header_margin = $hm;
  3628. }
  3629. /**
  3630. * Returns header margin in user units.
  3631. * @return float
  3632. * @since 4.0.012 (2008-07-24)
  3633. * @public
  3634. */
  3635. public function getHeaderMargin() {
  3636. return $this->header_margin;
  3637. }
  3638. /**
  3639. * Set footer margin.
  3640. * (minimum distance between footer and bottom page margin)
  3641. * @param $fm (int) distance in user units
  3642. * @public
  3643. */
  3644. public function setFooterMargin($fm=10) {
  3645. $this->footer_margin = $fm;
  3646. }
  3647. /**
  3648. * Returns footer margin in user units.
  3649. * @return float
  3650. * @since 4.0.012 (2008-07-24)
  3651. * @public
  3652. */
  3653. public function getFooterMargin() {
  3654. return $this->footer_margin;
  3655. }
  3656. /**
  3657. * Set a flag to print page header.
  3658. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  3659. * @public
  3660. */
  3661. public function setPrintHeader($val=true) {
  3662. $this->print_header = $val;
  3663. }
  3664. /**
  3665. * Set a flag to print page footer.
  3666. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  3667. * @public
  3668. */
  3669. public function setPrintFooter($val=true) {
  3670. $this->print_footer = $val;
  3671. }
  3672. /**
  3673. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3674. * @return float
  3675. * @public
  3676. */
  3677. public function getImageRBX() {
  3678. return $this->img_rb_x;
  3679. }
  3680. /**
  3681. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3682. * @return float
  3683. * @public
  3684. */
  3685. public function getImageRBY() {
  3686. return $this->img_rb_y;
  3687. }
  3688. /**
  3689. * This method is used to render the page header.
  3690. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3691. * @public
  3692. */
  3693. public function Header() {
  3694. $ormargins = $this->getOriginalMargins();
  3695. $headerfont = $this->getHeaderFont();
  3696. $headerdata = $this->getHeaderData();
  3697. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3698. $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3699. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3700. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3701. } elseif ($imgtype == 'svg') {
  3702. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3703. } else {
  3704. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3705. }
  3706. $imgy = $this->getImageRBY();
  3707. } else {
  3708. $imgy = $this->GetY();
  3709. }
  3710. $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
  3711. // set starting margin for text data cell
  3712. if ($this->getRTL()) {
  3713. $header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1);
  3714. } else {
  3715. $header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1);
  3716. }
  3717. $this->SetTextColor(0, 0, 0);
  3718. // header title
  3719. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  3720. $this->SetX($header_x);
  3721. $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3722. // header string
  3723. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3724. $this->SetX($header_x);
  3725. $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
  3726. // print an ending header line
  3727. $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  3728. $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY()));
  3729. if ($this->getRTL()) {
  3730. $this->SetX($ormargins['right']);
  3731. } else {
  3732. $this->SetX($ormargins['left']);
  3733. }
  3734. $this->Cell(0, 0, '', 'T', 0, 'C');
  3735. }
  3736. /**
  3737. * This method is used to render the page footer.
  3738. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3739. * @public
  3740. */
  3741. public function Footer() {
  3742. $cur_y = $this->GetY();
  3743. $ormargins = $this->getOriginalMargins();
  3744. $this->SetTextColor(0, 0, 0);
  3745. //set style for cell border
  3746. $line_width = 0.85 / $this->getScaleFactor();
  3747. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  3748. //print document barcode
  3749. $barcode = $this->getBarcode();
  3750. if (!empty($barcode)) {
  3751. $this->Ln($line_width);
  3752. $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right']) / 3);
  3753. $style = array(
  3754. 'position' => $this->rtl?'R':'L',
  3755. 'align' => $this->rtl?'R':'L',
  3756. 'stretch' => false,
  3757. 'fitwidth' => true,
  3758. 'cellfitalign' => '',
  3759. 'border' => false,
  3760. 'padding' => 0,
  3761. 'fgcolor' => array(0,0,0),
  3762. 'bgcolor' => false,
  3763. 'text' => false
  3764. );
  3765. $this->write1DBarcode($barcode, 'C128B', '', $cur_y + $line_width, '', (($this->getFooterMargin() / 3) - $line_width), 0.3, $style, '');
  3766. }
  3767. if (empty($this->pagegroups)) {
  3768. $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3769. } else {
  3770. $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3771. }
  3772. $this->SetY($cur_y);
  3773. //Print page number
  3774. if ($this->getRTL()) {
  3775. $this->SetX($ormargins['right']);
  3776. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3777. } else {
  3778. $this->SetX($ormargins['left']);
  3779. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
  3780. }
  3781. }
  3782. /**
  3783. * This method is used to render the page header.
  3784. * @protected
  3785. * @since 4.0.012 (2008-07-24)
  3786. */
  3787. protected function setHeader() {
  3788. if ($this->print_header) {
  3789. $this->setGraphicVars($this->default_graphic_vars);
  3790. $temp_thead = $this->thead;
  3791. $temp_theadMargins = $this->theadMargins;
  3792. $lasth = $this->lasth;
  3793. $this->_out('q');
  3794. $this->rMargin = $this->original_rMargin;
  3795. $this->lMargin = $this->original_lMargin;
  3796. $this->SetCellPadding(0);
  3797. //set current position
  3798. if ($this->rtl) {
  3799. $this->SetXY($this->original_rMargin, $this->header_margin);
  3800. } else {
  3801. $this->SetXY($this->original_lMargin, $this->header_margin);
  3802. }
  3803. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3804. $this->Header();
  3805. //restore position
  3806. if ($this->rtl) {
  3807. $this->SetXY($this->original_rMargin, $this->tMargin);
  3808. } else {
  3809. $this->SetXY($this->original_lMargin, $this->tMargin);
  3810. }
  3811. $this->_out('Q');
  3812. $this->lasth = $lasth;
  3813. $this->thead = $temp_thead;
  3814. $this->theadMargins = $temp_theadMargins;
  3815. $this->newline = false;
  3816. }
  3817. }
  3818. /**
  3819. * This method is used to render the page footer.
  3820. * @protected
  3821. * @since 4.0.012 (2008-07-24)
  3822. */
  3823. protected function setFooter() {
  3824. //Page footer
  3825. // save current graphic settings
  3826. $gvars = $this->getGraphicVars();
  3827. // mark this point
  3828. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3829. $this->_out("\n");
  3830. if ($this->print_footer) {
  3831. $this->setGraphicVars($this->default_graphic_vars);
  3832. $this->current_column = 0;
  3833. $this->num_columns = 1;
  3834. $temp_thead = $this->thead;
  3835. $temp_theadMargins = $this->theadMargins;
  3836. $lasth = $this->lasth;
  3837. $this->_out('q');
  3838. $this->rMargin = $this->original_rMargin;
  3839. $this->lMargin = $this->original_lMargin;
  3840. $this->SetCellPadding(0);
  3841. //set current position
  3842. $footer_y = $this->h - $this->footer_margin;
  3843. if ($this->rtl) {
  3844. $this->SetXY($this->original_rMargin, $footer_y);
  3845. } else {
  3846. $this->SetXY($this->original_lMargin, $footer_y);
  3847. }
  3848. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3849. $this->Footer();
  3850. //restore position
  3851. if ($this->rtl) {
  3852. $this->SetXY($this->original_rMargin, $this->tMargin);
  3853. } else {
  3854. $this->SetXY($this->original_lMargin, $this->tMargin);
  3855. }
  3856. $this->_out('Q');
  3857. $this->lasth = $lasth;
  3858. $this->thead = $temp_thead;
  3859. $this->theadMargins = $temp_theadMargins;
  3860. }
  3861. // restore graphic settings
  3862. $this->setGraphicVars($gvars);
  3863. $this->current_column = $gvars['current_column'];
  3864. $this->num_columns = $gvars['num_columns'];
  3865. // calculate footer length
  3866. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3867. }
  3868. /**
  3869. * This method is used to render the table header on new page (if any).
  3870. * @protected
  3871. * @since 4.5.030 (2009-03-25)
  3872. */
  3873. protected function setTableHeader() {
  3874. if ($this->num_columns > 1) {
  3875. // multi column mode
  3876. return;
  3877. }
  3878. if (isset($this->theadMargins['top'])) {
  3879. // restore the original top-margin
  3880. $this->tMargin = $this->theadMargins['top'];
  3881. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3882. $this->y = $this->tMargin;
  3883. }
  3884. if (!$this->empty_string($this->thead) AND (!$this->inthead)) {
  3885. // set margins
  3886. $prev_lMargin = $this->lMargin;
  3887. $prev_rMargin = $this->rMargin;
  3888. $prev_cell_padding = $this->cell_padding;
  3889. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3890. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3891. $this->cell_padding = $this->theadMargins['cell_padding'];
  3892. if ($this->rtl) {
  3893. $this->x = $this->w - $this->rMargin;
  3894. } else {
  3895. $this->x = $this->lMargin;
  3896. }
  3897. // print table header
  3898. $this->writeHTML($this->thead, false, false, false, false, '');
  3899. // set new top margin to skip the table headers
  3900. if (!isset($this->theadMargins['top'])) {
  3901. $this->theadMargins['top'] = $this->tMargin;
  3902. }
  3903. // store end of header position
  3904. if (!isset($this->columns[0]['th'])) {
  3905. $this->columns[0]['th'] = array();
  3906. }
  3907. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3908. $this->tMargin = $this->y;
  3909. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3910. $this->lasth = 0;
  3911. $this->lMargin = $prev_lMargin;
  3912. $this->rMargin = $prev_rMargin;
  3913. $this->cell_padding = $prev_cell_padding;
  3914. }
  3915. }
  3916. /**
  3917. * Returns the current page number.
  3918. * @return int page number
  3919. * @public
  3920. * @since 1.0
  3921. * @see AliasNbPages(), getAliasNbPages()
  3922. */
  3923. public function PageNo() {
  3924. return $this->page;
  3925. }
  3926. /**
  3927. * Defines a new spot color.
  3928. * It can be expressed in RGB components or gray scale.
  3929. * The method can be called before the first page is created and the value is retained from page to page.
  3930. * @param $name (string) name of the spot color
  3931. * @param $c (int) Cyan color for CMYK. Value between 0 and 100
  3932. * @param $m (int) Magenta color for CMYK. Value between 0 and 100
  3933. * @param $y (int) Yellow color for CMYK. Value between 0 and 100
  3934. * @param $k (int) Key (Black) color for CMYK. Value between 0 and 100
  3935. * @public
  3936. * @since 4.0.024 (2008-09-12)
  3937. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3938. */
  3939. public function AddSpotColor($name, $c, $m, $y, $k) {
  3940. if (!isset($this->spot_colors[$name])) {
  3941. $i = 1 + count($this->spot_colors);
  3942. $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
  3943. }
  3944. $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
  3945. $color = strtolower($color);
  3946. if (!isset($this->spotcolor[$color])) {
  3947. $this->spotcolor[$color] = array($c, $m, $y, $k, $name);
  3948. }
  3949. }
  3950. /**
  3951. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3952. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3953. * The method can be called before the first page is created and the value is retained from page to page.
  3954. * @param $color (array) array of colors
  3955. * @param $ret (boolean) if true do not send the PDF command.
  3956. * @return string the PDF command
  3957. * @public
  3958. * @since 3.1.000 (2008-06-11)
  3959. * @see SetDrawColor()
  3960. */
  3961. public function SetDrawColorArray($color, $ret=false) {
  3962. if (is_array($color)) {
  3963. $color = array_values($color);
  3964. $r = isset($color[0]) ? $color[0] : -1;
  3965. $g = isset($color[1]) ? $color[1] : -1;
  3966. $b = isset($color[2]) ? $color[2] : -1;
  3967. $k = isset($color[3]) ? $color[3] : -1;
  3968. $name = isset($color[4]) ? $color[4] : ''; // spot color name
  3969. if ($r >= 0) {
  3970. return $this->SetDrawColor($r, $g, $b, $k, $ret, $name);
  3971. }
  3972. }
  3973. return '';
  3974. }
  3975. /**
  3976. * 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.
  3977. * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3978. * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3979. * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3980. * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
  3981. * @param $ret (boolean) if true do not send the command.
  3982. * @param $name (string) spot color name (if any)
  3983. * @return string the PDF command
  3984. * @public
  3985. * @since 1.3
  3986. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3987. */
  3988. public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3989. // set default values
  3990. if (!is_numeric($col1)) {
  3991. $col1 = 0;
  3992. }
  3993. if (!is_numeric($col2)) {
  3994. $col2 = -1;
  3995. }
  3996. if (!is_numeric($col3)) {
  3997. $col3 = -1;
  3998. }
  3999. if (!is_numeric($col4)) {
  4000. $col4 = -1;
  4001. }
  4002. //Set color for all stroking operations
  4003. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  4004. // Grey scale
  4005. $this->DrawColor = sprintf('%.3F G', ($col1 / 255));
  4006. $this->strokecolor = array('G' => $col1);
  4007. } elseif ($col4 == -1) {
  4008. // RGB
  4009. $this->DrawColor = sprintf('%.3F %.3F %.3F RG', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  4010. $this->strokecolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  4011. } elseif (empty($name)) {
  4012. // CMYK
  4013. $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  4014. $this->strokecolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  4015. } else {
  4016. // SPOT COLOR
  4017. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  4018. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], 1);
  4019. $this->strokecolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  4020. }
  4021. if ($this->page > 0) {
  4022. if (!$ret) {
  4023. $this->_out($this->DrawColor);
  4024. }
  4025. return $this->DrawColor;
  4026. }
  4027. return '';
  4028. }
  4029. /**
  4030. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  4031. * @param $name (string) name of the spot color
  4032. * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4033. * @public
  4034. * @since 4.0.024 (2008-09-12)
  4035. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  4036. */
  4037. public function SetDrawSpotColor($name, $tint=100) {
  4038. if (!isset($this->spot_colors[$name])) {
  4039. $this->Error('Undefined spot color: '.$name);
  4040. }
  4041. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], ($tint / 100));
  4042. $this->strokecolor = array('C' => $this->spot_colors[$name]['c'], 'M' => $this->spot_colors[$name]['m'], 'Y' => $this->spot_colors[$name]['y'], 'K' => $this->spot_colors[$name]['k'], 'name' => $name);
  4043. if ($this->page > 0) {
  4044. $this->_out($this->DrawColor);
  4045. }
  4046. }
  4047. /**
  4048. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  4049. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  4050. * The method can be called before the first page is created and the value is retained from page to page.
  4051. * @param $color (array) array of colors
  4052. * @param $ret (boolean) if true do not send the PDF command.
  4053. * @public
  4054. * @since 3.1.000 (2008-6-11)
  4055. * @see SetFillColor()
  4056. */
  4057. public function SetFillColorArray($color, $ret=false) {
  4058. if (is_array($color)) {
  4059. $color = array_values($color);
  4060. $r = isset($color[0]) ? $color[0] : -1;
  4061. $g = isset($color[1]) ? $color[1] : -1;
  4062. $b = isset($color[2]) ? $color[2] : -1;
  4063. $k = isset($color[3]) ? $color[3] : -1;
  4064. $name = isset($color[4]) ? $color[4] : ''; // spot color name
  4065. if ($r >= 0) {
  4066. $this->SetFillColor($r, $g, $b, $k, $ret, $name);
  4067. }
  4068. }
  4069. }
  4070. /**
  4071. * 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.
  4072. * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4073. * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4074. * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4075. * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
  4076. * @param $ret (boolean) if true do not send the command.
  4077. * @param $name (string) spot color name (if any)
  4078. * @return string the PDF command
  4079. * @public
  4080. * @since 1.3
  4081. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  4082. */
  4083. public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4084. // set default values
  4085. if (!is_numeric($col1)) {
  4086. $col1 = 0;
  4087. }
  4088. if (!is_numeric($col2)) {
  4089. $col2 = -1;
  4090. }
  4091. if (!is_numeric($col3)) {
  4092. $col3 = -1;
  4093. }
  4094. if (!is_numeric($col4)) {
  4095. $col4 = -1;
  4096. }
  4097. //Set color for all filling operations
  4098. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  4099. // Grey scale
  4100. $this->FillColor = sprintf('%.3F g', ($col1 / 255));
  4101. $this->bgcolor = array('G' => $col1);
  4102. } elseif ($col4 == -1) {
  4103. // RGB
  4104. $this->FillColor = sprintf('%.3F %.3F %.3F rg', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  4105. $this->bgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  4106. } elseif (empty($name)) {
  4107. // CMYK
  4108. $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  4109. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  4110. } else {
  4111. // SPOT COLOR
  4112. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  4113. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], 1);
  4114. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  4115. }
  4116. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4117. if ($this->page > 0) {
  4118. if (!$ret) {
  4119. $this->_out($this->FillColor);
  4120. }
  4121. return $this->FillColor;
  4122. }
  4123. return '';
  4124. }
  4125. /**
  4126. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  4127. * @param $name (string) name of the spot color
  4128. * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4129. * @public
  4130. * @since 4.0.024 (2008-09-12)
  4131. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  4132. */
  4133. public function SetFillSpotColor($name, $tint=100) {
  4134. if (!isset($this->spot_colors[$name])) {
  4135. $this->Error('Undefined spot color: '.$name);
  4136. }
  4137. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], ($tint / 100));
  4138. $this->bgcolor = array('C' => $this->spot_colors[$name]['c'], 'M' => $this->spot_colors[$name]['m'], 'Y' => $this->spot_colors[$name]['y'], 'K' => $this->spot_colors[$name]['k'], 'name' => $name);
  4139. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4140. if ($this->page > 0) {
  4141. $this->_out($this->FillColor);
  4142. }
  4143. }
  4144. /**
  4145. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  4146. * The method can be called before the first page is created and the value is retained from page to page.
  4147. * @param $color (array) array of colors
  4148. * @param $ret (boolean) if true do not send the PDF command.
  4149. * @public
  4150. * @since 3.1.000 (2008-6-11)
  4151. * @see SetFillColor()
  4152. */
  4153. public function SetTextColorArray($color, $ret=false) {
  4154. if (is_array($color)) {
  4155. $color = array_values($color);
  4156. $r = isset($color[0]) ? $color[0] : -1;
  4157. $g = isset($color[1]) ? $color[1] : -1;
  4158. $b = isset($color[2]) ? $color[2] : -1;
  4159. $k = isset($color[3]) ? $color[3] : -1;
  4160. $name = isset($color[4]) ? $color[4] : ''; // spot color name
  4161. if ($r >= 0) {
  4162. $this->SetTextColor($r, $g, $b, $k, $ret, $name);
  4163. }
  4164. }
  4165. }
  4166. /**
  4167. * 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.
  4168. * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  4169. * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  4170. * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  4171. * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
  4172. * @param $ret (boolean) if true do not send the command.
  4173. * @param $name (string) spot color name (if any)
  4174. * @public
  4175. * @since 1.3
  4176. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  4177. */
  4178. public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  4179. // set default values
  4180. if (!is_numeric($col1)) {
  4181. $col1 = 0;
  4182. }
  4183. if (!is_numeric($col2)) {
  4184. $col2 = -1;
  4185. }
  4186. if (!is_numeric($col3)) {
  4187. $col3 = -1;
  4188. }
  4189. if (!is_numeric($col4)) {
  4190. $col4 = -1;
  4191. }
  4192. //Set color for text
  4193. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  4194. // Grey scale
  4195. $this->TextColor = sprintf('%.3F g', ($col1 / 255));
  4196. $this->fgcolor = array('G' => $col1);
  4197. } elseif ($col4 == -1) {
  4198. // RGB
  4199. $this->TextColor = sprintf('%.3F %.3F %.3F rg', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  4200. $this->fgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  4201. } elseif (empty($name)) {
  4202. // CMYK
  4203. $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  4204. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  4205. } else {
  4206. // SPOT COLOR
  4207. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  4208. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], 1);
  4209. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  4210. }
  4211. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4212. }
  4213. /**
  4214. * Defines the spot color used for text.
  4215. * @param $name (string) name of the spot color
  4216. * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  4217. * @public
  4218. * @since 4.0.024 (2008-09-12)
  4219. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  4220. */
  4221. public function SetTextSpotColor($name, $tint=100) {
  4222. if (!isset($this->spot_colors[$name])) {
  4223. $this->Error('Undefined spot color: '.$name);
  4224. }
  4225. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], ($tint / 100));
  4226. $this->fgcolor = array('C' => $this->spot_colors[$name]['c'], 'M' => $this->spot_colors[$name]['m'], 'Y' => $this->spot_colors[$name]['y'], 'K' => $this->spot_colors[$name]['k'], 'name' => $name);
  4227. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  4228. if ($this->page > 0) {
  4229. $this->_out($this->TextColor);
  4230. }
  4231. }
  4232. /**
  4233. * Returns the length of a string in user unit. A font must be selected.<br>
  4234. * @param $s (string) The string whose length is to be computed
  4235. * @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.
  4236. * @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.
  4237. * @param $fontsize (float) Font size in points. The default value is the current size.
  4238. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  4239. * @return mixed int total string length or array of characted widths
  4240. * @author Nicola Asuni
  4241. * @public
  4242. * @since 1.2
  4243. */
  4244. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  4245. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  4246. }
  4247. /**
  4248. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  4249. * @param $sa (string) The array of chars whose total length is to be computed
  4250. * @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.
  4251. * @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.
  4252. * @param $fontsize (float) Font size in points. The default value is the current size.
  4253. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  4254. * @return mixed int total string length or array of characted widths
  4255. * @author Nicola Asuni
  4256. * @public
  4257. * @since 2.4.000 (2008-03-06)
  4258. */
  4259. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  4260. // store current values
  4261. if (!$this->empty_string($fontname)) {
  4262. $prev_FontFamily = $this->FontFamily;
  4263. $prev_FontStyle = $this->FontStyle;
  4264. $prev_FontSizePt = $this->FontSizePt;
  4265. $this->SetFont($fontname, $fontstyle, $fontsize);
  4266. }
  4267. // convert UTF-8 array to Latin1 if required
  4268. $sa = $this->UTF8ArrToLatin1($sa);
  4269. $w = 0; // total width
  4270. $wa = array(); // array of characters widths
  4271. foreach ($sa as $ck => $char) {
  4272. // character width
  4273. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  4274. $wa[] = $cw;
  4275. $w += $cw;
  4276. }
  4277. // restore previous values
  4278. if (!$this->empty_string($fontname)) {
  4279. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
  4280. }
  4281. if ($getarray) {
  4282. return $wa;
  4283. }
  4284. return $w;
  4285. }
  4286. /**
  4287. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking/kerning).
  4288. * @param $char (int) The char code whose length is to be returned
  4289. * @param $notlast (boolean) set to false for the latest character on string, true otherwise (default)
  4290. * @return float char width
  4291. * @author Nicola Asuni
  4292. * @public
  4293. * @since 2.4.000 (2008-03-06)
  4294. */
  4295. public function GetCharWidth($char, $notlast=true) {
  4296. // get raw width
  4297. $chw = $this->getRawCharWidth($char);
  4298. if (($this->font_spacing != 0) AND $notlast) {
  4299. // increase/decrease font spacing
  4300. $chw += $this->font_spacing;
  4301. }
  4302. if ($this->font_stretching != 100) {
  4303. // fixed stretching mode
  4304. $chw *= ($this->font_stretching / 100);
  4305. }
  4306. return $chw;
  4307. }
  4308. /**
  4309. * Returns the length of the char in user unit for the current font.
  4310. * @param $char (int) The char code whose length is to be returned
  4311. * @return float char width
  4312. * @author Nicola Asuni
  4313. * @public
  4314. * @since 5.9.000 (2010-09-28)
  4315. */
  4316. public function getRawCharWidth($char) {
  4317. if ($char == 173) {
  4318. // SHY character will not be printed
  4319. return (0);
  4320. }
  4321. $cw = &$this->CurrentFont['cw'];
  4322. if (isset($cw[$char])) {
  4323. $w = $cw[$char];
  4324. } elseif (isset($this->CurrentFont['dw'])) {
  4325. // default width
  4326. $w = $this->CurrentFont['dw'];
  4327. } elseif (isset($cw[32])) {
  4328. // default width
  4329. $w = $cw[32];
  4330. } else {
  4331. $w = 600;
  4332. }
  4333. return ($w * $this->FontSize / 1000);
  4334. }
  4335. /**
  4336. * Returns the numbero of characters in a string.
  4337. * @param $s (string) The input string.
  4338. * @return int number of characters
  4339. * @public
  4340. * @since 2.0.0001 (2008-01-07)
  4341. */
  4342. public function GetNumChars($s) {
  4343. if ($this->isUnicodeFont()) {
  4344. return count($this->UTF8StringToArray($s));
  4345. }
  4346. return strlen($s);
  4347. }
  4348. /**
  4349. * Fill the list of available fonts ($this->fontlist).
  4350. * @protected
  4351. * @since 4.0.013 (2008-07-28)
  4352. */
  4353. protected function getFontsList() {
  4354. $fontsdir = opendir($this->_getfontpath());
  4355. while (($file = readdir($fontsdir)) !== false) {
  4356. if (substr($file, -4) == '.php') {
  4357. array_push($this->fontlist, strtolower(basename($file, '.php')));
  4358. }
  4359. }
  4360. closedir($fontsdir);
  4361. }
  4362. /**
  4363. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  4364. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  4365. * 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.
  4366. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  4367. * @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>
  4368. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4369. * @return array containing the font data, or false in case of error.
  4370. * @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.
  4371. * @public
  4372. * @since 1.5
  4373. * @see SetFont(), setFontSubsetting()
  4374. */
  4375. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  4376. if ($subset === 'default') {
  4377. $subset = $this->font_subsetting;
  4378. }
  4379. if ($this->empty_string($family)) {
  4380. if (!$this->empty_string($this->FontFamily)) {
  4381. $family = $this->FontFamily;
  4382. } else {
  4383. $this->Error('Empty font family');
  4384. }
  4385. }
  4386. // move embedded styles on $style
  4387. if (substr($family, -1) == 'I') {
  4388. $style .= 'I';
  4389. $family = substr($family, 0, -1);
  4390. }
  4391. if (substr($family, -1) == 'B') {
  4392. $style .= 'B';
  4393. $family = substr($family, 0, -1);
  4394. }
  4395. // normalize family name
  4396. $family = strtolower($family);
  4397. if ((!$this->isunicode) AND ($family == 'arial')) {
  4398. $family = 'helvetica';
  4399. }
  4400. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  4401. $style = '';
  4402. }
  4403. $tempstyle = strtoupper($style);
  4404. $style = '';
  4405. // underline
  4406. if (strpos($tempstyle, 'U') !== false) {
  4407. $this->underline = true;
  4408. } else {
  4409. $this->underline = false;
  4410. }
  4411. // line-through (deleted)
  4412. if (strpos($tempstyle, 'D') !== false) {
  4413. $this->linethrough = true;
  4414. } else {
  4415. $this->linethrough = false;
  4416. }
  4417. // overline
  4418. if (strpos($tempstyle, 'O') !== false) {
  4419. $this->overline = true;
  4420. } else {
  4421. $this->overline = false;
  4422. }
  4423. // bold
  4424. if (strpos($tempstyle, 'B') !== false) {
  4425. $style .= 'B';
  4426. }
  4427. // oblique
  4428. if (strpos($tempstyle, 'I') !== false) {
  4429. $style .= 'I';
  4430. }
  4431. $bistyle = $style;
  4432. $fontkey = $family.$style;
  4433. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  4434. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  4435. // check if the font has been already added
  4436. $fb = $this->getFontBuffer($fontkey);
  4437. if ($fb !== false) {
  4438. if ($this->inxobj) {
  4439. // we are inside an XObject template
  4440. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  4441. }
  4442. return $fontdata;
  4443. }
  4444. if (isset($type)) {
  4445. unset($type);
  4446. }
  4447. if (isset($cw)) {
  4448. unset($cw);
  4449. }
  4450. // get specified font directory (if any)
  4451. $fontdir = false;
  4452. if (!$this->empty_string($fontfile)) {
  4453. $fontdir = dirname($fontfile);
  4454. if ($this->empty_string($fontdir) OR ($fontdir == '.')) {
  4455. $fontdir = '';
  4456. } else {
  4457. $fontdir .= '/';
  4458. }
  4459. }
  4460. // search and include font file
  4461. if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
  4462. // build a standard filenames for specified font
  4463. $fontfile1 = str_replace(' ', '', $family).strtolower($style).'.php';
  4464. $fontfile2 = str_replace(' ', '', $family).'.php';
  4465. // search files on various directories
  4466. if (($fontdir !== false) AND file_exists($fontdir.$fontfile1)) {
  4467. $fontfile = $fontdir.$fontfile1;
  4468. } elseif (file_exists($this->_getfontpath().$fontfile1)) {
  4469. $fontfile = $this->_getfontpath().$fontfile1;
  4470. } elseif (file_exists($fontfile1)) {
  4471. $fontfile = $fontfile1;
  4472. } elseif (($fontdir !== false) AND file_exists($fontdir.$fontfile2)) {
  4473. $fontfile = $fontdir.$fontfile2;
  4474. } elseif (file_exists($this->_getfontpath().$fontfile2)) {
  4475. $fontfile = $this->_getfontpath().$fontfile2;
  4476. } else {
  4477. $fontfile = $fontfile2;
  4478. }
  4479. }
  4480. // include font file
  4481. if (file_exists($fontfile)) {
  4482. include($fontfile);
  4483. } else {
  4484. $this->Error('Could not include font definition file: '.$family.'');
  4485. }
  4486. // check font parameters
  4487. if ((!isset($type)) OR (!isset($cw))) {
  4488. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  4489. }
  4490. // SET default parameters
  4491. if (!isset($file) OR $this->empty_string($file)) {
  4492. $file = '';
  4493. }
  4494. if (!isset($enc) OR $this->empty_string($enc)) {
  4495. $enc = '';
  4496. }
  4497. if (!isset($cidinfo) OR $this->empty_string($cidinfo)) {
  4498. $cidinfo = array('Registry'=>'Adobe','Ordering'=>'Identity','Supplement'=>0);
  4499. $cidinfo['uni2cid'] = array();
  4500. }
  4501. if (!isset($ctg) OR $this->empty_string($ctg)) {
  4502. $ctg = '';
  4503. }
  4504. if (!isset($desc) OR $this->empty_string($desc)) {
  4505. $desc = array();
  4506. }
  4507. if (!isset($up) OR $this->empty_string($up)) {
  4508. $up = -100;
  4509. }
  4510. if (!isset($ut) OR $this->empty_string($ut)) {
  4511. $ut = 50;
  4512. }
  4513. if (!isset($cw) OR $this->empty_string($cw)) {
  4514. $cw = array();
  4515. }
  4516. if (!isset($dw) OR $this->empty_string($dw)) {
  4517. // set default width
  4518. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  4519. $dw = $desc['MissingWidth'];
  4520. } elseif (isset($cw[32])) {
  4521. $dw = $cw[32];
  4522. } else {
  4523. $dw = 600;
  4524. }
  4525. }
  4526. ++$this->numfonts;
  4527. if ($type == 'cidfont0') {
  4528. // register CID font (all styles at once)
  4529. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  4530. $sname = $name.$styles[$bistyle];
  4531. // artificial bold
  4532. if (strpos($bistyle, 'B') !== false) {
  4533. if (isset($desc['StemV'])) {
  4534. $desc['StemV'] *= 2;
  4535. } else {
  4536. $desc['StemV'] = 120;
  4537. }
  4538. }
  4539. // artificial italic
  4540. if (strpos($bistyle, 'I') !== false) {
  4541. if (isset($desc['ItalicAngle'])) {
  4542. $desc['ItalicAngle'] -= 11;
  4543. } else {
  4544. $desc['ItalicAngle'] = -11;
  4545. }
  4546. }
  4547. } elseif ($type == 'core') {
  4548. $name = $this->CoreFonts[$fontkey];
  4549. $subset = false;
  4550. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  4551. $subset = false;
  4552. } elseif ($type == 'TrueTypeUnicode') {
  4553. $enc = 'Identity-H';
  4554. } else {
  4555. $this->Error('Unknow font type: '.$type.'');
  4556. }
  4557. // initialize subsetchars to contain default ASCII values (0-255)
  4558. $subsetchars = array_fill(0, 256, true);
  4559. $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
  4560. if ($this->inxobj) {
  4561. // we are inside an XObject template
  4562. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4563. }
  4564. if (isset($diff) AND (!empty($diff))) {
  4565. //Search existing encodings
  4566. $d = 0;
  4567. $nb = count($this->diffs);
  4568. for ($i=1; $i <= $nb; ++$i) {
  4569. if ($this->diffs[$i] == $diff) {
  4570. $d = $i;
  4571. break;
  4572. }
  4573. }
  4574. if ($d == 0) {
  4575. $d = $nb + 1;
  4576. $this->diffs[$d] = $diff;
  4577. }
  4578. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4579. }
  4580. if (!$this->empty_string($file)) {
  4581. if (!isset($this->FontFiles[$file])) {
  4582. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4583. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4584. } elseif ($type != 'core') {
  4585. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4586. }
  4587. } else {
  4588. // update fontkeys that are sharing this font file
  4589. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4590. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4591. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4592. }
  4593. }
  4594. }
  4595. return $fontdata;
  4596. }
  4597. /**
  4598. * Sets the font used to print character strings.
  4599. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4600. * The method can be called before the first page is created and the font is retained from page to page.
  4601. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4602. * 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 />
  4603. * @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.
  4604. * @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.
  4605. * @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
  4606. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4607. * @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.
  4608. * @author Nicola Asuni
  4609. * @public
  4610. * @since 1.0
  4611. * @see AddFont(), SetFontSize()
  4612. */
  4613. public function SetFont($family, $style='', $size=0, $fontfile='', $subset='default') {
  4614. //Select a font; size given in points
  4615. if ($size == 0) {
  4616. $size = $this->FontSizePt;
  4617. }
  4618. // try to add font (if not already added)
  4619. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4620. $this->FontFamily = $fontdata['family'];
  4621. $this->FontStyle = $fontdata['style'];
  4622. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4623. $this->SetFontSize($size);
  4624. }
  4625. /**
  4626. * Defines the size of the current font.
  4627. * @param $size (float) The size (in points)
  4628. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4629. * @public
  4630. * @since 1.0
  4631. * @see SetFont()
  4632. */
  4633. public function SetFontSize($size, $out=true) {
  4634. // font size in points
  4635. $this->FontSizePt = $size;
  4636. // font size in user units
  4637. $this->FontSize = $size / $this->k;
  4638. // calculate some font metrics
  4639. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4640. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4641. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4642. } else {
  4643. $font_height = $size * 1.219;
  4644. }
  4645. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4646. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4647. }
  4648. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4649. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4650. }
  4651. if (!isset($font_ascent) AND !isset($font_descent)) {
  4652. // core font
  4653. $font_ascent = 0.76 * $font_height;
  4654. $font_descent = $font_height - $font_ascent;
  4655. } elseif (!isset($font_descent)) {
  4656. $font_descent = $font_height - $font_ascent;
  4657. } elseif (!isset($font_ascent)) {
  4658. $font_ascent = $font_height - $font_descent;
  4659. }
  4660. $this->FontAscent = $font_ascent / $this->k;
  4661. $this->FontDescent = $font_descent / $this->k;
  4662. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i']))) {
  4663. $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4664. }
  4665. }
  4666. /**
  4667. * Return the font descent value
  4668. * @param $font (string) font name
  4669. * @param $style (string) font style
  4670. * @param $size (float) The size (in points)
  4671. * @return int font descent
  4672. * @public
  4673. * @author Nicola Asuni
  4674. * @since 4.9.003 (2010-03-30)
  4675. */
  4676. public function getFontDescent($font, $style='', $size=0) {
  4677. $fontdata = $this->AddFont($font, $style);
  4678. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4679. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4680. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4681. } else {
  4682. $descent = 1.219 * 0.24 * $size;
  4683. }
  4684. return ($descent / $this->k);
  4685. }
  4686. /**
  4687. * Return the font ascent value
  4688. * @param $font (string) font name
  4689. * @param $style (string) font style
  4690. * @param $size (float) The size (in points)
  4691. * @return int font ascent
  4692. * @public
  4693. * @author Nicola Asuni
  4694. * @since 4.9.003 (2010-03-30)
  4695. */
  4696. public function getFontAscent($font, $style='', $size=0) {
  4697. $fontdata = $this->AddFont($font, $style);
  4698. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4699. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4700. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4701. } else {
  4702. $ascent = 1.219 * 0.76 * $size;
  4703. }
  4704. return ($ascent / $this->k);
  4705. }
  4706. /**
  4707. * Defines the default monospaced font.
  4708. * @param $font (string) Font name.
  4709. * @public
  4710. * @since 4.5.025
  4711. */
  4712. public function SetDefaultMonospacedFont($font) {
  4713. $this->default_monospaced_font = $font;
  4714. }
  4715. /**
  4716. * 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 />
  4717. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4718. * @public
  4719. * @since 1.5
  4720. * @see Cell(), Write(), Image(), Link(), SetLink()
  4721. */
  4722. public function AddLink() {
  4723. //Create a new internal link
  4724. $n = count($this->links) + 1;
  4725. $this->links[$n] = array(0, 0);
  4726. return $n;
  4727. }
  4728. /**
  4729. * Defines the page and position a link points to.
  4730. * @param $link (int) The link identifier returned by AddLink()
  4731. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4732. * @param $page (int) Number of target page; -1 indicates the current page. This is the default value
  4733. * @public
  4734. * @since 1.5
  4735. * @see AddLink()
  4736. */
  4737. public function SetLink($link, $y=0, $page=-1) {
  4738. if ($y == -1) {
  4739. $y = $this->y;
  4740. }
  4741. if ($page == -1) {
  4742. $page = $this->page;
  4743. }
  4744. $this->links[$link] = array($page, $y);
  4745. }
  4746. /**
  4747. * Puts a link on a rectangular area of the page.
  4748. * 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.
  4749. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4750. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4751. * @param $w (float) Width of the rectangle
  4752. * @param $h (float) Height of the rectangle
  4753. * @param $link (mixed) URL or identifier returned by AddLink()
  4754. * @param $spaces (int) number of spaces on the text to link
  4755. * @public
  4756. * @since 1.5
  4757. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4758. */
  4759. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  4760. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4761. }
  4762. /**
  4763. * Puts a markup annotation on a rectangular area of the page.
  4764. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4765. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4766. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4767. * @param $w (float) Width of the rectangle
  4768. * @param $h (float) Height of the rectangle
  4769. * @param $text (string) annotation text or alternate content
  4770. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  4771. * @param $spaces (int) number of spaces on the text to link
  4772. * @public
  4773. * @since 4.0.018 (2008-08-06)
  4774. */
  4775. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  4776. if ($this->inxobj) {
  4777. // store parameters for later use on template
  4778. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4779. return;
  4780. }
  4781. if ($x === '') {
  4782. $x = $this->x;
  4783. }
  4784. if ($y === '') {
  4785. $y = $this->y;
  4786. }
  4787. // check page for no-write regions and adapt page margins if necessary
  4788. $this->checkPageRegions($h, $x, $y);
  4789. // recalculate coordinates to account for graphic transformations
  4790. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4791. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4792. $maxid = count($this->transfmatrix[$i]) - 1;
  4793. for ($j=$maxid; $j >= 0; --$j) {
  4794. $ctm = $this->transfmatrix[$i][$j];
  4795. if (isset($ctm['a'])) {
  4796. $x = $x * $this->k;
  4797. $y = ($this->h - $y) * $this->k;
  4798. $w = $w * $this->k;
  4799. $h = $h * $this->k;
  4800. // top left
  4801. $xt = $x;
  4802. $yt = $y;
  4803. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4804. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4805. // top right
  4806. $xt = $x + $w;
  4807. $yt = $y;
  4808. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4809. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4810. // bottom left
  4811. $xt = $x;
  4812. $yt = $y - $h;
  4813. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4814. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4815. // bottom right
  4816. $xt = $x + $w;
  4817. $yt = $y - $h;
  4818. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4819. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4820. // new coordinates (rectangle area)
  4821. $x = min($x1, $x2, $x3, $x4);
  4822. $y = max($y1, $y2, $y3, $y4);
  4823. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4824. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4825. $x = $x / $this->k;
  4826. $y = $this->h - ($y / $this->k);
  4827. }
  4828. }
  4829. }
  4830. }
  4831. if ($this->page <= 0) {
  4832. $page = 1;
  4833. } else {
  4834. $page = $this->page;
  4835. }
  4836. if (!isset($this->PageAnnots[$page])) {
  4837. $this->PageAnnots[$page] = array();
  4838. }
  4839. ++$this->n;
  4840. $this->PageAnnots[$page][] = array('n' => $this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4841. 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'])]))) {
  4842. ++$this->n;
  4843. $this->embeddedfiles[basename($opt['FS'])] = array('n' => $this->n, 'file' => $opt['FS']);
  4844. }
  4845. // Add widgets annotation's icons
  4846. if (isset($opt['mk']['i']) AND file_exists($opt['mk']['i'])) {
  4847. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4848. }
  4849. if (isset($opt['mk']['ri']) AND file_exists($opt['mk']['ri'])) {
  4850. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4851. }
  4852. if (isset($opt['mk']['ix']) AND file_exists($opt['mk']['ix'])) {
  4853. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4854. }
  4855. }
  4856. /**
  4857. * Embedd the attached files.
  4858. * @since 4.4.000 (2008-12-07)
  4859. * @protected
  4860. * @see Annotation()
  4861. */
  4862. protected function _putEmbeddedFiles() {
  4863. reset($this->embeddedfiles);
  4864. foreach ($this->embeddedfiles as $filename => $filedata) {
  4865. $data = file_get_contents($filedata['file']);
  4866. $filter = '';
  4867. if ($this->compress) {
  4868. $data = gzcompress($data);
  4869. $filter = ' /Filter /FlateDecode';
  4870. }
  4871. $stream = $this->_getrawstream($data, $filedata['n']);
  4872. $out = $this->_getobj($filedata['n'])."\n";
  4873. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' >>';
  4874. $out .= ' stream'."\n".$stream."\n".'endstream';
  4875. $out .= "\n".'endobj';
  4876. $this->_out($out);
  4877. }
  4878. }
  4879. /**
  4880. * Prints a text cell at the specified position.
  4881. * This method allows to place a string precisely on the page.
  4882. * @param $x (float) Abscissa of the cell origin
  4883. * @param $y (float) Ordinate of the cell origin
  4884. * @param $txt (string) String to print
  4885. * @param $fstroke (int) outline size in user units (false = disable)
  4886. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4887. * @param $ffill (boolean) if true fills the text
  4888. * @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)))
  4889. * @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.
  4890. * @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>
  4891. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4892. * @param $link (mixed) URL or identifier returned by AddLink().
  4893. * @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.
  4894. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4895. * @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>
  4896. * @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>
  4897. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4898. * @public
  4899. * @since 1.0
  4900. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4901. */
  4902. 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) {
  4903. $textrendermode = $this->textrendermode;
  4904. $textstrokewidth = $this->textstrokewidth;
  4905. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4906. $this->SetXY($x, $y, $rtloff);
  4907. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4908. // restore previous rendering mode
  4909. $this->textrendermode = $textrendermode;
  4910. $this->textstrokewidth = $textstrokewidth;
  4911. }
  4912. /**
  4913. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4914. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4915. * This method is called automatically and should not be called directly by the application.
  4916. * @return boolean
  4917. * @public
  4918. * @since 1.4
  4919. * @see SetAutoPageBreak()
  4920. */
  4921. public function AcceptPageBreak() {
  4922. if ($this->num_columns > 1) {
  4923. // multi column mode
  4924. if($this->current_column < ($this->num_columns - 1)) {
  4925. // go to next column
  4926. $this->selectColumn($this->current_column + 1);
  4927. } else {
  4928. // add a new page
  4929. $this->AddPage();
  4930. // set first column
  4931. $this->selectColumn(0);
  4932. }
  4933. // avoid page breaking from checkPageBreak()
  4934. return false;
  4935. }
  4936. return $this->AutoPageBreak;
  4937. }
  4938. /**
  4939. * Add page if needed.
  4940. * @param $h (float) Cell height. Default value: 0.
  4941. * @param $y (mixed) starting y position, leave empty for current position.
  4942. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  4943. * @return boolean true in case of page break, false otherwise.
  4944. * @since 3.2.000 (2008-07-01)
  4945. * @protected
  4946. */
  4947. protected function checkPageBreak($h=0, $y='', $addpage=true) {
  4948. if ($this->empty_string($y)) {
  4949. $y = $this->y;
  4950. }
  4951. $current_page = $this->page;
  4952. if ((($y + $h) > $this->PageBreakTrigger) AND (!$this->InFooter) AND ($this->AcceptPageBreak())) {
  4953. if ($addpage) {
  4954. //Automatic page break
  4955. $x = $this->x;
  4956. $this->AddPage($this->CurOrientation);
  4957. $this->y = $this->tMargin;
  4958. $oldpage = $this->page - 1;
  4959. if ($this->rtl) {
  4960. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4961. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4962. } else {
  4963. $this->x = $x;
  4964. }
  4965. } else {
  4966. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4967. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4968. } else {
  4969. $this->x = $x;
  4970. }
  4971. }
  4972. }
  4973. return true;
  4974. }
  4975. if ($current_page != $this->page) {
  4976. // account for columns mode
  4977. return true;
  4978. }
  4979. return false;
  4980. }
  4981. /**
  4982. * Removes SHY characters from text.
  4983. * Unicode Data:<ul>
  4984. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  4985. * <li>HTML Entity (decimal): "&amp;#173;"</li>
  4986. * <li>HTML Entity (hex): "&amp;#xad;"</li>
  4987. * <li>HTML Entity (named): "&amp;shy;"</li>
  4988. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  4989. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  4990. * <li>UTF-8 character: chr(194).chr(173)</li>
  4991. * </ul>
  4992. * @param $txt (string) input string
  4993. * @return string without SHY characters.
  4994. * @public
  4995. * @since (4.5.019) 2009-02-28
  4996. */
  4997. public function removeSHY($txt='') {
  4998. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  4999. if (!$this->isunicode) {
  5000. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  5001. }
  5002. return $txt;
  5003. }
  5004. /**
  5005. * 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 />
  5006. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  5007. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  5008. * @param $h (float) Cell height. Default value: 0.
  5009. * @param $txt (string) String to print. Default value: empty string.
  5010. * @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)))
  5011. * @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.
  5012. * @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>
  5013. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5014. * @param $link (mixed) URL or identifier returned by AddLink().
  5015. * @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.
  5016. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  5017. * @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>
  5018. * @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>
  5019. * @public
  5020. * @since 1.0
  5021. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  5022. */
  5023. 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') {
  5024. $prev_cell_margin = $this->cell_margin;
  5025. $prev_cell_padding = $this->cell_padding;
  5026. $this->adjustCellPadding($border);
  5027. if (!$ignore_min_height) {
  5028. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  5029. if ($h < $min_cell_height) {
  5030. $h = $min_cell_height;
  5031. }
  5032. }
  5033. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  5034. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  5035. $this->cell_padding = $prev_cell_padding;
  5036. $this->cell_margin = $prev_cell_margin;
  5037. }
  5038. /**
  5039. * 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 />
  5040. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  5041. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  5042. * @param $h (float) Cell height. Default value: 0.
  5043. * @param $txt (string) String to print. Default value: empty string.
  5044. * @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)))
  5045. * @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.
  5046. * @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>
  5047. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5048. * @param $link (mixed) URL or identifier returned by AddLink().
  5049. * @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.
  5050. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  5051. * @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>
  5052. * @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>
  5053. * @return string containing cell code
  5054. * @protected
  5055. * @since 1.0
  5056. * @see Cell()
  5057. */
  5058. 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') {
  5059. $prev_cell_margin = $this->cell_margin;
  5060. $prev_cell_padding = $this->cell_padding;
  5061. $txt = $this->removeSHY($txt);
  5062. $rs = ''; //string to be returned
  5063. $this->adjustCellPadding($border);
  5064. if (!$ignore_min_height) {
  5065. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  5066. if ($h < $min_cell_height) {
  5067. $h = $min_cell_height;
  5068. }
  5069. }
  5070. $k = $this->k;
  5071. // check page for no-write regions and adapt page margins if necessary
  5072. $this->checkPageRegions($h, $this->x, $this->y);
  5073. if ($this->rtl) {
  5074. $x = $this->x - $this->cell_margin['R'];
  5075. } else {
  5076. $x = $this->x + $this->cell_margin['L'];
  5077. }
  5078. $y = $this->y + $this->cell_margin['T'];
  5079. $prev_font_stretching = $this->font_stretching;
  5080. $prev_font_spacing = $this->font_spacing;
  5081. // cell vertical alignment
  5082. switch ($calign) {
  5083. case 'A': {
  5084. // font top
  5085. switch ($valign) {
  5086. case 'T': {
  5087. // top
  5088. $y -= $this->cell_padding['T'];
  5089. break;
  5090. }
  5091. case 'B': {
  5092. // bottom
  5093. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  5094. break;
  5095. }
  5096. default:
  5097. case 'C':
  5098. case 'M': {
  5099. // center
  5100. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  5101. break;
  5102. }
  5103. }
  5104. break;
  5105. }
  5106. case 'L': {
  5107. // font baseline
  5108. switch ($valign) {
  5109. case 'T': {
  5110. // top
  5111. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  5112. break;
  5113. }
  5114. case 'B': {
  5115. // bottom
  5116. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  5117. break;
  5118. }
  5119. default:
  5120. case 'C':
  5121. case 'M': {
  5122. // center
  5123. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  5124. break;
  5125. }
  5126. }
  5127. break;
  5128. }
  5129. case 'D': {
  5130. // font bottom
  5131. switch ($valign) {
  5132. case 'T': {
  5133. // top
  5134. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  5135. break;
  5136. }
  5137. case 'B': {
  5138. // bottom
  5139. $y -= ($h - $this->cell_padding['B']);
  5140. break;
  5141. }
  5142. default:
  5143. case 'C':
  5144. case 'M': {
  5145. // center
  5146. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  5147. break;
  5148. }
  5149. }
  5150. break;
  5151. }
  5152. case 'B': {
  5153. // cell bottom
  5154. $y -= $h;
  5155. break;
  5156. }
  5157. case 'C':
  5158. case 'M': {
  5159. // cell center
  5160. $y -= ($h / 2);
  5161. break;
  5162. }
  5163. default:
  5164. case 'T': {
  5165. // cell top
  5166. break;
  5167. }
  5168. }
  5169. // text vertical alignment
  5170. switch ($valign) {
  5171. case 'T': {
  5172. // top
  5173. $yt = $y + $this->cell_padding['T'];
  5174. break;
  5175. }
  5176. case 'B': {
  5177. // bottom
  5178. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  5179. break;
  5180. }
  5181. default:
  5182. case 'C':
  5183. case 'M': {
  5184. // center
  5185. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  5186. break;
  5187. }
  5188. }
  5189. $basefonty = $yt + $this->FontAscent;
  5190. if ($this->empty_string($w) OR ($w <= 0)) {
  5191. if ($this->rtl) {
  5192. $w = $x - $this->lMargin;
  5193. } else {
  5194. $w = $this->w - $this->rMargin - $x;
  5195. }
  5196. }
  5197. $s = '';
  5198. // fill and borders
  5199. if (is_string($border) AND (strlen($border) == 4)) {
  5200. // full border
  5201. $border = 1;
  5202. }
  5203. if ($fill OR ($border == 1)) {
  5204. if ($fill) {
  5205. $op = ($border == 1) ? 'B' : 'f';
  5206. } else {
  5207. $op = 'S';
  5208. }
  5209. if ($this->rtl) {
  5210. $xk = (($x - $w) * $k);
  5211. } else {
  5212. $xk = ($x * $k);
  5213. }
  5214. $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  5215. }
  5216. // draw borders
  5217. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  5218. if ($txt != '') {
  5219. $txt2 = $txt;
  5220. if ($this->isunicode) {
  5221. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  5222. $txt2 = $this->UTF8ToLatin1($txt2);
  5223. } else {
  5224. $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
  5225. $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
  5226. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  5227. // ---- Fix for bug #2977340 "Incorrect Thai characters position arrangement" ----
  5228. // NOTE: this doesn't work with HTML justification
  5229. // Symbols that could overlap on the font top (only works in LTR)
  5230. $topchar = array(3611, 3613, 3615, 3650, 3651, 3652); // chars that extends on top
  5231. $topsym = array(3633, 3636, 3637, 3638, 3639, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662); // symbols with top position
  5232. $numchars = count($unicode); // number of chars
  5233. $unik = 0;
  5234. $uniblock = array();
  5235. $uniblock[$unik] = array();
  5236. $uniblock[$unik][] = $unicode[0];
  5237. // resolve overlapping conflicts by splitting the string in several parts
  5238. for ($i = 1; $i < $numchars; ++$i) {
  5239. // check if symbols overlaps at top
  5240. if (in_array($unicode[$i], $topsym) AND (in_array($unicode[($i - 1)], $topsym) OR in_array($unicode[($i - 1)], $topchar))) {
  5241. // move symbols to another array
  5242. ++$unik;
  5243. $uniblock[$unik] = array();
  5244. $uniblock[$unik][] = $unicode[$i];
  5245. ++$unik;
  5246. $uniblock[$unik] = array();
  5247. $unicode[$i] = 0x200b; // Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  5248. } else {
  5249. $uniblock[$unik][] = $unicode[$i];
  5250. }
  5251. }
  5252. // ---- END OF Fix for bug #2977340
  5253. }
  5254. $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
  5255. }
  5256. }
  5257. $txt2 = $this->_escape($txt2);
  5258. // get current text width (considering general font stretching and spacing)
  5259. $txwidth = $this->GetStringWidth($txt);
  5260. $width = $txwidth;
  5261. // check for stretch mode
  5262. if ($stretch > 0) {
  5263. // calculate ratio between cell width and text width
  5264. if ($width <= 0) {
  5265. $ratio = 1;
  5266. } else {
  5267. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  5268. }
  5269. // check if stretching is required
  5270. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  5271. // the text will be stretched to fit cell width
  5272. if ($stretch > 2) {
  5273. // set new character spacing
  5274. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  5275. } else {
  5276. // set new horizontal stretching
  5277. $this->font_stretching *= $ratio;
  5278. }
  5279. // recalculate text width (the text fills the entire cell)
  5280. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5281. // reset alignment
  5282. $align = '';
  5283. }
  5284. }
  5285. if ($this->font_stretching != 100) {
  5286. // apply font stretching
  5287. $rs .= sprintf('BT %.2F Tz ET ', $this->font_stretching);
  5288. }
  5289. if ($this->font_spacing != 0) {
  5290. // increase/decrease font spacing
  5291. $rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing * $this->k));
  5292. }
  5293. if ($this->ColorFlag) {
  5294. $s .= 'q '.$this->TextColor.' ';
  5295. }
  5296. // rendering mode
  5297. $s .= sprintf('BT %d Tr %.2F w ET ', $this->textrendermode, $this->textstrokewidth);
  5298. // count number of spaces
  5299. $ns = substr_count($txt, chr(32));
  5300. // Justification
  5301. $spacewidth = 0;
  5302. if (($align == 'J') AND ($ns > 0)) {
  5303. if ($this->isUnicodeFont()) {
  5304. // get string width without spaces
  5305. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  5306. // calculate average space width
  5307. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / $this->FontSize;
  5308. if ($this->font_stretching != 100) {
  5309. // word spacing is affected by stretching
  5310. $spacewidth /= ($this->font_stretching / 100);
  5311. }
  5312. // set word position to be used with TJ operator
  5313. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%.3F', $spacewidth).' (', $txt2);
  5314. $unicode_justification = true;
  5315. } else {
  5316. // get string width
  5317. $width = $txwidth;
  5318. // new space width
  5319. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5320. if ($this->font_stretching != 100) {
  5321. // word spacing (Tw) is affected by stretching
  5322. $spacewidth /= ($this->font_stretching / 100);
  5323. }
  5324. // set word spacing
  5325. $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
  5326. }
  5327. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5328. }
  5329. // replace carriage return characters
  5330. $txt2 = str_replace("\r", ' ', $txt2);
  5331. switch ($align) {
  5332. case 'C': {
  5333. $dx = ($w - $width) / 2;
  5334. break;
  5335. }
  5336. case 'R': {
  5337. if ($this->rtl) {
  5338. $dx = $this->cell_padding['R'];
  5339. } else {
  5340. $dx = $w - $width - $this->cell_padding['R'];
  5341. }
  5342. break;
  5343. }
  5344. case 'L': {
  5345. if ($this->rtl) {
  5346. $dx = $w - $width - $this->cell_padding['L'];
  5347. } else {
  5348. $dx = $this->cell_padding['L'];
  5349. }
  5350. break;
  5351. }
  5352. case 'J':
  5353. default: {
  5354. if ($this->rtl) {
  5355. $dx = $this->cell_padding['R'];
  5356. } else {
  5357. $dx = $this->cell_padding['L'];
  5358. }
  5359. break;
  5360. }
  5361. }
  5362. if ($this->rtl) {
  5363. $xdx = $x - $dx - $width;
  5364. } else {
  5365. $xdx = $x + $dx;
  5366. }
  5367. $xdk = $xdx * $k;
  5368. // print text
  5369. $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5370. if (isset($uniblock)) {
  5371. // print overlapping characters as separate string
  5372. $xshift = 0; // horizontal shift
  5373. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5374. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5375. foreach ($uniblock as $uk => $uniarr) {
  5376. if (($uk % 2) == 0) {
  5377. // x space to skip
  5378. if ($spacewidth != 0) {
  5379. // justification shift
  5380. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5381. }
  5382. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5383. } else {
  5384. // character to print
  5385. $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
  5386. $topchr = $this->_escape($topchr);
  5387. $s .= sprintf(' BT %.2F %.2F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5388. }
  5389. }
  5390. }
  5391. if ($this->underline) {
  5392. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5393. }
  5394. if ($this->linethrough) {
  5395. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5396. }
  5397. if ($this->overline) {
  5398. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5399. }
  5400. if ($this->ColorFlag) {
  5401. $s .= ' Q';
  5402. }
  5403. if ($link) {
  5404. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5405. }
  5406. }
  5407. // output cell
  5408. if ($s) {
  5409. // output cell
  5410. $rs .= $s;
  5411. if ($this->font_spacing != 0) {
  5412. // reset font spacing mode
  5413. $rs .= ' BT 0 Tc ET';
  5414. }
  5415. if ($this->font_stretching != 100) {
  5416. // reset font stretching mode
  5417. $rs .= ' BT 100 Tz ET';
  5418. }
  5419. }
  5420. // reset word spacing
  5421. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5422. $rs .= ' BT 0 Tw ET';
  5423. }
  5424. // reset stretching and spacing
  5425. $this->font_stretching = $prev_font_stretching;
  5426. $this->font_spacing = $prev_font_spacing;
  5427. $this->lasth = $h;
  5428. if ($ln > 0) {
  5429. //Go to the beginning of the next line
  5430. $this->y = $y + $h + $this->cell_margin['B'];
  5431. if ($ln == 1) {
  5432. if ($this->rtl) {
  5433. $this->x = $this->w - $this->rMargin;
  5434. } else {
  5435. $this->x = $this->lMargin;
  5436. }
  5437. }
  5438. } else {
  5439. // go left or right by case
  5440. if ($this->rtl) {
  5441. $this->x = $x - $w - $this->cell_margin['L'];
  5442. } else {
  5443. $this->x = $x + $w + $this->cell_margin['R'];
  5444. }
  5445. }
  5446. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5447. $rs = $gstyles.$rs;
  5448. $this->cell_padding = $prev_cell_padding;
  5449. $this->cell_margin = $prev_cell_margin;
  5450. return $rs;
  5451. }
  5452. /**
  5453. * Returns the code to draw the cell border
  5454. * @param $x (float) X coordinate.
  5455. * @param $y (float) Y coordinate.
  5456. * @param $w (float) Cell width.
  5457. * @param $h (float) Cell height.
  5458. * @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)))
  5459. * @return string containing cell border code
  5460. * @protected
  5461. * @see SetLineStyle()
  5462. * @since 5.7.000 (2010-08-02)
  5463. */
  5464. protected function getCellBorder($x, $y, $w, $h, $brd) {
  5465. $s = ''; // string to be returned
  5466. if (empty($brd)) {
  5467. return $s;
  5468. }
  5469. if ($brd == 1) {
  5470. $brd = array('LRTB' => true);
  5471. }
  5472. // calculate coordinates for border
  5473. $k = $this->k;
  5474. if ($this->rtl) {
  5475. $xeL = ($x - $w) * $k;
  5476. $xeR = $x * $k;
  5477. } else {
  5478. $xeL = $x * $k;
  5479. $xeR = ($x + $w) * $k;
  5480. }
  5481. $yeL = (($this->h - ($y + $h)) * $k);
  5482. $yeT = (($this->h - $y) * $k);
  5483. $xeT = $xeL;
  5484. $xeB = $xeR;
  5485. $yeR = $yeT;
  5486. $yeB = $yeL;
  5487. if (is_string($brd)) {
  5488. // convert string to array
  5489. $slen = strlen($brd);
  5490. $newbrd = array();
  5491. for ($i = 0; $i < $slen; ++$i) {
  5492. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  5493. }
  5494. $brd = $newbrd;
  5495. }
  5496. if (isset($brd['mode'])) {
  5497. $mode = $brd['mode'];
  5498. unset($brd['mode']);
  5499. } else {
  5500. $mode = 'normal';
  5501. }
  5502. foreach ($brd as $border => $style) {
  5503. if (is_array($style) AND !empty($style)) {
  5504. // apply border style
  5505. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5506. $s .= $this->SetLineStyle($style, true)."\n";
  5507. }
  5508. switch ($mode) {
  5509. case 'ext': {
  5510. $off = (($this->LineWidth / 2) * $k);
  5511. $xL = $xeL - $off;
  5512. $xR = $xeR + $off;
  5513. $yT = $yeT + $off;
  5514. $yL = $yeL - $off;
  5515. $xT = $xL;
  5516. $xB = $xR;
  5517. $yR = $yT;
  5518. $yB = $yL;
  5519. $w += $this->LineWidth;
  5520. $h += $this->LineWidth;
  5521. break;
  5522. }
  5523. case 'int': {
  5524. $off = ($this->LineWidth / 2) * $k;
  5525. $xL = $xeL + $off;
  5526. $xR = $xeR - $off;
  5527. $yT = $yeT - $off;
  5528. $yL = $yeL + $off;
  5529. $xT = $xL;
  5530. $xB = $xR;
  5531. $yR = $yT;
  5532. $yB = $yL;
  5533. $w -= $this->LineWidth;
  5534. $h -= $this->LineWidth;
  5535. break;
  5536. }
  5537. case 'normal':
  5538. default: {
  5539. $xL = $xeL;
  5540. $xT = $xeT;
  5541. $xB = $xeB;
  5542. $xR = $xeR;
  5543. $yL = $yeL;
  5544. $yT = $yeT;
  5545. $yB = $yeB;
  5546. $yR = $yeR;
  5547. break;
  5548. }
  5549. }
  5550. // draw borders by case
  5551. if (strlen($border) == 4) {
  5552. $s .= sprintf('%.2F %.2F %.2F %.2F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5553. } elseif (strlen($border) == 3) {
  5554. if (strpos($border,'B') === false) { // LTR
  5555. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5556. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5557. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5558. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5559. $s .= 'S ';
  5560. } elseif (strpos($border,'L') === false) { // TRB
  5561. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5562. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5563. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5564. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5565. $s .= 'S ';
  5566. } elseif (strpos($border,'T') === false) { // RBL
  5567. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5568. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5569. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5570. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5571. $s .= 'S ';
  5572. } elseif (strpos($border,'R') === false) { // BLT
  5573. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5574. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5575. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5576. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5577. $s .= 'S ';
  5578. }
  5579. } elseif (strlen($border) == 2) {
  5580. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5581. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5582. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5583. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5584. $s .= 'S ';
  5585. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5586. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5587. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5588. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5589. $s .= 'S ';
  5590. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5591. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5592. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5593. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5594. $s .= 'S ';
  5595. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5596. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5597. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5598. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5599. $s .= 'S ';
  5600. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5601. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5602. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5603. $s .= 'S ';
  5604. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5605. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5606. $s .= 'S ';
  5607. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5608. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5609. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5610. $s .= 'S ';
  5611. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5612. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5613. $s .= 'S ';
  5614. }
  5615. } else { // strlen($border) == 1
  5616. if (strpos($border,'L') !== false) { // L
  5617. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  5618. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  5619. $s .= 'S ';
  5620. } elseif (strpos($border,'T') !== false) { // T
  5621. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  5622. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  5623. $s .= 'S ';
  5624. } elseif (strpos($border,'R') !== false) { // R
  5625. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  5626. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  5627. $s .= 'S ';
  5628. } elseif (strpos($border,'B') !== false) { // B
  5629. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  5630. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  5631. $s .= 'S ';
  5632. }
  5633. }
  5634. if (is_array($style) AND !empty($style)) {
  5635. // reset border style to previous value
  5636. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5637. }
  5638. }
  5639. return $s;
  5640. }
  5641. /**
  5642. * This method allows printing text with line breaks.
  5643. * 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 />
  5644. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5645. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5646. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  5647. * @param $txt (string) String to print
  5648. * @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)))
  5649. * @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>
  5650. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5651. * @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>
  5652. * @param $x (float) x position in user units
  5653. * @param $y (float) y position in user units
  5654. * @param $reseth (boolean) if true reset the last cell height (default true).
  5655. * @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.
  5656. * @param $ishtml (boolean) set to true if $txt is HTML content (default = false).
  5657. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  5658. * @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.
  5659. * @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.
  5660. * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size.
  5661. * @return int Return the number of cells or 1 for html mode.
  5662. * @public
  5663. * @since 1.3
  5664. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5665. */
  5666. 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) {
  5667. $prev_cell_margin = $this->cell_margin;
  5668. $prev_cell_padding = $this->cell_padding;
  5669. // adjust internal padding
  5670. $this->adjustCellPadding($border);
  5671. $mc_padding = $this->cell_padding;
  5672. $mc_margin = $this->cell_margin;
  5673. $this->cell_padding['T'] = 0;
  5674. $this->cell_padding['B'] = 0;
  5675. $this->setCellMargins(0, 0, 0, 0);
  5676. if ($this->empty_string($this->lasth) OR $reseth) {
  5677. // reset row height
  5678. $this->resetLastH();
  5679. }
  5680. if (!$this->empty_string($y)) {
  5681. $this->SetY($y);
  5682. } else {
  5683. $y = $this->GetY();
  5684. }
  5685. $resth = 0;
  5686. if ((!$this->InFooter) AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5687. // spit cell in more pages/columns
  5688. $newh = $this->PageBreakTrigger - $y;
  5689. $resth = $h - $newh; // cell to be printed on the next page/column
  5690. $h = $newh;
  5691. }
  5692. // get current page number
  5693. $startpage = $this->page;
  5694. // get current column
  5695. $startcolumn = $this->current_column;
  5696. if (!$this->empty_string($x)) {
  5697. $this->SetX($x);
  5698. } else {
  5699. $x = $this->GetX();
  5700. }
  5701. // check page for no-write regions and adapt page margins if necessary
  5702. $this->checkPageRegions(0, $x, $y);
  5703. // apply margins
  5704. $oy = $y + $mc_margin['T'];
  5705. if ($this->rtl) {
  5706. $ox = $this->w - $x - $mc_margin['R'];
  5707. } else {
  5708. $ox = $x + $mc_margin['L'];
  5709. }
  5710. $this->x = $ox;
  5711. $this->y = $oy;
  5712. // set width
  5713. if ($this->empty_string($w) OR ($w <= 0)) {
  5714. if ($this->rtl) {
  5715. $w = $this->x - $this->lMargin - $mc_margin['L'];
  5716. } else {
  5717. $w = $this->w - $this->x - $this->rMargin - $mc_margin['R'];
  5718. }
  5719. }
  5720. // store original margin values
  5721. $lMargin = $this->lMargin;
  5722. $rMargin = $this->rMargin;
  5723. if ($this->rtl) {
  5724. $this->rMargin = $this->w - $this->x;
  5725. $this->lMargin = $this->x - $w;
  5726. } else {
  5727. $this->lMargin = $this->x;
  5728. $this->rMargin = $this->w - $this->x - $w;
  5729. }
  5730. if ($autopadding) {
  5731. // add top padding
  5732. $this->y += $mc_padding['T'];
  5733. }
  5734. if ($ishtml) { // ******* Write HTML text
  5735. $this->writeHTML($txt, true, 0, $reseth, true, $align);
  5736. $nl = 1;
  5737. } else { // ******* Write simple text
  5738. // vertical alignment
  5739. if ($maxh > 0) {
  5740. // get text height
  5741. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5742. if ($fitcell) {
  5743. $prev_FontSizePt = $this->FontSizePt;
  5744. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5745. $fmin = 1;
  5746. $fmax = $this->FontSizePt;
  5747. $prev_text_height = $text_height;
  5748. $maxit = 100; // max number of iterations
  5749. while ($maxit > 0) {
  5750. $fmid = (($fmax + $fmin) / 2);
  5751. $this->SetFontSize($fmid, false);
  5752. $this->resetLastH();
  5753. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5754. if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
  5755. break;
  5756. } elseif ($text_height < $maxh) {
  5757. $fmin = $fmid;
  5758. } else {
  5759. $fmax = $fmid;
  5760. }
  5761. --$maxit;
  5762. }
  5763. $this->SetFontSize($this->FontSizePt);
  5764. }
  5765. if ($text_height < $maxh) {
  5766. if ($valign == 'M') {
  5767. // text vertically centered
  5768. $this->y += (($maxh - $text_height) / 2);
  5769. } elseif ($valign == 'B') {
  5770. // text vertically aligned on bottom
  5771. $this->y += ($maxh - $text_height);
  5772. }
  5773. }
  5774. }
  5775. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5776. if ($fitcell) {
  5777. // restore font size
  5778. $this->SetFontSize($prev_FontSizePt);
  5779. }
  5780. }
  5781. if ($autopadding) {
  5782. // add bottom padding
  5783. $this->y += $mc_padding['B'];
  5784. }
  5785. // Get end-of-text Y position
  5786. $currentY = $this->y;
  5787. // get latest page number
  5788. $endpage = $this->page;
  5789. if ($resth > 0) {
  5790. $skip = ($endpage - $startpage);
  5791. $tmpresth = $resth;
  5792. while ($tmpresth > 0) {
  5793. if ($skip <= 0) {
  5794. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5795. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5796. }
  5797. if ($this->num_columns > 1) {
  5798. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5799. } else {
  5800. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5801. }
  5802. --$skip;
  5803. }
  5804. $currentY = $this->y;
  5805. $endpage = $this->page;
  5806. }
  5807. // get latest column
  5808. $endcolumn = $this->current_column;
  5809. if ($this->num_columns == 0) {
  5810. $this->num_columns = 1;
  5811. }
  5812. // get border modes
  5813. $border_start = $this->getBorderMode($border, $position='start');
  5814. $border_end = $this->getBorderMode($border, $position='end');
  5815. $border_middle = $this->getBorderMode($border, $position='middle');
  5816. // design borders around HTML cells.
  5817. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5818. $ccode = '';
  5819. $this->setPage($page);
  5820. if ($this->num_columns < 2) {
  5821. // single-column mode
  5822. $this->SetX($x);
  5823. $this->y = $this->tMargin;
  5824. }
  5825. // account for margin changes
  5826. if ($page > $startpage) {
  5827. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5828. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5829. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5830. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5831. }
  5832. }
  5833. if ($startpage == $endpage) {
  5834. // single page
  5835. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5836. $this->selectColumn($column);
  5837. if ($this->rtl) {
  5838. $this->x -= $mc_margin['R'];
  5839. } else {
  5840. $this->x += $mc_margin['L'];
  5841. }
  5842. if ($startcolumn == $endcolumn) { // single column
  5843. $cborder = $border;
  5844. $h = max($h, ($currentY - $oy));
  5845. $this->y = $oy;
  5846. } elseif ($column == $startcolumn) { // first column
  5847. $cborder = $border_start;
  5848. $this->y = $oy;
  5849. $h = $this->h - $this->y - $this->bMargin;
  5850. } elseif ($column == $endcolumn) { // end column
  5851. $cborder = $border_end;
  5852. $h = $currentY - $this->y;
  5853. if ($resth > $h) {
  5854. $h = $resth;
  5855. }
  5856. } else { // middle column
  5857. $cborder = $border_middle;
  5858. $h = $this->h - $this->y - $this->bMargin;
  5859. $resth -= $h;
  5860. }
  5861. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5862. } // end for each column
  5863. } elseif ($page == $startpage) { // first page
  5864. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5865. $this->selectColumn($column);
  5866. if ($this->rtl) {
  5867. $this->x -= $mc_margin['R'];
  5868. } else {
  5869. $this->x += $mc_margin['L'];
  5870. }
  5871. if ($column == $startcolumn) { // first column
  5872. $cborder = $border_start;
  5873. $this->y = $oy;
  5874. $h = $this->h - $this->y - $this->bMargin;
  5875. } else { // middle column
  5876. $cborder = $border_middle;
  5877. $h = $this->h - $this->y - $this->bMargin;
  5878. $resth -= $h;
  5879. }
  5880. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5881. } // end for each column
  5882. } elseif ($page == $endpage) { // last page
  5883. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5884. $this->selectColumn($column);
  5885. if ($this->rtl) {
  5886. $this->x -= $mc_margin['R'];
  5887. } else {
  5888. $this->x += $mc_margin['L'];
  5889. }
  5890. if ($column == $endcolumn) {
  5891. // end column
  5892. $cborder = $border_end;
  5893. $h = $currentY - $this->y;
  5894. if ($resth > $h) {
  5895. $h = $resth;
  5896. }
  5897. } else {
  5898. // middle column
  5899. $cborder = $border_middle;
  5900. $h = $this->h - $this->y - $this->bMargin;
  5901. $resth -= $h;
  5902. }
  5903. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5904. } // end for each column
  5905. } else { // middle page
  5906. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5907. $this->selectColumn($column);
  5908. if ($this->rtl) {
  5909. $this->x -= $mc_margin['R'];
  5910. } else {
  5911. $this->x += $mc_margin['L'];
  5912. }
  5913. $cborder = $border_middle;
  5914. $h = $this->h - $this->y - $this->bMargin;
  5915. $resth -= $h;
  5916. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5917. } // end for each column
  5918. }
  5919. if ($cborder OR $fill) {
  5920. // draw border and fill
  5921. if ($this->inxobj) {
  5922. // we are inside an XObject template
  5923. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5924. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5925. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5926. } else {
  5927. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  5928. }
  5929. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5930. $pstart = substr($pagebuff, 0, $pagemark);
  5931. $pend = substr($pagebuff, $pagemark);
  5932. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5933. $pagemark += strlen($ccode);
  5934. } else {
  5935. if (end($this->transfmrk[$this->page]) !== false) {
  5936. $pagemarkkey = key($this->transfmrk[$this->page]);
  5937. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  5938. } elseif ($this->InFooter) {
  5939. $pagemark = &$this->footerpos[$this->page];
  5940. } else {
  5941. $pagemark = &$this->intmrk[$this->page];
  5942. }
  5943. $pagebuff = $this->getPageBuffer($this->page);
  5944. $pstart = substr($pagebuff, 0, $pagemark);
  5945. $pend = substr($pagebuff, $pagemark);
  5946. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5947. $pagemark += strlen($ccode);
  5948. }
  5949. }
  5950. } // end for each page
  5951. // Get end-of-cell Y position
  5952. $currentY = $this->GetY();
  5953. // restore original margin values
  5954. $this->SetLeftMargin($lMargin);
  5955. $this->SetRightMargin($rMargin);
  5956. if ($ln > 0) {
  5957. //Go to the beginning of the next line
  5958. $this->SetY($currentY + $mc_margin['B']);
  5959. if ($ln == 2) {
  5960. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5961. }
  5962. } else {
  5963. // go left or right by case
  5964. $this->setPage($startpage);
  5965. $this->y = $y;
  5966. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5967. }
  5968. $this->setContentMark();
  5969. $this->cell_padding = $prev_cell_padding;
  5970. $this->cell_margin = $prev_cell_margin;
  5971. return $nl;
  5972. }
  5973. /**
  5974. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  5975. * @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)))
  5976. * @param $position (string) multicell position: 'start', 'middle', 'end'
  5977. * @return border mode array
  5978. * @protected
  5979. * @since 4.4.002 (2008-12-09)
  5980. */
  5981. protected function getBorderMode($brd, $position='start') {
  5982. if ((!$this->opencell) OR empty($brd)) {
  5983. return $brd;
  5984. }
  5985. if ($brd == 1) {
  5986. $brd = 'LTRB';
  5987. }
  5988. if (is_string($brd)) {
  5989. // convert string to array
  5990. $slen = strlen($brd);
  5991. $newbrd = array();
  5992. for ($i = 0; $i < $slen; ++$i) {
  5993. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  5994. }
  5995. $brd = $newbrd;
  5996. }
  5997. foreach ($brd as $border => $style) {
  5998. switch ($position) {
  5999. case 'start': {
  6000. if (strpos($border, 'B') !== false) {
  6001. // remove bottom line
  6002. $newkey = str_replace('B', '', $border);
  6003. if (strlen($newkey) > 0) {
  6004. $brd[$newkey] = $style;
  6005. }
  6006. unset($brd[$border]);
  6007. }
  6008. break;
  6009. }
  6010. case 'middle': {
  6011. if (strpos($border, 'B') !== false) {
  6012. // remove bottom line
  6013. $newkey = str_replace('B', '', $border);
  6014. if (strlen($newkey) > 0) {
  6015. $brd[$newkey] = $style;
  6016. }
  6017. unset($brd[$border]);
  6018. $border = $newkey;
  6019. }
  6020. if (strpos($border, 'T') !== false) {
  6021. // remove bottom line
  6022. $newkey = str_replace('T', '', $border);
  6023. if (strlen($newkey) > 0) {
  6024. $brd[$newkey] = $style;
  6025. }
  6026. unset($brd[$border]);
  6027. }
  6028. break;
  6029. }
  6030. case 'end': {
  6031. if (strpos($border, 'T') !== false) {
  6032. // remove bottom line
  6033. $newkey = str_replace('T', '', $border);
  6034. if (strlen($newkey) > 0) {
  6035. $brd[$newkey] = $style;
  6036. }
  6037. unset($brd[$border]);
  6038. }
  6039. break;
  6040. }
  6041. }
  6042. }
  6043. return $brd;
  6044. }
  6045. /**
  6046. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  6047. * @param $txt (string) String for calculating his height
  6048. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6049. * @param $reseth (boolean) if true reset the last cell height (default false).
  6050. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  6051. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  6052. * @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)))
  6053. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  6054. * @author Alexander Escalona Fernández, Nicola Asuni
  6055. * @public
  6056. * @since 4.5.011
  6057. */
  6058. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  6059. if ($txt === '') {
  6060. // empty string
  6061. return 1;
  6062. }
  6063. // adjust internal padding
  6064. $prev_cell_padding = $this->cell_padding;
  6065. $prev_lasth = $this->lasth;
  6066. if (is_array($cellpadding)) {
  6067. $this->cell_padding = $cellpadding;
  6068. }
  6069. $this->adjustCellPadding($border);
  6070. if ($this->empty_string($w) OR ($w <= 0)) {
  6071. if ($this->rtl) {
  6072. $w = $this->x - $this->lMargin;
  6073. } else {
  6074. $w = $this->w - $this->rMargin - $this->x;
  6075. }
  6076. }
  6077. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6078. if ($reseth) {
  6079. // reset row height
  6080. $this->resetLastH();
  6081. }
  6082. $lines = 1;
  6083. $sum = 0;
  6084. $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
  6085. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  6086. $length = count($chars);
  6087. $lastSeparator = -1;
  6088. for ($i = 0; $i < $length; ++$i) {
  6089. $charWidth = $charsWidth[$i];
  6090. if (preg_match($this->re_spaces, $this->unichr($chars[$i]))) {
  6091. $lastSeparator = $i;
  6092. }
  6093. if ((($sum + $charWidth) > $wmax) OR ($chars[$i] == 10)) {
  6094. ++$lines;
  6095. if ($lastSeparator != -1) {
  6096. $i = $lastSeparator;
  6097. $lastSeparator = -1;
  6098. $sum = 0;
  6099. } else {
  6100. $sum = $charWidth;
  6101. }
  6102. } else {
  6103. $sum += $charWidth;
  6104. }
  6105. }
  6106. if ($chars[($length - 1)] == 10) {
  6107. --$lines;
  6108. }
  6109. $this->cell_padding = $prev_cell_padding;
  6110. $this->lasth = $prev_lasth;
  6111. return $lines;
  6112. }
  6113. /**
  6114. * This method return the estimated needed height for print a simple text string in Multicell() method.
  6115. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  6116. * @pre
  6117. * // store current object
  6118. * $pdf->startTransaction();
  6119. * // store starting values
  6120. * $start_y = $pdf->GetY();
  6121. * $start_page = $pdf->getPage();
  6122. * // call your printing functions with your parameters
  6123. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6124. * $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);
  6125. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6126. * // get the new Y
  6127. * $end_y = $pdf->GetY();
  6128. * $end_page = $pdf->getPage();
  6129. * // calculate height
  6130. * $height = 0;
  6131. * if ($end_page == $start_page) {
  6132. * $height = $end_y - $start_y;
  6133. * } else {
  6134. * for ($page=$start_page; $page <= $end_page; ++$page) {
  6135. * $this->setPage($page);
  6136. * if ($page == $start_page) {
  6137. * // first page
  6138. * $height = $this->h - $start_y - $this->bMargin;
  6139. * } elseif ($page == $end_page) {
  6140. * // last page
  6141. * $height = $end_y - $this->tMargin;
  6142. * } else {
  6143. * $height = $this->h - $this->tMargin - $this->bMargin;
  6144. * }
  6145. * }
  6146. * }
  6147. * // restore previous object
  6148. * $pdf = $pdf->rollbackTransaction();
  6149. *
  6150. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  6151. * @param $txt (string) String for calculating his height
  6152. * @param $reseth (boolean) if true reset the last cell height (default false).
  6153. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  6154. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  6155. * @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)))
  6156. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  6157. * @author Nicola Asuni, Alexander Escalona Fernández
  6158. * @public
  6159. */
  6160. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  6161. // adjust internal padding
  6162. $prev_cell_padding = $this->cell_padding;
  6163. $prev_lasth = $this->lasth;
  6164. if (is_array($cellpadding)) {
  6165. $this->cell_padding = $cellpadding;
  6166. }
  6167. $this->adjustCellPadding($border);
  6168. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  6169. $height = $lines * ($this->FontSize * $this->cell_height_ratio);
  6170. if ($autopadding) {
  6171. // add top and bottom padding
  6172. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  6173. }
  6174. $this->cell_padding = $prev_cell_padding;
  6175. $this->lasth = $prev_lasth;
  6176. return $height;
  6177. }
  6178. /**
  6179. * This method prints text from the current position.<br />
  6180. * @param $h (float) Line height
  6181. * @param $txt (string) String to print
  6182. * @param $link (mixed) URL or identifier returned by AddLink()
  6183. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  6184. * @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>
  6185. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  6186. * @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.
  6187. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  6188. * @param $firstblock (boolean) if true the string is the starting of a line.
  6189. * @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.
  6190. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  6191. * @param $margin (array) margin array of the parent container
  6192. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  6193. * @public
  6194. * @since 1.5
  6195. */
  6196. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
  6197. // check page for no-write regions and adapt page margins if necessary
  6198. $this->checkPageRegions($h, $this->x, $this->y);
  6199. if (strlen($txt) == 0) {
  6200. // fix empty text
  6201. $txt = ' ';
  6202. }
  6203. if ($margin === '') {
  6204. // set default margins
  6205. $margin = $this->cell_margin;
  6206. }
  6207. // remove carriage returns
  6208. $s = str_replace("\r", '', $txt);
  6209. // check if string contains arabic text
  6210. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s)) {
  6211. $arabic = true;
  6212. } else {
  6213. $arabic = false;
  6214. }
  6215. // check if string contains RTL text
  6216. if ($arabic OR ($this->tmprtl == 'R') OR preg_match($this->unicode->uni_RE_PATTERN_RTL, $s)) {
  6217. $rtlmode = true;
  6218. } else {
  6219. $rtlmode = false;
  6220. }
  6221. // get a char width
  6222. $chrwidth = $this->GetCharWidth('.');
  6223. // get array of unicode values
  6224. $chars = $this->UTF8StringToArray($s);
  6225. // get array of chars
  6226. $uchars = $this->UTF8ArrayToUniArray($chars);
  6227. // get the number of characters
  6228. $nb = count($chars);
  6229. // replacement for SHY character (minus symbol)
  6230. $shy_replacement = 45;
  6231. $shy_replacement_char = $this->unichr($shy_replacement);
  6232. // widht for SHY replacement
  6233. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  6234. // max Y
  6235. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  6236. // calculate remaining line width ($w)
  6237. if ($this->rtl) {
  6238. $w = $this->x - $this->lMargin;
  6239. } else {
  6240. $w = $this->w - $this->rMargin - $this->x;
  6241. }
  6242. // max column width
  6243. $wmax = $w - $wadj;
  6244. if (!$firstline) {
  6245. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  6246. }
  6247. if ((!$firstline) AND (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax))) {
  6248. // a single character do not fit on column
  6249. return '';
  6250. }
  6251. // minimum row height
  6252. $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
  6253. $start_page = $this->page;
  6254. $i = 0; // character position
  6255. $j = 0; // current starting position
  6256. $sep = -1; // position of the last blank space
  6257. $shy = false; // true if the last blank is a soft hypen (SHY)
  6258. $l = 0; // current string length
  6259. $nl = 0; //number of lines
  6260. $linebreak = false;
  6261. $pc = 0; // previous character
  6262. // for each character
  6263. while ($i < $nb) {
  6264. if (($maxh > 0) AND ($this->y >= $maxy) ) {
  6265. break;
  6266. }
  6267. //Get the current character
  6268. $c = $chars[$i];
  6269. if ($c == 10) { // 10 = "\n" = new line
  6270. //Explicit line break
  6271. if ($align == 'J') {
  6272. if ($this->rtl) {
  6273. $talign = 'R';
  6274. } else {
  6275. $talign = 'L';
  6276. }
  6277. } else {
  6278. $talign = $align;
  6279. }
  6280. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  6281. if ($firstline) {
  6282. $startx = $this->x;
  6283. $tmparr = array_slice($chars, $j, ($i - $j));
  6284. if ($rtlmode) {
  6285. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6286. }
  6287. $linew = $this->GetArrStringWidth($tmparr);
  6288. unset($tmparr);
  6289. if ($this->rtl) {
  6290. $this->endlinex = $startx - $linew;
  6291. } else {
  6292. $this->endlinex = $startx + $linew;
  6293. }
  6294. $w = $linew;
  6295. $tmpcellpadding = $this->cell_padding;
  6296. if ($maxh == 0) {
  6297. $this->SetCellPadding(0);
  6298. }
  6299. }
  6300. if ($firstblock AND $this->isRTLTextDir()) {
  6301. $tmpstr = $this->stringRightTrim($tmpstr);
  6302. }
  6303. // Skip newlines at the begining of a page or column
  6304. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  6305. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  6306. }
  6307. unset($tmpstr);
  6308. if ($firstline) {
  6309. $this->cell_padding = $tmpcellpadding;
  6310. return ($this->UniArrSubString($uchars, $i));
  6311. }
  6312. ++$nl;
  6313. $j = $i + 1;
  6314. $l = 0;
  6315. $sep = -1;
  6316. $shy = false;
  6317. // account for margin changes
  6318. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
  6319. $this->AcceptPageBreak();
  6320. if ($this->rtl) {
  6321. $this->x -= $margin['R'];
  6322. } else {
  6323. $this->x += $margin['L'];
  6324. }
  6325. $this->lMargin += $margin['L'];
  6326. $this->rMargin += $margin['R'];
  6327. }
  6328. $w = $this->getRemainingWidth();
  6329. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6330. } else {
  6331. // 160 is the non-breaking space.
  6332. // 173 is SHY (Soft Hypen).
  6333. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6334. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6335. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6336. if (($c != 160) AND (($c == 173) OR preg_match($this->re_spaces, $this->unichr($c)))) {
  6337. // update last blank space position
  6338. $sep = $i;
  6339. // check if is a SHY
  6340. if ($c == 173) {
  6341. $shy = true;
  6342. if ($pc == 45) {
  6343. $tmp_shy_replacement_width = 0;
  6344. $tmp_shy_replacement_char = '';
  6345. } else {
  6346. $tmp_shy_replacement_width = $shy_replacement_width;
  6347. $tmp_shy_replacement_char = $shy_replacement_char;
  6348. }
  6349. } else {
  6350. $shy = false;
  6351. }
  6352. }
  6353. // update string length
  6354. if ($this->isUnicodeFont() AND ($arabic)) {
  6355. // with bidirectional algorithm some chars may be changed affecting the line length
  6356. // *** very slow ***
  6357. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  6358. } else {
  6359. $l += $this->GetCharWidth($c);
  6360. }
  6361. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) {
  6362. // we have reached the end of column
  6363. if ($sep == -1) {
  6364. // check if the line was already started
  6365. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
  6366. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $chrwidth)))) {
  6367. // print a void cell and go to next line
  6368. $this->Cell($w, $h, '', 0, 1);
  6369. $linebreak = true;
  6370. if ($firstline) {
  6371. return ($this->UniArrSubString($uchars, $j));
  6372. }
  6373. } else {
  6374. // truncate the word because do not fit on column
  6375. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  6376. if ($firstline) {
  6377. $startx = $this->x;
  6378. $tmparr = array_slice($chars, $j, ($i - $j));
  6379. if ($rtlmode) {
  6380. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6381. }
  6382. $linew = $this->GetArrStringWidth($tmparr);
  6383. unset($tmparr);
  6384. if ($this->rtl) {
  6385. $this->endlinex = $startx - $linew;
  6386. } else {
  6387. $this->endlinex = $startx + $linew;
  6388. }
  6389. $w = $linew;
  6390. $tmpcellpadding = $this->cell_padding;
  6391. if ($maxh == 0) {
  6392. $this->SetCellPadding(0);
  6393. }
  6394. }
  6395. if ($firstblock AND $this->isRTLTextDir()) {
  6396. $tmpstr = $this->stringRightTrim($tmpstr);
  6397. }
  6398. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6399. unset($tmpstr);
  6400. if ($firstline) {
  6401. $this->cell_padding = $tmpcellpadding;
  6402. return ($this->UniArrSubString($uchars, $i));
  6403. }
  6404. $j = $i;
  6405. --$i;
  6406. }
  6407. } else {
  6408. // word wrapping
  6409. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6410. $endspace = 1;
  6411. } else {
  6412. $endspace = 0;
  6413. }
  6414. if ($shy) {
  6415. // add hypen (minus symbol) at the end of the line
  6416. $shy_width = $tmp_shy_replacement_width;
  6417. if ($this->rtl) {
  6418. $shy_char_left = $tmp_shy_replacement_char;
  6419. $shy_char_right = '';
  6420. } else {
  6421. $shy_char_left = '';
  6422. $shy_char_right = $tmp_shy_replacement_char;
  6423. }
  6424. } else {
  6425. $shy_width = 0;
  6426. $shy_char_left = '';
  6427. $shy_char_right = '';
  6428. }
  6429. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  6430. if ($firstline) {
  6431. $startx = $this->x;
  6432. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6433. if ($rtlmode) {
  6434. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6435. }
  6436. $linew = $this->GetArrStringWidth($tmparr);
  6437. unset($tmparr);
  6438. if ($this->rtl) {
  6439. $this->endlinex = $startx - $linew - $shy_width;
  6440. } else {
  6441. $this->endlinex = $startx + $linew + $shy_width;
  6442. }
  6443. $w = $linew;
  6444. $tmpcellpadding = $this->cell_padding;
  6445. if ($maxh == 0) {
  6446. $this->SetCellPadding(0);
  6447. }
  6448. }
  6449. // print the line
  6450. if ($firstblock AND $this->isRTLTextDir()) {
  6451. $tmpstr = $this->stringRightTrim($tmpstr);
  6452. }
  6453. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6454. unset($tmpstr);
  6455. if ($firstline) {
  6456. // return the remaining text
  6457. $this->cell_padding = $tmpcellpadding;
  6458. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  6459. }
  6460. $i = $sep;
  6461. $sep = -1;
  6462. $shy = false;
  6463. $j = ($i+1);
  6464. }
  6465. // account for margin changes
  6466. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
  6467. $this->AcceptPageBreak();
  6468. if ($this->rtl) {
  6469. $this->x -= $margin['R'];
  6470. } else {
  6471. $this->x += $margin['L'];
  6472. }
  6473. $this->lMargin += $margin['L'];
  6474. $this->rMargin += $margin['R'];
  6475. }
  6476. $w = $this->getRemainingWidth();
  6477. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6478. if ($linebreak) {
  6479. $linebreak = false;
  6480. } else {
  6481. ++$nl;
  6482. $l = 0;
  6483. }
  6484. }
  6485. }
  6486. // save last character
  6487. $pc = $c;
  6488. ++$i;
  6489. } // end while i < nb
  6490. // print last substring (if any)
  6491. if ($l > 0) {
  6492. switch ($align) {
  6493. case 'J':
  6494. case 'C': {
  6495. $w = $w;
  6496. break;
  6497. }
  6498. case 'L': {
  6499. if ($this->rtl) {
  6500. $w = $w;
  6501. } else {
  6502. $w = $l;
  6503. }
  6504. break;
  6505. }
  6506. case 'R': {
  6507. if ($this->rtl) {
  6508. $w = $l;
  6509. } else {
  6510. $w = $w;
  6511. }
  6512. break;
  6513. }
  6514. default: {
  6515. $w = $l;
  6516. break;
  6517. }
  6518. }
  6519. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  6520. if ($firstline) {
  6521. $startx = $this->x;
  6522. $tmparr = array_slice($chars, $j, ($nb - $j));
  6523. if ($rtlmode) {
  6524. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  6525. }
  6526. $linew = $this->GetArrStringWidth($tmparr);
  6527. unset($tmparr);
  6528. if ($this->rtl) {
  6529. $this->endlinex = $startx - $linew;
  6530. } else {
  6531. $this->endlinex = $startx + $linew;
  6532. }
  6533. $w = $linew;
  6534. $tmpcellpadding = $this->cell_padding;
  6535. if ($maxh == 0) {
  6536. $this->SetCellPadding(0);
  6537. }
  6538. }
  6539. if ($firstblock AND $this->isRTLTextDir()) {
  6540. $tmpstr = $this->stringRightTrim($tmpstr);
  6541. }
  6542. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6543. unset($tmpstr);
  6544. if ($firstline) {
  6545. $this->cell_padding = $tmpcellpadding;
  6546. return ($this->UniArrSubString($uchars, $nb));
  6547. }
  6548. ++$nl;
  6549. }
  6550. if ($firstline) {
  6551. return '';
  6552. }
  6553. return $nl;
  6554. }
  6555. /**
  6556. * Returns the remaining width between the current position and margins.
  6557. * @return int Return the remaining width
  6558. * @protected
  6559. */
  6560. protected function getRemainingWidth() {
  6561. $this->checkPageRegions(0, $this->x, $this->y);
  6562. if ($this->rtl) {
  6563. return ($this->x - $this->lMargin);
  6564. } else {
  6565. return ($this->w - $this->rMargin - $this->x);
  6566. }
  6567. }
  6568. /**
  6569. * Extract a slice of the $strarr array and return it as string.
  6570. * @param $strarr (string) The input array of characters.
  6571. * @param $start (int) the starting element of $strarr.
  6572. * @param $end (int) first element that will not be returned.
  6573. * @return Return part of a string
  6574. * @public
  6575. */
  6576. public function UTF8ArrSubString($strarr, $start='', $end='') {
  6577. if (strlen($start) == 0) {
  6578. $start = 0;
  6579. }
  6580. if (strlen($end) == 0) {
  6581. $end = count($strarr);
  6582. }
  6583. $string = '';
  6584. for ($i=$start; $i < $end; ++$i) {
  6585. $string .= $this->unichr($strarr[$i]);
  6586. }
  6587. return $string;
  6588. }
  6589. /**
  6590. * Extract a slice of the $uniarr array and return it as string.
  6591. * @param $uniarr (string) The input array of characters.
  6592. * @param $start (int) the starting element of $strarr.
  6593. * @param $end (int) first element that will not be returned.
  6594. * @return Return part of a string
  6595. * @public
  6596. * @since 4.5.037 (2009-04-07)
  6597. */
  6598. public function UniArrSubString($uniarr, $start='', $end='') {
  6599. if (strlen($start) == 0) {
  6600. $start = 0;
  6601. }
  6602. if (strlen($end) == 0) {
  6603. $end = count($uniarr);
  6604. }
  6605. $string = '';
  6606. for ($i=$start; $i < $end; ++$i) {
  6607. $string .= $uniarr[$i];
  6608. }
  6609. return $string;
  6610. }
  6611. /**
  6612. * Convert an array of UTF8 values to array of unicode characters
  6613. * @param $ta (string) The input array of UTF8 values.
  6614. * @return Return array of unicode characters
  6615. * @public
  6616. * @since 4.5.037 (2009-04-07)
  6617. */
  6618. public function UTF8ArrayToUniArray($ta) {
  6619. return array_map(array($this, 'unichr'), $ta);
  6620. }
  6621. /**
  6622. * Returns the unicode caracter specified by UTF-8 value
  6623. * @param $c (int) UTF-8 value
  6624. * @return Returns the specified character.
  6625. * @author Miguel Perez, Nicola Asuni
  6626. * @public
  6627. * @since 2.3.000 (2008-03-05)
  6628. */
  6629. public function unichr($c) {
  6630. if (!$this->isunicode) {
  6631. return chr($c);
  6632. } elseif ($c <= 0x7F) {
  6633. // one byte
  6634. return chr($c);
  6635. } elseif ($c <= 0x7FF) {
  6636. // two bytes
  6637. return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
  6638. } elseif ($c <= 0xFFFF) {
  6639. // three bytes
  6640. return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  6641. } elseif ($c <= 0x10FFFF) {
  6642. // four bytes
  6643. return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
  6644. } else {
  6645. return '';
  6646. }
  6647. }
  6648. /**
  6649. * Return the image type given the file name or array returned by getimagesize() function.
  6650. * @param $imgfile (string) image file name
  6651. * @param $iminfo (array) array of image information returned by getimagesize() function.
  6652. * @return string image type
  6653. * @since 4.8.017 (2009-11-27)
  6654. */
  6655. public function getImageFileType($imgfile, $iminfo=array()) {
  6656. $type = '';
  6657. if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
  6658. $mime = explode('/', $iminfo['mime']);
  6659. if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
  6660. $type = strtolower(trim($mime[1]));
  6661. }
  6662. }
  6663. if (empty($type)) {
  6664. $fileinfo = pathinfo($imgfile);
  6665. if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) {
  6666. $type = strtolower(trim($fileinfo['extension']));
  6667. }
  6668. }
  6669. if ($type == 'jpg') {
  6670. $type = 'jpeg';
  6671. }
  6672. return $type;
  6673. }
  6674. /**
  6675. * Set the block dimensions accounting for page breaks and page/column fitting
  6676. * @param $w (float) width
  6677. * @param $h (float) height
  6678. * @param $x (float) X coordinate
  6679. * @param $y (float) Y coodiante
  6680. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  6681. * @protected
  6682. * @since 5.5.009 (2010-07-05)
  6683. */
  6684. protected function fitBlock(&$w, &$h, &$x, &$y, $fitonpage=false) {
  6685. if ($w <= 0) {
  6686. // set maximum width
  6687. $w = ($this->w - $this->lMargin - $this->rMargin);
  6688. }
  6689. if ($h <= 0) {
  6690. // set maximum height
  6691. $h = ($this->PageBreakTrigger - $this->tMargin);
  6692. }
  6693. // resize the block to be vertically contained on a single page or single column
  6694. if ($fitonpage OR $this->AutoPageBreak) {
  6695. $ratio_wh = ($w / $h);
  6696. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6697. $h = $this->PageBreakTrigger - $this->tMargin;
  6698. $w = ($h * $ratio_wh);
  6699. }
  6700. // resize the block to be horizontally contained on a single page or single column
  6701. if ($fitonpage) {
  6702. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6703. if ($w > $maxw) {
  6704. $w = $maxw;
  6705. $h = ($w / $ratio_wh);
  6706. }
  6707. }
  6708. }
  6709. // Check whether we need a new page or new column first as this does not fit
  6710. $prev_x = $this->x;
  6711. $prev_y = $this->y;
  6712. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6713. $y = $this->y;
  6714. if ($this->rtl) {
  6715. $x += ($prev_x - $this->x);
  6716. } else {
  6717. $x += ($this->x - $prev_x);
  6718. }
  6719. }
  6720. // resize the block to be contained on the remaining available page or column space
  6721. if ($fitonpage) {
  6722. $ratio_wh = ($w / $h);
  6723. if (($y + $h) > $this->PageBreakTrigger) {
  6724. $h = $this->PageBreakTrigger - $y;
  6725. $w = ($h * $ratio_wh);
  6726. }
  6727. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6728. $w = $this->w - $this->rMargin - $x;
  6729. $h = ($w / $ratio_wh);
  6730. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6731. $w = $x - $this->lMargin;
  6732. $h = ($w / $ratio_wh);
  6733. }
  6734. }
  6735. }
  6736. /**
  6737. * Puts an image in the page.
  6738. * The upper-left corner must be given.
  6739. * The dimensions can be specified in different ways:<ul>
  6740. * <li>explicit width and height (expressed in user unit)</li>
  6741. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6742. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6743. * 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;
  6744. * The format can be specified explicitly or inferred from the file extension.<br />
  6745. * It is possible to put a link on the image.<br />
  6746. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6747. * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string.
  6748. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6749. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6750. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6751. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6752. * @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.
  6753. * @param $link (mixed) URL or identifier returned by AddLink().
  6754. * @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>
  6755. * @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).
  6756. * @param $dpi (int) dot-per-inch resolution used on resize
  6757. * @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>
  6758. * @param $ismask (boolean) true if this image is a mask, false otherwise
  6759. * @param $imgmask (mixed) image object returned by this function or false
  6760. * @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)))
  6761. * @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).
  6762. * @param $hidden (boolean) if true do not display the image.
  6763. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  6764. * @return image information
  6765. * @public
  6766. * @since 1.1
  6767. */
  6768. 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) {
  6769. if ($x === '') {
  6770. $x = $this->x;
  6771. }
  6772. if ($y === '') {
  6773. $y = $this->y;
  6774. }
  6775. // check page for no-write regions and adapt page margins if necessary
  6776. $this->checkPageRegions($h, $x, $y);
  6777. $cached_file = false; // true when the file is cached
  6778. // check if we are passing an image as file or string
  6779. if ($file{0} === '@') { // image from string
  6780. $imgdata = substr($file, 1);
  6781. $file = tempnam(K_PATH_CACHE, 'img_');
  6782. $fp = fopen($file, 'w');
  6783. fwrite($fp, $imgdata);
  6784. fclose($fp);
  6785. unset($imgdata);
  6786. $cached_file = true;
  6787. $imsize = @getimagesize($file);
  6788. if ($imsize === FALSE) {
  6789. unlink($file);
  6790. $cached_file = false;
  6791. }
  6792. } else { // image file
  6793. // check if is local file
  6794. if (!@file_exists($file)) {
  6795. // encode spaces on filename (file is probably an URL)
  6796. $file = str_replace(' ', '%20', $file);
  6797. }
  6798. // get image dimensions
  6799. $imsize = @getimagesize($file);
  6800. if ($imsize === FALSE) {
  6801. if (function_exists('curl_init')) {
  6802. // try to get remote file data using cURL
  6803. $cs = curl_init(); // curl session
  6804. curl_setopt($cs, CURLOPT_URL, $file);
  6805. curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
  6806. curl_setopt($cs, CURLOPT_FAILONERROR, true);
  6807. curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
  6808. curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
  6809. curl_setopt($cs, CURLOPT_TIMEOUT, 30);
  6810. $imgdata = curl_exec($cs);
  6811. curl_close($cs);
  6812. if($imgdata !== FALSE) {
  6813. // copy image to cache
  6814. $file = tempnam(K_PATH_CACHE, 'img_');
  6815. $fp = fopen($file, 'w');
  6816. fwrite($fp, $imgdata);
  6817. fclose($fp);
  6818. unset($imgdata);
  6819. $cached_file = true;
  6820. $imsize = @getimagesize($file);
  6821. if ($imsize === FALSE) {
  6822. unlink($file);
  6823. $cached_file = false;
  6824. }
  6825. }
  6826. } elseif (($w > 0) AND ($h > 0)) {
  6827. // get measures from specified data
  6828. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6829. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6830. $imsize = array($pw, $ph);
  6831. }
  6832. }
  6833. }
  6834. if ($imsize === FALSE) {
  6835. $this->Error('[Image] Unable to get image: '.$file);
  6836. }
  6837. // get original image width and height in pixels
  6838. list($pixw, $pixh) = $imsize;
  6839. // calculate image width and height on document
  6840. if (($w <= 0) AND ($h <= 0)) {
  6841. // convert image size to document unit
  6842. $w = $this->pixelsToUnits($pixw);
  6843. $h = $this->pixelsToUnits($pixh);
  6844. } elseif ($w <= 0) {
  6845. $w = $h * $pixw / $pixh;
  6846. } elseif ($h <= 0) {
  6847. $h = $w * $pixh / $pixw;
  6848. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6849. if (strlen($fitbox) !== 2) {
  6850. // set default alignment
  6851. $fitbox = '--';
  6852. }
  6853. // scale image dimensions proportionally to fit within the ($w, $h) box
  6854. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6855. // store current height
  6856. $oldh = $h;
  6857. // calculate new height
  6858. $h = $w * $pixh / $pixw;
  6859. // height difference
  6860. $hdiff = ($oldh - $h);
  6861. // vertical alignment
  6862. switch (strtoupper($fitbox{1})) {
  6863. case 'T': {
  6864. break;
  6865. }
  6866. case 'M': {
  6867. $y += ($hdiff / 2);
  6868. break;
  6869. }
  6870. case 'B': {
  6871. $y += $hdiff;
  6872. break;
  6873. }
  6874. }
  6875. } else {
  6876. // store current width
  6877. $oldw = $w;
  6878. // calculate new width
  6879. $w = $h * $pixw / $pixh;
  6880. // width difference
  6881. $wdiff = ($oldw - $w);
  6882. // horizontal alignment
  6883. switch (strtoupper($fitbox{0})) {
  6884. case 'L': {
  6885. if ($this->rtl) {
  6886. $x -= $wdiff;
  6887. }
  6888. break;
  6889. }
  6890. case 'C': {
  6891. if ($this->rtl) {
  6892. $x -= ($wdiff / 2);
  6893. } else {
  6894. $x += ($wdiff / 2);
  6895. }
  6896. break;
  6897. }
  6898. case 'R': {
  6899. if (!$this->rtl) {
  6900. $x += $wdiff;
  6901. }
  6902. break;
  6903. }
  6904. }
  6905. }
  6906. }
  6907. // fit the image on available space
  6908. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6909. // calculate new minimum dimensions in pixels
  6910. $neww = round($w * $this->k * $dpi / $this->dpi);
  6911. $newh = round($h * $this->k * $dpi / $this->dpi);
  6912. // check if resize is necessary (resize is used only to reduce the image)
  6913. $newsize = ($neww * $newh);
  6914. $pixsize = ($pixw * $pixh);
  6915. if (intval($resize) == 2) {
  6916. $resize = true;
  6917. } elseif ($newsize >= $pixsize) {
  6918. $resize = false;
  6919. }
  6920. // check if image has been already added on document
  6921. $newimage = true;
  6922. if (in_array($file, $this->imagekeys)) {
  6923. $newimage = false;
  6924. // get existing image data
  6925. $info = $this->getImageBuffer($file);
  6926. // check if the newer image is larger
  6927. $oldsize = ($info['w'] * $info['h']);
  6928. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6929. $newimage = true;
  6930. }
  6931. }
  6932. if ($newimage) {
  6933. //First use of image, get info
  6934. $type = strtolower($type);
  6935. if ($type == '') {
  6936. $type = $this->getImageFileType($file, $imsize);
  6937. } elseif ($type == 'jpg') {
  6938. $type = 'jpeg';
  6939. }
  6940. $mqr = $this->get_mqr();
  6941. $this->set_mqr(false);
  6942. // Specific image handlers
  6943. $mtd = '_parse'.$type;
  6944. // GD image handler function
  6945. $gdfunction = 'imagecreatefrom'.$type;
  6946. $info = false;
  6947. if ((method_exists($this, $mtd)) AND (!($resize AND function_exists($gdfunction)))) {
  6948. // TCPDF image functions
  6949. $info = $this->$mtd($file);
  6950. if ($info == 'pngalpha') {
  6951. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign);
  6952. }
  6953. }
  6954. if (!$info) {
  6955. if (function_exists($gdfunction)) {
  6956. // GD library
  6957. $img = $gdfunction($file);
  6958. if ($resize) {
  6959. $imgr = imagecreatetruecolor($neww, $newh);
  6960. if (($type == 'gif') OR ($type == 'png')) {
  6961. $imgr = $this->_setGDImageTransparency($imgr, $img);
  6962. }
  6963. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6964. if (($type == 'gif') OR ($type == 'png')) {
  6965. $info = $this->_toPNG($imgr);
  6966. } else {
  6967. $info = $this->_toJPEG($imgr);
  6968. }
  6969. } else {
  6970. if (($type == 'gif') OR ($type == 'png')) {
  6971. $info = $this->_toPNG($img);
  6972. } else {
  6973. $info = $this->_toJPEG($img);
  6974. }
  6975. }
  6976. } elseif (extension_loaded('imagick')) {
  6977. // ImageMagick library
  6978. $img = new Imagick();
  6979. if ($type == 'SVG') {
  6980. // get SVG file content
  6981. $svgimg = file_get_contents($file);
  6982. // get width and height
  6983. $regs = array();
  6984. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6985. $svgtag = $regs[1];
  6986. $tmp = array();
  6987. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6988. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6989. $owu = sprintf('%.3F', ($ow * $dpi / 72)).$this->pdfunit;
  6990. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6991. } else {
  6992. $ow = $w;
  6993. }
  6994. $tmp = array();
  6995. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6996. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6997. $ohu = sprintf('%.3F', ($oh * $dpi / 72)).$this->pdfunit;
  6998. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  6999. } else {
  7000. $oh = $h;
  7001. }
  7002. $tmp = array();
  7003. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  7004. $vbw = ($ow * $this->imgscale * $this->k);
  7005. $vbh = ($oh * $this->imgscale * $this->k);
  7006. $vbox = sprintf(' viewBox="0 0 %.3F %.3F" ', $vbw, $vbh);
  7007. $svgtag = $vbox.$svgtag;
  7008. }
  7009. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  7010. }
  7011. $img->readImageBlob($svgimg);
  7012. } else {
  7013. $img->readImage($file);
  7014. }
  7015. if ($resize) {
  7016. $img->resizeImage($neww, $newh, 10, 1, false);
  7017. }
  7018. $img->setCompressionQuality($this->jpeg_quality);
  7019. $img->setImageFormat('jpeg');
  7020. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7021. $img->writeImage($tempname);
  7022. $info = $this->_parsejpeg($tempname);
  7023. unlink($tempname);
  7024. $img->destroy();
  7025. } else {
  7026. return;
  7027. }
  7028. }
  7029. if ($info === false) {
  7030. //If false, we cannot process image
  7031. return;
  7032. }
  7033. $this->set_mqr($mqr);
  7034. if ($ismask) {
  7035. // force grayscale
  7036. $info['cs'] = 'DeviceGray';
  7037. }
  7038. $info['i'] = $this->numimages;
  7039. if (!in_array($file, $this->imagekeys)) {
  7040. ++$info['i'];
  7041. }
  7042. if ($imgmask !== false) {
  7043. $info['masked'] = $imgmask;
  7044. }
  7045. // add image to document
  7046. $this->setImageBuffer($file, $info);
  7047. }
  7048. if ($cached_file) {
  7049. // remove cached file
  7050. unlink($file);
  7051. }
  7052. // set alignment
  7053. $this->img_rb_y = $y + $h;
  7054. // set alignment
  7055. if ($this->rtl) {
  7056. if ($palign == 'L') {
  7057. $ximg = $this->lMargin;
  7058. } elseif ($palign == 'C') {
  7059. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  7060. } elseif ($palign == 'R') {
  7061. $ximg = $this->w - $this->rMargin - $w;
  7062. } else {
  7063. $ximg = $x - $w;
  7064. }
  7065. $this->img_rb_x = $ximg;
  7066. } else {
  7067. if ($palign == 'L') {
  7068. $ximg = $this->lMargin;
  7069. } elseif ($palign == 'C') {
  7070. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  7071. } elseif ($palign == 'R') {
  7072. $ximg = $this->w - $this->rMargin - $w;
  7073. } else {
  7074. $ximg = $x;
  7075. }
  7076. $this->img_rb_x = $ximg + $w;
  7077. }
  7078. if ($ismask OR $hidden) {
  7079. // image is not displayed
  7080. return $info['i'];
  7081. }
  7082. $xkimg = $ximg * $this->k;
  7083. $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  7084. if (!empty($border)) {
  7085. $bx = $this->x;
  7086. $by = $this->y;
  7087. $this->x = $ximg;
  7088. if ($this->rtl) {
  7089. $this->x += $w;
  7090. }
  7091. $this->y = $y;
  7092. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  7093. $this->x = $bx;
  7094. $this->y = $by;
  7095. }
  7096. if ($link) {
  7097. $this->Link($ximg, $y, $w, $h, $link, 0);
  7098. }
  7099. // set pointer to align the next text/objects
  7100. switch($align) {
  7101. case 'T': {
  7102. $this->y = $y;
  7103. $this->x = $this->img_rb_x;
  7104. break;
  7105. }
  7106. case 'M': {
  7107. $this->y = $y + round($h/2);
  7108. $this->x = $this->img_rb_x;
  7109. break;
  7110. }
  7111. case 'B': {
  7112. $this->y = $this->img_rb_y;
  7113. $this->x = $this->img_rb_x;
  7114. break;
  7115. }
  7116. case 'N': {
  7117. $this->SetY($this->img_rb_y);
  7118. break;
  7119. }
  7120. default:{
  7121. break;
  7122. }
  7123. }
  7124. $this->endlinex = $this->img_rb_x;
  7125. if ($this->inxobj) {
  7126. // we are inside an XObject template
  7127. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  7128. }
  7129. return $info['i'];
  7130. }
  7131. /**
  7132. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  7133. * @param $mqr (boolean) FALSE for off, TRUE for on.
  7134. * @since 4.6.025 (2009-08-17)
  7135. */
  7136. public function set_mqr($mqr) {
  7137. if(!defined('PHP_VERSION_ID')) {
  7138. $version = PHP_VERSION;
  7139. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  7140. }
  7141. if (PHP_VERSION_ID < 50300) {
  7142. @set_magic_quotes_runtime($mqr);
  7143. }
  7144. }
  7145. /**
  7146. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  7147. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  7148. * @since 4.6.025 (2009-08-17)
  7149. */
  7150. public function get_mqr() {
  7151. if(!defined('PHP_VERSION_ID')) {
  7152. $version = PHP_VERSION;
  7153. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  7154. }
  7155. if (PHP_VERSION_ID < 50300) {
  7156. return @get_magic_quotes_runtime();
  7157. }
  7158. return 0;
  7159. }
  7160. /**
  7161. * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
  7162. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  7163. * @param $image (image) Image object.
  7164. * return image JPEG image object.
  7165. * @protected
  7166. */
  7167. protected function _toJPEG($image) {
  7168. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7169. imagejpeg($image, $tempname, $this->jpeg_quality);
  7170. imagedestroy($image);
  7171. $retvars = $this->_parsejpeg($tempname);
  7172. // tidy up by removing temporary image
  7173. unlink($tempname);
  7174. return $retvars;
  7175. }
  7176. /**
  7177. * Convert the loaded image to a PNG and then return a structure for the PDF creator.
  7178. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  7179. * @param $image (image) Image object.
  7180. * return image PNG image object.
  7181. * @protected
  7182. * @since 4.9.016 (2010-04-20)
  7183. */
  7184. protected function _toPNG($image) {
  7185. // set temporary image file name
  7186. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  7187. // turn off interlaced mode
  7188. imageinterlace($image, 0);
  7189. // create temporary PNG image
  7190. imagepng($image, $tempname);
  7191. // remove image from memory
  7192. imagedestroy($image);
  7193. // get PNG image data
  7194. $retvars = $this->_parsepng($tempname);
  7195. // tidy up by removing temporary image
  7196. unlink($tempname);
  7197. return $retvars;
  7198. }
  7199. /**
  7200. * Set the transparency for the given GD image.
  7201. * @param $new_image (image) GD image object
  7202. * @param $image (image) GD image object.
  7203. * return GD image object.
  7204. * @protected
  7205. * @since 4.9.016 (2010-04-20)
  7206. */
  7207. protected function _setGDImageTransparency($new_image, $image) {
  7208. // transparency index
  7209. $tid = imagecolortransparent($image);
  7210. // default transparency color
  7211. $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
  7212. if ($tid >= 0) {
  7213. // get the colors for the transparency index
  7214. $tcol = imagecolorsforindex($image, $tid);
  7215. }
  7216. $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
  7217. imagefill($new_image, 0, 0, $tid);
  7218. imagecolortransparent($new_image, $tid);
  7219. return $new_image;
  7220. }
  7221. /**
  7222. * Extract info from a JPEG file without using the GD library.
  7223. * @param $file (string) image file to parse
  7224. * @return array structure containing the image data
  7225. * @protected
  7226. */
  7227. protected function _parsejpeg($file) {
  7228. $a = getimagesize($file);
  7229. if (empty($a)) {
  7230. $this->Error('Missing or incorrect image file: '.$file);
  7231. }
  7232. if ($a[2] != 2) {
  7233. $this->Error('Not a JPEG file: '.$file);
  7234. }
  7235. if ((!isset($a['channels'])) OR ($a['channels'] == 3)) {
  7236. $colspace = 'DeviceRGB';
  7237. } elseif ($a['channels'] == 4) {
  7238. $colspace = 'DeviceCMYK';
  7239. } else {
  7240. $colspace = 'DeviceGray';
  7241. }
  7242. $bpc = isset($a['bits']) ? $a['bits'] : 8;
  7243. $data = file_get_contents($file);
  7244. return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
  7245. }
  7246. /**
  7247. * Extract info from a PNG file without using the GD library.
  7248. * @param $file (string) image file to parse
  7249. * @return array structure containing the image data
  7250. * @protected
  7251. */
  7252. protected function _parsepng($file) {
  7253. $f = fopen($file, 'rb');
  7254. if ($f === false) {
  7255. $this->Error('Can\'t open image file: '.$file);
  7256. }
  7257. //Check signature
  7258. if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  7259. $this->Error('Not a PNG file: '.$file);
  7260. }
  7261. //Read header chunk
  7262. fread($f, 4);
  7263. if (fread($f, 4) != 'IHDR') {
  7264. $this->Error('Incorrect PNG file: '.$file);
  7265. }
  7266. $w = $this->_freadint($f);
  7267. $h = $this->_freadint($f);
  7268. $bpc = ord(fread($f, 1));
  7269. if ($bpc > 8) {
  7270. //$this->Error('16-bit depth not supported: '.$file);
  7271. fclose($f);
  7272. return false;
  7273. }
  7274. $ct = ord(fread($f, 1));
  7275. if ($ct == 0) {
  7276. $colspace = 'DeviceGray';
  7277. } elseif ($ct == 2) {
  7278. $colspace = 'DeviceRGB';
  7279. } elseif ($ct == 3) {
  7280. $colspace = 'Indexed';
  7281. } else {
  7282. // alpha channel
  7283. fclose($f);
  7284. return 'pngalpha';
  7285. }
  7286. if (ord(fread($f, 1)) != 0) {
  7287. //$this->Error('Unknown compression method: '.$file);
  7288. fclose($f);
  7289. return false;
  7290. }
  7291. if (ord(fread($f, 1)) != 0) {
  7292. //$this->Error('Unknown filter method: '.$file);
  7293. fclose($f);
  7294. return false;
  7295. }
  7296. if (ord(fread($f, 1)) != 0) {
  7297. //$this->Error('Interlacing not supported: '.$file);
  7298. fclose($f);
  7299. return false;
  7300. }
  7301. fread($f, 4);
  7302. $parms = '/DecodeParms << /Predictor 15 /Colors '.($ct == 2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
  7303. //Scan chunks looking for palette, transparency and image data
  7304. $pal = '';
  7305. $trns = '';
  7306. $data = '';
  7307. do {
  7308. $n = $this->_freadint($f);
  7309. $type = fread($f, 4);
  7310. if ($type == 'PLTE') {
  7311. //Read palette
  7312. $pal = $this->rfread($f, $n);
  7313. fread($f, 4);
  7314. } elseif ($type == 'tRNS') {
  7315. //Read transparency info
  7316. $t = $this->rfread($f, $n);
  7317. if ($ct == 0) {
  7318. $trns = array(ord(substr($t, 1, 1)));
  7319. } elseif ($ct == 2) {
  7320. $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
  7321. } else {
  7322. $pos = strpos($t, chr(0));
  7323. if ($pos !== false) {
  7324. $trns = array($pos);
  7325. }
  7326. }
  7327. fread($f, 4);
  7328. } elseif ($type == 'IDAT') {
  7329. //Read image data block
  7330. $data .= $this->rfread($f, $n);
  7331. fread($f, 4);
  7332. } elseif ($type == 'IEND') {
  7333. break;
  7334. } else {
  7335. $this->rfread($f, $n + 4);
  7336. }
  7337. } while ($n);
  7338. if (($colspace == 'Indexed') AND (empty($pal))) {
  7339. //$this->Error('Missing palette in '.$file);
  7340. fclose($f);
  7341. return false;
  7342. }
  7343. fclose($f);
  7344. return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  7345. }
  7346. /**
  7347. * Binary-safe and URL-safe file read.
  7348. * 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.
  7349. * @param $handle (resource)
  7350. * @param $length (int)
  7351. * @return Returns the read string or FALSE in case of error.
  7352. * @author Nicola Asuni
  7353. * @protected
  7354. * @since 4.5.027 (2009-03-16)
  7355. */
  7356. protected function rfread($handle, $length) {
  7357. $data = fread($handle, $length);
  7358. if ($data === false) {
  7359. return false;
  7360. }
  7361. $rest = $length - strlen($data);
  7362. if ($rest > 0) {
  7363. $data .= $this->rfread($handle, $rest);
  7364. }
  7365. return $data;
  7366. }
  7367. /**
  7368. * Extract info from a PNG image with alpha channel using the GD library.
  7369. * @param $file (string) Name of the file containing the image.
  7370. * @param $x (float) Abscissa of the upper-left corner.
  7371. * @param $y (float) Ordinate of the upper-left corner.
  7372. * @param $wpx (float) Original width of the image in pixels.
  7373. * @param $hpx (float) original height of the image in pixels.
  7374. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7375. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  7376. * @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.
  7377. * @param $link (mixed) URL or identifier returned by AddLink().
  7378. * @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>
  7379. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  7380. * @param $dpi (int) dot-per-inch resolution used on resize
  7381. * @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>
  7382. * @author Nicola Asuni
  7383. * @protected
  7384. * @since 4.3.007 (2008-12-04)
  7385. * @see Image()
  7386. */
  7387. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign) {
  7388. // create temp image file (without alpha channel)
  7389. $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_');
  7390. // create temp alpha file
  7391. $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_');
  7392. if (extension_loaded('imagick')) { // ImageMagick
  7393. // ImageMagick library
  7394. $img = new Imagick();
  7395. $img->readImage($file);
  7396. // clone image object
  7397. $imga = $img->clone();
  7398. // extract alpha channel
  7399. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  7400. $img->negateImage(true);
  7401. $img->setImageFormat('png');
  7402. $img->writeImage($tempfile_alpha);
  7403. // remove alpha channel
  7404. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  7405. $imga->setImageFormat('png');
  7406. $imga->writeImage($tempfile_plain);
  7407. } else { // GD library
  7408. // generate images
  7409. $img = imagecreatefrompng($file);
  7410. $imgalpha = imagecreate($wpx, $hpx);
  7411. // generate gray scale palette (0 -> 255)
  7412. for ($c = 0; $c < 256; ++$c) {
  7413. ImageColorAllocate($imgalpha, $c, $c, $c);
  7414. }
  7415. // extract alpha channel
  7416. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  7417. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  7418. $color = imagecolorat($img, $xpx, $ypx);
  7419. $alpha = ($color >> 24); // shifts off the first 24 bits (where 8x3 are used for each color), and returns the remaining 7 allocated bits (commonly used for alpha)
  7420. $alpha = (((127 - $alpha) / 127) * 255); // GD alpha is only 7 bit (0 -> 127)
  7421. $alpha = $this->getGDgamma($alpha); // correct gamma
  7422. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  7423. }
  7424. }
  7425. imagepng($imgalpha, $tempfile_alpha);
  7426. imagedestroy($imgalpha);
  7427. // extract image without alpha channel
  7428. $imgplain = imagecreatetruecolor($wpx, $hpx);
  7429. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  7430. imagepng($imgplain, $tempfile_plain);
  7431. imagedestroy($imgplain);
  7432. }
  7433. // embed mask image
  7434. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  7435. // embed image, masked with previously embedded mask
  7436. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  7437. // remove temp files
  7438. unlink($tempfile_alpha);
  7439. unlink($tempfile_plain);
  7440. }
  7441. /**
  7442. * Correct the gamma value to be used with GD library
  7443. * @param $v (float) the gamma value to be corrected
  7444. * @protected
  7445. * @since 4.3.007 (2008-12-04)
  7446. */
  7447. protected function getGDgamma($v) {
  7448. return (pow(($v / 255), 2.2) * 255);
  7449. }
  7450. /**
  7451. * Performs a line break.
  7452. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  7453. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  7454. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  7455. * @public
  7456. * @since 1.0
  7457. * @see Cell()
  7458. */
  7459. public function Ln($h='', $cell=false) {
  7460. 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'])) {
  7461. // revove vertical space from the top of the column
  7462. return;
  7463. }
  7464. if ($cell) {
  7465. if ($this->rtl) {
  7466. $cellpadding = $this->cell_padding['R'];
  7467. } else {
  7468. $cellpadding = $this->cell_padding['L'];
  7469. }
  7470. } else {
  7471. $cellpadding = 0;
  7472. }
  7473. if ($this->rtl) {
  7474. $this->x = $this->w - $this->rMargin - $cellpadding;
  7475. } else {
  7476. $this->x = $this->lMargin + $cellpadding;
  7477. }
  7478. if (is_string($h)) {
  7479. $this->y += $this->lasth;
  7480. } else {
  7481. $this->y += $h;
  7482. }
  7483. $this->newline = true;
  7484. }
  7485. /**
  7486. * Returns the relative X value of current position.
  7487. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  7488. * @return float
  7489. * @public
  7490. * @since 1.2
  7491. * @see SetX(), GetY(), SetY()
  7492. */
  7493. public function GetX() {
  7494. //Get x position
  7495. if ($this->rtl) {
  7496. return ($this->w - $this->x);
  7497. } else {
  7498. return $this->x;
  7499. }
  7500. }
  7501. /**
  7502. * Returns the absolute X value of current position.
  7503. * @return float
  7504. * @public
  7505. * @since 1.2
  7506. * @see SetX(), GetY(), SetY()
  7507. */
  7508. public function GetAbsX() {
  7509. return $this->x;
  7510. }
  7511. /**
  7512. * Returns the ordinate of the current position.
  7513. * @return float
  7514. * @public
  7515. * @since 1.0
  7516. * @see SetY(), GetX(), SetX()
  7517. */
  7518. public function GetY() {
  7519. return $this->y;
  7520. }
  7521. /**
  7522. * Defines the abscissa of the current position.
  7523. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7524. * @param $x (float) The value of the abscissa.
  7525. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7526. * @public
  7527. * @since 1.2
  7528. * @see GetX(), GetY(), SetY(), SetXY()
  7529. */
  7530. public function SetX($x, $rtloff=false) {
  7531. if (!$rtloff AND $this->rtl) {
  7532. if ($x >= 0) {
  7533. $this->x = $this->w - $x;
  7534. } else {
  7535. $this->x = abs($x);
  7536. }
  7537. } else {
  7538. if ($x >= 0) {
  7539. $this->x = $x;
  7540. } else {
  7541. $this->x = $this->w + $x;
  7542. }
  7543. }
  7544. if ($this->x < 0) {
  7545. $this->x = 0;
  7546. }
  7547. if ($this->x > $this->w) {
  7548. $this->x = $this->w;
  7549. }
  7550. }
  7551. /**
  7552. * Moves the current abscissa back to the left margin and sets the ordinate.
  7553. * If the passed value is negative, it is relative to the bottom of the page.
  7554. * @param $y (float) The value of the ordinate.
  7555. * @param $resetx (bool) if true (default) reset the X position.
  7556. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7557. * @public
  7558. * @since 1.0
  7559. * @see GetX(), GetY(), SetY(), SetXY()
  7560. */
  7561. public function SetY($y, $resetx=true, $rtloff=false) {
  7562. if ($resetx) {
  7563. //reset x
  7564. if (!$rtloff AND $this->rtl) {
  7565. $this->x = $this->w - $this->rMargin;
  7566. } else {
  7567. $this->x = $this->lMargin;
  7568. }
  7569. }
  7570. if ($y >= 0) {
  7571. $this->y = $y;
  7572. } else {
  7573. $this->y = $this->h + $y;
  7574. }
  7575. if ($this->y < 0) {
  7576. $this->y = 0;
  7577. }
  7578. if ($this->y > $this->h) {
  7579. $this->y = $this->h;
  7580. }
  7581. }
  7582. /**
  7583. * Defines the abscissa and ordinate of the current position.
  7584. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7585. * @param $x (float) The value of the abscissa.
  7586. * @param $y (float) The value of the ordinate.
  7587. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7588. * @public
  7589. * @since 1.2
  7590. * @see SetX(), SetY()
  7591. */
  7592. public function SetXY($x, $y, $rtloff=false) {
  7593. $this->SetY($y, false, $rtloff);
  7594. $this->SetX($x, $rtloff);
  7595. }
  7596. /**
  7597. * Send the document to a given destination: string, local file or browser.
  7598. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7599. * The method first calls Close() if necessary to terminate the document.
  7600. * @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.
  7601. * @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>
  7602. * @public
  7603. * @since 1.0
  7604. * @see Close()
  7605. */
  7606. public function Output($name='doc.pdf', $dest='I') {
  7607. //Output PDF to some destination
  7608. //Finish document if necessary
  7609. if ($this->state < 3) {
  7610. $this->Close();
  7611. }
  7612. //Normalize parameters
  7613. if (is_bool($dest)) {
  7614. $dest = $dest ? 'D' : 'F';
  7615. }
  7616. $dest = strtoupper($dest);
  7617. if ($dest{0} != 'F') {
  7618. $name = preg_replace('/[\s]+/', '_', $name);
  7619. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  7620. }
  7621. if ($this->sign) {
  7622. // *** apply digital signature to the document ***
  7623. // get the document content
  7624. $pdfdoc = $this->getBuffer();
  7625. // remove last newline
  7626. $pdfdoc = substr($pdfdoc, 0, -1);
  7627. // Remove the original buffer
  7628. if (isset($this->diskcache) AND $this->diskcache) {
  7629. // remove buffer file from cache
  7630. unlink($this->buffer);
  7631. }
  7632. unset($this->buffer);
  7633. // remove filler space
  7634. $byterange_string_len = strlen($this->byterange_string);
  7635. // define the ByteRange
  7636. $byte_range = array();
  7637. $byte_range[0] = 0;
  7638. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  7639. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7640. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7641. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7642. // replace the ByteRange
  7643. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7644. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7645. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  7646. // write the document to a temporary folder
  7647. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  7648. $f = fopen($tempdoc, 'wb');
  7649. if (!$f) {
  7650. $this->Error('Unable to create temporary file: '.$tempdoc);
  7651. }
  7652. $pdfdoc_length = strlen($pdfdoc);
  7653. fwrite($f, $pdfdoc, $pdfdoc_length);
  7654. fclose($f);
  7655. // get digital signature via openssl library
  7656. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  7657. if (empty($this->signature_data['extracerts'])) {
  7658. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7659. } else {
  7660. 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']);
  7661. }
  7662. unlink($tempdoc);
  7663. // read signature
  7664. $signature = file_get_contents($tempsign);
  7665. unlink($tempsign);
  7666. // extract signature
  7667. $signature = substr($signature, $pdfdoc_length);
  7668. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7669. $tmparr = explode("\n\n", $signature);
  7670. $signature = $tmparr[1];
  7671. unset($tmparr);
  7672. // decode signature
  7673. $signature = base64_decode(trim($signature));
  7674. // convert signature to hex
  7675. $signature = current(unpack('H*', $signature));
  7676. $signature = str_pad($signature, $this->signature_max_length, '0');
  7677. // Add signature to the document
  7678. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7679. $this->diskcache = false;
  7680. $this->buffer = &$pdfdoc;
  7681. $this->bufferlen = strlen($pdfdoc);
  7682. }
  7683. switch($dest) {
  7684. case 'I': {
  7685. // Send PDF to the standard output
  7686. if (ob_get_contents()) {
  7687. $this->Error('Some data has already been output, can\'t send PDF file');
  7688. }
  7689. if (php_sapi_name() != 'cli') {
  7690. //We send to a browser
  7691. header('Content-Type: application/pdf');
  7692. if (headers_sent()) {
  7693. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7694. }
  7695. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7696. header('Pragma: public');
  7697. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7698. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7699. header('Content-Length: '.$this->bufferlen);
  7700. header('Content-Disposition: inline; filename="'.basename($name).'";');
  7701. }
  7702. echo $this->getBuffer();
  7703. break;
  7704. }
  7705. case 'D': {
  7706. // Download PDF as file
  7707. if (ob_get_contents()) {
  7708. $this->Error('Some data has already been output, can\'t send PDF file');
  7709. }
  7710. header('Content-Description: File Transfer');
  7711. if (headers_sent()) {
  7712. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7713. }
  7714. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7715. header('Pragma: public');
  7716. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7717. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7718. // force download dialog
  7719. if (strpos(php_sapi_name(), 'cgi') === false) {
  7720. header('Content-Type: application/force-download');
  7721. header('Content-Type: application/octet-stream', false);
  7722. header('Content-Type: application/download', false);
  7723. header('Content-Type: application/pdf', false);
  7724. } else {
  7725. header('Content-Type: application/pdf');
  7726. }
  7727. // use the Content-Disposition header to supply a recommended filename
  7728. header('Content-Disposition: attachment; filename="'.basename($name).'";');
  7729. header('Content-Transfer-Encoding: binary');
  7730. header('Content-Length: '.$this->bufferlen);
  7731. echo $this->getBuffer();
  7732. break;
  7733. }
  7734. case 'F':
  7735. case 'FI':
  7736. case 'FD': {
  7737. // Save PDF to a local file
  7738. if ($this->diskcache) {
  7739. copy($this->buffer, $name);
  7740. } else {
  7741. $f = fopen($name, 'wb');
  7742. if (!$f) {
  7743. $this->Error('Unable to create output file: '.$name);
  7744. }
  7745. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7746. fclose($f);
  7747. }
  7748. if ($dest == 'FI') {
  7749. // send headers to browser
  7750. header('Content-Type: application/pdf');
  7751. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7752. header('Pragma: public');
  7753. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7754. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7755. header('Content-Length: '.filesize($name));
  7756. header('Content-Disposition: inline; filename="'.basename($name).'";');
  7757. // send document to the browser
  7758. echo file_get_contents($name);
  7759. } elseif ($dest == 'FD') {
  7760. // send headers to browser
  7761. if (ob_get_contents()) {
  7762. $this->Error('Some data has already been output, can\'t send PDF file');
  7763. }
  7764. header('Content-Description: File Transfer');
  7765. if (headers_sent()) {
  7766. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7767. }
  7768. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7769. header('Pragma: public');
  7770. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7771. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7772. // force download dialog
  7773. if (strpos(php_sapi_name(), 'cgi') === false) {
  7774. header('Content-Type: application/force-download');
  7775. header('Content-Type: application/octet-stream', false);
  7776. header('Content-Type: application/download', false);
  7777. header('Content-Type: application/pdf', false);
  7778. } else {
  7779. header('Content-Type: application/pdf');
  7780. }
  7781. // use the Content-Disposition header to supply a recommended filename
  7782. header('Content-Disposition: attachment; filename="'.basename($name).'";');
  7783. header('Content-Transfer-Encoding: binary');
  7784. header('Content-Length: '.filesize($name));
  7785. // send document to the browser
  7786. echo file_get_contents($name);
  7787. }
  7788. break;
  7789. }
  7790. case 'E': {
  7791. // Return PDF as base64 mime multi-part email attachment (RFC 2045)
  7792. $retval = 'Content-Type: application/pdf;'."\r\n";
  7793. $retval .= ' name="'.$name.'"'."\r\n";
  7794. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7795. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7796. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7797. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7798. return $retval;
  7799. }
  7800. case 'S': {
  7801. // Returns PDF as a string
  7802. return $this->getBuffer();
  7803. }
  7804. default: {
  7805. $this->Error('Incorrect output destination: '.$dest);
  7806. }
  7807. }
  7808. return '';
  7809. }
  7810. /**
  7811. * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  7812. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  7813. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  7814. * @public
  7815. * @since 4.5.016 (2009-02-24)
  7816. */
  7817. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  7818. if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) {
  7819. // remove buffer file from cache
  7820. unlink($this->buffer);
  7821. }
  7822. foreach (array_keys(get_object_vars($this)) as $val) {
  7823. if ($destroyall OR (
  7824. ($val != 'internal_encoding')
  7825. AND ($val != 'state')
  7826. AND ($val != 'bufferlen')
  7827. AND ($val != 'buffer')
  7828. AND ($val != 'diskcache')
  7829. AND ($val != 'sign')
  7830. AND ($val != 'signature_data')
  7831. AND ($val != 'signature_max_length')
  7832. AND ($val != 'byterange_string')
  7833. )) {
  7834. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
  7835. unset($this->$val);
  7836. }
  7837. }
  7838. }
  7839. }
  7840. /**
  7841. * Check for locale-related bug
  7842. * @protected
  7843. */
  7844. protected function _dochecks() {
  7845. //Check for locale-related bug
  7846. if (1.1 == 1) {
  7847. $this->Error('Don\'t alter the locale before including class file');
  7848. }
  7849. //Check for decimal separator
  7850. if (sprintf('%.1F', 1.0) != '1.0') {
  7851. setlocale(LC_NUMERIC, 'C');
  7852. }
  7853. }
  7854. /**
  7855. * Return fonts path
  7856. * @return string
  7857. * @protected
  7858. */
  7859. protected function _getfontpath() {
  7860. if (!defined('K_PATH_FONTS') AND is_dir(dirname(__FILE__).'/fonts')) {
  7861. define('K_PATH_FONTS', dirname(__FILE__).'/fonts/');
  7862. }
  7863. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  7864. }
  7865. /**
  7866. * Output pages.
  7867. * @protected
  7868. */
  7869. protected function _putpages() {
  7870. $nb = $this->numpages;
  7871. if (!empty($this->AliasNbPages)) {
  7872. $nbs = $this->formatPageNumber($nb);
  7873. $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font
  7874. $alias_a = $this->_escape($this->AliasNbPages);
  7875. $alias_au = $this->_escape('{'.$this->AliasNbPages.'}');
  7876. if ($this->isunicode) {
  7877. $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  7878. $alias_bu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNbPages.'}'));
  7879. $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages, false, $this->tmprtl));
  7880. $alias_cu = $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages.'}', false, $this->tmprtl));
  7881. }
  7882. }
  7883. if (!empty($this->AliasNumPage)) {
  7884. $alias_pa = $this->_escape($this->AliasNumPage);
  7885. $alias_pau = $this->_escape('{'.$this->AliasNumPage.'}');
  7886. if ($this->isunicode) {
  7887. $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  7888. $alias_pbu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNumPage.'}'));
  7889. $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage, false, $this->tmprtl));
  7890. $alias_pcu = $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage.'}', false, $this->tmprtl));
  7891. }
  7892. }
  7893. $pagegroupnum = 0;
  7894. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7895. for ($n=1; $n <= $nb; ++$n) {
  7896. $temppage = $this->getPageBuffer($n);
  7897. if (!empty($this->pagegroups)) {
  7898. if(isset($this->newpagegroup[$n])) {
  7899. $pagegroupnum = 0;
  7900. }
  7901. ++$pagegroupnum;
  7902. foreach ($this->pagegroups as $k => $v) {
  7903. // replace total pages group numbers
  7904. $vs = $this->formatPageNumber($v);
  7905. $vu = $this->UTF8ToUTF16BE($vs, false);
  7906. $alias_ga = $this->_escape($k);
  7907. $alias_gau = $this->_escape('{'.$k.'}');
  7908. if ($this->isunicode) {
  7909. $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
  7910. $alias_gbu = $this->_escape($this->UTF8ToLatin1('{'.$k.'}'));
  7911. $alias_gc = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  7912. $alias_gcu = $this->_escape($this->utf8StrRev('{'.$k.'}', false, $this->tmprtl));
  7913. }
  7914. $temppage = str_replace($alias_gau, $vu, $temppage);
  7915. if ($this->isunicode) {
  7916. $temppage = str_replace($alias_gbu, $vu, $temppage);
  7917. $temppage = str_replace($alias_gcu, $vu, $temppage);
  7918. $temppage = str_replace($alias_gb, $vs, $temppage);
  7919. $temppage = str_replace($alias_gc, $vs, $temppage);
  7920. }
  7921. $temppage = str_replace($alias_ga, $vs, $temppage);
  7922. // replace page group numbers
  7923. $pvs = $this->formatPageNumber($pagegroupnum);
  7924. $pvu = $this->UTF8ToUTF16BE($pvs, false);
  7925. $pk = str_replace('{nb', '{pnb', $k);
  7926. $alias_pga = $this->_escape($pk);
  7927. $alias_pgau = $this->_escape('{'.$pk.'}');
  7928. if ($this->isunicode) {
  7929. $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
  7930. $alias_pgbu = $this->_escape($this->UTF8ToLatin1('{'.$pk.'}'));
  7931. $alias_pgc = $this->_escape($this->utf8StrRev($pk, false, $this->tmprtl));
  7932. $alias_pgcu = $this->_escape($this->utf8StrRev('{'.$pk.'}', false, $this->tmprtl));
  7933. }
  7934. $temppage = str_replace($alias_pgau, $pvu, $temppage);
  7935. if ($this->isunicode) {
  7936. $temppage = str_replace($alias_pgbu, $pvu, $temppage);
  7937. $temppage = str_replace($alias_pgcu, $pvu, $temppage);
  7938. $temppage = str_replace($alias_pgb, $pvs, $temppage);
  7939. $temppage = str_replace($alias_pgc, $pvs, $temppage);
  7940. }
  7941. $temppage = str_replace($alias_pga, $pvs, $temppage);
  7942. }
  7943. }
  7944. if (!empty($this->AliasNbPages)) {
  7945. // replace total pages number
  7946. $temppage = str_replace($alias_au, $nbu, $temppage);
  7947. if ($this->isunicode) {
  7948. $temppage = str_replace($alias_bu, $nbu, $temppage);
  7949. $temppage = str_replace($alias_cu, $nbu, $temppage);
  7950. $temppage = str_replace($alias_b, $nbs, $temppage);
  7951. $temppage = str_replace($alias_c, $nbs, $temppage);
  7952. }
  7953. $temppage = str_replace($alias_a, $nbs, $temppage);
  7954. }
  7955. if (!empty($this->AliasNumPage)) {
  7956. // replace page number
  7957. $pnbs = $this->formatPageNumber($n);
  7958. $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font
  7959. $temppage = str_replace($alias_pau, $pnbu, $temppage);
  7960. if ($this->isunicode) {
  7961. $temppage = str_replace($alias_pbu, $pnbu, $temppage);
  7962. $temppage = str_replace($alias_pcu, $pnbu, $temppage);
  7963. $temppage = str_replace($alias_pb, $pnbs, $temppage);
  7964. $temppage = str_replace($alias_pc, $pnbs, $temppage);
  7965. }
  7966. $temppage = str_replace($alias_pa, $pnbs, $temppage);
  7967. }
  7968. $temppage = str_replace($this->epsmarker, '', $temppage);
  7969. //Page
  7970. $this->page_obj_id[$n] = $this->_newobj();
  7971. $out = '<<';
  7972. $out .= ' /Type /Page';
  7973. $out .= ' /Parent 1 0 R';
  7974. $out .= ' /LastModified '.$this->_datestring();
  7975. $out .= ' /Resources 2 0 R';
  7976. $boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  7977. foreach ($boxes as $box) {
  7978. $out .= ' /'.$box;
  7979. $out .= sprintf(' [%.2F %.2F %.2F %.2F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  7980. }
  7981. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7982. $out .= ' /BoxColorInfo <<';
  7983. foreach ($boxes as $box) {
  7984. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7985. $out .= ' /'.$box.' <<';
  7986. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7987. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7988. $out .= ' /C [';
  7989. $out .= sprintf(' %.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255);
  7990. $out .= ' ]';
  7991. }
  7992. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7993. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7994. }
  7995. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7996. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7997. }
  7998. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7999. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  8000. $out .= ' /D [';
  8001. foreach ($dashes as $dash) {
  8002. $out .= sprintf(' %.3F', ($dash * $this->k));
  8003. }
  8004. $out .= ' ]';
  8005. }
  8006. $out .= ' >>';
  8007. }
  8008. }
  8009. $out .= ' >>';
  8010. }
  8011. $out .= ' /Contents '.($this->n + 1).' 0 R';
  8012. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  8013. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  8014. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  8015. // page transitions
  8016. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  8017. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  8018. }
  8019. $out .= ' /Trans <<';
  8020. $out .= ' /Type /Trans';
  8021. if (isset($this->pagedim[$n]['trans']['S'])) {
  8022. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  8023. }
  8024. if (isset($this->pagedim[$n]['trans']['D'])) {
  8025. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  8026. }
  8027. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  8028. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  8029. }
  8030. if (isset($this->pagedim[$n]['trans']['M'])) {
  8031. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  8032. }
  8033. if (isset($this->pagedim[$n]['trans']['Di'])) {
  8034. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  8035. }
  8036. if (isset($this->pagedim[$n]['trans']['SS'])) {
  8037. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  8038. }
  8039. if (isset($this->pagedim[$n]['trans']['B'])) {
  8040. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  8041. }
  8042. $out .= ' >>';
  8043. }
  8044. $out .= $this->_getannotsrefs($n);
  8045. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  8046. $out .= ' >>';
  8047. $out .= "\n".'endobj';
  8048. $this->_out($out);
  8049. //Page content
  8050. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  8051. $this->_newobj();
  8052. $p = $this->_getrawstream($p);
  8053. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  8054. if ($this->diskcache) {
  8055. // remove temporary files
  8056. unlink($this->pages[$n]);
  8057. }
  8058. }
  8059. //Pages root
  8060. $out = $this->_getobj(1)."\n";
  8061. $out .= '<< /Type /Pages /Kids [';
  8062. foreach($this->page_obj_id as $page_obj) {
  8063. $out .= ' '.$page_obj.' 0 R';
  8064. }
  8065. $out .= ' ] /Count '.$nb.' >>';
  8066. $out .= "\n".'endobj';
  8067. $this->_out($out);
  8068. }
  8069. /**
  8070. * Output references to page annotations
  8071. * @param $n (int) page number
  8072. * @protected
  8073. * @author Nicola Asuni
  8074. * @since 4.7.000 (2008-08-29)
  8075. * @deprecated
  8076. */
  8077. protected function _putannotsrefs($n) {
  8078. $this->_out($this->_getannotsrefs($n));
  8079. }
  8080. /**
  8081. * Get references to page annotations.
  8082. * @param $n (int) page number
  8083. * @return string
  8084. * @protected
  8085. * @author Nicola Asuni
  8086. * @since 5.0.010 (2010-05-17)
  8087. */
  8088. protected function _getannotsrefs($n) {
  8089. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  8090. return '';
  8091. }
  8092. $out = ' /Annots [';
  8093. if (isset($this->PageAnnots[$n])) {
  8094. foreach ($this->PageAnnots[$n] as $key => $val) {
  8095. if (!in_array($val['n'], $this->radio_groups)) {
  8096. $out .= ' '.$val['n'].' 0 R';
  8097. }
  8098. }
  8099. // add radiobutton groups
  8100. if (isset($this->radiobutton_groups[$n])) {
  8101. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  8102. if (isset($data['n'])) {
  8103. $out .= ' '.$data['n'].' 0 R';
  8104. }
  8105. }
  8106. }
  8107. }
  8108. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  8109. // set reference for signature object
  8110. $out .= ' '.$this->sig_obj_id.' 0 R';
  8111. }
  8112. $out .= ' ]';
  8113. return $out;
  8114. }
  8115. /**
  8116. * Output annotations objects for all pages.
  8117. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  8118. * See section 12.5 of PDF 32000_2008 reference.
  8119. * @protected
  8120. * @author Nicola Asuni
  8121. * @since 4.0.018 (2008-08-06)
  8122. */
  8123. protected function _putannotsobjs() {
  8124. // reset object counter
  8125. for ($n=1; $n <= $this->numpages; ++$n) {
  8126. if (isset($this->PageAnnots[$n])) {
  8127. // set page annotations
  8128. foreach ($this->PageAnnots[$n] as $key => $pl) {
  8129. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  8130. // create annotation object for grouping radiobuttons
  8131. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  8132. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  8133. $annots = '<<';
  8134. $annots .= ' /Type /Annot';
  8135. $annots .= ' /Subtype /Widget';
  8136. $annots .= ' /Rect [0 0 0 0]';
  8137. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  8138. $annots .= ' /FT /Btn';
  8139. $annots .= ' /Ff 49152';
  8140. $annots .= ' /Kids [';
  8141. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  8142. if ($key !== 'n') {
  8143. $annots .= ' '.$data['kid'].' 0 R';
  8144. if ($data['def'] !== 'Off') {
  8145. $defval = $data['def'];
  8146. }
  8147. }
  8148. }
  8149. $annots .= ' ]';
  8150. if (isset($defval)) {
  8151. $annots .= ' /V /'.$defval;
  8152. }
  8153. $annots .= ' >>';
  8154. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  8155. $this->form_obj_id[] = $radio_button_obj_id;
  8156. // store object id to be used on Parent entry of Kids
  8157. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  8158. }
  8159. $formfield = false;
  8160. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  8161. $a = $pl['x'] * $this->k;
  8162. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  8163. $c = $pl['w'] * $this->k;
  8164. $d = $pl['h'] * $this->k;
  8165. $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b+$d);
  8166. // create new annotation object
  8167. $annots = '<</Type /Annot';
  8168. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  8169. $annots .= ' /Rect ['.$rect.']';
  8170. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  8171. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  8172. $annots .= ' /FT /'.$pl['opt']['ft'];
  8173. $formfield = true;
  8174. }
  8175. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  8176. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  8177. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  8178. $annots .= ' /M '.$this->_datestring($annot_obj_id);
  8179. if (isset($pl['opt']['f'])) {
  8180. $val = 0;
  8181. if (is_array($pl['opt']['f'])) {
  8182. foreach ($pl['opt']['f'] as $f) {
  8183. switch (strtolower($f)) {
  8184. case 'invisible': {
  8185. $val += 1 << 0;
  8186. break;
  8187. }
  8188. case 'hidden': {
  8189. $val += 1 << 1;
  8190. break;
  8191. }
  8192. case 'print': {
  8193. $val += 1 << 2;
  8194. break;
  8195. }
  8196. case 'nozoom': {
  8197. $val += 1 << 3;
  8198. break;
  8199. }
  8200. case 'norotate': {
  8201. $val += 1 << 4;
  8202. break;
  8203. }
  8204. case 'noview': {
  8205. $val += 1 << 5;
  8206. break;
  8207. }
  8208. case 'readonly': {
  8209. $val += 1 << 6;
  8210. break;
  8211. }
  8212. case 'locked': {
  8213. $val += 1 << 8;
  8214. break;
  8215. }
  8216. case 'togglenoview': {
  8217. $val += 1 << 9;
  8218. break;
  8219. }
  8220. case 'lockedcontents': {
  8221. $val += 1 << 10;
  8222. break;
  8223. }
  8224. default: {
  8225. break;
  8226. }
  8227. }
  8228. }
  8229. } else {
  8230. $val = intval($pl['opt']['f']);
  8231. }
  8232. $annots .= ' /F '.intval($val);
  8233. }
  8234. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  8235. $annots .= ' /AS /'.$pl['opt']['as'];
  8236. }
  8237. if (isset($pl['opt']['ap'])) {
  8238. // appearance stream
  8239. $annots .= ' /AP <<';
  8240. if (is_array($pl['opt']['ap'])) {
  8241. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  8242. // $apmode can be: n = normal; r = rollover; d = down;
  8243. $annots .= ' /'.strtoupper($apmode);
  8244. if (is_array($apdef)) {
  8245. $annots .= ' <<';
  8246. foreach ($apdef as $apstate => $stream) {
  8247. // reference to XObject that define the appearance for this mode-state
  8248. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  8249. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  8250. }
  8251. $annots .= ' >>';
  8252. } else {
  8253. // reference to XObject that define the appearance for this mode
  8254. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  8255. $annots .= ' '.$apsobjid.' 0 R';
  8256. }
  8257. }
  8258. } else {
  8259. $annots .= $pl['opt']['ap'];
  8260. }
  8261. $annots .= ' >>';
  8262. }
  8263. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  8264. $annots .= ' /BS <<';
  8265. $annots .= ' /Type /Border';
  8266. if (isset($pl['opt']['bs']['w'])) {
  8267. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  8268. }
  8269. $bstyles = array('S', 'D', 'B', 'I', 'U');
  8270. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  8271. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  8272. }
  8273. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  8274. $annots .= ' /D [';
  8275. foreach ($pl['opt']['bs']['d'] as $cord) {
  8276. $annots .= ' '.intval($cord);
  8277. }
  8278. $annots .= ']';
  8279. }
  8280. $annots .= ' >>';
  8281. } else {
  8282. $annots .= ' /Border [';
  8283. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  8284. $annots .= intval($pl['opt']['border'][0]).' ';
  8285. $annots .= intval($pl['opt']['border'][1]).' ';
  8286. $annots .= intval($pl['opt']['border'][2]);
  8287. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  8288. $annots .= ' [';
  8289. foreach ($pl['opt']['border'][3] as $dash) {
  8290. $annots .= intval($dash).' ';
  8291. }
  8292. $annots .= ']';
  8293. }
  8294. } else {
  8295. $annots .= '0 0 0';
  8296. }
  8297. $annots .= ']';
  8298. }
  8299. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  8300. $annots .= ' /BE <<';
  8301. $bstyles = array('S', 'C');
  8302. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $markups)) {
  8303. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  8304. } else {
  8305. $annots .= ' /S /S';
  8306. }
  8307. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  8308. $annots .= ' /I '.sprintf(' %.4F', $pl['opt']['be']['i']);
  8309. }
  8310. $annots .= '>>';
  8311. }
  8312. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  8313. $annots .= ' /C [';
  8314. foreach ($pl['opt']['c'] as $col) {
  8315. $col = intval($col);
  8316. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  8317. $annots .= sprintf(' %.4F', $color);
  8318. }
  8319. $annots .= ']';
  8320. }
  8321. //$annots .= ' /StructParent ';
  8322. //$annots .= ' /OC ';
  8323. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  8324. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  8325. // this is a markup type
  8326. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8327. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  8328. }
  8329. //$annots .= ' /Popup ';
  8330. if (isset($pl['opt']['ca'])) {
  8331. $annots .= ' /CA '.sprintf('%.4F', floatval($pl['opt']['ca']));
  8332. }
  8333. if (isset($pl['opt']['rc'])) {
  8334. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8335. }
  8336. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id);
  8337. //$annots .= ' /IRT ';
  8338. if (isset($pl['opt']['subj'])) {
  8339. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  8340. }
  8341. //$annots .= ' /RT ';
  8342. //$annots .= ' /IT ';
  8343. //$annots .= ' /ExData ';
  8344. }
  8345. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  8346. // Annotation types
  8347. switch (strtolower($pl['opt']['subtype'])) {
  8348. case 'text': {
  8349. if (isset($pl['opt']['open'])) {
  8350. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  8351. }
  8352. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  8353. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8354. $annots .= ' /Name /'.$pl['opt']['name'];
  8355. } else {
  8356. $annots .= ' /Name /Note';
  8357. }
  8358. $statemodels = array('Marked', 'Review');
  8359. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  8360. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8361. } else {
  8362. $pl['opt']['statemodel'] = 'Marked';
  8363. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8364. }
  8365. if ($pl['opt']['statemodel'] == 'Marked') {
  8366. $states = array('Accepted', 'Unmarked');
  8367. } else {
  8368. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  8369. }
  8370. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  8371. $annots .= ' /State /'.$pl['opt']['state'];
  8372. } else {
  8373. if ($pl['opt']['statemodel'] == 'Marked') {
  8374. $annots .= ' /State /Unmarked';
  8375. } else {
  8376. $annots .= ' /State /None';
  8377. }
  8378. }
  8379. break;
  8380. }
  8381. case 'link': {
  8382. if(is_string($pl['txt'])) {
  8383. // external URI link
  8384. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  8385. } else {
  8386. // internal link
  8387. $l = $this->links[$pl['txt']];
  8388. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  8389. }
  8390. $hmodes = array('N', 'I', 'O', 'P');
  8391. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  8392. $annots .= ' /H /'.$pl['opt']['h'];
  8393. } else {
  8394. $annots .= ' /H /I';
  8395. }
  8396. //$annots .= ' /PA ';
  8397. //$annots .= ' /Quadpoints ';
  8398. break;
  8399. }
  8400. case 'freetext': {
  8401. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8402. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8403. }
  8404. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8405. $annots .= ' /Q '.intval($pl['opt']['q']);
  8406. }
  8407. if (isset($pl['opt']['rc'])) {
  8408. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8409. }
  8410. if (isset($pl['opt']['ds'])) {
  8411. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8412. }
  8413. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8414. $annots .= ' /CL [';
  8415. foreach ($pl['opt']['cl'] as $cl) {
  8416. $annots .= sprintf('%.4F ', $cl * $this->k);
  8417. }
  8418. $annots .= ']';
  8419. }
  8420. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  8421. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8422. $annots .= ' /IT /'.$pl['opt']['it'];
  8423. }
  8424. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8425. $l = $pl['opt']['rd'][0] * $this->k;
  8426. $r = $pl['opt']['rd'][1] * $this->k;
  8427. $t = $pl['opt']['rd'][2] * $this->k;
  8428. $b = $pl['opt']['rd'][3] * $this->k;
  8429. $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b).']';
  8430. }
  8431. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8432. $annots .= ' /LE /'.$pl['opt']['le'];
  8433. }
  8434. break;
  8435. }
  8436. case 'line': {
  8437. break;
  8438. }
  8439. case 'square': {
  8440. break;
  8441. }
  8442. case 'circle': {
  8443. break;
  8444. }
  8445. case 'polygon': {
  8446. break;
  8447. }
  8448. case 'polyline': {
  8449. break;
  8450. }
  8451. case 'highlight': {
  8452. break;
  8453. }
  8454. case 'underline': {
  8455. break;
  8456. }
  8457. case 'squiggly': {
  8458. break;
  8459. }
  8460. case 'strikeout': {
  8461. break;
  8462. }
  8463. case 'stamp': {
  8464. break;
  8465. }
  8466. case 'caret': {
  8467. break;
  8468. }
  8469. case 'ink': {
  8470. break;
  8471. }
  8472. case 'popup': {
  8473. break;
  8474. }
  8475. case 'fileattachment': {
  8476. if (!isset($pl['opt']['fs'])) {
  8477. break;
  8478. }
  8479. $filename = basename($pl['opt']['fs']);
  8480. if (isset($this->embeddedfiles[$filename]['n'])) {
  8481. $annots .= ' /FS <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  8482. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8483. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8484. $annots .= ' /Name /'.$pl['opt']['name'];
  8485. } else {
  8486. $annots .= ' /Name /PushPin';
  8487. }
  8488. }
  8489. break;
  8490. }
  8491. case 'sound': {
  8492. if (!isset($pl['opt']['fs'])) {
  8493. break;
  8494. }
  8495. $filename = basename($pl['opt']['fs']);
  8496. if (isset($this->embeddedfiles[$filename]['n'])) {
  8497. // ... TO BE COMPLETED ...
  8498. // /R /C /B /E /CO /CP
  8499. $annots .= ' /Sound <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  8500. $iconsapp = array('Speaker', 'Mic');
  8501. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8502. $annots .= ' /Name /'.$pl['opt']['name'];
  8503. } else {
  8504. $annots .= ' /Name /Speaker';
  8505. }
  8506. }
  8507. break;
  8508. }
  8509. case 'movie': {
  8510. break;
  8511. }
  8512. case 'widget': {
  8513. $hmode = array('N', 'I', 'O', 'P', 'T');
  8514. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8515. $annots .= ' /H /'.$pl['opt']['h'];
  8516. }
  8517. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8518. $annots .= ' /MK <<';
  8519. if (isset($pl['opt']['mk']['r'])) {
  8520. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8521. }
  8522. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8523. $annots .= ' /BC [';
  8524. foreach($pl['opt']['mk']['bc'] AS $col) {
  8525. $col = intval($col);
  8526. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  8527. $annots .= sprintf(' %.2F', $color);
  8528. }
  8529. $annots .= ']';
  8530. }
  8531. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8532. $annots .= ' /BG [';
  8533. foreach($pl['opt']['mk']['bg'] AS $col) {
  8534. $col = intval($col);
  8535. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  8536. $annots .= sprintf(' %.2F', $color);
  8537. }
  8538. $annots .= ']';
  8539. }
  8540. if (isset($pl['opt']['mk']['ca'])) {
  8541. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8542. }
  8543. if (isset($pl['opt']['mk']['rc'])) {
  8544. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8545. }
  8546. if (isset($pl['opt']['mk']['ac'])) {
  8547. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8548. }
  8549. if (isset($pl['opt']['mk']['i'])) {
  8550. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8551. if ($info !== false) {
  8552. $annots .= ' /I '.$info['n'].' 0 R';
  8553. }
  8554. }
  8555. if (isset($pl['opt']['mk']['ri'])) {
  8556. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8557. if ($info !== false) {
  8558. $annots .= ' /RI '.$info['n'].' 0 R';
  8559. }
  8560. }
  8561. if (isset($pl['opt']['mk']['ix'])) {
  8562. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8563. if ($info !== false) {
  8564. $annots .= ' /IX '.$info['n'].' 0 R';
  8565. }
  8566. }
  8567. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8568. $annots .= ' /IF <<';
  8569. $if_sw = array('A', 'B', 'S', 'N');
  8570. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8571. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8572. }
  8573. $if_s = array('A', 'P');
  8574. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8575. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8576. }
  8577. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8578. $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8579. }
  8580. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8581. $annots .= ' /FB true';
  8582. }
  8583. $annots .= '>>';
  8584. }
  8585. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8586. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8587. } else {
  8588. $annots .= ' /TP 0';
  8589. }
  8590. $annots .= '>>';
  8591. } // end MK
  8592. // --- Entries for field dictionaries ---
  8593. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8594. // set parent
  8595. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8596. }
  8597. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8598. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8599. }
  8600. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8601. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8602. }
  8603. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8604. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8605. }
  8606. if (isset($pl['opt']['ff'])) {
  8607. if (is_array($pl['opt']['ff'])) {
  8608. // array of bit settings
  8609. $flag = 0;
  8610. foreach($pl['opt']['ff'] as $val) {
  8611. $flag += 1 << ($val - 1);
  8612. }
  8613. } else {
  8614. $flag = intval($pl['opt']['ff']);
  8615. }
  8616. $annots .= ' /Ff '.$flag;
  8617. }
  8618. if (isset($pl['opt']['maxlen'])) {
  8619. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8620. }
  8621. if (isset($pl['opt']['v'])) {
  8622. $annots .= ' /V';
  8623. if (is_array($pl['opt']['v'])) {
  8624. foreach ($pl['opt']['v'] AS $optval) {
  8625. if (is_float($optval)) {
  8626. $optval = sprintf('%.2F', $optval);
  8627. }
  8628. $annots .= ' '.$optval;
  8629. }
  8630. } else {
  8631. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8632. }
  8633. }
  8634. if (isset($pl['opt']['dv'])) {
  8635. $annots .= ' /DV';
  8636. if (is_array($pl['opt']['dv'])) {
  8637. foreach ($pl['opt']['dv'] AS $optval) {
  8638. if (is_float($optval)) {
  8639. $optval = sprintf('%.2F', $optval);
  8640. }
  8641. $annots .= ' '.$optval;
  8642. }
  8643. } else {
  8644. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8645. }
  8646. }
  8647. if (isset($pl['opt']['rv'])) {
  8648. $annots .= ' /RV';
  8649. if (is_array($pl['opt']['rv'])) {
  8650. foreach ($pl['opt']['rv'] AS $optval) {
  8651. if (is_float($optval)) {
  8652. $optval = sprintf('%.2F', $optval);
  8653. }
  8654. $annots .= ' '.$optval;
  8655. }
  8656. } else {
  8657. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8658. }
  8659. }
  8660. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8661. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8662. }
  8663. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8664. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8665. }
  8666. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8667. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8668. }
  8669. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8670. $annots .= ' /Q '.intval($pl['opt']['q']);
  8671. }
  8672. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8673. $annots .= ' /Opt [';
  8674. foreach($pl['opt']['opt'] AS $copt) {
  8675. if (is_array($copt)) {
  8676. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8677. } else {
  8678. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8679. }
  8680. }
  8681. $annots .= ']';
  8682. }
  8683. if (isset($pl['opt']['ti'])) {
  8684. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8685. }
  8686. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8687. $annots .= ' /I [';
  8688. foreach($pl['opt']['i'] AS $copt) {
  8689. $annots .= intval($copt).' ';
  8690. }
  8691. $annots .= ']';
  8692. }
  8693. break;
  8694. }
  8695. case 'screen': {
  8696. break;
  8697. }
  8698. case 'printermark': {
  8699. break;
  8700. }
  8701. case 'trapnet': {
  8702. break;
  8703. }
  8704. case 'watermark': {
  8705. break;
  8706. }
  8707. case '3d': {
  8708. break;
  8709. }
  8710. default: {
  8711. break;
  8712. }
  8713. }
  8714. $annots .= '>>';
  8715. // create new annotation object
  8716. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8717. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8718. // store reference of form object
  8719. $this->form_obj_id[] = $annot_obj_id;
  8720. }
  8721. }
  8722. }
  8723. } // end for each page
  8724. }
  8725. /**
  8726. * Put appearance streams XObject used to define annotation's appearance states
  8727. * @param $w (int) annotation width
  8728. * @param $h (int) annotation height
  8729. * @param $stream (string) appearance stream
  8730. * @return int object ID
  8731. * @protected
  8732. * @since 4.8.001 (2009-09-09)
  8733. */
  8734. protected function _putAPXObject($w=0, $h=0, $stream='') {
  8735. $stream = trim($stream);
  8736. $out = $this->_getobj()."\n";
  8737. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8738. $out .= '<<';
  8739. $out .= ' /Type /XObject';
  8740. $out .= ' /Subtype /Form';
  8741. $out .= ' /FormType 1';
  8742. if ($this->compress) {
  8743. $stream = gzcompress($stream);
  8744. $out .= ' /Filter /FlateDecode';
  8745. }
  8746. $rect = sprintf('%.2F %.2F', $w, $h);
  8747. $out .= ' /BBox [0 0 '.$rect.']';
  8748. $out .= ' /Matrix [1 0 0 1 0 0]';
  8749. $out .= ' /Resources <<';
  8750. $out .= ' /ProcSet [/PDF /Text]';
  8751. $out .= ' /Font <<';
  8752. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  8753. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8754. }
  8755. $out .= ' >>';
  8756. $out .= ' >>';
  8757. $stream = $this->_getrawstream($stream);
  8758. $out .= ' /Length '.strlen($stream);
  8759. $out .= ' >>';
  8760. $out .= ' stream'."\n".$stream."\n".'endstream';
  8761. $out .= "\n".'endobj';
  8762. $this->_out($out);
  8763. return $this->n;
  8764. }
  8765. /**
  8766. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  8767. * @param $str (string) string from where to extract value
  8768. * @param $offset (int) point from where to read the data
  8769. * @return int 32 bit value
  8770. * @author Nicola Asuni
  8771. * @protected
  8772. * @since 5.2.000 (2010-06-02)
  8773. */
  8774. protected function _getULONG(&$str, &$offset) {
  8775. $v = unpack('Ni', substr($str, $offset, 4));
  8776. $offset += 4;
  8777. return $v['i'];
  8778. }
  8779. /**
  8780. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  8781. * @param $str (string) string from where to extract value
  8782. * @param $offset (int) point from where to read the data
  8783. * @return int 16 bit value
  8784. * @author Nicola Asuni
  8785. * @protected
  8786. * @since 5.2.000 (2010-06-02)
  8787. */
  8788. protected function _getUSHORT(&$str, &$offset) {
  8789. $v = unpack('ni', substr($str, $offset, 2));
  8790. $offset += 2;
  8791. return $v['i'];
  8792. }
  8793. /**
  8794. * Get SHORT from string (Big Endian 16-bit signed integer).
  8795. * @param $str (string) string from where to extract value
  8796. * @param $offset (int) point from where to read the data
  8797. * @return int 16 bit value
  8798. * @author Nicola Asuni
  8799. * @protected
  8800. * @since 5.2.000 (2010-06-02)
  8801. */
  8802. protected function _getSHORT(&$str, &$offset) {
  8803. $v = unpack('si', substr($str, $offset, 2));
  8804. $offset += 2;
  8805. return $v['i'];
  8806. }
  8807. /**
  8808. * Get BYTE from string (8-bit unsigned integer).
  8809. * @param $str (string) string from where to extract value
  8810. * @param $offset (int) point from where to read the data
  8811. * @return int 8 bit value
  8812. * @author Nicola Asuni
  8813. * @protected
  8814. * @since 5.2.000 (2010-06-02)
  8815. */
  8816. protected function _getBYTE(&$str, &$offset) {
  8817. $v = unpack('Ci', substr($str, $offset, 1));
  8818. ++$offset;
  8819. return $v['i'];
  8820. }
  8821. /**
  8822. * Returns a subset of the TrueType font data without the unused glyphs.
  8823. * @param $font (string) TrueType font data
  8824. * @param $subsetchars (array) array of used characters (the glyphs to keep)
  8825. * @return string a subset of TrueType font data without the unused glyphs
  8826. * @author Nicola Asuni
  8827. * @protected
  8828. * @since 5.2.000 (2010-06-02)
  8829. */
  8830. protected function _getTrueTypeFontSubset($font, $subsetchars) {
  8831. ksort($subsetchars);
  8832. $offset = 0; // offset position of the font data
  8833. if ($this->_getULONG($font, $offset) != 0x10000) {
  8834. // sfnt version must be 0x00010000 for TrueType version 1.0.
  8835. return $font;
  8836. }
  8837. // get number of tables
  8838. $numTables = $this->_getUSHORT($font, $offset);
  8839. // skip searchRange, entrySelector and rangeShift
  8840. $offset += 6;
  8841. // tables array
  8842. $table = array();
  8843. // for each table
  8844. for ($i = 0; $i < $numTables; ++$i) {
  8845. // get table info
  8846. $tag = substr($font, $offset, 4);
  8847. $offset += 4;
  8848. $table[$tag] = array();
  8849. $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
  8850. $table[$tag]['offset'] = $this->_getULONG($font, $offset);
  8851. $table[$tag]['length'] = $this->_getULONG($font, $offset);
  8852. }
  8853. // check magicNumber
  8854. $offset = $table['head']['offset'] + 12;
  8855. if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
  8856. // magicNumber must be 0x5F0F3CF5
  8857. return $font;
  8858. }
  8859. // get offset mode (indexToLocFormat : 0 = short, 1 = long)
  8860. $offset = $table['head']['offset'] + 50;
  8861. $short_offset = ($this->_getSHORT($font, $offset) == 0);
  8862. // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
  8863. $indexToLoc = array();
  8864. $offset = $table['loca']['offset'];
  8865. if ($short_offset) {
  8866. // short version
  8867. $n = $table['loca']['length'] / 2; // numGlyphs + 1
  8868. for ($i = 0; $i < $n; ++$i) {
  8869. $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
  8870. }
  8871. } else {
  8872. // long version
  8873. $n = $table['loca']['length'] / 4; // numGlyphs + 1
  8874. for ($i = 0; $i < $n; ++$i) {
  8875. $indexToLoc[$i] = $this->_getULONG($font, $offset);
  8876. }
  8877. }
  8878. // get glyphs indexes of chars from cmap table
  8879. $subsetglyphs = array(); // glyph IDs on key
  8880. $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
  8881. $offset = $table['cmap']['offset'] + 2;
  8882. $numEncodingTables = $this->_getUSHORT($font, $offset);
  8883. $encodingTables = array();
  8884. for ($i = 0; $i < $numEncodingTables; ++$i) {
  8885. $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
  8886. $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
  8887. $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
  8888. }
  8889. foreach ($encodingTables as $enctable) {
  8890. if (($enctable['platformID'] == 3) AND ($enctable['encodingID'] == 0)) {
  8891. $modesymbol = true;
  8892. } else {
  8893. $modesymbol = false;
  8894. }
  8895. $offset = $table['cmap']['offset'] + $enctable['offset'];
  8896. $format = $this->_getUSHORT($font, $offset);
  8897. switch ($format) {
  8898. case 0: { // Format 0: Byte encoding table
  8899. $offset += 4; // skip length and version/language
  8900. for ($k = 0; $k < 256; ++$k) {
  8901. if (isset($subsetchars[$k])) {
  8902. $g = $this->_getBYTE($font, $offset);
  8903. $subsetglyphs[$g] = $k;
  8904. } else {
  8905. ++$offset;
  8906. }
  8907. }
  8908. break;
  8909. }
  8910. case 2: { // Format 2: High-byte mapping through table
  8911. $offset += 4; // skip length and version
  8912. // to be implemented ...
  8913. break;
  8914. }
  8915. case 4: { // Format 4: Segment mapping to delta values
  8916. $length = $this->_getUSHORT($font, $offset);
  8917. $offset += 2; // skip version/language
  8918. $segCount = ($this->_getUSHORT($font, $offset) / 2);
  8919. $offset += 6; // skip searchRange, entrySelector, rangeShift
  8920. $endCount = array(); // array of end character codes for each segment
  8921. for ($k = 0; $k < $segCount; ++$k) {
  8922. $endCount[$k] = $this->_getUSHORT($font, $offset);
  8923. }
  8924. $offset += 2; // skip reservedPad
  8925. $startCount = array(); // array of start character codes for each segment
  8926. for ($k = 0; $k < $segCount; ++$k) {
  8927. $startCount[$k] = $this->_getUSHORT($font, $offset);
  8928. }
  8929. $idDelta = array(); // delta for all character codes in segment
  8930. for ($k = 0; $k < $segCount; ++$k) {
  8931. $idDelta[$k] = $this->_getUSHORT($font, $offset);
  8932. }
  8933. $idRangeOffset = array(); // Offsets into glyphIdArray or 0
  8934. for ($k = 0; $k < $segCount; ++$k) {
  8935. $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
  8936. }
  8937. $gidlen = ($length / 2) - 8 - (4 * $segCount);
  8938. $glyphIdArray = array(); // glyph index array
  8939. for ($k = 0; $k < $gidlen; ++$k) {
  8940. $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
  8941. }
  8942. for ($k = 0; $k < $segCount; ++$k) {
  8943. for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
  8944. if (isset($subsetchars[$c])) {
  8945. if ($idRangeOffset[$k] == 0) {
  8946. $g = $c;
  8947. } else {
  8948. $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
  8949. $g = $glyphIdArray[$gid];
  8950. }
  8951. $g += ($idDelta[$k] - 65536);
  8952. if ($g < 0) {
  8953. $g = 0;
  8954. }
  8955. $subsetglyphs[$g] = $c;
  8956. }
  8957. }
  8958. }
  8959. break;
  8960. }
  8961. case 6: { // Format 6: Trimmed table mapping
  8962. $offset += 4; // skip length and version/language
  8963. $firstCode = $this->_getUSHORT($font, $offset);
  8964. $entryCount = $this->_getUSHORT($font, $offset);
  8965. for ($k = 0; $k < $entryCount; ++$k) {
  8966. $c = ($k + $firstCode);
  8967. if (isset($subsetchars[$c])) {
  8968. $g = $this->_getUSHORT($font, $offset);
  8969. $subsetglyphs[$g] = $c;
  8970. } else {
  8971. $offset += 2;
  8972. }
  8973. }
  8974. break;
  8975. }
  8976. case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
  8977. $offset += 10; // skip length and version
  8978. // to be implemented ...
  8979. break;
  8980. }
  8981. case 10: { // Format 10: Trimmed array
  8982. $offset += 10; // skip length and version/language
  8983. $startCharCode = $this->_getULONG($font, $offset);
  8984. $numChars = $this->_getULONG($font, $offset);
  8985. for ($k = 0; $k < $numChars; ++$k) {
  8986. $c = ($k + $startCharCode);
  8987. if (isset($subsetchars[$c])) {
  8988. $g = $this->_getUSHORT($font, $offset);
  8989. $subsetglyphs[$g] = $c;
  8990. } else {
  8991. $offset += 2;
  8992. }
  8993. }
  8994. break;
  8995. }
  8996. case 12: { // Format 12: Segmented coverage
  8997. $offset += 10; // skip length and version/language
  8998. $nGroups = $this->_getULONG($font, $offset);
  8999. for ($k = 0; $k < $nGroups; ++$k) {
  9000. $startCharCode = $this->_getULONG($font, $offset);
  9001. $endCharCode = $this->_getULONG($font, $offset);
  9002. $startGlyphCode = $this->_getULONG($font, $offset);
  9003. for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
  9004. if (isset($subsetchars[$c])) {
  9005. $subsetglyphs[$startGlyphCode] = $c;
  9006. }
  9007. ++$startGlyphCode;
  9008. }
  9009. }
  9010. break;
  9011. }
  9012. }
  9013. }
  9014. // sort glyphs by key
  9015. ksort($subsetglyphs);
  9016. // add composite glyps to $subsetglyphs and remove missing glyphs
  9017. foreach ($subsetglyphs as $key => $val) {
  9018. if (isset($indexToLoc[$key])) {
  9019. $offset = $table['glyf']['offset'] + $indexToLoc[$key];
  9020. $numberOfContours = $this->_getSHORT($font, $offset);
  9021. if ($numberOfContours < 0) { // composite glyph
  9022. $offset += 8; // skip xMin, yMin, xMax, yMax
  9023. do {
  9024. $flags = $this->_getUSHORT($font, $offset);
  9025. $glyphIndex = $this->_getUSHORT($font, $offset);
  9026. if (!isset($subsetglyphs[$glyphIndex]) AND isset($indexToLoc[$glyphIndex])) {
  9027. // add missing glyphs
  9028. $subsetglyphs[$glyphIndex] = true;
  9029. }
  9030. // skip some bytes by case
  9031. if ($flags & 1) {
  9032. $offset += 4;
  9033. } else {
  9034. $offset += 2;
  9035. }
  9036. if ($flags & 8) {
  9037. $offset += 2;
  9038. } elseif ($flags & 64) {
  9039. $offset += 4;
  9040. } elseif ($flags & 128) {
  9041. $offset += 8;
  9042. }
  9043. } while ($flags & 32);
  9044. }
  9045. } else {
  9046. unset($subsetglyphs[$key]);
  9047. }
  9048. }
  9049. // build new glyf table with only used glyphs
  9050. $glyf = '';
  9051. $glyfSize = 0;
  9052. // create new empty indexToLoc table
  9053. $newIndexToLoc = array_fill(0, count($indexToLoc), 0);
  9054. $goffset = 0;
  9055. foreach ($subsetglyphs as $glyphID => $char) {
  9056. if (isset($indexToLoc[$glyphID]) AND isset($indexToLoc[($glyphID + 1)])) {
  9057. $start = $indexToLoc[$glyphID];
  9058. $length = ($indexToLoc[($glyphID + 1)] - $start);
  9059. $glyf .= substr($font, ($table['glyf']['offset'] + $start), $length);
  9060. $newIndexToLoc[$glyphID] = $goffset;
  9061. $goffset += $length;
  9062. }
  9063. }
  9064. // build new loca table
  9065. $loca = '';
  9066. if ($short_offset) {
  9067. foreach ($newIndexToLoc as $glyphID => $offset) {
  9068. $loca .= pack('n', ($offset / 2));
  9069. }
  9070. } else {
  9071. foreach ($newIndexToLoc as $glyphID => $offset) {
  9072. $loca .= pack('N', $offset);
  9073. }
  9074. }
  9075. // array of table names to preserve (loca and glyf tables will be added later)
  9076. //$table_names = array ('cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2', 'post', 'cvt ', 'fpgm', 'prep');
  9077. // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
  9078. $table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
  9079. // get the tables to preserve
  9080. $offset = 12;
  9081. foreach ($table as $tag => $val) {
  9082. if (in_array($tag, $table_names)) {
  9083. $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
  9084. if ($tag == 'head') {
  9085. // set the checkSumAdjustment to 0
  9086. $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
  9087. }
  9088. $pad = 4 - ($table[$tag]['length'] % 4);
  9089. if ($pad != 4) {
  9090. // the length of a table must be a multiple of four bytes
  9091. $table[$tag]['length'] += $pad;
  9092. $table[$tag]['data'] .= str_repeat("\x0", $pad);
  9093. }
  9094. $table[$tag]['offset'] = $offset;
  9095. $offset += $table[$tag]['length'];
  9096. // check sum is not changed (so keep the following line commented)
  9097. //$table[$tag]['checkSum'] = $this->_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
  9098. } else {
  9099. unset($table[$tag]);
  9100. }
  9101. }
  9102. // add loca
  9103. $table['loca']['data'] = $loca;
  9104. $table['loca']['length'] = strlen($loca);
  9105. $pad = 4 - ($table['loca']['length'] % 4);
  9106. if ($pad != 4) {
  9107. // the length of a table must be a multiple of four bytes
  9108. $table['loca']['length'] += $pad;
  9109. $table['loca']['data'] .= str_repeat("\x0", $pad);
  9110. }
  9111. $table['loca']['offset'] = $offset;
  9112. $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
  9113. $offset += $table['loca']['length'];
  9114. // add glyf
  9115. $table['glyf']['data'] = $glyf;
  9116. $table['glyf']['length'] = strlen($glyf);
  9117. $pad = 4 - ($table['glyf']['length'] % 4);
  9118. if ($pad != 4) {
  9119. // the length of a table must be a multiple of four bytes
  9120. $table['glyf']['length'] += $pad;
  9121. $table['glyf']['data'] .= str_repeat("\x0", $pad);
  9122. }
  9123. $table['glyf']['offset'] = $offset;
  9124. $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
  9125. // rebuild font
  9126. $font = '';
  9127. $font .= pack('N', 0x10000); // sfnt version
  9128. $numTables = count($table);
  9129. $font .= pack('n', $numTables); // numTables
  9130. $entrySelector = floor(log($numTables, 2));
  9131. $searchRange = pow(2, $entrySelector) * 16;
  9132. $rangeShift = ($numTables * 16) - $searchRange;
  9133. $font .= pack('n', $searchRange); // searchRange
  9134. $font .= pack('n', $entrySelector); // entrySelector
  9135. $font .= pack('n', $rangeShift); // rangeShift
  9136. $offset = ($numTables * 16);
  9137. foreach ($table as $tag => $data) {
  9138. $font .= $tag; // tag
  9139. $font .= pack('N', $data['checkSum']); // checkSum
  9140. $font .= pack('N', ($data['offset'] + $offset)); // offset
  9141. $font .= pack('N', $data['length']); // length
  9142. }
  9143. foreach ($table as $data) {
  9144. $font .= $data['data'];
  9145. }
  9146. // set checkSumAdjustment on head table
  9147. $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font));
  9148. $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12);
  9149. return $font;
  9150. }
  9151. /**
  9152. * Returs the checksum of a TTF table.
  9153. * @param $table (string) table to check
  9154. * @param $length (int) lenght of table in bytes
  9155. * @return int checksum
  9156. * @author Nicola Asuni
  9157. * @protected
  9158. * @since 5.2.000 (2010-06-02)
  9159. */
  9160. protected function _getTTFtableChecksum($table, $length) {
  9161. $sum = 0;
  9162. $tlen = ($length / 4);
  9163. $offset = 0;
  9164. for ($i = 0; $i < $tlen; ++$i) {
  9165. $v = unpack('Ni', substr($table, $offset, 4));
  9166. $sum += $v['i'];
  9167. $offset += 4;
  9168. }
  9169. $sum = unpack('Ni', pack('N', $sum));
  9170. return $sum['i'];
  9171. }
  9172. /**
  9173. * Outputs font widths
  9174. * @param $font (array) font data
  9175. * @param $cidoffset (int) offset for CID values
  9176. * @return PDF command string for font widths
  9177. * @author Nicola Asuni
  9178. * @protected
  9179. * @since 4.4.000 (2008-12-07)
  9180. */
  9181. protected function _putfontwidths($font, $cidoffset=0) {
  9182. ksort($font['cw']);
  9183. $rangeid = 0;
  9184. $range = array();
  9185. $prevcid = -2;
  9186. $prevwidth = -1;
  9187. $interval = false;
  9188. // for each character
  9189. foreach ($font['cw'] as $cid => $width) {
  9190. $cid -= $cidoffset;
  9191. if ($font['subset'] AND ($cid > 255) AND (!isset($font['subsetchars'][$cid]))) {
  9192. // ignore the unused characters (font subsetting)
  9193. continue;
  9194. }
  9195. if ($width != $font['dw']) {
  9196. if ($cid == ($prevcid + 1)) {
  9197. // consecutive CID
  9198. if ($width == $prevwidth) {
  9199. if ($width == $range[$rangeid][0]) {
  9200. $range[$rangeid][] = $width;
  9201. } else {
  9202. array_pop($range[$rangeid]);
  9203. // new range
  9204. $rangeid = $prevcid;
  9205. $range[$rangeid] = array();
  9206. $range[$rangeid][] = $prevwidth;
  9207. $range[$rangeid][] = $width;
  9208. }
  9209. $interval = true;
  9210. $range[$rangeid]['interval'] = true;
  9211. } else {
  9212. if ($interval) {
  9213. // new range
  9214. $rangeid = $cid;
  9215. $range[$rangeid] = array();
  9216. $range[$rangeid][] = $width;
  9217. } else {
  9218. $range[$rangeid][] = $width;
  9219. }
  9220. $interval = false;
  9221. }
  9222. } else {
  9223. // new range
  9224. $rangeid = $cid;
  9225. $range[$rangeid] = array();
  9226. $range[$rangeid][] = $width;
  9227. $interval = false;
  9228. }
  9229. $prevcid = $cid;
  9230. $prevwidth = $width;
  9231. }
  9232. }
  9233. // optimize ranges
  9234. $prevk = -1;
  9235. $nextk = -1;
  9236. $prevint = false;
  9237. foreach ($range as $k => $ws) {
  9238. $cws = count($ws);
  9239. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  9240. if (isset($range[$k]['interval'])) {
  9241. unset($range[$k]['interval']);
  9242. }
  9243. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  9244. unset($range[$k]);
  9245. } else {
  9246. $prevk = $k;
  9247. }
  9248. $nextk = $k + $cws;
  9249. if (isset($ws['interval'])) {
  9250. if ($cws > 3) {
  9251. $prevint = true;
  9252. } else {
  9253. $prevint = false;
  9254. }
  9255. unset($range[$k]['interval']);
  9256. --$nextk;
  9257. } else {
  9258. $prevint = false;
  9259. }
  9260. }
  9261. // output data
  9262. $w = '';
  9263. foreach ($range as $k => $ws) {
  9264. if (count(array_count_values($ws)) == 1) {
  9265. // interval mode is more compact
  9266. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  9267. } else {
  9268. // range mode
  9269. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
  9270. }
  9271. }
  9272. return '/W ['.$w.' ]';
  9273. }
  9274. /**
  9275. * Output fonts.
  9276. * @author Nicola Asuni
  9277. * @protected
  9278. */
  9279. protected function _putfonts() {
  9280. $nf = $this->n;
  9281. foreach ($this->diffs as $diff) {
  9282. //Encodings
  9283. $this->_newobj();
  9284. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  9285. }
  9286. $mqr = $this->get_mqr();
  9287. $this->set_mqr(false);
  9288. foreach ($this->FontFiles as $file => $info) {
  9289. // search and get font file to embedd
  9290. $fontdir = $info['fontdir'];
  9291. $file = strtolower($file);
  9292. $fontfile = '';
  9293. // search files on various directories
  9294. if (($fontdir !== false) AND file_exists($fontdir.$file)) {
  9295. $fontfile = $fontdir.$file;
  9296. } elseif (file_exists($this->_getfontpath().$file)) {
  9297. $fontfile = $this->_getfontpath().$file;
  9298. } elseif (file_exists($file)) {
  9299. $fontfile = $file;
  9300. }
  9301. if (!$this->empty_string($fontfile)) {
  9302. $font = file_get_contents($fontfile);
  9303. $compressed = (substr($file, -2) == '.z');
  9304. if ((!$compressed) AND (isset($info['length2']))) {
  9305. $header = (ord($font{0}) == 128);
  9306. if ($header) {
  9307. //Strip first binary header
  9308. $font = substr($font, 6);
  9309. }
  9310. if ($header AND (ord($font{$info['length1']}) == 128)) {
  9311. //Strip second binary header
  9312. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  9313. }
  9314. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  9315. if ($compressed) {
  9316. // uncompress font
  9317. $font = gzuncompress($font);
  9318. }
  9319. // merge subset characters
  9320. $subsetchars = array(); // used chars
  9321. foreach ($info['fontkeys'] as $fontkey) {
  9322. $fontinfo = $this->getFontBuffer($fontkey);
  9323. $subsetchars += $fontinfo['subsetchars'];
  9324. }
  9325. $font = $this->_getTrueTypeFontSubset($font, $subsetchars);
  9326. if ($compressed) {
  9327. // recompress font
  9328. $font = gzcompress($font);
  9329. }
  9330. }
  9331. $this->_newobj();
  9332. $this->FontFiles[$file]['n'] = $this->n;
  9333. $stream = $this->_getrawstream($font);
  9334. $out = '<< /Length '.strlen($stream);
  9335. if ($compressed) {
  9336. $out .= ' /Filter /FlateDecode';
  9337. }
  9338. $out .= ' /Length1 '.$info['length1'];
  9339. if (isset($info['length2'])) {
  9340. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  9341. }
  9342. $out .= ' >>';
  9343. $out .= ' stream'."\n".$stream."\n".'endstream';
  9344. $out .= "\n".'endobj';
  9345. $this->_out($out);
  9346. }
  9347. }
  9348. $this->set_mqr($mqr);
  9349. foreach ($this->fontkeys as $k) {
  9350. //Font objects
  9351. $font = $this->getFontBuffer($k);
  9352. $type = $font['type'];
  9353. $name = $font['name'];
  9354. if ($type == 'core') {
  9355. // standard core font
  9356. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  9357. $out .= '<</Type /Font';
  9358. $out .= ' /Subtype /Type1';
  9359. $out .= ' /BaseFont /'.$name;
  9360. $out .= ' /Name /F'.$font['i'];
  9361. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  9362. $out .= ' /Encoding /WinAnsiEncoding';
  9363. }
  9364. if ($k == 'helvetica') {
  9365. // add default font for annotations
  9366. $this->annotation_fonts[$k] = $font['i'];
  9367. }
  9368. $out .= ' >>';
  9369. $out .= "\n".'endobj';
  9370. $this->_out($out);
  9371. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  9372. // additional Type1 or TrueType font
  9373. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  9374. $out .= '<</Type /Font';
  9375. $out .= ' /Subtype /'.$type;
  9376. $out .= ' /BaseFont /'.$name;
  9377. $out .= ' /Name /F'.$font['i'];
  9378. $out .= ' /FirstChar 32 /LastChar 255';
  9379. $out .= ' /Widths '.($this->n + 1).' 0 R';
  9380. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  9381. if ($font['enc']) {
  9382. if (isset($font['diff'])) {
  9383. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  9384. } else {
  9385. $out .= ' /Encoding /WinAnsiEncoding';
  9386. }
  9387. }
  9388. $out .= ' >>';
  9389. $out .= "\n".'endobj';
  9390. $this->_out($out);
  9391. // Widths
  9392. $this->_newobj();
  9393. $cw = &$font['cw'];
  9394. $s = '[';
  9395. for ($i = 32; $i < 256; ++$i) {
  9396. $s .= $cw[$i].' ';
  9397. }
  9398. $s .= ']';
  9399. $s .= "\n".'endobj';
  9400. $this->_out($s);
  9401. //Descriptor
  9402. $this->_newobj();
  9403. $s = '<</Type /FontDescriptor /FontName /'.$name;
  9404. foreach ($font['desc'] as $fdk => $fdv) {
  9405. if(is_float($fdv)) {
  9406. $fdv = sprintf('%.3F', $fdv);
  9407. }
  9408. $s .= ' /'.$fdk.' '.$fdv.'';
  9409. }
  9410. if (!$this->empty_string($font['file'])) {
  9411. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  9412. }
  9413. $s .= '>>';
  9414. $s .= "\n".'endobj';
  9415. $this->_out($s);
  9416. } else {
  9417. // additional types
  9418. $mtd = '_put'.strtolower($type);
  9419. if (!method_exists($this, $mtd)) {
  9420. $this->Error('Unsupported font type: '.$type);
  9421. }
  9422. $this->$mtd($font);
  9423. }
  9424. }
  9425. }
  9426. /**
  9427. * Adds unicode fonts.<br>
  9428. * Based on PDF Reference 1.3 (section 5)
  9429. * @param $font (array) font data
  9430. * @protected
  9431. * @author Nicola Asuni
  9432. * @since 1.52.0.TC005 (2005-01-05)
  9433. */
  9434. protected function _puttruetypeunicode($font) {
  9435. $fontname = '';
  9436. if ($font['subset']) {
  9437. // change name for font subsetting
  9438. $subtag = sprintf('%06u', $font['i']);
  9439. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  9440. $fontname .= $subtag.'+';
  9441. }
  9442. $fontname .= $font['name'];
  9443. // Type0 Font
  9444. // A composite font composed of other fonts, organized hierarchically
  9445. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  9446. $out .= '<< /Type /Font';
  9447. $out .= ' /Subtype /Type0';
  9448. $out .= ' /BaseFont /'.$fontname;
  9449. $out .= ' /Name /F'.$font['i'];
  9450. $out .= ' /Encoding /'.$font['enc'];
  9451. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  9452. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  9453. $out .= ' >>';
  9454. $out .= "\n".'endobj';
  9455. $this->_out($out);
  9456. // ToUnicode map for Identity-H
  9457. $stream = "/CIDInit /ProcSet findresource begin\n";
  9458. $stream .= "12 dict begin\n";
  9459. $stream .= "begincmap\n";
  9460. $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n";
  9461. $stream .= "/CMapName /Adobe-Identity-UCS def\n";
  9462. $stream .= "/CMapType 2 def\n";
  9463. $stream .= "/WMode 0 def\n";
  9464. $stream .= "1 begincodespacerange\n";
  9465. $stream .= "<0000> <FFFF>\n";
  9466. $stream .= "endcodespacerange\n";
  9467. $stream .= "100 beginbfrange\n";
  9468. $stream .= "<0000> <00ff> <0000>\n";
  9469. $stream .= "<0100> <01ff> <0100>\n";
  9470. $stream .= "<0200> <02ff> <0200>\n";
  9471. $stream .= "<0300> <03ff> <0300>\n";
  9472. $stream .= "<0400> <04ff> <0400>\n";
  9473. $stream .= "<0500> <05ff> <0500>\n";
  9474. $stream .= "<0600> <06ff> <0600>\n";
  9475. $stream .= "<0700> <07ff> <0700>\n";
  9476. $stream .= "<0800> <08ff> <0800>\n";
  9477. $stream .= "<0900> <09ff> <0900>\n";
  9478. $stream .= "<0a00> <0aff> <0a00>\n";
  9479. $stream .= "<0b00> <0bff> <0b00>\n";
  9480. $stream .= "<0c00> <0cff> <0c00>\n";
  9481. $stream .= "<0d00> <0dff> <0d00>\n";
  9482. $stream .= "<0e00> <0eff> <0e00>\n";
  9483. $stream .= "<0f00> <0fff> <0f00>\n";
  9484. $stream .= "<1000> <10ff> <1000>\n";
  9485. $stream .= "<1100> <11ff> <1100>\n";
  9486. $stream .= "<1200> <12ff> <1200>\n";
  9487. $stream .= "<1300> <13ff> <1300>\n";
  9488. $stream .= "<1400> <14ff> <1400>\n";
  9489. $stream .= "<1500> <15ff> <1500>\n";
  9490. $stream .= "<1600> <16ff> <1600>\n";
  9491. $stream .= "<1700> <17ff> <1700>\n";
  9492. $stream .= "<1800> <18ff> <1800>\n";
  9493. $stream .= "<1900> <19ff> <1900>\n";
  9494. $stream .= "<1a00> <1aff> <1a00>\n";
  9495. $stream .= "<1b00> <1bff> <1b00>\n";
  9496. $stream .= "<1c00> <1cff> <1c00>\n";
  9497. $stream .= "<1d00> <1dff> <1d00>\n";
  9498. $stream .= "<1e00> <1eff> <1e00>\n";
  9499. $stream .= "<1f00> <1fff> <1f00>\n";
  9500. $stream .= "<2000> <20ff> <2000>\n";
  9501. $stream .= "<2100> <21ff> <2100>\n";
  9502. $stream .= "<2200> <22ff> <2200>\n";
  9503. $stream .= "<2300> <23ff> <2300>\n";
  9504. $stream .= "<2400> <24ff> <2400>\n";
  9505. $stream .= "<2500> <25ff> <2500>\n";
  9506. $stream .= "<2600> <26ff> <2600>\n";
  9507. $stream .= "<2700> <27ff> <2700>\n";
  9508. $stream .= "<2800> <28ff> <2800>\n";
  9509. $stream .= "<2900> <29ff> <2900>\n";
  9510. $stream .= "<2a00> <2aff> <2a00>\n";
  9511. $stream .= "<2b00> <2bff> <2b00>\n";
  9512. $stream .= "<2c00> <2cff> <2c00>\n";
  9513. $stream .= "<2d00> <2dff> <2d00>\n";
  9514. $stream .= "<2e00> <2eff> <2e00>\n";
  9515. $stream .= "<2f00> <2fff> <2f00>\n";
  9516. $stream .= "<3000> <30ff> <3000>\n";
  9517. $stream .= "<3100> <31ff> <3100>\n";
  9518. $stream .= "<3200> <32ff> <3200>\n";
  9519. $stream .= "<3300> <33ff> <3300>\n";
  9520. $stream .= "<3400> <34ff> <3400>\n";
  9521. $stream .= "<3500> <35ff> <3500>\n";
  9522. $stream .= "<3600> <36ff> <3600>\n";
  9523. $stream .= "<3700> <37ff> <3700>\n";
  9524. $stream .= "<3800> <38ff> <3800>\n";
  9525. $stream .= "<3900> <39ff> <3900>\n";
  9526. $stream .= "<3a00> <3aff> <3a00>\n";
  9527. $stream .= "<3b00> <3bff> <3b00>\n";
  9528. $stream .= "<3c00> <3cff> <3c00>\n";
  9529. $stream .= "<3d00> <3dff> <3d00>\n";
  9530. $stream .= "<3e00> <3eff> <3e00>\n";
  9531. $stream .= "<3f00> <3fff> <3f00>\n";
  9532. $stream .= "<4000> <40ff> <4000>\n";
  9533. $stream .= "<4100> <41ff> <4100>\n";
  9534. $stream .= "<4200> <42ff> <4200>\n";
  9535. $stream .= "<4300> <43ff> <4300>\n";
  9536. $stream .= "<4400> <44ff> <4400>\n";
  9537. $stream .= "<4500> <45ff> <4500>\n";
  9538. $stream .= "<4600> <46ff> <4600>\n";
  9539. $stream .= "<4700> <47ff> <4700>\n";
  9540. $stream .= "<4800> <48ff> <4800>\n";
  9541. $stream .= "<4900> <49ff> <4900>\n";
  9542. $stream .= "<4a00> <4aff> <4a00>\n";
  9543. $stream .= "<4b00> <4bff> <4b00>\n";
  9544. $stream .= "<4c00> <4cff> <4c00>\n";
  9545. $stream .= "<4d00> <4dff> <4d00>\n";
  9546. $stream .= "<4e00> <4eff> <4e00>\n";
  9547. $stream .= "<4f00> <4fff> <4f00>\n";
  9548. $stream .= "<5000> <50ff> <5000>\n";
  9549. $stream .= "<5100> <51ff> <5100>\n";
  9550. $stream .= "<5200> <52ff> <5200>\n";
  9551. $stream .= "<5300> <53ff> <5300>\n";
  9552. $stream .= "<5400> <54ff> <5400>\n";
  9553. $stream .= "<5500> <55ff> <5500>\n";
  9554. $stream .= "<5600> <56ff> <5600>\n";
  9555. $stream .= "<5700> <57ff> <5700>\n";
  9556. $stream .= "<5800> <58ff> <5800>\n";
  9557. $stream .= "<5900> <59ff> <5900>\n";
  9558. $stream .= "<5a00> <5aff> <5a00>\n";
  9559. $stream .= "<5b00> <5bff> <5b00>\n";
  9560. $stream .= "<5c00> <5cff> <5c00>\n";
  9561. $stream .= "<5d00> <5dff> <5d00>\n";
  9562. $stream .= "<5e00> <5eff> <5e00>\n";
  9563. $stream .= "<5f00> <5fff> <5f00>\n";
  9564. $stream .= "<6000> <60ff> <6000>\n";
  9565. $stream .= "<6100> <61ff> <6100>\n";
  9566. $stream .= "<6200> <62ff> <6200>\n";
  9567. $stream .= "<6300> <63ff> <6300>\n";
  9568. $stream .= "endbfrange\n";
  9569. $stream .= "100 beginbfrange\n";
  9570. $stream .= "<6400> <64ff> <6400>\n";
  9571. $stream .= "<6500> <65ff> <6500>\n";
  9572. $stream .= "<6600> <66ff> <6600>\n";
  9573. $stream .= "<6700> <67ff> <6700>\n";
  9574. $stream .= "<6800> <68ff> <6800>\n";
  9575. $stream .= "<6900> <69ff> <6900>\n";
  9576. $stream .= "<6a00> <6aff> <6a00>\n";
  9577. $stream .= "<6b00> <6bff> <6b00>\n";
  9578. $stream .= "<6c00> <6cff> <6c00>\n";
  9579. $stream .= "<6d00> <6dff> <6d00>\n";
  9580. $stream .= "<6e00> <6eff> <6e00>\n";
  9581. $stream .= "<6f00> <6fff> <6f00>\n";
  9582. $stream .= "<7000> <70ff> <7000>\n";
  9583. $stream .= "<7100> <71ff> <7100>\n";
  9584. $stream .= "<7200> <72ff> <7200>\n";
  9585. $stream .= "<7300> <73ff> <7300>\n";
  9586. $stream .= "<7400> <74ff> <7400>\n";
  9587. $stream .= "<7500> <75ff> <7500>\n";
  9588. $stream .= "<7600> <76ff> <7600>\n";
  9589. $stream .= "<7700> <77ff> <7700>\n";
  9590. $stream .= "<7800> <78ff> <7800>\n";
  9591. $stream .= "<7900> <79ff> <7900>\n";
  9592. $stream .= "<7a00> <7aff> <7a00>\n";
  9593. $stream .= "<7b00> <7bff> <7b00>\n";
  9594. $stream .= "<7c00> <7cff> <7c00>\n";
  9595. $stream .= "<7d00> <7dff> <7d00>\n";
  9596. $stream .= "<7e00> <7eff> <7e00>\n";
  9597. $stream .= "<7f00> <7fff> <7f00>\n";
  9598. $stream .= "<8000> <80ff> <8000>\n";
  9599. $stream .= "<8100> <81ff> <8100>\n";
  9600. $stream .= "<8200> <82ff> <8200>\n";
  9601. $stream .= "<8300> <83ff> <8300>\n";
  9602. $stream .= "<8400> <84ff> <8400>\n";
  9603. $stream .= "<8500> <85ff> <8500>\n";
  9604. $stream .= "<8600> <86ff> <8600>\n";
  9605. $stream .= "<8700> <87ff> <8700>\n";
  9606. $stream .= "<8800> <88ff> <8800>\n";
  9607. $stream .= "<8900> <89ff> <8900>\n";
  9608. $stream .= "<8a00> <8aff> <8a00>\n";
  9609. $stream .= "<8b00> <8bff> <8b00>\n";
  9610. $stream .= "<8c00> <8cff> <8c00>\n";
  9611. $stream .= "<8d00> <8dff> <8d00>\n";
  9612. $stream .= "<8e00> <8eff> <8e00>\n";
  9613. $stream .= "<8f00> <8fff> <8f00>\n";
  9614. $stream .= "<9000> <90ff> <9000>\n";
  9615. $stream .= "<9100> <91ff> <9100>\n";
  9616. $stream .= "<9200> <92ff> <9200>\n";
  9617. $stream .= "<9300> <93ff> <9300>\n";
  9618. $stream .= "<9400> <94ff> <9400>\n";
  9619. $stream .= "<9500> <95ff> <9500>\n";
  9620. $stream .= "<9600> <96ff> <9600>\n";
  9621. $stream .= "<9700> <97ff> <9700>\n";
  9622. $stream .= "<9800> <98ff> <9800>\n";
  9623. $stream .= "<9900> <99ff> <9900>\n";
  9624. $stream .= "<9a00> <9aff> <9a00>\n";
  9625. $stream .= "<9b00> <9bff> <9b00>\n";
  9626. $stream .= "<9c00> <9cff> <9c00>\n";
  9627. $stream .= "<9d00> <9dff> <9d00>\n";
  9628. $stream .= "<9e00> <9eff> <9e00>\n";
  9629. $stream .= "<9f00> <9fff> <9f00>\n";
  9630. $stream .= "<a000> <a0ff> <a000>\n";
  9631. $stream .= "<a100> <a1ff> <a100>\n";
  9632. $stream .= "<a200> <a2ff> <a200>\n";
  9633. $stream .= "<a300> <a3ff> <a300>\n";
  9634. $stream .= "<a400> <a4ff> <a400>\n";
  9635. $stream .= "<a500> <a5ff> <a500>\n";
  9636. $stream .= "<a600> <a6ff> <a600>\n";
  9637. $stream .= "<a700> <a7ff> <a700>\n";
  9638. $stream .= "<a800> <a8ff> <a800>\n";
  9639. $stream .= "<a900> <a9ff> <a900>\n";
  9640. $stream .= "<aa00> <aaff> <aa00>\n";
  9641. $stream .= "<ab00> <abff> <ab00>\n";
  9642. $stream .= "<ac00> <acff> <ac00>\n";
  9643. $stream .= "<ad00> <adff> <ad00>\n";
  9644. $stream .= "<ae00> <aeff> <ae00>\n";
  9645. $stream .= "<af00> <afff> <af00>\n";
  9646. $stream .= "<b000> <b0ff> <b000>\n";
  9647. $stream .= "<b100> <b1ff> <b100>\n";
  9648. $stream .= "<b200> <b2ff> <b200>\n";
  9649. $stream .= "<b300> <b3ff> <b300>\n";
  9650. $stream .= "<b400> <b4ff> <b400>\n";
  9651. $stream .= "<b500> <b5ff> <b500>\n";
  9652. $stream .= "<b600> <b6ff> <b600>\n";
  9653. $stream .= "<b700> <b7ff> <b700>\n";
  9654. $stream .= "<b800> <b8ff> <b800>\n";
  9655. $stream .= "<b900> <b9ff> <b900>\n";
  9656. $stream .= "<ba00> <baff> <ba00>\n";
  9657. $stream .= "<bb00> <bbff> <bb00>\n";
  9658. $stream .= "<bc00> <bcff> <bc00>\n";
  9659. $stream .= "<bd00> <bdff> <bd00>\n";
  9660. $stream .= "<be00> <beff> <be00>\n";
  9661. $stream .= "<bf00> <bfff> <bf00>\n";
  9662. $stream .= "<c000> <c0ff> <c000>\n";
  9663. $stream .= "<c100> <c1ff> <c100>\n";
  9664. $stream .= "<c200> <c2ff> <c200>\n";
  9665. $stream .= "<c300> <c3ff> <c300>\n";
  9666. $stream .= "<c400> <c4ff> <c400>\n";
  9667. $stream .= "<c500> <c5ff> <c500>\n";
  9668. $stream .= "<c600> <c6ff> <c600>\n";
  9669. $stream .= "<c700> <c7ff> <c700>\n";
  9670. $stream .= "endbfrange\n";
  9671. $stream .= "56 beginbfrange\n";
  9672. $stream .= "<c800> <c8ff> <c800>\n";
  9673. $stream .= "<c900> <c9ff> <c900>\n";
  9674. $stream .= "<ca00> <caff> <ca00>\n";
  9675. $stream .= "<cb00> <cbff> <cb00>\n";
  9676. $stream .= "<cc00> <ccff> <cc00>\n";
  9677. $stream .= "<cd00> <cdff> <cd00>\n";
  9678. $stream .= "<ce00> <ceff> <ce00>\n";
  9679. $stream .= "<cf00> <cfff> <cf00>\n";
  9680. $stream .= "<d000> <d0ff> <d000>\n";
  9681. $stream .= "<d100> <d1ff> <d100>\n";
  9682. $stream .= "<d200> <d2ff> <d200>\n";
  9683. $stream .= "<d300> <d3ff> <d300>\n";
  9684. $stream .= "<d400> <d4ff> <d400>\n";
  9685. $stream .= "<d500> <d5ff> <d500>\n";
  9686. $stream .= "<d600> <d6ff> <d600>\n";
  9687. $stream .= "<d700> <d7ff> <d700>\n";
  9688. $stream .= "<d800> <d8ff> <d800>\n";
  9689. $stream .= "<d900> <d9ff> <d900>\n";
  9690. $stream .= "<da00> <daff> <da00>\n";
  9691. $stream .= "<db00> <dbff> <db00>\n";
  9692. $stream .= "<dc00> <dcff> <dc00>\n";
  9693. $stream .= "<dd00> <ddff> <dd00>\n";
  9694. $stream .= "<de00> <deff> <de00>\n";
  9695. $stream .= "<df00> <dfff> <df00>\n";
  9696. $stream .= "<e000> <e0ff> <e000>\n";
  9697. $stream .= "<e100> <e1ff> <e100>\n";
  9698. $stream .= "<e200> <e2ff> <e200>\n";
  9699. $stream .= "<e300> <e3ff> <e300>\n";
  9700. $stream .= "<e400> <e4ff> <e400>\n";
  9701. $stream .= "<e500> <e5ff> <e500>\n";
  9702. $stream .= "<e600> <e6ff> <e600>\n";
  9703. $stream .= "<e700> <e7ff> <e700>\n";
  9704. $stream .= "<e800> <e8ff> <e800>\n";
  9705. $stream .= "<e900> <e9ff> <e900>\n";
  9706. $stream .= "<ea00> <eaff> <ea00>\n";
  9707. $stream .= "<eb00> <ebff> <eb00>\n";
  9708. $stream .= "<ec00> <ecff> <ec00>\n";
  9709. $stream .= "<ed00> <edff> <ed00>\n";
  9710. $stream .= "<ee00> <eeff> <ee00>\n";
  9711. $stream .= "<ef00> <efff> <ef00>\n";
  9712. $stream .= "<f000> <f0ff> <f000>\n";
  9713. $stream .= "<f100> <f1ff> <f100>\n";
  9714. $stream .= "<f200> <f2ff> <f200>\n";
  9715. $stream .= "<f300> <f3ff> <f300>\n";
  9716. $stream .= "<f400> <f4ff> <f400>\n";
  9717. $stream .= "<f500> <f5ff> <f500>\n";
  9718. $stream .= "<f600> <f6ff> <f600>\n";
  9719. $stream .= "<f700> <f7ff> <f700>\n";
  9720. $stream .= "<f800> <f8ff> <f800>\n";
  9721. $stream .= "<f900> <f9ff> <f900>\n";
  9722. $stream .= "<fa00> <faff> <fa00>\n";
  9723. $stream .= "<fb00> <fbff> <fb00>\n";
  9724. $stream .= "<fc00> <fcff> <fc00>\n";
  9725. $stream .= "<fd00> <fdff> <fd00>\n";
  9726. $stream .= "<fe00> <feff> <fe00>\n";
  9727. $stream .= "<ff00> <ffff> <ff00>\n";
  9728. $stream .= "endbfrange\n";
  9729. $stream .= "endcmap\n";
  9730. $stream .= "CMapName currentdict /CMap defineresource pop\n";
  9731. $stream .= "end\n";
  9732. $stream .= "end";
  9733. // ToUnicode Object
  9734. $this->_newobj();
  9735. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  9736. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  9737. $stream = $this->_getrawstream($stream);
  9738. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  9739. // CIDFontType2
  9740. // A CIDFont whose glyph descriptions are based on TrueType font technology
  9741. $oid = $this->_newobj();
  9742. $out = '<< /Type /Font';
  9743. $out .= ' /Subtype /CIDFontType2';
  9744. $out .= ' /BaseFont /'.$fontname;
  9745. // A dictionary containing entries that define the character collection of the CIDFont.
  9746. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  9747. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  9748. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  9749. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  9750. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  9751. $out .= ' /DW '.$font['dw']; // default width
  9752. $out .= "\n".$this->_putfontwidths($font, 0);
  9753. if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
  9754. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  9755. }
  9756. $out .= ' >>';
  9757. $out .= "\n".'endobj';
  9758. $this->_out($out);
  9759. // Font descriptor
  9760. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  9761. $this->_newobj();
  9762. $out = '<< /Type /FontDescriptor';
  9763. $out .= ' /FontName /'.$fontname;
  9764. foreach ($font['desc'] as $key => $value) {
  9765. if(is_float($value)) {
  9766. $value = sprintf('%.3F', $value);
  9767. }
  9768. $out .= ' /'.$key.' '.$value;
  9769. }
  9770. $fontdir = false;
  9771. if (!$this->empty_string($font['file'])) {
  9772. // A stream containing a TrueType font
  9773. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  9774. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  9775. }
  9776. $out .= ' >>';
  9777. $out .= "\n".'endobj';
  9778. $this->_out($out);
  9779. if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
  9780. $this->_newobj();
  9781. // Embed CIDToGIDMap
  9782. // A specification of the mapping from CIDs to glyph indices
  9783. // search and get CTG font file to embedd
  9784. $ctgfile = strtolower($font['ctg']);
  9785. // search and get ctg font file to embedd
  9786. $fontfile = '';
  9787. // search files on various directories
  9788. if (($fontdir !== false) AND file_exists($fontdir.$ctgfile)) {
  9789. $fontfile = $fontdir.$ctgfile;
  9790. } elseif (file_exists($this->_getfontpath().$ctgfile)) {
  9791. $fontfile = $this->_getfontpath().$ctgfile;
  9792. } elseif (file_exists($ctgfile)) {
  9793. $fontfile = $ctgfile;
  9794. }
  9795. if ($this->empty_string($fontfile)) {
  9796. $this->Error('Font file not found: '.$ctgfile);
  9797. }
  9798. $stream = $this->_getrawstream(file_get_contents($fontfile));
  9799. $out = '<< /Length '.strlen($stream).'';
  9800. if (substr($fontfile, -2) == '.z') { // check file extension
  9801. // Decompresses data encoded using the public-domain
  9802. // zlib/deflate compression method, reproducing the
  9803. // original text or binary data
  9804. $out .= ' /Filter /FlateDecode';
  9805. }
  9806. $out .= ' >>';
  9807. $out .= ' stream'."\n".$stream."\n".'endstream';
  9808. $out .= "\n".'endobj';
  9809. $this->_out($out);
  9810. }
  9811. }
  9812. /**
  9813. * Output CID-0 fonts.
  9814. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  9815. * @param $font (array) font data
  9816. * @protected
  9817. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  9818. * @since 3.2.000 (2008-06-23)
  9819. */
  9820. protected function _putcidfont0($font) {
  9821. $cidoffset = 0;
  9822. if (!isset($font['cw'][1])) {
  9823. $cidoffset = 31;
  9824. }
  9825. if (isset($font['cidinfo']['uni2cid'])) {
  9826. // convert unicode to cid.
  9827. $uni2cid = $font['cidinfo']['uni2cid'];
  9828. $cw = array();
  9829. foreach ($font['cw'] as $uni => $width) {
  9830. if (isset($uni2cid[$uni])) {
  9831. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  9832. } elseif ($uni < 256) {
  9833. $cw[$uni] = $width;
  9834. } // else unknown character
  9835. }
  9836. $font = array_merge($font, array('cw' => $cw));
  9837. }
  9838. $name = $font['name'];
  9839. $enc = $font['enc'];
  9840. if ($enc) {
  9841. $longname = $name.'-'.$enc;
  9842. } else {
  9843. $longname = $name;
  9844. }
  9845. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  9846. $out .= '<</Type /Font';
  9847. $out .= ' /Subtype /Type0';
  9848. $out .= ' /BaseFont /'.$longname;
  9849. $out .= ' /Name /F'.$font['i'];
  9850. if ($enc) {
  9851. $out .= ' /Encoding /'.$enc;
  9852. }
  9853. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  9854. $out .= ' >>';
  9855. $out .= "\n".'endobj';
  9856. $this->_out($out);
  9857. $oid = $this->_newobj();
  9858. $out = '<</Type /Font';
  9859. $out .= ' /Subtype /CIDFontType0';
  9860. $out .= ' /BaseFont /'.$name;
  9861. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  9862. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  9863. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  9864. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  9865. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  9866. $out .= ' /DW '.$font['dw'];
  9867. $out .= "\n".$this->_putfontwidths($font, $cidoffset);
  9868. $out .= ' >>';
  9869. $out .= "\n".'endobj';
  9870. $this->_out($out);
  9871. $this->_newobj();
  9872. $s = '<</Type /FontDescriptor /FontName /'.$name;
  9873. foreach ($font['desc'] as $k => $v) {
  9874. if ($k != 'Style') {
  9875. if(is_float($v)) {
  9876. $v = sprintf('%.3F', $v);
  9877. }
  9878. $s .= ' /'.$k.' '.$v.'';
  9879. }
  9880. }
  9881. $s .= '>>';
  9882. $s .= "\n".'endobj';
  9883. $this->_out($s);
  9884. }
  9885. /**
  9886. * Output images.
  9887. * @protected
  9888. */
  9889. protected function _putimages() {
  9890. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  9891. foreach ($this->imagekeys as $file) {
  9892. $info = $this->getImageBuffer($file);
  9893. $oid = $this->_newobj();
  9894. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  9895. $this->setImageSubBuffer($file, 'n', $this->n);
  9896. $out = '<</Type /XObject';
  9897. $out .= ' /Subtype /Image';
  9898. $out .= ' /Width '.$info['w'];
  9899. $out .= ' /Height '.$info['h'];
  9900. if (array_key_exists('masked', $info)) {
  9901. $out .= ' /SMask '.($this->n - 1).' 0 R';
  9902. }
  9903. if ($info['cs'] == 'Indexed') {
  9904. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  9905. } else {
  9906. $out .= ' /ColorSpace /'.$info['cs'];
  9907. if ($info['cs'] == 'DeviceCMYK') {
  9908. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  9909. }
  9910. }
  9911. $out .= ' /BitsPerComponent '.$info['bpc'];
  9912. if (isset($info['f'])) {
  9913. $out .= ' /Filter /'.$info['f'];
  9914. }
  9915. if (isset($info['parms'])) {
  9916. $out .= ' '.$info['parms'];
  9917. }
  9918. if (isset($info['trns']) AND is_array($info['trns'])) {
  9919. $trns='';
  9920. $count_info = count($info['trns']);
  9921. for ($i=0; $i < $count_info; ++$i) {
  9922. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  9923. }
  9924. $out .= ' /Mask ['.$trns.']';
  9925. }
  9926. $stream = $this->_getrawstream($info['data']);
  9927. $out .= ' /Length '.strlen($stream).' >>';
  9928. $out .= ' stream'."\n".$stream."\n".'endstream';
  9929. $out .= "\n".'endobj';
  9930. $this->_out($out);
  9931. //Palette
  9932. if ($info['cs'] == 'Indexed') {
  9933. $this->_newobj();
  9934. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  9935. $pal = $this->_getrawstream($pal);
  9936. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  9937. }
  9938. }
  9939. }
  9940. /**
  9941. * Output Form XObjects Templates.
  9942. * @author Nicola Asuni
  9943. * @since 5.8.017 (2010-08-24)
  9944. * @protected
  9945. * @see startTemplate(), endTemplate(), printTemplate()
  9946. */
  9947. protected function _putxobjects() {
  9948. foreach ($this->xobjects as $key => $data) {
  9949. if (isset($data['outdata'])) {
  9950. $stream = trim($data['outdata']);
  9951. $out = $this->_getobj($data['n'])."\n";
  9952. $out .= '<<';
  9953. $out .= ' /Type /XObject';
  9954. $out .= ' /Subtype /Form';
  9955. $out .= ' /FormType 1';
  9956. if ($this->compress) {
  9957. $stream = gzcompress($stream);
  9958. $out .= ' /Filter /FlateDecode';
  9959. }
  9960. $out .= sprintf(' /BBox [%.2F %.2F %.2F %.2F]', ($data['x'] * $this->k), (-$data['y'] * $this->k), (($data['w'] + $data['x']) * $this->k), (($data['h'] - $data['y']) * $this->k));
  9961. $out .= ' /Matrix [1 0 0 1 0 0]';
  9962. $out .= ' /Resources <<';
  9963. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  9964. // fonts
  9965. if (!empty($data['fonts'])) {
  9966. $out .= ' /Font <<';
  9967. foreach ($data['fonts'] as $fontkey => $fontid) {
  9968. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9969. }
  9970. $out .= ' >>';
  9971. }
  9972. // images or nested xobjects
  9973. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  9974. $out .= ' /XObject <<';
  9975. foreach ($data['images'] as $imgid) {
  9976. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  9977. }
  9978. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  9979. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  9980. }
  9981. $out .= ' >>';
  9982. }
  9983. $out .= ' >>';
  9984. $stream = $this->_getrawstream($stream);
  9985. $out .= ' /Length '.strlen($stream);
  9986. $out .= ' >>';
  9987. $out .= ' stream'."\n".$stream."\n".'endstream';
  9988. $out .= "\n".'endobj';
  9989. $this->_out($out);
  9990. }
  9991. }
  9992. }
  9993. /**
  9994. * Output Spot Colors Resources.
  9995. * @protected
  9996. * @since 4.0.024 (2008-09-12)
  9997. */
  9998. protected function _putspotcolors() {
  9999. foreach ($this->spot_colors as $name => $color) {
  10000. $this->_newobj();
  10001. $this->spot_colors[$name]['n'] = $this->n;
  10002. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  10003. $out .= ' /DeviceCMYK <<';
  10004. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  10005. $out .= ' '.sprintf('/C1 [%.4F %.4F %.4F %.4F] ', ($color['c'] / 100), ($color['m'] / 100), ($color['y'] / 100), ($color['k'] / 100));
  10006. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  10007. $out .= "\n".'endobj';
  10008. $this->_out($out);
  10009. }
  10010. }
  10011. /**
  10012. * Return XObjects Dictionary.
  10013. * @return string XObjects dictionary
  10014. * @protected
  10015. * @since 5.8.014 (2010-08-23)
  10016. */
  10017. protected function _getxobjectdict() {
  10018. $out = '';
  10019. foreach ($this->xobjects as $id => $objid) {
  10020. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  10021. }
  10022. return $out;
  10023. }
  10024. /**
  10025. * Output Resources Dictionary.
  10026. * @protected
  10027. */
  10028. protected function _putresourcedict() {
  10029. $out = $this->_getobj(2)."\n";
  10030. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  10031. $out .= ' /Font <<';
  10032. foreach ($this->fontkeys as $fontkey) {
  10033. $font = $this->getFontBuffer($fontkey);
  10034. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  10035. }
  10036. $out .= ' >>';
  10037. $out .= ' /XObject <<';
  10038. $out .= $this->_getxobjectdict();
  10039. $out .= ' >>';
  10040. // visibility
  10041. $out .= ' /Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R>>';
  10042. // transparency
  10043. $out .= ' /ExtGState <<';
  10044. foreach ($this->extgstates as $k => $extgstate) {
  10045. if (isset($extgstate['name'])) {
  10046. $out .= ' /'.$extgstate['name'];
  10047. } else {
  10048. $out .= ' /GS'.$k;
  10049. }
  10050. $out .= ' '.$extgstate['n'].' 0 R';
  10051. }
  10052. $out .= ' >>';
  10053. // gradient patterns
  10054. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  10055. $out .= ' /Pattern <<';
  10056. foreach ($this->gradients as $id => $grad) {
  10057. $out .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  10058. }
  10059. $out .= ' >>';
  10060. }
  10061. // gradient shadings
  10062. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  10063. $out .= ' /Shading <<';
  10064. foreach ($this->gradients as $id => $grad) {
  10065. $out .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  10066. }
  10067. $out .= ' >>';
  10068. }
  10069. // spot colors
  10070. if (isset($this->spot_colors) AND (count($this->spot_colors) > 0)) {
  10071. $out .= ' /ColorSpace <<';
  10072. foreach ($this->spot_colors as $color) {
  10073. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  10074. }
  10075. $out .= ' >>';
  10076. }
  10077. $out .= ' >>';
  10078. $out .= "\n".'endobj';
  10079. $this->_out($out);
  10080. }
  10081. /**
  10082. * Output Resources.
  10083. * @protected
  10084. */
  10085. protected function _putresources() {
  10086. $this->_putextgstates();
  10087. $this->_putocg();
  10088. $this->_putfonts();
  10089. $this->_putimages();
  10090. $this->_putxobjects();
  10091. $this->_putspotcolors();
  10092. $this->_putshaders();
  10093. $this->_putresourcedict();
  10094. $this->_putbookmarks();
  10095. $this->_putEmbeddedFiles();
  10096. $this->_putannotsobjs();
  10097. $this->_putjavascript();
  10098. $this->_putencryption();
  10099. }
  10100. /**
  10101. * Adds some Metadata information (Document Information Dictionary)
  10102. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  10103. * @return int object id
  10104. * @protected
  10105. */
  10106. protected function _putinfo() {
  10107. $oid = $this->_newobj();
  10108. $out = '<<';
  10109. // store current isunicode value
  10110. $prev_isunicode = $this->isunicode;
  10111. if ($this->docinfounicode) {
  10112. $this->isunicode = true;
  10113. }
  10114. if (!$this->empty_string($this->title)) {
  10115. // The document's title.
  10116. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  10117. }
  10118. if (!$this->empty_string($this->author)) {
  10119. // The name of the person who created the document.
  10120. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  10121. }
  10122. if (!$this->empty_string($this->subject)) {
  10123. // The subject of the document.
  10124. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  10125. }
  10126. if (!$this->empty_string($this->keywords)) {
  10127. // Keywords associated with the document.
  10128. $out .= ' /Keywords '.$this->_textstring($this->keywords.' TCPDF', $oid);
  10129. }
  10130. if (!$this->empty_string($this->creator)) {
  10131. // If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted.
  10132. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  10133. }
  10134. // restore previous isunicode value
  10135. $this->isunicode = $prev_isunicode;
  10136. // default producer
  10137. $out .= ' /Producer '.$this->_textstring("\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", $oid);
  10138. // The date and time the document was created, in human-readable form
  10139. $out .= ' /CreationDate '.$this->_datestring();
  10140. // The date and time the document was most recently modified, in human-readable form
  10141. $out .= ' /ModDate '.$this->_datestring();
  10142. // A name object indicating whether the document has been modified to include trapping information
  10143. $out .= ' /Trapped /False';
  10144. $out .= ' >>';
  10145. $out .= "\n".'endobj';
  10146. $this->_out($out);
  10147. return $oid;
  10148. }
  10149. /**
  10150. * Output Catalog.
  10151. * @return int object id
  10152. * @protected
  10153. */
  10154. protected function _putcatalog() {
  10155. $oid = $this->_newobj();
  10156. $out = '<< /Type /Catalog';
  10157. $out .= ' /Pages 1 0 R';
  10158. if ($this->ZoomMode == 'fullpage') {
  10159. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  10160. } elseif ($this->ZoomMode == 'fullwidth') {
  10161. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  10162. } elseif ($this->ZoomMode == 'real') {
  10163. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  10164. } elseif (!is_string($this->ZoomMode)) {
  10165. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %.2F]',($this->ZoomMode / 100));
  10166. }
  10167. if (isset($this->LayoutMode) AND (!$this->empty_string($this->LayoutMode))) {
  10168. $out .= ' /PageLayout /'.$this->LayoutMode;
  10169. }
  10170. if (isset($this->PageMode) AND (!$this->empty_string($this->PageMode))) {
  10171. $out .= ' /PageMode /'.$this->PageMode;
  10172. }
  10173. if (isset($this->l['a_meta_language'])) {
  10174. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  10175. }
  10176. $out .= ' /Names <<';
  10177. if ((!empty($this->javascript)) OR (!empty($this->js_objects))) {
  10178. $out .= ' /JavaScript '.($this->n_js).' 0 R';
  10179. }
  10180. $out .= ' >>';
  10181. if (count($this->outlines) > 0) {
  10182. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  10183. $out .= ' /PageMode /UseOutlines';
  10184. }
  10185. $out .= ' '.$this->_putviewerpreferences();
  10186. $p = $this->n_ocg_print.' 0 R';
  10187. $v = $this->n_ocg_view.' 0 R';
  10188. $as = '<< /Event /Print /OCGs ['.$p.' '.$v.'] /Category [/Print] >> << /Event /View /OCGs ['.$p.' '.$v.'] /Category [/View] >>';
  10189. $out .= ' /OCProperties << /OCGs ['.$p.' '.$v.'] /D << /ON ['.$p.'] /OFF ['.$v.'] /AS ['.$as.'] >> >>';
  10190. // AcroForm
  10191. if (!empty($this->form_obj_id) OR ($this->sign AND isset($this->signature_data['cert_type']))) {
  10192. $out .= ' /AcroForm <<';
  10193. $objrefs = '';
  10194. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10195. $objrefs .= $this->sig_obj_id.' 0 R';
  10196. }
  10197. if (!empty($this->form_obj_id)) {
  10198. foreach($this->form_obj_id as $objid) {
  10199. $objrefs .= ' '.$objid.' 0 R';
  10200. }
  10201. }
  10202. $out .= ' /Fields ['.$objrefs.']';
  10203. if (!empty($this->form_obj_id) AND !$this->sign) {
  10204. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  10205. $out .= ' /NeedAppearances true';
  10206. }
  10207. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10208. if ($this->signature_data['cert_type'] > 0) {
  10209. $out .= ' /SigFlags 3';
  10210. } else {
  10211. $out .= ' /SigFlags 1';
  10212. }
  10213. }
  10214. //$out .= ' /CO ';
  10215. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  10216. $out .= ' /DR <<';
  10217. $out .= ' /Font <<';
  10218. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  10219. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  10220. }
  10221. $out .= ' >> >>';
  10222. }
  10223. $font = $this->getFontBuffer('helvetica');
  10224. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  10225. $out .= ' /Q '.(($this->rtl)?'2':'0');
  10226. //$out .= ' /XFA ';
  10227. $out .= ' >>';
  10228. // signatures
  10229. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10230. if ($this->signature_data['cert_type'] > 0) {
  10231. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  10232. } else {
  10233. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  10234. }
  10235. }
  10236. }
  10237. $out .= ' >>';
  10238. $out .= "\n".'endobj';
  10239. $this->_out($out);
  10240. return $oid;
  10241. }
  10242. /**
  10243. * Output viewer preferences.
  10244. * @return string for viewer preferences
  10245. * @author Nicola asuni
  10246. * @since 3.1.000 (2008-06-09)
  10247. * @protected
  10248. */
  10249. protected function _putviewerpreferences() {
  10250. $out = '/ViewerPreferences <<';
  10251. if ($this->rtl) {
  10252. $out .= ' /Direction /R2L';
  10253. } else {
  10254. $out .= ' /Direction /L2R';
  10255. }
  10256. if (isset($this->viewer_preferences['HideToolbar']) AND ($this->viewer_preferences['HideToolbar'])) {
  10257. $out .= ' /HideToolbar true';
  10258. }
  10259. if (isset($this->viewer_preferences['HideMenubar']) AND ($this->viewer_preferences['HideMenubar'])) {
  10260. $out .= ' /HideMenubar true';
  10261. }
  10262. if (isset($this->viewer_preferences['HideWindowUI']) AND ($this->viewer_preferences['HideWindowUI'])) {
  10263. $out .= ' /HideWindowUI true';
  10264. }
  10265. if (isset($this->viewer_preferences['FitWindow']) AND ($this->viewer_preferences['FitWindow'])) {
  10266. $out .= ' /FitWindow true';
  10267. }
  10268. if (isset($this->viewer_preferences['CenterWindow']) AND ($this->viewer_preferences['CenterWindow'])) {
  10269. $out .= ' /CenterWindow true';
  10270. }
  10271. if (isset($this->viewer_preferences['DisplayDocTitle']) AND ($this->viewer_preferences['DisplayDocTitle'])) {
  10272. $out .= ' /DisplayDocTitle true';
  10273. }
  10274. if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
  10275. $out .= ' /NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'];
  10276. }
  10277. if (isset($this->viewer_preferences['ViewArea'])) {
  10278. $out .= ' /ViewArea /'.$this->viewer_preferences['ViewArea'];
  10279. }
  10280. if (isset($this->viewer_preferences['ViewClip'])) {
  10281. $out .= ' /ViewClip /'.$this->viewer_preferences['ViewClip'];
  10282. }
  10283. if (isset($this->viewer_preferences['PrintArea'])) {
  10284. $out .= ' /PrintArea /'.$this->viewer_preferences['PrintArea'];
  10285. }
  10286. if (isset($this->viewer_preferences['PrintClip'])) {
  10287. $out .= ' /PrintClip /'.$this->viewer_preferences['PrintClip'];
  10288. }
  10289. if (isset($this->viewer_preferences['PrintScaling'])) {
  10290. $out .= ' /PrintScaling /'.$this->viewer_preferences['PrintScaling'];
  10291. }
  10292. if (isset($this->viewer_preferences['Duplex']) AND (!$this->empty_string($this->viewer_preferences['Duplex']))) {
  10293. $out .= ' /Duplex /'.$this->viewer_preferences['Duplex'];
  10294. }
  10295. if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
  10296. if ($this->viewer_preferences['PickTrayByPDFSize']) {
  10297. $out .= ' /PickTrayByPDFSize true';
  10298. } else {
  10299. $out .= ' /PickTrayByPDFSize false';
  10300. }
  10301. }
  10302. if (isset($this->viewer_preferences['PrintPageRange'])) {
  10303. $PrintPageRangeNum = '';
  10304. foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v) {
  10305. $PrintPageRangeNum .= ' '.($v - 1).'';
  10306. }
  10307. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  10308. }
  10309. if (isset($this->viewer_preferences['NumCopies'])) {
  10310. $out .= ' /NumCopies '.intval($this->viewer_preferences['NumCopies']);
  10311. }
  10312. $out .= ' >>';
  10313. return $out;
  10314. }
  10315. /**
  10316. * Output PDF header.
  10317. * @protected
  10318. */
  10319. protected function _putheader() {
  10320. $this->_out('%PDF-'.$this->PDFVersion);
  10321. }
  10322. /**
  10323. * Output end of document (EOF).
  10324. * @protected
  10325. */
  10326. protected function _enddoc() {
  10327. $this->state = 1;
  10328. $this->_putheader();
  10329. $this->_putpages();
  10330. $this->_putresources();
  10331. // Signature
  10332. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  10333. // widget annotation for signature
  10334. $out = $this->_getobj($this->sig_obj_id)."\n";
  10335. $out .= '<< /Type /Annot';
  10336. $out .= ' /Subtype /Widget';
  10337. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  10338. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  10339. $out .= ' /F 4';
  10340. $out .= ' /FT /Sig';
  10341. $out .= ' /T '.$this->_textstring('Signature', $this->sig_obj_id);
  10342. $out .= ' /Ff 0';
  10343. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  10344. $out .= ' >>';
  10345. $out .= "\n".'endobj';
  10346. $this->_out($out);
  10347. // signature
  10348. $this->_putsignature();
  10349. }
  10350. // Info
  10351. $objid_info = $this->_putinfo();
  10352. // Catalog
  10353. $objid_catalog = $this->_putcatalog();
  10354. // Cross-ref
  10355. $o = $this->bufferlen;
  10356. // XREF section
  10357. $this->_out('xref');
  10358. $this->_out('0 '.($this->n + 1));
  10359. $this->_out('0000000000 65535 f ');
  10360. for ($i=1; $i <= $this->n; ++$i) {
  10361. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  10362. }
  10363. // TRAILER
  10364. $out = 'trailer <<';
  10365. $out .= ' /Size '.($this->n + 1);
  10366. $out .= ' /Root '.$objid_catalog.' 0 R';
  10367. $out .= ' /Info '.$objid_info.' 0 R';
  10368. if ($this->encrypted) {
  10369. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  10370. }
  10371. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  10372. $out .= ' >>';
  10373. $this->_out($out);
  10374. $this->_out('startxref');
  10375. $this->_out($o);
  10376. $this->_out('%%EOF');
  10377. $this->state = 3; // end-of-doc
  10378. if ($this->diskcache) {
  10379. // remove temporary files used for images
  10380. foreach ($this->imagekeys as $key) {
  10381. // remove temporary files
  10382. unlink($this->images[$key]);
  10383. }
  10384. foreach ($this->fontkeys as $key) {
  10385. // remove temporary files
  10386. unlink($this->fonts[$key]);
  10387. }
  10388. }
  10389. }
  10390. /**
  10391. * Initialize a new page.
  10392. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  10393. * @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().
  10394. * @protected
  10395. * @see getPageSizeFromFormat(), setPageFormat()
  10396. */
  10397. protected function _beginpage($orientation='', $format='') {
  10398. ++$this->page;
  10399. $this->setPageBuffer($this->page, '');
  10400. // initialize array for graphics tranformation positions inside a page buffer
  10401. $this->transfmrk[$this->page] = array();
  10402. $this->state = 2;
  10403. if ($this->empty_string($orientation)) {
  10404. if (isset($this->CurOrientation)) {
  10405. $orientation = $this->CurOrientation;
  10406. } elseif ($this->fwPt > $this->fhPt) {
  10407. // landscape
  10408. $orientation = 'L';
  10409. } else {
  10410. // portrait
  10411. $orientation = 'P';
  10412. }
  10413. }
  10414. if ($this->empty_string($format)) {
  10415. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  10416. $this->setPageOrientation($orientation);
  10417. } else {
  10418. $this->setPageFormat($format, $orientation);
  10419. }
  10420. if ($this->rtl) {
  10421. $this->x = $this->w - $this->rMargin;
  10422. } else {
  10423. $this->x = $this->lMargin;
  10424. }
  10425. $this->y = $this->tMargin;
  10426. if (isset($this->newpagegroup[$this->page])) {
  10427. // start a new group
  10428. $n = sizeof($this->pagegroups) + 1;
  10429. $alias = '{nb'.$n.'}';
  10430. $this->pagegroups[$alias] = 1;
  10431. $this->currpagegroup = $alias;
  10432. } elseif ($this->currpagegroup) {
  10433. ++$this->pagegroups[$this->currpagegroup];
  10434. }
  10435. }
  10436. /**
  10437. * Mark end of page.
  10438. * @protected
  10439. */
  10440. protected function _endpage() {
  10441. $this->setVisibility('all');
  10442. $this->state = 1;
  10443. }
  10444. /**
  10445. * Begin a new object and return the object number.
  10446. * @return int object number
  10447. * @protected
  10448. */
  10449. protected function _newobj() {
  10450. $this->_out($this->_getobj());
  10451. return $this->n;
  10452. }
  10453. /**
  10454. * Return the starting object string for the selected object ID.
  10455. * @param $objid (int) Object ID (leave empty to get a new ID).
  10456. * @return string the starting object string
  10457. * @protected
  10458. * @since 5.8.009 (2010-08-20)
  10459. */
  10460. protected function _getobj($objid='') {
  10461. if ($objid === '') {
  10462. ++$this->n;
  10463. $objid = $this->n;
  10464. }
  10465. $this->offsets[$objid] = $this->bufferlen;
  10466. return $objid.' 0 obj';
  10467. }
  10468. /**
  10469. * Underline text.
  10470. * @param $x (int) X coordinate
  10471. * @param $y (int) Y coordinate
  10472. * @param $txt (string) text to underline
  10473. * @protected
  10474. */
  10475. protected function _dounderline($x, $y, $txt) {
  10476. $w = $this->GetStringWidth($txt);
  10477. return $this->_dounderlinew($x, $y, $w);
  10478. }
  10479. /**
  10480. * Underline for rectangular text area.
  10481. * @param $x (int) X coordinate
  10482. * @param $y (int) Y coordinate
  10483. * @param $w (int) width to underline
  10484. * @protected
  10485. * @since 4.8.008 (2009-09-29)
  10486. */
  10487. protected function _dounderlinew($x, $y, $w) {
  10488. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  10489. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  10490. }
  10491. /**
  10492. * Line through text.
  10493. * @param $x (int) X coordinate
  10494. * @param $y (int) Y coordinate
  10495. * @param $txt (string) text to linethrough
  10496. * @protected
  10497. */
  10498. protected function _dolinethrough($x, $y, $txt) {
  10499. $w = $this->GetStringWidth($txt);
  10500. return $this->_dolinethroughw($x, $y, $w);
  10501. }
  10502. /**
  10503. * Line through for rectangular text area.
  10504. * @param $x (int) X coordinate
  10505. * @param $y (int) Y coordinate
  10506. * @param $w (int) line lenght (width)
  10507. * @protected
  10508. * @since 4.9.008 (2009-09-29)
  10509. */
  10510. protected function _dolinethroughw($x, $y, $w) {
  10511. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  10512. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  10513. }
  10514. /**
  10515. * Overline text.
  10516. * @param $x (int) X coordinate
  10517. * @param $y (int) Y coordinate
  10518. * @param $txt (string) text to overline
  10519. * @protected
  10520. * @since 4.9.015 (2010-04-19)
  10521. */
  10522. protected function _dooverline($x, $y, $txt) {
  10523. $w = $this->GetStringWidth($txt);
  10524. return $this->_dooverlinew($x, $y, $w);
  10525. }
  10526. /**
  10527. * Overline for rectangular text area.
  10528. * @param $x (int) X coordinate
  10529. * @param $y (int) Y coordinate
  10530. * @param $w (int) width to overline
  10531. * @protected
  10532. * @since 4.9.015 (2010-04-19)
  10533. */
  10534. protected function _dooverlinew($x, $y, $w) {
  10535. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  10536. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  10537. }
  10538. /**
  10539. * Read a 4-byte (32 bit) integer from file.
  10540. * @param $f (string) file name.
  10541. * @return 4-byte integer
  10542. * @protected
  10543. */
  10544. protected function _freadint($f) {
  10545. $a = unpack('Ni', fread($f, 4));
  10546. return $a['i'];
  10547. }
  10548. /**
  10549. * Add "\" before "\", "(" and ")"
  10550. * @param $s (string) string to escape.
  10551. * @return string escaped string.
  10552. * @protected
  10553. */
  10554. protected function _escape($s) {
  10555. // the chr(13) substitution fixes the Bugs item #1421290.
  10556. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  10557. }
  10558. /**
  10559. * Format a data string for meta information
  10560. * @param $s (string) data string to escape.
  10561. * @param $n (int) object ID
  10562. * @return string escaped string.
  10563. * @protected
  10564. */
  10565. protected function _datastring($s, $n=0) {
  10566. if ($n == 0) {
  10567. $n = $this->n;
  10568. }
  10569. $s = $this->_encrypt_data($n, $s);
  10570. return '('. $this->_escape($s).')';
  10571. }
  10572. /**
  10573. * Returns a formatted date for meta information
  10574. * @param $n (int) object ID
  10575. * @return string escaped date string.
  10576. * @protected
  10577. * @since 4.6.028 (2009-08-25)
  10578. */
  10579. protected function _datestring($n=0) {
  10580. $current_time = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0).'\'';
  10581. return $this->_datastring('D:'.$current_time, $n);
  10582. }
  10583. /**
  10584. * Format a text string for meta information
  10585. * @param $s (string) string to escape.
  10586. * @param $n (int) object ID
  10587. * @return string escaped string.
  10588. * @protected
  10589. */
  10590. protected function _textstring($s, $n=0) {
  10591. if ($this->isunicode) {
  10592. //Convert string to UTF-16BE
  10593. $s = $this->UTF8ToUTF16BE($s, true);
  10594. }
  10595. return $this->_datastring($s, $n);
  10596. }
  10597. /**
  10598. * THIS METHOD IS DEPRECATED
  10599. * Format a text string
  10600. * @param $s (string) string to escape.
  10601. * @return string escaped string.
  10602. * @protected
  10603. * @deprecated
  10604. */
  10605. protected function _escapetext($s) {
  10606. if ($this->isunicode) {
  10607. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  10608. $s = $this->UTF8ToLatin1($s);
  10609. } else {
  10610. //Convert string to UTF-16BE and reverse RTL language
  10611. $s = $this->utf8StrRev($s, false, $this->tmprtl);
  10612. }
  10613. }
  10614. return $this->_escape($s);
  10615. }
  10616. /**
  10617. * get raw output stream.
  10618. * @param $s (string) string to output.
  10619. * @param $n (int) object reference for encryption mode
  10620. * @protected
  10621. * @author Nicola Asuni
  10622. * @since 5.5.000 (2010-06-22)
  10623. */
  10624. protected function _getrawstream($s, $n=0) {
  10625. if ($n <= 0) {
  10626. // default to current object
  10627. $n = $this->n;
  10628. }
  10629. return $this->_encrypt_data($n, $s);
  10630. }
  10631. /**
  10632. * Format output stream (DEPRECATED).
  10633. * @param $s (string) string to output.
  10634. * @param $n (int) object reference for encryption mode
  10635. * @protected
  10636. * @deprecated
  10637. */
  10638. protected function _getstream($s, $n=0) {
  10639. return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
  10640. }
  10641. /**
  10642. * Output a stream (DEPRECATED).
  10643. * @param $s (string) string to output.
  10644. * @param $n (int) object reference for encryption mode
  10645. * @protected
  10646. * @deprecated
  10647. */
  10648. protected function _putstream($s, $n=0) {
  10649. $this->_out($this->_getstream($s, $n));
  10650. }
  10651. /**
  10652. * Output a string to the document.
  10653. * @param $s (string) string to output.
  10654. * @protected
  10655. */
  10656. protected function _out($s) {
  10657. if ($this->state == 2) {
  10658. if ($this->inxobj) {
  10659. // we are inside an XObject template
  10660. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  10661. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  10662. // puts data before page footer
  10663. $pagebuff = $this->getPageBuffer($this->page);
  10664. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  10665. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  10666. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  10667. // update footer position
  10668. $this->footerpos[$this->page] += strlen($s."\n");
  10669. } else {
  10670. $this->setPageBuffer($this->page, $s."\n", true);
  10671. }
  10672. } else {
  10673. $this->setBuffer($s."\n");
  10674. }
  10675. }
  10676. /**
  10677. * Converts UTF-8 strings to codepoints array.<br>
  10678. * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  10679. * Based on: http://www.faqs.org/rfcs/rfc3629.html
  10680. * <pre>
  10681. * Char. number range | UTF-8 octet sequence
  10682. * (hexadecimal) | (binary)
  10683. * --------------------+-----------------------------------------------
  10684. * 0000 0000-0000 007F | 0xxxxxxx
  10685. * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  10686. * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  10687. * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  10688. * ---------------------------------------------------------------------
  10689. *
  10690. * ABFN notation:
  10691. * ---------------------------------------------------------------------
  10692. * UTF8-octets = *( UTF8-char )
  10693. * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  10694. * UTF8-1 = %x00-7F
  10695. * UTF8-2 = %xC2-DF UTF8-tail
  10696. *
  10697. * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  10698. * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  10699. * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  10700. * %xF4 %x80-8F 2( UTF8-tail )
  10701. * UTF8-tail = %x80-BF
  10702. * ---------------------------------------------------------------------
  10703. * </pre>
  10704. * @param $str (string) string to process.
  10705. * @return array containing codepoints (UTF-8 characters values)
  10706. * @protected
  10707. * @author Nicola Asuni
  10708. * @since 1.53.0.TC005 (2005-01-05)
  10709. */
  10710. protected function UTF8StringToArray($str) {
  10711. // build a unique string key
  10712. $strkey = md5($str);
  10713. if (isset($this->cache_UTF8StringToArray[$strkey])) {
  10714. // return cached value
  10715. $chrarray = $this->cache_UTF8StringToArray[$strkey]['s'];
  10716. if (!isset($this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']])) {
  10717. if ($this->isunicode) {
  10718. foreach ($chrarray as $chr) {
  10719. // store this char for font subsetting
  10720. $this->CurrentFont['subsetchars'][$chr] = true;
  10721. }
  10722. // update font subsetchars
  10723. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  10724. }
  10725. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  10726. }
  10727. return $chrarray;
  10728. }
  10729. // check cache size
  10730. if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) {
  10731. // remove first element
  10732. array_shift($this->cache_UTF8StringToArray);
  10733. }
  10734. // new cache array for selected string
  10735. $this->cache_UTF8StringToArray[$strkey] = array('s' => array(), 'f' => array());
  10736. ++$this->cache_size_UTF8StringToArray;
  10737. if (!$this->isunicode) {
  10738. // split string into array of equivalent codes
  10739. $strarr = array();
  10740. $strlen = strlen($str);
  10741. for ($i=0; $i < $strlen; ++$i) {
  10742. $strarr[] = ord($str{$i});
  10743. }
  10744. // insert new value on cache
  10745. $this->cache_UTF8StringToArray[$strkey]['s'] = $strarr;
  10746. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  10747. return $strarr;
  10748. }
  10749. $unichar = -1; // last unicode char
  10750. $unicode = array(); // array containing unicode values
  10751. $bytes = array(); // array containing single character byte sequences
  10752. $numbytes = 1; // number of octetc needed to represent the UTF-8 character
  10753. $str .= ''; // force $str to be a string
  10754. $length = strlen($str);
  10755. for ($i = 0; $i < $length; ++$i) {
  10756. $char = ord($str{$i}); // get one string character at time
  10757. if (count($bytes) == 0) { // get starting octect
  10758. if ($char <= 0x7F) {
  10759. $unichar = $char; // use the character "as is" because is ASCII
  10760. $numbytes = 1;
  10761. } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
  10762. $bytes[] = ($char - 0xC0) << 0x06;
  10763. $numbytes = 2;
  10764. } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
  10765. $bytes[] = ($char - 0xE0) << 0x0C;
  10766. $numbytes = 3;
  10767. } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
  10768. $bytes[] = ($char - 0xF0) << 0x12;
  10769. $numbytes = 4;
  10770. } else {
  10771. // use replacement character for other invalid sequences
  10772. $unichar = 0xFFFD;
  10773. $bytes = array();
  10774. $numbytes = 1;
  10775. }
  10776. } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  10777. $bytes[] = $char - 0x80;
  10778. if (count($bytes) == $numbytes) {
  10779. // compose UTF-8 bytes to a single unicode value
  10780. $char = $bytes[0];
  10781. for ($j = 1; $j < $numbytes; ++$j) {
  10782. $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
  10783. }
  10784. if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  10785. /* The definition of UTF-8 prohibits encoding character numbers between
  10786. U+D800 and U+DFFF, which are reserved for use with the UTF-16
  10787. encoding form (as surrogate pairs) and do not directly represent
  10788. characters. */
  10789. $unichar = 0xFFFD; // use replacement character
  10790. } else {
  10791. $unichar = $char; // add char to array
  10792. }
  10793. // reset data for next char
  10794. $bytes = array();
  10795. $numbytes = 1;
  10796. }
  10797. } else {
  10798. // use replacement character for other invalid sequences
  10799. $unichar = 0xFFFD;
  10800. $bytes = array();
  10801. $numbytes = 1;
  10802. }
  10803. if ($unichar >= 0) {
  10804. // insert unicode value into array
  10805. $unicode[] = $unichar;
  10806. // store this char for font subsetting
  10807. $this->CurrentFont['subsetchars'][$unichar] = true;
  10808. $unichar = -1;
  10809. }
  10810. }
  10811. // update font subsetchars
  10812. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  10813. // insert new value on cache
  10814. $this->cache_UTF8StringToArray[$strkey]['s'] = $unicode;
  10815. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  10816. return $unicode;
  10817. }
  10818. /**
  10819. * Converts UTF-8 strings to UTF16-BE.<br>
  10820. * @param $str (string) string to process.
  10821. * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
  10822. * @return string
  10823. * @author Nicola Asuni
  10824. * @since 1.53.0.TC005 (2005-01-05)
  10825. * @see UTF8StringToArray(), arrUTF8ToUTF16BE()
  10826. * @protected
  10827. */
  10828. protected function UTF8ToUTF16BE($str, $setbom=true) {
  10829. if (!$this->isunicode) {
  10830. return $str; // string is not in unicode
  10831. }
  10832. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  10833. return $this->arrUTF8ToUTF16BE($unicode, $setbom);
  10834. }
  10835. /**
  10836. * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  10837. * @param $str (string) string to process.
  10838. * @return string
  10839. * @author Andrew Whitehead, Nicola Asuni
  10840. * @protected
  10841. * @since 3.2.000 (2008-06-23)
  10842. */
  10843. protected function UTF8ToLatin1($str) {
  10844. if (!$this->isunicode) {
  10845. return $str; // string is not in unicode
  10846. }
  10847. $outstr = ''; // string to be returned
  10848. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  10849. foreach ($unicode as $char) {
  10850. if ($char < 256) {
  10851. $outstr .= chr($char);
  10852. } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
  10853. // map from UTF-8
  10854. $outstr .= chr($this->unicode->uni_utf8tolatin[$char]);
  10855. } elseif ($char == 0xFFFD) {
  10856. // skip
  10857. } else {
  10858. $outstr .= '?';
  10859. }
  10860. }
  10861. return $outstr;
  10862. }
  10863. /**
  10864. * Converts UTF-8 characters array to array of Latin1 characters<br>
  10865. * @param $unicode (array) array containing UTF-8 unicode values
  10866. * @return array
  10867. * @author Nicola Asuni
  10868. * @protected
  10869. * @since 4.8.023 (2010-01-15)
  10870. */
  10871. protected function UTF8ArrToLatin1($unicode) {
  10872. if ((!$this->isunicode) OR $this->isUnicodeFont()) {
  10873. return $unicode;
  10874. }
  10875. $outarr = array(); // array to be returned
  10876. foreach ($unicode as $char) {
  10877. if ($char < 256) {
  10878. $outarr[] = $char;
  10879. } elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin)) {
  10880. // map from UTF-8
  10881. $outarr[] = $this->unicode->uni_utf8tolatin[$char];
  10882. } elseif ($char == 0xFFFD) {
  10883. // skip
  10884. } else {
  10885. $outarr[] = 63; // '?' character
  10886. }
  10887. }
  10888. return $outarr;
  10889. }
  10890. /**
  10891. * Converts array of UTF-8 characters to UTF16-BE string.<br>
  10892. * Based on: http://www.faqs.org/rfcs/rfc2781.html
  10893. * <pre>
  10894. * Encoding UTF-16:
  10895. *
  10896. * Encoding of a single character from an ISO 10646 character value to
  10897. * UTF-16 proceeds as follows. Let U be the character number, no greater
  10898. * than 0x10FFFF.
  10899. *
  10900. * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  10901. * terminate.
  10902. *
  10903. * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  10904. * U' must be less than or equal to 0xFFFFF. That is, U' can be
  10905. * represented in 20 bits.
  10906. *
  10907. * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  10908. * 0xDC00, respectively. These integers each have 10 bits free to
  10909. * encode the character value, for a total of 20 bits.
  10910. *
  10911. * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  10912. * bits of W1 and the 10 low-order bits of U' to the 10 low-order
  10913. * bits of W2. Terminate.
  10914. *
  10915. * Graphically, steps 2 through 4 look like:
  10916. * U' = yyyyyyyyyyxxxxxxxxxx
  10917. * W1 = 110110yyyyyyyyyy
  10918. * W2 = 110111xxxxxxxxxx
  10919. * </pre>
  10920. * @param $unicode (array) array containing UTF-8 unicode values
  10921. * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
  10922. * @return string
  10923. * @protected
  10924. * @author Nicola Asuni
  10925. * @since 2.1.000 (2008-01-08)
  10926. * @see UTF8ToUTF16BE()
  10927. */
  10928. protected function arrUTF8ToUTF16BE($unicode, $setbom=true) {
  10929. $outstr = ''; // string to be returned
  10930. if ($setbom) {
  10931. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  10932. }
  10933. foreach ($unicode as $char) {
  10934. if ($char == 0x200b) {
  10935. // skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  10936. } elseif ($char == 0xFFFD) {
  10937. $outstr .= "\xFF\xFD"; // replacement character
  10938. } elseif ($char < 0x10000) {
  10939. $outstr .= chr($char >> 0x08);
  10940. $outstr .= chr($char & 0xFF);
  10941. } else {
  10942. $char -= 0x10000;
  10943. $w1 = 0xD800 | ($char >> 0x10);
  10944. $w2 = 0xDC00 | ($char & 0x3FF);
  10945. $outstr .= chr($w1 >> 0x08);
  10946. $outstr .= chr($w1 & 0xFF);
  10947. $outstr .= chr($w2 >> 0x08);
  10948. $outstr .= chr($w2 & 0xFF);
  10949. }
  10950. }
  10951. return $outstr;
  10952. }
  10953. // ====================================================
  10954. /**
  10955. * Set header font.
  10956. * @param $font (array) font
  10957. * @public
  10958. * @since 1.1
  10959. */
  10960. public function setHeaderFont($font) {
  10961. $this->header_font = $font;
  10962. }
  10963. /**
  10964. * Get header font.
  10965. * @return array()
  10966. * @public
  10967. * @since 4.0.012 (2008-07-24)
  10968. */
  10969. public function getHeaderFont() {
  10970. return $this->header_font;
  10971. }
  10972. /**
  10973. * Set footer font.
  10974. * @param $font (array) font
  10975. * @public
  10976. * @since 1.1
  10977. */
  10978. public function setFooterFont($font) {
  10979. $this->footer_font = $font;
  10980. }
  10981. /**
  10982. * Get Footer font.
  10983. * @return array()
  10984. * @public
  10985. * @since 4.0.012 (2008-07-24)
  10986. */
  10987. public function getFooterFont() {
  10988. return $this->footer_font;
  10989. }
  10990. /**
  10991. * Set language array.
  10992. * @param $language (array)
  10993. * @public
  10994. * @since 1.1
  10995. */
  10996. public function setLanguageArray($language) {
  10997. $this->l = $language;
  10998. if (isset($this->l['a_meta_dir'])) {
  10999. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  11000. } else {
  11001. $this->rtl = false;
  11002. }
  11003. }
  11004. /**
  11005. * Returns the PDF data.
  11006. * @public
  11007. */
  11008. public function getPDFData() {
  11009. if ($this->state < 3) {
  11010. $this->Close();
  11011. }
  11012. return $this->buffer;
  11013. }
  11014. /**
  11015. * Output anchor link.
  11016. * @param $url (string) link URL or internal link (i.e.: &lt;a href="#23,4.5"&gt;link to page 23 at 4.5 Y position&lt;/a&gt;)
  11017. * @param $name (string) link name
  11018. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (