PageRenderTime 241ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 3ms

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

https://bitbucket.org/cbenelug/chamilo
PHP | 12620 lines | 8676 code | 397 blank | 3547 comment | 994 complexity | 721400aec663f78f78f877c4863d1691 MD5 | raw file
Possible License(s): GPL-3.0, MIT, GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 5.9.009
  5. // Begin : 2002-08-03
  6. // Last Update : 2010-10-21
  7. // Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  8. // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2010 Nicola Asuni - Tecnick.com S.r.l.
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the GNU Lesser General Public License
  25. // along with TCPDF. If not, see <http://www.gnu.org/licenses/>.
  26. //
  27. // See LICENSE.TXT file for more information.
  28. // -------------------------------------------------------------------
  29. //
  30. // Description : This is a PHP class for generating PDF documents without
  31. // requiring external extensions.
  32. //
  33. // NOTE:
  34. // This class was originally derived in 2002 from the Public
  35. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  36. // but now is almost entirely rewritten and contains thousands of
  37. // new lines of code and hundreds new features.
  38. //
  39. // Main features:
  40. // * no external libraries are required for the basic functions;
  41. // * all standard page formats, custom page formats, custom margins and units of measure;
  42. // * UTF-8 Unicode and Right-To-Left languages;
  43. // * TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  44. // * font subsetting;
  45. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  46. // * images, graphic (geometric figures) and transformation methods;
  47. // * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)
  48. // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, QR-Code, PDF417;
  49. // * Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  50. // * automatic page header and footer management;
  51. // * document encryption up to 256 bit and digital signature certifications;
  52. // * transactions to UNDO commands;
  53. // * PDF annotations, including links, text and file attachments;
  54. // * text rendering modes (fill, stroke and clipping);
  55. // * multiple columns mode;
  56. // * no-write page regions;
  57. // * bookmarks and table of content;
  58. // * text hyphenation;
  59. // * text stretching and spacing (tracking/kerning);
  60. // * automatic page break, line break and text alignments including justification;
  61. // * automatic page numbering and page groups;
  62. // * move and delete pages;
  63. // * page compression (requires php-zlib extension);
  64. // * XOBject Templates;
  65. //
  66. // -----------------------------------------------------------
  67. // THANKS TO:
  68. //
  69. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  70. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  71. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  72. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  73. // dullus for text Justification.
  74. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  75. // Patrick Benny for text stretch suggestion on Cell().
  76. // Johannes G�ntert for JavaScript support.
  77. // Denis Van Nuffelen for Dynamic Form.
  78. // Jacek Czekaj for multibyte justification
  79. // Anthony Ferrara for the reintroduction of legacy image methods.
  80. // Sourceforge user 1707880 (hucste) for line-trough mode.
  81. // Larry Stanbery for page groups.
  82. // Martin Hall-May for transparency.
  83. // Aaron C. Spike for Polycurve method.
  84. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  85. // Moritz Wagner and Andreas Wurmser for graphic functions.
  86. // Andrew Whitehead for core fonts support.
  87. // Esteban Jo�l Mar�n for OpenType font conversion.
  88. // Teus Hagen for several suggestions and fixes.
  89. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  90. // Kosmas Papachristos for some CSS improvements.
  91. // Marcel Partap for some fixes.
  92. // Won Kyu Park for several suggestions, fixes and patches.
  93. // Dominik Dzienia for QR-code support.
  94. // Laurent Minguet for some suggestions.
  95. // Christian Deligant for some suggestions and fixes.
  96. // Anyone that has reported a bug or sent a suggestion.
  97. //============================================================+
  98. /**
  99. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  100. * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  101. * <h3>TCPDF main features are:</h3>
  102. * <ul>
  103. * <li>no external libraries are required for the basic functions;</li>
  104. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  105. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  106. * <li>TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  107. * <li>font subsetting;</li>
  108. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  109. * <li>images, graphic (geometric figures) and transformation methods;
  110. * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)</li>
  111. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, QR-Code, PDF417;</li>
  112. * <li>Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  113. * <li>automatic page header and footer management;</li>
  114. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  115. * <li>transactions to UNDO commands;</li>
  116. * <li>PDF annotations, including links, text and file attachments;</li>
  117. * <li>text rendering modes (fill, stroke and clipping);</li>
  118. * <li>multiple columns mode;</li>
  119. * <li>no-write page regions;</li>
  120. * <li>bookmarks and table of content;</li>
  121. * <li>text hyphenation;</li>
  122. * <li>text stretching and spacing (tracking/kerning);</li>
  123. * <li>automatic page break, line break and text alignments including justification;</li>
  124. * <li>automatic page numbering and page groups;</li>
  125. * <li>move and delete pages;</li>
  126. * <li>page compression (requires php-zlib extension);</li>
  127. * <li>XOBject Templates;</li>
  128. * </ul>
  129. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  130. * @package com.tecnick.tcpdf
  131. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  132. * @author Nicola Asuni
  133. * @copyright 2002-2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  134. * @link http://www.tcpdf.org
  135. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  136. * @version 5.9.009
  137. */
  138. /**
  139. * main configuration file
  140. * (define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file)
  141. */
  142. require_once (dirname(__FILE__) . '/config/tcpdf_config.php');
  143. /**
  144. * define default PDF document producer
  145. */
  146. define('PDF_PRODUCER', 'TCPDF 5.9.009 (http://www.tcpdf.org)');
  147. /**
  148. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  149. * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  150. * @name TCPDF
  151. * @package com.tecnick.tcpdf
  152. * @version 5.9.009
  153. * @author Nicola Asuni - info@tecnick.com
  154. * @link http://www.tcpdf.org
  155. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  156. */
  157. class TCPDF
  158. {
  159. // Protected properties
  160. /**
  161. * @var current page number
  162. * @access protected
  163. */
  164. protected $page;
  165. /**
  166. * @var current object number
  167. * @access protected
  168. */
  169. protected $n;
  170. /**
  171. * @var array of object offsets
  172. * @access protected
  173. */
  174. protected $offsets;
  175. /**
  176. * @var buffer holding in-memory PDF
  177. * @access protected
  178. */
  179. protected $buffer;
  180. /**
  181. * @var array containing pages
  182. * @access protected
  183. */
  184. protected $pages = array();
  185. /**
  186. * @var current document state
  187. * @access protected
  188. */
  189. protected $state;
  190. /**
  191. * @var compression flag
  192. * @access protected
  193. */
  194. protected $compress;
  195. /**
  196. * @var current page orientation (P = Portrait, L = Landscape)
  197. * @access protected
  198. */
  199. protected $CurOrientation;
  200. /**
  201. * @var Page dimensions
  202. * @access protected
  203. */
  204. protected $pagedim = array();
  205. /**
  206. * @var scale factor (number of points in user unit)
  207. * @access protected
  208. */
  209. protected $k;
  210. /**
  211. * @var width of page format in points
  212. * @access protected
  213. */
  214. protected $fwPt;
  215. /**
  216. * @var height of page format in points
  217. * @access protected
  218. */
  219. protected $fhPt;
  220. /**
  221. * @var current width of page in points
  222. * @access protected
  223. */
  224. protected $wPt;
  225. /**
  226. * @var current height of page in points
  227. * @access protected
  228. */
  229. protected $hPt;
  230. /**
  231. * @var current width of page in user unit
  232. * @access protected
  233. */
  234. protected $w;
  235. /**
  236. * @var current height of page in user unit
  237. * @access protected
  238. */
  239. protected $h;
  240. /**
  241. * @var left margin
  242. * @access protected
  243. */
  244. protected $lMargin;
  245. /**
  246. * @var top margin
  247. * @access protected
  248. */
  249. protected $tMargin;
  250. /**
  251. * @var right margin
  252. * @access protected
  253. */
  254. protected $rMargin;
  255. /**
  256. * @var page break margin
  257. * @access protected
  258. */
  259. protected $bMargin;
  260. /**
  261. * @var array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left)
  262. * @since 5.9.000 (2010-10-03)
  263. * @access protected
  264. */
  265. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  266. /**
  267. * @var array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left)
  268. * @since 5.9.000 (2010-10-04)
  269. * @access protected
  270. */
  271. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  272. /**
  273. * @var current horizontal position in user unit for cell positioning
  274. * @access protected
  275. */
  276. protected $x;
  277. /**
  278. * @var current vertical position in user unit for cell positioning
  279. * @access protected
  280. */
  281. protected $y;
  282. /**
  283. * @var height of last cell printed
  284. * @access protected
  285. */
  286. protected $lasth;
  287. /**
  288. * @var line width in user unit
  289. * @access protected
  290. */
  291. protected $LineWidth;
  292. /**
  293. * @var array of standard font names
  294. * @access protected
  295. */
  296. protected $CoreFonts;
  297. /**
  298. * @var array of used fonts
  299. * @access protected
  300. */
  301. protected $fonts = array();
  302. /**
  303. * @var array of font files
  304. * @access protected
  305. */
  306. protected $FontFiles = array();
  307. /**
  308. * @var array of encoding differences
  309. * @access protected
  310. */
  311. protected $diffs = array();
  312. /**
  313. * @var array of used images
  314. * @access protected
  315. */
  316. protected $images = array();
  317. /**
  318. * @var array of Annotations in pages
  319. * @access protected
  320. */
  321. protected $PageAnnots = array();
  322. /**
  323. * @var array of internal links
  324. * @access protected
  325. */
  326. protected $links = array();
  327. /**
  328. * @var current font family
  329. * @access protected
  330. */
  331. protected $FontFamily;
  332. /**
  333. * @var current font style
  334. * @access protected
  335. */
  336. protected $FontStyle;
  337. /**
  338. * @var current font ascent (distance between font top and baseline)
  339. * @access protected
  340. * @since 2.8.000 (2007-03-29)
  341. */
  342. protected $FontAscent;
  343. /**
  344. * @var current font descent (distance between font bottom and baseline)
  345. * @access protected
  346. * @since 2.8.000 (2007-03-29)
  347. */
  348. protected $FontDescent;
  349. /**
  350. * @var underlining flag
  351. * @access protected
  352. */
  353. protected $underline;
  354. /**
  355. * @var overlining flag
  356. * @access protected
  357. */
  358. protected $overline;
  359. /**
  360. * @var current font info
  361. * @access protected
  362. */
  363. protected $CurrentFont;
  364. /**
  365. * @var current font size in points
  366. * @access protected
  367. */
  368. protected $FontSizePt;
  369. /**
  370. * @var current font size in user unit
  371. * @access protected
  372. */
  373. protected $FontSize;
  374. /**
  375. * @var commands for drawing color
  376. * @access protected
  377. */
  378. protected $DrawColor;
  379. /**
  380. * @var commands for filling color
  381. * @access protected
  382. */
  383. protected $FillColor;
  384. /**
  385. * @var commands for text color
  386. * @access protected
  387. */
  388. protected $TextColor;
  389. /**
  390. * @var indicates whether fill and text colors are different
  391. * @access protected
  392. */
  393. protected $ColorFlag;
  394. /**
  395. * @var automatic page breaking
  396. * @access protected
  397. */
  398. protected $AutoPageBreak;
  399. /**
  400. * @var threshold used to trigger page breaks
  401. * @access protected
  402. */
  403. protected $PageBreakTrigger;
  404. /**
  405. * @var flag set when processing footer
  406. * @access protected
  407. */
  408. protected $InFooter = false;
  409. /**
  410. * @var zoom display mode
  411. * @access protected
  412. */
  413. protected $ZoomMode;
  414. /**
  415. * @var layout display mode
  416. * @access protected
  417. */
  418. protected $LayoutMode;
  419. /**
  420. * @var title
  421. * @access protected
  422. */
  423. protected $title = '';
  424. /**
  425. * @var subject
  426. * @access protected
  427. */
  428. protected $subject = '';
  429. /**
  430. * @var author
  431. * @access protected
  432. */
  433. protected $author = '';
  434. /**
  435. * @var keywords
  436. * @access protected
  437. */
  438. protected $keywords = '';
  439. /**
  440. * @var creator
  441. * @access protected
  442. */
  443. protected $creator = '';
  444. /**
  445. * @var alias for total number of pages
  446. * @access protected
  447. */
  448. protected $AliasNbPages = '{nb}';
  449. /**
  450. * @var alias for page number
  451. * @access protected
  452. */
  453. protected $AliasNumPage = '{pnb}';
  454. /**
  455. * @var right-bottom corner X coordinate of inserted image
  456. * @since 2002-07-31
  457. * @author Nicola Asuni
  458. * @access protected
  459. */
  460. protected $img_rb_x;
  461. /**
  462. * @var right-bottom corner Y coordinate of inserted image
  463. * @since 2002-07-31
  464. * @author Nicola Asuni
  465. * @access protected
  466. */
  467. protected $img_rb_y;
  468. /**
  469. * @var adjusting factor to convert pixels to user units.
  470. * @since 2004-06-14
  471. * @author Nicola Asuni
  472. * @access protected
  473. */
  474. protected $imgscale = 1;
  475. /**
  476. * @var boolean set to true when the input text is unicode (require unicode fonts)
  477. * @since 2005-01-02
  478. * @author Nicola Asuni
  479. * @access protected
  480. */
  481. protected $isunicode = false;
  482. /**
  483. * @var object containing unicode data
  484. * @since 5.9.004 (2010-10-18)
  485. * @author Nicola Asuni
  486. * @access protected
  487. */
  488. protected $unicode;
  489. /**
  490. * @var PDF version
  491. * @since 1.5.3
  492. * @access protected
  493. */
  494. protected $PDFVersion = '1.7';
  495. /**
  496. * @var Minimum distance between header and top page margin.
  497. * @access protected
  498. */
  499. protected $header_margin;
  500. /**
  501. * @var Minimum distance between footer and bottom page margin.
  502. * @access protected
  503. */
  504. protected $footer_margin;
  505. /**
  506. * @var original left margin value
  507. * @access protected
  508. * @since 1.53.0.TC013
  509. */
  510. protected $original_lMargin;
  511. /**
  512. * @var original right margin value
  513. * @access protected
  514. * @since 1.53.0.TC013
  515. */
  516. protected $original_rMargin;
  517. /**
  518. * @var Header font.
  519. * @access protected
  520. */
  521. protected $header_font;
  522. /**
  523. * @var Footer font.
  524. * @access protected
  525. */
  526. protected $footer_font;
  527. /**
  528. * @var Language templates.
  529. * @access protected
  530. */
  531. protected $l;
  532. /**
  533. * @var Barcode to print on page footer (only if set).
  534. * @access protected
  535. */
  536. protected $barcode = false;
  537. /**
  538. * @var If true prints header
  539. * @access protected
  540. */
  541. protected $print_header = true;
  542. /**
  543. * @var If true prints footer.
  544. * @access protected
  545. */
  546. protected $print_footer = true;
  547. /**
  548. * @var Header image logo.
  549. * @access protected
  550. */
  551. protected $header_logo = '';
  552. /**
  553. * @var Header image logo width in mm.
  554. * @access protected
  555. */
  556. protected $header_logo_width = 30;
  557. /**
  558. * @var String to print as title on document header.
  559. * @access protected
  560. */
  561. protected $header_title = '';
  562. /**
  563. * @var String to print on document header.
  564. * @access protected
  565. */
  566. protected $header_string = '';
  567. /**
  568. * @var Default number of columns for html table.
  569. * @access protected
  570. */
  571. protected $default_table_columns = 4;
  572. // variables for html parser
  573. /**
  574. * @var HTML PARSER: array to store current link and rendering styles.
  575. * @access protected
  576. */
  577. protected $HREF = array();
  578. /**
  579. * @var store a list of available fonts on filesystem.
  580. * @access protected
  581. */
  582. protected $fontlist = array();
  583. /**
  584. * @var current foreground color
  585. * @access protected
  586. */
  587. protected $fgcolor;
  588. /**
  589. * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  590. * @access protected
  591. */
  592. protected $listordered = array();
  593. /**
  594. * @var HTML PARSER: array count list items on nested lists.
  595. * @access protected
  596. */
  597. protected $listcount = array();
  598. /**
  599. * @var HTML PARSER: current list nesting level.
  600. * @access protected
  601. */
  602. protected $listnum = 0;
  603. /**
  604. * @var HTML PARSER: indent amount for lists.
  605. * @access protected
  606. */
  607. protected $listindent = 0;
  608. /**
  609. * @var HTML PARSER: current list indententation level.
  610. * @access protected
  611. */
  612. protected $listindentlevel = 0;
  613. /**
  614. * @var current background color
  615. * @access protected
  616. */
  617. protected $bgcolor;
  618. /**
  619. * @var Store temporary font size in points.
  620. * @access protected
  621. */
  622. protected $tempfontsize = 10;
  623. /**
  624. * @var spacer for LI tags.
  625. * @access protected
  626. */
  627. protected $lispacer = '';
  628. /**
  629. * @var default encoding
  630. * @access protected
  631. * @since 1.53.0.TC010
  632. */
  633. protected $encoding = 'UTF-8';
  634. /**
  635. * @var PHP internal encoding
  636. * @access protected
  637. * @since 1.53.0.TC016
  638. */
  639. protected $internal_encoding;
  640. /**
  641. * @var indicates if the document language is Right-To-Left
  642. * @access protected
  643. * @since 2.0.000
  644. */
  645. protected $rtl = false;
  646. /**
  647. * @var used to force RTL or LTR string inversion
  648. * @access protected
  649. * @since 2.0.000
  650. */
  651. protected $tmprtl = false;
  652. // --- Variables used for document encryption:
  653. /**
  654. * Indicates whether document is protected
  655. * @access protected
  656. * @since 2.0.000 (2008-01-02)
  657. */
  658. protected $encrypted;
  659. /**
  660. * Array containing encryption settings
  661. * @access protected
  662. * @since 5.0.005 (2010-05-11)
  663. */
  664. protected $encryptdata = array();
  665. /**
  666. * last RC4 key encrypted (cached for optimisation)
  667. * @access protected
  668. * @since 2.0.000 (2008-01-02)
  669. */
  670. protected $last_enc_key;
  671. /**
  672. * last RC4 computed key
  673. * @access protected
  674. * @since 2.0.000 (2008-01-02)
  675. */
  676. protected $last_enc_key_c;
  677. /**
  678. * Encryption padding
  679. * @access protected
  680. */
  681. protected $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  682. /**
  683. * File ID (used on trailer)
  684. * @access protected
  685. * @since 5.0.005 (2010-05-12)
  686. */
  687. protected $file_id;
  688. // --- bookmark ---
  689. /**
  690. * Outlines for bookmark
  691. * @access protected
  692. * @since 2.1.002 (2008-02-12)
  693. */
  694. protected $outlines = array();
  695. /**
  696. * Outline root for bookmark
  697. * @access protected
  698. * @since 2.1.002 (2008-02-12)
  699. */
  700. protected $OutlineRoot;
  701. // --- javascript and form ---
  702. /**
  703. * javascript code
  704. * @access protected
  705. * @since 2.1.002 (2008-02-12)
  706. */
  707. protected $javascript = '';
  708. /**
  709. * javascript counter
  710. * @access protected
  711. * @since 2.1.002 (2008-02-12)
  712. */
  713. protected $n_js;
  714. /**
  715. * line trough state
  716. * @access protected
  717. * @since 2.8.000 (2008-03-19)
  718. */
  719. protected $linethrough;
  720. /**
  721. * Array with additional document-wide usage rights for the document.
  722. * @access protected
  723. * @since 5.8.014 (2010-08-23)
  724. */
  725. protected $ur = array();
  726. /**
  727. * Dot Per Inch Document Resolution (do not change)
  728. * @access protected
  729. * @since 3.0.000 (2008-03-27)
  730. */
  731. protected $dpi = 72;
  732. /**
  733. * Array of page numbers were a new page group was started
  734. * @access protected
  735. * @since 3.0.000 (2008-03-27)
  736. */
  737. protected $newpagegroup = array();
  738. /**
  739. * Contains the number of pages of the groups
  740. * @access protected
  741. * @since 3.0.000 (2008-03-27)
  742. */
  743. protected $pagegroups;
  744. /**
  745. * Contains the alias of the current page group
  746. * @access protected
  747. * @since 3.0.000 (2008-03-27)
  748. */
  749. protected $currpagegroup;
  750. /**
  751. * Restrict the rendering of some elements to screen or printout.
  752. * @access protected
  753. * @since 3.0.000 (2008-03-27)
  754. */
  755. protected $visibility = 'all';
  756. /**
  757. * Print visibility.
  758. * @access protected
  759. * @since 3.0.000 (2008-03-27)
  760. */
  761. protected $n_ocg_print;
  762. /**
  763. * View visibility.
  764. * @access protected
  765. * @since 3.0.000 (2008-03-27)
  766. */
  767. protected $n_ocg_view;
  768. /**
  769. * Array of transparency objects and parameters.
  770. * @access protected
  771. * @since 3.0.000 (2008-03-27)
  772. */
  773. protected $extgstates;
  774. /**
  775. * Set the default JPEG compression quality (1-100)
  776. * @access protected
  777. * @since 3.0.000 (2008-03-27)
  778. */
  779. protected $jpeg_quality;
  780. /**
  781. * Default cell height ratio.
  782. * @access protected
  783. * @since 3.0.014 (2008-05-23)
  784. */
  785. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  786. /**
  787. * PDF viewer preferences.
  788. * @access protected
  789. * @since 3.1.000 (2008-06-09)
  790. */
  791. protected $viewer_preferences;
  792. /**
  793. * A name object specifying how the document should be displayed when opened.
  794. * @access protected
  795. * @since 3.1.000 (2008-06-09)
  796. */
  797. protected $PageMode;
  798. /**
  799. * Array for storing gradient information.
  800. * @access protected
  801. * @since 3.1.000 (2008-06-09)
  802. */
  803. protected $gradients = array();
  804. /**
  805. * Array used to store positions inside the pages buffer.
  806. * keys are the page numbers
  807. * @access protected
  808. * @since 3.2.000 (2008-06-26)
  809. */
  810. protected $intmrk = array();
  811. /**
  812. * Array used to store positions inside the pages buffer.
  813. * keys are the page numbers
  814. * @access protected
  815. * @since 5.7.000 (2010-08-03)
  816. */
  817. protected $bordermrk = array();
  818. /**
  819. * Array used to store page positions to track empty pages.
  820. * keys are the page numbers
  821. * @access protected
  822. * @since 5.8.007 (2010-08-18)
  823. */
  824. protected $emptypagemrk = array();
  825. /**
  826. * Array used to store content positions inside the pages buffer.
  827. * keys are the page numbers
  828. * @access protected
  829. * @since 4.6.021 (2009-07-20)
  830. */
  831. protected $cntmrk = array();
  832. /**
  833. * Array used to store footer positions of each page.
  834. * @access protected
  835. * @since 3.2.000 (2008-07-01)
  836. */
  837. protected $footerpos = array();
  838. /**
  839. * Array used to store footer length of each page.
  840. * @access protected
  841. * @since 4.0.014 (2008-07-29)
  842. */
  843. protected $footerlen = array();
  844. /**
  845. * True if a newline is created.
  846. * @access protected
  847. * @since 3.2.000 (2008-07-01)
  848. */
  849. protected $newline = true;
  850. /**
  851. * End position of the latest inserted line
  852. * @access protected
  853. * @since 3.2.000 (2008-07-01)
  854. */
  855. protected $endlinex = 0;
  856. /**
  857. * PDF string for last line width
  858. * @access protected
  859. * @since 4.0.006 (2008-07-16)
  860. */
  861. protected $linestyleWidth = '';
  862. /**
  863. * PDF string for last line width
  864. * @access protected
  865. * @since 4.0.006 (2008-07-16)
  866. */
  867. protected $linestyleCap = '0 J';
  868. /**
  869. * PDF string for last line width
  870. * @access protected
  871. * @since 4.0.006 (2008-07-16)
  872. */
  873. protected $linestyleJoin = '0 j';
  874. /**
  875. * PDF string for last line width
  876. * @access protected
  877. * @since 4.0.006 (2008-07-16)
  878. */
  879. protected $linestyleDash = '[] 0 d';
  880. /**
  881. * True if marked-content sequence is open
  882. * @access protected
  883. * @since 4.0.013 (2008-07-28)
  884. */
  885. protected $openMarkedContent = false;
  886. /**
  887. * Count the latest inserted vertical spaces on HTML
  888. * @access protected
  889. * @since 4.0.021 (2008-08-24)
  890. */
  891. protected $htmlvspace = 0;
  892. /**
  893. * Array of Spot colors
  894. * @access protected
  895. * @since 4.0.024 (2008-09-12)
  896. */
  897. protected $spot_colors = array();
  898. /**
  899. * Symbol used for HTML unordered list items
  900. * @access protected
  901. * @since 4.0.028 (2008-09-26)
  902. */
  903. protected $lisymbol = '';
  904. /**
  905. * String used to mark the beginning and end of EPS image blocks
  906. * @access protected
  907. * @since 4.1.000 (2008-10-18)
  908. */
  909. protected $epsmarker = 'x#!#EPS#!#x';
  910. /**
  911. * Array of transformation matrix
  912. * @access protected
  913. * @since 4.2.000 (2008-10-29)
  914. */
  915. protected $transfmatrix = array();
  916. /**
  917. * Current key for transformation matrix
  918. * @access protected
  919. * @since 4.8.005 (2009-09-17)
  920. */
  921. protected $transfmatrix_key = 0;
  922. /**
  923. * Booklet mode for double-sided pages
  924. * @access protected
  925. * @since 4.2.000 (2008-10-29)
  926. */
  927. protected $booklet = false;
  928. /**
  929. * Epsilon value used for float calculations
  930. * @access protected
  931. * @since 4.2.000 (2008-10-29)
  932. */
  933. protected $feps = 0.005;
  934. /**
  935. * Array used for custom vertical spaces for HTML tags
  936. * @access protected
  937. * @since 4.2.001 (2008-10-30)
  938. */
  939. protected $tagvspaces = array();
  940. /**
  941. * @var HTML PARSER: custom indent amount for lists.
  942. * Negative value means disabled.
  943. * @access protected
  944. * @since 4.2.007 (2008-11-12)
  945. */
  946. protected $customlistindent = - 1;
  947. /**
  948. * @var if true keeps the border open for the cell sides that cross the page.
  949. * @access protected
  950. * @since 4.2.010 (2008-11-14)
  951. */
  952. protected $opencell = true;
  953. /**
  954. * @var array of files to embedd
  955. * @access protected
  956. * @since 4.4.000 (2008-12-07)
  957. */
  958. protected $embeddedfiles = array();
  959. /**
  960. * @var boolean true when inside html pre tag
  961. * @access protected
  962. * @since 4.4.001 (2008-12-08)
  963. */
  964. protected $premode = false;
  965. /**
  966. * Array used to store positions of graphics transformation blocks inside the page buffer.
  967. * keys are the page numbers
  968. * @access protected
  969. * @since 4.4.002 (2008-12-09)
  970. */
  971. protected $transfmrk = array();
  972. /**
  973. * Default color for html links
  974. * @access protected
  975. * @since 4.4.003 (2008-12-09)
  976. */
  977. protected $htmlLinkColorArray = array(0, 0, 255);
  978. /**
  979. * Default font style to add to html links
  980. * @access protected
  981. * @since 4.4.003 (2008-12-09)
  982. */
  983. protected $htmlLinkFontStyle = 'U';
  984. /**
  985. * Counts the number of pages.
  986. * @access protected
  987. * @since 4.5.000 (2008-12-31)
  988. */
  989. protected $numpages = 0;
  990. /**
  991. * Array containing page lengths in bytes.
  992. * @access protected
  993. * @since 4.5.000 (2008-12-31)
  994. */
  995. protected $pagelen = array();
  996. /**
  997. * Counts the number of pages.
  998. * @access protected
  999. * @since 4.5.000 (2008-12-31)
  1000. */
  1001. protected $numimages = 0;
  1002. /**
  1003. * Store the image keys.
  1004. * @access protected
  1005. * @since 4.5.000 (2008-12-31)
  1006. */
  1007. protected $imagekeys = array();
  1008. /**
  1009. * Length of the buffer in bytes.
  1010. * @access protected
  1011. * @since 4.5.000 (2008-12-31)
  1012. */
  1013. protected $bufferlen = 0;
  1014. /**
  1015. * If true enables disk caching.
  1016. * @access protected
  1017. * @since 4.5.000 (2008-12-31)
  1018. */
  1019. protected $diskcache = false;
  1020. /**
  1021. * Counts the number of fonts.
  1022. * @access protected
  1023. * @since 4.5.000 (2009-01-02)
  1024. */
  1025. protected $numfonts = 0;
  1026. /**
  1027. * Store the font keys.
  1028. * @access protected
  1029. * @since 4.5.000 (2009-01-02)
  1030. */
  1031. protected $fontkeys = array();
  1032. /**
  1033. * Store the font object IDs.
  1034. * @access protected
  1035. * @since 4.8.001 (2009-09-09)
  1036. */
  1037. protected $font_obj_ids = array();
  1038. /**
  1039. * Store the fage status (true when opened, false when closed).
  1040. * @access protected
  1041. * @since 4.5.000 (2009-01-02)
  1042. */
  1043. protected $pageopen = array();
  1044. /**
  1045. * Default monospaced font
  1046. * @access protected
  1047. * @since 4.5.025 (2009-03-10)
  1048. */
  1049. protected $default_monospaced_font = 'courier';
  1050. /**
  1051. * Used to store a cloned copy of the current class object
  1052. * @access protected
  1053. * @since 4.5.029 (2009-03-19)
  1054. */
  1055. protected $objcopy;
  1056. /**
  1057. * Array used to store the lengths of cache files
  1058. * @access protected
  1059. * @since 4.5.029 (2009-03-19)
  1060. */
  1061. protected $cache_file_length = array();
  1062. /**
  1063. * Table header content to be repeated on each new page
  1064. * @access protected
  1065. * @since 4.5.030 (2009-03-20)
  1066. */
  1067. protected $thead = '';
  1068. /**
  1069. * Margins used for table header.
  1070. * @access protected
  1071. * @since 4.5.030 (2009-03-20)
  1072. */
  1073. protected $theadMargins = array();
  1074. /**
  1075. * Cache array for UTF8StringToArray() method.
  1076. * @access protected
  1077. * @since 4.5.037 (2009-04-07)
  1078. */
  1079. protected $cache_UTF8StringToArray = array();
  1080. /**
  1081. * Maximum size of cache array used for UTF8StringToArray() method.
  1082. * @access protected
  1083. * @since 4.5.037 (2009-04-07)
  1084. */
  1085. protected $cache_maxsize_UTF8StringToArray = 8;
  1086. /**
  1087. * Current size of cache array used for UTF8StringToArray() method.
  1088. * @access protected
  1089. * @since 4.5.037 (2009-04-07)
  1090. */
  1091. protected $cache_size_UTF8StringToArray = 0;
  1092. /**
  1093. * If true enables document signing
  1094. * @access protected
  1095. * @since 4.6.005 (2009-04-24)
  1096. */
  1097. protected $sign = false;
  1098. /**
  1099. * Signature data
  1100. * @access protected
  1101. * @since 4.6.005 (2009-04-24)
  1102. */
  1103. protected $signature_data = array();
  1104. /**
  1105. * Signature max length
  1106. * @access protected
  1107. * @since 4.6.005 (2009-04-24)
  1108. */
  1109. protected $signature_max_length = 11742;
  1110. /**
  1111. * data for signature appearance
  1112. * @access protected
  1113. * @since 5.3.011 (2010-06-16)
  1114. */
  1115. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1116. /**
  1117. * Regular expression used to find blank characters used for word-wrapping.
  1118. * @access protected
  1119. * @since 4.6.006 (2009-04-28)
  1120. */
  1121. protected $re_spaces = '/[^\S\xa0]/';
  1122. /**
  1123. * Array of parts $re_spaces
  1124. * @access protected
  1125. * @since 5.5.011 (2010-07-09)
  1126. */
  1127. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1128. /**
  1129. * Signature object ID
  1130. * @access protected
  1131. * @since 4.6.022 (2009-06-23)
  1132. */
  1133. protected $sig_obj_id = 0;
  1134. /**
  1135. * ByteRange placemark used during signature process.
  1136. * @access protected
  1137. * @since 4.6.028 (2009-08-25)
  1138. */
  1139. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1140. /**
  1141. * Placemark used during signature process.
  1142. * @access protected
  1143. * @since 4.6.028 (2009-08-25)
  1144. */
  1145. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1146. /**
  1147. * ID of page objects
  1148. * @access protected
  1149. * @since 4.7.000 (2009-08-29)
  1150. */
  1151. protected $page_obj_id = array();
  1152. /**
  1153. * List of form annotations IDs
  1154. * @access protected
  1155. * @since 4.8.000 (2009-09-07)
  1156. */
  1157. protected $form_obj_id = array();
  1158. /**
  1159. * Deafult Javascript field properties. Possible values are described on official Javascript for Acrobat API reference. Annotation options can be directly specified using the 'aopt' entry.
  1160. * @access protected
  1161. * @since 4.8.000 (2009-09-07)
  1162. */
  1163. protected $default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255,
  1164. 255), 'strokeColor' => array(128, 128, 128));
  1165. /**
  1166. * Javascript objects array
  1167. * @access protected
  1168. * @since 4.8.000 (2009-09-07)
  1169. */
  1170. protected $js_objects = array();
  1171. /**
  1172. * Current form action (used during XHTML rendering)
  1173. * @access protected
  1174. * @since 4.8.000 (2009-09-07)
  1175. */
  1176. protected $form_action = '';
  1177. /**
  1178. * Current form encryption type (used during XHTML rendering)
  1179. * @access protected
  1180. * @since 4.8.000 (2009-09-07)
  1181. */
  1182. protected $form_enctype = 'application/x-www-form-urlencoded';
  1183. /**
  1184. * Current method to submit forms.
  1185. * @access protected
  1186. * @since 4.8.000 (2009-09-07)
  1187. */
  1188. protected $form_mode = 'post';
  1189. /**
  1190. * List of fonts used on form fields (fontname => fontkey).
  1191. * @access protected
  1192. * @since 4.8.001 (2009-09-09)
  1193. */
  1194. protected $annotation_fonts = array();
  1195. /**
  1196. * List of radio buttons parent objects.
  1197. * @access protected
  1198. * @since 4.8.001 (2009-09-09)
  1199. */
  1200. protected $radiobutton_groups = array();
  1201. /**
  1202. * List of radio group objects IDs
  1203. * @access protected
  1204. * @since 4.8.001 (2009-09-09)
  1205. */
  1206. protected $radio_groups = array();
  1207. /**
  1208. * Text indentation value (used for text-indent CSS attribute)
  1209. * @access protected
  1210. * @since 4.8.006 (2009-09-23)
  1211. */
  1212. protected $textindent = 0;
  1213. /**
  1214. * Store page number when startTransaction() is called.
  1215. * @access protected
  1216. * @since 4.8.006 (2009-09-23)
  1217. */
  1218. protected $start_transaction_page = 0;
  1219. /**
  1220. * Store Y position when startTransaction() is called.
  1221. * @access protected
  1222. * @since 4.9.001 (2010-03-28)
  1223. */
  1224. protected $start_transaction_y = 0;
  1225. /**
  1226. * True when we are printing the thead section on a new page
  1227. * @access protected
  1228. * @since 4.8.027 (2010-01-25)
  1229. */
  1230. protected $inthead = false;
  1231. /**
  1232. * Array of column measures (width, space, starting Y position)
  1233. * @access protected
  1234. * @since 4.9.001 (2010-03-28)
  1235. */
  1236. protected $columns = array();
  1237. /**
  1238. * Number of colums
  1239. * @access protected
  1240. * @since 4.9.001 (2010-03-28)
  1241. */
  1242. protected $num_columns = 1;
  1243. /**
  1244. * Current column number
  1245. * @access protected
  1246. * @since 4.9.001 (2010-03-28)
  1247. */
  1248. protected $current_column = 0;
  1249. /**
  1250. * Starting page for columns
  1251. * @access protected
  1252. * @since 4.9.001 (2010-03-28)
  1253. */
  1254. protected $column_start_page = 0;
  1255. /**
  1256. * Maximum page and column selected
  1257. * @access protected
  1258. * @since 5.8.000 (2010-08-11)
  1259. */
  1260. protected $maxselcol = array('page' => 0, 'column' => 0);
  1261. /**
  1262. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding
  1263. * @access protected
  1264. * @since 5.8.000 (2010-08-11)
  1265. */
  1266. protected $colxshift = array('x' => 0, 's' => 0, 'p' => 0);
  1267. /**
  1268. * Text rendering mode: 0 = Fill text; 1 = Stroke text; 2 = Fill, then stroke text; 3 = Neither fill nor stroke text (invisible); 4 = Fill text and add to path for clipping; 5 = Stroke text and add to path for clipping; 6 = Fill, then stroke text and add to path for clipping; 7 = Add text to path for clipping.
  1269. * @access protected
  1270. * @since 4.9.008 (2010-04-03)
  1271. */
  1272. protected $textrendermode = 0;
  1273. /**
  1274. * Text stroke width in doc units
  1275. * @access protected
  1276. * @since 4.9.008 (2010-04-03)
  1277. */
  1278. protected $textstrokewidth = 0;
  1279. /**
  1280. * @var current stroke color
  1281. * @access protected
  1282. * @since 4.9.008 (2010-04-03)
  1283. */
  1284. protected $strokecolor;
  1285. /**
  1286. * @var default unit of measure for document
  1287. * @access protected
  1288. * @since 5.0.000 (2010-04-22)
  1289. */
  1290. protected $pdfunit = 'mm';
  1291. /**
  1292. * @var true when we are on TOC (Table Of Content) page
  1293. * @access protected
  1294. */
  1295. protected $tocpage = false;
  1296. /**
  1297. * @var If true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1298. * @access protected
  1299. * @since 5.0.000 (2010-04-26)
  1300. */
  1301. protected $rasterize_vector_images = false;
  1302. /**
  1303. * @var If true enables font subsetting by default
  1304. * @access protected
  1305. * @since 5.3.002 (2010-06-07)
  1306. */
  1307. protected $font_subsetting = true;
  1308. /**
  1309. * @var Array of default graphic settings
  1310. * @access protected
  1311. * @since 5.5.008 (2010-07-02)
  1312. */
  1313. protected $default_graphic_vars = array();
  1314. /**
  1315. * @var Array of XObjects
  1316. * @access protected
  1317. * @since 5.8.014 (2010-08-23)
  1318. */
  1319. protected $xobjects = array();
  1320. /**
  1321. * @var boolean true when we are inside an XObject
  1322. * @access protected
  1323. * @since 5.8.017 (2010-08-24)
  1324. */
  1325. protected $inxobj = false;
  1326. /**
  1327. * @var current XObject ID
  1328. * @access protected
  1329. * @since 5.8.017 (2010-08-24)
  1330. */
  1331. protected $xobjid = '';
  1332. /**
  1333. * @var percentage of character stretching
  1334. * @access protected
  1335. * @since 5.9.000 (2010-09-29)
  1336. */
  1337. protected $font_stretching = 100;
  1338. /**
  1339. * @var increases or decreases the space between characters in a text by the specified amount (tracking/kerning).
  1340. * @access protected
  1341. * @since 5.9.000 (2010-09-29)
  1342. */
  1343. protected $font_spacing = 0;
  1344. /**
  1345. * @var array of no-write regions
  1346. * ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right)
  1347. * @access protected
  1348. * @since 5.9.003 (2010-10-14)
  1349. */
  1350. protected $page_regions = array();
  1351. /**
  1352. * @var array containing HTML color names and values
  1353. * @access protected
  1354. * @since 5.9.004 (2010-10-18)
  1355. */
  1356. protected $webcolor = array();
  1357. /**
  1358. * @var directory used for the last SVG image
  1359. * @access protected
  1360. * @since 5.0.000 (2010-05-05)
  1361. */
  1362. protected $svgdir = '';
  1363. /**
  1364. * @var Deafult unit of measure for SVG
  1365. * @access protected
  1366. * @since 5.0.000 (2010-05-02)
  1367. */
  1368. protected $svgunit = 'px';
  1369. /**
  1370. * @var array of SVG gradients
  1371. * @access protected
  1372. * @since 5.0.000 (2010-05-02)
  1373. */
  1374. protected $svggradients = array();
  1375. /**
  1376. * @var ID of last SVG gradient
  1377. * @access protected
  1378. * @since 5.0.000 (2010-05-02)
  1379. */
  1380. protected $svggradientid = 0;
  1381. /**
  1382. * @var true when in SVG defs group
  1383. * @access protected
  1384. * @since 5.0.000 (2010-05-02)
  1385. */
  1386. protected $svgdefsmode = false;
  1387. /**
  1388. * @var array of SVG defs
  1389. * @access protected
  1390. * @since 5.0.000 (2010-05-02)
  1391. */
  1392. protected $svgdefs = array();
  1393. /**
  1394. * @var true when in SVG clipPath tag
  1395. * @access protected
  1396. * @since 5.0.000 (2010-04-26)
  1397. */
  1398. protected $svgclipmode = false;
  1399. /**
  1400. * @var array of SVG clipPath commands
  1401. * @access protected
  1402. * @since 5.0.000 (2010-05-02)
  1403. */
  1404. protected $svgclippaths = array();
  1405. /**
  1406. * @var array of SVG clipPath tranformation matrix
  1407. * @access protected
  1408. * @since 5.8.022 (2010-08-31)
  1409. */
  1410. protected $svgcliptm = array();
  1411. /**
  1412. * @var ID of last SVG clipPath
  1413. * @access protected
  1414. * @since 5.0.000 (2010-05-02)
  1415. */
  1416. protected $svgclipid = 0;
  1417. /**
  1418. * @var svg text
  1419. * @access protected
  1420. * @since 5.0.000 (2010-05-02)
  1421. */
  1422. protected $svgtext = '';
  1423. /**
  1424. * @var svg text properties
  1425. * @access protected
  1426. * @since 5.8.013 (2010-08-23)
  1427. */
  1428. protected $svgtextmode = array();
  1429. /**
  1430. * @var array of hinheritable SVG properties
  1431. * @access protected
  1432. * @since 5.0.000 (2010-05-02)
  1433. */
  1434. protected $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters',
  1435. 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font',
  1436. 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight',
  1437. 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing',
  1438. 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke',
  1439. 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit',
  1440. 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing',
  1441. 'writing-mode');
  1442. /**
  1443. * @var array of SVG properties
  1444. * @access protected
  1445. * @since 5.0.000 (2010-05-02)
  1446. */
  1447. protected $svgstyles = array(
  1448. array('alignment-baseline' => 'auto', 'baseline-shift' => 'baseline', 'clip' => 'auto',
  1449. 'clip-path' => 'none', 'clip-rule' => 'nonzero', 'color' => 'black', 'color-interpolation' => 'sRGB',
  1450. 'color-interpolation-filters' => 'linearRGB', 'color-profile' => 'auto', 'color-rendering' => 'auto',
  1451. 'cursor' => 'auto', 'direction' => 'ltr', 'display' => 'inline', 'dominant-baseline' => 'auto',
  1452. 'enable-background' => 'accumulate', 'fill' => 'black', 'fill-opacity' => 1,
  1453. 'fill-rule' => 'nonzero', 'filter' => 'none', 'flood-color' => 'black', 'flood-opacity' => 1,
  1454. 'font' => '', 'font-family' => 'helvetica', 'font-size' => 'medium', 'font-size-adjust' => 'none',
  1455. 'font-stretch' => 'normal', 'font-style' => 'normal', 'font-variant' => 'normal',
  1456. 'font-weight' => 'normal', 'glyph-orientation-horizontal' => '0deg',
  1457. 'glyph-orientation-vertical' => 'auto', 'image-rendering' => 'auto', 'kerning' => 'auto',
  1458. 'letter-spacing' => 'normal', 'lighting-color' => 'white', 'marker' => '', 'marker-end' => 'none',
  1459. 'marker-mid' => 'none', 'marker-start' => 'none', 'mask' => 'none', 'opacity' => 1,
  1460. 'overflow' => 'auto', 'pointer-events' => 'visiblePainted', 'shape-rendering' => 'auto',
  1461. 'stop-color' => 'black', 'stop-opacity' => 1, 'stroke' => 'none', 'stroke-dasharray' => 'none',
  1462. 'stroke-dashoffset' => 0, 'stroke-linecap' => 'butt', 'stroke-linejoin' => 'miter',
  1463. 'stroke-miterlimit' => 4, 'stroke-opacity' => 1, 'stroke-width' => 1, 'text-anchor' => 'start',
  1464. 'text-decoration' => 'none', 'text-rendering' => 'auto', 'unicode-bidi' => 'normal',
  1465. 'visibility' => 'visible', 'word-spacing' => 'normal', 'writing-mode' => 'lr-tb',
  1466. 'text-color' => 'black', 'transfmatrix' => array(1, 0, 0, 1, 0, 0)));
  1467. //------------------------------------------------------------
  1468. // METHODS
  1469. //------------------------------------------------------------
  1470. /**
  1471. * This is the class constructor.
  1472. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1473. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1474. * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1475. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  1476. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1477. * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1478. * @param String $encoding charset encoding; default is UTF-8
  1479. * @access public
  1480. * @see getPageSizeFromFormat(), setPageFormat()
  1481. */
  1482. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false)
  1483. {
  1484. /* Set internal character encoding to ASCII */
  1485. if (function_exists('mb_internal_encoding') and mb_internal_encoding())
  1486. {
  1487. $this->internal_encoding = mb_internal_encoding();
  1488. mb_internal_encoding('ASCII');
  1489. }
  1490. require (dirname(__FILE__) . '/htmlcolors.php');
  1491. $this->webcolor = $webcolor;
  1492. require_once (dirname(__FILE__) . '/unicode_data.php');
  1493. $this->unicode = new TCPDF_UNICODE_DATA();
  1494. $this->font_obj_ids = array();
  1495. $this->page_obj_id = array();
  1496. $this->form_obj_id = array();
  1497. // set disk caching
  1498. $this->diskcache = $diskcache ? true : false;
  1499. // set language direction
  1500. $this->rtl = false;
  1501. $this->tmprtl = false;
  1502. // some checks
  1503. $this->_dochecks();
  1504. // initialization of properties
  1505. $this->isunicode = $unicode;
  1506. $this->page = 0;
  1507. $this->transfmrk[0] = array();
  1508. $this->pagedim = array();
  1509. $this->n = 2;
  1510. $this->buffer = '';
  1511. $this->pages = array();
  1512. $this->state = 0;
  1513. $this->fonts = array();
  1514. $this->FontFiles = array();
  1515. $this->diffs = array();
  1516. $this->images = array();
  1517. $this->links = array();
  1518. $this->gradients = array();
  1519. $this->InFooter = false;
  1520. $this->lasth = 0;
  1521. $this->FontFamily = 'helvetica';
  1522. $this->FontStyle = '';
  1523. $this->FontSizePt = 12;
  1524. $this->underline = false;
  1525. $this->overline = false;
  1526. $this->linethrough = false;
  1527. $this->DrawColor = '0 G';
  1528. $this->FillColor = '0 g';
  1529. $this->TextColor = '0 g';
  1530. $this->ColorFlag = false;
  1531. // encryption values
  1532. $this->encrypted = false;
  1533. $this->last_enc_key = '';
  1534. // standard Unicode fonts
  1535. $this->CoreFonts = array('courier' => 'Courier', 'courierB' => 'Courier-Bold',
  1536. 'courierI' => 'Courier-Oblique', 'courierBI' => 'Courier-BoldOblique', 'helvetica' => 'Helvetica',
  1537. 'helveticaB' => 'Helvetica-Bold', 'helveticaI' => 'Helvetica-Oblique',
  1538. 'helveticaBI' => 'Helvetica-BoldOblique', 'times' => 'Times-Roman', 'timesB' => 'Times-Bold',
  1539. 'timesI' => 'Times-Italic', 'timesBI' => 'Times-BoldItalic', 'symbol' => 'Symbol',
  1540. 'zapfdingbats' => 'ZapfDingbats');
  1541. // set scale factor
  1542. $this->setPageUnit($unit);
  1543. // set page format and orientation
  1544. $this->setPageFormat($format, $orientation);
  1545. // page margins (1 cm)
  1546. $margin = 28.35 / $this->k;
  1547. $this->SetMargins($margin, $margin);
  1548. // internal cell padding
  1549. $cpadding = $margin / 10;
  1550. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1551. // cell margins
  1552. $this->setCellMargins(0, 0, 0, 0);
  1553. // line width (0.2 mm)
  1554. $this->LineWidth = 0.57 / $this->k;
  1555. $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
  1556. $this->linestyleCap = '0 J';
  1557. $this->linestyleJoin = '0 j';
  1558. $this->linestyleDash = '[] 0 d';
  1559. // automatic page break
  1560. $this->SetAutoPageBreak(true, (2 * $margin));
  1561. // full width display mode
  1562. $this->SetDisplayMode('fullwidth');
  1563. // compression
  1564. $this->SetCompression(true);
  1565. // set default PDF version number
  1566. $this->PDFVersion = '1.7';
  1567. $this->encoding = $encoding;
  1568. $this->HREF = array();
  1569. $this->getFontsList();
  1570. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1571. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1572. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1573. $this->extgstates = array();
  1574. // user's rights
  1575. $this->sign = false;
  1576. $this->ur['enabled'] = false;
  1577. $this->ur['document'] = '/FullSave';
  1578. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1579. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1580. $this->ur['signature'] = '/Modify';
  1581. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1582. $this->ur['formex'] = '';
  1583. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1584. // set default JPEG quality
  1585. $this->jpeg_quality = 75;
  1586. // initialize some settings
  1587. $this->utf8Bidi(array(''), '');
  1588. // set default font
  1589. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1590. // check if PCRE Unicode support is enabled
  1591. if ($this->isunicode and (@preg_match('/\pL/u', 'a') == 1))
  1592. {
  1593. // PCRE unicode support is turned ON
  1594. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1595. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1596. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1597. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1598. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1599. }
  1600. else
  1601. {
  1602. // PCRE unicode support is turned OFF
  1603. $this->setSpacesRE('/[^\S\xa0]/');
  1604. }
  1605. $this->default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255,
  1606. 255), 'strokeColor' => array(128, 128, 128));
  1607. // set file ID for trailer
  1608. $this->file_id = md5($this->getRandomSeed('TCPDF' . $orientation . $unit . $format . $encoding));
  1609. // get default graphic vars
  1610. $this->default_graphic_vars = $this->getGraphicVars();
  1611. }
  1612. /**
  1613. * Default destructor.
  1614. * @access public
  1615. * @since 1.53.0.TC016
  1616. */
  1617. public function __destruct()
  1618. {
  1619. // restore internal encoding
  1620. if (isset($this->internal_encoding) and ! empty($this->internal_encoding))
  1621. {
  1622. mb_internal_encoding($this->internal_encoding);
  1623. }
  1624. // unset all class variables
  1625. $this->_destroy(true);
  1626. }
  1627. /**
  1628. * Set the units of measure for the document.
  1629. * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1630. * @access public
  1631. * @since 3.0.015 (2008-06-06)
  1632. */
  1633. public function setPageUnit($unit)
  1634. {
  1635. $unit = strtolower($unit);
  1636. //Set scale factor
  1637. switch ($unit)
  1638. {
  1639. // points
  1640. case 'px' :
  1641. case 'pt' :
  1642. {
  1643. $this->k = 1;
  1644. break;
  1645. }
  1646. // millimeters
  1647. case 'mm' :
  1648. {
  1649. $this->k = $this->dpi / 25.4;
  1650. break;
  1651. }
  1652. // centimeters
  1653. case 'cm' :
  1654. {
  1655. $this->k = $this->dpi / 2.54;
  1656. break;
  1657. }
  1658. // inches
  1659. case 'in' :
  1660. {
  1661. $this->k = $this->dpi;
  1662. break;
  1663. }
  1664. // unsupported unit
  1665. default :
  1666. {
  1667. $this->Error('Incorrect unit: ' . $unit);
  1668. break;
  1669. }
  1670. }
  1671. $this->pdfunit = $unit;
  1672. if (isset($this->CurOrientation))
  1673. {
  1674. $this->setPageOrientation($this->CurOrientation);
  1675. }
  1676. }
  1677. /**
  1678. * Get page dimensions from format name.
  1679. * @param mixed $format The format name. It can be: <ul>
  1680. * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
  1681. * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
  1682. * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
  1683. * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
  1684. * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
  1685. * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
  1686. * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
  1687. * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
  1688. * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
  1689. * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
  1690. * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
  1691. * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
  1692. * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
  1693. * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
  1694. * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
  1695. * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
  1696. * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
  1697. * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
  1698. * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
  1699. * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
  1700. * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
  1701. * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
  1702. * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
  1703. * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
  1704. * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
  1705. * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
  1706. * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
  1707. * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
  1708. * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
  1709. * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
  1710. * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
  1711. * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
  1712. * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
  1713. * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
  1714. * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
  1715. * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
  1716. * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
  1717. * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
  1718. * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
  1719. * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
  1720. * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
  1721. * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
  1722. * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
  1723. * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
  1724. * <li><b>SIS 014711 E Series</b></li>
  1725. * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
  1726. * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
  1727. * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
  1728. * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
  1729. * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
  1730. * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
  1731. * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
  1732. * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
  1733. * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
  1734. * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
  1735. * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
  1736. * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
  1737. * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
  1738. * <li><b>SIS 014711 G Series</b></li>
  1739. * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
  1740. * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
  1741. * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
  1742. * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
  1743. * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
  1744. * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
  1745. * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
  1746. * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
  1747. * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
  1748. * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
  1749. * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
  1750. * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
  1751. * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
  1752. * <li><b>ISO Press</b></li>
  1753. * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
  1754. * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
  1755. * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
  1756. * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
  1757. * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
  1758. * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
  1759. * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
  1760. * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
  1761. * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
  1762. * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
  1763. * <li><b>German DIN 476</b></li>
  1764. * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
  1765. * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
  1766. * <li><b>Variations on the ISO Standard</b></li>
  1767. * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
  1768. * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
  1769. * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
  1770. * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
  1771. * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
  1772. * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
  1773. * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
  1774. * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
  1775. * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
  1776. * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
  1777. * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
  1778. * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
  1779. * <li><b>ANSI Series</b></li>
  1780. * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
  1781. * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
  1782. * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
  1783. * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
  1784. * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
  1785. * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
  1786. * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
  1787. * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
  1788. * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
  1789. * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
  1790. * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
  1791. * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
  1792. * <li><b>Other North American Paper Sizes</b></li>
  1793. * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
  1794. * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
  1795. * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
  1796. * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
  1797. * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
  1798. * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
  1799. * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
  1800. * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
  1801. * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
  1802. * <li><b>Canadian standard CAN 2-9.60M</b></li>
  1803. * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
  1804. * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
  1805. * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
  1806. * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
  1807. * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
  1808. * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
  1809. * <li><b>North American Architectural Sizes</b></li>
  1810. * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
  1811. * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
  1812. * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
  1813. * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
  1814. * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
  1815. * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
  1816. * <li><b>Announcement Envelopes</b></li>
  1817. * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
  1818. * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
  1819. * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
  1820. * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
  1821. * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
  1822. * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
  1823. * <li><b>Commercial Envelopes</b></li>
  1824. * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
  1825. * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
  1826. * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
  1827. * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
  1828. * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
  1829. * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
  1830. * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
  1831. * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
  1832. * <li><b>Catalogue Envelopes</b></li>
  1833. * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
  1834. * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
  1835. * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
  1836. * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
  1837. * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
  1838. * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
  1839. * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
  1840. * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
  1841. * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
  1842. * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
  1843. * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
  1844. * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
  1845. * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
  1846. * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
  1847. * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
  1848. * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
  1849. * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
  1850. * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
  1851. * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
  1852. * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
  1853. * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
  1854. * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
  1855. * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
  1856. * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
  1857. * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
  1858. * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
  1859. * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
  1860. * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
  1861. * <li><b>PA Series</b></li>
  1862. * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
  1863. * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
  1864. * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
  1865. * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
  1866. * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
  1867. * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
  1868. * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
  1869. * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
  1870. * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
  1871. * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
  1872. * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
  1873. * <li><b>Standard Photographic Print Sizes</b></li>
  1874. * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
  1875. * <li>E (82x120 mm ; 3.25x4.72 in)</li>
  1876. * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
  1877. * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
  1878. * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
  1879. * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
  1880. * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
  1881. * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
  1882. * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
  1883. * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
  1884. * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
  1885. * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
  1886. * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
  1887. * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
  1888. * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
  1889. * <li><b>Common Newspaper Sizes</b></li>
  1890. * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
  1891. * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
  1892. * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
  1893. * <li><b>Business Cards</b></li>
  1894. * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
  1895. * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
  1896. * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
  1897. * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
  1898. * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
  1899. * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
  1900. * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
  1901. * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
  1902. * <li><b>Billboards</b></li>
  1903. * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
  1904. * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
  1905. * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
  1906. * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
  1907. * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
  1908. * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
  1909. * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
  1910. * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
  1911. * <li><b>Old Imperial English (some are still used in USA)</b></li>
  1912. * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
  1913. * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
  1914. * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
  1915. * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
  1916. * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
  1917. * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
  1918. * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
  1919. * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
  1920. * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
  1921. * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
  1922. * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
  1923. * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
  1924. * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
  1925. * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
  1926. * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
  1927. * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
  1928. * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
  1929. * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
  1930. * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
  1931. * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
  1932. * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
  1933. * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
  1934. * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
  1935. * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
  1936. * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
  1937. * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
  1938. * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
  1939. * <li><b>Old Imperial Belgian</b></li>
  1940. * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
  1941. * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
  1942. * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
  1943. * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
  1944. * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
  1945. * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
  1946. * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
  1947. * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  1948. * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
  1949. * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
  1950. * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
  1951. * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
  1952. * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
  1953. * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
  1954. * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
  1955. * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
  1956. * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
  1957. * <li><b>Old Imperial French</b></li>
  1958. * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
  1959. * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
  1960. * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
  1961. * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
  1962. * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
  1963. * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
  1964. * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
  1965. * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
  1966. * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
  1967. * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
  1968. * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
  1969. * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
  1970. * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
  1971. * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
  1972. * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
  1973. * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
  1974. * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  1975. * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
  1976. * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
  1977. * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
  1978. * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
  1979. * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
  1980. * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
  1981. * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
  1982. * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
  1983. * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
  1984. * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
  1985. * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
  1986. * </ul>
  1987. * @return array containing page width and height in points
  1988. * @access public
  1989. * @since 5.0.010 (2010-05-17)
  1990. */
  1991. public function getPageSizeFromFormat($format)
  1992. {
  1993. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
  1994. switch (strtoupper($format))
  1995. {
  1996. // ISO 216 A Series + 2 SIS 014711 extensions
  1997. case 'A0' :
  1998. {
  1999. $pf = array(2383.937, 3370.394);
  2000. break;
  2001. }
  2002. case 'A1' :
  2003. {
  2004. $pf = array(1683.780, 2383.937);
  2005. break;
  2006. }
  2007. case 'A2' :
  2008. {
  2009. $pf = array(1190.551, 1683.780);
  2010. break;
  2011. }
  2012. case 'A3' :
  2013. {
  2014. $pf = array(841.890, 1190.551);
  2015. break;
  2016. }
  2017. case 'A4' :
  2018. {
  2019. $pf = array(595.276, 841.890);
  2020. break;
  2021. }
  2022. case 'A5' :
  2023. {
  2024. $pf = array(419.528, 595.276);
  2025. break;
  2026. }
  2027. case 'A6' :
  2028. {
  2029. $pf = array(297.638, 419.528);
  2030. break;
  2031. }
  2032. case 'A7' :
  2033. {
  2034. $pf = array(209.764, 297.638);
  2035. break;
  2036. }
  2037. case 'A8' :
  2038. {
  2039. $pf = array(147.402, 209.764);
  2040. break;
  2041. }
  2042. case 'A9' :
  2043. {
  2044. $pf = array(104.882, 147.402);
  2045. break;
  2046. }
  2047. case 'A10' :
  2048. {
  2049. $pf = array(73.701, 104.882);
  2050. break;
  2051. }
  2052. case 'A11' :
  2053. {
  2054. $pf = array(51.024, 73.701);
  2055. break;
  2056. }
  2057. case 'A12' :
  2058. {
  2059. $pf = array(36.850, 51.024);
  2060. break;
  2061. }
  2062. // ISO 216 B Series + 2 SIS 014711 extensions
  2063. case 'B0' :
  2064. {
  2065. $pf = array(2834.646, 4008.189);
  2066. break;
  2067. }
  2068. case 'B1' :
  2069. {
  2070. $pf = array(2004.094, 2834.646);
  2071. break;
  2072. }
  2073. case 'B2' :
  2074. {
  2075. $pf = array(1417.323, 2004.094);
  2076. break;
  2077. }
  2078. case 'B3' :
  2079. {
  2080. $pf = array(1000.630, 1417.323);
  2081. break;
  2082. }
  2083. case 'B4' :
  2084. {
  2085. $pf = array(708.661, 1000.630);
  2086. break;
  2087. }
  2088. case 'B5' :
  2089. {
  2090. $pf = array(498.898, 708.661);
  2091. break;
  2092. }
  2093. case 'B6' :
  2094. {
  2095. $pf = array(354.331, 498.898);
  2096. break;
  2097. }
  2098. case 'B7' :
  2099. {
  2100. $pf = array(249.449, 354.331);
  2101. break;
  2102. }
  2103. case 'B8' :
  2104. {
  2105. $pf = array(175.748, 249.449);
  2106. break;
  2107. }
  2108. case 'B9' :
  2109. {
  2110. $pf = array(124.724, 175.748);
  2111. break;
  2112. }
  2113. case 'B10' :
  2114. {
  2115. $pf = array(87.874, 124.724);
  2116. break;
  2117. }
  2118. case 'B11' :
  2119. {
  2120. $pf = array(62.362, 87.874);
  2121. break;
  2122. }
  2123. case 'B12' :
  2124. {
  2125. $pf = array(42.520, 62.362);
  2126. break;
  2127. }
  2128. // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
  2129. case 'C0' :
  2130. {
  2131. $pf = array(2599.370, 3676.535);
  2132. break;
  2133. }
  2134. case 'C1' :
  2135. {
  2136. $pf = array(1836.850, 2599.370);
  2137. break;
  2138. }
  2139. case 'C2' :
  2140. {
  2141. $pf = array(1298.268, 1836.850);
  2142. break;
  2143. }
  2144. case 'C3' :
  2145. {
  2146. $pf = array(918.425, 1298.268);
  2147. break;
  2148. }
  2149. case 'C4' :
  2150. {
  2151. $pf = array(649.134, 918.425);
  2152. break;
  2153. }
  2154. case 'C5' :
  2155. {
  2156. $pf = array(459.213, 649.134);
  2157. break;
  2158. }
  2159. case 'C6' :
  2160. {
  2161. $pf = array(323.150, 459.213);
  2162. break;
  2163. }
  2164. case 'C7' :
  2165. {
  2166. $pf = array(229.606, 323.150);
  2167. break;
  2168. }
  2169. case 'C8' :
  2170. {
  2171. $pf = array(161.575, 229.606);
  2172. break;
  2173. }
  2174. case 'C9' :
  2175. {
  2176. $pf = array(113.386, 161.575);
  2177. break;
  2178. }
  2179. case 'C10' :
  2180. {
  2181. $pf = array(79.370, 113.386);
  2182. break;
  2183. }
  2184. case 'C11' :
  2185. {
  2186. $pf = array(56.693, 79.370);
  2187. break;
  2188. }
  2189. case 'C12' :
  2190. {
  2191. $pf = array(39.685, 56.693);
  2192. break;
  2193. }
  2194. case 'C76' :
  2195. {
  2196. $pf = array(229.606, 459.213);
  2197. break;
  2198. }
  2199. case 'DL' :
  2200. {
  2201. $pf = array(311.811, 623.622);
  2202. break;
  2203. }
  2204. // SIS 014711 E Series
  2205. case 'E0' :
  2206. {
  2207. $pf = array(2491.654, 3517.795);
  2208. break;
  2209. }
  2210. case 'E1' :
  2211. {
  2212. $pf = array(1757.480, 2491.654);
  2213. break;
  2214. }
  2215. case 'E2' :
  2216. {
  2217. $pf = array(1247.244, 1757.480);
  2218. break;
  2219. }
  2220. case 'E3' :
  2221. {
  2222. $pf = array(878.740, 1247.244);
  2223. break;
  2224. }
  2225. case 'E4' :
  2226. {
  2227. $pf = array(623.622, 878.740);
  2228. break;
  2229. }
  2230. case 'E5' :
  2231. {
  2232. $pf = array(439.370, 623.622);
  2233. break;
  2234. }
  2235. case 'E6' :
  2236. {
  2237. $pf = array(311.811, 439.370);
  2238. break;
  2239. }
  2240. case 'E7' :
  2241. {
  2242. $pf = array(221.102, 311.811);
  2243. break;
  2244. }
  2245. case 'E8' :
  2246. {
  2247. $pf = array(155.906, 221.102);
  2248. break;
  2249. }
  2250. case 'E9' :
  2251. {
  2252. $pf = array(110.551, 155.906);
  2253. break;
  2254. }
  2255. case 'E10' :
  2256. {
  2257. $pf = array(76.535, 110.551);
  2258. break;
  2259. }
  2260. case 'E11' :
  2261. {
  2262. $pf = array(53.858, 76.535);
  2263. break;
  2264. }
  2265. case 'E12' :
  2266. {
  2267. $pf = array(36.850, 53.858);
  2268. break;
  2269. }
  2270. // SIS 014711 G Series
  2271. case 'G0' :
  2272. {
  2273. $pf = array(2715.591, 3838.110);
  2274. break;
  2275. }
  2276. case 'G1' :
  2277. {
  2278. $pf = array(1919.055, 2715.591);
  2279. break;
  2280. }
  2281. case 'G2' :
  2282. {
  2283. $pf = array(1357.795, 1919.055);
  2284. break;
  2285. }
  2286. case 'G3' :
  2287. {
  2288. $pf = array(958.110, 1357.795);
  2289. break;
  2290. }
  2291. case 'G4' :
  2292. {
  2293. $pf = array(677.480, 958.110);
  2294. break;
  2295. }
  2296. case 'G5' :
  2297. {
  2298. $pf = array(479.055, 677.480);
  2299. break;
  2300. }
  2301. case 'G6' :
  2302. {
  2303. $pf = array(337.323, 479.055);
  2304. break;
  2305. }
  2306. case 'G7' :
  2307. {
  2308. $pf = array(238.110, 337.323);
  2309. break;
  2310. }
  2311. case 'G8' :
  2312. {
  2313. $pf = array(167.244, 238.110);
  2314. break;
  2315. }
  2316. case 'G9' :
  2317. {
  2318. $pf = array(119.055, 167.244);
  2319. break;
  2320. }
  2321. case 'G10' :
  2322. {
  2323. $pf = array(82.205, 119.055);
  2324. break;
  2325. }
  2326. case 'G11' :
  2327. {
  2328. $pf = array(59.528, 82.205);
  2329. break;
  2330. }
  2331. case 'G12' :
  2332. {
  2333. $pf = array(39.685, 59.528);
  2334. break;
  2335. }
  2336. // ISO Press
  2337. case 'RA0' :
  2338. {
  2339. $pf = array(2437.795, 3458.268);
  2340. break;
  2341. }
  2342. case 'RA1' :
  2343. {
  2344. $pf = array(1729.134, 2437.795);
  2345. break;
  2346. }
  2347. case 'RA2' :
  2348. {
  2349. $pf = array(1218.898, 1729.134);
  2350. break;
  2351. }
  2352. case 'RA3' :
  2353. {
  2354. $pf = array(864.567, 1218.898);
  2355. break;
  2356. }
  2357. case 'RA4' :
  2358. {
  2359. $pf = array(609.449, 864.567);
  2360. break;
  2361. }
  2362. case 'SRA0' :
  2363. {
  2364. $pf = array(2551.181, 3628.346);
  2365. break;
  2366. }
  2367. case 'SRA1' :
  2368. {
  2369. $pf = array(1814.173, 2551.181);
  2370. break;
  2371. }
  2372. case 'SRA2' :
  2373. {
  2374. $pf = array(1275.591, 1814.173);
  2375. break;
  2376. }
  2377. case 'SRA3' :
  2378. {
  2379. $pf = array(907.087, 1275.591);
  2380. break;
  2381. }
  2382. case 'SRA4' :
  2383. {
  2384. $pf = array(637.795, 907.087);
  2385. break;
  2386. }
  2387. // German DIN 476
  2388. case '4A0' :
  2389. {
  2390. $pf = array(4767.874, 6740.787);
  2391. break;
  2392. }
  2393. case '2A0' :
  2394. {
  2395. $pf = array(3370.394, 4767.874);
  2396. break;
  2397. }
  2398. // Variations on the ISO Standard
  2399. case 'A2_EXTRA' :
  2400. {
  2401. $pf = array(1261.417, 1754.646);
  2402. break;
  2403. }
  2404. case 'A3+' :
  2405. {
  2406. $pf = array(932.598, 1369.134);
  2407. break;
  2408. }
  2409. case 'A3_EXTRA' :
  2410. {
  2411. $pf = array(912.756, 1261.417);
  2412. break;
  2413. }
  2414. case 'A3_SUPER' :
  2415. {
  2416. $pf = array(864.567, 1440.000);
  2417. break;
  2418. }
  2419. case 'SUPER_A3' :
  2420. {
  2421. $pf = array(864.567, 1380.472);
  2422. break;
  2423. }
  2424. case 'A4_EXTRA' :
  2425. {
  2426. $pf = array(666.142, 912.756);
  2427. break;
  2428. }
  2429. case 'A4_SUPER' :
  2430. {
  2431. $pf = array(649.134, 912.756);
  2432. break;
  2433. }
  2434. case 'SUPER_A4' :
  2435. {
  2436. $pf = array(643.465, 1009.134);
  2437. break;
  2438. }
  2439. case 'A4_LONG' :
  2440. {
  2441. $pf = array(595.276, 986.457);
  2442. break;
  2443. }
  2444. case 'F4' :
  2445. {
  2446. $pf = array(595.276, 935.433);
  2447. break;
  2448. }
  2449. case 'SO_B5_EXTRA' :
  2450. {
  2451. $pf = array(572.598, 782.362);
  2452. break;
  2453. }
  2454. case 'A5_EXTRA' :
  2455. {
  2456. $pf = array(490.394, 666.142);
  2457. break;
  2458. }
  2459. // ANSI Series
  2460. case 'ANSI_E' :
  2461. {
  2462. $pf = array(2448.000, 3168.000);
  2463. break;
  2464. }
  2465. case 'ANSI_D' :
  2466. {
  2467. $pf = array(1584.000, 2448.000);
  2468. break;
  2469. }
  2470. case 'ANSI_C' :
  2471. {
  2472. $pf = array(1224.000, 1584.000);
  2473. break;
  2474. }
  2475. case 'ANSI_B' :
  2476. {
  2477. $pf = array(792.000, 1224.000);
  2478. break;
  2479. }
  2480. case 'ANSI_A' :
  2481. {
  2482. $pf = array(612.000, 792.000);
  2483. break;
  2484. }
  2485. // Traditional 'Loose' North American Paper Sizes
  2486. case 'USLEDGER' :
  2487. case 'LEDGER' :
  2488. {
  2489. $pf = array(1224.000, 792.000);
  2490. break;
  2491. }
  2492. case 'ORGANIZERK' :
  2493. case 'BIBLE' :
  2494. case 'USTABLOID' :
  2495. case 'TABLOID' :
  2496. {
  2497. $pf = array(792.000, 1224.000);
  2498. break;
  2499. }
  2500. case 'ORGANIZERM' :
  2501. case 'USLETTER' :
  2502. case 'LETTER' :
  2503. {
  2504. $pf = array(612.000, 792.000);
  2505. break;
  2506. }
  2507. case 'USLEGAL' :
  2508. case 'LEGAL' :
  2509. {
  2510. $pf = array(612.000, 1008.000);
  2511. break;
  2512. }
  2513. case 'GOVERNMENTLETTER' :
  2514. case 'GLETTER' :
  2515. {
  2516. $pf = array(576.000, 756.000);
  2517. break;
  2518. }
  2519. case 'JUNIORLEGAL' :
  2520. case 'JLEGAL' :
  2521. {
  2522. $pf = array(576.000, 360.000);
  2523. break;
  2524. }
  2525. // Other North American Paper Sizes
  2526. case 'QUADDEMY' :
  2527. {
  2528. $pf = array(2520.000, 3240.000);
  2529. break;
  2530. }
  2531. case 'SUPER_B' :
  2532. {
  2533. $pf = array(936.000, 1368.000);
  2534. break;
  2535. }
  2536. case 'QUARTO' :
  2537. {
  2538. $pf = array(648.000, 792.000);
  2539. break;
  2540. }
  2541. case 'GOVERNMENTLEGAL' :
  2542. case 'FOLIO' :
  2543. {
  2544. $pf = array(612.000, 936.000);
  2545. break;
  2546. }
  2547. case 'MONARCH' :
  2548. case 'EXECUTIVE' :
  2549. {
  2550. $pf = array(522.000, 756.000);
  2551. break;
  2552. }
  2553. case 'ORGANIZERL' :
  2554. case 'STATEMENT' :
  2555. case 'MEMO' :
  2556. {
  2557. $pf = array(396.000, 612.000);
  2558. break;
  2559. }
  2560. case 'FOOLSCAP' :
  2561. {
  2562. $pf = array(595.440, 936.000);
  2563. break;
  2564. }
  2565. case 'COMPACT' :
  2566. {
  2567. $pf = array(306.000, 486.000);
  2568. break;
  2569. }
  2570. case 'ORGANIZERJ' :
  2571. {
  2572. $pf = array(198.000, 360.000);
  2573. break;
  2574. }
  2575. // Canadian standard CAN 2-9.60M
  2576. case 'P1' :
  2577. {
  2578. $pf = array(1587.402, 2437.795);
  2579. break;
  2580. }
  2581. case 'P2' :
  2582. {
  2583. $pf = array(1218.898, 1587.402);
  2584. break;
  2585. }
  2586. case 'P3' :
  2587. {
  2588. $pf = array(793.701, 1218.898);
  2589. break;
  2590. }
  2591. case 'P4' :
  2592. {
  2593. $pf = array(609.449, 793.701);
  2594. break;
  2595. }
  2596. case 'P5' :
  2597. {
  2598. $pf = array(396.850, 609.449);
  2599. break;
  2600. }
  2601. case 'P6' :
  2602. {
  2603. $pf = array(303.307, 396.850);
  2604. break;
  2605. }
  2606. // North American Architectural Sizes
  2607. case 'ARCH_E' :
  2608. {
  2609. $pf = array(2592.000, 3456.000);
  2610. break;
  2611. }
  2612. case 'ARCH_E1' :
  2613. {
  2614. $pf = array(2160.000, 3024.000);
  2615. break;
  2616. }
  2617. case 'ARCH_D' :
  2618. {
  2619. $pf = array(1728.000, 2592.000);
  2620. break;
  2621. }
  2622. case 'BROADSHEET' :
  2623. case 'ARCH_C' :
  2624. {
  2625. $pf = array(1296.000, 1728.000);
  2626. break;
  2627. }
  2628. case 'ARCH_B' :
  2629. {
  2630. $pf = array(864.000, 1296.000);
  2631. break;
  2632. }
  2633. case 'ARCH_A' :
  2634. {
  2635. $pf = array(648.000, 864.000);
  2636. break;
  2637. }
  2638. // --- North American Envelope Sizes ---
  2639. // - Announcement Envelopes
  2640. case 'ANNENV_A2' :
  2641. {
  2642. $pf = array(314.640, 414.000);
  2643. break;
  2644. }
  2645. case 'ANNENV_A6' :
  2646. {
  2647. $pf = array(342.000, 468.000);
  2648. break;
  2649. }
  2650. case 'ANNENV_A7' :
  2651. {
  2652. $pf = array(378.000, 522.000);
  2653. break;
  2654. }
  2655. case 'ANNENV_A8' :
  2656. {
  2657. $pf = array(396.000, 584.640);
  2658. break;
  2659. }
  2660. case 'ANNENV_A10' :
  2661. {
  2662. $pf = array(450.000, 692.640);
  2663. break;
  2664. }
  2665. case 'ANNENV_SLIM' :
  2666. {
  2667. $pf = array(278.640, 638.640);
  2668. break;
  2669. }
  2670. // - Commercial Envelopes
  2671. case 'COMMENV_N6_1/4' :
  2672. {
  2673. $pf = array(252.000, 432.000);
  2674. break;
  2675. }
  2676. case 'COMMENV_N6_3/4' :
  2677. {
  2678. $pf = array(260.640, 468.000);
  2679. break;
  2680. }
  2681. case 'COMMENV_N8' :
  2682. {
  2683. $pf = array(278.640, 540.000);
  2684. break;
  2685. }
  2686. case 'COMMENV_N9' :
  2687. {
  2688. $pf = array(278.640, 638.640);
  2689. break;
  2690. }
  2691. case 'COMMENV_N10' :
  2692. {
  2693. $pf = array(296.640, 684.000);
  2694. break;
  2695. }
  2696. case 'COMMENV_N11' :
  2697. {
  2698. $pf = array(324.000, 746.640);
  2699. break;
  2700. }
  2701. case 'COMMENV_N12' :
  2702. {
  2703. $pf = array(342.000, 792.000);
  2704. break;
  2705. }
  2706. case 'COMMENV_N14' :
  2707. {
  2708. $pf = array(360.000, 828.000);
  2709. break;
  2710. }
  2711. // - Catalogue Envelopes
  2712. case 'CATENV_N1' :
  2713. {
  2714. $pf = array(432.000, 648.000);
  2715. break;
  2716. }
  2717. case 'CATENV_N1_3/4' :
  2718. {
  2719. $pf = array(468.000, 684.000);
  2720. break;
  2721. }
  2722. case 'CATENV_N2' :
  2723. {
  2724. $pf = array(468.000, 720.000);
  2725. break;
  2726. }
  2727. case 'CATENV_N3' :
  2728. {
  2729. $pf = array(504.000, 720.000);
  2730. break;
  2731. }
  2732. case 'CATENV_N6' :
  2733. {
  2734. $pf = array(540.000, 756.000);
  2735. break;
  2736. }
  2737. case 'CATENV_N7' :
  2738. {
  2739. $pf = array(576.000, 792.000);
  2740. break;
  2741. }
  2742. case 'CATENV_N8' :
  2743. {
  2744. $pf = array(594.000, 810.000);
  2745. break;
  2746. }
  2747. case 'CATENV_N9_1/2' :
  2748. {
  2749. $pf = array(612.000, 756.000);
  2750. break;
  2751. }
  2752. case 'CATENV_N9_3/4' :
  2753. {
  2754. $pf = array(630.000, 810.000);
  2755. break;
  2756. }
  2757. case 'CATENV_N10_1/2' :
  2758. {
  2759. $pf = array(648.000, 864.000);
  2760. break;
  2761. }
  2762. case 'CATENV_N12_1/2' :
  2763. {
  2764. $pf = array(684.000, 900.000);
  2765. break;
  2766. }
  2767. case 'CATENV_N13_1/2' :
  2768. {
  2769. $pf = array(720.000, 936.000);
  2770. break;
  2771. }
  2772. case 'CATENV_N14_1/4' :
  2773. {
  2774. $pf = array(810.000, 882.000);
  2775. break;
  2776. }
  2777. case 'CATENV_N14_1/2' :
  2778. {
  2779. $pf = array(828.000, 1044.000);
  2780. break;
  2781. }
  2782. // Japanese (JIS P 0138-61) Standard B-Series
  2783. case 'JIS_B0' :
  2784. {
  2785. $pf = array(2919.685, 4127.244);
  2786. break;
  2787. }
  2788. case 'JIS_B1' :
  2789. {
  2790. $pf = array(2063.622, 2919.685);
  2791. break;
  2792. }
  2793. case 'JIS_B2' :
  2794. {
  2795. $pf = array(1459.843, 2063.622);
  2796. break;
  2797. }
  2798. case 'JIS_B3' :
  2799. {
  2800. $pf = array(1031.811, 1459.843);
  2801. break;
  2802. }
  2803. case 'JIS_B4' :
  2804. {
  2805. $pf = array(728.504, 1031.811);
  2806. break;
  2807. }
  2808. case 'JIS_B5' :
  2809. {
  2810. $pf = array(515.906, 728.504);
  2811. break;
  2812. }
  2813. case 'JIS_B6' :
  2814. {
  2815. $pf = array(362.835, 515.906);
  2816. break;
  2817. }
  2818. case 'JIS_B7' :
  2819. {
  2820. $pf = array(257.953, 362.835);
  2821. break;
  2822. }
  2823. case 'JIS_B8' :
  2824. {
  2825. $pf = array(181.417, 257.953);
  2826. break;
  2827. }
  2828. case 'JIS_B9' :
  2829. {
  2830. $pf = array(127.559, 181.417);
  2831. break;
  2832. }
  2833. case 'JIS_B10' :
  2834. {
  2835. $pf = array(90.709, 127.559);
  2836. break;
  2837. }
  2838. case 'JIS_B11' :
  2839. {
  2840. $pf = array(62.362, 90.709);
  2841. break;
  2842. }
  2843. case 'JIS_B12' :
  2844. {
  2845. $pf = array(45.354, 62.362);
  2846. break;
  2847. }
  2848. // PA Series
  2849. case 'PA0' :
  2850. {
  2851. $pf = array(2381.102, 3174.803);
  2852. break;
  2853. }
  2854. case 'PA1' :
  2855. {
  2856. $pf = array(1587.402, 2381.102);
  2857. break;
  2858. }
  2859. case 'PA2' :
  2860. {
  2861. $pf = array(1190.551, 1587.402);
  2862. break;
  2863. }
  2864. case 'PA3' :
  2865. {
  2866. $pf = array(793.701, 1190.551);
  2867. break;
  2868. }
  2869. case 'PA4' :
  2870. {
  2871. $pf = array(595.276, 793.701);
  2872. break;
  2873. }
  2874. case 'PA5' :
  2875. {
  2876. $pf = array(396.850, 595.276);
  2877. break;
  2878. }
  2879. case 'PA6' :
  2880. {
  2881. $pf = array(297.638, 396.850);
  2882. break;
  2883. }
  2884. case 'PA7' :
  2885. {
  2886. $pf = array(198.425, 297.638);
  2887. break;
  2888. }
  2889. case 'PA8' :
  2890. {
  2891. $pf = array(147.402, 198.425);
  2892. break;
  2893. }
  2894. case 'PA9' :
  2895. {
  2896. $pf = array(99.213, 147.402);
  2897. break;
  2898. }
  2899. case 'PA10' :
  2900. {
  2901. $pf = array(73.701, 99.213);
  2902. break;
  2903. }
  2904. // Standard Photographic Print Sizes
  2905. case 'PASSPORT_PHOTO' :
  2906. {
  2907. $pf = array(99.213, 127.559);
  2908. break;
  2909. }
  2910. case 'E' :
  2911. {
  2912. $pf = array(233.858, 340.157);
  2913. break;
  2914. }
  2915. case 'L' :
  2916. case '3R' :
  2917. {
  2918. $pf = array(252.283, 360.000);
  2919. break;
  2920. }
  2921. case 'KG' :
  2922. case '4R' :
  2923. {
  2924. $pf = array(289.134, 430.866);
  2925. break;
  2926. }
  2927. case '4D' :
  2928. {
  2929. $pf = array(340.157, 430.866);
  2930. break;
  2931. }
  2932. case '2L' :
  2933. case '5R' :
  2934. {
  2935. $pf = array(360.000, 504.567);
  2936. break;
  2937. }
  2938. case '8P' :
  2939. case '6R' :
  2940. {
  2941. $pf = array(430.866, 575.433);
  2942. break;
  2943. }
  2944. case '6P' :
  2945. case '8R' :
  2946. {
  2947. $pf = array(575.433, 720.000);
  2948. break;
  2949. }
  2950. case '6PW' :
  2951. case 'S8R' :
  2952. {
  2953. $pf = array(575.433, 864.567);
  2954. break;
  2955. }
  2956. case '4P' :
  2957. case '10R' :
  2958. {
  2959. $pf = array(720.000, 864.567);
  2960. break;
  2961. }
  2962. case '4PW' :
  2963. case 'S10R' :
  2964. {
  2965. $pf = array(720.000, 1080.000);
  2966. break;
  2967. }
  2968. case '11R' :
  2969. {
  2970. $pf = array(790.866, 1009.134);
  2971. break;
  2972. }
  2973. case 'S11R' :
  2974. {
  2975. $pf = array(790.866, 1224.567);
  2976. break;
  2977. }
  2978. case '12R' :
  2979. {
  2980. $pf = array(864.567, 1080.000);
  2981. break;
  2982. }
  2983. case 'S12R' :
  2984. {
  2985. $pf = array(864.567, 1292.598);
  2986. break;
  2987. }
  2988. // Common Newspaper Sizes
  2989. case 'NEWSPAPER_BROADSHEET' :
  2990. {
  2991. $pf = array(2125.984, 1700.787);
  2992. break;
  2993. }
  2994. case 'NEWSPAPER_BERLINER' :
  2995. {
  2996. $pf = array(1332.283, 892.913);
  2997. break;
  2998. }
  2999. case 'NEWSPAPER_TABLOID' :
  3000. case 'NEWSPAPER_COMPACT' :
  3001. {
  3002. $pf = array(1218.898, 793.701);
  3003. break;
  3004. }
  3005. // Business Cards
  3006. case 'CREDIT_CARD' :
  3007. case 'BUSINESS_CARD' :
  3008. case 'BUSINESS_CARD_ISO7810' :
  3009. {
  3010. $pf = array(153.014, 242.646);
  3011. break;
  3012. }
  3013. case 'BUSINESS_CARD_ISO216' :
  3014. {
  3015. $pf = array(147.402, 209.764);
  3016. break;
  3017. }
  3018. case 'BUSINESS_CARD_IT' :
  3019. case 'BUSINESS_CARD_UK' :
  3020. case 'BUSINESS_CARD_FR' :
  3021. case 'BUSINESS_CARD_DE' :
  3022. case 'BUSINESS_CARD_ES' :
  3023. {
  3024. $pf = array(155.906, 240.945);
  3025. break;
  3026. }
  3027. case 'BUSINESS_CARD_CA' :
  3028. case 'BUSINESS_CARD_US' :
  3029. {
  3030. $pf = array(144.567, 252.283);
  3031. break;
  3032. }
  3033. case 'BUSINESS_CARD_JP' :
  3034. {
  3035. $pf = array(155.906, 257.953);
  3036. break;
  3037. }
  3038. case 'BUSINESS_CARD_HK' :
  3039. {
  3040. $pf = array(153.071, 255.118);
  3041. break;
  3042. }
  3043. case 'BUSINESS_CARD_AU' :
  3044. case 'BUSINESS_CARD_DK' :
  3045. case 'BUSINESS_CARD_SE' :
  3046. {
  3047. $pf = array(155.906, 255.118);
  3048. break;
  3049. }
  3050. case 'BUSINESS_CARD_RU' :
  3051. case 'BUSINESS_CARD_CZ' :
  3052. case 'BUSINESS_CARD_FI' :
  3053. case 'BUSINESS_CARD_HU' :
  3054. case 'BUSINESS_CARD_IL' :
  3055. {
  3056. $pf = array(141.732, 255.118);
  3057. break;
  3058. }
  3059. // Billboards
  3060. case '4SHEET' :
  3061. {
  3062. $pf = array(2880.000, 4320.000);
  3063. break;
  3064. }
  3065. case '6SHEET' :
  3066. {
  3067. $pf = array(3401.575, 5102.362);
  3068. break;
  3069. }
  3070. case '12SHEET' :
  3071. {
  3072. $pf = array(8640.000, 4320.000);
  3073. break;
  3074. }
  3075. case '16SHEET' :
  3076. {
  3077. $pf = array(5760.000, 8640.000);
  3078. break;
  3079. }
  3080. case '32SHEET' :
  3081. {
  3082. $pf = array(11520.000, 8640.000);
  3083. break;
  3084. }
  3085. case '48SHEET' :
  3086. {
  3087. $pf = array(17280.000, 8640.000);
  3088. break;
  3089. }
  3090. case '64SHEET' :
  3091. {
  3092. $pf = array(23040.000, 8640.000);
  3093. break;
  3094. }
  3095. case '96SHEET' :
  3096. {
  3097. $pf = array(34560.000, 8640.000);
  3098. break;
  3099. }
  3100. // Old European Sizes
  3101. // - Old Imperial English Sizes
  3102. case 'EN_EMPEROR' :
  3103. {
  3104. $pf = array(3456.000, 5184.000);
  3105. break;
  3106. }
  3107. case 'EN_ANTIQUARIAN' :
  3108. {
  3109. $pf = array(2232.000, 3816.000);
  3110. break;
  3111. }
  3112. case 'EN_GRAND_EAGLE' :
  3113. {
  3114. $pf = array(2070.000, 3024.000);
  3115. break;
  3116. }
  3117. case 'EN_DOUBLE_ELEPHANT' :
  3118. {
  3119. $pf = array(1926.000, 2880.000);
  3120. break;
  3121. }
  3122. case 'EN_ATLAS' :
  3123. {
  3124. $pf = array(1872.000, 2448.000);
  3125. break;
  3126. }
  3127. case 'EN_COLOMBIER' :
  3128. {
  3129. $pf = array(1692.000, 2484.000);
  3130. break;
  3131. }
  3132. case 'EN_ELEPHANT' :
  3133. {
  3134. $pf = array(1656.000, 2016.000);
  3135. break;
  3136. }
  3137. case 'EN_DOUBLE_DEMY' :
  3138. {
  3139. $pf = array(1620.000, 2556.000);
  3140. break;
  3141. }
  3142. case 'EN_IMPERIAL' :
  3143. {
  3144. $pf = array(1584.000, 2160.000);
  3145. break;
  3146. }
  3147. case 'EN_PRINCESS' :
  3148. {
  3149. $pf = array(1548.000, 2016.000);
  3150. break;
  3151. }
  3152. case 'EN_CARTRIDGE' :
  3153. {
  3154. $pf = array(1512.000, 1872.000);
  3155. break;
  3156. }
  3157. case 'EN_DOUBLE_LARGE_POST' :
  3158. {
  3159. $pf = array(1512.000, 2376.000);
  3160. break;
  3161. }
  3162. case 'EN_ROYAL' :
  3163. {
  3164. $pf = array(1440.000, 1800.000);
  3165. break;
  3166. }
  3167. case 'EN_SHEET' :
  3168. case 'EN_HALF_POST' :
  3169. {
  3170. $pf = array(1404.000, 1692.000);
  3171. break;
  3172. }
  3173. case 'EN_SUPER_ROYAL' :
  3174. {
  3175. $pf = array(1368.000, 1944.000);
  3176. break;
  3177. }
  3178. case 'EN_DOUBLE_POST' :
  3179. {
  3180. $pf = array(1368.000, 2196.000);
  3181. break;
  3182. }
  3183. case 'EN_MEDIUM' :
  3184. {
  3185. $pf = array(1260.000, 1656.000);
  3186. break;
  3187. }
  3188. case 'EN_DEMY' :
  3189. {
  3190. $pf = array(1260.000, 1620.000);
  3191. break;
  3192. }
  3193. case 'EN_LARGE_POST' :
  3194. {
  3195. $pf = array(1188.000, 1512.000);
  3196. break;
  3197. }
  3198. case 'EN_COPY_DRAUGHT' :
  3199. {
  3200. $pf = array(1152.000, 1440.000);
  3201. break;
  3202. }
  3203. case 'EN_POST' :
  3204. {
  3205. $pf = array(1116.000, 1386.000);
  3206. break;
  3207. }
  3208. case 'EN_CROWN' :
  3209. {
  3210. $pf = array(1080.000, 1440.000);
  3211. break;
  3212. }
  3213. case 'EN_PINCHED_POST' :
  3214. {
  3215. $pf = array(1062.000, 1332.000);
  3216. break;
  3217. }
  3218. case 'EN_BRIEF' :
  3219. {
  3220. $pf = array(972.000, 1152.000);
  3221. break;
  3222. }
  3223. case 'EN_FOOLSCAP' :
  3224. {
  3225. $pf = array(972.000, 1224.000);
  3226. break;
  3227. }
  3228. case 'EN_SMALL_FOOLSCAP' :
  3229. {
  3230. $pf = array(954.000, 1188.000);
  3231. break;
  3232. }
  3233. case 'EN_POTT' :
  3234. {
  3235. $pf = array(900.000, 1080.000);
  3236. break;
  3237. }
  3238. // - Old Imperial Belgian Sizes
  3239. case 'BE_GRAND_AIGLE' :
  3240. {
  3241. $pf = array(1984.252, 2948.031);
  3242. break;
  3243. }
  3244. case 'BE_COLOMBIER' :
  3245. {
  3246. $pf = array(1757.480, 2409.449);
  3247. break;
  3248. }
  3249. case 'BE_DOUBLE_CARRE' :
  3250. {
  3251. $pf = array(1757.480, 2607.874);
  3252. break;
  3253. }
  3254. case 'BE_ELEPHANT' :
  3255. {
  3256. $pf = array(1746.142, 2182.677);
  3257. break;
  3258. }
  3259. case 'BE_PETIT_AIGLE' :
  3260. {
  3261. $pf = array(1700.787, 2381.102);
  3262. break;
  3263. }
  3264. case 'BE_GRAND_JESUS' :
  3265. {
  3266. $pf = array(1559.055, 2069.291);
  3267. break;
  3268. }
  3269. case 'BE_JESUS' :
  3270. {
  3271. $pf = array(1530.709, 2069.291);
  3272. break;
  3273. }
  3274. case 'BE_RAISIN' :
  3275. {
  3276. $pf = array(1417.323, 1842.520);
  3277. break;
  3278. }
  3279. case 'BE_GRAND_MEDIAN' :
  3280. {
  3281. $pf = array(1303.937, 1714.961);
  3282. break;
  3283. }
  3284. case 'BE_DOUBLE_POSTE' :
  3285. {
  3286. $pf = array(1233.071, 1601.575);
  3287. break;
  3288. }
  3289. case 'BE_COQUILLE' :
  3290. {
  3291. $pf = array(1218.898, 1587.402);
  3292. break;
  3293. }
  3294. case 'BE_PETIT_MEDIAN' :
  3295. {
  3296. $pf = array(1176.378, 1502.362);
  3297. break;
  3298. }
  3299. case 'BE_RUCHE' :
  3300. {
  3301. $pf = array(1020.472, 1303.937);
  3302. break;
  3303. }
  3304. case 'BE_PROPATRIA' :
  3305. {
  3306. $pf = array(977.953, 1218.898);
  3307. break;
  3308. }
  3309. case 'BE_LYS' :
  3310. {
  3311. $pf = array(898.583, 1125.354);
  3312. break;
  3313. }
  3314. case 'BE_POT' :
  3315. {
  3316. $pf = array(870.236, 1088.504);
  3317. break;
  3318. }
  3319. case 'BE_ROSETTE' :
  3320. {
  3321. $pf = array(765.354, 983.622);
  3322. break;
  3323. }
  3324. // - Old Imperial French Sizes
  3325. case 'FR_UNIVERS' :
  3326. {
  3327. $pf = array(2834.646, 3685.039);
  3328. break;
  3329. }
  3330. case 'FR_DOUBLE_COLOMBIER' :
  3331. {
  3332. $pf = array(2551.181, 3571.654);
  3333. break;
  3334. }
  3335. case 'FR_GRANDE_MONDE' :
  3336. {
  3337. $pf = array(2551.181, 3571.654);
  3338. break;
  3339. }
  3340. case 'FR_DOUBLE_SOLEIL' :
  3341. {
  3342. $pf = array(2267.717, 3401.575);
  3343. break;
  3344. }
  3345. case 'FR_DOUBLE_JESUS' :
  3346. {
  3347. $pf = array(2154.331, 3174.803);
  3348. break;
  3349. }
  3350. case 'FR_GRAND_AIGLE' :
  3351. {
  3352. $pf = array(2125.984, 3004.724);
  3353. break;
  3354. }
  3355. case 'FR_PETIT_AIGLE' :
  3356. {
  3357. $pf = array(1984.252, 2664.567);
  3358. break;
  3359. }
  3360. case 'FR_DOUBLE_RAISIN' :
  3361. {
  3362. $pf = array(1842.520, 2834.646);
  3363. break;
  3364. }
  3365. case 'FR_JOURNAL' :
  3366. {
  3367. $pf = array(1842.520, 2664.567);
  3368. break;
  3369. }
  3370. case 'FR_COLOMBIER_AFFICHE' :
  3371. {
  3372. $pf = array(1785.827, 2551.181);
  3373. break;
  3374. }
  3375. case 'FR_DOUBLE_CAVALIER' :
  3376. {
  3377. $pf = array(1757.480, 2607.874);
  3378. break;
  3379. }
  3380. case 'FR_CLOCHE' :
  3381. {
  3382. $pf = array(1700.787, 2267.717);
  3383. break;
  3384. }
  3385. case 'FR_SOLEIL' :
  3386. {
  3387. $pf = array(1700.787, 2267.717);
  3388. break;
  3389. }
  3390. case 'FR_DOUBLE_CARRE' :
  3391. {
  3392. $pf = array(1587.402, 2551.181);
  3393. break;
  3394. }
  3395. case 'FR_DOUBLE_COQUILLE' :
  3396. {
  3397. $pf = array(1587.402, 2494.488);
  3398. break;
  3399. }
  3400. case 'FR_JESUS' :
  3401. {
  3402. $pf = array(1587.402, 2154.331);
  3403. break;
  3404. }
  3405. case 'FR_RAISIN' :
  3406. {
  3407. $pf = array(1417.323, 1842.520);
  3408. break;
  3409. }
  3410. case 'FR_CAVALIER' :
  3411. {
  3412. $pf = array(1303.937, 1757.480);
  3413. break;
  3414. }
  3415. case 'FR_DOUBLE_COURONNE' :
  3416. {
  3417. $pf = array(1303.937, 2040.945);
  3418. break;
  3419. }
  3420. case 'FR_CARRE' :
  3421. {
  3422. $pf = array(1275.591, 1587.402);
  3423. break;
  3424. }
  3425. case 'FR_COQUILLE' :
  3426. {
  3427. $pf = array(1247.244, 1587.402);
  3428. break;
  3429. }
  3430. case 'FR_DOUBLE_TELLIERE' :
  3431. {
  3432. $pf = array(1247.244, 1927.559);
  3433. break;
  3434. }
  3435. case 'FR_DOUBLE_CLOCHE' :
  3436. {
  3437. $pf = array(1133.858, 1700.787);
  3438. break;
  3439. }
  3440. case 'FR_DOUBLE_POT' :
  3441. {
  3442. $pf = array(1133.858, 1757.480);
  3443. break;
  3444. }
  3445. case 'FR_ECU' :
  3446. {
  3447. $pf = array(1133.858, 1474.016);
  3448. break;
  3449. }
  3450. case 'FR_COURONNE' :
  3451. {
  3452. $pf = array(1020.472, 1303.937);
  3453. break;
  3454. }
  3455. case 'FR_TELLIERE' :
  3456. {
  3457. $pf = array(963.780, 1247.244);
  3458. break;
  3459. }
  3460. case 'FR_POT' :
  3461. {
  3462. $pf = array(878.740, 1133.858);
  3463. break;
  3464. }
  3465. // DEFAULT ISO A4
  3466. default :
  3467. {
  3468. $pf = array(595.276, 841.890);
  3469. break;
  3470. }
  3471. }
  3472. return $pf;
  3473. }
  3474. /**
  3475. * Change the format of the current page
  3476. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numners (width, height) or an array containing the following measures and options:<ul>
  3477. * <li>['format'] = page format name (one of the above);</li>
  3478. * <li>['Rotate'] : The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li>
  3479. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  3480. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  3481. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  3482. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  3483. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  3484. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  3485. * <li>['CropBox'] : the visible region of default user space:</li>
  3486. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  3487. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  3488. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  3489. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  3490. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  3491. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  3492. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  3493. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  3494. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  3495. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  3496. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  3497. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  3498. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  3499. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  3500. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  3501. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  3502. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  3503. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  3504. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  3505. * <li>['BoxColorInfo'] :specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for each of the possible page boundaries other than the MediaBox:</li>
  3506. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  3507. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  3508. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  3509. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  3510. * <li>['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation</li>
  3511. * <li>['trans']['Dur'] : The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li>
  3512. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  3513. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  3514. * <li>['trans']['Dm'] : (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li>
  3515. * <li>['trans']['M'] : (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li>
  3516. * <li>['trans']['Di'] : (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li>
  3517. * <li>['trans']['SS'] : (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0.</li>
  3518. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  3519. * </ul>
  3520. * @param string $orientation page orientation. Possible values are (case insensitive):<ul>
  3521. * <li>P or Portrait (default)</li>
  3522. * <li>L or Landscape</li>
  3523. * <li>'' (empty string) for automatic orientation</li>
  3524. * </ul>
  3525. * @access protected
  3526. * @since 3.0.015 (2008-06-06)
  3527. * @see getPageSizeFromFormat()
  3528. */
  3529. protected function setPageFormat($format, $orientation = 'P')
  3530. {
  3531. if (! empty($format) and isset($this->pagedim[$this->page]))
  3532. {
  3533. // remove inherited values
  3534. unset($this->pagedim[$this->page]);
  3535. }
  3536. if (is_string($format))
  3537. {
  3538. // get page measures from format name
  3539. $pf = $this->getPageSizeFromFormat($format);
  3540. $this->fwPt = $pf[0];
  3541. $this->fhPt = $pf[1];
  3542. }
  3543. else
  3544. {
  3545. // the boundaries of the physical medium on which the page shall be displayed or printed
  3546. if (isset($format['MediaBox']))
  3547. {
  3548. $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
  3549. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  3550. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  3551. }
  3552. else
  3553. {
  3554. if (isset($format[0]) and is_numeric($format[0]) and isset($format[1]) and is_numeric($format[1]))
  3555. {
  3556. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  3557. }
  3558. else
  3559. {
  3560. if (! isset($format['format']))
  3561. {
  3562. // default value
  3563. $format['format'] = 'A4';
  3564. }
  3565. $pf = $this->getPageSizeFromFormat($format['format']);
  3566. }
  3567. $this->fwPt = $pf[0];
  3568. $this->fhPt = $pf[1];
  3569. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  3570. }
  3571. // the visible region of default user space
  3572. if (isset($format['CropBox']))
  3573. {
  3574. $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
  3575. }
  3576. // the region to which the contents of the page shall be clipped when output in a production environment
  3577. if (isset($format['BleedBox']))
  3578. {
  3579. $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
  3580. }
  3581. // the intended dimensions of the finished page after trimming
  3582. if (isset($format['TrimBox']))
  3583. {
  3584. $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
  3585. }
  3586. // the page's meaningful content (including potential white space)
  3587. if (isset($format['ArtBox']))
  3588. {
  3589. $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
  3590. }
  3591. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  3592. if (isset($format['BoxColorInfo']))
  3593. {
  3594. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  3595. }
  3596. if (isset($format['Rotate']) and (($format['Rotate'] % 90) == 0))
  3597. {
  3598. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  3599. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  3600. }
  3601. if (isset($format['PZ']))
  3602. {
  3603. // The page's preferred zoom (magnification) factor
  3604. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  3605. }
  3606. if (isset($format['trans']))
  3607. {
  3608. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  3609. if (isset($format['trans']['Dur']))
  3610. {
  3611. // The page's display duration
  3612. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  3613. }
  3614. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push',
  3615. 'Cover', 'Uncover', 'Fade');
  3616. if (isset($format['trans']['S']) and in_array($format['trans']['S'], $stansition_styles))
  3617. {
  3618. // The transition style that shall be used when moving to this page from another during a presentation
  3619. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  3620. $valid_effect = array('Split', 'Blinds');
  3621. $valid_vals = array('H', 'V');
  3622. if (isset($format['trans']['Dm']) and in_array($format['trans']['S'], $valid_effect) and in_array($format['trans']['Dm'], $valid_vals))
  3623. {
  3624. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  3625. }
  3626. $valid_effect = array('Split', 'Box', 'Fly');
  3627. $valid_vals = array('I', 'O');
  3628. if (isset($format['trans']['M']) and in_array($format['trans']['S'], $valid_effect) and in_array($format['trans']['M'], $valid_vals))
  3629. {
  3630. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  3631. }
  3632. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  3633. if (isset($format['trans']['Di']) and in_array($format['trans']['S'], $valid_effect))
  3634. {
  3635. if (((($format['trans']['Di'] == 90) or ($format['trans']['Di'] == 180)) and ($format['trans']['S'] == 'Wipe')) or (($format['trans']['Di'] == 315) and ($format['trans']['S'] == 'Glitter')) or (($format['trans']['Di'] == 0) or ($format['trans']['Di'] == 270)))
  3636. {
  3637. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  3638. }
  3639. }
  3640. if (isset($format['trans']['SS']) and ($format['trans']['S'] == 'Fly'))
  3641. {
  3642. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  3643. }
  3644. if (isset($format['trans']['B']) and ($format['trans']['B'] === true) and ($format['trans']['S'] == 'Fly'))
  3645. {
  3646. $this->pagedim[$this->page]['trans']['B'] = 'true';
  3647. }
  3648. }
  3649. else
  3650. {
  3651. $this->pagedim[$this->page]['trans']['S'] = 'R';
  3652. }
  3653. if (isset($format['trans']['D']))
  3654. {
  3655. // The duration of the transition effect, in seconds
  3656. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  3657. }
  3658. else
  3659. {
  3660. $this->pagedim[$this->page]['trans']['D'] = 1;
  3661. }
  3662. }
  3663. }
  3664. $this->setPageOrientation($orientation);
  3665. }
  3666. /**
  3667. * Set page boundaries.
  3668. * @param int $page page number
  3669. * @param string $type valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
  3670. * @param float $llx lower-left x coordinate in user units
  3671. * @param float $lly lower-left y coordinate in user units
  3672. * @param float $urx upper-right x coordinate in user units
  3673. * @param float $ury upper-right y coordinate in user units
  3674. * @param boolean $points if true uses user units as unit of measure, otherwise uses PDF points
  3675. * @access public
  3676. * @since 5.0.010 (2010-05-17)
  3677. */
  3678. public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points = false)
  3679. {
  3680. if (! isset($this->pagedim[$page]))
  3681. {
  3682. // initialize array
  3683. $this->pagedim[$page] = array();
  3684. }
  3685. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  3686. if (! in_array($type, $pageboxes))
  3687. {
  3688. return;
  3689. }
  3690. if ($points)
  3691. {
  3692. $k = 1;
  3693. }
  3694. else
  3695. {
  3696. $k = $this->k;
  3697. }
  3698. $this->pagedim[$page][$type]['llx'] = ($llx * $k);
  3699. $this->pagedim[$page][$type]['lly'] = ($lly * $k);
  3700. $this->pagedim[$page][$type]['urx'] = ($urx * $k);
  3701. $this->pagedim[$page][$type]['ury'] = ($ury * $k);
  3702. }
  3703. /**
  3704. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  3705. * @param int $page page number
  3706. * @access protected
  3707. * @since 5.0.010 (2010-05-17)
  3708. */
  3709. protected function swapPageBoxCoordinates($page)
  3710. {
  3711. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  3712. foreach ($pageboxes as $type)
  3713. {
  3714. // swap X and Y coordinates
  3715. if (isset($this->pagedim[$page][$type]))
  3716. {
  3717. $tmp = $this->pagedim[$page][$type]['llx'];
  3718. $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly'];
  3719. $this->pagedim[$page][$type]['lly'] = $tmp;
  3720. $tmp = $this->pagedim[$page][$type]['urx'];
  3721. $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury'];
  3722. $this->pagedim[$page][$type]['ury'] = $tmp;
  3723. }
  3724. }
  3725. }
  3726. /**
  3727. * Set page orientation.
  3728. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  3729. * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  3730. * @param float $bottommargin bottom margin of the page.
  3731. * @access public
  3732. * @since 3.0.015 (2008-06-06)
  3733. */
  3734. public function setPageOrientation($orientation, $autopagebreak = '', $bottommargin = '')
  3735. {
  3736. if (! isset($this->pagedim[$this->page]['MediaBox']))
  3737. {
  3738. // the boundaries of the physical medium on which the page shall be displayed or printed
  3739. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  3740. }
  3741. if (! isset($this->pagedim[$this->page]['CropBox']))
  3742. {
  3743. // the visible region of default user space
  3744. $this->setPageBoxes($this->page, 'CropBox', $this->pagedim[$this->page]['MediaBox']['llx'], $this->pagedim[$this->page]['MediaBox']['lly'], $this->pagedim[$this->page]['MediaBox']['urx'], $this->pagedim[$this->page]['MediaBox']['ury'], true);
  3745. }
  3746. if (! isset($this->pagedim[$this->page]['BleedBox']))
  3747. {
  3748. // the region to which the contents of the page shall be clipped when output in a production environment
  3749. $this->setPageBoxes($this->page, 'BleedBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
  3750. }
  3751. if (! isset($this->pagedim[$this->page]['TrimBox']))
  3752. {
  3753. // the intended dimensions of the finished page after trimming
  3754. $this->setPageBoxes($this->page, 'TrimBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
  3755. }
  3756. if (! isset($this->pagedim[$this->page]['ArtBox']))
  3757. {
  3758. // the page's meaningful content (including potential white space)
  3759. $this->setPageBoxes($this->page, 'ArtBox', $this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true);
  3760. }
  3761. if (! isset($this->pagedim[$this->page]['Rotate']))
  3762. {
  3763. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  3764. $this->pagedim[$this->page]['Rotate'] = 0;
  3765. }
  3766. if (! isset($this->pagedim[$this->page]['PZ']))
  3767. {
  3768. // The page's preferred zoom (magnification) factor
  3769. $this->pagedim[$this->page]['PZ'] = 1;
  3770. }
  3771. if ($this->fwPt > $this->fhPt)
  3772. {
  3773. // landscape
  3774. $default_orientation = 'L';
  3775. }
  3776. else
  3777. {
  3778. // portrait
  3779. $default_orientation = 'P';
  3780. }
  3781. $valid_orientations = array('P', 'L');
  3782. if (empty($orientation))
  3783. {
  3784. $orientation = $default_orientation;
  3785. }
  3786. else
  3787. {
  3788. $orientation = strtoupper($orientation{0});
  3789. }
  3790. if (in_array($orientation, $valid_orientations) and ($orientation != $default_orientation))
  3791. {
  3792. $this->CurOrientation = $orientation;
  3793. $this->wPt = $this->fhPt;
  3794. $this->hPt = $this->fwPt;
  3795. }
  3796. else
  3797. {
  3798. $this->CurOrientation = $default_orientation;
  3799. $this->wPt = $this->fwPt;
  3800. $this->hPt = $this->fhPt;
  3801. }
  3802. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) and (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps))
  3803. {
  3804. // swap X and Y coordinates (change page orientation)
  3805. $this->swapPageBoxCoordinates($this->page);
  3806. }
  3807. $this->w = $this->wPt / $this->k;
  3808. $this->h = $this->hPt / $this->k;
  3809. if ($this->empty_string($autopagebreak))
  3810. {
  3811. if (isset($this->AutoPageBreak))
  3812. {
  3813. $autopagebreak = $this->AutoPageBreak;
  3814. }
  3815. else
  3816. {
  3817. $autopagebreak = true;
  3818. }
  3819. }
  3820. if ($this->empty_string($bottommargin))
  3821. {
  3822. if (isset($this->bMargin))
  3823. {
  3824. $bottommargin = $this->bMargin;
  3825. }
  3826. else
  3827. {
  3828. // default value = 2 cm
  3829. $bottommargin = 2 * 28.35 / $this->k;
  3830. }
  3831. }
  3832. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  3833. // store page dimensions
  3834. $this->pagedim[$this->page]['w'] = $this->wPt;
  3835. $this->pagedim[$this->page]['h'] = $this->hPt;
  3836. $this->pagedim[$this->page]['wk'] = $this->w;
  3837. $this->pagedim[$this->page]['hk'] = $this->h;
  3838. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3839. $this->pagedim[$this->page]['bm'] = $bottommargin;
  3840. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  3841. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  3842. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  3843. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  3844. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  3845. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  3846. }
  3847. /**
  3848. * Set regular expression to detect withespaces or word separators.
  3849. * The pattern delimiter must be the forward-slash character '/'.
  3850. * Some example patterns are:
  3851. * <pre>
  3852. * Non-Unicode or missing PCRE unicode support: '/[^\S\xa0]/'
  3853. * Unicode and PCRE unicode support: '/[^\S\P{Z}\xa0]/u'
  3854. * Unicode and PCRE unicode support in Chinese mode: '/[^\S\P{Z}\P{Lo}\xa0]/u'
  3855. * if PCRE unicode support is turned ON (\P is the negate class of \p):
  3856. * \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  3857. * \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  3858. * \p{Lo} is needed for Chinese characters because are packed next to each other without spaces in between.
  3859. * </pre>
  3860. * @param string $re regular expression (leave empty for default).
  3861. * @access public
  3862. * @since 4.6.016 (2009-06-15)
  3863. */
  3864. public function setSpacesRE($re = '/[^\S\xa0]/')
  3865. {
  3866. $this->re_spaces = $re;
  3867. $re_parts = explode('/', $re);
  3868. // get pattern parts
  3869. $this->re_space = array();
  3870. if (isset($re_parts[1]) and ! empty($re_parts[1]))
  3871. {
  3872. $this->re_space['p'] = $re_parts[1];
  3873. }
  3874. else
  3875. {
  3876. $this->re_space['p'] = '[\s]';
  3877. }
  3878. // set pattern modifiers
  3879. if (isset($re_parts[2]) and ! empty($re_parts[2]))
  3880. {
  3881. $this->re_space['m'] = $re_parts[2];
  3882. }
  3883. else
  3884. {
  3885. $this->re_space['m'] = '';
  3886. }
  3887. }
  3888. /**
  3889. * Enable or disable Right-To-Left language mode
  3890. * @param Boolean $enable if true enable Right-To-Left language mode.
  3891. * @param Boolean $resetx if true reset the X position on direction change.
  3892. * @access public
  3893. * @since 2.0.000 (2008-01-03)
  3894. */
  3895. public function setRTL($enable, $resetx = true)
  3896. {
  3897. $enable = $enable ? true : false;
  3898. $resetx = ($resetx and ($enable != $this->rtl));
  3899. $this->rtl = $enable;
  3900. $this->tmprtl = false;
  3901. if ($resetx)
  3902. {
  3903. $this->Ln(0);
  3904. }
  3905. }
  3906. /**
  3907. * Return the RTL status
  3908. * @return boolean
  3909. * @access public
  3910. * @since 4.0.012 (2008-07-24)
  3911. */
  3912. public function getRTL()
  3913. {
  3914. return $this->rtl;
  3915. }
  3916. /**
  3917. * Force temporary RTL language direction
  3918. * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  3919. * @access public
  3920. * @since 2.1.000 (2008-01-09)
  3921. */
  3922. public function setTempRTL($mode)
  3923. {
  3924. $newmode = false;
  3925. switch (strtoupper($mode))
  3926. {
  3927. case 'LTR' :
  3928. case 'L' :
  3929. {
  3930. if ($this->rtl)
  3931. {
  3932. $newmode = 'L';
  3933. }
  3934. break;
  3935. }
  3936. case 'RTL' :
  3937. case 'R' :
  3938. {
  3939. if (! $this->rtl)
  3940. {
  3941. $newmode = 'R';
  3942. }
  3943. break;
  3944. }
  3945. case false :
  3946. default :
  3947. {
  3948. $newmode = false;
  3949. break;
  3950. }
  3951. }
  3952. $this->tmprtl = $newmode;
  3953. }
  3954. /**
  3955. * Return the current temporary RTL status
  3956. * @return boolean
  3957. * @access public
  3958. * @since 4.8.014 (2009-11-04)
  3959. */
  3960. public function isRTLTextDir()
  3961. {
  3962. return ($this->rtl or ($this->tmprtl == 'R'));
  3963. }
  3964. /**
  3965. * Set the last cell height.
  3966. * @param float $h cell height.
  3967. * @author Nicola Asuni
  3968. * @access public
  3969. * @since 1.53.0.TC034
  3970. */
  3971. public function setLastH($h)
  3972. {
  3973. $this->lasth = $h;
  3974. }
  3975. /**
  3976. * Reset the last cell height.
  3977. * @access public
  3978. * @since 5.9.000 (2010-10-03)
  3979. */
  3980. public function resetLastH()
  3981. {
  3982. $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  3983. }
  3984. /**
  3985. * Get the last cell height.
  3986. * @return last cell height
  3987. * @access public
  3988. * @since 4.0.017 (2008-08-05)
  3989. */
  3990. public function getLastH()
  3991. {
  3992. return $this->lasth;
  3993. }
  3994. /**
  3995. * Set the adjusting factor to convert pixels to user units.
  3996. * @param float $scale adjusting factor to convert pixels to user units.
  3997. * @author Nicola Asuni
  3998. * @access public
  3999. * @since 1.5.2
  4000. */
  4001. public function setImageScale($scale)
  4002. {
  4003. $this->imgscale = $scale;
  4004. }
  4005. /**
  4006. * Returns the adjusting factor to convert pixels to user units.
  4007. * @return float adjusting factor to convert pixels to user units.
  4008. * @author Nicola Asuni
  4009. * @access public
  4010. * @since 1.5.2
  4011. */
  4012. public function getImageScale()
  4013. {
  4014. return $this->imgscale;
  4015. }
  4016. /**
  4017. * Returns an array of page dimensions:
  4018. * <ul><li>$this->pagedim[$this->page]['w'] = page width in points</li><li>$this->pagedim[$this->page]['h'] = height in points</li><li>$this->pagedim[$this->page]['wk'] = page width in user units</li><li>$this->pagedim[$this->page]['hk'] = page height in user units</li><li>$this->pagedim[$this->page]['tm'] = top margin</li><li>$this->pagedim[$this->page]['bm'] = bottom margin</li><li>$this->pagedim[$this->page]['lm'] = left margin</li><li>$this->pagedim[$this->page]['rm'] = right margin</li><li>$this->pagedim[$this->page]['pb'] = auto page break</li><li>$this->pagedim[$this->page]['or'] = page orientation</li><li>$this->pagedim[$this->page]['olm'] = original left margin</li><li>$this->pagedim[$this->page]['orm'] = original right margin</li><li>$this->pagedim[$this->page]['Rotate'] = The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li><li>$this->pagedim[$this->page]['PZ'] = The page's preferred zoom (magnification) factor.</li><li>$this->pagedim[$this->page]['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation<ul><li>$this->pagedim[$this->page]['trans']['Dur'] = The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li><li>$this->pagedim[$this->page]['trans']['S'] = transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li><li>$this->pagedim[$this->page]['trans']['D'] = The duration of the transition effect, in seconds.</li><li>$this->pagedim[$this->page]['trans']['Dm'] = (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li><li>$this->pagedim[$this->page]['trans']['M'] = (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li><li>$this->pagedim[$this->page]['trans']['Di'] = (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li><li>$this->pagedim[$this->page]['trans']['SS'] = (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0. </li><li>$this->pagedim[$this->page]['trans']['B'] = (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li></ul></li><li>$this->pagedim[$this->page]['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed<ul><li>$this->pagedim[$this->page]['MediaBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['CropBox'] : the visible region of default user space<ul><li>$this->pagedim[$this->page]['CropBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment<ul><li>$this->pagedim[$this->page]['BleedBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['TrimBox'] : the intended dimensions of the finished page after trimming<ul><li>$this->pagedim[$this->page]['TrimBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['ArtBox'] : the extent of the page's meaningful content<ul><li>$this->pagedim[$this->page]['ArtBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['ury'] = upper-right y coordinate in points</li></ul></li></ul>
  4019. * @param int $pagenum page number (empty = current page)
  4020. * @return array of page dimensions.
  4021. * @author Nicola Asuni
  4022. * @access public
  4023. * @since 4.5.027 (2009-03-16)
  4024. */
  4025. public function getPageDimensions($pagenum = '')
  4026. {
  4027. if (empty($pagenum))
  4028. {
  4029. $pagenum = $this->page;
  4030. }
  4031. return $this->pagedim[$pagenum];
  4032. }
  4033. /**
  4034. * Returns the page width in units.
  4035. * @param int $pagenum page number (empty = current page)
  4036. * @return int page width.
  4037. * @author Nicola Asuni
  4038. * @access public
  4039. * @since 1.5.2
  4040. * @see getPageDimensions()
  4041. */
  4042. public function getPageWidth($pagenum = '')
  4043. {
  4044. if (empty($pagenum))
  4045. {
  4046. return $this->w;
  4047. }
  4048. return $this->pagedim[$pagenum]['w'];
  4049. }
  4050. /**
  4051. * Returns the page height in units.
  4052. * @param int $pagenum page number (empty = current page)
  4053. * @return int page height.
  4054. * @author Nicola Asuni
  4055. * @access public
  4056. * @since 1.5.2
  4057. * @see getPageDimensions()
  4058. */
  4059. public function getPageHeight($pagenum = '')
  4060. {
  4061. if (empty($pagenum))
  4062. {
  4063. return $this->h;
  4064. }
  4065. return $this->pagedim[$pagenum]['h'];
  4066. }
  4067. /**
  4068. * Returns the page break margin.
  4069. * @param int $pagenum page number (empty = current page)
  4070. * @return int page break margin.
  4071. * @author Nicola Asuni
  4072. * @access public
  4073. * @since 1.5.2
  4074. * @see getPageDimensions()
  4075. */
  4076. public function getBreakMargin($pagenum = '')
  4077. {
  4078. if (empty($pagenum))
  4079. {
  4080. return $this->bMargin;
  4081. }
  4082. return $this->pagedim[$pagenum]['bm'];
  4083. }
  4084. /**
  4085. * Returns the scale factor (number of points in user unit).
  4086. * @return int scale factor.
  4087. * @author Nicola Asuni
  4088. * @access public
  4089. * @since 1.5.2
  4090. */
  4091. public function getScaleFactor()
  4092. {
  4093. return $this->k;
  4094. }
  4095. /**
  4096. * Defines the left, top and right margins.
  4097. * @param float $left Left margin.
  4098. * @param float $top Top margin.
  4099. * @param float $right Right margin. Default value is the left one.
  4100. * @param boolean $keepmargins if true overwrites the default page margins
  4101. * @access public
  4102. * @since 1.0
  4103. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  4104. */
  4105. public function SetMargins($left, $top, $right = -1, $keepmargins = false)
  4106. {
  4107. //Set left, top and right margins
  4108. $this->lMargin = $left;
  4109. $this->tMargin = $top;
  4110. if ($right == - 1)
  4111. {
  4112. $right = $left;
  4113. }
  4114. $this->rMargin = $right;
  4115. if ($keepmargins)
  4116. {
  4117. // overwrite original values
  4118. $this->original_lMargin = $this->lMargin;
  4119. $this->original_rMargin = $this->rMargin;
  4120. }
  4121. }
  4122. /**
  4123. * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
  4124. * @param float $margin The margin.
  4125. * @access public
  4126. * @since 1.4
  4127. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  4128. */
  4129. public function SetLeftMargin($margin)
  4130. {
  4131. //Set left margin
  4132. $this->lMargin = $margin;
  4133. if (($this->page > 0) and ($this->x < $margin))
  4134. {
  4135. $this->x = $margin;
  4136. }
  4137. }
  4138. /**
  4139. * Defines the top margin. The method can be called before creating the first page.
  4140. * @param float $margin The margin.
  4141. * @access public
  4142. * @since 1.5
  4143. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  4144. */
  4145. public function SetTopMargin($margin)
  4146. {
  4147. //Set top margin
  4148. $this->tMargin = $margin;
  4149. if (($this->page > 0) and ($this->y < $margin))
  4150. {
  4151. $this->y = $margin;
  4152. }
  4153. }
  4154. /**
  4155. * Defines the right margin. The method can be called before creating the first page.
  4156. * @param float $margin The margin.
  4157. * @access public
  4158. * @since 1.5
  4159. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  4160. */
  4161. public function SetRightMargin($margin)
  4162. {
  4163. $this->rMargin = $margin;
  4164. if (($this->page > 0) and ($this->x > ($this->w - $margin)))
  4165. {
  4166. $this->x = $this->w - $margin;
  4167. }
  4168. }
  4169. /**
  4170. * Set the same internal Cell padding for top, right, bottom, left-
  4171. * @param float $pad internal padding.
  4172. * @access public
  4173. * @since 2.1.000 (2008-01-09)
  4174. * @see getCellPaddings(), setCellPaddings()
  4175. */
  4176. public function SetCellPadding($pad)
  4177. {
  4178. if ($pad >= 0)
  4179. {
  4180. $this->cell_padding['L'] = $pad;
  4181. $this->cell_padding['T'] = $pad;
  4182. $this->cell_padding['R'] = $pad;
  4183. $this->cell_padding['B'] = $pad;
  4184. }
  4185. }
  4186. /**
  4187. * Set the internal Cell paddings.
  4188. * @param float $left left padding
  4189. * @param float $top top padding
  4190. * @param float $right right padding
  4191. * @param float $bottom bottom padding
  4192. * @access public
  4193. * @since 5.9.000 (2010-10-03)
  4194. * @see getCellPaddings(), SetCellPadding()
  4195. */
  4196. public function setCellPaddings($left = '', $top = '', $right = '', $bottom = '')
  4197. {
  4198. if (($left !== '') and ($left >= 0))
  4199. {
  4200. $this->cell_padding['L'] = $left;
  4201. }
  4202. if (($top !== '') and ($top >= 0))
  4203. {
  4204. $this->cell_padding['T'] = $top;
  4205. }
  4206. if (($right !== '') and ($right >= 0))
  4207. {
  4208. $this->cell_padding['R'] = $right;
  4209. }
  4210. if (($bottom !== '') and ($bottom >= 0))
  4211. {
  4212. $this->cell_padding['B'] = $bottom;
  4213. }
  4214. }
  4215. /**
  4216. * Get the internal Cell padding array.
  4217. * @return array of padding values
  4218. * @access public
  4219. * @since 5.9.000 (2010-10-03)
  4220. * @see setCellPaddings(), SetCellPadding()
  4221. */
  4222. public function getCellPaddings()
  4223. {
  4224. return $this->cell_padding;
  4225. }
  4226. /**
  4227. * Set the internal Cell margins.
  4228. * @param float $left left margin
  4229. * @param float $top top margin
  4230. * @param float $right right margin
  4231. * @param float $bottom bottom margin
  4232. * @access public
  4233. * @since 5.9.000 (2010-10-03)
  4234. * @see getCellMargins()
  4235. */
  4236. public function setCellMargins($left = '', $top = '', $right = '', $bottom = '')
  4237. {
  4238. if (($left !== '') and ($left >= 0))
  4239. {
  4240. $this->cell_margin['L'] = $left;
  4241. }
  4242. if (($top !== '') and ($top >= 0))
  4243. {
  4244. $this->cell_margin['T'] = $top;
  4245. }
  4246. if (($right !== '') and ($right >= 0))
  4247. {
  4248. $this->cell_margin['R'] = $right;
  4249. }
  4250. if (($bottom !== '') and ($bottom >= 0))
  4251. {
  4252. $this->cell_margin['B'] = $bottom;
  4253. }
  4254. }
  4255. /**
  4256. * Get the internal Cell margin array.
  4257. * @return array of margin values
  4258. * @access public
  4259. * @since 5.9.000 (2010-10-03)
  4260. * @see setCellMargins()
  4261. */
  4262. public function getCellMargins()
  4263. {
  4264. return $this->cell_margin;
  4265. }
  4266. /**
  4267. * Adjust the internal Cell padding array to take account of the line width.
  4268. * @param mixed $brd Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4269. * @return array of adjustments
  4270. * @access public
  4271. * @since 5.9.000 (2010-10-03)
  4272. */
  4273. protected function adjustCellPadding($brd = 0)
  4274. {
  4275. if (empty($brd))
  4276. {
  4277. return;
  4278. }
  4279. if (is_string($brd))
  4280. {
  4281. // convert string to array
  4282. $slen = strlen($brd);
  4283. $newbrd = array();
  4284. for($i = 0; $i < $slen; ++ $i)
  4285. {
  4286. $newbrd[$brd{$i}] = true;
  4287. }
  4288. $brd = $newbrd;
  4289. }
  4290. elseif (($brd === 1) or ($brd === true) or (is_numeric($brd) and (intval($brd) > 0)))
  4291. {
  4292. $brd = array('LRTB' => true);
  4293. }
  4294. if (! is_array($brd))
  4295. {
  4296. return;
  4297. }
  4298. // store current cell padding
  4299. $cp = $this->cell_padding;
  4300. // select border mode
  4301. if (isset($brd['mode']))
  4302. {
  4303. $mode = $brd['mode'];
  4304. unset($brd['mode']);
  4305. }
  4306. else
  4307. {
  4308. $mode = 'normal';
  4309. }
  4310. // process borders
  4311. foreach ($brd as $border => $style)
  4312. {
  4313. $line_width = $this->LineWidth;
  4314. if (is_array($style) and isset($style['width']))
  4315. {
  4316. // get border width
  4317. $line_width = $style['width'];
  4318. }
  4319. $adj = 0; // line width inside the cell
  4320. switch ($mode)
  4321. {
  4322. case 'ext' :
  4323. {
  4324. $adj = 0;
  4325. break;
  4326. }
  4327. case 'int' :
  4328. {
  4329. $adj = $line_width;
  4330. break;
  4331. }
  4332. case 'normal' :
  4333. default :
  4334. {
  4335. $adj = ($line_width / 2);
  4336. break;
  4337. }
  4338. }
  4339. // correct internal cell padding if required to avoid overlap between text and lines
  4340. if ((strpos($border, 'T') !== false) and ($this->cell_padding['T'] < $adj))
  4341. {
  4342. $this->cell_padding['T'] = $adj;
  4343. }
  4344. if ((strpos($border, 'R') !== false) and ($this->cell_padding['R'] < $adj))
  4345. {
  4346. $this->cell_padding['R'] = $adj;
  4347. }
  4348. if ((strpos($border, 'B') !== false) and ($this->cell_padding['B'] < $adj))
  4349. {
  4350. $this->cell_padding['B'] = $adj;
  4351. }
  4352. if ((strpos($border, 'L') !== false) and ($this->cell_padding['L'] < $adj))
  4353. {
  4354. $this->cell_padding['L'] = $adj;
  4355. }
  4356. }
  4357. return array('T' => ($this->cell_padding['T'] - $cp['T']), 'R' => ($this->cell_padding['R'] - $cp['R']),
  4358. 'B' => ($this->cell_padding['B'] - $cp['B']), 'L' => ($this->cell_padding['L'] - $cp['L']));
  4359. }
  4360. /**
  4361. * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
  4362. * @param boolean $auto Boolean indicating if mode should be on or off.
  4363. * @param float $margin Distance from the bottom of the page.
  4364. * @access public
  4365. * @since 1.0
  4366. * @see Cell(), MultiCell(), AcceptPageBreak()
  4367. */
  4368. public function SetAutoPageBreak($auto, $margin = 0)
  4369. {
  4370. //Set auto page break mode and triggering margin
  4371. $this->AutoPageBreak = $auto;
  4372. $this->bMargin = $margin;
  4373. $this->PageBreakTrigger = $this->h - $margin;
  4374. }
  4375. /**
  4376. * Defines the way the document is to be displayed by the viewer.
  4377. * @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  4378. * @param string $layout The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  4379. * @param string $mode A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  4380. * @access public
  4381. * @since 1.2
  4382. */
  4383. public function SetDisplayMode($zoom, $layout = 'SinglePage', $mode = 'UseNone')
  4384. {
  4385. //Set display mode in viewer
  4386. if (($zoom == 'fullpage') or ($zoom == 'fullwidth') or ($zoom == 'real') or ($zoom == 'default') or (! is_string($zoom)))
  4387. {
  4388. $this->ZoomMode = $zoom;
  4389. }
  4390. else
  4391. {
  4392. $this->Error('Incorrect zoom display mode: ' . $zoom);
  4393. }
  4394. switch ($layout)
  4395. {
  4396. case 'default' :
  4397. case 'single' :
  4398. case 'SinglePage' :
  4399. {
  4400. $this->LayoutMode = 'SinglePage';
  4401. break;
  4402. }
  4403. case 'continuous' :
  4404. case 'OneColumn' :
  4405. {
  4406. $this->LayoutMode = 'OneColumn';
  4407. break;
  4408. }
  4409. case 'two' :
  4410. case 'TwoColumnLeft' :
  4411. {
  4412. $this->LayoutMode = 'TwoColumnLeft';
  4413. break;
  4414. }
  4415. case 'TwoColumnRight' :
  4416. {
  4417. $this->LayoutMode = 'TwoColumnRight';
  4418. break;
  4419. }
  4420. case 'TwoPageLeft' :
  4421. {
  4422. $this->LayoutMode = 'TwoPageLeft';
  4423. break;
  4424. }
  4425. case 'TwoPageRight' :
  4426. {
  4427. $this->LayoutMode = 'TwoPageRight';
  4428. break;
  4429. }
  4430. default :
  4431. {
  4432. $this->LayoutMode = 'SinglePage';
  4433. }
  4434. }
  4435. switch ($mode)
  4436. {
  4437. case 'UseNone' :
  4438. {
  4439. $this->PageMode = 'UseNone';
  4440. break;
  4441. }
  4442. case 'UseOutlines' :
  4443. {
  4444. $this->PageMode = 'UseOutlines';
  4445. break;
  4446. }
  4447. case 'UseThumbs' :
  4448. {
  4449. $this->PageMode = 'UseThumbs';
  4450. break;
  4451. }
  4452. case 'FullScreen' :
  4453. {
  4454. $this->PageMode = 'FullScreen';
  4455. break;
  4456. }
  4457. case 'UseOC' :
  4458. {
  4459. $this->PageMode = 'UseOC';
  4460. break;
  4461. }
  4462. case '' :
  4463. {
  4464. $this->PageMode = 'UseAttachments';
  4465. break;
  4466. }
  4467. default :
  4468. {
  4469. $this->PageMode = 'UseNone';
  4470. }
  4471. }
  4472. }
  4473. /**
  4474. * Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
  4475. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  4476. * @param boolean $compress Boolean indicating if compression must be enabled.
  4477. * @access public
  4478. * @since 1.4
  4479. */
  4480. public function SetCompression($compress)
  4481. {
  4482. //Set page compression
  4483. if (function_exists('gzcompress'))
  4484. {
  4485. $this->compress = $compress ? true : false;
  4486. }
  4487. else
  4488. {
  4489. $this->compress = false;
  4490. }
  4491. }
  4492. /**
  4493. * Defines the title of the document.
  4494. * @param string $title The title.
  4495. * @access public
  4496. * @since 1.2
  4497. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  4498. */
  4499. public function SetTitle($title)
  4500. {
  4501. //Title of document
  4502. $this->title = $title;
  4503. }
  4504. /**
  4505. * Defines the subject of the document.
  4506. * @param string $subject The subject.
  4507. * @access public
  4508. * @since 1.2
  4509. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  4510. */
  4511. public function SetSubject($subject)
  4512. {
  4513. //Subject of document
  4514. $this->subject = $subject;
  4515. }
  4516. /**
  4517. * Defines the author of the document.
  4518. * @param string $author The name of the author.
  4519. * @access public
  4520. * @since 1.2
  4521. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  4522. */
  4523. public function SetAuthor($author)
  4524. {
  4525. //Author of document
  4526. $this->author = $author;
  4527. }
  4528. /**
  4529. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  4530. * @param string $keywords The list of keywords.
  4531. * @access public
  4532. * @since 1.2
  4533. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  4534. */
  4535. public function SetKeywords($keywords)
  4536. {
  4537. //Keywords of document
  4538. $this->keywords = $keywords;
  4539. }
  4540. /**
  4541. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  4542. * @param string $creator The name of the creator.
  4543. * @access public
  4544. * @since 1.2
  4545. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  4546. */
  4547. public function SetCreator($creator)
  4548. {
  4549. //Creator of document
  4550. $this->creator = $creator;
  4551. }
  4552. /**
  4553. * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
  4554. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  4555. * @param string $msg The error message
  4556. * @access public
  4557. * @since 1.0
  4558. */
  4559. public function Error($msg)
  4560. {
  4561. // unset all class variables
  4562. $this->_destroy(true);
  4563. // exit program and print error
  4564. die('<strong>TCPDF ERROR: </strong>' . $msg);
  4565. }
  4566. /**
  4567. * This method begins the generation of the PDF document.
  4568. * It is not necessary to call it explicitly because AddPage() does it automatically.
  4569. * Note: no page is created by this method
  4570. * @access public
  4571. * @since 1.0
  4572. * @see AddPage(), Close()
  4573. */
  4574. public function Open()
  4575. {
  4576. //Begin document
  4577. $this->state = 1;
  4578. }
  4579. /**
  4580. * Terminates the PDF document.
  4581. * It is not necessary to call this method explicitly because Output() does it automatically.
  4582. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  4583. * @access public
  4584. * @since 1.0
  4585. * @see Open(), Output()
  4586. */
  4587. public function Close()
  4588. {
  4589. if ($this->state == 3)
  4590. {
  4591. return;
  4592. }
  4593. if ($this->page == 0)
  4594. {
  4595. $this->AddPage();
  4596. }
  4597. // save current graphic settings
  4598. $gvars = $this->getGraphicVars();
  4599. $this->lastpage(true);
  4600. $this->SetAutoPageBreak(false);
  4601. $this->x = 0;
  4602. $this->y = $this->h - (1 / $this->k);
  4603. $this->lMargin = 0;
  4604. $this->_out('q');
  4605. $this->setVisibility('screen');
  4606. $this->SetFont('helvetica', '', 1);
  4607. $this->SetTextColor(255, 255, 255);
  4608. $msg = "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
  4609. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  4610. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  4611. $this->setVisibility('all');
  4612. $this->_out('Q');
  4613. // restore graphic settings
  4614. $this->setGraphicVars($gvars);
  4615. // close page
  4616. $this->endPage();
  4617. // close document
  4618. $this->_enddoc();
  4619. // unset all class variables (except critical ones)
  4620. $this->_destroy(false);
  4621. }
  4622. /**
  4623. * Move pointer at the specified document page and update page dimensions.
  4624. * @param int $pnum page number (1 ... numpages)
  4625. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  4626. * @access public
  4627. * @since 2.1.000 (2008-01-07)
  4628. * @see getPage(), lastpage(), getNumPages()
  4629. */
  4630. public function setPage($pnum, $resetmargins = false)
  4631. {
  4632. if (($pnum == $this->page) and ($this->state == 2))
  4633. {
  4634. return;
  4635. }
  4636. if (($pnum > 0) and ($pnum <= $this->numpages))
  4637. {
  4638. $this->state = 2;
  4639. // save current graphic settings
  4640. //$gvars = $this->getGraphicVars();
  4641. $oldpage = $this->page;
  4642. $this->page = $pnum;
  4643. $this->wPt = $this->pagedim[$this->page]['w'];
  4644. $this->hPt = $this->pagedim[$this->page]['h'];
  4645. $this->w = $this->pagedim[$this->page]['wk'];
  4646. $this->h = $this->pagedim[$this->page]['hk'];
  4647. $this->tMargin = $this->pagedim[$this->page]['tm'];
  4648. $this->bMargin = $this->pagedim[$this->page]['bm'];
  4649. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  4650. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  4651. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  4652. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  4653. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  4654. // restore graphic settings
  4655. //$this->setGraphicVars($gvars);
  4656. if ($resetmargins)
  4657. {
  4658. $this->lMargin = $this->pagedim[$this->page]['olm'];
  4659. $this->rMargin = $this->pagedim[$this->page]['orm'];
  4660. $this->SetY($this->tMargin);
  4661. }
  4662. else
  4663. {
  4664. // account for booklet mode
  4665. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm'])
  4666. {
  4667. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  4668. $this->lMargin += $deltam;
  4669. $this->rMargin -= $deltam;
  4670. }
  4671. }
  4672. }
  4673. else
  4674. {
  4675. $this->Error('Wrong page number on setPage() function: ' . $pnum);
  4676. }
  4677. }
  4678. /**
  4679. * Reset pointer to the last document page.
  4680. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  4681. * @access public
  4682. * @since 2.0.000 (2008-01-04)
  4683. * @see setPage(), getPage(), getNumPages()
  4684. */
  4685. public function lastPage($resetmargins = false)
  4686. {
  4687. $this->setPage($this->getNumPages(), $resetmargins);
  4688. }
  4689. /**
  4690. * Get current document page number.
  4691. * @return int page number
  4692. * @access public
  4693. * @since 2.1.000 (2008-01-07)
  4694. * @see setPage(), lastpage(), getNumPages()
  4695. */
  4696. public function getPage()
  4697. {
  4698. return $this->page;
  4699. }
  4700. /**
  4701. * Get the total number of insered pages.
  4702. * @return int number of pages
  4703. * @access public
  4704. * @since 2.1.000 (2008-01-07)
  4705. * @see setPage(), getPage(), lastpage()
  4706. */
  4707. public function getNumPages()
  4708. {
  4709. return $this->numpages;
  4710. }
  4711. /**
  4712. * Adds a new TOC (Table Of Content) page to the document.
  4713. * @param string $orientation page orientation.
  4714. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  4715. * @access public
  4716. * @since 5.0.001 (2010-05-06)
  4717. * @see AddPage(), startPage(), endPage(), endTOCPage()
  4718. */
  4719. public function addTOCPage($orientation = '', $format = '', $keepmargins = false)
  4720. {
  4721. $this->AddPage($orientation, $format, $keepmargins, true);
  4722. }
  4723. /**
  4724. * Terminate the current TOC (Table Of Content) page
  4725. * @access public
  4726. * @since 5.0.001 (2010-05-06)
  4727. * @see AddPage(), startPage(), endPage(), addTOCPage()
  4728. */
  4729. public function endTOCPage()
  4730. {
  4731. $this->endPage(true);
  4732. }
  4733. /**
  4734. * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer (if enabled). Then the page is added, the current position set to the top-left corner according to the left and top margins (or top-right if in RTL mode), and Header() is called to display the header (if enabled).
  4735. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  4736. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  4737. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  4738. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  4739. * @param boolean $tocpage if true set the tocpage state to true (the added page will be used to display Table Of Content).
  4740. * @access public
  4741. * @since 1.0
  4742. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  4743. */
  4744. public function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
  4745. {
  4746. if ($this->inxobj)
  4747. {
  4748. // we are inside an XObject template
  4749. return;
  4750. }
  4751. if (! isset($this->original_lMargin) or $keepmargins)
  4752. {
  4753. $this->original_lMargin = $this->lMargin;
  4754. }
  4755. if (! isset($this->original_rMargin) or $keepmargins)
  4756. {
  4757. $this->original_rMargin = $this->rMargin;
  4758. }
  4759. // terminate previous page
  4760. $this->endPage();
  4761. // start new page
  4762. $this->startPage($orientation, $format, $tocpage);
  4763. }
  4764. /**
  4765. * Terminate the current page
  4766. * @param boolean $tocpage if true set the tocpage state to false (end the page used to display Table Of Content).
  4767. * @access public
  4768. * @since 4.2.010 (2008-11-14)
  4769. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  4770. */
  4771. public function endPage($tocpage = false)
  4772. {
  4773. // check if page is already closed
  4774. if (($this->page == 0) or ($this->numpages > $this->page) or (! $this->pageopen[$this->page]))
  4775. {
  4776. return;
  4777. }
  4778. $this->InFooter = true;
  4779. // print page footer
  4780. $this->setFooter();
  4781. // close page
  4782. $this->_endpage();
  4783. // mark page as closed
  4784. $this->pageopen[$this->page] = false;
  4785. $this->InFooter = false;
  4786. if ($tocpage)
  4787. {
  4788. $this->tocpage = false;
  4789. }
  4790. }
  4791. /**
  4792. * Starts a new page to the document. The page must be closed using the endPage() function.
  4793. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  4794. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  4795. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  4796. * @access public
  4797. * @since 4.2.010 (2008-11-14)
  4798. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  4799. */
  4800. public function startPage($orientation = '', $format = '', $tocpage = false)
  4801. {
  4802. if ($tocpage)
  4803. {
  4804. $this->tocpage = true;
  4805. }
  4806. if ($this->numpages > $this->page)
  4807. {
  4808. // this page has been already added
  4809. $this->setPage($this->page + 1);
  4810. $this->SetY($this->tMargin);
  4811. return;
  4812. }
  4813. // start a new page
  4814. if ($this->state == 0)
  4815. {
  4816. $this->Open();
  4817. }
  4818. ++ $this->numpages;
  4819. $this->swapMargins($this->booklet);
  4820. // save current graphic settings
  4821. $gvars = $this->getGraphicVars();
  4822. // start new page
  4823. $this->_beginpage($orientation, $format);
  4824. // mark page as open
  4825. $this->pageopen[$this->page] = true;
  4826. // restore graphic settings
  4827. $this->setGraphicVars($gvars);
  4828. // mark this point
  4829. $this->setPageMark();
  4830. // print page header
  4831. $this->setHeader();
  4832. // restore graphic settings
  4833. $this->setGraphicVars($gvars);
  4834. // mark this point
  4835. $this->setPageMark();
  4836. // print table header (if any)
  4837. $this->setTableHeader();
  4838. // set mark for empty page check
  4839. $this->emptypagemrk[$this->page] = $this->pagelen[$this->page];
  4840. }
  4841. /**
  4842. * Set start-writing mark on current page stream used to put borders and fills.
  4843. * Borders and fills are always created after content and inserted on the position marked by this method.
  4844. * This function must be called after calling Image() function for a background image.
  4845. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  4846. * @access public
  4847. * @since 4.0.016 (2008-07-30)
  4848. */
  4849. public function setPageMark()
  4850. {
  4851. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  4852. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  4853. $this->setContentMark();
  4854. }
  4855. /**
  4856. * Set start-writing mark on selected page.
  4857. * Borders and fills are always created after content and inserted on the position marked by this method.
  4858. * @param int $page page number (default is the current page)
  4859. * @access protected
  4860. * @since 4.6.021 (2009-07-20)
  4861. */
  4862. protected function setContentMark($page = 0)
  4863. {
  4864. if ($page <= 0)
  4865. {
  4866. $page = $this->page;
  4867. }
  4868. if (isset($this->footerlen[$page]))
  4869. {
  4870. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  4871. }
  4872. else
  4873. {
  4874. $this->cntmrk[$page] = $this->pagelen[$page];
  4875. }
  4876. }
  4877. /**
  4878. * Set header data.
  4879. * @param string $ln header image logo
  4880. * @param string $lw header image logo width in mm
  4881. * @param string $ht string to print as title on document header
  4882. * @param string $hs string to print on document header
  4883. * @access public
  4884. */
  4885. public function setHeaderData($ln = '', $lw = 0, $ht = '', $hs = '')
  4886. {
  4887. $this->header_logo = $ln;
  4888. $this->header_logo_width = $lw;
  4889. $this->header_title = $ht;
  4890. $this->header_string = $hs;
  4891. }
  4892. /**
  4893. * Returns header data:
  4894. * <ul><li>$ret['logo'] = logo image</li><li>$ret['logo_width'] = width of the image logo in user units</li><li>$ret['title'] = header title</li><li>$ret['string'] = header description string</li></ul>
  4895. * @return array()
  4896. * @access public
  4897. * @since 4.0.012 (2008-07-24)
  4898. */
  4899. public function getHeaderData()
  4900. {
  4901. $ret = array();
  4902. $ret['logo'] = $this->header_logo;
  4903. $ret['logo_width'] = $this->header_logo_width;
  4904. $ret['title'] = $this->header_title;
  4905. $ret['string'] = $this->header_string;
  4906. return $ret;
  4907. }
  4908. /**
  4909. * Set header margin.
  4910. * (minimum distance between header and top page margin)
  4911. * @param int $hm distance in user units
  4912. * @access public
  4913. */
  4914. public function setHeaderMargin($hm = 10)
  4915. {
  4916. $this->header_margin = $hm;
  4917. }
  4918. /**
  4919. * Returns header margin in user units.
  4920. * @return float
  4921. * @since 4.0.012 (2008-07-24)
  4922. * @access public
  4923. */
  4924. public function getHeaderMargin()
  4925. {
  4926. return $this->header_margin;
  4927. }
  4928. /**
  4929. * Set footer margin.
  4930. * (minimum distance between footer and bottom page margin)
  4931. * @param int $fm distance in user units
  4932. * @access public
  4933. */
  4934. public function setFooterMargin($fm = 10)
  4935. {
  4936. $this->footer_margin = $fm;
  4937. }
  4938. /**
  4939. * Returns footer margin in user units.
  4940. * @return float
  4941. * @since 4.0.012 (2008-07-24)
  4942. * @access public
  4943. */
  4944. public function getFooterMargin()
  4945. {
  4946. return $this->footer_margin;
  4947. }
  4948. /**
  4949. * Set a flag to print page header.
  4950. * @param boolean $val set to true to print the page header (default), false otherwise.
  4951. * @access public
  4952. */
  4953. public function setPrintHeader($val = true)
  4954. {
  4955. $this->print_header = $val;
  4956. }
  4957. /**
  4958. * Set a flag to print page footer.
  4959. * @param boolean $value set to true to print the page footer (default), false otherwise.
  4960. * @access public
  4961. */
  4962. public function setPrintFooter($val = true)
  4963. {
  4964. $this->print_footer = $val;
  4965. }
  4966. /**
  4967. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  4968. * @return float
  4969. * @access public
  4970. */
  4971. public function getImageRBX()
  4972. {
  4973. return $this->img_rb_x;
  4974. }
  4975. /**
  4976. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  4977. * @return float
  4978. * @access public
  4979. */
  4980. public function getImageRBY()
  4981. {
  4982. return $this->img_rb_y;
  4983. }
  4984. /**
  4985. * This method is used to render the page header.
  4986. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  4987. * @access public
  4988. */
  4989. public function Header()
  4990. {
  4991. $ormargins = $this->getOriginalMargins();
  4992. $headerfont = $this->getHeaderFont();
  4993. $headerdata = $this->getHeaderData();
  4994. if (($headerdata['logo']) and ($headerdata['logo'] != K_BLANK_IMAGE))
  4995. {
  4996. $this->Image(K_PATH_IMAGES . $headerdata['logo'], '', '', $headerdata['logo_width']);
  4997. $imgy = $this->getImageRBY();
  4998. }
  4999. else
  5000. {
  5001. $imgy = $this->GetY();
  5002. }
  5003. $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
  5004. // set starting margin for text data cell
  5005. if ($this->getRTL())
  5006. {
  5007. $header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1);
  5008. }
  5009. else
  5010. {
  5011. $header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1);
  5012. }
  5013. $this->SetTextColor(0, 0, 0);
  5014. // header title
  5015. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  5016. $this->SetX($header_x);
  5017. $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  5018. // header string
  5019. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  5020. $this->SetX($header_x);
  5021. $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
  5022. // print an ending header line
  5023. $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt',
  5024. 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  5025. $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY()));
  5026. if ($this->getRTL())
  5027. {
  5028. $this->SetX($ormargins['right']);
  5029. }
  5030. else
  5031. {
  5032. $this->SetX($ormargins['left']);
  5033. }
  5034. $this->Cell(0, 0, '', 'T', 0, 'C');
  5035. }
  5036. /**
  5037. * This method is used to render the page footer.
  5038. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  5039. * @access public
  5040. */
  5041. public function Footer()
  5042. {
  5043. $cur_y = $this->GetY();
  5044. $ormargins = $this->getOriginalMargins();
  5045. $this->SetTextColor(0, 0, 0);
  5046. //set style for cell border
  5047. $line_width = 0.85 / $this->getScaleFactor();
  5048. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0,
  5049. 'color' => array(0, 0, 0)));
  5050. //print document barcode
  5051. $barcode = $this->getBarcode();
  5052. if (! empty($barcode))
  5053. {
  5054. $this->Ln($line_width);
  5055. $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right']) / 3);
  5056. $style = array('position' => $this->rtl ? 'R' : 'L', 'align' => $this->rtl ? 'R' : 'L', 'stretch' => false,
  5057. 'fitwidth' => true, 'cellfitalign' => '', 'border' => false, 'padding' => 0,
  5058. 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'text' => false);
  5059. $this->write1DBarcode($barcode, 'C128B', '', $cur_y + $line_width, '', (($this->getFooterMargin() / 3) - $line_width), 0.3, $style, '');
  5060. }
  5061. if (empty($this->pagegroups))
  5062. {
  5063. $pagenumtxt = $this->l['w_page'] . ' ' . $this->getAliasNumPage() . ' / ' . $this->getAliasNbPages();
  5064. }
  5065. else
  5066. {
  5067. $pagenumtxt = $this->l['w_page'] . ' ' . $this->getPageNumGroupAlias() . ' / ' . $this->getPageGroupAlias();
  5068. }
  5069. $this->SetY($cur_y);
  5070. //Print page number
  5071. if ($this->getRTL())
  5072. {
  5073. $this->SetX($ormargins['right']);
  5074. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  5075. }
  5076. else
  5077. {
  5078. $this->SetX($ormargins['left']);
  5079. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
  5080. }
  5081. }
  5082. /**
  5083. * This method is used to render the page header.
  5084. * @access protected
  5085. * @since 4.0.012 (2008-07-24)
  5086. */
  5087. protected function setHeader()
  5088. {
  5089. if ($this->print_header)
  5090. {
  5091. $this->setGraphicVars($this->default_graphic_vars);
  5092. $temp_thead = $this->thead;
  5093. $temp_theadMargins = $this->theadMargins;
  5094. $lasth = $this->lasth;
  5095. $this->_out('q');
  5096. $this->rMargin = $this->original_rMargin;
  5097. $this->lMargin = $this->original_lMargin;
  5098. $this->SetCellPadding(0);
  5099. //set current position
  5100. if ($this->rtl)
  5101. {
  5102. $this->SetXY($this->original_rMargin, $this->header_margin);
  5103. }
  5104. else
  5105. {
  5106. $this->SetXY($this->original_lMargin, $this->header_margin);
  5107. }
  5108. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  5109. $this->Header();
  5110. //restore position
  5111. if ($this->rtl)
  5112. {
  5113. $this->SetXY($this->original_rMargin, $this->tMargin);
  5114. }
  5115. else
  5116. {
  5117. $this->SetXY($this->original_lMargin, $this->tMargin);
  5118. }
  5119. $this->_out('Q');
  5120. $this->lasth = $lasth;
  5121. $this->thead = $temp_thead;
  5122. $this->theadMargins = $temp_theadMargins;
  5123. $this->newline = false;
  5124. }
  5125. }
  5126. /**
  5127. * This method is used to render the page footer.
  5128. * @access protected
  5129. * @since 4.0.012 (2008-07-24)
  5130. */
  5131. protected function setFooter()
  5132. {
  5133. //Page footer
  5134. // save current graphic settings
  5135. $gvars = $this->getGraphicVars();
  5136. // mark this point
  5137. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  5138. $this->_out("\n");
  5139. if ($this->print_footer)
  5140. {
  5141. $this->setGraphicVars($this->default_graphic_vars);
  5142. $this->current_column = 0;
  5143. $this->num_columns = 1;
  5144. $temp_thead = $this->thead;
  5145. $temp_theadMargins = $this->theadMargins;
  5146. $lasth = $this->lasth;
  5147. $this->_out('q');
  5148. $this->rMargin = $this->original_rMargin;
  5149. $this->lMargin = $this->original_lMargin;
  5150. $this->SetCellPadding(0);
  5151. //set current position
  5152. $footer_y = $this->h - $this->footer_margin;
  5153. if ($this->rtl)
  5154. {
  5155. $this->SetXY($this->original_rMargin, $footer_y);
  5156. }
  5157. else
  5158. {
  5159. $this->SetXY($this->original_lMargin, $footer_y);
  5160. }
  5161. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  5162. $this->Footer();
  5163. //restore position
  5164. if ($this->rtl)
  5165. {
  5166. $this->SetXY($this->original_rMargin, $this->tMargin);
  5167. }
  5168. else
  5169. {
  5170. $this->SetXY($this->original_lMargin, $this->tMargin);
  5171. }
  5172. $this->_out('Q');
  5173. $this->lasth = $lasth;
  5174. $this->thead = $temp_thead;
  5175. $this->theadMargins = $temp_theadMargins;
  5176. }
  5177. // restore graphic settings
  5178. $this->setGraphicVars($gvars);
  5179. $this->current_column = $gvars['current_column'];
  5180. $this->num_columns = $gvars['num_columns'];
  5181. // calculate footer length
  5182. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  5183. }
  5184. /**
  5185. * This method is used to render the table header on new page (if any).
  5186. * @access protected
  5187. * @since 4.5.030 (2009-03-25)
  5188. */
  5189. protected function setTableHeader()
  5190. {
  5191. if ($this->num_columns > 1)
  5192. {
  5193. // multi column mode
  5194. return;
  5195. }
  5196. if (isset($this->theadMargins['top']))
  5197. {
  5198. // restore the original top-margin
  5199. $this->tMargin = $this->theadMargins['top'];
  5200. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  5201. $this->y = $this->tMargin;
  5202. }
  5203. if (! $this->empty_string($this->thead) and (! $this->inthead))
  5204. {
  5205. // set margins
  5206. $prev_lMargin = $this->lMargin;
  5207. $prev_rMargin = $this->rMargin;
  5208. $prev_cell_padding = $this->cell_padding;
  5209. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  5210. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  5211. $this->cell_padding = $this->theadMargins['cell_padding'];
  5212. if ($this->rtl)
  5213. {
  5214. $this->x = $this->w - $this->rMargin;
  5215. }
  5216. else
  5217. {
  5218. $this->x = $this->lMargin;
  5219. }
  5220. // print table header
  5221. $this->writeHTML($this->thead, false, false, false, false, '');
  5222. // set new top margin to skip the table headers
  5223. if (! isset($this->theadMargins['top']))
  5224. {
  5225. $this->theadMargins['top'] = $this->tMargin;
  5226. }
  5227. $this->tMargin = $this->y;
  5228. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  5229. $this->lasth = 0;
  5230. $this->lMargin = $prev_lMargin;
  5231. $this->rMargin = $prev_rMargin;
  5232. $this->cell_padding = $prev_cell_padding;
  5233. }
  5234. }
  5235. /**
  5236. * Returns the current page number.
  5237. * @return int page number
  5238. * @access public
  5239. * @since 1.0
  5240. * @see AliasNbPages(), getAliasNbPages()
  5241. */
  5242. public function PageNo()
  5243. {
  5244. return $this->page;
  5245. }
  5246. /**
  5247. * Defines a new spot color.
  5248. * It can be expressed in RGB components or gray scale.
  5249. * The method can be called before the first page is created and the value is retained from page to page.
  5250. * @param int $c Cyan color for CMYK. Value between 0 and 255
  5251. * @param int $m Magenta color for CMYK. Value between 0 and 255
  5252. * @param int $y Yellow color for CMYK. Value between 0 and 255
  5253. * @param int $k Key (Black) color for CMYK. Value between 0 and 255
  5254. * @access public
  5255. * @since 4.0.024 (2008-09-12)
  5256. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  5257. */
  5258. public function AddSpotColor($name, $c, $m, $y, $k)
  5259. {
  5260. if (! isset($this->spot_colors[$name]))
  5261. {
  5262. $i = 1 + count($this->spot_colors);
  5263. $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
  5264. }
  5265. }
  5266. /**
  5267. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  5268. * It can be expressed in RGB components or gray scale.
  5269. * The method can be called before the first page is created and the value is retained from page to page.
  5270. * @param array $color array of colors
  5271. * @param boolean $ret if true do not send the command.
  5272. * @return string the PDF command
  5273. * @access public
  5274. * @since 3.1.000 (2008-06-11)
  5275. * @see SetDrawColor()
  5276. */
  5277. public function SetDrawColorArray($color, $ret = false)
  5278. {
  5279. if (is_array($color))
  5280. {
  5281. $color = array_values($color);
  5282. $r = isset($color[0]) ? $color[0] : - 1;
  5283. $g = isset($color[1]) ? $color[1] : - 1;
  5284. $b = isset($color[2]) ? $color[2] : - 1;
  5285. $k = isset($color[3]) ? $color[3] : - 1;
  5286. if ($r >= 0)
  5287. {
  5288. return $this->SetDrawColor($r, $g, $b, $k, $ret);
  5289. }
  5290. }
  5291. return '';
  5292. }
  5293. /**
  5294. * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  5295. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  5296. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  5297. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  5298. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  5299. * @param boolean $ret if true do not send the command.
  5300. * @return string the PDF command
  5301. * @access public
  5302. * @since 1.3
  5303. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  5304. */
  5305. public function SetDrawColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false)
  5306. {
  5307. // set default values
  5308. if (! is_numeric($col1))
  5309. {
  5310. $col1 = 0;
  5311. }
  5312. if (! is_numeric($col2))
  5313. {
  5314. $col2 = - 1;
  5315. }
  5316. if (! is_numeric($col3))
  5317. {
  5318. $col3 = - 1;
  5319. }
  5320. if (! is_numeric($col4))
  5321. {
  5322. $col4 = - 1;
  5323. }
  5324. //Set color for all stroking operations
  5325. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  5326. {
  5327. // Grey scale
  5328. $this->DrawColor = sprintf('%.3F G', $col1 / 255);
  5329. $this->strokecolor = array('G' => $col1);
  5330. }
  5331. elseif ($col4 == - 1)
  5332. {
  5333. // RGB
  5334. $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $col1 / 255, $col2 / 255, $col3 / 255);
  5335. $this->strokecolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  5336. }
  5337. else
  5338. {
  5339. // CMYK
  5340. $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  5341. $this->strokecolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  5342. }
  5343. if ($this->page > 0)
  5344. {
  5345. if (! $ret)
  5346. {
  5347. $this->_out($this->DrawColor);
  5348. }
  5349. return $this->DrawColor;
  5350. }
  5351. return '';
  5352. }
  5353. /**
  5354. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  5355. * @param string $name name of the spot color
  5356. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5357. * @access public
  5358. * @since 4.0.024 (2008-09-12)
  5359. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  5360. */
  5361. public function SetDrawSpotColor($name, $tint = 100)
  5362. {
  5363. if (! isset($this->spot_colors[$name]))
  5364. {
  5365. $this->Error('Undefined spot color: ' . $name);
  5366. }
  5367. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], $tint / 100);
  5368. if ($this->page > 0)
  5369. {
  5370. $this->_out($this->DrawColor);
  5371. }
  5372. }
  5373. /**
  5374. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  5375. * It can be expressed in RGB components or gray scale.
  5376. * The method can be called before the first page is created and the value is retained from page to page.
  5377. * @param array $color array of colors
  5378. * @access public
  5379. * @since 3.1.000 (2008-6-11)
  5380. * @see SetFillColor()
  5381. */
  5382. public function SetFillColorArray($color)
  5383. {
  5384. if (is_array($color))
  5385. {
  5386. $color = array_values($color);
  5387. $r = isset($color[0]) ? $color[0] : - 1;
  5388. $g = isset($color[1]) ? $color[1] : - 1;
  5389. $b = isset($color[2]) ? $color[2] : - 1;
  5390. $k = isset($color[3]) ? $color[3] : - 1;
  5391. if ($r >= 0)
  5392. {
  5393. $this->SetFillColor($r, $g, $b, $k);
  5394. }
  5395. }
  5396. }
  5397. /**
  5398. * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  5399. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  5400. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  5401. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  5402. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  5403. * @access public
  5404. * @since 1.3
  5405. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  5406. */
  5407. public function SetFillColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1)
  5408. {
  5409. // set default values
  5410. if (! is_numeric($col1))
  5411. {
  5412. $col1 = 0;
  5413. }
  5414. if (! is_numeric($col2))
  5415. {
  5416. $col2 = - 1;
  5417. }
  5418. if (! is_numeric($col3))
  5419. {
  5420. $col3 = - 1;
  5421. }
  5422. if (! is_numeric($col4))
  5423. {
  5424. $col4 = - 1;
  5425. }
  5426. //Set color for all filling operations
  5427. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  5428. {
  5429. // Grey scale
  5430. $this->FillColor = sprintf('%.3F g', $col1 / 255);
  5431. $this->bgcolor = array('G' => $col1);
  5432. }
  5433. elseif ($col4 == - 1)
  5434. {
  5435. // RGB
  5436. $this->FillColor = sprintf('%.3F %.3F %.3F rg', $col1 / 255, $col2 / 255, $col3 / 255);
  5437. $this->bgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  5438. }
  5439. else
  5440. {
  5441. // CMYK
  5442. $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  5443. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  5444. }
  5445. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5446. if ($this->page > 0)
  5447. {
  5448. $this->_out($this->FillColor);
  5449. }
  5450. }
  5451. /**
  5452. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  5453. * @param string $name name of the spot color
  5454. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5455. * @access public
  5456. * @since 4.0.024 (2008-09-12)
  5457. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  5458. */
  5459. public function SetFillSpotColor($name, $tint = 100)
  5460. {
  5461. if (! isset($this->spot_colors[$name]))
  5462. {
  5463. $this->Error('Undefined spot color: ' . $name);
  5464. }
  5465. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint / 100);
  5466. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5467. if ($this->page > 0)
  5468. {
  5469. $this->_out($this->FillColor);
  5470. }
  5471. }
  5472. /**
  5473. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  5474. * The method can be called before the first page is created and the value is retained from page to page.
  5475. * @param array $color array of colors
  5476. * @access public
  5477. * @since 3.1.000 (2008-6-11)
  5478. * @see SetFillColor()
  5479. */
  5480. public function SetTextColorArray($color)
  5481. {
  5482. if (is_array($color))
  5483. {
  5484. $color = array_values($color);
  5485. $r = isset($color[0]) ? $color[0] : - 1;
  5486. $g = isset($color[1]) ? $color[1] : - 1;
  5487. $b = isset($color[2]) ? $color[2] : - 1;
  5488. $k = isset($color[3]) ? $color[3] : - 1;
  5489. if ($r >= 0)
  5490. {
  5491. $this->SetTextColor($r, $g, $b, $k);
  5492. }
  5493. }
  5494. }
  5495. /**
  5496. * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  5497. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  5498. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  5499. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  5500. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  5501. * @access public
  5502. * @since 1.3
  5503. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  5504. */
  5505. public function SetTextColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1)
  5506. {
  5507. // set default values
  5508. if (! is_numeric($col1))
  5509. {
  5510. $col1 = 0;
  5511. }
  5512. if (! is_numeric($col2))
  5513. {
  5514. $col2 = - 1;
  5515. }
  5516. if (! is_numeric($col3))
  5517. {
  5518. $col3 = - 1;
  5519. }
  5520. if (! is_numeric($col4))
  5521. {
  5522. $col4 = - 1;
  5523. }
  5524. //Set color for text
  5525. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  5526. {
  5527. // Grey scale
  5528. $this->TextColor = sprintf('%.3F g', $col1 / 255);
  5529. $this->fgcolor = array('G' => $col1);
  5530. }
  5531. elseif ($col4 == - 1)
  5532. {
  5533. // RGB
  5534. $this->TextColor = sprintf('%.3F %.3F %.3F rg', $col1 / 255, $col2 / 255, $col3 / 255);
  5535. $this->fgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  5536. }
  5537. else
  5538. {
  5539. // CMYK
  5540. $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  5541. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  5542. }
  5543. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5544. }
  5545. /**
  5546. * Defines the spot color used for text.
  5547. * @param string $name name of the spot color
  5548. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5549. * @access public
  5550. * @since 4.0.024 (2008-09-12)
  5551. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  5552. */
  5553. public function SetTextSpotColor($name, $tint = 100)
  5554. {
  5555. if (! isset($this->spot_colors[$name]))
  5556. {
  5557. $this->Error('Undefined spot color: ' . $name);
  5558. }
  5559. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint / 100);
  5560. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5561. if ($this->page > 0)
  5562. {
  5563. $this->_out($this->TextColor);
  5564. }
  5565. }
  5566. /**
  5567. * Returns the length of a string in user unit. A font must be selected.<br>
  5568. * @param string $s The string whose length is to be computed
  5569. * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  5570. * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line-trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  5571. * @param float $fontsize Font size in points. The default value is the current size.
  5572. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  5573. * @return mixed int total string length or array of characted widths
  5574. * @author Nicola Asuni
  5575. * @access public
  5576. * @since 1.2
  5577. */
  5578. public function GetStringWidth($s, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  5579. {
  5580. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  5581. }
  5582. /**
  5583. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  5584. * @param string $sa The array of chars whose total length is to be computed
  5585. * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  5586. * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  5587. * @param float $fontsize Font size in points. The default value is the current size.
  5588. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  5589. * @return mixed int total string length or array of characted widths
  5590. * @author Nicola Asuni
  5591. * @access public
  5592. * @since 2.4.000 (2008-03-06)
  5593. */
  5594. public function GetArrStringWidth($sa, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  5595. {
  5596. // store current values
  5597. if (! $this->empty_string($fontname))
  5598. {
  5599. $prev_FontFamily = $this->FontFamily;
  5600. $prev_FontStyle = $this->FontStyle;
  5601. $prev_FontSizePt = $this->FontSizePt;
  5602. $this->SetFont($fontname, $fontstyle, $fontsize);
  5603. }
  5604. // convert UTF-8 array to Latin1 if required
  5605. $sa = $this->UTF8ArrToLatin1($sa);
  5606. $w = 0; // total width
  5607. $wa = array(); // array of characters widths
  5608. foreach ($sa as $ck => $char)
  5609. {
  5610. // character width
  5611. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  5612. $wa[] = $cw;
  5613. $w += $cw;
  5614. }
  5615. // restore previous values
  5616. if (! $this->empty_string($fontname))
  5617. {
  5618. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
  5619. }
  5620. if ($getarray)
  5621. {
  5622. return $wa;
  5623. }
  5624. return $w;
  5625. }
  5626. /**
  5627. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking/kerning).
  5628. * @param int $char The char code whose length is to be returned
  5629. * @param boolean $notlast set to false for the latest character on string, true otherwise (default)
  5630. * @return float char width
  5631. * @author Nicola Asuni
  5632. * @access public
  5633. * @since 2.4.000 (2008-03-06)
  5634. */
  5635. public function GetCharWidth($char, $notlast = true)
  5636. {
  5637. // get raw width
  5638. $chw = $this->getRawCharWidth($char);
  5639. if (($this->font_spacing != 0) and $notlast)
  5640. {
  5641. // increase/decrease font spacing
  5642. $chw += $this->font_spacing;
  5643. }
  5644. if ($this->font_stretching != 100)
  5645. {
  5646. // fixed stretching mode
  5647. $chw *= ($this->font_stretching / 100);
  5648. }
  5649. return $chw;
  5650. }
  5651. /**
  5652. * Returns the length of the char in user unit for the current font.
  5653. * @param int $char The char code whose length is to be returned
  5654. * @return float char width
  5655. * @author Nicola Asuni
  5656. * @access public
  5657. * @since 5.9.000 (2010-09-28)
  5658. */
  5659. public function getRawCharWidth($char)
  5660. {
  5661. if ($char == 173)
  5662. {
  5663. // SHY character will not be printed
  5664. return (0);
  5665. }
  5666. $cw = &$this->CurrentFont['cw'];
  5667. if (isset($cw[$char]))
  5668. {
  5669. $w = $cw[$char];
  5670. }
  5671. elseif (isset($this->CurrentFont['dw']))
  5672. {
  5673. // default width
  5674. $w = $this->CurrentFont['dw'];
  5675. }
  5676. elseif (isset($cw[32]))
  5677. {
  5678. // default width
  5679. $w = $cw[32];
  5680. }
  5681. else
  5682. {
  5683. $w = 600;
  5684. }
  5685. return ($w * $this->FontSize / 1000);
  5686. }
  5687. /**
  5688. * Returns the numbero of characters in a string.
  5689. * @param string $s The input string.
  5690. * @return int number of characters
  5691. * @access public
  5692. * @since 2.0.0001 (2008-01-07)
  5693. */
  5694. public function GetNumChars($s)
  5695. {
  5696. if ($this->isUnicodeFont())
  5697. {
  5698. return count($this->UTF8StringToArray($s));
  5699. }
  5700. return strlen($s);
  5701. }
  5702. /**
  5703. * Fill the list of available fonts ($this->fontlist).
  5704. * @access protected
  5705. * @since 4.0.013 (2008-07-28)
  5706. */
  5707. protected function getFontsList()
  5708. {
  5709. $fontsdir = opendir($this->_getfontpath());
  5710. while (($file = readdir($fontsdir)) !== false)
  5711. {
  5712. if (substr($file, - 4) == '.php')
  5713. {
  5714. array_push($this->fontlist, strtolower(basename($file, '.php')));
  5715. }
  5716. }
  5717. closedir($fontsdir);
  5718. }
  5719. /**
  5720. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  5721. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  5722. * The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
  5723. * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  5724. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  5725. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  5726. * @return array containing the font data, or false in case of error.
  5727. * @param mixed $subset if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  5728. * @access public
  5729. * @since 1.5
  5730. * @see SetFont(), setFontSubsetting()
  5731. */
  5732. public function AddFont($family, $style = '', $fontfile = '', $subset = 'default')
  5733. {
  5734. if ($subset === 'default')
  5735. {
  5736. $subset = $this->font_subsetting;
  5737. }
  5738. if ($this->empty_string($family))
  5739. {
  5740. if (! $this->empty_string($this->FontFamily))
  5741. {
  5742. $family = $this->FontFamily;
  5743. }
  5744. else
  5745. {
  5746. $this->Error('Empty font family');
  5747. }
  5748. }
  5749. // move embedded styles on $style
  5750. if (substr($family, - 1) == 'I')
  5751. {
  5752. $style .= 'I';
  5753. $family = substr($family, 0, - 1);
  5754. }
  5755. if (substr($family, - 1) == 'B')
  5756. {
  5757. $style .= 'B';
  5758. $family = substr($family, 0, - 1);
  5759. }
  5760. // normalize family name
  5761. $family = strtolower($family);
  5762. if ((! $this->isunicode) and ($family == 'arial'))
  5763. {
  5764. $family = 'helvetica';
  5765. }
  5766. if (($family == 'symbol') or ($family == 'zapfdingbats'))
  5767. {
  5768. $style = '';
  5769. }
  5770. $tempstyle = strtoupper($style);
  5771. $style = '';
  5772. // underline
  5773. if (strpos($tempstyle, 'U') !== false)
  5774. {
  5775. $this->underline = true;
  5776. }
  5777. else
  5778. {
  5779. $this->underline = false;
  5780. }
  5781. // line-through (deleted)
  5782. if (strpos($tempstyle, 'D') !== false)
  5783. {
  5784. $this->linethrough = true;
  5785. }
  5786. else
  5787. {
  5788. $this->linethrough = false;
  5789. }
  5790. // overline
  5791. if (strpos($tempstyle, 'O') !== false)
  5792. {
  5793. $this->overline = true;
  5794. }
  5795. else
  5796. {
  5797. $this->overline = false;
  5798. }
  5799. // bold
  5800. if (strpos($tempstyle, 'B') !== false)
  5801. {
  5802. $style .= 'B';
  5803. }
  5804. // oblique
  5805. if (strpos($tempstyle, 'I') !== false)
  5806. {
  5807. $style .= 'I';
  5808. }
  5809. $bistyle = $style;
  5810. $fontkey = $family . $style;
  5811. $font_style = $style . ($this->underline ? 'U' : '') . ($this->linethrough ? 'D' : '') . ($this->overline ? 'O' : '');
  5812. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  5813. // check if the font has been already added
  5814. $fb = $this->getFontBuffer($fontkey);
  5815. if ($fb !== false)
  5816. {
  5817. if ($this->inxobj)
  5818. {
  5819. // we are inside an XObject template
  5820. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  5821. }
  5822. return $fontdata;
  5823. }
  5824. if (isset($type))
  5825. {
  5826. unset($type);
  5827. }
  5828. if (isset($cw))
  5829. {
  5830. unset($cw);
  5831. }
  5832. // get specified font directory (if any)
  5833. $fontdir = false;
  5834. if (! $this->empty_string($fontfile))
  5835. {
  5836. $fontdir = dirname($fontfile);
  5837. if ($this->empty_string($fontdir) or ($fontdir == '.'))
  5838. {
  5839. $fontdir = '';
  5840. }
  5841. else
  5842. {
  5843. $fontdir .= '/';
  5844. }
  5845. }
  5846. // search and include font file
  5847. if ($this->empty_string($fontfile) or (! file_exists($fontfile)))
  5848. {
  5849. // build a standard filenames for specified font
  5850. $fontfile1 = str_replace(' ', '', $family) . strtolower($style) . '.php';
  5851. $fontfile2 = str_replace(' ', '', $family) . '.php';
  5852. // search files on various directories
  5853. if (($fontdir !== false) and file_exists($fontdir . $fontfile1))
  5854. {
  5855. $fontfile = $fontdir . $fontfile1;
  5856. }
  5857. elseif (file_exists($this->_getfontpath() . $fontfile1))
  5858. {
  5859. $fontfile = $this->_getfontpath() . $fontfile1;
  5860. }
  5861. elseif (file_exists($fontfile1))
  5862. {
  5863. $fontfile = $fontfile1;
  5864. }
  5865. elseif (($fontdir !== false) and file_exists($fontdir . $fontfile2))
  5866. {
  5867. $fontfile = $fontdir . $fontfile2;
  5868. }
  5869. elseif (file_exists($this->_getfontpath() . $fontfile2))
  5870. {
  5871. $fontfile = $this->_getfontpath() . $fontfile2;
  5872. }
  5873. else
  5874. {
  5875. $fontfile = $fontfile2;
  5876. }
  5877. }
  5878. // include font file
  5879. if (file_exists($fontfile))
  5880. {
  5881. include ($fontfile);
  5882. }
  5883. else
  5884. {
  5885. $this->Error('Could not include font definition file: ' . $family . '');
  5886. }
  5887. // check font parameters
  5888. if ((! isset($type)) or (! isset($cw)))
  5889. {
  5890. $this->Error('The font definition file has a bad format: ' . $fontfile . '');
  5891. }
  5892. // SET default parameters
  5893. if (! isset($file) or $this->empty_string($file))
  5894. {
  5895. $file = '';
  5896. }
  5897. if (! isset($enc) or $this->empty_string($enc))
  5898. {
  5899. $enc = '';
  5900. }
  5901. if (! isset($cidinfo) or $this->empty_string($cidinfo))
  5902. {
  5903. $cidinfo = array('Registry' => 'Adobe', 'Ordering' => 'Identity', 'Supplement' => 0);
  5904. $cidinfo['uni2cid'] = array();
  5905. }
  5906. if (! isset($ctg) or $this->empty_string($ctg))
  5907. {
  5908. $ctg = '';
  5909. }
  5910. if (! isset($desc) or $this->empty_string($desc))
  5911. {
  5912. $desc = array();
  5913. }
  5914. if (! isset($up) or $this->empty_string($up))
  5915. {
  5916. $up = - 100;
  5917. }
  5918. if (! isset($ut) or $this->empty_string($ut))
  5919. {
  5920. $ut = 50;
  5921. }
  5922. if (! isset($cw) or $this->empty_string($cw))
  5923. {
  5924. $cw = array();
  5925. }
  5926. if (! isset($dw) or $this->empty_string($dw))
  5927. {
  5928. // set default width
  5929. if (isset($desc['MissingWidth']) and ($desc['MissingWidth'] > 0))
  5930. {
  5931. $dw = $desc['MissingWidth'];
  5932. }
  5933. elseif (isset($cw[32]))
  5934. {
  5935. $dw = $cw[32];
  5936. }
  5937. else
  5938. {
  5939. $dw = 600;
  5940. }
  5941. }
  5942. ++ $this->numfonts;
  5943. if ($type == 'cidfont0')
  5944. {
  5945. // register CID font (all styles at once)
  5946. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  5947. $sname = $name . $styles[$bistyle];
  5948. // artificial bold
  5949. if (strpos($bistyle, 'B') !== false)
  5950. {
  5951. if (isset($desc['StemV']))
  5952. {
  5953. $desc['StemV'] *= 2;
  5954. }
  5955. else
  5956. {
  5957. $desc['StemV'] = 120;
  5958. }
  5959. }
  5960. // artificial italic
  5961. if (strpos($bistyle, 'I') !== false)
  5962. {
  5963. if (isset($desc['ItalicAngle']))
  5964. {
  5965. $desc['ItalicAngle'] -= 11;
  5966. }
  5967. else
  5968. {
  5969. $desc['ItalicAngle'] = - 11;
  5970. }
  5971. }
  5972. }
  5973. elseif ($type == 'core')
  5974. {
  5975. $name = $this->CoreFonts[$fontkey];
  5976. $subset = false;
  5977. }
  5978. elseif (($type == 'TrueType') or ($type == 'Type1'))
  5979. {
  5980. $subset = false;
  5981. }
  5982. elseif ($type == 'TrueTypeUnicode')
  5983. {
  5984. $enc = 'Identity-H';
  5985. }
  5986. else
  5987. {
  5988. $this->Error('Unknow font type: ' . $type . '');
  5989. }
  5990. // initialize subsetchars to contain default ASCII values (0-255)
  5991. $subsetchars = array_fill(0, 256, true);
  5992. $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type,
  5993. 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc,
  5994. 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset,
  5995. 'subsetchars' => $subsetchars));
  5996. if ($this->inxobj)
  5997. {
  5998. // we are inside an XObject template
  5999. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  6000. }
  6001. if (isset($diff) and (! empty($diff)))
  6002. {
  6003. //Search existing encodings
  6004. $d = 0;
  6005. $nb = count($this->diffs);
  6006. for($i = 1; $i <= $nb; ++ $i)
  6007. {
  6008. if ($this->diffs[$i] == $diff)
  6009. {
  6010. $d = $i;
  6011. break;
  6012. }
  6013. }
  6014. if ($d == 0)
  6015. {
  6016. $d = $nb + 1;
  6017. $this->diffs[$d] = $diff;
  6018. }
  6019. $this->setFontSubBuffer($fontkey, 'diff', $d);
  6020. }
  6021. if (! $this->empty_string($file))
  6022. {
  6023. if (! isset($this->FontFiles[$file]))
  6024. {
  6025. if ((strcasecmp($type, 'TrueType') == 0) or (strcasecmp($type, 'TrueTypeUnicode') == 0))
  6026. {
  6027. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir,
  6028. 'subset' => $subset, 'fontkeys' => array($fontkey));
  6029. }
  6030. elseif ($type != 'core')
  6031. {
  6032. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir,
  6033. 'subset' => $subset, 'fontkeys' => array($fontkey));
  6034. }
  6035. }
  6036. else
  6037. {
  6038. // update fontkeys that are sharing this font file
  6039. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] and $subset);
  6040. if (! in_array($fontkey, $this->FontFiles[$file]['fontkeys']))
  6041. {
  6042. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  6043. }
  6044. }
  6045. }
  6046. return $fontdata;
  6047. }
  6048. /**
  6049. * Sets the font used to print character strings.
  6050. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  6051. * The method can be called before the first page is created and the font is retained from page to page.
  6052. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  6053. * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the K_PATH_FONTS constant</li></ul><br />
  6054. * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
  6055. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li><li>O: overline</li></ul> or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
  6056. * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
  6057. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  6058. * @param mixed $subset if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  6059. * @author Nicola Asuni
  6060. * @access public
  6061. * @since 1.0
  6062. * @see AddFont(), SetFontSize()
  6063. */
  6064. public function SetFont($family, $style = '', $size = 0, $fontfile = '', $subset = 'default')
  6065. {
  6066. //Select a font; size given in points
  6067. if ($size == 0)
  6068. {
  6069. $size = $this->FontSizePt;
  6070. }
  6071. // try to add font (if not already added)
  6072. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  6073. $this->FontFamily = $fontdata['family'];
  6074. $this->FontStyle = $fontdata['style'];
  6075. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  6076. $this->SetFontSize($size);
  6077. }
  6078. /**
  6079. * Defines the size of the current font.
  6080. * @param float $size The size (in points)
  6081. * @param boolean $out if true output the font size command, otherwise only set the font properties.
  6082. * @access public
  6083. * @since 1.0
  6084. * @see SetFont()
  6085. */
  6086. public function SetFontSize($size, $out = true)
  6087. {
  6088. // font size in points
  6089. $this->FontSizePt = $size;
  6090. // font size in user units
  6091. $this->FontSize = $size / $this->k;
  6092. // calculate some font metrics
  6093. if (isset($this->CurrentFont['desc']['FontBBox']))
  6094. {
  6095. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, - 1));
  6096. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  6097. }
  6098. else
  6099. {
  6100. $font_height = $size * 1.219;
  6101. }
  6102. if (isset($this->CurrentFont['desc']['Ascent']) and ($this->CurrentFont['desc']['Ascent'] > 0))
  6103. {
  6104. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  6105. }
  6106. if (isset($this->CurrentFont['desc']['Descent']) and ($this->CurrentFont['desc']['Descent'] <= 0))
  6107. {
  6108. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  6109. }
  6110. if (! isset($font_ascent) and ! isset($font_descent))
  6111. {
  6112. // core font
  6113. $font_ascent = 0.76 * $font_height;
  6114. $font_descent = $font_height - $font_ascent;
  6115. }
  6116. elseif (! isset($font_descent))
  6117. {
  6118. $font_descent = $font_height - $font_ascent;
  6119. }
  6120. elseif (! isset($font_ascent))
  6121. {
  6122. $font_ascent = $font_height - $font_descent;
  6123. }
  6124. $this->FontAscent = $font_ascent / $this->k;
  6125. $this->FontDescent = $font_descent / $this->k;
  6126. if ($out and ($this->page > 0) and (isset($this->CurrentFont['i'])))
  6127. {
  6128. $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  6129. }
  6130. }
  6131. /**
  6132. * Return the font descent value
  6133. * @param string $font font name
  6134. * @param string $style font style
  6135. * @param float $size The size (in points)
  6136. * @return int font descent
  6137. * @access public
  6138. * @author Nicola Asuni
  6139. * @since 4.9.003 (2010-03-30)
  6140. */
  6141. public function getFontDescent($font, $style = '', $size = 0)
  6142. {
  6143. $fontdata = $this->AddFont($font, $style);
  6144. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  6145. if (isset($fontinfo['desc']['Descent']) and ($fontinfo['desc']['Descent'] <= 0))
  6146. {
  6147. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  6148. }
  6149. else
  6150. {
  6151. $descent = 1.219 * 0.24 * $size;
  6152. }
  6153. return ($descent / $this->k);
  6154. }
  6155. /**
  6156. * Return the font ascent value
  6157. * @param string $font font name
  6158. * @param string $style font style
  6159. * @param float $size The size (in points)
  6160. * @return int font ascent
  6161. * @access public
  6162. * @author Nicola Asuni
  6163. * @since 4.9.003 (2010-03-30)
  6164. */
  6165. public function getFontAscent($font, $style = '', $size = 0)
  6166. {
  6167. $fontdata = $this->AddFont($font, $style);
  6168. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  6169. if (isset($fontinfo['desc']['Ascent']) and ($fontinfo['desc']['Ascent'] > 0))
  6170. {
  6171. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  6172. }
  6173. else
  6174. {
  6175. $ascent = 1.219 * 0.76 * $size;
  6176. }
  6177. return ($ascent / $this->k);
  6178. }
  6179. /**
  6180. * Defines the default monospaced font.
  6181. * @param string $font Font name.
  6182. * @access public
  6183. * @since 4.5.025
  6184. */
  6185. public function SetDefaultMonospacedFont($font)
  6186. {
  6187. $this->default_monospaced_font = $font;
  6188. }
  6189. /**
  6190. * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
  6191. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  6192. * @access public
  6193. * @since 1.5
  6194. * @see Cell(), Write(), Image(), Link(), SetLink()
  6195. */
  6196. public function AddLink()
  6197. {
  6198. //Create a new internal link
  6199. $n = count($this->links) + 1;
  6200. $this->links[$n] = array(0, 0);
  6201. return $n;
  6202. }
  6203. /**
  6204. * Defines the page and position a link points to.
  6205. * @param int $link The link identifier returned by AddLink()
  6206. * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  6207. * @param int $page Number of target page; -1 indicates the current page. This is the default value
  6208. * @access public
  6209. * @since 1.5
  6210. * @see AddLink()
  6211. */
  6212. public function SetLink($link, $y = 0, $page = -1)
  6213. {
  6214. if ($y == - 1)
  6215. {
  6216. $y = $this->y;
  6217. }
  6218. if ($page == - 1)
  6219. {
  6220. $page = $this->page;
  6221. }
  6222. $this->links[$link] = array($page, $y);
  6223. }
  6224. /**
  6225. * Puts a link on a rectangular area of the page.
  6226. * Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.
  6227. * @param float $x Abscissa of the upper-left corner of the rectangle
  6228. * @param float $y Ordinate of the upper-left corner of the rectangle
  6229. * @param float $w Width of the rectangle
  6230. * @param float $h Height of the rectangle
  6231. * @param mixed $link URL or identifier returned by AddLink()
  6232. * @param int $spaces number of spaces on the text to link
  6233. * @access public
  6234. * @since 1.5
  6235. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  6236. */
  6237. public function Link($x, $y, $w, $h, $link, $spaces = 0)
  6238. {
  6239. $this->Annotation($x, $y, $w, $h, $link, array('Subtype' => 'Link'), $spaces);
  6240. }
  6241. /**
  6242. * Puts a markup annotation on a rectangular area of the page.
  6243. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  6244. * @param float $x Abscissa of the upper-left corner of the rectangle
  6245. * @param float $y Ordinate of the upper-left corner of the rectangle
  6246. * @param float $w Width of the rectangle
  6247. * @param float $h Height of the rectangle
  6248. * @param string $text annotation text or alternate content
  6249. * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  6250. * @param int $spaces number of spaces on the text to link
  6251. * @access public
  6252. * @since 4.0.018 (2008-08-06)
  6253. */
  6254. public function Annotation($x, $y, $w, $h, $text, $opt = array('Subtype'=>'Text'), $spaces = 0)
  6255. {
  6256. if ($this->inxobj)
  6257. {
  6258. // store parameters for later use on template
  6259. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w,
  6260. 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  6261. return;
  6262. }
  6263. if ($x === '')
  6264. {
  6265. $x = $this->x;
  6266. }
  6267. if ($y === '')
  6268. {
  6269. $y = $this->y;
  6270. }
  6271. // check page for no-write regions and adapt page margins if necessary
  6272. $this->checkPageRegions($h, $x, $y);
  6273. // recalculate coordinates to account for graphic transformations
  6274. if (isset($this->transfmatrix) and ! empty($this->transfmatrix))
  6275. {
  6276. for($i = $this->transfmatrix_key; $i > 0; -- $i)
  6277. {
  6278. $maxid = count($this->transfmatrix[$i]) - 1;
  6279. for($j = $maxid; $j >= 0; -- $j)
  6280. {
  6281. $ctm = $this->transfmatrix[$i][$j];
  6282. if (isset($ctm['a']))
  6283. {
  6284. $x = $x * $this->k;
  6285. $y = ($this->h - $y) * $this->k;
  6286. $w = $w * $this->k;
  6287. $h = $h * $this->k;
  6288. // top left
  6289. $xt = $x;
  6290. $yt = $y;
  6291. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6292. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6293. // top right
  6294. $xt = $x + $w;
  6295. $yt = $y;
  6296. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6297. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6298. // bottom left
  6299. $xt = $x;
  6300. $yt = $y - $h;
  6301. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6302. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6303. // bottom right
  6304. $xt = $x + $w;
  6305. $yt = $y - $h;
  6306. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6307. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6308. // new coordinates (rectangle area)
  6309. $x = min($x1, $x2, $x3, $x4);
  6310. $y = max($y1, $y2, $y3, $y4);
  6311. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  6312. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  6313. $x = $x / $this->k;
  6314. $y = $this->h - ($y / $this->k);
  6315. }
  6316. }
  6317. }
  6318. }
  6319. if ($this->page <= 0)
  6320. {
  6321. $page = 1;
  6322. }
  6323. else
  6324. {
  6325. $page = $this->page;
  6326. }
  6327. if (! isset($this->PageAnnots[$page]))
  6328. {
  6329. $this->PageAnnots[$page] = array();
  6330. }
  6331. ++ $this->n;
  6332. $this->PageAnnots[$page][] = array('n' => $this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text,
  6333. 'opt' => $opt, 'numspaces' => $spaces);
  6334. if ((($opt['Subtype'] == 'FileAttachment') or ($opt['Subtype'] == 'Sound')) and (! $this->empty_string($opt['FS'])) and file_exists($opt['FS']) and (! isset($this->embeddedfiles[basename($opt['FS'])])))
  6335. {
  6336. ++ $this->n;
  6337. $this->embeddedfiles[basename($opt['FS'])] = array('n' => $this->n, 'file' => $opt['FS']);
  6338. }
  6339. // Add widgets annotation's icons
  6340. if (isset($opt['mk']['i']) and file_exists($opt['mk']['i']))
  6341. {
  6342. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  6343. }
  6344. if (isset($opt['mk']['ri']) and file_exists($opt['mk']['ri']))
  6345. {
  6346. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  6347. }
  6348. if (isset($opt['mk']['ix']) and file_exists($opt['mk']['ix']))
  6349. {
  6350. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  6351. }
  6352. }
  6353. /**
  6354. * Embedd the attached files.
  6355. * @since 4.4.000 (2008-12-07)
  6356. * @access protected
  6357. * @see Annotation()
  6358. */
  6359. protected function _putEmbeddedFiles()
  6360. {
  6361. reset($this->embeddedfiles);
  6362. foreach ($this->embeddedfiles as $filename => $filedata)
  6363. {
  6364. $data = file_get_contents($filedata['file']);
  6365. $filter = '';
  6366. if ($this->compress)
  6367. {
  6368. $data = gzcompress($data);
  6369. $filter = ' /Filter /FlateDecode';
  6370. }
  6371. $stream = $this->_getrawstream($data, $filedata['n']);
  6372. $out = $this->_getobj($filedata['n']) . "\n";
  6373. $out .= '<< /Type /EmbeddedFile' . $filter . ' /Length ' . strlen($stream) . ' >>';
  6374. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  6375. $out .= "\n" . 'endobj';
  6376. $this->_out($out);
  6377. }
  6378. }
  6379. /**
  6380. * Prints a text cell at the specified position.
  6381. * The origin is on the left of the first charcter, on the baseline.
  6382. * This method allows to place a string precisely on the page.
  6383. * @param float $x Abscissa of the cell origin
  6384. * @param float $y Ordinate of the cell origin
  6385. * @param string $txt String to print
  6386. * @param int $fstroke outline size in user units (false = disable)
  6387. * @param boolean $fclip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  6388. * @param boolean $ffill if true fills the text
  6389. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6390. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6391. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6392. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  6393. * @param mixed $link URL or identifier returned by AddLink().
  6394. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6395. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  6396. * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li><li>B : cell bottom</li></ul>
  6397. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  6398. * @param boolean $rtloff if true uses the page top-left corner as origin of axis for $x and $y initial position.
  6399. * @access public
  6400. * @since 1.0
  6401. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  6402. */
  6403. public function Text($x, $y, $txt, $fstroke = false, $fclip = false, $ffill = true, $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M', $rtloff = false)
  6404. {
  6405. $textrendermode = $this->textrendermode;
  6406. $textstrokewidth = $this->textstrokewidth;
  6407. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  6408. $this->SetXY($x, $y, $rtloff);
  6409. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  6410. // restore previous rendering mode
  6411. $this->textrendermode = $textrendermode;
  6412. $this->textstrokewidth = $textstrokewidth;
  6413. }
  6414. /**
  6415. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  6416. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  6417. * This method is called automatically and should not be called directly by the application.
  6418. * @return boolean
  6419. * @access public
  6420. * @since 1.4
  6421. * @see SetAutoPageBreak()
  6422. */
  6423. public function AcceptPageBreak()
  6424. {
  6425. if ($this->num_columns > 1)
  6426. {
  6427. // multi column mode
  6428. if ($this->current_column < ($this->num_columns - 1))
  6429. {
  6430. // go to next column
  6431. $this->selectColumn($this->current_column + 1);
  6432. }
  6433. else
  6434. {
  6435. // add a new page
  6436. $this->AddPage();
  6437. // set first column
  6438. $this->selectColumn(0);
  6439. }
  6440. // avoid page breaking from checkPageBreak()
  6441. return false;
  6442. }
  6443. return $this->AutoPageBreak;
  6444. }
  6445. /**
  6446. * Add page if needed.
  6447. * @param float $h Cell height. Default value: 0.
  6448. * @param mixed $y starting y position, leave empty for current position.
  6449. * @param boolean $addpage if true add a page, otherwise only return the true/false state
  6450. * @return boolean true in case of page break, false otherwise.
  6451. * @since 3.2.000 (2008-07-01)
  6452. * @access protected
  6453. */
  6454. protected function checkPageBreak($h = 0, $y = '', $addpage = true)
  6455. {
  6456. if ($this->empty_string($y))
  6457. {
  6458. $y = $this->y;
  6459. }
  6460. $current_page = $this->page;
  6461. if ((($y + $h) > $this->PageBreakTrigger) and (! $this->InFooter) and ($this->AcceptPageBreak()))
  6462. {
  6463. if ($addpage)
  6464. {
  6465. //Automatic page break
  6466. $x = $this->x;
  6467. $this->AddPage($this->CurOrientation);
  6468. $this->y = $this->tMargin;
  6469. $oldpage = $this->page - 1;
  6470. if ($this->rtl)
  6471. {
  6472. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm'])
  6473. {
  6474. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  6475. }
  6476. else
  6477. {
  6478. $this->x = $x;
  6479. }
  6480. }
  6481. else
  6482. {
  6483. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm'])
  6484. {
  6485. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  6486. }
  6487. else
  6488. {
  6489. $this->x = $x;
  6490. }
  6491. }
  6492. }
  6493. $this->newline = true;
  6494. return true;
  6495. }
  6496. if ($current_page != $this->page)
  6497. {
  6498. // account for columns mode
  6499. $this->newline = true;
  6500. return true;
  6501. }
  6502. return false;
  6503. }
  6504. /**
  6505. * Removes SHY characters from text.
  6506. * Unicode Data:<ul>
  6507. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  6508. * <li>HTML Entity (decimal): &amp;#173;</li>
  6509. * <li>HTML Entity (hex): &amp;#xad;</li>
  6510. * <li>HTML Entity (named): &amp;shy;</li>
  6511. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  6512. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  6513. * <li>UTF-8 character: chr(194).chr(173)</li>
  6514. * </ul>
  6515. * @param string $txt input string
  6516. * @return string without SHY characters.
  6517. * @access public
  6518. * @since (4.5.019) 2009-02-28
  6519. */
  6520. public function removeSHY($txt = '')
  6521. {
  6522. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  6523. if (! $this->isunicode)
  6524. {
  6525. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  6526. }
  6527. return $txt;
  6528. }
  6529. /**
  6530. * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  6531. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  6532. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  6533. * @param float $h Cell height. Default value: 0.
  6534. * @param string $txt String to print. Default value: empty string.
  6535. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6536. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6537. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6538. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  6539. * @param mixed $link URL or identifier returned by AddLink().
  6540. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6541. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  6542. * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  6543. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  6544. * @access public
  6545. * @since 1.0
  6546. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  6547. */
  6548. public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M')
  6549. {
  6550. $prev_cell_margin = $this->cell_margin;
  6551. $prev_cell_padding = $this->cell_padding;
  6552. $this->adjustCellPadding($border);
  6553. if (! $ignore_min_height)
  6554. {
  6555. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  6556. if ($h < $min_cell_height)
  6557. {
  6558. $h = $min_cell_height;
  6559. }
  6560. }
  6561. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  6562. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  6563. $this->cell_padding = $prev_cell_padding;
  6564. $this->cell_margin = $prev_cell_margin;
  6565. }
  6566. /**
  6567. * Returns the PDF string code to print a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  6568. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  6569. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  6570. * @param float $h Cell height. Default value: 0.
  6571. * @param string $txt String to print. Default value: empty string.
  6572. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6573. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6574. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6575. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  6576. * @param mixed $link URL or identifier returned by AddLink().
  6577. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6578. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  6579. * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  6580. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  6581. * @return string containing cell code
  6582. * @access protected
  6583. * @since 1.0
  6584. * @see Cell()
  6585. */
  6586. protected function getCellCode($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M')
  6587. {
  6588. $prev_cell_margin = $this->cell_margin;
  6589. $prev_cell_padding = $this->cell_padding;
  6590. $txt = $this->removeSHY($txt);
  6591. $rs = ''; //string to be returned
  6592. $this->adjustCellPadding($border);
  6593. if (! $ignore_min_height)
  6594. {
  6595. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  6596. if ($h < $min_cell_height)
  6597. {
  6598. $h = $min_cell_height;
  6599. }
  6600. }
  6601. // check page for no-write regions and adapt page margins if necessary
  6602. $this->checkPageRegions($h);
  6603. $k = $this->k;
  6604. if ($this->rtl)
  6605. {
  6606. $x = $this->x - $this->cell_margin['R'];
  6607. }
  6608. else
  6609. {
  6610. $x = $this->x + $this->cell_margin['L'];
  6611. }
  6612. $y = $this->y + $this->cell_margin['T'];
  6613. $prev_font_stretching = $this->font_stretching;
  6614. $prev_font_spacing = $this->font_spacing;
  6615. // cell vertical alignment
  6616. switch ($calign)
  6617. {
  6618. case 'A' :
  6619. {
  6620. // font top
  6621. switch ($valign)
  6622. {
  6623. case 'T' :
  6624. {
  6625. // top
  6626. $y -= $this->cell_padding['T'];
  6627. break;
  6628. }
  6629. case 'B' :
  6630. {
  6631. // bottom
  6632. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  6633. break;
  6634. }
  6635. default :
  6636. case 'C' :
  6637. case 'M' :
  6638. {
  6639. // center
  6640. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  6641. break;
  6642. }
  6643. }
  6644. break;
  6645. }
  6646. case 'L' :
  6647. {
  6648. // font baseline
  6649. switch ($valign)
  6650. {
  6651. case 'T' :
  6652. {
  6653. // top
  6654. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  6655. break;
  6656. }
  6657. case 'B' :
  6658. {
  6659. // bottom
  6660. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  6661. break;
  6662. }
  6663. default :
  6664. case 'C' :
  6665. case 'M' :
  6666. {
  6667. // center
  6668. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  6669. break;
  6670. }
  6671. }
  6672. break;
  6673. }
  6674. case 'D' :
  6675. {
  6676. // font bottom
  6677. switch ($valign)
  6678. {
  6679. case 'T' :
  6680. {
  6681. // top
  6682. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  6683. break;
  6684. }
  6685. case 'B' :
  6686. {
  6687. // bottom
  6688. $y -= ($h - $this->cell_padding['B']);
  6689. break;
  6690. }
  6691. default :
  6692. case 'C' :
  6693. case 'M' :
  6694. {
  6695. // center
  6696. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  6697. break;
  6698. }
  6699. }
  6700. break;
  6701. }
  6702. case 'B' :
  6703. {
  6704. // cell bottom
  6705. $y -= $h;
  6706. break;
  6707. }
  6708. case 'C' :
  6709. case 'M' :
  6710. {
  6711. // cell center
  6712. $y -= ($h / 2);
  6713. break;
  6714. }
  6715. default :
  6716. case 'T' :
  6717. {
  6718. // cell top
  6719. break;
  6720. }
  6721. }
  6722. // text vertical alignment
  6723. switch ($valign)
  6724. {
  6725. case 'T' :
  6726. {
  6727. // top
  6728. $yt = $y + $this->cell_padding['T'];
  6729. break;
  6730. }
  6731. case 'B' :
  6732. {
  6733. // bottom
  6734. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  6735. break;
  6736. }
  6737. default :
  6738. case 'C' :
  6739. case 'M' :
  6740. {
  6741. // center
  6742. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  6743. break;
  6744. }
  6745. }
  6746. $basefonty = $yt + $this->FontAscent;
  6747. if ($this->empty_string($w) or ($w <= 0))
  6748. {
  6749. if ($this->rtl)
  6750. {
  6751. $w = $x - $this->lMargin;
  6752. }
  6753. else
  6754. {
  6755. $w = $this->w - $this->rMargin - $x;
  6756. }
  6757. }
  6758. $s = '';
  6759. // fill and borders
  6760. if (is_string($border) and (strlen($border) == 4))
  6761. {
  6762. // full border
  6763. $border = 1;
  6764. }
  6765. if ($fill or ($border == 1))
  6766. {
  6767. if ($fill)
  6768. {
  6769. $op = ($border == 1) ? 'B' : 'f';
  6770. }
  6771. else
  6772. {
  6773. $op = 'S';
  6774. }
  6775. if ($this->rtl)
  6776. {
  6777. $xk = (($x - $w) * $k);
  6778. }
  6779. else
  6780. {
  6781. $xk = ($x * $k);
  6782. }
  6783. $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (- $h * $k), $op);
  6784. }
  6785. // draw borders
  6786. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  6787. if ($txt != '')
  6788. {
  6789. $txt2 = $txt;
  6790. if ($this->isunicode)
  6791. {
  6792. if (($this->CurrentFont['type'] == 'core') or ($this->CurrentFont['type'] == 'TrueType') or ($this->CurrentFont['type'] == 'Type1'))
  6793. {
  6794. $txt2 = $this->UTF8ToLatin1($txt2);
  6795. }
  6796. else
  6797. {
  6798. $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
  6799. $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
  6800. if (defined('K_THAI_TOPCHARS') and (K_THAI_TOPCHARS == true))
  6801. {
  6802. // ---- Fix for bug #2977340 "Incorrect Thai characters position arrangement" ----
  6803. // NOTE: this doesn't work with HTML justification
  6804. // Symbols that could overlap on the font top (only works in LTR)
  6805. $topchar = array(3611,
  6806. 3613, 3615, 3650, 3651, 3652); // chars that extends on top
  6807. $topsym = array(3633, 3636, 3637, 3638, 3639, 3655, 3656, 3657, 3658,
  6808. 3659, 3660, 3661, 3662); // symbols with top position
  6809. $numchars = count($unicode); // number of chars
  6810. $unik = 0;
  6811. $uniblock = array();
  6812. $uniblock[$unik] = array();
  6813. $uniblock[$unik][] = $unicode[0];
  6814. // resolve overlapping conflicts by splitting the string in several parts
  6815. for($i = 1; $i < $numchars; ++ $i)
  6816. {
  6817. // check if symbols overlaps at top
  6818. if (in_array($unicode[$i], $topsym) and (in_array($unicode[($i - 1)], $topsym) or in_array($unicode[($i - 1)], $topchar)))
  6819. {
  6820. // move symbols to another array
  6821. ++ $unik;
  6822. $uniblock[$unik] = array();
  6823. $uniblock[$unik][] = $unicode[$i];
  6824. ++ $unik;
  6825. $uniblock[$unik] = array();
  6826. $unicode[$i] = 0x200b; // Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  6827. }
  6828. else
  6829. {
  6830. $uniblock[$unik][] = $unicode[$i];
  6831. }
  6832. }
  6833. // ---- END OF Fix for bug #2977340
  6834. }
  6835. $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
  6836. }
  6837. }
  6838. $txt2 = $this->_escape($txt2);
  6839. // get current text width (considering general font stretching and spacing)
  6840. $txwidth = $this->GetStringWidth($txt);
  6841. $width = $txwidth;
  6842. // check for stretch mode
  6843. if ($stretch > 0)
  6844. {
  6845. // calculate ratio between cell width and text width
  6846. if ($width <= 0)
  6847. {
  6848. $ratio = 1;
  6849. }
  6850. else
  6851. {
  6852. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  6853. }
  6854. // check if stretching is required
  6855. if (($ratio < 1) or (($ratio > 1) and (($stretch % 2) == 0)))
  6856. {
  6857. // the text will be stretched to fit cell width
  6858. if ($stretch > 2)
  6859. {
  6860. // set new character spacing
  6861. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  6862. }
  6863. else
  6864. {
  6865. // set new horizontal stretching
  6866. $this->font_stretching *= $ratio;
  6867. }
  6868. // recalculate text width (the text fills the entire cell)
  6869. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6870. // reset alignment
  6871. $align = '';
  6872. }
  6873. }
  6874. if ($this->font_stretching != 100)
  6875. {
  6876. // apply font stretching
  6877. $rs .= sprintf('BT %.2F Tz ET ', $this->font_stretching);
  6878. }
  6879. if ($this->font_spacing != 0)
  6880. {
  6881. // increase/decrease font spacing
  6882. $rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing * $this->k));
  6883. }
  6884. if ($this->ColorFlag)
  6885. {
  6886. $s .= 'q ' . $this->TextColor . ' ';
  6887. }
  6888. // rendering mode
  6889. $s .= sprintf('BT %d Tr %.2F w ET ', $this->textrendermode, $this->textstrokewidth);
  6890. // count number of spaces
  6891. $ns = substr_count($txt, chr(32));
  6892. // Justification
  6893. $spacewidth = 0;
  6894. if (($align == 'J') and ($ns > 0))
  6895. {
  6896. if ($this->isUnicodeFont())
  6897. {
  6898. // get string width without spaces
  6899. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  6900. // calculate average space width
  6901. $spacewidth = - 1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1) / $this->FontSize;
  6902. if ($this->font_stretching != 100)
  6903. {
  6904. // word spacing is affected by stretching
  6905. $spacewidth /= ($this->font_stretching / 100);
  6906. }
  6907. // set word position to be used with TJ operator
  6908. $txt2 = str_replace(chr(0) . chr(32), ') ' . sprintf('%.3F', $spacewidth) . ' (', $txt2);
  6909. $unicode_justification = true;
  6910. }
  6911. else
  6912. {
  6913. // get string width
  6914. $width = $txwidth;
  6915. // new space width
  6916. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1)) * $this->k;
  6917. if ($this->font_stretching != 100)
  6918. {
  6919. // word spacing (Tw) is affected by stretching
  6920. $spacewidth /= ($this->font_stretching / 100);
  6921. }
  6922. // set word spacing
  6923. $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
  6924. }
  6925. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6926. }
  6927. // replace carriage return characters
  6928. $txt2 = str_replace("\r", ' ', $txt2);
  6929. switch ($align)
  6930. {
  6931. case 'C' :
  6932. {
  6933. $dx = ($w - $width) / 2;
  6934. break;
  6935. }
  6936. case 'R' :
  6937. {
  6938. if ($this->rtl)
  6939. {
  6940. $dx = $this->cell_padding['R'];
  6941. }
  6942. else
  6943. {
  6944. $dx = $w - $width - $this->cell_padding['R'];
  6945. }
  6946. break;
  6947. }
  6948. case 'L' :
  6949. {
  6950. if ($this->rtl)
  6951. {
  6952. $dx = $w - $width - $this->cell_padding['L'];
  6953. }
  6954. else
  6955. {
  6956. $dx = $this->cell_padding['L'];
  6957. }
  6958. break;
  6959. }
  6960. case 'J' :
  6961. default :
  6962. {
  6963. if ($this->rtl)
  6964. {
  6965. $dx = $this->cell_padding['R'];
  6966. }
  6967. else
  6968. {
  6969. $dx = $this->cell_padding['L'];
  6970. }
  6971. break;
  6972. }
  6973. }
  6974. if ($this->rtl)
  6975. {
  6976. $xdx = $x - $dx - $width;
  6977. }
  6978. else
  6979. {
  6980. $xdx = $x + $dx;
  6981. }
  6982. $xdk = $xdx * $k;
  6983. // print text
  6984. $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  6985. if (isset($uniblock))
  6986. {
  6987. // print overlapping characters as separate string
  6988. $xshift = 0; // horizontal shift
  6989. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  6990. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1));
  6991. foreach ($uniblock as $uk => $uniarr)
  6992. {
  6993. if (($uk % 2) == 0)
  6994. {
  6995. // x space to skip
  6996. if ($spacewidth != 0)
  6997. {
  6998. // justification shift
  6999. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  7000. }
  7001. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  7002. }
  7003. else
  7004. {
  7005. // character to print
  7006. $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
  7007. $topchr = $this->_escape($topchr);
  7008. $s .= sprintf(' BT %.2F %.2F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  7009. }
  7010. }
  7011. }
  7012. if ($this->underline)
  7013. {
  7014. $s .= ' ' . $this->_dounderlinew($xdx, $basefonty, $width);
  7015. }
  7016. if ($this->linethrough)
  7017. {
  7018. $s .= ' ' . $this->_dolinethroughw($xdx, $basefonty, $width);
  7019. }
  7020. if ($this->overline)
  7021. {
  7022. $s .= ' ' . $this->_dooverlinew($xdx, $basefonty, $width);
  7023. }
  7024. if ($this->ColorFlag)
  7025. {
  7026. $s .= ' Q';
  7027. }
  7028. if ($link)
  7029. {
  7030. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  7031. }
  7032. }
  7033. // output cell
  7034. if ($s)
  7035. {
  7036. // output cell
  7037. $rs .= $s;
  7038. if ($this->font_spacing != 0)
  7039. {
  7040. // reset font spacing mode
  7041. $rs .= ' BT 0 Tc ET';
  7042. }
  7043. if ($this->font_stretching != 100)
  7044. {
  7045. // reset font stretching mode
  7046. $rs .= ' BT 100 Tz ET';
  7047. }
  7048. }
  7049. // reset word spacing
  7050. if (! $this->isUnicodeFont() and ($align == 'J'))
  7051. {
  7052. $rs .= ' BT 0 Tw ET';
  7053. }
  7054. // reset stretching and spacing
  7055. $this->font_stretching = $prev_font_stretching;
  7056. $this->font_spacing = $prev_font_spacing;
  7057. $this->lasth = $h;
  7058. if ($ln > 0)
  7059. {
  7060. //Go to the beginning of the next line
  7061. $this->y = $y + $h + $this->cell_margin['B'];
  7062. if ($ln == 1)
  7063. {
  7064. if ($this->rtl)
  7065. {
  7066. $this->x = $this->w - $this->rMargin;
  7067. }
  7068. else
  7069. {
  7070. $this->x = $this->lMargin;
  7071. }
  7072. }
  7073. }
  7074. else
  7075. {
  7076. // go left or right by case
  7077. if ($this->rtl)
  7078. {
  7079. $this->x = $x - $w - $this->cell_margin['L'];
  7080. }
  7081. else
  7082. {
  7083. $this->x = $x + $w + $this->cell_margin['R'];
  7084. }
  7085. }
  7086. $gstyles = '' . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ' . $this->FillColor . "\n";
  7087. $rs = $gstyles . $rs;
  7088. $this->cell_padding = $prev_cell_padding;
  7089. $this->cell_margin = $prev_cell_margin;
  7090. return $rs;
  7091. }
  7092. /**
  7093. * Returns the code to draw the cell border
  7094. * @param float $x X coordinate.
  7095. * @param float $y Y coordinate.
  7096. * @param float $w Cell width.
  7097. * @param float $h Cell height.
  7098. * @param mixed $brd Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7099. * @param string $mode border position respect the square edge: normal: centered; ext: external; int: internal;
  7100. * @return string containing cell border code
  7101. * @access protected
  7102. * @see SetLineStyle()
  7103. * @since 5.7.000 (2010-08-02)
  7104. */
  7105. protected function getCellBorder($x, $y, $w, $h, $brd)
  7106. {
  7107. $s = ''; // string to be returned
  7108. if (empty($brd))
  7109. {
  7110. return $s;
  7111. }
  7112. if ($brd == 1)
  7113. {
  7114. $brd = array('LRTB' => true);
  7115. }
  7116. // calculate coordinates for border
  7117. $k = $this->k;
  7118. if ($this->rtl)
  7119. {
  7120. $xeL = ($x - $w) * $k;
  7121. $xeR = $x * $k;
  7122. }
  7123. else
  7124. {
  7125. $xeL = $x * $k;
  7126. $xeR = ($x + $w) * $k;
  7127. }
  7128. $yeL = (($this->h - ($y + $h)) * $k);
  7129. $yeT = (($this->h - $y) * $k);
  7130. $xeT = $xeL;
  7131. $xeB = $xeR;
  7132. $yeR = $yeT;
  7133. $yeB = $yeL;
  7134. if (is_string($brd))
  7135. {
  7136. // convert string to array
  7137. $slen = strlen($brd);
  7138. $newbrd = array();
  7139. for($i = 0; $i < $slen; ++ $i)
  7140. {
  7141. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  7142. }
  7143. $brd = $newbrd;
  7144. }
  7145. if (isset($brd['mode']))
  7146. {
  7147. $mode = $brd['mode'];
  7148. unset($brd['mode']);
  7149. }
  7150. else
  7151. {
  7152. $mode = 'normal';
  7153. }
  7154. foreach ($brd as $border => $style)
  7155. {
  7156. if (is_array($style) and ! empty($style))
  7157. {
  7158. // apply border style
  7159. $prev_style = $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ';
  7160. $s .= $this->SetLineStyle($style, true) . "\n";
  7161. }
  7162. switch ($mode)
  7163. {
  7164. case 'ext' :
  7165. {
  7166. $off = (($this->LineWidth / 2) * $k);
  7167. $xL = $xeL - $off;
  7168. $xR = $xeR + $off;
  7169. $yT = $yeT + $off;
  7170. $yL = $yeL - $off;
  7171. $xT = $xL;
  7172. $xB = $xR;
  7173. $yR = $yT;
  7174. $yB = $yL;
  7175. $w += $this->LineWidth;
  7176. $h += $this->LineWidth;
  7177. break;
  7178. }
  7179. case 'int' :
  7180. {
  7181. $off = ($this->LineWidth / 2) * $k;
  7182. $xL = $xeL + $off;
  7183. $xR = $xeR - $off;
  7184. $yT = $yeT - $off;
  7185. $yL = $yeL + $off;
  7186. $xT = $xL;
  7187. $xB = $xR;
  7188. $yR = $yT;
  7189. $yB = $yL;
  7190. $w -= $this->LineWidth;
  7191. $h -= $this->LineWidth;
  7192. break;
  7193. }
  7194. case 'normal' :
  7195. default :
  7196. {
  7197. $xL = $xeL;
  7198. $xT = $xeT;
  7199. $xB = $xeB;
  7200. $xR = $xeR;
  7201. $yL = $yeL;
  7202. $yT = $yeT;
  7203. $yB = $yeB;
  7204. $yR = $yeR;
  7205. break;
  7206. }
  7207. }
  7208. // draw borders by case
  7209. if (strlen($border) == 4)
  7210. {
  7211. $s .= sprintf('%.2F %.2F %.2F %.2F re S ', $xT, $yT, ($w * $k), (- $h * $k));
  7212. }
  7213. elseif (strlen($border) == 3)
  7214. {
  7215. if (strpos($border, 'B') === false)
  7216. { // LTR
  7217. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7218. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7219. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7220. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7221. $s .= 'S ';
  7222. }
  7223. elseif (strpos($border, 'L') === false)
  7224. { // TRB
  7225. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7226. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7227. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7228. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7229. $s .= 'S ';
  7230. }
  7231. elseif (strpos($border, 'T') === false)
  7232. { // RBL
  7233. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7234. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7235. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7236. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7237. $s .= 'S ';
  7238. }
  7239. elseif (strpos($border, 'R') === false)
  7240. { // BLT
  7241. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7242. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7243. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7244. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7245. $s .= 'S ';
  7246. }
  7247. }
  7248. elseif (strlen($border) == 2)
  7249. {
  7250. if ((strpos($border, 'L') !== false) and (strpos($border, 'T') !== false))
  7251. { // LT
  7252. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7253. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7254. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7255. $s .= 'S ';
  7256. }
  7257. elseif ((strpos($border, 'T') !== false) and (strpos($border, 'R') !== false))
  7258. { // TR
  7259. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7260. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7261. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7262. $s .= 'S ';
  7263. }
  7264. elseif ((strpos($border, 'R') !== false) and (strpos($border, 'B') !== false))
  7265. { // RB
  7266. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7267. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7268. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7269. $s .= 'S ';
  7270. }
  7271. elseif ((strpos($border, 'B') !== false) and (strpos($border, 'L') !== false))
  7272. { // BL
  7273. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7274. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7275. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7276. $s .= 'S ';
  7277. }
  7278. elseif ((strpos($border, 'L') !== false) and (strpos($border, 'R') !== false))
  7279. { // LR
  7280. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7281. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7282. $s .= 'S ';
  7283. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7284. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7285. $s .= 'S ';
  7286. }
  7287. elseif ((strpos($border, 'T') !== false) and (strpos($border, 'B') !== false))
  7288. { // TB
  7289. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7290. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7291. $s .= 'S ';
  7292. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7293. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7294. $s .= 'S ';
  7295. }
  7296. }
  7297. else
  7298. { // strlen($border) == 1
  7299. if (strpos($border, 'L') !== false)
  7300. { // L
  7301. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7302. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7303. $s .= 'S ';
  7304. }
  7305. elseif (strpos($border, 'T') !== false)
  7306. { // T
  7307. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7308. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7309. $s .= 'S ';
  7310. }
  7311. elseif (strpos($border, 'R') !== false)
  7312. { // R
  7313. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7314. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7315. $s .= 'S ';
  7316. }
  7317. elseif (strpos($border, 'B') !== false)
  7318. { // B
  7319. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7320. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7321. $s .= 'S ';
  7322. }
  7323. }
  7324. if (is_array($style) and ! empty($style))
  7325. {
  7326. // reset border style to previous value
  7327. $s .= "\n" . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . "\n";
  7328. }
  7329. }
  7330. return $s;
  7331. }
  7332. /**
  7333. * This method allows printing text with line breaks.
  7334. * They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />
  7335. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  7336. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  7337. * @param float $h Cell minimum height. The cell extends automatically if needed.
  7338. * @param string $txt String to print
  7339. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7340. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
  7341. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  7342. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  7343. * @param float $x x position in user units
  7344. * @param float $y y position in user units
  7345. * @param boolean $reseth if true reset the last cell height (default true).
  7346. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  7347. * @param boolean $ishtml set to true if $txt is HTML content (default = false).
  7348. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  7349. * @param float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false.
  7350. * @param string $valign Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false.
  7351. * @param boolean $fitcell if true attempt to fit all the text within the cell by reducing the font size.
  7352. * @return int Return the number of cells or 1 for html mode.
  7353. * @access public
  7354. * @since 1.3
  7355. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  7356. */
  7357. public function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = false, $ln = 1, $x = '', $y = '', $reseth = true, $stretch = 0, $ishtml = false, $autopadding = true, $maxh = 0, $valign = 'T', $fitcell = false)
  7358. {
  7359. $prev_cell_margin = $this->cell_margin;
  7360. $prev_cell_padding = $this->cell_padding;
  7361. // adjust internal padding
  7362. $this->adjustCellPadding($border);
  7363. $mc_padding = $this->cell_padding;
  7364. $mc_margin = $this->cell_margin;
  7365. $this->cell_padding['T'] = 0;
  7366. $this->cell_padding['B'] = 0;
  7367. $this->setCellMargins(0, 0, 0, 0);
  7368. if ($this->empty_string($this->lasth) or $reseth)
  7369. {
  7370. // reset row height
  7371. $this->resetLastH();
  7372. }
  7373. if (! $this->empty_string($y))
  7374. {
  7375. $this->SetY($y);
  7376. }
  7377. else
  7378. {
  7379. $y = $this->GetY();
  7380. }
  7381. $resth = 0;
  7382. if ((! $this->InFooter) and (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger))
  7383. {
  7384. // spit cell in more pages/columns
  7385. $newh = $this->PageBreakTrigger - $y;
  7386. $resth = $h - $newh; // cell to be printed on the next page/column
  7387. $h = $newh;
  7388. }
  7389. // get current page number
  7390. $startpage = $this->page;
  7391. // get current column
  7392. $startcolumn = $this->current_column;
  7393. if (! $this->empty_string($x))
  7394. {
  7395. $this->SetX($x);
  7396. }
  7397. else
  7398. {
  7399. $x = $this->GetX();
  7400. }
  7401. // check page for no-write regions and adapt page margins if necessary
  7402. $this->checkPageRegions(0, $x, $y);
  7403. // apply margins
  7404. $oy = $y + $mc_margin['T'];
  7405. if ($this->rtl)
  7406. {
  7407. $ox = $this->w - $x - $mc_margin['R'];
  7408. }
  7409. else
  7410. {
  7411. $ox = $x + $mc_margin['L'];
  7412. }
  7413. $this->x = $ox;
  7414. $this->y = $oy;
  7415. // set width
  7416. if ($this->empty_string($w) or ($w <= 0))
  7417. {
  7418. if ($this->rtl)
  7419. {
  7420. $w = $this->x - $this->lMargin - $mc_margin['L'];
  7421. }
  7422. else
  7423. {
  7424. $w = $this->w - $this->x - $this->rMargin - $mc_margin['R'];
  7425. }
  7426. }
  7427. // store original margin values
  7428. $lMargin = $this->lMargin;
  7429. $rMargin = $this->rMargin;
  7430. if ($this->rtl)
  7431. {
  7432. $this->rMargin = $this->w - $this->x;
  7433. $this->lMargin = $this->x - $w;
  7434. }
  7435. else
  7436. {
  7437. $this->lMargin = $this->x;
  7438. $this->rMargin = $this->w - $this->x - $w;
  7439. }
  7440. if ($autopadding)
  7441. {
  7442. // add top padding
  7443. $this->y += $mc_padding['T'];
  7444. }
  7445. if ($ishtml)
  7446. { // ******* Write HTML text
  7447. $this->writeHTML($txt, true, 0, $reseth, true, $align);
  7448. $nl = 1;
  7449. }
  7450. else
  7451. { // ******* Write simple text
  7452. // vertical alignment
  7453. if ($maxh > 0)
  7454. {
  7455. // get text height
  7456. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  7457. if ($fitcell)
  7458. {
  7459. $prev_FontSizePt = $this->FontSizePt;
  7460. // try to reduce font size to fit text on cell (use a quick search algorithm)
  7461. $fmin = 1;
  7462. $fmax = $this->FontSizePt;
  7463. $prev_text_height = $text_height;
  7464. $maxit = 100; // max number of iterations
  7465. while ($maxit > 0)
  7466. {
  7467. $fmid = (($fmax + $fmin) / 2);
  7468. $this->SetFontSize($fmid, false);
  7469. $this->resetLastH();
  7470. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  7471. if (($text_height == $maxh) or (($text_height < $maxh) and ($fmin >= ($fmax - 0.01))))
  7472. {
  7473. break;
  7474. }
  7475. elseif ($text_height < $maxh)
  7476. {
  7477. $fmin = $fmid;
  7478. }
  7479. else
  7480. {
  7481. $fmax = $fmid;
  7482. }
  7483. -- $maxit;
  7484. }
  7485. $this->SetFontSize($this->FontSizePt);
  7486. }
  7487. if ($text_height < $maxh)
  7488. {
  7489. if ($valign == 'M')
  7490. {
  7491. // text vertically centered
  7492. $this->y += (($maxh - $text_height) / 2);
  7493. }
  7494. elseif ($valign == 'B')
  7495. {
  7496. // text vertically aligned on bottom
  7497. $this->y += ($maxh - $text_height);
  7498. }
  7499. }
  7500. }
  7501. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  7502. if ($fitcell)
  7503. {
  7504. // restore font size
  7505. $this->SetFontSize($prev_FontSizePt);
  7506. }
  7507. }
  7508. if ($autopadding)
  7509. {
  7510. // add bottom padding
  7511. $this->y += $mc_padding['B'];
  7512. }
  7513. // Get end-of-text Y position
  7514. $currentY = $this->y;
  7515. // get latest page number
  7516. $endpage = $this->page;
  7517. if ($resth > 0)
  7518. {
  7519. $skip = ($endpage - $startpage);
  7520. $tmpresth = $resth;
  7521. while ($tmpresth > 0)
  7522. {
  7523. if ($skip <= 0)
  7524. {
  7525. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  7526. $this->checkPageBreak($this->PageBreakTrigger + 1);
  7527. }
  7528. if ($this->num_columns > 1)
  7529. {
  7530. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  7531. }
  7532. else
  7533. {
  7534. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  7535. }
  7536. -- $skip;
  7537. }
  7538. $currentY = $this->y;
  7539. $endpage = $this->page;
  7540. }
  7541. // get latest column
  7542. $endcolumn = $this->current_column;
  7543. if ($this->num_columns == 0)
  7544. {
  7545. $this->num_columns = 1;
  7546. }
  7547. // get border modes
  7548. $border_start = $this->getBorderMode($border, $position = 'start');
  7549. $border_end = $this->getBorderMode($border, $position = 'end');
  7550. $border_middle = $this->getBorderMode($border, $position = 'middle');
  7551. // design borders around HTML cells.
  7552. for($page = $startpage; $page <= $endpage; ++ $page)
  7553. { // for each page
  7554. $ccode = '';
  7555. $this->setPage($page);
  7556. if ($this->num_columns < 2)
  7557. {
  7558. // single-column mode
  7559. $this->SetX($x);
  7560. $this->y = $this->tMargin;
  7561. }
  7562. // account for margin changes
  7563. if ($page > $startpage)
  7564. {
  7565. if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm']))
  7566. {
  7567. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  7568. }
  7569. elseif ((! $this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm']))
  7570. {
  7571. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  7572. }
  7573. }
  7574. if ($startpage == $endpage)
  7575. {
  7576. // single page
  7577. for($column = $startcolumn; $column <= $endcolumn; ++ $column)
  7578. { // for each column
  7579. $this->selectColumn($column);
  7580. if ($this->rtl)
  7581. {
  7582. $this->x -= $mc_margin['R'];
  7583. }
  7584. else
  7585. {
  7586. $this->x += $mc_margin['L'];
  7587. }
  7588. if ($startcolumn == $endcolumn)
  7589. { // single column
  7590. $cborder = $border;
  7591. $h = max($h, ($currentY - $oy));
  7592. $this->y = $oy;
  7593. }
  7594. elseif ($column == $startcolumn)
  7595. { // first column
  7596. $cborder = $border_start;
  7597. $this->y = $oy;
  7598. $h = $this->h - $this->y - $this->bMargin;
  7599. }
  7600. elseif ($column == $endcolumn)
  7601. { // end column
  7602. $cborder = $border_end;
  7603. $h = $currentY - $this->y;
  7604. if ($resth > $h)
  7605. {
  7606. $h = $resth;
  7607. }
  7608. }
  7609. else
  7610. { // middle column
  7611. $cborder = $border_middle;
  7612. $h = $this->h - $this->y - $this->bMargin;
  7613. $resth -= $h;
  7614. }
  7615. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7616. } // end for each column
  7617. }
  7618. elseif ($page == $startpage)
  7619. { // first page
  7620. for($column = $startcolumn; $column < $this->num_columns; ++ $column)
  7621. { // for each column
  7622. $this->selectColumn($column);
  7623. if ($this->rtl)
  7624. {
  7625. $this->x -= $mc_margin['R'];
  7626. }
  7627. else
  7628. {
  7629. $this->x += $mc_margin['L'];
  7630. }
  7631. if ($column == $startcolumn)
  7632. { // first column
  7633. $cborder = $border_start;
  7634. $this->y = $oy;
  7635. $h = $this->h - $this->y - $this->bMargin;
  7636. }
  7637. else
  7638. { // middle column
  7639. $cborder = $border_middle;
  7640. $h = $this->h - $this->y - $this->bMargin;
  7641. $resth -= $h;
  7642. }
  7643. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7644. } // end for each column
  7645. }
  7646. elseif ($page == $endpage)
  7647. { // last page
  7648. for($column = 0; $column <= $endcolumn; ++ $column)
  7649. { // for each column
  7650. $this->selectColumn($column);
  7651. if ($this->rtl)
  7652. {
  7653. $this->x -= $mc_margin['R'];
  7654. }
  7655. else
  7656. {
  7657. $this->x += $mc_margin['L'];
  7658. }
  7659. if ($column == $endcolumn)
  7660. {
  7661. // end column
  7662. $cborder = $border_end;
  7663. $h = $currentY - $this->y;
  7664. if ($resth > $h)
  7665. {
  7666. $h = $resth;
  7667. }
  7668. }
  7669. else
  7670. {
  7671. // middle column
  7672. $cborder = $border_middle;
  7673. $h = $this->h - $this->y - $this->bMargin;
  7674. $resth -= $h;
  7675. }
  7676. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7677. } // end for each column
  7678. }
  7679. else
  7680. { // middle page
  7681. for($column = 0; $column < $this->num_columns; ++ $column)
  7682. { // for each column
  7683. $this->selectColumn($column);
  7684. if ($this->rtl)
  7685. {
  7686. $this->x -= $mc_margin['R'];
  7687. }
  7688. else
  7689. {
  7690. $this->x += $mc_margin['L'];
  7691. }
  7692. $cborder = $border_middle;
  7693. $h = $this->h - $this->y - $this->bMargin;
  7694. $resth -= $h;
  7695. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7696. } // end for each column
  7697. }
  7698. if ($cborder or $fill)
  7699. {
  7700. // draw border and fill
  7701. if ($this->inxobj)
  7702. {
  7703. // we are inside an XObject template
  7704. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false)
  7705. {
  7706. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  7707. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  7708. }
  7709. else
  7710. {
  7711. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  7712. }
  7713. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  7714. $pstart = substr($pagebuff, 0, $pagemark);
  7715. $pend = substr($pagebuff, $pagemark);
  7716. $this->xobjects[$this->xobjid]['outdata'] = $pstart . $ccode . $pend;
  7717. $pagemark += strlen($ccode);
  7718. }
  7719. else
  7720. {
  7721. if (end($this->transfmrk[$this->page]) !== false)
  7722. {
  7723. $pagemarkkey = key($this->transfmrk[$this->page]);
  7724. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  7725. }
  7726. elseif ($this->InFooter)
  7727. {
  7728. $pagemark = &$this->footerpos[$this->page];
  7729. }
  7730. else
  7731. {
  7732. $pagemark = &$this->intmrk[$this->page];
  7733. }
  7734. $pagebuff = $this->getPageBuffer($this->page);
  7735. $pstart = substr($pagebuff, 0, $pagemark);
  7736. $pend = substr($pagebuff, $pagemark);
  7737. $this->setPageBuffer($this->page, $pstart . $ccode . $pend);
  7738. $pagemark += strlen($ccode);
  7739. }
  7740. }
  7741. } // end for each page
  7742. // Get end-of-cell Y position
  7743. $currentY = $this->GetY();
  7744. // restore original margin values
  7745. $this->SetLeftMargin($lMargin);
  7746. $this->SetRightMargin($rMargin);
  7747. if ($ln > 0)
  7748. {
  7749. //Go to the beginning of the next line
  7750. $this->SetY($currentY + $mc_margin['B']);
  7751. if ($ln == 2)
  7752. {
  7753. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  7754. }
  7755. }
  7756. else
  7757. {
  7758. // go left or right by case
  7759. $this->setPage($startpage);
  7760. $this->y = $y;
  7761. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  7762. }
  7763. $this->setContentMark();
  7764. $this->cell_padding = $prev_cell_padding;
  7765. $this->cell_margin = $prev_cell_margin;
  7766. return $nl;
  7767. }
  7768. /**
  7769. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  7770. * @param mixed $brd Indicates if borders must be drawn around the cell block. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7771. * @param string multicell position: 'start', 'middle', 'end'
  7772. * @return border mode array
  7773. * @access protected
  7774. * @since 4.4.002 (2008-12-09)
  7775. */
  7776. protected function getBorderMode($brd, $position = 'start')
  7777. {
  7778. if ((! $this->opencell) or empty($brd))
  7779. {
  7780. return $brd;
  7781. }
  7782. if ($brd == 1)
  7783. {
  7784. $brd = 'LTRB';
  7785. }
  7786. if (is_string($brd))
  7787. {
  7788. // convert string to array
  7789. $slen = strlen($brd);
  7790. $newbrd = array();
  7791. for($i = 0; $i < $slen; ++ $i)
  7792. {
  7793. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  7794. }
  7795. $brd = $newbrd;
  7796. }
  7797. foreach ($brd as $border => $style)
  7798. {
  7799. switch ($position)
  7800. {
  7801. case 'start' :
  7802. {
  7803. if (strpos($border, 'B') !== false)
  7804. {
  7805. // remove bottom line
  7806. $newkey = str_replace('B', '', $border);
  7807. if (strlen($newkey) > 0)
  7808. {
  7809. $brd[$newkey] = $style;
  7810. }
  7811. unset($brd[$border]);
  7812. }
  7813. break;
  7814. }
  7815. case 'middle' :
  7816. {
  7817. if (strpos($border, 'B') !== false)
  7818. {
  7819. // remove bottom line
  7820. $newkey = str_replace('B', '', $border);
  7821. if (strlen($newkey) > 0)
  7822. {
  7823. $brd[$newkey] = $style;
  7824. }
  7825. unset($brd[$border]);
  7826. $border = $newkey;
  7827. }
  7828. if (strpos($border, 'T') !== false)
  7829. {
  7830. // remove bottom line
  7831. $newkey = str_replace('T', '', $border);
  7832. if (strlen($newkey) > 0)
  7833. {
  7834. $brd[$newkey] = $style;
  7835. }
  7836. unset($brd[$border]);
  7837. }
  7838. break;
  7839. }
  7840. case 'end' :
  7841. {
  7842. if (strpos($border, 'T') !== false)
  7843. {
  7844. // remove bottom line
  7845. $newkey = str_replace('T', '', $border);
  7846. if (strlen($newkey) > 0)
  7847. {
  7848. $brd[$newkey] = $style;
  7849. }
  7850. unset($brd[$border]);
  7851. }
  7852. break;
  7853. }
  7854. }
  7855. }
  7856. return $brd;
  7857. }
  7858. /**
  7859. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  7860. * @param string $txt String for calculating his height
  7861. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  7862. * @param boolean $reseth if true reset the last cell height (default false).
  7863. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  7864. * @param float $cellpadding Internal cell padding, if empty uses default cell padding.
  7865. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7866. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  7867. * @author Alexander Escalona Fern�ndez, Nicola Asuni
  7868. * @access public
  7869. * @since 4.5.011
  7870. */
  7871. public function getNumLines($txt, $w = 0, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0)
  7872. {
  7873. if ($txt === '')
  7874. {
  7875. // empty string
  7876. return 1;
  7877. }
  7878. // adjust internal padding
  7879. $prev_cell_padding = $this->cell_padding;
  7880. $prev_lasth = $this->lasth;
  7881. if (is_array($cellpadding))
  7882. {
  7883. $this->cell_padding = $cellpadding;
  7884. }
  7885. $this->adjustCellPadding($border);
  7886. if ($this->empty_string($w) or ($w <= 0))
  7887. {
  7888. if ($this->rtl)
  7889. {
  7890. $w = $this->x - $this->lMargin;
  7891. }
  7892. else
  7893. {
  7894. $w = $this->w - $this->rMargin - $this->x;
  7895. }
  7896. }
  7897. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  7898. if ($reseth)
  7899. {
  7900. // reset row height
  7901. $this->resetLastH();
  7902. }
  7903. $lines = 1;
  7904. $sum = 0;
  7905. $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
  7906. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  7907. $length = count($chars);
  7908. $lastSeparator = - 1;
  7909. for($i = 0; $i < $length; ++ $i)
  7910. {
  7911. $charWidth = $charsWidth[$i];
  7912. if (preg_match($this->re_spaces, $this->unichr($chars[$i])))
  7913. {
  7914. $lastSeparator = $i;
  7915. }
  7916. if ((($sum + $charWidth) > $wmax) or ($chars[$i] == 10))
  7917. {
  7918. ++ $lines;
  7919. if ($lastSeparator != - 1)
  7920. {
  7921. $i = $lastSeparator;
  7922. $lastSeparator = - 1;
  7923. $sum = 0;
  7924. }
  7925. else
  7926. {
  7927. $sum = $charWidth;
  7928. }
  7929. }
  7930. else
  7931. {
  7932. $sum += $charWidth;
  7933. }
  7934. }
  7935. if ($chars[($length - 1)] == 10)
  7936. {
  7937. -- $lines;
  7938. }
  7939. $this->cell_padding = $prev_cell_padding;
  7940. $this->lasth = $prev_lasth;
  7941. return $lines;
  7942. }
  7943. /**
  7944. * This method return the estimated needed height for print a simple text string in Multicell() method.
  7945. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  7946. * <pre>
  7947. * // store current object
  7948. * $pdf->startTransaction();
  7949. * // store starting values
  7950. * $start_y = $pdf->GetY();
  7951. * $start_page = $pdf->getPage();
  7952. * // call your printing functions with your parameters
  7953. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7954. * $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
  7955. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7956. * // get the new Y
  7957. * $end_y = $pdf->GetY();
  7958. * $end_page = $pdf->getPage();
  7959. * // calculate height
  7960. * $height = 0;
  7961. * if ($end_page == $start_page) {
  7962. * $height = $end_y - $start_y;
  7963. * } else {
  7964. * for ($page=$start_page; $page <= $end_page; ++$page) {
  7965. * $this->setPage($page);
  7966. * if ($page == $start_page) {
  7967. * // first page
  7968. * $height = $this->h - $start_y - $this->bMargin;
  7969. * } elseif ($page == $end_page) {
  7970. * // last page
  7971. * $height = $end_y - $this->tMargin;
  7972. * } else {
  7973. * $height = $this->h - $this->tMargin - $this->bMargin;
  7974. * }
  7975. * }
  7976. * }
  7977. * // restore previous object
  7978. * $pdf = $pdf->rollbackTransaction();
  7979. * </pre>
  7980. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  7981. * @param string $txt String for calculating his height
  7982. * @param boolean $reseth if true reset the last cell height (default false).
  7983. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  7984. * @param float $cellpadding Internal cell padding, if empty uses default cell padding.
  7985. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7986. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  7987. * @author Nicola Asuni, Alexander Escalona Fern�ndez
  7988. * @access public
  7989. */
  7990. public function getStringHeight($w, $txt, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0)
  7991. {
  7992. // adjust internal padding
  7993. $prev_cell_padding = $this->cell_padding;
  7994. $prev_lasth = $this->lasth;
  7995. if (is_array($cellpadding))
  7996. {
  7997. $this->cell_padding = $cellpadding;
  7998. }
  7999. $this->adjustCellPadding($border);
  8000. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  8001. $height = $lines * ($this->FontSize * $this->cell_height_ratio);
  8002. if ($autopadding)
  8003. {
  8004. // add top and bottom padding
  8005. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  8006. }
  8007. $this->cell_padding = $prev_cell_padding;
  8008. $this->lasth = $prev_lasth;
  8009. return $height;
  8010. }
  8011. /**
  8012. * This method prints text from the current position.<br />
  8013. * @param float $h Line height
  8014. * @param string $txt String to print
  8015. * @param mixed $link URL or identifier returned by AddLink()
  8016. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  8017. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  8018. * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  8019. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  8020. * @param boolean $firstline if true prints only the first line and return the remaining string.
  8021. * @param boolean $firstblock if true the string is the starting of a line.
  8022. * @param float $maxh maximum height. The remaining unprinted text will be returned. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  8023. * @param float $wadj first line width will be reduced by this amount (used in HTML mode).
  8024. * @param array $margin margin array of the parent container
  8025. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  8026. * @access public
  8027. * @since 1.5
  8028. */
  8029. public function Write($h, $txt, $link = '', $fill = false, $align = '', $ln = false, $stretch = 0, $firstline = false, $firstblock = false, $maxh = 0, $wadj = 0, $margin = '')
  8030. {
  8031. // check page for no-write regions and adapt page margins if necessary
  8032. $this->checkPageRegions($h);
  8033. if (strlen($txt) == 0)
  8034. {
  8035. // fix empty text
  8036. $txt = ' ';
  8037. }
  8038. if ($margin === '')
  8039. {
  8040. // set default margins
  8041. $margin = $this->cell_margin;
  8042. }
  8043. // remove carriage returns
  8044. $s = str_replace("\r", '', $txt);
  8045. // check if string contains arabic text
  8046. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s))
  8047. {
  8048. $arabic = true;
  8049. }
  8050. else
  8051. {
  8052. $arabic = false;
  8053. }
  8054. // check if string contains RTL text
  8055. if ($arabic or ($this->tmprtl == 'R') or preg_match($this->unicode->uni_RE_PATTERN_RTL, $s))
  8056. {
  8057. $rtlmode = true;
  8058. }
  8059. else
  8060. {
  8061. $rtlmode = false;
  8062. }
  8063. // get a char width
  8064. $chrwidth = $this->GetCharWidth('.');
  8065. // get array of unicode values
  8066. $chars = $this->UTF8StringToArray($s);
  8067. // get array of chars
  8068. $uchars = $this->UTF8ArrayToUniArray($chars);
  8069. // get the number of characters
  8070. $nb = count($chars);
  8071. // replacement for SHY character (minus symbol)
  8072. $shy_replacement = 45;
  8073. $shy_replacement_char = $this->unichr($shy_replacement);
  8074. // widht for SHY replacement
  8075. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  8076. // max Y
  8077. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  8078. // calculate remaining line width ($w)
  8079. if ($this->rtl)
  8080. {
  8081. $w = $this->x - $this->lMargin;
  8082. }
  8083. else
  8084. {
  8085. $w = $this->w - $this->rMargin - $this->x;
  8086. }
  8087. // max column width
  8088. $wmax = $w - $wadj;
  8089. if (! $firstline)
  8090. {
  8091. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  8092. }
  8093. if ((! $firstline) and (($chrwidth > $wmax) or ($this->GetCharWidth($chars[0]) > $wmax)))
  8094. {
  8095. // a single character do not fit on column
  8096. return '';
  8097. }
  8098. // minimum row height
  8099. $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
  8100. $start_page = $this->page;
  8101. $i = 0; // character position
  8102. $j = 0; // current starting position
  8103. $sep = - 1; // position of the last blank space
  8104. $shy = false; // true if the last blank is a soft hypen (SHY)
  8105. $l = 0; // current string length
  8106. $nl = 0; //number of lines
  8107. $linebreak = false;
  8108. $pc = 0; // previous character
  8109. // for each character
  8110. while ($i < $nb)
  8111. {
  8112. if (($maxh > 0) and ($this->y >= $maxy))
  8113. {
  8114. break;
  8115. }
  8116. //Get the current character
  8117. $c = $chars[$i];
  8118. if ($c == 10)
  8119. { // 10 = "\n" = new line
  8120. //Explicit line break
  8121. if ($align == 'J')
  8122. {
  8123. if ($this->rtl)
  8124. {
  8125. $talign = 'R';
  8126. }
  8127. else
  8128. {
  8129. $talign = 'L';
  8130. }
  8131. }
  8132. else
  8133. {
  8134. $talign = $align;
  8135. }
  8136. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  8137. if ($firstline)
  8138. {
  8139. $startx = $this->x;
  8140. $tmparr = array_slice($chars, $j, ($i - $j));
  8141. if ($rtlmode)
  8142. {
  8143. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8144. }
  8145. $linew = $this->GetArrStringWidth($tmparr);
  8146. unset($tmparr);
  8147. if ($this->rtl)
  8148. {
  8149. $this->endlinex = $startx - $linew;
  8150. }
  8151. else
  8152. {
  8153. $this->endlinex = $startx + $linew;
  8154. }
  8155. $w = $linew;
  8156. $tmpcellpadding = $this->cell_padding;
  8157. if ($maxh == 0)
  8158. {
  8159. $this->SetCellPadding(0);
  8160. }
  8161. }
  8162. if ($firstblock and $this->isRTLTextDir())
  8163. {
  8164. $tmpstr = $this->stringRightTrim($tmpstr);
  8165. }
  8166. // Skip newlines at the begining of a page or column
  8167. if (! empty($tmpstr) or ($this->y < ($this->PageBreakTrigger - $row_height)))
  8168. {
  8169. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  8170. }
  8171. unset($tmpstr);
  8172. if ($firstline)
  8173. {
  8174. $this->cell_padding = $tmpcellpadding;
  8175. return ($this->UniArrSubString($uchars, $i));
  8176. }
  8177. ++ $nl;
  8178. $j = $i + 1;
  8179. $l = 0;
  8180. $sep = - 1;
  8181. $shy = false;
  8182. // account for margin changes
  8183. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and (! $this->InFooter))
  8184. {
  8185. $this->AcceptPageBreak();
  8186. if ($this->rtl)
  8187. {
  8188. $this->x -= $margin['R'];
  8189. }
  8190. else
  8191. {
  8192. $this->x += $margin['L'];
  8193. }
  8194. $this->lMargin += $margin['L'];
  8195. $this->rMargin += $margin['R'];
  8196. }
  8197. $w = $this->getRemainingWidth();
  8198. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  8199. }
  8200. else
  8201. {
  8202. // 160 is the non-breaking space.
  8203. // 173 is SHY (Soft Hypen).
  8204. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  8205. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  8206. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  8207. if (($c != 160) and (($c == 173) or preg_match($this->re_spaces, $this->unichr($c))))
  8208. {
  8209. // update last blank space position
  8210. $sep = $i;
  8211. // check if is a SHY
  8212. if ($c == 173)
  8213. {
  8214. $shy = true;
  8215. if ($pc == 45)
  8216. {
  8217. $tmp_shy_replacement_width = 0;
  8218. $tmp_shy_replacement_char = '';
  8219. }
  8220. else
  8221. {
  8222. $tmp_shy_replacement_width = $shy_replacement_width;
  8223. $tmp_shy_replacement_char = $shy_replacement_char;
  8224. }
  8225. }
  8226. else
  8227. {
  8228. $shy = false;
  8229. }
  8230. }
  8231. // update string length
  8232. if ($this->isUnicodeFont() and ($arabic))
  8233. {
  8234. // with bidirectional algorithm some chars may be changed affecting the line length
  8235. // *** very slow ***
  8236. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  8237. }
  8238. else
  8239. {
  8240. $l += $this->GetCharWidth($c);
  8241. }
  8242. if (($l > $wmax) or (($c == 173) and (($l + $tmp_shy_replacement_width) > $wmax)))
  8243. {
  8244. // we have reached the end of column
  8245. if ($sep == - 1)
  8246. {
  8247. // check if the line was already started
  8248. if (($this->rtl and ($this->x <= ($this->w - $this->rMargin - $chrwidth))) or ((! $this->rtl) and ($this->x >= ($this->lMargin + $chrwidth))))
  8249. {
  8250. // print a void cell and go to next line
  8251. $this->Cell($w, $h, '', 0, 1);
  8252. $linebreak = true;
  8253. if ($firstline)
  8254. {
  8255. return ($this->UniArrSubString($uchars, $j));
  8256. }
  8257. }
  8258. else
  8259. {
  8260. // truncate the word because do not fit on column
  8261. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  8262. if ($firstline)
  8263. {
  8264. $startx = $this->x;
  8265. $tmparr = array_slice($chars, $j, ($i - $j));
  8266. if ($rtlmode)
  8267. {
  8268. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8269. }
  8270. $linew = $this->GetArrStringWidth($tmparr);
  8271. unset($tmparr);
  8272. if ($this->rtl)
  8273. {
  8274. $this->endlinex = $startx - $linew;
  8275. }
  8276. else
  8277. {
  8278. $this->endlinex = $startx + $linew;
  8279. }
  8280. $w = $linew;
  8281. $tmpcellpadding = $this->cell_padding;
  8282. if ($maxh == 0)
  8283. {
  8284. $this->SetCellPadding(0);
  8285. }
  8286. }
  8287. if ($firstblock and $this->isRTLTextDir())
  8288. {
  8289. $tmpstr = $this->stringRightTrim($tmpstr);
  8290. }
  8291. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  8292. unset($tmpstr);
  8293. if ($firstline)
  8294. {
  8295. $this->cell_padding = $tmpcellpadding;
  8296. return ($this->UniArrSubString($uchars, $i));
  8297. }
  8298. $j = $i;
  8299. -- $i;
  8300. }
  8301. }
  8302. else
  8303. {
  8304. // word wrapping
  8305. if ($this->rtl and (! $firstblock) and ($sep < $i))
  8306. {
  8307. $endspace = 1;
  8308. }
  8309. else
  8310. {
  8311. $endspace = 0;
  8312. }
  8313. if ($shy)
  8314. {
  8315. // add hypen (minus symbol) at the end of the line
  8316. $shy_width = $tmp_shy_replacement_width;
  8317. if ($this->rtl)
  8318. {
  8319. $shy_char_left = $tmp_shy_replacement_char;
  8320. $shy_char_right = '';
  8321. }
  8322. else
  8323. {
  8324. $shy_char_left = '';
  8325. $shy_char_right = $tmp_shy_replacement_char;
  8326. }
  8327. }
  8328. else
  8329. {
  8330. $shy_width = 0;
  8331. $shy_char_left = '';
  8332. $shy_char_right = '';
  8333. }
  8334. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  8335. if ($firstline)
  8336. {
  8337. $startx = $this->x;
  8338. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  8339. if ($rtlmode)
  8340. {
  8341. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8342. }
  8343. $linew = $this->GetArrStringWidth($tmparr);
  8344. unset($tmparr);
  8345. if ($this->rtl)
  8346. {
  8347. $this->endlinex = $startx - $linew - $shy_width;
  8348. }
  8349. else
  8350. {
  8351. $this->endlinex = $startx + $linew + $shy_width;
  8352. }
  8353. $w = $linew;
  8354. $tmpcellpadding = $this->cell_padding;
  8355. if ($maxh == 0)
  8356. {
  8357. $this->SetCellPadding(0);
  8358. }
  8359. }
  8360. // print the line
  8361. if ($firstblock and $this->isRTLTextDir())
  8362. {
  8363. $tmpstr = $this->stringRightTrim($tmpstr);
  8364. }
  8365. $this->Cell($w, $h, $shy_char_left . $tmpstr . $shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  8366. unset($tmpstr);
  8367. if ($firstline)
  8368. {
  8369. // return the remaining text
  8370. $this->cell_padding = $tmpcellpadding;
  8371. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  8372. }
  8373. $i = $sep;
  8374. $sep = - 1;
  8375. $shy = false;
  8376. $j = ($i + 1);
  8377. }
  8378. // account for margin changes
  8379. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and (! $this->InFooter))
  8380. {
  8381. $this->AcceptPageBreak();
  8382. if ($this->rtl)
  8383. {
  8384. $this->x -= $margin['R'];
  8385. }
  8386. else
  8387. {
  8388. $this->x += $margin['L'];
  8389. }
  8390. $this->lMargin += $margin['L'];
  8391. $this->rMargin += $margin['R'];
  8392. }
  8393. $w = $this->getRemainingWidth();
  8394. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  8395. if ($linebreak)
  8396. {
  8397. $linebreak = false;
  8398. }
  8399. else
  8400. {
  8401. ++ $nl;
  8402. $l = 0;
  8403. }
  8404. }
  8405. }
  8406. // save last character
  8407. $pc = $c;
  8408. ++ $i;
  8409. } // end while i < nb
  8410. // print last substring (if any)
  8411. if ($l > 0)
  8412. {
  8413. switch ($align)
  8414. {
  8415. case 'J' :
  8416. case 'C' :
  8417. {
  8418. $w = $w;
  8419. break;
  8420. }
  8421. case 'L' :
  8422. {
  8423. if ($this->rtl)
  8424. {
  8425. $w = $w;
  8426. }
  8427. else
  8428. {
  8429. $w = $l;
  8430. }
  8431. break;
  8432. }
  8433. case 'R' :
  8434. {
  8435. if ($this->rtl)
  8436. {
  8437. $w = $l;
  8438. }
  8439. else
  8440. {
  8441. $w = $w;
  8442. }
  8443. break;
  8444. }
  8445. default :
  8446. {
  8447. $w = $l;
  8448. break;
  8449. }
  8450. }
  8451. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  8452. if ($firstline)
  8453. {
  8454. $startx = $this->x;
  8455. $tmparr = array_slice($chars, $j, ($nb - $j));
  8456. if ($rtlmode)
  8457. {
  8458. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8459. }
  8460. $linew = $this->GetArrStringWidth($tmparr);
  8461. unset($tmparr);
  8462. if ($this->rtl)
  8463. {
  8464. $this->endlinex = $startx - $linew;
  8465. }
  8466. else
  8467. {
  8468. $this->endlinex = $startx + $linew;
  8469. }
  8470. $w = $linew;
  8471. $tmpcellpadding = $this->cell_padding;
  8472. if ($maxh == 0)
  8473. {
  8474. $this->SetCellPadding(0);
  8475. }
  8476. }
  8477. if ($firstblock and $this->isRTLTextDir())
  8478. {
  8479. $tmpstr = $this->stringRightTrim($tmpstr);
  8480. }
  8481. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  8482. unset($tmpstr);
  8483. if ($firstline)
  8484. {
  8485. $this->cell_padding = $tmpcellpadding;
  8486. return ($this->UniArrSubString($uchars, $nb));
  8487. }
  8488. ++ $nl;
  8489. }
  8490. if ($firstline)
  8491. {
  8492. return '';
  8493. }
  8494. return $nl;
  8495. }
  8496. /**
  8497. * Returns the remaining width between the current position and margins.
  8498. * @return int Return the remaining width
  8499. * @access protected
  8500. */
  8501. protected function getRemainingWidth()
  8502. {
  8503. $this->checkPageRegions();
  8504. if ($this->rtl)
  8505. {
  8506. return ($this->x - $this->lMargin);
  8507. }
  8508. else
  8509. {
  8510. return ($this->w - $this->rMargin - $this->x);
  8511. }
  8512. }
  8513. /**
  8514. * Extract a slice of the $strarr array and return it as string.
  8515. * @param string $strarr The input array of characters.
  8516. * @param int $start the starting element of $strarr.
  8517. * @param int $end first element that will not be returned.
  8518. * @return Return part of a string
  8519. * @access public
  8520. */
  8521. public function UTF8ArrSubString($strarr, $start = '', $end = '')
  8522. {
  8523. if (strlen($start) == 0)
  8524. {
  8525. $start = 0;
  8526. }
  8527. if (strlen($end) == 0)
  8528. {
  8529. $end = count($strarr);
  8530. }
  8531. $string = '';
  8532. for($i = $start; $i < $end; ++ $i)
  8533. {
  8534. $string .= $this->unichr($strarr[$i]);
  8535. }
  8536. return $string;
  8537. }
  8538. /**
  8539. * Extract a slice of the $uniarr array and return it as string.
  8540. * @param string $uniarr The input array of characters.
  8541. * @param int $start the starting element of $strarr.
  8542. * @param int $end first element that will not be returned.
  8543. * @return Return part of a string
  8544. * @access public
  8545. * @since 4.5.037 (2009-04-07)
  8546. */
  8547. public function UniArrSubString($uniarr, $start = '', $end = '')
  8548. {
  8549. if (strlen($start) == 0)
  8550. {
  8551. $start = 0;
  8552. }
  8553. if (strlen($end) == 0)
  8554. {
  8555. $end = count($uniarr);
  8556. }
  8557. $string = '';
  8558. for($i = $start; $i < $end; ++ $i)
  8559. {
  8560. $string .= $uniarr[$i];
  8561. }
  8562. return $string;
  8563. }
  8564. /**
  8565. * Convert an array of UTF8 values to array of unicode characters
  8566. * @param string $ta The input array of UTF8 values.
  8567. * @return Return array of unicode characters
  8568. * @access public
  8569. * @since 4.5.037 (2009-04-07)
  8570. */
  8571. public function UTF8ArrayToUniArray($ta)
  8572. {
  8573. return array_map(array($this, 'unichr'), $ta);
  8574. }
  8575. /**
  8576. * Returns the unicode caracter specified by UTF-8 value
  8577. * @param int $c UTF-8 value
  8578. * @return Returns the specified character.
  8579. * @author Miguel Perez, Nicola Asuni
  8580. * @access public
  8581. * @since 2.3.000 (2008-03-05)
  8582. */
  8583. public function unichr($c)
  8584. {
  8585. if (! $this->isunicode)
  8586. {
  8587. return chr($c);
  8588. }
  8589. elseif ($c <= 0x7F)
  8590. {
  8591. // one byte
  8592. return chr($c);
  8593. }
  8594. elseif ($c <= 0x7FF)
  8595. {
  8596. // two bytes
  8597. return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
  8598. }
  8599. elseif ($c <= 0xFFFF)
  8600. {
  8601. // three bytes
  8602. return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  8603. }
  8604. elseif ($c <= 0x10FFFF)
  8605. {
  8606. // four bytes
  8607. return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  8608. }
  8609. else
  8610. {
  8611. return '';
  8612. }
  8613. }
  8614. /**
  8615. * Return the image type given the file name or array returned by getimagesize() function.
  8616. * @param string $imgfile image file name
  8617. * @param array $iminfo array of image information returned by getimagesize() function.
  8618. * @return string image type
  8619. * @since 4.8.017 (2009-11-27)
  8620. */
  8621. public function getImageFileType($imgfile, $iminfo = array())
  8622. {
  8623. $type = '';
  8624. if (isset($iminfo['mime']) and ! empty($iminfo['mime']))
  8625. {
  8626. $mime = explode('/', $iminfo['mime']);
  8627. if ((count($mime) > 1) and ($mime[0] == 'image') and (! empty($mime[1])))
  8628. {
  8629. $type = strtolower(trim($mime[1]));
  8630. }
  8631. }
  8632. if (empty($type))
  8633. {
  8634. $fileinfo = pathinfo($imgfile);
  8635. if (isset($fileinfo['extension']) and (! $this->empty_string($fileinfo['extension'])))
  8636. {
  8637. $type = strtolower(trim($fileinfo['extension']));
  8638. }
  8639. }
  8640. if ($type == 'jpg')
  8641. {
  8642. $type = 'jpeg';
  8643. }
  8644. return $type;
  8645. }
  8646. /**
  8647. * Set the block dimensions accounting for page breaks and page/column fitting
  8648. * @param float $w width
  8649. * @param float $h height
  8650. * @param float $x X coordinate
  8651. * @param float $y Y coodiante
  8652. * @param boolean $fitonpage if true the block is resized to not exceed page dimensions.
  8653. * @access protected
  8654. * @since 5.5.009 (2010-07-05)
  8655. */
  8656. protected function fitBlock(&$w, &$h, &$x, &$y, $fitonpage = false)
  8657. {
  8658. // resize the block to be vertically contained on a single page or single column
  8659. if ($fitonpage or $this->AutoPageBreak)
  8660. {
  8661. $ratio_wh = ($w / $h);
  8662. if ($h > ($this->PageBreakTrigger - $this->tMargin))
  8663. {
  8664. $h = $this->PageBreakTrigger - $this->tMargin;
  8665. $w = ($h * $ratio_wh);
  8666. }
  8667. // resize the block to be horizontally contained on a single page or single column
  8668. if ($fitonpage)
  8669. {
  8670. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  8671. if ($w > $maxw)
  8672. {
  8673. $w = $maxw;
  8674. $h = ($w / $ratio_wh);
  8675. }
  8676. }
  8677. }
  8678. // Check whether we need a new page or new column first as this does not fit
  8679. $prev_x = $this->x;
  8680. $prev_y = $this->y;
  8681. if ($this->checkPageBreak($h, $y) or ($this->y < $prev_y))
  8682. {
  8683. $y = $this->y;
  8684. if ($this->rtl)
  8685. {
  8686. $x += ($prev_x - $this->x);
  8687. }
  8688. else
  8689. {
  8690. $x += ($this->x - $prev_x);
  8691. }
  8692. }
  8693. // resize the block to be contained on the remaining available page or column space
  8694. if ($fitonpage)
  8695. {
  8696. $ratio_wh = ($w / $h);
  8697. if (($y + $h) > $this->PageBreakTrigger)
  8698. {
  8699. $h = $this->PageBreakTrigger - $y;
  8700. $w = ($h * $ratio_wh);
  8701. }
  8702. if ((! $this->rtl) and (($x + $w) > ($this->w - $this->rMargin)))
  8703. {
  8704. $w = $this->w - $this->rMargin - $x;
  8705. $h = ($w / $ratio_wh);
  8706. }
  8707. elseif (($this->rtl) and (($x - $w) < ($this->lMargin)))
  8708. {
  8709. $w = $x - $this->lMargin;
  8710. $h = ($w / $ratio_wh);
  8711. }
  8712. }
  8713. }
  8714. /**
  8715. * Puts an image in the page.
  8716. * The upper-left corner must be given.
  8717. * The dimensions can be specified in different ways:<ul>
  8718. * <li>explicit width and height (expressed in user unit)</li>
  8719. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  8720. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  8721. * Supported formats are JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;
  8722. * The format can be specified explicitly or inferred from the file extension.<br />
  8723. * It is possible to put a link on the image.<br />
  8724. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  8725. * @param string $file Name of the file containing the image.
  8726. * @param float $x Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  8727. * @param float $y Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  8728. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8729. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8730. * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  8731. * @param mixed $link URL or identifier returned by AddLink().
  8732. * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  8733. * @param mixed $resize If true resize (reduce) the image to fit $w and $h (requires GD or ImageMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
  8734. * @param int $dpi dot-per-inch resolution used on resize
  8735. * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  8736. * @param boolean $ismask true if this image is a mask, false otherwise
  8737. * @param mixed $imgmask image object returned by this function or false
  8738. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  8739. * @param boolean $fitbox If true scale image dimensions proportionally to fit within the ($w, $h) box.
  8740. * @param boolean $hidden if true do not display the image.
  8741. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  8742. * @return image information
  8743. * @access public
  8744. * @since 1.1
  8745. */
  8746. public function Image($file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false, $hidden = false, $fitonpage = false)
  8747. {
  8748. if ($x === '')
  8749. {
  8750. $x = $this->x;
  8751. }
  8752. if ($y === '')
  8753. {
  8754. $y = $this->y;
  8755. }
  8756. // check page for no-write regions and adapt page margins if necessary
  8757. $this->checkPageRegions($h, $x, $y);
  8758. $cached_file = false; // true when the file is cached
  8759. // get image dimensions
  8760. $imsize = @getimagesize($file);
  8761. if ($imsize === FALSE)
  8762. {
  8763. // try to encode spaces on filename
  8764. $file = str_replace(' ', '%20', $file);
  8765. $imsize = @getimagesize($file);
  8766. if ($imsize === FALSE)
  8767. {
  8768. if (function_exists('curl_init'))
  8769. {
  8770. // try to get remote file data using cURL
  8771. $cs = curl_init(); // curl session
  8772. curl_setopt($cs, CURLOPT_URL, $file);
  8773. curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
  8774. curl_setopt($cs, CURLOPT_FAILONERROR, true);
  8775. curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
  8776. curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
  8777. curl_setopt($cs, CURLOPT_TIMEOUT, 30);
  8778. $imgdata = curl_exec($cs);
  8779. curl_close($cs);
  8780. if ($imgdata !== FALSE)
  8781. {
  8782. // copy image to cache
  8783. $file = tempnam(K_PATH_CACHE, 'img_');
  8784. $fp = fopen($file, 'w');
  8785. fwrite($fp, $imgdata);
  8786. fclose($fp);
  8787. unset($imgdata);
  8788. $cached_file = true;
  8789. $imsize = @getimagesize($file);
  8790. if ($imsize === FALSE)
  8791. {
  8792. unlink($file);
  8793. $cached_file = false;
  8794. }
  8795. }
  8796. }
  8797. elseif (($w > 0) and ($h > 0))
  8798. {
  8799. // get measures from specified data
  8800. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8801. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8802. $imsize = array($pw, $ph);
  8803. }
  8804. }
  8805. }
  8806. if ($imsize === FALSE)
  8807. {
  8808. $this->Error('[Image] Unable to get image: ' . $file);
  8809. }
  8810. // get original image width and height in pixels
  8811. list($pixw, $pixh) = $imsize;
  8812. // calculate image width and height on document
  8813. if (($w <= 0) and ($h <= 0))
  8814. {
  8815. // convert image size to document unit
  8816. $w = $this->pixelsToUnits($pixw);
  8817. $h = $this->pixelsToUnits($pixh);
  8818. }
  8819. elseif ($w <= 0)
  8820. {
  8821. $w = $h * $pixw / $pixh;
  8822. }
  8823. elseif ($h <= 0)
  8824. {
  8825. $h = $w * $pixh / $pixw;
  8826. }
  8827. elseif ($fitbox and ($w > 0) and ($h > 0))
  8828. {
  8829. // scale image dimensions proportionally to fit within the ($w, $h) box
  8830. if ((($w * $pixh) / ($h * $pixw)) < 1)
  8831. {
  8832. $h = $w * $pixh / $pixw;
  8833. }
  8834. else
  8835. {
  8836. $w = $h * $pixw / $pixh;
  8837. }
  8838. }
  8839. // fit the image on available space
  8840. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  8841. // calculate new minimum dimensions in pixels
  8842. $neww = round($w * $this->k * $dpi / $this->dpi);
  8843. $newh = round($h * $this->k * $dpi / $this->dpi);
  8844. // check if resize is necessary (resize is used only to reduce the image)
  8845. $newsize = ($neww * $newh);
  8846. $pixsize = ($pixw * $pixh);
  8847. if (intval($resize) == 2)
  8848. {
  8849. $resize = true;
  8850. }
  8851. elseif ($newsize >= $pixsize)
  8852. {
  8853. $resize = false;
  8854. }
  8855. // check if image has been already added on document
  8856. $newimage = true;
  8857. if (in_array($file, $this->imagekeys))
  8858. {
  8859. $newimage = false;
  8860. // get existing image data
  8861. $info = $this->getImageBuffer($file);
  8862. // check if the newer image is larger
  8863. $oldsize = ($info['w'] * $info['h']);
  8864. if ((($oldsize < $newsize) and ($resize)) or (($oldsize < $pixsize) and (! $resize)))
  8865. {
  8866. $newimage = true;
  8867. }
  8868. }
  8869. if ($newimage)
  8870. {
  8871. //First use of image, get info
  8872. $type = strtolower($type);
  8873. if ($type == '')
  8874. {
  8875. $type = $this->getImageFileType($file, $imsize);
  8876. }
  8877. elseif ($type == 'jpg')
  8878. {
  8879. $type = 'jpeg';
  8880. }
  8881. $mqr = $this->get_mqr();
  8882. $this->set_mqr(false);
  8883. // Specific image handlers
  8884. $mtd = '_parse' . $type;
  8885. // GD image handler function
  8886. $gdfunction = 'imagecreatefrom' . $type;
  8887. $info = false;
  8888. if ((method_exists($this, $mtd)) and (! ($resize and function_exists($gdfunction))))
  8889. {
  8890. // TCPDF image functions
  8891. $info = $this->$mtd($file);
  8892. if ($info == 'pngalpha')
  8893. {
  8894. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign);
  8895. }
  8896. }
  8897. if (! $info)
  8898. {
  8899. if (function_exists($gdfunction))
  8900. {
  8901. // GD library
  8902. $img = $gdfunction($file);
  8903. if ($resize)
  8904. {
  8905. $imgr = imagecreatetruecolor($neww, $newh);
  8906. if (($type == 'gif') or ($type == 'png'))
  8907. {
  8908. $imgr = $this->_setGDImageTransparency($imgr, $img);
  8909. }
  8910. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  8911. if (($type == 'gif') or ($type == 'png'))
  8912. {
  8913. $info = $this->_toPNG($imgr);
  8914. }
  8915. else
  8916. {
  8917. $info = $this->_toJPEG($imgr);
  8918. }
  8919. }
  8920. else
  8921. {
  8922. if (($type == 'gif') or ($type == 'png'))
  8923. {
  8924. $info = $this->_toPNG($img);
  8925. }
  8926. else
  8927. {
  8928. $info = $this->_toJPEG($img);
  8929. }
  8930. }
  8931. }
  8932. elseif (extension_loaded('imagick'))
  8933. {
  8934. // ImageMagick library
  8935. $img = new Imagick();
  8936. if ($type == 'SVG')
  8937. {
  8938. // get SVG file content
  8939. $svgimg = file_get_contents($file);
  8940. // get width and height
  8941. $regs = array();
  8942. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs))
  8943. {
  8944. $svgtag = $regs[1];
  8945. $tmp = array();
  8946. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp))
  8947. {
  8948. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  8949. $owu = sprintf('%.3F', ($ow * $dpi / 72)) . $this->pdfunit;
  8950. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="' . $owu . '"', $svgtag, 1);
  8951. }
  8952. else
  8953. {
  8954. $ow = $w;
  8955. }
  8956. $tmp = array();
  8957. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp))
  8958. {
  8959. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  8960. $ohu = sprintf('%.3F', ($oh * $dpi / 72)) . $this->pdfunit;
  8961. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="' . $ohu . '"', $svgtag, 1);
  8962. }
  8963. else
  8964. {
  8965. $oh = $h;
  8966. }
  8967. $tmp = array();
  8968. if (! preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp))
  8969. {
  8970. $vbw = ($ow * $this->imgscale * $this->k);
  8971. $vbh = ($oh * $this->imgscale * $this->k);
  8972. $vbox = sprintf(' viewBox="0 0 %.3F %.3F" ', $vbw, $vbh);
  8973. $svgtag = $vbox . $svgtag;
  8974. }
  8975. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg' . $svgtag . '>', $svgimg, 1);
  8976. }
  8977. $img->readImageBlob($svgimg);
  8978. }
  8979. else
  8980. {
  8981. $img->readImage($file);
  8982. }
  8983. if ($resize)
  8984. {
  8985. $img->resizeImage($neww, $newh, 10, 1, false);
  8986. }
  8987. $img->setCompressionQuality($this->jpeg_quality);
  8988. $img->setImageFormat('jpeg');
  8989. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  8990. $img->writeImage($tempname);
  8991. $info = $this->_parsejpeg($tempname);
  8992. unlink($tempname);
  8993. $img->destroy();
  8994. }
  8995. else
  8996. {
  8997. return;
  8998. }
  8999. }
  9000. if ($info === false)
  9001. {
  9002. //If false, we cannot process image
  9003. return;
  9004. }
  9005. $this->set_mqr($mqr);
  9006. if ($ismask)
  9007. {
  9008. // force grayscale
  9009. $info['cs'] = 'DeviceGray';
  9010. }
  9011. $info['i'] = $this->numimages;
  9012. if (! in_array($file, $this->imagekeys))
  9013. {
  9014. ++ $info['i'];
  9015. }
  9016. if ($imgmask !== false)
  9017. {
  9018. $info['masked'] = $imgmask;
  9019. }
  9020. // add image to document
  9021. $this->setImageBuffer($file, $info);
  9022. }
  9023. if ($cached_file)
  9024. {
  9025. // remove cached file
  9026. unlink($file);
  9027. }
  9028. // set alignment
  9029. $this->img_rb_y = $y + $h;
  9030. // set alignment
  9031. if ($this->rtl)
  9032. {
  9033. if ($palign == 'L')
  9034. {
  9035. $ximg = $this->lMargin;
  9036. }
  9037. elseif ($palign == 'C')
  9038. {
  9039. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  9040. }
  9041. elseif ($palign == 'R')
  9042. {
  9043. $ximg = $this->w - $this->rMargin - $w;
  9044. }
  9045. else
  9046. {
  9047. $ximg = $x - $w;
  9048. }
  9049. $this->img_rb_x = $ximg;
  9050. }
  9051. else
  9052. {
  9053. if ($palign == 'L')
  9054. {
  9055. $ximg = $this->lMargin;
  9056. }
  9057. elseif ($palign == 'C')
  9058. {
  9059. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  9060. }
  9061. elseif ($palign == 'R')
  9062. {
  9063. $ximg = $this->w - $this->rMargin - $w;
  9064. }
  9065. else
  9066. {
  9067. $ximg = $x;
  9068. }
  9069. $this->img_rb_x = $ximg + $w;
  9070. }
  9071. if ($ismask or $hidden)
  9072. {
  9073. // image is not displayed
  9074. return $info['i'];
  9075. }
  9076. $xkimg = $ximg * $this->k;
  9077. $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  9078. if (! empty($border))
  9079. {
  9080. $bx = $this->x;
  9081. $by = $this->y;
  9082. $this->x = $ximg;
  9083. if ($this->rtl)
  9084. {
  9085. $this->x += $w;
  9086. }
  9087. $this->y = $y;
  9088. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  9089. $this->x = $bx;
  9090. $this->y = $by;
  9091. }
  9092. if ($link)
  9093. {
  9094. $this->Link($ximg, $y, $w, $h, $link, 0);
  9095. }
  9096. // set pointer to align the next text/objects
  9097. switch ($align)
  9098. {
  9099. case 'T' :
  9100. {
  9101. $this->y = $y;
  9102. $this->x = $this->img_rb_x;
  9103. break;
  9104. }
  9105. case 'M' :
  9106. {
  9107. $this->y = $y + round($h / 2);
  9108. $this->x = $this->img_rb_x;
  9109. break;
  9110. }
  9111. case 'B' :
  9112. {
  9113. $this->y = $this->img_rb_y;
  9114. $this->x = $this->img_rb_x;
  9115. break;
  9116. }
  9117. case 'N' :
  9118. {
  9119. $this->SetY($this->img_rb_y);
  9120. break;
  9121. }
  9122. default :
  9123. {
  9124. break;
  9125. }
  9126. }
  9127. $this->endlinex = $this->img_rb_x;
  9128. if ($this->inxobj)
  9129. {
  9130. // we are inside an XObject template
  9131. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  9132. }
  9133. return $info['i'];
  9134. }
  9135. /**
  9136. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  9137. * @param boolean $mqr FALSE for off, TRUE for on.
  9138. * @since 4.6.025 (2009-08-17)
  9139. */
  9140. public function set_mqr($mqr)
  9141. {
  9142. if (! defined('PHP_VERSION_ID'))
  9143. {
  9144. $version = PHP_VERSION;
  9145. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  9146. }
  9147. if (PHP_VERSION_ID < 50300)
  9148. {
  9149. @set_magic_quotes_runtime($mqr);
  9150. }
  9151. }
  9152. /**
  9153. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  9154. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  9155. * @since 4.6.025 (2009-08-17)
  9156. */
  9157. public function get_mqr()
  9158. {
  9159. if (! defined('PHP_VERSION_ID'))
  9160. {
  9161. $version = PHP_VERSION;
  9162. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  9163. }
  9164. if (PHP_VERSION_ID < 50300)
  9165. {
  9166. return @get_magic_quotes_runtime();
  9167. }
  9168. return 0;
  9169. }
  9170. /**
  9171. * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
  9172. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  9173. * @param string $file Image file name.
  9174. * @param image $image Image object.
  9175. * return image JPEG image object.
  9176. * @access protected
  9177. */
  9178. protected function _toJPEG($image)
  9179. {
  9180. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  9181. imagejpeg($image, $tempname, $this->jpeg_quality);
  9182. imagedestroy($image);
  9183. $retvars = $this->_parsejpeg($tempname);
  9184. // tidy up by removing temporary image
  9185. unlink($tempname);
  9186. return $retvars;
  9187. }
  9188. /**
  9189. * Convert the loaded image to a PNG and then return a structure for the PDF creator.
  9190. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  9191. * @param string $file Image file name.
  9192. * @param image $image Image object.
  9193. * return image PNG image object.
  9194. * @access protected
  9195. * @since 4.9.016 (2010-04-20)
  9196. */
  9197. protected function _toPNG($image)
  9198. {
  9199. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  9200. imagepng($image, $tempname);
  9201. imagedestroy($image);
  9202. $retvars = $this->_parsepng($tempname);
  9203. // tidy up by removing temporary image
  9204. unlink($tempname);
  9205. return $retvars;
  9206. }
  9207. /**
  9208. * Set the transparency for the given GD image.
  9209. * @param image $new_image GD image object
  9210. * @param image $image GD image object.
  9211. * return GD image object.
  9212. * @access protected
  9213. * @since 4.9.016 (2010-04-20)
  9214. */
  9215. protected function _setGDImageTransparency($new_image, $image)
  9216. {
  9217. // transparency index
  9218. $tid = imagecolortransparent($image);
  9219. // default transparency color
  9220. $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
  9221. if ($tid >= 0)
  9222. {
  9223. // get the colors for the transparency index
  9224. $tcol = imagecolorsforindex($image, $tid);
  9225. }
  9226. $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
  9227. imagefill($new_image, 0, 0, $tid);
  9228. imagecolortransparent($new_image, $tid);
  9229. return $new_image;
  9230. }
  9231. /**
  9232. * Extract info from a JPEG file without using the GD library.
  9233. * @param string $file image file to parse
  9234. * @return array structure containing the image data
  9235. * @access protected
  9236. */
  9237. protected function _parsejpeg($file)
  9238. {
  9239. $a = getimagesize($file);
  9240. if (empty($a))
  9241. {
  9242. $this->Error('Missing or incorrect image file: ' . $file);
  9243. }
  9244. if ($a[2] != 2)
  9245. {
  9246. $this->Error('Not a JPEG file: ' . $file);
  9247. }
  9248. if ((! isset($a['channels'])) or ($a['channels'] == 3))
  9249. {
  9250. $colspace = 'DeviceRGB';
  9251. }
  9252. elseif ($a['channels'] == 4)
  9253. {
  9254. $colspace = 'DeviceCMYK';
  9255. }
  9256. else
  9257. {
  9258. $colspace = 'DeviceGray';
  9259. }
  9260. $bpc = isset($a['bits']) ? $a['bits'] : 8;
  9261. $data = file_get_contents($file);
  9262. return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
  9263. }
  9264. /**
  9265. * Extract info from a PNG file without using the GD library.
  9266. * @param string $file image file to parse
  9267. * @return array structure containing the image data
  9268. * @access protected
  9269. */
  9270. protected function _parsepng($file)
  9271. {
  9272. $f = fopen($file, 'rb');
  9273. if ($f === false)
  9274. {
  9275. $this->Error('Can\'t open image file: ' . $file);
  9276. }
  9277. //Check signature
  9278. if (fread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10))
  9279. {
  9280. $this->Error('Not a PNG file: ' . $file);
  9281. }
  9282. //Read header chunk
  9283. fread($f, 4);
  9284. if (fread($f, 4) != 'IHDR')
  9285. {
  9286. $this->Error('Incorrect PNG file: ' . $file);
  9287. }
  9288. $w = $this->_freadint($f);
  9289. $h = $this->_freadint($f);
  9290. $bpc = ord(fread($f, 1));
  9291. if ($bpc > 8)
  9292. {
  9293. //$this->Error('16-bit depth not supported: '.$file);
  9294. fclose($f);
  9295. return false;
  9296. }
  9297. $ct = ord(fread($f, 1));
  9298. if ($ct == 0)
  9299. {
  9300. $colspace = 'DeviceGray';
  9301. }
  9302. elseif ($ct == 2)
  9303. {
  9304. $colspace = 'DeviceRGB';
  9305. }
  9306. elseif ($ct == 3)
  9307. {
  9308. $colspace = 'Indexed';
  9309. }
  9310. else
  9311. {
  9312. // alpha channel
  9313. fclose($f);
  9314. return 'pngalpha';
  9315. }
  9316. if (ord(fread($f, 1)) != 0)
  9317. {
  9318. //$this->Error('Unknown compression method: '.$file);
  9319. fclose($f);
  9320. return false;
  9321. }
  9322. if (ord(fread($f, 1)) != 0)
  9323. {
  9324. //$this->Error('Unknown filter method: '.$file);
  9325. fclose($f);
  9326. return false;
  9327. }
  9328. if (ord(fread($f, 1)) != 0)
  9329. {
  9330. //$this->Error('Interlacing not supported: '.$file);
  9331. fclose($f);
  9332. return false;
  9333. }
  9334. fread($f, 4);
  9335. $parms = '/DecodeParms << /Predictor 15 /Colors ' . ($ct == 2 ? 3 : 1) . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . ' >>';
  9336. //Scan chunks looking for palette, transparency and image data
  9337. $pal = '';
  9338. $trns = '';
  9339. $data = '';
  9340. do
  9341. {
  9342. $n = $this->_freadint($f);
  9343. $type = fread($f, 4);
  9344. if ($type == 'PLTE')
  9345. {
  9346. //Read palette
  9347. $pal = $this->rfread($f, $n);
  9348. fread($f, 4);
  9349. }
  9350. elseif ($type == 'tRNS')
  9351. {
  9352. //Read transparency info
  9353. $t = $this->rfread($f, $n);
  9354. if ($ct == 0)
  9355. {
  9356. $trns = array(ord(substr($t, 1, 1)));
  9357. }
  9358. elseif ($ct == 2)
  9359. {
  9360. $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
  9361. }
  9362. else
  9363. {
  9364. $pos = strpos($t, chr(0));
  9365. if ($pos !== false)
  9366. {
  9367. $trns = array($pos);
  9368. }
  9369. }
  9370. fread($f, 4);
  9371. }
  9372. elseif ($type == 'IDAT')
  9373. {
  9374. //Read image data block
  9375. $data .= $this->rfread($f, $n);
  9376. fread($f, 4);
  9377. }
  9378. elseif ($type == 'IEND')
  9379. {
  9380. break;
  9381. }
  9382. else
  9383. {
  9384. $this->rfread($f, $n + 4);
  9385. }
  9386. }
  9387. while ($n);
  9388. if (($colspace == 'Indexed') and (empty($pal)))
  9389. {
  9390. //$this->Error('Missing palette in '.$file);
  9391. fclose($f);
  9392. return false;
  9393. }
  9394. fclose($f);
  9395. return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms,
  9396. 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  9397. }
  9398. /**
  9399. * Binary-safe and URL-safe file read.
  9400. * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
  9401. * @param resource $handle
  9402. * @param int $length
  9403. * @return Returns the read string or FALSE in case of error.
  9404. * @author Nicola Asuni
  9405. * @access protected
  9406. * @since 4.5.027 (2009-03-16)
  9407. */
  9408. protected function rfread($handle, $length)
  9409. {
  9410. $data = fread($handle, $length);
  9411. if ($data === false)
  9412. {
  9413. return false;
  9414. }
  9415. $rest = $length - strlen($data);
  9416. if ($rest > 0)
  9417. {
  9418. $data .= $this->rfread($handle, $rest);
  9419. }
  9420. return $data;
  9421. }
  9422. /**
  9423. * Extract info from a PNG image with alpha channel using the GD library.
  9424. * @param string $file Name of the file containing the image.
  9425. * @param float $x Abscissa of the upper-left corner.
  9426. * @param float $y Ordinate of the upper-left corner.
  9427. * @param float $wpx Original width of the image in pixels.
  9428. * @param float $hpx original height of the image in pixels.
  9429. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9430. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9431. * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  9432. * @param mixed $link URL or identifier returned by AddLink().
  9433. * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  9434. * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  9435. * @param int $dpi dot-per-inch resolution used on resize
  9436. * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  9437. * @author Nicola Asuni
  9438. * @access protected
  9439. * @since 4.3.007 (2008-12-04)
  9440. * @see Image()
  9441. */
  9442. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign)
  9443. {
  9444. // create temp image file (without alpha channel)
  9445. $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_');
  9446. // create temp alpha file
  9447. $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_');
  9448. if (extension_loaded('imagick'))
  9449. { // ImageMagick
  9450. // ImageMagick library
  9451. $img = new Imagick();
  9452. $img->readImage($file);
  9453. // clone image object
  9454. $imga = $img->clone();
  9455. // extract alpha channel
  9456. $img->separateImageChannel(imagick :: CHANNEL_ALPHA | imagick :: CHANNEL_OPACITY | imagick :: CHANNEL_MATTE);
  9457. $img->negateImage(true);
  9458. $img->setImageFormat('png');
  9459. $img->writeImage($tempfile_alpha);
  9460. // remove alpha channel
  9461. $imga->separateImageChannel(imagick :: CHANNEL_ALL & ~ (imagick :: CHANNEL_ALPHA | imagick :: CHANNEL_OPACITY | imagick :: CHANNEL_MATTE));
  9462. $imga->setImageFormat('png');
  9463. $imga->writeImage($tempfile_plain);
  9464. }
  9465. else
  9466. { // GD library
  9467. // generate images
  9468. $img = imagecreatefrompng($file);
  9469. $imgalpha = imagecreate($wpx, $hpx);
  9470. // generate gray scale palette (0 -> 255)
  9471. for($c = 0; $c < 256; ++ $c)
  9472. {
  9473. ImageColorAllocate($imgalpha, $c, $c, $c);
  9474. }
  9475. // extract alpha channel
  9476. for($xpx = 0; $xpx < $wpx; ++ $xpx)
  9477. {
  9478. for($ypx = 0; $ypx < $hpx; ++ $ypx)
  9479. {
  9480. $color = imagecolorat($img, $xpx, $ypx);
  9481. $alpha = ($color >> 24); // shifts off the first 24 bits (where 8x3 are used for each color), and returns the remaining 7 allocated bits (commonly used for alpha)
  9482. $alpha = (((127 - $alpha) / 127) * 255); // GD alpha is only 7 bit (0 -> 127)
  9483. $alpha = $this->getGDgamma($alpha); // correct gamma
  9484. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  9485. }
  9486. }
  9487. imagepng($imgalpha, $tempfile_alpha);
  9488. imagedestroy($imgalpha);
  9489. // extract image without alpha channel
  9490. $imgplain = imagecreatetruecolor($wpx, $hpx);
  9491. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  9492. imagepng($imgplain, $tempfile_plain);
  9493. imagedestroy($imgplain);
  9494. }
  9495. // embed mask image
  9496. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  9497. // embed image, masked with previously embedded mask
  9498. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  9499. // remove temp files
  9500. unlink($tempfile_alpha);
  9501. unlink($tempfile_plain);
  9502. }
  9503. /**
  9504. * Correct the gamma value to be used with GD library
  9505. * @param float $v the gamma value to be corrected
  9506. * @access protected
  9507. * @since 4.3.007 (2008-12-04)
  9508. */
  9509. protected function getGDgamma($v)
  9510. {
  9511. return (pow(($v / 255), 2.2) * 255);
  9512. }
  9513. /**
  9514. * Performs a line break.
  9515. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  9516. * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  9517. * @param boolean $cell if true add the current left (or right o for RTL) padding to the X coordinate
  9518. * @access public
  9519. * @since 1.0
  9520. * @see Cell()
  9521. */
  9522. public function Ln($h = '', $cell = false)
  9523. {
  9524. if (($this->num_columns > 1) and ($this->y == $this->columns[$this->current_column]['y']) and isset($this->columns[$this->current_column]['x']) and ($this->x == $this->columns[$this->current_column]['x']))
  9525. {
  9526. // revove vertical space from the top of the column
  9527. return;
  9528. }
  9529. if ($cell)
  9530. {
  9531. if ($this->rtl)
  9532. {
  9533. $cellpadding = $this->cell_padding['R'];
  9534. }
  9535. else
  9536. {
  9537. $cellpadding = $this->cell_padding['L'];
  9538. }
  9539. }
  9540. else
  9541. {
  9542. $cellpadding = 0;
  9543. }
  9544. if ($this->rtl)
  9545. {
  9546. $this->x = $this->w - $this->rMargin - $cellpadding;
  9547. }
  9548. else
  9549. {
  9550. $this->x = $this->lMargin + $cellpadding;
  9551. }
  9552. if (is_string($h))
  9553. {
  9554. $this->y += $this->lasth;
  9555. }
  9556. else
  9557. {
  9558. $this->y += $h;
  9559. }
  9560. $this->newline = true;
  9561. }
  9562. /**
  9563. * Returns the relative X value of current position.
  9564. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  9565. * @return float
  9566. * @access public
  9567. * @since 1.2
  9568. * @see SetX(), GetY(), SetY()
  9569. */
  9570. public function GetX()
  9571. {
  9572. //Get x position
  9573. if ($this->rtl)
  9574. {
  9575. return ($this->w - $this->x);
  9576. }
  9577. else
  9578. {
  9579. return $this->x;
  9580. }
  9581. }
  9582. /**
  9583. * Returns the absolute X value of current position.
  9584. * @return float
  9585. * @access public
  9586. * @since 1.2
  9587. * @see SetX(), GetY(), SetY()
  9588. */
  9589. public function GetAbsX()
  9590. {
  9591. return $this->x;
  9592. }
  9593. /**
  9594. * Returns the ordinate of the current position.
  9595. * @return float
  9596. * @access public
  9597. * @since 1.0
  9598. * @see SetY(), GetX(), SetX()
  9599. */
  9600. public function GetY()
  9601. {
  9602. return $this->y;
  9603. }
  9604. /**
  9605. * Defines the abscissa of the current position.
  9606. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  9607. * @param float $x The value of the abscissa.
  9608. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  9609. * @access public
  9610. * @since 1.2
  9611. * @see GetX(), GetY(), SetY(), SetXY()
  9612. */
  9613. public function SetX($x, $rtloff = false)
  9614. {
  9615. if (! $rtloff and $this->rtl)
  9616. {
  9617. if ($x >= 0)
  9618. {
  9619. $this->x = $this->w - $x;
  9620. }
  9621. else
  9622. {
  9623. $this->x = abs($x);
  9624. }
  9625. }
  9626. else
  9627. {
  9628. if ($x >= 0)
  9629. {
  9630. $this->x = $x;
  9631. }
  9632. else
  9633. {
  9634. $this->x = $this->w + $x;
  9635. }
  9636. }
  9637. if ($this->x < 0)
  9638. {
  9639. $this->x = 0;
  9640. }
  9641. if ($this->x > $this->w)
  9642. {
  9643. $this->x = $this->w;
  9644. }
  9645. }
  9646. /**
  9647. * Moves the current abscissa back to the left margin and sets the ordinate.
  9648. * If the passed value is negative, it is relative to the bottom of the page.
  9649. * @param float $y The value of the ordinate.
  9650. * @param bool $resetx if true (default) reset the X position.
  9651. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  9652. * @access public
  9653. * @since 1.0
  9654. * @see GetX(), GetY(), SetY(), SetXY()
  9655. */
  9656. public function SetY($y, $resetx = true, $rtloff = false)
  9657. {
  9658. if ($resetx)
  9659. {
  9660. //reset x
  9661. if (! $rtloff and $this->rtl)
  9662. {
  9663. $this->x = $this->w - $this->rMargin;
  9664. }
  9665. else
  9666. {
  9667. $this->x = $this->lMargin;
  9668. }
  9669. }
  9670. if ($y >= 0)
  9671. {
  9672. $this->y = $y;
  9673. }
  9674. else
  9675. {
  9676. $this->y = $this->h + $y;
  9677. }
  9678. if ($this->y < 0)
  9679. {
  9680. $this->y = 0;
  9681. }
  9682. if ($this->y > $this->h)
  9683. {
  9684. $this->y = $this->h;
  9685. }
  9686. }
  9687. /**
  9688. * Defines the abscissa and ordinate of the current position.
  9689. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  9690. * @param float $x The value of the abscissa.
  9691. * @param float $y The value of the ordinate.
  9692. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  9693. * @access public
  9694. * @since 1.2
  9695. * @see SetX(), SetY()
  9696. */
  9697. public function SetXY($x, $y, $rtloff = false)
  9698. {
  9699. $this->SetY($y, false, $rtloff);
  9700. $this->SetX($x, $rtloff);
  9701. }
  9702. /**
  9703. * Send the document to a given destination: string, local file or browser.
  9704. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  9705. * The method first calls Close() if necessary to terminate the document.
  9706. * @param string $name The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  9707. * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li></ul>
  9708. * @access public
  9709. * @since 1.0
  9710. * @see Close()
  9711. */
  9712. public function Output($name = 'doc.pdf', $dest = 'I')
  9713. {
  9714. //Output PDF to some destination
  9715. //Finish document if necessary
  9716. if ($this->state < 3)
  9717. {
  9718. $this->Close();
  9719. }
  9720. //Normalize parameters
  9721. if (is_bool($dest))
  9722. {
  9723. $dest = $dest ? 'D' : 'F';
  9724. }
  9725. $dest = strtoupper($dest);
  9726. if ($dest{0} != 'F')
  9727. {
  9728. $name = preg_replace('/[\s]+/', '_', $name);
  9729. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  9730. }
  9731. if ($this->sign)
  9732. {
  9733. // *** apply digital signature to the document ***
  9734. // get the document content
  9735. $pdfdoc = $this->getBuffer();
  9736. // remove last newline
  9737. $pdfdoc = substr($pdfdoc, 0, - 1);
  9738. // Remove the original buffer
  9739. if (isset($this->diskcache) and $this->diskcache)
  9740. {
  9741. // remove buffer file from cache
  9742. unlink($this->buffer);
  9743. }
  9744. unset($this->buffer);
  9745. // remove filler space
  9746. $byterange_string_len = strlen($this->byterange_string);
  9747. // define the ByteRange
  9748. $byte_range = array();
  9749. $byte_range[0] = 0;
  9750. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  9751. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  9752. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  9753. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . substr($pdfdoc, $byte_range[2]);
  9754. // replace the ByteRange
  9755. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  9756. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  9757. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  9758. // write the document to a temporary folder
  9759. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  9760. $f = fopen($tempdoc, 'wb');
  9761. if (! $f)
  9762. {
  9763. $this->Error('Unable to create temporary file: ' . $tempdoc);
  9764. }
  9765. $pdfdoc_length = strlen($pdfdoc);
  9766. fwrite($f, $pdfdoc, $pdfdoc_length);
  9767. fclose($f);
  9768. // get digital signature via openssl library
  9769. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  9770. if (empty($this->signature_data['extracerts']))
  9771. {
  9772. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array(
  9773. $this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  9774. }
  9775. else
  9776. {
  9777. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array(
  9778. $this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']);
  9779. }
  9780. unlink($tempdoc);
  9781. // read signature
  9782. $signature = file_get_contents($tempsign);
  9783. unlink($tempsign);
  9784. // extract signature
  9785. $signature = substr($signature, $pdfdoc_length);
  9786. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  9787. $tmparr = explode("\n\n", $signature);
  9788. $signature = $tmparr[1];
  9789. unset($tmparr);
  9790. // decode signature
  9791. $signature = base64_decode(trim($signature));
  9792. // convert signature to hex
  9793. $signature = current(unpack('H*', $signature));
  9794. $signature = str_pad($signature, $this->signature_max_length, '0');
  9795. // Add signature to the document
  9796. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . '<' . $signature . '>' . substr($pdfdoc, $byte_range[1]);
  9797. $this->diskcache = false;
  9798. $this->buffer = &$pdfdoc;
  9799. $this->bufferlen = strlen($pdfdoc);
  9800. }
  9801. switch ($dest)
  9802. {
  9803. case 'I' :
  9804. {
  9805. // Send PDF to the standard output
  9806. if (ob_get_contents())
  9807. {
  9808. $this->Error('Some data has already been output, can\'t send PDF file');
  9809. }
  9810. if (php_sapi_name() != 'cli')
  9811. {
  9812. //We send to a browser
  9813. header('Content-Type: application/pdf');
  9814. if (headers_sent())
  9815. {
  9816. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9817. }
  9818. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9819. header('Pragma: public');
  9820. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9821. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9822. header('Content-Length: ' . $this->bufferlen);
  9823. header('Content-Disposition: inline; filename="' . basename($name) . '";');
  9824. }
  9825. echo $this->getBuffer();
  9826. break;
  9827. }
  9828. case 'D' :
  9829. {
  9830. // Download PDF as file
  9831. if (ob_get_contents())
  9832. {
  9833. $this->Error('Some data has already been output, can\'t send PDF file');
  9834. }
  9835. header('Content-Description: File Transfer');
  9836. if (headers_sent())
  9837. {
  9838. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9839. }
  9840. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9841. header('Pragma: public');
  9842. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9843. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9844. // force download dialog
  9845. header('Content-Type: application/force-download');
  9846. header('Content-Type: application/octet-stream', false);
  9847. header('Content-Type: application/download', false);
  9848. header('Content-Type: application/pdf', false);
  9849. // use the Content-Disposition header to supply a recommended filename
  9850. header('Content-Disposition: attachment; filename="' . basename($name) . '";');
  9851. header('Content-Transfer-Encoding: binary');
  9852. header('Content-Length: ' . $this->bufferlen);
  9853. echo $this->getBuffer();
  9854. break;
  9855. }
  9856. case 'F' :
  9857. case 'FI' :
  9858. case 'FD' :
  9859. {
  9860. // Save PDF to a local file
  9861. if ($this->diskcache)
  9862. {
  9863. copy($this->buffer, $name);
  9864. }
  9865. else
  9866. {
  9867. $f = fopen($name, 'wb');
  9868. if (! $f)
  9869. {
  9870. $this->Error('Unable to create output file: ' . $name);
  9871. }
  9872. fwrite($f, $this->getBuffer(), $this->bufferlen);
  9873. fclose($f);
  9874. }
  9875. if ($dest == 'FI')
  9876. {
  9877. // send headers to browser
  9878. header('Content-Type: application/pdf');
  9879. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9880. header('Pragma: public');
  9881. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9882. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9883. header('Content-Length: ' . filesize($name));
  9884. header('Content-Disposition: inline; filename="' . basename($name) . '";');
  9885. // send document to the browser
  9886. echo file_get_contents($name);
  9887. }
  9888. elseif ($dest == 'FD')
  9889. {
  9890. // send headers to browser
  9891. if (ob_get_contents())
  9892. {
  9893. $this->Error('Some data has already been output, can\'t send PDF file');
  9894. }
  9895. header('Content-Description: File Transfer');
  9896. if (headers_sent())
  9897. {
  9898. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9899. }
  9900. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9901. header('Pragma: public');
  9902. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9903. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9904. // force download dialog
  9905. header('Content-Type: application/force-download');
  9906. header('Content-Type: application/octet-stream', false);
  9907. header('Content-Type: application/download', false);
  9908. header('Content-Type: application/pdf', false);
  9909. // use the Content-Disposition header to supply a recommended filename
  9910. header('Content-Disposition: attachment; filename="' . basename($name) . '";');
  9911. header('Content-Transfer-Encoding: binary');
  9912. header('Content-Length: ' . filesize($name));
  9913. // send document to the browser
  9914. echo file_get_contents($name);
  9915. }
  9916. break;
  9917. }
  9918. case 'S' :
  9919. {
  9920. // Returns PDF as a string
  9921. return $this->getBuffer();
  9922. }
  9923. default :
  9924. {
  9925. $this->Error('Incorrect output destination: ' . $dest);
  9926. }
  9927. }
  9928. return '';
  9929. }
  9930. /**
  9931. * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  9932. * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  9933. * @param boolean $preserve_objcopy if true preserves the objcopy variable
  9934. * @access public
  9935. * @since 4.5.016 (2009-02-24)
  9936. */
  9937. public function _destroy($destroyall = false, $preserve_objcopy = false)
  9938. {
  9939. if ($destroyall and isset($this->diskcache) and $this->diskcache and (! $preserve_objcopy) and (! $this->empty_string($this->buffer)))
  9940. {
  9941. // remove buffer file from cache
  9942. unlink($this->buffer);
  9943. }
  9944. foreach (array_keys(get_object_vars($this)) as $val)
  9945. {
  9946. if ($destroyall or (($val != 'internal_encoding') and ($val != 'state') and ($val != 'bufferlen') and ($val != 'buffer') and ($val != 'diskcache') and ($val != 'sign') and ($val != 'signature_data') and ($val != 'signature_max_length') and ($val != 'byterange_string')))
  9947. {
  9948. if ((! $preserve_objcopy or ($val != 'objcopy')) and isset($this->$val))
  9949. {
  9950. unset($this->$val);
  9951. }
  9952. }
  9953. }
  9954. }
  9955. /**
  9956. * Check for locale-related bug
  9957. * @access protected
  9958. */
  9959. protected function _dochecks()
  9960. {
  9961. //Check for locale-related bug
  9962. if (1.1 == 1)
  9963. {
  9964. $this->Error('Don\'t alter the locale before including class file');
  9965. }
  9966. //Check for decimal separator
  9967. if (sprintf('%.1F', 1.0) != '1.0')
  9968. {
  9969. setlocale(LC_NUMERIC, 'C');
  9970. }
  9971. }
  9972. /**
  9973. * Return fonts path
  9974. * @return string
  9975. * @access protected
  9976. */
  9977. protected function _getfontpath()
  9978. {
  9979. if (! defined('K_PATH_FONTS') and is_dir(dirname(__FILE__) . '/fonts'))
  9980. {
  9981. define('K_PATH_FONTS', dirname(__FILE__) . '/fonts/');
  9982. }
  9983. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  9984. }
  9985. /**
  9986. * Output pages.
  9987. * @access protected
  9988. */
  9989. protected function _putpages()
  9990. {
  9991. $nb = $this->numpages;
  9992. if (! empty($this->AliasNbPages))
  9993. {
  9994. $nbs = $this->formatPageNumber($nb);
  9995. $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font
  9996. $alias_a = $this->_escape($this->AliasNbPages);
  9997. $alias_au = $this->_escape('{' . $this->AliasNbPages . '}');
  9998. if ($this->isunicode)
  9999. {
  10000. $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  10001. $alias_bu = $this->_escape($this->UTF8ToLatin1('{' . $this->AliasNbPages . '}'));
  10002. $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages, false, $this->tmprtl));
  10003. $alias_cu = $this->_escape($this->utf8StrRev('{' . $this->AliasNbPages . '}', false, $this->tmprtl));
  10004. }
  10005. }
  10006. if (! empty($this->AliasNumPage))
  10007. {
  10008. $alias_pa = $this->_escape($this->AliasNumPage);
  10009. $alias_pau = $this->_escape('{' . $this->AliasNumPage . '}');
  10010. if ($this->isunicode)
  10011. {
  10012. $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  10013. $alias_pbu = $this->_escape($this->UTF8ToLatin1('{' . $this->AliasNumPage . '}'));
  10014. $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage, false, $this->tmprtl));
  10015. $alias_pcu = $this->_escape($this->utf8StrRev('{' . $this->AliasNumPage . '}', false, $this->tmprtl));
  10016. }
  10017. }
  10018. $pagegroupnum = 0;
  10019. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  10020. for($n = 1; $n <= $nb; ++ $n)
  10021. {
  10022. $temppage = $this->getPageBuffer($n);
  10023. if (! empty($this->pagegroups))
  10024. {
  10025. if (isset($this->newpagegroup[$n]))
  10026. {
  10027. $pagegroupnum = 0;
  10028. }
  10029. ++ $pagegroupnum;
  10030. foreach ($this->pagegroups as $k => $v)
  10031. {
  10032. // replace total pages group numbers
  10033. $vs = $this->formatPageNumber($v);
  10034. $vu = $this->UTF8ToUTF16BE($vs, false);
  10035. $alias_ga = $this->_escape($k);
  10036. $alias_gau = $this->_escape('{' . $k . '}');
  10037. if ($this->isunicode)
  10038. {
  10039. $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
  10040. $alias_gbu = $this->_escape($this->UTF8ToLatin1('{' . $k . '}'));
  10041. $alias_gc = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  10042. $alias_gcu = $this->_escape($this->utf8StrRev('{' . $k . '}', false, $this->tmprtl));
  10043. }
  10044. $temppage = str_replace($alias_gau, $vu, $temppage);
  10045. if ($this->isunicode)
  10046. {
  10047. $temppage = str_replace($alias_gbu, $vu, $temppage);
  10048. $temppage = str_replace($alias_gcu, $vu, $temppage);
  10049. $temppage = str_replace($alias_gb, $vs, $temppage);
  10050. $temppage = str_replace($alias_gc, $vs, $temppage);
  10051. }
  10052. $temppage = str_replace($alias_ga, $vs, $temppage);
  10053. // replace page group numbers
  10054. $pvs = $this->formatPageNumber($pagegroupnum);
  10055. $pvu = $this->UTF8ToUTF16BE($pvs, false);
  10056. $pk = str_replace('{nb', '{pnb', $k);
  10057. $alias_pga = $this->_escape($pk);
  10058. $alias_pgau = $this->_escape('{' . $pk . '}');
  10059. if ($this->isunicode)
  10060. {
  10061. $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
  10062. $alias_pgbu = $this->_escape($this->UTF8ToLatin1('{' . $pk . '}'));
  10063. $alias_pgc = $this->_escape($this->utf8StrRev($pk, false, $this->tmprtl));
  10064. $alias_pgcu = $this->_escape($this->utf8StrRev('{' . $pk . '}', false, $this->tmprtl));
  10065. }
  10066. $temppage = str_replace($alias_pgau, $pvu, $temppage);
  10067. if ($this->isunicode)
  10068. {
  10069. $temppage = str_replace($alias_pgbu, $pvu, $temppage);
  10070. $temppage = str_replace($alias_pgcu, $pvu, $temppage);
  10071. $temppage = str_replace($alias_pgb, $pvs, $temppage);
  10072. $temppage = str_replace($alias_pgc, $pvs, $temppage);
  10073. }
  10074. $temppage = str_replace($alias_pga, $pvs, $temppage);
  10075. }
  10076. }
  10077. if (! empty($this->AliasNbPages))
  10078. {
  10079. // replace total pages number
  10080. $temppage = str_replace($alias_au, $nbu, $temppage);
  10081. if ($this->isunicode)
  10082. {
  10083. $temppage = str_replace($alias_bu, $nbu, $temppage);
  10084. $temppage = str_replace($alias_cu, $nbu, $temppage);
  10085. $temppage = str_replace($alias_b, $nbs, $temppage);
  10086. $temppage = str_replace($alias_c, $nbs, $temppage);
  10087. }
  10088. $temppage = str_replace($alias_a, $nbs, $temppage);
  10089. }
  10090. if (! empty($this->AliasNumPage))
  10091. {
  10092. // replace page number
  10093. $pnbs = $this->formatPageNumber($n);
  10094. $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font
  10095. $temppage = str_replace($alias_pau, $pnbu, $temppage);
  10096. if ($this->isunicode)
  10097. {
  10098. $temppage = str_replace($alias_pbu, $pnbu, $temppage);
  10099. $temppage = str_replace($alias_pcu, $pnbu, $temppage);
  10100. $temppage = str_replace($alias_pb, $pnbs, $temppage);
  10101. $temppage = str_replace($alias_pc, $pnbs, $temppage);
  10102. }
  10103. $temppage = str_replace($alias_pa, $pnbs, $temppage);
  10104. }
  10105. $temppage = str_replace($this->epsmarker, '', $temppage);
  10106. //Page
  10107. $this->page_obj_id[$n] = $this->_newobj();
  10108. $out = '<<';
  10109. $out .= ' /Type /Page';
  10110. $out .= ' /Parent 1 0 R';
  10111. $out .= ' /LastModified ' . $this->_datestring();
  10112. $out .= ' /Resources 2 0 R';
  10113. $boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  10114. foreach ($boxes as $box)
  10115. {
  10116. $out .= ' /' . $box;
  10117. $out .= sprintf(' [%.2F %.2F %.2F %.2F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  10118. }
  10119. if (isset($this->pagedim[$n]['BoxColorInfo']) and ! empty($this->pagedim[$n]['BoxColorInfo']))
  10120. {
  10121. $out .= ' /BoxColorInfo <<';
  10122. foreach ($boxes as $box)
  10123. {
  10124. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]))
  10125. {
  10126. $out .= ' /' . $box . ' <<';
  10127. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C']))
  10128. {
  10129. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  10130. $out .= ' /C [';
  10131. $out .= sprintf(' %.3F %.3F %.3F', $color[0] / 255, $color[1] / 255, $color[2] / 255);
  10132. $out .= ' ]';
  10133. }
  10134. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W']))
  10135. {
  10136. $out .= ' /W ' . ($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  10137. }
  10138. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S']))
  10139. {
  10140. $out .= ' /S /' . $this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  10141. }
  10142. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D']))
  10143. {
  10144. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  10145. $out .= ' /D [';
  10146. foreach ($dashes as $dash)
  10147. {
  10148. $out .= sprintf(' %.3F', ($dash * $this->k));
  10149. }
  10150. $out .= ' ]';
  10151. }
  10152. $out .= ' >>';
  10153. }
  10154. }
  10155. $out .= ' >>';
  10156. }
  10157. $out .= ' /Contents ' . ($this->n + 1) . ' 0 R';
  10158. $out .= ' /Rotate ' . $this->pagedim[$n]['Rotate'];
  10159. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  10160. if (isset($this->pagedim[$n]['trans']) and ! empty($this->pagedim[$n]['trans']))
  10161. {
  10162. // page transitions
  10163. if (isset($this->pagedim[$n]['trans']['Dur']))
  10164. {
  10165. $out .= ' /Dur ' . $this->pagedim[$n]['trans']['Dur'];
  10166. }
  10167. $out .= ' /Trans <<';
  10168. $out .= ' /Type /Trans';
  10169. if (isset($this->pagedim[$n]['trans']['S']))
  10170. {
  10171. $out .= ' /S /' . $this->pagedim[$n]['trans']['S'];
  10172. }
  10173. if (isset($this->pagedim[$n]['trans']['D']))
  10174. {
  10175. $out .= ' /D ' . $this->pagedim[$n]['trans']['D'];
  10176. }
  10177. if (isset($this->pagedim[$n]['trans']['Dm']))
  10178. {
  10179. $out .= ' /Dm /' . $this->pagedim[$n]['trans']['Dm'];
  10180. }
  10181. if (isset($this->pagedim[$n]['trans']['M']))
  10182. {
  10183. $out .= ' /M /' . $this->pagedim[$n]['trans']['M'];
  10184. }
  10185. if (isset($this->pagedim[$n]['trans']['Di']))
  10186. {
  10187. $out .= ' /Di ' . $this->pagedim[$n]['trans']['Di'];
  10188. }
  10189. if (isset($this->pagedim[$n]['trans']['SS']))
  10190. {
  10191. $out .= ' /SS ' . $this->pagedim[$n]['trans']['SS'];
  10192. }
  10193. if (isset($this->pagedim[$n]['trans']['B']))
  10194. {
  10195. $out .= ' /B ' . $this->pagedim[$n]['trans']['B'];
  10196. }
  10197. $out .= ' >>';
  10198. }
  10199. $out .= $this->_getannotsrefs($n);
  10200. $out .= ' /PZ ' . $this->pagedim[$n]['PZ'];
  10201. $out .= ' >>';
  10202. $out .= "\n" . 'endobj';
  10203. $this->_out($out);
  10204. //Page content
  10205. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  10206. $this->_newobj();
  10207. $p = $this->_getrawstream($p);
  10208. $this->_out('<<' . $filter . '/Length ' . strlen($p) . '>> stream' . "\n" . $p . "\n" . 'endstream' . "\n" . 'endobj');
  10209. if ($this->diskcache)
  10210. {
  10211. // remove temporary files
  10212. unlink($this->pages[$n]);
  10213. }
  10214. }
  10215. //Pages root
  10216. $out = $this->_getobj(1) . "\n";
  10217. $out .= '<< /Type /Pages /Kids [';
  10218. foreach ($this->page_obj_id as $page_obj)
  10219. {
  10220. $out .= ' ' . $page_obj . ' 0 R';
  10221. }
  10222. $out .= ' ] /Count ' . $nb . ' >>';
  10223. $out .= "\n" . 'endobj';
  10224. $this->_out($out);
  10225. }
  10226. /**
  10227. * Output references to page annotations
  10228. * @param int $n page number
  10229. * @access protected
  10230. * @author Nicola Asuni
  10231. * @since 4.7.000 (2008-08-29)
  10232. * @deprecated
  10233. */
  10234. protected function _putannotsrefs($n)
  10235. {
  10236. $this->_out($this->_getannotsrefs($n));
  10237. }
  10238. /**
  10239. * Get references to page annotations.
  10240. * @param int $n page number
  10241. * @return string
  10242. * @access protected
  10243. * @author Nicola Asuni
  10244. * @since 5.0.010 (2010-05-17)
  10245. */
  10246. protected function _getannotsrefs($n)
  10247. {
  10248. if (! (isset($this->PageAnnots[$n]) or ($this->sign and isset($this->signature_data['cert_type']))))
  10249. {
  10250. return '';
  10251. }
  10252. $out = ' /Annots [';
  10253. if (isset($this->PageAnnots[$n]))
  10254. {
  10255. foreach ($this->PageAnnots[$n] as $key => $val)
  10256. {
  10257. if (! in_array($val['n'], $this->radio_groups))
  10258. {
  10259. $out .= ' ' . $val['n'] . ' 0 R';
  10260. }
  10261. }
  10262. // add radiobutton groups
  10263. if (isset($this->radiobutton_groups[$n]))
  10264. {
  10265. foreach ($this->radiobutton_groups[$n] as $key => $data)
  10266. {
  10267. if (isset($data['n']))
  10268. {
  10269. $out .= ' ' . $data['n'] . ' 0 R';
  10270. }
  10271. }
  10272. }
  10273. }
  10274. if ($this->sign and ($n == $this->signature_appearance['page']) and isset($this->signature_data['cert_type']))
  10275. {
  10276. // set reference for signature object
  10277. $out .= ' ' . $this->sig_obj_id . ' 0 R';
  10278. }
  10279. $out .= ' ]';
  10280. return $out;
  10281. }
  10282. /**
  10283. * Output annotations objects for all pages.
  10284. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  10285. * See section 12.5 of PDF 32000_2008 reference.
  10286. * @access protected
  10287. * @author Nicola Asuni
  10288. * @since 4.0.018 (2008-08-06)
  10289. */
  10290. protected function _putannotsobjs()
  10291. {
  10292. // reset object counter
  10293. for($n = 1; $n <= $this->numpages; ++ $n)
  10294. {
  10295. if (isset($this->PageAnnots[$n]))
  10296. {
  10297. // set page annotations
  10298. foreach ($this->PageAnnots[$n] as $key => $pl)
  10299. {
  10300. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  10301. // create annotation object for grouping radiobuttons
  10302. if (isset($this->radiobutton_groups[$n][$pl['txt']]) and is_array($this->radiobutton_groups[$n][$pl['txt']]))
  10303. {
  10304. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  10305. $annots = '<<';
  10306. $annots .= ' /Type /Annot';
  10307. $annots .= ' /Subtype /Widget';
  10308. $annots .= ' /Rect [0 0 0 0]';
  10309. $annots .= ' /T ' . $this->_datastring($pl['txt'], $radio_button_obj_id);
  10310. $annots .= ' /FT /Btn';
  10311. $annots .= ' /Ff 49152';
  10312. $annots .= ' /Kids [';
  10313. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data)
  10314. {
  10315. if ($key !== 'n')
  10316. {
  10317. $annots .= ' ' . $data['kid'] . ' 0 R';
  10318. if ($data['def'] !== 'Off')
  10319. {
  10320. $defval = $data['def'];
  10321. }
  10322. }
  10323. }
  10324. $annots .= ' ]';
  10325. if (isset($defval))
  10326. {
  10327. $annots .= ' /V /' . $defval;
  10328. }
  10329. $annots .= ' >>';
  10330. $this->_out($this->_getobj($radio_button_obj_id) . "\n" . $annots . "\n" . 'endobj');
  10331. $this->form_obj_id[] = $radio_button_obj_id;
  10332. // store object id to be used on Parent entry of Kids
  10333. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  10334. }
  10335. $formfield = false;
  10336. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  10337. $a = $pl['x'] * $this->k;
  10338. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  10339. $c = $pl['w'] * $this->k;
  10340. $d = $pl['h'] * $this->k;
  10341. $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a + $c, $b + $d);
  10342. // create new annotation object
  10343. $annots = '<</Type /Annot';
  10344. $annots .= ' /Subtype /' . $pl['opt']['subtype'];
  10345. $annots .= ' /Rect [' . $rect . ']';
  10346. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  10347. if (isset($pl['opt']['ft']) and in_array($pl['opt']['ft'], $ft))
  10348. {
  10349. $annots .= ' /FT /' . $pl['opt']['ft'];
  10350. $formfield = true;
  10351. }
  10352. $annots .= ' /Contents ' . $this->_textstring($pl['txt'], $annot_obj_id);
  10353. $annots .= ' /P ' . $this->page_obj_id[$n] . ' 0 R';
  10354. $annots .= ' /NM ' . $this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  10355. $annots .= ' /M ' . $this->_datestring($annot_obj_id);
  10356. if (isset($pl['opt']['f']))
  10357. {
  10358. $val = 0;
  10359. if (is_array($pl['opt']['f']))
  10360. {
  10361. foreach ($pl['opt']['f'] as $f)
  10362. {
  10363. switch (strtolower($f))
  10364. {
  10365. case 'invisible' :
  10366. {
  10367. $val += 1 << 0;
  10368. break;
  10369. }
  10370. case 'hidden' :
  10371. {
  10372. $val += 1 << 1;
  10373. break;
  10374. }
  10375. case 'print' :
  10376. {
  10377. $val += 1 << 2;
  10378. break;
  10379. }
  10380. case 'nozoom' :
  10381. {
  10382. $val += 1 << 3;
  10383. break;
  10384. }
  10385. case 'norotate' :
  10386. {
  10387. $val += 1 << 4;
  10388. break;
  10389. }
  10390. case 'noview' :
  10391. {
  10392. $val += 1 << 5;
  10393. break;
  10394. }
  10395. case 'readonly' :
  10396. {
  10397. $val += 1 << 6;
  10398. break;
  10399. }
  10400. case 'locked' :
  10401. {
  10402. $val += 1 << 8;
  10403. break;
  10404. }
  10405. case 'togglenoview' :
  10406. {
  10407. $val += 1 << 9;
  10408. break;
  10409. }
  10410. case 'lockedcontents' :
  10411. {
  10412. $val += 1 << 10;
  10413. break;
  10414. }
  10415. default :
  10416. {
  10417. break;
  10418. }
  10419. }
  10420. }
  10421. }
  10422. else
  10423. {
  10424. $val = intval($pl['opt']['f']);
  10425. }
  10426. $annots .= ' /F ' . intval($val);
  10427. }
  10428. if (isset($pl['opt']['as']) and is_string($pl['opt']['as']))
  10429. {
  10430. $annots .= ' /AS /' . $pl['opt']['as'];
  10431. }
  10432. if (isset($pl['opt']['ap']))
  10433. {
  10434. // appearance stream
  10435. $annots .= ' /AP <<';
  10436. if (is_array($pl['opt']['ap']))
  10437. {
  10438. foreach ($pl['opt']['ap'] as $apmode => $apdef)
  10439. {
  10440. // $apmode can be: n = normal; r = rollover; d = down;
  10441. $annots .= ' /' . strtoupper($apmode);
  10442. if (is_array($apdef))
  10443. {
  10444. $annots .= ' <<';
  10445. foreach ($apdef as $apstate => $stream)
  10446. {
  10447. // reference to XObject that define the appearance for this mode-state
  10448. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  10449. $annots .= ' /' . $apstate . ' ' . $apsobjid . ' 0 R';
  10450. }
  10451. $annots .= ' >>';
  10452. }
  10453. else
  10454. {
  10455. // reference to XObject that define the appearance for this mode
  10456. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  10457. $annots .= ' ' . $apsobjid . ' 0 R';
  10458. }
  10459. }
  10460. }
  10461. else
  10462. {
  10463. $annots .= $pl['opt']['ap'];
  10464. }
  10465. $annots .= ' >>';
  10466. }
  10467. if (isset($pl['opt']['bs']) and (is_array($pl['opt']['bs'])))
  10468. {
  10469. $annots .= ' /BS <<';
  10470. $annots .= ' /Type /Border';
  10471. if (isset($pl['opt']['bs']['w']))
  10472. {
  10473. $annots .= ' /W ' . intval($pl['opt']['bs']['w']);
  10474. }
  10475. $bstyles = array('S', 'D', 'B', 'I', 'U');
  10476. if (isset($pl['opt']['bs']['s']) and in_array($pl['opt']['bs']['s'], $bstyles))
  10477. {
  10478. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  10479. }
  10480. if (isset($pl['opt']['bs']['d']) and (is_array($pl['opt']['bs']['d'])))
  10481. {
  10482. $annots .= ' /D [';
  10483. foreach ($pl['opt']['bs']['d'] as $cord)
  10484. {
  10485. $annots .= ' ' . intval($cord);
  10486. }
  10487. $annots .= ']';
  10488. }
  10489. $annots .= ' >>';
  10490. }
  10491. else
  10492. {
  10493. $annots .= ' /Border [';
  10494. if (isset($pl['opt']['border']) and (count($pl['opt']['border']) >= 3))
  10495. {
  10496. $annots .= intval($pl['opt']['border'][0]) . ' ';
  10497. $annots .= intval($pl['opt']['border'][1]) . ' ';
  10498. $annots .= intval($pl['opt']['border'][2]);
  10499. if (isset($pl['opt']['border'][3]) and is_array($pl['opt']['border'][3]))
  10500. {
  10501. $annots .= ' [';
  10502. foreach ($pl['opt']['border'][3] as $dash)
  10503. {
  10504. $annots .= intval($dash) . ' ';
  10505. }
  10506. $annots .= ']';
  10507. }
  10508. }
  10509. else
  10510. {
  10511. $annots .= '0 0 0';
  10512. }
  10513. $annots .= ']';
  10514. }
  10515. if (isset($pl['opt']['be']) and (is_array($pl['opt']['be'])))
  10516. {
  10517. $annots .= ' /BE <<';
  10518. $bstyles = array('S', 'C');
  10519. if (isset($pl['opt']['be']['s']) and in_array($pl['opt']['be']['s'], $markups))
  10520. {
  10521. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  10522. }
  10523. else
  10524. {
  10525. $annots .= ' /S /S';
  10526. }
  10527. if (isset($pl['opt']['be']['i']) and ($pl['opt']['be']['i'] >= 0) and ($pl['opt']['be']['i'] <= 2))
  10528. {
  10529. $annots .= ' /I ' . sprintf(' %.4F', $pl['opt']['be']['i']);
  10530. }
  10531. $annots .= '>>';
  10532. }
  10533. if (isset($pl['opt']['c']) and (is_array($pl['opt']['c'])) and ! empty($pl['opt']['c']))
  10534. {
  10535. $annots .= ' /C [';
  10536. foreach ($pl['opt']['c'] as $col)
  10537. {
  10538. $col = intval($col);
  10539. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  10540. $annots .= sprintf(' %.4F', $color);
  10541. }
  10542. $annots .= ']';
  10543. }
  10544. //$annots .= ' /StructParent ';
  10545. //$annots .= ' /OC ';
  10546. $markups = array('text', 'freetext', 'line', 'square',
  10547. 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp',
  10548. 'caret', 'ink', 'fileattachment', 'sound');
  10549. if (in_array(strtolower($pl['opt']['subtype']), $markups))
  10550. {
  10551. // this is a markup type
  10552. if (isset($pl['opt']['t']) and is_string($pl['opt']['t']))
  10553. {
  10554. $annots .= ' /T ' . $this->_textstring($pl['opt']['t'], $annot_obj_id);
  10555. }
  10556. //$annots .= ' /Popup ';
  10557. if (isset($pl['opt']['ca']))
  10558. {
  10559. $annots .= ' /CA ' . sprintf('%.4F', floatval($pl['opt']['ca']));
  10560. }
  10561. if (isset($pl['opt']['rc']))
  10562. {
  10563. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc'], $annot_obj_id);
  10564. }
  10565. $annots .= ' /CreationDate ' . $this->_datestring($annot_obj_id);
  10566. //$annots .= ' /IRT ';
  10567. if (isset($pl['opt']['subj']))
  10568. {
  10569. $annots .= ' /Subj ' . $this->_textstring($pl['opt']['subj'], $annot_obj_id);
  10570. }
  10571. //$annots .= ' /RT ';
  10572. //$annots .= ' /IT ';
  10573. //$annots .= ' /ExData ';
  10574. }
  10575. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt',
  10576. 'ROpenArrow', 'RClosedArrow', 'Slash');
  10577. // Annotation types
  10578. switch (strtolower($pl['opt']['subtype']))
  10579. {
  10580. case 'text' :
  10581. {
  10582. if (isset($pl['opt']['open']))
  10583. {
  10584. $annots .= ' /Open ' . (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  10585. }
  10586. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note',
  10587. 'Paragraph');
  10588. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  10589. {
  10590. $annots .= ' /Name /' . $pl['opt']['name'];
  10591. }
  10592. else
  10593. {
  10594. $annots .= ' /Name /Note';
  10595. }
  10596. $statemodels = array('Marked', 'Review');
  10597. if (isset($pl['opt']['statemodel']) and in_array($pl['opt']['statemodel'], $statemodels))
  10598. {
  10599. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  10600. }
  10601. else
  10602. {
  10603. $pl['opt']['statemodel'] = 'Marked';
  10604. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  10605. }
  10606. if ($pl['opt']['statemodel'] == 'Marked')
  10607. {
  10608. $states = array('Accepted', 'Unmarked');
  10609. }
  10610. else
  10611. {
  10612. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  10613. }
  10614. if (isset($pl['opt']['state']) and in_array($pl['opt']['state'], $states))
  10615. {
  10616. $annots .= ' /State /' . $pl['opt']['state'];
  10617. }
  10618. else
  10619. {
  10620. if ($pl['opt']['statemodel'] == 'Marked')
  10621. {
  10622. $annots .= ' /State /Unmarked';
  10623. }
  10624. else
  10625. {
  10626. $annots .= ' /State /None';
  10627. }
  10628. }
  10629. break;
  10630. }
  10631. case 'link' :
  10632. {
  10633. if (is_string($pl['txt']))
  10634. {
  10635. // external URI link
  10636. $annots .= ' /A <</S /URI /URI ' . $this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id) . '>>';
  10637. }
  10638. else
  10639. {
  10640. // internal link
  10641. $l = $this->links[$pl['txt']];
  10642. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  10643. }
  10644. $hmodes = array('N', 'I', 'O', 'P');
  10645. if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmodes))
  10646. {
  10647. $annots .= ' /H /' . $pl['opt']['h'];
  10648. }
  10649. else
  10650. {
  10651. $annots .= ' /H /I';
  10652. }
  10653. //$annots .= ' /PA ';
  10654. //$annots .= ' /Quadpoints ';
  10655. break;
  10656. }
  10657. case 'freetext' :
  10658. {
  10659. if (isset($pl['opt']['da']) and ! empty($pl['opt']['da']))
  10660. {
  10661. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  10662. }
  10663. if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2))
  10664. {
  10665. $annots .= ' /Q ' . intval($pl['opt']['q']);
  10666. }
  10667. if (isset($pl['opt']['rc']))
  10668. {
  10669. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc'], $annot_obj_id);
  10670. }
  10671. if (isset($pl['opt']['ds']))
  10672. {
  10673. $annots .= ' /DS ' . $this->_textstring($pl['opt']['ds'], $annot_obj_id);
  10674. }
  10675. if (isset($pl['opt']['cl']) and is_array($pl['opt']['cl']))
  10676. {
  10677. $annots .= ' /CL [';
  10678. foreach ($pl['opt']['cl'] as $cl)
  10679. {
  10680. $annots .= sprintf('%.4F ', $cl * $this->k);
  10681. }
  10682. $annots .= ']';
  10683. }
  10684. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  10685. if (isset($pl['opt']['it']) and in_array($pl['opt']['it'], $tfit))
  10686. {
  10687. $annots .= ' /IT /' . $pl['opt']['it'];
  10688. }
  10689. if (isset($pl['opt']['rd']) and is_array($pl['opt']['rd']))
  10690. {
  10691. $l = $pl['opt']['rd'][0] * $this->k;
  10692. $r = $pl['opt']['rd'][1] * $this->k;
  10693. $t = $pl['opt']['rd'][2] * $this->k;
  10694. $b = $pl['opt']['rd'][3] * $this->k;
  10695. $annots .= ' /RD [' . sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b) . ']';
  10696. }
  10697. if (isset($pl['opt']['le']) and in_array($pl['opt']['le'], $lineendings))
  10698. {
  10699. $annots .= ' /LE /' . $pl['opt']['le'];
  10700. }
  10701. break;
  10702. }
  10703. case 'line' :
  10704. {
  10705. break;
  10706. }
  10707. case 'square' :
  10708. {
  10709. break;
  10710. }
  10711. case 'circle' :
  10712. {
  10713. break;
  10714. }
  10715. case 'polygon' :
  10716. {
  10717. break;
  10718. }
  10719. case 'polyline' :
  10720. {
  10721. break;
  10722. }
  10723. case 'highlight' :
  10724. {
  10725. break;
  10726. }
  10727. case 'underline' :
  10728. {
  10729. break;
  10730. }
  10731. case 'squiggly' :
  10732. {
  10733. break;
  10734. }
  10735. case 'strikeout' :
  10736. {
  10737. break;
  10738. }
  10739. case 'stamp' :
  10740. {
  10741. break;
  10742. }
  10743. case 'caret' :
  10744. {
  10745. break;
  10746. }
  10747. case 'ink' :
  10748. {
  10749. break;
  10750. }
  10751. case 'popup' :
  10752. {
  10753. break;
  10754. }
  10755. case 'fileattachment' :
  10756. {
  10757. if (! isset($pl['opt']['fs']))
  10758. {
  10759. break;
  10760. }
  10761. $filename = basename($pl['opt']['fs']);
  10762. if (isset($this->embeddedfiles[$filename]['n']))
  10763. {
  10764. $annots .= ' /FS <</Type /Filespec /F ' . $this->_datastring($filename, $annot_obj_id) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  10765. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  10766. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  10767. {
  10768. $annots .= ' /Name /' . $pl['opt']['name'];
  10769. }
  10770. else
  10771. {
  10772. $annots .= ' /Name /PushPin';
  10773. }
  10774. }
  10775. break;
  10776. }
  10777. case 'sound' :
  10778. {
  10779. if (! isset($pl['opt']['fs']))
  10780. {
  10781. break;
  10782. }
  10783. $filename = basename($pl['opt']['fs']);
  10784. if (isset($this->embeddedfiles[$filename]['n']))
  10785. {
  10786. // ... TO BE COMPLETED ...
  10787. // /R /C /B /E /CO /CP
  10788. $annots .= ' /Sound <</Type /Filespec /F ' . $this->_datastring($filename, $annot_obj_id) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  10789. $iconsapp = array('Speaker', 'Mic');
  10790. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  10791. {
  10792. $annots .= ' /Name /' . $pl['opt']['name'];
  10793. }
  10794. else
  10795. {
  10796. $annots .= ' /Name /Speaker';
  10797. }
  10798. }
  10799. break;
  10800. }
  10801. case 'movie' :
  10802. {
  10803. break;
  10804. }
  10805. case 'widget' :
  10806. {
  10807. $hmode = array('N', 'I', 'O', 'P', 'T');
  10808. if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmode))
  10809. {
  10810. $annots .= ' /H /' . $pl['opt']['h'];
  10811. }
  10812. if (isset($pl['opt']['mk']) and (is_array($pl['opt']['mk'])) and ! empty($pl['opt']['mk']))
  10813. {
  10814. $annots .= ' /MK <<';
  10815. if (isset($pl['opt']['mk']['r']))
  10816. {
  10817. $annots .= ' /R ' . $pl['opt']['mk']['r'];
  10818. }
  10819. if (isset($pl['opt']['mk']['bc']) and (is_array($pl['opt']['mk']['bc'])))
  10820. {
  10821. $annots .= ' /BC [';
  10822. foreach ($pl['opt']['mk']['bc'] as $col)
  10823. {
  10824. $col = intval($col);
  10825. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  10826. $annots .= sprintf(' %.2F', $color);
  10827. }
  10828. $annots .= ']';
  10829. }
  10830. if (isset($pl['opt']['mk']['bg']) and (is_array($pl['opt']['mk']['bg'])))
  10831. {
  10832. $annots .= ' /BG [';
  10833. foreach ($pl['opt']['mk']['bg'] as $col)
  10834. {
  10835. $col = intval($col);
  10836. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  10837. $annots .= sprintf(' %.2F', $color);
  10838. }
  10839. $annots .= ']';
  10840. }
  10841. if (isset($pl['opt']['mk']['ca']))
  10842. {
  10843. $annots .= ' /CA ' . $pl['opt']['mk']['ca'];
  10844. }
  10845. if (isset($pl['opt']['mk']['rc']))
  10846. {
  10847. $annots .= ' /RC ' . $pl['opt']['mk']['rc'];
  10848. }
  10849. if (isset($pl['opt']['mk']['ac']))
  10850. {
  10851. $annots .= ' /AC ' . $pl['opt']['mk']['ac'];
  10852. }
  10853. if (isset($pl['opt']['mk']['i']))
  10854. {
  10855. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  10856. if ($info !== false)
  10857. {
  10858. $annots .= ' /I ' . $info['n'] . ' 0 R';
  10859. }
  10860. }
  10861. if (isset($pl['opt']['mk']['ri']))
  10862. {
  10863. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  10864. if ($info !== false)
  10865. {
  10866. $annots .= ' /RI ' . $info['n'] . ' 0 R';
  10867. }
  10868. }
  10869. if (isset($pl['opt']['mk']['ix']))
  10870. {
  10871. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  10872. if ($info !== false)
  10873. {
  10874. $annots .= ' /IX ' . $info['n'] . ' 0 R';
  10875. }
  10876. }
  10877. if (isset($pl['opt']['mk']['if']) and (is_array($pl['opt']['mk']['if'])) and ! empty($pl['opt']['mk']['if']))
  10878. {
  10879. $annots .= ' /IF <<';
  10880. $if_sw = array('A', 'B', 'S', 'N');
  10881. if (isset($pl['opt']['mk']['if']['sw']) and in_array($pl['opt']['mk']['if']['sw'], $if_sw))
  10882. {
  10883. $annots .= ' /SW /' . $pl['opt']['mk']['if']['sw'];
  10884. }
  10885. $if_s = array('A', 'P');
  10886. if (isset($pl['opt']['mk']['if']['s']) and in_array($pl['opt']['mk']['if']['s'], $if_s))
  10887. {
  10888. $annots .= ' /S /' . $pl['opt']['mk']['if']['s'];
  10889. }
  10890. if (isset($pl['opt']['mk']['if']['a']) and (is_array($pl['opt']['mk']['if']['a'])) and ! empty($pl['opt']['mk']['if']['a']))
  10891. {
  10892. $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  10893. }
  10894. if (isset($pl['opt']['mk']['if']['fb']) and ($pl['opt']['mk']['if']['fb']))
  10895. {
  10896. $annots .= ' /FB true';
  10897. }
  10898. $annots .= '>>';
  10899. }
  10900. if (isset($pl['opt']['mk']['tp']) and ($pl['opt']['mk']['tp'] >= 0) and ($pl['opt']['mk']['tp'] <= 6))
  10901. {
  10902. $annots .= ' /TP ' . intval($pl['opt']['mk']['tp']);
  10903. }
  10904. else
  10905. {
  10906. $annots .= ' /TP 0';
  10907. }
  10908. $annots .= '>>';
  10909. } // end MK
  10910. // --- Entries for field dictionaries ---
  10911. if (isset($this->radiobutton_groups[$n][$pl['txt']]))
  10912. {
  10913. // set parent
  10914. $annots .= ' /Parent ' . $this->radiobutton_groups[$n][$pl['txt']] . ' 0 R';
  10915. }
  10916. if (isset($pl['opt']['t']) and is_string($pl['opt']['t']))
  10917. {
  10918. $annots .= ' /T ' . $this->_datastring($pl['opt']['t'], $annot_obj_id);
  10919. }
  10920. if (isset($pl['opt']['tu']) and is_string($pl['opt']['tu']))
  10921. {
  10922. $annots .= ' /TU ' . $this->_datastring($pl['opt']['tu'], $annot_obj_id);
  10923. }
  10924. if (isset($pl['opt']['tm']) and is_string($pl['opt']['tm']))
  10925. {
  10926. $annots .= ' /TM ' . $this->_datastring($pl['opt']['tm'], $annot_obj_id);
  10927. }
  10928. if (isset($pl['opt']['ff']))
  10929. {
  10930. if (is_array($pl['opt']['ff']))
  10931. {
  10932. // array of bit settings
  10933. $flag = 0;
  10934. foreach ($pl['opt']['ff'] as $val)
  10935. {
  10936. $flag += 1 << ($val - 1);
  10937. }
  10938. }
  10939. else
  10940. {
  10941. $flag = intval($pl['opt']['ff']);
  10942. }
  10943. $annots .= ' /Ff ' . $flag;
  10944. }
  10945. if (isset($pl['opt']['maxlen']))
  10946. {
  10947. $annots .= ' /MaxLen ' . intval($pl['opt']['maxlen']);
  10948. }
  10949. if (isset($pl['opt']['v']))
  10950. {
  10951. $annots .= ' /V';
  10952. if (is_array($pl['opt']['v']))
  10953. {
  10954. foreach ($pl['opt']['v'] as $optval)
  10955. {
  10956. if (is_float($optval))
  10957. {
  10958. $optval = sprintf('%.2F', $optval);
  10959. }
  10960. $annots .= ' ' . $optval;
  10961. }
  10962. }
  10963. else
  10964. {
  10965. $annots .= ' ' . $this->_textstring($pl['opt']['v'], $annot_obj_id);
  10966. }
  10967. }
  10968. if (isset($pl['opt']['dv']))
  10969. {
  10970. $annots .= ' /DV';
  10971. if (is_array($pl['opt']['dv']))
  10972. {
  10973. foreach ($pl['opt']['dv'] as $optval)
  10974. {
  10975. if (is_float($optval))
  10976. {
  10977. $optval = sprintf('%.2F', $optval);
  10978. }
  10979. $annots .= ' ' . $optval;
  10980. }
  10981. }
  10982. else
  10983. {
  10984. $annots .= ' ' . $this->_textstring($pl['opt']['dv'], $annot_obj_id);
  10985. }
  10986. }
  10987. if (isset($pl['opt']['rv']))
  10988. {
  10989. $annots .= ' /RV';
  10990. if (is_array($pl['opt']['rv']))
  10991. {
  10992. foreach ($pl['opt']['rv'] as $optval)
  10993. {
  10994. if (is_float($optval))
  10995. {
  10996. $optval = sprintf('%.2F', $optval);
  10997. }
  10998. $annots .= ' ' . $optval;
  10999. }
  11000. }
  11001. else
  11002. {
  11003. $annots .= ' ' . $this->_textstring($pl['opt']['rv'], $annot_obj_id);
  11004. }
  11005. }
  11006. if (isset($pl['opt']['a']) and ! empty($pl['opt']['a']))
  11007. {
  11008. $annots .= ' /A << ' . $pl['opt']['a'] . ' >>';
  11009. }
  11010. if (isset($pl['opt']['aa']) and ! empty($pl['opt']['aa']))
  11011. {
  11012. $annots .= ' /AA << ' . $pl['opt']['aa'] . ' >>';
  11013. }
  11014. if (isset($pl['opt']['da']) and ! empty($pl['opt']['da']))
  11015. {
  11016. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  11017. }
  11018. if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2))
  11019. {
  11020. $annots .= ' /Q ' . intval($pl['opt']['q']);
  11021. }
  11022. if (isset($pl['opt']['opt']) and (is_array($pl['opt']['opt'])) and ! empty($pl['opt']['opt']))
  11023. {
  11024. $annots .= ' /Opt [';
  11025. foreach ($pl['opt']['opt'] as $copt)
  11026. {
  11027. if (is_array($copt))
  11028. {
  11029. $annots .= ' [' . $this->_textstring($copt[0], $annot_obj_id) . ' ' . $this->_textstring($copt[1], $annot_obj_id) . ']';
  11030. }
  11031. else
  11032. {
  11033. $annots .= ' ' . $this->_textstring($copt, $annot_obj_id);
  11034. }
  11035. }
  11036. $annots .= ']';
  11037. }
  11038. if (isset($pl['opt']['ti']))
  11039. {
  11040. $annots .= ' /TI ' . intval($pl['opt']['ti']);
  11041. }
  11042. if (isset($pl['opt']['i']) and (is_array($pl['opt']['i'])) and ! empty($pl['opt']['i']))
  11043. {
  11044. $annots .= ' /I [';
  11045. foreach ($pl['opt']['i'] as $copt)
  11046. {
  11047. $annots .= intval($copt) . ' ';
  11048. }
  11049. $annots .= ']';
  11050. }
  11051. break;
  11052. }
  11053. case 'screen' :
  11054. {
  11055. break;
  11056. }
  11057. case 'printermark' :
  11058. {
  11059. break;
  11060. }
  11061. case 'trapnet' :
  11062. {
  11063. break;
  11064. }
  11065. case 'watermark' :
  11066. {
  11067. break;
  11068. }
  11069. case '3d' :
  11070. {
  11071. break;
  11072. }
  11073. default :
  11074. {
  11075. break;
  11076. }
  11077. }
  11078. $annots .= '>>';
  11079. // create new annotation object
  11080. $this->_out($this->_getobj($annot_obj_id) . "\n" . $annots . "\n" . 'endobj');
  11081. if ($formfield and ! isset($this->radiobutton_groups[$n][$pl['txt']]))
  11082. {
  11083. // store reference of form object
  11084. $this->form_obj_id[] = $annot_obj_id;
  11085. }
  11086. }
  11087. }
  11088. } // end for each page
  11089. }
  11090. /**
  11091. * Put appearance streams XObject used to define annotation's appearance states
  11092. * @param int $w annotation width
  11093. * @param int $h annotation height
  11094. * @param string $stream appearance stream
  11095. * @return int object ID
  11096. * @access protected
  11097. * @since 4.8.001 (2009-09-09)
  11098. */
  11099. protected function _putAPXObject($w = 0, $h = 0, $stream = '')
  11100. {
  11101. $stream = trim($stream);
  11102. $out = $this->_getobj() . "\n";
  11103. $this->xobjects['AX' . $this->n] = array('n' => $this->n);
  11104. $out .= '<<';
  11105. $out .= ' /Type /XObject';
  11106. $out .= ' /Subtype /Form';
  11107. $out .= ' /FormType 1';
  11108. if ($this->compress)
  11109. {
  11110. $stream = gzcompress($stream);
  11111. $out .= ' /Filter /FlateDecode';
  11112. }
  11113. $rect = sprintf('%.2F %.2F', $w, $h);
  11114. $out .= ' /BBox [0 0 ' . $rect . ']';
  11115. $out .= ' /Matrix [1 0 0 1 0 0]';
  11116. $out .= ' /Resources <<';
  11117. $out .= ' /ProcSet [/PDF /Text]';
  11118. $out .= ' /Font <<';
  11119. foreach ($this->annotation_fonts as $fontkey => $fontid)
  11120. {
  11121. $out .= ' /F' . $fontid . ' ' . $this->font_obj_ids[$fontkey] . ' 0 R';
  11122. }
  11123. $out .= ' >>';
  11124. $out .= ' >>';
  11125. $stream = $this->_getrawstream($stream);
  11126. $out .= ' /Length ' . strlen($stream);
  11127. $out .= ' >>';
  11128. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  11129. $out .= "\n" . 'endobj';
  11130. $this->_out($out);
  11131. return $this->n;
  11132. }
  11133. /**
  11134. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  11135. * @param string $str string from where to extract value
  11136. * @param int $offset point from where to read the data
  11137. * @return int 32 bit value
  11138. * @author Nicola Asuni
  11139. * @access protected
  11140. * @since 5.2.000 (2010-06-02)
  11141. */
  11142. protected function _getULONG(&$str, &$offset)
  11143. {
  11144. $v = unpack('Ni', substr($str, $offset, 4));
  11145. $offset += 4;
  11146. return $v['i'];
  11147. }
  11148. /**
  11149. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  11150. * @param string $str string from where to extract value
  11151. * @param int $offset point from where to read the data
  11152. * @return int 16 bit value
  11153. * @author Nicola Asuni
  11154. * @access protected
  11155. * @since 5.2.000 (2010-06-02)
  11156. */
  11157. protected function _getUSHORT(&$str, &$offset)
  11158. {
  11159. $v = unpack('ni', substr($str, $offset, 2));
  11160. $offset += 2;
  11161. return $v['i'];
  11162. }
  11163. /**
  11164. * Get SHORT from string (Big Endian 16-bit signed integer).
  11165. * @param string $str string from where to extract value
  11166. * @param int $offset point from where to read the data
  11167. * @return int 16 bit value
  11168. * @author Nicola Asuni
  11169. * @access protected
  11170. * @since 5.2.000 (2010-06-02)
  11171. */
  11172. protected function _getSHORT(&$str, &$offset)
  11173. {
  11174. $v = unpack('si', substr($str, $offset, 2));
  11175. $offset += 2;
  11176. return $v['i'];
  11177. }
  11178. /**
  11179. * Get BYTE from string (8-bit unsigned integer).
  11180. * @param string $str string from where to extract value
  11181. * @param int $offset point from where to read the data
  11182. * @return int 8 bit value
  11183. * @author Nicola Asuni
  11184. * @access protected
  11185. * @since 5.2.000 (2010-06-02)
  11186. */
  11187. protected function _getBYTE(&$str, &$offset)
  11188. {
  11189. $v = unpack('Ci', substr($str, $offset, 1));
  11190. ++ $offset;
  11191. return $v['i'];
  11192. }
  11193. /**
  11194. * Returns a subset of the TrueType font data without the unused glyphs.
  11195. * @param string $font TrueType font data
  11196. * @param array $subsetchars array of used characters (the glyphs to keep)
  11197. * @return string a subset of TrueType font data without the unused glyphs
  11198. * @author Nicola Asuni
  11199. * @access protected
  11200. * @since 5.2.000 (2010-06-02)
  11201. */
  11202. protected function _getTrueTypeFontSubset($font, $subsetchars)
  11203. {
  11204. ksort($subsetchars);
  11205. $offset = 0; // offset position of the font data
  11206. if ($this->_getULONG($font, $offset) != 0x10000)
  11207. {
  11208. // sfnt version must be 0x00010000 for TrueType version 1.0.
  11209. return $font;
  11210. }
  11211. // get number of tables
  11212. $numTables = $this->_getUSHORT($font, $offset);
  11213. // skip searchRange, entrySelector and rangeShift
  11214. $offset += 6;
  11215. // tables array
  11216. $table = array();
  11217. // for each table
  11218. for($i = 0; $i < $numTables; ++ $i)
  11219. {
  11220. // get table info
  11221. $tag = substr($font, $offset, 4);
  11222. $offset += 4;
  11223. $table[$tag] = array();
  11224. $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
  11225. $table[$tag]['offset'] = $this->_getULONG($font, $offset);
  11226. $table[$tag]['length'] = $this->_getULONG($font, $offset);
  11227. }
  11228. // check magicNumber
  11229. $offset = $table['head']['offset'] + 12;
  11230. if ($this->_getULONG($font, $offset) != 0x5F0F3CF5)
  11231. {
  11232. // magicNumber must be 0x5F0F3CF5
  11233. return $font;
  11234. }
  11235. // get offset mode (indexToLocFormat : 0 = short, 1 = long)
  11236. $offset = $table['head']['offset'] + 50;
  11237. $short_offset = ($this->_getSHORT($font, $offset) == 0);
  11238. // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
  11239. $indexToLoc = array();
  11240. $offset = $table['loca']['offset'];
  11241. if ($short_offset)
  11242. {
  11243. // short version
  11244. $n = $table['loca']['length'] / 2; // numGlyphs + 1
  11245. for($i = 0; $i < $n; ++ $i)
  11246. {
  11247. $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
  11248. }
  11249. }
  11250. else
  11251. {
  11252. // long version
  11253. $n = $table['loca']['length'] / 4; // numGlyphs + 1
  11254. for($i = 0; $i < $n; ++ $i)
  11255. {
  11256. $indexToLoc[$i] = $this->_getULONG($font, $offset);
  11257. }
  11258. }
  11259. // get glyphs indexes of chars from cmap table
  11260. $subsetglyphs = array(); // glyph IDs on key
  11261. $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
  11262. $offset = $table['cmap']['offset'] + 2;
  11263. $numEncodingTables = $this->_getUSHORT($font, $offset);
  11264. $encodingTables = array();
  11265. for($i = 0; $i < $numEncodingTables; ++ $i)
  11266. {
  11267. $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
  11268. $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
  11269. $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
  11270. }
  11271. foreach ($encodingTables as $enctable)
  11272. {
  11273. if (($enctable['platformID'] == 3) and ($enctable['encodingID'] == 0))
  11274. {
  11275. $modesymbol = true;
  11276. }
  11277. else
  11278. {
  11279. $modesymbol = false;
  11280. }
  11281. $offset = $table['cmap']['offset'] + $enctable['offset'];
  11282. $format = $this->_getUSHORT($font, $offset);
  11283. switch ($format)
  11284. {
  11285. case 0 :
  11286. { // Format 0: Byte encoding table
  11287. $offset += 4; // skip length and version/language
  11288. for($k = 0; $k < 256; ++ $k)
  11289. {
  11290. if (isset($subsetchars[$k]))
  11291. {
  11292. $g = $this->_getBYTE($font, $offset);
  11293. $subsetglyphs[$g] = $k;
  11294. }
  11295. else
  11296. {
  11297. ++ $offset;
  11298. }
  11299. }
  11300. break;
  11301. }
  11302. case 2 :
  11303. { // Format 2: High-byte mapping through table
  11304. $offset += 4; // skip length and version
  11305. // to be implemented ...
  11306. break;
  11307. }
  11308. case 4 :
  11309. { // Format 4: Segment mapping to delta values
  11310. $length = $this->_getUSHORT($font, $offset);
  11311. $offset += 2; // skip version/language
  11312. $segCount = ($this->_getUSHORT($font, $offset) / 2);
  11313. $offset += 6; // skip searchRange, entrySelector, rangeShift
  11314. $endCount = array(); // array of end character codes for each segment
  11315. for($k = 0; $k < $segCount; ++ $k)
  11316. {
  11317. $endCount[$k] = $this->_getUSHORT($font, $offset);
  11318. }
  11319. $offset += 2; // skip reservedPad
  11320. $startCount = array(); // array of start character codes for each segment
  11321. for($k = 0; $k < $segCount; ++ $k)
  11322. {
  11323. $startCount[$k] = $this->_getUSHORT($font, $offset);
  11324. }
  11325. $idDelta = array(); // delta for all character codes in segment
  11326. for($k = 0; $k < $segCount; ++ $k)
  11327. {
  11328. $idDelta[$k] = $this->_getUSHORT($font, $offset);
  11329. }
  11330. $idRangeOffset = array(); // Offsets into glyphIdArray or 0
  11331. for($k = 0; $k < $segCount; ++ $k)
  11332. {
  11333. $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
  11334. }
  11335. $gidlen = ($length / 2) - 8 - (4 * $segCount);
  11336. $glyphIdArray = array(); // glyph index array
  11337. for($k = 0; $k < $gidlen; ++ $k)
  11338. {
  11339. $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
  11340. }
  11341. for($k = 0; $k < $segCount; ++ $k)
  11342. {
  11343. for($c = $startCount[$k]; $c <= $endCount[$k]; ++ $c)
  11344. {
  11345. if (isset($subsetchars[$c]))
  11346. {
  11347. if ($idRangeOffset[$k] == 0)
  11348. {
  11349. $g = $c;
  11350. }
  11351. else
  11352. {
  11353. $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
  11354. $g = $glyphIdArray[$gid];
  11355. }
  11356. $g += ($idDelta[$k] - 65536);
  11357. if ($g < 0)
  11358. {
  11359. $g = 0;
  11360. }
  11361. $subsetglyphs[$g] = $c;
  11362. }
  11363. }
  11364. }
  11365. break;
  11366. }
  11367. case 6 :
  11368. { // Format 6: Trimmed table mapping
  11369. $offset += 4; // skip length and version/language
  11370. $firstCode = $this->_getUSHORT($font, $offset);
  11371. $entryCount = $this->_getUSHORT($font, $offset);
  11372. for($k = 0; $k < $entryCount; ++ $k)
  11373. {
  11374. $c = ($k + $firstCode);
  11375. if (isset($subsetchars[$c]))
  11376. {
  11377. $g = $this->_getUSHORT($font, $offset);
  11378. $subsetglyphs[$g] = $c;
  11379. }
  11380. else
  11381. {
  11382. $offset += 2;
  11383. }
  11384. }
  11385. break;
  11386. }
  11387. case 8 :
  11388. { // Format 8: Mixed 16-bit and 32-bit coverage
  11389. $offset += 10; // skip length and version
  11390. // to be implemented ...
  11391. break;
  11392. }
  11393. case 10 :
  11394. { // Format 10: Trimmed array
  11395. $offset += 10; // skip length and version/language
  11396. $startCharCode = $this->_getULONG($font, $offset);
  11397. $numChars = $this->_getULONG($font, $offset);
  11398. for($k = 0; $k < $numChars; ++ $k)
  11399. {
  11400. $c = ($k + $startCharCode);
  11401. if (isset($subsetchars[$c]))
  11402. {
  11403. $g = $this->_getUSHORT($font, $offset);
  11404. $subsetglyphs[$g] = $c;
  11405. }
  11406. else
  11407. {
  11408. $offset += 2;
  11409. }
  11410. }
  11411. break;
  11412. }
  11413. case 12 :
  11414. { // Format 12: Segmented coverage
  11415. $offset += 10; // skip length and version/language
  11416. $nGroups = $this->_getULONG($font, $offset);
  11417. for($k = 0; $k < $nGroups; ++ $k)
  11418. {
  11419. $startCharCode = $this->_getULONG($font, $offset);
  11420. $endCharCode = $this->_getULONG($font, $offset);
  11421. $startGlyphCode = $this->_getULONG($font, $offset);
  11422. for($c = $startCharCode; $c <= $endCharCode; ++ $c)
  11423. {
  11424. if (isset($subsetchars[$c]))
  11425. {
  11426. $subsetglyphs[$startGlyphCode] = $c;
  11427. }
  11428. ++ $startGlyphCode;
  11429. }
  11430. }
  11431. break;
  11432. }
  11433. }
  11434. }
  11435. // sort glyphs by key
  11436. ksort($subsetglyphs);
  11437. // add composite glyps to $subsetglyphs and remove missing glyphs
  11438. foreach ($subsetglyphs as $key => $val)
  11439. {
  11440. if (isset($indexToLoc[$key]))
  11441. {
  11442. $offset = $table['glyf']['offset'] + $indexToLoc[$key];
  11443. $numberOfContours = $this->_getSHORT($font, $offset);
  11444. if ($numberOfContours < 0)
  11445. { // composite glyph
  11446. $offset += 8; // skip xMin, yMin, xMax, yMax
  11447. do
  11448. {
  11449. $flags = $this->_getUSHORT($font, $offset);
  11450. $glyphIndex = $this->_getUSHORT($font, $offset);
  11451. if (! isset($subsetglyphs[$glyphIndex]) and isset($indexToLoc[$glyphIndex]))
  11452. {
  11453. // add missing glyphs
  11454. $subsetglyphs[$glyphIndex] = true;
  11455. }
  11456. // skip some bytes by case
  11457. if ($flags & 1)
  11458. {
  11459. $offset += 4;
  11460. }
  11461. else
  11462. {
  11463. $offset += 2;
  11464. }
  11465. if ($flags & 8)
  11466. {
  11467. $offset += 2;
  11468. }
  11469. elseif ($flags & 64)
  11470. {
  11471. $offset += 4;
  11472. }
  11473. elseif ($flags & 128)
  11474. {
  11475. $offset += 8;
  11476. }
  11477. }
  11478. while ($flags & 32);
  11479. }
  11480. }
  11481. else
  11482. {
  11483. unset($subsetglyphs[$key]);
  11484. }
  11485. }
  11486. // build new glyf table with only used glyphs
  11487. $glyf = '';
  11488. $glyfSize = 0;
  11489. // create new empty indexToLoc table
  11490. $newIndexToLoc = array_fill(0, count($indexToLoc), 0);
  11491. $goffset = 0;
  11492. foreach ($subsetglyphs as $glyphID => $char)
  11493. {
  11494. if (isset($indexToLoc[$glyphID]) and isset($indexToLoc[($glyphID + 1)]))
  11495. {
  11496. $start = $indexToLoc[$glyphID];
  11497. $length = ($indexToLoc[($glyphID + 1)] - $start);
  11498. $glyf .= substr($font, ($table['glyf']['offset'] + $start), $length);
  11499. $newIndexToLoc[$glyphID] = $goffset;
  11500. $goffset += $length;
  11501. }
  11502. }
  11503. // build new loca table
  11504. $loca = '';
  11505. if ($short_offset)
  11506. {
  11507. foreach ($newIndexToLoc as $glyphID => $offset)
  11508. {
  11509. $loca .= pack('n', ($offset / 2));
  11510. }
  11511. }
  11512. else
  11513. {
  11514. foreach ($newIndexToLoc as $glyphID => $offset)
  11515. {
  11516. $loca .= pack('N', $offset);
  11517. }
  11518. }
  11519. // array of table names to preserve (loca and glyf tables will be added later)
  11520. //$table_names = array ('cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2', 'post', 'cvt ', 'fpgm', 'prep');
  11521. // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
  11522. $table_names = array('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
  11523. // get the tables to preserve
  11524. $offset = 12;
  11525. foreach ($table as $tag => $val)
  11526. {
  11527. if (in_array($tag, $table_names))
  11528. {
  11529. $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
  11530. if ($tag == 'head')
  11531. {
  11532. // set the checkSumAdjustment to 0
  11533. $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8) . "\x0\x0\x0\x0" . substr($table[$tag]['data'], 12);
  11534. }
  11535. $pad = 4 - ($table[$tag]['length'] % 4);
  11536. if ($pad != 4)
  11537. {
  11538. // the length of a table must be a multiple of four bytes
  11539. $table[$tag]['length'] += $pad;
  11540. $table[$tag]['data'] .= str_repeat("\x0", $pad);
  11541. }
  11542. $table[$tag]['offset'] = $offset;
  11543. $offset += $table[$tag]['length'];
  11544. // check sum is not changed (so keep the following line commented)
  11545. //$table[$tag]['checkSum'] = $this->_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
  11546. }
  11547. else
  11548. {
  11549. unset($table[$tag]);
  11550. }
  11551. }
  11552. // add loca
  11553. $table['loca']['data'] = $loca;
  11554. $table['loca']['length'] = strlen($loca);
  11555. $pad = 4 - ($table['loca']['length'] % 4);
  11556. if ($pad != 4)
  11557. {
  11558. // the length of a table must be a multiple of four bytes
  11559. $table['loca']['length'] += $pad;
  11560. $table['loca']['data'] .= str_repeat("\x0", $pad);
  11561. }
  11562. $table['loca']['offset'] = $offset;
  11563. $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
  11564. $offset += $table['loca']['length'];
  11565. // add glyf
  11566. $table['glyf']['data'] = $glyf;
  11567. $table['glyf']['length'] = strlen($glyf);
  11568. $pad = 4 - ($table['glyf']['length'] % 4);
  11569. if ($pad != 4)
  11570. {
  11571. // the length of a table must be a multiple of four bytes
  11572. $table['glyf']['length'] += $pad;
  11573. $table['glyf']['data'] .= str_repeat("\x0", $pad);
  11574. }
  11575. $table['glyf']['offset'] = $offset;
  11576. $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
  11577. // rebuild font
  11578. $font = '';
  11579. $font .= pack('N', 0x10000); // sfnt version
  11580. $numTables = count($table);
  11581. $font .= pack('n', $numTables); // numTables
  11582. $entrySelector = floor(log($numTables, 2));
  11583. $searchRange = pow(2, $entrySelector) * 16;
  11584. $rangeShift = ($numTables * 16) - $searchRange;
  11585. $font .= pack('n', $searchRange); // searchRange
  11586. $font .= pack('n', $entrySelector); // entrySelector
  11587. $font .= pack('n', $rangeShift); // rangeShift
  11588. $offset = ($numTables * 16);
  11589. foreach ($table as $tag => $data)
  11590. {
  11591. $font .= $tag; // tag
  11592. $font .= pack('N', $data['checkSum']); // checkSum
  11593. $font .= pack('N', ($data['offset'] + $offset)); // offset
  11594. $font .= pack('N', $data['length']); // length
  11595. }
  11596. foreach ($table as $data)
  11597. {
  11598. $font .= $data['data'];
  11599. }
  11600. // set checkSumAdjustment on head table
  11601. $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font));
  11602. $font = substr($font, 0, $table['head']['offset'] + 8) . pack('N', $checkSumAdjustment) . substr($font, $table['head']['offset'] + 12);
  11603. return $font;
  11604. }
  11605. /**
  11606. * Returs the checksum of a TTF table.
  11607. * @param string $table table to check
  11608. * @param int $length lenght of table in bytes
  11609. * @return int checksum
  11610. * @author Nicola Asuni
  11611. * @access protected
  11612. * @since 5.2.000 (2010-06-02)
  11613. */
  11614. protected function _getTTFtableChecksum($table, $length)
  11615. {
  11616. $sum = 0;
  11617. $tlen = ($length / 4);
  11618. $offset = 0;
  11619. for($i = 0; $i < $tlen; ++ $i)
  11620. {
  11621. $v = unpack('Ni', substr($table, $offset, 4));
  11622. $sum += $v['i'];
  11623. $offset += 4;
  11624. }
  11625. $sum = unpack('Ni', pack('N', $sum));
  11626. return $sum['i'];
  11627. }
  11628. /**
  11629. * Outputs font widths
  11630. * @param array $font font data
  11631. * @param int $cidoffset offset for CID values
  11632. * @return PDF command string for font widths
  11633. * @author Nicola Asuni
  11634. * @access protected
  11635. * @since 4.4.000 (2008-12-07)
  11636. */
  11637. protected function _putfontwidths($font, $cidoffset = 0)
  11638. {
  11639. ksort($font['cw']);
  11640. $rangeid = 0;
  11641. $range = array();
  11642. $prevcid = - 2;
  11643. $prevwidth = - 1;
  11644. $interval = false;
  11645. // for each character
  11646. foreach ($font['cw'] as $cid => $width)
  11647. {
  11648. $cid -= $cidoffset;
  11649. if ($font['subset'] and ($cid > 255) and (! isset($font['subsetchars'][$cid])))
  11650. {
  11651. // ignore the unused characters (font subsetting)
  11652. continue;
  11653. }
  11654. if ($width != $font['dw'])
  11655. {
  11656. if ($cid == ($prevcid + 1))
  11657. {
  11658. // consecutive CID
  11659. if ($width == $prevwidth)
  11660. {
  11661. if ($width == $range[$rangeid][0])
  11662. {
  11663. $range[$rangeid][] = $width;
  11664. }
  11665. else
  11666. {
  11667. array_pop($range[$rangeid]);
  11668. // new range
  11669. $rangeid = $prevcid;
  11670. $range[$rangeid] = array();
  11671. $range[$rangeid][] = $prevwidth;
  11672. $range[$rangeid][] = $width;
  11673. }
  11674. $interval = true;
  11675. $range[$rangeid]['interval'] = true;
  11676. }
  11677. else
  11678. {
  11679. if ($interval)
  11680. {
  11681. // new range
  11682. $rangeid = $cid;
  11683. $range[$rangeid] = array();
  11684. $range[$rangeid][] = $width;
  11685. }
  11686. else
  11687. {
  11688. $range[$rangeid][] = $width;
  11689. }
  11690. $interval = false;
  11691. }
  11692. }
  11693. else
  11694. {
  11695. // new range
  11696. $rangeid = $cid;
  11697. $range[$rangeid] = array();
  11698. $range[$rangeid][] = $width;
  11699. $interval = false;
  11700. }
  11701. $prevcid = $cid;
  11702. $prevwidth = $width;
  11703. }
  11704. }
  11705. // optimize ranges
  11706. $prevk = - 1;
  11707. $nextk = - 1;
  11708. $prevint = false;
  11709. foreach ($range as $k => $ws)
  11710. {
  11711. $cws = count($ws);
  11712. if (($k == $nextk) and (! $prevint) and ((! isset($ws['interval'])) or ($cws < 4)))
  11713. {
  11714. if (isset($range[$k]['interval']))
  11715. {
  11716. unset($range[$k]['interval']);
  11717. }
  11718. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  11719. unset($range[$k]);
  11720. }
  11721. else
  11722. {
  11723. $prevk = $k;
  11724. }
  11725. $nextk = $k + $cws;
  11726. if (isset($ws['interval']))
  11727. {
  11728. if ($cws > 3)
  11729. {
  11730. $prevint = true;
  11731. }
  11732. else
  11733. {
  11734. $prevint = false;
  11735. }
  11736. unset($range[$k]['interval']);
  11737. -- $nextk;
  11738. }
  11739. else
  11740. {
  11741. $prevint = false;
  11742. }
  11743. }
  11744. // output data
  11745. $w = '';
  11746. foreach ($range as $k => $ws)
  11747. {
  11748. if (count(array_count_values($ws)) == 1)
  11749. {
  11750. // interval mode is more compact
  11751. $w .= ' ' . $k . ' ' . ($k + count($ws) - 1) . ' ' . $ws[0];
  11752. }
  11753. else
  11754. {
  11755. // range mode
  11756. $w .= ' ' . $k . ' [ ' . implode(' ', $ws) . ' ]';
  11757. }
  11758. }
  11759. return '/W [' . $w . ' ]';
  11760. }
  11761. /**
  11762. * Output fonts.
  11763. * @author Nicola Asuni
  11764. * @access protected
  11765. */
  11766. protected function _putfonts()
  11767. {
  11768. $nf = $this->n;
  11769. foreach ($this->diffs as $diff)
  11770. {
  11771. //Encodings
  11772. $this->_newobj();
  11773. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . '] >>' . "\n" . 'endobj');
  11774. }
  11775. $mqr = $this->get_mqr();
  11776. $this->set_mqr(false);
  11777. foreach ($this->FontFiles as $file => $info)
  11778. {
  11779. // search and get font file to embedd
  11780. $fontdir = $info['fontdir'];
  11781. $file = strtolower($file);
  11782. $fontfile = '';
  11783. // search files on various directories
  11784. if (($fontdir !== false) and file_exists($fontdir . $file))
  11785. {
  11786. $fontfile = $fontdir . $file;
  11787. }
  11788. elseif (file_exists($this->_getfontpath() . $file))
  11789. {
  11790. $fontfile = $this->_getfontpath() . $file;
  11791. }
  11792. elseif (file_exists($file))
  11793. {
  11794. $fontfile = $file;
  11795. }
  11796. if (! $this->empty_string($fontfile))
  11797. {
  11798. $font = file_get_contents($fontfile);
  11799. $compressed = (substr($file, - 2) == '.z');
  11800. if ((! $compressed) and (isset($info['length2'])))
  11801. {
  11802. $header = (ord($font{0}) == 128);
  11803. if ($header)
  11804. {
  11805. //Strip first binary header
  11806. $font = substr($font, 6);
  11807. }
  11808. if ($header and (ord($font{$info['length1']}) == 128))
  11809. {
  11810. //Strip second binary header
  11811. $font = substr($font, 0, $info['length1']) . substr($font, ($info['length1'] + 6));
  11812. }
  11813. }
  11814. elseif ($info['subset'] and ((! $compressed) or ($compressed and function_exists('gzcompress'))))
  11815. {
  11816. if ($compressed)
  11817. {
  11818. // uncompress font
  11819. $font = gzuncompress($font);
  11820. }
  11821. // merge subset characters
  11822. $subsetchars = array(); // used chars
  11823. foreach ($info['fontkeys'] as $fontkey)
  11824. {
  11825. $fontinfo = $this->getFontBuffer($fontkey);
  11826. $subsetchars += $fontinfo['subsetchars'];
  11827. }
  11828. $font = $this->_getTrueTypeFontSubset($font, $subsetchars);
  11829. if ($compressed)
  11830. {
  11831. // recompress font
  11832. $font = gzcompress($font);
  11833. }
  11834. }
  11835. $this->_newobj();
  11836. $this->FontFiles[$file]['n'] = $this->n;
  11837. $stream = $this->_getrawstream($font);
  11838. $out = '<< /Length ' . strlen($stream);
  11839. if ($compressed)
  11840. {
  11841. $out .= ' /Filter /FlateDecode';
  11842. }
  11843. $out .= ' /Length1 ' . $info['length1'];
  11844. if (isset($info['length2']))
  11845. {
  11846. $out .= ' /Length2 ' . $info['length2'] . ' /Length3 0';
  11847. }
  11848. $out .= ' >>';
  11849. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  11850. $out .= "\n" . 'endobj';
  11851. $this->_out($out);
  11852. }
  11853. }
  11854. $this->set_mqr($mqr);
  11855. foreach ($this->fontkeys as $k)
  11856. {
  11857. //Font objects
  11858. $font = $this->getFontBuffer($k);
  11859. $type = $font['type'];
  11860. $name = $font['name'];
  11861. if ($type == 'core')
  11862. {
  11863. // standard core font
  11864. $out = $this->_getobj($this->font_obj_ids[$k]) . "\n";
  11865. $out .= '<</Type /Font';
  11866. $out .= ' /Subtype /Type1';
  11867. $out .= ' /BaseFont /' . $name;
  11868. $out .= ' /Name /F' . $font['i'];
  11869. if ((strtolower($name) != 'symbol') and (strtolower($name) != 'zapfdingbats'))
  11870. {
  11871. $out .= ' /Encoding /WinAnsiEncoding';
  11872. }
  11873. if ($k == 'helvetica')
  11874. {
  11875. // add default font for annotations
  11876. $this->annotation_fonts[$k] = $font['i'];
  11877. }
  11878. $out .= ' >>';
  11879. $out .= "\n" . 'endobj';
  11880. $this->_out($out);
  11881. }
  11882. elseif (($type == 'Type1') or ($type == 'TrueType'))
  11883. {
  11884. // additional Type1 or TrueType font
  11885. $out = $this->_getobj($this->font_obj_ids[$k]) . "\n";
  11886. $out .= '<</Type /Font';
  11887. $out .= ' /Subtype /' . $type;
  11888. $out .= ' /BaseFont /' . $name;
  11889. $out .= ' /Name /F' . $font['i'];
  11890. $out .= ' /FirstChar 32 /LastChar 255';
  11891. $out .= ' /Widths ' . ($this->n + 1) . ' 0 R';
  11892. $out .= ' /FontDescriptor ' . ($this->n + 2) . ' 0 R';
  11893. if ($font['enc'])
  11894. {
  11895. if (isset($font['diff']))
  11896. {
  11897. $out .= ' /Encoding ' . ($nf + $font['diff']) . ' 0 R';
  11898. }
  11899. else
  11900. {
  11901. $out .= ' /Encoding /WinAnsiEncoding';
  11902. }
  11903. }
  11904. $out .= ' >>';
  11905. $out .= "\n" . 'endobj';
  11906. $this->_out($out);
  11907. // Widths
  11908. $this->_newobj();
  11909. $cw = &$font['cw'];
  11910. $s = '[';
  11911. for($i = 32; $i < 256; ++ $i)
  11912. {
  11913. $s .= $cw[$i] . ' ';
  11914. }
  11915. $s .= ']';
  11916. $s .= "\n" . 'endobj';
  11917. $this->_out($s);
  11918. //Descriptor
  11919. $this->_newobj();
  11920. $s = '<</Type /FontDescriptor /FontName /' . $name;
  11921. foreach ($font['desc'] as $fdk => $fdv)
  11922. {
  11923. if (is_float($fdv))
  11924. {
  11925. $fdv = sprintf('%.3F', $fdv);
  11926. }
  11927. $s .= ' /' . $fdk . ' ' . $fdv . '';
  11928. }
  11929. if (! $this->empty_string($font['file']))
  11930. {
  11931. $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R';
  11932. }
  11933. $s .= '>>';
  11934. $s .= "\n" . 'endobj';
  11935. $this->_out($s);
  11936. }
  11937. else
  11938. {
  11939. // additional types
  11940. $mtd = '_put' . strtolower($type);
  11941. if (! method_exists($this, $mtd))
  11942. {
  11943. $this->Error('Unsupported font type: ' . $type);
  11944. }
  11945. $this->$mtd($font);
  11946. }
  11947. }
  11948. }
  11949. /**
  11950. * Adds unicode fonts.<br>
  11951. * Based on PDF Reference 1.3 (section 5)
  11952. * @param array $font font data
  11953. * @access protected
  11954. * @author Nicola Asuni
  11955. * @since 1.52.0.TC005 (2005-01-05)
  11956. */
  11957. protected function _puttruetypeunicode($font)
  11958. {
  11959. $fontname = '';
  11960. if ($font['subset'])
  11961. {
  11962. // change name for font subsetting
  11963. $subtag = sprintf('%06u', $font['i']);
  11964. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  11965. $fontname .= $subtag . '+';
  11966. }
  11967. $fontname .= $font['name'];
  11968. // Type0 Font
  11969. // A composite font composed of other fonts, organized hierarchically
  11970. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']]) . "\n";
  11971. $out .= '<< /Type /Font';
  11972. $out .= ' /Subtype /Type0';
  11973. $out .= ' /BaseFont /' . $fontname;
  11974. $out .= ' /Name /F' . $font['i'];
  11975. $out .= ' /Encoding /' . $font['enc'];
  11976. $out .= ' /ToUnicode ' . ($this->n + 1) . ' 0 R';
  11977. $out .= ' /DescendantFonts [' . ($this->n + 2) . ' 0 R]';
  11978. $out .= ' >>';
  11979. $out .= "\n" . 'endobj';
  11980. $this->_out($out);
  11981. // ToUnicode map for Identity-H
  11982. $stream = "/CIDInit /ProcSet findresource begin\n";
  11983. $stream .= "12 dict begin\n";
  11984. $stream .= "begincmap\n";
  11985. $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n";
  11986. $stream .= "/CMapName /Adobe-Identity-UCS def\n";
  11987. $stream .= "/CMapType 2 def\n";
  11988. $stream .= "/WMode 0 def\n";
  11989. $stream .= "1 begincodespacerange\n";
  11990. $stream .= "<0000> <FFFF>\n";
  11991. $stream .= "endcodespacerange\n";
  11992. $stream .= "100 beginbfrange\n";
  11993. $stream .= "<0000> <00ff> <0000>\n";
  11994. $stream .= "<0100> <01ff> <0100>\n";
  11995. $stream .= "<0200> <02ff> <0200>\n";
  11996. $stream .= "<0300> <03ff> <0300>\n";
  11997. $stream .= "<0400> <04ff> <0400>\n";
  11998. $stream .= "<0500> <05ff> <0500>\n";
  11999. $stream .= "<0600> <06ff> <0600>\n";
  12000. $stream .= "<0700> <07ff> <0700>\n";
  12001. $stream .= "<0800> <08ff> <0800>\n";
  12002. $stream .= "<0900> <09ff> <0900>\n";
  12003. $stream .= "<0a00> <0aff> <0a00>\n";
  12004. $stream .= "<0b00> <0bff> <0b00>\n";
  12005. $stream .= "<0c00> <0cff> <0c00>\n";
  12006. $stream .= "<0d00> <0dff> <0d00>\n";
  12007. $stream .= "<0e00> <0eff> <0e00>\n";
  12008. $stream .= "<0f00> <0fff> <0f00>\n";
  12009. $stream .= "<1000> <10ff> <1000>\n";
  12010. $stream .= "<1100> <11ff> <1100>\n";
  12011. $stream .= "<1200> <12ff> <1200>\n";
  12012. $stream .= "<1300> <13ff> <1300>\n";
  12013. $stream .= "<1400> <14ff> <1400>\n";
  12014. $stream .= "<1500> <15ff> <1500>\n";
  12015. $stream .= "<1600> <16ff> <1600>\n";
  12016. $stream .= "<1700> <17ff> <1700>\n";
  12017. $stream .= "<1800> <18ff> <1800>\n";
  12018. $stream .= "<1900> <19ff> <1900>\n";
  12019. $stream .= "<1a00> <1aff> <1a00>\n";
  12020. $stream .= "<1b00> <1bff> <1b00>\n";
  12021. $stream .= "<1c00> <1cff> <1c00>\n";
  12022. $stream .= "<1d00> <1dff> <1d00>\n";
  12023. $stream .= "<1e00> <1eff> <1e00>\n";
  12024. $stream .= "<1f00> <1fff> <1f00>\n";
  12025. $stream .= "<2000> <20ff> <2000>\n";
  12026. $stream .= "<2100> <21ff> <2100>\n";
  12027. $stream .= "<2200> <22ff> <2200>\n";
  12028. $stream .= "<2300> <23ff> <2300>\n";
  12029. $stream .= "<2400> <24ff> <2400>\n";
  12030. $stream .= "<2500> <25ff> <2500>\n";
  12031. $stream .= "<2600> <26ff> <2600>\n";
  12032. $stream .= "<2700> <27ff> <2700>\n";
  12033. $stream .= "<2800> <28ff> <2800>\n";
  12034. $stream .= "<2900> <29ff> <2900>\n";
  12035. $stream .= "<2a00> <2aff> <2a00>\n";
  12036. $stream .= "<2b00> <2bff> <2b00>\n";
  12037. $stream .= "<2c00> <2cff> <2c00>\n";
  12038. $stream .= "<2d00> <2dff> <2d00>\n";
  12039. $stream .= "<2e00> <2eff> <2e00>\n";
  12040. $stream .= "<2f00> <2fff> <2f00>\n";
  12041. $stream .= "<3000> <30ff> <3000>\n";
  12042. $stream .= "<3100> <31ff> <3100>\n";
  12043. $stream .= "<3200> <32ff> <3200>\n";
  12044. $stream .= "<3300> <33ff> <3300>\n";
  12045. $stream .= "<3400> <34ff> <3400>\n";
  12046. $stream .= "<3500> <35ff> <3500>\n";
  12047. $stream .= "<3600> <36ff> <3600>\n";
  12048. $stream .= "<3700> <37ff> <3700>\n";
  12049. $stream .= "<3800> <38ff> <3800>\n";
  12050. $stream .= "<3900> <39ff> <3900>\n";
  12051. $stream .= "<3a00> <3aff> <3a00>\n";
  12052. $stream .= "<3b00> <3bff> <3b00>\n";
  12053. $stream .= "<3c00> <3cff> <3c00>\n";
  12054. $stream .= "<3d00> <3dff> <3d00>\n";
  12055. $stream .= "<3e00> <3eff> <3e00>\n";
  12056. $stream .= "<3f00> <3fff> <3f00>\n";
  12057. $stream .= "<4000> <40ff> <4000>\n";
  12058. $stream .= "<4100> <41ff> <4100>\n";
  12059. $stream .= "<4200> <42ff> <4200>\n";
  12060. $stream .= "<4300> <43ff> <4300>\n";
  12061. $stream .= "<4400> <44ff> <4400>\n";
  12062. $stream .= "<4500> <45ff> <4500>\n";
  12063. $stream .= "<4600> <46ff> <4600>\n";
  12064. $stream .= "<4700> <47ff> <4700>\n";
  12065. $stream .= "<4800> <48ff> <4800>\n";
  12066. $stream .= "<4900> <49ff> <4900>\n";
  12067. $stream .= "<4a00> <4aff> <4a00>\n";
  12068. $stream .= "<4b00> <4bff> <4b00>\n";
  12069. $stream .= "<4c00> <4cff> <4c00>\n";
  12070. $stream .= "<4d00> <4dff> <4d00>\n";
  12071. $stream .= "<4e00> <4eff> <4e00>\n";
  12072. $stream .= "<4f00> <4fff> <4f00>\n";
  12073. $stream .= "<5000> <50ff> <5000>\n";
  12074. $stream .= "<5100> <51ff> <5100>\n";
  12075. $stream .= "<5200> <52ff> <5200>\n";
  12076. $stream .= "<5300> <53ff> <5300>\n";
  12077. $stream .= "<5400> <54ff> <5400>\n";
  12078. $stream .= "<5500> <55ff> <5500>\n";
  12079. $stream .= "<5600> <56ff> <5600>\n";
  12080. $stream .= "<5700> <57ff> <5700>\n";
  12081. $stream .= "<5800> <58ff> <5800>\n";
  12082. $stream .= "<5900> <59ff> <5900>\n";
  12083. $stream .= "<5a00> <5aff> <5a00>\n";
  12084. $stream .= "<5b00> <5bff> <5b00>\n";
  12085. $stream .= "<5c00> <5cff> <5c00>\n";
  12086. $stream .= "<5d00> <5dff> <5d00>\n";
  12087. $stream .= "<5e00> <5eff> <5e00>\n";
  12088. $stream .= "<5f00> <5fff> <5f00>\n";
  12089. $stream .= "<6000> <60ff> <6000>\n";
  12090. $stream .= "<6100> <61ff> <6100>\n";
  12091. $stream .= "<6200> <62ff> <6200>\n";
  12092. $stream .= "<6300> <63ff> <6300>\n";
  12093. $stream .= "endbfrange\n";
  12094. $stream .= "100 beginbfrange\n";
  12095. $stream .= "<6400> <64ff> <6400>\n";
  12096. $stream .= "<6500> <65ff> <6500>\n";
  12097. $stream .= "<6600> <66ff> <6600>\n";
  12098. $stream .= "<6700> <67ff> <6700>\n";
  12099. $stream .= "<6800> <68ff> <6800>\n";
  12100. $stream .= "<6900> <69ff> <6900>\n";
  12101. $stream .= "<6a00> <6aff> <6a00>\n";
  12102. $stream .= "<6b00> <6bff> <6b00>\n";
  12103. $stream .= "<6c00> <6cff> <6c00>\n";
  12104. $stream .= "<6d00> <6dff> <6d00>\n";
  12105. $stream .= "<6e00> <6eff> <6e00>\n";
  12106. $stream .= "<6f00> <6fff> <6f00>\n";
  12107. $stream .= "<7000> <70ff> <7000>\n";
  12108. $stream .= "<7100> <71ff> <7100>\n";
  12109. $stream .= "<7200> <72ff> <7200>\n";
  12110. $stream .= "<7300> <73ff> <7300>\n";
  12111. $stream .= "<7400> <74ff> <7400>\n";
  12112. $stream .= "<7500> <75ff> <7500>\n";
  12113. $stream .= "<7600> <76ff> <7600>\n";
  12114. $stream .= "<7700> <77ff> <7700>\n";
  12115. $stream .= "<7800> <78ff> <7800>\n";
  12116. $stream .= "<7900> <79ff> <7900>\n";
  12117. $stream .= "<7a00> <7aff> <7a00>\n";
  12118. $stream .= "<7b00> <7bff> <7b00>\n";
  12119. $stream .= "<7c00> <7cff> <7c00>\n";
  12120. $stream .= "<7d00> <7dff> <7d00>\n";
  12121. $stream .= "<7e00> <7eff> <7e00>\n";
  12122. $stream .= "<7f00> <7fff> <7f00>\n";
  12123. $stream .= "<8000> <80ff> <8000>\n";
  12124. $stream .= "<8100> <81ff> <8100>\n";
  12125. $stream .= "<8200> <82ff> <8200>\n";
  12126. $stream .= "<8300> <83ff> <8300>\n";
  12127. $stream .= "<8400> <84ff> <8400>\n";
  12128. $stream .= "<8500> <85ff> <8500>\n";
  12129. $stream .= "<8600> <86ff> <8600>\n";
  12130. $stream .= "<8700> <87ff> <8700>\n";
  12131. $stream .= "<8800> <88ff> <8800>\n";
  12132. $stream .= "<8900> <89ff> <8900>\n";
  12133. $stream .= "<8a00> <8aff> <8a00>\n";
  12134. $stream .= "<8b00> <8bff> <8b00>\n";
  12135. $stream .= "<8c00> <8cff> <8c00>\n";
  12136. $stream .= "<8d00> <8dff> <8d00>\n";
  12137. $stream .= "<8e00> <8eff> <8e00>\n";
  12138. $stream .= "<8f00> <8fff> <8f00>\n";
  12139. $stream .= "<9000> <90ff> <9000>\n";
  12140. $stream .= "<9100> <91ff> <9100>\n";
  12141. $stream .= "<9200> <92ff> <9200>\n";
  12142. $stream .= "<9300> <93ff> <9300>\n";
  12143. $stream .= "<9400> <94ff> <9400>\n";
  12144. $stream .= "<9500> <95ff> <9500>\n";
  12145. $stream .= "<9600> <96ff> <9600>\n";
  12146. $stream .= "<9700> <97ff> <9700>\n";
  12147. $stream .= "<9800> <98ff> <9800>\n";
  12148. $stream .= "<9900> <99ff> <9900>\n";
  12149. $stream .= "<9a00> <9aff> <9a00>\n";
  12150. $stream .= "<9b00> <9bff> <9b00>\n";
  12151. $stream .= "<9c00> <9cff> <9c00>\n";
  12152. $stream .= "<9d00> <9dff> <9d00>\n";
  12153. $stream .= "<9e00> <9eff> <9e00>\n";
  12154. $stream .= "<9f00> <9fff> <9f00>\n";
  12155. $stream .= "<a000> <a0ff> <a000>\n";
  12156. $stream .= "<a100> <a1ff> <a100>\n";
  12157. $stream .= "<a200> <a2ff> <a200>\n";
  12158. $stream .= "<a300> <a3ff> <a300>\n";
  12159. $stream .= "<a400> <a4ff> <a400>\n";
  12160. $stream .= "<a500> <a5ff> <a500>\n";
  12161. $stream .= "<a600> <a6ff> <a600>\n";
  12162. $stream .= "<a700> <a7ff> <a700>\n";
  12163. $stream .= "<a800> <a8ff> <a800>\n";
  12164. $stream .= "<a900> <a9ff> <a900>\n";
  12165. $stream .= "<aa00> <aaff> <aa00>\n";
  12166. $stream .= "<ab00> <abff> <ab00>\n";
  12167. $stream .= "<ac00> <acff> <ac00>\n";
  12168. $stream .= "<ad00> <adff> <ad00>\n";
  12169. $stream .= "<ae00> <aeff> <ae00>\n";
  12170. $stream .= "<af00> <afff> <af00>\n";
  12171. $stream .= "<b000> <b0ff> <b000>\n";
  12172. $stream .= "<b100> <b1ff> <b100>\n";
  12173. $stream .= "<b200> <b2ff> <b200>\n";
  12174. $stream .= "<b300> <b3ff> <b300>\n";
  12175. $stream .= "<b400> <b4ff> <b400>\n";
  12176. $stream .= "<b500> <b5ff> <b500>\n";
  12177. $stream .= "<b600> <b6ff> <b600>\n";
  12178. $stream .= "<b700> <b7ff> <b700>\n";
  12179. $stream .= "<b800> <b8ff> <b800>\n";
  12180. $stream .= "<b900> <b9ff> <b900>\n";
  12181. $stream .= "<ba00> <baff> <ba00>\n";
  12182. $stream .= "<bb00> <bbff> <bb00>\n";
  12183. $stream .= "<bc00> <bcff> <bc00>\n";
  12184. $stream .= "<bd00> <bdff> <bd00>\n";
  12185. $stream .= "<be00> <beff> <be00>\n";
  12186. $stream .= "<bf00> <bfff> <bf00>\n";
  12187. $stream .= "<c000> <c0ff> <c000>\n";
  12188. $stream .= "<c100> <c1ff> <c100>\n";
  12189. $stream .= "<c200> <c2ff> <c200>\n";
  12190. $stream .= "<c300> <c3ff> <c300>\n";
  12191. $stream .= "<c400> <c4ff> <c400>\n";
  12192. $stream .= "<c500> <c5ff> <c500>\n";
  12193. $stream .= "<c600> <c6ff> <c600>\n";
  12194. $stream .= "<c700> <c7ff> <c700>\n";
  12195. $stream .= "endbfrange\n";
  12196. $stream .= "56 beginbfrange\n";
  12197. $stream .= "<c800> <c8ff> <c800>\n";
  12198. $stream .= "<c900> <c9ff> <c900>\n";
  12199. $stream .= "<ca00> <caff> <ca00>\n";
  12200. $stream .= "<cb00> <cbff> <cb00>\n";
  12201. $stream .= "<cc00> <ccff> <cc00>\n";
  12202. $stream .= "<cd00> <cdff> <cd00>\n";
  12203. $stream .= "<ce00> <ceff> <ce00>\n";
  12204. $stream .= "<cf00> <cfff> <cf00>\n";
  12205. $stream .= "<d000> <d0ff> <d000>\n";
  12206. $stream .= "<d100> <d1ff> <d100>\n";
  12207. $stream .= "<d200> <d2ff> <d200>\n";
  12208. $stream .= "<d300> <d3ff> <d300>\n";
  12209. $stream .= "<d400> <d4ff> <d400>\n";
  12210. $stream .= "<d500> <d5ff> <d500>\n";
  12211. $stream .= "<d600> <d6ff> <d600>\n";
  12212. $stream .= "<d700> <d7ff> <d700>\n";
  12213. $stream .= "<d800> <d8ff> <d800>\n";
  12214. $stream .= "<d900> <d9ff> <d900>\n";
  12215. $stream .= "<da00> <daff> <da00>\n";
  12216. $stream .= "<db00> <dbff> <db00>\n";
  12217. $stream .= "<dc00> <dcff> <dc00>\n";
  12218. $stream .= "<dd00> <ddff> <dd00>\n";
  12219. $stream .= "<de00> <deff> <de00>\n";
  12220. $stream .= "<df00> <dfff> <df00>\n";
  12221. $stream .= "<e000> <e0ff> <e000>\n";
  12222. $stream .= "<e100> <e1ff> <e100>\n";
  12223. $stream .=