PageRenderTime 91ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 3ms

/application/libraries/mpdf/mpdf5.2.php

https://bitbucket.org/mannysoft/erpts
PHP | 13223 lines | 10610 code | 1263 blank | 1350 comment | 4247 complexity | 95f4a7216122481a88d6f233a41c36f6 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // ******************************************************************************
  3. // Software: mPDF, Unicode-HTML Free PDF generator *
  4. // Version: 5.2 based on *
  5. // FPDF by Olivier PLATHEY *
  6. // HTML2FPDF by Renato Coelho *
  7. // Date: 2011-06-19 *
  8. // Author: Ian Back <ianb@bpm1.com> *
  9. // License: GPL *
  10. // *
  11. // Changes: See changelog.txt *
  12. // ******************************************************************************
  13. define('mPDF_VERSION','5.2');
  14. define('AUTOFONT_CJK',1);
  15. define('AUTOFONT_THAIVIET',2);
  16. define('AUTOFONT_RTL',4);
  17. define('AUTOFONT_INDIC',8);
  18. define('AUTOFONT_ALL',15);
  19. define('_BORDER_ALL',15);
  20. define('_BORDER_TOP',8);
  21. define('_BORDER_RIGHT',4);
  22. define('_BORDER_BOTTOM',2);
  23. define('_BORDER_LEFT',1);
  24. if (!defined('_MPDF_PATH')) define('_MPDF_PATH', dirname(preg_replace('/\\\\/','/',__FILE__)) . '/');
  25. if (!defined('_MPDF_URI')) define('_MPDF_URI',_MPDF_PATH); // mPDF 5.0
  26. require_once(_MPDF_PATH.'includes/functions.php');
  27. require_once(_MPDF_PATH.'config_cp.php');
  28. if (!defined('_JPGRAPH_PATH')) define("_JPGRAPH_PATH", _MPDF_PATH.'jpgraph/');
  29. if (!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", _MPDF_PATH.'tmp/');
  30. if (!defined('_MPDF_TTFONTPATH')) { define('_MPDF_TTFONTPATH',_MPDF_PATH.'ttfonts/'); } // mPDF 5.0
  31. if (!defined('_MPDF_TTFONTDATAPATH')) { define('_MPDF_TTFONTDATAPATH',_MPDF_PATH.'ttfontdata/'); }
  32. $errorlevel=error_reporting();
  33. $errorlevel=error_reporting($errorlevel & ~E_NOTICE);
  34. //error_reporting(E_ALL);
  35. if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
  36. @date_default_timezone_set(@date_default_timezone_get());
  37. if (!function_exists("mb_strlen")) { die("Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled."); }
  38. // mPDF 5.0
  39. if (!defined('PHP_VERSION_ID')) {
  40. $version = explode('.', PHP_VERSION);
  41. define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
  42. }
  43. class mPDF
  44. {
  45. ///////////////////////////////
  46. // EXTERNAL (PUBLIC) VARIABLES
  47. // Define these in config.php
  48. ///////////////////////////////
  49. var $repackageTTF; // mPDF 5.2
  50. var $allowCJKorphans;
  51. var $allowCJKoverflow;
  52. var $CJKleading;
  53. var $CJKfollowing;
  54. var $CJKoverflow;
  55. var $useKerning; // mPDF 5.0.061
  56. var $restrictColorSpace; // mPDF 5.0.051
  57. var $bleedMargin; // mPDF 5.0.047
  58. var $crossMarkMargin; // mPDF 5.0.047
  59. var $cropMarkMargin; // mPDF 5.0.047
  60. var $cropMarkLength; // mPDF 5.0.047
  61. var $nonPrintMargin; // mPDF 5.0.047
  62. var $PDFX;
  63. var $PDFXauto;
  64. var $PDFA;
  65. var $PDFAauto;
  66. var $ICCProfile;
  67. // mPDF 5.0
  68. var $printers_info; // mPDF 5.0.006
  69. var $iterationCounter;
  70. var $smCapsScale;
  71. var $smCapsStretch;
  72. var $backupSubsFont;
  73. var $backupSIPFont;
  74. var $debugfonts;
  75. var $useAdobeCJK;
  76. var $percentSubset;
  77. var $maxTTFFilesize;
  78. var $BMPonly;
  79. var $tableMinSizePriority;
  80. var $dpi;
  81. var $watermarkImgAlphaBlend;
  82. var $watermarkImgBehind;
  83. var $justifyB4br;
  84. var $packTableData;
  85. var $pgsIns;
  86. var $simpleTables;
  87. var $enableImports;
  88. var $debug;
  89. var $showStats;
  90. var $setAutoTopMargin;
  91. var $setAutoBottomMargin;
  92. var $autoMarginPadding;
  93. var $collapseBlockMargins;
  94. var $falseBoldWeight;
  95. var $normalLineheight;
  96. var $progressBar;
  97. var $incrementFPR1;
  98. var $incrementFPR2;
  99. var $incrementFPR3;
  100. var $incrementFPR4;
  101. var $hyphenate;
  102. var $hyphenateTables;
  103. var $SHYlang;
  104. var $SHYleftmin;
  105. var $SHYrightmin;
  106. var $SHYcharmin;
  107. var $SHYcharmax;
  108. var $SHYlanguages;
  109. // PageNumber Conditional Text
  110. var $pagenumPrefix;
  111. var $pagenumSuffix;
  112. var $nbpgPrefix;
  113. var $nbpgSuffix;
  114. var $showImageErrors;
  115. var $allow_output_buffering;
  116. var $autoPadding;
  117. var $useGraphs;
  118. var $autoFontGroupSize;
  119. var $tabSpaces;
  120. var $useLang;
  121. var $restoreBlockPagebreaks;
  122. var $watermarkTextAlpha;
  123. var $watermarkImageAlpha;
  124. var $watermark_size;
  125. var $watermark_pos;
  126. var $annotSize;
  127. var $annotMargin;
  128. var $annotOpacity;
  129. var $title2annots;
  130. var $keepColumns;
  131. var $keep_table_proportions;
  132. var $ignore_table_widths;
  133. var $ignore_table_percents;
  134. var $list_align_style;
  135. var $list_number_suffix;
  136. var $useSubstitutions;
  137. var $CSSselectMedia;
  138. // $disablePrintCSS depracated
  139. var $forcePortraitHeaders;
  140. var $forcePortraitMargins;
  141. var $displayDefaultOrientation;
  142. var $ignore_invalid_utf8;
  143. var $allowedCSStags;
  144. var $onlyCoreFonts;
  145. var $allow_charset_conversion;
  146. var $jSWord;
  147. var $jSmaxChar;
  148. var $jSmaxCharLast;
  149. var $jSmaxWordLast;
  150. var $orphansAllowed;
  151. var $max_colH_correction;
  152. var $table_error_report;
  153. var $table_error_report_param;
  154. var $biDirectional;
  155. var $text_input_as_HTML;
  156. var $anchor2Bookmark;
  157. var $list_indent_first_level;
  158. var $shrink_tables_to_fit;
  159. var $allow_html_optional_endtags;
  160. var $img_dpi;
  161. var $defaultheaderfontsize;
  162. var $defaultheaderfontstyle;
  163. var $defaultheaderline;
  164. var $defaultfooterfontsize;
  165. var $defaultfooterfontstyle;
  166. var $defaultfooterline;
  167. var $header_line_spacing;
  168. var $footer_line_spacing;
  169. var $textarea_lineheight;
  170. var $pregRTLchars;
  171. var $pregUHCchars;
  172. var $pregSJISchars;
  173. var $pregCJKchars;
  174. var $pregASCIIchars1;
  175. var $pregASCIIchars2;
  176. var $pregASCIIchars3;
  177. var $pregVIETchars;
  178. var $pregVIETPluschars;
  179. var $pregHEBchars;
  180. var $pregARABICchars;
  181. var $pregNonARABICchars;
  182. // INDIC
  183. var $pregHIchars;
  184. var $pregBNchars;
  185. var $pregPAchars;
  186. var $pregGUchars;
  187. var $pregORchars;
  188. var $pregTAchars;
  189. var $pregTEchars;
  190. var $pregKNchars;
  191. var $pregMLchars;
  192. var $pregSHchars;
  193. var $pregINDextra;
  194. var $mirrorMargins;
  195. var $default_lineheight_correction;
  196. var $watermarkText;
  197. var $watermarkImage;
  198. var $showWatermarkText;
  199. var $showWatermarkImage;
  200. var $fontsizes;
  201. // Aliases for backward compatability
  202. var $UnvalidatedText; // alias = $watermarkText
  203. var $TopicIsUnvalidated; // alias = $showWatermarkText
  204. var $useOddEven; // alias = $mirrorMargins
  205. var $useSubstitutionsMB; // alias = $useSubstitutions
  206. //////////////////////
  207. // INTERNAL VARIABLES
  208. //////////////////////
  209. var $kerning; // mPDF 5.0.061
  210. var $fixedlSpacing; // mPDF 5.0.063
  211. var $minwSpacing; // mPDF 5.0.063
  212. var $lSpacingCSS; // mPDF 5.0.063
  213. var $wSpacingCSS; // mPDF 5.0.063
  214. var $listDir; // mPDF 5.0.054
  215. var $spotColorIDs; // mPDF 5.0.051
  216. var $SVGcolors; // mPDF 5.0.051
  217. var $spotColors; // mPDF 5.0.051
  218. var $defTextColor; // mPDF 5.0.051
  219. var $defDrawColor; // mPDF 5.0.051
  220. var $defFillColor; // mPDF 5.0.051
  221. var $tableBackgrounds; // mPDF 5.0.018
  222. var $inlineDisplayOff; // mPDF 5.0
  223. var $kt_y00;
  224. var $kt_p00;
  225. var $upperCase;
  226. var $checkSIP; // mPDF 5.0
  227. var $checkSMP; // mPDF 5.0.03
  228. var $checkCJK; // mPDF 5.0
  229. var $tableCJK; // mPDF 5.0
  230. var $watermarkImgAlpha;
  231. var $PDFAXwarnings; // mDPF 5.0.051
  232. var $MetadataRoot;
  233. var $OutputIntentRoot;
  234. var $InfoRoot;
  235. var $current_filename;
  236. var $parsers;
  237. var $current_parser;
  238. var $_obj_stack;
  239. var $_don_obj_stack;
  240. var $_current_obj_id;
  241. var $tpls;
  242. var $tpl;
  243. var $tplprefix;
  244. var $_res;
  245. var $pdf_version;
  246. var $noImageFile;
  247. var $lastblockbottommargin;
  248. var $baselineC;
  249. var $subPos;
  250. var $subArrMB;
  251. var $ReqFontStyle;
  252. var $tableClipPath ;
  253. var $forceExactLineheight;
  254. var $listOcc;
  255. var $fullImageHeight;
  256. var $inFixedPosBlock; // Internal flag for position:fixed block
  257. var $fixedPosBlock; // Buffer string for position:fixed block
  258. var $fixedPosBlockDepth;
  259. var $fixedPosBlockBBox;
  260. var $fixedPosBlockSave;
  261. var $maxPosL;
  262. var $maxPosR;
  263. var $loaded;
  264. var $extraFontSubsets;
  265. var $docTemplateStart; // Internal flag for page (page no. -1) that docTemplate starts on
  266. var $time0;
  267. // Classes
  268. var $indic;
  269. var $barcode;
  270. var $SHYpatterns;
  271. var $loadedSHYpatterns;
  272. var $loadedSHYdictionary;
  273. var $SHYdictionary;
  274. var $SHYdictionaryWords;
  275. var $spanbgcolorarray;
  276. var $default_font;
  277. var $list_lineheight;
  278. var $headerbuffer;
  279. var $lastblocklevelchange;
  280. var $nestedtablejustfinished;
  281. var $linebreakjustfinished;
  282. var $cell_border_dominance_L;
  283. var $cell_border_dominance_R;
  284. var $cell_border_dominance_T;
  285. var $cell_border_dominance_B;
  286. var $tbCSSlvl;
  287. var $listCSSlvl;
  288. var $table_keep_together;
  289. var $plainCell_properties;
  290. var $inherit_lineheight;
  291. var $listitemtype;
  292. var $shrin_k1;
  293. var $outerfilled;
  294. var $blockContext;
  295. var $floatDivs;
  296. var $tablecascadeCSS;
  297. var $listcascadeCSS;
  298. var $patterns;
  299. var $pageBackgrounds;
  300. var $bodyBackgroundGradient;
  301. var $bodyBackgroundImage;
  302. var $bodyBackgroundColor;
  303. var $writingHTMLheader; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  304. var $writingHTMLfooter;
  305. var $autoFontGroups;
  306. var $angle;
  307. var $gradients;
  308. var $kwt_Reference;
  309. var $kwt_BMoutlines;
  310. var $kwt_toc;
  311. var $tbrot_Reference;
  312. var $tbrot_BMoutlines;
  313. var $tbrot_toc;
  314. var $col_Reference;
  315. var $col_BMoutlines;
  316. var $col_toc;
  317. var $currentGraphId;
  318. var $graphs;
  319. var $floatbuffer;
  320. var $floatmargins;
  321. var $bullet;
  322. var $bulletarray;
  323. var $rtlAsArabicFarsi; // DEPRACATED
  324. var $currentLang;
  325. var $default_lang;
  326. var $default_available_fonts;
  327. var $pageTemplate;
  328. var $docTemplate;
  329. var $docTemplateContinue;
  330. var $arabGlyphs;
  331. var $arabHex;
  332. var $persianGlyphs;
  333. var $persianHex;
  334. var $arabVowels;
  335. var $arabPrevLink;
  336. var $arabNextLink;
  337. var $formobjects; // array of Form Objects for WMF
  338. var $gdiObjectArray; // array of GDI objects for WMF
  339. var $InlineProperties; // Should have done this a long time ago
  340. var $InlineAnnots;
  341. var $ktAnnots;
  342. var $tbrot_Annots;
  343. var $kwt_Annots;
  344. var $columnAnnots;
  345. var $PageAnnots;
  346. var $pageDim; // Keep track of page wxh for orientation changes - set in _beginpage, used in _putannots
  347. var $breakpoints;
  348. var $tableLevel;
  349. var $tbctr;
  350. var $innermostTableLevel;
  351. var $saveTableCounter;
  352. var $cellBorderBuffer;
  353. var $saveHTMLFooter_height;
  354. var $saveHTMLFooterE_height;
  355. var $firstPageBoxHeader;
  356. var $firstPageBoxHeaderEven;
  357. var $firstPageBoxFooter;
  358. var $firstPageBoxFooterEven;
  359. var $page_box;
  360. var $show_marks; // crop or cross marks
  361. var $basepathIsLocal;
  362. var $use_kwt;
  363. var $kwt;
  364. var $kwt_height;
  365. var $kwt_y0;
  366. var $kwt_x0;
  367. var $kwt_buffer;
  368. var $kwt_Links;
  369. var $kwt_moved;
  370. var $kwt_saved;
  371. // NOT USED???
  372. var $formBgColor;
  373. var $formBgColorSmall; // Color used for background of form fields if reduced in size (so border disappears)
  374. var $PageNumSubstitutions;
  375. var $table_borders_separate;
  376. var $base_table_properties;
  377. var $borderstyles;
  378. // doesn't include none or hidden
  379. var $listjustfinished;
  380. var $blockjustfinished;
  381. var $orig_bMargin;
  382. var $orig_tMargin;
  383. var $orig_lMargin;
  384. var $orig_rMargin;
  385. var $orig_hMargin;
  386. var $orig_fMargin;
  387. var $pageheaders;
  388. var $pagefooters;
  389. var $pageHTMLheaders;
  390. var $pageHTMLfooters;
  391. var $saveHTMLHeader;
  392. var $saveHTMLFooter;
  393. var $HTMLheaderPageLinks;
  394. var $HTMLheaderPageAnnots; // mPDF 5.0
  395. // See config_fonts.php for these next 5 values
  396. var $available_unifonts;
  397. var $sans_fonts;
  398. var $serif_fonts;
  399. var $mono_fonts;
  400. var $defaultSubsFont; // mPDF 5.0
  401. // List of ALL available CJK fonts (incl. styles) (Adobe add-ons) hw removed
  402. var $available_CJK_fonts;
  403. var $cascadeCSS;
  404. var $HTMLHeader;
  405. var $HTMLFooter;
  406. var $HTMLHeaderE; // for Even pages
  407. var $HTMLFooterE; // for Even pages
  408. var $bufferoutput;
  409. var $showdefaultpagenos; // DEPRACATED -left for backward compatability
  410. var $chrs;
  411. var $ords;
  412. // CJK fonts
  413. var $Big5_widths;
  414. var $GB_widths;
  415. var $SJIS_widths;
  416. var $UHC_widths;
  417. // SetProtection
  418. var $encrypted; //whether document is protected
  419. var $Uvalue; //U entry in pdf document
  420. var $Ovalue; //O entry in pdf document
  421. var $Pvalue; //P entry in pdf document
  422. var $enc_obj_id; //encryption object id
  423. var $last_rc4_key; //last RC4 key encrypted (cached for optimisation)
  424. var $last_rc4_key_c; //last RC4 computed key
  425. var $encryption_key;
  426. var $padding; //used for encryption
  427. // Bookmark
  428. var $BMoutlines;
  429. var $OutlineRoot;
  430. // TOC
  431. var $_toc;
  432. var $TOCmark;
  433. var $TOCfont;
  434. var $TOCfontsize;
  435. var $TOCindent;
  436. var $TOCheader;
  437. var $TOCfooter;
  438. var $TOCpreHTML;
  439. var $TOCpostHTML;
  440. var $TOCbookmarkText;
  441. var $TOCusePaging;
  442. var $TOCuseLinking;
  443. var $TOCorientation;
  444. var $TOC_margin_left;
  445. var $TOC_margin_right;
  446. var $TOC_margin_top;
  447. var $TOC_margin_bottom;
  448. var $TOC_margin_header;
  449. var $TOC_margin_footer;
  450. var $TOC_odd_header_name;
  451. var $TOC_even_header_name;
  452. var $TOC_odd_footer_name;
  453. var $TOC_even_footer_name;
  454. var $TOC_odd_header_value;
  455. var $TOC_even_header_value;
  456. var $TOC_odd_footer_value;
  457. var $TOC_even_footer_value;
  458. var $TOC_start;
  459. var $TOC_end;
  460. var $TOC_npages;
  461. var $m_TOC;
  462. // INDEX
  463. var $ColActive;
  464. var $ChangePage; //Flag indicating that a page break has occurred
  465. var $Reference;
  466. var $CurrCol;
  467. var $NbCol;
  468. var $y0; //Top ordinate of columns
  469. var $ColL;
  470. var $ColWidth;
  471. var $ColGap;
  472. // COLUMNS
  473. var $ColR;
  474. var $ChangeColumn;
  475. var $columnbuffer;
  476. var $ColDetails;
  477. var $columnLinks;
  478. var $colvAlign;
  479. // Substitutions
  480. var $substitute; // Array of substitution strings e.g. <ttz>112</ttz>
  481. var $entsearch; // Array of HTML entities (>ASCII 127) to substitute
  482. var $entsubstitute; // Array of substitution decimal unicode for the Hi entities
  483. // Default values if no style sheet offered (cf. http://www.w3.org/TR/CSS21/sample.html)
  484. var $defaultCSS;
  485. var $form_element_spacing;
  486. var $linemaxfontsize;
  487. var $lineheight_correction;
  488. var $lastoptionaltag; // Save current block item which HTML specifies optionsl endtag
  489. var $pageoutput;
  490. var $charset_in;
  491. var $blk;
  492. var $blklvl;
  493. var $ColumnAdjust;
  494. var $ws; // Word spacing
  495. var $HREF;
  496. var $pgwidth;
  497. var $fontlist;
  498. var $issetfont;
  499. var $issetcolor;
  500. var $oldx;
  501. var $oldy;
  502. var $B;
  503. var $U; //underlining flag
  504. var $S; // mPDF 5.0 SmallCaps flag
  505. var $I;
  506. var $tdbegin;
  507. var $table;
  508. var $cell;
  509. var $col;
  510. var $row;
  511. var $divbegin;
  512. var $divalign;
  513. var $divwidth;
  514. var $divheight;
  515. var $divrevert;
  516. var $spanbgcolor;
  517. var $spanlvl;
  518. var $listlvl;
  519. var $listnum;
  520. var $listtype;
  521. var $listoccur;
  522. var $listlist;
  523. var $listitem;
  524. var $pjustfinished;
  525. var $ignorefollowingspaces;
  526. var $SUP;
  527. var $SUB;
  528. var $SMALL;
  529. var $BIG;
  530. var $toupper;
  531. var $tolower;
  532. var $capitalize; // mPDF 5.0.062
  533. var $dash_on;
  534. var $dotted_on;
  535. var $strike;
  536. var $CSS;
  537. var $textbuffer;
  538. var $currentfontstyle;
  539. var $currentfontfamily;
  540. var $currentfontsize;
  541. var $colorarray;
  542. var $bgcolorarray;
  543. var $internallink;
  544. var $enabledtags;
  545. var $lineheight;
  546. var $basepath;
  547. var $outlineparam;
  548. var $outline_on;
  549. var $specialcontent;
  550. var $selectoption;
  551. var $usecss;
  552. var $usepre;
  553. var $usetableheader;
  554. var $tableheadernrows;
  555. var $tablefooternrows;
  556. var $objectbuffer;
  557. // Table Rotation
  558. var $table_rotate;
  559. var $tbrot_maxw;
  560. var $tbrot_maxh;
  561. var $tablebuffer;
  562. var $tbrot_align;
  563. var $tbrot_Links;
  564. var $divbuffer; // Buffer used when keeping DIV on one page
  565. var $keep_block_together; // Keep a Block from page-break-inside: avoid
  566. var $ktLinks; // Keep-together Block links array
  567. var $ktBlock; // Keep-together Block array
  568. var $ktReference;
  569. var $ktBMoutlines;
  570. var $_kttoc;
  571. var $tbrot_y0;
  572. var $tbrot_x0;
  573. var $tbrot_w;
  574. var $tbrot_h;
  575. var $mb_enc;
  576. var $directionality;
  577. var $extgstates; // Used for alpha channel - Transparency (Watermark)
  578. //var $tt_savefont; // mPDF 5.0.063 not req.
  579. var $mgl;
  580. var $mgt;
  581. var $mgr;
  582. var $mgb;
  583. var $tts;
  584. var $ttz;
  585. var $tta;
  586. var $headerDetails;
  587. var $footerDetails;
  588. // Best to alter the below variables using default stylesheet above
  589. var $div_margin_bottom;
  590. var $div_bottom_border;
  591. var $p_margin_bottom;
  592. var $p_bottom_border;
  593. var $page_break_after_avoid;
  594. var $margin_bottom_collapse;
  595. var $img_margin_top; // default is set at top of fn.openTag 'IMG'
  596. var $img_margin_bottom;
  597. var $list_indent;
  598. var $list_align;
  599. var $list_margin_bottom;
  600. var $default_font_size; // in pts
  601. var $original_default_font_size; // used to save default sizes when using table default
  602. var $original_default_font;
  603. var $watermark_font;
  604. var $defaultAlign;
  605. // TABLE
  606. var $defaultTableAlign;
  607. var $tablethead;
  608. var $thead_font_weight;
  609. var $thead_font_style;
  610. var $thead_font_smCaps; // mPDF 5.0
  611. var $thead_valign_default;
  612. var $thead_textalign_default;
  613. var $tabletfoot;
  614. var $tfoot_font_weight;
  615. var $tfoot_font_style;
  616. var $tfoot_font_smCaps; // mPDF 5.0
  617. var $tfoot_valign_default;
  618. var $tfoot_textalign_default;
  619. var $trow_text_rotate;
  620. var $cellPaddingL;
  621. var $cellPaddingR;
  622. var $cellPaddingT;
  623. var $cellPaddingB;
  624. var $table_lineheight;
  625. var $table_border_attr_set;
  626. var $table_border_css_set;
  627. var $shrin_k; // factor with which to shrink tables - used internally - do not change
  628. var $shrink_this_table_to_fit; // 0 or false to disable; value (if set) gives maximum factor to reduce fontsize
  629. var $MarginCorrection; // corrects for OddEven Margins
  630. var $margin_footer;
  631. var $margin_header;
  632. var $tabletheadjustfinished;
  633. var $usingCoreFont;
  634. var $charspacing;
  635. //Private properties FROM FPDF
  636. var $DisplayPreferences;
  637. var $outlines;
  638. var $flowingBlockAttr;
  639. var $page; //current page number
  640. var $n; //current object number
  641. var $offsets; //array of object offsets
  642. var $buffer; //buffer holding in-memory PDF
  643. var $pages; //array containing pages
  644. var $state; //current document state
  645. var $compress; //compression flag
  646. var $DefOrientation; //default orientation
  647. var $CurOrientation; //current orientation
  648. var $OrientationChanges; //array indicating orientation changes
  649. var $k; //scale factor (number of points in user unit)
  650. var $fwPt;
  651. var $fhPt; //dimensions of page format in points
  652. var $fw;
  653. var $fh; //dimensions of page format in user unit
  654. var $wPt;
  655. var $hPt; //current dimensions of page in points
  656. var $w;
  657. var $h; //current dimensions of page in user unit
  658. var $lMargin; //left margin
  659. var $tMargin; //top margin
  660. var $rMargin; //right margin
  661. var $bMargin; //page break margin
  662. var $cMarginL; //cell margin Left
  663. var $cMarginR; //cell margin Right
  664. var $cMarginT; //cell margin Left
  665. var $cMarginB; //cell margin Right
  666. var $DeflMargin; //Default left margin
  667. var $DefrMargin; //Default right margin
  668. var $x;
  669. var $y; //current position in user unit for cell positioning
  670. var $lasth; //height of last cell printed
  671. var $LineWidth; //line width in user unit
  672. var $CoreFonts; //array of standard font names
  673. var $fonts; //array of used fonts
  674. var $FontFiles; //array of font files
  675. var $diffs; //array of encoding differences
  676. var $images; //array of used images
  677. var $PageLinks; //array of links in pages
  678. var $links; //array of internal links
  679. var $FontFamily; //current font family
  680. var $FontStyle; //current font style
  681. var $CurrentFont; //current font info
  682. var $FontSizePt; //current font size in points
  683. var $FontSize; //current font size in user unit
  684. var $DrawColor; //commands for drawing color
  685. var $FillColor; //commands for filling color
  686. var $TextColor; //commands for text color
  687. var $ColorFlag; //indicates whether fill and text colors are different
  688. var $autoPageBreak; //automatic page breaking
  689. var $PageBreakTrigger; //threshold used to trigger page breaks
  690. var $InFooter; //flag set when processing footer
  691. var $InHTMLFooter;
  692. var $processingFooter; //flag set when processing footer - added for columns
  693. var $processingHeader; //flag set when processing header - added for columns
  694. var $ZoomMode; //zoom display mode
  695. var $LayoutMode; //layout display mode
  696. var $title; //title
  697. var $subject; //subject
  698. var $author; //author
  699. var $keywords; //keywords
  700. var $creator; //creator
  701. var $aliasNbPg; //alias for total number of pages
  702. var $aliasNbPgGp; //alias for total number of pages in page group
  703. var $aliasNbPgHex; // mPDF 5.0.04
  704. var $aliasNbPgGpHex; // mPDF 5.0.04
  705. var $ispre;
  706. var $outerblocktags;
  707. var $innerblocktags;
  708. // NOT Currently used
  709. var $inlinetags;
  710. var $listtags;
  711. var $tabletags;
  712. var $formtags;
  713. // **********************************
  714. // **********************************
  715. // **********************************
  716. // **********************************
  717. // **********************************
  718. // **********************************
  719. // **********************************
  720. // **********************************
  721. // **********************************
  722. //My config/ I added this 6.22.2011 to meet my needs
  723. //end Manny Isles
  724. //function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') {
  725. function mPDF($params = array()) {
  726. //Added 6.22.2011
  727. $mode = '';
  728. $format = 'A4';
  729. $format = 'Letter-L';
  730. $format = $params['format'];
  731. $default_font_size = 0;
  732. $default_font = '';
  733. $mgl = '15';
  734. $mgr = '15';
  735. $mgt = '16';
  736. $mgb = '16';
  737. $mgh = '9';
  738. $mgf = '9';
  739. $orientation = 'P';
  740. if (count($params) > 0)
  741. {
  742. foreach ($params as $key => $val)
  743. {
  744. //$this->$key = $val;
  745. //http://php.net/manual/en/language.variables.variable.php
  746. ${$key} = $val;
  747. }
  748. }
  749. //End added Manny Isles
  750. $this->time0 = microtime(true);
  751. $unit='mm';
  752. //Some checks
  753. $this->_dochecks();
  754. // Set up Aliases for backwards compatability
  755. $this->UnvalidatedText =& $this->watermarkText;
  756. $this->TopicIsUnvalidated =& $this->showWatermarkText;
  757. $this->AliasNbPg =& $this->aliasNbPg;
  758. $this->AliasNbPgGp =& $this->aliasNbPgGp;
  759. $this->BiDirectional =& $this->biDirectional;
  760. $this->Anchor2Bookmark =& $this->anchor2Bookmark;
  761. $this->KeepColumns =& $this->keepColumns;
  762. $this->useOddEven =& $this->mirrorMargins;
  763. $this->useSubstitutionsMB =& $this->useSubstitutions; // mPDF 5.0
  764. //Initialization of properties
  765. $this->spotColors=array(); // mPDF 5.0.051
  766. $this->spotColorIDs = array(); // mPDF 5.0.051
  767. $this->tableBackgrounds = array(); // mPDF 5.0.018
  768. $this->kt_y00 = '';
  769. $this->kt_p00 = '';
  770. $this->iterationCounter = false;
  771. $this->BMPonly = array();
  772. $this->page=0;
  773. $this->n=2;
  774. $this->buffer='';
  775. $this->objectbuffer = array();
  776. $this->pages=array();
  777. $this->OrientationChanges=array();
  778. $this->state=0;
  779. $this->fonts=array();
  780. $this->FontFiles=array();
  781. $this->diffs=array();
  782. $this->images=array();
  783. $this->links=array();
  784. $this->InFooter=false;
  785. $this->processingFooter=false;
  786. $this->processingHeader=false;
  787. $this->lasth=0;
  788. $this->FontFamily='';
  789. $this->FontStyle='';
  790. $this->FontSizePt=9;
  791. $this->U=false;
  792. // mPDF 5.0 Small Caps
  793. $this->upperCase = array();
  794. @include(_MPDF_PATH.'includes/upperCase.php');
  795. $this->S = false; // mPDF 5.0
  796. $this->smCapsScale = 1;
  797. $this->smCapsStretch = 100;
  798. $this->defTextColor = $this->TextColor = $this->SetTColor($this->ConvertColor(0),true); // mPDF 5.0.051
  799. $this->defDrawColor = $this->DrawColor = $this->SetDColor($this->ConvertColor(0),true); // mPDF 5.0.051
  800. $this->defFillColor = $this->FillColor = $this->SetFColor($this->ConvertColor(255),true); // mPDF 5.0.051
  801. // mPDF 5.0.051
  802. //SVG color names array
  803. //http://www.w3schools.com/css/css_colornames.asp
  804. $this->SVGcolors = array('antiquewhite'=>'#FAEBD7','aqua'=>'#00FFFF','aquamarine'=>'#7FFFD4','beige'=>'#F5F5DC','black'=>'#000000',
  805. 'blue'=>'#0000FF','brown'=>'#A52A2A','cadetblue'=>'#5F9EA0','chocolate'=>'#D2691E','cornflowerblue'=>'#6495ED','crimson'=>'#DC143C',
  806. 'darkblue'=>'#00008B','darkgoldenrod'=>'#B8860B','darkgreen'=>'#006400','darkmagenta'=>'#8B008B','darkorange'=>'#FF8C00',
  807. 'darkred'=>'#8B0000','darkseagreen'=>'#8FBC8F','darkslategray'=>'#2F4F4F','darkviolet'=>'#9400D3','deepskyblue'=>'#00BFFF',
  808. 'dodgerblue'=>'#1E90FF','firebrick'=>'#B22222','forestgreen'=>'#228B22','fuchsia'=>'#FF00FF','gainsboro'=>'#DCDCDC','gold'=>'#FFD700',
  809. 'gray'=>'#808080','green'=>'#008000','greenyellow'=>'#ADFF2F','hotpink'=>'#FF69B4','indigo'=>'#4B0082','khaki'=>'#F0E68C',
  810. 'lavenderblush'=>'#FFF0F5','lemonchiffon'=>'#FFFACD','lightcoral'=>'#F08080','lightgoldenrodyellow'=>'#FAFAD2','lightgreen'=>'#90EE90',
  811. 'lightsalmon'=>'#FFA07A','lightskyblue'=>'#87CEFA','lightslategray'=>'#778899','lightyellow'=>'#FFFFE0','lime'=>'#00FF00','limegreen'=>'#32CD32',
  812. 'magenta'=>'#FF00FF','maroon'=>'#800000','mediumaquamarine'=>'#66CDAA','mediumorchid'=>'#BA55D3','mediumseagreen'=>'#3CB371',
  813. 'mediumspringgreen'=>'#00FA9A','mediumvioletred'=>'#C71585','midnightblue'=>'#191970','mintcream'=>'#F5FFFA','moccasin'=>'#FFE4B5','navy'=>'#000080',
  814. 'olive'=>'#808000','orange'=>'#FFA500','orchid'=>'#DA70D6','palegreen'=>'#98FB98',
  815. 'palevioletred'=>'#D87093','peachpuff'=>'#FFDAB9','pink'=>'#FFC0CB','powderblue'=>'#B0E0E6','purple'=>'#800080',
  816. 'red'=>'#FF0000','royalblue'=>'#4169E1','salmon'=>'#FA8072','seagreen'=>'#2E8B57','sienna'=>'#A0522D','silver'=>'#C0C0C0','skyblue'=>'#87CEEB',
  817. 'slategray'=>'#708090','springgreen'=>'#00FF7F','steelblue'=>'#4682B4','tan'=>'#D2B48C','teal'=>'#008080','thistle'=>'#D8BFD8','turquoise'=>'#40E0D0',
  818. 'violetred'=>'#D02090','white'=>'#FFFFFF','yellow'=>'#FFFF00',
  819. 'aliceblue'=>'#f0f8ff', 'azure'=>'#f0ffff', 'bisque'=>'#ffe4c4', 'blanchedalmond'=>'#ffebcd', 'blueviolet'=>'#8a2be2', 'burlywood'=>'#deb887',
  820. 'chartreuse'=>'#7fff00', 'coral'=>'#ff7f50', 'cornsilk'=>'#fff8dc', 'cyan'=>'#00ffff', 'darkcyan'=>'#008b8b', 'darkgray'=>'#a9a9a9',
  821. 'darkgrey'=>'#a9a9a9', 'darkkhaki'=>'#bdb76b', 'darkolivegreen'=>'#556b2f', 'darkorchid'=>'#9932cc', 'darksalmon'=>'#e9967a',
  822. 'darkslateblue'=>'#483d8b', 'darkslategrey'=>'#2f4f4f', 'darkturquoise'=>'#00ced1', 'deeppink'=>'#ff1493', 'dimgray'=>'#696969',
  823. 'dimgrey'=>'#696969', 'floralwhite'=>'#fffaf0', 'ghostwhite'=>'#f8f8ff', 'goldenrod'=>'#daa520', 'grey'=>'#808080', 'honeydew'=>'#f0fff0',
  824. 'indianred'=>'#cd5c5c', 'ivory'=>'#fffff0', 'lavender'=>'#e6e6fa', 'lawngreen'=>'#7cfc00', 'lightblue'=>'#add8e6', 'lightcyan'=>'#e0ffff',
  825. 'lightgray'=>'#d3d3d3', 'lightgrey'=>'#d3d3d3', 'lightpink'=>'#ffb6c1', 'lightseagreen'=>'#20b2aa', 'lightslategrey'=>'#778899',
  826. 'lightsteelblue'=>'#b0c4de', 'linen'=>'#faf0e6', 'mediumblue'=>'#0000cd', 'mediumpurple'=>'#9370db', 'mediumslateblue'=>'#7b68ee',
  827. 'mediumturquoise'=>'#48d1cc', 'mistyrose'=>'#ffe4e1', 'navajowhite'=>'#ffdead', 'oldlace'=>'#fdf5e6', 'olivedrab'=>'#6b8e23', 'orangered'=>'#ff4500',
  828. 'palegoldenrod'=>'#eee8aa', 'paleturquoise'=>'#afeeee', 'papayawhip'=>'#ffefd5', 'peru'=>'#cd853f', 'plum'=>'#dda0dd', 'rosybrown'=>'#bc8f8f',
  829. 'saddlebrown'=>'#8b4513', 'sandybrown'=>'#f4a460', 'seashell'=>'#fff5ee', 'slateblue'=>'#6a5acd', 'slategrey'=>'#708090', 'snow'=>'#fffafa',
  830. 'tomato'=>'#ff6347', 'violet'=>'#ee82ee', 'wheat'=>'#f5deb3', 'whitesmoke'=>'#f5f5f5', 'yellowgreen'=>'#9acd32');
  831. $this->ColorFlag=false;
  832. $this->extgstates = array();
  833. $this->mb_enc='windows-1252';
  834. $this->directionality='ltr';
  835. $this->defaultAlign = 'L';
  836. $this->defaultTableAlign = 'L';
  837. $this->fixedPosBlockSave = array();
  838. $this->extraFontSubsets = 0;
  839. $this->SHYpatterns = array();
  840. $this->loadedSHYdictionary = false;
  841. $this->SHYdictionary = array();
  842. $this->SHYdictionaryWords = array();
  843. $this->blockContext = 1;
  844. $this->floatDivs = array();
  845. $this->DisplayPreferences='';
  846. $this->tablecascadeCSS = array();
  847. $this->listcascadeCSS = array();
  848. $this->patterns = array(); // Tiling patterns used for backgrounds
  849. $this->pageBackgrounds = array();
  850. $this->writingHTMLheader = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  851. $this->writingHTMLfooter = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  852. $this->gradients = array();
  853. $this->kwt_Reference = array();
  854. $this->kwt_BMoutlines = array();
  855. $this->kwt_toc = array();
  856. $this->tbrot_Reference = array();
  857. $this->tbrot_BMoutlines = array();
  858. $this->tbrot_toc = array();
  859. $this->col_Reference = array();
  860. $this->col_BMoutlines = array();
  861. $this->col_toc = array();
  862. $this->graphs = array();
  863. $this->pgsIns = array();
  864. $this->PDFAXwarnings = array(); // mDPF 5.0.051
  865. $this->inlineDisplayOff = false; // mPDF 5.0
  866. $this->kerning = false; // mDPF 5.0.061
  867. $this->lSpacingCSS = ''; // mPDF 5.0.063
  868. $this->wSpacingCSS = ''; // mPDF 5.0.063
  869. $this->fixedlSpacing = false; // mPDF 5.0.063
  870. $this->minwSpacing = 0; // mPDF 5.0.063
  871. $this->baselineC = 0.35; // Baseline for text
  872. $this->noImageFile = str_replace("\\","/",dirname(__FILE__)) . '/includes/no_image.jpg';
  873. $this->subPos = 0;
  874. $this->forceExactLineheight = false;
  875. $this->listOcc = 0;
  876. $this->normalLineheight = 1.3;
  877. // These are intended as configuration variables, and should be set in config.php - which will override these values;
  878. // set here as failsafe as will cause an error if not defined
  879. $this->incrementFPR1 = 10;
  880. $this->incrementFPR2 = 10;
  881. $this->incrementFPR3 = 10;
  882. $this->incrementFPR4 = 10;
  883. $this->fullImageHeight = false;
  884. $this->floatbuffer = array();
  885. $this->floatmargins = array();
  886. $this->autoFontGroups = 0;
  887. $this->formobjects=array(); // array of Form Objects for WMF
  888. $this->InlineProperties=array();
  889. $this->InlineAnnots=array();
  890. $this->ktAnnots=array();
  891. $this->tbrot_Annots=array();
  892. $this->kwt_Annots=array();
  893. $this->columnAnnots=array();
  894. $this->pageDim=array();
  895. $this->breakpoints = array(); // used in columnbuffer
  896. $this->tableLevel=0;
  897. $this->tbctr=array(); // counter for nested tables at each level
  898. $this->page_box = array();
  899. $this->show_marks = ''; // crop or cross marks
  900. $this->kwt = false;
  901. $this->kwt_height = 0;
  902. $this->kwt_y0 = 0;
  903. $this->kwt_x0 = 0;
  904. $this->kwt_buffer = array();
  905. $this->kwt_Links = array();
  906. $this->kwt_moved = false;
  907. $this->kwt_saved = false;
  908. $this->PageNumSubstitutions = array();
  909. $this->base_table_properties=array();
  910. $this->borderstyles = array('inset','groove','outset','ridge','dotted','dashed','solid','double');
  911. $this->tbrot_align = 'C';
  912. $this->pageheaders=array();
  913. $this->pagefooters=array();
  914. $this->pageHTMLheaders=array();
  915. $this->pageHTMLfooters=array();
  916. $this->HTMLheaderPageLinks = array();
  917. $this->HTMLheaderPageAnnots = array(); // mPDF 5.0
  918. $this->cascadeCSS = array();
  919. $this->bufferoutput = false;
  920. $this->encrypted=false; //whether document is protected
  921. $this->BMoutlines=array();
  922. $this->_toc=array();
  923. $this->TOCheader=false;
  924. $this->TOCfooter=false;
  925. $this->ColActive=0; //Flag indicating that columns are on (the index is being processed)
  926. $this->ChangePage=0; //Flag indicating that a page break has occurred
  927. $this->Reference=array(); //Array containing the references
  928. $this->CurrCol=0; //Current column number
  929. $this->ColL = array(0); // Array of Left pos of columns - absolute - needs Margin correction for Odd-Even
  930. $this->ColR = array(0); // Array of Right pos of columns - absolute pos - needs Margin correction for Odd-Even
  931. $this->ChangeColumn = 0;
  932. $this->columnbuffer = array();
  933. $this->ColDetails = array(); // Keeps track of some column details
  934. $this->columnLinks = array(); // Cross references PageLinks
  935. $this->substitute = array(); // Array of substitution strings e.g. <ttz>112</ttz>
  936. $this->entsearch = array(); // Array of HTML entities (>ASCII 127) to substitute
  937. $this->entsubstitute = array(); // Array of substitution decimal unicode for the Hi entities
  938. $this->lastoptionaltag = '';
  939. $this->charset_in = '';
  940. $this->blk = array();
  941. $this->blklvl = 0;
  942. $this->TOCmark = 0;
  943. $this->tts = false;
  944. $this->ttz = false;
  945. $this->tta = false;
  946. $this->ispre=false;
  947. $this->checkSIP = false; // mPDF 5.0
  948. $this->checkSMP = false; // mPDF 5.0.03
  949. $this->checkCJK = false; // mPDF 5.0
  950. $this->tableCJK = false; // mPDF 5.0
  951. $this->headerDetails=array();
  952. $this->footerDetails=array();
  953. $this->div_bottom_border = '';
  954. $this->p_bottom_border = '';
  955. $this->page_break_after_avoid = false;
  956. $this->margin_bottom_collapse = false;
  957. $this->tablethead = 0;
  958. $this->tabletfoot = 0;
  959. $this->table_border_attr_set = 0;
  960. $this->table_border_css_set = 0;
  961. $this->shrin_k = 1.0;
  962. $this->shrink_this_table_to_fit = 0;
  963. $this->MarginCorrection = 0;
  964. $this->tabletheadjustfinished = false;
  965. $this->usingCoreFont = false;
  966. $this->charspacing=0;
  967. $this->outlines=array();
  968. $this->autoPageBreak = true;
  969. /*-- FORMS --*/
  970. // FORM ELEMENT SPACING
  971. $this->form_element_spacing['select']['outer']['h'] = 0.5; // Horizontal spacing around SELECT
  972. $this->form_element_spacing['select']['outer']['v'] = 0.5; // Vertical spacing around SELECT
  973. $this->form_element_spacing['select']['inner']['h'] = 0.7; // Horizontal padding around SELECT
  974. $this->form_element_spacing['select']['inner']['v'] = 0.7; // Vertical padding around SELECT
  975. $this->form_element_spacing['input']['outer']['h'] = 0.5;
  976. $this->form_element_spacing['input']['outer']['v'] = 0.5;
  977. $this->form_element_spacing['input']['inner']['h'] = 0.7;
  978. $this->form_element_spacing['input']['inner']['v'] = 0.7;
  979. $this->form_element_spacing['textarea']['outer']['h'] = 0.5;
  980. $this->form_element_spacing['textarea']['outer']['v'] = 0.5;
  981. $this->form_element_spacing['textarea']['inner']['h'] = 1;
  982. $this->form_element_spacing['textarea']['inner']['v'] = 0.5;
  983. $this->form_element_spacing['button']['outer']['h'] = 0.5;
  984. $this->form_element_spacing['button']['outer']['v'] = 0.5;
  985. $this->form_element_spacing['button']['inner']['h'] = 2;
  986. $this->form_element_spacing['button']['inner']['v'] = 1;
  987. /*-- END FORMS --*/
  988. require(_MPDF_PATH.'config.php'); // config data
  989. //Scale factor
  990. $this->k=72/25.4; // Will only use mm
  991. $this->_setPageSize($format, $orientation);
  992. $this->DefOrientation=$orientation;
  993. $this->margin_header=$mgh;
  994. $this->margin_footer=$mgf;
  995. $bmargin=$mgb;
  996. $this->DeflMargin = $mgl;
  997. $this->DefrMargin = $mgr;
  998. // v1.4 Save orginal settings in case of changed orientation
  999. $this->orig_tMargin = $mgt;
  1000. $this->orig_bMargin = $bmargin;
  1001. $this->orig_lMargin = $this->DeflMargin;
  1002. $this->orig_rMargin = $this->DefrMargin;
  1003. $this->orig_hMargin = $this->margin_header;
  1004. $this->orig_fMargin = $this->margin_footer;
  1005. if ($this->setAutoTopMargin=='pad') { $mgt += $this->margin_header; }
  1006. if ($this->setAutoBottomMargin=='pad') { $mgb += $this->margin_footer; }
  1007. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$mgt); // sets l r t margin
  1008. //Automatic page break
  1009. $this->SetAutoPageBreak($this->autoPageBreak,$bmargin); // sets $this->bMargin & PageBreakTrigger
  1010. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  1011. //Interior cell margin (1 mm) ? not used
  1012. $this->cMarginL = 1;
  1013. $this->cMarginR = 1;
  1014. //Line width (0.2 mm)
  1015. $this->LineWidth=.567/$this->k;
  1016. //To make the function Footer() work - replaces {nb} with page number
  1017. $this->AliasNbPages();
  1018. $this->AliasNbPageGroups();
  1019. // mPDF 5.0.04
  1020. $this->aliasNbPgHex = '{nbHEXmarker}';
  1021. $this->aliasNbPgGpHex = '{nbpgHEXmarker}';
  1022. //Enable all tags as default
  1023. $this->DisableTags();
  1024. //Full width display mode
  1025. $this->SetDisplayMode(100); // fullwidth? 'fullpage'
  1026. //Compression
  1027. $this->SetCompression(true);
  1028. //Set default display preferences
  1029. $this->SetDisplayPreferences('');
  1030. // Font data
  1031. require(_MPDF_PATH.'config_fonts.php');
  1032. // Available fonts
  1033. $this->available_unifonts = array();
  1034. foreach ($this->fontdata AS $f => $fs) {
  1035. if (isset($fs['R']) && $fs['R']) { $this->available_unifonts[] = $f; }
  1036. if (isset($fs['B']) && $fs['B']) { $this->available_unifonts[] = $f.'B'; }
  1037. if (isset($fs['I']) && $fs['I']) { $this->available_unifonts[] = $f.'I'; }
  1038. if (isset($fs['BI']) && $fs['BI']) { $this->available_unifonts[] = $f.'BI'; }
  1039. }
  1040. $this->default_available_fonts = $this->available_unifonts;
  1041. $optcore = false;
  1042. $onlyCoreFonts = false;
  1043. // mPDF 5.0
  1044. if (preg_match('/([\-+])aCJK/i',$mode, $m)) {
  1045. preg_replace('/([\-+])aCJK/i','',$mode);
  1046. if ($m[1]=='+') { $this->useAdobeCJK = true; }
  1047. else { $this->useAdobeCJK = false; }
  1048. }
  1049. if (strlen($mode)==1) {
  1050. if ($mode=='s') { $this->percentSubset = 100; $mode = ''; }
  1051. else if ($mode=='c') { $onlyCoreFonts = true; $mode = ''; }
  1052. }
  1053. else if (substr($mode,-2)=='-s') {
  1054. $this->percentSubset = 100;
  1055. $mode = substr($mode,0,strlen($mode)-2);
  1056. }
  1057. else if (substr($mode,-2)=='-c') {
  1058. $onlyCoreFonts = true;
  1059. $mode = substr($mode,0,strlen($mode)-2);
  1060. }
  1061. else if (substr($mode,-2)=='-x') {
  1062. $optcore = true;
  1063. $mode = substr($mode,0,strlen($mode)-2);
  1064. }
  1065. // Autodetect if mode is a language_country string (en-GB or en_GB or en)
  1066. if ((strlen($mode) == 5 && $mode != 'UTF-8') || strlen($mode) == 2) {
  1067. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($mode, $this->useAdobeCJK);
  1068. if ($coreSuitable && $optcore) { $onlyCoreFonts = true; }
  1069. if ($mpdf_pdf_unifonts) {
  1070. $this->RestrictUnicodeFonts($mpdf_pdf_unifonts);
  1071. $this->default_available_fonts = $mpdf_pdf_unifonts;
  1072. }
  1073. // $this->SetDirectionality($mpdf_directionality); // mPDF 5.0.054
  1074. $this->currentLang = $mode;
  1075. $this->default_lang = $mode;
  1076. }
  1077. $this->onlyCoreFonts = $onlyCoreFonts;
  1078. if ($this->onlyCoreFonts) {
  1079. $this->setMBencoding('windows-1252'); // sets $this->mb_enc
  1080. }
  1081. else {
  1082. $this->setMBencoding('UTF-8'); // sets $this->mb_enc
  1083. }
  1084. @mb_regex_encoding('UTF-8');
  1085. // mPDF 5.0 Adobe CJK fonts
  1086. //if ($this->useAdobeCJK) {
  1087. $this->available_CJK_fonts = array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  1088. 'gbBI','big5BI','sjisBI','uhcBI');
  1089. //}
  1090. //else { $this->available_CJK_fonts = array(); }
  1091. //Standard fonts
  1092. $this->CoreFonts=array('ccourier'=>'Courier','ccourierB'=>'Courier-Bold','ccourierI'=>'Courier-Oblique','ccourierBI'=>'Courier-BoldOblique',
  1093. 'chelvetica'=>'Helvetica','chelveticaB'=>'Helvetica-Bold','chelveticaI'=>'Helvetica-Oblique','chelveticaBI'=>'Helvetica-BoldOblique',
  1094. 'ctimes'=>'Times-Roman','ctimesB'=>'Times-Bold','ctimesI'=>'Times-Italic','ctimesBI'=>'Times-BoldItalic',
  1095. 'csymbol'=>'Symbol','czapfdingbats'=>'ZapfDingbats');
  1096. $this->fontlist=array("ctimes","ccourier","chelvetica","csymbol","czapfdingbats");
  1097. // Substitutions
  1098. $this->setHiEntitySubstitutions();
  1099. if ($this->onlyCoreFonts) {
  1100. $this->useSubstitutions = true;
  1101. $this->SetSubstitutions();
  1102. }
  1103. else { $this->useSubstitutions = false; }
  1104. if (file_exists(_MPDF_PATH.'mpdf.css')) {
  1105. $css = file_get_contents(_MPDF_PATH.'mpdf.css');
  1106. $css2 = $this->ReadDefaultCSS($css);
  1107. $this->defaultCSS = $this->array_merge_recursive_unique($this->defaultCSS,$css2);
  1108. }
  1109. if ($default_font=='') {
  1110. if ($this->onlyCoreFonts) {
  1111. if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->mono_fonts)) { $default_font = 'ccourier'; }
  1112. else if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->sans_fonts)) { $default_font = 'chelvetica'; }
  1113. else { $default_font = 'ctimes'; }
  1114. }
  1115. else { $default_font = $this->defaultCSS['BODY']['FONT-FAMILY']; }
  1116. }
  1117. if (!$default_font_size) {
  1118. $mmsize = $this->ConvertSize($this->defaultCSS['BODY']['FONT-SIZE']);
  1119. $default_font_size = $mmsize*($this->k);
  1120. }
  1121. if ($default_font) { $this->SetDefaultFont($default_font); }
  1122. if ($default_font_size) { $this->SetDefaultFontSize($default_font_size); }
  1123. $this->SetLineHeight(); // lineheight is in mm
  1124. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  1125. $this->HREF='';
  1126. $this->oldy=-1;
  1127. $this->B=0;
  1128. $this->U=0;
  1129. $this->S=0; // mPDF 5.0
  1130. $this->I=0;
  1131. $this->listlvl=0;
  1132. $this->listnum=0;
  1133. $this->listtype='';
  1134. $this->listoccur=array();
  1135. $this->listlist=array();
  1136. $this->listitem=array();
  1137. $this->tdbegin=false;
  1138. $this->table=array();
  1139. $this->cell=array();
  1140. $this->col=-1;
  1141. $this->row=-1;
  1142. $this->cellBorderBuffer = array();
  1143. $this->divbegin=false;
  1144. $this->divalign=''; // mPDF 5.0.054
  1145. $this->divwidth=0;
  1146. $this->divheight=0;
  1147. $this->spanbgcolor=false;
  1148. $this->divrevert=false;
  1149. $this->issetfont=false;
  1150. $this->issetcolor=false;
  1151. $this->blockjustfinished=false;
  1152. $this->listjustfinished=false;
  1153. $this->ignorefollowingspaces = true; //in order to eliminate exceeding left-side spaces
  1154. $this->toupper=false;
  1155. $this->tolower=false;
  1156. $this->capitalize=false; // mPDF 5.0.062
  1157. $this->dash_on=false;
  1158. $this->dotted_on=false;
  1159. $this->SUP=false;
  1160. $this->SUB=false;
  1161. $this->strike=false;
  1162. $this->currentfontfamily='';
  1163. $this->currentfontsize='';
  1164. $this->currentfontstyle='';
  1165. $this->colorarray=array();
  1166. $this->spanbgcolorarray=array();
  1167. $this->textbuffer=array();
  1168. $this->CSS=array();
  1169. $this->internallink=array();
  1170. $this->basepath = "";
  1171. $this->SetBasePath('');
  1172. $this->outlineparam = array();
  1173. $this->outline_on = false;
  1174. $this->specialcontent = '';
  1175. $this->selectoption = array();
  1176. $this->usetableheader=false;
  1177. $this->usecss=true;
  1178. $this->usepre=true;
  1179. for($i=0;$i<256;$i++) {
  1180. $this->chrs[$i] = chr($i);
  1181. $this->ords[chr($i)] = $i;
  1182. }
  1183. /*-- IMPORTS --*/
  1184. $this->tpls = array();
  1185. $this->tpl = 0;
  1186. $this->tplprefix = "/TPL";
  1187. $this->res = array();
  1188. if ($this->enableImports) {
  1189. $this->SetImportUse();
  1190. }
  1191. /*-- END IMPORTS --*/
  1192. if ($this->progressBar) { $this->StartProgressBarOutput($this->progressBar) ; } // *PROGRESS-BAR*
  1193. }
  1194. function _setPageSize($format, &$orientation) {
  1195. //Page format
  1196. if(is_string($format))
  1197. {
  1198. if ($format=='') { $format = 'A4'; }
  1199. $pfo = 'P';
  1200. if(preg_match('/([0-9a-zA-Z]*)-L/i',$format,$m)) { // e.g. A4-L = A$ landscape
  1201. $format=$m[1];
  1202. $pfo='L';
  1203. }
  1204. $format = $this->_getPageFormat($format);
  1205. if (!$format) { $this->Error('Unknown page format: '.$format); }
  1206. else { $orientation = $pfo; }
  1207. $this->fwPt=$format[0];
  1208. $this->fhPt=$format[1];
  1209. }
  1210. else
  1211. {
  1212. if (!$format[0] || !$format[1]) { $this->Error('Invalid page format: '.$format[0].' '.$format[1]); }
  1213. $this->fwPt=$format[0]*$this->k;
  1214. $this->fhPt=$format[1]*$this->k;
  1215. }
  1216. $this->fw=$this->fwPt/$this->k;
  1217. $this->fh=$this->fhPt/$this->k;
  1218. //Page orientation
  1219. $orientation=strtolower($orientation);
  1220. if($orientation=='p' or $orientation=='portrait')
  1221. {
  1222. $orientation='P';
  1223. $this->wPt=$this->fwPt;
  1224. $this->hPt=$this->fhPt;
  1225. }
  1226. elseif($orientation=='l' or $orientation=='landscape')
  1227. {
  1228. $orientation='L';
  1229. $this->wPt=$this->fhPt;
  1230. $this->hPt=$this->fwPt;
  1231. }
  1232. else $this->Error('Incorrect orientation: '.$orientation);
  1233. $this->CurOrientation=$orientation;
  1234. $this->w=$this->wPt/$this->k;
  1235. $this->h=$this->hPt/$this->k;
  1236. }
  1237. function _getPageFormat($format) {
  1238. switch (strtoupper($format)) {
  1239. case '4A0': {$format = array(4767.87,6740.79); break;}
  1240. case '2A0': {$format = array(3370.39,4767.87); break;}
  1241. case 'A0': {$format = array(2383.94,3370.39); break;}
  1242. case 'A1': {$format = array(1683.78,2383.94); break;}
  1243. case 'A2': {$format = array(1190.55,1683.78); break;}
  1244. case 'A3': {$format = array(841.89,1190.55); break;}
  1245. case 'A4': default: {$format = array(595.28,841.89); break;}
  1246. case 'A5': {$format = array(419.53,595.28); break;}
  1247. case 'A6': {$format = array(297.64,419.53); break;}
  1248. case 'A7': {$format = array(209.76,297.64); break;}
  1249. case 'A8': {$format = array(147.40,209.76); break;}
  1250. case 'A9': {$format = array(104.88,147.40); break;}
  1251. case 'A10': {$format = array(73.70,104.88); break;}
  1252. case 'B0': {$format = array(2834.65,4008.19); break;}
  1253. case 'B1': {$format = array(2004.09,2834.65); break;}
  1254. case 'B2': {$format = array(1417.32,2004.09); break;}
  1255. case 'B3': {$format = array(1000.63,1417.32); break;}
  1256. case 'B4': {$format = array(708.66,1000.63); break;}
  1257. case 'B5': {$format = array(498.90,708.66); break;}
  1258. case 'B6': {$format = array(354.33,498.90); break;}
  1259. case 'B7': {$format = array(249.45,354.33); break;}
  1260. case 'B8': {$format = array(175.75,249.45); break;}
  1261. case 'B9': {$format = array(124.72,175.75); break;}
  1262. case 'B10': {$format = array(87.87,124.72); break;}
  1263. case 'C0': {$format = array(2599.37,3676.54); break;}
  1264. case 'C1': {$format = array(1836.85,2599.37); break;}
  1265. case 'C2': {$format = array(1298.27,1836.85); break;}
  1266. case 'C3': {$format = array(918.43,1298.27); break;}
  1267. case 'C4': {$format = array(649.13,918.43); break;}
  1268. case 'C5': {$format = array(459.21,649.13); break;}
  1269. case 'C6': {$format = array(323.15,459.21); break;}
  1270. case 'C7': {$format = array(229.61,323.15); break;}
  1271. case 'C8': {$format = array(161.57,229.61); break;}
  1272. case 'C9': {$format = array(113.39,161.57); break;}
  1273. case 'C10': {$format = array(79.37,113.39); break;}
  1274. case 'RA0': {$format = array(2437.80,3458.27); break;}
  1275. case 'RA1': {$format = array(1729.13,2437.80); break;}
  1276. case 'RA2': {$format = array(1218.90,1729.13); break;}
  1277. case 'RA3': {$format = array(864.57,1218.90); break;}
  1278. case 'RA4': {$format = array(609.45,864.57); break;}
  1279. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  1280. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  1281. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  1282. case 'SRA3': {$format = array(907.09,1275.59); break;}
  1283. case 'SRA4': {$format = array(637.80,907.09); break;}
  1284. case 'LETTER': {$format = array(612.00,792.00); break;}
  1285. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  1286. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  1287. case 'FOLIO': {$format = array(612.00,936.00); break;}
  1288. case 'B': {$format=array(362.83,561.26 ); break;} // 'B' format paperback size 128x198mm
  1289. case 'A': {$format=array(314.65,504.57 ); break;} // 'A' format paperback size 111x178mm
  1290. case 'DEMY': {$format=array(382.68,612.28 ); break;} // 'Demy' format paperback size 135x216mm
  1291. case 'ROYAL': {$format=array(433.70,663.30 ); break;} // 'Royal' format paperback size 153x234mm
  1292. default: $format = false;
  1293. }
  1294. return $format;
  1295. }
  1296. /*-- PROGRESS-BAR --*/
  1297. function StartProgressBarOutput($mode=1) {
  1298. // must be relative path, or URI (not a file system path)
  1299. if (!defined('_MPDF_URI')) {
  1300. $this->progressBar = false;
  1301. if ($this->debug) { $this->Error("You need to define _MPDF_URI to use the progress bar!"); }
  1302. else return false;
  1303. }
  1304. $this->progressBar = $mode;
  1305. if ($this->progbar_altHTML) {
  1306. echo $this->progbar_altHTML;
  1307. }
  1308. else {
  1309. echo '<html>
  1310. <head>
  1311. <title>mPDF File Progress</title>
  1312. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1313. <link rel="stylesheet" type="text/css" href="'._MPDF_URI.'progbar.css" />
  1314. </head>
  1315. <body>
  1316. <div class="main">
  1317. <div class="heading">'.$this->progbar_heading.'</div>
  1318. <div class="demo">
  1319. ';
  1320. if ($this->progressBar==2) { echo ' <table width="100%"><tr><td style="width: 50%;">
  1321. <span class="barheading">Writing HTML code</span> <br/>
  1322. <div class="progressBar">
  1323. <div id="element1" class="innerBar">&nbsp;</div>
  1324. </div>
  1325. <span class="code" id="box1"></span>
  1326. </td><td style="width: 50%;">
  1327. <span class="barheading">Autosizing elements</span> <br/>
  1328. <div class="progressBar">
  1329. <div id="element4" class="innerBar">&nbsp;</div>
  1330. </div>
  1331. <span class="code" id="box4"></span>
  1332. <br/><br/>
  1333. <span class="barheading">Writing Tables</span> <br/>
  1334. <div class="progressBar">
  1335. <div id="element7" class="innerBar">&nbsp;</div>
  1336. </div>
  1337. <span class="code" id="box7"></span>
  1338. </td></tr>
  1339. <tr><td><br /><br /></td><td></td></tr>
  1340. <tr><td style="width: 50%;">
  1341. '; }
  1342. echo ' <span class="barheading">Writing PDF file</span> <br/>
  1343. <div class="progressBar">
  1344. <div id="element2" class="innerBar">&nbsp;</div>
  1345. </div>
  1346. <span class="code" id="box2"></span>
  1347. ';
  1348. if ($this->progressBar==2) { echo '
  1349. </td><td style="width: 50%;">
  1350. <span class="barheading">Memory usage</span> <br/>
  1351. <div class="progressBar">
  1352. <div id="element5" class="innerBar">&nbsp;</div>
  1353. </div>
  1354. <span id="box5">0</span> '.ini_get("memory_limit").'<br />
  1355. <br/><br/>
  1356. <span class="barheading">Memory usage (peak)</span> <br/>
  1357. <div class="progressBar">
  1358. <div id="element6" class="innerBar">&nbsp;</div>
  1359. </div>
  1360. <span id="box6">0</span> '.ini_get("memory_limit").'<br />
  1361. </td></tr>
  1362. </table>
  1363. '; }
  1364. echo ' <br/><br/>
  1365. <span id="box3"></span>
  1366. </div>
  1367. ';
  1368. }
  1369. ob_flush();
  1370. flush();
  1371. }
  1372. function UpdateProgressBar($el,$val,$txt='') {
  1373. // $val should be a string - 5 = actual value, +15 = increment
  1374. if ($this->progressBar<2) {
  1375. if ($el>3) { return; }
  1376. else if ($el ==1) { $el = 2; }
  1377. }
  1378. echo '<script type="text/javascript">';
  1379. if ($val) { echo ' document.getElementById(\'element'.$el.'\').style.width=\''.$val.'%\'; '; }
  1380. if ($txt) { echo ' document.getElementById(\'box'.$el.'\').innerHTML=\''.$txt.'\'; '; }
  1381. if ($this->progressBar==2) {
  1382. $m = round(memory_get_usage()/1048576);
  1383. $m2 = round(memory_get_peak_usage()/1048576);
  1384. $mem = $m * 100 / (ini_get("memory_limit")+0);
  1385. $mem2 = $m2 * 100 / (ini_get("memory_limit")+0);
  1386. echo ' document.getElementById(\'element5\').style.width=\''.$mem.'%\'; ';
  1387. echo ' document.getElementById(\'element6\').style.width=\''.$mem2.'%\'; ';
  1388. echo ' document.getElementById(\'box5\').innerHTML=\''.$m.'MB / \'; ';
  1389. echo ' document.getElementById(\'box6\').innerHTML=\''.$m2.'MB / \'; ';
  1390. }
  1391. echo '</script>'."\n";
  1392. ob_flush();
  1393. flush();
  1394. }
  1395. /*-- END PROGRESS-BAR --*/
  1396. function RestrictUnicodeFonts($res) {
  1397. // $res = array of (Unicode) fonts to restrict to: e.g. norasi|norasiB - language specific
  1398. if (count($res)) { // Leave full list of available fonts if passed blank array
  1399. $this->available_unifonts = $res;
  1400. }
  1401. else { $this->available_unifonts = $this->default_available_fonts; }
  1402. if (count($this->available_unifonts) == 0) { $this->available_unifonts[] = $this->default_available_fonts[0]; }
  1403. $this->available_unifonts = array_values($this->available_unifonts);
  1404. }
  1405. function setMBencoding($enc) {
  1406. @mb_regex_encoding('UTF-8');
  1407. $curr = $this->mb_enc;
  1408. $this->mb_enc = $enc;
  1409. if (!$this->mb_enc || $curr != $this->mb_enc) {
  1410. mb_internal_encoding($this->mb_enc);
  1411. if ($enc == 'UTF-8') { @mb_regex_encoding('UTF-8'); }
  1412. // else if ($enc == 'windows-1252') { @mb_regex_encoding('ISO-8859-1'); }
  1413. }
  1414. }
  1415. function SetMargins($left,$right,$top) {
  1416. //Set left, top and right margins
  1417. $this->lMargin=$left;
  1418. $this->rMargin=$right;
  1419. $this->tMargin=$top;
  1420. }
  1421. function ResetMargins() {
  1422. //ReSet left, top margins
  1423. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P' && $this->CurOrientation=='L') {
  1424. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1425. $this->tMargin=$this->orig_rMargin;
  1426. $this->bMargin=$this->orig_lMargin;
  1427. }
  1428. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1429. $this->tMargin=$this->orig_lMargin;
  1430. $this->bMargin=$this->orig_rMargin;
  1431. }
  1432. $this->lMargin=$this->DeflMargin;
  1433. $this->rMargin=$this->DefrMargin;
  1434. $this->MarginCorrection = 0;
  1435. $this->PageBreakTrigger=$this->h-$this->bMargin;
  1436. }
  1437. else if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1438. $this->lMargin=$this->DefrMargin;
  1439. $this->rMargin=$this->DeflMargin;
  1440. $this->MarginCorrection = $this->DefrMargin-$this->DeflMargin;
  1441. }
  1442. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1443. $this->lMargin=$this->DeflMargin;
  1444. $this->rMargin=$this->DefrMargin;
  1445. if ($this->mirrorMargins) { $this->MarginCorrection = $this->DeflMargin-$this->DefrMargin; }
  1446. }
  1447. $this->x=$this->lMargin;
  1448. }
  1449. function SetLeftMargin($margin) {
  1450. //Set left margin
  1451. $this->lMargin=$margin;
  1452. if($this->page>0 and $this->x<$margin) $this->x=$margin;
  1453. }
  1454. function SetTopMargin($margin) {
  1455. //Set top margin
  1456. $this->tMargin=$margin;
  1457. }
  1458. function SetRightMargin($margin) {
  1459. //Set right margin
  1460. $this->rMargin=$margin;
  1461. }
  1462. function SetAutoPageBreak($auto,$margin=0) {
  1463. //Set auto page break mode and triggering margin
  1464. $this->autoPageBreak=$auto;
  1465. $this->bMargin=$margin;
  1466. $this->PageBreakTrigger=$this->h-$margin;
  1467. }
  1468. function SetDisplayMode($zoom,$layout='continuous') {
  1469. //Set display mode in viewer
  1470. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
  1471. $this->ZoomMode=$zoom;
  1472. else
  1473. $this->Error('Incorrect zoom display mode: '.$zoom);
  1474. // mPDF 5.1.023
  1475. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='twoleft' or $layout=='tworight' or $layout=='default')
  1476. $this->LayoutMode=$layout;
  1477. else
  1478. $this->Error('Incorrect layout display mode: '.$layout);
  1479. }
  1480. function SetCompression($compress) {
  1481. //Set page compression
  1482. if(function_exists('gzcompress')) $this->compress=$compress;
  1483. else $this->compress=false;
  1484. }
  1485. function SetTitle($title) {
  1486. //Title of document // Arrives as UTF-8
  1487. $this->title = $title;
  1488. }
  1489. function SetSubject($subject) {
  1490. //Subject of document
  1491. $this->subject= $subject;
  1492. }
  1493. function SetAuthor($author) {
  1494. //Author of document
  1495. $this->author= $author;
  1496. }
  1497. function SetKeywords($keywords) {
  1498. //Keywords of document
  1499. $this->keywords= $keywords;
  1500. }
  1501. function SetCreator($creator) {
  1502. //Creator of document
  1503. $this->creator= $creator;
  1504. }
  1505. function SetAnchor2Bookmark($x) {
  1506. $this->anchor2Bookmark = $x;
  1507. }
  1508. function AliasNbPages($alias='{nb}') {
  1509. //Define an alias for total number of pages
  1510. $this->aliasNbPg=$alias;
  1511. }
  1512. function AliasNbPageGroups($alias='{nbpg}') {
  1513. //Define an alias for total number of pages in a group
  1514. $this->aliasNbPgGp=$alias;
  1515. }
  1516. function SetAlpha($alpha, $bm='Normal', $return=false, $mode='B') { // mPDF 5.0.051
  1517. // alpha: real value from 0 (transparent) to 1 (opaque)
  1518. // bm: blend mode, one of the following:
  1519. // Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
  1520. // HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  1521. // set alpha for stroking (CA) and non-stroking (ca) operations
  1522. // mode determines F (fill) S (stroke) B (both)
  1523. if (($this->PDFA || $this->PDFX) && $alpha!=1) {
  1524. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Image opacity must be 100% (Opacity changed to 100%)"; }
  1525. $alpha = 1;
  1526. }
  1527. // mPDF 5.0.051
  1528. $a = array('BM'=>'/'.$bm);
  1529. if ($mode=='F' || $mode='B') $a['ca'] = $alpha;
  1530. if ($mode=='S' || $mode='B') $a['CA'] = $alpha;
  1531. $gs = $this->AddExtGState($a);
  1532. if ($return) { return sprintf('/GS%d gs', $gs); }
  1533. else { $this->_out(sprintf('/GS%d gs', $gs)); }
  1534. }
  1535. // mPDF 5.0 - Accepts any Graphic state
  1536. function AddExtGState($parms) {
  1537. $n = count($this->extgstates);
  1538. // check if graphics state already exists
  1539. for ($i=1; $i<=$n; $i++) {
  1540. if (count($this->extgstates[$i]['parms']) == count($parms)) {
  1541. $same = true;
  1542. foreach($this->extgstates[$i]['parms'] AS $k=>$v) {
  1543. if (!isset($parms[$k]) || $parms[$k] != $v) { $same = false; break; }
  1544. }
  1545. if ($same) { return $i; }
  1546. }
  1547. }
  1548. $n++;
  1549. $this->extgstates[$n]['parms'] = $parms;
  1550. return $n;
  1551. }
  1552. function Error($msg) {
  1553. //Fatal error
  1554. header('Content-Type: text/html; charset=utf-8');
  1555. die('<B>mPDF error: </B>'.$msg);
  1556. }
  1557. function Open() {
  1558. //Begin document
  1559. if($this->state==0) $this->_begindoc();
  1560. }
  1561. function Close() {
  1562. if ($this->progressBar) { $this->UpdateProgressBar(2,'2','Closing last page'); } // *PROGRESS-BAR*
  1563. //Terminate document
  1564. if($this->state==3) return;
  1565. if($this->page==0) $this->AddPage($this->CurOrientation);
  1566. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  1567. if ($this->tablebuffer) { $this->printtablebuffer(); } // *TABLES*
  1568. /*-- COLUMNS --*/
  1569. if ($this->ColActive) {
  1570. $this->SetColumns(0);
  1571. $this->ColActive = 0;
  1572. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  1573. }
  1574. /*-- END COLUMNS --*/
  1575. if (count($this->divbuffer)) { $this->printdivbuffer(); }
  1576. // BODY Backgrounds
  1577. $s = '';
  1578. // mPDF 5.0.023 5.0.047
  1579. $s .= $this->PrintBodyBackgrounds();
  1580. $s .= $this->PrintPageBackgrounds();
  1581. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1582. $this->pageBackgrounds = array();
  1583. if (!$this->TOCmark) { //Page footer
  1584. $this->InFooter=true;
  1585. $this->Footer();
  1586. $this->InFooter=false;
  1587. }
  1588. if ($this->TOCmark || count($this->m_TOC)) { $this->insertTOC(); } // *TOC*
  1589. //Close page
  1590. $this->_endpage();
  1591. //Close document
  1592. $this->_enddoc();
  1593. }
  1594. /*-- BACKGROUNDS --*/
  1595. function _resizeBackgroundImage($imw, $imh, $cw, $ch, $resize=0, $repx, $repy) {
  1596. $cw = $cw*$this->k;
  1597. $ch = $ch*$this->k;
  1598. if (!$resize) { return array($imw, $imh, $repx, $repy); }
  1599. if ($resize==1 && $imw > $cw) {
  1600. $h = $imh * $cw/$imw;
  1601. $repx = false;
  1602. return array($cw, $h, $repx, $repy);
  1603. }
  1604. else if ($resize==2 && $imh > $ch) {
  1605. $w = $imw * $ch/$imh;
  1606. $repy = false;
  1607. return array($w, $ch, $repx, $repy);
  1608. }
  1609. else if ($resize==3) {
  1610. $w = $imw;
  1611. $h = $imh;
  1612. $saverepx = $repx;
  1613. if ($w > $cw) {
  1614. $h = $h * $cw/$w;
  1615. $w = $cw;
  1616. $repx = false;
  1617. }
  1618. if ($h > $ch) {
  1619. $w = $w * $ch/$h;
  1620. $h = $ch;
  1621. $repy = false;
  1622. $repx = $saverepx;
  1623. }
  1624. return array($w, $h, $repx, $repy);
  1625. }
  1626. else if ($resize==4) {
  1627. $h = $imh * $cw/$imw;
  1628. $repx = false;
  1629. return array($cw, $h, $repx, $repy);
  1630. }
  1631. else if ($resize==5) {
  1632. $w = $imw * $ch/$imh;
  1633. $repy = false;
  1634. return array($w, $ch, $repx, $repy);
  1635. }
  1636. else if ($resize==6) {
  1637. $repx = false;
  1638. $repy = false;
  1639. return array($cw, $ch, $repx, $repy);
  1640. }
  1641. return array($imw, $imh, $repx, $repy);
  1642. }
  1643. // mPDF 5.0.023
  1644. function SetBackground(&$properties, &$maxwidth) {
  1645. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['BACKGROUND-IMAGE'])) {
  1646. return array('gradient'=>$properties['BACKGROUND-IMAGE']);
  1647. }
  1648. else {
  1649. $file = $properties['BACKGROUND-IMAGE'];
  1650. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, true); // mPDF 5.0.039
  1651. if (isset($sizesarray['IMAGE_ID'])) {
  1652. $image_id = $sizesarray['IMAGE_ID'];
  1653. $orig_w = $sizesarray['WIDTH']*$this->k; // in user units i.e. mm
  1654. $orig_h = $sizesarray['HEIGHT']*$this->k; // (using $this->img_dpi)
  1655. // mPDF 5.0.031
  1656. if (isset($properties['BACKGROUND-IMAGE-RESOLUTION'])) {
  1657. if (preg_match('/from-image/i', $properties['BACKGROUND-IMAGE-RESOLUTION']) && isset($sizesarray['set-dpi']) && $sizesarray['set-dpi']>0) {
  1658. $orig_w *= $this->img_dpi / $sizesarray['set-dpi'];
  1659. $orig_h *= $this->img_dpi / $sizesarray['set-dpi'];
  1660. }
  1661. else if (preg_match('/(\d+)dpi/i', $properties['BACKGROUND-IMAGE-RESOLUTION'], $m)) {
  1662. $dpi = $m[1];
  1663. if ($dpi > 0) {
  1664. $orig_w *= $this->img_dpi / $dpi;
  1665. $orig_h *= $this->img_dpi / $dpi;
  1666. }
  1667. }
  1668. }
  1669. $x_repeat = true;
  1670. $y_repeat = true;
  1671. if (isset($properties['BACKGROUND-REPEAT'])) {
  1672. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  1673. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  1674. }
  1675. $x_pos = 0;
  1676. $y_pos = 0;
  1677. if (isset($properties['BACKGROUND-POSITION'])) {
  1678. $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']);
  1679. $x_pos = $ppos[0];
  1680. $y_pos = $ppos[1];
  1681. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$maxwidth,$this->FontSize); }
  1682. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$maxwidth,$this->FontSize); }
  1683. }
  1684. if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; }
  1685. else { $resize = 0; }
  1686. if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; }
  1687. else { $opacity = 1; }
  1688. return array('image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$sizesarray['itype']); // mPDF 5.0.039
  1689. }
  1690. }
  1691. return false;
  1692. }
  1693. /*-- END BACKGROUNDS --*/
  1694. // mPDF 5.0.023
  1695. // mPDF 5.0.047
  1696. function PrintBodyBackgrounds() {
  1697. $s = '';
  1698. $clx = 0;
  1699. $cly = 0;
  1700. $clw = $this->w;
  1701. $clh = $this->h;
  1702. // If using bleed and trim margins in paged media
  1703. if ($this->pageDim[$this->page]['outer_width_LR'] || $this->pageDim[$this->page]['outer_width_TB']) {
  1704. $clx = $this->pageDim[$this->page]['outer_width_LR'] - $this->pageDim[$this->page]['bleedMargin'];
  1705. $cly = $this->pageDim[$this->page]['outer_width_TB'] - $this->pageDim[$this->page]['bleedMargin'];
  1706. $clw = $this->w - 2*$clx;
  1707. $clh = $this->h - 2*$cly;
  1708. }
  1709. if ($this->bodyBackgroundColor) {
  1710. $s .= 'q ' .$this->SetFColor($this->bodyBackgroundColor, true)."\n"; // mPDF 5.0.051
  1711. if ($this->bodyBackgroundColor[0]==5) { // RGBa
  1712. $s .= $this->SetAlpha($this->bodyBackgroundColor[4], 'Normal', true, 'F')."\n"; // mPDF 5.0.051
  1713. }
  1714. else if ($this->bodyBackgroundColor[0]==6) { // CMYKa
  1715. $s .= $this->SetAlpha($this->bodyBackgroundColor[5], 'Normal', true, 'F')."\n"; // mPDF 5.0.051
  1716. }
  1717. $s .= sprintf('%.3f %.3f %.3f %.3f re f Q', ($clx*$this->k), ($cly*$this->k),$clw*$this->k,$clh*$this->k)."\n";
  1718. }
  1719. /*-- BACKGROUNDS --*/
  1720. if ($this->bodyBackgroundGradient) {
  1721. $g = $this->parseBackgroundGradient($this->bodyBackgroundGradient);
  1722. if ($g) {
  1723. $s .= $this->Gradient($clx, $cly, $clw, $clh, (isset($g['gradtype']) ? $g['gradtype'] : null), $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true); // mPDF 5.0.052
  1724. }
  1725. }
  1726. if ($this->bodyBackgroundImage) {
  1727. if ( $this->bodyBackgroundImage['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->bodyBackgroundImage['gradient'])) {
  1728. $g = $this->parseMozGradient( $this->bodyBackgroundImage['gradient']);
  1729. if ($g) {
  1730. $s .= $this->Gradient($clx, $cly, $clw, $clh, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
  1731. }
  1732. }
  1733. else if ($this->bodyBackgroundImage['image_id']) { // Background pattern
  1734. $n = count($this->patterns)+1;
  1735. // If using resize, uses TrimBox (not including the bleed)
  1736. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($this->bodyBackgroundImage['orig_w'], $this->bodyBackgroundImage['orig_h'], $clw, $clh, $this->bodyBackgroundImage['resize'], $this->bodyBackgroundImage['x_repeat'], $this->bodyBackgroundImage['y_repeat']);
  1737. $this->patterns[$n] = array('x'=>$clx, 'y'=>$cly, 'w'=>$clw, 'h'=>$clh, 'pgh'=>$this->h, 'image_id'=>$this->bodyBackgroundImage['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$this->bodyBackgroundImage['x_pos'], 'y_pos'=>$this->bodyBackgroundImage['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$this->bodyBackgroundImage['itype']); // mPDF 5.0.039
  1738. if ($this->bodyBackgroundImage['opacity']>0 && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); }
  1739. else { $opac = ''; }
  1740. $s .= sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, ($clx*$this->k), ($cly*$this->k),$clw*$this->k, $clh*$this->k) ."\n";
  1741. }
  1742. }
  1743. /*-- END BACKGROUNDS --*/
  1744. return $s;
  1745. }
  1746. function PrintPageBackgrounds($adjustmenty=0) {
  1747. $s = '';
  1748. ksort($this->pageBackgrounds);
  1749. foreach($this->pageBackgrounds AS $bl=>$pbs) {
  1750. foreach ($pbs AS $pb) {
  1751. if (!isset($pb['image_id']) && !isset($pb['gradient'])) { // Background colour
  1752. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1753. $s .= 'q '.$this->SetFColor($pb['col'], true)."\n"; // mPDF 5.0.051
  1754. if ($pb['col'][0]==5) { // RGBa
  1755. $s .= $this->SetAlpha($pb['col'][4], 'Normal', true, 'F')."\n"; // mPDF 5.0.051
  1756. }
  1757. else if ($pb['col'][0]==6) { // CMYKa
  1758. $s .= $this->SetAlpha($pb['col'][5], 'Normal', true, 'F')."\n"; // mPDF 5.0.051
  1759. }
  1760. $s .= sprintf('%.3f %.3f %.3f %.3f re f Q',$pb['x']*$this->k,($this->h-$pb['y'])*$this->k,$pb['w']*$this->k,-$pb['h']*$this->k)."\n";
  1761. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1762. }
  1763. }
  1764. /*-- BACKGROUNDS --*/
  1765. foreach ($pbs AS $pb) {
  1766. if (isset($pb['gradient']) && $pb['gradient']) {
  1767. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1768. // mPDF 5.0.020
  1769. $s .= $this->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1770. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1771. }
  1772. // mPDF 5.0.023
  1773. else if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1774. $pb['y'] -= $adjustmenty;
  1775. $pb['h'] += $adjustmenty;
  1776. $n = count($this->patterns)+1;
  1777. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($pb['orig_w'], $pb['orig_h'], $pb['w'], $pb['h'], $pb['resize'], $pb['x_repeat'], $pb['y_repeat']);
  1778. $this->patterns[$n] = array('x'=>$pb['x'], 'y'=>$pb['y'], 'w'=>$pb['w'], 'h'=>$pb['h'], 'pgh'=>$this->h, 'image_id'=>$pb['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$pb['x_pos'], 'y_pos'=>$pb['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$pb['itype']); // mPDF 5.0.039
  1779. $x = $pb['x']*$this->k;
  1780. $y = ($this->h - $pb['y'])*$this->k;
  1781. $w = $pb['w']*$this->k;
  1782. $h = -$pb['h']*$this->k;
  1783. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1784. if ($this->writingHTMLfooter || $this->writingHTMLheader) {
  1785. $iw = $pb['orig_w']/$this->k;
  1786. $ih = $pb['orig_h']/$this->k;
  1787. $w = $pb['w'];
  1788. $h = $pb['h'];
  1789. $x0 = $pb['x'];
  1790. $y0 = $pb['y'];
  1791. // Number to repeat
  1792. if ($pb['x_repeat']) { $nx = ceil($w/$iw); }
  1793. else { $nx = 1; }
  1794. if ($pb['y_repeat']) { $ny = ceil($h/$ih); }
  1795. else { $ny = 1; }
  1796. $x_pos = $pb['x_pos'];
  1797. if (stristr($x_pos ,'%') ) {
  1798. $x_pos += 0;
  1799. $x_pos /= 100;
  1800. $x_pos = ($w * $x_pos) - ($iw * $x_pos);
  1801. }
  1802. $y_pos = $pb['y_pos'];
  1803. if (stristr($y_pos ,'%') ) {
  1804. $y_pos += 0;
  1805. $y_pos /= 100;
  1806. $y_pos = ($h * $y_pos) - ($ih * $y_pos);
  1807. }
  1808. if ($nx>1) {
  1809. while($x_pos>0) { $x_pos -= $iw; }
  1810. }
  1811. if ($ny>1) {
  1812. while($y_pos>0) { $y_pos -= $ih; }
  1813. }
  1814. for($xi=0;$xi<$nx;$xi++) {
  1815. for($yi=0;$yi<$ny;$yi++) {
  1816. $x = $x0 + $x_pos + ($iw*$xi);
  1817. $y = $y0 + $y_pos + ($ih*$yi);
  1818. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1819. else { $opac = ''; }
  1820. $s .= sprintf("q %s %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q", $opac,$iw*$this->k,$ih*$this->k,$x*$this->k,($this->h-($y+$ih))*$this->k,$pb['image_id']) ."\n";
  1821. }
  1822. }
  1823. }
  1824. else {
  1825. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1826. else { $opac = ''; }
  1827. $s .= sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1828. }
  1829. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1830. }
  1831. }
  1832. /*-- END BACKGROUNDS --*/
  1833. }
  1834. return $s;
  1835. }
  1836. // mPDF 5.0.018
  1837. function PrintTableBackgrounds($adjustmenty=0) {
  1838. $s = '';
  1839. /*-- BACKGROUNDS --*/
  1840. ksort($this->tableBackgrounds);
  1841. foreach($this->tableBackgrounds AS $bl=>$pbs) {
  1842. // mPDF 5.1.008
  1843. foreach ($pbs AS $pb) {
  1844. if ((!isset($pb['gradient']) || !$pb['gradient']) && (!isset($pb['image_id']) || !$pb['image_id'])) {
  1845. $s .= $this->SetFColor($pb['col'], true)."\n";
  1846. $s .= sprintf('%.3f %.3f %.3f %.3f re %s',$pb['x']*$this->k,($this->h-$pb['y'])*$this->k,$pb['w']*$this->k,-$pb['h']*$this->k,'f')."\n";
  1847. }
  1848. if (isset($pb['gradient']) && $pb['gradient']) {
  1849. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1850. // mPDF 5.0.020
  1851. $s .= $this->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1852. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1853. }
  1854. if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1855. $pb['y'] -= $adjustmenty;
  1856. $pb['h'] += $adjustmenty;
  1857. $n = count($this->patterns)+1;
  1858. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($pb['orig_w'], $pb['orig_h'], $pb['w'], $pb['h'], $pb['resize'], $pb['x_repeat'], $pb['y_repeat']);
  1859. $this->patterns[$n] = array('x'=>$pb['x'], 'y'=>$pb['y'], 'w'=>$pb['w'], 'h'=>$pb['h'], 'pgh'=>$this->h, 'image_id'=>$pb['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$pb['x_pos'], 'y_pos'=>$pb['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat);
  1860. $x = $pb['x']*$this->k;
  1861. $y = ($this->h - $pb['y'])*$this->k;
  1862. $w = $pb['w']*$this->k;
  1863. $h = -$pb['h']*$this->k;
  1864. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1865. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1866. else { $opac = ''; }
  1867. $s .= sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1868. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1869. }
  1870. }
  1871. }
  1872. /*-- END BACKGROUNDS --*/
  1873. return $s;
  1874. }
  1875. // Depracated - can use AddPage for all
  1876. function AddPages($orientation='',$condition='', $resetpagenum='', $pagenumstyle='', $suppress='',$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='')
  1877. {
  1878. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  1879. }
  1880. function AddPageByArray($a) {
  1881. if (!is_array($a)) { $a = array(); }
  1882. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  1883. $condition = (isset($a['condition']) ? $a['condition'] : '');
  1884. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  1885. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  1886. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  1887. $mgl = (isset($a['mgl']) ? $a['mgl'] : '');
  1888. $mgr = (isset($a['mgr']) ? $a['mgr'] : '');
  1889. $mgt = (isset($a['mgt']) ? $a['mgt'] : '');
  1890. $mgb = (isset($a['mgb']) ? $a['mgb'] : '');
  1891. $mgh = (isset($a['mgh']) ? $a['mgh'] : '');
  1892. $mgf = (isset($a['mgf']) ? $a['mgf'] : '');
  1893. $ohname = (isset($a['ohname']) ? $a['ohname'] : '');
  1894. $ehname = (isset($a['ehname']) ? $a['ehname'] : '');
  1895. $ofname = (isset($a['ofname']) ? $a['ofname'] : '');
  1896. $efname = (isset($a['efname']) ? $a['efname'] : '');
  1897. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : 0);
  1898. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : 0);
  1899. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : 0);
  1900. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : 0);
  1901. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : '');
  1902. $newformat = (isset($a['newformat']) ? $a['newformat'] : '');
  1903. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  1904. }
  1905. function AddPage($orientation='',$condition='', $resetpagenum='', $pagenumstyle='', $suppress='',$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='')
  1906. {
  1907. /*-- CSS-FLOAT --*/
  1908. // Float DIV
  1909. // Cannot do with columns on, or if any change in page orientation/margins etc.
  1910. // If next page already exists - i.e background /headers and footers already written
  1911. if ($this->state > 0 && $this->page < count($this->pages)) {
  1912. $bak_cml = $this->cMarginL;
  1913. $bak_cmr = $this->cMarginR;
  1914. $bak_dw = $this->divwidth;
  1915. // Paint Div Border if necessary
  1916. if ($this->blklvl > 0) {
  1917. $save_tr = $this->table_rotate; // *TABLES*
  1918. $this->table_rotate = 0; // *TABLES*
  1919. if ($this->y == $this->blk[$this->blklvl]['y0']) { $this->blk[$this->blklvl]['startpage']++; }
  1920. if (($this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  1921. else { $toplvl = $this->blklvl-1; }
  1922. $sy = $this->y;
  1923. for ($bl=1;$bl<=$toplvl;$bl++) {
  1924. $this->PaintDivBB('pagebottom',0,$bl);
  1925. }
  1926. $this->y = $sy;
  1927. $this->table_rotate = $save_tr; // *TABLES*
  1928. }
  1929. $s = $this->PrintPageBackgrounds();
  1930. // Writes after the marker so not overwritten later by page background etc.
  1931. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  1932. $this->pageBackgrounds = array();
  1933. $family=$this->FontFamily;
  1934. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  1935. $size=$this->FontSizePt;
  1936. $lw=$this->LineWidth;
  1937. $dc=$this->DrawColor;
  1938. $fc=$this->FillColor;
  1939. $tc=$this->TextColor;
  1940. $cf=$this->ColorFlag;
  1941. $this->printfloatbuffer();
  1942. //Move to next page
  1943. $this->page++;
  1944. $this->ResetMargins();
  1945. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  1946. $this->x=$this->lMargin;
  1947. $this->y=$this->tMargin;
  1948. $this->FontFamily='';
  1949. $this->_out('2 J');
  1950. $this->LineWidth=$lw;
  1951. $this->_out(sprintf('%.3f w',$lw*$this->k));
  1952. if($family) $this->SetFont($family,$style,$size,true,true);
  1953. $this->DrawColor=$dc;
  1954. if($dc!=$this->defDrawColor) $this->_out($dc); // mPDF 5.0.051
  1955. $this->FillColor=$fc;
  1956. if($fc!=$this->defFillColor) $this->_out($fc); // mPDF 5.0.051
  1957. $this->TextColor=$tc;
  1958. $this->ColorFlag=$cf;
  1959. for($bl=1;$bl<=$this->blklvl;$bl++) {
  1960. $this->blk[$bl]['y0'] = $this->y;
  1961. // Don't correct more than once for background DIV containing a Float
  1962. if (!isset($this->blk[$bl]['marginCorrected'][$this->page])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  1963. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  1964. }
  1965. $this->cMarginL = $bak_cml;
  1966. $this->cMarginR = $bak_cmr;
  1967. $this->divwidth = $bak_dw;
  1968. return '';
  1969. }
  1970. /*-- END CSS-FLOAT --*/
  1971. //Start a new page
  1972. if($this->state==0) $this->Open();
  1973. $bak_cml = $this->cMarginL;
  1974. $bak_cmr = $this->cMarginR;
  1975. $bak_dw = $this->divwidth;
  1976. $bak_lh = $this->lineheight;
  1977. $orientation = substr(strtoupper($orientation),0,1);
  1978. $condition = strtoupper($condition);
  1979. if ($condition == 'NEXT-EVEN') { // always adds at least one new page to create an Even page
  1980. if (!$this->mirrorMargins) { $condition = ''; }
  1981. else {
  1982. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1983. else { $pbch = false; } // *CSS-PAGE*
  1984. $this->AddPage($this->CurOrientation,'O');
  1985. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1986. $condition = '';
  1987. }
  1988. }
  1989. if ($condition == 'NEXT-ODD') { // always adds at least one new page to create an Odd page
  1990. if (!$this->mirrorMargins) { $condition = ''; }
  1991. else {
  1992. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1993. else { $pbch = false; } // *CSS-PAGE*
  1994. $this->AddPage($this->CurOrientation,'E');
  1995. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1996. $condition = '';
  1997. }
  1998. }
  1999. if ($condition == 'E') { // only adds new page if needed to create an Even page
  2000. if (!$this->mirrorMargins || ($this->page)%2==0) { return false; }
  2001. }
  2002. if ($condition == 'O') { // only adds new page if needed to create an Odd page
  2003. if (!$this->mirrorMargins || ($this->page)%2==1) { return false; }
  2004. }
  2005. if ($resetpagenum || $pagenumstyle || $suppress) {
  2006. $this->PageNumSubstitutions[] = array('from'=>($this->page+1), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  2007. }
  2008. $save_tr = $this->table_rotate; // *TABLES*
  2009. $this->table_rotate = 0; // *TABLES*
  2010. $save_kwt = $this->kwt;
  2011. $this->kwt = 0;
  2012. // Paint Div Border if necessary
  2013. //PAINTS BACKGROUND COLOUR OR BORDERS for DIV - DISABLED FOR COLUMNS (cf. AcceptPageBreak) AT PRESENT in ->PaintDivBB
  2014. if (!$this->ColActive && $this->blklvl > 0) {
  2015. if (isset($this->blk[$this->blklvl]['y0']) && $this->y == $this->blk[$this->blklvl]['y0']) {
  2016. if (isset($this->blk[$this->blklvl]['startpage'])) { $this->blk[$this->blklvl]['startpage']++; }
  2017. else { $this->blk[$this->blklvl]['startpage'] = 1; }
  2018. }
  2019. if ((isset($this->blk[$this->blklvl]['y0']) && $this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  2020. else { $toplvl = $this->blklvl-1; }
  2021. $sy = $this->y;
  2022. for ($bl=1;$bl<=$toplvl;$bl++) {
  2023. $this->PaintDivBB('pagebottom',0,$bl);
  2024. }
  2025. $this->y = $sy;
  2026. // RESET block y0 and x0 - see below
  2027. }
  2028. // BODY Backgrounds
  2029. if ($this->page > 0) {
  2030. $s = '';
  2031. // mPDF 5.0.023 5.0.047
  2032. $s .= $this->PrintBodyBackgrounds();
  2033. $s .= $this->PrintPageBackgrounds();
  2034. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  2035. $this->pageBackgrounds = array();
  2036. }
  2037. $save_kt = $this->keep_block_together; // mPDF 5.0
  2038. $this->keep_block_together = 0;
  2039. $save_cols = false;
  2040. /*-- COLUMNS --*/
  2041. if ($this->ColActive) {
  2042. $save_cols = true;
  2043. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  2044. $this->SetColumns(0);
  2045. }
  2046. /*-- END COLUMNS --*/
  2047. $family=$this->FontFamily;
  2048. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2049. $size=$this->FontSizePt;
  2050. $this->ColumnAdjust = true; // enables column height adjustment for the page
  2051. $lw=$this->LineWidth;
  2052. $dc=$this->DrawColor;
  2053. $fc=$this->FillColor;
  2054. $tc=$this->TextColor;
  2055. $cf=$this->ColorFlag;
  2056. if($this->page>0)
  2057. {
  2058. //Page footer
  2059. $this->InFooter=true;
  2060. $this->Reset();
  2061. $this->pageoutput[$this->page] = array();
  2062. $this->Footer();
  2063. //Close page
  2064. $this->_endpage();
  2065. }
  2066. //Start new page
  2067. $this->_beginpage($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat);
  2068. if ($this->docTemplate) {
  2069. $pagecount = $this->SetSourceFile($this->docTemplate);
  2070. if (($this->page - $this->docTemplateStart) > $pagecount) {
  2071. if ($this->docTemplateContinue) {
  2072. $tplIdx = $this->ImportPage($pagecount);
  2073. $this->UseTemplate($tplIdx);
  2074. }
  2075. }
  2076. else {
  2077. $tplIdx = $this->ImportPage(($this->page - $this->docTemplateStart));
  2078. $this->UseTemplate($tplIdx);
  2079. }
  2080. }
  2081. if ($this->pageTemplate) {
  2082. $this->UseTemplate($this->pageTemplate);
  2083. }
  2084. // Tiling Patterns // Moved here mPDF 4.0
  2085. $this->_out('___PAGE___START'.date('jY')); // mPDF 5.0
  2086. $this->_out('___BACKGROUND___PATTERNS'.date('jY'));
  2087. $this->_out('___HEADER___MARKER'.date('jY'));
  2088. $this->pageBackgrounds = array();
  2089. //Set line cap style to square
  2090. $this->SetLineCap(2); // mPDF 5.0.051 n J
  2091. //Set line width
  2092. $this->LineWidth=$lw;
  2093. $this->_out(sprintf('%.3f w',$lw*$this->k));
  2094. //Set font
  2095. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2096. //Set colors
  2097. $this->DrawColor=$dc;
  2098. if($dc!=$this->defDrawColor) $this->_out($dc); // mPDF 5.0.051
  2099. $this->FillColor=$fc;
  2100. if($fc!=$this->defFillColor) $this->_out($fc); // mPDF 5.0.051
  2101. $this->TextColor=$tc;
  2102. $this->ColorFlag=$cf;
  2103. //Page header
  2104. $this->Header();
  2105. //Restore line width
  2106. if($this->LineWidth!=$lw)
  2107. {
  2108. $this->LineWidth=$lw;
  2109. $this->_out(sprintf('%.3f w',$lw*$this->k));
  2110. }
  2111. //Restore font
  2112. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2113. //Restore colors
  2114. if($this->DrawColor!=$dc)
  2115. {
  2116. $this->DrawColor=$dc;
  2117. $this->_out($dc);
  2118. }
  2119. if($this->FillColor!=$fc)
  2120. {
  2121. $this->FillColor=$fc;
  2122. $this->_out($fc);
  2123. }
  2124. $this->TextColor=$tc;
  2125. $this->ColorFlag=$cf;
  2126. $this->InFooter=false;
  2127. /*-- COLUMNS --*/
  2128. if ($save_cols) {
  2129. // Restore columns
  2130. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  2131. }
  2132. if ($this->ColActive) { $this->SetCol(0); }
  2133. /*-- END COLUMNS --*/
  2134. //RESET BLOCK BORDER TOP
  2135. if (!$this->ColActive) {
  2136. for($bl=1;$bl<=$this->blklvl;$bl++) {
  2137. $this->blk[$bl]['y0'] = $this->y;
  2138. if (isset($this->blk[$bl]['x0'])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  2139. else { $this->blk[$bl]['x0'] = $this->MarginCorrection; }
  2140. // Added mPDF 3.0 Float DIV
  2141. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  2142. }
  2143. }
  2144. $this->table_rotate = $save_tr; // *TABLES*
  2145. $this->kwt = $save_kwt;
  2146. $this->keep_block_together = $save_kt ; // mPDF 5.0
  2147. $this->cMarginL = $bak_cml;
  2148. $this->cMarginR = $bak_cmr;
  2149. $this->divwidth = $bak_dw;
  2150. $this->lineheight = $bak_lh;
  2151. }
  2152. function PageNo() {
  2153. //Get current page number
  2154. return $this->page;
  2155. }
  2156. // mPDF 5.0.058
  2157. function AddSpotColorsFromFile($file) {
  2158. $colors = @file($file) or die("Cannot load spot colors file - ".$file);
  2159. foreach($colors AS $sc) {
  2160. list($name, $c, $m, $y, $k) = preg_split("/\t/",$sc);
  2161. $c = intval($c);
  2162. $m = intval($m);
  2163. $y = intval($y);
  2164. $k = intval($k);
  2165. $this->AddSpotColor($name, $c, $m, $y, $k);
  2166. }
  2167. }
  2168. // mPDF 5.0.051
  2169. function AddSpotColor($name, $c, $m, $y, $k) {
  2170. $name = strtoupper(trim($name));
  2171. if(!isset($this->spotColors[$name])) {
  2172. $i=count($this->spotColors)+1;
  2173. $this->spotColors[$name]=array('i'=>$i,'c'=>$c,'m'=>$m,'y'=>$y,'k'=>$k);
  2174. $this->spotColorIDs[$i]=$name;
  2175. }
  2176. }
  2177. // mPDF 5.0.049
  2178. function SetColor($col, $type='') {
  2179. $out = '';
  2180. if ($col[0]==3 || $col[0]==5) { // RGB / RGBa
  2181. $out = sprintf('%.3f %.3f %.3f rg',$col[1]/255,$col[2]/255,$col[3]/255);
  2182. }
  2183. else if ($col[0]==1) { // GRAYSCALE
  2184. $out = sprintf('%.3f g',$col[1]/255);
  2185. }
  2186. else if ($col[0]==2) { // SPOT COLOR
  2187. $out = sprintf('/CS%d cs %.3f scn',$col[1],$col[2]/100);
  2188. }
  2189. else if ($col[0]==4 || $col[0]==6) { // CMYK / CMYKa
  2190. $out = sprintf('%.3f %.3f %.3f %.3f k', $col[1]/100, $col[2]/100, $col[3]/100, $col[4]/100);
  2191. }
  2192. if ($type=='Draw') { $out = strtoupper($out); } // e.g. rg => RG
  2193. return $out;
  2194. }
  2195. function SetDColor($col, $return=false) {
  2196. $out = $this->SetColor($col, 'Draw');
  2197. if ($return) { return $out; }
  2198. if ($out=='') { return ''; }
  2199. $this->DrawColor = $out;
  2200. if($this->page>0 && ((isset($this->pageoutput[$this->page]['DrawColor']) && $this->pageoutput[$this->page]['DrawColor'] != $this->DrawColor) || !isset($this->pageoutput[$this->page]['DrawColor']) || $this->keep_block_together)) { $this->_out($this->DrawColor); }
  2201. $this->pageoutput[$this->page]['DrawColor'] = $this->DrawColor;
  2202. }
  2203. function SetFColor($col, $return=false) {
  2204. $out = $this->SetColor($col, 'Fill');
  2205. if ($return) { return $out; }
  2206. if ($out=='') { return ''; }
  2207. $this->FillColor = $out;
  2208. $this->ColorFlag = ($out != $this->TextColor);
  2209. if($this->page>0 && ((isset($this->pageoutput[$this->page]['FillColor']) && $this->pageoutput[$this->page]['FillColor'] != $this->FillColor) || !isset($this->pageoutput[$this->page]['FillColor']) || $this->keep_block_together)) { $this->_out($this->FillColor); }
  2210. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  2211. }
  2212. function SetTColor($col, $return=false) {
  2213. $out = $this->SetColor($col, 'Text');
  2214. if ($return) { return $out; }
  2215. if ($out=='') { return ''; }
  2216. $this->TextColor = $out;
  2217. $this->ColorFlag = ($this->FillColor != $out);
  2218. }
  2219. function SetDrawColor($r,$g=-1,$b=-1,$col4=-1) {
  2220. //Set color for all stroking operations
  2221. $col = array();
  2222. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2223. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2224. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2225. $out = $this->SetDColor($col, $return);
  2226. return $out;
  2227. }
  2228. function SetFillColor($r,$g=-1,$b=-1,$col4=-1) {
  2229. //Set color for all filling operations
  2230. $col = array();
  2231. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2232. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2233. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2234. $out = $this->SetFColor($col, $return);
  2235. return $out;
  2236. }
  2237. function SetTextColor($r,$g=-1,$b=-1,$col4=-1) {
  2238. //Set color for text
  2239. $col = array();
  2240. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2241. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2242. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2243. $out = $this->SetTColor($col, $return);
  2244. return $out;
  2245. }
  2246. // mPDF 5.0
  2247. function _getCharWidth(&$cw, $u, $isdef=true) {
  2248. if ($u==0) { $w = false; }
  2249. else { $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); }
  2250. if ($w == 65535) { return 0; }
  2251. else if ($w) { return $w; }
  2252. else if ($isdef) { return false; }
  2253. else { return 0; }
  2254. }
  2255. // mPDF 5.0
  2256. function _charDefined(&$cw, $u) {
  2257. if ($u==0) { return false; }
  2258. $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]);
  2259. if ($w) { return true; }
  2260. else { return false; }
  2261. }
  2262. function GetStringWidth($s, $addSubset=true) { // mPDF 5.1.020
  2263. //Get width of a string in the current font
  2264. $s = (string)$s;
  2265. $cw = &$this->CurrentFont['cw'];
  2266. $w = 0;
  2267. $kerning = 0; // mPDF 5.0.061
  2268. $lastchar = 0;
  2269. // mPDF ITERATION
  2270. if ($this->iterationCounter) $s = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/', '\\1', $s);
  2271. if (!$this->usingCoreFont) {
  2272. $unicode = $this->UTF8StringToArray($s, $addSubset); // mPDF 5.1.020
  2273. if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts
  2274. foreach($unicode as $char) {
  2275. if ($char == 173) { continue; } // Soft Hyphens
  2276. elseif (isset($cw[$char])) { $w+=$cw[$char]; }
  2277. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2278. else { $w += 500; }
  2279. }
  2280. }
  2281. else {
  2282. foreach($unicode as $char) {
  2283. if ($char == 173) { continue; } // Soft Hyphens
  2284. else if ($this->S && isset($this->upperCase[$char])) {
  2285. $charw = $this->_getCharWidth($cw,$this->upperCase[$char]);
  2286. if ($charw!==false) {
  2287. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2288. $w+=$charw;
  2289. }
  2290. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2291. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2292. else { $w += 500; }
  2293. }
  2294. else {
  2295. $charw = $this->_getCharWidth($cw,$char);
  2296. if ($charw!==false) { $w+=$charw; } // mPDF 5.0
  2297. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2298. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2299. else { $w += 500; }
  2300. // mPDF 5.0.061
  2301. if ($this->kerning && $this->useKerning && $lastchar) {
  2302. if (isset($this->CurrentFont['kerninfo'][$lastchar][$char])) {
  2303. $kerning += $this->CurrentFont['kerninfo'][$lastchar][$char];
  2304. }
  2305. }
  2306. $lastchar = $char;
  2307. }
  2308. }
  2309. }
  2310. }
  2311. else {
  2312. $l = strlen($s);
  2313. for($i=0; $i<$l; $i++) {
  2314. // Soft Hyphens chr(173)
  2315. if ($s[$i] == chr(173) && $this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  2316. continue;
  2317. }
  2318. else if ($this->S && isset($this->upperCase[ord($s[$i])])) {
  2319. $charw = $cw[chr($this->upperCase[ord($s[$i])])];
  2320. if ($charw!==false) {
  2321. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2322. $w+=$charw;
  2323. }
  2324. }
  2325. else if (isset($cw[$s[$i]])) {
  2326. $w += $cw[$s[$i]];
  2327. }
  2328. else if (isset($cw[ord($s[$i])])) {
  2329. $w += $cw[ord($s[$i])];
  2330. }
  2331. // mPDF 5.0.061
  2332. if ($this->kerning && $this->useKerning) {
  2333. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]])) {
  2334. $kerning += $this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]];
  2335. }
  2336. }
  2337. }
  2338. }
  2339. unset($cw);
  2340. // mPDF 5.0.061
  2341. if ($this->kerning && $this->useKerning) { $w += $kerning; }
  2342. $w *= ($this->FontSize/ 1000);
  2343. // mPDF 5.0.063
  2344. if ($this->minwSpacing || $this->fixedlSpacing) { // mPDF 5.0.064
  2345. $nb_carac = mb_strlen($s, $this->mb_enc);
  2346. $nb_spaces = mb_substr_count($s,' ', $this->mb_enc);
  2347. $w += (($nb_carac + $nb_spaces) * $this->fixedlSpacing) + ($nb_spaces * $this->minwSpacing);
  2348. }
  2349. return ($w);
  2350. }
  2351. function SetLineWidth($width) {
  2352. //Set line width
  2353. $this->LineWidth=$width;
  2354. $lwout = (sprintf('%.3f w',$width*$this->k));
  2355. if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineWidth']) && $this->pageoutput[$this->page]['LineWidth'] != $lwout) || !isset($this->pageoutput[$this->page]['LineWidth']) || $this->keep_block_together)) {
  2356. $this->_out($lwout);
  2357. }
  2358. $this->pageoutput[$this->page]['LineWidth'] = $lwout;
  2359. }
  2360. function Line($x1,$y1,$x2,$y2) {
  2361. //Draw a line
  2362. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
  2363. }
  2364. function Arrow($x1,$y1,$x2,$y2,$headsize=3,$fill='B',$angle=25) {
  2365. //F == fill //S == stroke //B == stroke and fill
  2366. // angle = splay of arrowhead - 1 - 89 degrees
  2367. if($fill=='F') $fill='f';
  2368. elseif($fill=='FD' or $fill=='DF' or $fill=='B') $fill='B';
  2369. else $fill='S';
  2370. $a = atan2(($y2-$y1),($x2-$x1));
  2371. $b = $a + deg2rad($angle);
  2372. $c = $a - deg2rad($angle);
  2373. $x3 = $x2 - ($headsize* cos($b));
  2374. $y3 = $this->h-($y2 - ($headsize* sin($b)));
  2375. $x4 = $x2 - ($headsize* cos($c));
  2376. $y4 = $this->h-($y2 - ($headsize* sin($c)));
  2377. $x5 = $x3-($x3-$x4)/2; // mid point of base of arrowhead - to join arrow line to
  2378. $y5 = $y3-($y3-$y4)/2;
  2379. $s = '';
  2380. $s.=sprintf('%.3f %.3f m %.3f %.3f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x5*$this->k,$y5*$this->k);
  2381. $this->_out($s);
  2382. $s = '';
  2383. $s.=sprintf('%.3f %.3f m %.3f %.3f l %.3f %.3f l %.3f %.3f l %.3f %.3f l ',$x5*$this->k,$y5*$this->k,$x3*$this->k,$y3*$this->k,$x2*$this->k,($this->h-$y2)*$this->k,$x4*$this->k,$y4*$this->k,$x5*$this->k,$y5*$this->k);
  2384. $s.=$fill;
  2385. $this->_out($s);
  2386. }
  2387. function Rect($x,$y,$w,$h,$style='') {
  2388. //Draw a rectangle
  2389. if($style=='F') $op='f';
  2390. elseif($style=='FD' or $style=='DF') $op='B';
  2391. else $op='S';
  2392. $this->_out(sprintf('%.3f %.3f %.3f %.3f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
  2393. }
  2394. function AddFont($family,$style='') { // mPDF 5.0
  2395. if(empty($family)) { return; }
  2396. $family = strtolower($family);
  2397. $style=strtoupper($style);
  2398. $style=str_replace('U','',$style);
  2399. if($style=='IB') $style='BI';
  2400. $fontkey = $family.$style;
  2401. // check if the font has been already added
  2402. if(isset($this->fonts[$fontkey])) {
  2403. return;
  2404. }
  2405. if (in_array($family,$this->available_CJK_fonts)) {
  2406. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2407. $this->AddCJKFont($family); // don't need to add style
  2408. return;
  2409. }
  2410. if ($this->usingCoreFont) { die("mPDF Error - problem with Font management"); }
  2411. $stylekey = $style;
  2412. if (!$style) { $stylekey = 'R'; }
  2413. if (!isset($this->fontdata[$family][$stylekey]) || !$this->fontdata[$family][$stylekey]) {
  2414. die('mPDF Error - Font is not supported - '.$family.' '.$style);
  2415. }
  2416. $name = '';
  2417. $originalsize = 0;
  2418. $sip = false;
  2419. $smp = false;
  2420. $haskerninfo = false; // mPDF 5.0.061
  2421. $BMPselected = false;
  2422. @include(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php');
  2423. $ttffile = '';
  2424. if (defined('_MPDF_SYSTEM_TTFONTS')) {
  2425. $ttffile = _MPDF_SYSTEM_TTFONTS.$this->fontdata[$family][$stylekey];
  2426. if (!file_exists($ttffile)) { $ttffile = ''; }
  2427. }
  2428. if (!$ttffile) {
  2429. $ttffile = _MPDF_TTFONTPATH.$this->fontdata[$family][$stylekey];
  2430. if (!file_exists($ttffile)) { die("mPDF Error - cannot find TTF TrueType font file - ".$ttffile); }
  2431. }
  2432. $ttfstat = stat($ttffile);
  2433. if (isset($this->fontdata[$family]['TTCfontID'][$stylekey])) { $TTCfontID = $this->fontdata[$family]['TTCfontID'][$stylekey]; }
  2434. else { $TTCfontID = 0; }
  2435. // mPDF 5.0Beta.16
  2436. $BMPonly = false;
  2437. if (in_array($family,$this->BMPonly)) { $BMPonly = true; }
  2438. $regenerate = false;
  2439. if ($BMPonly && !$BMPselected) { $regenerate = true; }
  2440. else if (!$BMPonly && $BMPselected) { $regenerate = true; }
  2441. if ($this->useKerning && !$haskerninfo) { $regenerate = true; } // mPDF 5.0.061
  2442. if (!isset($name) || $originalsize != $ttfstat['size'] || $regenerate) {
  2443. $mqr=$this->_getMQR(); // mPDF 5.0
  2444. if ($mqr) { set_magic_quotes_runtime(0); }
  2445. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  2446. $ttf = new TTFontFile();
  2447. // mPDF 5.0.03
  2448. $ttf->getMetrics($ttffile, $TTCfontID, $this->debugfonts, $BMPonly, $this->useKerning); // mPDF 5.0.061
  2449. $cw = $ttf->charWidths;
  2450. $kerninfo = $ttf->kerninfo; // mPDF 5.0.061
  2451. $haskerninfo = true; // mPDF 5.1.002
  2452. $name = preg_replace('/[ ()]/','',$ttf->fullName);
  2453. $sip = $ttf->sipset;
  2454. $smp = $ttf->smpset;
  2455. //$name = $ttf->familyName;
  2456. //if (preg_match('/(bold|italic|oblique|heavy)/i',$ttf->styleName)) { $name .= ','.$ttf->styleName; }
  2457. //$name = preg_replace('/[()]/','',$name);
  2458. //$name = preg_replace('/[ ]/','#20',$name);
  2459. $desc= array('Ascent'=>round($ttf->ascent),
  2460. 'Descent'=>round($ttf->descent),
  2461. 'CapHeight'=>round($ttf->capHeight),
  2462. 'Flags'=>$ttf->flags,
  2463. 'FontBBox'=>'['.round($ttf->bbox[0])." ".round($ttf->bbox[1])." ".round($ttf->bbox[2])." ".round($ttf->bbox[3]).']',
  2464. 'ItalicAngle'=>$ttf->italicAngle,
  2465. 'StemV'=>round($ttf->stemV),
  2466. 'MissingWidth'=>round($ttf->defaultWidth));
  2467. $panose = '';
  2468. // mPDF 5.0
  2469. if (count($ttf->panose)) { $panose = $ttf->sFamilyClass.' '.$ttf->sFamilySubClass.' '.implode(' ',$ttf->panose); }
  2470. $up = round($ttf->underlinePosition);
  2471. $ut = round($ttf->underlineThickness);
  2472. $originalsize = $ttfstat['size']+0;
  2473. $type = 'TTF';
  2474. //Generate metrics .php file
  2475. $s='<?php'."\n";
  2476. $s.='$name=\''.$name."';\n";
  2477. $s.='$type=\''.$type."';\n";
  2478. $s.='$desc='.var_export($desc,true).";\n";
  2479. $s.='$up='.$up.";\n";
  2480. $s.='$ut='.$ut.";\n";
  2481. $s.='$ttffile=\''.$ttffile."';\n";
  2482. $s.='$TTCfontID=\''.$TTCfontID."';\n";
  2483. $s.='$originalsize='.$originalsize.";\n";
  2484. if ($sip) $s.='$sip=true;'."\n";
  2485. else $s.='$sip=false;'."\n";
  2486. if ($smp) $s.='$smp=true;'."\n";
  2487. else $s.='$smp=false;'."\n";
  2488. if ($BMPonly) $s.='$BMPselected=true;'."\n";
  2489. else $s.='$BMPselected=false;'."\n";
  2490. $s.='$fontkey=\''.$fontkey."';\n";
  2491. $s.='$panose=\''.$panose."';\n"; // mPDF 5.0
  2492. // mPDF 5.0.061
  2493. if ($this->useKerning) {
  2494. $s.='$kerninfo='.var_export($kerninfo,true).";\n";
  2495. $s.='$haskerninfo=true;'."\n";
  2496. }
  2497. else $s.='$haskerninfo=false;'."\n";
  2498. $s.="?>";
  2499. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  2500. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php',"w");
  2501. fwrite($fh,$s,strlen($s));
  2502. fclose($fh);
  2503. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat',"wb");
  2504. fwrite($fh,$cw,strlen($cw));
  2505. fclose($fh);
  2506. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cgm');
  2507. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.z');
  2508. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw127.php');
  2509. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw');
  2510. }
  2511. else if ($this->debugfonts) { $this->Error('Cannot write to the font caching directory - '._MPDF_TTFONTDATAPATH); }
  2512. unset($ttf);
  2513. if ($mqr) { set_magic_quotes_runtime($mqr); }
  2514. }
  2515. else {
  2516. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat');
  2517. }
  2518. if (isset($this->fontdata[$family]['indic']) && $this->fontdata[$family]['indic']) { $indic = true; }
  2519. else { $indic = false; }
  2520. if (isset($this->fontdata[$family]['sip-ext']) && $this->fontdata[$family]['sip-ext']) { $sipext = $this->fontdata[$family]['sip-ext']; }
  2521. else { $sipext = ''; }
  2522. $i = count($this->fonts)+$this->extraFontSubsets+1;
  2523. if ($sip || $smp) { // mPDF 5.0.03 Added SMP
  2524. $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subsets'=>array(0=>range(0,127)), 'subsetfontids'=>array($i), 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID); // mPDF 5.0.061
  2525. }
  2526. else {
  2527. $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subset'=>range(0,127), 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID); // mPDF 5.0.061
  2528. }
  2529. if ($this->useKerning && $haskerninfo) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; } // mPDF 5.0.061
  2530. $this->FontFiles[$fontkey]=array('length1'=>$originalsize, 'type'=>"TTF", 'ttffile'=>$ttffile, 'sip'=>$sip, 'smp'=>$smp);
  2531. unset($cw);
  2532. }
  2533. function SetFont($family,$style='',$size=0, $write=true, $forcewrite=false) {
  2534. $family=strtolower($family);
  2535. if($family=='') {
  2536. if ($this->FontFamily) { $family=$this->FontFamily; }
  2537. else if ($this->default_font) { $family=$this->default_font; }
  2538. else { $this->Error("No font or default font set!"); }
  2539. }
  2540. $this->ReqFontStyle = $style; // required or requested style - used later for artificial bold/italic
  2541. if (($family == 'csymbol') || ($family == 'czapfdingbats') || ($family == 'ctimes') || ($family == 'ccourier') || ($family == 'chelvetica')) {
  2542. if ($this->PDFA || $this->PDFX) {
  2543. if ($family == 'csymbol' || $family == 'czapfdingbats') {
  2544. $this->Error("Symbol and Zapfdingbats cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a).");
  2545. }
  2546. if ($family == 'ctimes' || $family == 'ccourier' || $family == 'chelvetica') {
  2547. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Core Adobe font ".ucfirst($family)." cannot be embedded in mPDF, which is required for PDFA1-b or PDFX/1-a. (Embedded font will be substituted.)"; }
  2548. if ($family == 'chelvetica') { $family = 'sans'; }
  2549. if ($family == 'ctimes') { $family = 'serif'; }
  2550. if ($family == 'ccourier') { $family = 'mono'; }
  2551. }
  2552. $this->usingCoreFont = false;
  2553. }
  2554. else { $this->usingCoreFont = true; }
  2555. }
  2556. else { $this->usingCoreFont = false; }
  2557. if($family=='csymbol' or $family=='czapfdingbats') { $style=''; }
  2558. $style=strtoupper($style);
  2559. if(strpos($style,'U')!==false) {
  2560. $this->U=true;
  2561. $style=str_replace('U','',$style);
  2562. }
  2563. else { $this->U=false; }
  2564. if(strpos($style,'S')!==false) { // mPDF 5.0
  2565. $this->S=true;
  2566. $style=str_replace('S','',$style);
  2567. }
  2568. else { $this->S=false; }
  2569. if ($style=='IB') $style='BI';
  2570. if ($size==0) $size=$this->FontSizePt;
  2571. $fontkey=$family.$style;
  2572. $stylekey = $style; // mPDF 5.0
  2573. if (!$stylekey) { $stylekey = "R"; }
  2574. if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  2575. // CJK fonts
  2576. if (in_array($fontkey,$this->available_CJK_fonts)) {
  2577. if(!isset($this->fonts[$fontkey])) { // already added
  2578. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2579. $this->AddCJKFont($family); // don't need to add style
  2580. }
  2581. }
  2582. // Test to see if requested font/style is available - or substitute
  2583. else if (!in_array($fontkey,$this->available_unifonts)) {
  2584. // If font[nostyle] exists - set it
  2585. if (in_array($family,$this->available_unifonts)) {
  2586. $style = '';
  2587. }
  2588. // Else if only one font available - set it (assumes if only one font available it will not have a style)
  2589. else if (count($this->available_unifonts) == 1) {
  2590. $family = $this->available_unifonts[0];
  2591. $style = '';
  2592. }
  2593. else {
  2594. $found = 0;
  2595. // else substitute font of similar type
  2596. if (in_array($family,$this->sans_fonts)) {
  2597. $i = array_intersect($this->sans_fonts,$this->available_unifonts);
  2598. if (count($i)) {
  2599. $i = array_values($i);
  2600. // with requested style if possible
  2601. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2602. $style = '';
  2603. }
  2604. $family = $i[0];
  2605. $found = 1;
  2606. }
  2607. }
  2608. else if (in_array($family,$this->serif_fonts)) {
  2609. $i = array_intersect($this->serif_fonts,$this->available_unifonts);
  2610. if (count($i)) {
  2611. $i = array_values($i);
  2612. // with requested style if possible
  2613. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2614. $style = '';
  2615. }
  2616. $family = $i[0];
  2617. $found = 1;
  2618. }
  2619. }
  2620. else if (in_array($family,$this->mono_fonts)) {
  2621. $i = array_intersect($this->mono_fonts,$this->available_unifonts);
  2622. if (count($i)) {
  2623. $i = array_values($i);
  2624. // with requested style if possible
  2625. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2626. $style = '';
  2627. }
  2628. $family = $i[0];
  2629. $found = 1;
  2630. }
  2631. }
  2632. if (!$found) {
  2633. // set first available font
  2634. $fs = $this->available_unifonts[0];
  2635. preg_match('/^([a-z_0-9\-]+)([BI]{0,2})$/',$fs,$fas); // mPDF 5.0 Allow "-"
  2636. // with requested style if possible
  2637. $ws = $fas[1].$style;
  2638. if (in_array($ws,$this->available_unifonts)) {
  2639. $family = $fas[1]; // leave $style as is
  2640. }
  2641. else if (in_array($fas[1],$this->available_unifonts)) {
  2642. // or without style
  2643. $family = $fas[1];
  2644. $style = '';
  2645. }
  2646. else {
  2647. // or with the style specified
  2648. $family = $fas[1];
  2649. $style = $fas[2];
  2650. }
  2651. }
  2652. }
  2653. $fontkey = $family.$style;
  2654. }
  2655. // try to add font (if not already added)
  2656. $this->AddFont($family, $style);
  2657. //Test if font is already selected
  2658. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2659. return $family;
  2660. }
  2661. $fontkey = $family.$style;
  2662. //Select it
  2663. $this->FontFamily = $family;
  2664. $this->FontStyle = $style;
  2665. $this->FontSizePt = $size;
  2666. $this->FontSize = $size / $this->k;
  2667. $this->CurrentFont = &$this->fonts[$fontkey];
  2668. if ($write) {
  2669. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2670. // Edited mPDF 3.0
  2671. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  2672. $this->pageoutput[$this->page]['Font'] = $fontout;
  2673. }
  2674. // Added - currentfont (lowercase) used in HTML2PDF
  2675. $this->currentfontfamily=$family;
  2676. $this->currentfontsize=$size;
  2677. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2678. $this->setMBencoding('UTF-8');
  2679. }
  2680. else { // if using core fonts
  2681. if ($this->PDFA || $this->PDFX) {
  2682. $this->Error('Core Adobe fonts cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a) - cannot use option to use core fonts.');
  2683. }
  2684. $this->setMBencoding('windows-1252');
  2685. //Test if font is already selected
  2686. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2687. return $family;
  2688. }
  2689. if (!isset($this->CoreFonts[$fontkey])) {
  2690. if (in_array($family,$this->serif_fonts)) { $family = 'ctimes'; }
  2691. else if (in_array($family,$this->mono_fonts)) { $family = 'ccourier'; }
  2692. else { $family = 'chelvetica'; }
  2693. $this->usingCoreFont = true;
  2694. $fontkey = $family.$style;
  2695. }
  2696. if(!isset($this->fonts[$fontkey])) {
  2697. // STANDARD CORE FONTS
  2698. if (isset($this->CoreFonts[$fontkey])) {
  2699. //Load metric file
  2700. $file=$family;
  2701. if($family=='ctimes' || $family=='chelvetica' || $family=='ccourier') { $file.=strtolower($style); }
  2702. $file.='.php';
  2703. include(_MPDF_PATH.'font/'.$file);
  2704. if(!isset($cw)) { $this->Error('Could not include font metric file'); }
  2705. $i=count($this->fonts)+$this->extraFontSubsets+1;
  2706. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw); // mPDF 5.0.061
  2707. if ($this->useKerning) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; } // mPDF 5.0.061
  2708. }
  2709. else {
  2710. die('mPDF error - Font not defined');
  2711. }
  2712. }
  2713. //Test if font is already selected
  2714. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2715. return $family;
  2716. }
  2717. //Select it
  2718. $this->FontFamily=$family;
  2719. $this->FontStyle=$style;
  2720. $this->FontSizePt=$size;
  2721. $this->FontSize=$size/$this->k;
  2722. $this->CurrentFont=&$this->fonts[$fontkey];
  2723. if ($write) {
  2724. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2725. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  2726. $this->pageoutput[$this->page]['Font'] = $fontout;
  2727. }
  2728. // Added - currentfont (lowercase) used in HTML2PDF
  2729. $this->currentfontfamily=$family;
  2730. $this->currentfontsize=$size;
  2731. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2732. }
  2733. return $family;
  2734. }
  2735. function SetFontSize($size,$write=true) {
  2736. //Set font size in points
  2737. if($this->FontSizePt==$size) return;
  2738. $this->FontSizePt=$size;
  2739. $this->FontSize=$size/$this->k;
  2740. $this->currentfontsize=$size;
  2741. if ($write) {
  2742. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2743. // Edited mPDF 3.0
  2744. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  2745. $this->pageoutput[$this->page]['Font'] = $fontout;
  2746. }
  2747. }
  2748. function AddLink() {
  2749. //Create a new internal link
  2750. $n=count($this->links)+1;
  2751. $this->links[$n]=array(0,0);
  2752. return $n;
  2753. }
  2754. function SetLink($link,$y=0,$page=-1) {
  2755. //Set destination of internal link
  2756. if($y==-1) $y=$this->y;
  2757. if($page==-1) $page=$this->page;
  2758. $this->links[$link]=array($page,$y);
  2759. }
  2760. function Link($x,$y,$w,$h,$link) {
  2761. if ($this->keep_block_together) { // Save to array - don't write yet
  2762. $this->ktLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2763. return;
  2764. }
  2765. else if ($this->table_rotate) { // *TABLES*
  2766. $this->tbrot_Links[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link); // *TABLES*
  2767. return; // *TABLES*
  2768. } // *TABLES*
  2769. else if ($this->kwt) {
  2770. $this->kwt_Links[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2771. return;
  2772. }
  2773. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  2774. $this->HTMLheaderPageLinks[]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2775. return;
  2776. }
  2777. //Put a link on the page
  2778. $this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2779. // Save cross-reference to Column buffer
  2780. $ref = count($this->PageLinks[$this->page])-1; // *COLUMNS*
  2781. $this->columnLinks[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref; // *COLUMNS*
  2782. }
  2783. function Text($x,$y,$txt) {
  2784. // Output a string
  2785. // Called (internally) by Watermark and _tableWrite [rotated cells]
  2786. // Expects input to be mb_encoded if necessary and RTL reversed
  2787. // mPDF 5.0 ARTIFICIAL BOLD AND ITALIC
  2788. $s = 'q ';
  2789. if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false) {
  2790. $s .= '2 Tr 1 J 1 j ';
  2791. $s .= sprintf('%.3f w ',($this->FontSize/130)*$this->k*$this->falseBoldWeight);
  2792. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2793. if($this->FillColor!=$tc) { $s .= $tc.' '; } // stroke (outline) = same colour as text(fill)
  2794. }
  2795. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) {
  2796. $aix = '1 0 0.261799 1 %.3f %.3f Tm';
  2797. }
  2798. else { $aix = '%.3f %.3f Td'; }
  2799. if($this->ColorFlag) $s.=$this->TextColor.' ';
  2800. $this->CurrentFont['used']= true;
  2801. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) { // mPDF 5.0.03 Added SMP
  2802. $txt2 = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$txt); // mPDF 5.0
  2803. $txt2 = $this->UTF8toSubset($txt2);
  2804. $s.=sprintf('BT '.$aix.' %s Tj ET ',$x*$this->k,($this->h-$y)*$this->k,$txt2);
  2805. }
  2806. else if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  2807. $txt2 = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$txt);
  2808. $this->UTF8StringToArray($txt2); // mPDF 5.0 this is just to add chars to subset list
  2809. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); } // mPDF 5.0.061
  2810. else {
  2811. //Convert string to UTF-16BE without BOM
  2812. $txt2= $this->UTF8ToUTF16BE($txt2, false);
  2813. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt2));
  2814. }
  2815. }
  2816. else {
  2817. $txt2 = str_replace($this->chrs[160],$this->chrs[32],$txt);
  2818. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); } // mPDF 5.0.061
  2819. else {
  2820. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt2));
  2821. }
  2822. }
  2823. if($this->U and $txt!='') {
  2824. $s.=$this->_dounderline($x,$y + (0.1* $this->FontSize),$txt).' ';
  2825. }
  2826. $s .= 'Q';
  2827. $this->_out($s);
  2828. }
  2829. /*-- DIRECTW --*/
  2830. function WriteText($x,$y,$txt) {
  2831. // Output a string using Text() but does encoding and text reversing of RTL
  2832. $txt = $this->purify_utf8_text($txt);
  2833. if ($this->text_input_as_HTML) {
  2834. $txt = $this->all_entities_to_utf8($txt);
  2835. }
  2836. if ($this->onlyCoreFonts) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2837. // DIRECTIONALITY
  2838. // mPDF 5.0.054
  2839. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  2840. // mPDF 5.0.054
  2841. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  2842. // Font-specific ligature substitution for Indic fonts
  2843. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  2844. $this->Text($x,$y,$txt);
  2845. }
  2846. function WriteCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0) {
  2847. //Output a cell using Cell() but does encoding and text reversing of RTL
  2848. $txt = $this->purify_utf8_text($txt);
  2849. if ($this->text_input_as_HTML) {
  2850. $txt = $this->all_entities_to_utf8($txt);
  2851. }
  2852. if (!$this->onlyCoreFonts) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2853. // DIRECTIONALITY
  2854. // mPDF 5.0.054
  2855. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  2856. // mPDF 5.0.054
  2857. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  2858. // Font-specific ligature substitution for Indic fonts
  2859. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  2860. $this->Cell($w,$h,$txt,$border,$ln,$align,$fill,$link, $currentx);
  2861. }
  2862. /*-- END DIRECTW --*/
  2863. function ResetSpacing() {
  2864. if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2865. $this->ws=0;
  2866. if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2867. $this->charspacing=0;
  2868. }
  2869. function SetSpacing($cs,$ws) {
  2870. if (intval($cs*1000)==0) { $cs = 0; } // mPDF 5.0.051
  2871. if ($cs) { $this->_out(sprintf('BT %.3f Tc ET',$cs)); }
  2872. else if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2873. $this->charspacing=$cs;
  2874. if (intval($ws*1000)==0) { $ws = 0; } // mPDF 5.0.051
  2875. if ($ws) { $this->_out(sprintf('BT %.3f Tw ET',$ws)); }
  2876. else if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2877. $this->ws=$ws;
  2878. }
  2879. // WORD SPACING
  2880. function GetJspacing($nc,$ns,$w,$inclCursive) { // mPDF 5.0.071
  2881. $ws = 0;
  2882. $charspacing = 0;
  2883. $ww = $this->jSWord;
  2884. $ncx = $nc-1;
  2885. if ($nc == 0) { return array(0,0); } // mPDF 5.0.071
  2886. else if ($nc==1) { $charspacing = $w; }
  2887. // Only word spacing allowed / possible
  2888. else if ($this->fixedlSpacing !== false || $inclCursive) { // mPDF 5.0.066 // mPDF 5.0.071
  2889. if ($ns) { $ws = $w / $ns; }
  2890. }
  2891. else if (!$ns) {
  2892. $charspacing = $w / ($ncx ); // mPDF 5.0.071
  2893. if (($this->jSmaxChar > 0) && ($charspacing > $this->jSmaxChar)) {
  2894. $charspacing = $this->jSmaxChar;
  2895. }
  2896. }
  2897. else if ($ns == ($ncx )) {
  2898. $charspacing = $w / $ns;
  2899. }
  2900. else {
  2901. if ($this->usingCoreFont) {
  2902. $cs = ($w * (1 - $this->jSWord)) / ($ncx );
  2903. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  2904. $cs = $this->jSmaxChar;
  2905. $ww = 1 - (($cs * ($ncx ))/$w);
  2906. }
  2907. $charspacing = $cs;
  2908. $ws = ($w * ($ww) ) / $ns;
  2909. }
  2910. else {
  2911. $cs = ($w * (1 - $this->jSWord)) / ($ncx -$ns);
  2912. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  2913. $cs = $this->jSmaxChar;
  2914. $ww = 1 - (($cs * ($ncx -$ns))/$w);
  2915. }
  2916. $charspacing = $cs;
  2917. $ws = (($w * ($ww) ) / $ns) - $charspacing;
  2918. }
  2919. }
  2920. return array($charspacing,$ws);
  2921. }
  2922. function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0, $lcpaddingL=0, $lcpaddingR=0, $valign='M', $spanfill=0, $abovefont=0, $belowfont=0) {
  2923. //Output a cell
  2924. // Expects input to be mb_encoded if necessary and RTL reversed
  2925. // NON_BREAKING SPACE
  2926. if ($this->usingCoreFont) {
  2927. $txt = str_replace($this->chrs[160],$this->chrs[32],$txt);
  2928. }
  2929. else {
  2930. $txt = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$txt);
  2931. }
  2932. $k=$this->k;
  2933. $oldcolumn = $this->CurrCol;
  2934. // Automatic page break
  2935. // Allows PAGE-BREAK-AFTER = avoid to work
  2936. if (!$this->tableLevel && (($this->y+$this->divheight>$this->PageBreakTrigger) || ($this->y+$h>$this->PageBreakTrigger) ||
  2937. ($this->y+($h*2)>$this->PageBreakTrigger && $this->blk[$this->blklvl]['page_break_after_avoid'])) and !$this->InFooter and $this->AcceptPageBreak()) {
  2938. $x=$this->x;//Current X position
  2939. // WORD SPACING
  2940. $ws=$this->ws;//Word Spacing
  2941. $charspacing=$this->charspacing;//Character Spacing
  2942. $this->ResetSpacing();
  2943. $this->AddPage($this->CurOrientation);
  2944. // Added to correct for OddEven Margins
  2945. $x += $this->MarginCorrection;
  2946. if ($currentx) {
  2947. $currentx += $this->MarginCorrection;
  2948. }
  2949. $this->x=$x;
  2950. // WORD SPACING
  2951. $this->SetSpacing($charspacing,$ws);
  2952. }
  2953. // Test: to put border round each cell: $border=1;
  2954. // Test: to put line through centre of cell: $this->Line($this->x,$this->y+($h/2),$this->x+50,$this->y+($h/2));
  2955. /*-- COLUMNS --*/
  2956. // COLS
  2957. // COLUMN CHANGE
  2958. if ($this->CurrCol != $oldcolumn) {
  2959. if ($currentx) {
  2960. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  2961. }
  2962. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  2963. }
  2964. // COLUMNS Update/overwrite the lowest bottom of printing y value for a column
  2965. if ($this->ColActive) {
  2966. if ($h) { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h; }
  2967. else { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$this->divheight; }
  2968. }
  2969. /*-- END COLUMNS --*/
  2970. // KEEP BLOCK TOGETHER Update/overwrite the lowest bottom of printing y value on first page
  2971. if ($this->keep_block_together) {
  2972. if ($h) { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h; }
  2973. // else { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$this->divheight; }
  2974. }
  2975. if($w==0) $w = $this->w-$this->rMargin-$this->x;
  2976. $s='';
  2977. if($fill==1 && $this->FillColor) {
  2978. if((isset($this->pageoutput[$this->page]['FillColor']) && $this->pageoutput[$this->page]['FillColor'] != $this->FillColor) || !isset($this->pageoutput[$this->page]['FillColor']) || $this->keep_block_together) { $s .= $this->FillColor.' '; }
  2979. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  2980. }
  2981. $boxtop = $this->y;
  2982. $boxheight = $h;
  2983. $boxbottom = $this->y+$h;
  2984. if($txt!='') {
  2985. // FONT SIZE - this determines the baseline caculation
  2986. if ($this->linemaxfontsize && !$this->processingHeader) { $bfs = $this->linemaxfontsize; }
  2987. else { $bfs = $this->FontSize; }
  2988. //Calculate baseline Superscript and Subscript Y coordinate adjustment
  2989. $bfx = $this->baselineC;
  2990. $baseline = $bfx*$bfs;
  2991. if($this->SUP) { $baseline += ($bfx-1.05)*$this->FontSize; }
  2992. else if($this->SUB) { $baseline += ($bfx + 0.04)*$this->FontSize; }
  2993. else if($this->bullet) { $baseline += ($bfx-0.7)*$this->FontSize; }
  2994. // Vertical align (for Images)
  2995. if ($abovefont || $belowfont) { // from flowing block - valign always M
  2996. $va = $abovefont + (0.5*$bfs);
  2997. }
  2998. else if ($this->lineheight_correction) {
  2999. if ($valign == 'T') { $va = (0.5 * $bfs * $this->lineheight_correction); }
  3000. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->lineheight_correction); }
  3001. else { $va = 0.5*$h; } // Middle
  3002. }
  3003. else {
  3004. if ($valign == 'T') { $va = (0.5 * $bfs * $this->default_lineheight_correction); }
  3005. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->default_lineheight_correction); }
  3006. else { $va = 0.5*$h; } // Middle
  3007. }
  3008. // ONLY SET THESE IF WANT TO CONFINE BORDER +- FILL TO FIT FONTSIZE - NOT FULL CELL
  3009. if ($spanfill) {
  3010. $boxtop = $this->y+$baseline+$va-($this->FontSize*(0.5+$bfx));
  3011. $boxheight = $this->FontSize;
  3012. $boxbottom = $boxtop + $boxheight;
  3013. }
  3014. }
  3015. if($fill==1 or $border==1) {
  3016. if ($fill==1) $op=($border==1) ? 'B' : 'f';
  3017. else $op='S';
  3018. $s.=sprintf('%.3f %.3f %.3f %.3f re %s ',$this->x*$k,($this->h-$boxtop)*$k,$w*$k,-$boxheight*$k,$op);
  3019. }
  3020. if(is_string($border)) {
  3021. $x=$this->x;
  3022. $y=$this->y;
  3023. if(is_int(strpos($border,'L')))
  3024. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',$x*$k,($this->h-$boxtop)*$k,$x*$k,($this->h-($boxbottom))*$k);
  3025. if(is_int(strpos($border,'T')))
  3026. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',$x*$k,($this->h-$boxtop)*$k,($x+$w)*$k,($this->h-$boxtop)*$k);
  3027. if(is_int(strpos($border,'R')))
  3028. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',($x+$w)*$k,($this->h-$boxtop)*$k,($x+$w)*$k,($this->h-($boxbottom))*$k);
  3029. if(is_int(strpos($border,'B')))
  3030. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',$x*$k,($this->h-($boxbottom))*$k,($x+$w)*$k,($this->h-($boxbottom))*$k);
  3031. }
  3032. if($txt!='') {
  3033. $stringWidth = $this->GetStringWidth($txt) + ( $this->charspacing * mb_strlen( $txt, $this->mb_enc ) / $k )
  3034. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ) / $k );
  3035. // Set x OFFSET FOR PRINTING
  3036. if($align=='R') {
  3037. $dx=$w-$this->cMarginR - $stringWidth - $lcpaddingR;
  3038. }
  3039. elseif($align=='C') {
  3040. $dx=(($w - $stringWidth )/2);
  3041. }
  3042. elseif($align=='L' or $align=='J') $dx=$this->cMarginL + $lcpaddingL;
  3043. else $dx = 0;
  3044. if($this->ColorFlag) $s.='q '.$this->TextColor.' ';
  3045. // OUTLINE
  3046. if($this->outline_on && !$this->S) {
  3047. $s.=' '.sprintf('%.3f w',$this->LineWidth*$k).' ';
  3048. $s.=" $this->DrawColor ";
  3049. $s.=" 2 Tr ";
  3050. }
  3051. else if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false && !$this->S) { // can't use together with OUTLINE or Small Caps
  3052. $s .= ' 2 Tr 1 J 1 j ';
  3053. $s .= ' '.sprintf('%.3f w',($this->FontSize/130)*$k*$this->falseBoldWeight).' ';
  3054. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3055. if($this->FillColor!=$tc) { $s .= ' '.$tc.' '; } // stroke (outline) = same colour as text(fill)
  3056. }
  3057. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) { // Artificial italic
  3058. $aix = '1 0 0.261799 1 %.3f %.3f Tm ';
  3059. }
  3060. else { $aix = '%.3f %.3f Td '; }
  3061. // THE TEXT
  3062. $this->CurrentFont['used']= true;
  3063. // WORD SPACING
  3064. // IF multibyte - Tw has no effect - need to use alternative method - do word spacing using an adjustment before each space
  3065. if ($this->ws && !$this->usingCoreFont && !$this->CurrentFont['sip'] && !$this->CurrentFont['smp'] && !$this->S) { // mPDF 5.0.03
  3066. $s .= ' BT 0 Tw ET '; // mPDF 5.1.020
  3067. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt, 'MBTw', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); } // mPDF 5.0.061
  3068. else {
  3069. $space = " ";
  3070. //Convert string to UTF-16BE without BOM
  3071. $space= $this->UTF8ToUTF16BE($space , false);
  3072. $space=$this->_escape($space );
  3073. $s.=sprintf('BT '.$aix,($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k);
  3074. $t = explode(' ',$txt);
  3075. $s.=sprintf(' %.3f Tc [',$this->charspacing); // mPDF 5.0.063
  3076. for($i=0;$i<count($t);$i++) {
  3077. $tx = $t[$i];
  3078. //Convert string to UTF-16BE without BOM
  3079. $tx = $this->UTF8ToUTF16BE($tx , false);
  3080. $tx = $this->_escape($tx);
  3081. $s.=sprintf('(%s) ',$tx); // mPDF 5.0.063
  3082. if (($i+1)<count($t)) {
  3083. $adj = -($this->ws)*1000/$this->FontSizePt; // mPDF 5.0.063
  3084. $s.=sprintf('%d(%s) ',$adj,$space); // mPDF 5.0.063
  3085. }
  3086. }
  3087. $s.='] TJ '; // mPDF 5.0.063
  3088. $s.=' ET';
  3089. }
  3090. }
  3091. else {
  3092. $txt2= $txt;
  3093. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) { // mPDF 5.0.03 Added SMP
  3094. if ($this->S) { $s .= $this->_smallCaps($txt2, 'SIPSMP', $aix, $dx, $k, $baseline, $va, $space); }
  3095. else {
  3096. $txt2 = $this->UTF8toSubset($txt2);
  3097. $s.=sprintf('BT '.$aix.' %s Tj ET',($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k,$txt2);
  3098. }
  3099. }
  3100. else {
  3101. if ($this->S) { $s .= $this->_smallCaps($txt2, '', $aix, $dx, $k, $baseline, $va, $space); }
  3102. else if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); } // mPDF 5.0.061
  3103. else {
  3104. if (!$this->usingCoreFont) {
  3105. $txt2 = $this->UTF8ToUTF16BE($txt2, false);
  3106. }
  3107. $txt2=$this->_escape($txt2);
  3108. $s.=sprintf('BT '.$aix.' (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k,$txt2);
  3109. }
  3110. }
  3111. }
  3112. // UNDERLINE
  3113. if($this->U) {
  3114. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3115. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  3116. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  3117. else { $up = -100; }
  3118. $adjusty = (-$up/1000* $this->FontSize);
  3119. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3120. else { $ut = 60/1000* $this->FontSize; }
  3121. $olw = $this->LineWidth;
  3122. $s.=' '.(sprintf(' %.3f w',$ut*$this->k));
  3123. $s.=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3124. $s.=' '.(sprintf(' %.3f w',$olw*$this->k));
  3125. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  3126. }
  3127. // STRIKETHROUGH
  3128. if($this->strike) {
  3129. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3130. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  3131. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  3132. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  3133. else { $ch = 700; }
  3134. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  3135. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3136. else { $ut = 60/1000* $this->FontSize; }
  3137. $olw = $this->LineWidth;
  3138. $s.=' '.(sprintf(' %.3f w',$ut*$this->k));
  3139. $s.=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3140. $s.=' '.(sprintf(' %.3f w',$olw));
  3141. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  3142. }
  3143. // COLOR
  3144. if($this->ColorFlag) $s.=' Q';
  3145. // LINK
  3146. if($link!='') {
  3147. $this->Link($this->x+$dx,$this->y+$va-.5*$this->FontSize,$stringWidth,$this->FontSize,$link);
  3148. }
  3149. }
  3150. if($s) $this->_out($s);
  3151. // WORD SPACING
  3152. if ($this->ws && !$this->usingCoreFont) {
  3153. $this->_out(sprintf('BT %.3f Tc ET',$this->charspacing));
  3154. }
  3155. $this->lasth=$h;
  3156. if( strpos($txt,"\n") !== false) $ln=1; // cell recognizes \n from <BR> tag
  3157. if($ln>0)
  3158. {
  3159. //Go to next line
  3160. $this->y += $h;
  3161. if($ln==1) {
  3162. //Move to next line
  3163. if ($currentx != 0) { $this->x=$currentx; }
  3164. else { $this->x=$this->lMargin; }
  3165. }
  3166. }
  3167. else $this->x+=$w;
  3168. }
  3169. // mPDF 5.0.061
  3170. function _kern($txt, $mode, $aix, $x, $y) {
  3171. if ($mode == 'MBTw') { // Multibyte requiring word spacing
  3172. $space = ' ';
  3173. //Convert string to UTF-16BE without BOM
  3174. $space= $this->UTF8ToUTF16BE($space , false);
  3175. $space=$this->_escape($space );
  3176. $s = sprintf(' BT '.$aix,$x*$this->k,($this->h-$y)*$this->k);
  3177. $t = explode(' ',$txt);
  3178. for($i=0;$i<count($t);$i++) {
  3179. $tx = $t[$i];
  3180. $tj = '(';
  3181. $unicode = $this->UTF8StringToArray($tx);
  3182. for($ti=0;$ti<count($unicode);$ti++) {
  3183. if ($ti > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]])) {
  3184. $kern = -$this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]];
  3185. $tj .= sprintf(')%d(',$kern);
  3186. }
  3187. $tc = code2utf($unicode[$ti]);
  3188. $tc = $this->UTF8ToUTF16BE($tc, false);
  3189. $tj .= $this->_escape($tc);
  3190. }
  3191. $tj .= ')';
  3192. $s.=sprintf(' %.3f Tc [%s] TJ',$this->charspacing,$tj);
  3193. if (($i+1)<count($t)) {
  3194. $s.=sprintf(' %.3f Tc (%s) Tj',$this->ws+$this->charspacing,$space);
  3195. }
  3196. }
  3197. $s.=' ET ';
  3198. }
  3199. else if (!$this->usingCoreFont) {
  3200. $s = '';
  3201. $tj = '(';
  3202. $unicode = $this->UTF8StringToArray($txt);
  3203. for($i=0;$i<count($unicode);$i++) {
  3204. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]])) {
  3205. $kern = -$this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]];
  3206. $tj .= sprintf(')%d(',$kern);
  3207. }
  3208. $tx = code2utf($unicode[$i]);
  3209. $tx = $this->UTF8ToUTF16BE($tx, false);
  3210. $tj .= $this->_escape($tx);
  3211. }
  3212. $tj .= ')';
  3213. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*$this->k,($this->h-$y)*$this->k,$tj);
  3214. }
  3215. else { // CORE Font
  3216. $s = '';
  3217. $tj = '(';
  3218. $l = strlen($txt);
  3219. for($i=0;$i<$l;$i++) {
  3220. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]])) {
  3221. $kern = -$this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]];
  3222. $tj .= sprintf(')%d(',$kern);
  3223. }
  3224. $tj .= $this->_escape($txt[$i]);
  3225. }
  3226. $tj .= ')';
  3227. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*$this->k,($this->h-$y)*$this->k,$tj);
  3228. }
  3229. return $s;
  3230. }
  3231. function _smallCaps($txt, $mode, $aix, $dx, $k, $baseline, $va, $space) {
  3232. $upp = false;
  3233. $str = array();
  3234. $bits = array();
  3235. if (!$this->usingCoreFont) {
  3236. $unicode = $this->UTF8StringToArray($txt);
  3237. foreach($unicode as $char) {
  3238. // mPDF 5.0.064
  3239. if ($this->ws && $char == 32) { // space
  3240. if (count($str)) { $bits[] = array($upp, $str, false); }
  3241. $bits[] = array(false, array(32), true);
  3242. $str = array();
  3243. $upp = false;
  3244. }
  3245. else if (isset($this->upperCase[$char])) {
  3246. if (!$upp) {
  3247. if (count($str)) { $bits[] = array($upp, $str, false); }
  3248. $str = array();
  3249. }
  3250. $str[] = $this->upperCase[$char];
  3251. if ((!isset($this->CurrentFont['sip']) || !$this->CurrentFont['sip']) && (!isset($this->CurrentFont['smp']) || !$this->CurrentFont['smp'])) {
  3252. $this->CurrentFont['subset'][$this->upperCase[$char]] = $this->upperCase[$char];
  3253. }
  3254. $upp = true;
  3255. }
  3256. else {
  3257. if ($upp) {
  3258. if (count($str)) { $bits[] = array($upp, $str, false); }
  3259. $str = array();
  3260. }
  3261. $str[] = $char;
  3262. $upp = false;
  3263. }
  3264. }
  3265. }
  3266. else {
  3267. for($i=0;$i<strlen($txt);$i++) {
  3268. if (isset($this->upperCase[ord($txt[$i])]) && $this->upperCase[ord($txt[$i])] < 256) {
  3269. if (!$upp) {
  3270. if (count($str)) { $bits[] = array($upp, $str, false); }
  3271. $str = array();
  3272. }
  3273. $str[] = $this->upperCase[ord($txt[$i])];
  3274. $upp = true;
  3275. }
  3276. else {
  3277. if ($upp) {
  3278. if (count($str)) { $bits[] = array($upp, $str, false); }
  3279. $str = array();
  3280. }
  3281. $str[] = ord($txt[$i]);
  3282. $upp = false;
  3283. }
  3284. }
  3285. }
  3286. if (count($str)) { $bits[] = array($upp, $str, false); }
  3287. $fid = $this->CurrentFont['i'];
  3288. $s.=sprintf(' BT '.$aix,($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k);
  3289. foreach($bits AS $b) {
  3290. if ($b[0]) { $upp = true; }
  3291. else { $upp = false; }
  3292. $size = count ($b[1]);
  3293. $txt = '';
  3294. for ($i = 0; $i < $size; $i++) {
  3295. $txt .= code2utf($b[1][$i]);
  3296. }
  3297. if ($this->usingCoreFont) {
  3298. $txt = utf8_decode($txt);
  3299. }
  3300. if ($mode == 'SIPSMP') {
  3301. $txt = $this->UTF8toSubset($txt);
  3302. }
  3303. else {
  3304. if (!$this->usingCoreFont) {
  3305. $txt = $this->UTF8ToUTF16BE($txt, false);
  3306. }
  3307. $txt=$this->_escape($txt);
  3308. $txt = '('.$txt.')';
  3309. }
  3310. // mPDF 5.0.064
  3311. if ($b[2]) { // space
  3312. $s.=sprintf(' /F%d %.3f Tf %d Tz', $fid, $this->FontSizePt, 100);
  3313. $s.=sprintf(' %.3f Tc', ($this->charspacing+$this->ws));
  3314. $s.=sprintf(' %s Tj', $txt);
  3315. }
  3316. else if ($upp) {
  3317. $s.=sprintf(' /F%d %.3f Tf', $fid, $this->FontSizePt*$this->smCapsScale);
  3318. $s.=sprintf(' %d Tz', $this->smCapsStretch);
  3319. $s.=sprintf(' %.3f Tc', ($this->charspacing*100/$this->smCapsStretch));
  3320. $s.=sprintf(' %s Tj', $txt);
  3321. }
  3322. else {
  3323. $s.=sprintf(' /F%d %.3f Tf %d Tz', $fid, $this->FontSizePt, 100);
  3324. $s.=sprintf(' %.3f Tc', ($this->charspacing));
  3325. $s.=sprintf(' %s Tj', $txt);
  3326. }
  3327. }
  3328. $s.=' ET ';
  3329. return $s;
  3330. }
  3331. function MultiCell($w,$h,$txt,$border=0,$align='',$fill=0,$link='',$directionality='ltr',$encoded=false)
  3332. {
  3333. // Parameter (pre-)encoded - When called internally from ToC or textarea: mb_encoding already done - but not reverse RTL/Indic
  3334. if (!$encoded) {
  3335. $txt = $this->purify_utf8_text($txt);
  3336. if ($this->text_input_as_HTML) {
  3337. $txt = $this->all_entities_to_utf8($txt);
  3338. }
  3339. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  3340. // Font-specific ligature substitution for Indic fonts
  3341. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { // *INDIC*
  3342. $this->ConvertIndic($tmp); // *INDIC*
  3343. } // *INDIC*
  3344. // mPDF 5.0.054
  3345. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  3346. }
  3347. // mPDF 5.0.054
  3348. if (!$align) { $align = $this->defaultAlign; }
  3349. //Output text with automatic or explicit line breaks
  3350. $cw=&$this->CurrentFont['cw'];
  3351. if($w==0) $w=$this->w-$this->rMargin-$this->x;
  3352. $wmax = ($w - ($this->cMarginL+$this->cMarginR)); // mPDF 5.0
  3353. if ($this->usingCoreFont) {
  3354. $s=str_replace("\r",'',$txt);
  3355. $nb=strlen($s);
  3356. while($nb>0 and $s[$nb-1]=="\n") $nb--;
  3357. }
  3358. else {
  3359. $s=str_replace("\r",'',$txt);
  3360. $nb=mb_strlen($s, $this->mb_enc );
  3361. while($nb>0 and mb_substr($s,$nb-1,1,$this->mb_enc )=="\n") $nb--;
  3362. }
  3363. $b=0;
  3364. if($border) {
  3365. if($border==1) {
  3366. $border='LTRB';
  3367. $b='LRT';
  3368. $b2='LR';
  3369. }
  3370. else {
  3371. $b2='';
  3372. if(is_int(strpos($border,'L'))) $b2.='L';
  3373. if(is_int(strpos($border,'R'))) $b2.='R';
  3374. $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
  3375. }
  3376. }
  3377. $sep=-1;
  3378. $i=0;
  3379. $j=0;
  3380. $l=0;
  3381. $ns=0;
  3382. $nl=1;
  3383. if (!$this->usingCoreFont) {
  3384. // mPDF 5.0.071
  3385. $checkCursive=false;
  3386. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  3387. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  3388. while($i<$nb) {
  3389. //Get next character
  3390. $c = mb_substr($s,$i,1,$this->mb_enc );
  3391. if($c == "\n") {
  3392. //Explicit line break
  3393. // WORD SPACING
  3394. $this->ResetSpacing();
  3395. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3396. // DIRECTIONALITY
  3397. // mPDF 5.0.054
  3398. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3399. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3400. $i++;
  3401. $sep=-1;
  3402. $j=$i;
  3403. $l=0;
  3404. $ns=0;
  3405. $nl++;
  3406. if($border and $nl==2) $b=$b2;
  3407. continue;
  3408. }
  3409. if($c == " ") {
  3410. $sep=$i;
  3411. $ls=$l;
  3412. $ns++;
  3413. }
  3414. $l += $this->GetStringWidth($c); // mPDF 5.0.072
  3415. if($l>$wmax) {
  3416. //Automatic line break
  3417. if($sep==-1) { // Only one word
  3418. if($i==$j) $i++;
  3419. // WORD SPACING
  3420. $this->ResetSpacing();
  3421. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3422. // DIRECTIONALITY
  3423. // mPDF 5.0.054
  3424. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3425. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3426. }
  3427. else {
  3428. $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc));
  3429. if($align=='J') {
  3430. //////////////////////////////////////////
  3431. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3432. // WORD SPACING UNICODE
  3433. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3434. $tmp = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$tmp );
  3435. $len_ligne = $this->GetStringWidth($tmp );
  3436. $nb_carac = mb_strlen( $tmp , $this->mb_enc ) ;
  3437. $nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3438. // mPDF 5.0.071
  3439. $inclCursive=false;
  3440. if ($checkCursive) {
  3441. if (preg_match("/([".$this->pregRTLchars."])/u", $tmp)) { $inclCursive = true; } // *RTL*
  3442. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $tmp)) { $inclCursive = true; } // *INDIC*
  3443. }
  3444. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * $this->k),$inclCursive); // mPDF 5.0.071
  3445. $this->SetSpacing($charspacing,$ws);
  3446. //////////////////////////////////////////
  3447. }
  3448. // DIRECTIONALITY
  3449. // mPDF 5.0.054
  3450. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3451. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3452. $i=$sep+1;
  3453. }
  3454. $sep=-1;
  3455. $j=$i;
  3456. $l=0;
  3457. $ns=0;
  3458. $nl++;
  3459. if($border and $nl==2) $b=$b2;
  3460. }
  3461. else $i++;
  3462. }
  3463. //Last chunk
  3464. // WORD SPACING
  3465. $this->ResetSpacing();
  3466. }
  3467. else {
  3468. while($i<$nb) {
  3469. //Get next character
  3470. $c=$s[$i];
  3471. if($c == "\n") {
  3472. //Explicit line break
  3473. // WORD SPACING
  3474. $this->ResetSpacing();
  3475. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3476. $i++;
  3477. $sep=-1;
  3478. $j=$i;
  3479. $l=0;
  3480. $ns=0;
  3481. $nl++;
  3482. if($border and $nl==2) $b=$b2;
  3483. continue;
  3484. }
  3485. if($c == " ") {
  3486. $sep=$i;
  3487. $ls=$l;
  3488. $ns++;
  3489. }
  3490. $l += $this->GetStringWidth($c);
  3491. if($l>$wmax) {
  3492. //Automatic line break
  3493. if($sep==-1) {
  3494. if($i==$j) $i++;
  3495. // WORD SPACING
  3496. $this->ResetSpacing();
  3497. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3498. }
  3499. else {
  3500. if($align=='J') {
  3501. $tmp = rtrim(substr($s,$j,$sep-$j));
  3502. //////////////////////////////////////////
  3503. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3504. // WORD SPACING NON_UNICDOE/CJK
  3505. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3506. $tmp = str_replace($this->chrs[160],$this->chrs[32],$tmp);
  3507. $len_ligne = $this->GetStringWidth($tmp );
  3508. $nb_carac = strlen( $tmp ) ;
  3509. $nb_spaces = substr_count( $tmp ,' ' ) ;
  3510. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * $this->k),false); // mPDF 5.0.071
  3511. $this->SetSpacing($charspacing,$ws);
  3512. //////////////////////////////////////////
  3513. }
  3514. $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link);
  3515. $i=$sep+1;
  3516. }
  3517. $sep=-1;
  3518. $j=$i;
  3519. $l=0;
  3520. $ns=0;
  3521. $nl++;
  3522. if($border and $nl==2) $b=$b2;
  3523. }
  3524. else $i++;
  3525. }
  3526. //Last chunk
  3527. // WORD SPACING
  3528. $this->ResetSpacing();
  3529. }
  3530. //Last chunk
  3531. if($border and is_int(strpos($border,'B'))) $b.='B';
  3532. if (!$this->usingCoreFont) {
  3533. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3534. // DIRECTIONALITY
  3535. // mPDF 5.0.054
  3536. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3537. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3538. }
  3539. else { $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); }
  3540. $this->x=$this->lMargin;
  3541. }
  3542. /*-- DIRECTW --*/
  3543. function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
  3544. // mPDF 5.0.054
  3545. if (!$align) {
  3546. if ($directionality=='rtl') { $align = 'R'; }
  3547. else { $align = 'L'; }
  3548. }
  3549. if ($h == 0) { $this->SetLineHeight(); $h = $this->lineheight; }
  3550. //Output text in flowing mode
  3551. $w = $this->w - $this->rMargin - $this->x;
  3552. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3553. $s=str_replace("\r",'',$txt);
  3554. if ($this->usingCoreFont) { $nb=strlen($s); }
  3555. else {
  3556. $nb=mb_strlen($s, $this->mb_enc );
  3557. // handle single space character
  3558. if(($nb==1) && $s == " ") {
  3559. $this->x += $this->GetStringWidth($s);
  3560. return;
  3561. }
  3562. }
  3563. $sep=-1;
  3564. $i=0;
  3565. $j=0;
  3566. $l=0;
  3567. $nl=1;
  3568. if (!$this->usingCoreFont) {
  3569. // mPDF 5.0.071
  3570. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  3571. $checkCursive=false;
  3572. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  3573. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  3574. while($i<$nb) {
  3575. //Get next character
  3576. $c = mb_substr($s,$i,1,$this->mb_enc );
  3577. if($c == "\n") {
  3578. // WORD SPACING
  3579. $this->ResetSpacing();
  3580. //Explicit line break
  3581. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3582. // mPDF 5.0.054
  3583. if ($directionality == 'rtl' && $align == 'J') { $align = 'R'; } // *RTL*
  3584. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3585. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3586. $i++;
  3587. $sep = -1;
  3588. $j = $i;
  3589. $l = 0;
  3590. if($nl == 1) {
  3591. if ($currentx != 0) $this->x=$currentx;
  3592. else $this->x=$this->lMargin;
  3593. $w = $this->w - $this->rMargin - $this->x;
  3594. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3595. }
  3596. $nl++;
  3597. continue;
  3598. }
  3599. if($c == " ") { $sep= $i; }
  3600. $l += $this->GetStringWidth($c); // mPDF 5.0.072
  3601. if($l > $wmax) {
  3602. //Automatic line break (word wrapping)
  3603. if($sep == -1) {
  3604. // WORD SPACING
  3605. $this->ResetSpacing();
  3606. if($this->x > $this->lMargin) {
  3607. //Move to next line
  3608. if ($currentx != 0) $this->x=$currentx;
  3609. else $this->x=$this->lMargin;
  3610. $this->y+=$h;
  3611. $w=$this->w-$this->rMargin-$this->x;
  3612. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3613. $i++;
  3614. $nl++;
  3615. continue;
  3616. }
  3617. if($i==$j) { $i++; }
  3618. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3619. // mPDF 5.0.054
  3620. if ($directionality == 'rtl' && $align == 'J') { $align = 'R'; } // *RTL*
  3621. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3622. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3623. }
  3624. else {
  3625. $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc));
  3626. // mPDF 5.0.054
  3627. if ($directionality == 'rtl' && $align == 'J') { $align = 'R'; } // *RTL*
  3628. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3629. if($align=='J') {
  3630. //////////////////////////////////////////
  3631. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3632. // WORD SPACING
  3633. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3634. $tmp = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$tmp );
  3635. $len_ligne = $this->GetStringWidth($tmp );
  3636. $nb_carac = mb_strlen( $tmp , $this->mb_enc ) ;
  3637. $nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3638. // mPDF 5.0.071
  3639. $inclCursive=false;
  3640. if ($checkCursive) {
  3641. if (preg_match("/([".$this->pregRTLchars."])/u", $tmp)) { $inclCursive = true; } // *RTL*
  3642. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $tmp)) { $inclCursive = true; } // *INDIC*
  3643. }
  3644. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * $this->k),$inclCursive); // mPDF 5.0.071
  3645. $this->SetSpacing($charspacing,$ws);
  3646. //////////////////////////////////////////
  3647. }
  3648. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3649. $i=$sep+1;
  3650. }
  3651. $sep = -1;
  3652. $j = $i;
  3653. $l = 0;
  3654. if($nl==1) {
  3655. if ($currentx != 0) $this->x=$currentx;
  3656. else $this->x=$this->lMargin;
  3657. $w=$this->w-$this->rMargin-$this->x;
  3658. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3659. }
  3660. $nl++;
  3661. }
  3662. else { $i++; }
  3663. }
  3664. //Last chunk
  3665. // WORD SPACING
  3666. $this->ResetSpacing();
  3667. }
  3668. else {
  3669. while($i<$nb) {
  3670. //Get next character
  3671. $c=$s[$i];
  3672. if($c == "\n") {
  3673. //Explicit line break
  3674. // WORD SPACING
  3675. $this->ResetSpacing();
  3676. $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
  3677. $i++;
  3678. $sep = -1;
  3679. $j = $i;
  3680. $l = 0;
  3681. if($nl == 1) {
  3682. if ($currentx != 0) $this->x=$currentx;
  3683. else $this->x=$this->lMargin;
  3684. $w = $this->w - $this->rMargin - $this->x;
  3685. $wmax=$w-($this->cMarginL+$this->cMarginR); // mPDF 5.0.072
  3686. }
  3687. $nl++;
  3688. continue;
  3689. }
  3690. if($c == " ") { $sep= $i; }
  3691. $l += $this->GetStringWidth($c); // mPDF 5.0.072
  3692. if($l > $wmax) {
  3693. //Automatic line break (word wrapping)
  3694. if($sep == -1) {
  3695. // WORD SPACING
  3696. $this->ResetSpacing();
  3697. if($this->x > $this->lMargin) {
  3698. //Move to next line
  3699. if ($currentx != 0) $this->x=$currentx;
  3700. else $this->x=$this->lMargin;
  3701. $this->y+=$h;
  3702. $w=$this->w-$this->rMargin-$this->x;
  3703. $wmax=$w-($this->cMarginL+$this->cMarginR); // mPDF 5.0.072
  3704. $i++;
  3705. $nl++;
  3706. continue;
  3707. }
  3708. if($i==$j) { $i++; }
  3709. $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
  3710. }
  3711. else {
  3712. $tmp = substr($s, $j, $sep-$j);
  3713. if($align=='J') {
  3714. //////////////////////////////////////////
  3715. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3716. // WORD SPACING
  3717. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3718. $tmp = str_replace($this->chrs[160],$this->chrs[32],$tmp );
  3719. $len_ligne = $this->GetStringWidth($tmp );
  3720. $nb_carac = strlen( $tmp ) ;
  3721. $nb_spaces = substr_count( $tmp ,' ' ) ;
  3722. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * $this->k),$false); // mPDF 5.0.071
  3723. $this->SetSpacing($charspacing,$ws);
  3724. //////////////////////////////////////////
  3725. }
  3726. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3727. $i=$sep+1;
  3728. }
  3729. $sep = -1;
  3730. $j = $i;
  3731. $l = 0;
  3732. if($nl==1) {
  3733. if ($currentx != 0) $this->x=$currentx;
  3734. else $this->x=$this->lMargin;
  3735. $w=$this->w-$this->rMargin-$this->x;
  3736. $wmax=$w-($this->cMarginL+$this->cMarginR); // mPDF 5.0.072
  3737. }
  3738. $nl++;
  3739. }
  3740. else {
  3741. $i++;
  3742. }
  3743. }
  3744. // WORD SPACING
  3745. $this->ResetSpacing();
  3746. }
  3747. //Last chunk
  3748. if($i!=$j) {
  3749. if ($currentx != 0) $this->x=$currentx; // mPDF 5.0.072
  3750. else $this->x=$this->lMargin; // mPDF 5.0.072
  3751. if ($this->usingCoreFont) { $tmp = substr($s,$j,$i-$j); }
  3752. else {
  3753. $tmp = mb_substr($s,$j,$i-$j,$this->mb_enc);
  3754. // mPDF 5.0.054
  3755. if ($directionality == 'rtl' && $align == 'J') { $align = 'R'; } // *RTL*
  3756. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3757. }
  3758. $this->Cell($w,$h,$tmp,0,0,$align,$fill,$link);
  3759. }
  3760. }
  3761. /*-- END DIRECTW --*/
  3762. function saveInlineProperties() {
  3763. $saved = array();
  3764. $saved[ 'family' ] = $this->FontFamily;
  3765. $saved[ 'style' ] = $this->FontStyle;
  3766. $saved[ 'sizePt' ] = $this->FontSizePt;
  3767. $saved[ 'size' ] = $this->FontSize;
  3768. $saved[ 'HREF' ] = $this->HREF;
  3769. $saved[ 'underline' ] = $this->U;
  3770. $saved[ 'smCaps' ] = $this->S; // mPDF 5.0
  3771. $saved[ 'strike' ] = $this->strike;
  3772. $saved[ 'SUP' ] = $this->SUP;
  3773. $saved[ 'SUB' ] = $this->SUB;
  3774. $saved[ 'linewidth' ] = $this->LineWidth;
  3775. $saved[ 'drawcolor' ] = $this->DrawColor;
  3776. $saved[ 'is_outline' ] = $this->outline_on;
  3777. $saved[ 'outlineparam' ] = $this->outlineparam;
  3778. $saved[ 'toupper' ] = $this->toupper;
  3779. $saved[ 'tolower' ] = $this->tolower;
  3780. $saved[ 'capitalize' ] = $this->capitalize; // mPDF 5.0.062
  3781. $saved[ 'fontkerning' ] = $this->kerning; // mPDF 5.0.063
  3782. $saved[ 'lSpacingCSS' ] = $this->lSpacingCSS; // mPDF 5.0.063
  3783. $saved[ 'wSpacingCSS' ] = $this->wSpacingCSS; // mPDF 5.0.063
  3784. $saved[ 'I' ] = $this->I;
  3785. $saved[ 'B' ] = $this->B;
  3786. $saved[ 'colorarray' ] = $this->colorarray;
  3787. $saved[ 'bgcolorarray' ] = $this->spanbgcolorarray;
  3788. $saved[ 'color' ] = $this->TextColor;
  3789. $saved[ 'bgcolor' ] = $this->FillColor;
  3790. $saved['lang'] = $this->currentLang;
  3791. $saved['display_off'] = $this->inlineDisplayOff; // mPDF 5.0
  3792. return $saved;
  3793. }
  3794. function restoreInlineProperties( &$saved) {
  3795. $FontFamily = $saved[ 'family' ];
  3796. $this->FontStyle = $saved[ 'style' ];
  3797. $this->FontSizePt = $saved[ 'sizePt' ];
  3798. $this->FontSize = $saved[ 'size' ];
  3799. $this->currentLang = $saved['lang'];
  3800. if ($this->useLang && !$this->usingCoreFont) {
  3801. if ($this->currentLang != $this->default_lang && ((strlen($this->currentLang) == 5 && $this->currentLang != 'UTF-8') || strlen($this->currentLang ) == 2)) {
  3802. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($this->currentLang, $this->useAdobeCJK);
  3803. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  3804. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  3805. }
  3806. else {
  3807. $this->RestrictUnicodeFonts($this->default_available_fonts );
  3808. }
  3809. }
  3810. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3811. $this->HREF = $saved[ 'HREF' ];
  3812. $this->U = $saved[ 'underline' ];
  3813. $this->S = $saved[ 'smCaps' ]; // mPDF 5.0
  3814. $this->strike = $saved[ 'strike' ];
  3815. $this->SUP = $saved[ 'SUP' ];
  3816. $this->SUB = $saved[ 'SUB' ];
  3817. $this->LineWidth = $saved[ 'linewidth' ];
  3818. $this->DrawColor = $saved[ 'drawcolor' ];
  3819. $this->outline_on = $saved[ 'is_outline' ];
  3820. $this->outlineparam = $saved[ 'outlineparam' ];
  3821. $this->inlineDisplayOff = $saved['display_off']; // mPDF 5.0
  3822. $this->toupper = $saved[ 'toupper' ];
  3823. $this->tolower = $saved[ 'tolower' ];
  3824. $this->capitalize = $saved[ 'capitalize' ]; // mPDF 5.0.062
  3825. $this->kerning = $saved[ 'fontkerning' ]; // mPDF 5.0.063
  3826. $this->lSpacingCSS = $saved[ 'lSpacingCSS' ]; // mPDF 5.0.063
  3827. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { // mPDF 5.0.066
  3828. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); // mPDF 5.0.066
  3829. }
  3830. else { $this->fixedlSpacing = false; }
  3831. $this->wSpacingCSS = $saved[ 'wSpacingCSS' ]; // mPDF 5.0.063
  3832. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  3833. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); // mPDF 5.0.066
  3834. }
  3835. else { $this->minwSpacing = 0; }
  3836. $this->SetFont($FontFamily, $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],false);
  3837. //$this->currentfontfamily = $saved[ 'family' ];
  3838. $this->currentfontstyle = $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : '');
  3839. $this->currentfontsize = $saved[ 'sizePt' ];
  3840. $this->SetStylesArray(array('S'=>$this->S, 'U'=>$this->U, 'B'=>$saved[ 'B' ], 'I'=>$saved[ 'I' ])); // mPDF 5.0
  3841. $this->TextColor = $saved[ 'color' ];
  3842. $this->FillColor = $saved[ 'bgcolor' ];
  3843. $this->colorarray = $saved[ 'colorarray' ];
  3844. $cor = $saved[ 'colorarray' ];
  3845. if ($cor) $this->SetTColor($cor); // mPDF 5.0.020
  3846. $this->spanbgcolorarray = $saved[ 'bgcolorarray' ];
  3847. $cor = $saved[ 'bgcolorarray' ];
  3848. if ($cor) $this->SetFColor($cor); // mPDF 5.0.020
  3849. }
  3850. // Used when ColActive for tables - updated to return first block with background fill OR borders
  3851. function GetFirstBlockFill() {
  3852. // Returns the first blocklevel that uses a bgcolor fill
  3853. $startfill = 0;
  3854. for ($i=1;$i<=$this->blklvl;$i++) {
  3855. if ($this->blk[$i]['bgcolor'] || $this->blk[$i]['border_left']['w'] || $this->blk[$i]['border_right']['w'] || $this->blk[$i]['border_top']['w'] || $this->blk[$i]['border_bottom']['w'] ) {
  3856. $startfill = $i;
  3857. break;
  3858. }
  3859. }
  3860. return $startfill;
  3861. }
  3862. function SetBlockFill($blvl) {
  3863. if ($this->blk[$blvl]['bgcolor']) {
  3864. $this->SetFColor($this->blk[$blvl]['bgcolorarray']); // mPDF 5.0.020
  3865. return 1;
  3866. }
  3867. else {
  3868. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  3869. return 0;
  3870. }
  3871. }
  3872. //-------------------------FLOWING BLOCK------------------------------------//
  3873. //The following functions were originally written by Damon Kohler //
  3874. //--------------------------------------------------------------------------//
  3875. function saveFont() {
  3876. $saved = array();
  3877. $saved[ 'family' ] = $this->FontFamily;
  3878. $saved[ 'style' ] = $this->FontStyle;
  3879. $saved[ 'sizePt' ] = $this->FontSizePt;
  3880. $saved[ 'size' ] = $this->FontSize;
  3881. $saved[ 'curr' ] = &$this->CurrentFont;
  3882. $saved[ 'color' ] = $this->TextColor;
  3883. $saved[ 'spanbgcolor' ] = $this->spanbgcolor;
  3884. $saved[ 'spanbgcolorarray' ] = $this->spanbgcolorarray;
  3885. $saved[ 'HREF' ] = $this->HREF;
  3886. $saved[ 'underline' ] = $this->U;
  3887. $saved[ 'smCaps' ] = $this->S; // mPDF 5.0
  3888. $saved[ 'strike' ] = $this->strike;
  3889. $saved[ 'SUP' ] = $this->SUP;
  3890. $saved[ 'SUB' ] = $this->SUB;
  3891. $saved[ 'linewidth' ] = $this->LineWidth;
  3892. $saved[ 'drawcolor' ] = $this->DrawColor;
  3893. $saved[ 'is_outline' ] = $this->outline_on;
  3894. $saved[ 'outlineparam' ] = $this->outlineparam;
  3895. $saved[ 'ReqFontStyle' ] = $this->ReqFontStyle;
  3896. $saved[ 'fontkerning' ] = $this->kerning; // mPDF 5.0.063
  3897. $saved[ 'fixedlSpacing' ] = $this->fixedlSpacing; // mPDF 5.0.063
  3898. $saved[ 'minwSpacing' ] = $this->minwSpacing; // mPDF 5.0.063
  3899. return $saved;
  3900. }
  3901. function restoreFont( &$saved, $write=true) {
  3902. if (!isset($saved) || empty($saved)) return;
  3903. $this->FontFamily = $saved[ 'family' ];
  3904. $this->FontStyle = $saved[ 'style' ];
  3905. $this->FontSizePt = $saved[ 'sizePt' ];
  3906. $this->FontSize = $saved[ 'size' ];
  3907. $this->CurrentFont = &$saved[ 'curr' ];
  3908. $this->TextColor = $saved[ 'color' ];
  3909. $this->spanbgcolor = $saved[ 'spanbgcolor' ];
  3910. $this->spanbgcolorarray = $saved[ 'spanbgcolorarray' ];
  3911. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3912. $this->HREF = $saved[ 'HREF' ];
  3913. $this->U = $saved[ 'underline' ];
  3914. $this->S = $saved[ 'smCaps' ]; // mPDF 5.0
  3915. $this->kerning = $saved[ 'fontkerning' ]; // mPDF 5.0.063
  3916. $this->fixedlSpacing = $saved[ 'fixedlSpacing' ]; // mPDF 5.0.063
  3917. $this->minwSpacing = $saved[ 'minwSpacing' ]; // mPDF 5.0.063
  3918. $this->strike = $saved[ 'strike' ];
  3919. $this->SUP = $saved[ 'SUP' ];
  3920. $this->SUB = $saved[ 'SUB' ];
  3921. $this->LineWidth = $saved[ 'linewidth' ];
  3922. $this->DrawColor = $saved[ 'drawcolor' ];
  3923. $this->outline_on = $saved[ 'is_outline' ];
  3924. $this->outlineparam = $saved[ 'outlineparam' ];
  3925. if ($write) {
  3926. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],true,true); // force output
  3927. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  3928. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); }
  3929. $this->pageoutput[$this->page]['Font'] = $fontout;
  3930. }
  3931. else
  3932. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ]);
  3933. $this->ReqFontStyle = $saved[ 'ReqFontStyle' ];
  3934. }
  3935. function newFlowingBlock( $w, $h, $a = '', $is_table = false, $is_list = false, $blockstate = 0, $newblock=true, $blockdir='ltr')
  3936. {
  3937. // mPDF 5.0.054
  3938. if (!$a) {
  3939. if ($blockdir=='rtl') { $a = 'R'; }
  3940. else { $a = 'L'; }
  3941. }
  3942. $this->flowingBlockAttr[ 'width' ] = ($w * $this->k);
  3943. // line height in user units
  3944. $this->flowingBlockAttr[ 'is_table' ] = $is_table;
  3945. $this->flowingBlockAttr[ 'is_list' ] = $is_list;
  3946. $this->flowingBlockAttr[ 'height' ] = $h;
  3947. $this->flowingBlockAttr[ 'lineCount' ] = 0;
  3948. $this->flowingBlockAttr[ 'align' ] = $a;
  3949. $this->flowingBlockAttr[ 'font' ] = array();
  3950. $this->flowingBlockAttr[ 'content' ] = array();
  3951. $this->flowingBlockAttr[ 'contentWidth' ] = 0;
  3952. $this->flowingBlockAttr[ 'blockstate' ] = $blockstate;
  3953. $this->flowingBlockAttr[ 'newblock' ] = $newblock;
  3954. $this->flowingBlockAttr[ 'valign' ] = 'M';
  3955. // mPDF 5.0.054
  3956. $this->flowingBlockAttr['blockdir'] = $blockdir;
  3957. }
  3958. function finishFlowingBlock($endofblock=false, $next='') {
  3959. $currentx = $this->x;
  3960. //prints out the last chunk
  3961. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  3962. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  3963. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  3964. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  3965. $align =& $this->flowingBlockAttr[ 'align' ];
  3966. $content =& $this->flowingBlockAttr[ 'content' ];
  3967. $font =& $this->flowingBlockAttr[ 'font' ];
  3968. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  3969. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  3970. $valign =& $this->flowingBlockAttr[ 'valign' ];
  3971. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  3972. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  3973. // mPDF 5.0.054
  3974. $blockdir = $this->flowingBlockAttr['blockdir'];
  3975. // *********** BLOCK BACKGROUND COLOR *****************//
  3976. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  3977. $fill = 0;
  3978. }
  3979. else {
  3980. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  3981. $fill = 0;
  3982. }
  3983. // mPDF 5.0.060 Edited - Always right trim!
  3984. // Right trim content and adjust width if need to justify (later)
  3985. // if (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br))) {
  3986. if (preg_match('/[ ]+$/',$content[count($content)-1], $m)) {
  3987. $strip = strlen($m[0]);
  3988. $content[count($content)-1] = substr($content[count($content)-1],0,(strlen($content[count($content)-1])-$strip));
  3989. $this->restoreFont( $font[ count($content)-1 ],false );
  3990. $contentWidth -= $this->GetStringWidth($m[0]) * $this->k;
  3991. }
  3992. // }
  3993. // the amount of space taken up so far in user units
  3994. $usedWidth = 0;
  3995. // COLS
  3996. $oldcolumn = $this->CurrCol;
  3997. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  3998. // Print out each chunk
  3999. /*-- TABLES --*/
  4000. if ($is_table) {
  4001. $ipaddingL = 0;
  4002. $ipaddingR = 0;
  4003. $paddingL = 0;
  4004. $paddingR = 0;
  4005. }
  4006. else {
  4007. /*-- END TABLES --*/
  4008. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4009. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4010. $paddingL = ($ipaddingL * $this->k);
  4011. $paddingR = ($ipaddingR * $this->k);
  4012. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4013. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4014. // Added mPDF 3.0 Float DIV
  4015. $fpaddingR = 0;
  4016. $fpaddingL = 0;
  4017. /*-- CSS-FLOAT --*/
  4018. if (count($this->floatDivs)) {
  4019. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4020. if ($r_exists) { $fpaddingR = $r_width; }
  4021. if ($l_exists) { $fpaddingL = $l_width; }
  4022. }
  4023. /*-- END CSS-FLOAT --*/
  4024. $usey = $this->y + 0.002;
  4025. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4026. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4027. }
  4028. /*-- CSS-IMAGE-FLOAT --*/
  4029. // If float exists at this level
  4030. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4031. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4032. /*-- END CSS-IMAGE-FLOAT --*/
  4033. } // *TABLES*
  4034. // Set Current lineheight (correction factor)
  4035. $lhfixed = false;
  4036. /*-- LISTS --*/
  4037. if ($is_list) {
  4038. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  4039. $lhfixed = true;
  4040. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  4041. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4042. }
  4043. else {
  4044. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  4045. }
  4046. }
  4047. else
  4048. /*-- END LISTS --*/
  4049. /*-- TABLES --*/
  4050. if ($is_table) {
  4051. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  4052. $lhfixed = true;
  4053. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  4054. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  4055. }
  4056. else {
  4057. $this->lineheight_correction = $this->table_lineheight;
  4058. }
  4059. }
  4060. else
  4061. /*-- END TABLES --*/
  4062. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  4063. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  4064. $lhfixed = true;
  4065. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  4066. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4067. }
  4068. else {
  4069. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  4070. }
  4071. }
  4072. else {
  4073. $this->lineheight_correction = $this->normalLineheight;
  4074. }
  4075. // correct lineheight to maximum fontsize
  4076. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  4077. else { $maxlineHeight = 0; }
  4078. $this->forceExactLineheight = true;
  4079. $maxfontsize = 0;
  4080. // mPDF 5.0.071
  4081. // While we're at it, check if contains cursive text
  4082. $checkCursive=false;
  4083. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  4084. foreach ( $content as $k => $chunk )
  4085. {
  4086. $this->restoreFont( $font[ $k ],false );
  4087. if (!isset($this->objectbuffer[$k])) {
  4088. // Soft Hyphens chr(173)
  4089. if (!$this->usingCoreFont) {
  4090. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  4091. // mPDF 5.0.071
  4092. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  4093. }
  4094. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  4095. $content[$k] = $chunk = str_replace($this->chrs[173],'',$chunk );
  4096. }
  4097. // Special case of sub/sup carried over on its own to last line
  4098. if (($this->SUB || $this->SUP) && count($content)==1) { $actfs = $this->FontSize*100/55; } // 55% is font change for sub/sup
  4099. else { $actfs = $this->FontSize; }
  4100. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4101. if ($lhfixed && ($actfs > $def_fontsize || ($actfs > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  4102. $this->forceExactLineheight = false;
  4103. }
  4104. $maxfontsize = max($maxfontsize,$actfs);
  4105. }
  4106. }
  4107. if(isset($font[count($font)-1])) { // mPDF 5.0.052
  4108. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  4109. $lastfontstyle = $font[count($font)-1]['style'];
  4110. }
  4111. else {
  4112. $lastfontreqstyle=null;
  4113. $lastfontstyle=null;
  4114. }
  4115. // mPDF 5.0.054
  4116. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  4117. $lastitalic = $this->FontSize*0.15*$this->k;
  4118. }
  4119. else { $lastitalic = 0; }
  4120. /*-- LISTS --*/
  4121. if ($is_list && is_array($this->bulletarray) && count($this->bulletarray)) {
  4122. $actfs = $this->bulletarray['fontsize'];
  4123. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4124. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  4125. $maxfontsize = max($maxfontsize,$actfs);
  4126. }
  4127. /*-- END LISTS --*/
  4128. // when every text item checked i.e. $maxfontsize is set properly
  4129. $af = 0; // Above font
  4130. $bf = 0; // Below font
  4131. $mta = 0; // Maximum top-aligned
  4132. $mba = 0; // Maximum bottom-aligned
  4133. foreach ( $content as $k => $chunk )
  4134. {
  4135. if (isset($this->objectbuffer[$k])) {
  4136. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  4137. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  4138. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  4139. if ($va == 'BS') { // (BASELINE default)
  4140. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  4141. }
  4142. else if ($va == 'M') {
  4143. $af = max($af, ($oh - $maxfontsize)/2);
  4144. $bf = max($bf, ($oh - $maxfontsize)/2);
  4145. }
  4146. else if ($va == 'TT') {
  4147. $bf = max($bf, ($oh - $maxfontsize));
  4148. }
  4149. else if ($va == 'TB') {
  4150. $af = max($af, ($oh - $maxfontsize));
  4151. }
  4152. else if ($va == 'T') {
  4153. $mta = max($mta, $oh);
  4154. }
  4155. else if ($va == 'B') {
  4156. $mba = max($mba, $oh);
  4157. }
  4158. }
  4159. }
  4160. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  4161. $maxlineHeight = $maxfontsize + $af + $bf;
  4162. }
  4163. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  4164. if ($mta > $maxlineHeight) {
  4165. $bf += ($mta - $maxlineHeight);
  4166. $maxlineHeight = $mta;
  4167. }
  4168. if ($mba > $maxlineHeight) {
  4169. $af += ($mba - $maxlineHeight);
  4170. $maxlineHeight = $mba;
  4171. }
  4172. $lineHeight = $maxlineHeight;
  4173. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  4174. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  4175. $this->linemaxfontsize = $def_fontsize;
  4176. }
  4177. else { $this->linemaxfontsize = $maxfontsize; }
  4178. // Get PAGEBREAK TO TEST for height including the bottom border/padding
  4179. $check_h = max($this->divheight,$lineHeight);
  4180. // mPDF 5.0.050
  4181. // This fixes a proven bug...
  4182. if ($endofblock && $newblock && $blockstate==0 && !$content) { $check_h = 0; }
  4183. // but ? needs to fix potentially more widespread...
  4184. // if (!$content) { $check_h = 0; }
  4185. if ($this->blklvl > 0 && !$is_table) {
  4186. if ($endofblock && $blockstate > 1) {
  4187. if ($this->blk[$this->blklvl]['page_break_after_avoid']) { $check_h += $lineHeight; }
  4188. $check_h += ($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4189. }
  4190. if (($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0) || ($endofblock && $blockstate > 1 && $lineCount == 0)) {
  4191. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  4192. }
  4193. }
  4194. // Force PAGE break if column height cannot take check-height
  4195. // mPDF 5.0.054
  4196. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  4197. $this->SetCol($this->NbCol-1);
  4198. }
  4199. // PAGEBREAK
  4200. //'If' below used in order to fix "first-line of other page with justify on" bug
  4201. if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  4202. $bak_x=$this->x;//Current X position
  4203. // WORD SPACING
  4204. $ws=$this->ws;//Word Spacing
  4205. $charspacing=$this->charspacing;//Character Spacing
  4206. $this->ResetSpacing();
  4207. $this->AddPage($this->CurOrientation);
  4208. $this->x=$bak_x;
  4209. // Added to correct for OddEven Margins
  4210. $currentx += $this->MarginCorrection;
  4211. $this->x += $this->MarginCorrection;
  4212. // WORD SPACING
  4213. $this->SetSpacing($charspacing,$ws);
  4214. }
  4215. // mPDF 5.0
  4216. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  4217. $this->printdivbuffer();
  4218. $this->keep_block_together = 0;
  4219. }
  4220. /*-- COLUMNS --*/
  4221. // COLS
  4222. // COLUMN CHANGE
  4223. if ($this->CurrCol != $oldcolumn) {
  4224. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4225. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4226. $oldcolumn = $this->CurrCol;
  4227. }
  4228. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; }
  4229. /*-- END COLUMNS --*/
  4230. // TOP MARGIN
  4231. if ($newblock && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && $lineCount == 0 && !$is_table && !$is_list) {
  4232. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4233. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4234. }
  4235. if ($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0 && !$is_table && !$is_list) {
  4236. $this->blk[$this->blklvl]['y0'] = $this->y;
  4237. $this->blk[$this->blklvl]['startpage'] = $this->page;
  4238. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4239. }
  4240. // ADDED for Paragraph_indent
  4241. $WidthCorrection = 0;
  4242. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  4243. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4244. $WidthCorrection = ($ti*$this->k);
  4245. }
  4246. // PADDING and BORDER spacing/fill
  4247. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 0) && (!$is_table) && (!$is_list)) {
  4248. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4249. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  4250. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4251. $this->x = $currentx;
  4252. }
  4253. // Added mPDF 3.0 Float DIV
  4254. $fpaddingR = 0;
  4255. $fpaddingL = 0;
  4256. /*-- CSS-FLOAT --*/
  4257. if (count($this->floatDivs)) {
  4258. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4259. if ($r_exists) { $fpaddingR = $r_width; }
  4260. if ($l_exists) { $fpaddingL = $l_width; }
  4261. }
  4262. /*-- END CSS-FLOAT --*/
  4263. $usey = $this->y + 0.002;
  4264. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4265. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4266. }
  4267. /*-- CSS-IMAGE-FLOAT --*/
  4268. // If float exists at this level
  4269. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4270. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4271. /*-- END CSS-IMAGE-FLOAT --*/
  4272. if ($content) {
  4273. // In FinishFlowing Block no lines are justified as it is always last line
  4274. // but if orphansAllowed have allowed content width to go over max width, use J charspacing to compress line
  4275. // JUSTIFICATION J - NOT!
  4276. $nb_carac = 0;
  4277. $nb_spaces = 0;
  4278. // mPDF 5.0.063
  4279. $jcharspacing = 0;
  4280. $jws = 0;
  4281. // mPDF 5.0.071
  4282. $inclCursive=false;
  4283. foreach ( $content as $k => $chunk ) {
  4284. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  4285. if ($this->usingCoreFont) {
  4286. $chunk = str_replace($this->chrs[160],$this->chrs[32],$chunk );
  4287. }
  4288. else {
  4289. $chunk = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$chunk );
  4290. }
  4291. $nb_carac += mb_strlen( $chunk, $this->mb_enc );
  4292. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc );
  4293. // mPDF 5.0.071
  4294. if ($checkCursive) {
  4295. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  4296. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  4297. }
  4298. }
  4299. }
  4300. // if it's justified, we need to find the char/word spacing (or if orphans have allowed length of line to go over the maxwidth)
  4301. // If "orphans" in fact is just a final space - ignore this
  4302. if (((($contentWidth + $lastitalic) > $maxWidth) && ($content[count($content)-1] != ' ') ) ||
  4303. (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br)))
  4304. ) {
  4305. // WORD SPACING
  4306. // mPDF 5.0.063
  4307. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$contentWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*$this->k)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) )),$inclCursive); // mPDF 5.0.071
  4308. }
  4309. // Check if will fit at word/char spacing of previous line - if so continue it
  4310. // but only allow a maximum of $this->jSmaxWordLast and $this->jSmaxCharLast
  4311. else if ($contentWidth < ($maxWidth - $lastitalic-$WidthCorrection - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k))) && !$this->fixedlSpacing) { // mPDF 5.0.063
  4312. if ($this->ws > $this->jSmaxWordLast) {
  4313. $jws = $this->jSmaxWordLast; // mPDF 5.0.063
  4314. }
  4315. if ($this->charspacing > $this->jSmaxCharLast) {
  4316. $jcharspacing = $this->jSmaxCharLast; // mPDF 5.0.063
  4317. }
  4318. $check = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) - ( $jcharspacing * $nb_carac) - ( $jws * $nb_spaces);
  4319. if ($check <= 0) {
  4320. $jcharspacing = 0;
  4321. $jws = 0;
  4322. }
  4323. }
  4324. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) );
  4325. // mPDF 5.0.063
  4326. $empty -= ($jcharspacing * $nb_carac);
  4327. $empty -= ($jws * $nb_spaces);
  4328. $empty /= $this->k;
  4329. if (!$is_table) {
  4330. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin'] - $empty));
  4331. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $empty));
  4332. }
  4333. $arraysize = count($content);
  4334. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  4335. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  4336. // DIRECTIONALITY RTL
  4337. $all_rtl = false;
  4338. $contains_rtl = false;
  4339. /*-- RTL --*/
  4340. // mPDF 5.0.054
  4341. if ($blockdir == 'rtl' || $this->biDirectional) { // mPDF 5.0.054
  4342. $all_rtl = true;
  4343. foreach ( $content as $k => $chunk ) {
  4344. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir); // mPDF 5.0.054
  4345. if ($reversed > 0) { $contains_rtl = true; }
  4346. if ($reversed < 2) { $all_rtl = false; }
  4347. $content[$k] = $chunk;
  4348. }
  4349. // mPDF 5.0.054
  4350. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $content = array_reverse($content,false); }
  4351. }
  4352. /*-- END RTL --*/
  4353. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL;
  4354. if ($align == 'R') { $this->x += $empty; }
  4355. // mPDF 5.0.054
  4356. else if ($align == 'J' && $blockdir == 'rtl') { $this->x += $empty; }
  4357. else if ($align == 'C') { $this->x += ($empty / 2); }
  4358. // Paragraph INDENT
  4359. $WidthCorrection = 0;
  4360. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align !='C')) {
  4361. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4362. $this->x += $ti;
  4363. }
  4364. foreach ( $content as $k => $chunk )
  4365. {
  4366. // FOR IMAGES
  4367. // mPDF 5.0.054
  4368. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $dirk = $arraysize-1 - $k; } else { $dirk = $k; }
  4369. $va = 'M'; // default for text
  4370. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  4371. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'];
  4372. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  4373. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  4374. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  4375. $va = $this->objectbuffer[$dirk]['vertical-align'];
  4376. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  4377. if ($va == 'BS') {
  4378. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4379. }
  4380. else if ($va == 'M' || $va == '') {
  4381. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  4382. }
  4383. else if ($va == 'TB') {
  4384. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4385. }
  4386. else if ($va == 'TT') {
  4387. $yadj += $af;
  4388. }
  4389. else if ($va == 'B') {
  4390. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4391. }
  4392. else if ($va == 'T') {
  4393. $yadj += 0;
  4394. }
  4395. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  4396. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  4397. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  4398. }
  4399. // DIRECTIONALITY RTL
  4400. // mPDF 5.0.054
  4401. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $this->restoreFont( $font[ $arraysize-1 - $k ] ); }
  4402. else { $this->restoreFont( $font[ $k ] ); }
  4403. // mPDF 5.0.063
  4404. $this->SetSpacing(($this->fixedlSpacing*$this->k)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*$this->k+$jws);
  4405. $this->fixedlSpacing = false;
  4406. $this->minwSpacing = 0;
  4407. // *********** SPAN BACKGROUND COLOR ***************** //
  4408. if (isset($this->spanbgcolor) && $this->spanbgcolor) {
  4409. $cor = $this->spanbgcolorarray;
  4410. $this->SetFColor($cor); // mPDF 5.0.020
  4411. $save_fill = $fill; $spanfill = 1; $fill = 1;
  4412. }
  4413. // WORD SPACING
  4414. $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / $this->k )
  4415. + ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / $this->k );
  4416. if (isset($this->objectbuffer[$dirk])) {
  4417. if ($this->objectbuffer[$dirk]['type']=='dottab') {
  4418. $this->objectbuffer[$dirk]['OUTER-WIDTH'] +=$empty;
  4419. }
  4420. $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH'];
  4421. }
  4422. if ($stringWidth==0) { $stringWidth = 0.000001; } // mPDF 5.0
  4423. if ($k == $arraysize-1) $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF , $currentx,0,0,'M', $fill, $af, $bf ); //mono-style line or last part (skips line)
  4424. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf );//first or middle part
  4425. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  4426. if (isset($spanfill) && $spanfill) {
  4427. $fill = $save_fill; $spanfill = 0;
  4428. if ($fill) { $this->SetFColor($bcor); } // mPDF 5.0.020
  4429. }
  4430. }
  4431. $this->printobjectbuffer($is_table, $blockdir); // mPDF 5.0.054
  4432. $this->objectbuffer = array();
  4433. $this->ResetSpacing();
  4434. /*-- LISTS --*/
  4435. // LIST BULLETS/NUMBERS
  4436. if ($is_list && is_array($this->bulletarray) && ($lineCount == 0) ) {
  4437. $savedFont = $this->saveFont();
  4438. $bull = $this->bulletarray;
  4439. // mPDF 5.1.018
  4440. if (is_array($bull['col'])) { $this->SetTColor($bull['col']); }
  4441. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  4442. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  4443. }
  4444. if (isset($bull['level']) && isset($bull['occur']) && isset($bull['num']) && isset($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) && $this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) { $this->restoreInlineProperties($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]); }
  4445. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4446. $this->bullet = true;
  4447. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  4448. }
  4449. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  4450. //Output bullet
  4451. $this->x = $currentx;
  4452. if (isset($bull['x'])) { $this->x += $bull['x']; }
  4453. $this->y -= $lineHeight;
  4454. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  4455. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4456. $this->bullet = false;
  4457. }
  4458. $this->x = $currentx; // Reset
  4459. $this->y += $lineHeight;
  4460. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4461. $this->restoreFont( $savedFont );
  4462. // $font = array( $savedFont );
  4463. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  4464. }
  4465. /*-- END LISTS --*/
  4466. } // END IF CONTENT
  4467. /*-- CSS-IMAGE-FLOAT --*/
  4468. // Update values if set to skipline
  4469. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  4470. if ($endofblock && $blockstate>1) {
  4471. // If float exists at this level
  4472. if (isset($this->floatmargins['R']['y1'])) { $fry1 = $this->floatmargins['R']['y1']; }
  4473. else { $fry1 = 0; }
  4474. if (isset($this->floatmargins['L']['y1'])) { $fly1 = $this->floatmargins['L']['y1']; }
  4475. else { $fly1 = 0; }
  4476. if ($this->y < $fry1 || $this->y < $fly1) {
  4477. $drop = max($fry1,$fly1) - $this->y;
  4478. $this->DivLn($drop);
  4479. $this->x = $currentx;
  4480. }
  4481. }
  4482. /*-- END CSS-IMAGE-FLOAT --*/
  4483. // PADDING and BORDER spacing/fill
  4484. if ($endofblock && ($blockstate > 1) && ($this->blk[$this->blklvl]['padding_bottom'] || $this->blk[$this->blklvl]['border_bottom'] || $this->blk[$this->blklvl]['css_set_height']) && (!$is_table) && (!$is_list)) {
  4485. // If CSS height set, extend bottom - if on same page as block started, and CSS HEIGHT > actual height,
  4486. // and does not force pagebreak
  4487. $extra = 0;
  4488. if ($this->blk[$this->blklvl]['css_set_height'] && $this->blk[$this->blklvl]['startpage']==$this->page) {
  4489. // predicted height
  4490. $h1 = ($this->y-$this->blk[$this->blklvl]['y0']) + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  4491. // mPDF 5.0.022
  4492. if ($h1 < ($this->blk[$this->blklvl]['css_set_height']+$this->blk[$this->blklvl]['padding_bottom']+$this->blk[$this->blklvl]['padding_top'])) { $extra = ($this->blk[$this->blklvl]['css_set_height']+$this->blk[$this->blklvl]['padding_bottom']+$this->blk[$this->blklvl]['padding_top']) - $h1; }
  4493. if($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra > $this->PageBreakTrigger) {
  4494. $extra = $this->PageBreakTrigger - ($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4495. }
  4496. }
  4497. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4498. $this->DivLn($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra,-3,true,false,2);
  4499. $this->x = $currentx;
  4500. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4501. }
  4502. // SET Bottom y1 of block (used for painting borders)
  4503. if (($endofblock) && ($blockstate > 1) && (!$is_table) && (!$is_list)) {
  4504. $this->blk[$this->blklvl]['y1'] = $this->y;
  4505. }
  4506. // BOTTOM MARGIN
  4507. if (($endofblock) && ($blockstate > 1) && ($this->blk[$this->blklvl]['margin_bottom']) && (!$is_table) && (!$is_list)) {
  4508. if($this->y+$this->blk[$this->blklvl]['margin_bottom'] < $this->PageBreakTrigger and !$this->InFooter) {
  4509. $this->DivLn($this->blk[$this->blklvl]['margin_bottom'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4510. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4511. }
  4512. }
  4513. // Reset lineheight
  4514. $lineHeight = $this->divheight;
  4515. }
  4516. function printobjectbuffer($is_table=false, $blockdir=false) {
  4517. // mPDF 5.0.054
  4518. if (!$blockdir) { $blockdir = $this->directionality; }
  4519. if ($is_table && $this->shrin_k > 1) { $k = $this->shrin_k; }
  4520. else { $k = 1; }
  4521. $save_y = $this->y;
  4522. $save_x = $this->x;
  4523. $save_currentfontfamily = $this->FontFamily;
  4524. $save_currentfontsize = $this->FontSizePt;
  4525. $save_currentfontstyle = $this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  4526. // mPDF 5.0.054
  4527. if ($blockdir == 'rtl') { $rtlalign = 'R'; } else { $rtlalign = 'L'; }
  4528. foreach ($this->objectbuffer AS $ib => $objattr) {
  4529. if ($objattr['type'] == 'bookmark' || $objattr['type'] == 'indexentry' || $objattr['type'] == 'toc') {
  4530. $x = $objattr['OUTER-X'];
  4531. $y = $objattr['OUTER-Y'];
  4532. $this->y = $y - $this->FontSize/2;
  4533. $this->x = $x;
  4534. if ($objattr['type'] == 'bookmark' ) { $this->Bookmark($objattr['CONTENT'],$objattr['bklevel'] ,$y - $this->FontSize); } // *BOOKMARKS*
  4535. if ($objattr['type'] == 'indexentry') { $this->IndexEntry($objattr['CONTENT']); } // *INDEX*
  4536. if ($objattr['type'] == 'toc') { $this->TOC_Entry($objattr['CONTENT'], $objattr['toclevel'], $objattr['toc_id']); } // *TOC*
  4537. }
  4538. /*-- ANNOTATIONS --*/
  4539. else if ($objattr['type'] == 'annot') {
  4540. if ($objattr['POS-X']) { $x = $objattr['POS-X']; }
  4541. else if ($this->annotMargin<>0) { $x = -$objattr['OUTER-X']; }
  4542. else { $x = $objattr['OUTER-X']; }
  4543. if ($objattr['POS-Y']) { $y = $objattr['POS-Y']; }
  4544. else { $y = $objattr['OUTER-Y'] - $this->FontSize/2; }
  4545. // Create a dummy entry in the _out/columnBuffer with position sensitive data,
  4546. // linking $y-1 in the Columnbuffer with entry in $this->columnAnnots
  4547. // and when columns are split in length will not break annotation from current line
  4548. $this->y = $y-1;
  4549. $this->x = $x-1;
  4550. $this->Line($x-1,$y-1,$x-1,$y-1);
  4551. $this->Annotation($objattr['CONTENT'], $x , $y , $objattr['ICON'], $objattr['AUTHOR'], $objattr['SUBJECT'], $objattr['OPACITY'], $objattr['COLOR'], $objattr['POPUP'], $objattr['FILE']); // mPDF 5.0.048
  4552. }
  4553. /*-- END ANNOTATIONS --*/
  4554. else {
  4555. $y = $objattr['OUTER-Y'];
  4556. $x = $objattr['OUTER-X'];
  4557. $w = $objattr['OUTER-WIDTH'];
  4558. $h = $objattr['OUTER-HEIGHT'];
  4559. if (isset($objattr['text'])) { $texto = $objattr['text']; }
  4560. $this->y = $y;
  4561. $this->x = $x;
  4562. if (isset($objattr['fontfamily'])) { $this->SetFont($objattr['fontfamily'],'',$objattr['fontsize'] ); }
  4563. }
  4564. // HR
  4565. if ($objattr['type'] == 'hr') {
  4566. $this->SetDColor($objattr['color']); // mPDF 5.0.020
  4567. switch($objattr['align']) {
  4568. case 'C':
  4569. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4570. $empty /= 2;
  4571. $x += $empty;
  4572. break;
  4573. case 'R':
  4574. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4575. $x += $empty;
  4576. break;
  4577. }
  4578. $oldlinewidth = $this->LineWidth;
  4579. $this->SetLineWidth($objattr['linewidth']/$k );
  4580. $this->y += ($objattr['linewidth']/2) + $objattr['margin_top']/$k;
  4581. $this->Line($x,$this->y,$x+$objattr['INNER-WIDTH'],$this->y);
  4582. $this->SetLineWidth($oldlinewidth);
  4583. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  4584. }
  4585. // IMAGE
  4586. if ($objattr['type'] == 'image') {
  4587. if (isset($objattr['opacity'])) { $this->SetAlpha($objattr['opacity']); }
  4588. $rotate = 0;
  4589. $obiw = $objattr['INNER-WIDTH'];
  4590. $obih = $objattr['INNER-HEIGHT'];
  4591. $sx = $objattr['INNER-WIDTH']*$this->k / $objattr['orig_w'];
  4592. $sy = abs($objattr['INNER-HEIGHT'])*$this->k / abs($objattr['orig_h']);
  4593. $sx = ($objattr['INNER-WIDTH']*$this->k / $objattr['orig_w']);
  4594. $sy = ($objattr['INNER-HEIGHT']*$this->k / $objattr['orig_h']);
  4595. if (isset($objattr['ROTATE'])) { $rotate = $objattr['ROTATE']; }
  4596. if ($rotate==90) {
  4597. // Clockwise
  4598. $obiw = $objattr['INNER-HEIGHT'];
  4599. $obih = $objattr['INNER-WIDTH'];
  4600. $tr = $this->transformTranslate(0, -$objattr['INNER-WIDTH'], true) ;
  4601. $tr .= ' '. $this->transformRotate(90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4602. $sx = $obiw*$this->k / $objattr['orig_h'];
  4603. $sy = $obih*$this->k / $objattr['orig_w'];
  4604. }
  4605. // mPDF 5.0.032
  4606. else if ($rotate==-90 || $rotate==270) {
  4607. // AntiClockwise
  4608. $obiw = $objattr['INNER-HEIGHT'];
  4609. $obih = $objattr['INNER-WIDTH'];
  4610. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], ($objattr['INNER-HEIGHT']-$objattr['INNER-WIDTH']), true) ;
  4611. $tr .= ' '. $this->transformRotate(-90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4612. $sx = $obiw*$this->k / $objattr['orig_h'];
  4613. $sy = $obih*$this->k / $objattr['orig_w'];
  4614. }
  4615. else if ($rotate==180) {
  4616. // Mirror
  4617. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], -$objattr['INNER-HEIGHT'], true) ;
  4618. $tr .= ' '. $this->transformRotate(180, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ),true) ;
  4619. }
  4620. else { $tr = ''; }
  4621. $tr = trim($tr);
  4622. if ($tr) { $tr .= ' '; }
  4623. $gradmask = '';
  4624. /*-- BACKGROUNDS --*/
  4625. // mPDF 5.0.033
  4626. if (isset($objattr['GRADIENT-MASK'])) {
  4627. $g = $this->parseMozGradient( $objattr['GRADIENT-MASK'] );
  4628. if ($g) {
  4629. $dummy = $this->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true, true);
  4630. $gradmask = '/TGS'.count($this->gradients).' gs ';
  4631. // $this->_out("q ".$tr.$this->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true)." Q");
  4632. }
  4633. }
  4634. /*-- END BACKGROUNDS --*/
  4635. /*-- IMAGES-WMF --*/
  4636. if (isset($objattr['itype']) && $objattr['itype']=='wmf') {
  4637. $outstring = sprintf('q '.$tr.'%.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*$this->k-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*$this->k)+$sy*$objattr['wmf_y'], $objattr['ID']);
  4638. }
  4639. else
  4640. /*-- END IMAGES-WMF --*/
  4641. if (isset($objattr['itype']) && $objattr['itype']=='svg') {
  4642. $outstring = sprintf('q '.$tr.'%.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*$this->k-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*$this->k)+$sy*$objattr['wmf_y'], $objattr['ID']);
  4643. }
  4644. else {
  4645. $outstring = sprintf("q ".$tr."%.3f 0 0 %.3f %.3f %.3f cm ".$gradmask."/I%d Do Q",$obiw*$this->k, $obih*$this->k, $objattr['INNER-X'] *$this->k, ($this->h-($objattr['INNER-Y'] +$obih ))*$this->k,$objattr['ID'] ); // mPDF 5.0.033
  4646. }
  4647. $this->_out($outstring);
  4648. // LINK
  4649. if (isset($objattr['link'])) $this->Link($objattr['INNER-X'],$objattr['INNER-Y'],$objattr['INNER-WIDTH'],$objattr['INNER-HEIGHT'],$objattr['link']);
  4650. if (isset($objattr['opacity'])) { $this->SetAlpha(1); }
  4651. // mPDF 5.0.027
  4652. if ((isset($objattr['border_top']) && $objattr['border_top']>0) || (isset($objattr['border_left']) && $objattr['border_left']>0) || (isset($objattr['border_right']) && $objattr['border_right']>0) || (isset($objattr['border_bottom']) && $objattr['border_bottom']>0)) { $this->PaintImgBorder($objattr,$is_table); }
  4653. }
  4654. /*-- BARCODES --*/
  4655. // BARCODE
  4656. if ($objattr['type'] == 'barcode') {
  4657. $bgcol = $this->ConvertColor(255); // mPDF 5.0.051
  4658. if (isset($objattr['bgcolor']) && is_array($objattr['bgcolor'])) {
  4659. $bgcol = $objattr['bgcolor'];
  4660. }
  4661. $col = $this->ConvertColor(0); // mPDF 5.0.051
  4662. if (isset($objattr['color']) && is_array($objattr['color'])) {
  4663. $col = $objattr['color'];
  4664. }
  4665. $this->SetFColor($bgcol); // mPDF 5.0.051
  4666. $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
  4667. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  4668. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4669. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  4670. $this->WriteBarcode($objattr['code'], $objattr['showtext'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], 0, 0, 0, 0, 0, $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['bsupp'], $objattr['bsupp_code'], $k);
  4671. }
  4672. // mPDF 5.0 QR-code
  4673. else if ($objattr['btype']=='QR') {
  4674. if (!class_exists('QRcode', false)) {
  4675. include(_MPDF_PATH.'qrcode/qrcode.class.php');
  4676. }
  4677. $this->qrcode = new QRcode($objattr['code'], $objattr['errorlevel']); // mPDF 5.1.010
  4678. // mPDF 5.1.019
  4679. // $this->qrcode->displayFPDF($this, $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize']*25, array($bgcol[1],$bgcol[2],$bgcol[3]), array($col[1],$col[2],$col[3])); // mPDF 5.0.051
  4680. $this->qrcode->displayFPDF($this, $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize']*25, array(255,255,255), array(0,0,0)); // mPDF 5.1.019
  4681. }
  4682. else {
  4683. $this->WriteBarcode2($objattr['code'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k);
  4684. }
  4685. }
  4686. /*-- END BARCODES --*/
  4687. $this->ResetSpacing();
  4688. // DOT-TAB
  4689. if ($objattr['type'] == 'dottab') {
  4690. $sp = $this->GetStringWidth(' ');
  4691. $nb=floor(($w-2*$sp)/$this->GetStringWidth('.'));
  4692. if ($nb>0) { $dots=' '.str_repeat('.',$nb).' '; }
  4693. else { $dots=' '; }
  4694. // mPDF 5.0.037
  4695. $col = $this->ConvertColor(0); // mPDF 5.0.051
  4696. if (isset($objattr['colorarray']) && is_array($objattr['colorarray'])) {
  4697. $col = $objattr['colorarray'];
  4698. }
  4699. $this->SetTColor($col); // mPDF 5.0.051
  4700. $this->Cell($w,$h,$dots,0,0,'C');
  4701. // mPDF 5.0
  4702. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4703. }
  4704. /*-- FORMS --*/
  4705. // TEXT/PASSWORD INPUT
  4706. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD')) {
  4707. $w -= $this->form_element_spacing['input']['outer']['h']*2 /$k;
  4708. $h -= $this->form_element_spacing['input']['outer']['v']*2 /$k;
  4709. $this->x += $this->form_element_spacing['input']['outer']['h'] /$k;
  4710. $this->y += $this->form_element_spacing['input']['outer']['v'] /$k;
  4711. // Chop texto to max length $w-inner-padding
  4712. while ($this->GetStringWidth($texto) > $w-($this->form_element_spacing['input']['inner']['h']*2)) {
  4713. $texto = mb_substr($texto,0,mb_strlen($texto,$this->mb_enc)-1,$this->mb_enc);
  4714. }
  4715. // DIRECTIONALITY
  4716. $this->SetLineWidth(0.2 /$k );
  4717. // mPDF 5.0.054
  4718. $this->magic_reverse_dir($texto, false, $blockdir); // *RTL*
  4719. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4720. $this->SetFColor($this->ConvertColor(225)); // mPDF 5.0.051
  4721. $this->SetTColor($this->ConvertColor(127)); // mPDF 5.0.051
  4722. }
  4723. else if (isset($objattr['readonly']) && $objattr['readonly']) {
  4724. $this->SetFColor($this->ConvertColor(225)); // mPDF 5.0.051
  4725. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4726. }
  4727. else {
  4728. $this->SetFColor($this->ConvertColor(250)); // mPDF 5.0.051
  4729. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4730. }
  4731. $this->Cell($w,$h,$texto,1,0,$rtlalign,1,'',0,$this->form_element_spacing['input']['inner']['h'] /$k ,$this->form_element_spacing['input']['inner']['h'] /$k , 'M');
  4732. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  4733. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4734. }
  4735. // SELECT
  4736. if ($objattr['type'] == 'select') {
  4737. // DIRECTIONALITY
  4738. // mPDF 5.0.054
  4739. $this->magic_reverse_dir($texto, false, $blockdir); // *RTL*
  4740. $this->SetLineWidth(0.2 /$k );
  4741. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4742. $this->SetFColor($this->ConvertColor(225)); // mPDF 5.0.051
  4743. $this->SetTColor($this->ConvertColor(127)); // mPDF 5.0.051
  4744. }
  4745. else {
  4746. $this->SetFColor($this->ConvertColor(250)); // mPDF 5.0.051
  4747. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4748. }
  4749. $w -= $this->form_element_spacing['select']['outer']['h']*2 /$k ;
  4750. $h -= $this->form_element_spacing['select']['outer']['v']*2 /$k ;
  4751. $this->x += $this->form_element_spacing['select']['outer']['h'] /$k ;
  4752. $this->y += $this->form_element_spacing['select']['outer']['v'] /$k ;
  4753. $this->Cell($w-($this->FontSize*1.4),$h,$texto,1,0,$rtlalign,1,'',0,$this->form_element_spacing['select']['inner']['h'] /$k,$this->form_element_spacing['select']['inner']['h'] /$k , 'M') ;
  4754. $this->SetFColor($this->ConvertColor(190)); // mPDF 5.0.051
  4755. $save_font = $this->FontFamily;
  4756. $save_currentfont = $this->currentfontfamily;
  4757. if ($this->PDFA || $this->PDFX) {
  4758. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Core Adobe font Zapfdingbats cannot be embedded in mPDF - used in Form element: Select - which is required for PDFA1-b or PDFX/1-a. (Different character/font will be substituted.)"; }
  4759. $this->SetFont('sans');
  4760. if ($this->_charDefined($this->CurrentFont['cw'], 9660)) { $down = "\xe2\x96\xbc"; } // mPDF 5.1.003
  4761. else { $down = '='; }
  4762. $this->Cell(($this->FontSize*1.4),$h,$down,1,0,'C',1,'',0,0,0, 'M') ;
  4763. }
  4764. else {
  4765. $this->SetFont('czapfdingbats','',0);
  4766. $this->Cell(($this->FontSize*1.4),$h,$this->chrs[116],1,0,'C',1,'',0,0,0, 'M') ;
  4767. }
  4768. $this->SetFont($save_font,'',0);
  4769. $this->currentfontfamily = $save_currentfont;
  4770. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  4771. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4772. }
  4773. // INPUT/BUTTON as IMAGE
  4774. if ($objattr['type'] == 'input' && $objattr['subtype'] == 'IMAGE') {
  4775. $this->y = $objattr['INNER-Y'];
  4776. $this->_out( sprintf("q %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q",$objattr['INNER-WIDTH'] *$this->k,$objattr['INNER-HEIGHT'] *$this->k,$objattr['INNER-X'] *$this->k,($this->h-($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ))*$this->k,$objattr['ID'] ) );
  4777. if (isset($objattr['BORDER-WIDTH']) && $objattr['BORDER-WIDTH']) { $this->PaintImgBorder($objattr,$is_table); }
  4778. }
  4779. // BUTTON
  4780. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'SUBMIT' || $objattr['subtype'] == 'RESET' || $objattr['subtype'] == 'BUTTON')) {
  4781. $this->SetLineWidth(0.2 /$k );
  4782. $this->SetFColor($this->ConvertColor(190)); // mPDF 5.0.051
  4783. $w -= $this->form_element_spacing['button']['outer']['h']*2 /$k ;
  4784. $h -= $this->form_element_spacing['button']['outer']['v']*2 /$k ;
  4785. $this->x += $this->form_element_spacing['button']['outer']['h'] /$k ;
  4786. $this->y += $this->form_element_spacing['button']['outer']['v'] /$k ;
  4787. $this->RoundedRect($this->x, $this->y, $w, $h, 0.5 /$k , 'DF');
  4788. $w -= $this->form_element_spacing['button']['inner']['h']*2 /$k ;
  4789. $h -= $this->form_element_spacing['button']['inner']['v']*2 /$k ;
  4790. $this->x += $this->form_element_spacing['button']['inner']['h'] /$k ;
  4791. $this->y += $this->form_element_spacing['button']['inner']['v'] /$k ;
  4792. // mPDF 5.0.054
  4793. $this->magic_reverse_dir($texto, false, $blockdir); // *RTL*
  4794. $this->Cell($w,$h,$texto,'',0,'C',0,'',0,0,0, 'M') ;
  4795. $this->SetFColor($this->ConvertColor(0)); // mPDF 5.0.051
  4796. }
  4797. // TEXTAREA
  4798. if ($objattr['type'] == 'textarea') {
  4799. $w -= $this->form_element_spacing['textarea']['outer']['h']*2 /$k ;
  4800. $h -= $this->form_element_spacing['textarea']['outer']['v']*2 /$k ;
  4801. $this->x += $this->form_element_spacing['textarea']['outer']['h'] /$k ;
  4802. $this->y += $this->form_element_spacing['textarea']['outer']['v'] /$k ;
  4803. $this->SetLineWidth(0.2 /$k );
  4804. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4805. $this->SetFColor($this->ConvertColor(225)); // mPDF 5.0.051
  4806. $this->SetTColor($this->ConvertColor(127)); // mPDF 5.0.051
  4807. }
  4808. else if (isset($objattr['readonly']) && $objattr['readonly']) {
  4809. $this->SetFColor($this->ConvertColor(225)); // mPDF 5.0.051
  4810. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4811. }
  4812. else {
  4813. $this->SetFColor($this->ConvertColor(250)); // mPDF 5.0.051
  4814. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4815. }
  4816. $this->Rect($this->x,$this->y,$w,$h,'DF');
  4817. $w -= $this->form_element_spacing['textarea']['inner']['h']*2 /$k ;
  4818. $this->x += $this->form_element_spacing['textarea']['inner']['h'] /$k ;
  4819. $this->y += $this->form_element_spacing['textarea']['inner']['v'] /$k ;
  4820. $linesneeded = $this->WordWrap($texto,$w);
  4821. if ($linesneeded > $objattr['rows']) { //Too many words inside textarea
  4822. $textoaux = explode("\n",$texto);
  4823. $texto = '';
  4824. for($i=0;$i<$objattr['rows'];$i++) {
  4825. if ($i == ($objattr['rows']-1)) $texto .= $textoaux[$i];
  4826. else $texto .= $textoaux[$i] . "\n";
  4827. }
  4828. $texto = mb_substr($texto,0,mb_strlen($texto,$this->mb_enc)-4,$this->mb_enc) . "...";
  4829. }
  4830. // mPDF 5.0.054
  4831. if ($texto != '') $this->MultiCell($w,$this->FontSize*$this->textarea_lineheight,$texto,0,'',0,'',$blockdir,true);
  4832. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  4833. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  4834. }
  4835. // CHECKBOX
  4836. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'CHECKBOX')) {
  4837. $iw = $w * 0.7;
  4838. $ih = $h * 0.7;
  4839. $lx = $x + (($w-$iw)/2);
  4840. $ty = $y + (($h-$ih)/2);
  4841. $rx = $lx + $iw;
  4842. $by = $ty + $ih;
  4843. $this->SetLineWidth(0.2 /$k );
  4844. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4845. $this->SetFColor($this->ConvertColor(225)); // mPDF 5.0.051
  4846. $this->SetDColor($this->ConvertColor(127)); // mPDF 5.0.051
  4847. }
  4848. else {
  4849. $this->SetFColor($this->ConvertColor(250)); // mPDF 5.0.051
  4850. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  4851. }
  4852. $this->Rect($lx,$ty,$iw,$ih,'DF');
  4853. if (isset($objattr['checked']) && $objattr['checked']) {
  4854. //Round join and cap
  4855. $this->SetLineCap(1); // mPDF 5.0.051 n J
  4856. $this->Line($lx,$ty,$rx,$by);
  4857. $this->Line($lx,$by,$rx,$ty);
  4858. //Set line cap style back to square
  4859. $this->SetLineCap(2); // mPDF 5.0.051 n J
  4860. }
  4861. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  4862. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  4863. }
  4864. // RADIO
  4865. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'RADIO')) {
  4866. $this->SetLineWidth(0.2 /$k );
  4867. $radius = $this->FontSize *0.35;
  4868. $cx = $x + ($w/2);
  4869. $cy = $y + ($h/2);
  4870. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4871. $this->SetFColor($this->ConvertColor(127)); // mPDF 5.0.051
  4872. $this->SetDColor($this->ConvertColor(127)); // mPDF 5.0.051
  4873. }
  4874. else {
  4875. $this->SetFColor($this->ConvertColor(0)); // mPDF 5.0.051
  4876. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  4877. }
  4878. $this->Circle($cx,$cy,$radius,'D');
  4879. if (isset($objattr['checked']) && $objattr['checked']) {
  4880. $this->Circle($cx,$cy,$radius*0.4,'DF');
  4881. }
  4882. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  4883. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  4884. }
  4885. /*-- END FORMS --*/
  4886. }
  4887. $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize);
  4888. $this->y = $save_y;
  4889. $this->x = $save_x;
  4890. unset($content);
  4891. }
  4892. function WriteFlowingBlock( $s)
  4893. {
  4894. $currentx = $this->x;
  4895. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  4896. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  4897. // width of all the content so far in points
  4898. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  4899. // cell width in points
  4900. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  4901. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  4902. // line height in user units
  4903. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  4904. $align =& $this->flowingBlockAttr[ 'align' ];
  4905. $content =& $this->flowingBlockAttr[ 'content' ];
  4906. $font =& $this->flowingBlockAttr[ 'font' ];
  4907. $valign =& $this->flowingBlockAttr[ 'valign' ];
  4908. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  4909. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  4910. // mPDF 5.0.054
  4911. $blockdir = $this->flowingBlockAttr['blockdir'];
  4912. // *********** BLOCK BACKGROUND COLOR ***************** //
  4913. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  4914. $fill = 0;
  4915. // $fill = 1;
  4916. // $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  4917. // $this->SetFColor($bcor);
  4918. }
  4919. else {
  4920. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  4921. $fill = 0;
  4922. }
  4923. $font[] = $this->saveFont();
  4924. $content[] = '';
  4925. $currContent =& $content[ count( $content ) - 1 ];
  4926. // where the line should be cutoff if it is to be justified
  4927. $cutoffWidth = $contentWidth;
  4928. $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  4929. $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  4930. $CJKoverflow = false; // mPDF 5.1.009
  4931. // COLS
  4932. $oldcolumn = $this->CurrCol;
  4933. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4934. /*-- TABLES --*/
  4935. if ($is_table) {
  4936. $ipaddingL = 0;
  4937. $ipaddingR = 0;
  4938. $paddingL = 0;
  4939. $paddingR = 0;
  4940. $cpaddingadjustL = 0;
  4941. $cpaddingadjustR = 0;
  4942. // Added mPDF 3.0
  4943. $fpaddingR = 0;
  4944. $fpaddingL = 0;
  4945. }
  4946. else {
  4947. /*-- END TABLES --*/
  4948. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4949. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4950. $paddingL = ($ipaddingL * $this->k);
  4951. $paddingR = ($ipaddingR * $this->k);
  4952. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4953. $cpaddingadjustL = -$this->cMarginL;
  4954. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4955. $cpaddingadjustR = -$this->cMarginR;
  4956. // Added mPDF 3.0 Float DIV
  4957. $fpaddingR = 0;
  4958. $fpaddingL = 0;
  4959. /*-- CSS-FLOAT --*/
  4960. if (count($this->floatDivs)) {
  4961. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4962. if ($r_exists) { $fpaddingR = $r_width; }
  4963. if ($l_exists) { $fpaddingL = $l_width; }
  4964. }
  4965. /*-- END CSS-FLOAT --*/
  4966. $usey = $this->y + 0.002;
  4967. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4968. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4969. }
  4970. /*-- CSS-IMAGE-FLOAT --*/
  4971. // If float exists at this level
  4972. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4973. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4974. /*-- END CSS-IMAGE-FLOAT --*/
  4975. } // *TABLES*
  4976. //OBJECTS - IMAGES & FORM Elements (NB has already skipped line/page if required - in printbuffer)
  4977. if (substr($s,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  4978. $objattr = $this->_getObjAttr($s);
  4979. $h_corr = 0;
  4980. if ($is_table) { // *TABLES*
  4981. $maximumW = ($maxWidth/$this->k) - ($this->cellPaddingL + $this->cMarginL + $this->cellPaddingR + $this->cMarginR); // *TABLES*
  4982. } // *TABLES*
  4983. else { // *TABLES*
  4984. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) && (!$is_table)) { $h_corr = $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; }
  4985. $maximumW = ($maxWidth/$this->k) - ($this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_right'] + $this->blk[$this->blklvl]['border_right']['w'] + $fpaddingL + $fpaddingR );
  4986. } // *TABLES*
  4987. $objattr = $this->inlineObject($objattr['type'],$this->lMargin + $fpaddingL + ($contentWidth/$this->k),($this->y + $h_corr), $objattr, $this->lMargin,($contentWidth/$this->k),$maximumW,$lineHeight,true,$is_table);
  4988. // SET LINEHEIGHT for this line ================ RESET AT END
  4989. $lineHeight = MAX($lineHeight,$objattr['OUTER-HEIGHT']);
  4990. $this->objectbuffer[count($content)-1] = $objattr;
  4991. // if (isset($objattr['vertical-align'])) { $valign = $objattr['vertical-align']; }
  4992. // else { $valign = ''; }
  4993. $contentWidth += ($objattr['OUTER-WIDTH'] * $this->k);
  4994. return;
  4995. }
  4996. if ($this->usingCoreFont) {
  4997. $tmp = strlen( $s );
  4998. }
  4999. else {
  5000. $tmp = mb_strlen( $s, $this->mb_enc );
  5001. }
  5002. $orphs = 0;
  5003. $check = 0;
  5004. // for every character in the string
  5005. for ( $i = 0; $i < $tmp; $i++ ) {
  5006. // extract the current character
  5007. // get the width of the character in points
  5008. if ($this->usingCoreFont) {
  5009. $c = $s[$i];
  5010. // Soft Hyphens chr(173)
  5011. if ($c == chr(173) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) { $cw = 0; }
  5012. else {
  5013. $cw = ($this->GetStringWidth($c) * $this->k); // mPDF 5.0.063 (so adjust for letter/word spacing)
  5014. // mPDF 5.0.061/ 5.0.063
  5015. if ($this->kerning && $this->useKerning && $i > 0) {
  5016. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$c])) {
  5017. $cw += ($this->CurrentFont['kerninfo'][$s[($i-1)]][$c] * $this->FontSizePt / 1000 );
  5018. }
  5019. }
  5020. }
  5021. }
  5022. else {
  5023. $c = mb_substr($s,$i,1,$this->mb_enc );
  5024. $cw = ($this->GetStringWidth($c) * $this->k);
  5025. // mPDF 5.0.061
  5026. if ($this->kerning && $this->useKerning && $i > 0) {
  5027. $lastc = mb_substr($s,($i-1),1,$this->mb_enc );
  5028. $ulastc = $this->UTF8StringToArray($lastc, false);
  5029. $uc = $this->UTF8StringToArray($c, false);
  5030. if (isset($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]])) {
  5031. $cw += ($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]] * $this->FontSizePt / 1000 );
  5032. }
  5033. }
  5034. }
  5035. if ($c==' ') { $check = 1; }
  5036. // CHECK for ORPHANS
  5037. // mPDF 5.0 Added "]"
  5038. // mPDF 5.1.009
  5039. else if ($c=='.' || $c==',' || $c==')' || $c==']' || $c==';' || $c==':' || $c=='!' || $c=='?'|| $c=='"' || $c==$curlyquote || $c==$curlylowquote || (!$is_table && $this->CJKfollowing && preg_match("/[".$this->CJKfollowing."]/u", $c)) || ($is_table && preg_match("/[".$this->CJKoverflow ."]/u", $c))) {$check++; }
  5040. else { $check = 0; }
  5041. // There's an orphan '. ' or ', ' or <sup>32</sup> about to be cut off at the end of line
  5042. if($check==1) {
  5043. $currContent .= $c;
  5044. $cutoffWidth = $contentWidth;
  5045. $contentWidth += $cw;
  5046. continue;
  5047. }
  5048. if(($this->SUP || $this->SUB) && ($orphs < $this->orphansAllowed)) { // ? disable orphans in table if borders used
  5049. $currContent .= $c;
  5050. $cutoffWidth = $contentWidth;
  5051. $contentWidth += $cw;
  5052. $orphs++;
  5053. continue;
  5054. }
  5055. else { $orphs = 0; }
  5056. // ADDED for Paragraph_indent
  5057. $WidthCorrection = 0;
  5058. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  5059. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5060. $WidthCorrection = ($ti*$this->k);
  5061. }
  5062. // Added mPDF 3.0 Float DIV
  5063. $fpaddingR = 0;
  5064. $fpaddingL = 0;
  5065. /*-- CSS-FLOAT --*/
  5066. if (count($this->floatDivs)) {
  5067. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  5068. if ($r_exists) { $fpaddingR = $r_width; }
  5069. if ($l_exists) { $fpaddingL = $l_width; }
  5070. }
  5071. /*-- END CSS-FLOAT --*/
  5072. $usey = $this->y + 0.002;
  5073. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  5074. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  5075. }
  5076. /*-- CSS-IMAGE-FLOAT --*/
  5077. // If float exists at this level
  5078. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  5079. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  5080. /*-- END CSS-IMAGE-FLOAT --*/
  5081. // try adding another char
  5082. if (( $contentWidth + $cw > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) + 0.001)) {// 0.001 is to correct for deviations converting mm=>pts
  5083. // it won't fit, output what we already have
  5084. $lineCount++;
  5085. // contains any content that didn't make it into this print
  5086. $savedContent = '';
  5087. $savedFont = array();
  5088. $savedObj = array();
  5089. // cut off and save any partial words at the end of the string
  5090. $words = explode( ' ', $currContent );
  5091. ///////////////////
  5092. // HYPHENATION
  5093. $currWord = $words[count($words)-1] ;
  5094. $success = false;
  5095. /*-- HYPHENATION --*/
  5096. // Soft Hyphens chr(173)
  5097. if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$currWord)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$currWord) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) {
  5098. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) );
  5099. list($success,$pre,$post,$prelength) = $this->softHyphenate($currWord, (($rem-$cutoffWidth)/$this->k -$this->GetStringWidth(" ")) );
  5100. }
  5101. if (!$success && ($this->hyphenate || ($this->hyphenateTables && $is_table))) {
  5102. // Look ahead to get current word
  5103. for($ac = $i; $ac<(mb_strlen($s)-1); $ac++) {
  5104. $addc = mb_substr($s,$ac,1,$this->mb_enc );
  5105. if ($addc == ' ') { break; }
  5106. $currWord .= $addc;
  5107. }
  5108. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) );
  5109. list($success,$pre,$post,$prelength) = $this->hyphenateWord($currWord, (($rem-$cutoffWidth)/$this->k -$this->GetStringWidth(" ")) );
  5110. }
  5111. if ($success) {
  5112. $already = array_pop( $words );
  5113. $forward = mb_substr($already,$prelength,mb_strlen($already, $this->mb_enc), $this->mb_enc);
  5114. $words[] = $pre.'-';
  5115. $words[] = $forward;
  5116. $currContent = mb_substr($currContent,0,mb_strlen($currContent, $this->mb_enc)+1-mb_strlen($post, $this->mb_enc), $this->mb_enc) . '-';
  5117. }
  5118. /*-- END HYPHENATION --*/
  5119. // if it looks like we didn't finish any words for this chunk
  5120. if ( count( $words ) == 1 ) {
  5121. // TO correct for error when word too wide for page - but only when one long word from left to right margin
  5122. if (count($content) == 1 && $currContent != ' ') {
  5123. /////////////////////////////////////////////////////////////////////////////////////
  5124. // mPDF 5.1.009
  5125. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5126. // Last character that fits is not allowed to end a line - move lastchar(s) to start of next line
  5127. if (!$is_table && $this->checkCJK && preg_match("/[".$this->CJKleading."]/u", $lastchar)) {
  5128. //move lastchar(s) to next line
  5129. $m0 = $lastchar;
  5130. $m1 = $c;
  5131. while(preg_match("/[".$this->CJKleading."]/u", $m0) && mb_strlen($words[0], $this->mb_enc)>2) {
  5132. // trim last letter off word[0]
  5133. $words[0] = mb_substr($words[0],0,mb_strlen($words[0], $this->mb_enc)-1, $this->mb_enc);
  5134. // and add it to savedContent for next line
  5135. $savedContent = $m0.$savedContent;
  5136. $m1 = $lastchar;
  5137. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5138. $m0 = $lastchar;
  5139. }
  5140. $lastContent = $words[0];
  5141. $savedFont = $this->saveFont();
  5142. // replace the current content with the cropped version
  5143. $currContent = rtrim( $lastContent );
  5144. }
  5145. // Next character is not allowed to start a new line - move lastchar(s) to next line
  5146. else if (!$is_table && $this->checkCJK && preg_match("/[".$this->CJKfollowing."]/u", $c)) {
  5147. // try squeezing another character(s) onto this line = Oikomi
  5148. if ($this->allowCJKorphans) {
  5149. $lookahead = mb_substr($s,$i+1,1,$this->mb_enc );
  5150. //if lookahead is not another following char
  5151. if ($lookahead && !preg_match("/[".$this->CJKfollowing."]/u", $lookahead)) {
  5152. $currContent .= $c;
  5153. $cutoffWidth = $contentWidth;
  5154. $contentWidth += $cw;
  5155. if ($this->allowCJKoverflow && !$is_table && preg_match("/[".$this->CJKoverflow."]/u", $c)) { $CJKoverflow = true; }
  5156. continue;
  5157. }
  5158. }
  5159. // or move lastchar(s) to next line to keep $c company = Oidashi
  5160. $m0 = $lastchar;
  5161. $m1 = $c;
  5162. while(preg_match("/[".$this->CJKfollowing."]/u", $m1) && mb_strlen($words[0], $this->mb_enc)>2) {
  5163. // trim last letter off word[0]
  5164. $words[0] = mb_substr($words[0],0,mb_strlen($words[0], $this->mb_enc)-1, $this->mb_enc);
  5165. // and add it to savedContent for next line
  5166. $savedContent = $m0.$savedContent;
  5167. $m1 = $lastchar;
  5168. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5169. $m0 = $lastchar;
  5170. }
  5171. $lastContent = $words[0];
  5172. $savedFont = $this->saveFont();
  5173. // replace the current content with the cropped version
  5174. $currContent = rtrim( $lastContent );
  5175. }
  5176. else {
  5177. /////////////////////////////////////////////////////////////////////////////////////
  5178. $lastContent = $words[0];
  5179. $savedFont = $this->saveFont();
  5180. // replace the current content with the cropped version
  5181. $currContent = rtrim( $lastContent );
  5182. /////////////////////////////////////////////////////////////////////////////////////
  5183. }
  5184. /////////////////////////////////////////////////////////////////////////////////////
  5185. }
  5186. else {
  5187. // save and crop off the content currently on the stack
  5188. $savedContent = array_pop( $content );
  5189. $savedFont = array_pop( $font );
  5190. // trim any trailing spaces off the last bit of content
  5191. $currContent =& $content[ count( $content ) - 1 ];
  5192. $currContent = rtrim( $currContent );
  5193. }
  5194. }
  5195. else { // otherwise, we need to find which bit to cut off
  5196. $lastContent = '';
  5197. for ( $w = 0; $w < count( $words ) - 1; $w++) { $lastContent .= $words[ $w ]." "; }
  5198. $savedContent = $words[ count( $words ) - 1 ];
  5199. $savedFont = $this->saveFont();
  5200. // replace the current content with the cropped version
  5201. $currContent = rtrim( $lastContent );
  5202. }
  5203. // mPDF 5.0.071
  5204. // CJK - strip CJK space at end of line
  5205. // &#x3000; = \xe3\x80\x80 = CJK space
  5206. if ($this->checkCJK) { $currContent = preg_replace("/\xe3\x80\x80$/",'',$currContent) ; } // *CJK*
  5207. if (isset($this->objectbuffer[(count($content)-1)]) && $this->objectbuffer[(count($content)-1)]['type']=='dottab') {
  5208. $savedObj = array_pop( $this->objectbuffer );
  5209. $contentWidth -= ($this->objectbuffer[(count($content)-1)]['OUTER-WIDTH'] * $this->k);
  5210. }
  5211. // Set Current lineheight (correction factor)
  5212. $lhfixed = false;
  5213. /*-- LISTS --*/
  5214. if ($is_list) {
  5215. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  5216. $lhfixed = true;
  5217. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  5218. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5219. }
  5220. else {
  5221. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  5222. }
  5223. }
  5224. else
  5225. /*-- END LISTS --*/
  5226. /*-- TABLES --*/
  5227. if ($is_table) {
  5228. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  5229. $lhfixed = true;
  5230. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  5231. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  5232. }
  5233. else {
  5234. $this->lineheight_correction = $this->table_lineheight;
  5235. }
  5236. }
  5237. else
  5238. /*-- END TABLES --*/
  5239. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  5240. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  5241. $lhfixed = true;
  5242. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  5243. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5244. }
  5245. else {
  5246. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  5247. }
  5248. }
  5249. else {
  5250. $this->lineheight_correction = $this->normalLineheight;
  5251. }
  5252. // update $contentWidth and $cutoffWidth since they changed with cropping
  5253. // Also correct lineheight to maximum fontsize (not for tables)
  5254. $contentWidth = 0;
  5255. // correct lineheight to maximum fontsize
  5256. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  5257. else { $maxlineHeight = 0; }
  5258. $this->forceExactLineheight = true;
  5259. $maxfontsize = 0;
  5260. // mPDF 5.0.071
  5261. // While we're at it, check for cursive text
  5262. $checkCursive=false;
  5263. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  5264. foreach ( $content as $k => $chunk )
  5265. {
  5266. $this->restoreFont( $font[ $k ]);
  5267. if (!isset($this->objectbuffer[$k])) {
  5268. if (!$this->usingCoreFont) {
  5269. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  5270. // mPDF 5.0.071
  5271. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  5272. }
  5273. // Soft Hyphens chr(173)
  5274. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  5275. $content[$k] = $chunk = str_replace($this->chrs[173],'',$chunk );
  5276. }
  5277. $contentWidth += $this->GetStringWidth( $chunk ) * $this->k;
  5278. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$this->FontSize * $this->lineheight_correction ); }
  5279. if ($lhfixed && ($this->FontSize > $def_fontsize || ($this->FontSize > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  5280. $this->forceExactLineheight = false;
  5281. }
  5282. $maxfontsize = max($maxfontsize,$this->FontSize);
  5283. }
  5284. }
  5285. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  5286. $lastfontstyle = $font[count($font)-1]['style'];
  5287. // mPDF 5.0.054
  5288. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  5289. $lastitalic = $this->FontSize*0.15*$this->k;
  5290. }
  5291. else { $lastitalic = 0; }
  5292. /*-- LISTS --*/
  5293. if ($is_list && is_array($this->bulletarray) && $this->bulletarray) {
  5294. $actfs = $this->bulletarray['fontsize'];
  5295. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  5296. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  5297. $maxfontsize = max($maxfontsize,$actfs);
  5298. }
  5299. /*-- END LISTS --*/
  5300. // when every text item checked i.e. $maxfontsize is set properly
  5301. $af = 0; // Above font
  5302. $bf = 0; // Below font
  5303. $mta = 0; // Maximum top-aligned
  5304. $mba = 0; // Maximum bottom-aligned
  5305. foreach ( $content as $k => $chunk ) {
  5306. if (isset($this->objectbuffer[$k]) && $this->objectbuffer[$k]) {
  5307. $contentWidth += $this->objectbuffer[$k]['OUTER-WIDTH'] * $this->k;
  5308. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  5309. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  5310. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  5311. if ($va == 'BS') { // (BASELINE default)
  5312. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  5313. }
  5314. else if ($va == 'M') {
  5315. $af = max($af, ($oh - $maxfontsize)/2);
  5316. $bf = max($bf, ($oh - $maxfontsize)/2);
  5317. }
  5318. else if ($va == 'TT') {
  5319. $bf = max($bf, ($oh - $maxfontsize));
  5320. }
  5321. else if ($va == 'TB') {
  5322. $af = max($af, ($oh - $maxfontsize));
  5323. }
  5324. else if ($va == 'T') {
  5325. $mta = max($mta, $oh);
  5326. }
  5327. else if ($va == 'B') {
  5328. $mba = max($mba, $oh);
  5329. }
  5330. }
  5331. }
  5332. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  5333. $maxlineHeight = $maxfontsize + $af + $bf;
  5334. }
  5335. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  5336. if ($mta > $maxlineHeight) {
  5337. $bf += ($mta - $maxlineHeight);
  5338. $maxlineHeight = $mta;
  5339. }
  5340. if ($mba > $maxlineHeight) {
  5341. $af += ($mba - $maxlineHeight);
  5342. $maxlineHeight = $mba;
  5343. }
  5344. $lineHeight = $maxlineHeight;
  5345. $cutoffWidth = $contentWidth;
  5346. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  5347. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  5348. $this->linemaxfontsize = $def_fontsize;
  5349. }
  5350. else { $this->linemaxfontsize = $maxfontsize; }
  5351. // mPDF 5.0.071
  5352. $inclCursive=false;
  5353. // mPDF 5.0.063
  5354. foreach ( $content as $k => $chunk ) {
  5355. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5356. if ($this->usingCoreFont) {
  5357. $content[$k] = str_replace($this->chrs[160],$this->chrs[32],$chunk );
  5358. }
  5359. else {
  5360. $content[$k] = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$chunk );
  5361. // mPDF 5.0.071
  5362. if ($checkCursive) {
  5363. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  5364. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  5365. }
  5366. }
  5367. }
  5368. }
  5369. // JUSTIFICATION J
  5370. // mPDF 5.0.063
  5371. $jcharspacing = 0;
  5372. $jws = 0;
  5373. $nb_carac = 0;
  5374. $nb_spaces = 0;
  5375. // if it's justified, we need to find the char/word spacing (or if orphans have allowed length of line to go over the maxwidth)
  5376. // mPDF 5.1.009
  5377. if(( $align == 'J' ) || (($cutoffWidth + $lastitalic > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) + 0.001) && !$CJKoverflow)) { // 0.001 is to correct for deviations converting mm=>pts
  5378. // JUSTIFY J (Use character spacing)
  5379. // WORD SPACING
  5380. foreach ( $content as $k => $chunk ) {
  5381. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5382. $nb_carac += mb_strlen( $chunk, $this->mb_enc ) ;
  5383. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc ) ;
  5384. }
  5385. }
  5386. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$cutoffWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*$this->k)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) )),$inclCursive); // mPDF 5.0.071
  5387. }
  5388. // WORD SPACING
  5389. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) );
  5390. $empty -= ($jcharspacing * $nb_carac);
  5391. $empty -= ($jws * $nb_spaces);
  5392. $empty /= $this->k;
  5393. $b = ''; //do not use borders
  5394. // Get PAGEBREAK TO TEST for height including the top border/padding
  5395. $check_h = max($this->divheight,$lineHeight);
  5396. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blklvl > 0) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5397. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  5398. }
  5399. // mPDF 5.0.054
  5400. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  5401. $this->SetCol($this->NbCol-1);
  5402. }
  5403. // PAGEBREAK
  5404. // 'If' below used in order to fix "first-line of other page with justify on" bug
  5405. if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5406. $bak_x=$this->x;//Current X position
  5407. // WORD SPACING
  5408. $ws=$this->ws;//Word Spacing
  5409. $charspacing=$this->charspacing;//Character Spacing
  5410. $this->ResetSpacing();
  5411. $this->AddPage($this->CurOrientation);
  5412. $this->x = $bak_x;
  5413. // Added to correct for OddEven Margins
  5414. $currentx += $this->MarginCorrection;
  5415. $this->x += $this->MarginCorrection;
  5416. // WORD SPACING
  5417. $this->SetSpacing($charspacing,$ws);
  5418. }
  5419. // mPDF 5.0
  5420. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  5421. $this->printdivbuffer();
  5422. $this->keep_block_together = 0;
  5423. }
  5424. /*-- COLUMNS --*/
  5425. // COLS
  5426. // COLUMN CHANGE
  5427. if ($this->CurrCol != $oldcolumn) {
  5428. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5429. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5430. $oldcolumn = $this->CurrCol;
  5431. }
  5432. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5433. /*-- END COLUMNS --*/
  5434. // TOP MARGIN
  5435. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5436. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  5437. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5438. }
  5439. // Update y0 for top of block (used to paint border)
  5440. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5441. $this->blk[$this->blklvl]['y0'] = $this->y;
  5442. $this->blk[$this->blklvl]['startpage'] = $this->page;
  5443. }
  5444. // TOP PADDING and BORDER spacing/fill
  5445. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5446. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  5447. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  5448. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5449. }
  5450. $arraysize = count($content);
  5451. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  5452. // PAINT BACKGROUND FOR THIS LINE
  5453. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  5454. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL ;
  5455. if ($align == 'R') { $this->x += $empty; }
  5456. else if ($align == 'C') { $this->x += ($empty / 2); }
  5457. // Paragraph INDENT
  5458. // mPDF 5.0.054
  5459. if (isset($this->blk[$this->blklvl]['text_indent']) && ($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && ($blockdir !='rtl') && ($align !='C')) {
  5460. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5461. $this->x += $ti;
  5462. }
  5463. // DIRECTIONALITY RTL
  5464. $all_rtl = false;
  5465. $contains_rtl = false;
  5466. /*-- RTL --*/
  5467. // mPDF 5.0.054
  5468. if ($blockdir == 'rtl' || $this->biDirectional) { // mPDF 5.0.054
  5469. $all_rtl = true;
  5470. foreach ( $content as $k => $chunk ) {
  5471. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir); // mPDF 5.0.054
  5472. if ($reversed > 0) { $contains_rtl = true; }
  5473. if ($reversed < 2) { $all_rtl = false; }
  5474. $content[$k] = $chunk;
  5475. }
  5476. // mPDF 5.0.054
  5477. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $content = array_reverse($content,false); }
  5478. }
  5479. /*-- END RTL --*/
  5480. foreach ( $content as $k => $chunk ) {
  5481. // FOR IMAGES - UPDATE POSITION
  5482. // mPDF 5.0.054
  5483. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $dirk = $arraysize-1 - $k ; } else { $dirk = $k; }
  5484. $va = 'M'; // default for text
  5485. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  5486. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'] ;
  5487. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  5488. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  5489. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  5490. $va = $this->objectbuffer[$dirk]['vertical-align'];
  5491. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  5492. if ($va == 'BS') {
  5493. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5494. }
  5495. else if ($va == 'M' || $va == '') {
  5496. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  5497. }
  5498. else if ($va == 'TB') {
  5499. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5500. }
  5501. else if ($va == 'TT') {
  5502. $yadj += $af;
  5503. }
  5504. else if ($va == 'B') {
  5505. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5506. }
  5507. else if ($va == 'T') {
  5508. $yadj += 0;
  5509. }
  5510. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  5511. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  5512. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  5513. }
  5514. // DIRECTIONALITY RTL
  5515. // mPDF 5.0.054
  5516. if ((($blockdir == 'rtl') && ($contains_rtl )) || ($all_rtl )) { $this->restoreFont($font[$arraysize-1 - $k]); }
  5517. else { $this->restoreFont( $font[ $k ] ); }
  5518. // mPDF 5.0.063
  5519. $this->SetSpacing(($this->fixedlSpacing*$this->k)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*$this->k+$jws);
  5520. // Now unset these values so they don't influence GetStringwidth below or in fn. Cell
  5521. $this->fixedlSpacing = false;
  5522. $this->minwSpacing = 0;
  5523. // *********** SPAN BACKGROUND COLOR ***************** //
  5524. if ($this->spanbgcolor) {
  5525. $cor = $this->spanbgcolorarray;
  5526. $this->SetFColor($cor); // mPDF 5.0.020
  5527. $save_fill = $fill; $spanfill = 1; $fill = 1;
  5528. }
  5529. // WORD SPACING
  5530. $stringWidth = $this->GetStringWidth($chunk );
  5531. $stringWidth += ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / $this->k );
  5532. $stringWidth += ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / $this->k );
  5533. if (isset($this->objectbuffer[$dirk])) { $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH']; }
  5534. if ($stringWidth==0) { $stringWidth = 0.000001; } // mPDF 5.0
  5535. if ($k == $arraysize-1) {
  5536. $stringWidth -= ( $this->charspacing / $this->k );
  5537. $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF , $currentx,0,0,'M', $fill, $af, $bf ); //mono-style line or last part (skips line)
  5538. }
  5539. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf );//first or middle part
  5540. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  5541. if (isset($spanfill) && $spanfill) {
  5542. $fill = $save_fill; $spanfill = 0;
  5543. if ($fill) { $this->SetFColor($bcor); } // mPDF 5.0.020
  5544. }
  5545. }
  5546. if (!$is_table) {
  5547. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin']));
  5548. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']));
  5549. }
  5550. // move on to the next line, reset variables, tack on saved content and current char
  5551. $this->printobjectbuffer($is_table, $blockdir); // mPDF 5.0.054
  5552. $this->objectbuffer = array();
  5553. /*-- LISTS --*/
  5554. // LIST BULLETS/NUMBERS
  5555. if ($is_list && is_array($this->bulletarray) && ($lineCount == 1) ) {
  5556. $this->ResetSpacing();
  5557. $bull = $this->bulletarray;
  5558. // mPDF 5.1.018
  5559. if (is_array($bull['col'])) { $this->SetTColor($bull['col']); }
  5560. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  5561. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  5562. }
  5563. if (isset($bull['level']) && isset($bull['occur']) && isset($bull['num']) && isset($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) && $this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) { $this->restoreInlineProperties($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]); }
  5564. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5565. $this->bullet = true;
  5566. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  5567. }
  5568. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  5569. //Output bullet
  5570. $this->x = $currentx;
  5571. if (isset($bull['x'])) { $this->x += $bull['x']; }
  5572. $this->y -= $lineHeight;
  5573. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  5574. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5575. $this->bullet = false;
  5576. }
  5577. $this->x = $currentx; // Reset
  5578. $this->y += $lineHeight;
  5579. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5580. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  5581. }
  5582. /*-- END LISTS --*/
  5583. /*-- CSS-IMAGE-FLOAT --*/
  5584. // Update values if set to skipline
  5585. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  5586. /*-- END CSS-IMAGE-FLOAT --*/
  5587. // Reset lineheight
  5588. $lineHeight = $this->divheight;
  5589. $valign = 'M';
  5590. $this->restoreFont( $savedFont );
  5591. $font = array();
  5592. $content = array();
  5593. $contentWidth = 0;
  5594. if (!empty($savedObj)) {
  5595. $this->objectbuffer[] = $savedObj;
  5596. $font[] = $savedFont;
  5597. $content[] = '';
  5598. $contentWidth += $savedObj['OUTER-WIDTH'] * $this->k;
  5599. }
  5600. $font[] = $savedFont;
  5601. $content[] = $savedContent . $c;
  5602. $currContent =& $content[ (count($content)-1) ];
  5603. // mPDF 5.0.071
  5604. // CJK - strip CJK space at end of line
  5605. // &#x3000; = \xe3\x80\x80 = CJK space
  5606. if ($this->checkCJK && $currContent == "\xe3\x80\x80") { $currContent = '' ; } // *CJK*
  5607. $contentWidth += $this->GetStringWidth( $currContent ) * $this->k;
  5608. $cutoffWidth = $contentWidth;
  5609. $CJKoverflow = false; // mPDF 5.1.009
  5610. }
  5611. // another character will fit, so add it on
  5612. else {
  5613. $contentWidth += $cw;
  5614. $currContent .= $c;
  5615. }
  5616. }
  5617. unset($content);
  5618. }
  5619. //----------------------END OF FLOWING BLOCK------------------------------------//
  5620. /*-- CSS-IMAGE-FLOAT --*/
  5621. // Update values if set to skipline
  5622. function _advanceFloatMargins() {
  5623. // Update floatmargins - L
  5624. if (isset($this->floatmargins['L']) && $this->floatmargins['L']['skipline'] && $this->floatmargins['L']['y0'] != $this->y) {
  5625. $yadj = $this->y - $this->floatmargins['L']['y0'];
  5626. $this->floatmargins['L']['y0'] = $this->y;
  5627. $this->floatmargins['L']['y1'] += $yadj;
  5628. // Update objattr in floatbuffer
  5629. if ($this->floatbuffer[$this->floatmargins['L']['id']]['border_left']['w']) {
  5630. $this->floatbuffer[$this->floatmargins['L']['id']]['BORDER-Y'] += $yadj;
  5631. }
  5632. $this->floatbuffer[$this->floatmargins['L']['id']]['INNER-Y'] += $yadj;
  5633. $this->floatbuffer[$this->floatmargins['L']['id']]['OUTER-Y'] += $yadj;
  5634. // Unset values
  5635. $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false;
  5636. $this->floatmargins['L']['skipline'] = false;
  5637. $this->floatmargins['L']['id'] = '';
  5638. }
  5639. // Update floatmargins - R
  5640. if (isset($this->floatmargins['R']) && $this->floatmargins['R']['skipline'] && $this->floatmargins['R']['y0'] != $this->y) {
  5641. $yadj = $this->y - $this->floatmargins['R']['y0'];
  5642. $this->floatmargins['R']['y0'] = $this->y;
  5643. $this->floatmargins['R']['y1'] += $yadj;
  5644. // Update objattr in floatbuffer
  5645. if ($this->floatbuffer[$this->floatmargins['R']['id']]['border_left']['w']) {
  5646. $this->floatbuffer[$this->floatmargins['R']['id']]['BORDER-Y'] += $yadj;
  5647. }
  5648. $this->floatbuffer[$this->floatmargins['R']['id']]['INNER-Y'] += $yadj;
  5649. $this->floatbuffer[$this->floatmargins['R']['id']]['OUTER-Y'] += $yadj;
  5650. // Unset values
  5651. $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false;
  5652. $this->floatmargins['R']['skipline'] = false;
  5653. $this->floatmargins['R']['id'] = '';
  5654. }
  5655. }
  5656. /*-- END CSS-IMAGE-FLOAT --*/
  5657. ////////////////////////////////////////////////////////////////////////////////
  5658. // ADDED forcewrap - to call from inline OBJECT functions to breakwords if necessary in cell
  5659. ////////////////////////////////////////////////////////////////////////////////
  5660. function WordWrap(&$text, $maxwidth, $forcewrap = 0) {
  5661. $biggestword=0;
  5662. $toonarrow=false;
  5663. $text = trim($text);
  5664. if ($text==='') return 0;
  5665. $space = $this->GetStringWidth(' ');
  5666. $lines = explode("\n", $text);
  5667. $text = '';
  5668. $count = 0;
  5669. foreach ($lines as $line) {
  5670. $words = explode(' ', $line);
  5671. $width = 0;
  5672. foreach ($words as $word) {
  5673. $word = trim($word);
  5674. $wordwidth = $this->GetStringWidth($word);
  5675. //Warn user that maxwidth is insufficient
  5676. if ($wordwidth > $maxwidth + 0.0001) {
  5677. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  5678. $toonarrow=true;
  5679. // ADDED
  5680. if ($forcewrap) {
  5681. while($wordwidth > $maxwidth) {
  5682. $chw = 0; // check width
  5683. for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) {
  5684. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  5685. if ($chw > $maxwidth ) {
  5686. if ($text) {
  5687. $text = rtrim($text)."\n".mb_substr($word,0,$i,$this->mb_enc );
  5688. $count++;
  5689. }
  5690. else {
  5691. $text = mb_substr($word,0,$i,$this->mb_enc );
  5692. }
  5693. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  5694. $wordwidth = $this->GetStringWidth($word);
  5695. $width = $maxwidth;
  5696. break;
  5697. }
  5698. }
  5699. }
  5700. }
  5701. }
  5702. if ($width + $wordwidth < $maxwidth - 0.0001) {
  5703. $width += $wordwidth + $space;
  5704. $text .= $word.' ';
  5705. }
  5706. else {
  5707. $width = $wordwidth + $space;
  5708. $text = rtrim($text)."\n".$word.' ';
  5709. $count++;
  5710. }
  5711. }
  5712. // mPDF 5.1.012
  5713. //$text = rtrim($text)."\n";
  5714. $text .= "\n";
  5715. $count++;
  5716. }
  5717. $text = rtrim($text);
  5718. //Return -(wordsize) if word is bigger than maxwidth
  5719. // ADDED
  5720. if ($forcewrap) { return $count; }
  5721. if (($toonarrow) && ($this->table_error_report)) {
  5722. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  5723. }
  5724. if ($toonarrow) return -$biggestword;
  5725. else return $count;
  5726. }
  5727. function _SetTextRendering($mode) {
  5728. if (!(($mode == 0) || ($mode == 1) || ($mode == 2)))
  5729. $this->Error("Text rendering mode should be 0, 1 or 2 (value : $mode)");
  5730. $tr = ($mode.' Tr');
  5731. if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); }
  5732. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5733. }
  5734. function SetTextOutline($width, $col=0) { // mPDF 5.0.051
  5735. if ($width == false) //Now resets all values
  5736. {
  5737. $this->outline_on = false;
  5738. $this->SetLineWidth(0.2);
  5739. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  5740. $this->_SetTextRendering(0);
  5741. $tr = ('0 Tr');
  5742. if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); }
  5743. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5744. }
  5745. else
  5746. {
  5747. $this->SetLineWidth($width);
  5748. $this->SetDColor($col); // mPDF 5.0.051
  5749. $tr = ('2 Tr');
  5750. if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); }
  5751. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5752. }
  5753. }
  5754. function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$paint=true, $constrain=true, $watermark=false, $shownoimg=true, $allowvector=true) {
  5755. $orig_srcpath = $file;
  5756. $this->GetFullPath($file);
  5757. $info=$this->_getImage($file, true, $allowvector, $orig_srcpath );
  5758. if(!$info && $paint) {
  5759. $info = $this->_getImage($this->noImageFile);
  5760. if ($info) {
  5761. $file = $this->noImageFile;
  5762. $w = ($info['w'] * (25.4/$this->dpi)); // 14 x 16px
  5763. $h = ($info['h'] * (25.4/$this->dpi)); // 14 x 16px
  5764. }
  5765. }
  5766. if(!$info) return false;
  5767. //Automatic width and height calculation if needed
  5768. if($w==0 and $h==0) {
  5769. /*-- IMAGES-WMF --*/
  5770. if ($info['type']=='wmf') {
  5771. // WMF units are twips (1/20pt)
  5772. // divide by 20 to get points
  5773. // divide by k to get user units
  5774. $w = abs($info['w'])/(20*$this->k);
  5775. $h = abs($info['h']) / (20*$this->k);
  5776. }
  5777. else
  5778. /*-- END IMAGES-WMF --*/
  5779. if ($info['type']=='svg') {
  5780. // returned SVG units are pts
  5781. // divide by k to get user units (mm)
  5782. $w = abs($info['w'])/$this->k;
  5783. $h = abs($info['h']) /$this->k;
  5784. }
  5785. else {
  5786. //Put image at default image dpi
  5787. $w=($info['w']/$this->k) * (72/$this->img_dpi);
  5788. $h=($info['h']/$this->k) * (72/$this->img_dpi);
  5789. }
  5790. }
  5791. if($w==0) $w=abs($h*$info['w']/$info['h']);
  5792. if($h==0) $h=abs($w*$info['h']/$info['w']);
  5793. /*-- WATERMARK --*/
  5794. if ($watermark) {
  5795. $maxw = $this->w;
  5796. $maxh = $this->h;
  5797. // Size = D PF or array
  5798. if (is_array($this->watermark_size)) {
  5799. $w = $this->watermark_size[0];
  5800. $h = $this->watermark_size[1];
  5801. }
  5802. else if (!is_string($this->watermark_size)) {
  5803. $maxw -= $this->watermark_size*2;
  5804. $maxh -= $this->watermark_size*2;
  5805. $w = $maxw;
  5806. $h=abs($w*$info['h']/$info['w']);
  5807. if ($h > $maxh ) {
  5808. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5809. }
  5810. }
  5811. else if ($this->watermark_size == 'F') {
  5812. if ($this->ColActive) { $maxw = $this->w - ($this->DeflMargin + $this->DefrMargin); }
  5813. else { $maxw = $this->pgwidth; }
  5814. $maxh = $this->h - ($this->tMargin + $this->bMargin);
  5815. $w = $maxw;
  5816. $h=abs($w*$info['h']/$info['w']);
  5817. if ($h > $maxh ) {
  5818. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5819. }
  5820. }
  5821. else if ($this->watermark_size == 'P') { // Default P
  5822. $w = $maxw;
  5823. $h=abs($w*$info['h']/$info['w']);
  5824. if ($h > $maxh ) {
  5825. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5826. }
  5827. }
  5828. // Automatically resize to maximum dimensions of page if too large
  5829. if ($w > $maxw) {
  5830. $w = $maxw;
  5831. $h=abs($w*$info['h']/$info['w']);
  5832. }
  5833. if ($h > $maxh ) {
  5834. $h = $maxh ;
  5835. $w=abs($h*$info['w']/$info['h']);
  5836. }
  5837. // Position
  5838. if (is_array($this->watermark_pos)) {
  5839. $x = $this->watermark_pos[0];
  5840. $y = $this->watermark_pos[1];
  5841. }
  5842. else if ($this->watermark_pos == 'F') { // centred on printable area
  5843. if ($this->ColActive) { // *COLUMNS*
  5844. if (($this->mirrorMargins) && (($this->page)%2==0)) { $xadj = $this->DeflMargin-$this->DefrMargin; } // *COLUMNS*
  5845. else { $xadj = 0; } // *COLUMNS*
  5846. $x = ($this->DeflMargin - $xadj + ($this->w - ($this->DeflMargin + $this->DefrMargin))/2) - ($w/2); // *COLUMNS*
  5847. } // *COLUMNS*
  5848. else { // *COLUMNS*
  5849. $x = ($this->lMargin + ($this->pgwidth)/2) - ($w/2);
  5850. } // *COLUMNS*
  5851. $y = ($this->tMargin + ($this->h - ($this->tMargin + $this->bMargin))/2) - ($h/2);
  5852. }
  5853. else { // default P - centred on whole page
  5854. $x = ($this->w/2) - ($w/2);
  5855. $y = ($this->h/2) - ($h/2);
  5856. }
  5857. /*-- IMAGES-WMF --*/
  5858. if ($info['type']=='wmf') {
  5859. $sx = $w*$this->k / $info['w'];
  5860. $sy = -$h*$this->k / $info['h'];
  5861. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']);
  5862. }
  5863. else
  5864. /*-- END IMAGES-WMF --*/
  5865. if ($info['type']=='svg') {
  5866. $sx = $w*$this->k / $info['w'];
  5867. $sy = -$h*$this->k / $info['h'];
  5868. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']);
  5869. }
  5870. else {
  5871. $outstring = sprintf("q %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q",$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']);
  5872. }
  5873. if ($this->watermarkImgBehind) {
  5874. $outstring = $this->watermarkImgAlpha . "\n" . $outstring . "\n" . $this->SetAlpha(1, 'Normal', true) . "\n";
  5875. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$outstring."\n".'\\1', $this->pages[$this->page]);
  5876. }
  5877. else { $this->_out($outstring); }
  5878. return 0;
  5879. } // end of IF watermark
  5880. /*-- END WATERMARK --*/
  5881. if ($constrain) {
  5882. // Automatically resize to maximum dimensions of page if too large
  5883. if (isset($this->blk[$this->blklvl]['inner_width']) && $this->blk[$this->blklvl]['inner_width']) { $maxw = $this->blk[$this->blklvl]['inner_width']; }
  5884. else { $maxw = $this->pgwidth; }
  5885. if ($w > $maxw) {
  5886. $w = $maxw;
  5887. $h=abs($w*$info['h']/$info['w']);
  5888. }
  5889. // mPDF 5.0.011 (was 10mm)
  5890. if ($h > $this->h - ($this->tMargin + $this->bMargin + 1)) { // see below - +10 to avoid drawing too close to border of page
  5891. $h = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  5892. if ($this->fullImageHeight) { $h = $this->fullImageHeight; }
  5893. $w=abs($h*$info['w']/$info['h']);
  5894. }
  5895. //Avoid drawing out of the paper(exceeding width limits).
  5896. //if ( ($x + $w) > $this->fw ) {
  5897. if ( ($x + $w) > $this->w ) {
  5898. $x = $this->lMargin;
  5899. $y += 5;
  5900. }
  5901. $changedpage = false;
  5902. $oldcolumn = $this->CurrCol;
  5903. //Avoid drawing out of the page.
  5904. if($y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5905. $this->AddPage($this->CurOrientation);
  5906. // Added to correct for OddEven Margins
  5907. $x=$x +$this->MarginCorrection;
  5908. $y = $tMargin + $this->margin_header;
  5909. $changedpage = true;
  5910. }
  5911. /*-- COLUMNS --*/
  5912. // COLS
  5913. // COLUMN CHANGE
  5914. if ($this->CurrCol != $oldcolumn) {
  5915. $y = $this->y0;
  5916. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5917. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5918. }
  5919. /*-- END COLUMNS --*/
  5920. } // end of IF constrain
  5921. /*-- IMAGES-WMF --*/
  5922. if ($info['type']=='wmf') {
  5923. $sx = $w*$this->k / $info['w'];
  5924. $sy = -$h*$this->k / $info['h'];
  5925. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']);
  5926. }
  5927. else
  5928. /*-- END IMAGES-WMF --*/
  5929. if ($info['type']=='svg') {
  5930. $sx = $w*$this->k / $info['w'];
  5931. $sy = -$h*$this->k / $info['h'];
  5932. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']);
  5933. }
  5934. else {
  5935. $outstring = sprintf("q %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q",$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']);
  5936. }
  5937. if($paint) {
  5938. $this->_out($outstring);
  5939. if($link) $this->Link($x,$y,$w,$h,$link);
  5940. // Avoid writing text on top of the image. // THIS WAS OUTSIDE THE if ($paint) bit!!!!!!!!!!!!!!!!
  5941. $this->y = $y + $h;
  5942. }
  5943. //Return width-height array
  5944. $sizesarray['WIDTH'] = $w;
  5945. $sizesarray['HEIGHT'] = $h;
  5946. $sizesarray['X'] = $x; //Position before painting image
  5947. $sizesarray['Y'] = $y; //Position before painting image
  5948. $sizesarray['OUTPUT'] = $outstring;
  5949. $sizesarray['IMAGE_ID'] = $info['i'];
  5950. $sizesarray['itype'] = $info['type']; // mPDF 5.0.039
  5951. // mPDF 5.0.031
  5952. $sizesarray['set-dpi'] = $info['set-dpi'];
  5953. return $sizesarray;
  5954. }
  5955. //=============================================================
  5956. //=============================================================
  5957. //=============================================================
  5958. //=============================================================
  5959. //=============================================================
  5960. function _getObjAttr($t) {
  5961. $c = explode("\xbb\xa4\xac",$t,2);
  5962. $c = explode(",",$c[1],2);
  5963. foreach($c as $v) {
  5964. $v = explode("=",$v,2);
  5965. $sp[$v[0]] = $v[1];
  5966. }
  5967. return (unserialize($sp['objattr']));
  5968. }
  5969. function inlineObject($type,$x,$y,$objattr,$Lmargin,$widthUsed,$maxWidth,$lineHeight,$paint=false,$is_table=false)
  5970. {
  5971. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  5972. // NB $x is only used when paint=true
  5973. // Lmargin not used
  5974. $w = 0;
  5975. if (isset($objattr['width'])) { $w = $objattr['width']/$k; }
  5976. $h = 0;
  5977. if (isset($objattr['height'])) { $h = abs($objattr['height']/$k); }
  5978. $widthLeft = $maxWidth - $widthUsed;
  5979. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  5980. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  5981. // For Images
  5982. if (isset($objattr['border_left'])) {
  5983. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right'])/$k;
  5984. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom'])/$k;
  5985. if ($type == 'image' || $type == 'barcode') {
  5986. $extraWidth += ($objattr['padding_left'] + $objattr['padding_right'])/$k;
  5987. $extraHeight += ($objattr['padding_top'] + $objattr['padding_bottom'])/$k;
  5988. }
  5989. }
  5990. if (!isset($objattr['vertical-align'])) { $objattr['vertical-align'] = 'M'; }
  5991. if ($type == 'image' || (isset($objattr['subtype']) && $objattr['subtype'] == 'IMAGE')) {
  5992. if (isset($objattr['itype']) && ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg')) {
  5993. $file = $objattr['file'];
  5994. $info=$this->formobjects[$file];
  5995. }
  5996. else if (isset($objattr['file'])) {
  5997. $file = $objattr['file'];
  5998. $info=$this->images[$file];
  5999. }
  6000. }
  6001. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  6002. $w = 0.00001;
  6003. $h = 0.00001;
  6004. }
  6005. // TEST whether need to skipline
  6006. if (!$paint) {
  6007. if ($type == 'hr') { // always force new line
  6008. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-2, $w ,$h ); } // New page + new line
  6009. else { return array(1, $w ,$h ); } // new line
  6010. }
  6011. else {
  6012. if ($widthUsed > 0 && $w > $widthLeft && (!$is_table || $type != 'image')) { // New line needed
  6013. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter) { return array(-2,$w ,$h ); } // New page + new line
  6014. return array(1,$w ,$h ); // new line
  6015. }
  6016. else if ($widthUsed > 0 && $w > $widthLeft && $is_table) { // New line needed in TABLE
  6017. return array(1,$w ,$h ); // new line
  6018. }
  6019. // Will fit on line but NEW PAGE REQUIRED
  6020. else if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-1,$w ,$h ); }
  6021. else { return array(0,$w ,$h ); }
  6022. }
  6023. }
  6024. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  6025. $w = 0.00001;
  6026. $h = 0.00001;
  6027. $objattr['BORDER-WIDTH'] = 0;
  6028. $objattr['BORDER-HEIGHT'] = 0;
  6029. $objattr['BORDER-X'] = $x;
  6030. $objattr['BORDER-Y'] = $y;
  6031. $objattr['INNER-WIDTH'] = 0;
  6032. $objattr['INNER-HEIGHT'] = 0;
  6033. $objattr['INNER-X'] = $x;
  6034. $objattr['INNER-Y'] = $y;
  6035. }
  6036. if ($type == 'image') {
  6037. // Automatically resize to width remaining
  6038. if ($w > $widthLeft && !$is_table) {
  6039. $w = $widthLeft ;
  6040. $h=abs($w*$info['h']/$info['w']);
  6041. }
  6042. $img_w = $w - $extraWidth ;
  6043. $img_h = $h - $extraHeight ;
  6044. $objattr['BORDER-WIDTH'] = $img_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6045. $objattr['BORDER-HEIGHT'] = $img_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6046. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6047. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6048. $objattr['INNER-WIDTH'] = $img_w;
  6049. $objattr['INNER-HEIGHT'] = $img_h;
  6050. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6051. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6052. $objattr['ID'] = $info['i'];
  6053. }
  6054. if ($type == 'input' && $objattr['subtype'] == 'IMAGE') {
  6055. $img_w = $w - $extraWidth ;
  6056. $img_h = $h - $extraHeight ;
  6057. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6058. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6059. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6060. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6061. $objattr['INNER-WIDTH'] = $img_w;
  6062. $objattr['INNER-HEIGHT'] = $img_h;
  6063. $objattr['INNER-X'] = $x + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6064. $objattr['INNER-Y'] = $y + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6065. $objattr['ID'] = $info['i'];
  6066. }
  6067. /*-- BARCODES --*/
  6068. if ($type == 'barcode') {
  6069. $b_w = $w - $extraWidth ;
  6070. $b_h = $h - $extraHeight ;
  6071. $objattr['BORDER-WIDTH'] = $b_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6072. $objattr['BORDER-HEIGHT'] = $b_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6073. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6074. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6075. // mPDF 5.0 Not required/used
  6076. // $objattr['INNER-WIDTH'] = $img_w;
  6077. // $objattr['INNER-HEIGHT'] = $img_h;
  6078. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6079. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6080. }
  6081. /*-- END BARCODES --*/
  6082. if ($type == 'textarea') {
  6083. // Automatically resize to width remaining
  6084. if ($w > $widthLeft && !$is_table) {
  6085. $w = $widthLeft ;
  6086. }
  6087. if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter) {
  6088. $h=$this->h - $y - $this->bMargin;
  6089. }
  6090. }
  6091. if ($type == 'hr') {
  6092. if ($is_table) {
  6093. $objattr['INNER-WIDTH'] = $maxWidth * $objattr['W-PERCENT']/100;
  6094. $objattr['width'] = $objattr['INNER-WIDTH'];
  6095. $w = $maxWidth;
  6096. }
  6097. else {
  6098. if ($w>$maxWidth) { $w = $maxWidth; }
  6099. $objattr['INNER-WIDTH'] = $w;
  6100. $w = $maxWidth;
  6101. }
  6102. }
  6103. if (($type == 'select') || ($type == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD'))) {
  6104. // Automatically resize to width remaining
  6105. if ($w > $widthLeft && !$is_table) {
  6106. $w = $widthLeft;
  6107. }
  6108. }
  6109. if ($type == 'textarea' || $type == 'select' || $type == 'input') {
  6110. if (isset($objattr['fontsize'])) $objattr['fontsize'] /= $k;
  6111. if (isset($objattr['linewidth'])) $objattr['linewidth'] /= $k;
  6112. }
  6113. if (!isset($objattr['BORDER-Y'])) { $objattr['BORDER-Y'] = 0; }
  6114. if (!isset($objattr['BORDER-X'])) { $objattr['BORDER-X'] = 0; }
  6115. if (!isset($objattr['INNER-Y'])) { $objattr['INNER-Y'] = 0; }
  6116. if (!isset($objattr['INNER-X'])) { $objattr['INNER-X'] = 0; }
  6117. //Return width-height array
  6118. $objattr['OUTER-WIDTH'] = $w;
  6119. $objattr['OUTER-HEIGHT'] = $h;
  6120. $objattr['OUTER-X'] = $x;
  6121. $objattr['OUTER-Y'] = $y;
  6122. return $objattr;
  6123. }
  6124. //=============================================================
  6125. //=============================================================
  6126. //=============================================================
  6127. //=============================================================
  6128. //=============================================================
  6129. // mPDF 5.0.051
  6130. function SetLineJoin($mode=0)
  6131. {
  6132. $s=sprintf('%d j',$mode);
  6133. if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineJoin']) && $this->pageoutput[$this->page]['LineJoin'] != $s) || !isset($this->pageoutput[$this->page]['LineJoin']) || $this->keep_block_together)) { $this->_out($s); }
  6134. $this->pageoutput[$this->page]['LineJoin'] = $s;
  6135. }
  6136. function SetLineCap($mode=2) {
  6137. $s=sprintf('%d J',$mode);
  6138. if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineCap']) && $this->pageoutput[$this->page]['LineCap'] != $s) || !isset($this->pageoutput[$this->page]['LineCap']) || $this->keep_block_together)) { $this->_out($s); }
  6139. $this->pageoutput[$this->page]['LineCap'] = $s;
  6140. }
  6141. function SetDash($black=false,$white=false)
  6142. {
  6143. if($black and $white) $s=sprintf('[%.3f %.3f] 0 d',$black*$this->k,$white*$this->k);
  6144. else $s='[] 0 d';
  6145. if($this->page>0 && ((isset($this->pageoutput[$this->page]['Dash']) && $this->pageoutput[$this->page]['Dash'] != $s) || !isset($this->pageoutput[$this->page]['Dash']) || $this->keep_block_together)) { $this->_out($s); }
  6146. $this->pageoutput[$this->page]['Dash'] = $s;
  6147. }
  6148. function SetDisplayPreferences($preferences) {
  6149. // String containing any or none of /HideMenubar/HideToolbar/HideWindowUI/DisplayDocTitle/CenterWindow/FitWindow
  6150. $this->DisplayPreferences .= $preferences;
  6151. }
  6152. function Ln($h='',$collapsible=0)
  6153. {
  6154. // Added collapsible to allow collapsible top-margin on new page
  6155. //Line feed; default value is last cell height
  6156. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  6157. if ($collapsible && ($this->y==$this->tMargin) && (!$this->ColActive)) { $h = 0; }
  6158. if(is_string($h)) $this->y+=$this->lasth;
  6159. else $this->y+=$h;
  6160. }
  6161. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6162. function DivLn($h,$level=-3,$move_y=true,$collapsible=false,$state=0) {
  6163. // this->x is returned as it was
  6164. // adds lines (y) where DIV bgcolors are filled in
  6165. // allows .00001 as nominal height used for bookmarks/annotations etc.
  6166. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)) && (!$this->ColActive)) { return; }
  6167. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->y0)) && ($this->ColActive) && $this->CurrCol == 0) { return; } // *COLUMNS*
  6168. // Still use this method if columns or page-break-inside: avoid, as it allows repositioning later
  6169. // otherwise, now uses PaintDivBB()
  6170. if (!$this->ColActive && !$this->keep_block_together && !$this->kwt) {
  6171. if ($move_y && !$this->ColActive) { $this->y += $h; }
  6172. return;
  6173. }
  6174. if ($level == -3) { $level = $this->blklvl; }
  6175. $firstblockfill = $this->GetFirstBlockFill();
  6176. if ($firstblockfill && $this->blklvl > 0 && $this->blklvl >= $firstblockfill) {
  6177. $last_x = 0;
  6178. $last_w = 0;
  6179. $last_fc = $this->FillColor;
  6180. $bak_x = $this->x;
  6181. $bak_h = $this->divheight;
  6182. $this->divheight = 0; // Temporarily turn off divheight - as Cell() uses it to check for PageBreak
  6183. for ($blvl=$firstblockfill;$blvl<=$level;$blvl++) {
  6184. $this->SetBlockFill($blvl);
  6185. $this->x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6186. if ($last_x != $this->lMargin + $this->blk[$blvl]['outer_left_margin'] || $last_w != $this->blk[$blvl]['width'] || $last_fc != $this->FillColor) {
  6187. $x = $this->x;
  6188. $this->Cell( ($this->blk[$blvl]['width']), $h, '', '', 0, '', 1);
  6189. if (!$this->keep_block_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  6190. $this->x = $x;
  6191. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6192. if ($blvl == $this->blklvl) { $this->PaintDivLnBorder($state,$blvl,$h); }
  6193. else { $this->PaintDivLnBorder(0,$blvl,$h); }
  6194. }
  6195. }
  6196. $last_x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6197. $last_w = $this->blk[$blvl]['width'];
  6198. $last_fc = $this->FillColor;
  6199. }
  6200. // Reset current block fill
  6201. if (isset($this->blk[$this->blklvl]['bgcolorarray'])) {
  6202. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  6203. $this->SetFColor($bcor); // mPDF 5.0.020
  6204. }
  6205. $this->x = $bak_x;
  6206. $this->divheight = $bak_h;
  6207. }
  6208. if ($move_y) { $this->y += $h; }
  6209. }
  6210. function GetX()
  6211. {
  6212. //Get x position
  6213. return $this->x;
  6214. }
  6215. function SetX($x)
  6216. {
  6217. //Set x position
  6218. if($x >= 0) $this->x=$x;
  6219. else $this->x = $this->w + $x;
  6220. }
  6221. function GetY()
  6222. {
  6223. //Get y position
  6224. return $this->y;
  6225. }
  6226. function SetY($y)
  6227. {
  6228. //Set y position and reset x
  6229. $this->x=$this->lMargin;
  6230. if($y>=0)
  6231. $this->y=$y;
  6232. else
  6233. $this->y=$this->h+$y;
  6234. }
  6235. function SetXY($x,$y)
  6236. {
  6237. //Set x and y positions
  6238. $this->SetY($y);
  6239. $this->SetX($x);
  6240. }
  6241. function Output($name='',$dest='')
  6242. {
  6243. //Output PDF to some destination
  6244. global $_SERVER;
  6245. if ($this->showStats) {
  6246. echo '<div>Generated in '.sprintf('%.2f',(microtime(true) - $this->time0)).' seconds</div>';
  6247. }
  6248. //Finish document if necessary
  6249. if ($this->progressBar) { $this->UpdateProgressBar(1,'100','Finished'); } // *PROGRESS-BAR*
  6250. if($this->state < 3) $this->Close();
  6251. if ($this->progressBar) { $this->UpdateProgressBar(2,'100','Finished'); } // *PROGRESS-BAR*
  6252. // fn. error_get_last is only in PHP>=5.2
  6253. if ($this->debug && function_exists('error_get_last') && error_get_last()) {
  6254. $e = error_get_last();
  6255. if (($e['type'] < 2048 && $e['type'] != 8) || (intval($e['type']) & intval(ini_get("error_reporting")))) {
  6256. echo "<p>Error message detected - PDF file generation aborted.</p>";
  6257. echo $e['message'].'<br />';
  6258. echo 'File: '.$e['file'].'<br />';
  6259. echo 'Line: '.$e['line'].'<br />';
  6260. exit;
  6261. }
  6262. }
  6263. if (($this->PDFA || $this->PDFX) && $this->encrypted) { $this->Error("PDFA1-b or PDFX/1-a does not permit encryption of documents."); }
  6264. if (count($this->PDFAXwarnings) && (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto))) {
  6265. if ($this->PDFA) {
  6266. echo '<div>WARNING - This file could not be generated as it stands as a PDFA1-b compliant file.</div>';
  6267. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFAauto=true;</i></div>';
  6268. echo '<div>Action that mPDF will take to automatically force PDFA1-b compliance are shown in brackets.</div>';
  6269. }
  6270. else {
  6271. echo '<div>WARNING - This file could not be generated as it stands as a PDFX/1-a compliant file.</div>';
  6272. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFXauto=true;</i></div>';
  6273. echo '<div>Action that mPDF will take to automatically force PDFX/1-a compliance are shown in brackets.</div>';
  6274. }
  6275. echo '<div>Warning(s) generated:</div><ul>';
  6276. $this->PDFAXwarnings = array_unique($this->PDFAXwarnings);
  6277. foreach($this->PDFAXwarnings AS $w) {
  6278. echo '<li>'.$w.'</li>';
  6279. }
  6280. echo '</ul>';
  6281. exit;
  6282. }
  6283. if ($this->showStats) {
  6284. echo '<div>Compiled in '.sprintf('%.2f',(microtime(true) - $this->time0)).' seconds (total)</div>';
  6285. echo '<div>Peak Memory usage '.number_format((memory_get_peak_usage(true)/(1024*1024)),2).' MB</div>';
  6286. echo '<div>PDF file size '.number_format((strlen($this->buffer)/1024)).' kB</div>';
  6287. echo '<div>Number of fonts '.count($this->fonts).'</div>';
  6288. exit;
  6289. }
  6290. if(is_bool($dest)) $dest=$dest ? 'D' : 'F';
  6291. $dest=strtoupper($dest);
  6292. if($dest=='') {
  6293. if($name=='') {
  6294. $name='mpdf.pdf';
  6295. $dest='I';
  6296. }
  6297. else { $dest='F'; }
  6298. }
  6299. /*-- PROGRESS-BAR --*/
  6300. if ($this->progressBar && ($dest=='D' || $dest=='I')) {
  6301. if($name=='') { $name='mpdf.pdf'; }
  6302. $tempfile = '_tempPDF'.RAND(1,10000);
  6303. //Save to local file
  6304. $f=fopen(_MPDF_TEMP_PATH.$tempfile.'.pdf','wb');
  6305. if(!$f) $this->Error('Unable to create temporary output file: '.$tempfile.'.pdf');
  6306. fwrite($f,$this->buffer,strlen($this->buffer));
  6307. fclose($f);
  6308. $this->UpdateProgressBar(3,'','Finished');
  6309. echo '<script type="text/javascript">
  6310. var form = document.createElement("form");
  6311. form.setAttribute("method", "post");
  6312. form.setAttribute("action", "'._MPDF_URI.'includes/out.php");
  6313. var hiddenField = document.createElement("input");
  6314. hiddenField.setAttribute("type", "hidden");
  6315. hiddenField.setAttribute("name", "filename");
  6316. hiddenField.setAttribute("value", "'.$tempfile.'");
  6317. form.appendChild(hiddenField);
  6318. var hiddenField = document.createElement("input");
  6319. hiddenField.setAttribute("type", "hidden");
  6320. hiddenField.setAttribute("name", "dest");
  6321. hiddenField.setAttribute("value", "'.$dest.'");
  6322. form.appendChild(hiddenField);
  6323. var hiddenField = document.createElement("input");
  6324. hiddenField.setAttribute("type", "hidden");
  6325. hiddenField.setAttribute("name", "opname");
  6326. hiddenField.setAttribute("value", "'.$name.'");
  6327. form.appendChild(hiddenField);
  6328. var hiddenField = document.createElement("input");
  6329. hiddenField.setAttribute("type", "hidden");
  6330. hiddenField.setAttribute("name", "path");
  6331. hiddenField.setAttribute("value", "'.urlencode(_MPDF_TEMP_PATH).'");
  6332. form.appendChild(hiddenField);
  6333. document.body.appendChild(form);
  6334. form.submit();
  6335. </script>
  6336. </div>
  6337. </body>
  6338. </html>';
  6339. exit;
  6340. }
  6341. else {
  6342. if ($this->progressBar) { $this->UpdateProgressBar(3,'','Finished'); }
  6343. /*-- END PROGRESS-BAR --*/
  6344. switch($dest) {
  6345. case 'I':
  6346. if ($this->debug && !$this->allow_output_buffering && ob_get_contents()) { echo "<p>Output has already been sent from the script - PDF file generation aborted.</p>"; exit; }
  6347. //Send to standard output
  6348. if(isset($_SERVER['SERVER_NAME']))
  6349. {
  6350. //We send to a browser
  6351. header('Content-Type: application/pdf');
  6352. if(headers_sent())
  6353. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6354. header('Content-Length: '.strlen($this->buffer));
  6355. header('Content-disposition: inline; filename="'.$name.'"');
  6356. // NEW OUTPUT HEADERS mPDF 5.0
  6357. header('Cache-Control: public, must-revalidate, max-age=0');
  6358. header('Pragma: public');
  6359. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6360. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6361. /*
  6362. header('Pragma: no-cache');
  6363. header('Cache-Control: maxage=0');
  6364. */
  6365. }
  6366. echo $this->buffer;
  6367. break;
  6368. case 'D':
  6369. //Download file
  6370. header('Content-Description: File Transfer');
  6371. if (headers_sent())
  6372. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6373. // NEW OUTPUT HEADERS mPDF 5.0
  6374. header('Content-Transfer-Encoding: binary');
  6375. header('Cache-Control: public, must-revalidate, max-age=0');
  6376. header('Pragma: public');
  6377. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6378. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6379. header('Content-Type: application/force-download');
  6380. header('Content-Type: application/octet-stream', false);
  6381. header('Content-Type: application/download', false);
  6382. header('Content-Type: application/pdf', false);
  6383. /*
  6384. if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) {
  6385. if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') {
  6386. header('HTTP/1.1 200 OK');
  6387. header('Status: 200 OK');
  6388. header('Pragma: anytextexeptno-cache', true);
  6389. header("Cache-Control: public, must-revalidate");
  6390. }
  6391. else {
  6392. header('Pragma: no-cache');
  6393. header('Cache-Control: maxage=0');
  6394. }
  6395. header('Content-Type: application/force-download');
  6396. }
  6397. else {
  6398. header('Content-Type: application/octet-stream');
  6399. }
  6400. */
  6401. header('Content-Length: '.strlen($this->buffer));
  6402. header('Content-disposition: attachment; filename="'.$name.'"');
  6403. echo $this->buffer;
  6404. break;
  6405. case 'F':
  6406. //Save to local file
  6407. $f=fopen($name,'wb');
  6408. if(!$f) $this->Error('Unable to create output file: '.$name);
  6409. fwrite($f,$this->buffer,strlen($this->buffer));
  6410. fclose($f);
  6411. break;
  6412. case 'S':
  6413. //Return as a string
  6414. return $this->buffer;
  6415. default:
  6416. $this->Error('Incorrect output destination: '.$dest);
  6417. }
  6418. } // *PROGRESS-BAR*
  6419. return '';
  6420. }
  6421. // *****************************************************************************
  6422. // *
  6423. // Protected methods *
  6424. // *
  6425. // *****************************************************************************
  6426. function _dochecks()
  6427. {
  6428. //Check for locale-related bug
  6429. if(1.1==1)
  6430. $this->Error('Don\'t alter the locale before including class file');
  6431. //Check for decimal separator
  6432. if(sprintf('%.1f',1.0)!='1.0')
  6433. setlocale(LC_NUMERIC,'C');
  6434. }
  6435. function _begindoc()
  6436. {
  6437. //Start document
  6438. $this->state=1;
  6439. $this->_out('%PDF-'.$this->pdf_version);
  6440. $this->_out('%'.chr(226).chr(227).chr(207).chr(211)); // 4 chars > 128 to show binary file
  6441. }
  6442. /*-- HTMLHEADERS-FOOTERS --*/
  6443. function _puthtmlheaders() {
  6444. $this->state=2;
  6445. $nb=$this->page;
  6446. for($n=1;$n<=$nb;$n++) {
  6447. if ($this->mirrorMargins && $n%2==0) { $OE = 'E'; } // EVEN
  6448. else { $OE = 'O'; }
  6449. $this->page = $n;
  6450. if (isset($this->saveHTMLHeader[$n][$OE])) {
  6451. $html = $this->saveHTMLHeader[$n][$OE]['html'];
  6452. $this->lMargin = $this->saveHTMLHeader[$n][$OE]['ml'];
  6453. $this->rMargin = $this->saveHTMLHeader[$n][$OE]['mr'];
  6454. $this->tMargin = $this->saveHTMLHeader[$n][$OE]['mh'];
  6455. $this->bMargin = $this->saveHTMLHeader[$n][$OE]['mf'];
  6456. $this->margin_header = $this->saveHTMLHeader[$n][$OE]['mh'];
  6457. $this->margin_footer = $this->saveHTMLHeader[$n][$OE]['mf'];
  6458. $this->w = $this->saveHTMLHeader[$n][$OE]['pw'];
  6459. $this->h = $this->saveHTMLHeader[$n][$OE]['ph'];
  6460. $rotate = $this->saveHTMLHeader[$n][$OE]['rotate'];
  6461. $this->Reset();
  6462. $this->pageoutput[$n] = array();
  6463. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6464. $this->x = $this->lMargin;
  6465. $this->y = $this->margin_header;
  6466. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6467. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6468. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6469. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6470. $this->HTMLheaderPageLinks = array();
  6471. $this->pageBackgrounds = array();
  6472. $this->writingHTMLheader = true;
  6473. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6474. $this->writingHTMLheader = false;
  6475. $this->Reset();
  6476. $this->pageoutput[$n] = array();
  6477. $s = $this->PrintPageBackgrounds();
  6478. $this->headerbuffer = $s . $this->headerbuffer;
  6479. $os = '';
  6480. if ($rotate) {
  6481. $os .= sprintf('q 0 -1 1 0 0 %.3f cm ',($this->w*$this->k));
  6482. }
  6483. $os .= $this->headerbuffer ;
  6484. if ($rotate) {
  6485. $os .= ' Q' . "\n";
  6486. }
  6487. // Writes over the page background but behind any other output on page
  6488. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6489. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6490. $lks = $this->HTMLheaderPageLinks;
  6491. foreach($lks AS $lk) {
  6492. if ($rotate) {
  6493. $lw = $lk[2];
  6494. $lh = $lk[3];
  6495. $lk[2] = $lh;
  6496. $lk[3] = $lw; // swap width and height
  6497. $ax = $lk[0]/$this->k;
  6498. $ay = $lk[1]/$this->k;
  6499. $bx = $ay-($lh/$this->k);
  6500. $by = $this->w-$ax;
  6501. $lk[0] = $bx*$this->k;
  6502. $lk[1] = ($this->h-$by)*$this->k - $lw;
  6503. }
  6504. $this->PageLinks[$n][]=$lk;
  6505. }
  6506. }
  6507. if (isset($this->saveHTMLFooter[$n][$OE])) {
  6508. $html = $this->saveHTMLFooter[$this->page][$OE]['html'];
  6509. $this->lMargin = $this->saveHTMLFooter[$n][$OE]['ml'];
  6510. $this->rMargin = $this->saveHTMLFooter[$n][$OE]['mr'];
  6511. $this->tMargin = $this->saveHTMLFooter[$n][$OE]['mh'];
  6512. $this->bMargin = $this->saveHTMLFooter[$n][$OE]['mf'];
  6513. $this->margin_header = $this->saveHTMLFooter[$n][$OE]['mh'];
  6514. $this->margin_footer = $this->saveHTMLFooter[$n][$OE]['mf'];
  6515. $this->w = $this->saveHTMLFooter[$n][$OE]['pw'];
  6516. $this->h = $this->saveHTMLFooter[$n][$OE]['ph'];
  6517. // mPDF 5.0.052
  6518. $rotate = (isset($this->saveHTMLFooter[$n][$OE]['rotate']) ? $this->saveHTMLFooter[$n][$OE]['rotate'] : null);
  6519. $this->Reset();
  6520. $this->pageoutput[$n] = array();
  6521. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6522. $this->x = $this->lMargin;
  6523. $top_y = $this->y = $this->h - $this->margin_footer;
  6524. // if bottom-margin==0, corrects to avoid division by zero
  6525. if ($this->y == $this->h) { $top_y = $this->y = ($this->h - 0.1); }
  6526. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6527. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6528. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6529. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6530. $this->HTMLheaderPageLinks = array();
  6531. $this->pageBackgrounds = array();
  6532. $this->writingHTMLfooter = true;
  6533. $this->InFooter = true;
  6534. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6535. $this->writingHTMLfooter = false;
  6536. $this->InFooter = false;
  6537. $this->Reset();
  6538. $this->pageoutput[$n] = array();
  6539. $fheight = $this->y - $top_y;
  6540. $adj = -$fheight;
  6541. $s = $this->PrintPageBackgrounds(-$adj);
  6542. $this->headerbuffer = $s . $this->headerbuffer;
  6543. $os = '';
  6544. $os .= $this->StartTransform(true)."\n";
  6545. if ($rotate) {
  6546. $os .= sprintf('q 0 -1 1 0 0 %.3f cm ',($this->w*$this->k));
  6547. }
  6548. $os .= $this->transformTranslate(0, $adj, true)."\n";
  6549. $os .= $this->headerbuffer ;
  6550. if ($rotate) {
  6551. $os .= ' Q' . "\n";
  6552. }
  6553. $os .= $this->StopTransform(true)."\n";
  6554. // Writes over the page background but behind any other output on page
  6555. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6556. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6557. $lks = $this->HTMLheaderPageLinks;
  6558. foreach($lks AS $lk) {
  6559. $lk[1] -= $adj*$this->k;
  6560. if ($rotate) {
  6561. $lw = $lk[2];
  6562. $lh = $lk[3];
  6563. $lk[2] = $lh;
  6564. $lk[3] = $lw; // swap width and height
  6565. $ax = $lk[0]/$this->k;
  6566. $ay = $lk[1]/$this->k;
  6567. $bx = $ay-($lh/$this->k);
  6568. $by = $this->w-$ax;
  6569. $lk[0] = $bx*$this->k;
  6570. $lk[1] = ($this->h-$by)*$this->k - $lw;
  6571. }
  6572. $this->PageLinks[$n][]=$lk;
  6573. }
  6574. }
  6575. }
  6576. $this->page=$nb;
  6577. $this->state=1;
  6578. }
  6579. /*-- END HTMLHEADERS-FOOTERS --*/
  6580. function _putpages()
  6581. {
  6582. $nb=$this->page;
  6583. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  6584. if($this->DefOrientation=='P') {
  6585. $defwPt=$this->fwPt;
  6586. $defhPt=$this->fhPt;
  6587. }
  6588. else {
  6589. $defwPt=$this->fhPt;
  6590. $defhPt=$this->fwPt;
  6591. }
  6592. $annotid=(3+2*$nb);
  6593. for($n=1;$n<=$nb;$n++)
  6594. {
  6595. if(isset($this->OrientationChanges[$n])) {
  6596. $hPt=$this->pageDim[$n]['w']*$this->k;
  6597. $wPt=$this->pageDim[$n]['h']*$this->k;
  6598. // mPDF 5.0.047
  6599. $owidthPt_LR = $this->pageDim[$n]['outer_width_TB']*$this->k;
  6600. $owidthPt_TB = $this->pageDim[$n]['outer_width_LR']*$this->k;
  6601. }
  6602. else {
  6603. $wPt=$this->pageDim[$n]['w']*$this->k;
  6604. $hPt=$this->pageDim[$n]['h']*$this->k;
  6605. // mPDF 5.0.047
  6606. $owidthPt_LR = $this->pageDim[$n]['outer_width_LR']*$this->k;
  6607. $owidthPt_TB = $this->pageDim[$n]['outer_width_TB']*$this->k;
  6608. }
  6609. //Replace number of pages
  6610. if(!empty($this->aliasNbPg)) {
  6611. // mPDF 5.0
  6612. if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPg, false); }
  6613. else { $s1 = $this->aliasNbPg; }
  6614. if (!$this->onlyCoreFonts) { $r = $this->UTF8ToUTF16BE($nb, false); }
  6615. else { $r = $nb; }
  6616. if (preg_match_all('/{mpdfheadernbpg (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$this->pages[$n],$m)) {
  6617. for($hi=0;$hi<count($m[0]);$hi++) {
  6618. $pos = $m[1][$hi];
  6619. $hff = $m[2][$hi];
  6620. $hfst = $m[3][$hi];
  6621. $hfsz = $m[4][$hi];
  6622. $this->SetFont($hff,$hfst,$hfsz, false);
  6623. $x1 = $this->GetStringWidth($this->aliasNbPg);
  6624. $x2 = $this->GetStringWidth($nb);
  6625. $xadj = $x1 - $x2;
  6626. if ($pos=='C') { $xadj /= 2; }
  6627. $rep = sprintf(' q 1 0 0 1 %.3f 0 cm ', $xadj*$this->k);
  6628. $this->pages[$n] = str_replace($m[0][$hi], $rep, $this->pages[$n]);
  6629. }
  6630. }
  6631. $this->pages[$n]=str_replace($s1,$r,$this->pages[$n]);
  6632. // mPDF 5.0.04
  6633. // And now for any SMP/SIP fonts subset using <HH> format
  6634. $r = '';
  6635. $nstr = "$nb";
  6636. for($i=0;$i<strlen($nstr);$i++) {
  6637. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  6638. }
  6639. $this->pages[$n]=str_replace($this->aliasNbPgHex,$r,$this->pages[$n]);
  6640. }
  6641. //Replace number of pages in group
  6642. if(!empty($this->aliasNbPgGp)) {
  6643. // mPDF 5.0
  6644. if (!$this->onlyCoreFonts) { $s2 = $this->UTF8ToUTF16BE($this->aliasNbPgGp, false); }
  6645. else { $s2 = $this->aliasNbPgGp; }
  6646. $nbt = $this->docPageNumTotal($n);
  6647. if (!$this->onlyCoreFonts) { $r = $this->UTF8ToUTF16BE($nbt, false); }
  6648. else { $r = $nbt; }
  6649. if (preg_match_all('/{mpdfheadernbpggp (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$this->pages[$n],$m)) {
  6650. for($hi=0;$hi<count($m[0]);$hi++) {
  6651. $pos = $m[1][$hi];
  6652. $hff = $m[2][$hi];
  6653. $hfst = $m[3][$hi];
  6654. $hfsz = $m[4][$hi];
  6655. $this->SetFont($hff,$hfst,$hfsz, false);
  6656. $x1 = $this->GetStringWidth($this->aliasNbPgGp);
  6657. $x2 = $this->GetStringWidth($nbt);
  6658. $xadj = $x1 - $x2;
  6659. if ($pos=='C') { $xadj /= 2; }
  6660. $rep = sprintf(' q 1 0 0 1 %.3f 0 cm ', $xadj*$this->k);
  6661. $this->pages[$n] = str_replace($m[0][$hi], $rep, $this->pages[$n]);
  6662. }
  6663. }
  6664. $this->pages[$n]=str_replace($s2,$r,$this->pages[$n]);
  6665. // mPDF 5.0.04
  6666. // And now for any SMP/SIP fonts subset using <HH> format
  6667. $r = '';
  6668. $nstr = "$nbt";
  6669. for($i=0;$i<strlen($nstr);$i++) {
  6670. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  6671. }
  6672. $this->pages[$n]=str_replace($this->aliasNbPgGpHex,$r,$this->pages[$n]);
  6673. }
  6674. $this->pages[$n] = preg_replace('/(\s*___BACKGROUND___PATTERNS'.date('jY').'\s*)/', " ", $this->pages[$n]);
  6675. $this->pages[$n] = preg_replace('/(\s*___HEADER___MARKER'.date('jY').'\s*)/', " ", $this->pages[$n]);
  6676. $this->pages[$n] = preg_replace('/(\s*___PAGE___START'.date('jY').'\s*)/', " ", $this->pages[$n]); // mPDF 5.0
  6677. $this->pages[$n] = preg_replace('/(\s*___TABLE___BACKGROUNDS'.date('jY').'\s*)/', " ", $this->pages[$n]); // mPDF 5.0.018
  6678. //Page
  6679. $this->_newobj();
  6680. $this->_out('<</Type /Page');
  6681. $this->_out('/Parent 1 0 R');
  6682. if(isset($this->OrientationChanges[$n])) {
  6683. $this->_out(sprintf('/MediaBox [0 0 %.3f %.3f]',$hPt,$wPt));
  6684. // mPDF 5.0.047
  6685. //If BleedBox is defined, it must be larger than the TrimBox, but smaller than the MediaBox
  6686. $bleedMargin = $this->pageDim[$n]['bleedMargin']*$this->k;
  6687. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  6688. $x0 = $owidthPt_TB-$bleedMargin;
  6689. $y0 = $owidthPt_LR-$bleedMargin;
  6690. $x1 = $hPt-$owidthPt_TB+$bleedMargin;
  6691. $y1 = $wPt-$owidthPt_LR+$bleedMargin;
  6692. $this->_out(sprintf('/BleedBox [%.3f %.3f %.3f %.3f]', $x0, $y0, $x1, $y1));
  6693. }
  6694. $this->_out(sprintf('/TrimBox [%.3f %.3f %.3f %.3f]', $owidthPt_TB, $owidthPt_LR, ($hPt-$owidthPt_TB), ($wPt-$owidthPt_LR)));
  6695. if (isset($this->OrientationChanges[$n]) && $this->displayDefaultOrientation) {
  6696. if ($this->DefOrientation=='P') { $this->_out('/Rotate 270'); }
  6697. else { $this->_out('/Rotate 90'); }
  6698. }
  6699. }
  6700. //else if($wPt != $defwPt || $hPt != $defhPt) {
  6701. else { // mPDF 5.0.047
  6702. $this->_out(sprintf('/MediaBox [0 0 %.3f %.3f]',$wPt,$hPt));
  6703. // mPDF 5.0.047
  6704. $bleedMargin = $this->pageDim[$n]['bleedMargin']*$this->k;
  6705. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  6706. $x0 = $owidthPt_LR-$bleedMargin;
  6707. $y0 = $owidthPt_TB-$bleedMargin;
  6708. $x1 = $wPt-$owidthPt_LR+$bleedMargin;
  6709. $y1 = $hPt-$owidthPt_TB+$bleedMargin;
  6710. $this->_out(sprintf('/BleedBox [%.3f %.3f %.3f %.3f]', $x0, $y0, $x1, $y1));
  6711. }
  6712. $this->_out(sprintf('/TrimBox [%.3f %.3f %.3f %.3f]', $owidthPt_LR, $owidthPt_TB, ($wPt-$owidthPt_LR), ($hPt-$owidthPt_TB)));
  6713. }
  6714. $this->_out('/Resources 2 0 R');
  6715. // Important to keep in RGB colorSpace when using transparency
  6716. // mPDF 5.0.019 5.0.046 5.0.051
  6717. if (!$this->PDFA && !$this->PDFX) {
  6718. if ($this->restrictColorSpace == 3)
  6719. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceCMYK >> ');
  6720. else if ($this->restrictColorSpace == 1)
  6721. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >> ');
  6722. else
  6723. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceRGB >> ');
  6724. }
  6725. $annotsnum = 0;
  6726. if (isset($this->PageLinks[$n])) { $annotsnum += count($this->PageLinks[$n]); }
  6727. /*-- ANNOTATIONS --*/
  6728. if (isset($this->PageAnnots[$n])) {
  6729. foreach ($this->PageAnnots[$n] as $k => $pl) {
  6730. if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $annotsnum += 2 ; } // mPDF 5.0.048
  6731. else { $annotsnum++; }
  6732. $this->PageAnnots[$n][$k]['pageobj'] = $this->n; // mPDF 5.0.051
  6733. }
  6734. }
  6735. /*-- END ANNOTATIONS --*/
  6736. if ($annotsnum ) {
  6737. $s = '/Annots [ ';
  6738. for($i=0;$i<$annotsnum;$i++) {
  6739. $s .= ($annotid + $i) . ' 0 R ';
  6740. }
  6741. $annotid += $annotsnum;
  6742. $s .= '] ';
  6743. $this->_out($s);
  6744. }
  6745. $this->_out('/Contents '.($this->n+1).' 0 R>>');
  6746. $this->_out('endobj');
  6747. //Page content
  6748. $this->_newobj();
  6749. $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
  6750. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  6751. $this->_putstream($p);
  6752. $this->_out('endobj');
  6753. }
  6754. $this->_putannots($n);
  6755. //Pages root
  6756. $this->offsets[1]=strlen($this->buffer);
  6757. $this->_out('1 0 obj');
  6758. $this->_out('<</Type /Pages');
  6759. $kids='/Kids [';
  6760. for($i=0;$i<$nb;$i++)
  6761. $kids.=(3+2*$i).' 0 R ';
  6762. $this->_out($kids.']');
  6763. $this->_out('/Count '.$nb);
  6764. $this->_out(sprintf('/MediaBox [0 0 %.3f %.3f]',$defwPt,$defhPt));
  6765. $this->_out('>>');
  6766. $this->_out('endobj');
  6767. }
  6768. function _putannots($n) {
  6769. $nb=$this->page;
  6770. for($n=1;$n<=$nb;$n++)
  6771. {
  6772. $annotobjs = array();
  6773. if(isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n])) {
  6774. $wPt=$this->pageDim[$n]['w']*$this->k;
  6775. $hPt=$this->pageDim[$n]['h']*$this->k;
  6776. //Links
  6777. if(isset($this->PageLinks[$n])) {
  6778. foreach($this->PageLinks[$n] as $key => $pl) {
  6779. $this->_newobj();
  6780. $annot='';
  6781. $rect=sprintf('%.3f %.3f %.3f %.3f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  6782. $annot .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.']';
  6783. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl[4]);
  6784. $annot .= ' /NM ('.sprintf('%04u-%04u', $n, $key).')';
  6785. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6786. $annot .= ' /Border [0 0 0]';
  6787. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  6788. if (strpos($pl[4],'@')===0) {
  6789. $p=substr($pl[4],1);
  6790. // $h=isset($this->OrientationChanges[$p]) ? $wPt : $hPt;
  6791. $htarg=$this->pageDim[$p]['h']*$this->k;
  6792. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3f null]>>',1+2*$p,$htarg);
  6793. }
  6794. else if(is_string($pl[4])) {
  6795. $annot .= ' /A <</S /URI /URI '.$this->_textstring($pl[4]).'>> >>';
  6796. }
  6797. else {
  6798. $l=$this->links[$pl[4]];
  6799. // may not be set if #link points to non-existent target
  6800. if (isset($this->pageDim[$l[0]]['h'])) { $htarg=$this->pageDim[$l[0]]['h']*$this->k; }
  6801. else { $htarg=$this->h*$this->k; } // doesn't really matter
  6802. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3f null]>>',1+2*$l[0],$htarg-$l[1]*$this->k);
  6803. }
  6804. $this->_out($annot);
  6805. $this->_out('endobj');
  6806. }
  6807. }
  6808. /*-- ANNOTATIONS --*/
  6809. if(isset($this->PageAnnots[$n])) {
  6810. foreach ($this->PageAnnots[$n] as $key => $pl) {
  6811. // mPDF 5.0.048
  6812. if ($pl['opt']['file']) { $FileAttachment=true; }
  6813. else { $FileAttachment=false; }
  6814. $this->_newobj();
  6815. $annot='';
  6816. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  6817. $x = $pl['x'];
  6818. if ($this->annotMargin <> 0 || $x==0 || $x<0) { // Odd page
  6819. $x = ($wPt/$this->k) - $this->annotMargin;
  6820. }
  6821. // mPDF 5.0.048 annotSize removed as not required
  6822. // $w = $h = ($this->annotSize * $this->k);
  6823. $w = $h = 0; // mPDF 5.0.048
  6824. $a = $x * $this->k;
  6825. $b = $hPt - ($pl['y'] * $this->k);
  6826. // mPDF 5.0.048
  6827. $annot .= '<</Type /Annot ';
  6828. if ($FileAttachment) {
  6829. $annot .= '/Subtype /FileAttachment';
  6830. // Need to set a size for FileAttachment icons
  6831. if ($pl['opt']['icon']=='Paperclip') { $w=8.235; $h=20; } // 7,17
  6832. else if ($pl['opt']['icon']=='Tag') { $w=20; $h=16; }
  6833. else if ($pl['opt']['icon']=='Graph') { $w=20; $h=20; }
  6834. else { $w=14; $h=20; } // PushPin
  6835. $f = $pl['opt']['file'];
  6836. $f = preg_replace('/^.*\//', '', $f);
  6837. $f = preg_replace('/[^a-zA-Z0-9._]/', '', $f);
  6838. $annot .= '/FS <</Type /Filespec /F ('.$f.')';
  6839. $annot .= '/EF <</F '.($this->n+1).' 0 R>>';
  6840. $annot .= '>>';
  6841. }
  6842. else {
  6843. $annot .= '/Subtype /Text';
  6844. }
  6845. $rect = sprintf('%.3f %.3f %.3f %.3f', $a, $b-$h, $a+$w, $b);
  6846. $annot .= '/Rect ['.$rect.']';
  6847. // contents = description of file in free text
  6848. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl['txt']);
  6849. $annot .= ' /NM ('.sprintf('%04u-%04u', $n, (2000 + $key)).')';
  6850. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6851. $annot .= ' /CreationDate '.$this->_textstring('D:'.date('YmdHis'));
  6852. $annot .= ' /Border [0 0 0]';
  6853. if ($this->PDFA || $this->PDFX) {
  6854. $annot .= ' /F 28';
  6855. $annot .= ' /CA 1';
  6856. }
  6857. else if ($pl['opt']['ca']>0) { $annot .= ' /CA '.$pl['opt']['ca']; }
  6858. $annotcolor = ' /C [';
  6859. // mPDF 5.0.051
  6860. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c']))) {
  6861. $col = $pl['opt']['c'];
  6862. if ($col[0]==3 || $col[0]==5) { $annotcolor .= sprintf("%.3f %.3f %.3f", $col[1]/255,$col[2]/255,$col[3]/255); }
  6863. else if ($col[0]==1) { $annotcolor .= sprintf("%.3f", $col[1]/255); }
  6864. else if ($col[0]==4 || $col[0]==6) { $annotcolor .= sprintf("%.3f %.3f %.3f %.3f", $col[1]/100,$col[2]/100,$col[3]/100,$col[4]/100); }
  6865. else { $annotcolor .= '1 1 0'; }
  6866. }
  6867. else { $annotcolor .= '1 1 0'; }
  6868. $annotcolor .= ']';
  6869. $annot .= $annotcolor;
  6870. // Usually Author
  6871. // Use as Title for fileattachment
  6872. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  6873. $annot .= ' /T '.$this->_UTF16BEtextstring($pl['opt']['t']);
  6874. }
  6875. if ($FileAttachment) {
  6876. $iconsapp = array('Paperclip', 'Graph', 'PushPin', 'Tag');
  6877. }
  6878. else { $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); }
  6879. if (isset($pl['opt']['icon']) AND in_array($pl['opt']['icon'], $iconsapp)) {
  6880. $annot .= ' /Name /'.$pl['opt']['icon'];
  6881. }
  6882. else if ($FileAttachment) { $annot .= ' /Name /PushPin'; }
  6883. else { $annot .= ' /Name /Note'; }
  6884. if (!$FileAttachment) {
  6885. // mPDF 5.0.051 /Subj is PDF 1.5 spec.
  6886. if (isset($pl['opt']['subj']) && !$this->PDFA && !$this->PDFX) {
  6887. $annot .= ' /Subj '.$this->_UTF16BEtextstring($pl['opt']['subj']);
  6888. }
  6889. if (!empty($pl['opt']['popup'])) {
  6890. $annot .= ' /Open true';
  6891. $annot .= ' /Popup '.($this->n+1).' 0 R';
  6892. }
  6893. else { $annot .= ' /Open false'; }
  6894. }
  6895. $annot .= ' /P '.$pl['pageobj'].' 0 R'; // mPDF 5.0.051
  6896. $annot .= '>>';
  6897. $this->_out($annot);
  6898. $this->_out('endobj');
  6899. // mPDF 5.0.048
  6900. if ($FileAttachment) {
  6901. $file = @file_get_contents($pl['opt']['file']) or die('mPDF Error: Cannot access file attachment - '.$pl['opt']['file']);
  6902. $filestream = gzcompress($file);
  6903. $this->_newobj();
  6904. $this->_out('<</Type /EmbeddedFile');
  6905. $this->_out('/Length '.strlen($filestream));
  6906. $this->_out('/Filter /FlateDecode');
  6907. $this->_out('>>');
  6908. $this->_putstream($filestream);
  6909. $this->_out('endobj');
  6910. }
  6911. else if (!empty($pl['opt']['popup'])) {
  6912. $this->_newobj();
  6913. $annot='';
  6914. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][0])) { $x = $pl['opt']['popup'][0] * $this->k; }
  6915. else { $x = $pl['x'] * $this->k; }
  6916. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][1])) { $y = $hPt - ($pl['opt']['popup'][1] * $this->k); }
  6917. else { $y = $hPt - ($pl['y'] * $this->k); }
  6918. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][2])) { $w = $pl['opt']['popup'][2] * $this->k; }
  6919. else { $w = 180; }
  6920. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][3])) { $h = $pl['opt']['popup'][3] * $this->k; }
  6921. else { $h = 120; }
  6922. $rect = sprintf('%.3f %.3f %.3f %.3f', $x, $y-$h, $x+$w, $y);
  6923. $annot .= '<</Type /Annot /Subtype /Popup /Rect ['.$rect.']';
  6924. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6925. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  6926. $annot .= ' /Parent '.($this->n-1).' 0 R';
  6927. $annot .= '>>';
  6928. $this->_out($annot);
  6929. $this->_out('endobj');
  6930. }
  6931. }
  6932. }
  6933. /*-- END ANNOTATIONS --*/
  6934. }
  6935. }
  6936. }
  6937. /*-- ANNOTATIONS --*/
  6938. function Annotation($text, $x=0, $y=0, $icon='Note', $author='', $subject='', $opacity=0, $colarray=false, $popup='', $file='') {
  6939. // mPDF 5.0.051
  6940. if (is_array($colarray) && count($colarray)==3) { $colarray = array(3,$colarray[0],$colarray[1],$colarray[2]); }
  6941. if ($colarray === false) { $colarray = $this->ConvertColor('yellow'); } // mPDF 5.0.051
  6942. if ($x==0) { $x = $this->x; }
  6943. if ($y==0) { $y = $this->y; }
  6944. $page = $this->page;
  6945. if ($page < 1) { // Document has not been started - assume it's for first page
  6946. $page = 1;
  6947. if ($x==0) { $x = $this->lMargin; }
  6948. if ($y==0) { $y = $this->tMargin; }
  6949. }
  6950. if ($this->PDFA || $this->PDFX) {
  6951. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Annotation markers cannot be semi-transparent in PDFA1-b or PDFX/1-a, so they may make underlying text unreadable. (Annotation markers moved to right margin)"; }
  6952. $x = ($this->w) - $this->rMargin*0.66;
  6953. }
  6954. if (!$this->annotMargin) { $y -= $this->FontSize / 2; }
  6955. if (!$opacity && $this->annotMargin) { $opacity = 1; }
  6956. else if (!$opacity) { $opacity = $this->annotOpacity; }
  6957. if ($this->keep_block_together) { // Save to array - don't write yet
  6958. $this->ktAnnots[$this->page][]=array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file)); // mPDF 5.0.048
  6959. return;
  6960. }
  6961. else if ($this->table_rotate) {
  6962. $this->tbrot_Annots[$this->page][]=array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file)); // mPDF 5.0.048
  6963. return;
  6964. }
  6965. else if ($this->kwt) {
  6966. $this->kwt_Annots[$this->page][]=array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file)); // mPDF 5.0.048
  6967. return;
  6968. }
  6969. // mPDF 5.0
  6970. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  6971. $this->HTMLheaderPageAnnots[]=array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file)); // mPDF 5.0.048
  6972. return;
  6973. }
  6974. //Put an Annotation on the page
  6975. $this->PageAnnots[$page][] = array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file)); // mPDF 5.0.048
  6976. /*-- COLUMNS --*/
  6977. // Save cross-reference to Column buffer
  6978. $ref = count($this->PageAnnots[$this->page])-1;
  6979. $this->columnAnnots[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref;
  6980. /*-- END COLUMNS --*/
  6981. }
  6982. /*-- END ANNOTATIONS --*/
  6983. function _putfonts() {
  6984. $nf=$this->n;
  6985. $mqr=$this->_getMQR(); // mPDF 5.0
  6986. if ($mqr) { set_magic_quotes_runtime(0); }
  6987. foreach($this->FontFiles as $fontkey=>$info) {
  6988. // TrueType embedded
  6989. if (isset($info['type']) && $info['type']=='TTF' && !$info['sip'] && !$info['smp']) { // mPDF 5.0.03 Added SMP
  6990. $used = true;
  6991. $asSubset = false;
  6992. foreach($this->fonts AS $k=>$f) {
  6993. if ($f['fontkey'] == $fontkey && $f['type']=='TTF') {
  6994. $used = $f['used'];
  6995. if ($used) {
  6996. $nChars = (ord($f['cw'][0]) << 8) + ord($f['cw'][1]); // mPDF 5.0
  6997. $usage = intval(count($f['subset'])*100 / $nChars);
  6998. $fsize = $info['length1'];
  6999. // Always subset the very large TTF files
  7000. if ($fsize > ($this->maxTTFFilesize *1024)) { $asSubset = true; }
  7001. else if ($usage < $this->percentSubset) { $asSubset = true; }
  7002. }
  7003. $this->fonts[$k]['asSubset'] = $asSubset;
  7004. break; // mPDF 5.1.020
  7005. }
  7006. }
  7007. if ($used && !$asSubset) {
  7008. //Font file embedding
  7009. $this->_newobj();
  7010. $this->FontFiles[$fontkey]['n']=$this->n;
  7011. $font='';
  7012. $originalsize = $info['length1']; // mPDF 5.2.024
  7013. // mPDF 5.1.020
  7014. if ($this->repackageTTF || $this->fonts[$fontkey]['TTCfontID']>0) {
  7015. // First see if there is a cached compressed file
  7016. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z')) {
  7017. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z','rb');
  7018. if(!$f) { $this->Error('Font file .ps.z not found'); }
  7019. while(!feof($f)) { $font .= fread($f, 2048); }
  7020. fclose($f);
  7021. // mPDF 5.2.024
  7022. include(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php'); // sets $originalsize (of repackaged font)
  7023. }
  7024. else {
  7025. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7026. $ttf = new TTFontFile();
  7027. $font = $ttf->repackageTTF($this->FontFiles[$fontkey]['ttffile'], $this->fonts[$fontkey]['TTCfontID'], $this->debugfonts);
  7028. $originalsize = strlen($font); // mPDF 5.2.024
  7029. $font = gzcompress($font);
  7030. unset($ttf);
  7031. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7032. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z',"wb");
  7033. fwrite($fh,$font,strlen($font));
  7034. fclose($fh);
  7035. // mPDF 5.2.024
  7036. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php',"wb");
  7037. $len = "<?php \n";
  7038. $len.='$originalsize='.$originalsize.";\n";
  7039. $len.="?>";
  7040. fwrite($fh,$len,strlen($len));
  7041. fclose($fh);
  7042. }
  7043. }
  7044. }
  7045. else {
  7046. // First see if there is a cached compressed file
  7047. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.z')) {
  7048. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z','rb');
  7049. if(!$f) { $this->Error('Font file not found'); }
  7050. while(!feof($f)) { $font .= fread($f, 2048); }
  7051. fclose($f);
  7052. }
  7053. else {
  7054. $f=fopen($this->FontFiles[$fontkey]['ttffile'],'rb');
  7055. if(!$f) { $this->Error('Font file not found'); }
  7056. while(!feof($f)) { $font .= fread($f, 2048); }
  7057. fclose($f);
  7058. $font = gzcompress($font);
  7059. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7060. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z',"wb");
  7061. fwrite($fh,$font,strlen($font));
  7062. fclose($fh);
  7063. }
  7064. }
  7065. }
  7066. $this->_out('<</Length '.strlen($font));
  7067. $this->_out('/Filter /FlateDecode');
  7068. $this->_out('/Length1 '.$originalsize); // mPDF 5.2.024
  7069. $this->_out('>>');
  7070. $this->_putstream($font);
  7071. $this->_out('endobj');
  7072. }
  7073. }
  7074. }
  7075. $nfonts = count($this->fonts);
  7076. $fctr = 1;
  7077. foreach($this->fonts as $k=>$font) {
  7078. //Font objects
  7079. $type=$font['type'];
  7080. $name=$font['name'];
  7081. if ((!isset($font['used']) || !$font['used']) && $type=='TTF') { continue; }
  7082. if ($this->progressBar) { $this->UpdateProgressBar(2,intval($fctr*100/$nfonts),'Writing Fonts'); $fctr++; } // *PROGRESS-BAR*
  7083. if (isset($font['asSubset'])) { $asSubset = $font['asSubset']; }
  7084. else { $asSubset = ''; }
  7085. if($type=='Type0') { // = Adobe CJK Fonts
  7086. $this->fonts[$k]['n']=$this->n+1;
  7087. $this->_newobj();
  7088. $this->_out('<</Type /Font');
  7089. $this->_putType0($font);
  7090. }
  7091. else if($type=='core') {
  7092. //Standard font
  7093. $this->fonts[$k]['n']=$this->n+1;
  7094. if ($this->PDFA || $this->PDFX) { $this->Error('Core fonts are not allowed in PDF/A1-b or PDFX/1-a files (Times, Helvetica, Courier etc.)'); }
  7095. $this->_newobj();
  7096. $this->_out('<</Type /Font');
  7097. $this->_out('/BaseFont /'.$name);
  7098. $this->_out('/Subtype /Type1');
  7099. if($name!='Symbol' && $name!='ZapfDingbats') {
  7100. $this->_out('/Encoding /WinAnsiEncoding');
  7101. }
  7102. $this->_out('>>');
  7103. $this->_out('endobj');
  7104. }
  7105. // TrueType embedded SUBSETS for SIP (CJK extB containing Supplementary Ideographic Plane 2)
  7106. // Or Unicode Plane 1 - Supplementary Multilingual Plane
  7107. else if ($type=='TTF' && ($font['sip'] || $font['smp'])) { // mPDF 5.0.03
  7108. if (!$font['used']) { continue; }
  7109. $ssfaid="AA";
  7110. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7111. $ttf = new TTFontFile();
  7112. for($sfid=0;$sfid<count($font['subsetfontids']);$sfid++) {
  7113. $this->fonts[$k]['n'][$sfid]=$this->n+1; // NB an array for subset
  7114. $subsetname = 'MPDF'.$ssfaid.'+'.$font['name'];
  7115. $ssfaid++;
  7116. $subset = $font['subsets'][$sfid];
  7117. unset($subset[0]);
  7118. $ttfontstream = $ttf->makeSubsetSIP($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts);
  7119. $ttfontsize = strlen($ttfontstream);
  7120. $fontstream = gzcompress($ttfontstream);
  7121. $widthstring = '';
  7122. $toUnistring = '';
  7123. foreach($font['subsets'][$sfid] AS $cp=>$u) {
  7124. $w = $this->_getCharWidth($font['cw'], $u);
  7125. if ($w !== false) {
  7126. $widthstring .= $w.' ';
  7127. }
  7128. else {
  7129. $widthstring .= round($ttf->defaultWidth).' ';
  7130. }
  7131. if ($u > 65535) {
  7132. $utf8 = chr(($u>>18)+240).chr((($u>>12)&63)+128).chr((($u>>6)&63)+128) .chr(($u&63)+128);
  7133. $utf16 = mb_convert_encoding($utf8, 'UTF-16BE', 'UTF-8');
  7134. $l1 = ord($utf16[0]);
  7135. $h1 = ord($utf16[1]);
  7136. $l2 = ord($utf16[2]);
  7137. $h2 = ord($utf16[3]);
  7138. $toUnistring .= sprintf("<%02s> <%02s%02s%02s%02s>\n", strtoupper(dechex($cp)), strtoupper(dechex($l1)), strtoupper(dechex($h1)), strtoupper(dechex($l2)), strtoupper(dechex($h2)));
  7139. }
  7140. else {
  7141. $toUnistring .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), strtoupper(dechex($u)));
  7142. }
  7143. }
  7144. //Additional Type1 or TrueType font
  7145. $this->_newobj();
  7146. $this->_out('<</Type /Font');
  7147. $this->_out('/BaseFont /'.$subsetname);
  7148. $this->_out('/Subtype /TrueType');
  7149. $this->_out('/FirstChar 0 /LastChar '.(count($font['subsets'][$sfid])-1)); // mPDF 5.1.020
  7150. $this->_out('/Widths '.($this->n+1).' 0 R');
  7151. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  7152. $this->_out('/ToUnicode '.($this->n + 3).' 0 R');
  7153. $this->_out('>>');
  7154. $this->_out('endobj');
  7155. //Widths
  7156. $this->_newobj();
  7157. $this->_out('['.$widthstring.']');
  7158. $this->_out('endobj');
  7159. //Descriptor
  7160. $this->_newobj();
  7161. $s='<</Type /FontDescriptor /FontName /'.$subsetname."\n";
  7162. foreach($font['desc'] as $kd=>$v) {
  7163. if ($kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7164. $s.=' /'.$kd.' '.$v."\n";
  7165. }
  7166. $s.='/FontFile2 '.($this->n + 2).' 0 R';
  7167. $this->_out($s.'>>');
  7168. $this->_out('endobj');
  7169. // ToUnicode
  7170. $toUni = "stream\n";
  7171. $toUni .= "/CIDInit /ProcSet findresource begin\n";
  7172. $toUni .= "12 dict begin\n";
  7173. $toUni .= "begincmap\n";
  7174. $toUni .= "/CIDSystemInfo\n";
  7175. $toUni .= "<</Registry (Adobe)\n";
  7176. $toUni .= "/Ordering (UCS)\n";
  7177. $toUni .= "/Supplement 0\n";
  7178. $toUni .= ">> def\n";
  7179. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  7180. $toUni .= "/CMapType 2 def\n";
  7181. $toUni .= "1 begincodespacerange\n";
  7182. $toUni .= "<00> <FF>\n";
  7183. $toUni .= "endcodespacerange\n";
  7184. $toUni .= count($font['subsets'][$sfid])." beginbfchar\n";
  7185. $toUni .= $toUnistring;
  7186. $toUni .= "endbfchar\n";
  7187. $toUni .= "endcmap\n";
  7188. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  7189. $toUni .= "end\n";
  7190. $toUni .= "end\n";
  7191. $toUni .= "endstream\n";
  7192. $toUni .= "endobj";
  7193. $this->_newobj();
  7194. $this->_out('<</Length '.(strlen($toUni)-24).'>>');
  7195. $this->_out($toUni);
  7196. //Font file
  7197. $this->_newobj();
  7198. $this->_out('<</Length '.strlen($fontstream));
  7199. $this->_out('/Filter /FlateDecode');
  7200. $this->_out('/Length1 '.$ttfontsize);
  7201. $this->_out('>>');
  7202. $this->_putstream($fontstream);
  7203. $this->_out('endobj');
  7204. } // foreach subset
  7205. unset($ttf);
  7206. }
  7207. // TrueType embedded SUBSETS or FULL
  7208. else if ($type=='TTF') {
  7209. $this->fonts[$k]['n']=$this->n+1;
  7210. if ($asSubset ) {
  7211. $ssfaid="A";
  7212. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7213. $ttf = new TTFontFile();
  7214. $fontname = 'MPDFA'.$ssfaid.'+'.$font['name'];
  7215. $subset = $font['subset'];
  7216. unset($subset[0]);
  7217. $ttfontstream = $ttf->makeSubset($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts);
  7218. $ttfontsize = strlen($ttfontstream);
  7219. $fontstream = gzcompress($ttfontstream);
  7220. $codeToGlyph = $ttf->codeToGlyph;
  7221. unset($codeToGlyph[0]);
  7222. }
  7223. else { $fontname = $font['name']; }
  7224. // Type0 Font
  7225. // A composite font - a font composed of other fonts, organized hierarchically
  7226. $this->_newobj();
  7227. $this->_out('<</Type /Font');
  7228. $this->_out('/Subtype /Type0');
  7229. $this->_out('/BaseFont /'.$fontname.'');
  7230. $this->_out('/Encoding /Identity-H');
  7231. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  7232. $this->_out('/ToUnicode '.($this->n + 2).' 0 R');
  7233. $this->_out('>>');
  7234. $this->_out('endobj');
  7235. // CIDFontType2
  7236. // A CIDFont whose glyph descriptions are based on TrueType font technology
  7237. $this->_newobj();
  7238. $this->_out('<</Type /Font');
  7239. $this->_out('/Subtype /CIDFontType2');
  7240. $this->_out('/BaseFont /'.$fontname.'');
  7241. $this->_out('/CIDSystemInfo '.($this->n + 2).' 0 R');
  7242. $this->_out('/FontDescriptor '.($this->n + 3).' 0 R');
  7243. if (isset($font['desc']['MissingWidth'])){
  7244. $this->_out('/DW '.$font['desc']['MissingWidth'].'');
  7245. }
  7246. if (!$asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw')) {
  7247. $w = '';
  7248. $w=file_get_contents(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw');
  7249. $this->_out($w);
  7250. }
  7251. else {
  7252. $this->_putTTfontwidths($font, $asSubset, $ttf->maxUni);
  7253. }
  7254. $this->_out('/CIDToGIDMap '.($this->n + 4).' 0 R');
  7255. $this->_out('>>');
  7256. $this->_out('endobj');
  7257. // ToUnicode
  7258. $this->_newobj();
  7259. $this->_out('<</Length 345>>');
  7260. $this->_out('stream');
  7261. $this->_out('/CIDInit /ProcSet findresource begin');
  7262. $this->_out('12 dict begin');
  7263. $this->_out('begincmap');
  7264. $this->_out('/CIDSystemInfo');
  7265. $this->_out('<</Registry (Adobe)');
  7266. $this->_out('/Ordering (UCS)');
  7267. $this->_out('/Supplement 0');
  7268. $this->_out('>> def');
  7269. $this->_out('/CMapName /Adobe-Identity-UCS def');
  7270. $this->_out('/CMapType 2 def');
  7271. $this->_out('1 begincodespacerange');
  7272. $this->_out('<0000> <FFFF>');
  7273. $this->_out('endcodespacerange');
  7274. $this->_out('1 beginbfrange');
  7275. $this->_out('<0000> <FFFF> <0000>');
  7276. $this->_out('endbfrange');
  7277. $this->_out('endcmap');
  7278. $this->_out('CMapName currentdict /CMap defineresource pop');
  7279. $this->_out('end');
  7280. $this->_out('end');
  7281. $this->_out('endstream');
  7282. $this->_out('endobj');
  7283. // CIDSystemInfo dictionary
  7284. $this->_newobj();
  7285. $this->_out('<</Registry (Adobe)');
  7286. $this->_out('/Ordering (UCS)');
  7287. $this->_out('/Supplement 0');
  7288. $this->_out('>>');
  7289. $this->_out('endobj');
  7290. // Font descriptor
  7291. $this->_newobj();
  7292. $this->_out('<</Type /FontDescriptor');
  7293. $this->_out('/FontName /'.$fontname);
  7294. foreach($font['desc'] as $kd=>$v) {
  7295. if ($asSubset && $kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7296. $this->_out(' /'.$kd.' '.$v);
  7297. }
  7298. // mPDF 5.0
  7299. if ($font['panose']) {
  7300. $this->_out(' /Style << /Panose <'.$font['panose'].'> >>');
  7301. }
  7302. if ($asSubset ) {
  7303. $this->_out('/FontFile2 '.($this->n + 2).' 0 R');
  7304. }
  7305. else if ($font['fontkey']) {
  7306. // obj ID of a stream containing a TrueType font program
  7307. $this->_out('/FontFile2 '.$this->FontFiles[$font['fontkey']]['n'].' 0 R');
  7308. }
  7309. $this->_out('>>');
  7310. $this->_out('endobj');
  7311. // Embed CIDToGIDMap
  7312. // A specification of the mapping from CIDs to glyph indices
  7313. if ($asSubset ) {
  7314. $cidtogidmap = '';
  7315. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7316. foreach($codeToGlyph as $cc=>$glyph) {
  7317. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7318. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7319. }
  7320. $cidtogidmap = gzcompress($cidtogidmap);
  7321. }
  7322. else {
  7323. // First see if there is a cached CIDToGIDMapfile
  7324. $cidtogidmap = '';
  7325. if (file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm')) {
  7326. $f=fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm','rb');
  7327. while(!feof($f)) { $cidtogidmap .= fread($f, 2048); }
  7328. fclose($f);
  7329. }
  7330. else {
  7331. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7332. $ttf = new TTFontFile();
  7333. $charToGlyph = $ttf->getCTG($font['ttffile'], $font['TTCfontID'], $this->debugfonts);
  7334. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7335. foreach($charToGlyph as $cc=>$glyph) {
  7336. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7337. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7338. }
  7339. unset($ttf);
  7340. $cidtogidmap = gzcompress($cidtogidmap);
  7341. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7342. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm',"wb");
  7343. fwrite($fh,$cidtogidmap,strlen($cidtogidmap));
  7344. fclose($fh);
  7345. }
  7346. }
  7347. }
  7348. $this->_newobj();
  7349. $this->_out('<</Length '.strlen($cidtogidmap).'');
  7350. $this->_out('/Filter /FlateDecode');
  7351. $this->_out('>>');
  7352. $this->_putstream($cidtogidmap);
  7353. $this->_out('endobj');
  7354. //Font file
  7355. if ($asSubset ) {
  7356. $this->_newobj();
  7357. $this->_out('<</Length '.strlen($fontstream));
  7358. $this->_out('/Filter /FlateDecode');
  7359. $this->_out('/Length1 '.$ttfontsize);
  7360. $this->_out('>>');
  7361. $this->_putstream($fontstream);
  7362. $this->_out('endobj');
  7363. unset($ttf);
  7364. }
  7365. }
  7366. else { $this->Error('Unsupported font type: '.$type.' ('.$name.')'); }
  7367. }
  7368. if ($mqr) { set_magic_quotes_runtime($mqr); }
  7369. }
  7370. function _putTTfontwidths(&$font, $asSubset, $maxUni) {
  7371. if ($asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php')) {
  7372. include(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php') ;
  7373. $startcid = 128;
  7374. }
  7375. else {
  7376. $rangeid = 0;
  7377. $range = array();
  7378. $prevcid = -2;
  7379. $prevwidth = -1;
  7380. $interval = false;
  7381. $startcid = 1;
  7382. }
  7383. if ($asSubset) { $cwlen = $maxUni + 1; }
  7384. else { $cwlen = (strlen($font['cw'])/2); }
  7385. // for each character
  7386. for ($cid=$startcid; $cid<$cwlen; $cid++) {
  7387. if ($cid==128 && $asSubset && (!file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php'))) {
  7388. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7389. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php',"wb");
  7390. $cw127='<?php'."\n";
  7391. $cw127.='$rangeid='.$rangeid.";\n";
  7392. $cw127.='$prevcid='.$prevcid.";\n";
  7393. $cw127.='$prevwidth='.$prevwidth.";\n";
  7394. if ($interval) { $cw127.='$interval=true'.";\n"; }
  7395. else { $cw127.='$interval=false'.";\n"; }
  7396. $cw127.='$range='.var_export($range,true).";\n";
  7397. $cw127.="?>";
  7398. fwrite($fh,$cw127,strlen($cw127));
  7399. fclose($fh);
  7400. }
  7401. }
  7402. if ($font['cw'][$cid*2] == "\00" && $font['cw'][$cid*2+1] == "\00") { continue; }
  7403. $width = (ord($font['cw'][$cid*2]) << 8) + ord($font['cw'][$cid*2+1]);
  7404. if ($width == 65535) { $width = 0; }
  7405. if ($asSubset && $cid > 255 && (!isset($font['subset'][$cid]) || !$font['subset'][$cid])) {
  7406. continue;
  7407. }
  7408. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7409. if ($cid == ($prevcid + 1)) {
  7410. // consecutive CID
  7411. if ($width == $prevwidth) {
  7412. if ($width == $range[$rangeid][0]) {
  7413. $range[$rangeid][] = $width;
  7414. } else {
  7415. array_pop($range[$rangeid]);
  7416. // new range
  7417. $rangeid = $prevcid;
  7418. $range[$rangeid] = array();
  7419. $range[$rangeid][] = $prevwidth;
  7420. $range[$rangeid][] = $width;
  7421. }
  7422. $interval = true;
  7423. $range[$rangeid]['interval'] = true;
  7424. } else {
  7425. if ($interval) {
  7426. // new range
  7427. $rangeid = $cid;
  7428. $range[$rangeid] = array();
  7429. $range[$rangeid][] = $width;
  7430. } else {
  7431. $range[$rangeid][] = $width;
  7432. }
  7433. $interval = false;
  7434. }
  7435. } else {
  7436. // new range
  7437. $rangeid = $cid;
  7438. $range[$rangeid] = array();
  7439. $range[$rangeid][] = $width;
  7440. $interval = false;
  7441. }
  7442. $prevcid = $cid;
  7443. $prevwidth = $width;
  7444. }
  7445. }
  7446. $w = $this->_putfontranges($range);
  7447. $this->_out($w);
  7448. if (!$asSubset) {
  7449. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7450. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw',"wb");
  7451. fwrite($fh,$w,strlen($w));
  7452. fclose($fh);
  7453. }
  7454. }
  7455. }
  7456. function _putfontranges(&$range) {
  7457. // optimize ranges
  7458. $prevk = -1;
  7459. $nextk = -1;
  7460. $prevint = false;
  7461. foreach ($range as $k => $ws) {
  7462. $cws = count($ws);
  7463. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  7464. if (isset($range[$k]['interval'])) {
  7465. unset($range[$k]['interval']);
  7466. }
  7467. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  7468. unset($range[$k]);
  7469. } else {
  7470. $prevk = $k;
  7471. }
  7472. $nextk = $k + $cws;
  7473. if (isset($ws['interval'])) {
  7474. if ($cws > 3) {
  7475. $prevint = true;
  7476. } else {
  7477. $prevint = false;
  7478. }
  7479. unset($range[$k]['interval']);
  7480. --$nextk;
  7481. } else {
  7482. $prevint = false;
  7483. }
  7484. }
  7485. // output data
  7486. $w = '';
  7487. foreach ($range as $k => $ws) {
  7488. if (count(array_count_values($ws)) == 1) {
  7489. // interval mode is more compact
  7490. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  7491. } else {
  7492. // range mode
  7493. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]' . "\n";
  7494. }
  7495. }
  7496. return '/W ['.$w.' ]';
  7497. }
  7498. function _putfontwidths(&$font, $cidoffset=0) {
  7499. ksort($font['cw']);
  7500. unset($font['cw'][65535]);
  7501. $rangeid = 0;
  7502. $range = array();
  7503. $prevcid = -2;
  7504. $prevwidth = -1;
  7505. $interval = false;
  7506. // for each character
  7507. foreach ($font['cw'] as $cid => $width) {
  7508. $cid -= $cidoffset;
  7509. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7510. if ($cid == ($prevcid + 1)) {
  7511. // consecutive CID
  7512. if ($width == $prevwidth) {
  7513. if ($width == $range[$rangeid][0]) {
  7514. $range[$rangeid][] = $width;
  7515. } else {
  7516. array_pop($range[$rangeid]);
  7517. // new range
  7518. $rangeid = $prevcid;
  7519. $range[$rangeid] = array();
  7520. $range[$rangeid][] = $prevwidth;
  7521. $range[$rangeid][] = $width;
  7522. }
  7523. $interval = true;
  7524. $range[$rangeid]['interval'] = true;
  7525. } else {
  7526. if ($interval) {
  7527. // new range
  7528. $rangeid = $cid;
  7529. $range[$rangeid] = array();
  7530. $range[$rangeid][] = $width;
  7531. } else {
  7532. $range[$rangeid][] = $width;
  7533. }
  7534. $interval = false;
  7535. }
  7536. } else {
  7537. // new range
  7538. $rangeid = $cid;
  7539. $range[$rangeid] = array();
  7540. $range[$rangeid][] = $width;
  7541. $interval = false;
  7542. }
  7543. $prevcid = $cid;
  7544. $prevwidth = $width;
  7545. }
  7546. }
  7547. $this->_out($this->_putfontranges($range));
  7548. }
  7549. // from class PDF_Chinese CJK EXTENSIONS
  7550. function _putType0(&$font)
  7551. {
  7552. //Type0
  7553. $this->_out('/Subtype /Type0');
  7554. $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']);
  7555. $this->_out('/Encoding /'.$font['CMap']);
  7556. $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]');
  7557. $this->_out('>>');
  7558. $this->_out('endobj');
  7559. //CIDFont
  7560. $this->_newobj();
  7561. $this->_out('<</Type /Font');
  7562. $this->_out('/Subtype /CIDFontType0');
  7563. $this->_out('/BaseFont /'.$font['name']);
  7564. $cidinfo = '/Registry '.$this->_textstring('Adobe');
  7565. $cidinfo .= ' /Ordering '.$this->_textstring($font['registry']['ordering']);
  7566. $cidinfo .= ' /Supplement '.$font['registry']['supplement'];
  7567. $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  7568. $this->_out('/FontDescriptor '.($this->n+1).' 0 R');
  7569. if (isset($font['MissingWidth'])){
  7570. $this->_out('/DW '.$font['MissingWidth'].'');
  7571. }
  7572. $this->_putfontwidths($font, 31); // mPDF 5.0
  7573. $this->_out('>>');
  7574. $this->_out('endobj');
  7575. //Font descriptor
  7576. $this->_newobj();
  7577. $s = '<</Type /FontDescriptor /FontName /'.$font['name'];
  7578. foreach ($font['desc'] as $k => $v) {
  7579. if ($k != 'Style') {
  7580. $s .= ' /'.$k.' '.$v.'';
  7581. }
  7582. }
  7583. $this->_out($s.'>>');
  7584. $this->_out('endobj');
  7585. }
  7586. function _putimages()
  7587. {
  7588. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  7589. reset($this->images);
  7590. while(list($file,$info)=each($this->images)) {
  7591. $this->_newobj();
  7592. $this->images[$file]['n']=$this->n;
  7593. $this->_out('<</Type /XObject');
  7594. $this->_out('/Subtype /Image');
  7595. $this->_out('/Width '.$info['w']);
  7596. $this->_out('/Height '.$info['h']);
  7597. if (isset($info['masked'])) {
  7598. $this->_out('/SMask '.($this->n - 1).' 0 R');
  7599. }
  7600. // mPDF 5.0.051
  7601. if($info['cs']=='Indexed') {
  7602. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) { $this->Error("PDFA1-b and PDFX/1-a files do not permit using mixed colour space (".$file.")."); }
  7603. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  7604. }
  7605. else {
  7606. $this->_out('/ColorSpace /'.$info['cs']);
  7607. if($info['cs']=='DeviceCMYK') {
  7608. if ($this->PDFA && $this->restrictColorSpace!=3) { $this->Error("PDFA1-b does not permit Images using mixed colour space (".$file.")."); }
  7609. if($info['type']=='jpg') { $this->_out('/Decode [1 0 1 0 1 0 1 0]'); }
  7610. }
  7611. else if ($info['cs']=='DeviceRGB' && ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3))) { $this->Error("PDFA1-b and PDFX/1-a files do not permit using mixed colour space (".$file.")."); }
  7612. }
  7613. $this->_out('/BitsPerComponent '.$info['bpc']);
  7614. if (isset($info['f']) && $info['f']) { $this->_out('/Filter /'.$info['f']); }
  7615. if(isset($info['parms'])) { $this->_out($info['parms']); }
  7616. if(isset($info['trns']) and is_array($info['trns'])) {
  7617. $trns='';
  7618. for($i=0;$i<count($info['trns']);$i++)
  7619. $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  7620. $this->_out('/Mask ['.$trns.']');
  7621. }
  7622. $this->_out('/Length '.strlen($info['data']).'>>');
  7623. $this->_putstream($info['data']);
  7624. unset($this->images[$file]['data']);
  7625. $this->_out('endobj');
  7626. //Palette
  7627. if($info['cs']=='Indexed') {
  7628. $this->_newobj();
  7629. $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  7630. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  7631. $this->_putstream($pal);
  7632. $this->_out('endobj');
  7633. }
  7634. }
  7635. }
  7636. function _putinfo()
  7637. {
  7638. $this->_out('/Producer '.$this->_UTF16BEtextstring('mPDF '.mPDF_VERSION));
  7639. if(!empty($this->title))
  7640. $this->_out('/Title '.$this->_UTF16BEtextstring($this->title));
  7641. if(!empty($this->subject))
  7642. $this->_out('/Subject '.$this->_UTF16BEtextstring($this->subject));
  7643. if(!empty($this->author))
  7644. $this->_out('/Author '.$this->_UTF16BEtextstring($this->author));
  7645. if(!empty($this->keywords))
  7646. $this->_out('/Keywords '.$this->_UTF16BEtextstring($this->keywords));
  7647. if(!empty($this->creator))
  7648. $this->_out('/Creator '.$this->_UTF16BEtextstring($this->creator));
  7649. $z = date('O'); // +0200
  7650. $offset = substr($z,0,3)."'".substr($z,3,2)."'";
  7651. $this->_out('/CreationDate '.$this->_textstring(date('YmdHis').$offset));
  7652. $this->_out('/ModDate '.$this->_textstring(date('YmdHis').$offset));
  7653. // mPDF 5.0.051
  7654. if ($this->PDFX) {
  7655. $this->_out('/Trapped/False');
  7656. $this->_out('/GTS_PDFXVersion(PDF/X-1a:2003)');
  7657. }
  7658. }
  7659. function _putmetadata() {
  7660. $this->_newobj();
  7661. $this->MetadataRoot = $this->n;
  7662. $Producer = 'mPDF '.mPDF_VERSION;
  7663. $z = date('O'); // +0200
  7664. $offset = substr($z,0,3).':'.substr($z,3,2);
  7665. $CreationDate = date('Y-m-d\TH:i:s').$offset; // 2006-03-10T10:47:26-05:00 2006-06-19T09:05:17Z
  7666. $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  7667. mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
  7668. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) );
  7669. $m = '<?xpacket begin="'.chr(239).chr(187).chr(191).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; // begin = FEFF BOM
  7670. $m .= ' <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701">'."\n";
  7671. $m .= ' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  7672. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  7673. $m .= ' <pdf:Producer>'.$Producer.'</pdf:Producer>'."\n";
  7674. if(!empty($this->keywords)) { $m .= ' <pdf:Keywords>'.$this->keywords.'</pdf:Keywords>'."\n"; }
  7675. $m .= ' </rdf:Description>'."\n";
  7676. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  7677. $m .= ' <xmp:CreateDate>'.$CreationDate.'</xmp:CreateDate>'."\n";
  7678. $m .= ' <xmp:ModifyDate>'.$CreationDate.'</xmp:ModifyDate>'."\n";
  7679. $m .= ' <xmp:MetadataDate>'.$CreationDate.'</xmp:MetadataDate>'."\n";
  7680. if(!empty($this->creator)) { $m .= ' <xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n"; }
  7681. $m .= ' </rdf:Description>'."\n";
  7682. // DC elements
  7683. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  7684. $m .= ' <dc:format>application/pdf</dc:format>'."\n";
  7685. if(!empty($this->title)) {
  7686. $m .= ' <dc:title>
  7687. <rdf:Alt>
  7688. <rdf:li xml:lang="x-default">'.$this->title.'</rdf:li>
  7689. </rdf:Alt>
  7690. </dc:title>'."\n";
  7691. }
  7692. if(!empty($this->keywords)) {
  7693. $m .= ' <dc:subject>
  7694. <rdf:Bag>
  7695. <rdf:li>'.$this->keywords.'</rdf:li>
  7696. </rdf:Bag>
  7697. </dc:subject>'."\n";
  7698. }
  7699. if(!empty($this->subject)) {
  7700. $m .= ' <dc:description>
  7701. <rdf:Alt>
  7702. <rdf:li xml:lang="x-default">'.$this->subject.'</rdf:li>
  7703. </rdf:Alt>
  7704. </dc:description>'."\n";
  7705. }
  7706. if(!empty($this->author)) {
  7707. $m .= ' <dc:creator>
  7708. <rdf:Seq>
  7709. <rdf:li>'.$this->author.'</rdf:li>
  7710. </rdf:Seq>
  7711. </dc:creator>'."\n";
  7712. }
  7713. $m .= ' </rdf:Description>'."\n";
  7714. // This bit is specific to PDFX-1a
  7715. if ($this->PDFX) {
  7716. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfx="http://ns.adobe.com/pdfx/1.3/" pdfx:Apag_PDFX_Checkup="1.3" pdfx:GTS_PDFXConformance="PDF/X-1a:2003" pdfx:GTS_PDFXVersion="PDF/X-1:2003"/>'."\n";
  7717. }
  7718. // This bit is specific to PDFA-1b
  7719. else if ($this->PDFA) {
  7720. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" >'."\n";
  7721. $m .= ' <pdfaid:part>1</pdfaid:part>'."\n";
  7722. $m .= ' <pdfaid:conformance>B</pdfaid:conformance>'."\n";
  7723. $m .= ' <pdfaid:amd>2005</pdfaid:amd>'."\n";
  7724. $m .= ' </rdf:Description>'."\n";
  7725. }
  7726. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  7727. $m .= ' <xmpMM:DocumentID>uuid:'.$uuid.'</xmpMM:DocumentID>'."\n";
  7728. $m .= ' </rdf:Description>'."\n";
  7729. $m .= ' </rdf:RDF>'."\n";
  7730. $m .= ' </x:xmpmeta>'."\n";
  7731. $m .= str_repeat(str_repeat(' ',100)."\n",20); // 2-4kB whitespace padding required
  7732. $m .= '<?xpacket end="w"?>'; // "r" read only
  7733. $this->_out('<</Type/Metadata/Subtype/XML/Length '.strlen($m).'>>');
  7734. $this->_putstream($m);
  7735. $this->_out('endobj');
  7736. }
  7737. function _putoutputintent() {
  7738. $this->_newobj();
  7739. $this->OutputIntentRoot = $this->n;
  7740. $this->_out('<</Type /OutputIntent');
  7741. if ($this->PDFA) {
  7742. $this->_out('/S /GTS_PDFA1');
  7743. if ($this->ICCProfile) {
  7744. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  7745. $this->_out('/OutputConditionIdentifier (Custom)');
  7746. $this->_out('/OutputCondition ()');
  7747. }
  7748. else {
  7749. $this->_out('/Info (sRGB IEC61966-2.1)');
  7750. $this->_out('/OutputConditionIdentifier (sRGB IEC61966-2.1)');
  7751. $this->_out('/OutputCondition ()');
  7752. }
  7753. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  7754. }
  7755. else if ($this->PDFX) { // always a CMYK profile
  7756. $this->_out('/S /GTS_PDFX');
  7757. if ($this->ICCProfile) {
  7758. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  7759. $this->_out('/OutputConditionIdentifier (Custom)');
  7760. $this->_out('/OutputCondition ()');
  7761. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  7762. }
  7763. else {
  7764. $this->_out('/Info (CGATS TR 001)');
  7765. $this->_out('/OutputConditionIdentifier (CGATS TR 001)');
  7766. $this->_out('/OutputCondition (CGATS TR 001 (SWOP))');
  7767. $this->_out('/RegistryName (http://www.color.org)');
  7768. }
  7769. }
  7770. $this->_out('>>');
  7771. $this->_out('endobj');
  7772. if ($this->PDFX && !$this->ICCProfile) { return; } // no ICCProfile embedded
  7773. $this->_newobj();
  7774. if ($this->ICCProfile)
  7775. $s = file_get_contents(_MPDF_PATH.'iccprofiles/'.$this->ICCProfile.'.icc');
  7776. else
  7777. $s = file_get_contents(_MPDF_PATH.'iccprofiles/sRGB_IEC61966-2-1.icc');
  7778. if ($this->compress) { $s = gzcompress($s); }
  7779. $this->_out('<<');
  7780. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace == 3)) { $this->_out('/N 4'); }
  7781. else { $this->_out('/N 3'); }
  7782. if ($this->compress)
  7783. $this->_out('/Filter /FlateDecode ');
  7784. $this->_out('/Length '.strlen($s).'>>');
  7785. $this->_putstream($s);
  7786. $this->_out('endobj');
  7787. }
  7788. function _putcatalog() {
  7789. $this->_out('/Type /Catalog');
  7790. $this->_out('/Pages 1 0 R');
  7791. if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]');
  7792. elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]');
  7793. elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  7794. elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  7795. else $this->_out('/OpenAction [3 0 R /XYZ null null null]');
  7796. if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage');
  7797. elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn');
  7798. elseif($this->LayoutMode=='twoleft') $this->_out('/PageLayout /TwoColumnLeft'); // mPDF 5.1.021
  7799. elseif($this->LayoutMode=='tworight') $this->_out('/PageLayout /TwoColumnRight'); // mPDF 5.1.021
  7800. elseif($this->LayoutMode=='two') {
  7801. if ($this->mirrorMargins) { $this->_out('/PageLayout /TwoColumnRight'); }
  7802. else { $this->_out('/PageLayout /TwoColumnLeft'); }
  7803. }
  7804. /*-- BOOKMARKS --*/
  7805. if(count($this->BMoutlines)>0) {
  7806. $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  7807. $this->_out('/PageMode /UseOutlines');
  7808. }
  7809. /*-- END BOOKMARKS --*/
  7810. if(is_int(strpos($this->DisplayPreferences,'FullScreen'))) $this->_out('/PageMode /FullScreen');
  7811. // Metadata
  7812. if ($this->PDFA || $this->PDFX) {
  7813. $this->_out('/Metadata '.$this->MetadataRoot.' 0 R');
  7814. }
  7815. // OutputIntents
  7816. if ($this->PDFA || $this->PDFX || $this->ICCProfile) {
  7817. $this->_out('/OutputIntents ['.$this->OutputIntentRoot.' 0 R]');
  7818. }
  7819. if($this->DisplayPreferences || $this->directionality == 'rtl' || $this->mirrorMargins) {
  7820. $this->_out('/ViewerPreferences<<');
  7821. if(is_int(strpos($this->DisplayPreferences,'HideMenubar'))) $this->_out('/HideMenubar true');
  7822. if(is_int(strpos($this->DisplayPreferences,'HideToolbar'))) $this->_out('/HideToolbar true');
  7823. if(is_int(strpos($this->DisplayPreferences,'HideWindowUI'))) $this->_out('/HideWindowUI true');
  7824. if(is_int(strpos($this->DisplayPreferences,'DisplayDocTitle'))) $this->_out('/DisplayDocTitle true');
  7825. if(is_int(strpos($this->DisplayPreferences,'CenterWindow'))) $this->_out('/CenterWindow true');
  7826. if(is_int(strpos($this->DisplayPreferences,'FitWindow'))) $this->_out('/FitWindow true');
  7827. // mPDF 5.0.051 /PrintScaling is PDF 1.6 spec.
  7828. if(is_int(strpos($this->DisplayPreferences,'NoPrintScaling')) && !$this->PDFA && !$this->PDFX)
  7829. $this->_out('/PrintScaling /None'); // mPDF 5.0.004
  7830. if($this->directionality == 'rtl') $this->_out('/Direction /R2L');
  7831. // mPDF 5.0.051 /Duplex is PDF 1.7 spec.
  7832. if($this->mirrorMargins && !$this->PDFA && !$this->PDFX) {
  7833. // if ($this->DefOrientation=='P') $this->_out('/Duplex /DuplexFlipShortEdge');
  7834. $this->_out('/Duplex /DuplexFlipLongEdge'); // PDF v1.7+
  7835. }
  7836. $this->_out('>>');
  7837. }
  7838. }
  7839. // Inactive function left for backwards compatability
  7840. function SetUserRights($enable=true, $annots="", $form="", $signature="") {
  7841. // Does nothing
  7842. }
  7843. function _enddoc() {
  7844. if ($this->progressBar) { $this->UpdateProgressBar(2,'10','Writing Headers & Footers'); } // *PROGRESS-BAR*
  7845. $this->_puthtmlheaders(); // *HTMLHEADERS-FOOTERS*
  7846. if ($this->progressBar) { $this->UpdateProgressBar(2,'20','Writing Pages'); } // *PROGRESS-BAR*
  7847. // Remove references to unused fonts (usually default font)
  7848. foreach($this->fonts as $fk=>$font) {
  7849. if (!$font['used'] && ($font['type']=='TTF')) {
  7850. if ($font['sip'] || $font['smp']) { // mPDF 5.0.03 Added SMP
  7851. foreach($font['subsetfontids'] AS $k => $fid) {
  7852. foreach($this->pages AS $pn=>$page) {
  7853. $this->pages[$pn] = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7854. }
  7855. }
  7856. }
  7857. else {
  7858. foreach($this->pages AS $pn=>$page) {
  7859. $this->pages[$pn] = preg_replace('/\s\/F'.$font['i'].' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7860. }
  7861. }
  7862. }
  7863. }
  7864. $this->_putpages();
  7865. if ($this->progressBar) { $this->UpdateProgressBar(2,'30','Writing document resources'); } // *PROGRESS-BAR*
  7866. $this->_putresources();
  7867. //Info
  7868. $this->_newobj();
  7869. $this->InfoRoot = $this->n;
  7870. $this->_out('<<');
  7871. if ($this->progressBar) { $this->UpdateProgressBar(2,'80','Writing document info'); } // *PROGRESS-BAR*
  7872. $this->_putinfo();
  7873. $this->_out('>>');
  7874. $this->_out('endobj');
  7875. // METADATA
  7876. if ($this->PDFA || $this->PDFX) { $this->_putmetadata(); }
  7877. // OUTPUTINTENT
  7878. if ($this->PDFA || $this->PDFX || $this->ICCProfile) { $this->_putoutputintent(); }
  7879. //Catalog
  7880. $this->_newobj();
  7881. $this->_out('<<');
  7882. if ($this->progressBar) { $this->UpdateProgressBar(2,'90','Writing document catalog'); } // *PROGRESS-BAR*
  7883. $this->_putcatalog();
  7884. $this->_out('>>');
  7885. $this->_out('endobj');
  7886. //Cross-ref
  7887. $o=strlen($this->buffer);
  7888. $this->_out('xref');
  7889. $this->_out('0 '.($this->n+1));
  7890. $this->_out('0000000000 65535 f ');
  7891. for($i=1; $i <= $this->n ; $i++)
  7892. $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  7893. //Trailer
  7894. $this->_out('trailer');
  7895. $this->_out('<<');
  7896. $this->_puttrailer();
  7897. $this->_out('>>');
  7898. $this->_out('startxref');
  7899. $this->_out($o);
  7900. $this->buffer .= '%%EOF';
  7901. $this->state=3;
  7902. /*-- IMPORTS --*/
  7903. if ($this->enableImports && count($this->parsers) > 0) {
  7904. foreach ($this->parsers as $k => $_){
  7905. $this->parsers[$k]->closeFile();
  7906. $this->parsers[$k] = null;
  7907. unset($this->parsers[$k]);
  7908. }
  7909. }
  7910. /*-- END IMPORTS --*/
  7911. }
  7912. function _beginpage($orientation,$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') {
  7913. $this->page++;
  7914. $this->pages[$this->page]='';
  7915. $this->state=2;
  7916. $resetHTMLHeadersrequired = false;
  7917. if ($newformat) { $this->_setPageSize($newformat, $orientation); }
  7918. /*-- CSS-PAGE --*/
  7919. // Paged media (page-box)
  7920. if ($pagesel || (isset($this->page_box['using']) && $this->page_box['using'])) {
  7921. if ($pagesel || $this->page==1) { $first = true; }
  7922. else { $first = false; }
  7923. if ($this->mirrorMargins && ($this->page % 2==0)) { $oddEven = 'E'; }
  7924. else { $oddEven = 'O'; }
  7925. if ($pagesel) { $psel = $pagesel; }
  7926. else if ($this->page_box['current']) { $psel = $this->page_box['current']; }
  7927. else { $psel = ''; }
  7928. list($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS($psel, $first, $oddEven);
  7929. if ($this->mirrorMargins && ($this->page % 2==0)) {
  7930. if ($hname) { $ehvalue = 1; $ehname = $hname; } else { $ehvalue = -1; }
  7931. if ($fname) { $efvalue = 1; $efname = $fname; } else { $efvalue = -1; }
  7932. }
  7933. else {
  7934. if ($hname) { $ohvalue = 1; $ohname = $hname; } else { $ohvalue = -1; }
  7935. if ($fname) { $ofvalue = 1; $ofname = $fname; } else { $ofvalue = -1; }
  7936. }
  7937. if ($resetpagenum || $pagenumstyle || $suppress) {
  7938. $this->PageNumSubstitutions[] = array('from'=>($this->page), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  7939. }
  7940. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  7941. $this->show_marks = $marks;
  7942. // Background color
  7943. if (isset($bg['BACKGROUND-COLOR'])) {
  7944. $cor = $this->ConvertColor($bg['BACKGROUND-COLOR']);
  7945. if ($cor) {
  7946. $this->bodyBackgroundColor = $cor;
  7947. }
  7948. }
  7949. else { $this->bodyBackgroundColor = false; }
  7950. /*-- BACKGROUNDS --*/
  7951. if (isset($bg['BACKGROUND-GRADIENT'])) {
  7952. $this->bodyBackgroundGradient = $bg['BACKGROUND-GRADIENT'];
  7953. }
  7954. else { $this->bodyBackgroundGradient = false; }
  7955. // Tiling Patterns
  7956. if (isset($bg['BACKGROUND-IMAGE']) && $bg['BACKGROUND-IMAGE']) {
  7957. // mPDF 5.0.023
  7958. $ret = $this->SetBackground($bg, $this->pgwidth);
  7959. if ($ret) { $this->bodyBackgroundImage = $ret; }
  7960. }
  7961. else { $this->bodyBackgroundImage = false; }
  7962. /*-- END BACKGROUNDS --*/
  7963. $this->page_box['current'] = $psel;
  7964. $this->page_box['using'] = true;
  7965. }
  7966. /*-- END CSS-PAGE --*/
  7967. //Page orientation
  7968. if(!$orientation)
  7969. $orientation=$this->DefOrientation;
  7970. else {
  7971. $orientation=strtoupper(substr($orientation,0,1));
  7972. if($orientation!=$this->DefOrientation)
  7973. $this->OrientationChanges[$this->page]=true;
  7974. }
  7975. if($orientation!=$this->CurOrientation || $newformat) {
  7976. //Change orientation
  7977. if($orientation=='P') {
  7978. $this->wPt=$this->fwPt;
  7979. $this->hPt=$this->fhPt;
  7980. $this->w=$this->fw;
  7981. $this->h=$this->fh;
  7982. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  7983. $this->tMargin = $this->orig_tMargin;
  7984. $this->bMargin = $this->orig_bMargin;
  7985. $this->DeflMargin = $this->orig_lMargin;
  7986. $this->DefrMargin = $this->orig_rMargin;
  7987. $this->margin_header = $this->orig_hMargin;
  7988. $this->margin_footer = $this->orig_fMargin;
  7989. }
  7990. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  7991. }
  7992. else {
  7993. $this->wPt=$this->fhPt;
  7994. $this->hPt=$this->fwPt;
  7995. $this->w=$this->fh;
  7996. $this->h=$this->fw;
  7997. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  7998. $this->tMargin = $this->orig_lMargin;
  7999. $this->bMargin = $this->orig_rMargin;
  8000. $this->DeflMargin = $this->orig_bMargin;
  8001. $this->DefrMargin = $this->orig_tMargin;
  8002. $this->margin_header = $this->orig_hMargin;
  8003. $this->margin_footer = $this->orig_fMargin;
  8004. }
  8005. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  8006. }
  8007. $this->CurOrientation=$orientation;
  8008. $this->ResetMargins();
  8009. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8010. $this->PageBreakTrigger=$this->h-$this->bMargin;
  8011. }
  8012. $this->pageDim[$this->page]['w']=$this->w ;
  8013. $this->pageDim[$this->page]['h']=$this->h ;
  8014. // mPDF 5.0.047
  8015. // mPDF 5.1.016
  8016. $this->pageDim[$this->page]['outer_width_LR'] = isset($this->page_box['outer_width_LR']) ? $this->page_box['outer_width_LR'] : 0;
  8017. $this->pageDim[$this->page]['outer_width_TB'] = isset($this->page_box['outer_width_TB']) ? $this->page_box['outer_width_TB'] : 0;
  8018. if (!isset($this->page_box['outer_width_LR']) && !isset($this->page_box['outer_width_TB'])) {
  8019. $this->pageDim[$this->page]['bleedMargin'] = 0;
  8020. }
  8021. else if ($this->bleedMargin <= $this->page_box['outer_width_LR'] && $this->bleedMargin <= $this->page_box['outer_width_TB']) {
  8022. $this->pageDim[$this->page]['bleedMargin'] = $this->bleedMargin;
  8023. }
  8024. else {
  8025. $this->pageDim[$this->page]['bleedMargin'] = min($this->page_box['outer_width_LR'], $this->page_box['outer_width_TB'])-0.01;
  8026. }
  8027. // If Page Margins are re-defined
  8028. // strlen()>0 is used to pick up (integer) 0, (string) '0', or set value
  8029. if ((strlen($mgl)>0 && $this->DeflMargin != $mgl) || (strlen($mgr)>0 && $this->DefrMargin != $mgr) || (strlen($mgt)>0 && $this->tMargin != $mgt) || (strlen($mgb)>0 && $this->bMargin != $mgb) || (strlen($mgh)>0 && $this->margin_header!=$mgh) || (strlen($mgf)>0 && $this->margin_footer!=$mgf)) {
  8030. if (strlen($mgl)>0) $this->DeflMargin = $mgl;
  8031. if (strlen($mgr)>0) $this->DefrMargin = $mgr;
  8032. if (strlen($mgt)>0) $this->tMargin = $mgt;
  8033. if (strlen($mgb)>0) $this->bMargin = $mgb;
  8034. if (strlen($mgh)>0) $this->margin_header=$mgh;
  8035. if (strlen($mgf)>0) $this->margin_footer=$mgf;
  8036. $this->ResetMargins();
  8037. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8038. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8039. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8040. }
  8041. $this->ResetMargins();
  8042. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8043. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8044. // Reset column top margin
  8045. $this->y0 = $this->tMargin;
  8046. $this->x=$this->lMargin;
  8047. $this->y=$this->tMargin;
  8048. $this->FontFamily='';
  8049. // HEADERS AND FOOTERS
  8050. if ($ohvalue<0 || strtoupper($ohvalue)=='OFF') {
  8051. $this->HTMLHeader = '';
  8052. $this->headerDetails['odd'] = array();
  8053. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8054. }
  8055. else if ($ohname && $ohvalue>0) {
  8056. /*-- HTMLHEADERS-FOOTERS --*/
  8057. if (preg_match('/^html_(.*)$/i',$ohname,$n)) {
  8058. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeader = $this->pageHTMLheaders[$n[1]]; }
  8059. else { $this->HTMLHeader = ''; }
  8060. $this->headerDetails['odd'] = array();
  8061. $resetHTMLHeadersrequired = true;
  8062. }
  8063. else {
  8064. /*-- END HTMLHEADERS-FOOTERS --*/
  8065. if (isset($this->pageheaders[$ohname])) { $this->headerDetails['odd'] = $this->pageheaders[$ohname]; }
  8066. else if ($ohname!='_default') { $this->headerDetails['odd'] = array(); } // mPDF 5.0.007
  8067. $this->HTMLHeader = '';
  8068. /*-- HTMLHEADERS-FOOTERS --*/
  8069. $resetHTMLHeadersrequired = false;
  8070. }
  8071. /*-- END HTMLHEADERS-FOOTERS --*/
  8072. }
  8073. if ($ehvalue<0 || strtoupper($ehvalue)=='OFF') {
  8074. $this->HTMLHeaderE = '';
  8075. $this->headerDetails['even'] = array();
  8076. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8077. }
  8078. else if ($ehname && $ehvalue>0) {
  8079. /*-- HTMLHEADERS-FOOTERS --*/
  8080. if (preg_match('/^html_(.*)$/i',$ehname,$n)) {
  8081. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeaderE = $this->pageHTMLheaders[$n[1]]; }
  8082. else { $this->HTMLHeaderE = ''; }
  8083. $this->headerDetails['even'] = array();
  8084. $resetHTMLHeadersrequired = true;
  8085. }
  8086. else {
  8087. /*-- END HTMLHEADERS-FOOTERS --*/
  8088. if (isset($this->pageheaders[$ehname])) { $this->headerDetails['even'] = $this->pageheaders[$ehname]; }
  8089. else if ($ehname!='_default') { $this->headerDetails['even'] = array(); } // mPDF 5.0.007
  8090. $this->HTMLHeaderE = '';
  8091. /*-- HTMLHEADERS-FOOTERS --*/
  8092. $resetHTMLHeadersrequired = false;
  8093. }
  8094. /*-- END HTMLHEADERS-FOOTERS --*/
  8095. }
  8096. if ($ofvalue<0 || strtoupper($ofvalue)=='OFF') {
  8097. $this->HTMLFooter = '';
  8098. $this->footerDetails['odd'] = array();
  8099. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8100. }
  8101. else if ($ofname && $ofvalue>0) {
  8102. /*-- HTMLHEADERS-FOOTERS --*/
  8103. if (preg_match('/^html_(.*)$/i',$ofname,$n)) {
  8104. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooter = $this->pageHTMLfooters[$n[1]]; }
  8105. else { $this->HTMLFooter = ''; }
  8106. $this->footerDetails['odd'] = array();
  8107. $resetHTMLHeadersrequired = true;
  8108. }
  8109. else {
  8110. /*-- END HTMLHEADERS-FOOTERS --*/
  8111. if (isset($this->pagefooters[$ofname])) { $this->footerDetails['odd'] = $this->pagefooters[$ofname]; }
  8112. else if ($ofname!='_default') { $this->footerDetails['odd'] = array(); } // mPDF 5.0.007
  8113. $this->HTMLFooter = '';
  8114. /*-- HTMLHEADERS-FOOTERS --*/
  8115. $resetHTMLHeadersrequired = true;
  8116. }
  8117. /*-- END HTMLHEADERS-FOOTERS --*/
  8118. }
  8119. if ($efvalue<0 || strtoupper($efvalue)=='OFF') {
  8120. $this->HTMLFooterE = '';
  8121. $this->footerDetails['even'] = array();
  8122. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8123. }
  8124. else if ($efname && $efvalue>0) {
  8125. /*-- HTMLHEADERS-FOOTERS --*/
  8126. if (preg_match('/^html_(.*)$/i',$efname,$n)) {
  8127. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooterE = $this->pageHTMLfooters[$n[1]]; }
  8128. else { $this->HTMLFooterE = ''; }
  8129. $this->footerDetails['even'] = array();
  8130. $resetHTMLHeadersrequired = true;
  8131. }
  8132. else {
  8133. /*-- END HTMLHEADERS-FOOTERS --*/
  8134. if (isset($this->pagefooters[$efname])) { $this->footerDetails['even'] = $this->pagefooters[$efname]; }
  8135. else if ($efname!='_default') { $this->footerDetails['even'] = array(); } // mPDF 5.0.007
  8136. $this->HTMLFooterE = '';
  8137. /*-- HTMLHEADERS-FOOTERS --*/
  8138. $resetHTMLHeadersrequired = true;
  8139. }
  8140. /*-- END HTMLHEADERS-FOOTERS --*/
  8141. }
  8142. /*-- HTMLHEADERS-FOOTERS --*/
  8143. if ($resetHTMLHeadersrequired) {
  8144. $this->SetHTMLHeader($this->HTMLHeader );
  8145. $this->SetHTMLHeader($this->HTMLHeaderE ,'E');
  8146. $this->SetHTMLFooter($this->HTMLFooter );
  8147. $this->SetHTMLFooter($this->HTMLFooterE ,'E');
  8148. }
  8149. /*-- END HTMLHEADERS-FOOTERS --*/
  8150. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  8151. $this->_setAutoHeaderHeight($this->headerDetails['even'], $this->HTMLHeaderE);
  8152. $this->_setAutoFooterHeight($this->footerDetails['even'], $this->HTMLFooterE);
  8153. }
  8154. else { // ODD or DEFAULT
  8155. $this->_setAutoHeaderHeight($this->headerDetails['odd'], $this->HTMLHeader);
  8156. $this->_setAutoFooterHeight($this->footerDetails['odd'], $this->HTMLFooter);
  8157. }
  8158. // Reset column top margin
  8159. $this->y0 = $this->tMargin;
  8160. $this->x=$this->lMargin;
  8161. $this->y=$this->tMargin;
  8162. }
  8163. function _setAutoHeaderHeight(&$det, &$htmlh) {
  8164. if ($this->setAutoTopMargin=='pad') {
  8165. if ($htmlh['h']) { $h = $htmlh['h']; }
  8166. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8167. else { $h = 0; }
  8168. $this->tMargin = $this->margin_header + $h + $this->orig_tMargin;
  8169. }
  8170. else if ($this->setAutoTopMargin=='stretch') {
  8171. if ($htmlh['h']) { $h = $htmlh['h']; }
  8172. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8173. else { $h = 0; }
  8174. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $h + $this->autoMarginPadding);
  8175. }
  8176. }
  8177. function _setAutoFooterHeight(&$det, &$htmlf) {
  8178. if ($this->setAutoBottomMargin=='pad') {
  8179. if ($htmlf['h']) { $h = $htmlf['h']; }
  8180. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8181. else { $h = 0; }
  8182. $this->bMargin = $this->margin_footer + $h + $this->orig_bMargin;
  8183. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8184. }
  8185. else if ($this->setAutoBottomMargin=='stretch') {
  8186. if ($htmlf['h']) { $h = $htmlf['h']; }
  8187. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8188. else { $h = 0; }
  8189. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $h + $this->autoMarginPadding);
  8190. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8191. }
  8192. }
  8193. function _getHFHeight(&$det,$end) {
  8194. $h = 0;
  8195. if(count($det)) {
  8196. foreach(array('L','C','R') AS $pos) {
  8197. if (isset($det[$pos]['content']) && $det[$pos]['content']) {
  8198. if (isset($det[$pos]['font-size']) && $det[$pos]['font-size']) { $hfsz = $det[$pos]['font-size']; }
  8199. else { $hfsz = $this->default_font_size; }
  8200. $h = max($h,$hfsz/$this->k);
  8201. }
  8202. }
  8203. if ($det['line'] && $end=='H') { $h += $h/$this->k*$this->header_line_spacing; }
  8204. else if ($det['line'] && $end=='F') { $h += $h/$this->k*$this->footer_line_spacing; }
  8205. }
  8206. return $h;
  8207. }
  8208. function _endpage() {
  8209. /*-- CSS-IMAGE-FLOAT --*/
  8210. $this->printfloatbuffer();
  8211. /*-- END CSS-IMAGE-FLOAT --*/
  8212. //End of page contents
  8213. $this->state=1;
  8214. }
  8215. function _newobj($obj_id=false,$onlynewobj=false) {
  8216. if (!$obj_id) {
  8217. $obj_id = ++$this->n;
  8218. }
  8219. //Begin a new object
  8220. if (!$onlynewobj) {
  8221. $this->offsets[$obj_id] = strlen($this->buffer);
  8222. $this->_out($obj_id.' 0 obj');
  8223. $this->_current_obj_id = $obj_id; // for later use with encryption
  8224. }
  8225. }
  8226. function _dounderline($x,$y,$txt) {
  8227. // Now print line exactly where $y secifies - called from Text() and Cell() - adjust position there
  8228. // WORD SPACING
  8229. $w =($this->GetStringWidth($txt)*$this->k) + ($this->charspacing * mb_strlen( $txt, $this->mb_enc ))
  8230. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ));
  8231. //Draw a line
  8232. return sprintf('%.3f %.3f m %.3f %.3f l S',$x*$this->k,($this->h-$y)*$this->k,($x*$this->k)+$w,($this->h-$y)*$this->k);
  8233. }
  8234. function _imageError($file, $firsttime, $msg) {
  8235. // Save re-trying image URL's which have already failed
  8236. $this->failedimages[$file] = true;
  8237. if ($firsttime && ($this->showImageErrors || $this->debug)) {
  8238. $this->Error("IMAGE Error (".$file."): ".$msg);
  8239. }
  8240. return false;
  8241. }
  8242. function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false) {
  8243. // firsttime i.e. whether to add to this->images - use false when calling iteratively
  8244. // Image Data passed directly as var:varname
  8245. if (preg_match('/var:\s*(.*)/',$file, $v)) {
  8246. $data = $this->$v[1];
  8247. $file = md5($data);
  8248. }
  8249. $ppUx = 0; // mPDF 5.0.051
  8250. if ($firsttime && preg_match('/(.*\/)([^\/]*)/',$file,$fm)) {
  8251. if (strlen($fm[2])) { $file = $fm[1].preg_replace('/ /','%20',$fm[2]); }
  8252. }
  8253. if ($orig_srcpath && isset($this->images[$orig_srcpath])) { $file=$orig_srcpath; return $this->images[$orig_srcpath]; }
  8254. if (isset($this->images[$file])) { return $this->images[$file]; }
  8255. else if ($orig_srcpath && isset($this->formobjects[$orig_srcpath])) { $file=$orig_srcpath; return $this->formobjects[$file]; }
  8256. else if (isset($this->formobjects[$file])) { return $this->formobjects[$file]; }
  8257. // Save re-trying image URL's which have already failed
  8258. else if ($firsttime && isset($this->failedimages[$file])) { return $this->_imageError($file, $firsttime, ''); }
  8259. if (empty($data)) { // mPDF 5.0.052
  8260. $type = '';
  8261. $data = '';
  8262. $mqr=$this->_getMQR(); // mPDF 5.0
  8263. if ($mqr) { set_magic_quotes_runtime(0); }
  8264. if ($orig_srcpath && $this->basepathIsLocal && $check = @fopen($orig_srcpath,"rb")) {
  8265. fclose($check);
  8266. $file=$orig_srcpath;
  8267. $data = file_get_contents($file);
  8268. $type = $this->_imageTypeFromString($data);
  8269. }
  8270. if (!$data && $check = @fopen($file,"rb")) {
  8271. fclose($check);
  8272. $data = file_get_contents($file);
  8273. $type = $this->_imageTypeFromString($data);
  8274. }
  8275. if ((!$data || !$type) && !ini_get('allow_url_fopen')) { // only worth trying if remote file and !ini_get('allow_url_fopen')
  8276. $this->file_get_contents_by_socket($file, $data); // needs full url?? even on local (never needed for local)
  8277. if ($data) { $type = $this->_imageTypeFromString($data); }
  8278. }
  8279. if ((!$data || !$type) && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  8280. $this->file_get_contents_by_curl($file, $data); // needs full url?? even on local (never needed for local)
  8281. if ($data) { $type = $this->_imageTypeFromString($data); }
  8282. }
  8283. if ($mqr) { set_magic_quotes_runtime($mqr); }
  8284. }
  8285. if (!$data) { return $this->_imageError($file, $firsttime, 'Could not find image file'); }
  8286. if (empty($type)) { $type = $this->_imageTypeFromString($data); } // mPDF 5.0.052
  8287. if (($type == 'wmf' || $type == 'svg') && !$allowvector) { return $this->_imageError($file, $firsttime, 'WMF or SVG image file not supported in this context'); }
  8288. // SVG
  8289. if ($type == 'svg') {
  8290. if (!class_exists('SVG', false)) { include(_MPDF_PATH .'classes/svg.php'); }
  8291. $svg = new SVG($this);
  8292. $family=$this->FontFamily;
  8293. $style=$this->FontStyle;
  8294. $size=$this->FontSizePt;
  8295. $info = $svg->ImageSVG($data);
  8296. //Restore font
  8297. if($family) $this->SetFont($family,$style,$size,false);
  8298. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing SVG file'); }
  8299. $info['type']='svg';
  8300. $info['i']=count($this->formobjects)+1;
  8301. $this->formobjects[$file]=$info;
  8302. return $info;
  8303. }
  8304. // JPEG
  8305. if ($type == 'jpeg' || $type == 'jpg') {
  8306. $hdr = $this->_jpgHeaderFromString($data);
  8307. if (!$hdr) { return $this->_imageError($file, $firsttime, 'Error parsing JPG header'); }
  8308. $a = $this->_jpgDataFromHeader($hdr);
  8309. // mPDF 5.0.031
  8310. $j = strpos($data,'JFIF');
  8311. if ($j) {
  8312. //Read resolution
  8313. $unitSp=ord(substr($data,($j+7),1));
  8314. if ($unitSp > 0) {
  8315. $ppUx=$this->_twobytes2int(substr($data,($j+8),2)); // horizontal pixels per meter, usually set to zero
  8316. //$ppUy=$this->_twobytes2int(substr($data,($j+10),2)); // vertical pixels per meter, usually set to zero
  8317. if ($unitSp == 2) { // = dots per cm (if == 1 set as dpi)
  8318. $ppUx=round($ppUx/10 *25.4);
  8319. //$ppUy=round($ppUy/10 *25.4);
  8320. }
  8321. }
  8322. }
  8323. // mPDF 5.0.051
  8324. if ($a[2] == 'DeviceCMYK' && (($this->PDFA && $this->restrictColorSpace!=3) || $this->restrictColorSpace==2)) {
  8325. // convert to RGB image
  8326. if (!function_exists("gd_info")) { $this->Error("JPG image may not use CMYK color space (".$file.")."); }
  8327. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "JPG image may not use CMYK color space - ".$file." - (Image converted to RGB. NB This will alter the colour profile of the image.)"; }
  8328. $im = @imagecreatefromstring($data);
  8329. if ($im) {
  8330. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8331. imageinterlace($im, false);
  8332. $check = @imagepng($im, $tempfile);
  8333. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse JPG(CMYK) image'); }
  8334. $info = $this->_getImage($tempfile, false);
  8335. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse JPG(CMYK) image'); }
  8336. imagedestroy($im);
  8337. unlink($tempfile);
  8338. $info['type']='jpg';
  8339. if ($firsttime) {
  8340. $info['i']=count($this->images)+1;
  8341. $this->images[$file]=$info;
  8342. }
  8343. return $info;
  8344. }
  8345. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from JPG(CMYK) image'); }
  8346. }
  8347. // mPDF 5.0.051
  8348. else if ($a[2] == 'DeviceRGB' && ($this->PDFX || $this->restrictColorSpace==3)) {
  8349. // Convert to CMYK image stream - nominally returned as type='png'
  8350. $info = $this->_convImage($data, $a[2], 'DeviceCMYK', $a[0], $a[1], $ppUx, false);
  8351. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "JPG image may not use RGB color space - ".$file." - (Image converted to CMYK. NB This will alter the colour profile of the image.)"; }
  8352. }
  8353. // mPDF 5.0.051
  8354. else if (($a[2] == 'DeviceRGB' || $a[2] == 'DeviceCMYK') && $this->restrictColorSpace==1) {
  8355. // Convert to Grayscale image stream - nominally returned as type='png'
  8356. $info = $this->_convImage($data, $a[2], 'DeviceGray', $a[0], $a[1], $ppUx, false);
  8357. }
  8358. else {
  8359. $info = array('w'=>$a[0],'h'=>$a[1],'cs'=>$a[2],'bpc'=>$a[3],'f'=>'DCTDecode','data'=>$data, 'type'=>'jpg');
  8360. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8361. }
  8362. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting JPG image'); }
  8363. if ($firsttime) {
  8364. $info['i']=count($this->images)+1;
  8365. $this->images[$file]=$info;
  8366. }
  8367. return $info;
  8368. }
  8369. // PNG
  8370. else if ($type == 'png') {
  8371. //Check signature
  8372. if(substr($data,0,8)!=$this->chrs[137].'PNG'.$this->chrs[13].$this->chrs[10].$this->chrs[26].$this->chrs[10]) {
  8373. return $this->_imageError($file, $firsttime, 'Error parsing PNG identifier');
  8374. }
  8375. //Read header chunk
  8376. if(substr($data,12,4)!='IHDR') {
  8377. return $this->_imageError($file, $firsttime, 'Incorrect PNG file (no IHDR block found)');
  8378. }
  8379. $w=$this->_fourbytes2int(substr($data,16,4));
  8380. $h=$this->_fourbytes2int(substr($data,20,4));
  8381. $bpc=$this->ords[substr($data,24,1)];
  8382. $errpng = false;
  8383. $pngalpha = false;
  8384. if($bpc>8) { $errpng = 'not 8-bit depth'; }
  8385. $ct=$this->ords[substr($data,25,1)];
  8386. if($ct==0) { $colspace='DeviceGray'; }
  8387. elseif($ct==2) { $colspace='DeviceRGB'; }
  8388. elseif($ct==3) { $colspace='Indexed'; }
  8389. elseif($ct==4) { $colspace='DeviceGray'; $errpng = 'alpha channel'; $pngalpha = true; }
  8390. else { $colspace='DeviceRGB'; $errpng = 'alpha channel'; $pngalpha = true; }
  8391. if($this->ords[substr($data,26,1)]!=0) { $errpng = 'compression method'; }
  8392. if($this->ords[substr($data,27,1)]!=0) { $errpng = 'filter method'; }
  8393. if($this->ords[substr($data,28,1)]!=0) { $errpng = 'interlaced file'; }
  8394. // mPDF 5.0.031
  8395. $j = strpos($data,'pHYs');
  8396. if ($j) {
  8397. //Read resolution
  8398. $unitSp=ord(substr($data,($j+12),1));
  8399. if ($unitSp == 1) {
  8400. $ppUx=$this->_fourbytes2int(substr($data,($j+4),4)); // horizontal pixels per meter, usually set to zero
  8401. //$ppUy=$this->_fourbytes2int(substr($data,($j+8),4)); // vertical pixels per meter, usually set to zero
  8402. $ppUx=round($ppUx/1000 *25.4);
  8403. //$ppUy=round($ppUy/1000 *25.4);
  8404. }
  8405. }
  8406. // mPDF 5.0.051
  8407. if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && ($this->PDFX || $this->restrictColorSpace==3)) {
  8408. // Convert to CMYK image stream - nominally returned as type='png'
  8409. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8410. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "JPG image may not use RGB color space - ".$file." - (Image converted to CMYK. NB This will alter the colour profile of the image.)"; }
  8411. }
  8412. // mPDF 5.0.051
  8413. else if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && $this->restrictColorSpace==1) {
  8414. // Convert to Grayscale image stream - nominally returned as type='png'
  8415. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8416. }
  8417. // mPDF 5.0.051
  8418. else if (($this->PDFA || $this->PDFX) && $pngalpha) {
  8419. // Remove alpha channel
  8420. if ($this->restrictColorSpace==1) { // Grayscale
  8421. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8422. }
  8423. else if ($this->restrictColorSpace==3) { // CMYK
  8424. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8425. }
  8426. else if ($this->PDFA ) { // RGB
  8427. $info = $this->_convImage($data, $colspace, 'DeviceRGB', $w, $h, $ppUx, $pngalpha);
  8428. }
  8429. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Transparency (alpha channel) not permitted in PDFA or PDFX files - ".$file." - (Image converted to one without transparency.)"; }
  8430. }
  8431. else if ($errpng || $pngalpha) {
  8432. if (function_exists('gd_info')) { $gd = gd_info(); }
  8433. else {$gd = array(); }
  8434. if (!isset($gd['PNG Support'])) { return $this->_imageError($file, $firsttime, 'GD library required for PNG image ('.$errpng.')'); }
  8435. $im = imagecreatefromstring($data);
  8436. if (!$im) { return $this->_imageError($file, $firsttime, 'Error creating GD image from PNG file ('.$errpng.')'); }
  8437. $w = imagesx($im);
  8438. $h = imagesy($im);
  8439. if ($im) {
  8440. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8441. // Alpha channel set
  8442. if ($pngalpha) {
  8443. if ($this->PDFA) { $this->Error("PDFA1-b does not permit images with alpha channel transparency (".$file.")."); }
  8444. $imgalpha = imagecreate($w, $h);
  8445. // generate gray scale pallete
  8446. for ($c = 0; $c < 256; ++$c) { ImageColorAllocate($imgalpha, $c, $c, $c); }
  8447. // extract alpha channel
  8448. for ($xpx = 0; $xpx < $w; ++$xpx) {
  8449. for ($ypx = 0; $ypx < $h; ++$ypx) {
  8450. $colorindex = imagecolorat($im, $xpx, $ypx);
  8451. $col = imagecolorsforindex($im, $colorindex);
  8452. $gammacorr = 2.2; // gamma correction
  8453. $gamma = (pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255);
  8454. imagesetpixel($imgalpha, $xpx, $ypx, $gamma);
  8455. }
  8456. }
  8457. // create temp alpha file
  8458. $tempfile_alpha = _MPDF_TEMP_PATH.'_tempMskPNG'.RAND(1,10000).'.png';
  8459. // mPDF 5.0
  8460. if (!is_writable($tempfile_alpha)) {
  8461. ob_start();
  8462. $check = @imagepng($imgalpha);
  8463. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8464. imagedestroy($imgalpha);
  8465. $this->_tempimg = ob_get_contents();
  8466. $this->_tempimglnk = 'var:_tempimg';
  8467. ob_end_clean();
  8468. // extract image without alpha channel
  8469. $imgplain = imagecreatetruecolor($w, $h);
  8470. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8471. // create temp image file
  8472. $minfo = $this->_getImage($this->_tempimglnk, false);
  8473. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8474. ob_start();
  8475. $check = @imagepng($imgplain);
  8476. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8477. $this->_tempimg = ob_get_contents();
  8478. $this->_tempimglnk = 'var:_tempimg';
  8479. ob_end_clean();
  8480. $info = $this->_getImage($this->_tempimglnk, false);
  8481. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8482. imagedestroy($imgplain);
  8483. $imgmask = count($this->images)+1;
  8484. $minfo['cs'] = 'DeviceGray';
  8485. $minfo['i']=$imgmask ;
  8486. $this->images[$tempfile_alpha] = $minfo;
  8487. }
  8488. else {
  8489. $check = @imagepng($imgalpha, $tempfile_alpha);
  8490. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile_alpha.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8491. imagedestroy($imgalpha);
  8492. // extract image without alpha channel
  8493. $imgplain = imagecreatetruecolor($w, $h);
  8494. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8495. // create temp image file
  8496. $check = @imagepng($imgplain, $tempfile);
  8497. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8498. imagedestroy($imgplain);
  8499. // embed mask image
  8500. $minfo = $this->_getImage($tempfile_alpha, false);
  8501. unlink($tempfile_alpha);
  8502. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile_alpha.') created with GD library to parse PNG image'); }
  8503. $imgmask = count($this->images)+1;
  8504. $minfo['cs'] = 'DeviceGray';
  8505. $minfo['i']=$imgmask ;
  8506. $this->images[$tempfile_alpha] = $minfo;
  8507. // embed image, masked with previously embedded mask
  8508. $info = $this->_getImage($tempfile, false);
  8509. unlink($tempfile);
  8510. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8511. }
  8512. $info['masked'] = $imgmask;
  8513. if ($ppUx) { $info['set-dpi'] = $ppUx; } // mPDF 5.0.051
  8514. $info['type']='png';
  8515. if ($firsttime) {
  8516. $info['i']=count($this->images)+1;
  8517. $this->images[$file]=$info;
  8518. }
  8519. return $info;
  8520. }
  8521. else { // No alpha/transparency set
  8522. imagealphablending($im, false);
  8523. imagesavealpha($im, false);
  8524. imageinterlace($im, false);
  8525. // mPDF 5.0
  8526. if (!is_writable($tempfile)) {
  8527. ob_start();
  8528. $check = @imagepng($im);
  8529. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8530. $this->_tempimg = ob_get_contents();
  8531. $this->_tempimglnk = 'var:_tempimg';
  8532. ob_end_clean();
  8533. $info = $this->_getImage($this->_tempimglnk, false);
  8534. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8535. imagedestroy($im);
  8536. }
  8537. else {
  8538. $check = @imagepng($im, $tempfile );
  8539. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image ('.$errpng.')'); }
  8540. imagedestroy($im);
  8541. $info = $this->_getImage($tempfile, false) ;
  8542. unlink($tempfile );
  8543. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8544. }
  8545. if ($ppUx) { $info['set-dpi'] = $ppUx; } // mPDF 5.0.051
  8546. $info['type']='png';
  8547. if ($firsttime) {
  8548. $info['i']=count($this->images)+1;
  8549. $this->images[$file]=$info;
  8550. }
  8551. return $info;
  8552. }
  8553. }
  8554. }
  8555. else {
  8556. $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  8557. //Scan chunks looking for palette, transparency and image data
  8558. $pal='';
  8559. $trns='';
  8560. $pngdata='';
  8561. $p = 33;
  8562. do {
  8563. $n=$this->_fourbytes2int(substr($data,$p,4)); $p += 4;
  8564. $type=substr($data,$p,4); $p += 4;
  8565. if($type=='PLTE') {
  8566. //Read palette
  8567. $pal=substr($data,$p,$n); $p += $n;
  8568. $p += 4;
  8569. }
  8570. elseif($type=='tRNS') {
  8571. //Read transparency info
  8572. $t=substr($data,$p,$n); $p += $n;
  8573. if($ct==0) $trns=array($this->ords[substr($t,1,1)]);
  8574. elseif($ct==2) $trns=array($this->ords[substr($t,1,1)],$this->ords[substr($t,3,1)],$this->ords[substr($t,5,1)]);
  8575. else
  8576. {
  8577. $pos=strpos($t,$this->chrs[0]);
  8578. if(is_int($pos)) $trns=array($pos);
  8579. }
  8580. $p += 4;
  8581. }
  8582. elseif($type=='IDAT') {
  8583. $pngdata.=substr($data,$p,$n); $p += $n;
  8584. $p += 4;
  8585. }
  8586. elseif($type=='IEND') { break; }
  8587. else if (preg_match('/[a-zA-Z]{4}/',$type)) { $p += $n+4; }
  8588. else { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data'); }
  8589. }
  8590. while($n);
  8591. if (!$pngdata) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - no IDAT data found'); }
  8592. if($colspace=='Indexed' and empty($pal)) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - missing colour palette'); }
  8593. $info = array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$pngdata);
  8594. $info['type']='png';
  8595. if ($ppUx) { $info['set-dpi'] = $ppUx; } // mPDF 5.0.051
  8596. }
  8597. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting PNG image'); }
  8598. if ($firsttime) {
  8599. $info['i']=count($this->images)+1;
  8600. $this->images[$file]=$info;
  8601. }
  8602. return $info;
  8603. }
  8604. // GIF
  8605. else if ($type == 'gif') {
  8606. if (function_exists('gd_info')) { $gd = gd_info(); }
  8607. else {$gd = array(); }
  8608. if (isset($gd['GIF Read Support']) && $gd['GIF Read Support']) {
  8609. $im = @imagecreatefromstring($data);
  8610. if ($im) {
  8611. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8612. imagealphablending($im, false);
  8613. imagesavealpha($im, false);
  8614. imageinterlace($im, false);
  8615. // mPDF 5.0
  8616. if (!is_writable($tempfile)) {
  8617. ob_start();
  8618. $check = @imagepng($im);
  8619. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse GIF image'); }
  8620. $this->_tempimg = ob_get_contents();
  8621. $this->_tempimglnk = 'var:_tempimg';
  8622. ob_end_clean();
  8623. $info = $this->_getImage($this->_tempimglnk, false);
  8624. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse GIF image'); }
  8625. imagedestroy($im);
  8626. }
  8627. else {
  8628. $check = @imagepng($im, $tempfile);
  8629. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse GIF image'); }
  8630. $info = $this->_getImage($tempfile, false);
  8631. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse GIF image'); }
  8632. imagedestroy($im);
  8633. unlink($tempfile);
  8634. }
  8635. $info['type']='gif';
  8636. if ($firsttime) {
  8637. $info['i']=count($this->images)+1;
  8638. $this->images[$file]=$info;
  8639. }
  8640. return $info;
  8641. }
  8642. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from GIF image'); }
  8643. }
  8644. if (!class_exists('gif', false)) {
  8645. include_once(_MPDF_PATH.'classes/gif.php');
  8646. }
  8647. $gif=new CGIF(); // mPDF 5.0.012
  8648. $h=0;
  8649. $w=0;
  8650. $gif->loadFile($data, 0);
  8651. if(isset($gif->m_img->m_gih->m_bLocalClr) && $gif->m_img->m_gih->m_bLocalClr) {
  8652. $nColors = $gif->m_img->m_gih->m_nTableSize;
  8653. $pal = $gif->m_img->m_gih->m_colorTable->toString();
  8654. if($bgColor != -1) {
  8655. $bgColor = $gif->m_img->m_gih->m_colorTable->colorIndex($bgColor);
  8656. }
  8657. $colspace='Indexed';
  8658. } elseif(isset($gif->m_gfh->m_bGlobalClr) && $gif->m_gfh->m_bGlobalClr) {
  8659. $nColors = $gif->m_gfh->m_nTableSize;
  8660. $pal = $gif->m_gfh->m_colorTable->toString();
  8661. if((isset($bgColor)) and $bgColor != -1) {
  8662. $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor);
  8663. }
  8664. $colspace='Indexed';
  8665. } else {
  8666. $nColors = 0;
  8667. $bgColor = -1;
  8668. $colspace='DeviceGray';
  8669. $pal='';
  8670. }
  8671. $trns='';
  8672. if(isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans && ($nColors > 0)) {
  8673. $trns=array($gif->m_img->m_nTrans);
  8674. }
  8675. $gifdata=$gif->m_img->m_data;
  8676. $w=$gif->m_gfh->m_nWidth;
  8677. $h=$gif->m_gfh->m_nHeight;
  8678. $gif->ClearData();
  8679. if($colspace=='Indexed' and empty($pal)) {
  8680. return $this->_imageError($file, $firsttime, 'Error parsing GIF image - missing colour palette');
  8681. }
  8682. if ($this->compress) {
  8683. $gifdata=gzcompress($gifdata);
  8684. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8685. }
  8686. else {
  8687. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8688. }
  8689. $info['type']='gif';
  8690. if ($firsttime) {
  8691. $info['i']=count($this->images)+1;
  8692. $this->images[$file]=$info;
  8693. }
  8694. return $info;
  8695. }
  8696. // BMP (Windows Bitmap)
  8697. else if ($type == 'bmp') {
  8698. // Adapted from script by Valentin Schmidt
  8699. // http://staff.dasdeck.de/valentin/fpdf/fpdf_bmp/
  8700. $bfOffBits=$this->_fourbytes2int_le(substr($data,10,4));
  8701. $width=$this->_fourbytes2int_le(substr($data,18,4));
  8702. $height=$this->_fourbytes2int_le(substr($data,22,4));
  8703. $flip = ($height<0);
  8704. if ($flip) $height =-$height;
  8705. $biBitCount=$this->_twobytes2int_le(substr($data,28,2));
  8706. $biCompression=$this->_fourbytes2int_le(substr($data,30,4));
  8707. $info = array('w'=>$width, 'h'=>$height);
  8708. if ($biBitCount<16){
  8709. $info['cs'] = 'Indexed';
  8710. $info['bpc'] = $biBitCount;
  8711. $palStr = substr($data,54,($bfOffBits-54));
  8712. $pal = '';
  8713. $cnt = strlen($palStr)/4;
  8714. for ($i=0;$i<$cnt;$i++){
  8715. $n = 4*$i;
  8716. $pal .= $palStr[$n+2].$palStr[$n+1].$palStr[$n];
  8717. }
  8718. $info['pal'] = $pal;
  8719. }
  8720. else{
  8721. $info['cs'] = 'DeviceRGB';
  8722. $info['bpc'] = 8;
  8723. }
  8724. // mPDF 5.0.051
  8725. if ($this->restrictColorSpace==1 || $this->PDFX || $this->restrictColorSpace==3) {
  8726. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Image cannot be converted to suitable colour space for PDFA or PDFX file - ".$file." - (Image replaced by 'no-image'.)"; }
  8727. return $this->_imageError($file, $firsttime, "BMP Image cannot be converted to suitable colour space - ".$file." - (Image replaced by 'no-image'.)");
  8728. }
  8729. // mPDF 5.0.031
  8730. $biXPelsPerMeter=$this->_fourbytes2int_le(substr($data,38,4)); // horizontal pixels per meter, usually set to zero
  8731. //$biYPelsPerMeter=$this->_fourbytes2int_le(substr($data,42,4)); // vertical pixels per meter, usually set to zero
  8732. $biXPelsPerMeter=round($biXPelsPerMeter/1000 *25.4);
  8733. //$biYPelsPerMeter=round($biYPelsPerMeter/1000 *25.4);
  8734. $info['set-dpi'] = $biXPelsPerMeter;
  8735. switch ($biCompression){
  8736. case 0:
  8737. $str = substr($data,$bfOffBits);
  8738. break;
  8739. case 1: # BI_RLE8
  8740. $str = $this->rle8_decode(substr($data,$bfOffBits), $width);
  8741. break;
  8742. case 2: # BI_RLE4
  8743. $str = $this->rle4_decode(substr($data,$bfOffBits), $width);
  8744. break;
  8745. }
  8746. $bmpdata = '';
  8747. $padCnt = (4-ceil(($width/(8/$biBitCount)))%4)%4;
  8748. switch ($biBitCount){
  8749. case 1:
  8750. case 4:
  8751. case 8:
  8752. $w = floor($width/(8/$biBitCount)) + ($width%(8/$biBitCount)?1:0);
  8753. $w_row = $w + $padCnt;
  8754. if ($flip){
  8755. for ($y=0;$y<$height;$y++){
  8756. $y0 = $y*$w_row;
  8757. for ($x=0;$x<$w;$x++)
  8758. $bmpdata .= $str[$y0+$x];
  8759. }
  8760. }else{
  8761. for ($y=$height-1;$y>=0;$y--){
  8762. $y0 = $y*$w_row;
  8763. for ($x=0;$x<$w;$x++)
  8764. $bmpdata .= $str[$y0+$x];
  8765. }
  8766. }
  8767. break;
  8768. case 16:
  8769. $w_row = $width*2 + $padCnt;
  8770. if ($flip){
  8771. for ($y=0;$y<$height;$y++){
  8772. $y0 = $y*$w_row;
  8773. for ($x=0;$x<$width;$x++){
  8774. $n = (ord( $str[$y0 + 2*$x + 1])*256 + ord( $str[$y0 + 2*$x]));
  8775. $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7128;
  8776. $bmpdata .= chr($r) . chr($g) . chr($b);
  8777. }
  8778. }
  8779. }else{
  8780. for ($y=$height-1;$y>=0;$y--){
  8781. $y0 = $y*$w_row;
  8782. for ($x=0;$x<$width;$x++){
  8783. $n = (ord( $str[$y0 + 2*$x + 1])*256 + ord( $str[$y0 + 2*$x]));
  8784. $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7;
  8785. $bmpdata .= chr($r) . chr($g) . chr($b);
  8786. }
  8787. }
  8788. }
  8789. break;
  8790. case 24:
  8791. case 32:
  8792. $byteCnt = $biBitCount/8;
  8793. $w_row = $width*$byteCnt + $padCnt;
  8794. if ($flip){
  8795. for ($y=0;$y<$height;$y++){
  8796. $y0 = $y*$w_row;
  8797. for ($x=0;$x<$width;$x++){
  8798. $i = $y0 + $x*$byteCnt ; # + 1
  8799. $bmpdata .= $str[$i+2].$str[$i+1].$str[$i];
  8800. }
  8801. }
  8802. }else{
  8803. for ($y=$height-1;$y>=0;$y--){
  8804. $y0 = $y*$w_row;
  8805. for ($x=0;$x<$width;$x++){
  8806. $i = $y0 + $x*$byteCnt ; # + 1
  8807. $bmpdata .= $str[$i+2].$str[$i+1].$str[$i];
  8808. }
  8809. }
  8810. }
  8811. break;
  8812. default:
  8813. return $this->_imageError($file, $firsttime, 'Error parsing BMP image - Unsupported image biBitCount');
  8814. }
  8815. if ($this->compress) {
  8816. $bmpdata=gzcompress($bmpdata);
  8817. $info['f']='FlateDecode';
  8818. }
  8819. $info['data']=$bmpdata;
  8820. $info['type']='bmp';
  8821. if ($firsttime) {
  8822. $info['i']=count($this->images)+1;
  8823. $this->images[$file]=$info;
  8824. }
  8825. return $info;
  8826. }
  8827. /*-- IMAGES-WMF --*/
  8828. // WMF
  8829. else if ($type == 'wmf') {
  8830. $this->gdiObjectArray = array();
  8831. $a=unpack('stest',"\1\0");
  8832. if ($a['test']!=1)
  8833. return $this->_imageError($file, $firsttime, 'Error parsing WMF image - Big-endian architecture not supported');
  8834. // check for Aldus placeable metafile header
  8835. $key = unpack('Lmagic', substr($data, 0, 4));
  8836. $p = 18; // WMF header
  8837. if ($key['magic'] == (int)0x9AC6CDD7) { $p +=22; } // Aldus header
  8838. // define some state variables
  8839. $wo=null; // window origin
  8840. $we=null; // window extent
  8841. $polyFillMode = 0;
  8842. $nullPen = false;
  8843. $nullBrush = false;
  8844. $endRecord = false;
  8845. $wmfdata = '';
  8846. while ($p < strlen($data) && !$endRecord) {
  8847. $recordInfo = unpack('Lsize/Sfunc', substr($data, $p, 6)); $p += 6;
  8848. // size of record given in WORDs (= 2 bytes)
  8849. $size = $recordInfo['size'];
  8850. // func is number of GDI function
  8851. $func = $recordInfo['func'];
  8852. if ($size > 3) {
  8853. $parms = substr($data, $p, 2*($size-3)); $p += 2*($size-3);
  8854. }
  8855. switch ($func) {
  8856. case 0x020b: // SetWindowOrg
  8857. // do not allow window origin to be changed
  8858. // after drawing has begun
  8859. if (!$wmfdata)
  8860. $wo = array_reverse(unpack('s2', $parms));
  8861. break;
  8862. case 0x020c: // SetWindowExt
  8863. // do not allow window extent to be changed
  8864. // after drawing has begun
  8865. if (!$wmfdata)
  8866. $we = array_reverse(unpack('s2', $parms));
  8867. break;
  8868. case 0x02fc: // CreateBrushIndirect
  8869. $brush = unpack('sstyle/Cr/Cg/Cb/Ca/Shatch', $parms);
  8870. $brush['type'] = 'B';
  8871. $this->_AddGDIObject($brush);
  8872. break;
  8873. case 0x02fa: // CreatePenIndirect
  8874. $pen = unpack('Sstyle/swidth/sdummy/Cr/Cg/Cb/Ca', $parms);
  8875. // convert width from twips to user unit
  8876. $pen['width'] /= (20 * $this->k);
  8877. $pen['type'] = 'P';
  8878. $this->_AddGDIObject($pen);
  8879. break;
  8880. // MUST create other GDI objects even if we don't handle them
  8881. case 0x06fe: // CreateBitmap
  8882. case 0x02fd: // CreateBitmapIndirect
  8883. case 0x00f8: // CreateBrush
  8884. case 0x02fb: // CreateFontIndirect
  8885. case 0x00f7: // CreatePalette
  8886. case 0x01f9: // CreatePatternBrush
  8887. case 0x06ff: // CreateRegion
  8888. case 0x0142: // DibCreatePatternBrush
  8889. $dummyObject = array('type'=>'D');
  8890. $this->_AddGDIObject($dummyObject);
  8891. break;
  8892. case 0x0106: // SetPolyFillMode
  8893. $polyFillMode = unpack('smode', $parms);
  8894. $polyFillMode = $polyFillMode['mode'];
  8895. break;
  8896. case 0x01f0: // DeleteObject
  8897. $idx = unpack('Sidx', $parms);
  8898. $idx = $idx['idx'];
  8899. $this->_DeleteGDIObject($idx);
  8900. break;
  8901. case 0x012d: // SelectObject
  8902. $idx = unpack('Sidx', $parms);
  8903. $idx = $idx['idx'];
  8904. $obj = $this->_GetGDIObject($idx);
  8905. switch ($obj['type']) {
  8906. case 'B':
  8907. $nullBrush = false;
  8908. if ($obj['style'] == 1) { $nullBrush = true; }
  8909. else {
  8910. $wmfdata .= $this->SetFColor($this->ConvertColor('rgb('.$obj['r'].','.$obj['g'].','.$obj['b'].')'), true)."\n"; // mPDF 5.0.051
  8911. }
  8912. break;
  8913. case 'P':
  8914. $nullPen = false;
  8915. $dashArray = array();
  8916. // dash parameters are custom
  8917. switch ($obj['style']) {
  8918. case 0: // PS_SOLID
  8919. break;
  8920. case 1: // PS_DASH
  8921. $dashArray = array(3,1);
  8922. break;
  8923. case 2: // PS_DOT
  8924. $dashArray = array(0.5,0.5);
  8925. break;
  8926. case 3: // PS_DASHDOT
  8927. $dashArray = array(2,1,0.5,1);
  8928. break;
  8929. case 4: // PS_DASHDOTDOT
  8930. $dashArray = array(2,1,0.5,1,0.5,1);
  8931. break;
  8932. case 5: // PS_NULL
  8933. $nullPen = true;
  8934. break;
  8935. }
  8936. if (!$nullPen) {
  8937. $wmfdata .= $this->SetDColor($this->ConvertColor('rgb('.$obj['r'].','.$obj['g'].','.$obj['b'].')'), true)."\n"; // mPDF 5.0.051
  8938. $wmfdata .= sprintf("%.3f w\n",$obj['width']*$this->k);
  8939. }
  8940. if (!empty($dashArray)) {
  8941. $s = '[';
  8942. for ($i=0; $i<count($dashArray);$i++) {
  8943. $s .= $dashArray[$i] * $this->k;
  8944. if ($i != count($dashArray)-1) { $s .= ' '; }
  8945. }
  8946. $s .= '] 0 d';
  8947. $wmfdata .= $s."\n";
  8948. }
  8949. break;
  8950. }
  8951. break;
  8952. case 0x0325: // Polyline
  8953. case 0x0324: // Polygon
  8954. $coords = unpack('s'.($size-3), $parms);
  8955. $numpoints = $coords[1];
  8956. for ($i = $numpoints; $i > 0; $i--) {
  8957. $px = $coords[2*$i];
  8958. $py = $coords[2*$i+1];
  8959. if ($i < $numpoints) { $wmfdata .= $this->_LineTo($px, $py); }
  8960. else { $wmfdata .= $this->_MoveTo($px, $py); }
  8961. }
  8962. if ($func == 0x0325) { $op = 's'; }
  8963. else if ($func == 0x0324) {
  8964. if ($nullPen) {
  8965. if ($nullBrush) { $op = 'n'; } // no op
  8966. else { $op = 'f'; } // fill
  8967. }
  8968. else {
  8969. if ($nullBrush) { $op = 's'; } // stroke
  8970. else { $op = 'b'; } // stroke and fill
  8971. }
  8972. if ($polyFillMode==1 && ($op=='b' || $op=='f')) { $op .= '*'; } // use even-odd fill rule
  8973. }
  8974. $wmfdata .= $op."\n";
  8975. break;
  8976. case 0x0538: // PolyPolygon
  8977. $coords = unpack('s'.($size-3), $parms);
  8978. $numpolygons = $coords[1];
  8979. $adjustment = $numpolygons;
  8980. for ($j = 1; $j <= $numpolygons; $j++) {
  8981. $numpoints = $coords[$j + 1];
  8982. for ($i = $numpoints; $i > 0; $i--) {
  8983. $px = $coords[2*$i + $adjustment];
  8984. $py = $coords[2*$i+1 + $adjustment];
  8985. if ($i == $numpoints) { $wmfdata .= $this->_MoveTo($px, $py); }
  8986. else { $wmfdata .= $this->_LineTo($px, $py); }
  8987. }
  8988. $adjustment += $numpoints * 2;
  8989. }
  8990. if ($nullPen) {
  8991. if ($nullBrush) { $op = 'n'; } // no op
  8992. else { $op = 'f'; } // fill
  8993. }
  8994. else {
  8995. if ($nullBrush) { $op = 's'; } // stroke
  8996. else { $op = 'b'; } // stroke and fill
  8997. }
  8998. if ($polyFillMode==1 && ($op=='b' || $op=='f')) { $op .= '*'; } // use even-odd fill rule
  8999. $wmfdata .= $op."\n";
  9000. break;
  9001. case 0x0000:
  9002. $endRecord = true;
  9003. break;
  9004. }
  9005. }
  9006. if (!$wmfdata) { return $this->_imageError($file, $firsttime, 'Error parsing WMF image'); }
  9007. $info = array('x'=>$wo[0],'y'=>$wo[1],'w'=>$we[0],'h'=>$we[1],'data'=>$wmfdata);
  9008. $info['i']=count($this->formobjects)+1;
  9009. $info['type']='wmf';
  9010. $this->formobjects[$file]=$info;
  9011. return $info;
  9012. }
  9013. /*-- END IMAGES-WMF --*/
  9014. // UNKNOWN TYPE - try GD imagecreatefromstring
  9015. else {
  9016. if (function_exists('gd_info')) { $gd = gd_info(); }
  9017. else {$gd = array(); }
  9018. if (isset($gd['PNG Support']) && $gd['PNG Support']) {
  9019. $im = @imagecreatefromstring($data);
  9020. if (!$im) { return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised, and not supported by GD imagecreate'); }
  9021. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  9022. imagealphablending($im, false);
  9023. imagesavealpha($im, false);
  9024. imageinterlace($im, false);
  9025. $check = @imagepng($im, $tempfile);
  9026. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse unknown image type'); }
  9027. $info = $this->_getImage($tempfile, false);
  9028. imagedestroy($im);
  9029. unlink($tempfile);
  9030. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse unknown image type'); }
  9031. $info['type']='png';
  9032. if ($firsttime) {
  9033. $info['i']=count($this->images)+1;
  9034. $this->images[$file]=$info;
  9035. }
  9036. return $info;
  9037. }
  9038. }
  9039. return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised');
  9040. }
  9041. //==============================================================
  9042. // mPDF 5.0.051
  9043. function _convImage(&$data, $colspace, $targetcs, $w, $h, $dpi, $mask) {
  9044. if ($this->PDFA || $this->PDFX) { $mask=false; }
  9045. $im = @imagecreatefromstring($data);
  9046. $info = array();
  9047. if ($im) {
  9048. $imgdata = '';
  9049. $mimgdata = '';
  9050. $minfo = array();
  9051. //Read transparency info
  9052. $trns=array();
  9053. $trnsrgb = false;
  9054. if (!$this->PDFA && !$this->PDFX) {
  9055. $p = strpos($data,'tRNS');
  9056. if ($p) {
  9057. $n=$this->_fourbytes2int(substr($data,($p-4),4));
  9058. $t = substr($data,($p+4),$n);
  9059. if ($colspace=='DeviceGray') {
  9060. $trns=array($this->ords[substr($t,1,1)]);
  9061. $trnsrgb = array($trns[0],$trns[0],$trns[0]);
  9062. }
  9063. else if ($colspace=='DeviceRGB') {
  9064. $trns=array($this->ords[substr($t,1,1)],$this->ords[substr($t,3,1)],$this->ords[substr($t,5,1)]);
  9065. $trnsrgb = $trns;
  9066. if ($targetcs=='DeviceCMYK') {
  9067. $col = $this->rgb2cmyk(array(3,$trns[0],$trns[1],$trns[2]));
  9068. $c1 = intval($col[1]*2.55);
  9069. $c2 = intval($col[2]*2.55);
  9070. $c3 = intval($col[3]*2.55);
  9071. $c4 = intval($col[4]*2.55);
  9072. $trns = array($c1,$c2,$c3,$c4);
  9073. }
  9074. else if ($targetcs=='DeviceGray') {
  9075. $c = intval(($trns[0] * .21) + ($trns[1] * .71) + ($trns[2] * .07));
  9076. $trns = array($c);
  9077. }
  9078. }
  9079. else { // Indexed
  9080. $pos = strpos($t,$this->chrs[0]);
  9081. if (is_int($pos)) {
  9082. $pal = imagecolorsforindex($im, $pos);
  9083. $r = $pal['red'];
  9084. $g = $pal['green'];
  9085. $b = $pal['blue'];
  9086. $trns=array($r,$g,$b); // ****
  9087. $trnsrgb = $trns;
  9088. if ($targetcs=='DeviceCMYK') {
  9089. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  9090. $c1 = intval($col[1]*2.55);
  9091. $c2 = intval($col[2]*2.55);
  9092. $c3 = intval($col[3]*2.55);
  9093. $c4 = intval($col[4]*2.55);
  9094. $trns = array($c1,$c2,$c3,$c4);
  9095. }
  9096. else if ($targetcs=='DeviceGray') {
  9097. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  9098. $trns = array($c);
  9099. }
  9100. }
  9101. }
  9102. }
  9103. }
  9104. for ($i = 0; $i < $h; $i++) {
  9105. for ($j = 0; $j < $w; $j++) {
  9106. $rgb = imagecolorat($im, $j, $i);
  9107. $r = ($rgb >> 16) & 0xFF;
  9108. $g = ($rgb >> 8) & 0xFF;
  9109. $b = $rgb & 0xFF;
  9110. if ($colspace=='Indexed') {
  9111. $pal = imagecolorsforindex($im, $rgb);
  9112. $r = $pal['red'];
  9113. $g = $pal['green'];
  9114. $b = $pal['blue'];
  9115. }
  9116. if ($targetcs=='DeviceCMYK') {
  9117. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  9118. $c1 = intval($col[1]*2.55);
  9119. $c2 = intval($col[2]*2.55);
  9120. $c3 = intval($col[3]*2.55);
  9121. $c4 = intval($col[4]*2.55);
  9122. if ($trnsrgb) {
  9123. // original pixel was not set as transparent but processed color does match
  9124. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c1,$c2,$c3,$c4)) {
  9125. if ($c4==0) { $c4=1; } else { $c4--; }
  9126. }
  9127. }
  9128. $imgdata .= chr($c1).chr($c2).chr($c3).chr($c4);
  9129. }
  9130. else if ($targetcs=='DeviceGray') {
  9131. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  9132. if ($trnsrgb) {
  9133. // original pixel was not set as transparent but processed color does match
  9134. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c)) {
  9135. if ($c==0) { $c=1; } else { $c--; }
  9136. }
  9137. }
  9138. $imgdata .= chr($c);
  9139. }
  9140. else if ($targetcs=='DeviceRGB') {
  9141. $imgdata .= chr($r).chr($g).chr($b);
  9142. }
  9143. if ($mask) {
  9144. $col = imagecolorsforindex($im, $rgb);
  9145. $gammacorr = 2.2; // gamma correction
  9146. $gamma = intval((pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255));
  9147. $mimgdata .= chr($gamma);
  9148. }
  9149. }
  9150. }
  9151. if ($targetcs=='DeviceGray') { $ncols = 1; }
  9152. else if ($targetcs=='DeviceRGB') { $ncols = 3; }
  9153. else if ($targetcs=='DeviceCMYK') { $ncols = 4; }
  9154. $imgdata = gzcompress($imgdata);
  9155. $info = array('w'=>$w,'h'=>$h,'cs'=>$targetcs,'bpc'=>8,'f'=>'FlateDecode','data'=>$imgdata, 'type'=>'png',
  9156. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  9157. if ($dpi) { $info['set-dpi'] = $dpi; }
  9158. if ($mask) {
  9159. $mimgdata = gzcompress($mimgdata);
  9160. $minfo = array('w'=>$w,'h'=>$h,'cs'=>'DeviceGray','bpc'=>8,'f'=>'FlateDecode','data'=>$mimgdata, 'type'=>'png',
  9161. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  9162. if ($dpi) { $minfo['set-dpi'] = $dpi; }
  9163. $tempfile = '_tempImgPNG'.RAND(1,10000).'.png';
  9164. $imgmask = count($this->images)+1;
  9165. $minfo['i']=$imgmask ;
  9166. $this->images[$tempfile] = $minfo;
  9167. $info['masked'] = $imgmask;
  9168. }
  9169. else if ($trns) { $info['trns'] = $trns; }
  9170. imagedestroy($im);
  9171. }
  9172. return $info;
  9173. }
  9174. # Decoder for RLE8 compression in windows bitmaps
  9175. # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
  9176. function rle8_decode ($str, $width){
  9177. $lineWidth = $width + (3 - ($width-1) % 4);
  9178. $out = '';
  9179. $cnt = strlen($str);
  9180. for ($i=0;$i<$cnt;$i++){
  9181. $o = ord($str[$i]);
  9182. switch ($o){
  9183. case 0: # ESCAPE
  9184. $i++;
  9185. switch (ord($str[$i])){
  9186. case 0: # NEW LINE
  9187. $padCnt = $lineWidth - strlen($out)%$lineWidth;
  9188. if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
  9189. break;
  9190. case 1: # END OF FILE
  9191. $padCnt = $lineWidth - strlen($out)%$lineWidth;
  9192. if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
  9193. break 3;
  9194. case 2: # DELTA
  9195. $i += 2;
  9196. break;
  9197. default: # ABSOLUTE MODE
  9198. $num = ord($str[$i]);
  9199. for ($j=0;$j<$num;$j++)
  9200. $out .= $str[++$i];
  9201. if ($num % 2) $i++;
  9202. }
  9203. break;
  9204. default:
  9205. $out .= str_repeat($str[++$i], $o);
  9206. }
  9207. }
  9208. return $out;
  9209. }
  9210. # Decoder for RLE4 compression in windows bitmaps
  9211. # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
  9212. function rle4_decode ($str, $width){
  9213. $w = floor($width/2) + ($width % 2);
  9214. $lineWidth = $w + (3 - ( ($width-1) / 2) % 4);
  9215. $pixels = array();
  9216. $cnt = strlen($str);
  9217. for ($i=0;$i<$cnt;$i++){
  9218. $o = ord($str[$i]);
  9219. switch ($o){
  9220. case 0: # ESCAPE
  9221. $i++;
  9222. switch (ord($str[$i])){
  9223. case 0: # NEW LINE
  9224. while (count($pixels)%$lineWidth!=0)
  9225. $pixels[]=0;
  9226. break;
  9227. case 1: # END OF FILE
  9228. while (count($pixels)%$lineWidth!=0)
  9229. $pixels[]=0;
  9230. break 3;
  9231. case 2: # DELTA
  9232. $i += 2;
  9233. break;
  9234. default: # ABSOLUTE MODE
  9235. $num = ord($str[$i]);
  9236. for ($j=0;$j<$num;$j++){
  9237. if ($j%2==0){
  9238. $c = ord($str[++$i]);
  9239. $pixels[] = ($c & 240)>>4;
  9240. } else
  9241. $pixels[] = $c & 15;
  9242. }
  9243. if ($num % 2) $i++;
  9244. }
  9245. break;
  9246. default:
  9247. $c = ord($str[++$i]);
  9248. for ($j=0;$j<$o;$j++)
  9249. $pixels[] = ($j%2==0 ? ($c & 240)>>4 : $c & 15);
  9250. }
  9251. }
  9252. $out = '';
  9253. if (count($pixels)%2) $pixels[]=0;
  9254. $cnt = count($pixels)/2;
  9255. for ($i=0;$i<$cnt;$i++)
  9256. $out .= chr(16*$pixels[2*$i] + $pixels[2*$i+1]);
  9257. return $out;
  9258. }
  9259. function _fourbytes2int_le($s) {
  9260. //Read a 4-byte integer from string
  9261. return (ord($s[3])<<24) + (ord($s[2])<<16) + (ord($s[1])<<8) + ord($s[0]);
  9262. }
  9263. function _twobytes2int_le($s) {
  9264. //Read a 2-byte integer from string
  9265. return (ord(substr($s, 1, 1))<<8) + ord(substr($s, 0, 1));
  9266. }
  9267. function _fourbytes2int($s) {
  9268. //Read a 4-byte integer from string
  9269. return (ord($s[0])<<24) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]);
  9270. }
  9271. function _twobytes2int($s) {
  9272. //Read a 2-byte integer from string
  9273. return (ord(substr($s, 0, 1))<<8) + ord(substr($s, 1, 1));
  9274. }
  9275. function _jpgHeaderFromString(&$data) {
  9276. $p = 4;
  9277. $p += $this->_twobytes2int(substr($data, $p, 2)); // Length of initial marker block
  9278. $marker = substr($data, $p, 2);
  9279. while($marker != chr(255).chr(192) && $marker != chr(255).chr(194) && $p<strlen($data)) {
  9280. // Start of frame marker (FFC0) or (FFC2) mPDF 4.4.004
  9281. $p += ($this->_twobytes2int(substr($data, $p+2, 2))) + 2; // Length of marker block
  9282. $marker = substr($data, $p, 2);
  9283. }
  9284. if ($marker != chr(255).chr(192) && $marker != chr(255).chr(194)) { return false; }
  9285. return substr($data, $p+2, 10);
  9286. }
  9287. function _jpgDataFromHeader($hdr) {
  9288. $bpc = ord(substr($hdr, 2, 1));
  9289. if (!$bpc) { $bpc = 8; }
  9290. $h = $this->_twobytes2int(substr($hdr, 3, 2));
  9291. $w = $this->_twobytes2int(substr($hdr, 5, 2));
  9292. $channels = ord(substr($hdr, 7, 1));
  9293. if ($channels==3) { $colspace='DeviceRGB'; }
  9294. elseif($channels==4) { $colspace='DeviceCMYK'; }
  9295. else { $colspace='DeviceGray'; }
  9296. return array($w, $h, $colspace, $bpc);
  9297. }
  9298. function file_get_contents_by_curl($url, &$data) {
  9299. $timeout = 5;
  9300. $ch = curl_init($url);
  9301. curl_setopt($ch, CURLOPT_HEADER, 0);
  9302. curl_setopt($ch, CURLOPT_NOBODY, 0);
  9303. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  9304. curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , $timeout );
  9305. $data = curl_exec($ch);
  9306. curl_close($ch);
  9307. }
  9308. function file_get_contents_by_socket($url, &$data) {
  9309. $timeout = 1;
  9310. $p = parse_url($url);
  9311. $file = $p['path'];
  9312. if ($p['query']) { $file .= '?'.$p['query']; }
  9313. if(!($fh = @fsockopen($p['host'], 80, $errno, $errstr, $timeout))) { return false; }
  9314. $getstring =
  9315. "GET ".$file." HTTP/1.0 \r\n" .
  9316. "Host: ".$p['host']." \r\n" .
  9317. "Connection: close\r\n\r\n";
  9318. fwrite($fh, $getstring);
  9319. // Get rid of HTTP header
  9320. $s = fgets($fh, 1024);
  9321. if (!$s) { return false; }
  9322. $httpheader .= $s;
  9323. while (!feof($fh)) {
  9324. $s = fgets($fh, 1024);
  9325. if ( $s == "\r\n" ) { break; }
  9326. }
  9327. $data = '';
  9328. while (!feof($fh)) {
  9329. $data .= fgets($fh, 1024);
  9330. }
  9331. fclose($fh);
  9332. }
  9333. //==============================================================
  9334. function _imageTypeFromString(&$data) {
  9335. $type = '';
  9336. if (substr($data, 6, 4)== 'JFIF' || substr($data, 6, 4)== 'Exif') {
  9337. $type = 'jpeg';
  9338. }
  9339. else if (substr($data, 0, 6)== "GIF87a" || substr($data, 0, 6)== "GIF89a") {
  9340. $type = 'gif';
  9341. }
  9342. else if (substr($data, 0, 8)== chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  9343. $type = 'png';
  9344. }
  9345. /*-- IMAGES-WMF --*/
  9346. else if (substr($data, 0, 4)== chr(215).chr(205).chr(198).chr(154)) {
  9347. $type = 'wmf';
  9348. }
  9349. /*-- END IMAGES-WMF --*/
  9350. else if (preg_match('/<svg.*<\/svg>/is',$data)) {
  9351. $type = 'svg';
  9352. }
  9353. // BMP images
  9354. else if (substr($data, 0, 2)== "BM") {
  9355. $type = 'bmp';
  9356. }
  9357. return $type;
  9358. }
  9359. //==============================================================
  9360. /*-- IMAGES-WMF --*/
  9361. // WMF functions
  9362. function _MoveTo($x, $y) {
  9363. return "$x $y m\n";
  9364. }
  9365. // a line must have been started using _MoveTo() first
  9366. function _LineTo($x, $y) {
  9367. return "$x $y l\n";
  9368. }
  9369. function _AddGDIObject($obj) {
  9370. // find next available slot
  9371. $idx = 0;
  9372. if (!empty($this->gdiObjectArray)) {
  9373. $empty = false;
  9374. $i = 0;
  9375. while (!$empty) {
  9376. $empty = !isset($this->gdiObjectArray[$i]);
  9377. $i++;
  9378. }
  9379. $idx = $i-1;
  9380. }
  9381. $this->gdiObjectArray[$idx] = $obj;
  9382. }
  9383. function _GetGDIObject($idx) {
  9384. return $this->gdiObjectArray[$idx];
  9385. }
  9386. function _DeleteGDIObject($idx) {
  9387. unset($this->gdiObjectArray[$idx]);
  9388. }
  9389. // END of WMF functions
  9390. /*-- END IMAGES-WMF --*/
  9391. // Moved outside WMF as also needed for SVG
  9392. function _putformobjects() {
  9393. reset($this->formobjects);
  9394. while(list($file,$info)=each($this->formobjects)) {
  9395. $this->_newobj();
  9396. $this->formobjects[$file]['n']=$this->n;
  9397. $this->_out('<</Type /XObject');
  9398. $this->_out('/Subtype /Form');
  9399. $this->_out('/Group '.($this->n+1).' 0 R');
  9400. $this->_out('/BBox ['.$info['x'].' '.$info['y'].' '.($info['w']+$info['x']).' '.($info['h']+$info['y']).']');
  9401. if ($this->compress)
  9402. $this->_out('/Filter /FlateDecode');
  9403. $data=($this->compress) ? gzcompress($info['data']) : $info['data'];
  9404. $this->_out('/Length '.strlen($data).'>>');
  9405. $this->_putstream($data);
  9406. unset($this->formobjects[$file]['data']);
  9407. $this->_out('endobj');
  9408. // Required for SVG transparency (opacity) to work
  9409. $this->_newobj();
  9410. $this->_out('<</Type /Group');
  9411. $this->_out('/S /Transparency');
  9412. $this->_out('>>');
  9413. $this->_out('endobj');
  9414. }
  9415. }
  9416. function _freadint($f)
  9417. {
  9418. //Read a 4-byte integer from file
  9419. $i=$this->ords[fread($f,1)]<<24;
  9420. $i+=$this->ords[fread($f,1)]<<16;
  9421. $i+=$this->ords[fread($f,1)]<<8;
  9422. $i+=$this->ords[fread($f,1)];
  9423. return $i;
  9424. }
  9425. function _UTF16BEtextstring($s) {
  9426. $s = $this->UTF8ToUTF16BE($s, true);
  9427. /*-- ENCRYPTION --*/
  9428. if ($this->encrypted) {
  9429. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9430. }
  9431. /*-- END ENCRYPTION --*/
  9432. return '('. $this->_escape($s).')';
  9433. }
  9434. function _textstring($s) {
  9435. /*-- ENCRYPTION --*/
  9436. if ($this->encrypted) {
  9437. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9438. }
  9439. /*-- END ENCRYPTION --*/
  9440. return '('. $this->_escape($s).')';
  9441. }
  9442. function _escape($s)
  9443. {
  9444. // the chr(13) substitution fixes the Bugs item #1421290.
  9445. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', $this->chrs[13] => '\r'));
  9446. }
  9447. function _putstream($s) {
  9448. /*-- ENCRYPTION --*/
  9449. if ($this->encrypted) {
  9450. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9451. }
  9452. /*-- END ENCRYPTION --*/
  9453. $this->_out('stream');
  9454. $this->_out($s);
  9455. $this->_out('endstream');
  9456. }
  9457. function _out($s,$ln=true) {
  9458. if($this->state==2) {
  9459. if ($this->bufferoutput) {
  9460. $this->headerbuffer.= $s."\n";
  9461. }
  9462. /*-- COLUMNS --*/
  9463. else if (($this->ColActive) && !$this->processingHeader && !$this->processingFooter) {
  9464. // Captures everything in buffer for columns; Almost everything is sent from fn. Cell() except:
  9465. // Images sent from Image() or
  9466. // later sent as _out($textto) in printbuffer
  9467. // Line()
  9468. if (preg_match('/q \d+\.\d\d+ 0 0 (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ cm \/(I|FO)\d+ Do Q/',$s,$m)) { // Image data
  9469. $h = ($m[1]/$this->k);
  9470. // Update/overwrite the lowest bottom of printing y value for a column
  9471. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h;
  9472. }
  9473. /*-- TABLES --*/
  9474. else if (preg_match('/\d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ ([\-]{0,1}\d+\.\d\d+) re/',$s,$m) && $this->tableLevel>0) { // Rect in table
  9475. $h = ($m[1]/$this->k);
  9476. // Update/overwrite the lowest bottom of printing y value for a column
  9477. $this->ColDetails[$this->CurrCol]['bottom_margin'] = max($this->ColDetails[$this->CurrCol]['bottom_margin'],($this->y+$h));
  9478. }
  9479. /*-- END TABLES --*/
  9480. else { // Td Text Set in Cell()
  9481. if (isset($this->ColDetails[$this->CurrCol]['bottom_margin'])) { $h = $this->ColDetails[$this->CurrCol]['bottom_margin'] - $this->y; }
  9482. else { $h = 0; }
  9483. }
  9484. if ($h < 0) { $h = -$h; }
  9485. $this->columnbuffer[] = array(
  9486. 's' => $s, // Text string to output
  9487. 'col' => $this->CurrCol, // Column when printed
  9488. 'x' => $this->x, // x when printed
  9489. 'y' => $this->y, // this->y when printed (after column break)
  9490. 'h' => $h // actual y at bottom when printed = y+h
  9491. );
  9492. }
  9493. /*-- END COLUMNS --*/
  9494. /*-- TABLES --*/
  9495. else if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  9496. // Captures eveything in buffer for rotated tables;
  9497. $this->tablebuffer .= $s . "\n";
  9498. }
  9499. /*-- END TABLES --*/
  9500. else if ($this->kwt && !$this->processingHeader && !$this->processingFooter) {
  9501. // Captures eveything in buffer for keep-with-table (h1-6);
  9502. $this->kwt_buffer[] = array(
  9503. 's' => $s, // Text string to output
  9504. 'x' => $this->x, // x when printed
  9505. 'y' => $this->y, // y when printed
  9506. );
  9507. }
  9508. else if (($this->keep_block_together) && !$this->processingHeader && !$this->processingFooter) {
  9509. if (!isset($this->ktBlock[$this->page]['bottom_margin'])) {
  9510. $this->ktBlock[$this->page]['bottom_margin'] = $this->y;
  9511. }
  9512. // Captures eveything in buffer;
  9513. if (preg_match('/q \d+\.\d\d+ 0 0 (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ cm \/(I|FO)\d+ Do Q/',$s,$m)) { // Image data
  9514. $h = ($m[1]/$this->k);
  9515. // Update/overwrite the lowest bottom of printing y value for Keep together block
  9516. $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h;
  9517. }
  9518. else { // Td Text Set in Cell()
  9519. if (isset($this->ktBlock[$this->page]['bottom_margin'])) { $h = $this->ktBlock[$this->page]['bottom_margin'] - $this->y; }
  9520. else { $h = 0; }
  9521. }
  9522. if ($h < 0) { $h = -$h; }
  9523. $this->divbuffer[] = array(
  9524. 'page' => $this->page,
  9525. 's' => $s, // Text string to output
  9526. 'x' => $this->x, // x when printed
  9527. 'y' => $this->y, // y when printed (after column break)
  9528. 'h' => $h // actual y at bottom when printed = y+h
  9529. );
  9530. }
  9531. else {
  9532. $this->pages[$this->page] .= $s.($ln == true ? "\n" : '');
  9533. }
  9534. }
  9535. else {
  9536. $this->buffer .= $s.($ln == true ? "\n" : '');
  9537. }
  9538. }
  9539. /*-- WATERMARK --*/
  9540. // add a watermark
  9541. function watermark( $texte, $angle=45, $fontsize=96, $alpha=0.2 ) {
  9542. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9543. if (!$this->watermark_font) { $this->watermark_font = $this->default_font; }
  9544. $this->SetFont( $this->watermark_font, "B", $fontsize, false ); // Don't output
  9545. $texte= $this->purify_utf8_text($texte);
  9546. if ($this->text_input_as_HTML) {
  9547. $texte= $this->all_entities_to_utf8($texte);
  9548. }
  9549. if ($this->usingCoreFont) { $texte = mb_convert_encoding($texte,$this->mb_enc,'UTF-8'); }
  9550. // DIRECTIONALITY
  9551. // mPDF 5.0.054
  9552. $this->magic_reverse_dir($texte, true, $this->directionality); // *RTL*
  9553. // Font-specific ligature substitution for Indic fonts
  9554. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($texte); // *INDIC*
  9555. $this->SetAlpha($alpha);
  9556. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  9557. $szfont = $fontsize;
  9558. $loop = 0;
  9559. $maxlen = (min($this->w,$this->h) ); // sets max length of text as 7/8 width/height of page
  9560. while ( $loop == 0 )
  9561. {
  9562. $this->SetFont( $this->watermark_font, "B", $szfont, false ); // Don't output
  9563. $offset = ((sin(deg2rad($angle))) * ($szfont/$this->k));
  9564. $strlen = $this->GetStringWidth($texte);
  9565. if ( $strlen > $maxlen - $offset )
  9566. $szfont --;
  9567. else
  9568. $loop ++;
  9569. }
  9570. $this->SetFont( $this->watermark_font, "B", $szfont-0.1, true, true); // Output The -0.1 is because SetFont above is not written to PDF
  9571. // Repeating it will not output anything as mPDF thinks it is set
  9572. $adj = ((cos(deg2rad($angle))) * ($strlen/2));
  9573. $opp = ((sin(deg2rad($angle))) * ($strlen/2));
  9574. $wx = ($this->w/2) - $adj + $offset/3;
  9575. $wy = ($this->h/2) + $opp;
  9576. $this->Rotate($angle,$wx,$wy);
  9577. $this->Text($wx,$wy,$texte);
  9578. $this->Rotate(0);
  9579. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  9580. $this->SetAlpha(1);
  9581. }
  9582. function watermarkImg( $src, $alpha=0.2 ) {
  9583. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9584. if ($this->watermarkImgBehind) { $this->watermarkImgAlpha = $this->SetAlpha($alpha, 'Normal', true); }
  9585. else { $this->SetAlpha($alpha, $this->watermarkImgAlphaBlend); }
  9586. $this->Image($src,0,0,0,0,'','', true, true, true);
  9587. if (!$this->watermarkImgBehind) { $this->SetAlpha(1); }
  9588. }
  9589. /*-- END WATERMARK --*/
  9590. function Rotate($angle,$x=-1,$y=-1)
  9591. {
  9592. if($x==-1)
  9593. $x=$this->x;
  9594. if($y==-1)
  9595. $y=$this->y;
  9596. if($this->angle!=0)
  9597. $this->_out('Q');
  9598. $this->angle=$angle;
  9599. if($angle!=0)
  9600. {
  9601. $angle*=M_PI/180;
  9602. $c=cos($angle);
  9603. $s=sin($angle);
  9604. $cx=$x*$this->k;
  9605. $cy=($this->h-$y)*$this->k;
  9606. $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.3f %.3f cm 1 0 0 1 %.3f %.3f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
  9607. }
  9608. }
  9609. // From Invoice
  9610. function RoundedRect($x, $y, $w, $h, $r, $style = '')
  9611. {
  9612. $k = $this->k;
  9613. $hp = $this->h;
  9614. if($style=='F')
  9615. $op='f';
  9616. elseif($style=='FD' or $style=='DF')
  9617. $op='B';
  9618. else
  9619. $op='S';
  9620. $MyArc = 4/3 * (sqrt(2) - 1);
  9621. $this->_out(sprintf('%.3f %.3f m',($x+$r)*$k,($hp-$y)*$k ));
  9622. $xc = $x+$w-$r ;
  9623. $yc = $y+$r;
  9624. $this->_out(sprintf('%.3f %.3f l', $xc*$k,($hp-$y)*$k ));
  9625. $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
  9626. $xc = $x+$w-$r ;
  9627. $yc = $y+$h-$r;
  9628. $this->_out(sprintf('%.3f %.3f l',($x+$w)*$k,($hp-$yc)*$k));
  9629. $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
  9630. $xc = $x+$r ;
  9631. $yc = $y+$h-$r;
  9632. $this->_out(sprintf('%.3f %.3f l',$xc*$k,($hp-($y+$h))*$k));
  9633. $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
  9634. $xc = $x+$r ;
  9635. $yc = $y+$r;
  9636. $this->_out(sprintf('%.3f %.3f l',($x)*$k,($hp-$yc)*$k ));
  9637. $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
  9638. $this->_out($op);
  9639. }
  9640. function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
  9641. {
  9642. $h = $this->h;
  9643. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c ', $x1*$this->k, ($h-$y1)*$this->k,
  9644. $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
  9645. }
  9646. /*-- BACKGROUNDS --*/
  9647. // mPDF 5.0.020
  9648. // type = linear:2; radial: 3;
  9649. // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
  9650. // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  9651. // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
  9652. // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
  9653. // (fx, fy) should be inside the circle, otherwise some areas will not be defined
  9654. // $col = array(R,G,B/255); or array(G/255); or array(C,M,Y,K/100)
  9655. // $stops = array('col'=>$col [, 'opacity'=>0-1] [, 'offset'=>0-1])
  9656. // mPDF 5.0.033 Added $is_mask
  9657. function Gradient($x, $y, $w, $h, $type, $stops=array(), $colorspace='RGB', $coords='', $extend='', $return=false, $is_mask=false) {
  9658. if (strtoupper(substr($type,0,1)) == 'L') { $type = 2; } // linear
  9659. else if (strtoupper(substr($type,0,1)) == 'R') { $type = 3; } // radial
  9660. if ($colorspace != 'CMYK' && $colorspace != 'Gray') {
  9661. $colorspace = 'RGB';
  9662. }
  9663. $bboxw = $w;
  9664. $bboxh = $h;
  9665. $usex = $x;
  9666. $usey = $y;
  9667. $usew = $bboxw;
  9668. $useh = $bboxh;
  9669. if ($type < 1) { $type = 2; }
  9670. if ($coords[0]!==false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$coords[0],$m)) {
  9671. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  9672. if ($tmp) { $coords[0] = $tmp/$w; }
  9673. }
  9674. if ($coords[1]!==false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$coords[1],$m)) {
  9675. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  9676. if ($tmp) { $coords[1] = 1-($tmp/$h); }
  9677. }
  9678. // LINEAR
  9679. if ($type == 2) {
  9680. $angle = $coords[4];
  9681. $repeat = $coords[5]; // mPDF 5.0.029
  9682. // ALL POINTS SET (default for custom mPDF linear gradient) - no -moz
  9683. if ($coords[0]!==false && $coords[1]!==false && $coords[2]!==false && $coords[3]!==false) {
  9684. // do nothing - coords used as they are
  9685. }
  9686. // If both a <point> and <angle> are defined, the gradient axis starts from the point and runs along the angle. The end point is
  9687. // defined as before - in this case start points may not be in corners, and axis may not correctly fall in the right quadrant.
  9688. // NO end points (Angle defined & Start points)
  9689. else if ($angle!==false && $coords[0]!==false && $coords[1]!==false && $coords[2]===false && $coords[3]===false) {
  9690. if ($angle==0 || $angle==360) { $coords[3]=$coords[1]; if ($coords[0]==1) $coords[2]=2; else $coords[2]=1; }
  9691. else if ($angle==90) { $coords[2]=$coords[0]; $coords[3]=1; if ($coords[1]==1) $coords[3]=2; else $coords[3]=1; }
  9692. else if ($angle==180) { if ($coords[4]==0) $coords[2]=-1; else $coords[2]=0; $coords[3]=$coords[1]; }
  9693. else if ($angle==270) { $coords[2]=$coords[0]; if ($coords[1]==0) $coords[3]=-1; else $coords[3]=0; }
  9694. else {
  9695. $endx=1; $endy=1;
  9696. if ($angle <=90) {
  9697. if ($angle <=45) { $endy=tan(deg2rad($angle)); }
  9698. else { $endx=tan(deg2rad(90-$angle)); }
  9699. $b = atan2(($endy*$bboxh), ($endx*$bboxw));
  9700. $ny = 1 - $coords[1] - (tan($b) * (1-$coords[0]));
  9701. $tx = sin($b) * cos($b) * $ny;
  9702. $ty = cos($b) * cos($b) * $ny;
  9703. $coords[2] = 1+$tx; $coords[3] = 1-$ty;
  9704. }
  9705. else if ($angle <=180) {
  9706. if ($angle <=135) { $endx=tan(deg2rad($angle-90)); }
  9707. else { $endy=tan(deg2rad(180-$angle)); }
  9708. $b = atan2(($endy*$bboxh), ($endx*$bboxw));
  9709. $ny = 1 - $coords[1] - (tan($b) * ($coords[0]));
  9710. $tx = sin($b) * cos($b) * $ny;
  9711. $ty = cos($b) * cos($b) * $ny;
  9712. $coords[2] = -$tx; $coords[3] = 1-$ty;
  9713. }
  9714. else if ($angle <=270) {
  9715. if ($angle <=225) { $endy=tan(deg2rad($angle-180)); }
  9716. else { $endx=tan(deg2rad(270-$angle)); }
  9717. $b = atan2(($endy*$bboxh), ($endx*$bboxw));
  9718. $ny = $coords[1] - (tan($b) * ($coords[0]));
  9719. $tx = sin($b) * cos($b) * $ny;
  9720. $ty = cos($b) * cos($b) * $ny;
  9721. $coords[2] = -$tx; $coords[3] = $ty;
  9722. }
  9723. else {
  9724. if ($angle <=315) { $endx=tan(deg2rad($angle-270)); }
  9725. else { $endy=tan(deg2rad(360-$angle)); }
  9726. $b = atan2(($endy*$bboxh), ($endx*$bboxw));
  9727. $ny = $coords[1] - (tan($b) * (1-$coords[0]));
  9728. $tx = sin($b) * cos($b) * $ny;
  9729. $ty = cos($b) * cos($b) * $ny;
  9730. $coords[2] = 1+$tx; $coords[3] = $ty;
  9731. }
  9732. }
  9733. }
  9734. // -moz If the first parameter is only an <angle>, the gradient axis starts from the box's corner that would ensure the
  9735. // axis goes through the box. The axis runs along the specified angle. The end point of the axis is defined such that the
  9736. // farthest corner of the box from the starting point is perpendicular to the gradient axis at that point.
  9737. // NO end points or Start points (Angle defined)
  9738. else if ($angle!==false && $coords[0]===false && $coords[1]===false) {
  9739. if ($angle==0 || $angle==360) { $coords[0]=0; $coords[1]=0; $coords[2]=1; $coords[3]=0; }
  9740. else if ($angle==90) { $coords[0]=0; $coords[1]=0; $coords[2]=0; $coords[3]=1; }
  9741. else if ($angle==180) { $coords[0]=1; $coords[1]=0; $coords[2]=0; $coords[3]=0; }
  9742. else if ($angle==270) { $coords[0]=0; $coords[1]=1; $coords[2]=0; $coords[3]=0; }
  9743. else {
  9744. if ($angle <=90) {
  9745. $coords[0]=0; $coords[1]=0;
  9746. if ($angle <=45) { $endx=1; $endy=tan(deg2rad($angle)); }
  9747. else { $endx=tan(deg2rad(90-$angle)); $endy=1; }
  9748. }
  9749. else if ($angle <=180) {
  9750. $coords[0]=1; $coords[1]=0;
  9751. if ($angle <=135) { $endx=tan(deg2rad($angle-90)); $endy=1; }
  9752. else { $endx=1; $endy=tan(deg2rad(180-$angle)); }
  9753. }
  9754. else if ($angle <=270) {
  9755. $coords[0]=1; $coords[1]=1;
  9756. if ($angle <=225) { $endx=1; $endy=tan(deg2rad($angle-180)); }
  9757. else { $endx=tan(deg2rad(270-$angle)); $endy=1; }
  9758. }
  9759. else {
  9760. $coords[0]=0; $coords[1]=1;
  9761. if ($angle <=315) { $endx=tan(deg2rad($angle-270)); $endy=1; }
  9762. else { $endx=1; $endy=tan(deg2rad(360-$angle)); }
  9763. }
  9764. $b = atan2(($endy*$bboxh), ($endx*$bboxw));
  9765. $h2 = $bboxh - ($bboxh * tan($b));
  9766. $px = $bboxh + ($h2 * sin($b) * cos($b));
  9767. $py = ($bboxh * tan($b)) + ($h2 * sin($b) * sin($b));
  9768. $x1 = $px / $bboxh;
  9769. $y1 = $py / $bboxh;
  9770. if ($angle <=90) { $coords[2] = $x1; $coords[3] = $y1; }
  9771. else if ($angle <=180) { $coords[2] = 1-$x1; $coords[3] = $y1; }
  9772. else if ($angle <=270) { $coords[2] = 1-$x1; $coords[3] = 1-$y1; }
  9773. else { $coords[2] = $x1; $coords[3] = 1-$y1; }
  9774. }
  9775. }
  9776. // -moz If the first parameter to the gradient function is only a <point>, the gradient axis starts from the specified point,
  9777. // and ends at the point you would get if you rotated the starting point by 180 degrees about the center of the box that the
  9778. // gradient is to be applied to.
  9779. // NO angle and NO end points (Start points defined)
  9780. else if ((!isset($angle) || $angle===false) && $coords[0]!==false && $coords[1]!==false) { // should have start and end defined
  9781. $coords[2] = 1-$coords[0]; $coords[3] = 1-$coords[1];
  9782. $angle = rad2deg(atan2($coords[3]-$coords[1],$coords[2]-$coords[0]));
  9783. if ($angle < 0) { $angle += 360; }
  9784. else if ($angle > 360) { $angle -= 360; }
  9785. if ($angle!=0 && $angle!=360 && $angle!=90 && $angle!=180 && $angle!=270) {
  9786. if ($w >= $h) {
  9787. $coords[1] *= $h/$w ;
  9788. $coords[3] *= $h/$w ;
  9789. $usew = $useh = $bboxw;
  9790. $usey -= ($w-$h);
  9791. }
  9792. else {
  9793. $coords[0] *= $w/$h ;
  9794. $coords[2] *= $w/$h ;
  9795. $usew = $useh = $bboxh;
  9796. }
  9797. }
  9798. }
  9799. // -moz If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient
  9800. // axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
  9801. else { // default values T2B
  9802. // All values are set in parseMozGradient - so won't appear here
  9803. $coords = array(0,0,1,0); // default for original linear gradient (L2R)
  9804. }
  9805. $s = ' q';
  9806. $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k)."\n";
  9807. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew*$this->k, $useh*$this->k, $usex*$this->k, ($this->h-($usey+$useh))*$this->k)."\n";
  9808. }
  9809. // RADIAL
  9810. else if ($type == 3) {
  9811. $radius = $coords[4];
  9812. $angle = $coords[5]; // ?? no effect
  9813. $shape = $coords[6];
  9814. $size = $coords[7];
  9815. $repeat = $coords[8]; // mPDF 5.0.029
  9816. // ALL POINTS AND RADIUS SET (default for custom mPDF radial gradient) - no -moz
  9817. if ($coords[0]!==false && $coords[1]!==false && $coords[2]!==false && $coords[3]!==false && $coords[4]!==false) {
  9818. // do nothing - coords used as they are
  9819. }
  9820. // If a <point> is defined
  9821. else if ($shape!==false && $size!==false) {
  9822. if ($coords[2]==false) { $coords[2] = $coords[0]; }
  9823. if ($coords[3]==false) { $coords[3] = $coords[1]; }
  9824. // ELLIPSE
  9825. if ($shape=='ellipse') {
  9826. $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
  9827. $corner2 = sqrt(pow($coords[0],2) + pow((1-$coords[1]),2));
  9828. $corner3 = sqrt(pow((1-$coords[0]),2) + pow($coords[1],2));
  9829. $corner4 = sqrt(pow((1-$coords[0]),2) + pow((1-$coords[1]),2));
  9830. if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (1-$coords[0]), (1-$coords[1])); }
  9831. else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
  9832. else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (1-$coords[0]), (1-$coords[1])); }
  9833. else { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
  9834. }
  9835. // CIRCLE
  9836. else if ($shape=='circle') {
  9837. if ($w >= $h) {
  9838. $coords[1] = $coords[3] = ($coords[1] * $h/$w) ;
  9839. $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
  9840. $corner2 = sqrt(pow($coords[0],2) + pow((($h/$w)-$coords[1]),2));
  9841. $corner3 = sqrt(pow((1-$coords[0]),2) + pow($coords[1],2));
  9842. $corner4 = sqrt(pow((1-$coords[0]),2) + pow((($h/$w)-$coords[1]),2));
  9843. if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (1-$coords[0]), (($h/$w)-$coords[1])); }
  9844. else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
  9845. else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (1-$coords[0]), (($h/$w)-$coords[1])); }
  9846. else if ($size=='farthest-corner') { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
  9847. $usew = $useh = $bboxw;
  9848. $usey -= ($w-$h);
  9849. }
  9850. else {
  9851. $coords[0] = $coords[2] = ($coords[0] * $w/$h) ;
  9852. $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
  9853. $corner2 = sqrt(pow($coords[0],2) + pow((1-$coords[1]),2));
  9854. $corner3 = sqrt(pow((($w/$h)-$coords[0]),2) + pow($coords[1],2));
  9855. $corner4 = sqrt(pow((($w/$h)-$coords[0]),2) + pow((1-$coords[1]),2));
  9856. if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (($w/$h)-$coords[0]), (1-$coords[1])); }
  9857. else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
  9858. else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (($w/$h)-$coords[0]), (1-$coords[1])); }
  9859. else if ($size=='farthest-corner') { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
  9860. $usew = $useh = $bboxh;
  9861. }
  9862. }
  9863. if ($radius==0) { $radius=0.001; } // to prevent error
  9864. $coords[4] = $radius;
  9865. }
  9866. // -moz If entire function consists of only <stop> values
  9867. else { // default values
  9868. // All values are set in parseMozGradient - so won't appear here
  9869. $coords = array(0.5,0.5,0.5,0.5); // default for radial gradient (centred)
  9870. }
  9871. $s = ' q';
  9872. $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k)."\n";
  9873. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew*$this->k, $useh*$this->k, $usex*$this->k, ($this->h-($usey+$useh))*$this->k)."\n";
  9874. }
  9875. $n = count($this->gradients) + 1;
  9876. $this->gradients[$n]['type'] = $type;
  9877. $this->gradients[$n]['colorspace'] = $colorspace;
  9878. $trans = false;
  9879. // mPDF 5.0.033
  9880. $this->gradients[$n]['is_mask'] = $is_mask;
  9881. if ($is_mask) { $trans = true; }
  9882. if (count($stops) == 1) { $stops[1] = $stops[0]; }
  9883. if (!isset($stops[0]['offset'])) { $stops[0]['offset'] = 0; }
  9884. if (!isset($stops[(count($stops)-1)]['offset'])) { $stops[(count($stops)-1)]['offset'] = 1; }
  9885. // Fix stop-offsets set as absolute lengths
  9886. if ($type==2) {
  9887. $axisx = ($coords[2]-$coords[0])*$usew;
  9888. $axisy = ($coords[3]-$coords[1])*$useh;
  9889. $axis_length = sqrt(pow($axisx,2) + pow($axisy,2));
  9890. }
  9891. else { $axis_length = $coords[4]*$usew; } // Absolute lengths are meaningless for an ellipse - Firefox uses Width as reference
  9892. for($i=0;$i<count($stops);$i++) {
  9893. if (isset($stops[$i]['offset']) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$stops[$i]['offset'],$m)) {
  9894. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  9895. $stops[$i]['offset'] = $tmp/$axis_length;
  9896. }
  9897. }
  9898. if (isset($stops[0]['offset']) && $stops[0]['offset']>0) {
  9899. $firststop = $stops[0];
  9900. $firststop['offset'] = 0;
  9901. array_unshift($stops, $firststop);
  9902. }
  9903. if (!$repeat && isset($stops[(count($stops)-1)]['offset']) && $stops[(count($stops)-1)]['offset']<1) { // mPDF 5.0.029
  9904. $endstop = $stops[(count($stops)-1)];
  9905. $endstop['offset'] = 1;
  9906. $stops[] = $endstop;
  9907. }
  9908. if ($stops[0]['offset'] > $stops[(count($stops)-1)]['offset']) {
  9909. $stops[0]['offset'] = 0;
  9910. $stops[(count($stops)-1)]['offset'] = 1;
  9911. }
  9912. for($i=0;$i<count($stops);$i++) {
  9913. if ($colorspace == 'CMYK') { // mPDF 5.0.051
  9914. $this->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F %.3F %.3F %.3F', ($stops[$i]['col'][1]/100), ($stops[$i]['col'][2]/100), ($stops[$i]['col'][3]/100), ($stops[$i]['col'][4]/100));
  9915. }
  9916. else if ($colorspace == 'Gray') { // mPDF 5.0.051
  9917. $this->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F', ($stops[$i]['col'][1]/255));
  9918. }
  9919. else { // mPDF 5.0.051
  9920. $this->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F %.3F %.3F', ($stops[$i]['col'][1]/255), ($stops[$i]['col'][2]/255), ($stops[$i]['col'][3]/255));
  9921. }
  9922. if (!isset($stops[$i]['opacity'])) { $stops[$i]['opacity'] = 1; }
  9923. else if ($stops[$i]['opacity'] > 1 || $stops[$i]['opacity'] < 0) { $stops[$i]['opacity'] = 1; }
  9924. else if ($stops[$i]['opacity'] < 1) {
  9925. $trans = true;
  9926. }
  9927. $this->gradients[$n]['stops'][$i]['opacity'] = $stops[$i]['opacity'];
  9928. // OFFSET
  9929. if ($i>0 && $i<(count($stops)-1)) {
  9930. if (!isset($stops[$i]['offset']) || (isset($stops[$i+1]['offset']) && $stops[$i]['offset']>$stops[$i+1]['offset']) || $stops[$i]['offset']<$stops[$i-1]['offset']) {
  9931. if (isset($stops[$i-1]['offset']) && isset($stops[$i+1]['offset'])) {
  9932. $stops[$i]['offset'] = ($stops[$i-1]['offset']+$stops[$i+1]['offset'])/2;
  9933. }
  9934. else {
  9935. for($j=($i+1);$j<count($stops);$j++) {
  9936. if(isset($stops[$j]['offset'])) { break; }
  9937. }
  9938. $int = ($stops[$j]['offset'] - $stops[($i-1)]['offset'])/($j-$i+1);
  9939. for($k=0;$k<($j-$i-1);$k++) {
  9940. $stops[($i+$k)]['offset'] = $stops[($i+$k-1)]['offset'] + ($int);
  9941. }
  9942. }
  9943. }
  9944. }
  9945. $this->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
  9946. $this->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
  9947. }
  9948. // mPDF 5.0.029
  9949. if ($repeat) {
  9950. $ns = count($this->gradients[$n]['stops']);
  9951. $offs = array();
  9952. for($i=0;$i<$ns;$i++) {
  9953. $offs[$i] = $this->gradients[$n]['stops'][$i]['offset'];
  9954. }
  9955. $gp = 0;
  9956. $inside=true;
  9957. while($inside) {
  9958. $gp++;
  9959. for($i=0;$i<$ns;$i++) {
  9960. $this->gradients[$n]['stops'][(($ns*$gp)+$i)] = $this->gradients[$n]['stops'][(($ns*($gp-1))+$i)];
  9961. $tmp = $this->gradients[$n]['stops'][(($ns*($gp-1))+($ns-1))]['offset']+$offs[$i] ;
  9962. if ($tmp < 1) { $this->gradients[$n]['stops'][(($ns*$gp)+$i)]['offset'] = $tmp; }
  9963. else {
  9964. $this->gradients[$n]['stops'][(($ns*$gp)+$i)]['offset'] = 1;
  9965. $inside = false;
  9966. break(2);
  9967. }
  9968. }
  9969. }
  9970. }
  9971. if ($trans) {
  9972. $this->gradients[$n]['trans'] = true;
  9973. $s .= ' /TGS'.$n.' gs ';
  9974. }
  9975. if (!is_array($extend) || count($extend) <1) {
  9976. $extend=array('true', 'true'); // These are supposed to be quoted - appear in PDF file as text
  9977. }
  9978. $this->gradients[$n]['coords'] = $coords;
  9979. $this->gradients[$n]['extend'] = $extend;
  9980. //paint the gradient
  9981. $s .= '/Sh'.$n.' sh '."\n";
  9982. //restore previous Graphic State
  9983. $s .= ' Q '."\n";
  9984. if ($return) { return $s; }
  9985. else { $this->_out($s); }
  9986. }
  9987. /*-- END BACKGROUNDS --*/
  9988. //====================================================
  9989. /*-- DIRECTW --*/
  9990. function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 )
  9991. {
  9992. // F (shading - no line),S (line, no shading),DF (both)
  9993. if (!$font) { $font= $this->default_font; }
  9994. if (!$szfont) { $szfont = ($this->default_font_size * 1.8); }
  9995. $text = $this->purify_utf8_text($text);
  9996. if ($this->text_input_as_HTML) {
  9997. $text = $this->all_entities_to_utf8($text);
  9998. }
  9999. if ($this->usingCoreFont) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  10000. // DIRECTIONALITY
  10001. // mPDF 5.0.054
  10002. $this->magic_reverse_dir($text, true, $this->directionality); // *RTL*
  10003. // Font-specific ligature substitution for Indic fonts
  10004. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($text); // *INDIC*
  10005. $text = ' '.$text.' ';
  10006. if (!$width) { $width = $this->pgwidth; } else { $width=$this->ConvertSize($width,$this->pgwidth); }
  10007. $midpt = $this->lMargin+($this->pgwidth/2);
  10008. $r1 = $midpt-($width/2); //($this->w / 2) - 40;
  10009. $r2 = $r1 + $width; //$r1 + 80;
  10010. $y1 = $this->y;
  10011. $mid = ($r1 + $r2 ) / 2;
  10012. $loop = 0;
  10013. while ( $loop == 0 )
  10014. {
  10015. $this->SetFont( $font, $fontstyle, $szfont );
  10016. $sz = $this->GetStringWidth( $text );
  10017. if ( ($r1+$sz) > $r2 )
  10018. $szfont --;
  10019. else
  10020. $loop ++;
  10021. }
  10022. $y2 = $this->FontSize+($pad*2);
  10023. $this->SetLineWidth(0.1);
  10024. $fc = $this->ConvertColor($fill);
  10025. $tc = $this->ConvertColor($color);
  10026. $this->SetFColor($fc); // mPDF 5.0.020
  10027. $this->SetTColor($tc); // mPDF 5.0.020
  10028. $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, $radius, $style);
  10029. $this->SetX( $r1);
  10030. $this->Cell($r2-$r1, $y2, $text, 0, 1, "C" );
  10031. $this->SetY($y1+$y2+2); // +2 = mm margin below shaded box
  10032. $this->Reset();
  10033. }
  10034. /*-- END DIRECTW --*/
  10035. function UTF8StringToArray($str, $addSubset=true) {
  10036. $out = array();
  10037. $len = strlen($str);
  10038. for ($i = 0; $i < $len; $i++) {
  10039. $uni = -1;
  10040. $h = ord($str[$i]);
  10041. if ( $h <= 0x7F )
  10042. $uni = $h;
  10043. elseif ( $h >= 0xC2 ) {
  10044. if ( ($h <= 0xDF) && ($i < $len -1) )
  10045. $uni = ($h & 0x1F) << 6 | (ord($str[++$i]) & 0x3F);
  10046. elseif ( ($h <= 0xEF) && ($i < $len -2) )
  10047. $uni = ($h & 0x0F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  10048. elseif ( ($h <= 0xF4) && ($i < $len -3) )
  10049. $uni = ($h & 0x0F) << 18 | (ord($str[++$i]) & 0x3F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  10050. }
  10051. if ($uni >= 0) {
  10052. $out[] = $uni;
  10053. if ($addSubset && isset($this->CurrentFont['subset'])) { // mPDF 5.0
  10054. $this->CurrentFont['subset'][$uni] = $uni;
  10055. }
  10056. }
  10057. }
  10058. return $out;
  10059. }
  10060. //Convert utf-8 string to <HHHHHH> for Font Subsets
  10061. function UTF8toSubset($str) {
  10062. $ret = '<';
  10063. $str = preg_replace('/'.preg_quote($this->aliasNbPg,'/').'/', chr(7), $str );
  10064. $str = preg_replace('/'.preg_quote($this->aliasNbPgGp,'/').'/', chr(8), $str );
  10065. $unicode = $this->UTF8StringToArray($str);
  10066. $orig_fid = $this->CurrentFont['subsetfontids'][0];
  10067. $last_fid = $this->CurrentFont['subsetfontids'][0];
  10068. foreach($unicode as $c) {
  10069. if ($c == 7 || $c == 8) {
  10070. if ($orig_fid != $last_fid) {
  10071. $ret .= '> Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <';
  10072. $last_fid = $orig_fid;
  10073. }
  10074. if ($c == 7) { $ret .= $this->aliasNbPgHex; } // mPDF 5.0.04
  10075. else { $ret .= $this->aliasNbPgGpHex; } // mPDF 5.0.04
  10076. continue;
  10077. }
  10078. for ($i=0; $i<99; $i++) {
  10079. // return c as decimal char
  10080. $init = array_search($c, $this->CurrentFont['subsets'][$i]);
  10081. if ($init!==false) {
  10082. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  10083. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  10084. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  10085. }
  10086. $ret .= sprintf("%02s", strtoupper(dechex($init)));
  10087. break;
  10088. }
  10089. // TrueType embedded SUBSETS
  10090. else if (count($this->CurrentFont['subsets'][$i]) < 255) {
  10091. $n = count($this->CurrentFont['subsets'][$i]);
  10092. $this->CurrentFont['subsets'][$i][$n] = $c;
  10093. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  10094. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  10095. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  10096. }
  10097. $ret .= sprintf("%02s", strtoupper(dechex($n)));
  10098. break;
  10099. }
  10100. else if (!isset($this->CurrentFont['subsets'][($i+1)])) {
  10101. // TrueType embedded SUBSETS
  10102. $this->CurrentFont['subsets'][($i+1)] = array(0=>0);
  10103. $new_fid = count($this->fonts)+$this->extraFontSubsets+1;
  10104. $this->CurrentFont['subsetfontids'][($i+1)] = $new_fid;
  10105. $this->extraFontSubsets++;
  10106. }
  10107. }
  10108. }
  10109. $ret .= '>';
  10110. if ($last_fid != $orig_fid) {
  10111. $ret .= ' Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <> ';
  10112. }
  10113. return $ret;
  10114. }
  10115. // Converts UTF-8 strings to UTF16-BE.
  10116. function UTF8ToUTF16BE($str, $setbom=true) {
  10117. // mPDF 5.0
  10118. if ($this->checkSIP && preg_match("/([\x{20000}-\x{2FFFF}])/u", $str)) {
  10119. if (!in_array($this->currentfontfamily, array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  10120. 'gbBI','big5BI','sjisBI','uhcBI'))) {
  10121. $str = preg_replace("/[\x{20000}-\x{2FFFF}]/u", chr(0), $str);
  10122. }
  10123. }
  10124. // mPDF 5.0.03
  10125. if ($this->checkSMP && preg_match("/([\x{10000}-\x{1FFFF}])/u", $str )) {
  10126. $str = preg_replace("/[\x{10000}-\x{1FFFF}]/u", chr(0), $str );
  10127. }
  10128. $outstr = ""; // string to be returned
  10129. if ($setbom) {
  10130. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  10131. }
  10132. $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8');
  10133. return $outstr;
  10134. }
  10135. // ====================================================
  10136. // ====================================================
  10137. // from class PDF_Chinese CJK EXTENSIONS
  10138. function AddCIDFont($family,$style,$name,&$cw,$CMap,$registry,$desc)
  10139. {
  10140. $fontkey=strtolower($family).strtoupper($style);
  10141. if(isset($this->fonts[$fontkey]))
  10142. $this->Error("Font already added: $family $style");
  10143. $i=count($this->fonts)+$this->extraFontSubsets+1;
  10144. $name=str_replace(' ','',$name);
  10145. if ($family == 'sjis') { $up = -120; } else { $up = -130; }
  10146. // ? 'up' and 'ut' do not seem to be referenced anywhere
  10147. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>$up,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry,'MissingWidth'=>1000,'desc'=>$desc);
  10148. }
  10149. function AddCJKFont($family) {
  10150. if ($this->PDFA || $this->PDFX) {
  10151. $this->Error("Adobe CJK fonts cannot be embedded in mPDF (required for PDFA1-b and PDFX/1-a).");
  10152. }
  10153. if ($family == 'big5') { $this->AddBig5Font(); }
  10154. else if ($family == 'gb') { $this->AddGBFont(); }
  10155. else if ($family == 'sjis') { $this->AddSJISFont(); }
  10156. else if ($family == 'uhc') { $this->AddUHCFont(); }
  10157. }
  10158. function AddBig5Font()
  10159. {
  10160. //Add Big5 font with proportional Latin
  10161. $family='big5';
  10162. $name='MSungStd-Light-Acro';
  10163. $cw=$this->Big5_widths;
  10164. $CMap='UniCNS-UTF16-H';
  10165. $registry=array('ordering'=>'CNS1','supplement'=>4); // mPDF 5.0.045
  10166. $desc = array(
  10167. 'Ascent' => 880,
  10168. 'Descent' => -120,
  10169. 'CapHeight' => 880,
  10170. 'Flags' => 6,
  10171. 'FontBBox' => '[-160 -249 1015 1071]',
  10172. 'ItalicAngle' => 0,
  10173. 'StemV' => 93,
  10174. );
  10175. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  10176. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  10177. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  10178. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  10179. }
  10180. function AddGBFont()
  10181. {
  10182. //Add GB font with proportional Latin
  10183. $family='gb';
  10184. $name='STSongStd-Light-Acro';
  10185. $cw=$this->GB_widths;
  10186. $CMap='UniGB-UTF16-H';
  10187. $registry=array('ordering'=>'GB1','supplement'=>4); // mPDF 5.0.045
  10188. $desc = array(
  10189. 'Ascent' => 752,
  10190. 'Descent' => -271,
  10191. 'CapHeight' => 737,
  10192. 'Flags' => 6,
  10193. 'FontBBox' => '[-25 -254 1000 880]',
  10194. 'ItalicAngle' => 0,
  10195. 'StemV' => 58,
  10196. 'Style' => '<< /Panose <000000000400000000000000> >>',
  10197. );
  10198. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  10199. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  10200. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  10201. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  10202. }
  10203. function AddSJISFont()
  10204. {
  10205. //Add SJIS font with proportional Latin
  10206. $family='sjis';
  10207. $name='KozMinPro-Regular-Acro';
  10208. $cw=$this->SJIS_widths;
  10209. $CMap='UniJIS-UTF16-H';
  10210. $registry=array('ordering'=>'Japan1','supplement'=>5); // mPDF 5.0.045
  10211. $desc = array(
  10212. 'Ascent' => 880,
  10213. 'Descent' => -120,
  10214. 'CapHeight' => 740,
  10215. 'Flags' => 6,
  10216. 'FontBBox' => '[-195 -272 1110 1075]',
  10217. 'ItalicAngle' => 0,
  10218. 'StemV' => 86,
  10219. 'XHeight' => 502,
  10220. );
  10221. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  10222. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  10223. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  10224. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  10225. }
  10226. function AddUHCFont()
  10227. {
  10228. //Add UHC font with proportional Latin
  10229. $family='uhc';
  10230. $name='HYSMyeongJoStd-Medium-Acro';
  10231. $cw=$this->UHC_widths;
  10232. $CMap='UniKS-UTF16-H';
  10233. $registry=array('ordering'=>'Korea1','supplement'=>2); // mPDF 5.0.045
  10234. $desc = array(
  10235. 'Ascent' => 880,
  10236. 'Descent' => -120,
  10237. 'CapHeight' => 720,
  10238. 'Flags' => 6,
  10239. 'FontBBox' => '[-28 -148 1001 880]',
  10240. 'ItalicAngle' => 0,
  10241. 'StemV' => 60,
  10242. 'Style' => '<< /Panose <000000000600000000000000> >>',
  10243. );
  10244. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  10245. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  10246. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  10247. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  10248. }
  10249. //////////////////////////////////////////////////////////////////////////////
  10250. //////////////////////////////////////////////////////////////////////////////
  10251. //////////////////////////////////////////////////////////////////////////////
  10252. //////////////////////////////////////////////////////////////////////////////
  10253. //////////////////////////////////////////////////////////////////////////////
  10254. //////////////////////////////////////////////////////////////////////////////
  10255. //////////////////////////////////////////////////////////////////////////////
  10256. function SetAutoFont($af = AUTOFONT_ALL) {
  10257. if ($this->onlyCoreFonts) { return false; }
  10258. if (!$af && $af !== 0) { $af = AUTOFONT_ALL; }
  10259. $this->autoFontGroups = $af;
  10260. if ($this->autoFontGroups ) {
  10261. $this->useLang = true;
  10262. // mPDF 5.0.054
  10263. }
  10264. }
  10265. function SetDefaultFont($font) {
  10266. // Disallow embedded fonts to be used as defaults in PDFA
  10267. if ($this->PDFA || $this->PDFX) {
  10268. if (strtolower($font) == 'ctimes') { $font = 'serif'; }
  10269. if (strtolower($font) == 'ccourier') { $font = 'monospace'; }
  10270. if (strtolower($font) == 'chelvetica') { $font = 'sans-serif'; }
  10271. }
  10272. $font = $this->SetFont($font); // returns substituted font if necessary
  10273. $this->default_font = $font;
  10274. $this->original_default_font = $font;
  10275. if (!$this->watermark_font ) { $this->watermark_font = $font; } // *WATERMARK*
  10276. $this->defaultCSS['BODY']['FONT-FAMILY'] = $font;
  10277. $this->CSS['BODY']['FONT-FAMILY'] = $font;
  10278. }
  10279. function SetDefaultFontSize($fontsize) {
  10280. $this->default_font_size = $fontsize;
  10281. $this->original_default_font_size = $fontsize;
  10282. $this->SetFontSize($fontsize);
  10283. $this->defaultCSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  10284. $this->CSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  10285. }
  10286. function SetDefaultBodyCSS($prop, $val) {
  10287. if ($prop) {
  10288. $this->defaultCSS['BODY'][strtoupper($prop)] = $val;
  10289. $this->CSS['BODY'][strtoupper($prop)] = $val;
  10290. }
  10291. }
  10292. function SetDirectionality($dir='ltr') {
  10293. /*-- RTL --*/
  10294. if (strtolower($dir) == 'rtl') {
  10295. if ($this->directionality != 'rtl') {
  10296. // Swop L/R Margins so page 1 RTL is an 'even' page
  10297. $tmp = $this->DeflMargin;
  10298. $this->DeflMargin = $this->DefrMargin;
  10299. $this->DefrMargin = $tmp;
  10300. $this->orig_lMargin = $this->DeflMargin;
  10301. $this->orig_rMargin = $this->DefrMargin;
  10302. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$this->tMargin);
  10303. }
  10304. $this->directionality = 'rtl';
  10305. $this->defaultAlign = 'R';
  10306. $this->defaultTableAlign = 'R';
  10307. }
  10308. else {
  10309. /*-- END RTL --*/
  10310. $this->directionality = 'ltr';
  10311. $this->defaultAlign = 'L';
  10312. $this->defaultTableAlign = 'L';
  10313. } // *RTL*
  10314. $this->CSS['BODY']['DIRECTION'] = $this->directionality; // mPDF 5.0.070
  10315. }
  10316. // mPDF 5.0.054
  10317. // Added to set line-height-correction
  10318. function SetLineHeightCorrection($val) {
  10319. if ($val > 0) { $this->default_lineheight_correction = $val; }
  10320. else { $this->default_lineheight_correction = 1.2; }
  10321. }
  10322. // Set a (fixed) lineheight to an actual value - either to named fontsize(pts) or default
  10323. function SetLineHeight($FontPt='',$spacing = '') {
  10324. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  10325. else { $k = 1; }
  10326. if ($spacing > 0) {
  10327. if (preg_match('/mm/',$spacing)) {
  10328. $this->lineheight = ($spacing + 0.0) / $k; // convert to number
  10329. }
  10330. else {
  10331. if ($FontPt) { $this->lineheight = (($FontPt/$this->k) *$spacing); }
  10332. else { $this->lineheight = (($this->FontSizePt/$this->k) *$spacing); }
  10333. }
  10334. }
  10335. else {
  10336. if ($FontPt) { $this->lineheight = (($FontPt/$this->k) *$this->normalLineheight); }
  10337. else { $this->lineheight = (($this->FontSizePt/$this->k) *$this->normalLineheight); }
  10338. }
  10339. }
  10340. function _computeLineheight($lh, $fs='') {
  10341. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  10342. else { $k = 1; }
  10343. if (!$fs) { $fs = $this->FontSize; }
  10344. if (preg_match('/mm/',$lh)) {
  10345. return (($lh + 0.0) / $k); // convert to number
  10346. }
  10347. else if ($lh > 0) {
  10348. return ($fs * $lh);
  10349. }
  10350. else if (isset($this->normalLineheight)) { return ($fs * $this->normalLineheight); }
  10351. else return ($fs * $this->default_lineheight_correction);
  10352. }
  10353. function SetBasePath($str='') {
  10354. if ( isset($_SERVER['HTTP_HOST']) ) { $host = $_SERVER['HTTP_HOST']; }
  10355. else if ( isset($_SERVER['SERVER_NAME']) ) { $host = $_SERVER['SERVER_NAME']; }
  10356. else { $host = ''; }
  10357. if (!$str) {
  10358. if ($_SERVER['SCRIPT_NAME']) { $currentPath = dirname($_SERVER['SCRIPT_NAME']); }
  10359. else { $currentPath = dirname($_SERVER['PHP_SELF']); }
  10360. $currentPath = str_replace("\\","/",$currentPath);
  10361. if ($currentPath == '/') { $currentPath = ''; }
  10362. if ($host) { $currpath = 'http://' . $host . $currentPath .'/'; }
  10363. else { $currpath = ''; }
  10364. $this->basepath = $currpath;
  10365. $this->basepathIsLocal = true;
  10366. return;
  10367. }
  10368. $str = preg_replace('/\?.*/','',$str);
  10369. if (!preg_match('/(http|https|ftp):\/\/.*\//i',$str)) { $str .= '/'; }
  10370. $str .= 'xxx'; // in case $str ends in / e.g. http://www.bbc.co.uk/
  10371. $this->basepath = dirname($str) . "/"; // returns e.g. e.g. http://www.google.com/dir1/dir2/dir3/
  10372. $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
  10373. $tr = parse_url($this->basepath);
  10374. if (isset($tr['host']) && ($tr['host'] == $host)) { $this->basepathIsLocal = true; }
  10375. else { $this->basepathIsLocal = false; }
  10376. }
  10377. function GetFullPath(&$path,$basepath='') {
  10378. // When parsing CSS need to pass temporary basepath - so links are relative to current stylesheet
  10379. if (!$basepath) { $basepath = $this->basepath; }
  10380. //Fix path value
  10381. $path = str_replace("\\","/",$path); //If on Windows
  10382. //Get link info and obtain its absolute path
  10383. $regexp = '|^./|'; // Inadvertently corrects "./path/etc" and "//www.domain.com/etc"
  10384. $path = preg_replace($regexp,'',$path);
  10385. if(substr($path,0,1) == '#') { return; }
  10386. if (stristr($path,"mailto:") !== false) { return; }
  10387. if (strpos($path,"../") !== false ) { //It is a Relative Link
  10388. $backtrackamount = substr_count($path,"../");
  10389. $maxbacktrack = substr_count($basepath,"/") - 1;
  10390. $filepath = str_replace("../",'',$path);
  10391. $path = $basepath;
  10392. //If it is an invalid relative link, then make it go to directory root
  10393. if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
  10394. //Backtrack some directories
  10395. for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
  10396. $path = $path . "/" . $filepath; //Make it an absolute path
  10397. }
  10398. else if( strpos($path,":/") === false || strpos($path,":/") > 10) { //It is a Local Link
  10399. if (substr($path,0,1) == "/") {
  10400. $tr = parse_url($basepath);
  10401. $root = $tr['scheme'].'://'.$tr['host'];
  10402. $path = $root . $path;
  10403. }
  10404. else { $path = $basepath . $path; }
  10405. }
  10406. //Do nothing if it is an Absolute Link
  10407. }
  10408. // Used for external CSS files
  10409. function _get_file($path) {
  10410. // If local file try using local path (? quicker, but also allowed even if allow_url_fopen false)
  10411. $contents = '';
  10412. $contents = @file_get_contents($path);
  10413. if ($contents) { return $contents; }
  10414. if ($this->basepathIsLocal) {
  10415. $tr = parse_url($path);
  10416. $lp=getenv("SCRIPT_NAME");
  10417. $ap=realpath($lp);
  10418. $ap=str_replace("\\","/",$ap);
  10419. $docroot=substr($ap,0,strpos($ap,$lp));
  10420. // WriteHTML parses all paths to full URLs; may be local file name
  10421. if ($tr['scheme'] && $tr['host'] && $_SERVER["DOCUMENT_ROOT"] ) {
  10422. $localpath = $_SERVER["DOCUMENT_ROOT"] . $tr['path'];
  10423. }
  10424. // DOCUMENT_ROOT is not returned on IIS
  10425. else if ($docroot) {
  10426. $localpath = $docroot . $tr['path'];
  10427. }
  10428. else { $localpath = $path; }
  10429. $contents = @file_get_contents($localpath);
  10430. }
  10431. // if not use full URL
  10432. else if (!$contents && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  10433. $ch = curl_init($path);
  10434. curl_setopt($ch, CURLOPT_HEADER, 0);
  10435. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  10436. $contents = curl_exec($ch);
  10437. curl_close($ch);
  10438. }
  10439. return $contents;
  10440. }
  10441. function UseCSS($opt=true)
  10442. {
  10443. $this->usecss=$opt;
  10444. }
  10445. function UseTableHeader($opt=true)
  10446. {
  10447. $this->usetableheader=$opt;
  10448. }
  10449. function UsePRE($opt=true)
  10450. {
  10451. $this->usepre=$opt;
  10452. }
  10453. function docPageNum($num = 0, $extras = false) {
  10454. if ($num < 1) { $num = $this->page; }
  10455. $type = '1'; // set default decimal
  10456. $ppgno = $num;
  10457. $suppress = 0;
  10458. $offset = 0;
  10459. $lastreset = 0;
  10460. foreach($this->PageNumSubstitutions AS $psarr) {
  10461. if ($num >= $psarr['from']) {
  10462. if ($psarr['reset']) {
  10463. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  10464. $ppgno = $num - $psarr['from'] + 1 + $offset;
  10465. $lastreset = $psarr['from'];
  10466. }
  10467. if ($psarr['type']) { $type = $psarr['type']; }
  10468. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  10469. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  10470. }
  10471. }
  10472. if ($suppress) { return ''; }
  10473. foreach($this->pgsIns AS $k=>$v) {
  10474. if ($k>$lastreset && $k<$num) {
  10475. $ppgno -= $v;
  10476. }
  10477. }
  10478. if ($type=='A') { $ppgno = $this->dec2alpha($ppgno,true); }
  10479. else if ($type=='a') { $ppgno = $this->dec2alpha($ppgno,false);}
  10480. else if ($type=='I') { $ppgno = $this->dec2roman($ppgno,true); }
  10481. else if ($type=='i') { $ppgno = $this->dec2roman($ppgno,false); }
  10482. if ($extras) { $ppgno = $this->pagenumPrefix . $ppgno . $this->pagenumSuffix; }
  10483. return $ppgno;
  10484. }
  10485. function docPageSettings($num = 0) {
  10486. // Returns current type (numberstyle), suppression state for this page number;
  10487. // reset is only returned if set for this page number
  10488. if ($num < 1) { $num = $this->page; }
  10489. $type = '1'; // set default decimal
  10490. $ppgno = $num;
  10491. $suppress = 0;
  10492. $offset = 0;
  10493. $reset = '';
  10494. foreach($this->PageNumSubstitutions AS $psarr) {
  10495. if ($num >= $psarr['from']) {
  10496. if ($psarr['reset']) {
  10497. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  10498. $ppgno = $num - $psarr['from'] + 1 + $offset;
  10499. }
  10500. if ($psarr['type']) { $type = $psarr['type']; }
  10501. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  10502. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  10503. }
  10504. if ($num == $psarr['from']) { $reset = $psarr['reset']; }
  10505. }
  10506. if ($suppress) { $suppress = 'on'; }
  10507. else { $suppress = 'off'; }
  10508. return array($type, $suppress, $reset);
  10509. }
  10510. function docPageNumTotal($num = 0, $extras = false) {
  10511. if ($num < 1) { $num = $this->page; }
  10512. $type = '1'; // set default decimal
  10513. $ppgstart = 1;
  10514. $ppgend = count($this->pages)+1;
  10515. $suppress = 0;
  10516. $offset = 0;
  10517. foreach($this->PageNumSubstitutions AS $psarr) {
  10518. if ($num >= $psarr['from']) {
  10519. if ($psarr['reset']) {
  10520. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  10521. $ppgstart = $psarr['from'] + $offset;
  10522. $ppgend = count($this->pages)+1 + $offset;
  10523. }
  10524. if ($psarr['type']) { $type = $psarr['type']; }
  10525. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  10526. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  10527. }
  10528. if ($num < $psarr['from']) {
  10529. if ($psarr['reset']) {
  10530. $ppgend = $psarr['from'] + $offset;
  10531. break;
  10532. }
  10533. }
  10534. }
  10535. if ($suppress) { return ''; }
  10536. $ppgno = $ppgend-$ppgstart+$offset;
  10537. if ($extras) { $ppgno = $this->nbpgPrefix . $ppgno . $this->nbpgSuffix; }
  10538. return $ppgno;
  10539. }
  10540. function RestartDocTemplate() {
  10541. $this->docTemplateStart = $this->page;
  10542. }
  10543. //Page header
  10544. function Header($content='') {
  10545. $this->cMarginL = 0;
  10546. $this->cMarginR = 0;
  10547. /*-- HTMLHEADERS-FOOTERS --*/
  10548. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLHeaderE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLHeader) || (!$this->mirrorMargins && $this->HTMLHeader)) {
  10549. $this->writeHTMLHeaders();
  10550. return;
  10551. }
  10552. /*-- END HTMLHEADERS-FOOTERS --*/
  10553. $this->processingHeader=true;
  10554. $h = $this->headerDetails;
  10555. if(count($h)) {
  10556. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10557. $this->_out(sprintf('q 0 -1 1 0 0 %.3f cm ',($this->h*$this->k)));
  10558. $yadj = $this->w - $this->h;
  10559. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  10560. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10561. $headerlmargin = $this->orig_rMargin;
  10562. }
  10563. else {
  10564. $headerlmargin = $this->orig_lMargin;
  10565. }
  10566. }
  10567. else {
  10568. $yadj = 0;
  10569. $headerpgwidth = $this->pgwidth;
  10570. $headerlmargin = $this->lMargin;
  10571. }
  10572. $this->y = $this->margin_header - $yadj ;
  10573. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  10574. $this->SUP = false;
  10575. $this->SUB = false;
  10576. $this->bullet = false;
  10577. // only show pagenumber if numbering on
  10578. $pgno = $this->docPageNum($this->page, true);
  10579. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10580. $side = 'even';
  10581. }
  10582. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  10583. $side = 'odd';
  10584. }
  10585. $maxfontheight = 0;
  10586. foreach(array('L','C','R') AS $pos) {
  10587. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10588. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10589. else { $hfsz = $this->default_font_size; }
  10590. $maxfontheight = max($maxfontheight,$hfsz);
  10591. }
  10592. }
  10593. // LEFT-CENTER-RIGHT
  10594. foreach(array('L','C','R') AS $pos) {
  10595. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10596. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  10597. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  10598. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  10599. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  10600. else { $hff = $this->original_default_font; }
  10601. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10602. else { $hfsz = $this->original_default_font_size; } // pts
  10603. $maxfontheight = max($maxfontheight,$hfsz);
  10604. $hfst = '';
  10605. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) {
  10606. $hfst = $h[$side][$pos]['font-style'];
  10607. }
  10608. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  10609. $hfcol = $h[$side][$pos]['color'];
  10610. $cor = $this->ConvertColor($hfcol);
  10611. if ($cor) { $this->SetTColor($cor); } // mPDF 5.0.020
  10612. }
  10613. else { $hfcol = ''; }
  10614. $this->SetFont($hff,$hfst,$hfsz,true,true);
  10615. $this->x = $headerlmargin ;
  10616. $this->y = $this->margin_header - $yadj ;
  10617. $hd = $this->purify_utf8_text($hd);
  10618. if ($this->text_input_as_HTML) {
  10619. $hd = $this->all_entities_to_utf8($hd);
  10620. }
  10621. // CONVERT CODEPAGE
  10622. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  10623. // DIRECTIONALITY RTL
  10624. // mPDF 5.0.054
  10625. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  10626. // Font-specific ligature substitution for Indic fonts
  10627. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  10628. $align = $pos;
  10629. /*-- RTL --*/
  10630. // mPDF 5.0.054
  10631. if ($this->directionality == 'rtl') {
  10632. if ($pos == 'L') { $align = 'R'; }
  10633. else if ($pos == 'R') { $align = 'L'; }
  10634. }
  10635. /*-- END RTL --*/
  10636. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  10637. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  10638. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  10639. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  10640. $this->_out('Q');
  10641. }
  10642. else {
  10643. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  10644. }
  10645. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); } // mPDF 5.0.051
  10646. }
  10647. }
  10648. //Return Font to normal
  10649. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  10650. // LINE
  10651. if (isset($h[$side]['line']) && $h[$side]['line']) {
  10652. $this->SetLineWidth(0.1);
  10653. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  10654. $this->Line($headerlmargin , $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/$this->k) - $yadj , $headerlmargin + $headerpgwidth, $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/$this->k) - $yadj );
  10655. }
  10656. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10657. $this->_out('Q');
  10658. }
  10659. }
  10660. $this->SetY($this->tMargin);
  10661. if ($this->ColActive) { $this->pgwidth = $this->ColWidth; } // *COLUMNS*
  10662. $this->processingHeader=false;
  10663. }
  10664. /*-- TABLES --*/
  10665. function TableHeaderFooter($content='',$tablestartpage='',$tablestartcolumn ='',$horf = 'H',$level) {
  10666. if((($this->usetableheader && $horf=='H') || $horf=='F') && !empty($content)) {
  10667. $table = &$this->table[1][1];
  10668. // Advance down page by half width of top border
  10669. if ($horf=='H') { // Only if header
  10670. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  10671. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  10672. if ($adv) {
  10673. if ($this->table_rotate) {
  10674. $this->y += ($adv);
  10675. }
  10676. else {
  10677. $this->DivLn($adv,$this->blklvl,true);
  10678. }
  10679. }
  10680. }
  10681. if ($horf=='F') { // Table Footer
  10682. $firstrow = count($table['cells']) - $this->tablefooternrows;
  10683. $lastrow = count($table['cells']) - 1;
  10684. }
  10685. else { // Table Header
  10686. $firstrow = 0;
  10687. $lastrow = $this->tableheadernrows - 1;
  10688. }
  10689. $topy = $content[$firstrow][0]['y']-$this->y;
  10690. for ($i=$firstrow ; $i<=$lastrow; $i++) {
  10691. $y = $this->y;
  10692. /*-- COLUMNS --*/
  10693. // If outside columns, this is done in PaintDivBB
  10694. if ($this->ColActive) {
  10695. //OUTER FILL BGCOLOR of DIVS
  10696. if ($this->blklvl > 0) {
  10697. $firstblockfill = $this->GetFirstBlockFill();
  10698. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  10699. $divh = $content[$i][0]['h'];
  10700. $bak_x = $this->x;
  10701. $this->DivLn($divh,-3,false);
  10702. // Reset current block fill
  10703. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  10704. $this->SetFColor($bcor); // mPDF 5.0.020
  10705. $this->x = $bak_x;
  10706. }
  10707. }
  10708. }
  10709. /*-- END COLUMNS --*/
  10710. $colctr = 0;
  10711. foreach($content[$i] as $tablehf) {
  10712. $colctr++;
  10713. $y = $tablehf['y'] - $topy;
  10714. $this->y = $y;
  10715. //Set some cell values
  10716. $x = $tablehf['x'];
  10717. if (($this->mirrorMargins) && ($tablestartpage == 'ODD') && (($this->page)%2==0)) { // EVEN
  10718. $x = $x +$this->MarginCorrection;
  10719. }
  10720. else if (($this->mirrorMargins) && ($tablestartpage == 'EVEN') && (($this->page)%2==1)) { // ODD
  10721. $x = $x +$this->MarginCorrection;
  10722. }
  10723. /*-- COLUMNS --*/
  10724. // Added to correct for Columns
  10725. if ($this->ColActive) {
  10726. // mPDF 5.0.054 .068
  10727. if ($this->directionality == 'rtl') { // *RTL*
  10728. $x -= ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  10729. } // *RTL*
  10730. else { // *RTL*
  10731. $x += ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap);
  10732. } // *RTL*
  10733. }
  10734. /*-- END COLUMNS --*/
  10735. if ($colctr==1) { $x0 = $x; } // mPDF 5.0.018
  10736. // mPDF ITERATION
  10737. if ($this->iterationCounter) {
  10738. foreach($tablehf['text'] AS $k=>$t) {
  10739. if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t, $m)) {
  10740. $vname = '__'.$m[1].'_';
  10741. if (!isset($this->$vname)) { $this->$vname = 1; }
  10742. else { $this->$vname++; }
  10743. $tablehf['text'][$k] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $tablehf['text'][$k]);
  10744. $tablehf['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $tablehf['textbuffer'][$k][0]);
  10745. }
  10746. }
  10747. }
  10748. $w = $tablehf['w'];
  10749. $h = $tablehf['h'];
  10750. $va = $tablehf['va'];
  10751. $R = $tablehf['R'];
  10752. $mih = $tablehf['mih'];
  10753. // $fill = $tablehf['bgcolor']; // mPDF 5.1.008
  10754. $border = $tablehf['border'];
  10755. $border_details = $tablehf['border_details'];
  10756. $padding = $tablehf['padding'];
  10757. $this->tabletheadjustfinished = true;
  10758. $textbuffer = $tablehf['textbuffer'];
  10759. $align = $tablehf['a'];
  10760. //Align
  10761. $this->divalign=$align;
  10762. $this->x = $x;
  10763. // mPDF 5.1.008
  10764. if ($this->ColActive) { // mPDF 5.1.008
  10765. if ($table['borders_separate']) {
  10766. $tablefill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  10767. if ($tablefill) {
  10768. $color = $this->ConvertColor($tablefill);
  10769. if ($color) { // mPDF 5.0.018
  10770. $xadj = ($table['border_spacing_H']/2);
  10771. $yadj = ($table['border_spacing_V']/2);
  10772. $wadj = $table['border_spacing_H'];
  10773. $hadj = $table['border_spacing_V'];
  10774. if ($i == $firstrow && $horf=='H') { // Top
  10775. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  10776. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  10777. }
  10778. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom
  10779. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  10780. }
  10781. if ($colctr == 1) { // Left
  10782. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  10783. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  10784. }
  10785. if ($colctr == count($content[$i]) ) { // Right
  10786. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  10787. }
  10788. $this->SetFColor($color); // mPDF 5.0.020
  10789. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  10790. }
  10791. }
  10792. }
  10793. }
  10794. // TABLE BORDER - if separate
  10795. if ($table['borders_separate'] && $table['border']) {
  10796. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  10797. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  10798. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  10799. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  10800. $tbx = $x;
  10801. $tby = $y;
  10802. $tbw = $w;
  10803. $tbh = $h;
  10804. $tab_bord = 0;
  10805. $corner = '';
  10806. if ($i == $firstrow && $horf=='H') { // Top
  10807. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  10808. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  10809. $this->setBorder($tab_bord , _BORDER_TOP);
  10810. $corner .= 'T';
  10811. }
  10812. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom
  10813. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  10814. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  10815. $corner .= 'B';
  10816. }
  10817. if ($colctr == 1) { // Top Left
  10818. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  10819. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  10820. $this->setBorder($tab_bord , _BORDER_LEFT);
  10821. $corner .= 'L';
  10822. }
  10823. if ($colctr == count($content[$i])) {
  10824. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  10825. $this->setBorder($tab_bord , _BORDER_RIGHT);
  10826. $corner .= 'R';
  10827. }
  10828. $this->_tableRect($tbx, $tby, $tbw, $tbh, $tab_bord , $table['border_details'], false, $table['borders_separate'], 'table', $corner, $table['border_spacing_V'], $table['border_spacing_H'] );
  10829. }
  10830. if ($table['empty_cells']!='hide' || !empty($textbuffer) || !$table['borders_separate']) { $paintcell = true; }
  10831. else { $paintcell = false; }
  10832. //Vertical align
  10833. if ($R && INTVAL($R) > 0 && isset($va) && $va!='B') { $va='B';}
  10834. if (!isset($va) || empty($va) || $va=='M') $this->y += ($h-$mih)/2;
  10835. elseif (isset($va) && $va=='B') $this->y += $h-$mih;
  10836. //TABLE ROW OR CELL FILL BGCOLOR
  10837. // mPDF 5.1.008
  10838. $fill = 0;
  10839. if (isset($tablehf['bgcolor']) && $tablehf['bgcolor'] && $tablehf['bgcolor']!='transparent') {
  10840. $fill = $tablehf['bgcolor'];
  10841. $leveladj = 6;
  10842. }
  10843. else if (isset($content[$i][0]['trbgcolor']) && $content[$i][0]['trbgcolor'] && $content[$i][0]['trbgcolor']!='transparent') { // Row color
  10844. $fill = $content[$i][0]['trbgcolor'];
  10845. $leveladj = 3;
  10846. }
  10847. if ($fill && $paintcell) {
  10848. $color = $this->ConvertColor($fill);
  10849. if ($color) { // mPDF 5.0.017
  10850. if ($table['borders_separate']) {
  10851. // mPDF 5.1.008
  10852. if ($this->ColActive) { // mPDF 5.1.008
  10853. $this->SetFColor($color); // mPDF 5.0.020
  10854. $this->Rect($x+ ($table['border_spacing_H']/2), $y+ ($table['border_spacing_V']/2), $w- $table['border_spacing_H'], $h- $table['border_spacing_V'], 'F');
  10855. }
  10856. else {
  10857. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>($x + ($table['border_spacing_H']/2)), 'y'=>($y + ($table['border_spacing_V']/2)), 'w'=>($w - $table['border_spacing_H']), 'h'=>($h - $table['border_spacing_V']), 'col'=>$color);
  10858. }
  10859. }
  10860. else {
  10861. // mPDF 5.1.008
  10862. if ($this->ColActive) { // mPDF 5.1.008
  10863. $this->SetFColor($color); // mPDF 5.0.020
  10864. $this->Rect($x, $y, $w, $h, 'F');
  10865. }
  10866. else {
  10867. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  10868. }
  10869. }
  10870. }
  10871. }
  10872. /*-- BACKGROUNDS --*/
  10873. if (isset($tablehf['gradient']) && $tablehf['gradient'] && $paintcell){
  10874. $g = $this->parseBackgroundGradient($tablehf['gradient']);
  10875. if ($g) {
  10876. if ($table['borders_separate']) {
  10877. $px = $x+ ($table['border_spacing_H']/2);
  10878. $py = $y+ ($table['border_spacing_V']/2);
  10879. $pw = $w- $table['border_spacing_H'];
  10880. $ph = $h- $table['border_spacing_V'];
  10881. }
  10882. else {
  10883. $px = $x;
  10884. $py = $y;
  10885. $pw = $w;
  10886. $ph = $h;
  10887. }
  10888. if ($this->ColActive) { // mPDF 5.1.008
  10889. $this->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10890. }
  10891. else {
  10892. // mPDF 5.1.008
  10893. $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  10894. }
  10895. }
  10896. }
  10897. if (isset($tablehf['background-image']) && $paintcell){
  10898. // mPDF 5.0.023
  10899. if ($tablehf['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $tablehf['background-image']['gradient'] )) {
  10900. $g = $this->parseMozGradient( $tablehf['background-image']['gradient'] );
  10901. if ($g) {
  10902. if ($table['borders_separate']) {
  10903. $px = $x+ ($table['border_spacing_H']/2);
  10904. $py = $y+ ($table['border_spacing_V']/2);
  10905. $pw = $w- $table['border_spacing_H'];
  10906. $ph = $h- $table['border_spacing_V'];
  10907. }
  10908. else {
  10909. $px = $x;
  10910. $py = $y;
  10911. $pw = $w;
  10912. $ph = $h;
  10913. }
  10914. if ($this->ColActive) { // mPDF 5.1.008
  10915. $this->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10916. }
  10917. else {
  10918. // mPDF 5.1.008
  10919. $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  10920. }
  10921. }
  10922. }
  10923. else if ($tablehf['background-image']['image_id']) { // Background pattern
  10924. $n = count($this->patterns)+1;
  10925. if ($table['borders_separate']) {
  10926. $px = $x+ ($table['border_spacing_H']/2);
  10927. $py = $y+ ($table['border_spacing_V']/2);
  10928. $pw = $w- $table['border_spacing_H'];
  10929. $ph = $h- $table['border_spacing_V'];
  10930. }
  10931. else {
  10932. $px = $x;
  10933. $py = $y;
  10934. $pw = $w;
  10935. $ph = $h;
  10936. }
  10937. if ($this->ColActive) { // mPDF 5.1.008
  10938. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($tablehf['background-image']['orig_w'], $tablehf['background-image']['orig_h'], $pw, $ph, $tablehf['background-image']['resize'], $tablehf['background-image']['x_repeat'] , $tablehf['background-image']['y_repeat']);
  10939. $this->patterns[$n] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'pgh'=>$this->h, 'image_id'=>$tablehf['background-image']['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$tablehf['background-image']['x_pos'] , 'y_pos'=>$tablehf['background-image']['y_pos'] , 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat);
  10940. if ($tablehf['background-image']['opacity']>0 && $tablehf['background-image']['opacity']<1) { $opac = $this->SetAlpha($tablehf['background-image']['opacity'],'Normal',true); }
  10941. else { $opac = ''; }
  10942. $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, $px*$this->k, ($this->h-$py)*$this->k, $pw*$this->k, -$ph*$this->k));
  10943. }
  10944. else {
  10945. // mPDF 5.1.008
  10946. $image_id = $tablehf['background-image']['image_id'];
  10947. $orig_w = $tablehf['background-image']['orig_w'];
  10948. $orig_h = $tablehf['background-image']['orig_h'];
  10949. $x_pos = $tablehf['background-image']['x_pos'];
  10950. $y_pos = $tablehf['background-image']['y_pos'];
  10951. $x_repeat = $tablehf['background-image']['x_repeat'];
  10952. $y_repeat = $tablehf['background-image']['y_repeat'];
  10953. $resize = $tablehf['background-image']['resize'];
  10954. $opacity = $tablehf['background-image']['opacity'];
  10955. $this->tableBackgrounds[$level*9+8][] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity);
  10956. }
  10957. }
  10958. }
  10959. /*-- END BACKGROUNDS --*/
  10960. //Border
  10961. if ($table['borders_separate'] && $paintcell && $border) {
  10962. $this->_tableRect($x+ ($table['border_spacing_H']/2)+($border_details['L']['w'] /2), $y+ ($table['border_spacing_V']/2)+($border_details['T']['w'] /2), $w-$table['border_spacing_H']-($border_details['L']['w'] /2)-($border_details['R']['w'] /2), $h- $table['border_spacing_V']-($border_details['T']['w'] /2)-($border_details['B']['w']/2), $border, $border_details, false, $table['borders_separate']);
  10963. }
  10964. else if ($paintcell && $border) {
  10965. $this->_tableRect($x, $y, $w, $h, $border, $border_details, true, $table['borders_separate']); // true causes buffer
  10966. }
  10967. //Print cell content
  10968. // $this->divheight = $this->table_lineheight*$this->lineheight;
  10969. if (!empty($textbuffer)) {
  10970. if ($R) {
  10971. $cellPtSize = $textbuffer[0][11] / $this->shrin_k;
  10972. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; } // mPDF 5.0
  10973. $cellFontHeight = ($cellPtSize/$this->k);
  10974. $opx = $this->x;
  10975. $opy = $this->y;
  10976. $angle = INTVAL($R);
  10977. // Only allow 45 - 90 degrees (when bottom-aligned) or -90
  10978. if ($angle > 90) { $angle = 90; }
  10979. else if ($angle > 0 && (isset($va) && $va!='B')) { $angle = 90; }
  10980. else if ($angle > 0 && $angle <45) { $angle = 45; }
  10981. else if ($angle < 0) { $angle = -90; }
  10982. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  10983. if (isset($align) && $align =='R') {
  10984. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($padding['R'] + $border_details['R']['w']);
  10985. }
  10986. else if (!isset($align ) || $align =='C') {
  10987. $this->x += ($w/2) + ($offset);
  10988. }
  10989. else {
  10990. $this->x += ($offset) + ($cellFontHeight/3)+($padding['L'] + $border_details['L']['w']);
  10991. }
  10992. $str = trim(implode(' ',$tablehf['text']));
  10993. if (!isset($va) || $va=='M') {
  10994. $this->y -= ($h-$mih)/2; //Undo what was added earlier VERTICAL ALIGN
  10995. if ($angle > 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']) + ($mih-($padding['T'] + $border_details['T']['w']+$border_details['B']['w']+$padding['B'])); }
  10996. else if ($angle < 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']); }
  10997. }
  10998. else if (isset($va) && $va=='B') {
  10999. $this->y -= $h-$mih; //Undo what was added earlier VERTICAL ALIGN
  11000. if ($angle > 0) { $this->y += $h-($border_details['B']['w']+$padding['B']); }
  11001. else if ($angle < 0) { $this->y += $h-$mih+($padding['T'] + $border_details['T']['w']); }
  11002. }
  11003. else if (isset($va) && $va=='T') {
  11004. if ($angle > 0) { $this->y += $mih-($border_details['B']['w']+$padding['B']); }
  11005. else if ($angle < 0) { $this->y += ($padding['T'] + $border_details['T']['w']); }
  11006. }
  11007. $this->Rotate($angle,$this->x,$this->y);
  11008. $s_fs = $this->FontSizePt;
  11009. $s_f = $this->FontFamily;
  11010. $s_st = $this->FontStyle;
  11011. $this->SetFont($textbuffer[0][4],$textbuffer[0][2],$cellPtSize,true,true);
  11012. $this->Text($this->x,$this->y,$str);
  11013. $this->Rotate(0);
  11014. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  11015. $this->x = $opx;
  11016. $this->y = $opy;
  11017. }
  11018. else {
  11019. if ($table['borders_separate']) { // NB twice border width
  11020. $xadj = $border_details['L']['w'] + $padding['L'] +($table['border_spacing_H']/2);
  11021. $wadj = $border_details['L']['w'] + $border_details['R']['w'] + $padding['L'] +$padding['R'] + $table['border_spacing_H'];
  11022. $yadj = $border_details['T']['w'] + $padding['T'] + ($table['border_spacing_H']/2);
  11023. }
  11024. else {
  11025. $xadj = $border_details['L']['w']/2 + $padding['L'];
  11026. $wadj = ($border_details['L']['w'] + $border_details['R']['w'])/2 + $padding['L'] + $padding['R'];
  11027. $yadj = $border_details['T']['w']/2 + $padding['T'];
  11028. }
  11029. $this->divwidth=$w-($wadj);
  11030. $this->x += $xadj;
  11031. $this->y += $yadj;
  11032. $this->printbuffer($textbuffer,'',true);
  11033. }
  11034. }
  11035. $textbuffer = array();
  11036. /*-- BACKGROUNDS --*/
  11037. if (!$this->ColActive) { // mPDF 5.1.008
  11038. // mPDF 5.0.018
  11039. if (isset($content[$i][0]['trgradients']) && ($colctr==1 || $table['borders_separate'])) {
  11040. $g = $this->parseBackgroundGradient($content[$i][0]['trgradients']);
  11041. if ($g) {
  11042. $gx = $x0;
  11043. $gy = $y;
  11044. $gh = $h;
  11045. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; // mPDF 5.1.008
  11046. if ($table['borders_separate']) {
  11047. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  11048. $s = '';
  11049. $clx = $x+ ($table['border_spacing_H']/2);
  11050. $cly = $y+ ($table['border_spacing_V']/2);
  11051. $clw = $w- $table['border_spacing_H'];
  11052. $clh = $h- $table['border_spacing_V'];
  11053. // Set clipping path
  11054. $s = ' q 0 w '; // Line width=0
  11055. $s .= sprintf('%.3f %.3f m ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // start point TL before the arc
  11056. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BL
  11057. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BR
  11058. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly))*$this->k); // line to TR
  11059. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // line to TL
  11060. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  11061. // mPDF 5.0.020 // mPDF 5.0.022 // mPDF 5.1.008
  11062. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  11063. }
  11064. else {
  11065. // mPDF 5.0.020 // mPDF 5.1.008
  11066. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  11067. }
  11068. }
  11069. }
  11070. if (isset($content[$i][0]['trbackground-images']) && ($colctr==1 || $table['borders_separate'])) {
  11071. // mPDF 5.0.023
  11072. if ($content[$i][0]['trbackground-images']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $content[$i][0]['trbackground-images']['gradient'] )) {
  11073. $g = $this->parseMozGradient( $content[$i][0]['trbackground-images']['gradient'] );
  11074. if ($g) {
  11075. $gx = $x0;
  11076. $gy = $y;
  11077. $gh = $h;
  11078. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; // mPDF 5.1.008
  11079. if ($table['borders_separate']) {
  11080. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  11081. $s = '';
  11082. $clx = $x+ ($table['border_spacing_H']/2);
  11083. $cly = $y+ ($table['border_spacing_V']/2);
  11084. $clw = $w- $table['border_spacing_H'];
  11085. $clh = $h- $table['border_spacing_V'];
  11086. // Set clipping path
  11087. $s = ' q 0 w '; // Line width=0
  11088. $s .= sprintf('%.3f %.3f m ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // start point TL before the arc
  11089. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BL
  11090. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BR
  11091. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly))*$this->k); // line to TR
  11092. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // line to TL
  11093. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  11094. // mPDF 5.0.020 // mPDF 5.0.022 // mPDF 5.1.008
  11095. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  11096. }
  11097. else {
  11098. // mPDF 5.0.020 // mPDF 5.1.008
  11099. $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  11100. }
  11101. }
  11102. }
  11103. else {
  11104. $image_id = $content[$i][0]['trbackground-images']['image_id'];
  11105. $orig_w = $content[$i][0]['trbackground-images']['orig_w'];
  11106. $orig_h = $content[$i][0]['trbackground-images']['orig_h'];
  11107. $x_pos = $content[$i][0]['trbackground-images']['x_pos'];
  11108. $y_pos = $content[$i][0]['trbackground-images']['y_pos'];
  11109. $x_repeat = $content[$i][0]['trbackground-images']['x_repeat'];
  11110. $y_repeat = $content[$i][0]['trbackground-images']['y_repeat'];
  11111. $resize = $content[$i][0]['trbackground-images']['resize'];
  11112. $opacity = $content[$i][0]['trbackground-images']['opacity'];
  11113. $clippath = '';
  11114. $gx = $x0;
  11115. $gy = $y;
  11116. $gh = $h;
  11117. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; // mPDF 5.1.008
  11118. if ($table['borders_separate']) {
  11119. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  11120. $s = '';
  11121. $clx = $x+ ($table['border_spacing_H']/2);
  11122. $cly = $y+ ($table['border_spacing_V']/2);
  11123. $clw = $w- $table['border_spacing_H'];
  11124. $clh = $h- $table['border_spacing_V'];
  11125. // Set clipping path
  11126. $s = ' q 0 w '; // Line width=0
  11127. $s .= sprintf('%.3f %.3f m ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // start point TL before the arc
  11128. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BL
  11129. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BR
  11130. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly))*$this->k); // line to TR
  11131. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // line to TL
  11132. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  11133. // mPDF 5.0.022 // mPDF 5.1.008
  11134. $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>$s, 'resize'=>$resize, 'opacity'=>$opacity);
  11135. }
  11136. else { // mPDF 5.1.008
  11137. $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity);
  11138. }
  11139. }
  11140. }
  11141. }
  11142. /*-- END BACKGROUNDS --*/
  11143. }// end column $content
  11144. $this->y = $y + $h; //Update y coordinate
  11145. }// end row $i
  11146. }//end of 'if usetableheader ...'
  11147. }
  11148. /*-- END TABLES --*/
  11149. /*-- HTMLHEADERS-FOOTERS --*/
  11150. function SetHTMLHeader($header='',$OE='',$write=false) {
  11151. $height = 0;
  11152. if (is_array($header) && isset($header['html']) && $header['html']) {
  11153. $Hhtml = $header['html'];
  11154. if ($this->setAutoTopMargin) {
  11155. if (isset($header['h'])) { $height = $header['h']; }
  11156. else { $height = $this->_gethtmlheight($Hhtml); }
  11157. }
  11158. }
  11159. else if (!is_array($header) && $header) {
  11160. $Hhtml = $header;
  11161. if ($this->setAutoTopMargin) { $height = $this->_gethtmlheight($Hhtml); }
  11162. }
  11163. else { $Hhtml = ''; }
  11164. if ($OE != 'E') { $OE = 'O'; }
  11165. if ($OE == 'E') {
  11166. if ($Hhtml) {
  11167. $this->HTMLHeaderE['html'] = $Hhtml;
  11168. $this->HTMLHeaderE['h'] = $height;
  11169. }
  11170. else { $this->HTMLHeaderE = ''; }
  11171. }
  11172. else {
  11173. if ($Hhtml) {
  11174. $this->HTMLHeader['html'] = $Hhtml;
  11175. $this->HTMLHeader['h'] = $height;
  11176. }
  11177. else { $this->HTMLHeader = ''; }
  11178. }
  11179. if (!$this->mirrorMargins && $OE == 'E') { return; }
  11180. if ($Hhtml=='') { return; }
  11181. if ($OE == 'E') {
  11182. $this->headerDetails['even'] = array(); // override and clear any other non-HTML header/footer
  11183. }
  11184. else {
  11185. $this->headerDetails['odd'] = array(); // override and clear any non-HTML other header/footer
  11186. }
  11187. if ($this->setAutoTopMargin=='pad') {
  11188. $this->tMargin = $this->margin_header + $height + $this->orig_tMargin;
  11189. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  11190. }
  11191. else if ($this->setAutoTopMargin=='stretch') {
  11192. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $height + $this->autoMarginPadding);
  11193. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  11194. }
  11195. if ($write && $this->state!=0 && (($this->mirrorMargins && $OE == 'E' && ($this->page)%2==0) || ($this->mirrorMargins && $OE != 'E' && ($this->page)%2==1) || !$this->mirrorMargins)) { $this->writeHTMLHeaders(); }
  11196. }
  11197. function SetHTMLFooter($footer='',$OE='') {
  11198. $height = 0;
  11199. if (is_array($footer) && isset($footer['html']) && $footer['html']) {
  11200. $Fhtml = $footer['html'];
  11201. if ($this->setAutoBottomMargin) {
  11202. if (isset($footer['h'])) { $height = $footer['h']; }
  11203. else { $height = $this->_gethtmlheight($Fhtml); }
  11204. }
  11205. }
  11206. else if (!is_array($footer) && $footer) {
  11207. $Fhtml = $footer;
  11208. if ($this->setAutoBottomMargin) { $height = $this->_gethtmlheight($Fhtml); }
  11209. }
  11210. else { $Fhtml = ''; }
  11211. if ($OE != 'E') { $OE = 'O'; }
  11212. if ($OE == 'E') {
  11213. if ($Fhtml) {
  11214. $this->HTMLFooterE['html'] = $Fhtml;
  11215. $this->HTMLFooterE['h'] = $height;
  11216. }
  11217. else { $this->HTMLFooterE = ''; }
  11218. }
  11219. else {
  11220. if ($Fhtml) {
  11221. $this->HTMLFooter['html'] = $Fhtml;
  11222. $this->HTMLFooter['h'] = $height;
  11223. }
  11224. else { $this->HTMLFooter = ''; }
  11225. }
  11226. if (!$this->mirrorMargins && $OE == 'E') { return; }
  11227. if ($Fhtml=='') { return false; }
  11228. if ($OE == 'E') {
  11229. $this->footerDetails['even'] = array(); // override and clear any other header/footer
  11230. }
  11231. else {
  11232. $this->footerDetails['odd'] = array(); // override and clear any other header/footer
  11233. }
  11234. if ($this->setAutoBottomMargin=='pad') {
  11235. $this->bMargin = $this->margin_footer + $height + $this->orig_bMargin;
  11236. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  11237. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  11238. }
  11239. else if ($this->setAutoBottomMargin=='stretch') {
  11240. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $height + $this->autoMarginPadding);
  11241. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  11242. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  11243. }
  11244. }
  11245. function _getHtmlHeight($html) {
  11246. $save_state = $this->state;
  11247. if($this->state==0) {
  11248. $this->AddPage($this->CurOrientation);
  11249. }
  11250. $this->state = 2;
  11251. $this->Reset();
  11252. $this->pageoutput[$this->page] = array();
  11253. $save_x = $this->x;
  11254. $save_y = $this->y;
  11255. $this->x = $this->lMargin;
  11256. $this->y = $this->margin_header;
  11257. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($this->page).$this->pagenumSuffix,$html);
  11258. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($this->page).$this->nbpgSuffix,$html );
  11259. $html = str_replace($this->aliasNbPg,$this->page,$html );
  11260. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  11261. $this->HTMLheaderPageLinks = array();
  11262. $this->HTMLheaderPageAnnots = array(); // mPDF 5.0
  11263. $savepb = $this->pageBackgrounds;
  11264. $this->writingHTMLheader = true;
  11265. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  11266. $this->writingHTMLheader = false;
  11267. $h = ($this->y - $this->margin_header);
  11268. $this->Reset();
  11269. $this->pageoutput[$this->page] = array();
  11270. $this->headerbuffer = '';
  11271. $this->pageBackgrounds = $savepb;
  11272. $this->x = $save_x;
  11273. $this->y = $save_y;
  11274. $this->state = $save_state;
  11275. if($save_state==0) {
  11276. unset($this->pages[1]);
  11277. $this->page = 0;
  11278. }
  11279. return $h;
  11280. }
  11281. // Called internally from Header
  11282. function writeHTMLHeaders() {
  11283. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  11284. else { $OE = 'O'; }
  11285. if ($OE == 'E') {
  11286. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeaderE['html'] ;
  11287. }
  11288. else {
  11289. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeader['html'] ;
  11290. }
  11291. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  11292. $this->saveHTMLHeader[$this->page][$OE]['rotate'] = true;
  11293. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->tMargin;
  11294. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->bMargin;
  11295. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  11296. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  11297. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->h;
  11298. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->w;
  11299. }
  11300. else {
  11301. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->lMargin;
  11302. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->rMargin;
  11303. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  11304. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  11305. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->w;
  11306. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->h;
  11307. }
  11308. }
  11309. function writeHTMLFooters() {
  11310. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  11311. else { $OE = 'O'; }
  11312. if ($OE == 'E') {
  11313. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooterE['html'] ;
  11314. }
  11315. else {
  11316. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooter['html'] ;
  11317. }
  11318. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  11319. $this->saveHTMLFooter[$this->page][$OE]['rotate'] = true;
  11320. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->tMargin;
  11321. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->bMargin;
  11322. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->rMargin;
  11323. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->lMargin;
  11324. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  11325. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  11326. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->h;
  11327. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->w;
  11328. }
  11329. else {
  11330. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->lMargin;
  11331. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->rMargin;
  11332. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->tMargin;
  11333. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->bMargin;
  11334. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  11335. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  11336. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->w;
  11337. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->h;
  11338. }
  11339. }
  11340. /*-- END HTMLHEADERS-FOOTERS --*/
  11341. function DefHeaderByName($name,$arr) {
  11342. if (!$name) { $name = '_default'; }
  11343. $this->pageheaders[$name] = $arr;
  11344. }
  11345. function DefFooterByName($name,$arr) {
  11346. if (!$name) { $name = '_default'; }
  11347. $this->pagefooters[$name] = $arr;
  11348. }
  11349. function SetHeaderByName($name,$side='O',$write=false) {
  11350. if (!$name) { $name = '_default'; }
  11351. if ($side=='E') { $this->headerDetails['even'] = $this->pageheaders[$name]; }
  11352. else { $this->headerDetails['odd'] = $this->pageheaders[$name]; }
  11353. if ($write) { $this->Header(); }
  11354. }
  11355. function SetFooterByName($name,$side='O') {
  11356. if (!$name) { $name = '_default'; }
  11357. if ($side=='E') { $this->footerDetails['even'] = $this->pagefooters[$name]; }
  11358. else { $this->footerDetails['odd'] = $this->pagefooters[$name]; }
  11359. }
  11360. /*-- HTMLHEADERS-FOOTERS --*/
  11361. function DefHTMLHeaderByName($name,$html) {
  11362. if (!$name) { $name = '_default'; }
  11363. $this->pageHTMLheaders[$name]['html'] = $html;
  11364. $this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html);
  11365. }
  11366. function DefHTMLFooterByName($name,$html) {
  11367. if (!$name) { $name = '_default'; }
  11368. $this->pageHTMLfooters[$name]['html'] = $html;
  11369. $this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html);
  11370. }
  11371. function SetHTMLHeaderByName($name,$side='O',$write=false) {
  11372. if (!$name) { $name = '_default'; }
  11373. $this->SetHTMLHeader($this->pageHTMLheaders[$name],$side,$write);
  11374. }
  11375. function SetHTMLFooterByName($name,$side='O') {
  11376. if (!$name) { $name = '_default'; }
  11377. $this->SetHTMLFooter($this->pageHTMLfooters[$name],$side,$write);
  11378. }
  11379. /*-- END HTMLHEADERS-FOOTERS --*/
  11380. function SetHeader($Harray=array(),$side='',$write=false) {
  11381. if (is_string($Harray)) {
  11382. if (strlen($Harray)==0) {
  11383. if ($side=='O') { $this->headerDetails['odd'] = array(); }
  11384. else if ($side=='E') { $this->headerDetails['even'] = array(); }
  11385. else { $this->headerDetails = array(); }
  11386. }
  11387. else if (strpos($Harray,'|') || strpos($Harray,'|')===0) {
  11388. $hdet = explode('|',$Harray);
  11389. $this->headerDetails = array (
  11390. 'odd' => array (
  11391. 'L' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11392. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11393. 'R' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11394. 'line' => $this->defaultheaderline,
  11395. ),
  11396. 'even' => array (
  11397. 'R' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11398. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11399. 'L' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11400. 'line' => $this->defaultheaderline,
  11401. )
  11402. );
  11403. }
  11404. else {
  11405. $this->headerDetails = array (
  11406. 'odd' => array (
  11407. 'R' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11408. 'line' => $this->defaultheaderline,
  11409. ),
  11410. 'even' => array (
  11411. 'L' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11412. 'line' => $this->defaultheaderline,
  11413. )
  11414. );
  11415. }
  11416. }
  11417. else if (is_array($Harray)) {
  11418. if ($side=='O') { $this->headerDetails['odd'] = $Harray; }
  11419. else if ($side=='E') { $this->headerDetails['even'] = $Harray; }
  11420. else { $this->headerDetails = $Harray; }
  11421. }
  11422. /*-- HTMLHEADERS-FOOTERS --*/
  11423. // Overwrite any HTML Header previously set
  11424. if ($side=='E') { $this->SetHTMLHeader('','E'); }
  11425. else if ($side=='O') { $this->SetHTMLHeader(''); }
  11426. else {
  11427. $this->SetHTMLHeader('');
  11428. $this->SetHTMLHeader('','E');
  11429. }
  11430. /*-- END HTMLHEADERS-FOOTERS --*/
  11431. if ($write) {
  11432. $save_y = $this->y;
  11433. $this->Header();
  11434. $this->SetY($save_y) ;
  11435. }
  11436. }
  11437. function SetFooter($Farray=array(),$side='') {
  11438. if (is_string($Farray)) {
  11439. if (strlen($Farray)==0) {
  11440. if ($side=='O') { $this->footerDetails['odd'] = array(); }
  11441. else if ($side=='E') { $this->footerDetails['even'] = array(); }
  11442. else { $this->footerDetails = array(); }
  11443. }
  11444. else if (strpos($Farray,'|') || strpos($Farray,'|')===0) {
  11445. $fdet = explode('|',$Farray);
  11446. $this->footerDetails = array (
  11447. 'odd' => array (
  11448. 'L' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11449. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11450. 'R' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11451. 'line' => $this->defaultfooterline,
  11452. ),
  11453. 'even' => array (
  11454. 'R' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11455. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11456. 'L' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11457. 'line' => $this->defaultfooterline,
  11458. )
  11459. );
  11460. }
  11461. else {
  11462. $this->footerDetails = array (
  11463. 'odd' => array (
  11464. 'R' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11465. 'line' => $this->defaultfooterline,
  11466. ),
  11467. 'even' => array (
  11468. 'L' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11469. 'line' => $this->defaultfooterline,
  11470. )
  11471. );
  11472. }
  11473. }
  11474. else if (is_array($Farray)) {
  11475. if ($side=='O') { $this->footerDetails['odd'] = $Farray; }
  11476. else if ($side=='E') { $this->footerDetails['even'] = $Farray; }
  11477. else { $this->footerDetails = $Farray; }
  11478. }
  11479. /*-- HTMLHEADERS-FOOTERS --*/
  11480. // Overwrite any HTML Footer previously set
  11481. if ($side=='E') { $this->SetHTMLFooter('','E'); }
  11482. else if ($side=='O') { $this->SetHTMLFooter(''); }
  11483. else {
  11484. $this->SetHTMLFooter('');
  11485. $this->SetHTMLFooter('','E');
  11486. }
  11487. /*-- END HTMLHEADERS-FOOTERS --*/
  11488. }
  11489. /*-- WATERMARK --*/
  11490. function setUnvalidatedText($txt='', $alpha=-1) {
  11491. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  11492. $this->watermarkText = $txt;
  11493. }
  11494. function SetWatermarkText($txt='', $alpha=-1) {
  11495. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  11496. $this->watermarkText = $txt;
  11497. }
  11498. function SetWatermarkImage($src, $alpha=-1, $size='D', $pos='F') {
  11499. if ($alpha>=0) $this->watermarkImageAlpha = $alpha;
  11500. $this->watermarkImage = $src;
  11501. $this->watermark_size = $size;
  11502. $this->watermark_pos = $pos;
  11503. }
  11504. /*-- END WATERMARK --*/
  11505. //Page footer
  11506. function Footer() {
  11507. /*-- CSS-PAGE --*/
  11508. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  11509. if ($this->show_marks == 'CROP' || $this->show_marks == 'CROPCROSS') { // mPDF 5.0.006
  11510. // Show TICK MARKS
  11511. $this->SetLineWidth(0.1); // = 0.1 mm
  11512. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  11513. $l = $this->cropMarkLength; // mPDF 5.0.047
  11514. $m = $this->cropMarkMargin; // mPDF 5.0.047 // Distance of crop mark from margin
  11515. $b = $this->nonPrintMargin; // mPDF 5.0.047 // Non-printable border at edge of paper sheet
  11516. $ax1 = $b;
  11517. $bx = $this->page_box['outer_width_LR'] - $m;
  11518. $ax = max($ax1, $bx-$l);
  11519. $cx1 = $this->w - $b;
  11520. $dx = $this->w - $this->page_box['outer_width_LR'] + $m;
  11521. $cx = min($cx1, $dx+$l);
  11522. $ay1 = $b;
  11523. $by = $this->page_box['outer_width_TB'] - $m;
  11524. $ay = max($ay1, $by-$l);
  11525. $cy1 = $this->h - $b;
  11526. $dy = $this->h - $this->page_box['outer_width_TB'] + $m;
  11527. $cy = min($cy1, $dy+$l);
  11528. $this->Line($ax, $this->page_box['outer_width_TB'], $bx, $this->page_box['outer_width_TB']);
  11529. $this->Line($cx, $this->page_box['outer_width_TB'], $dx, $this->page_box['outer_width_TB']);
  11530. $this->Line($ax, $this->h - $this->page_box['outer_width_TB'], $bx, $this->h - $this->page_box['outer_width_TB']);
  11531. $this->Line($cx, $this->h - $this->page_box['outer_width_TB'], $dx, $this->h - $this->page_box['outer_width_TB']);
  11532. $this->Line($this->page_box['outer_width_LR'], $ay, $this->page_box['outer_width_LR'], $by);
  11533. $this->Line($this->page_box['outer_width_LR'], $cy, $this->page_box['outer_width_LR'], $dy);
  11534. $this->Line($this->w - $this->page_box['outer_width_LR'], $ay, $this->w - $this->page_box['outer_width_LR'], $by);
  11535. $this->Line($this->w - $this->page_box['outer_width_LR'], $cy, $this->w - $this->page_box['outer_width_LR'], $dy);
  11536. if ($this->printers_info) { // mPDF 5.0.006
  11537. $hd = date('Y-m-d H:i').' Page '.$this->page.' of {nb}';
  11538. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  11539. $this->SetFont('arial','',7.5,true,true);
  11540. $this->x = $this->page_box['outer_width_LR'] + 1.5;
  11541. $this->y = 1;
  11542. $this->Cell($headerpgwidth ,$this->FontSize,$hd,0,0,'L',0,'',0,0,0,'M');
  11543. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  11544. }
  11545. }
  11546. if ($this->show_marks == 'CROSS' || $this->show_marks == 'CROPCROSS') { // mPDF 5.0.006
  11547. $this->SetLineWidth(0.1); // = 0.1 mm
  11548. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  11549. $l = 14 /2; // longer length of the cross line (half)
  11550. $w = 6 /2; // shorter width of the cross line (half)
  11551. $r = 1.2; // radius of circle
  11552. $m = $this->crossMarkMargin; // mPDF 5.0.047 // Distance of cross mark from margin
  11553. $x1 = $this->page_box['outer_width_LR'] - $m;
  11554. $x2 = $this->w - $this->page_box['outer_width_LR'] + $m;
  11555. $y1 = $this->page_box['outer_width_TB'] - $m;
  11556. $y2 = $this->h - $this->page_box['outer_width_TB'] + $m;
  11557. // Left
  11558. $this->Circle($x1, $this->h/2, $r, 'S') ;
  11559. $this->Line($x1-$w, $this->h/2, $x1+$w, $this->h/2);
  11560. $this->Line($x1, $this->h/2-$l, $x1, $this->h/2+$l);
  11561. // Right
  11562. $this->Circle($x2, $this->h/2, $r, 'S') ;
  11563. $this->Line($x2-$w, $this->h/2, $x2+$w, $this->h/2);
  11564. $this->Line($x2, $this->h/2-$l, $x2, $this->h/2+$l);
  11565. // Top
  11566. $this->Circle($this->w/2, $y1, $r, 'S') ;
  11567. $this->Line($this->w/2, $y1-$w, $this->w/2, $y1+$w);
  11568. $this->Line($this->w/2-$l, $y1, $this->w/2+$l, $y1);
  11569. // Bottom
  11570. $this->Circle($this->w/2, $y2, $r, 'S') ;
  11571. $this->Line($this->w/2, $y2-$w, $this->w/2, $y2+$w);
  11572. $this->Line($this->w/2-$l, $y2, $this->w/2+$l, $y2);
  11573. }
  11574. // If @page set non-HTML headers/footers named, they were not read until later in the HTML code - so now set them
  11575. if ($this->page==1) {
  11576. if ($this->firstPageBoxHeader) {
  11577. $this->headerDetails['odd'] = $this->pageheaders[$this->firstPageBoxHeader];
  11578. $this->Header();
  11579. }
  11580. if ($this->firstPageBoxFooter) {
  11581. $this->footerDetails['odd'] = $this->pagefooters[$this->firstPageBoxFooter];
  11582. }
  11583. $this->firstPageBoxHeader='';
  11584. $this->firstPageBoxFooter='';
  11585. }
  11586. /*-- END CSS-PAGE --*/
  11587. /*-- HTMLHEADERS-FOOTERS --*/
  11588. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLFooterE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLFooter) || (!$this->mirrorMargins && $this->HTMLFooter)) {
  11589. $this->writeHTMLFooters();
  11590. /*-- WATERMARK --*/
  11591. if (($this->watermarkText) && ($this->showWatermarkText)) {
  11592. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  11593. }
  11594. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  11595. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  11596. }
  11597. /*-- END WATERMARK --*/
  11598. return;
  11599. }
  11600. /*-- END HTMLHEADERS-FOOTERS --*/
  11601. $this->processingHeader=true;
  11602. $this->ResetMargins(); // necessary after columns
  11603. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11604. /*-- WATERMARK --*/
  11605. if (($this->watermarkText) && ($this->showWatermarkText)) {
  11606. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  11607. }
  11608. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  11609. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  11610. }
  11611. /*-- END WATERMARK --*/
  11612. $h = $this->footerDetails;
  11613. if(count($h)) {
  11614. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  11615. $this->_out(sprintf('q 0 -1 1 0 0 %.3f cm ',($this->h*$this->k)));
  11616. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  11617. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  11618. $headerlmargin = $this->orig_rMargin;
  11619. }
  11620. else {
  11621. $headerlmargin = $this->orig_lMargin;
  11622. }
  11623. }
  11624. else {
  11625. $yadj = 0;
  11626. $headerpgwidth = $this->pgwidth;
  11627. $headerlmargin = $this->lMargin;
  11628. }
  11629. $this->SetY(-$this->margin_footer);
  11630. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  11631. $this->SUP = false;
  11632. $this->SUB = false;
  11633. $this->bullet = false;
  11634. // only show pagenumber if numbering on
  11635. $pgno = $this->docPageNum($this->page, true);
  11636. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  11637. $side = 'even';
  11638. }
  11639. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  11640. $side = 'odd';
  11641. }
  11642. $maxfontheight = 0;
  11643. foreach(array('L','C','R') AS $pos) {
  11644. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  11645. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  11646. else { $hfsz = $this->default_font_size; }
  11647. $maxfontheight = max($maxfontheight,$hfsz);
  11648. }
  11649. }
  11650. // LEFT-CENTER-RIGHT
  11651. foreach(array('L','C','R') AS $pos) {
  11652. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  11653. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  11654. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  11655. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  11656. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  11657. else { $hff = $this->original_default_font; }
  11658. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  11659. else { $hfsz = $this->original_default_font_size; }
  11660. $maxfontheight = max($maxfontheight,$hfsz);
  11661. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) { $hfst = $h[$side][$pos]['font-style']; }
  11662. else { $hfst = ''; }
  11663. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  11664. $hfcol = $h[$side][$pos]['color'];
  11665. $cor = $this->ConvertColor($hfcol);
  11666. if ($cor) { $this->SetTColor($cor); } // mPDF 5.0.020
  11667. }
  11668. else { $hfcol = ''; }
  11669. $this->SetFont($hff,$hfst,$hfsz,true,true);
  11670. $this->x = $headerlmargin ;
  11671. // $this->y = $this->h - $this->margin_footer - ($maxfontheight/$this->k * 0.5) - 0.5;
  11672. $this->y = $this->h - $this->margin_footer - ($maxfontheight/$this->k);
  11673. $hd = $this->purify_utf8_text($hd);
  11674. if ($this->text_input_as_HTML) {
  11675. $hd = $this->all_entities_to_utf8($hd);
  11676. }
  11677. // CONVERT CODEPAGE
  11678. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  11679. // DIRECTIONALITY RTL
  11680. // mPDF 5.0.054
  11681. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  11682. // Font-specific ligature substitution for Indic fonts
  11683. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  11684. $align = $pos;
  11685. // mPDF 5.0.054
  11686. if ($this->directionality == 'rtl') {
  11687. if ($pos == 'L') { $align = 'R'; }
  11688. else if ($pos == 'R') { $align = 'L'; }
  11689. }
  11690. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  11691. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  11692. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  11693. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  11694. $this->_out('Q');
  11695. }
  11696. else {
  11697. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  11698. }
  11699. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); } // mPDF 5.0.051
  11700. }
  11701. }
  11702. // Return Font to normal
  11703. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  11704. // LINE
  11705. if (isset($h[$side]['line']) && $h[$side]['line']) {
  11706. $this->SetLineWidth(0.1);
  11707. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  11708. $this->Line($headerlmargin , $this->y-($maxfontheight*($this->footer_line_spacing)/$this->k), $headerlmargin +$headerpgwidth, $this->y-($maxfontheight*($this->footer_line_spacing)/$this->k));
  11709. }
  11710. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  11711. $this->_out('Q');
  11712. }
  11713. }
  11714. $this->processingHeader=false;
  11715. }
  11716. /*-- HYPHENATION --*/
  11717. ///////////////////
  11718. ///////////////////
  11719. // HYPHENATION
  11720. ///////////////////
  11721. // Soft hyphs
  11722. function softHyphenate($word, $maxWidth) {
  11723. // Don't hyphenate web addresses
  11724. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  11725. // Get dictionary
  11726. $poss = array();
  11727. $softhyphens = array();
  11728. $offset = 0;
  11729. $p = true;
  11730. if ($this->usingCoreFont) {
  11731. $wl = strlen($word);
  11732. }
  11733. else {
  11734. $wl = mb_strlen($word,'UTF-8');
  11735. }
  11736. while($offset < $wl) {
  11737. // Soft Hyphens chr(173)
  11738. if (!$this->usingCoreFont) {
  11739. $p = mb_strpos($word, "\xc2\xad", $offset, 'UTF-8');
  11740. }
  11741. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  11742. $p = strpos($word, chr(173), $offset);
  11743. }
  11744. if ($p !== false) { $poss[] = $p - count($poss); }
  11745. else { break; }
  11746. $offset = $p+1;
  11747. }
  11748. $success = false;
  11749. foreach($poss AS $i) {
  11750. if ($this->usingCoreFont) {
  11751. $a = substr($word,0,$i);
  11752. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  11753. $pre = $a;
  11754. $post = substr($word,$i,strlen($word));
  11755. $prelength = strlen($pre);
  11756. }
  11757. else {
  11758. $a = mb_substr($word,0,$i,'UTF-8');
  11759. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  11760. $pre = $a;
  11761. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8');
  11762. $prelength = mb_strlen($pre, 'UTF-8');
  11763. }
  11764. $success = true;
  11765. }
  11766. return array($success,$pre,$post,$prelength);
  11767. }
  11768. ///////////////////
  11769. // Word hyphenation
  11770. function hyphenateWord($word, $maxWidth) {
  11771. // Do everything inside this function in utf-8
  11772. // Don't hyphenate web addresses
  11773. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  11774. // Get dictionary
  11775. if (!$this->loadedSHYdictionary) {
  11776. if (file_exists(_MPDF_PATH.'patterns/dictionary.txt')) {
  11777. $this->SHYdictionary = file(_MPDF_PATH.'patterns/dictionary.txt',FILE_SKIP_EMPTY_LINES);
  11778. foreach($this->SHYdictionary as $entry) {
  11779. $entry = trim($entry);
  11780. $poss = array();
  11781. $offset = 0;
  11782. $p = true;
  11783. $wl = mb_strlen($entry ,'UTF-8');
  11784. while($offset < $wl) {
  11785. $p = mb_strpos($entry, '/', $offset, 'UTF-8');
  11786. if ($p !== false) { $poss[] = $p - count($poss); }
  11787. else { break; }
  11788. $offset = $p+1;
  11789. }
  11790. if (count($poss)) { $this->SHYdictionaryWords[str_replace('/', '', mb_strtolower($entry))] = $poss; }
  11791. }
  11792. }
  11793. $this->loadedSHYdictionary = true;
  11794. }
  11795. if (!in_array($this->SHYlang,$this->SHYlanguages)) { return array(false,'','',''); }
  11796. // If no pattern loaded or not the best one
  11797. if (count($this->SHYpatterns) < 1 || ($this->loadedSHYpatterns && $this->loadedSHYpatterns != $this->SHYlang)) {
  11798. include(_MPDF_PATH."patterns/" . $this->SHYlang . ".php");
  11799. $patterns = explode(' ', $patterns);
  11800. $new_patterns = array();
  11801. for($i = 0; $i < count($patterns); $i++) {
  11802. $value = $patterns[$i];
  11803. $new_patterns[preg_replace('/[0-9]/', '', $value)] = $value;
  11804. }
  11805. $this->SHYpatterns = $new_patterns;
  11806. $this->loadedSHYpatterns = $this->SHYlang;
  11807. }
  11808. if ($this->usingCoreFont) { $word = mb_convert_encoding($word,'UTF-8',$this->mb_enc); }
  11809. $prepre = '';
  11810. $postpost = '';
  11811. $startpunctuation = "\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f";
  11812. $endpunctuation = "\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb";
  11813. $pre = '';
  11814. $post = '';
  11815. if (preg_match('/^(["\''.$startpunctuation .'])+(.{'.$this->SHYcharmin.',})$/u',$word,$m)) {
  11816. $prepre = $m[1];
  11817. $word = $m[2];
  11818. }
  11819. if (preg_match('/^(.{'.$this->SHYcharmin.',})([\'\.,;:!?"'.$endpunctuation .']+)$/u',$word,$m)) {
  11820. $word = $m[1];
  11821. $postpost = $m[2];
  11822. }
  11823. if(mb_strlen($word,'UTF-8') < $this->SHYcharmin) {
  11824. return array(false,'','','');
  11825. }
  11826. $success = false;
  11827. if(isset($this->SHYdictionaryWords[mb_strtolower($word)])) {
  11828. foreach($this->SHYdictionaryWords[mb_strtolower($word)] AS $i) {
  11829. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11830. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11831. else { $testa = $a; }
  11832. if ($this->GetStringWidth($testa.'-') > $maxWidth) { break ; }
  11833. $pre = $a;
  11834. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11835. $success = true;
  11836. }
  11837. }
  11838. if (!$success) {
  11839. $text_word = '_' . $word . '_';
  11840. $word_length = mb_strlen($text_word,'UTF-8');
  11841. $single_character = preg_split('//u', $text_word);
  11842. $text_word = mb_strtolower($text_word,'UTF-8');
  11843. $hyphenated_word = array();
  11844. $numb3rs = array('0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true);
  11845. for($position = 0; $position <= ($word_length - $this->SHYcharmin); $position++) {
  11846. $maxwins = min(($word_length - $position), $this->SHYcharmax);
  11847. for($win = $this->SHYcharmin; $win <= $maxwins; $win++) {
  11848. if(isset($this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')])) {
  11849. $pattern = $this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')];
  11850. $digits = 1;
  11851. $pattern_length = mb_strlen($pattern,'UTF-8');
  11852. for($i = 0; $i < $pattern_length; $i++) {
  11853. $char = $pattern[$i];
  11854. if(isset($numb3rs[$char])) {
  11855. $zero = ($i == 0) ? $position - 1 : $position + $i - $digits;
  11856. if(!isset($hyphenated_word[$zero]) || $hyphenated_word[$zero] != $char) $hyphenated_word[$zero] = $char;
  11857. $digits++;
  11858. }
  11859. }
  11860. }
  11861. }
  11862. }
  11863. for($i = $this->SHYleftmin; $i <= (mb_strlen($word,'UTF-8') - $this->SHYrightmin); $i++) {
  11864. if(isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 != 0) {
  11865. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11866. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11867. else { $testa = $a; }
  11868. if ($this->GetStringWidth($testa.'-') > $maxWidth + 0.0001) { break ; }
  11869. $pre = $a;
  11870. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11871. $success = true;
  11872. }
  11873. }
  11874. }
  11875. if ($this->usingCoreFont) {
  11876. $pre = mb_convert_encoding($pre,$this->mb_enc,'UTF-8');
  11877. $post = mb_convert_encoding($post,$this->mb_enc,'UTF-8');
  11878. $prelength = strlen($pre);
  11879. }
  11880. else {
  11881. $prelength = mb_strlen($pre);
  11882. }
  11883. return array($success,$pre,$post,$prelength);
  11884. }
  11885. /*-- END HYPHENATION --*/
  11886. ///////////////////
  11887. /// HTML parser ///
  11888. ///////////////////
  11889. function WriteHTML($html,$sub=0,$init=true,$close=true) {
  11890. // $sub ADDED - 0 = default; 1=headerCSS only; 2=HTML body (parts) only; 3 - HTML parses only
  11891. // 4 - writes HTML headers
  11892. // $close Leaves buffers etc. in current state, so that it can continue a block etc.
  11893. // $init - Clears and sets buffers to Top level block etc.
  11894. if (empty($html)) { $html = ''; }
  11895. if ($this->progressBar) { $this->UpdateProgressBar(1,0,'Parsing CSS & Headers'); } // *PROGRESS-BAR*
  11896. if ($init) {
  11897. $this->headerbuffer='';
  11898. $this->textbuffer = array();
  11899. $this->fixedPosBlockSave = array();
  11900. }
  11901. if ($sub == 1) { $html = '<style> '.$html.' </style>'; } // stylesheet only
  11902. if ($this->allow_charset_conversion) {
  11903. if ($sub < 1) {
  11904. $this->ReadCharset($html);
  11905. }
  11906. if ($this->charset_in) {
  11907. $success = iconv($this->charset_in,'UTF-8//TRANSLIT',$html);
  11908. if ($success) { $html = $success; }
  11909. }
  11910. }
  11911. $html = $this->purify_utf8($html,false);
  11912. if ($init) {
  11913. $this->blklvl = 0;
  11914. $this->lastblocklevelchange = 0;
  11915. $this->blk = array();
  11916. $this->initialiseBlock($this->blk[0]);
  11917. $this->blk[0]['width'] =& $this->pgwidth;
  11918. $this->blk[0]['inner_width'] =& $this->pgwidth;
  11919. $this->blk[0]['blockContext'] = $this->blockContext;
  11920. }
  11921. $zproperties = array();
  11922. if ($sub < 2) {
  11923. $this->ReadMetaTags($html);
  11924. // NB default stylesheet now in mPDF.css - read on initialising class
  11925. $html = $this->ReadCSS($html);
  11926. if ($this->useLang && !$this->usingCoreFont && preg_match('/<html [^>]*lang=[\'\"](.*?)[\'\"]/ism',$html,$m)) {
  11927. $html_lang = $m[1];
  11928. }
  11929. // mPDDF 5.0.054
  11930. if (preg_match('/<html [^>]*dir=[\'\"]\s*rtl\s*[\'\"]/ism',$html)) {
  11931. $zproperties['DIRECTION'] = 'rtl';
  11932. }
  11933. // allow in-line CSS for body tag to be parsed // Get <body> tag inline CSS
  11934. if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism',$html,$m) || preg_match('/<body([^>]*)>(.*)$/ism',$html,$m)) {
  11935. $html = $m[2];
  11936. // Changed to allow style="background: url('bg.jpg')"
  11937. if (preg_match('/style=[\"](.*?)[\"]/ism',$m[1],$mm) || preg_match('/style=[\'](.*?)[\']/ism',$m[1],$mm)) {
  11938. $zproperties = $this->readInlineCSS($mm[1]);
  11939. }
  11940. // mPDDF 5.0.0