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

https://bitbucket.org/mannysoft/erpts · PHP · 32259 lines · 28121 code · 2035 blank · 2103 comment · 6948 complexity · 95f4a7216122481a88d6f233a41c36f6 MD5 · raw file

  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.054
  11941. if (preg_match('/dir=[\'\"]\s*rtl\s*[\'\"]/ism',$m[1])) {
  11942. $zproperties['DIRECTION'] = 'rtl';
  11943. }
  11944. if (isset($html_lang) && $html_lang) { $properties['LANG'] = $html_lang; }
  11945. if ($this->useLang && !$this->usingCoreFont && preg_match('/lang=[\'\"](.*?)[\'\"]/ism',$m[1],$mm)) {
  11946. $zproperties['LANG'] = $mm[1];
  11947. }
  11948. }
  11949. }
  11950. $properties = $this->MergeCSS('BLOCK','BODY','');
  11951. if ($zproperties) { $properties = $this->array_merge_recursive_unique($properties,$zproperties); }
  11952. // mPDDF 5.0.054
  11953. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) {
  11954. $this->CSS['BODY']['DIRECTION'] = $properties['DIRECTION'];
  11955. }
  11956. if (!isset($this->CSS['BODY']['DIRECTION'])) {
  11957. $this->CSS['BODY']['DIRECTION'] = $this->directionality;
  11958. }
  11959. else { $this->SetDirectionality($this->CSS['BODY']['DIRECTION']); }
  11960. $this->setCSS($properties,'','BODY');
  11961. $this->blk[0]['InlineProperties'] = $this->saveInlineProperties(); // mPDF 5.0
  11962. if ($sub == 1) { return ''; }
  11963. if (!isset($this->CSS['BODY'])) { $this->CSS['BODY'] = array(); }
  11964. /*-- BACKGROUNDS --*/
  11965. if (isset($properties['BACKGROUND-GRADIENT'])) {
  11966. $this->bodyBackgroundGradient = $properties['BACKGROUND-GRADIENT'];
  11967. }
  11968. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE']) {
  11969. // mPDF 5.0.023
  11970. $ret = $this->SetBackground($properties, $this->pgwidth);
  11971. if ($ret) { $this->bodyBackgroundImage = $ret; }
  11972. }
  11973. /*-- END BACKGROUNDS --*/
  11974. /*-- CSS-PAGE --*/
  11975. // If page-box is set
  11976. if ($this->state==0 && isset($this->CSS['@PAGE']) && $this->CSS['@PAGE'] ) { // mPDF 5.0.052
  11977. $this->page_box['current'] = '';
  11978. $this->page_box['using'] = true;
  11979. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', false, 'O');
  11980. $this->DefOrientation = $this->CurOrientation = $pborientation;
  11981. $this->orig_lMargin = $this->DeflMargin = $pbmgl;
  11982. $this->orig_rMargin = $this->DefrMargin = $pbmgr;
  11983. $this->orig_tMargin = $this->tMargin = $pbmgt;
  11984. $this->orig_bMargin = $this->bMargin = $pbmgb;
  11985. $this->orig_hMargin = $this->margin_header = $pbmgh;
  11986. $this->orig_fMargin = $this->margin_footer = $pbmgf;
  11987. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', true, 'O'); // first page
  11988. $this->show_marks = $marks;
  11989. if ($hname && !preg_match('/^html_(.*)$/i',$hname)) $this->firstPageBoxHeader = $hname;
  11990. if ($fname && !preg_match('/^html_(.*)$/i',$fname)) $this->firstPageBoxFooter = $fname;
  11991. }
  11992. /*-- END CSS-PAGE --*/
  11993. if($this->state==0 && $sub!=1 && $sub!=3 && $sub!=4) {
  11994. $this->AddPage($this->CurOrientation);
  11995. }
  11996. $parseonly = false;
  11997. $this->bufferoutput = false;
  11998. if ($sub == 3) {
  11999. $parseonly = true;
  12000. // Close any open block tags
  12001. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  12002. // Output any text left in buffer
  12003. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  12004. $this->textbuffer=array();
  12005. }
  12006. else if ($sub == 4) {
  12007. // Close any open block tags
  12008. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  12009. // Output any text left in buffer
  12010. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  12011. $this->bufferoutput = true;
  12012. $this->textbuffer=array();
  12013. $this->headerbuffer='';
  12014. $properties = $this->MergeCSS('BLOCK','BODY','');
  12015. $this->setCSS($properties,'','BODY');
  12016. }
  12017. mb_internal_encoding('UTF-8');
  12018. $html = $this->AdjustHTML($html,$this->directionality,$this->usepre, $this->tabSpaces); //Try to make HTML look more like XHTML
  12019. if ($this->autoFontGroups) { $html = $this->AutoFont($html); }
  12020. /*-- HTMLHEADERS-FOOTERS --*/
  12021. preg_match_all('/<htmlpageheader([^>]*)>(.*?)<\/htmlpageheader>/si',$html,$h);
  12022. for($i=0;$i<count($h[1]);$i++) {
  12023. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$h[1][$i],$n)) {
  12024. $this->pageHTMLheaders[$n[1]]['html'] = $h[2][$i];
  12025. $this->pageHTMLheaders[$n[1]]['h'] = $this->_gethtmlheight($h[2][$i]);
  12026. }
  12027. }
  12028. preg_match_all('/<htmlpagefooter([^>]*)>(.*?)<\/htmlpagefooter>/si',$html,$f);
  12029. for($i=0;$i<count($f[1]);$i++) {
  12030. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$f[1][$i],$n)) {
  12031. $this->pageHTMLfooters[$n[1]]['html'] = $f[2][$i];
  12032. $this->pageHTMLfooters[$n[1]]['h'] = $this->_gethtmlheight($f[2][$i]);
  12033. }
  12034. }
  12035. /*-- END HTMLHEADERS-FOOTERS --*/
  12036. $html = preg_replace('/<htmlpageheader.*?<\/htmlpageheader>/si','',$html);
  12037. $html = preg_replace('/<htmlpagefooter.*?<\/htmlpagefooter>/si','',$html);
  12038. /*-- HTMLHEADERS-FOOTERS --*/
  12039. if (isset($hname) && preg_match('/^html_(.*)$/i',$hname,$n)) $this->SetHTMLHeader($this->pageHTMLheaders[$n[1]],'O',true);
  12040. if (isset($fname) && preg_match('/^html_(.*)$/i',$fname,$n)) $this->SetHTMLFooter($this->pageHTMLfooters[$n[1]],'O');
  12041. /*-- END HTMLHEADERS-FOOTERS --*/
  12042. $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word
  12043. if ($this->onlyCoreFonts) { $html = $this->SubstituteChars($html); }
  12044. if (preg_match("/([".$this->pregRTLchars."])/u", $html)) { $this->biDirectional = true; } // *RTL*
  12045. // mPDF 5.0
  12046. if (preg_match("/([\x{20000}-\x{2FFFF}])/u", $html)) { $this->checkSIP = true; }
  12047. else { $this->checkSIP = false; }
  12048. // mPDF 5.0.03
  12049. if (preg_match("/([\x{10000}-\x{1FFFF}])/u", $html)) { $this->checkSMP = true; }
  12050. else { $this->checkSMP = false; }
  12051. // mPDF 5.0
  12052. if (preg_match("/([".$this->pregCJKchars."])/u", $html)) { $this->checkCJK = true; }
  12053. else { $this->checkCJK = false; }
  12054. // Don't allow non-breaking spaces that are converted to substituted chars or will break anyway and mess up table width calc.
  12055. $html = str_replace('<tta>160</tta>',$this->chrs[32],$html);
  12056. $html = str_replace('</tta><tta>','|',$html);
  12057. $html = str_replace('</tts><tts>','|',$html);
  12058. $html = str_replace('</ttz><ttz>','|',$html);
  12059. //Add new supported tags in the DisableTags function
  12060. $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string
  12061. //Explode the string in order to parse the HTML code
  12062. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  12063. // ? more accurate regexp that allows e.g. <a name="Silly <name>">
  12064. // if changing - also change in fn.SubstituteChars()
  12065. // $a = preg_split ('/<((?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+)>/ms', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
  12066. if ($this->mb_enc) {
  12067. mb_internal_encoding($this->mb_enc);
  12068. }
  12069. $pbc = 0;
  12070. if ($this->progressBar) { $this->UpdateProgressBar(1,0); } // *PROGRESS-BAR*
  12071. $this->subPos = -1; // mPDF 5.1.005
  12072. $cnt = count($a);
  12073. for($i=0;$i<$cnt; $i++) {
  12074. $e = $a[$i];
  12075. if($i%2==0) {
  12076. //TEXT
  12077. if ($this->blk[$this->blklvl]['hide']) { continue; }
  12078. if ($this->inlineDisplayOff) { continue; } // mPDF 5.0
  12079. if ($this->inFixedPosBlock) { $this->fixedPosBlock .= $e; continue; } // *CSS-POSITION*
  12080. if (strlen($e) == 0) { continue; }
  12081. $e = strcode2utf($e);
  12082. $e = $this->lesser_entity_decode($e);
  12083. // mPDF 5.0
  12084. if ($this->checkSIP && $this->CurrentFont['sipext'] && !$this->usingCoreFont && $this->subPos<$i && !$this->specialcontent) {
  12085. $cnt += $this->SubstituteCharsSIP($a, $i, $e);
  12086. }
  12087. // mPDF 5.0
  12088. if ($this->useSubstitutions && !$this->onlyCoreFonts && !$this->usingCoreFont && $this->CurrentFont['type']!='Type0' && $this->subPos<$i && !$this->specialcontent) {
  12089. $cnt += $this->SubstituteCharsMB($a, $i, $e);
  12090. }
  12091. // mPDF 5.0.054
  12092. if ($this->biDirectional) { // *RTL*
  12093. $e = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $e); // *RTL*
  12094. } // *RTL*
  12095. // Font-specific ligature substitution for Indic fonts
  12096. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($e); // *INDIC*
  12097. // CONVERT ENCODING
  12098. if ($this->usingCoreFont) {
  12099. $e = mb_convert_encoding($e,$this->mb_enc,'UTF-8');
  12100. if ($this->toupper) { $e = strtoupper($e); }
  12101. if ($this->tolower) { $e = strtolower($e); }
  12102. if ($this->capitalize) { $e = ucwords($e); } // mPDF 5.0.062
  12103. }
  12104. else {
  12105. if ($this->toupper) { $e = mb_strtoupper($e,$this->mb_enc); }
  12106. if ($this->tolower) { $e = mb_strtolower($e,$this->mb_enc); }
  12107. if ($this->capitalize) { $e = mb_convert_case($e, MB_CASE_TITLE, "UTF-8"); } // mPDF 5.0.062
  12108. }
  12109. if (($this->tts) || ($this->ttz) || ($this->tta)) {
  12110. $es = explode('|',$e);
  12111. $e = '';
  12112. foreach($es AS $val) {
  12113. $e .= $this->chrs[$val];
  12114. }
  12115. }
  12116. //Adjust lineheight
  12117. //$this->SetLineHeight($this->FontSizePt); //should be inside printbuffer? // does nothing
  12118. /*-- FORMS --*/
  12119. // FORM ELEMENTS
  12120. if ($this->specialcontent) {
  12121. //SELECT tag (form element)
  12122. if ($this->specialcontent == "type=select") {
  12123. $e = ltrim($e);
  12124. $stringwidth = $this->GetStringWidth($e);
  12125. if (!isset($this->selectoption['MAXWIDTH']) || $stringwidth > $this->selectoption['MAXWIDTH']) { $this->selectoption['MAXWIDTH'] = $stringwidth; }
  12126. if (!isset($this->selectoption['SELECTED']) || $this->selectoption['SELECTED'] == '') { $this->selectoption['SELECTED'] = $e; }
  12127. // mPDD 1.4 Active Forms
  12128. if (isset($this->selectoption['ACTIVE']) && $this->selectoption['ACTIVE']) {
  12129. $this->selectoption['ITEMS'][]=array('exportValue'=>$this->selectoption['currentVAL'], 'content'=>$e, 'selected'=>$this->selectoption['currentSEL']);
  12130. }
  12131. }
  12132. // TEXTAREA
  12133. else {
  12134. $objattr = unserialize($this->specialcontent);
  12135. $objattr['text'] = $e;
  12136. $te = "\xbb\xa4\xactype=textarea,objattr=".serialize($objattr)."\xbb\xa4\xac";
  12137. if ($this->tdbegin) {
  12138. $this->cell[$this->row][$this->col]['textbuffer'][] = array($te,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  12139. }
  12140. else {
  12141. $this->textbuffer[] = array($te,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  12142. }
  12143. }
  12144. }
  12145. /*-- END FORMS --*/
  12146. // TABLE
  12147. /*-- TABLES --*/
  12148. else if ($this->tableLevel) {
  12149. if ($this->tdbegin) {
  12150. if (($this->ignorefollowingspaces) && !$this->ispre) { $e = ltrim($e); }
  12151. if ($e || $e==='0') {
  12152. if (($this->blockjustfinished || $this->listjustfinished) && $this->cell[$this->row][$this->col]['s']>0) {
  12153. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  12154. $this->cell[$this->row][$this->col]['text'][] = "\n";
  12155. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  12156. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  12157. }
  12158. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  12159. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  12160. }
  12161. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  12162. }
  12163. $this->blockjustfinished=false;
  12164. $this->listjustfinished=false;
  12165. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  12166. $this->cell[$this->row][$this->col]['text'][] = $e;
  12167. if (!isset($this->cell[$this->row][$this->col]['R']) || !$this->cell[$this->row][$this->col]['R']) {
  12168. if (isset($this->cell[$this->row][$this->col]['s'])) {
  12169. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e, false); // mPDF 5.1.020
  12170. }
  12171. else { $this->cell[$this->row][$this->col]['s'] = $this->GetStringWidth($e, false); } // mPDF 5.1.020
  12172. }
  12173. // mPDF 5.0
  12174. if ($this->checkCJK && preg_match("/([".$this->pregCJKchars."])/u", $e)) { $this->tableCJK = true; }
  12175. if ($this->tableLevel==1 && $this->useGraphs) {
  12176. $this->graphs[$this->currentGraphId]['data'][$this->row][$this->col] = $e;
  12177. }
  12178. $this->nestedtablejustfinished = false;
  12179. $this->linebreakjustfinished=false;
  12180. }
  12181. }
  12182. }
  12183. /*-- END TABLES --*/
  12184. // ALL ELSE
  12185. else {
  12186. if ($this->ignorefollowingspaces and !$this->ispre) { $e = ltrim($e); }
  12187. if ($e || $e==='0') $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  12188. }
  12189. }
  12190. else { // TAG **
  12191. if($e[0]=='/') {
  12192. /*-- PROGRESS-BAR --*/
  12193. if ($this->progressBar) { // 10% increments
  12194. if (intval($i*10/$cnt) != $pbc) { $pbc = intval($i*10/$cnt); $this->UpdateProgressBar(1,$pbc*10,$tag); }
  12195. }
  12196. /*-- END PROGRESS-BAR --*/
  12197. // Check for tags where HTML specifies optional end tags,
  12198. // and/or does not allow nesting e.g. P inside P, or
  12199. $endtag = strtoupper(substr($e,1));
  12200. if($this->blk[$this->blklvl]['hide']) {
  12201. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) {
  12202. unset($this->blk[$this->blklvl]);
  12203. $this->blklvl--;
  12204. }
  12205. continue;
  12206. }
  12207. /*-- CSS-POSITION --*/
  12208. if ($this->inFixedPosBlock) {
  12209. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) { $this->fixedPosBlockDepth--; }
  12210. if ($this->fixedPosBlockDepth == 0) {
  12211. $this->fixedPosBlockSave[] = array($this->fixedPosBlock, $this->fixedPosBlockBBox, $this->page);
  12212. $this->fixedPosBlock = '';
  12213. $this->inFixedPosBlock = false;
  12214. continue;
  12215. }
  12216. $this->fixedPosBlock .= '<'.$e.'>';
  12217. continue;
  12218. }
  12219. /*-- END CSS-POSITION --*/
  12220. if ($this->allow_html_optional_endtags && !$parseonly) {
  12221. if (($endtag == 'DIV' || $endtag =='FORM' || $endtag =='CENTER') && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); }
  12222. if ($this->lastoptionaltag == 'LI' && $endtag == 'OL') { $this->CloseTag($this->lastoptionaltag ); }
  12223. if ($this->lastoptionaltag == 'LI' && $endtag == 'UL') { $this->CloseTag($this->lastoptionaltag ); }
  12224. if ($this->lastoptionaltag == 'DD' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  12225. if ($this->lastoptionaltag == 'DT' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  12226. if ($this->lastoptionaltag == 'OPTION' && $endtag == 'SELECT') { $this->CloseTag($this->lastoptionaltag ); }
  12227. /*-- TABLES --*/
  12228. if ($endtag == 'TABLE') {
  12229. if ($this->lastoptionaltag == 'THEAD' || $this->lastoptionaltag == 'TBODY' || $this->lastoptionaltag == 'TFOOT') {
  12230. $this->CloseTag($this->lastoptionaltag);
  12231. }
  12232. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  12233. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  12234. }
  12235. if ($endtag == 'THEAD' || $endtag == 'TBODY' || $endtag == 'TFOOT') {
  12236. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  12237. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  12238. }
  12239. if ($endtag == 'TR') {
  12240. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); }
  12241. }
  12242. /*-- END TABLES --*/
  12243. }
  12244. $this->CloseTag($endtag);
  12245. }
  12246. else { // OPENING TAG
  12247. if($this->blk[$this->blklvl]['hide']) {
  12248. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  12249. else { $te = strtoupper($e); }
  12250. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) {
  12251. $this->blklvl++;
  12252. $this->blk[$this->blklvl]['hide']=true;
  12253. }
  12254. continue;
  12255. }
  12256. /*-- CSS-POSITION --*/
  12257. if ($this->inFixedPosBlock) {
  12258. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  12259. else { $te = strtoupper($e); }
  12260. $this->fixedPosBlock .= '<'.$e.'>';
  12261. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) { $this->fixedPosBlockDepth++; }
  12262. continue;
  12263. }
  12264. /*-- END CSS-POSITION --*/
  12265. $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any
  12266. $e = preg_replace($regexp,"=\"\$1\"",$e);
  12267. // changes anykey=anyvalue to anykey="anyvalue" (only do this inside tags)
  12268. if (substr($e,0,10)!='pageheader' && substr($e,0,10)!='pagefooter') {
  12269. $regexp = '| (\\w+?)=([^\\s>"]+)|si';
  12270. $e = preg_replace($regexp," \$1=\"\$2\"",$e);
  12271. }
  12272. $e = preg_replace('/ (\\S+?)\s*=\s*"/i', " \\1=\"", $e); // mPDF 5.0
  12273. //Fix path values, if needed
  12274. $orig_srcpath = '';
  12275. if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) ) {
  12276. $regexp = '/ (href|src)\s*=\s*"(.*?)"/i';
  12277. preg_match($regexp,$e,$auxiliararray);
  12278. if (isset($auxiliararray[2])) { $path = $auxiliararray[2]; }
  12279. else { $path = ''; }
  12280. if (trim($path) != '' && !(stristr($e,"src=") !== false && substr($path,0,4)=='var:')) {
  12281. $orig_srcpath = $path;
  12282. $this->GetFullPath($path);
  12283. $regexp = '/ (href|src)="(.*?)"/i';
  12284. $e = preg_replace($regexp,' \\1="'.$path.'"',$e);
  12285. }
  12286. }//END of Fix path values
  12287. //Extract attributes
  12288. $contents=array();
  12289. // Changed to allow style="background: url('bg.jpg')"
  12290. preg_match_all('/\\S*=["][^"]*["]/',$e,$contents1);
  12291. preg_match_all('/\\S*=[\'][^\']*[\']/',$e,$contents2);
  12292. $contents = array_merge($contents1, $contents2);
  12293. preg_match('/\\S+/',$e,$a2);
  12294. $tag=strtoupper($a2[0]);
  12295. $attr=array();
  12296. if ($orig_srcpath) { $attr['ORIG_SRC'] = $orig_srcpath; }
  12297. if (!empty($contents)) {
  12298. foreach($contents[0] as $v) {
  12299. // Changed to allow style="background: url('bg.jpg')"
  12300. if(preg_match('/^([^=]*)=["]?([^"]*)["]?$/',$v,$a3) || preg_match('/^([^=]*)=[\']?([^\']*)[\']?$/',$v,$a3)) {
  12301. if (strtoupper($a3[1])=='ID' || strtoupper($a3[1])=='CLASS') { // 4.2.013 Omits STYLE
  12302. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  12303. }
  12304. // includes header-style-right etc. used for <pageheader>
  12305. else if (preg_match('/^(HEADER|FOOTER)-STYLE/i',$a3[1])) {
  12306. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  12307. }
  12308. else {
  12309. $attr[strtoupper($a3[1])]=trim($a3[2]);
  12310. }
  12311. }
  12312. }
  12313. }
  12314. $this->OpenTag($tag,$attr);
  12315. /*-- CSS-POSITION --*/
  12316. if ($this->inFixedPosBlock) {
  12317. $this->fixedPosBlockBBox = array($tag,$attr, $this->x, $this->y);
  12318. $this->fixedPosBlock = '';
  12319. $this->fixedPosBlockDepth = 1;
  12320. }
  12321. /*-- END CSS-POSITION --*/
  12322. }
  12323. } // end TAG
  12324. } //end of foreach($a as $i=>$e)
  12325. if ($close) {
  12326. // Close any open block tags
  12327. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  12328. // Output any text left in buffer
  12329. if (count($this->textbuffer) && !$parseonly) { $this->printbuffer($this->textbuffer); }
  12330. if (!$parseonly) $this->textbuffer=array();
  12331. /*-- CSS-FLOAT --*/
  12332. // If ended with a float, need to move to end page
  12333. $currpos = $this->page*1000 + $this->y;
  12334. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  12335. $old_page = $this->page;
  12336. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  12337. if ($old_page != $new_page) {
  12338. $s = $this->PrintPageBackgrounds();
  12339. // Writes after the marker so not overwritten later by page background etc.
  12340. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  12341. $this->pageBackgrounds = array();
  12342. $this->page = $new_page;
  12343. $this->ResetMargins();
  12344. $this->Reset();
  12345. $this->pageoutput[$this->page] = array();
  12346. }
  12347. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  12348. }
  12349. /*-- END CSS-FLOAT --*/
  12350. /*-- CSS-IMAGE-FLOAT --*/
  12351. $this->printfloatbuffer();
  12352. /*-- END CSS-IMAGE-FLOAT --*/
  12353. //Create Internal Links, if needed
  12354. if (!empty($this->internallink) ) {
  12355. foreach($this->internallink as $k=>$v) {
  12356. if (strpos($k,"#") !== false ) { continue; } //ignore
  12357. $ypos = $v['Y'];
  12358. $pagenum = $v['PAGE'];
  12359. $sharp = "#";
  12360. while (array_key_exists($sharp.$k,$this->internallink)) {
  12361. $internallink = $this->internallink[$sharp.$k];
  12362. $this->SetLink($internallink,$ypos,$pagenum);
  12363. $sharp .= "#";
  12364. }
  12365. }
  12366. }
  12367. $this->linemaxfontsize = '';
  12368. $this->lineheight_correction = $this->default_lineheight_correction;
  12369. $this->bufferoutput = false;
  12370. /*-- CSS-POSITION --*/
  12371. if (count($this->fixedPosBlockSave) && $sub != 4) {
  12372. foreach($this->fixedPosBlockSave AS $fpbs) {
  12373. $old_page = $this->page;
  12374. $this->page = $fpbs[2];
  12375. $this->WriteFixedPosHTML($fpbs[0], 0, 0, 100, 100,'auto', $fpbs[1]); // 0,0,10,10 are overwritten by bbox
  12376. $this->page = $old_page;
  12377. }
  12378. }
  12379. /*-- END CSS-POSITION --*/
  12380. }
  12381. }
  12382. /*-- CSS-POSITION --*/
  12383. function WriteFixedPosHTML($html='',$x, $y, $w, $h, $overflow='visible', $bounding=array()) {
  12384. // $overflow can be 'hidden', 'visible' or 'auto' - 'auto' causes autofit to size
  12385. // Annotations disabled - enabled in mPDF 5.0
  12386. // Links do work
  12387. // Will always go on current page (or start Page 1 if required)
  12388. // Probably INCOMPATIBLE WITH keep with table, columns etc.
  12389. // Called externally or interally via <div style="position: [fixed|absolute]">
  12390. // When used internally, $x $y $w $h and $overflow are all overridden by $bounding
  12391. $overflow = strtolower($overflow);
  12392. if($this->state==0) {
  12393. $this->AddPage($this->CurOrientation);
  12394. }
  12395. $save_y = $this->y;
  12396. $save_x = $this->x;
  12397. $this->fullImageHeight = $this->h;
  12398. $save_cols = false;
  12399. /*-- COLUMNS --*/
  12400. if ($this->ColActive) {
  12401. $save_cols = true;
  12402. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  12403. $this->SetColumns(0);
  12404. }
  12405. /*-- END COLUMNS --*/
  12406. $save_annots = $this->title2annots; // *ANNOTATIONS*
  12407. $this->writingHTMLheader = true; // a FIX to stop pagebreaks etc.
  12408. $this->writingHTMLfooter = true;
  12409. $this->InFooter = true; // suppresses autopagebreaks
  12410. $save_bgs = $this->pageBackgrounds;
  12411. $checkinnerhtml = preg_replace('/\s/','',$html);
  12412. if ($w > $this->w) { $x = 0; $w = $this->w; }
  12413. if ($h > $this->h) { $y = 0; $h = $this->h; }
  12414. if ($x > $this->w) { $x = $this->w - $w; }
  12415. if ($y > $this->h) { $y = $this->h - $h; }
  12416. if (!empty($bounding)) {
  12417. // $cont_ containing block = full physical page (position: absolute) or page inside margins (position: fixed)
  12418. // $bbox_ Bounding box is the <div> which is positioned absolutely/fixed
  12419. // top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken from bounding
  12420. // font*[family/size/style/weight]/line-height/text*[align/decoration/transform/indent]/color are transferred to $inner
  12421. // as an enclosing <div> (after having checked ID/CLASS)
  12422. // $x, $y, $w, $h are inside of $bbox_ = containing box for $inner_
  12423. // $inner_ InnerHTML is the contents of that block to be output
  12424. $tag = $bounding[0];
  12425. $attr = $bounding[1];
  12426. $orig_x0 = $bounding[2];
  12427. $orig_y0 = $bounding[3];
  12428. // As in WriteHTML() initialising
  12429. $this->blklvl = 0;
  12430. $this->lastblocklevelchange = 0;
  12431. $this->blk = array();
  12432. $this->initialiseBlock($this->blk[0]);
  12433. $this->blk[0]['width'] =& $this->pgwidth;
  12434. $this->blk[0]['inner_width'] =& $this->pgwidth;
  12435. $this->blk[0]['blockContext'] = $this->blockContext;
  12436. $properties = $this->MergeCSS('BLOCK','BODY','');
  12437. $this->setCSS($properties,'','BODY');
  12438. $this->blklvl = 1;
  12439. $this->initialiseBlock($this->blk[1]);
  12440. $this->blk[1]['tag'] = $tag;
  12441. $this->blk[1]['attr'] = $attr;
  12442. $this->Reset();
  12443. $p = $this->MergeCSS('BLOCK',$tag,$attr);
  12444. // mPDF 5.0
  12445. if (isset($p['ROTATE']) && ($p['ROTATE']==90 || $p['ROTATE']==-90)) { $rotate = $p['ROTATE']; }
  12446. else { $rotate = 0; }
  12447. if (isset($p['OVERFLOW'])) { $overflow = strtolower($p['OVERFLOW']); }
  12448. if (strtolower($p['POSITION']) == 'fixed') {
  12449. $cont_w = $this->pgwidth; // $this->blk[0]['inner_width'];
  12450. $cont_h = $this->h - $this->tMargin - $this->bMargin;
  12451. $cont_x = $this->lMargin;
  12452. $cont_y = $this->tMargin;
  12453. }
  12454. else {
  12455. $cont_w = $this->w; // ABSOLUTE;
  12456. $cont_h = $this->h;
  12457. $cont_x = 0;
  12458. $cont_y = 0;
  12459. }
  12460. // Pass on in-line properties to the innerhtml
  12461. $css = '';
  12462. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; }
  12463. if (isset($p['TEXT-TRANSFORM'])) { $css .= 'text-transform: '.strtolower($p['TEXT-TRANSFORM']).'; '; }
  12464. if (isset($p['TEXT-INDENT'])) { $css .= 'text-indent: '.strtolower($p['TEXT-INDENT']).'; '; }
  12465. if (isset($p['TEXT-DECORATION'])) { $css .= 'text-decoration: '.strtolower($p['TEXT-DECORATION']).'; '; }
  12466. if (isset($p['FONT-FAMILY'])) { $css .= 'font-family: '.strtolower($p['FONT-FAMILY']).'; '; }
  12467. if (isset($p['FONT-STYLE'])) { $css .= 'font-style: '.strtolower($p['FONT-STYLE']).'; '; }
  12468. if (isset($p['FONT-WEIGHT'])) { $css .= 'font-weight: '.strtolower($p['FONT-WEIGHT']).'; '; }
  12469. if (isset($p['FONT-SIZE'])) { $css .= 'font-size: '.strtolower($p['FONT-SIZE']).'; '; }
  12470. if (isset($p['LINE-HEIGHT'])) { $css .= 'line-height: '.strtolower($p['LINE-HEIGHT']).'; '; }
  12471. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; } // mPDF 5.0
  12472. if (isset($p['FONT-VARIANT'])) { $css .= 'font-variant: '.strtolower($p['FONT-VARIANT']).'; '; } // mPDF 5.0
  12473. if (isset($p['COLOR'])) { $css .= 'color: '.strtolower($p['COLOR']).'; '; }
  12474. if ($css) {
  12475. $html = '<div style="'.$css.'">'.$html.'</div>';
  12476. }
  12477. // Copy over (only) the properties to set for border and background
  12478. $pb = array();
  12479. $pb['MARGIN-TOP'] = $p['MARGIN-TOP'];
  12480. $pb['MARGIN-RIGHT'] = $p['MARGIN-RIGHT'];
  12481. $pb['MARGIN-BOTTOM'] = $p['MARGIN-BOTTOM'];
  12482. $pb['MARGIN-LEFT'] = $p['MARGIN-LEFT'];
  12483. $pb['PADDING-TOP'] = $p['PADDING-TOP'];
  12484. $pb['PADDING-RIGHT'] = $p['PADDING-RIGHT'];
  12485. $pb['PADDING-BOTTOM'] = $p['PADDING-BOTTOM'];
  12486. $pb['PADDING-LEFT'] = $p['PADDING-LEFT'];
  12487. $pb['BORDER-TOP'] = $p['BORDER-TOP'];
  12488. $pb['BORDER-RIGHT'] = $p['BORDER-RIGHT'];
  12489. $pb['BORDER-BOTTOM'] = $p['BORDER-BOTTOM'];
  12490. $pb['BORDER-LEFT'] = $p['BORDER-LEFT'];
  12491. if (isset($p['BACKGROUND-COLOR'])) { $pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  12492. /*-- BACKGROUNDS --*/
  12493. if (isset($p['BACKGROUND-IMAGE'])) { $pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  12494. if (isset($p['BACKGROUND-IMAGE-RESIZE'])) { $pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  12495. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; }
  12496. if (isset($p['BACKGROUND-REPEAT'])) { $pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  12497. if (isset($p['BACKGROUND-POSITION'])) { $pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  12498. if (isset($p['BACKGROUND-GRADIENT'])) { $pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  12499. /*-- END BACKGROUNDS --*/
  12500. $this->setCSS($pb,'BLOCK',$tag);
  12501. //================================================================
  12502. $bbox_dir = $p['DIR'];
  12503. $bbox_br = $this->blk[1]['border_right']['w'];
  12504. $bbox_bl = $this->blk[1]['border_left']['w'];
  12505. $bbox_bt = $this->blk[1]['border_top']['w'];
  12506. $bbox_bb = $this->blk[1]['border_bottom']['w'];
  12507. $bbox_pr = $this->blk[1]['padding_right'];
  12508. $bbox_pl = $this->blk[1]['padding_left'];
  12509. $bbox_pt = $this->blk[1]['padding_top'];
  12510. $bbox_pb = $this->blk[1]['padding_bottom'];
  12511. $bbox_mr = $this->blk[1]['margin_right'];
  12512. if (strtolower($p['MARGIN-RIGHT'])=='auto') { $bbox_mr = 'auto'; }
  12513. $bbox_ml = $this->blk[1]['margin_left'];
  12514. if (strtolower($p['MARGIN-LEFT'])=='auto') { $bbox_ml = 'auto'; }
  12515. $bbox_mt = $this->blk[1]['margin_top'];
  12516. if (strtolower($p['MARGIN-TOP'])=='auto') { $bbox_mt = 'auto'; }
  12517. $bbox_mb = $this->blk[1]['margin_bottom'];
  12518. if (strtolower($p['MARGIN-BOTTOM'])=='auto') { $bbox_mb = 'auto'; }
  12519. if (isset($p['LEFT']) && strtolower($p['LEFT'])!='auto') { $bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this->FontSize,false); }
  12520. else { $bbox_left = 'auto'; }
  12521. if (isset($p['TOP']) && strtolower($p['TOP'])!='auto') { $bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this->FontSize,false); }
  12522. else { $bbox_top = 'auto'; }
  12523. if (isset($p['RIGHT']) && strtolower($p['RIGHT'])!='auto') { $bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w, $this->FontSize,false); }
  12524. else { $bbox_right = 'auto'; }
  12525. if (isset($p['BOTTOM']) && strtolower($p['BOTTOM'])!='auto') { $bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h, $this->FontSize,false); }
  12526. else { $bbox_bottom = 'auto'; }
  12527. if (isset($p['WIDTH']) && strtolower($p['WIDTH'])!='auto') { $inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this->FontSize,false); }
  12528. else { $inner_w = 'auto'; }
  12529. if (isset($p['HEIGHT']) && strtolower($p['HEIGHT'])!='auto') { $inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this->FontSize,false); }
  12530. else { $inner_h = 'auto'; }
  12531. // mPDF 5.0
  12532. // If bottom or right pos are set and not left / top - save this to adjust rotated block later
  12533. if ($rotate) {
  12534. if ($bbox_left === 'auto' && $bbox_right !== 'auto') { $rot_rpos = $bbox_right; }
  12535. else { $rot_rpos = false; }
  12536. if ($bbox_top === 'auto' && $bbox_bottom !== 'auto') { $rot_bpos = $bbox_bottom; }
  12537. else { $rot_bpos = false; }
  12538. }
  12539. //================================================================
  12540. if ($checkinnerhtml=='' && $inner_h==='auto') { $inner_h = 0.0001; }
  12541. if ($checkinnerhtml=='' && $inner_w==='auto') { $inner_w = $this->GetStringWidth('WW'); }
  12542. //================================================================
  12543. // Algorithm from CSS2.1 See http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height
  12544. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto') {
  12545. $bbox_top_orig = $bbox_top; // mPDF 5.0
  12546. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  12547. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  12548. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  12549. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  12550. }
  12551. else if ($bbox_top!=='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  12552. if ($bbox_mt==='auto' && $bbox_mb==='auto') {
  12553. $x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  12554. $bbox_mt = $bbox_mb = ($x/2);
  12555. }
  12556. else if ($bbox_mt==='auto') {
  12557. $bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12558. }
  12559. else if ($bbox_mb==='auto') {
  12560. $bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  12561. }
  12562. else {
  12563. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  12564. }
  12565. }
  12566. else {
  12567. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  12568. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  12569. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom!=='auto') {
  12570. // solve for $bbox_top when content_h known - $inner_h=='auto' && $bbox_top =='auto'
  12571. }
  12572. else if ($bbox_top==='auto' && $bbox_bottom==='auto' && $inner_h!=='auto') {
  12573. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  12574. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  12575. }
  12576. else if ($inner_h==='auto' && $bbox_bottom==='auto' && $bbox_top!=='auto') {
  12577. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  12578. }
  12579. else if ($bbox_top==='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  12580. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  12581. }
  12582. else if ($inner_h==='auto' && $bbox_top!=='auto' && $bbox_bottom!=='auto') {
  12583. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  12584. }
  12585. else if ($bbox_bottom==='auto' && $bbox_top!=='auto' && $inner_h!=='auto') {
  12586. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  12587. }
  12588. }
  12589. // THEN DO SAME FOR WIDTH
  12590. // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width
  12591. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right==='auto') {
  12592. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  12593. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  12594. // IF containing element RTL, should set $bbox_right
  12595. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  12596. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  12597. }
  12598. else if ($bbox_left!=='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  12599. if ($bbox_ml==='auto' && $bbox_mr==='auto') {
  12600. $x = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  12601. $bbox_ml = $bbox_mr = ($x/2);
  12602. }
  12603. else if ($bbox_ml==='auto') {
  12604. $bbox_ml = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  12605. }
  12606. else if ($bbox_mr==='auto') {
  12607. $bbox_mr = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  12608. }
  12609. else {
  12610. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12611. }
  12612. }
  12613. else {
  12614. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  12615. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  12616. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right!=='auto') {
  12617. // solve for $bbox_left when content_w known - $inner_w=='auto' && $bbox_left =='auto'
  12618. }
  12619. else if ($bbox_left==='auto' && $bbox_right==='auto' && $inner_w!=='auto') {
  12620. // IF containing element RTL, should set $bbox_right
  12621. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  12622. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12623. }
  12624. else if ($inner_w==='auto' && $bbox_right==='auto' && $bbox_left!=='auto') {
  12625. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  12626. }
  12627. else if ($bbox_left==='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  12628. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  12629. }
  12630. else if ($inner_w==='auto' && $bbox_left!=='auto' && $bbox_right!=='auto') {
  12631. $inner_w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  12632. }
  12633. else if ($bbox_right==='auto' && $bbox_left!=='auto' && $inner_w!=='auto') {
  12634. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12635. }
  12636. }
  12637. //================================================================
  12638. //================================================================
  12639. /*-- BACKGROUNDS --*/
  12640. if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) {
  12641. // mPDF 5.0.023
  12642. $ret = $this->SetBackground($pb, $this->blk[1]['inner_width']);
  12643. if ($ret) { $this->blk[1]['background-image'] = $ret; }
  12644. }
  12645. /*-- END BACKGROUNDS --*/
  12646. //================================================================
  12647. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  12648. $h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12649. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  12650. $w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  12651. // Set (temporary) values for x y w h to do first paint, if values are auto
  12652. if ($inner_h==='auto' && $bbox_top==='auto') {
  12653. $y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt;
  12654. $h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  12655. }
  12656. else if ($inner_h==='auto' && $bbox_bottom==='auto') {
  12657. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  12658. $h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  12659. }
  12660. if ($inner_w==='auto' && $bbox_left==='auto') {
  12661. $x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl;
  12662. $w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  12663. }
  12664. else if ($inner_w==='auto' && $bbox_right==='auto') {
  12665. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  12666. $w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  12667. }
  12668. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12669. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  12670. $saved_block1 = $this->blk[1];
  12671. unset($p);
  12672. unset($pb);
  12673. //================================================================
  12674. if ($inner_w==='auto') { // do a first write
  12675. $this->lMargin=$x;
  12676. $this->rMargin=$this->w - $w - $x;
  12677. // SET POSITION & FONT VALUES
  12678. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12679. $this->pageoutput[$this->page]=array();
  12680. $this->x = $x;
  12681. $this->y = $y;
  12682. $this->HTMLheaderPageLinks = array();
  12683. $this->HTMLheaderPageAnnots = array(); // mPDF 5.0
  12684. $this->pageBackgrounds = array();
  12685. $this->maxPosR = 0;
  12686. $this->maxPosL = $this->w; // For RTL
  12687. $this->WriteHTML($html , 4);
  12688. $inner_w = $this->maxPosR - $this->lMargin;
  12689. if ($bbox_right==='auto') {
  12690. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12691. }
  12692. else if ($bbox_left==='auto') {
  12693. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  12694. $bbox_x = $cont_x + $bbox_left + $bbox_ml ;
  12695. $inner_x = $bbox_x + $bbox_bl + $bbox_pl;
  12696. $x = $inner_x;
  12697. }
  12698. $w = $inner_w;
  12699. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12700. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  12701. }
  12702. if ($inner_h==='auto') { // do a first write
  12703. $this->lMargin=$x;
  12704. $this->rMargin=$this->w - $w - $x;
  12705. // SET POSITION & FONT VALUES
  12706. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12707. $this->pageoutput[$this->page]=array();
  12708. $this->x = $x;
  12709. $this->y = $y;
  12710. $this->HTMLheaderPageLinks = array();
  12711. $this->HTMLheaderPageAnnots = array(); // mPDF 5.0
  12712. $this->pageBackgrounds = array();
  12713. $this->WriteHTML($html , 4);
  12714. $inner_h = $this->y - $y;
  12715. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  12716. if (($this->y + $bbox_pb + $bbox_bb) > ($cont_y + $cont_h)) {
  12717. $adj = ($this->y + $bbox_pb + $bbox_bb) - ($cont_y + $cont_h);
  12718. $inner_h -= $adj;
  12719. }
  12720. }
  12721. // mPDF 5.0
  12722. if ($bbox_bottom==='auto' && $bbox_top_orig==='auto') {
  12723. $bbox_bottom = $bbox_top = ($cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb)/2;
  12724. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  12725. if ($bbox_top < 0) {
  12726. $bbox_top = 0;
  12727. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12728. }
  12729. }
  12730. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12731. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  12732. $y = $inner_y;
  12733. }
  12734. else if ($bbox_bottom==='auto') {
  12735. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb;
  12736. }
  12737. else if ($bbox_top==='auto') {
  12738. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12739. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  12740. if ($bbox_top < 0) {
  12741. $bbox_top = 0;
  12742. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12743. }
  12744. }
  12745. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12746. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  12747. $y = $inner_y;
  12748. }
  12749. $h = $inner_h;
  12750. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12751. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  12752. }
  12753. $inner_w = $w;
  12754. $inner_h = $h;
  12755. }
  12756. $this->lMargin=$x;
  12757. $this->rMargin=$this->w - $w - $x;
  12758. // SET POSITION & FONT VALUES
  12759. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12760. $this->pageoutput[$this->page]=array();
  12761. $this->x = $x;
  12762. $this->y = $y;
  12763. $this->HTMLheaderPageLinks = array();
  12764. $this->HTMLheaderPageAnnots = array(); // mPDF 5.0
  12765. $this->pageBackgrounds = array();
  12766. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  12767. $actual_h = $this->y - $y;
  12768. $use_w = $w;
  12769. $use_h = $h;
  12770. $ratio = $actual_h / $use_w;
  12771. if ($overflow!='hidden' && $overflow!='visible') {
  12772. $target = $h/$w;
  12773. if (($ratio / $target ) > 1) {
  12774. $nl = CEIL($actual_h / $this->lineheight);
  12775. $l = $use_w * $nl;
  12776. $est_w = sqrt(($l * $this->lineheight) / $target) * 0.8;
  12777. $use_w += ($est_w - $use_w) - ($w/100);
  12778. }
  12779. $bpcstart = ($ratio / $target);
  12780. $bpcctr = 1;
  12781. while(($ratio / $target ) > 1) {
  12782. if ($this->progressBar) { $this->UpdateProgressBar(4,intval(100/($ratio/$target)),('Auto-sizing fixed-position block: '.$bpcctr++)); } // *PROGRESS-BAR*
  12783. $this->x = $x;
  12784. $this->y = $y;
  12785. if (($ratio / $target) > 1.5 || ($ratio / $target) < 0.6) {
  12786. $use_w += ($w/$this->incrementFPR1);
  12787. }
  12788. else if (($ratio / $target) > 1.2 || ($ratio / $target) < 0.85) {
  12789. $use_w += ($w/$this->incrementFPR2);
  12790. }
  12791. else if (($ratio / $target) > 1.1 || ($ratio / $target) < 0.91) {
  12792. $use_w += ($w/$this->incrementFPR3);
  12793. }
  12794. else {
  12795. $use_w += ($w/$this->incrementFPR4);
  12796. }
  12797. $use_h = $use_w * $target ;
  12798. $this->rMargin=$this->w - $use_w - $x;
  12799. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12800. $this->HTMLheaderPageLinks = array();
  12801. $this->HTMLheaderPageAnnots = array(); // mPDF 5.0
  12802. $this->pageBackgrounds = array();
  12803. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  12804. $actual_h = $this->y - $y;
  12805. $ratio = $actual_h / $use_w;
  12806. }
  12807. if ($this->progressBar) { $this->UpdateProgressBar(4,'100',' '); } // *PROGRESS-BAR*
  12808. }
  12809. $shrink_f = $w/$use_w;
  12810. //================================================================
  12811. $this->pages[$this->page] .= '___BEFORE_BORDERS___';
  12812. $block_s = $this->PrintPageBackgrounds(); // Save to print later inside clipping path
  12813. $this->pageBackgrounds = array();
  12814. //================================================================
  12815. // mPDF 5.0
  12816. if ($rotate) {
  12817. $prerotw = $bbox_bl + $bbox_pl + $inner_w + $bbox_pr + $bbox_br;
  12818. $preroth = $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb;
  12819. $rot_start = " q\n";
  12820. if ($rotate == 90) {
  12821. if ($rot_rpos !== false) { $adjw = $prerotw; } // width before rotation
  12822. else { $adjw = $preroth; } // height before rotation
  12823. if ($rot_bpos !== false) { $adjh = -$prerotw + $preroth; }
  12824. else { $adjh = 0; }
  12825. }
  12826. else {
  12827. if ($rot_rpos !== false) { $adjw = $prerotw - $preroth; }
  12828. else { $adjw = 0; }
  12829. if ($rot_bpos !== false) { $adjh = $preroth; } // height before rotation
  12830. else { $adjh = $prerotw; } // width before rotation
  12831. }
  12832. $rot_start .= $this->transformTranslate($adjw, $adjh, true)."\n";
  12833. $rot_start .= $this->transformRotate($rotate, $bbox_x, $bbox_y, true)."\n";
  12834. $rot_end = " Q\n";
  12835. }
  12836. else {
  12837. $rot_start = '';
  12838. $rot_end = '';
  12839. }
  12840. //================================================================
  12841. if (!empty($bounding)) {
  12842. // WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the bottom
  12843. // Re-instate saved $this->blk[1]
  12844. $this->blk[1] = $saved_block1;
  12845. // These are only needed when painting border/background
  12846. $this->blk[1]['width'] = $bbox_w = $cont_w - $bbox_left - $bbox_ml - $bbox_mr - $bbox_right;
  12847. $this->blk[1]['x0'] = $bbox_x;
  12848. $this->blk[1]['y0'] = $bbox_y;
  12849. $this->blk[1]['startpage'] = $this->page;
  12850. $this->blk[1]['y1'] = $bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ;
  12851. $this->_out($rot_start); // mPDF 5.0
  12852. $this->PaintDivBB('',0,1); // Prints borders and sets backgrounds in $this->pageBackgrounds
  12853. $this->_out($rot_end); // mPDF 5.0
  12854. }
  12855. $s = $this->PrintPageBackgrounds();
  12856. $s = $rot_start.$s.$rot_end; // mPDF 5.0
  12857. $this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n".$s."\n", $this->pages[$this->page]);
  12858. $this->pageBackgrounds = array();
  12859. $this->_out($rot_start); // mPDF 5.0
  12860. // Clipping Output
  12861. if ($overflow=='hidden') {
  12862. //Bounding rectangle to clip
  12863. $clip_y1 = $this->y;
  12864. if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) > ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) {
  12865. $clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb);
  12866. }
  12867. //$op = 'W* n'; // Clipping
  12868. $op = 'W n'; // Clipping alternative mode
  12869. $this->_out("q");
  12870. $ch = $clip_y1 - $y;
  12871. $this->_out(sprintf('%.3f %.3f %.3f %.3f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$ch*$this->k,$op));
  12872. if (!empty($block_s)) {
  12873. $tmp = "q\n".sprintf('%.3f %.3f %.3f %.3f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$ch*$this->k,$op);
  12874. $tmp .= "\n".$block_s."\nQ";
  12875. $block_s = $tmp ;
  12876. }
  12877. }
  12878. if (!empty($block_s)) {
  12879. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12880. $tmp = "q\n".$this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y, true);
  12881. $tmp .= "\n".$block_s."\nQ";
  12882. $block_s = $tmp ;
  12883. }
  12884. $this->_out($block_s);
  12885. }
  12886. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12887. $this->StartTransform();
  12888. $this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y);
  12889. }
  12890. $this->_out($this->headerbuffer);
  12891. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12892. $this->StopTransform();
  12893. }
  12894. if ($overflow=='hidden') {
  12895. //End clipping
  12896. $this->_out("Q");
  12897. }
  12898. $this->_out($rot_end); // mPDF 5.0
  12899. // Page Links
  12900. foreach($this->HTMLheaderPageLinks AS $lk) {
  12901. // mPDF 5.0
  12902. if ($rotate) {
  12903. $tmp = $lk[2]; // Switch h - w
  12904. $lk[2] = $lk[3];
  12905. $lk[3] = $tmp;
  12906. $lx1 = (($lk[0]/$this->k));
  12907. $ly1 = (($this->h-($lk[1]/$this->k)));
  12908. if ($rotate == 90) {
  12909. $adjx = -($lx1-$bbox_x) + ($preroth - ($ly1-$bbox_y));
  12910. $adjy = -($ly1-$bbox_y) + ($lx1-$bbox_x);
  12911. $lk[2] = -$lk[2];
  12912. }
  12913. else if ($rotate == -90) {
  12914. $adjx = -($lx1-$bbox_x) + ($ly1-$bbox_y);
  12915. $adjy = -($ly1-$bbox_y) - ($lx1-$bbox_x) + $prerotw;
  12916. $lk[3] = -$lk[3];
  12917. }
  12918. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12919. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12920. $lx1 += $adjx;
  12921. $ly1 += $adjy;
  12922. $lk[0] = $lx1*$this->k;
  12923. $lk[1] = ($this->h-$ly1)*$this->k;
  12924. }
  12925. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12926. $lx1 = (($lk[0]/$this->k)-$x);
  12927. $lx2 = $x + ($lx1 * $shrink_f);
  12928. $lk[0] = $lx2*$this->k;
  12929. $ly1 = (($this->h-($lk[1]/$this->k))-$y);
  12930. $ly2 = $y + ($ly1 * $shrink_f);
  12931. $lk[1] = ($this->h-$ly2)*$this->k;
  12932. $lk[2] *= $shrink_f; // width
  12933. $lk[3] *= $shrink_f; // height
  12934. }
  12935. $this->PageLinks[$this->page][]=$lk;
  12936. }
  12937. // Page Annotations // mPDF 5.0
  12938. foreach($this->HTMLheaderPageAnnots AS $lk) {
  12939. if ($rotate) {
  12940. if ($rotate == 90) {
  12941. $adjx = -($lk['x']-$bbox_x) + ($preroth - ($lk['y']-$bbox_y));
  12942. $adjy = -($lk['y']-$bbox_y) + ($lk['x']-$bbox_x);
  12943. }
  12944. else if ($rotate == -90) {
  12945. $adjx = -($lk['x']-$bbox_x) + ($lk['y']-$bbox_y);
  12946. $adjy = -($lk['y']-$bbox_y) - ($lk['x']-$bbox_x) + $prerotw;
  12947. }
  12948. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12949. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12950. $lk['x'] += $adjx;
  12951. $lk['y'] += $adjy;
  12952. }
  12953. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12954. $lk['x'] = $x + (($lk['x']-$x) * $shrink_f);
  12955. $lk['y'] = $y + (($lk['y']-$y) * $shrink_f);
  12956. }
  12957. $this->PageAnnots[$this->page][]=$lk;
  12958. }
  12959. // Restore
  12960. $this->headerbuffer = '';
  12961. $this->HTMLheaderPageLinks = array();
  12962. $this->HTMLheaderPageAnnots = array(); // mPDF 5.0
  12963. $this->pageBackgrounds = $save_bgs;
  12964. $this->writingHTMLheader = false;
  12965. $this->writingHTMLfooter = false;
  12966. $this->fullImageHeight = false;
  12967. $this->ResetMargins();
  12968. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12969. $this->SetXY($save_x,$save_y) ;
  12970. $this->title2annots = $save_annots; // *ANNOTATIONS*
  12971. $this->InFooter = false; // turns back on autopagebreaks
  12972. $this->pageoutput[$this->page]=array();
  12973. $this->pageoutput[$this->page]['Font']='';
  12974. /*-- COLUMNS --*/
  12975. if ($save_cols) {
  12976. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  12977. }
  12978. /*-- END COLUMNS --*/
  12979. }
  12980. /*-- END CSS-POSITION --*/
  12981. function initialiseBlock(&$blk) {
  12982. $blk['margin_top'] = 0;
  12983. $blk['margin_left'] = 0;
  12984. $blk['margin_bottom'] = 0;
  12985. $blk['margin_right'] = 0;
  12986. $blk['padding_top'] = 0;
  12987. $blk['padding_left'] = 0;
  12988. $blk['padding_bottom'] = 0;
  12989. $blk['padding_right'] = 0;
  12990. $blk['border_top']['w'] = 0;
  12991. $blk['border_left']['w'] = 0;
  12992. $blk['border_bottom']['w'] = 0;
  12993. $blk['border_right']['w'] = 0;
  12994. $blk['hide'] = false;
  12995. $blk['outer_left_margin'] = 0;
  12996. $blk['outer_right_margin'] = 0;
  12997. $blk['cascadeCSS'] = array();
  12998. $blk['block-align'] = false;
  12999. $blk['bgcolor'] = false;
  13000. $blk['page_break_after_avoid'] = false;
  13001. $blk['keep_block_together'] = false;
  13002. $blk['float'] = false;
  13003. $blk['line_height'] = '';
  13004. $blk['margin_collapse'] = false;
  13005. }
  13006. function border_details($bd) {
  13007. $prop = preg_split('/\s+/',trim($bd));
  13008. if (isset($this->blk[$this->blklvl]['inner_width'])) { $refw = $this->blk[$this->blklvl]['inner_width']; }
  13009. else if (isset($this->blk[$this->blklvl-1]['inner_width'])) { $refw = $this->blk[$this->blklvl-1]['inner_width']; }
  13010. else { $refw = $this->w; }
  13011. if ( count($prop) == 1 ) {
  13012. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  13013. if ($bsize > 0) {
  13014. return array('s' => 1, 'w' => $bsize, 'c' => $this->ConvertColor(0), 'style'=>'solid'); // mPDF 5.0.051
  13015. }
  13016. else { return array('w' => 0, 's' => 0); }
  13017. }
  13018. else if (count($prop) == 2 ) {
  13019. // 1px solid
  13020. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $prop[2] = ''; }
  13021. // solid #000000
  13022. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $prop[0] = ''; $prop[1] = $prop[0]; $prop[2] = $prop[1]; }
  13023. // 1px #000000
  13024. else { $prop[1] = ''; $prop[2] = $prop[1]; }
  13025. }
  13026. else if ( count($prop) == 3 ) {
  13027. // Change #000000 1px solid to 1px solid #000000 (proper)
  13028. if (substr($prop[0],0,1) == '#') { $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $prop[2]; $prop[2] = $tmp; }
  13029. // Change solid #000000 1px to 1px solid #000000 (proper)
  13030. else if (substr($prop[0],1,1) == '#') { $tmp = $prop[1]; $prop[0] = $prop[2]; $prop[1] = $prop[0]; $prop[2] = $tmp; }
  13031. // Change solid 1px #000000 to 1px solid #000000 (proper)
  13032. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  13033. $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $tmp;
  13034. }
  13035. }
  13036. else { return array(); }
  13037. // Size
  13038. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  13039. //color
  13040. $coul = $this->ConvertColor($prop[2]); // returns array
  13041. // Style
  13042. $prop[1] = strtolower($prop[1]);
  13043. if (in_array($prop[1],$this->borderstyles) && $bsize > 0) { $on = 1; }
  13044. else if ($prop[1] == 'hidden') { $on = 1; $bsize = 0; $coul = ''; }
  13045. else if ($prop[1] == 'none') { $on = 0; $bsize = 0; $coul = ''; }
  13046. else { $on = 0; $bsize = 0; $coul = ''; $prop[1] = ''; }
  13047. return array('s' => $on, 'w' => $bsize, 'c' => $coul, 'style'=> $prop[1] );
  13048. }
  13049. function _fix_borderStr($bd) {
  13050. $prop = preg_split('/\s+/',trim($bd));
  13051. $w = 'medium';
  13052. $c = '#000000';
  13053. $s = 'none';
  13054. if ( count($prop) == 1 ) {
  13055. // solid
  13056. if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; }
  13057. // #000000
  13058. else if (is_array($this->ConvertColor($prop[0]))) { $c = $prop[0]; }
  13059. // 1px
  13060. else { $w = $prop[0]; }
  13061. }
  13062. else if (count($prop) == 2 ) {
  13063. // 1px solid
  13064. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; }
  13065. // solid #000000
  13066. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; }
  13067. // 1px #000000
  13068. else { $w = $prop[0]; $c = $prop[1]; }
  13069. }
  13070. else if ( count($prop) == 3 ) {
  13071. // Change #000000 1px solid to 1px solid #000000 (proper)
  13072. if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; }
  13073. // Change solid #000000 1px to 1px solid #000000 (proper)
  13074. else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; }
  13075. // Change solid 1px #000000 to 1px solid #000000 (proper)
  13076. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  13077. $s = $prop[0]; $w = $prop[1]; $c = $prop[2];
  13078. }
  13079. else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; }
  13080. }
  13081. else { return ''; }
  13082. $s = strtolower($s);
  13083. return $w.' '.$s.' '.$c;
  13084. }
  13085. // NEW FUNCTION FOR CSS MARGIN or PADDING called from SetCSS
  13086. function fixCSS($prop) {
  13087. if (!is_array($prop) || (count($prop)==0)) return array();
  13088. $newprop = array();
  13089. foreach($prop AS $k => $v) {
  13090. if ($k != 'BACKGROUND-IMAGE' && $k != 'BACKGROUND' && $k != 'ODD-HEADER-NAME' && $k != 'EVEN-HEADER-NAME' && $k != 'ODD-FOOTER-NAME' && $k != 'EVEN-FOOTER-NAME' && $k != 'HEADER' && $k != 'FOOTER') {
  13091. $v = strtolower($v);
  13092. }
  13093. if ($k == 'FONT') {
  13094. $s = trim($v);
  13095. preg_match_all('/\"(.*?)\"/',$s,$ff);
  13096. if (count($ff[1])) {
  13097. foreach($ff[1] AS $ffp) {
  13098. $w = preg_split('/\s+/',$ffp);
  13099. $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s);
  13100. }
  13101. }
  13102. preg_match_all('/\'(.*?)\'/',$s,$ff);
  13103. if (count($ff[1])) {
  13104. foreach($ff[1] AS $ffp) {
  13105. $w = preg_split('/\s+/',$ffp);
  13106. $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s);
  13107. }
  13108. }
  13109. $s = preg_replace('/\s*,\s*/',',',$s);
  13110. $bits = preg_split('/\s+/',$s);
  13111. if (count($bits)>1) {
  13112. $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)];
  13113. $fs = $bits[(count($bits)-2)];
  13114. if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) {
  13115. $newprop['FONT-SIZE'] = $fsp[1];
  13116. $newprop['LINE-HEIGHT'] = $fsp[2];
  13117. }
  13118. else { $newprop['FONT-SIZE'] = $fs; }
  13119. if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; }
  13120. else { $newprop['FONT-STYLE'] = 'normal'; }
  13121. if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; }
  13122. else { $newprop['FONT-WEIGHT'] = 'normal'; }
  13123. if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; }
  13124. }
  13125. }
  13126. if ($k == 'FONT-FAMILY') {
  13127. $aux_fontlist = explode(",",$v);
  13128. $found = 0;
  13129. foreach($aux_fontlist AS $f) {
  13130. $fonttype = trim($f);
  13131. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  13132. $fonttype = preg_replace('/ /','',$fonttype);
  13133. $v = strtolower(trim($fonttype));
  13134. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  13135. if ((!$this->usingCoreFont && in_array($v,$this->available_unifonts)) ||
  13136. ($this->usingCoreFont && in_array($v,array('courier','times','helvetica','arial'))) ||
  13137. in_array($v, array('sjis','uhc','big5','gb'))) {
  13138. $newprop[$k] = $v;
  13139. $found = 1;
  13140. break;
  13141. }
  13142. }
  13143. if (!$found) {
  13144. foreach($aux_fontlist AS $f) {
  13145. $fonttype = trim($f);
  13146. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  13147. $fonttype = preg_replace('/ /','',$fonttype);
  13148. $v = strtolower(trim($fonttype));
  13149. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  13150. if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  13151. $newprop[$k] = $v;
  13152. break;
  13153. }
  13154. }
  13155. }
  13156. }
  13157. else if ($k == 'MARGIN') {
  13158. $tmp = $this->expand24($v);
  13159. $newprop['MARGIN-TOP'] = $tmp['T'];
  13160. $newprop['MARGIN-RIGHT'] = $tmp['R'];
  13161. $newprop['MARGIN-BOTTOM'] = $tmp['B'];
  13162. $newprop['MARGIN-LEFT'] = $tmp['L'];
  13163. }
  13164. /*-- BORDER-RADIUS --*/
  13165. else if ($k == 'BORDER-RADIUS' || $k == 'BORDER-TOP-LEFT-RADIUS' || $k == 'BORDER-TOP-RIGHT-RADIUS' || $k == 'BORDER-BOTTOM-LEFT-RADIUS' || $k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  13166. $tmp = $this->border_radius_expand($v,$k);
  13167. if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
  13168. if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
  13169. if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
  13170. if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
  13171. if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
  13172. if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
  13173. if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
  13174. if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
  13175. }
  13176. /*-- END BORDER-RADIUS --*/
  13177. else if ($k == 'PADDING') {
  13178. $tmp = $this->expand24($v);
  13179. $newprop['PADDING-TOP'] = $tmp['T'];
  13180. $newprop['PADDING-RIGHT'] = $tmp['R'];
  13181. $newprop['PADDING-BOTTOM'] = $tmp['B'];
  13182. $newprop['PADDING-LEFT'] = $tmp['L'];
  13183. }
  13184. else if ($k == 'BORDER') {
  13185. if ($v == '1') { $v = '1px solid #000000'; }
  13186. else { $v = $this->_fix_borderStr($v); }
  13187. $newprop['BORDER-TOP'] = $v;
  13188. $newprop['BORDER-RIGHT'] = $v;
  13189. $newprop['BORDER-BOTTOM'] = $v;
  13190. $newprop['BORDER-LEFT'] = $v;
  13191. }
  13192. else if ($k == 'BORDER-TOP') {
  13193. $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
  13194. }
  13195. else if ($k == 'BORDER-RIGHT') {
  13196. $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
  13197. }
  13198. else if ($k == 'BORDER-BOTTOM') {
  13199. $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
  13200. }
  13201. else if ($k == 'BORDER-LEFT') {
  13202. $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
  13203. }
  13204. else if ($k == 'BORDER-STYLE') {
  13205. $e = $this->expand24($v);
  13206. $newprop['BORDER-TOP-STYLE'] = $e['T'];
  13207. $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
  13208. $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
  13209. $newprop['BORDER-LEFT-STYLE'] = $e['L'];
  13210. }
  13211. else if ($k == 'BORDER-WIDTH') {
  13212. $e = $this->expand24($v);
  13213. $newprop['BORDER-TOP-WIDTH'] = $e['T'];
  13214. $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
  13215. $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
  13216. $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
  13217. }
  13218. else if ($k == 'BORDER-COLOR') {
  13219. $e = $this->expand24($v);
  13220. $newprop['BORDER-TOP-COLOR'] = $e['T'];
  13221. $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
  13222. $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
  13223. $newprop['BORDER-LEFT-COLOR'] = $e['L'];
  13224. }
  13225. else if ($k == 'BORDER-SPACING') {
  13226. $prop = preg_split('/\s+/',trim($v));
  13227. if (count($prop) == 1 ) {
  13228. $newprop['BORDER-SPACING-H'] = $prop[0];
  13229. $newprop['BORDER-SPACING-V'] = $prop[0];
  13230. }
  13231. else if (count($prop) == 2 ) {
  13232. $newprop['BORDER-SPACING-H'] = $prop[0];
  13233. $newprop['BORDER-SPACING-V'] = $prop[1];
  13234. }
  13235. }
  13236. else if ($k == 'SIZE') {
  13237. $prop = preg_split('/\s+/',trim($v));
  13238. if (preg_match('/(auto|portrait|landscape)/',$prop[0])) {
  13239. $newprop['SIZE'] = strtoupper($prop[0]);
  13240. }
  13241. else if (count($prop) == 1 ) {
  13242. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  13243. $newprop['SIZE']['H'] = $this->ConvertSize($prop[0]);
  13244. }
  13245. else if (count($prop) == 2 ) {
  13246. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  13247. $newprop['SIZE']['H'] = $this->ConvertSize($prop[1]);
  13248. }
  13249. }
  13250. else if ($k == 'SHEET-SIZE') {
  13251. $prop = preg_split('/\s+/',trim($v));
  13252. if (count($prop) == 2 ) {
  13253. $newprop['SHEET-SIZE'] = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  13254. }
  13255. else {
  13256. if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape
  13257. $ft = $this->_getPageFormat($m[1]);
  13258. $format = array($ft[1],$ft[0]);
  13259. }
  13260. else { $format = $this->_getPageFormat($v); }
  13261. if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/$this->k, $format[1]/$this->k); }
  13262. }
  13263. }
  13264. else if ($k == 'BACKGROUND') {
  13265. $bg = $this->parseCSSbackground($v);
  13266. if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; }
  13267. else { $newprop['BACKGROUND-COLOR'] = 'transparent'; }
  13268. /*-- BACKGROUNDS --*/
  13269. if ($bg['i']) {
  13270. $newprop['BACKGROUND-IMAGE'] = $bg['i'];
  13271. if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; }
  13272. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  13273. }
  13274. else { $newprop['BACKGROUND-IMAGE'] = ''; }
  13275. /*-- END BACKGROUNDS --*/
  13276. }
  13277. /*-- BACKGROUNDS --*/
  13278. else if ($k == 'BACKGROUND-IMAGE') {
  13279. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$v,$m)) { // mPDF 5.0.020 // 5.0.023
  13280. $newprop['BACKGROUND-IMAGE'] = $m[0];
  13281. continue;
  13282. }
  13283. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) { // 4.2.013
  13284. $newprop['BACKGROUND-IMAGE'] = $m[1];
  13285. }
  13286. else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; }
  13287. }
  13288. else if ($k == 'BACKGROUND-REPEAT') {
  13289. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) {
  13290. $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
  13291. }
  13292. }
  13293. else if ($k == 'BACKGROUND-POSITION') {
  13294. $s = $v;
  13295. $bits = preg_split('/\s+/',trim($s));
  13296. // These should be Position x1 or x2
  13297. if (count($bits)==1) {
  13298. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  13299. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  13300. else { $bg['p'] = $bits[0] . ' 50%'; }
  13301. }
  13302. else if (count($bits)==2) {
  13303. // Can be either right center or center right
  13304. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  13305. $bg['p'] = $bits[1] . ' '.$bits[0];
  13306. }
  13307. else {
  13308. $bg['p'] = $bits[0] . ' '.$bits[1];
  13309. }
  13310. }
  13311. if ($bg['p']) {
  13312. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  13313. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  13314. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  13315. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
  13316. $bg['p'] = false;
  13317. }
  13318. }
  13319. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  13320. }
  13321. /*-- END BACKGROUNDS --*/
  13322. // mPDF 5.0.032
  13323. else if ($k == 'IMAGE-ORIENTATION') {
  13324. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$v,$m)) {
  13325. $angle = $m[1] + 0;
  13326. if (strtolower($m[2])=='deg') { $angle = $angle; }
  13327. else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
  13328. else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
  13329. while($angle < 0) { $angle += 360; }
  13330. $angle = ($angle % 360);
  13331. $angle /= 90;
  13332. $angle = round($angle) * 90;
  13333. $newprop['IMAGE-ORIENTATION'] = $angle;
  13334. }
  13335. }
  13336. else {
  13337. $newprop[$k] = $v;
  13338. }
  13339. }
  13340. return $newprop;
  13341. }
  13342. function parseCSSbackground($s) {
  13343. $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, );
  13344. /*-- BACKGROUNDS --*/
  13345. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$s,$m)) { // mPDF 5.0.023
  13346. $bg['i'] = $m[0];
  13347. }
  13348. else
  13349. /*-- END BACKGROUNDS --*/
  13350. if (preg_match('/url\(/i',$s)) {
  13351. // If color, set and strip it off
  13352. if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|rgb\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i',$s,$m)) {
  13353. $bg['c'] = strtolower($m[1]);
  13354. $s = $m[2];
  13355. }
  13356. /*-- BACKGROUNDS --*/
  13357. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) {
  13358. $bg['i'] = $m[1];
  13359. $s = strtolower($m[2]);
  13360. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) {
  13361. $bg['r'] = $m[1];
  13362. }
  13363. // Remove repeat, attachment (discarded) and also any inherit
  13364. $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s);
  13365. $bits = preg_split('/\s+/',trim($s));
  13366. // These should be Position x1 or x2
  13367. if (count($bits)==1) {
  13368. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  13369. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  13370. else { $bg['p'] = $bits[0] . ' 50%'; }
  13371. }
  13372. else if (count($bits)==2) {
  13373. // Can be either right center or center right
  13374. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  13375. $bg['p'] = $bits[1] . ' '.$bits[0];
  13376. }
  13377. else {
  13378. $bg['p'] = $bits[0] . ' '.$bits[1];
  13379. }
  13380. }
  13381. if ($bg['p']) {
  13382. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  13383. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  13384. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  13385. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
  13386. $bg['p'] = false;
  13387. }
  13388. }
  13389. }
  13390. /*-- END BACKGROUNDS --*/
  13391. }
  13392. else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|rgb\(.*?\)|[a-zA-Z]{3,})/i',$s,$m)) { $bg['c'] = strtolower($m[1]); }
  13393. return ($bg);
  13394. }
  13395. /*-- BACKGROUNDS --*/
  13396. // mPDF 5.0.020
  13397. function parseMozGradient($bg) {
  13398. // background[-image]: -moz-linear-gradient(left, #c7Fdde 20%, #FF0000 );
  13399. // background[-image]: linear-gradient(left, #c7Fdde 20%, #FF0000 ); // CSS3
  13400. if (preg_match('/repeating-/',$bg)) { $repeat = true; } // mPDF 5.0.029
  13401. else { $repeat = false; } // mPDF 5.0.029
  13402. if (preg_match('/linear-gradient\((.*)\)/',$bg,$m)) {
  13403. $g = array();
  13404. $g['type'] = 2;
  13405. $g['colorspace'] = 'RGB';
  13406. $g['extend'] = array('true','true');
  13407. $v = trim($m[1]);
  13408. // Change commas inside e.g. rgb(x,x,x)
  13409. while(preg_match('/(\([^\)]*?),/',$v)) { $v = preg_replace('/(\([^\)]*?),/','\\1@',$v); }
  13410. // Remove spaces inside e.g. rgb(x, x, x)
  13411. while(preg_match('/(\([^\)]*?)[ ]/',$v)) { $v = preg_replace('/(\([^\)]*?)[ ]/','\\1',$v); }
  13412. $bgr = preg_split('/\s*,\s*/',$v);
  13413. for($i=0;$i<count($bgr);$i++) { $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]); }
  13414. // Is first part $bgr[0] a valid point/angle?
  13415. $first = preg_split('/\s+/',trim($bgr[0]));
  13416. if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i',$bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i',$bgr[0])) {
  13417. $startStops = 1;
  13418. }
  13419. else if (trim($first[(count($first)-1)]) === "0") {
  13420. $startStops = 1;
  13421. }
  13422. else {
  13423. $check = $this->ConvertColor($first[0]);
  13424. if ($check) $startStops = 0;
  13425. else $startStops = 1;
  13426. }
  13427. // first part a valid point/angle?
  13428. if ($startStops == 1) { // default values
  13429. // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
  13430. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$bgr[0],$m)) {
  13431. $angle = $m[1] + 0;
  13432. if (strtolower($m[2])=='deg') { $angle = $angle; }
  13433. else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
  13434. else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); } // mPDF 5.0.032
  13435. while($angle < 0) { $angle += 360; }
  13436. $angle = ($angle % 360);
  13437. }
  13438. else if (trim($first[(count($first)-1)]) === "0") { $angle = 0; }
  13439. if (preg_match('/left/i',$bgr[0])) { $startx = 0; }
  13440. else if (preg_match('/right/i',$bgr[0])) { $startx = 1; }
  13441. if (preg_match('/top/i',$bgr[0])) { $starty = 1; }
  13442. else if (preg_match('/bottom/i',$bgr[0])) { $starty = 0; }
  13443. // Check for %? ?% or %%
  13444. if (preg_match('/(\d+)[%]/i',$first[0],$m)) { $startx = $m[1]/100; }
  13445. else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[0],$m)) {
  13446. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  13447. if ($tmp) { $startx = $m[1]; }
  13448. }
  13449. if (isset($first[1]) && preg_match('/(\d+)[%]/i',$first[1],$m)) { $starty = 1 - ($m[1]/100); }
  13450. else if (!isset($starty) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[1],$m)) {
  13451. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  13452. if ($tmp) { $starty = $m[1]; }
  13453. }
  13454. if (isset($startx) && !isset($starty)) { $starty = 0.5; }
  13455. if (!isset($startx) && isset($starty)) { $startx = 0.5; }
  13456. }
  13457. // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
  13458. else { // default values T2B
  13459. $starty = 1; $startx = 0.5;
  13460. $endy = 0; $endx = 0.5;
  13461. }
  13462. $coords = array();
  13463. if (!isset($startx)) { $startx = false; }
  13464. if (!isset($starty)) { $starty = false; }
  13465. if (!isset($endx)) { $endx = false; }
  13466. if (!isset($endy)) { $endy = false; }
  13467. if (!isset($angle)) { $angle = false; }
  13468. $g['coords'] = array($startx ,$starty ,$endx ,$endy, $angle, $repeat ); // mPDF 5.0.029
  13469. $g['stops'] = array();
  13470. for($i=$startStops;$i<count($bgr);$i++) {
  13471. $stop = array();
  13472. // parse stops
  13473. $el = preg_split('/\s+/',trim($bgr[$i]));
  13474. $col = $this->ConvertColor($el[0]);
  13475. if ($col) { $stop['col'] = $col; } // mPDF 5.0.051
  13476. else { $stop['col'] = $col = $this->ConvertColor(255); } // mPDF 5.0.051
  13477. if ($col[0]==1) $g['colorspace'] = 'Gray';
  13478. else if ($col[0]==4 || $col[0]==6) $g['colorspace'] = 'CMYK';
  13479. if ($col[0]==5) { $stop['opacity'] = $col[4]; } // mPDF 5.0.051 transparency from rgba()
  13480. else if ($col[0]==6) { $stop['opacity'] = $col[5]; } // mPDF 5.0.051 transparency from cmyka()
  13481. else if ($col[0]==1 && isset($col[2])) { $stop['opacity'] = $col[2]; } // mPDF 5.0.051 transparency converted from rgba or cmyka()
  13482. if (isset($el[1]) && preg_match('/(\d+)[%]/',$el[1],$m)) {
  13483. $stop['offset'] = $m[1]/100;
  13484. if ($stop['offset']>1) { unset($stop['offset']); }
  13485. }
  13486. else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$el[1],$m)) {
  13487. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  13488. if ($tmp) { $stop['offset'] = $m[1]; }
  13489. }
  13490. $g['stops'][] = $stop;
  13491. }
  13492. if (count($g['stops'] )) { return $g; }
  13493. }
  13494. else if (preg_match('/radial-gradient\((.*)\)/',$bg,$m)) {
  13495. $g = array();
  13496. $g['type'] = 3;
  13497. $g['colorspace'] = 'RGB';
  13498. $g['extend'] = array('true','true');
  13499. $v = trim($m[1]);
  13500. // Change commas inside e.g. rgb(x,x,x)
  13501. while(preg_match('/(\([^\)]*?),/',$v)) { $v = preg_replace('/(\([^\)]*?),/','\\1@',$v); }
  13502. // Remove spaces inside e.g. rgb(x, x, x)
  13503. while(preg_match('/(\([^\)]*?)[ ]/',$v)) { $v = preg_replace('/(\([^\)]*?)[ ]/','\\1',$v); }
  13504. $bgr = preg_split('/\s*,\s*/',$v);
  13505. for($i=0;$i<count($bgr);$i++) { $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]); }
  13506. // Is first part $bgr[0] a valid point/angle?
  13507. $startStops = 0;
  13508. $pos_angle = false;
  13509. $shape_size = false;
  13510. $first = preg_split('/\s+/',trim($bgr[0]));
  13511. $checkCol = $this->ConvertColor($first[0]);
  13512. if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i',$bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i',$bgr[0])) {
  13513. $startStops=1;
  13514. $pos_angle = $bgr[0];
  13515. }
  13516. else if (trim($first[(count($first)-1)]) === "0") {
  13517. $startStops=1;
  13518. $pos_angle = $bgr[0];
  13519. }
  13520. else if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$bgr[0])) {
  13521. $startStops=1;
  13522. $shape_size = $bgr[0];
  13523. }
  13524. else if (!$checkCol) {
  13525. $startStops=1;
  13526. $pos_angle = $bgr[0];
  13527. }
  13528. if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$bgr[1])) {
  13529. $startStops=2;
  13530. $shape_size = $bgr[1];
  13531. }
  13532. // If valid point/angle?
  13533. if ($pos_angle) { // default values
  13534. // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
  13535. if (preg_match('/left/i',$pos_angle)) { $startx = 0; }
  13536. else if (preg_match('/right/i',$pos_angle)) { $startx = 1; }
  13537. if (preg_match('/top/i',$pos_angle)) { $starty = 1; }
  13538. else if (preg_match('/bottom/i',$pos_angle)) { $starty = 0; }
  13539. // Check for %? ?% or %%
  13540. if (preg_match('/(\d+)[%]/i',$first[0],$m)) { $startx = $m[1]/100; }
  13541. else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[0],$m)) {
  13542. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  13543. if ($tmp) { $startx = $m[1]; }
  13544. }
  13545. if (isset($first[1]) && preg_match('/(\d+)[%]/i',$first[1],$m)) { $starty = 1 - ($m[1]/100); }
  13546. else if (!isset($starty) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[1],$m)) {
  13547. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  13548. if ($tmp) { $starty = $m[1]; }
  13549. }
  13550. /*
  13551. // ?? Angle has no effect in radial gradient (does not exist in CSS3 spec.)
  13552. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$pos_angle,$m)) {
  13553. $angle = $m[1] + 0;
  13554. if (strtolower($m[2])=='deg') { $angle = $angle; }
  13555. else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
  13556. else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); } // mPDF 5.0.032
  13557. while($angle < 0) { $angle += 360; }
  13558. $angle = ($angle % 360);
  13559. }
  13560. */
  13561. if (!isset($starty)) { $starty = 0.5; }
  13562. if (!isset($startx)) { $startx = 0.5; }
  13563. }
  13564. // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
  13565. else { // default values Center
  13566. $starty = 0.5; $startx = 0.5;
  13567. $endy = 0.5; $endx = 0.5;
  13568. }
  13569. // If valid shape/size?
  13570. $shape = 'ellipse'; // default
  13571. $size = 'farthest-corner'; // default
  13572. if ($shape_size) { // default values
  13573. if (preg_match('/(circle|ellipse)/i',$shape_size, $m)) {
  13574. $shape = $m[1];
  13575. }
  13576. if (preg_match('/(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$shape_size, $m)) {
  13577. $size = $m[1];
  13578. if ($size=='contain') { $size = 'closest-side'; }
  13579. else if ($size=='cover') { $size = 'farthest-corner'; }
  13580. }
  13581. }
  13582. $coords = array();
  13583. if (!isset($startx)) { $startx = false; }
  13584. if (!isset($starty)) { $starty = false; }
  13585. if (!isset($endx)) { $endx = false; }
  13586. if (!isset($endy)) { $endy = false; }
  13587. if (!isset($radius)) { $radius = false; }
  13588. if (!isset($angle)) { $angle = 0; }
  13589. $g['coords'] = array($startx ,$starty ,$endx ,$endy, $radius, $angle, $shape, $size, $repeat ); // mPDF 5.0.029
  13590. $g['stops'] = array();
  13591. for($i=$startStops;$i<count($bgr);$i++) {
  13592. $stop = array();
  13593. // parse stops
  13594. $el = preg_split('/\s+/',trim($bgr[$i]));
  13595. $col = $this->ConvertColor($el[0]);
  13596. if ($col) { $stop['col'] = $col; } // mPDF 5.0.051
  13597. else { $stop['col'] = $col = $this->ConvertColor(255); } // mPDF 5.0.051
  13598. if ($col[0]==1) $g['colorspace'] = 'Gray';
  13599. else if ($col[0]==4 || $col[0]==6) $g['colorspace'] = 'CMYK';
  13600. if ($col[0]==5) { $stop['opacity'] = $col[4]; } // mPDF 5.0.051 transparency from rgba()
  13601. else if ($col[0]==6) { $stop['opacity'] = $col[5]; } // mPDF 5.0.051 transparency from cmyka()
  13602. else if ($col[0]==1 && isset($col[2])) { $stop['opacity'] = $col[2]; } // mPDF 5.0.051 transparency converted from rgba or cmyka()
  13603. if (isset($el[1]) && preg_match('/(\d+)[%]/',$el[1],$m)) {
  13604. $stop['offset'] = $m[1]/100;
  13605. if ($stop['offset']>1) { unset($stop['offset']); }
  13606. }
  13607. else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$el[1],$m)) {
  13608. $tmp = $this->ConvertSize($m[1],$this->w,$this->FontSize,false);
  13609. $stop['offset'] = $el[1];
  13610. }
  13611. $g['stops'][] = $stop;
  13612. }
  13613. if (count($g['stops'] )) { return $g; }
  13614. }
  13615. return array();
  13616. }
  13617. function parseBackgroundGradient($bg) {
  13618. // background-gradient: linear #00FFFF #FFFF00 0 0.5 1 0.5; or
  13619. // background-gradient: radial #00FFFF #FFFF00 0.5 0.5 1 1 1.2;
  13620. $v = trim($bg);
  13621. $bgr = preg_split('/\s+/',$v);
  13622. $g = array();
  13623. if (count($bgr)> 6) {
  13624. if (strtoupper(substr($bgr[0],0,1)) == 'L' && count($bgr)==7) { // linear
  13625. $g['type'] = 2;
  13626. //$coords = array(0,0,1,1 ); // 0 0 1 0 or 0 1 1 1 is L 2 R; 1,1,0,1 is R2L; 1,1,1,0 is T2B; 1,0,1,1 is B2T
  13627. // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
  13628. // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  13629. $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6]);
  13630. }
  13631. else if (count($bgr)==8) { // radial
  13632. $g['type'] = 3;
  13633. // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
  13634. // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
  13635. // (fx, fy) should be inside the circle, otherwise some areas will not be defined
  13636. $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6], $bgr[7]);
  13637. }
  13638. $g['colorspace'] = 'RGB';
  13639. $cor = $this->ConvertColor($bgr[1]);
  13640. if ($cor[0]==1) $g['colorspace'] = 'Gray';
  13641. else if ($cor[0]==4 || $cor[0]==6) $g['colorspace'] = 'CMYK';
  13642. if ($cor) { $g['col'] = $cor; } // mPDF 5.0.051
  13643. else { $g['col'] = $this->ConvertColor(255); } // mPDF 5.0.051
  13644. $cor = $this->ConvertColor($bgr[2]);
  13645. if ($cor) { $g['col2'] = $cor; } // mPDF 5.0.051
  13646. else { $g['col2'] = $this->ConvertColor(255); } // mPDF 5.0.051
  13647. $g['extend'] = array('true','true');
  13648. // mPDF 5.0.020
  13649. $g['stops'] = array(array('col'=>$g['col'], 'opacity'=>1, 'offset'=>0), array('col'=>$g['col2'], 'opacity'=>1, 'offset'=>1));
  13650. return $g;
  13651. }
  13652. return false;
  13653. }
  13654. /*-- END BACKGROUNDS --*/
  13655. function expand24($mp) {
  13656. $prop = preg_split('/\s+/',trim($mp));
  13657. if (count($prop) == 1 ) {
  13658. return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]);
  13659. }
  13660. if (count($prop) == 2 ) {
  13661. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]);
  13662. }
  13663. if (count($prop) == 3 ) {
  13664. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]);
  13665. }
  13666. if (count($prop) == 4 ) {
  13667. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]);
  13668. }
  13669. return array();
  13670. }
  13671. /*-- BORDER-RADIUS --*/
  13672. function border_radius_expand($val,$k) {
  13673. $b = array();
  13674. if ($k == 'BORDER-RADIUS') {
  13675. $hv = explode('/',trim($val));
  13676. $prop = preg_split('/\s+/',trim($hv[0]));
  13677. if (count($prop)==1) {
  13678. $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
  13679. }
  13680. else if (count($prop)==2) {
  13681. $b['TL-H'] = $b['BR-H'] = $prop[0];
  13682. $b['TR-H'] = $b['BL-H'] = $prop[1];
  13683. }
  13684. else if (count($prop)==3) {
  13685. $b['TL-H'] = $prop[0];
  13686. $b['TR-H'] = $b['BL-H'] = $prop[1];
  13687. $b['BR-H'] = $prop[2];
  13688. }
  13689. else if (count($prop)==4) {
  13690. $b['TL-H'] = $prop[0];
  13691. $b['TR-H'] = $prop[1];
  13692. $b['BR-H'] = $prop[2];
  13693. $b['BL-H'] = $prop[3];
  13694. }
  13695. if (count($hv)==2) {
  13696. $prop = preg_split('/\s+/',trim($hv[1]));
  13697. if (count($prop)==1) {
  13698. $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
  13699. }
  13700. else if (count($prop)==2) {
  13701. $b['TL-V'] = $b['BR-V'] = $prop[0];
  13702. $b['TR-V'] = $b['BL-V'] = $prop[1];
  13703. }
  13704. else if (count($prop)==3) {
  13705. $b['TL-V'] = $prop[0];
  13706. $b['TR-V'] = $b['BL-V'] = $prop[1];
  13707. $b['BR-V'] = $prop[2];
  13708. }
  13709. else if (count($prop)==4) {
  13710. $b['TL-V'] = $prop[0];
  13711. $b['TR-V'] = $prop[1];
  13712. $b['BR-V'] = $prop[2];
  13713. $b['BL-V'] = $prop[3];
  13714. }
  13715. }
  13716. else {
  13717. $b['TL-V'] = $b['TL-H'];
  13718. $b['TR-V'] = $b['TR-H'];
  13719. $b['BL-V'] = $b['BL-H'];
  13720. $b['BR-V'] = $b['BR-H'];
  13721. }
  13722. return $b;
  13723. }
  13724. // Parse 2
  13725. $h = 0;
  13726. $v = 0;
  13727. $prop = preg_split('/\s+/',trim($val));
  13728. if (count($prop)==1) { $h = $v = $val; }
  13729. else { $h = $prop[0]; $v = $prop[1]; }
  13730. if ($h==0 || $v==0) { $h = $v = 0; }
  13731. if ($k == 'BORDER-TOP-LEFT-RADIUS') {
  13732. $b['TL-H'] = $h;
  13733. $b['TL-V'] = $v;
  13734. }
  13735. else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
  13736. $b['TR-H'] = $h;
  13737. $b['TR-V'] = $v;
  13738. }
  13739. else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
  13740. $b['BL-H'] = $h;
  13741. $b['BL-V'] = $v;
  13742. }
  13743. else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  13744. $b['BR-H'] = $h;
  13745. $b['BR-V'] = $v;
  13746. }
  13747. return $b;
  13748. }
  13749. /*-- END BORDER-RADIUS --*/
  13750. // Return either a number (factor) - based on current set fontsize (if % or em) - or exact lineheight (with 'mm' after it)
  13751. function fixLineheight($v) {
  13752. $lh = false;
  13753. if (preg_match('/^[0-9\.,]*$/',$v) && $v >= 0) { return ($v + 0); }
  13754. else if (strtoupper($v) == 'NORMAL') {
  13755. return $this->normalLineheight;
  13756. }
  13757. else {
  13758. $tlh = $this->ConvertSize($v,$this->FontSize,$this->FontSize,true);
  13759. if ($tlh) { return ($tlh.'mm'); }
  13760. }
  13761. return $this->normalLineheight;
  13762. }
  13763. /*-- BORDER-RADIUS --*/
  13764. function _borderPadding($a, $b, &$px, &$py) {
  13765. // $px and py are padding long axis (x) and short axis (y)
  13766. $added = 0; // extra padding
  13767. $x = $a-$px;
  13768. $y = $b-$py;
  13769. // Check if Falls within ellipse of border radius
  13770. if ( ( (($x+$added)*($x+$added))/($a*$a) + (($y+$added)*($y+$added))/($b*$b) ) <=1 ) { return false; }
  13771. $t = atan2($y,$x);
  13772. $newx = $b / sqrt((($b*$b)/($a*$a)) + ( tan($t) * tan($t) ) );
  13773. $newy = $a / sqrt((($a*$a)/($b*$b)) + ( (1/tan($t)) * (1/tan($t)) ) );
  13774. $px = max($px, $a - $newx + $added);
  13775. $py = max($py, $b - $newy + $added);
  13776. }
  13777. /*-- END BORDER-RADIUS --*/
  13778. /*-- TABLES --*/
  13779. function setBorderDominance($prop, $val) {
  13780. if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; }
  13781. if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; }
  13782. if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; }
  13783. if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; }
  13784. }
  13785. /*-- END TABLES --*/
  13786. function _mergeCSS(&$p, &$t) {
  13787. // Save Cascading CSS e.g. "div.topic p" at this block level
  13788. if (isset($p) && $p) {
  13789. $carry = $p;
  13790. if ($t) {
  13791. $t = $this->array_merge_recursive_unique($t, $carry);
  13792. }
  13793. else { $t = $carry; }
  13794. }
  13795. }
  13796. // for CSS handling
  13797. function array_merge_recursive_unique($array1, $array2) {
  13798. $arrays = func_get_args();
  13799. $narrays = count($arrays);
  13800. $ret = $arrays[0];
  13801. for ($i = 1; $i < $narrays; $i ++) {
  13802. foreach ($arrays[$i] as $key => $value) {
  13803. if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
  13804. $ret[] = $value;
  13805. }
  13806. else { // string key - merge
  13807. if (is_array($value) && isset($ret[$key])) {
  13808. $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
  13809. }
  13810. else {
  13811. $ret[$key] = $value;
  13812. }
  13813. }
  13814. }
  13815. }
  13816. return $ret;
  13817. }
  13818. function _mergeFullCSS(&$p, &$t, $tag, $classes, $id) {
  13819. $this->_mergeCSS($p[$tag], $t);
  13820. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13821. foreach($classes AS $class) {
  13822. $this->_mergeCSS($p['CLASS>>'.$class], $t);
  13823. }
  13824. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  13825. if (isset($id) && $id) {
  13826. $this->_mergeCSS($p['ID>>'.$id], $t);
  13827. }
  13828. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13829. foreach($classes AS $class) {
  13830. $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t);
  13831. }
  13832. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  13833. if (isset($id)) {
  13834. $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t);
  13835. }
  13836. }
  13837. function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) {
  13838. if (isset($m)) {
  13839. if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth'
  13840. if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES*
  13841. if (is_array($m)) {
  13842. $p = array_merge($p,$m);
  13843. $this->_mergeBorders($p,$m);
  13844. }
  13845. }
  13846. }
  13847. }
  13848. function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
  13849. foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) {
  13850. foreach(array('STYLE','WIDTH','COLOR') AS $el) {
  13851. if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE']
  13852. $s = trim($a['BORDER-'.$side.'-'.$el]);
  13853. if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP']
  13854. $p = trim($b['BORDER-'.$side]);
  13855. }
  13856. else { $p = ''; }
  13857. if ($el=='STYLE') {
  13858. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); }
  13859. else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; }
  13860. }
  13861. else if ($el=='WIDTH') {
  13862. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); }
  13863. else { $b['BORDER-'.$side] = $s.' none #000000'; }
  13864. }
  13865. else if ($el=='COLOR') {
  13866. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); }
  13867. else { $b['BORDER-'.$side] = '0px none '.$s; }
  13868. }
  13869. // mPDF 5.1.013
  13870. //unset($a['BORDER-'.$side.'-'.$el]);
  13871. }
  13872. }
  13873. }
  13874. }
  13875. function MergeCSS($inherit,$tag,$attr) {
  13876. $p = array();
  13877. $zp = array();
  13878. $classes = array();
  13879. if (isset($attr['CLASS'])) {
  13880. $classes = preg_split('/\s+/',$attr['CLASS']);
  13881. }
  13882. // mPDF 5.0.05
  13883. if (!isset($attr['ID'])) { $attr['ID']=''; }
  13884. //===============================================
  13885. /*-- TABLES --*/
  13886. // Set Inherited properties
  13887. if ($inherit == 'TOPTABLE') { // $tag = TABLE
  13888. //===============================================
  13889. // Save Cascading CSS e.g. "div.topic p" at this block level
  13890. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  13891. $this->tablecascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  13892. }
  13893. else {
  13894. $this->tablecascadeCSS[0] = $this->cascadeCSS;
  13895. }
  13896. }
  13897. //===============================================
  13898. // Set Inherited properties
  13899. if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
  13900. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  13901. if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) {
  13902. foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) {
  13903. $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
  13904. }
  13905. }
  13906. $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  13907. //===============================================
  13908. // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
  13909. //===============================================
  13910. // STYLESHEET TAG e.g. table
  13911. $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  13912. //===============================================
  13913. }
  13914. /*-- END TABLES --*/
  13915. //===============================================
  13916. /*-- LISTS --*/
  13917. // Set Inherited properties
  13918. if ($inherit == 'TOPLIST') { // $tag = UL,OL
  13919. //===============================================
  13920. // Save Cascading CSS e.g. "div.topic p" at this block level
  13921. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  13922. $this->listcascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  13923. }
  13924. else {
  13925. $this->listcascadeCSS[0] = $this->cascadeCSS;
  13926. }
  13927. }
  13928. //===============================================
  13929. // Set Inherited properties
  13930. if ($inherit == 'TOPLIST' || $inherit == 'LIST') {
  13931. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  13932. if (isset($this->listcascadeCSS[$this->listCSSlvl-1]) && is_array($this->listcascadeCSS[$this->listCSSlvl-1])) {
  13933. foreach($this->listcascadeCSS[$this->listCSSlvl-1] AS $k=>$v) {
  13934. $this->listcascadeCSS[$this->listCSSlvl][$k] = $v;
  13935. }
  13936. }
  13937. $this->_mergeFullCSS($this->cascadeCSS, $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  13938. //===============================================
  13939. // Cascading forward CSS e.g. "table.topic td" for this list in $this->listcascadeCSS
  13940. //===============================================
  13941. // STYLESHEET TAG e.g. table
  13942. $this->_mergeFullCSS($this->listcascadeCSS[$this->listCSSlvl-1], $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  13943. //===============================================
  13944. }
  13945. /*-- END LISTS --*/
  13946. //===============================================
  13947. // Set Inherited properties
  13948. if ($inherit == 'BLOCK') {
  13949. if (isset($this->blk[$this->blklvl-1]['cascadeCSS']) && is_array($this->blk[$this->blklvl-1]['cascadeCSS'])) {
  13950. foreach($this->blk[$this->blklvl-1]['cascadeCSS'] AS $k=>$v) {
  13951. $this->blk[$this->blklvl]['cascadeCSS'][$k] = $v;
  13952. }
  13953. }
  13954. //===============================================
  13955. // Save Cascading CSS e.g. "div.topic p" at this block level
  13956. $this->_mergeFullCSS($this->cascadeCSS, $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  13957. //===============================================
  13958. // Cascading forward CSS
  13959. //===============================================
  13960. $this->_mergeFullCSS($this->blk[$this->blklvl-1]['cascadeCSS'], $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  13961. //===============================================
  13962. // Block properties
  13963. if (isset($this->blk[$this->blklvl-1]['margin_collapse']) && $this->blk[$this->blklvl-1]['margin_collapse']) { $p['MARGIN-COLLAPSE'] = 'COLLAPSE'; } // custom tag, but follows CSS principle that border-collapse is inherited
  13964. if (isset($this->blk[$this->blklvl-1]['line_height']) && $this->blk[$this->blklvl-1]['line_height']) { $p['LINE-HEIGHT'] = $this->blk[$this->blklvl-1]['line_height']; }
  13965. // mPDF 5.0.054
  13966. if (isset($this->blk[$this->blklvl-1]['direction']) && $this->blk[$this->blklvl-1]['direction']) { $p['DIRECTION'] = $this->blk[$this->blklvl-1]['direction']; }
  13967. if (isset($this->blk[$this->blklvl-1]['align']) && $this->blk[$this->blklvl-1]['align']) {
  13968. if ($this->blk[$this->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; }
  13969. else if ($this->blk[$this->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; }
  13970. else if ($this->blk[$this->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; }
  13971. else if ($this->blk[$this->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; }
  13972. }
  13973. if ($this->ColActive || $this->keep_block_together) {
  13974. if (isset($this->blk[$this->blklvl-1]['bgcolor']) && $this->blk[$this->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
  13975. $cor = $this->blk[$this->blklvl-1]['bgcolorarray' ];
  13976. $p['BACKGROUND-COLOR'] = $this->_colAtoString($cor); // mPDF 5.0.051
  13977. }
  13978. }
  13979. if (isset($this->blk[$this->blklvl-1]['text_indent']) && ($this->blk[$this->blklvl-1]['text_indent'] || $this->blk[$this->blklvl-1]['text_indent']===0)) { $p['TEXT-INDENT'] = $this->blk[$this->blklvl-1]['text_indent']; }
  13980. // mPDF 5.0.052
  13981. if (isset($this->blk[$this->blklvl-1]['InlineProperties'])) {
  13982. $biilp = $this->blk[$this->blklvl-1]['InlineProperties'];
  13983. }
  13984. else { $biilp = null; }
  13985. if (isset($biilp[ 'family' ]) && $biilp[ 'family' ]) { $p['FONT-FAMILY'] = $biilp[ 'family' ]; }
  13986. if (isset($biilp[ 'I' ]) && $biilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  13987. if (isset($biilp[ 'sizePt' ]) && $biilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $biilp[ 'sizePt' ] . 'pt'; }
  13988. if (isset($biilp[ 'B' ]) && $biilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  13989. if (isset($biilp[ 'colorarray' ]) && $biilp[ 'colorarray' ]) {
  13990. $cor = $biilp[ 'colorarray' ];
  13991. $p['COLOR'] = $this->_colAtoString($cor); // mPDF 5.0.051
  13992. }
  13993. if (isset($biilp[ 'fontkerning' ])) { // mPDF 5.0.063
  13994. if ($biilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; }
  13995. else { $p['FONT-KERNING'] = 'none'; }
  13996. }
  13997. if (isset($biilp[ 'lSpacingCSS' ]) && $biilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $biilp[ 'lSpacingCSS' ]; } // mPDF 5.0.063
  13998. if (isset($biilp[ 'wSpacingCSS' ]) && $biilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $biilp[ 'wSpacingCSS' ]; } // mPDF 5.0.063
  13999. if (isset($biilp[ 'toupper' ]) && $biilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  14000. else if (isset($biilp[ 'tolower' ]) && $biilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  14001. else if (isset($biilp[ 'capitalize' ]) && $biilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; } // mPDF 5.0.062
  14002. // CSS says text-decoration is not inherited, but IE7 does??
  14003. if (isset($biilp[ 'underline' ]) && $biilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  14004. if (isset($biilp[ 'smCaps' ]) && $biilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; } // mPDF 5.0
  14005. }
  14006. //===============================================
  14007. //===============================================
  14008. /*-- LISTS --*/
  14009. // Set Inherited properties
  14010. if ($inherit == 'TOPLIST') {
  14011. if ($this->listCSSlvl == 1) {
  14012. $bilp = $this->blk[$this->blklvl]['InlineProperties'];
  14013. if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; }
  14014. if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  14015. if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; }
  14016. if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  14017. if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) {
  14018. $cor = $bilp[ 'colorarray' ];
  14019. $p['COLOR'] = $this->_colAtoString($cor); // mPDF 5.0.051
  14020. }
  14021. if (isset($bilp[ 'toupper' ]) && $bilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  14022. else if (isset($bilp[ 'tolower' ]) && $bilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  14023. else if (isset($bilp[ 'capitalize' ]) && $bilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; } // mPDF 5.0.062
  14024. if (isset($bilp[ 'fontkerning' ])) { // mPDF 5.0.063
  14025. if ($bilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; }
  14026. else { $p['FONT-KERNING'] = 'none'; }
  14027. }
  14028. if (isset($bilp[ 'lSpacingCSS' ]) && $bilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $bilp[ 'lSpacingCSS' ]; } // mPDF 5.0.063
  14029. if (isset($bilp[ 'wSpacingCSS' ]) && $bilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $bilp[ 'wSpacingCSS' ]; } // mPDF 5.0.063
  14030. // CSS says text-decoration is not inherited, but IE7 does??
  14031. if (isset($bilp[ 'underline' ]) && $bilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  14032. if (isset($bilp[ 'smCaps' ]) && $bilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; } // mPDF 5.0
  14033. if ($tag=='LI') {
  14034. $lilp = $this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]];
  14035. if (isset($lilp[ 'family' ]) && $lilp[ 'family' ]) { $p['FONT-FAMILY'] = $lilp[ 'family' ]; }
  14036. if (isset($lilp[ 'I' ]) && $lilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  14037. if (isset($lilp[ 'sizePt' ]) && $lilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $lilp[ 'sizePt' ] . 'pt'; }
  14038. if (isset($lilp[ 'B' ]) && $lilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  14039. if (isset($lilp[ 'colorarray' ]) && $lilp[ 'colorarray' ]) {
  14040. $cor = $lilp[ 'colorarray' ];
  14041. $p['COLOR'] = $this->_colAtoString($cor); // mPDF 5.0.051
  14042. }
  14043. if (isset($lilp[ 'toupper' ]) && $lilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  14044. else if (isset($lilp[ 'tolower' ]) && $lilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  14045. else if (isset($lilp[ 'capitalize' ]) && $lilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; } // mPDF 5.0.062
  14046. if (isset($lilp[ 'fontkerning' ])) { // mPDF 5.0.063
  14047. if ($lilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; }
  14048. else { $p['FONT-KERNING'] = 'none'; }
  14049. }
  14050. if (isset($lilp[ 'lSpacingCSS' ]) && $lilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $lilp[ 'lSpacingCSS' ]; } // mPDF 5.0.063
  14051. if (isset($lilp[ 'wSpacingCSS' ]) && $lilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $lilp[ 'wSpacingCSS' ]; } // mPDF 5.0.063
  14052. // CSS says text-decoration is not inherited, but IE7 does??
  14053. if (isset($lilp[ 'underline' ]) && $lilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  14054. if (isset($lilp[ 'smCaps' ]) && $lilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; } // mPDF 5.0
  14055. }
  14056. }
  14057. }
  14058. /*-- END LISTS --*/
  14059. //===============================================
  14060. //===============================================
  14061. // DEFAULT for this TAG set in DefaultCSS
  14062. if (isset($this->defaultCSS[$tag])) {
  14063. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  14064. // mPDF 5.0.054
  14065. if (is_array($zp)) { // Default overwrites Inherited
  14066. $p = array_merge($p,$zp); // !! Note other way round !!
  14067. $this->_mergeBorders($p,$zp);
  14068. }
  14069. }
  14070. //===============================================
  14071. /*-- TABLES --*/
  14072. // cellPadding overwrites TD/TH default but not specific CSS set on cell
  14073. if (($tag=='TD' || $tag=='TH') && ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'] || $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']===0)) {
  14074. $p['PADDING-LEFT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  14075. $p['PADDING-RIGHT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  14076. $p['PADDING-TOP'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  14077. $p['PADDING-BOTTOM'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  14078. }
  14079. /*-- END TABLES --*/
  14080. //===============================================
  14081. // STYLESHEET TAG e.g. h1 p div table
  14082. if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
  14083. $zp = $this->CSS[$tag];
  14084. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  14085. if (is_array($zp)) {
  14086. // mPDF 5.0.054
  14087. $p = array_merge($p,$zp);
  14088. $this->_mergeBorders($p,$zp);
  14089. }
  14090. }
  14091. //===============================================
  14092. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  14093. foreach($classes AS $class) {
  14094. $zp = array();
  14095. if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; }
  14096. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  14097. if (is_array($zp)) {
  14098. // mPDF 5.0.054
  14099. $p = array_merge($p,$zp);
  14100. $this->_mergeBorders($p,$zp);
  14101. }
  14102. }
  14103. //===============================================
  14104. // STYLESHEET ID e.g. #smallone{} #redletter{}
  14105. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) {
  14106. $zp = $this->CSS['ID>>'.$attr['ID']];
  14107. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  14108. if (is_array($zp)) {
  14109. // mPDF 5.0.054
  14110. $p = array_merge($p,$zp);
  14111. $this->_mergeBorders($p,$zp);
  14112. }
  14113. }
  14114. //===============================================
  14115. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  14116. foreach($classes AS $class) {
  14117. $zp = array();
  14118. if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  14119. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  14120. if (is_array($zp)) {
  14121. // mPDF 5.0.054
  14122. $p = array_merge($p,$zp);
  14123. $this->_mergeBorders($p,$zp);
  14124. }
  14125. }
  14126. //===============================================
  14127. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  14128. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) {
  14129. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  14130. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  14131. if (is_array($zp)) {
  14132. // mPDF 5.0.054
  14133. $p = array_merge($p,$zp);
  14134. $this->_mergeBorders($p,$zp);
  14135. }
  14136. }
  14137. //===============================================
  14138. // Cascaded e.g. div.class p only works for block level
  14139. if ($inherit == 'BLOCK') {
  14140. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag], $p);
  14141. foreach($classes AS $class) {
  14142. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p);
  14143. }
  14144. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  14145. foreach($classes AS $class) {
  14146. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  14147. }
  14148. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  14149. }
  14150. else if ($inherit == 'INLINE') {
  14151. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag], $p);
  14152. foreach($classes AS $class) {
  14153. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['CLASS>>'.$class], $p);
  14154. }
  14155. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  14156. foreach($classes AS $class) {
  14157. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  14158. }
  14159. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  14160. }
  14161. /*-- TABLES --*/
  14162. else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
  14163. // false, 9 = don't check for 'depth' and do set border dominance
  14164. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9);
  14165. foreach($classes AS $class) {
  14166. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9);
  14167. }
  14168. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9);
  14169. foreach($classes AS $class) {
  14170. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9);
  14171. }
  14172. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9);
  14173. }
  14174. /*-- END TABLES --*/
  14175. //===============================================
  14176. /*-- LISTS --*/
  14177. else if ($inherit == 'TOPLIST' || $inherit == 'LIST') { // NB looks at $this->listcascadeCSS-1 for cascading CSS
  14178. // false = don't check for 'depth'
  14179. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag], $p, false);
  14180. foreach($classes AS $class) {
  14181. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['CLASS>>'.$class], $p, false);
  14182. }
  14183. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['ID>>'.$attr['ID']], $p, false);
  14184. foreach($classes AS $class) {
  14185. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false);
  14186. }
  14187. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false);
  14188. }
  14189. /*-- END LISTS --*/
  14190. //===============================================
  14191. //===============================================
  14192. // INLINE STYLE e.g. style="CSS:property"
  14193. if (isset($attr['STYLE'])) {
  14194. $zp = $this->readInlineCSS($attr['STYLE']);
  14195. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  14196. if (is_array($zp)) {
  14197. // mPDF 5.0.054
  14198. $p = array_merge($p,$zp);
  14199. $this->_mergeBorders($p,$zp);
  14200. }
  14201. }
  14202. //===============================================
  14203. //===============================================
  14204. // INLINE ATTRIBUTES e.g. .. ALIGN="CENTER">
  14205. if (isset($attr['LANG']) and $attr['LANG']!='') {
  14206. $p['LANG'] = $attr['LANG'];
  14207. }
  14208. if (isset($attr['COLOR']) and $attr['COLOR']!='') {
  14209. $p['COLOR'] = $attr['COLOR'];
  14210. }
  14211. if ($tag != 'INPUT') {
  14212. if (isset($attr['WIDTH']) and $attr['WIDTH']!='') {
  14213. $p['WIDTH'] = $attr['WIDTH'];
  14214. }
  14215. if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') {
  14216. $p['HEIGHT'] = $attr['HEIGHT'];
  14217. }
  14218. }
  14219. if ($tag == 'FONT') {
  14220. if (isset($attr['FACE'])) {
  14221. $p['FONT-FAMILY'] = $attr['FACE'];
  14222. }
  14223. if (isset($attr['SIZE']) and $attr['SIZE']!='') {
  14224. $s = '';
  14225. if ($attr['SIZE'] === '+1') { $s = '120%'; }
  14226. else if ($attr['SIZE'] === '-1') { $s = '86%'; }
  14227. else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; }
  14228. else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; }
  14229. else if ($attr['SIZE'] == '3') { $s = 'SMALL'; }
  14230. else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; }
  14231. else if ($attr['SIZE'] == '5') { $s = 'LARGE'; }
  14232. else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; }
  14233. else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; }
  14234. if ($s) $p['FONT-SIZE'] = $s;
  14235. }
  14236. }
  14237. if (isset($attr['VALIGN']) and $attr['VALIGN']!='') {
  14238. $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
  14239. }
  14240. if (isset($attr['VSPACE']) and $attr['VSPACE']!='') {
  14241. $p['MARGIN-TOP'] = $attr['VSPACE'];
  14242. $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
  14243. }
  14244. if (isset($attr['HSPACE']) and $attr['HSPACE']!='') {
  14245. $p['MARGIN-LEFT'] = $attr['HSPACE'];
  14246. $p['MARGIN-RIGHT'] = $attr['HSPACE'];
  14247. }
  14248. //===============================================
  14249. return $p;
  14250. }
  14251. /*-- CSS-PAGE --*/
  14252. function SetPagedMediaCSS($name='', $first, $oddEven) {
  14253. if ($oddEven == 'E') {
  14254. if ($this->directionality=='rtl') { $side = 'R'; }
  14255. else { $side = 'L'; }
  14256. }
  14257. else {
  14258. if ($this->directionality=='rtl') { $side = 'L'; }
  14259. else { $side = 'R'; }
  14260. }
  14261. $name = strtoupper($name);
  14262. $p = array();
  14263. $p['SIZE'] = 'AUTO';
  14264. // Uses mPDF original margins as default
  14265. $p['MARGIN-RIGHT'] = strval($this->orig_rMargin).'mm';
  14266. $p['MARGIN-LEFT'] = strval($this->orig_lMargin).'mm';
  14267. $p['MARGIN-TOP'] = strval($this->orig_tMargin).'mm';
  14268. $p['MARGIN-BOTTOM'] = strval($this->orig_bMargin).'mm';
  14269. $p['MARGIN-HEADER'] = strval($this->orig_hMargin).'mm';
  14270. $p['MARGIN-FOOTER'] = strval($this->orig_fMargin).'mm';
  14271. // Basic page + selector
  14272. if (isset($this->CSS['@PAGE'])) { $zp = $this->CSS['@PAGE']; }
  14273. else { $zp = array(); }
  14274. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14275. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  14276. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  14277. }
  14278. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  14279. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  14280. }
  14281. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  14282. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  14283. }
  14284. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  14285. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  14286. }
  14287. // If right/Odd page
  14288. if (isset($this->CSS['@PAGE>>PSEUDO>>RIGHT']) && $side=='R') {
  14289. $zp = $this->CSS['@PAGE>>PSEUDO>>RIGHT'];
  14290. }
  14291. else { $zp = array(); }
  14292. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  14293. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  14294. // Disallow margin-left or -right on :LEFT or :RIGHT
  14295. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  14296. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  14297. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14298. // If left/Even page
  14299. if (isset($this->CSS['@PAGE>>PSEUDO>>LEFT']) && $side=='L') {
  14300. $zp = $this->CSS['@PAGE>>PSEUDO>>LEFT'];
  14301. }
  14302. else { $zp = array(); }
  14303. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  14304. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  14305. // Disallow margin-left or -right on :LEFT or :RIGHT
  14306. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  14307. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  14308. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14309. // If first page
  14310. if (isset($this->CSS['@PAGE>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>PSEUDO>>FIRST']; }
  14311. else { $zp = array(); }
  14312. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  14313. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  14314. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14315. // If named page
  14316. if ($name) {
  14317. if (isset($this->CSS['@PAGE>>NAMED>>'.$name])) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name]; }
  14318. else { $zp = array(); }
  14319. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14320. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  14321. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  14322. }
  14323. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  14324. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  14325. }
  14326. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  14327. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  14328. }
  14329. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  14330. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  14331. }
  14332. // If named right/Odd page
  14333. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']) && $side=='R') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']; }
  14334. else { $zp = array(); }
  14335. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  14336. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  14337. // Disallow margin-left or -right on :LEFT or :RIGHT
  14338. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  14339. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  14340. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14341. // If named left/Even page
  14342. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']) && $side=='L') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']; }
  14343. else { $zp = array(); }
  14344. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  14345. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  14346. // Disallow margin-left or -right on :LEFT or :RIGHT
  14347. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  14348. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  14349. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14350. // If named first page
  14351. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']; }
  14352. else { $zp = array(); }
  14353. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  14354. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  14355. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  14356. }
  14357. $orientation = $mgl = $mgr = $mgt = $mgb = $mgh = $mgf = '';
  14358. $header = $footer = '';
  14359. $resetpagenum = $pagenumstyle = $suppress = '';
  14360. $marks = '';
  14361. $bg = array();
  14362. $newformat = '';
  14363. if (isset($p['SHEET-SIZE']) && is_array($p['SHEET-SIZE'])) {
  14364. $newformat = $p['SHEET-SIZE'];
  14365. if ($newformat[0] > $newformat[1]) { // landscape
  14366. $newformat = array_reverse($newformat);
  14367. $p['ORIENTATION'] = 'L';
  14368. }
  14369. else { $p['ORIENTATION'] = 'P'; }
  14370. $this->_setPageSize($newformat, $p['ORIENTATION']);
  14371. }
  14372. if (isset($p['SIZE']) && is_array($p['SIZE']) && !$newformat) {
  14373. if ($p['SIZE']['W'] > $p['SIZE']['H']) { $p['ORIENTATION'] = 'L'; }
  14374. else { $p['ORIENTATION'] = 'P'; }
  14375. }
  14376. if (is_array($p['SIZE'])) {
  14377. if ($p['SIZE']['W'] > $this->fw) { $p['SIZE']['W'] = $this->fw; } // mPD 4.2 use fw not fPt
  14378. if ($p['SIZE']['H'] > $this->fh) { $p['SIZE']['H'] = $this->fh; }
  14379. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  14380. $outer_width_LR = ($this->fw - $p['SIZE']['W'])/2;
  14381. $outer_width_TB = ($this->fh - $p['SIZE']['H'])/2;
  14382. }
  14383. else {
  14384. $outer_width_LR = ($this->fh - $p['SIZE']['W'])/2;
  14385. $outer_width_TB = ($this->fw - $p['SIZE']['H'])/2;
  14386. }
  14387. $pgw = $p['SIZE']['W'];
  14388. $pgh = $p['SIZE']['H'];
  14389. }
  14390. else { // AUTO LANDSCAPE PORTRAIT
  14391. $outer_width_LR = 0;
  14392. $outer_width_TB = 0;
  14393. if (!$newformat) {
  14394. if (strtoupper($p['SIZE']) == 'AUTO') { $p['ORIENTATION']=$this->DefOrientation; }
  14395. else if (strtoupper($p['SIZE']) == 'LANDSCAPE') { $p['ORIENTATION']='L'; }
  14396. else { $p['ORIENTATION']='P'; }
  14397. }
  14398. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  14399. $pgw = $this->fw;
  14400. $pgh = $this->fh;
  14401. }
  14402. else {
  14403. $pgw = $this->fh;
  14404. $pgh = $this->fw;
  14405. }
  14406. }
  14407. if (isset($p['HEADER']) && $p['HEADER']) { $header = $p['HEADER']; }
  14408. if (isset($p['FOOTER']) && $p['FOOTER']) { $footer = $p['FOOTER']; }
  14409. if (isset($p['RESETPAGENUM']) && $p['RESETPAGENUM']) { $resetpagenum = $p['RESETPAGENUM']; }
  14410. if (isset($p['PAGENUMSTYLE']) && $p['PAGENUMSTYLE']) { $pagenumstyle = $p['PAGENUMSTYLE']; }
  14411. if (isset($p['SUPPRESS']) && $p['SUPPRESS']) { $suppress = $p['SUPPRESS']; }
  14412. if (preg_match('/cross/i', $p['MARKS']) && preg_match('/crop/i', $p['MARKS'])) { $marks = 'CROPCROSS'; } // mPDF 5.0.006
  14413. else if (strtoupper($p['MARKS']) == 'CROP') { $marks = 'CROP'; }
  14414. else if (strtoupper($p['MARKS']) == 'CROSS') { $marks = 'CROSS'; }
  14415. if (isset($p['BACKGROUND-COLOR']) && $p['BACKGROUND-COLOR']) { $bg['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  14416. /*-- BACKGROUNDS --*/
  14417. if (isset($p['BACKGROUND-GRADIENT']) && $p['BACKGROUND-GRADIENT']) { $bg['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  14418. if (isset($p['BACKGROUND-IMAGE']) && $p['BACKGROUND-IMAGE']) { $bg['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  14419. if (isset($p['BACKGROUND-REPEAT']) && $p['BACKGROUND-REPEAT']) { $bg['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  14420. if (isset($p['BACKGROUND-POSITION']) && $p['BACKGROUND-POSITION']) { $bg['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  14421. // mPDF 5.0.047
  14422. if (isset($p['BACKGROUND-IMAGE-RESIZE']) && $p['BACKGROUND-IMAGE-RESIZE']) { $bg['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  14423. if (isset($p['BACKGROUND-IMAGE-OPACITY']) && $p['BACKGROUND-IMAGE-OPACITY']) { $bg['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; }
  14424. /*-- END BACKGROUNDS --*/
  14425. if (isset($p['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($p['MARGIN-LEFT'],$pgw) + $outer_width_LR; }
  14426. if (isset($p['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($p['MARGIN-RIGHT'],$pgw) + $outer_width_LR; }
  14427. if (isset($p['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($p['MARGIN-BOTTOM'],$pgh) + $outer_width_TB; }
  14428. if (isset($p['MARGIN-TOP'])) { $mgt = $this->ConvertSize($p['MARGIN-TOP'],$pgh) + $outer_width_TB; }
  14429. if (isset($p['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($p['MARGIN-HEADER'],$pgh) + $outer_width_TB; }
  14430. if (isset($p['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($p['MARGIN-FOOTER'],$pgh) + $outer_width_TB; }
  14431. if (isset($p['ORIENTATION']) && $p['ORIENTATION']) { $orientation = $p['ORIENTATION']; }
  14432. $this->page_box['outer_width_LR'] = $outer_width_LR; // Used in MARKS:crop etc.
  14433. $this->page_box['outer_width_TB'] = $outer_width_TB;
  14434. return array($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$header,$footer,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat);
  14435. }
  14436. /*-- END CSS-PAGE --*/
  14437. function PreviewBlockCSS($tag,$attr) {
  14438. // Looks ahead from current block level to a new level
  14439. $p = array();
  14440. $zp = array();
  14441. $oldcascadeCSS = $this->blk[$this->blklvl]['cascadeCSS'];
  14442. $classes = array();
  14443. if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); }
  14444. //===============================================
  14445. // DEFAULT for this TAG set in DefaultCSS
  14446. if (isset($this->defaultCSS[$tag])) {
  14447. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  14448. if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default
  14449. }
  14450. // STYLESHEET TAG e.g. h1 p div table
  14451. if (isset($this->CSS[$tag])) {
  14452. $zp = $this->CSS[$tag];
  14453. if (is_array($zp)) { $p = array_merge($p,$zp); }
  14454. }
  14455. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  14456. foreach($classes AS $class) {
  14457. $zp = array();
  14458. if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; }
  14459. if (is_array($zp)) { $p = array_merge($p,$zp); }
  14460. }
  14461. // STYLESHEET ID e.g. #smallone{} #redletter{}
  14462. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) {
  14463. $zp = $this->CSS['ID>>'.$attr['ID']];
  14464. if (is_array($zp)) { $p = array_merge($p,$zp); }
  14465. }
  14466. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  14467. foreach($classes AS $class) {
  14468. $zp = array();
  14469. if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  14470. if (is_array($zp)) { $p = array_merge($p,$zp); }
  14471. }
  14472. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  14473. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) {
  14474. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  14475. if (is_array($zp)) { $p = array_merge($p,$zp); }
  14476. }
  14477. //===============================================
  14478. // STYLESHEET TAG e.g. div h1 div p
  14479. $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
  14480. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  14481. foreach($classes AS $class) {
  14482. $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p);
  14483. }
  14484. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  14485. if (isset($attr['ID'])) {
  14486. $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p);
  14487. }
  14488. // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
  14489. foreach($classes AS $class) {
  14490. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p);
  14491. }
  14492. // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
  14493. if (isset($attr['ID'])) {
  14494. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p);
  14495. }
  14496. //===============================================
  14497. // INLINE STYLE e.g. style="CSS:property"
  14498. if (isset($attr['STYLE'])) {
  14499. $zp = $this->readInlineCSS($attr['STYLE']);
  14500. if (is_array($zp)) { $p = array_merge($p,$zp); }
  14501. }
  14502. //===============================================
  14503. return $p;
  14504. }
  14505. /*-- CSS-FLOAT --*/
  14506. // Added mPDF 3.0 Float DIV - CLEAR
  14507. function ClearFloats($clear, $blklvl=0) {
  14508. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($blklvl,true);
  14509. $end = $currpos = ($this->page*1000 + $this->y);
  14510. if ($clear == 'BOTH' && ($l_exists || $r_exists)) {
  14511. $this->pageoutput[$this->page] = array();
  14512. $end = max($l_max, $r_max, $currpos);
  14513. }
  14514. else if ($clear == 'RIGHT' && $r_exists) {
  14515. $this->pageoutput[$this->page] = array();
  14516. $end = max($r_max, $currpos);
  14517. }
  14518. else if ($clear == 'LEFT' && $l_exists ) {
  14519. $this->pageoutput[$this->page] = array();
  14520. $end = max($l_max, $currpos);
  14521. }
  14522. else { return; }
  14523. $old_page = $this->page;
  14524. $new_page = intval($end/1000);
  14525. if ($old_page != $new_page) {
  14526. $s = $this->PrintPageBackgrounds();
  14527. // Writes after the marker so not overwritten later by page background etc.
  14528. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  14529. $this->pageBackgrounds = array();
  14530. $this->page = $new_page;
  14531. }
  14532. $this->ResetMargins();
  14533. $this->pageoutput[$this->page] = array();
  14534. $this->y = (($end*1000) % 1000000)/1000; // mod changes operands to integers before processing
  14535. }
  14536. // Added mPDF 3.0 Float DIV
  14537. function GetFloatDivInfo($blklvl=0,$clear=false) {
  14538. // If blklvl specified, only returns floats at that level - for ClearFloats
  14539. $l_exists = false;
  14540. $r_exists = false;
  14541. $l_max = 0;
  14542. $r_max = 0;
  14543. $l_width = 0;
  14544. $r_width = 0;
  14545. if (count($this->floatDivs)) {
  14546. $currpos = ($this->page*1000 + $this->y);
  14547. foreach($this->floatDivs AS $f) {
  14548. if (($clear && $f['blockContext'] == $this->blk[$blklvl]['blockContext']) || (!$clear && $currpos >= $f['startpos'] && $currpos < ($f['endpos']-0.001) && $f['blklvl'] > $blklvl && $f['blockContext'] == $this->blk[$blklvl]['blockContext'])) {
  14549. if ($f['side']=='L') {
  14550. $l_exists= true;
  14551. $l_max = max($l_max, $f['endpos']);
  14552. $l_width = max($l_width , $f['w']);
  14553. }
  14554. if ($f['side']=='R') {
  14555. $r_exists= true;
  14556. $r_max = max($r_max, $f['endpos']);
  14557. $r_width = max($r_width , $f['w']);
  14558. }
  14559. }
  14560. }
  14561. }
  14562. return array($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width);
  14563. }
  14564. /*-- END CSS-FLOAT --*/
  14565. function OpenTag($tag,$attr)
  14566. {
  14567. // What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here>
  14568. // Correct tags where HTML specifies optional end tags,
  14569. // and/or does not allow nesting e.g. P inside P, or
  14570. if ($this->allow_html_optional_endtags) {
  14571. if (($tag == 'P' || $tag == 'DIV' || $tag == 'H1' || $tag == 'H2' || $tag == 'H3' || $tag == 'H4' || $tag == 'H5' || $tag == 'H6' || $tag == 'UL' || $tag == 'OL' || $tag == 'TABLE' || $tag=='PRE' || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DL' || $tag == 'HR' ) && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); }
  14572. if ($tag == 'DD' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  14573. if ($tag == 'DD' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  14574. if ($tag == 'DT' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  14575. if ($tag == 'DT' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  14576. if ($tag == 'LI' && $this->lastoptionaltag == 'LI') { $this->CloseTag($this->lastoptionaltag ); }
  14577. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  14578. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  14579. if ($tag == 'TR' && $this->lastoptionaltag == 'TR') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  14580. if ($tag == 'TR' && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  14581. if ($tag == 'TR' && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  14582. if ($tag == 'OPTION' && $this->lastoptionaltag == 'OPTION') { $this->CloseTag($this->lastoptionaltag ); }
  14583. }
  14584. $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','text-top'=>'TT','middle'=>'M','baseline'=>'BS','bottom'=>'B','text-bottom'=>'TB','justify'=>'J');
  14585. $this->ignorefollowingspaces=false;
  14586. //Opening tag
  14587. switch($tag){
  14588. case 'DOTTAB':
  14589. $objattr = array();
  14590. $objattr['type'] = 'dottab';
  14591. $dots=str_repeat('.', 3)." "; // minimum number of dots
  14592. $objattr['width'] = $this->GetStringWidth($dots);
  14593. $objattr['margin_top'] = 0;
  14594. $objattr['margin_bottom'] = 0;
  14595. $objattr['margin_left'] = 0;
  14596. $objattr['margin_right'] = 0;
  14597. $objattr['height'] = 0;
  14598. $objattr['colorarray'] = $this->colorarray; // mPDF 5.0
  14599. $objattr['border_top']['w'] = 0;
  14600. $objattr['border_bottom']['w'] = 0;
  14601. $objattr['border_left']['w'] = 0;
  14602. $objattr['border_right']['w'] = 0;
  14603. $e = "\xbb\xa4\xactype=dottab,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14604. /*-- TABLES --*/
  14605. // Output it to buffers
  14606. if ($this->tableLevel) {
  14607. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14608. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14609. }
  14610. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14611. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14612. }
  14613. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14614. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  14615. }
  14616. else {
  14617. /*-- END TABLES --*/
  14618. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  14619. } // *TABLES*
  14620. break;
  14621. case 'PAGEHEADER':
  14622. case 'PAGEFOOTER':
  14623. $this->ignorefollowingspaces = true;
  14624. if ($attr['NAME']) { $pname = $attr['NAME']; }
  14625. else { $pname = '_default'; }
  14626. if ($tag=='PAGEHEADER') { $p = &$this->pageheaders[$pname]; }
  14627. else { $p = &$this->pagefooters[$pname]; }
  14628. $p['L']=array();
  14629. $p['C']=array();
  14630. $p['R']=array();
  14631. $p['L']['font-style'] = '';
  14632. $p['C']['font-style'] = '';
  14633. $p['R']['font-style'] = '';
  14634. if (isset($attr['CONTENT-LEFT'])) {
  14635. $p['L']['content'] = $attr['CONTENT-LEFT'];
  14636. }
  14637. if (isset($attr['CONTENT-CENTER'])) {
  14638. $p['C']['content'] = $attr['CONTENT-CENTER'];
  14639. }
  14640. if (isset($attr['CONTENT-RIGHT'])) {
  14641. $p['R']['content'] = $attr['CONTENT-RIGHT'];
  14642. }
  14643. if (isset($attr['HEADER-STYLE']) || isset($attr['FOOTER-STYLE'])) { // font-family,size,weight,style,color
  14644. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE']); }
  14645. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE']); }
  14646. if (isset($properties['FONT-FAMILY'])) {
  14647. $p['L']['font-family'] = $properties['FONT-FAMILY'];
  14648. $p['C']['font-family'] = $properties['FONT-FAMILY'];
  14649. $p['R']['font-family'] = $properties['FONT-FAMILY'];
  14650. }
  14651. if (isset($properties['FONT-SIZE'])) {
  14652. $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k;
  14653. $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k;
  14654. $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k;
  14655. }
  14656. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') {
  14657. $p['L']['font-style'] = 'B';
  14658. $p['C']['font-style'] = 'B';
  14659. $p['R']['font-style'] = 'B';
  14660. }
  14661. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') {
  14662. $p['L']['font-style'] .= 'I';
  14663. $p['C']['font-style'] .= 'I';
  14664. $p['R']['font-style'] .= 'I';
  14665. }
  14666. if (isset($properties['COLOR'])) {
  14667. $p['L']['color'] = $properties['COLOR'];
  14668. $p['C']['color'] = $properties['COLOR'];
  14669. $p['R']['color'] = $properties['COLOR'];
  14670. }
  14671. }
  14672. if (isset($attr['HEADER-STYLE-LEFT']) || isset($attr['FOOTER-STYLE-LEFT'])) {
  14673. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-LEFT']); }
  14674. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-LEFT']); }
  14675. if (isset($properties['FONT-FAMILY'])) { $p['L']['font-family'] = $properties['FONT-FAMILY']; }
  14676. if (isset($properties['FONT-SIZE'])) { $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k; }
  14677. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') { $p['L']['font-style'] ='B'; }
  14678. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') { $p['L']['font-style'] .='I'; }
  14679. if (isset($properties['COLOR'])) { $p['L']['color'] = $properties['COLOR']; }
  14680. }
  14681. if (isset($attr['HEADER-STYLE-CENTER']) || isset($attr['FOOTER-STYLE-CENTER'])) {
  14682. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-CENTER']); }
  14683. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-CENTER']); }
  14684. if (isset($properties['FONT-FAMILY'])) { $p['C']['font-family'] = $properties['FONT-FAMILY']; }
  14685. if (isset($properties['FONT-SIZE'])) { $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k; }
  14686. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') { $p['C']['font-style'] = 'B'; }
  14687. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') { $p['C']['font-style'] .= 'I'; }
  14688. if (isset($properties['COLOR'])) { $p['C']['color'] = $properties['COLOR']; }
  14689. }
  14690. if (isset($attr['HEADER-STYLE-RIGHT']) || isset($attr['FOOTER-STYLE-RIGHT'])) {
  14691. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-RIGHT']); }
  14692. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-RIGHT']); }
  14693. if (isset($properties['FONT-FAMILY'])) { $p['R']['font-family'] = $properties['FONT-FAMILY']; }
  14694. if (isset($properties['FONT-SIZE'])) { $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k; }
  14695. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') { $p['R']['font-style'] = 'B'; }
  14696. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') { $p['R']['font-style'] .= 'I'; }
  14697. if (isset($properties['COLOR'])) { $p['R']['color'] = $properties['COLOR']; }
  14698. }
  14699. if (isset($attr['LINE']) && $attr['LINE']) { // 0|1|on|off
  14700. if ($attr['LINE']=='1' || strtoupper($attr['LINE'])=='ON') { $lineset=1; }
  14701. else { $lineset=0; }
  14702. $p['line'] = $lineset;
  14703. }
  14704. break;
  14705. /*-- HTMLHEADERS-FOOTERS --*/
  14706. case 'SETHTMLPAGEHEADER':
  14707. case 'SETHTMLPAGEFOOTER':
  14708. $this->ignorefollowingspaces = true;
  14709. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  14710. else { $pname = '_default'; }
  14711. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  14712. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  14713. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  14714. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  14715. else { $side='odd'; }
  14716. }
  14717. else { $side='odd'; }
  14718. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  14719. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  14720. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  14721. else { $set=1; }
  14722. }
  14723. else { $set=1; }
  14724. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETHTMLPAGEHEADER') { $write = 1; }
  14725. else { $write = 0; }
  14726. if ($side=='odd' || $side=='both') {
  14727. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'O',$write); }
  14728. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'O'); }
  14729. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','O'); }
  14730. else { $this->SetHTMLFooter('','O'); }
  14731. }
  14732. if ($side=='even' || $side=='both') {
  14733. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'E',$write); }
  14734. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'E'); }
  14735. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','E'); }
  14736. else { $this->SetHTMLFooter('','E'); }
  14737. }
  14738. break;
  14739. /*-- END HTMLHEADERS-FOOTERS --*/
  14740. case 'SETPAGEHEADER':
  14741. case 'SETPAGEFOOTER':
  14742. $this->ignorefollowingspaces = true;
  14743. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  14744. else { $pname = '_default'; }
  14745. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  14746. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  14747. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  14748. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  14749. else { $side='odd'; }
  14750. }
  14751. else { $side='odd'; }
  14752. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  14753. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  14754. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  14755. else { $set=1; }
  14756. }
  14757. else { $set=1; }
  14758. if ($side=='odd' || $side=='both') {
  14759. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = $this->pageheaders[$pname]; }
  14760. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['odd'] = $this->pagefooters[$pname]; }
  14761. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = array(); }
  14762. else { $this->footerDetails['odd'] = array(); }
  14763. if (!$this->mirrorMargins || ($this->page)%2!=0) { // ODD
  14764. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['odd'],$this->HTMLHeader); }
  14765. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['odd'],$this->HTMLFooter); }
  14766. }
  14767. }
  14768. if ($side=='even' || $side=='both') {
  14769. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['even'] = $this->pageheaders[$pname]; }
  14770. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['even'] = $this->pagefooters[$pname]; }
  14771. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['even'] = array(); }
  14772. else { $this->footerDetails['even'] = array(); }
  14773. if ($this->mirrorMargins && ($this->page)%2==0) { // EVEN
  14774. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['even'],$this->HTMLHeaderE); }
  14775. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['even'],$this->HTMLFooterE); }
  14776. }
  14777. }
  14778. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETPAGEHEADER') {
  14779. $this->Header();
  14780. }
  14781. break;
  14782. /*-- TOC --*/
  14783. case 'TOC': //added custom-tag - set Marker for insertion later of ToC
  14784. if (isset($attr['FONT-SIZE']) && $attr['FONT-SIZE']) { $tocfontsize = $attr['FONT-SIZE']; } else { $tocfontsize = ''; }
  14785. if (isset($attr['FONT']) && $attr['FONT']) { $tocfont = $attr['FONT']; } else { $tocfont = ''; }
  14786. if (isset($attr['INDENT']) && $attr['INDENT']) { $tocindent = $attr['INDENT']; } else { $tocindent = ''; }
  14787. if (isset($attr['RESETPAGENUM']) && $attr['RESETPAGENUM']) { $resetpagenum = $attr['RESETPAGENUM']; } else { $resetpagenum = ''; }
  14788. if (isset($attr['PAGENUMSTYLE']) && $attr['PAGENUMSTYLE']) { $pagenumstyle = $attr['PAGENUMSTYLE']; } else { $pagenumstyle= ''; }
  14789. if (isset($attr['SUPPRESS']) && $attr['SUPPRESS']) { $suppress = $attr['SUPPRESS']; } else { $suppress = ''; }
  14790. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $toc_orientation = $attr['TOC-ORIENTATION']; } else { $toc_orientation = ''; }
  14791. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $paging = false; }
  14792. else { $paging = true; }
  14793. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  14794. else { $links = false; }
  14795. if (isset($attr['NAME']) && $attr['NAME']) { $toc_id = strtolower($attr['NAME']); } else { $toc_id = 0; }
  14796. $this->TOC($tocfont,$tocfontsize,$tocindent,$resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $paging, $links, $toc_id);
  14797. break;
  14798. case 'TOCPAGEBREAK': // custom-tag - set Marker for insertion later of ToC AND adds PAGEBREAK
  14799. if (isset($attr['NAME']) && $attr['NAME']) { $toc_id = strtolower($attr['NAME']); } else { $toc_id = 0; }
  14800. if ($toc_id) {
  14801. if (isset($attr['FONT-SIZE'])) { $this->m_TOC[$toc_id]['TOCfontsize'] = $attr['FONT-SIZE']; } else { $this->m_TOC[$toc_id]['TOCfontsize'] = $this->default_font_size; }
  14802. if (isset($attr['FONT'])) { $this->m_TOC[$toc_id]['TOCfont'] = $attr['FONT']; } else { $this->m_TOC[$toc_id]['TOCfont'] = $this->default_font; }
  14803. if (isset($attr['INDENT']) && $attr['INDENT']) { $this->m_TOC[$toc_id]['TOCindent'] = $attr['INDENT']; } else { $this->m_TOC[$toc_id]['TOCindent'] = ''; }
  14804. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $this->m_TOC[$toc_id]['TOCorientation'] = $attr['TOC-ORIENTATION']; } else { $this->m_TOC[$toc_id]['TOCorientation'] = ''; }
  14805. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $this->m_TOC[$toc_id]['TOCusePaging'] = false; }
  14806. else { $this->m_TOC[$toc_id]['TOCusePaging'] = true; }
  14807. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $this->m_TOC[$toc_id]['TOCuseLinking'] = true; }
  14808. else { $this->m_TOC[$toc_id]['TOCuseLinking'] = false; }
  14809. $this->m_TOC[$toc_id]['TOC_margin_left'] = $this->m_TOC[$toc_id]['TOC_margin_right'] = $this->m_TOC[$toc_id]['TOC_margin_top'] = $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $this->m_TOC[$toc_id]['TOC_margin_header'] = $this->m_TOC[$toc_id]['TOC_margin_footer'] = '';
  14810. if (isset($attr['TOC-MARGIN-RIGHT'])) { $this->m_TOC[$toc_id]['TOC_margin_right'] = $this->ConvertSize($attr['TOC-MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  14811. if (isset($attr['TOC-MARGIN-LEFT'])) { $this->m_TOC[$toc_id]['TOC_margin_left'] = $this->ConvertSize($attr['TOC-MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  14812. if (isset($attr['TOC-MARGIN-TOP'])) { $this->m_TOC[$toc_id]['TOC_margin_top'] = $this->ConvertSize($attr['TOC-MARGIN-TOP'],$this->w,$this->FontSize,false); }
  14813. if (isset($attr['TOC-MARGIN-BOTTOM'])) { $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $this->ConvertSize($attr['TOC-MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  14814. if (isset($attr['TOC-MARGIN-HEADER'])) { $this->m_TOC[$toc_id]['TOC_margin_header'] = $this->ConvertSize($attr['TOC-MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  14815. if (isset($attr['TOC-MARGIN-FOOTER'])) { $this->m_TOC[$toc_id]['TOC_margin_footer'] = $this->ConvertSize($attr['TOC-MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  14816. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $this->m_TOC[$toc_id]['TOC_even_header_name'] = $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $this->m_TOC[$toc_id]['TOC_even_footer_name'] = '';
  14817. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) { $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $attr['TOC-ODD-HEADER-NAME']; }
  14818. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) { $this->m_TOC[$toc_id]['TOC_even_header_name'] = $attr['TOC-EVEN-HEADER-NAME']; }
  14819. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) { $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $attr['TOC-ODD-FOOTER-NAME']; }
  14820. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) { $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $attr['TOC-EVEN-FOOTER-NAME']; }
  14821. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = $this->m_TOC[$toc_id]['TOC_even_header_value'] = $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = $this->m_TOC[$toc_id]['TOC_even_footer_value'] = 0;
  14822. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_odd_header_value'] = 1; }
  14823. else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_odd_header_value'] = -1; }
  14824. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_even_header_value'] = 1; }
  14825. else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_even_header_value'] = -1; }
  14826. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = 1; }
  14827. else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = -1; }
  14828. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_even_footer_value'] = 1; }
  14829. else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_even_footer_value'] = -1; }
  14830. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) { $this->m_TOC[$toc_id]['TOC_page_selector'] = $attr['TOC-PAGE-SELECTOR']; }
  14831. else { $this->m_TOC[$toc_id]['TOC_page_selector'] = ''; }
  14832. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) { $this->m_TOC[$toc_id]['TOCsheetsize'] = $attr['TOC-SHEET-SIZE']; } else { $this->m_TOC[$toc_id]['TOCsheetsize'] = ''; }
  14833. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) { $this->m_TOC[$toc_id]['TOCpreHTML'] = htmlspecialchars_decode($attr['TOC-PREHTML'],ENT_QUOTES); }
  14834. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) { $this->m_TOC[$toc_id]['TOCpostHTML'] = htmlspecialchars_decode($attr['TOC-POSTHTML'],ENT_QUOTES); }
  14835. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) { $this->m_TOC[$toc_id]['TOCbookmarkText'] = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'],ENT_QUOTES); } // *BOOKMARKS*
  14836. }
  14837. else {
  14838. if (isset($attr['FONT-SIZE'])) { $this->TOCfontsize = $attr['FONT-SIZE']; } else { $this->TOCfontsize = $this->default_font_size; }
  14839. if (isset($attr['FONT'])) { $this->TOCfont = $attr['FONT']; } else { $this->TOCfont = $this->default_font; }
  14840. if (isset($attr['INDENT']) && $attr['INDENT']) { $this->TOCindent = $attr['INDENT']; } else { $this->TOCindent = ''; }
  14841. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $this->TOCorientation = $attr['TOC-ORIENTATION']; } else { $this->TOCorientation = ''; }
  14842. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $this->TOCusePaging = false; }
  14843. else { $this->TOCusePaging = true; }
  14844. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $this->TOCuseLinking = true; }
  14845. else { $this->TOCuseLinking = false; }
  14846. $this->TOC_margin_left = $this->TOC_margin_right = $this->TOC_margin_top = $this->TOC_margin_bottom = $this->TOC_margin_header = $this->TOC_margin_footer = '';
  14847. if (isset($attr['TOC-MARGIN-RIGHT'])) { $this->TOC_margin_right = $this->ConvertSize($attr['TOC-MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  14848. if (isset($attr['TOC-MARGIN-LEFT'])) { $this->TOC_margin_left = $this->ConvertSize($attr['TOC-MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  14849. if (isset($attr['TOC-MARGIN-TOP'])) { $this->TOC_margin_top = $this->ConvertSize($attr['TOC-MARGIN-TOP'],$this->w,$this->FontSize,false); }
  14850. if (isset($attr['TOC-MARGIN-BOTTOM'])) { $this->TOC_margin_bottom = $this->ConvertSize($attr['TOC-MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  14851. if (isset($attr['TOC-MARGIN-HEADER'])) { $this->TOC_margin_header = $this->ConvertSize($attr['TOC-MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  14852. if (isset($attr['TOC-MARGIN-FOOTER'])) { $this->TOC_margin_footer = $this->ConvertSize($attr['TOC-MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  14853. $this->TOC_odd_header_name = $this->TOC_even_header_name = $this->TOC_odd_footer_name = $this->TOC_even_footer_name = '';
  14854. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) { $this->TOC_odd_header_name = $attr['TOC-ODD-HEADER-NAME']; }
  14855. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) { $this->TOC_even_header_name = $attr['TOC-EVEN-HEADER-NAME']; }
  14856. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) { $this->TOC_odd_footer_name = $attr['TOC-ODD-FOOTER-NAME']; }
  14857. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) { $this->TOC_even_footer_name = $attr['TOC-EVEN-FOOTER-NAME']; }
  14858. $this->TOC_odd_header_value = $this->TOC_even_header_value = $this->TOC_odd_footer_value = $this->TOC_even_footer_value = 0;
  14859. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='ON')) { $this->TOC_odd_header_value = 1; }
  14860. else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='OFF')) { $this->TOC_odd_header_value = -1; }
  14861. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='ON')) { $this->TOC_even_header_value = 1; }
  14862. else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='OFF')) { $this->TOC_even_header_value = -1; }
  14863. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='ON')) { $this->TOC_odd_footer_value = 1; }
  14864. else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='OFF')) { $this->TOC_odd_footer_value = -1; }
  14865. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='ON')) { $this->TOC_even_footer_value = 1; }
  14866. else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='OFF')) { $this->TOC_even_footer_value = -1; }
  14867. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) { $this->TOC_page_selector = $attr['TOC-PAGE-SELECTOR']; }
  14868. else { $this->TOC_page_selector = ''; }
  14869. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) { $this->TOCsheetsize = $attr['TOC-SHEET-SIZE']; } else { $this->TOCsheetsize = ''; }
  14870. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) { $this->TOCpreHTML = htmlspecialchars_decode($attr['TOC-PREHTML'],ENT_QUOTES); }
  14871. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) { $this->TOCpostHTML = htmlspecialchars_decode($attr['TOC-POSTHTML'],ENT_QUOTES); }
  14872. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) { $this->TOCbookmarkText = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'],ENT_QUOTES); } // *BOOKMARKS*
  14873. }
  14874. if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) {
  14875. if ($toc_id) { $this->m_TOC[$toc_id]['TOCmark'] = $this->page; }
  14876. else { $this->TOCmark = $this->page; }
  14877. // Don't add a page
  14878. if ($this->page==1 && count($this->PageNumSubstitutions)==0) {
  14879. $resetpagenum = '';
  14880. $pagenumstyle = '';
  14881. $suppress = '';
  14882. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  14883. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  14884. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  14885. if (!$suppress) { $suppress = 'off'; }
  14886. if (!$resetpagenum) { $resetpagenum= 1; }
  14887. $this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  14888. }
  14889. break;
  14890. }
  14891. // No break - continues as PAGEBREAK...
  14892. /*-- END TOC --*/
  14893. case 'PAGE_BREAK': //custom-tag
  14894. case 'PAGEBREAK': //custom-tag
  14895. case 'NEWPAGE': //custom-tag
  14896. case 'FORMFEED': //custom-tag
  14897. $save_blklvl = $this->blklvl;
  14898. $save_blk = $this->blk;
  14899. $save_silp = $this->saveInlineProperties();
  14900. $save_spanlvl = $this->spanlvl;
  14901. $save_ilp = $this->InlineProperties;
  14902. // Close any open block tags
  14903. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  14904. if(!empty($this->textbuffer)) { //Output previously buffered content
  14905. $this->printbuffer($this->textbuffer);
  14906. $this->textbuffer=array();
  14907. }
  14908. $this->ignorefollowingspaces = true;
  14909. $save_cols = false;
  14910. /*-- COLUMNS --*/
  14911. if ($this->ColActive) {
  14912. $save_cols = true;
  14913. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  14914. $this->SetColumns(0);
  14915. }
  14916. /*-- END COLUMNS --*/
  14917. if (isset($attr['SHEET-SIZE']) && $tag != 'FORMFEED' && !$this->restoreBlockPageBreaks) {
  14918. // Convert to same types as accepted in initial mPDF() A4, A4-L, or array(w,h)
  14919. $prop = preg_split('/\s+/',trim($attr['SHEET-SIZE']));
  14920. if (count($prop) == 2 ) {
  14921. $newformat = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  14922. }
  14923. else { $newformat = $attr['SHEET-SIZE']; }
  14924. }
  14925. else { $newformat = ''; }
  14926. $mgr = $mgl = $mgt = $mgb = $mgh = $mgf = '';
  14927. if (isset($attr['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($attr['MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  14928. if (isset($attr['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($attr['MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  14929. if (isset($attr['MARGIN-TOP'])) { $mgt = $this->ConvertSize($attr['MARGIN-TOP'],$this->w,$this->FontSize,false); }
  14930. if (isset($attr['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($attr['MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  14931. if (isset($attr['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($attr['MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  14932. if (isset($attr['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($attr['MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  14933. $ohname = $ehname = $ofname = $efname = '';
  14934. if (isset($attr['ODD-HEADER-NAME'])) { $ohname = $attr['ODD-HEADER-NAME']; }
  14935. if (isset($attr['EVEN-HEADER-NAME'])) { $ehname = $attr['EVEN-HEADER-NAME']; }
  14936. if (isset($attr['ODD-FOOTER-NAME'])) { $ofname = $attr['ODD-FOOTER-NAME']; }
  14937. if (isset($attr['EVEN-FOOTER-NAME'])) { $efname = $attr['EVEN-FOOTER-NAME']; }
  14938. $ohvalue = $ehvalue = $ofvalue = $efvalue = 0;
  14939. if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='1' || strtoupper($attr['ODD-HEADER-VALUE'])=='ON')) { $ohvalue = 1; }
  14940. else if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='-1' || strtoupper($attr['ODD-HEADER-VALUE'])=='OFF')) { $ohvalue = -1; }
  14941. if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='ON')) { $ehvalue = 1; }
  14942. else if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='OFF')) { $ehvalue = -1; }
  14943. if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='ON')) { $ofvalue = 1; }
  14944. else if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='OFF')) { $ofvalue = -1; }
  14945. if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='ON')) { $efvalue = 1; }
  14946. else if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='OFF')) { $efvalue = -1; }
  14947. if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='L' || strtoupper($attr['ORIENTATION'])=='LANDSCAPE')) { $orient = 'L'; }
  14948. else if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='P' || strtoupper($attr['ORIENTATION'])=='PORTRAIT')) { $orient = 'P'; }
  14949. else { $orient = $this->CurOrientation; }
  14950. if (isset($attr['PAGE-SELECTOR']) && $attr['PAGE-SELECTOR']) { $pagesel = $attr['PAGE-SELECTOR']; }
  14951. else { $pagesel = ''; }
  14952. $resetpagenum = '';
  14953. $pagenumstyle = '';
  14954. $suppress = '';
  14955. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  14956. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  14957. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  14958. if ($tag == 'TOCPAGEBREAK') { $type = 'NEXT-ODD'; }
  14959. else if(isset($attr['TYPE'])) { $type = strtoupper($attr['TYPE']); }
  14960. else { $type = ''; }
  14961. if ($type == 'E' || $type == 'EVEN') { $this->AddPage($orient,'E', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  14962. else if ($type == 'O' || $type == 'ODD') { $this->AddPage($orient,'O', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  14963. else if ($type == 'NEXT-ODD') { $this->AddPage($orient,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  14964. else if ($type == 'NEXT-EVEN') { $this->AddPage($orient,'NEXT-EVEN', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  14965. else { $this->AddPage($orient,'', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  14966. /*-- TOC --*/
  14967. if ($tag == 'TOCPAGEBREAK') {
  14968. if ($toc_id) { $this->m_TOC[$toc_id]['TOCmark'] = $this->page; }
  14969. else { $this->TOCmark = $this->page; }
  14970. }
  14971. /*-- END TOC --*/
  14972. /*-- COLUMNS --*/
  14973. if ($save_cols) {
  14974. // Restore columns
  14975. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  14976. }
  14977. /*-- END COLUMNS --*/
  14978. if (($tag == 'FORMFEED' || $this->restoreBlockPagebreaks) && !$this->tableLevel && !$this->listlvl) {
  14979. $this->blk = $save_blk;
  14980. // Re-open block tags
  14981. $t = $this->blk[0]['tag'];
  14982. $a = $this->blk[0]['attr'];
  14983. $this->blklvl = 0;
  14984. for ($b=0; $b<=$save_blklvl;$b++) {
  14985. $tc = $t;
  14986. $ac = $a;
  14987. $t = $this->blk[$b+1]['tag'];
  14988. $a = $this->blk[$b+1]['attr'];
  14989. unset($this->blk[$b+1]);
  14990. $this->OpenTag($tc,$ac);
  14991. }
  14992. $this->spanlvl = $save_spanlvl;
  14993. $this->InlineProperties = $save_ilp;
  14994. $this->restoreInlineProperties($save_silp);
  14995. }
  14996. break;
  14997. /*-- TOC --*/
  14998. case 'TOCENTRY':
  14999. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  15000. $objattr = array();
  15001. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  15002. $objattr['type'] = 'toc';
  15003. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['toclevel'] = $attr['LEVEL']; } else { $objattr['toclevel'] = 0; }
  15004. if (isset($attr['NAME']) && $attr['NAME']) { $objattr['toc_id'] = $attr['NAME']; } else { $objattr['toc_id'] = 0; }
  15005. $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15006. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  15007. else { // *TABLES*
  15008. $this->textbuffer[] = array($e);
  15009. } // *TABLES*
  15010. }
  15011. break;
  15012. /*-- END TOC --*/
  15013. /*-- INDEX --*/
  15014. case 'INDEXENTRY':
  15015. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  15016. if (isset($attr['XREF']) && $attr['XREF']) {
  15017. $this->IndexEntry(htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES),$attr['XREF']);
  15018. break;
  15019. }
  15020. $objattr = array();
  15021. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  15022. $objattr['type'] = 'indexentry';
  15023. $e = "\xbb\xa4\xactype=indexentry,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15024. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  15025. else { // *TABLES*
  15026. $this->textbuffer[] = array($e);
  15027. } // *TABLES*
  15028. }
  15029. break;
  15030. case 'INDEXINSERT':
  15031. if (isset($attr['FONT-SIZE'])) { $reffontsize = $attr['FONT-SIZE']; } else { $reffontsize = ''; }
  15032. if (isset($attr['LINE-SPACING']) && $attr['LINE-SPACING']) { $linespacing = $attr['LINE-SPACING']; } else { $linespacing = ''; }
  15033. if (isset($attr['DIV-FONT-SIZE']) && $attr['DIV-FONT-SIZE']) { $divlettfontsize = $attr['DIV-FONT-SIZE']; } else { $divlettfontsize = ''; }
  15034. if (isset($attr['FONT']) && $attr['FONT']) { $reffont = $attr['FONT']; } else { $reffont = ''; }
  15035. if (isset($attr['DIV-FONT']) && $attr['DIV-FONT']) { $divlettfont = $attr['DIV-FONT']; } else { $divlettfont = ''; }
  15036. if (isset($attr['COLS']) && $attr['COLS']) { $cols = $attr['COLS']; } else { $cols = 1; }
  15037. if (isset($attr['OFFSET']) && $attr['OFFSET']) { $offset = $attr['OFFSET']; } else { $offset = 3; }
  15038. if (isset($attr['GAP']) && $attr['GAP']) { $gap = $attr['GAP']; } else { $gap = 5; }
  15039. if (isset($attr['USEDIVLETTERS']) && (strtoupper($attr['USEDIVLETTERS'])=='OFF' || $attr['USEDIVLETTERS']==-1 || $attr['USEDIVLETTERS']==='0')) { $usedivletters = 0; }
  15040. else { $usedivletters = 1; }
  15041. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  15042. else { $links = false; }
  15043. $this->CreateIndex($cols, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont,$divlettfont, $links);
  15044. break;
  15045. /*-- END INDEX --*/
  15046. /*-- WATERMARK --*/
  15047. case 'WATERMARKTEXT':
  15048. if (isset($attr['CONTENT']) && $attr['CONTENT']) { $txt = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); } else { $txt = ''; }
  15049. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  15050. $this->SetWatermarkText($txt, $alpha);
  15051. break;
  15052. case 'WATERMARKIMAGE':
  15053. if (isset($attr['SRC'])) { $src = $attr['SRC']; } else { $src = ''; }
  15054. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  15055. if (isset($attr['SIZE']) && $attr['SIZE']) {
  15056. $size = $attr['SIZE'];
  15057. if (strpos($size,',')) { $size = explode(',',$size); }
  15058. }
  15059. else { $size = 'D'; }
  15060. if (isset($attr['POS']) && $attr['POS']) {
  15061. $pos = $attr['POS'];
  15062. if (strpos($pos,',')) { $pos = explode(',',$pos); }
  15063. }
  15064. else { $pos = 'P'; }
  15065. $this->SetWatermarkImage($src, $alpha, $size, $pos);
  15066. break;
  15067. /*-- END WATERMARK --*/
  15068. /*-- BOOKMARKS --*/
  15069. case 'BOOKMARK':
  15070. if (isset($attr['CONTENT'])) {
  15071. $objattr = array();
  15072. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  15073. $objattr['type'] = 'bookmark';
  15074. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  15075. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15076. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  15077. else { // *TABLES*
  15078. $this->textbuffer[] = array($e);
  15079. } // *TABLES*
  15080. }
  15081. break;
  15082. /*-- END BOOKMARKS --*/
  15083. /*-- ANNOTATIONS --*/
  15084. case 'ANNOTATION':
  15085. // mPDF 5.0
  15086. //if (isset($attr['CONTENT']) && !$this->writingHTMLheader && !$this->writingHTMLfooter) { // Stops annotations in FixedPos
  15087. if (isset($attr['CONTENT'])) {
  15088. $objattr = array();
  15089. $objattr['margin_top'] = 0;
  15090. $objattr['margin_bottom'] = 0;
  15091. $objattr['margin_left'] = 0;
  15092. $objattr['margin_right'] = 0;
  15093. $objattr['width'] = 0;
  15094. $objattr['height'] = 0;
  15095. $objattr['border_top']['w'] = 0;
  15096. $objattr['border_bottom']['w'] = 0;
  15097. $objattr['border_left']['w'] = 0;
  15098. $objattr['border_right']['w'] = 0;
  15099. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  15100. $objattr['type'] = 'annot';
  15101. $objattr['POPUP'] = '';
  15102. }
  15103. else { break; }
  15104. if (isset($attr['POS-X'])) { $objattr['POS-X'] = $attr['POS-X']; } else { $objattr['POS-X'] = 0; }
  15105. if (isset($attr['POS-Y'])) { $objattr['POS-Y'] = $attr['POS-Y']; } else { $objattr['POS-Y'] = 0; }
  15106. if (isset($attr['ICON'])) { $objattr['ICON'] = $attr['ICON']; } else { $objattr['ICON'] = 'Note'; }
  15107. if (isset($attr['AUTHOR'])) { $objattr['AUTHOR'] = $attr['AUTHOR']; }
  15108. else if (isset($attr['TITLE'])) { $objattr['AUTHOR'] = $attr['TITLE']; } else { $objattr['AUTHOR'] = ''; } // mPDF 5.0.048
  15109. if (isset($attr['FILE'])) { $objattr['FILE'] = $attr['FILE']; } else { $objattr['FILE'] = ''; } // mPDF 5.0.048
  15110. if (isset($attr['SUBJECT'])) { $objattr['SUBJECT'] = $attr['SUBJECT']; } else { $objattr['SUBJECT'] = ''; }
  15111. if (isset($attr['OPACITY']) && $attr['OPACITY']>0 && $attr['OPACITY']<=1) { $objattr['OPACITY'] = $attr['OPACITY']; }
  15112. else if ($this->annotMargin) { $objattr['OPACITY'] = 1; }
  15113. else { $objattr['OPACITY'] = $this->annotOpacity; }
  15114. if (isset($attr['COLOR'])) {
  15115. $cor = $this->ConvertColor($attr['COLOR']);
  15116. if ($cor) { $objattr['COLOR'] = $cor; }
  15117. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); } // mPDF 5.0.051
  15118. }
  15119. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); } // mPDF 5.0.051
  15120. if (isset($attr['POPUP']) && !empty($attr['POPUP'])) {
  15121. $pop = preg_split('/\s+/',trim($attr['POPUP']));
  15122. if (count($pop)>1) { $objattr['POPUP'] = $pop; }
  15123. else { $objattr['POPUP'] = true; }
  15124. }
  15125. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15126. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  15127. else { // *TABLES*
  15128. $this->textbuffer[] = array($e);
  15129. } // *TABLES*
  15130. break;
  15131. /*-- END ANNOTATIONS --*/
  15132. /*-- COLUMNS --*/
  15133. case 'COLUMNS': //added custom-tag
  15134. if (isset($attr['COLUMN-COUNT']) && ($attr['COLUMN-COUNT'] || $attr['COLUMN-COUNT']==='0')) {
  15135. // Close any open block tags
  15136. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  15137. if(!empty($this->textbuffer)) { //Output previously buffered content
  15138. $this->printbuffer($this->textbuffer);
  15139. $this->textbuffer=array();
  15140. }
  15141. if (isset($attr['VALIGN']) && $attr['VALIGN']) {
  15142. if ($attr['VALIGN'] == 'J') { $valign = 'J'; }
  15143. else { $valign = $align[$attr['VALIGN']]; }
  15144. }
  15145. else { $valign = ''; }
  15146. if (isset($attr['COLUMN-GAP']) && $attr['COLUMN-GAP']) { $this->SetColumns($attr['COLUMN-COUNT'],$valign,$attr['COLUMN-GAP']); }
  15147. else { $this->SetColumns($attr['COLUMN-COUNT'],$valign); }
  15148. }
  15149. $this->ignorefollowingspaces = true;
  15150. break;
  15151. case 'COLUMN_BREAK': //custom-tag
  15152. case 'COLUMNBREAK': //custom-tag
  15153. case 'NEWCOLUMN': //custom-tag
  15154. $this->ignorefollowingspaces = true;
  15155. $this->NewColumn();
  15156. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  15157. break;
  15158. /*-- END COLUMNS --*/
  15159. case 'BDO':
  15160. // $this->biDirectional = true; // mPDF 5.0.054
  15161. break;
  15162. case 'TTZ':
  15163. $this->ttz = true;
  15164. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15165. $this->setCSS(array('FONT-FAMILY'=>'czapfdingbats','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  15166. break;
  15167. case 'TTS':
  15168. $this->tts = true;
  15169. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15170. $this->setCSS(array('FONT-FAMILY'=>'csymbol','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  15171. break;
  15172. case 'TTA':
  15173. $this->tta = true;
  15174. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15175. if (in_array($this->FontFamily,$this->mono_fonts)) {
  15176. $this->setCSS(array('FONT-FAMILY'=>'ccourier'),'INLINE');
  15177. }
  15178. else if (in_array($this->FontFamily,$this->serif_fonts)) {
  15179. $this->setCSS(array('FONT-FAMILY'=>'ctimes'),'INLINE');
  15180. }
  15181. else {
  15182. $this->setCSS(array('FONT-FAMILY'=>'chelvetica'),'INLINE');
  15183. }
  15184. break;
  15185. // INLINE PHRASES OR STYLES
  15186. case 'SUB':
  15187. case 'SUP':
  15188. case 'ACRONYM':
  15189. case 'BIG':
  15190. case 'SMALL':
  15191. case 'INS':
  15192. case 'S':
  15193. case 'STRIKE':
  15194. case 'DEL':
  15195. case 'STRONG':
  15196. case 'CITE':
  15197. case 'Q':
  15198. case 'EM':
  15199. case 'B':
  15200. case 'I':
  15201. case 'U':
  15202. case 'SAMP':
  15203. case 'CODE':
  15204. case 'KBD':
  15205. case 'TT':
  15206. case 'VAR':
  15207. case 'FONT':
  15208. case 'SPAN':
  15209. /*-- ANNOTATIONS --*/
  15210. if ($this->title2annots && isset($attr['TITLE'])) {
  15211. $objattr = array();
  15212. $objattr['margin_top'] = 0;
  15213. $objattr['margin_bottom'] = 0;
  15214. $objattr['margin_left'] = 0;
  15215. $objattr['margin_right'] = 0;
  15216. $objattr['width'] = 0;
  15217. $objattr['height'] = 0;
  15218. $objattr['border_top']['w'] = 0;
  15219. $objattr['border_bottom']['w'] = 0;
  15220. $objattr['border_left']['w'] = 0;
  15221. $objattr['border_right']['w'] = 0;
  15222. $objattr['CONTENT'] = $attr['TITLE'];
  15223. $objattr['type'] = 'annot';
  15224. $objattr['POS-X'] = 0;
  15225. $objattr['POS-Y'] = 0;
  15226. $objattr['ICON'] = 'Comment';
  15227. $objattr['AUTHOR'] = '';
  15228. $objattr['SUBJECT'] = '';
  15229. $objattr['OPACITY'] = $this->annotOpacity;
  15230. $objattr['COLOR'] = $this->ConvertColor('yellow'); // mPDF 5.0.051
  15231. $annot = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15232. }
  15233. /*-- END ANNOTATIONS --*/
  15234. if ($tag == 'SPAN') {
  15235. $this->spanlvl++;
  15236. $this->InlineProperties['SPAN'][$this->spanlvl] = $this->saveInlineProperties();
  15237. if (isset($annot)) { $this->InlineAnnots[$tag][$this->spanlvl] = $annot; } // *ANNOTATIONS*
  15238. }
  15239. else {
  15240. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15241. if (isset($annot)) { $this->InlineAnnots[$tag] = $annot; } // *ANNOTATIONS*
  15242. }
  15243. $properties = $this->MergeCSS('INLINE',$tag,$attr);
  15244. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  15245. break;
  15246. case 'A':
  15247. if (isset($attr['NAME']) and $attr['NAME'] != '') {
  15248. $e = '';
  15249. /*-- BOOKMARKS --*/
  15250. if ($this->anchor2Bookmark) {
  15251. $objattr = array();
  15252. $objattr['CONTENT'] = htmlspecialchars_decode($attr['NAME'],ENT_QUOTES);
  15253. $objattr['type'] = 'bookmark';
  15254. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  15255. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15256. }
  15257. /*-- END BOOKMARKS --*/
  15258. if($this->tableLevel) { // *TABLES*
  15259. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,'','',array(),'',false,false,$attr['NAME']); // *TABLES*
  15260. } // *TABLES*
  15261. else { // *TABLES*
  15262. $this->textbuffer[] = array($e,'','',array(),'',false,false,$attr['NAME']); //an internal link (adds a space for recognition)
  15263. } // *TABLES*
  15264. }
  15265. if (isset($attr['HREF'])) {
  15266. $this->InlineProperties['A'] = $this->saveInlineProperties();
  15267. $properties = $this->MergeCSS('',$tag,$attr);
  15268. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  15269. $this->HREF=$attr['HREF'];
  15270. }
  15271. break;
  15272. case 'BR':
  15273. // Added mPDF 3.0 Float DIV - CLEAR
  15274. if (isset($attr['STYLE'])) {
  15275. $properties = $this->readInlineCSS($attr['STYLE']);
  15276. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  15277. }
  15278. /*-- TABLES --*/
  15279. if($this->tableLevel) {
  15280. if ($this->blockjustfinished || $this->listjustfinished) {
  15281. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15282. $this->cell[$this->row][$this->col]['text'][] = "\n";
  15283. }
  15284. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15285. $this->cell[$this->row][$this->col]['text'][] = "\n";
  15286. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  15287. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  15288. }
  15289. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  15290. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  15291. }
  15292. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  15293. }
  15294. else {
  15295. /*-- END TABLES --*/
  15296. if (count($this->textbuffer)) { // mPDF 5.0
  15297. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/ $/','',$this->textbuffer[count($this->textbuffer)-1][0]);
  15298. }
  15299. $this->textbuffer[] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15300. } // *TABLES*
  15301. $this->ignorefollowingspaces = true;
  15302. $this->blockjustfinished=false;
  15303. $this->listjustfinished=false;
  15304. $this->linebreakjustfinished=true;
  15305. break;
  15306. // *********** BLOCKS ********************
  15307. //NB $outerblocktags = array('DIV','FORM','CENTER','DL');
  15308. //NB $innerblocktags = array('P','BLOCKQUOTE','ADDRESS','PRE',''H1','H2','H3','H4','H5','H6','DT','DD');
  15309. case 'PRE':
  15310. $this->ispre=true; // ADDED - Prevents left trim of textbuffer in printbuffer()
  15311. case 'DIV':
  15312. case 'FORM':
  15313. case 'CENTER':
  15314. case 'BLOCKQUOTE':
  15315. case 'ADDRESS':
  15316. case 'P':
  15317. case 'H1':
  15318. case 'H2':
  15319. case 'H3':
  15320. case 'H4':
  15321. case 'H5':
  15322. case 'H6':
  15323. case 'DL':
  15324. case 'DT':
  15325. case 'DD':
  15326. $p = $this->PreviewBlockCSS($tag,$attr);
  15327. if(isset($p['DISPLAY']) && strtolower($p['DISPLAY'])=='none') {
  15328. $this->blklvl++;
  15329. $this->blk[$this->blklvl]['hide'] = true;
  15330. return;
  15331. }
  15332. /*-- CSS-POSITION --*/
  15333. if ((isset($p['POSITION']) && (strtolower($p['POSITION'])=='fixed' || strtolower($p['POSITION'])=='absolute')) && $this->blklvl==0) {
  15334. if ($this->inFixedPosBlock) {
  15335. $this->Error("Cannot nest block with position:fixed or position:absolute");
  15336. }
  15337. $this->inFixedPosBlock = true;
  15338. return;
  15339. }
  15340. /*-- END CSS-POSITION --*/
  15341. // Start Block
  15342. $this->ignorefollowingspaces = true;
  15343. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  15344. else { $lastbottommargin = 0; }
  15345. $this->lastblockbottommargin = 0;
  15346. $this->blockjustfinished=false;
  15347. /*-- LISTS --*/
  15348. if ($this->listlvl>0) { return; }
  15349. /*-- END LISTS --*/
  15350. $this->InlineProperties = array();
  15351. $this->spanlvl = 0;
  15352. $this->listjustfinished=false;
  15353. $this->divbegin=true;
  15354. $this->linebreakjustfinished=false;
  15355. /*-- TABLES --*/
  15356. if ($this->tableLevel) {
  15357. // If already something on the line
  15358. if ($this->cell[$this->row][$this->col]['s'] > 0 && !$this->nestedtablejustfinished ) {
  15359. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15360. $this->cell[$this->row][$this->col]['text'][] = "\n";
  15361. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  15362. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  15363. }
  15364. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  15365. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  15366. }
  15367. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  15368. }
  15369. // Cannot set block properties inside table - use Bold to indicate h1-h6
  15370. if ($tag == 'CENTER' && $this->tdbegin) { $this->cell[$this->row][$this->col]['a'] = $align['center']; }
  15371. $this->InlineProperties['BLOCKINTABLE'] = $this->saveInlineProperties();
  15372. $properties = $this->MergeCSS('',$tag,$attr);
  15373. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  15374. break;
  15375. }
  15376. /*-- END TABLES --*/
  15377. if ($tag == 'P' || $tag == 'DT' || $tag == 'DD') { $this->lastoptionaltag = $tag; } // Save current HTML specified optional endtag
  15378. else { $this->lastoptionaltag = ''; }
  15379. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  15380. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  15381. $this->printbuffer($this->textbuffer,$blockstate);
  15382. $this->textbuffer=array();
  15383. $this->blklvl++;
  15384. $currblk =& $this->blk[$this->blklvl];
  15385. $this->initialiseBlock($currblk);
  15386. $prevblk =& $this->blk[$this->blklvl-1];
  15387. $currblk['tag'] = $tag;
  15388. $currblk['attr'] = $attr;
  15389. $this->Reset();
  15390. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  15391. $pagesel = '';
  15392. /*-- CSS-PAGE --*/
  15393. if (isset($properties['PAGE'])) { $pagesel = $properties['PAGE']; }
  15394. /*-- END CSS-PAGE --*/
  15395. // If page-box has changed AND/OR PAGE-BREAK-BEFORE
  15396. $save_cols = false;
  15397. if (($pagesel && $pagesel != $this->page_box['current']) || (isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  15398. if ($this->blklvl>1) {
  15399. // Close any open block tags
  15400. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  15401. // Output any text left in buffer
  15402. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  15403. }
  15404. /*-- COLUMNS --*/
  15405. if ($this->ColActive) {
  15406. $save_cols = true;
  15407. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  15408. $this->SetColumns(0);
  15409. }
  15410. /*-- END COLUMNS --*/
  15411. // Must Add new page if changed page properties
  15412. if (isset($properties['PAGE-BREAK-BEFORE'])) {
  15413. if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  15414. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  15415. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'ALWAYS') { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  15416. else if ($this->page_box['current'] != $pagesel) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } // *CSS-PAGE*
  15417. }
  15418. /*-- CSS-PAGE --*/
  15419. else if ($pagesel != $this->page_box['current']) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  15420. /*-- END CSS-PAGE --*/
  15421. // if using htmlheaders, the headers need to be rewritten when new page
  15422. // done by calling WriteHTML() within resethtmlheaders
  15423. // so block is reset to 0 - now we need to resurrect it
  15424. // As in WriteHTML() initialising
  15425. $this->blklvl = 0;
  15426. $this->lastblocklevelchange = 0;
  15427. $this->blk = array();
  15428. $this->initialiseBlock($this->blk[0]);
  15429. $this->blk[0]['width'] =& $this->pgwidth;
  15430. $this->blk[0]['inner_width'] =& $this->pgwidth;
  15431. $this->blk[0]['blockContext'] = $this->blockContext;
  15432. $properties = $this->MergeCSS('BLOCK','BODY','');
  15433. $this->setCSS($properties,'','BODY');
  15434. $this->blklvl++;
  15435. $currblk =& $this->blk[$this->blklvl];
  15436. $prevblk =& $this->blk[$this->blklvl-1];
  15437. $this->initialiseBlock($currblk);
  15438. $currblk['tag'] = $tag;
  15439. $currblk['attr'] = $attr;
  15440. $this->Reset();
  15441. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  15442. /*-- COLUMNS --*/
  15443. if ($save_cols) {
  15444. // Restore columns
  15445. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  15446. }
  15447. /*-- END COLUMNS --*/
  15448. }
  15449. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE']) == 'AVOID' && !$this->ColActive && !$this->keep_block_together) {
  15450. $currblk['keep_block_together'] = 1;
  15451. $this->kt_y00 = $this->y; // mPDF 5.0
  15452. $this->kt_p00 = $this->page; // mPDF 5.0
  15453. $this->keep_block_together = 1;
  15454. $this->divbuffer = array();
  15455. $this->ktLinks = array();
  15456. $this->ktAnnots = array();
  15457. $this->ktBlock = array();
  15458. $this->ktReference = array();
  15459. $this->ktBMoutlines = array();
  15460. $this->_kttoc = array();
  15461. }
  15462. // mPDF 5.0.010
  15463. if ($lastbottommargin && $properties['MARGIN-TOP'] && !$properties['FLOAT']) { $currblk['lastbottommargin'] = $lastbottommargin; }
  15464. $this->setCSS($properties,'BLOCK',$tag); //name(id/class/style) found in the CSS array!
  15465. $currblk['InlineProperties'] = $this->saveInlineProperties();
  15466. // mPDF 5.0.054
  15467. if(isset($attr['DIR']) && $attr['DIR']) { $currblk['direction'] = strtolower($attr['DIR']); }
  15468. if(isset($attr['ALIGN']) && $attr['ALIGN']) { $currblk['block-align'] = $align[strtolower($attr['ALIGN'])]; }
  15469. if (isset($properties['HEIGHT'])) {
  15470. $currblk['css_set_height'] = $this->ConvertSize($properties['HEIGHT'],($this->h - $this->tMargin - $this->bMargin),$this->FontSize,false);
  15471. // mPDF 5.0.028
  15472. if (($currblk['css_set_height'] + $this->y) > $this->PageBreakTrigger && $this->y > $this->tMargin+5 && $currblk['css_set_height'] < ($this->h - ($this->tMargin + $this->bMargin))) { $this->AddPage($this->CurOrientation); }
  15473. }
  15474. else { $currblk['css_set_height'] = false; }
  15475. // Added mPDF 3.0 Float DIV
  15476. if (isset($prevblk['blockContext'])) { $currblk['blockContext'] = $prevblk['blockContext'] ; } // *CSS-FLOAT*
  15477. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']), $this->blklvl-1); } // *CSS-FLOAT*
  15478. $container_w = $prevblk['inner_width'];
  15479. $bdr = $currblk['border_right']['w'];
  15480. $bdl = $currblk['border_left']['w'];
  15481. $pdr = $currblk['padding_right'];
  15482. $pdl = $currblk['padding_left'];
  15483. if (isset($currblk['css_set_width'])) { $setwidth = $currblk['css_set_width']; }
  15484. else { $setwidth = 0; }
  15485. /*-- CSS-FLOAT --*/
  15486. if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'RIGHT' && !$this->ColActive) {
  15487. // Cancel Keep-Block-together
  15488. $currblk['keep_block_together'] = false;
  15489. $this->kt_y00 = ''; // mPDF 5.0
  15490. $this->keep_block_together = 0;
  15491. $this->blockContext++;
  15492. $currblk['blockContext'] = $this->blockContext;
  15493. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  15494. // DIV is too narrow for text to fit!
  15495. $maxw = $container_w - $l_width - $r_width;
  15496. if (($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) < $this->GetStringWidth('WW')) {
  15497. // Too narrow to fit - try to move down past L or R float
  15498. if ($l_max < $r_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > $this->GetStringWidth('WW')) {
  15499. $this->ClearFloats('LEFT', $this->blklvl-1);
  15500. }
  15501. else if ($r_max < $l_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > $this->GetStringWidth('WW')) {
  15502. $this->ClearFloats('RIGHT', $this->blklvl-1);
  15503. }
  15504. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  15505. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  15506. }
  15507. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  15508. $currblk['float'] = 'R';
  15509. $currblk['float_start_y'] = $this->y;
  15510. if ($currblk['css_set_width']) {
  15511. $currblk['margin_left'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  15512. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  15513. }
  15514. else {
  15515. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  15516. // and do borders and backgrounds - For now - just set to maximum width left
  15517. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  15518. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  15519. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  15520. }
  15521. }
  15522. else if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'LEFT' && !$this->ColActive) {
  15523. // Cancel Keep-Block-together
  15524. $currblk['keep_block_together'] = false;
  15525. $this->kt_y00 = ''; // mPDF 5.0
  15526. $this->keep_block_together = 0;
  15527. $this->blockContext++;
  15528. $currblk['blockContext'] = $this->blockContext;
  15529. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  15530. // DIV is too narrow for text to fit!
  15531. $maxw = $container_w - $l_width - $r_width;
  15532. if (($setwidth + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < $this->GetStringWidth('WW')) {
  15533. // Too narrow to fit - try to move down past L or R float
  15534. if ($l_max < $r_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > $this->GetStringWidth('WW')) {
  15535. $this->ClearFloats('LEFT', $this->blklvl-1);
  15536. }
  15537. else if ($r_max < $l_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > $this->GetStringWidth('WW')) {
  15538. $this->ClearFloats('RIGHT', $this->blklvl-1);
  15539. }
  15540. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  15541. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  15542. }
  15543. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  15544. $currblk['float'] = 'L';
  15545. $currblk['float_start_y'] = $this->y;
  15546. if ($setwidth) {
  15547. $currblk['margin_right'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  15548. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  15549. }
  15550. else {
  15551. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  15552. // and do borders and backgrounds - For now - just set to maximum width left
  15553. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  15554. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  15555. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  15556. }
  15557. }
  15558. else {
  15559. // Don't allow overlap - if floats present - adjust padding to avoid overlap with Floats
  15560. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  15561. $maxw = $container_w - $l_width - $r_width;
  15562. if (($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < $this->GetStringWidth('WW')) {
  15563. // Too narrow to fit - try to move down past L or R float
  15564. if ($l_max < $r_max && ($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) > $this->GetStringWidth('WW')) {
  15565. $this->ClearFloats('LEFT', $this->blklvl-1);
  15566. }
  15567. else if ($r_max < $l_max && ($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) > $this->GetStringWidth('WW')) {
  15568. $this->ClearFloats('RIGHT', $this->blklvl-1);
  15569. }
  15570. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  15571. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  15572. }
  15573. if ($r_exists) { $currblk['padding_right'] = max(($r_width-$currblk['margin_right']-$bdr), $pdr); }
  15574. if ($l_exists) { $currblk['padding_left'] = max(($l_width-$currblk['margin_left']-$bdl), $pdl); }
  15575. }
  15576. /*-- END CSS-FLOAT --*/
  15577. /*-- BORDER-RADIUS --*/
  15578. // Automatically increase padding if required for border-radius
  15579. if ($this->autoPadding && !$this->ColActive && !$this->keep_block_together) {
  15580. if ($currblk['border_radius_TL_H']>$currblk['padding_left'] && $currblk['border_radius_TL_V']>$currblk['padding_top']) {
  15581. if ($currblk['border_radius_TL_H']>$currblk['border_radius_TL_V']) {
  15582. $this->_borderPadding($currblk['border_radius_TL_H'],$currblk['border_radius_TL_V'], $currblk['padding_left'], $currblk['padding_top']);
  15583. }
  15584. else {
  15585. $this->_borderPadding($currblk['border_radius_TL_V'],$currblk['border_radius_TL_H'], $currblk['padding_top'], $currblk['padding_left']);
  15586. }
  15587. }
  15588. if ($currblk['border_radius_TR_H']>$currblk['padding_right'] && $currblk['border_radius_TR_V']>$currblk['padding_top']) {
  15589. if ($currblk['border_radius_TR_H']>$currblk['border_radius_TR_V']) {
  15590. $this->_borderPadding($currblk['border_radius_TR_H'],$currblk['border_radius_TR_V'], $currblk['padding_right'], $currblk['padding_top']);
  15591. }
  15592. else {
  15593. $this->_borderPadding($currblk['border_radius_TR_V'],$currblk['border_radius_TR_H'], $currblk['padding_top'], $currblk['padding_right']);
  15594. }
  15595. }
  15596. if ($currblk['border_radius_BL_H']>$currblk['padding_left'] && $currblk['border_radius_BL_V']>$currblk['padding_bottom']) {
  15597. if ($currblk['border_radius_BL_H']>$currblk['border_radius_BL_V']) {
  15598. $this->_borderPadding($currblk['border_radius_BL_H'],$currblk['border_radius_BL_V'], $currblk['padding_left'], $currblk['padding_bottom']);
  15599. }
  15600. else {
  15601. $this->_borderPadding($currblk['border_radius_BL_V'],$currblk['border_radius_BL_H'], $currblk['padding_bottom'], $currblk['padding_left']);
  15602. }
  15603. }
  15604. if ($currblk['border_radius_BR_H']>$currblk['padding_right'] && $currblk['border_radius_BR_V']>$currblk['padding_bottom']) {
  15605. if ($currblk['border_radius_BR_H']>$currblk['border_radius_BR_V']) {
  15606. $this->_borderPadding($currblk['border_radius_BR_H'],$currblk['border_radius_BR_V'], $currblk['padding_right'], $currblk['padding_bottom']);
  15607. }
  15608. else {
  15609. $this->_borderPadding($currblk['border_radius_BR_V'],$currblk['border_radius_BR_H'], $currblk['padding_bottom'], $currblk['padding_right']);
  15610. }
  15611. }
  15612. }
  15613. /*-- END BORDER-RADIUS --*/
  15614. // Hanging indent - if negative indent: ensure padding is >= indent
  15615. // mPDF 5.0.052
  15616. if(!isset($currblk['text_indent'])) { $currblk['text_indent'] = null; }
  15617. if(!isset($currblk['inner_width'])) { $currblk['inner_width'] = null; }
  15618. $cbti = $this->ConvertSize($currblk['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15619. if ($cbti < 0) {
  15620. $hangind = -($cbti);
  15621. // mPDF 5.0.054
  15622. if ($currblk['direction'] == 'rtl') { // *RTL*
  15623. $currblk['padding_right'] = max($currblk['padding_right'],$hangind); // *RTL*
  15624. } // *RTL*
  15625. else { // *RTL*
  15626. $currblk['padding_left'] = max($currblk['padding_left'],$hangind);
  15627. } // *RTL*
  15628. }
  15629. if (isset($currblk['css_set_width'])) {
  15630. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  15631. // Try to reduce margins to accomodate - if still too wide, set margin-right/left=0 (reduces width)
  15632. $anyextra = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  15633. if ($anyextra>0) {
  15634. $currblk['margin_left'] = $currblk['margin_right'] = $anyextra /2;
  15635. }
  15636. else {
  15637. $currblk['margin_left'] = $currblk['margin_right'] = 0;
  15638. }
  15639. }
  15640. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  15641. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  15642. $currblk['margin_left'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_right']);
  15643. if ($currblk['margin_left'] < 0) {
  15644. $currblk['margin_left'] = 0;
  15645. }
  15646. }
  15647. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  15648. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  15649. $currblk['margin_right'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_left']);
  15650. if ($currblk['margin_right'] < 0) {
  15651. $currblk['margin_right'] = 0;
  15652. }
  15653. }
  15654. else {
  15655. // mPDF 5.0.054
  15656. if ($currblk['direction'] == 'rtl') { // *RTL*
  15657. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  15658. $currblk['margin_left'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_right']); // *RTL*
  15659. if ($currblk['margin_left'] < 0) { // *RTL*
  15660. $currblk['margin_left'] = 0; // *RTL*
  15661. } // *RTL*
  15662. } // *RTL*
  15663. else { // *RTL*
  15664. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  15665. $currblk['margin_right'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_left']);
  15666. if ($currblk['margin_right'] < 0) {
  15667. $currblk['margin_right'] = 0;
  15668. }
  15669. } // *RTL*
  15670. }
  15671. }
  15672. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  15673. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  15674. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  15675. $currblk['inner_width'] = $currblk['width'] - ($currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  15676. // Check DIV is not now too narrow to fit text
  15677. $mw = $this->GetStringWidth('WW');
  15678. if ($currblk['inner_width'] < $mw) {
  15679. $currblk['padding_left'] = 0;
  15680. $currblk['padding_right'] = 0;
  15681. $currblk['border_left']['w'] = 0.2;
  15682. $currblk['border_right']['w'] = 0.2;
  15683. $currblk['margin_left'] = 0;
  15684. $currblk['margin_right'] = 0;
  15685. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  15686. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  15687. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  15688. $currblk['inner_width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  15689. // if ($currblk['inner_width'] < $mw) { $this->Error("DIV is too narrow for text to fit!"); }
  15690. }
  15691. $this->x = $this->lMargin + $currblk['outer_left_margin'];
  15692. /*-- BACKGROUNDS --*/
  15693. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive && !$this->keep_block_together) {
  15694. // mPDF 5.0.023
  15695. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  15696. if ($ret) { $currblk['background-image'] = $ret; }
  15697. }
  15698. /*-- END BACKGROUNDS --*/
  15699. /*-- TABLES --*/
  15700. if ($this->use_kwt && isset($attr['KEEP-WITH-TABLE']) && !$this->ColActive && !$this->keep_block_together) {
  15701. $this->kwt = true;
  15702. $this->kwt_y0 = $this->y;
  15703. $this->kwt_x0 = $this->x;
  15704. $this->kwt_height = 0;
  15705. $this->kwt_buffer = array();
  15706. $this->kwt_Links = array();
  15707. $this->kwt_Annots = array();
  15708. $this->kwt_moved = false;
  15709. $this->kwt_saved = false;
  15710. $this->kwt_Reference = array();
  15711. $this->kwt_BMoutlines = array();
  15712. $this->kwt_toc = array();
  15713. }
  15714. else {
  15715. /*-- END TABLES --*/
  15716. $this->kwt = false;
  15717. } // *TABLES*
  15718. //Save x,y coords in case we need to print borders...
  15719. $currblk['y0'] = $this->y;
  15720. $currblk['x0'] = $this->x;
  15721. $currblk['startpage'] = $this->page;
  15722. $this->oldy = $this->y;
  15723. $this->lastblocklevelchange = 1 ;
  15724. break;
  15725. case 'HR':
  15726. // Added mPDF 3.0 Float DIV - CLEAR
  15727. if (isset($attr['STYLE'])) {
  15728. $properties = $this->readInlineCSS($attr['STYLE']);
  15729. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  15730. }
  15731. $this->ignorefollowingspaces = true;
  15732. $objattr = array();
  15733. $objattr['margin_top'] = 0;
  15734. $objattr['margin_bottom'] = 0;
  15735. $objattr['margin_left'] = 0;
  15736. $objattr['margin_right'] = 0;
  15737. $objattr['width'] = 0;
  15738. $objattr['height'] = 0;
  15739. $objattr['border_top']['w'] = 0;
  15740. $objattr['border_bottom']['w'] = 0;
  15741. $objattr['border_left']['w'] = 0;
  15742. $objattr['border_right']['w'] = 0;
  15743. $properties = $this->MergeCSS('',$tag,$attr);
  15744. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15745. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15746. if (isset($properties['WIDTH'])) { $objattr['width'] = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); }
  15747. if (isset($properties['TEXT-ALIGN'])) { $objattr['align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15748. if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  15749. $objattr['align'] = 'R';
  15750. }
  15751. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  15752. $objattr['align'] = 'L';
  15753. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto' && isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  15754. $objattr['align'] = 'C';
  15755. }
  15756. }
  15757. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15758. if (isset($properties['HEIGHT'])) { $objattr['linewidth'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15759. if(isset($attr['WIDTH']) && $attr['WIDTH'] != '') $objattr['width'] = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  15760. if(isset($attr['ALIGN']) && $attr['ALIGN'] != '') $objattr['align'] = $align[strtolower($attr['ALIGN'])];
  15761. if(isset($attr['COLOR']) && $attr['COLOR'] != '') $objattr['color'] = $this->ConvertColor($attr['COLOR']);
  15762. /*-- TABLES --*/
  15763. if ($this->tableLevel) {
  15764. $objattr['W-PERCENT'] = 100;
  15765. if (isset($properties['WIDTH']) && stristr($properties['WIDTH'],'%')) {
  15766. $properties['WIDTH'] += 0; //make "90%" become simply "90"
  15767. $objattr['W-PERCENT'] = $properties['WIDTH'];
  15768. }
  15769. if (isset($attr['WIDTH']) && stristr($attr['WIDTH'],'%')) {
  15770. $attr['WIDTH'] += 0; //make "90%" become simply "90"
  15771. $objattr['W-PERCENT'] = $attr['WIDTH'];
  15772. }
  15773. }
  15774. /*-- END TABLES --*/
  15775. $objattr['type'] = 'hr';
  15776. $objattr['height'] = $objattr['linewidth'] + $objattr['margin_top'] + $objattr['margin_bottom'];
  15777. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15778. // Clear properties - tidy up
  15779. $properties = array();
  15780. /*-- TABLES --*/
  15781. // Output it to buffers
  15782. if ($this->tableLevel) {
  15783. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  15784. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  15785. }
  15786. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  15787. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  15788. }
  15789. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  15790. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15791. }
  15792. else {
  15793. /*-- END TABLES --*/
  15794. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15795. } // *TABLES*
  15796. break;
  15797. /*-- BARCODES --*/
  15798. case 'BARCODE':
  15799. if(isset($attr['CODE']) && $attr['CODE']) {
  15800. $objattr = array();
  15801. $objattr['margin_top'] = 0;
  15802. $objattr['margin_bottom'] = 0;
  15803. $objattr['margin_left'] = 0;
  15804. $objattr['margin_right'] = 0;
  15805. $objattr['padding_top'] = 0;
  15806. $objattr['padding_bottom'] = 0;
  15807. $objattr['padding_left'] = 0;
  15808. $objattr['padding_right'] = 0;
  15809. $objattr['width'] = 0;
  15810. $objattr['height'] = 0;
  15811. $objattr['border_top']['w'] = 0;
  15812. $objattr['border_bottom']['w'] = 0;
  15813. $objattr['border_left']['w'] = 0;
  15814. $objattr['border_right']['w'] = 0;
  15815. $objattr['code'] = $attr['CODE'];
  15816. if(isset($attr['TYPE'])) {
  15817. $objattr['btype'] = trim(strtoupper($attr['TYPE']));
  15818. }
  15819. else { $objattr['btype'] = 'EAN13'; } // default
  15820. if (preg_match('/^(EAN13|ISBN|ISSN|EAN8|UPCA|UPCE)P([25])$/',$objattr['btype'],$m)) {
  15821. $objattr['btype'] = $m[1];
  15822. $objattr['bsupp'] = $m[2];
  15823. if (preg_match('/^(\S+)\s+(.*)$/',$objattr['code'],$mm)) {
  15824. $objattr['code'] = $mm[1];
  15825. $objattr['bsupp_code'] = $mm[2];
  15826. }
  15827. }
  15828. else { $objattr['bsupp'] = 0; }
  15829. if(isset($attr['TEXT']) && $attr['TEXT']==1) { $objattr['showtext'] = 1; }
  15830. else { $objattr['showtext'] = 0; }
  15831. if(isset($attr['SIZE']) && $attr['SIZE']>0) { $objattr['bsize'] = $attr['SIZE']; }
  15832. else { $objattr['bsize'] = 1; }
  15833. if(isset($attr['HEIGHT']) && $attr['HEIGHT']>0) { $objattr['bheight'] = $attr['HEIGHT']; }
  15834. else { $objattr['bheight'] = 1; }
  15835. if(isset($attr['PR']) && $attr['PR']>0) { $objattr['pr_ratio'] = $attr['PR']; }
  15836. else { $objattr['pr_ratio'] = ''; }
  15837. $properties = $this->MergeCSS('',$tag,$attr);
  15838. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15839. return;
  15840. }
  15841. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15842. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15843. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15844. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15845. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15846. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15847. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15848. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15849. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15850. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15851. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15852. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15853. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15854. if (isset($properties['COLOR']) && $properties['COLOR'] != '') { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15855. else { $objattr['color'] = false; }
  15856. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15857. else { $objattr['bgcolor'] = false; }
  15858. if (!class_exists('PDFBarcode', false)) {
  15859. include(_MPDF_PATH.'classes/barcode.php');
  15860. }
  15861. $this->barcode = new PDFBarcode(); // mPDF 5.0.012
  15862. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  15863. $code = preg_replace('/\-/','',$objattr['code']);
  15864. if ($objattr['btype'] == 'ISSN' || $objattr['btype'] == 'ISBN') {
  15865. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  15866. }
  15867. else { $arrcode = $this->barcode->getBarcodeArray($code, $objattr['btype'] ); }
  15868. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  15869. if ($objattr['bsupp'] == 2 || $objattr['bsupp'] == 5) { // EAN-2 or -5 Supplement
  15870. $supparrcode = $this->barcode->getBarcodeArray($objattr['bsupp_code'], 'EAN'.$objattr['bsupp'] );
  15871. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR'] + $supparrcode["maxw"] + $supparrcode['sepM']) * $arrcode['nom-X'] * $objattr['bsize'];
  15872. }
  15873. else {
  15874. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  15875. }
  15876. $h = $arrcode['nom-H'] * $objattr['bsize'] * $objattr['bheight'];
  15877. // Add height for ISBN string + margin from top of bars
  15878. if (($objattr['showtext'] && $objattr['btype'] == 'EAN13') || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN') {
  15879. $tisbnm = 1.5 * $objattr['bsize']; // Top margin between TOP TEXT (isbn - if shown) & bars
  15880. $isbn_fontsize = 2.1 * $objattr['bsize'];
  15881. $h += $isbn_fontsize + $tisbnm ;
  15882. }
  15883. }
  15884. // mPDF 5.0 QR-code
  15885. else if ($objattr['btype'] == 'QR') {
  15886. $w = $h = $objattr['bsize']*25; // Factor of 25mm (default)
  15887. $objattr['errorlevel'] = 'L';
  15888. if (isset($attr['ERROR'])) { $objattr['errorlevel'] = $attr['ERROR']; }
  15889. }
  15890. else if ($objattr['btype'] == 'IMB' || $objattr['btype'] == 'RM4SCC' || $objattr['btype'] == 'KIX' || $objattr['btype'] == 'POSTNET' || $objattr['btype'] == 'PLANET') {
  15891. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'] );
  15892. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  15893. $w = ($arrcode["maxw"] * $arrcode['nom-X'] * $objattr['bsize']) + $arrcode['quietL'] + $arrcode['quietR'];
  15894. $h = ($arrcode['nom-H'] * $objattr['bsize']) + (2*$arrcode['quietTB']);
  15895. }
  15896. else if (in_array($objattr['btype'], array('C128A','C128B','C128C','EAN128A','EAN128B','EAN128C','C39','C39+','C39E','C39E+','S25','S25+','I25','I25+','I25B','I25B+','C93','MSI','MSI+','CODABAR','CODE11'))) {
  15897. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'], $objattr['pr_ratio'] );
  15898. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  15899. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  15900. $h = ((2*$arrcode['lightTB'] * $arrcode['nom-X']) + $arrcode['nom-H']) * $objattr['bsize'] * $objattr['bheight'];
  15901. }
  15902. else { break; }
  15903. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15904. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15905. $objattr['type'] = 'barcode';
  15906. $objattr['height'] = $h + $extraheight;
  15907. $objattr['width'] = $w + $extrawidth;
  15908. $objattr['barcode_height'] = $h;
  15909. $objattr['barcode_width'] = $w;
  15910. /*-- CSS-IMAGE-FLOAT --*/
  15911. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  15912. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  15913. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  15914. }
  15915. }
  15916. /*-- END CSS-IMAGE-FLOAT --*/
  15917. $e = "\xbb\xa4\xactype=barcode,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15918. // Clear properties - tidy up
  15919. $properties = array();
  15920. /*-- TABLES --*/
  15921. // Output it to buffers
  15922. if ($this->tableLevel) {
  15923. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15924. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15925. }
  15926. else {
  15927. /*-- END TABLES --*/
  15928. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  15929. } // *TABLES*
  15930. }
  15931. break;
  15932. /*-- END BARCODES --*/
  15933. // *********** FORM ELEMENTS ********************
  15934. /*-- FORMS --*/
  15935. case 'SELECT':
  15936. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  15937. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15938. $properties = $this->MergeCSS('',$tag,$attr);
  15939. if (isset($properties['FONT-FAMILY'])) {
  15940. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15941. }
  15942. if (isset($properties['FONT-SIZE'])) {
  15943. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  15944. $this->SetFontSize($mmsize*$this->k,false);
  15945. }
  15946. if (isset($properties['COLOR'])) { $this->selectoption['COLOR'] = $this->ConvertColor($properties['COLOR']); }
  15947. $this->specialcontent = "type=select";
  15948. if(isset($attr['DISABLED'])) { $this->selectoption['DISABLED'] = $attr['DISABLED']; }
  15949. if(isset($attr['TITLE'])) { $this->selectoption['TITLE'] = $attr['TITLE']; }
  15950. if(isset($attr['MULTIPLE'])) { $this->selectoption['MULTIPLE'] = $attr['MULTIPLE']; }
  15951. if(isset($attr['SIZE']) && $attr['SIZE']>1) { $this->selectoption['SIZE'] = $attr['SIZE']; }
  15952. $properties = array();
  15953. break;
  15954. case 'OPTION':
  15955. $this->lastoptionaltag = 'OPTION'; // Save current HTML specified optional endtag
  15956. $this->selectoption['ACTIVE'] = true;
  15957. $this->selectoption['currentSEL'] = false;
  15958. if (empty($this->selectoption)) {
  15959. $this->selectoption['MAXWIDTH'] = '';
  15960. $this->selectoption['SELECTED'] = '';
  15961. }
  15962. if (isset($attr['SELECTED'])) {
  15963. $this->selectoption['SELECTED'] = '';
  15964. $this->selectoption['currentSEL'] = true;
  15965. }
  15966. // mPDD 1.4 Active Forms
  15967. $this->selectoption['currentVAL'] = $attr['VALUE'];
  15968. break;
  15969. case 'TEXTAREA':
  15970. $objattr = array();
  15971. $objattr['margin_top'] = 0;
  15972. $objattr['margin_bottom'] = 0;
  15973. $objattr['margin_left'] = 0;
  15974. $objattr['margin_right'] = 0;
  15975. $objattr['width'] = 0;
  15976. $objattr['height'] = 0;
  15977. $objattr['border_top']['w'] = 0;
  15978. $objattr['border_bottom']['w'] = 0;
  15979. $objattr['border_left']['w'] = 0;
  15980. $objattr['border_right']['w'] = 0;
  15981. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  15982. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  15983. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  15984. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15985. $properties = $this->MergeCSS('',$tag,$attr);
  15986. if (isset($properties['FONT-FAMILY'])) {
  15987. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  15988. }
  15989. if (isset($properties['FONT-SIZE'])) {
  15990. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  15991. $this->SetFontSize($mmsize*$this->k,false);
  15992. }
  15993. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15994. $objattr['fontfamily'] = $this->FontFamily;
  15995. $objattr['fontsize'] = $this->FontSizePt;
  15996. $this->SetLineHeight('',$this->textarea_lineheight);
  15997. $formLineHeight = $this->lineheight;
  15998. $w = 0;
  15999. $h = 0;
  16000. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16001. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16002. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16003. $colsize = 20; //HTML default value
  16004. $rowsize = 2; //HTML default value
  16005. if (isset($attr['COLS'])) $colsize = intval($attr['COLS']);
  16006. if (isset($attr['ROWS'])) $rowsize = intval($attr['ROWS']);
  16007. $charsize = $this->GetStringWidth('w');
  16008. if ($w) { $colsize = round(($w-($this->form_element_spacing['textarea']['outer']['h']*2)-($this->form_element_spacing['textarea']['inner']['h']*2))/$charsize); }
  16009. if ($h) { $rowsize = round(($h-($this->form_element_spacing['textarea']['outer']['v']*2)-($this->form_element_spacing['textarea']['inner']['v']*2))/$formLineHeight); }
  16010. $objattr['type'] = 'textarea';
  16011. $objattr['width'] = ($colsize * $charsize) + ($this->form_element_spacing['textarea']['outer']['h']*2)+($this->form_element_spacing['textarea']['inner']['h']*2);
  16012. $objattr['height'] = ($rowsize * $formLineHeight) + ($this->form_element_spacing['textarea']['outer']['v']*2)+($this->form_element_spacing['textarea']['inner']['v']*2);
  16013. $objattr['rows'] = $rowsize;
  16014. $objattr['cols'] = $colsize;
  16015. $this->specialcontent = serialize($objattr);
  16016. if ($this->tableLevel) { // *TABLES*
  16017. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  16018. } // *TABLES*
  16019. // Clear properties - tidy up
  16020. $properties = array();
  16021. break;
  16022. // *********** FORM - INPUT ********************
  16023. case 'INPUT':
  16024. if (!isset($attr['TYPE'])) $attr['TYPE'] == 'TEXT';
  16025. $objattr = array();
  16026. $objattr['margin_top'] = 0;
  16027. $objattr['margin_bottom'] = 0;
  16028. $objattr['margin_left'] = 0;
  16029. $objattr['margin_right'] = 0;
  16030. $objattr['width'] = 0;
  16031. $objattr['height'] = 0;
  16032. $objattr['border_top']['w'] = 0;
  16033. $objattr['border_bottom']['w'] = 0;
  16034. $objattr['border_left']['w'] = 0;
  16035. $objattr['border_right']['w'] = 0;
  16036. $objattr['type'] = 'input';
  16037. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  16038. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  16039. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  16040. else if(isset($attr['ALT'])) { $objattr['title'] = $attr['ALT']; }
  16041. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  16042. $properties = $this->MergeCSS('',$tag,$attr);
  16043. $objattr['vertical-align'] = '';
  16044. if (isset($properties['FONT-FAMILY'])) {
  16045. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  16046. }
  16047. if (isset($properties['FONT-SIZE'])) {
  16048. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/$this->k));
  16049. $this->SetFontSize($mmsize*$this->k,false);
  16050. }
  16051. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  16052. $objattr['fontfamily'] = $this->FontFamily;
  16053. $objattr['fontsize'] = $this->FontSizePt;
  16054. $type = '';
  16055. $texto='';
  16056. $height = $this->FontSize;
  16057. $width = 0;
  16058. $spacesize = $this->GetStringWidth(' ');
  16059. $w = 0;
  16060. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  16061. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16062. switch(strtoupper($attr['TYPE'])){
  16063. case 'HIDDEN':
  16064. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16065. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16066. unset($this->InlineProperties[$tag]);
  16067. break 2;
  16068. case 'CHECKBOX': //Draw Checkbox
  16069. $type = 'CHECKBOX';
  16070. if (isset($attr['VALUE'])) $objattr['value'] = $attr['VALUE'];
  16071. if (isset($attr['CHECKED'])) { $objattr['checked'] = true; }
  16072. else { $objattr['checked'] = false; }
  16073. $width = $this->FontSize;
  16074. $height = $this->FontSize;
  16075. break;
  16076. case 'RADIO': //Draw Radio button
  16077. $type = 'RADIO';
  16078. if (isset($attr['CHECKED'])) $objattr['checked'] = true;
  16079. $width = $this->FontSize;
  16080. $height = $this->FontSize;
  16081. break;
  16082. /*-- IMAGES-CORE --*/
  16083. case 'IMAGE': // Draw an Image button
  16084. if(isset($attr['SRC'])) {
  16085. $type = 'IMAGE';
  16086. $srcpath = $attr['SRC'];
  16087. $orig_srcpath = $attr['ORIG_SRC'];
  16088. // VSPACE and HSPACE converted to margins in MergeCSS
  16089. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16090. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16091. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16092. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16093. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  16094. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  16095. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  16096. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  16097. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16098. $w = 0;
  16099. $h = 0;
  16100. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  16101. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width']);
  16102. $extraheight = $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  16103. $extrawidth = $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  16104. // Image file
  16105. $info=$this->_getImage($srcpath, true, true, $orig_srcpath); // mPDF 5.0.038
  16106. if(!$info) {
  16107. $info = $this->_getImage($this->noImageFile);
  16108. if ($info) {
  16109. $srcpath = $this->noImageFile;
  16110. $w = ($info['w'] * (25.4/$this->dpi));
  16111. $h = ($info['h'] * (25.4/$this->dpi));
  16112. }
  16113. }
  16114. if(!$info) break;
  16115. $objattr['file'] = $srcpath;
  16116. //Default width and height calculation if needed
  16117. if($w==0 and $h==0) {
  16118. // mPDF 5.0.038
  16119. /*-- IMAGES-WMF --*/
  16120. if ($info['type']=='wmf') {
  16121. // WMF units are twips (1/20pt)
  16122. // divide by 20 to get points
  16123. // divide by k to get user units
  16124. $w = abs($info['w'])/(20*$this->k);
  16125. $h = abs($info['h']) / (20*$this->k);
  16126. }
  16127. else
  16128. /*-- END IMAGES-WMF --*/
  16129. if ($info['type']=='svg') {
  16130. // SVG units are pixels
  16131. $w = abs($info['w'])/$this->k;
  16132. $h = abs($info['h'])/$this->k;
  16133. }
  16134. else {
  16135. //Put image at default image dpi
  16136. $w=($info['w']/$this->k) * (72/$this->img_dpi);
  16137. $h=($info['h']/$this->k) * (72/$this->img_dpi);
  16138. }
  16139. // mPDF 5.0.031
  16140. if (isset($properties['IMAGE-RESOLUTION'])) {
  16141. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  16142. $w *= $this->img_dpi / $info['set-dpi'];
  16143. $h *= $this->img_dpi / $info['set-dpi'];
  16144. }
  16145. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  16146. $dpi = $m[1];
  16147. if ($dpi > 0) {
  16148. $w *= $this->img_dpi / $dpi;
  16149. $h *= $this->img_dpi / $dpi;
  16150. }
  16151. }
  16152. }
  16153. }
  16154. // IF WIDTH OR HEIGHT SPECIFIED
  16155. if($w==0) $w=$h*$info['w']/$info['h'];
  16156. if($h==0) $h=$w*$info['h']/$info['w'];
  16157. // Resize to maximum dimensions of page
  16158. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  16159. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  16160. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  16161. if ($w + $extrawidth > $maxWidth ) {
  16162. $w = $maxWidth - $extrawidth;
  16163. $h=$w*$info['h']/$info['w'];
  16164. }
  16165. if ($h + $extraheight > $maxHeight ) {
  16166. $h = $maxHeight - $extraheight;
  16167. $w=$h*$info['w']/$info['h'];
  16168. }
  16169. $height = $h + $extraheight;
  16170. $width = $w + $extrawidth;
  16171. // mPDF 5.0.038
  16172. $objattr['type'] = 'image';
  16173. $objattr['itype'] = $info['type'];
  16174. $objattr['orig_h'] = $info['h'];
  16175. $objattr['orig_w'] = $info['w'];
  16176. /*-- IMAGES-WMF --*/
  16177. if ($info['type']=='wmf') {
  16178. $objattr['wmf_x'] = $info['x'];
  16179. $objattr['wmf_y'] = $info['y'];
  16180. }
  16181. else
  16182. /*-- END IMAGES-WMF --*/
  16183. if ($info['type']=='svg') {
  16184. $objattr['wmf_x'] = $info['x'];
  16185. $objattr['wmf_y'] = $info['y'];
  16186. }
  16187. $objattr['height'] = $h + $extraheight;
  16188. $objattr['width'] = $w + $extrawidth;
  16189. $objattr['image_height'] = $h;
  16190. $objattr['image_width'] = $w;
  16191. $objattr['ID'] = $info['i'];
  16192. $texto = 'X';
  16193. break;
  16194. }
  16195. /*-- END IMAGES-CORE --*/
  16196. case 'BUTTON': // Draw a button
  16197. case 'SUBMIT':
  16198. case 'RESET':
  16199. $type = strtoupper($attr['TYPE']);
  16200. if ($type=='IMAGE') { $type = 'BUTTON'; } // src path not found
  16201. if (isset($attr['VALUE'])) {
  16202. $objattr['value'] = $attr['VALUE'];
  16203. }
  16204. else {
  16205. $objattr['value'] = ucfirst(strtolower($type));
  16206. }
  16207. // mPDF 5.0.059
  16208. $objattr['value'] = strcode2utf($objattr['value']);
  16209. $texto = " " . $objattr['value'] . " ";
  16210. $width = $this->GetStringWidth($texto) + ($this->form_element_spacing['button']['outer']['h']*2)+($this->form_element_spacing['button']['inner']['h']*2);
  16211. $height = $this->FontSize + ($this->form_element_spacing['button']['outer']['v']*2)+($this->form_element_spacing['button']['inner']['v']*2);
  16212. break;
  16213. case 'PASSWORD':
  16214. case 'TEXT':
  16215. default:
  16216. if ($type == '') { $type = 'TEXT'; }
  16217. if(strtoupper($attr['TYPE'])=='PASSWORD') { $type = 'PASSWORD'; }
  16218. if (isset($attr['VALUE'])) {
  16219. if ($type == 'PASSWORD') {
  16220. $num_stars = strlen($attr['VALUE']);
  16221. $texto = str_repeat('*',$num_stars);
  16222. }
  16223. else { $texto = $attr['VALUE']; }
  16224. }
  16225. $xw = ($this->form_element_spacing['input']['outer']['h']*2)+($this->form_element_spacing['input']['inner']['h']*2);
  16226. $xh = ($this->form_element_spacing['input']['outer']['v']*2)+($this->form_element_spacing['input']['inner']['v']*2);
  16227. if ($w) { $width = $w + $xw; }
  16228. else { $width = (20 * $spacesize) + $xw; } // Default width in chars
  16229. if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $width = ($attr['SIZE'] * $spacesize) + $xw;
  16230. $height = $this->FontSize + $xh;
  16231. break;
  16232. }
  16233. $objattr['subtype'] = $type;
  16234. $objattr['text'] = $texto;
  16235. $objattr['width'] = $width;
  16236. $objattr['height'] = $height;
  16237. $e = "\xbb\xa4\xactype=input,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16238. // Clear properties - tidy up
  16239. $properties = array();
  16240. /*-- TABLES --*/
  16241. // Output it to buffers
  16242. if ($this->tableLevel) {
  16243. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  16244. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  16245. }
  16246. else {
  16247. /*-- END TABLES --*/
  16248. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063);
  16249. } // *TABLES*
  16250. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16251. unset($this->InlineProperties[$tag]);
  16252. break; // END of INPUT
  16253. /*-- END FORMS --*/
  16254. // *********** GRAPH ********************
  16255. case 'JPGRAPH':
  16256. if (!$this->useGraphs) { break; }
  16257. if ($attr['TABLE']) { $gid = strtoupper($attr['TABLE']); }
  16258. else { $gid = '0'; }
  16259. if (!is_array($this->graphs[$gid]) || count($this->graphs[$gid])==0 ) { break; }
  16260. include_once(_MPDF_PATH.'graph.php');
  16261. $this->graphs[$gid]['attr'] = $attr;
  16262. if (isset($this->graphs[$gid]['attr']['WIDTH']) && $this->graphs[$gid]['attr']['WIDTH']) {
  16263. $this->graphs[$gid]['attr']['cWIDTH']=$this->ConvertSize($this->graphs[$gid]['attr']['WIDTH'],$pgwidth);
  16264. } // mm
  16265. if (isset($this->graphs[$gid]['attr']['HEIGHT']) && $this->graphs[$gid]['attr']['HEIGHT']) {
  16266. $this->graphs[$gid]['attr']['cHEIGHT']=$this->ConvertSize($this->graphs[$gid]['attr']['HEIGHT'],$pgwidth);
  16267. }
  16268. $graph_img = print_graph($this->graphs[$gid],$this->blk[$this->blklvl]['inner_width']);
  16269. if ($graph_img) {
  16270. if(isset($attr['ROTATE'])) {
  16271. if ($attr['ROTATE']==90 || $attr['ROTATE']==-90) {
  16272. $tmpw = $graph_img['w'];
  16273. $graph_img['w']= $graph_img['h'];
  16274. $graph_img['h']= $tmpw;
  16275. }
  16276. }
  16277. $attr['SRC'] = $graph_img['file'];
  16278. $attr['WIDTH'] = $graph_img['w'];
  16279. $attr['HEIGHT'] = $graph_img['h'];
  16280. }
  16281. else { break; }
  16282. // *********** IMAGE ********************
  16283. /*-- IMAGES-CORE --*/
  16284. case 'IMG':
  16285. if ($this->progressBar) { $this->UpdateProgressBar(1,'','IMG'); } // *PROGRESS-BAR*
  16286. $objattr = array();
  16287. $objattr['margin_top'] = 0;
  16288. $objattr['margin_bottom'] = 0;
  16289. $objattr['margin_left'] = 0;
  16290. $objattr['margin_right'] = 0;
  16291. $objattr['padding_top'] = 0;
  16292. $objattr['padding_bottom'] = 0;
  16293. $objattr['padding_left'] = 0;
  16294. $objattr['padding_right'] = 0;
  16295. $objattr['width'] = 0;
  16296. $objattr['height'] = 0;
  16297. $objattr['border_top']['w'] = 0;
  16298. $objattr['border_bottom']['w'] = 0;
  16299. $objattr['border_left']['w'] = 0;
  16300. $objattr['border_right']['w'] = 0;
  16301. if(isset($attr['SRC'])) {
  16302. $srcpath = $attr['SRC'];
  16303. $orig_srcpath = $attr['ORIG_SRC'];
  16304. $properties = $this->MergeCSS('',$tag,$attr);
  16305. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  16306. return;
  16307. }
  16308. // VSPACE and HSPACE converted to margins in MergeCSS
  16309. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16310. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16311. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16312. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16313. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16314. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16315. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16316. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16317. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  16318. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  16319. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  16320. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  16321. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16322. $w = 0;
  16323. $h = 0;
  16324. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16325. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16326. if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16327. if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16328. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  16329. if ($this->HREF) { $objattr['link'] = $this->HREF; } // ? this isn't used
  16330. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  16331. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  16332. /*-- BACKGROUNDS --*/
  16333. // mPDF 5.0.027
  16334. if(isset($properties['GRADIENT-MASK']) && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['GRADIENT-MASK'])) {
  16335. $objattr['GRADIENT-MASK'] = $properties['GRADIENT-MASK'];
  16336. }
  16337. /*-- END BACKGROUNDS --*/
  16338. // Image file
  16339. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  16340. if(!$info) {
  16341. $info = $this->_getImage($this->noImageFile);
  16342. if ($info) {
  16343. $srcpath = $this->noImageFile;
  16344. $w = ($info['w'] * (25.4/$this->dpi));
  16345. $h = ($info['h'] * (25.4/$this->dpi));
  16346. }
  16347. }
  16348. if(!$info) break;
  16349. // mPDF 5.0.032
  16350. if(isset($attr['ROTATE'])) { $image_orientation = $attr['ROTATE']; }
  16351. else if(isset($properties['IMAGE-ORIENTATION'])) { $image_orientation = $properties['IMAGE-ORIENTATION']; }
  16352. else { $image_orientation = 0; }
  16353. if($image_orientation) {
  16354. if ($image_orientation==90 || $image_orientation==-90 || $image_orientation==270) {
  16355. $tmpw = $info['w'];
  16356. $info['w'] = $info['h'];
  16357. $info['h'] = $tmpw;
  16358. }
  16359. $objattr['ROTATE'] = $image_orientation;
  16360. }
  16361. $objattr['file'] = $srcpath;
  16362. //Default width and height calculation if needed
  16363. if($w==0 and $h==0) {
  16364. /*-- IMAGES-WMF --*/
  16365. if ($info['type']=='wmf') {
  16366. // WMF units are twips (1/20pt)
  16367. // divide by 20 to get points
  16368. // divide by k to get user units
  16369. $w = abs($info['w'])/(20*$this->k);
  16370. $h = abs($info['h']) / (20*$this->k);
  16371. }
  16372. else
  16373. /*-- END IMAGES-WMF --*/
  16374. if ($info['type']=='svg') {
  16375. // SVG units are pixels
  16376. $w = abs($info['w'])/$this->k;
  16377. $h = abs($info['h'])/$this->k;
  16378. }
  16379. else {
  16380. //Put image at default image dpi
  16381. $w=($info['w']/$this->k) * (72/$this->img_dpi);
  16382. $h=($info['h']/$this->k) * (72/$this->img_dpi);
  16383. }
  16384. // mPDF 5.0.031
  16385. if (isset($properties['IMAGE-RESOLUTION'])) {
  16386. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  16387. $w *= $this->img_dpi / $info['set-dpi'];
  16388. $h *= $this->img_dpi / $info['set-dpi'];
  16389. }
  16390. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  16391. $dpi = $m[1];
  16392. if ($dpi > 0) {
  16393. $w *= $this->img_dpi / $dpi;
  16394. $h *= $this->img_dpi / $dpi;
  16395. }
  16396. }
  16397. }
  16398. }
  16399. // IF WIDTH OR HEIGHT SPECIFIED
  16400. if($w==0) $w=abs($h*$info['w']/$info['h']);
  16401. if($h==0) $h=abs($w*$info['h']/$info['w']);
  16402. // Resize to maximum dimensions of page
  16403. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  16404. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 1) ; // mPDF 5.0.011 (was 10mm)
  16405. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  16406. if ($w + $extrawidth > $maxWidth ) {
  16407. $w = $maxWidth - $extrawidth;
  16408. $h=abs($w*$info['h']/$info['w']);
  16409. }
  16410. if ($h + $extraheight > $maxHeight ) {
  16411. $h = $maxHeight - $extraheight;
  16412. $w=abs($h*$info['w']/$info['h']);
  16413. }
  16414. $objattr['type'] = 'image';
  16415. $objattr['itype'] = $info['type'];
  16416. $objattr['orig_h'] = $info['h'];
  16417. $objattr['orig_w'] = $info['w'];
  16418. /*-- IMAGES-WMF --*/
  16419. if ($info['type']=='wmf') {
  16420. $objattr['wmf_x'] = $info['x'];
  16421. $objattr['wmf_y'] = $info['y'];
  16422. }
  16423. else
  16424. /*-- END IMAGES-WMF --*/
  16425. if ($info['type']=='svg') {
  16426. $objattr['wmf_x'] = $info['x'];
  16427. $objattr['wmf_y'] = $info['y'];
  16428. }
  16429. $objattr['height'] = $h + $extraheight;
  16430. $objattr['width'] = $w + $extrawidth;
  16431. $objattr['image_height'] = $h;
  16432. $objattr['image_width'] = $w;
  16433. /*-- CSS-IMAGE-FLOAT --*/
  16434. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  16435. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  16436. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  16437. }
  16438. }
  16439. /*-- END CSS-IMAGE-FLOAT --*/
  16440. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16441. // Clear properties - tidy up
  16442. $properties = array();
  16443. /*-- TABLES --*/
  16444. // Output it to buffers
  16445. if ($this->tableLevel) {
  16446. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  16447. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  16448. }
  16449. else {
  16450. /*-- END TABLES --*/
  16451. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  16452. } // *TABLES*
  16453. /*-- ANNOTATIONS --*/
  16454. if ($this->title2annots && isset($attr['TITLE'])) {
  16455. $objattr = array();
  16456. $objattr['margin_top'] = 0;
  16457. $objattr['margin_bottom'] = 0;
  16458. $objattr['margin_left'] = 0;
  16459. $objattr['margin_right'] = 0;
  16460. $objattr['width'] = 0;
  16461. $objattr['height'] = 0;
  16462. $objattr['border_top']['w'] = 0;
  16463. $objattr['border_bottom']['w'] = 0;
  16464. $objattr['border_left']['w'] = 0;
  16465. $objattr['border_right']['w'] = 0;
  16466. $objattr['CONTENT'] = $attr['TITLE'];
  16467. $objattr['type'] = 'annot';
  16468. $objattr['POS-X'] = 0;
  16469. $objattr['POS-Y'] = 0;
  16470. $objattr['ICON'] = 'Comment';
  16471. $objattr['AUTHOR'] = '';
  16472. $objattr['SUBJECT'] = '';
  16473. $objattr['OPACITY'] = $this->annotOpacity;
  16474. $objattr['COLOR'] = $this->ConvertColor('yellow'); // mPDF 5.0.051
  16475. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16476. if($this->tableLevel) { // *TABLES*
  16477. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); // *TABLES*
  16478. } // *TABLES*
  16479. else { // *TABLES*
  16480. $this->textbuffer[] = array($e);
  16481. } // *TABLES*
  16482. }
  16483. /*-- END ANNOTATIONS --*/
  16484. }
  16485. break;
  16486. /*-- END IMAGES-CORE --*/
  16487. /*-- TABLES --*/
  16488. case 'TABLE': // TABLE-BEGIN
  16489. $this->tdbegin = false;
  16490. $this->lastoptionaltag = '';
  16491. // Disable vertical justification in columns
  16492. if ($this->ColActive) { $this->colvAlign = ''; } // *COLUMNS*
  16493. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  16494. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  16495. // called from block after new div e.g. <div> ... <table> ... Outputs block top margin/border and padding
  16496. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  16497. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']); // mPDF 5.0.054
  16498. $this->finishFlowingBlock(true); // true = END of flowing block
  16499. }
  16500. else if (!$this->tableLevel && count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  16501. //else if (!$this->tableLevel) { $this->printbuffer($this->textbuffer,$blockstate); }
  16502. $this->textbuffer=array();
  16503. $this->lastblocklevelchange = -1;
  16504. if ($this->tableLevel) { // i.e. now a nested table coming...
  16505. // Save current level table
  16506. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties']= $this->base_table_properties;
  16507. // $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tablecascadeCSS'] = $this->tablecascadeCSS;
  16508. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  16509. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'] = $this->row;
  16510. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'] = $this->col;
  16511. }
  16512. $this->tableLevel++;
  16513. $this->tbCSSlvl++;
  16514. // mPDF 5.0.065
  16515. if ($this->tableLevel>1) { // inherit table properties from cell in which nested
  16516. $this->base_table_properties['FONT-KERNING'] = $this->kerning ;
  16517. $this->base_table_properties['LETTER-SPACING'] = $this->lSpacingCSS ;
  16518. $this->base_table_properties['WORD-SPACING'] = $this->wSpacingCSS ;
  16519. }
  16520. if (isset($this->tbctr[$this->tableLevel])) { $this->tbctr[$this->tableLevel]++; }
  16521. else { $this->tbctr[$this->tableLevel] = 1; }
  16522. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['level'] = $this->tableLevel;
  16523. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['levelid'] = $this->tbctr[$this->tableLevel];
  16524. if ($this->tableLevel > $this->innermostTableLevel) { $this->innermostTableLevel = $this->tableLevel; }
  16525. if ($this->tableLevel > 1) {
  16526. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nestedpos'] = array($this->row,$this->col,$this->tbctr[($this->tableLevel-1)]);
  16527. }
  16528. //++++++++++++++++++++++++++++
  16529. $this->cell = array();
  16530. $this->col=-1; //int
  16531. $this->row=-1; //int
  16532. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  16533. $table['direction'] = $this->directionality; // mPDF 5.0.054
  16534. $table['bgcolor'] = false;
  16535. $table['va'] = false;
  16536. $table['txta'] = false;
  16537. $table['topntail'] = false;
  16538. $table['thead-underline'] = false;
  16539. $table['border'] = false;
  16540. $table['border_details']['R']['w'] = 0;
  16541. $table['border_details']['L']['w'] = 0;
  16542. $table['border_details']['T']['w'] = 0;
  16543. $table['border_details']['B']['w'] = 0;
  16544. $table['border_details']['R']['style'] = '';
  16545. $table['border_details']['L']['style'] = '';
  16546. $table['border_details']['T']['style'] = '';
  16547. $table['border_details']['B']['style'] = '';
  16548. $table['max_cell_border_width']['R'] = 0;
  16549. $table['max_cell_border_width']['L'] = 0;
  16550. $table['max_cell_border_width']['T'] = 0;
  16551. $table['max_cell_border_width']['B'] = 0;
  16552. $table['padding']['L'] = false;
  16553. $table['padding']['R'] = false;
  16554. $table['padding']['T'] = false;
  16555. $table['padding']['B'] = false;
  16556. $table['margin']['L'] = false;
  16557. $table['margin']['R'] = false;
  16558. $table['margin']['T'] = false;
  16559. $table['margin']['B'] = false;
  16560. $table['a'] = false;
  16561. $table['border_spacing_H'] = false;
  16562. $table['border_spacing_V'] = false;
  16563. $this->Reset();
  16564. $this->InlineProperties = array();
  16565. $this->spanlvl = 0;
  16566. $table['nc'] = $table['nr'] = 0;
  16567. $this->tablethead = 0;
  16568. $this->tabletfoot = 0;
  16569. $this->tabletheadjustfinished = false;
  16570. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins && $this->tableLevel==1) { $lastbottommargin = $this->lastblockbottommargin; }
  16571. else { $lastbottommargin = 0; }
  16572. $this->lastblockbottommargin = 0;
  16573. $this->blockjustfinished=false;
  16574. if ($this->tableLevel==1) {
  16575. // mPDF 5.0
  16576. $this->tableCJK = false;
  16577. $this->table_lineheight = $this->normalLineheight;
  16578. $this->tableheadernrows = 0;
  16579. $this->tablefooternrows = 0;
  16580. $this->usetableheader = false;
  16581. $this->base_table_properties = array();
  16582. }
  16583. // ADDED CSS FUNCIONS FOR TABLE
  16584. if ($this->tbCSSlvl==1) {
  16585. $properties = $this->MergeCSS('TOPTABLE',$tag,$attr);
  16586. }
  16587. else {
  16588. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16589. }
  16590. $w = '';
  16591. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  16592. // mPDF 5.0.054 / 5.0.055
  16593. if(isset($properties['DIRECTION']) && $properties['DIRECTION']) { $table['direction'] = strtolower($properties['DIRECTION']); }
  16594. if(isset($attr['DIR']) && $attr['DIR']) { $table['direction'] = strtolower($attr['DIR']); }
  16595. else if (!isset($table['direction'])){ $table['direction'] = $this->blk[$this->blklvl]['direction']; }
  16596. if (isset($properties['BACKGROUND-COLOR'])) { $table['bgcolor'][-1] = $properties['BACKGROUND-COLOR']; }
  16597. else if (isset($properties['BACKGROUND'])) { $table['bgcolor'][-1] = $properties['BACKGROUND']; }
  16598. if (isset($properties['VERTICAL-ALIGN'])) { $table['va'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16599. if (isset($properties['TEXT-ALIGN'])) { $table['txta'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  16600. if (isset($properties['AUTOSIZE']) && $properties['AUTOSIZE'] && $this->tableLevel ==1) {
  16601. $this->shrink_this_table_to_fit = $properties['AUTOSIZE'];
  16602. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 0; }
  16603. }
  16604. if (isset($properties['ROTATE']) && $properties['ROTATE'] && $this->tableLevel ==1) {
  16605. $this->table_rotate = $properties['ROTATE'];
  16606. }
  16607. if (isset($properties['TOPNTAIL'])) { $table['topntail'] = $properties['TOPNTAIL']; }
  16608. if (isset($properties['THEAD-UNDERLINE'])) { $table['thead-underline'] = $properties['THEAD-UNDERLINE']; }
  16609. if (isset($properties['BORDER'])) {
  16610. $bord = $this->border_details($properties['BORDER']);
  16611. if ($bord['s']) {
  16612. $table['border'] = _BORDER_ALL;
  16613. $table['border_details']['R'] = $bord;
  16614. $table['border_details']['L'] = $bord;
  16615. $table['border_details']['T'] = $bord;
  16616. $table['border_details']['B'] = $bord;
  16617. }
  16618. }
  16619. if (isset($properties['BORDER-RIGHT'])) {
  16620. // mPDF 5.0.054
  16621. if ($table['direction'] == 'rtl') { // *RTL*
  16622. $table['border_details']['R'] = $this->border_details($properties['BORDER-LEFT']); // *RTL*
  16623. } // *RTL*
  16624. else { // *RTL*
  16625. $table['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  16626. } // *RTL*
  16627. $this->setBorder($table['border'], _BORDER_RIGHT, $table['border_details']['R']['s']);
  16628. }
  16629. if (isset($properties['BORDER-LEFT'])) {
  16630. // mPDF 5.0.054
  16631. if ($table['direction'] == 'rtl') { // *RTL*
  16632. $table['border_details']['L'] = $this->border_details($properties['BORDER-RIGHT']); // *RTL*
  16633. } // *RTL*
  16634. else { // *RTL*
  16635. $table['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  16636. } // *RTL*
  16637. $this->setBorder($table['border'], _BORDER_LEFT, $table['border_details']['L']['s']);
  16638. }
  16639. if (isset($properties['BORDER-BOTTOM'])) {
  16640. $table['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  16641. $this->setBorder($table['border'], _BORDER_BOTTOM, $table['border_details']['B']['s']);
  16642. }
  16643. if (isset($properties['BORDER-TOP'])) {
  16644. $table['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  16645. $this->setBorder($table['border'], _BORDER_TOP, $table['border_details']['T']['s']);
  16646. }
  16647. if ($table['border']){
  16648. $this->table_border_css_set = 1;
  16649. }
  16650. else {
  16651. $this->table_border_css_set = 0;
  16652. }
  16653. if (isset($properties['FONT-FAMILY'])) {
  16654. $this->default_font = $properties['FONT-FAMILY'];
  16655. $this->SetFont($this->default_font,'',0,false);
  16656. $this->base_table_properties['FONT-FAMILY'] = $properties['FONT-FAMILY'];
  16657. }
  16658. if (isset($properties['FONT-SIZE'])) {
  16659. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  16660. if ($mmsize) {
  16661. $this->default_font_size = $mmsize*($this->k);
  16662. $this->SetFontSize($this->default_font_size,false);
  16663. $this->base_table_properties['FONT-SIZE'] = $properties['FONT-SIZE'];
  16664. }
  16665. }
  16666. if (isset($properties['FONT-WEIGHT'])) {
  16667. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->base_table_properties['FONT-WEIGHT'] = 'BOLD'; }
  16668. }
  16669. if (isset($properties['FONT-STYLE'])) {
  16670. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->base_table_properties['FONT-STYLE'] = 'ITALIC'; }
  16671. }
  16672. if (isset($properties['COLOR'])) {
  16673. $this->base_table_properties['COLOR'] = $properties['COLOR'];
  16674. }
  16675. // mPDF 5.0.065
  16676. if (isset($properties['FONT-KERNING'])) {
  16677. $this->base_table_properties['FONT-KERNING'] = $properties['FONT-KERNING'];
  16678. }
  16679. if (isset($properties['LETTER-SPACING'])) {
  16680. $this->base_table_properties['LETTER-SPACING'] = $properties['LETTER-SPACING'];
  16681. }
  16682. if (isset($properties['WORD-SPACING'])) {
  16683. $this->base_table_properties['WORD-SPACING'] = $properties['WORD-SPACING'];
  16684. }
  16685. if (isset($properties['PADDING-LEFT'])) {
  16686. $table['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16687. }
  16688. if (isset($properties['PADDING-RIGHT'])) {
  16689. $table['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16690. }
  16691. if (isset($properties['PADDING-TOP'])) {
  16692. $table['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16693. }
  16694. if (isset($properties['PADDING-BOTTOM'])) {
  16695. $table['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16696. }
  16697. if (isset($properties['MARGIN-TOP'])) {
  16698. if ($lastbottommargin) {
  16699. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16700. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  16701. else { $properties['MARGIN-TOP'] = 0; }
  16702. }
  16703. $table['margin']['T'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16704. }
  16705. if (isset($properties['MARGIN-BOTTOM'])) {
  16706. $table['margin']['B'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16707. }
  16708. if (isset($properties['MARGIN-LEFT'])) {
  16709. $table['margin']['L'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16710. }
  16711. if (isset($properties['MARGIN-RIGHT'])) {
  16712. $table['margin']['R'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16713. }
  16714. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  16715. $table['a'] = 'C';
  16716. }
  16717. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  16718. $table['a'] = 'R';
  16719. }
  16720. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  16721. $table['a'] = 'L';
  16722. }
  16723. if (isset($properties['LINE-HEIGHT']) && $this->tableLevel==1) {
  16724. $this->table_lineheight = $this->fixLineheight($properties['LINE-HEIGHT']);
  16725. if (!$this->table_lineheight) { $this->table_lineheight = $this->normalLineheight; }
  16726. }
  16727. if (isset($properties['BORDER-COLLAPSE']) && strtoupper($properties['BORDER-COLLAPSE'])=='SEPARATE') {
  16728. $table['borders_separate'] = true;
  16729. }
  16730. else {
  16731. $table['borders_separate'] = false;
  16732. }
  16733. if (isset($properties['BORDER-SPACING-H'])) {
  16734. $table['border_spacing_H'] = $this->ConvertSize($properties['BORDER-SPACING-H'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16735. }
  16736. if (isset($properties['BORDER-SPACING-V'])) {
  16737. $table['border_spacing_V'] = $this->ConvertSize($properties['BORDER-SPACING-V'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16738. }
  16739. if (isset($properties['EMPTY-CELLS'])) {
  16740. $table['empty_cells'] = strtolower($properties['EMPTY-CELLS']); // 'hide' or 'show'
  16741. }
  16742. else { $table['empty_cells'] = ''; }
  16743. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE'])=='AVOID' && $this->tableLevel==1 && !$this->writingHTMLfooter) { // mPDF 5.0.002
  16744. $this->table_keep_together = true;
  16745. }
  16746. else if ($this->tableLevel==1) {
  16747. $this->table_keep_together = false;
  16748. }
  16749. // mPDF 5.0.018
  16750. /*-- BACKGROUNDS --*/
  16751. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $table['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  16752. // mPDF 5.0.018
  16753. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  16754. // mPDF 5.0.023
  16755. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  16756. if ($ret) { $table['background-image'] = $ret; }
  16757. }
  16758. /*-- END BACKGROUNDS --*/
  16759. if (isset($properties['OVERFLOW'])) {
  16760. $table['overflow'] = strtolower($properties['OVERFLOW']); // 'hidden' 'wrap' or 'visible' or 'auto'
  16761. }
  16762. $properties = array();
  16763. if (!$table['borders_separate']) { $table['border_spacing_H'] = $table['border_spacing_V'] = 0; }
  16764. else if (isset($attr['CELLSPACING'])) {
  16765. $table['border_spacing_H'] = $table['border_spacing_V'] = $this->ConvertSize($attr['CELLSPACING'],$this->blk[$this->blklvl]['inner_width']);
  16766. }
  16767. if (isset($attr['CELLPADDING'])) {
  16768. $table['cell_padding'] = $attr['CELLPADDING'];
  16769. }
  16770. else {
  16771. $table['cell_padding'] = false;
  16772. }
  16773. if (isset($attr['BORDER'])) {
  16774. $this->table_border_attr_set = 1;
  16775. if ($attr['BORDER']=='1') {
  16776. $bord = $this->border_details('#000000 1px solid');
  16777. if ($bord['s']) {
  16778. $table['border'] = _BORDER_ALL;
  16779. $table['border_details']['R'] = $bord;
  16780. $table['border_details']['L'] = $bord;
  16781. $table['border_details']['T'] = $bord;
  16782. $table['border_details']['B'] = $bord;
  16783. }
  16784. }
  16785. }
  16786. else {
  16787. $this->table_border_attr_set = 0;
  16788. }
  16789. if (isset($attr['REPEAT_HEADER']) and $attr['REPEAT_HEADER'] == true) { $this->UseTableHeader(true); }
  16790. if (isset($attr['ALIGN'])) { $table['a'] = $align[strtolower($attr['ALIGN'])]; }
  16791. // mPDF 5.0.054
  16792. if (!$table['a']) {
  16793. if ($table['direction'] == 'rtl' ) { $table['a'] = 'R'; }
  16794. else { $table['a'] = 'L'; }
  16795. }
  16796. if (isset($attr['BGCOLOR'])) { $table['bgcolor'][-1] = $attr['BGCOLOR']; }
  16797. if (isset($attr['WIDTH']) && $attr['WIDTH']) { $w = $attr['WIDTH']; }
  16798. if ($w) { // set here or earlier in $properties
  16799. $maxwidth = $this->blk[$this->blklvl]['inner_width'];
  16800. if ($table['borders_separate']) {
  16801. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['border_details']['L']['w']/2 + $table['border_details']['R']['w']/2;
  16802. }
  16803. else {
  16804. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2;
  16805. }
  16806. if (strpos($w,'%') && $this->tableLevel == 1 && !$this->ignore_table_percents ) {
  16807. // % needs to be of inner box without table margins etc.
  16808. $maxwidth -= $tblblw ;
  16809. $wmm = $this->ConvertSize($w,$maxwidth,$this->FontSize,false);
  16810. $table['w'] = $wmm + $tblblw ;
  16811. }
  16812. if (strpos($w,'%') && $this->tableLevel > 1 && !$this->ignore_table_percents && $this->keep_table_proportions) {
  16813. $table['wpercent'] = $w + 0; // makes 80% -> 80
  16814. }
  16815. if (!strpos($w,'%') && !$this->ignore_table_widths ) {
  16816. $wmm = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16817. $table['w'] = $wmm + $tblblw ;
  16818. }
  16819. if (!$this->keep_table_proportions) {
  16820. if (isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width']) { $table['w'] = $this->blk[$this->blklvl]['inner_width']; }
  16821. }
  16822. }
  16823. if (isset($attr['AUTOSIZE']) && $this->tableLevel==1) {
  16824. $this->shrink_this_table_to_fit = $attr['AUTOSIZE'];
  16825. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 1; }
  16826. }
  16827. if (isset($attr['ROTATE']) && $this->tableLevel==1) {
  16828. $this->table_rotate = $attr['ROTATE'];
  16829. }
  16830. //++++++++++++++++++++++++++++
  16831. // keeping block together on one page
  16832. // Autosize is now forced therefore keep block together disabled
  16833. if ($this->keep_block_together) {
  16834. $this->keep_block_together = 0;
  16835. $this->printdivbuffer();
  16836. $this->blk[$this->blklvl]['keep_block_together'] = 0;
  16837. }
  16838. if ($this->table_rotate) {
  16839. $this->tbrot_Links = array();
  16840. $this->tbrot_Annots = array();
  16841. $this->tbrot_Reference = array();
  16842. $this->tbrot_BMoutlines = array();
  16843. $this->tbrot_toc = array();
  16844. }
  16845. if ($this->kwt) {
  16846. if ($this->table_rotate) { $this->table_keep_together = true; }
  16847. $this->kwt = false;
  16848. $this->kwt_saved = true;
  16849. }
  16850. if ($this->tableLevel==1 && $this->useGraphs) {
  16851. if (isset($attr['ID']) && $attr['ID']) { $this->currentGraphId = strtoupper($attr['ID']); }
  16852. else { $this->currentGraphId = '0'; }
  16853. $this->graphs[$this->currentGraphId] = array();
  16854. }
  16855. //++++++++++++++++++++++++++++
  16856. $this->plainCell_properties = array();
  16857. break;
  16858. case 'THEAD':
  16859. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16860. $this->tbCSSlvl++;
  16861. $this->tablethead = 1;
  16862. $this->UseTableHeader(true);
  16863. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16864. if (isset($properties['FONT-WEIGHT'])) {
  16865. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->thead_font_weight = 'B'; }
  16866. else { $this->thead_font_weight = ''; }
  16867. }
  16868. if (isset($properties['FONT-STYLE'])) {
  16869. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->thead_font_style = 'I'; }
  16870. else { $this->thead_font_style = ''; }
  16871. }
  16872. if (isset($properties['FONT-VARIANT'])) { // mPDF 5.0
  16873. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->thead_font_smCaps = 'S'; }
  16874. else { $this->thead_font_smCaps = ''; }
  16875. }
  16876. if (isset($properties['VERTICAL-ALIGN'])) {
  16877. $this->thead_valign_default = $properties['VERTICAL-ALIGN'];
  16878. }
  16879. if (isset($properties['TEXT-ALIGN'])) {
  16880. $this->thead_textalign_default = $properties['TEXT-ALIGN'];
  16881. }
  16882. $properties = array();
  16883. break;
  16884. case 'TFOOT':
  16885. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16886. $this->tbCSSlvl++;
  16887. $this->tabletfoot = 1;
  16888. $this->tablethead = 0;
  16889. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16890. if (isset($properties['FONT-WEIGHT'])) {
  16891. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->tfoot_font_weight = 'B'; }
  16892. else { $this->tfoot_font_weight = ''; }
  16893. }
  16894. if (isset($properties['FONT-STYLE'])) {
  16895. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->tfoot_font_style = 'I'; }
  16896. else { $this->tfoot_font_style = ''; }
  16897. }
  16898. if (isset($properties['FONT-VARIANT'])) { // mPDF 5.0
  16899. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->tfoot_font_smCaps = 'S'; }
  16900. else { $this->tfoot_font_smCaps = ''; }
  16901. }
  16902. if (isset($properties['VERTICAL-ALIGN'])) {
  16903. $this->tfoot_valign_default = $properties['VERTICAL-ALIGN'];
  16904. }
  16905. if (isset($properties['TEXT-ALIGN'])) {
  16906. $this->tfoot_textalign_default = $properties['TEXT-ALIGN'];
  16907. }
  16908. $properties = array();
  16909. break;
  16910. case 'TBODY':
  16911. $this->tablethead = 0;
  16912. $this->tabletfoot = 0;
  16913. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16914. $this->tbCSSlvl++;
  16915. $this->MergeCSS('TABLE',$tag,$attr);
  16916. break;
  16917. case 'TR':
  16918. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16919. $this->tbCSSlvl++;
  16920. $this->row++;
  16921. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']++;
  16922. $this->col = -1;
  16923. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16924. // mPDF 5.0.003
  16925. if (!$this->simpleTables && !$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate']) {
  16926. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row] = $properties['BORDER-LEFT']; }
  16927. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row] = $properties['BORDER-RIGHT']; }
  16928. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-top'][$this->row] = $properties['BORDER-TOP']; }
  16929. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-bottom'][$this->row] = $properties['BORDER-BOTTOM']; }
  16930. }
  16931. if (isset($properties['BACKGROUND-COLOR'])) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $properties['BACKGROUND-COLOR']; }
  16932. // mPDF 5.0.018
  16933. /*-- BACKGROUNDS --*/
  16934. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$this->row] = $properties['BACKGROUND-GRADIENT']; }
  16935. // mPDF 5.0.018
  16936. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  16937. // mPDF 5.0.023
  16938. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  16939. if ($ret) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$this->row] = $ret; }
  16940. }
  16941. /*-- END BACKGROUNDS --*/
  16942. if (isset($properties['TEXT-ROTATE'])) {
  16943. $this->trow_text_rotate = $properties['TEXT-ROTATE'];
  16944. }
  16945. if (isset($attr['TEXT-ROTATE'])) $this->trow_text_rotate = $attr['TEXT-ROTATE'];
  16946. if (isset($attr['BGCOLOR'])) $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $attr['BGCOLOR'];
  16947. if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; }
  16948. if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; }
  16949. $properties = array();
  16950. break;
  16951. case 'TH':
  16952. case 'TD':
  16953. $this->ignorefollowingspaces = true;
  16954. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16955. $this->tbCSSlvl++;
  16956. $this->InlineProperties = array();
  16957. $this->spanlvl = 0;
  16958. $this->tdbegin = true;
  16959. $this->col++;
  16960. while (isset($this->cell[$this->row][$this->col])) { $this->col++; }
  16961. //Update number column
  16962. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+1; }
  16963. $this->cell[$this->row][$this->col] = array();
  16964. $this->cell[$this->row][$this->col]['text'] = array();
  16965. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16966. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  16967. $cell = &$this->cell[$this->row][$this->col];
  16968. $cell['a'] = false;
  16969. $cell['R'] = false;
  16970. $cell['nowrap'] = false;
  16971. $cell['bgcolor'] = false;
  16972. $cell['padding']['L'] = false;
  16973. $cell['padding']['R'] = false;
  16974. $cell['padding']['T'] = false;
  16975. $cell['padding']['B'] = false;
  16976. if ($this->simpleTables && $this->row==0 && $this->col==0){
  16977. $table['simple']['border'] = false;
  16978. $table['simple']['border_details']['R']['w'] = 0;
  16979. $table['simple']['border_details']['L']['w'] = 0;
  16980. $table['simple']['border_details']['T']['w'] = 0;
  16981. $table['simple']['border_details']['B']['w'] = 0;
  16982. $table['simple']['border_details']['R']['style'] = '';
  16983. $table['simple']['border_details']['L']['style'] = '';
  16984. $table['simple']['border_details']['T']['style'] = '';
  16985. $table['simple']['border_details']['B']['style'] = '';
  16986. }
  16987. else if (!$this->simpleTables) {
  16988. $cell['border'] = false;
  16989. $cell['border_details']['R']['w'] = 0;
  16990. $cell['border_details']['L']['w'] = 0;
  16991. $cell['border_details']['T']['w'] = 0;
  16992. $cell['border_details']['B']['w'] = 0;
  16993. $cell['border_details']['mbw']['BL'] = 0;
  16994. $cell['border_details']['mbw']['BR'] = 0;
  16995. $cell['border_details']['mbw']['RT'] = 0;
  16996. $cell['border_details']['mbw']['RB'] = 0;
  16997. $cell['border_details']['mbw']['TL'] = 0;
  16998. $cell['border_details']['mbw']['TR'] = 0;
  16999. $cell['border_details']['mbw']['LT'] = 0;
  17000. $cell['border_details']['mbw']['LB'] = 0;
  17001. $cell['border_details']['R']['style'] = '';
  17002. $cell['border_details']['L']['style'] = '';
  17003. $cell['border_details']['T']['style'] = '';
  17004. $cell['border_details']['B']['style'] = '';
  17005. $cell['border_details']['R']['s'] = 0;
  17006. $cell['border_details']['L']['s'] = 0;
  17007. $cell['border_details']['T']['s'] = 0;
  17008. $cell['border_details']['B']['s'] = 0;
  17009. $cell['border_details']['R']['c'] = $this->ConvertColor(0); // mPDF 5.0.051
  17010. $cell['border_details']['L']['c'] = $this->ConvertColor(0); // mPDF 5.0.051
  17011. $cell['border_details']['T']['c'] = $this->ConvertColor(0); // mPDF 5.0.051
  17012. $cell['border_details']['B']['c'] = $this->ConvertColor(0); // mPDF 5.0.051
  17013. $cell['border_details']['R']['dom'] = 0;
  17014. $cell['border_details']['L']['dom'] = 0;
  17015. $cell['border_details']['T']['dom'] = 0;
  17016. $cell['border_details']['B']['dom'] = 0;
  17017. }
  17018. // INHERITED TABLE PROPERTIES (or ROW for BGCOLOR)
  17019. // If cell bgcolor not set specifically, set to TR row bgcolor (if set)
  17020. // mPDF 5.1.008
  17021. // if ((!$cell['bgcolor']) && isset($table['bgcolor'][$this->row])) {
  17022. // $cell['bgcolor'] = $table['bgcolor'][$this->row];
  17023. // }
  17024. // mPDF 5.1.008
  17025. // else if (isset($table['bgcolor'][-1])) {
  17026. // $cell['bgcolor'] = $table['bgcolor'][-1];
  17027. // }
  17028. if ($table['va']) { $cell['va'] = $table['va']; }
  17029. if ($table['txta']) { $cell['a'] = $table['txta']; }
  17030. if ($this->table_border_attr_set) {
  17031. if ($table['border_details']) {
  17032. if (!$this->simpleTables){
  17033. $cell['border_details']['R'] = $table['border_details']['R'];
  17034. $cell['border_details']['L'] = $table['border_details']['L'];
  17035. $cell['border_details']['T'] = $table['border_details']['T'];
  17036. $cell['border_details']['B'] = $table['border_details']['B'];
  17037. $cell['border'] = $table['border'];
  17038. $cell['border_details']['L']['dom'] = 1;
  17039. $cell['border_details']['R']['dom'] = 1;
  17040. $cell['border_details']['T']['dom'] = 1;
  17041. $cell['border_details']['B']['dom'] = 1;
  17042. }
  17043. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  17044. $table['simple']['border_details']['R'] = $table['border_details']['R'];
  17045. $table['simple']['border_details']['L'] = $table['border_details']['L'];
  17046. $table['simple']['border_details']['T'] = $table['border_details']['T'];
  17047. $table['simple']['border_details']['B'] = $table['border_details']['B'];
  17048. $table['simple']['border'] = $table['border'];
  17049. }
  17050. }
  17051. }
  17052. // INHERITED THEAD CSS Properties
  17053. if ($this->tablethead) {
  17054. if ($this->thead_valign_default) $cell['va'] = $align[strtolower($this->thead_valign_default)];
  17055. if ($this->thead_textalign_default) $cell['a'] = $align[strtolower($this->thead_textalign_default)];
  17056. if ($this->thead_font_weight == 'B') { $this->SetStyle('B',true); }
  17057. if ($this->thead_font_style == 'I') { $this->SetStyle('I',true); }
  17058. if ($this->thead_font_variant == 'S') { $this->SetStyle('S',true); } // mPDF 5.0
  17059. }
  17060. // INHERITED TFOOT CSS Properties
  17061. if ($this->tabletfoot) {
  17062. if ($this->tfoot_valign_default) $cell['va'] = $align[strtolower($this->tfoot_valign_default)];
  17063. if ($this->tfoot_textalign_default) $cell['a'] = $align[strtolower($this->tfoot_textalign_default)];
  17064. if ($this->tfoot_font_weight == 'B') { $this->SetStyle('B',true); }
  17065. if ($this->tfoot_font_style == 'I') { $this->SetStyle('I',true); }
  17066. if ($this->tfoot_font_style == 'S') { $this->SetStyle('S',true); } // mPDF 5.0
  17067. }
  17068. if ($this->trow_text_rotate){
  17069. $cell['R'] = $this->trow_text_rotate;
  17070. }
  17071. $this->cell_border_dominance_L = 0;
  17072. $this->cell_border_dominance_R = 0;
  17073. $this->cell_border_dominance_T = 0;
  17074. $this->cell_border_dominance_B = 0;
  17075. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  17076. $properties = $this->array_merge_recursive_unique($this->base_table_properties, $properties);
  17077. // mPDF 5.0.065
  17078. if (isset($properties['FONT-KERNING']) && (strtoupper($properties['FONT-KERNING'])=='NORMAL' || strtoupper($properties['FONT-KERNING'])=='AUTO')) {
  17079. $this->kerning = true;
  17080. }
  17081. else { $this->kerning = false; }
  17082. if (isset($properties['LETTER-SPACING']) && ($properties['LETTER-SPACING'] || $properties['LETTER-SPACING']==='0') && strtoupper($properties['LETTER-SPACING']) != 'NORMAL') { // mPDF 5.0.066
  17083. $this->lSpacingCSS = strtoupper($properties['LETTER-SPACING']);
  17084. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); // mPDF 5.0.066
  17085. }
  17086. else {
  17087. $this->lSpacingCSS = '';
  17088. $this->fixedlSpacing = false;
  17089. }
  17090. if (isset($properties['WORD-SPACING']) && strtoupper($properties['WORD-SPACING']) != 'NORMAL') {
  17091. $this->wSpacingCSS = strtoupper($properties['WORD-SPACING']);
  17092. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); // mPDF 5.0.066
  17093. }
  17094. else {
  17095. $this->minwSpacing = 0;
  17096. $this->wSpacingCSS = '';
  17097. }
  17098. if (isset($properties['BACKGROUND-COLOR'])) { $cell['bgcolor'] = $properties['BACKGROUND-COLOR']; }
  17099. else if (isset($properties['BACKGROUND'])) { $cell['bgcolor'] = $properties['BACKGROUND']; }
  17100. /*-- BACKGROUNDS --*/
  17101. if (isset($properties['BACKGROUND-GRADIENT'])) { $cell['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  17102. else { $cell['gradient'] = false; }
  17103. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->keep_block_together) { // mPDF 5.1.008
  17104. // mPDF 5.0.023
  17105. $ret = $this->SetBackground($properties, $this->blk[$this->blklvl]['inner_width']);
  17106. if ($ret) { $cell['background-image'] = $ret; }
  17107. }
  17108. /*-- END BACKGROUNDS --*/
  17109. if (isset($properties['VERTICAL-ALIGN'])) { $cell['va']=$align[strtolower($properties['VERTICAL-ALIGN'])]; }
  17110. if (isset($properties['TEXT-ALIGN'])) { $cell['a'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  17111. if (isset($properties['TEXT-ROTATE']) && ($properties['TEXT-ROTATE'] || $properties['TEXT-ROTATE']==="0")){ // mPDF 5.0.025
  17112. $cell['R'] = $properties['TEXT-ROTATE'];
  17113. }
  17114. if (isset($properties['BORDER'])) {
  17115. $bord = $this->border_details($properties['BORDER']);
  17116. if ($bord['s']) {
  17117. if (!$this->simpleTables){
  17118. $cell['border'] = _BORDER_ALL;
  17119. $cell['border_details']['R'] = $bord;
  17120. $cell['border_details']['L'] = $bord;
  17121. $cell['border_details']['T'] = $bord;
  17122. $cell['border_details']['B'] = $bord;
  17123. $cell['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  17124. $cell['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  17125. $cell['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  17126. $cell['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  17127. }
  17128. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  17129. $table['simple']['border'] = _BORDER_ALL;
  17130. $table['simple']['border_details']['R'] = $bord;
  17131. $table['simple']['border_details']['L'] = $bord;
  17132. $table['simple']['border_details']['T'] = $bord;
  17133. $table['simple']['border_details']['B'] = $bord;
  17134. }
  17135. }
  17136. }
  17137. if (!$this->simpleTables){
  17138. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) {
  17139. $cell['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  17140. $this->setBorder($cell['border'], _BORDER_RIGHT, $cell['border_details']['R']['s']);
  17141. $cell['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  17142. }
  17143. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  17144. $cell['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  17145. $this->setBorder($cell['border'], _BORDER_LEFT, $cell['border_details']['L']['s']);
  17146. $cell['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  17147. }
  17148. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) {
  17149. $cell['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  17150. $this->setBorder($cell['border'], _BORDER_BOTTOM, $cell['border_details']['B']['s']);
  17151. $cell['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  17152. }
  17153. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) {
  17154. $cell['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  17155. $this->setBorder($cell['border'], _BORDER_TOP, $cell['border_details']['T']['s']);
  17156. $cell['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  17157. }
  17158. }
  17159. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  17160. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  17161. $bord = $this->border_details($properties['BORDER-LEFT']);
  17162. if ($bord['s']) { $table['simple']['border'] = _BORDER_ALL; }
  17163. else { $table['simple']['border'] = 0; }
  17164. $table['simple']['border_details']['R'] = $bord;
  17165. $table['simple']['border_details']['L'] = $bord;
  17166. $table['simple']['border_details']['T'] = $bord;
  17167. $table['simple']['border_details']['B'] = $bord;
  17168. }
  17169. }
  17170. if ($this->simpleTables && $this->row==0 && $this->col==0 && !$table['borders_separate']){
  17171. $table['border_details'] = $table['simple']['border_details'];
  17172. $table['border'] = $table['simple']['border'];
  17173. }
  17174. if ($this->packTableData && !$this->simpleTables) {
  17175. $cell['borderbin'] = $this->_packCellBorder($cell);
  17176. unset($cell['border']);
  17177. unset($cell['border_details']);
  17178. }
  17179. if (isset($properties['PADDING-LEFT'])) {
  17180. $cell['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  17181. }
  17182. if (isset($properties['PADDING-RIGHT'])) {
  17183. $cell['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  17184. }
  17185. if (isset($properties['PADDING-BOTTOM'])) {
  17186. $cell['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  17187. }
  17188. if (isset($properties['PADDING-TOP'])) {
  17189. $cell['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  17190. }
  17191. $w = '';
  17192. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  17193. if (isset($attr['WIDTH'])) { $w = $attr['WIDTH']; }
  17194. if ($w) {
  17195. if (strpos($w,'%') && !$this->ignore_table_percents ) { $cell['wpercent'] = $w + 0; } // makes 80% -> 80
  17196. else if (!strpos($w,'%') && !$this->ignore_table_widths ) { $cell['w'] = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  17197. }
  17198. if (isset($properties['HEIGHT'])) { $cell['h'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  17199. if (isset($properties['COLOR'])) {
  17200. $cor = $this->ConvertColor($properties['COLOR']);
  17201. if ($cor) {
  17202. $this->colorarray = $cor;
  17203. $this->SetTColor($cor); // mPDF 5.0.020
  17204. $this->issetcolor=true;
  17205. }
  17206. }
  17207. if (isset($properties['FONT-FAMILY'])) {
  17208. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  17209. }
  17210. if (isset($properties['FONT-SIZE'])) {
  17211. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  17212. if ($mmsize) {
  17213. $this->SetFontSize($mmsize*($this->k),false);
  17214. }
  17215. }
  17216. $cell['dfs'] = $this->FontSize; // Default Font size
  17217. if (isset($properties['FONT-WEIGHT'])) {
  17218. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->SetStyle('B',true); }
  17219. }
  17220. if (isset($properties['FONT-STYLE'])) {
  17221. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->SetStyle('I',true); }
  17222. }
  17223. if (isset($properties['FONT-VARIANT'])) {
  17224. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->SetStyle('S',true); }
  17225. }
  17226. if (isset($properties['WHITE-SPACE'])) {
  17227. if (strtoupper($properties['WHITE-SPACE']) == 'NOWRAP') { $cell['nowrap']= 1; }
  17228. }
  17229. $properties = array();
  17230. if (isset($attr['HEIGHT'])) $cell['h'] = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  17231. if (isset($attr['ALIGN'])) $cell['a'] = $align[strtolower($attr['ALIGN'])];
  17232. // mPDF 5.0.054
  17233. if (!$cell['a']) {
  17234. if ($table['direction'] == 'rtl' ) { $cell['a'] = 'R'; }
  17235. else { $cell['a'] = 'L'; }
  17236. }
  17237. if (isset($attr['VALIGN'])) $cell['va'] = $align[strtolower($attr['VALIGN'])];
  17238. if (isset($attr['BGCOLOR'])) $cell['bgcolor'] = $attr['BGCOLOR'];
  17239. $cs = $rs = 1;
  17240. if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $cell['colspan'] = $attr['COLSPAN'];
  17241. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+$cs) {
  17242. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+$cs;
  17243. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  17244. if ($l-$this->col) $this->cell[$this->row][$l] = 0;
  17245. }
  17246. }
  17247. if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $cell['rowspan'] = $attr['ROWSPAN'];
  17248. for ($k=$this->row ; $k < $this->row+$rs ;$k++) {
  17249. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  17250. if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0;
  17251. }
  17252. }
  17253. if (isset($attr['TEXT-ROTATE'])) {
  17254. $cell['R'] = $attr['TEXT-ROTATE'];
  17255. }
  17256. if (isset($attr['NOWRAP']) && $attr['NOWRAP']) $cell['nowrap']= 1;
  17257. unset($cell );
  17258. break;
  17259. /*-- END TABLES --*/
  17260. /*-- LISTS --*/
  17261. // *********** LISTS ********************
  17262. case 'OL':
  17263. case 'UL':
  17264. $this->listjustfinished = false;
  17265. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  17266. else { $lastbottommargin = 0; }
  17267. $this->lastblockbottommargin = 0;
  17268. $this->blockjustfinished=false;
  17269. $this->linebreakjustfinished=false;
  17270. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  17271. $this->listCSSlvl++;
  17272. if((!$this->tableLevel) && ($this->listlvl == 0)) {
  17273. $blockstate = 0;
  17274. //if ($this->lastblocklevelchange == 1) { $blockstate = -1; } // Top margins/padding only
  17275. //else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  17276. // called from block after new div e.g. <div> ... <ol> ... Outputs block top margin/border and padding
  17277. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  17278. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']); // mPDF 5.0.054
  17279. $this->finishFlowingBlock(true); // true = END of flowing block
  17280. }
  17281. else if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  17282. $this->textbuffer=array();
  17283. $this->lastblocklevelchange = -1;
  17284. }
  17285. // ol and ul types are mixed here
  17286. if ($this->listlvl == 0) {
  17287. $this->list_indent = array();
  17288. $this->list_align = array();
  17289. $this->list_lineheight = array();
  17290. $this->InlineProperties['LIST'] = array();
  17291. $this->InlineProperties['LISTITEM'] = array();
  17292. }
  17293. /*-- TABLES --*/
  17294. // A simple list for inside a table
  17295. if($this->tableLevel) {
  17296. $this->list_indent[$this->listlvl] = 0; // mm default indent for each level
  17297. if ($tag == 'OL') $this->listtype = '1';
  17298. else if ($tag == 'UL') $this->listtype = 'disc';
  17299. if ($this->listlvl > 0) {
  17300. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  17301. }
  17302. $this->listlvl++;
  17303. $this->listnum = 0; // reset
  17304. $this->listlist[$this->listlvl] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  17305. break;
  17306. }
  17307. /*-- END TABLES --*/
  17308. if (($this->PDFA || $this->PDFX) && $tag == 'UL') {
  17309. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "List bullets cannot use core font Zapfdingbats in PDFA1-b or PDFX/1-a. (Substitute characters from current font used if available, otherwise substitutes hyphen '-')"; }
  17310. }
  17311. if ($this->listCSSlvl==1) {
  17312. $properties = $this->MergeCSS('TOPLIST',$tag,$attr);
  17313. }
  17314. else {
  17315. $properties = $this->MergeCSS('LIST',$tag,$attr);
  17316. }
  17317. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  17318. // List-type
  17319. $this->listtype = '';
  17320. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listtype = $attr['TYPE']; }
  17321. else if (isset($properties['LIST-STYLE-TYPE'])) {
  17322. $this->listtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  17323. }
  17324. else if (isset($properties['LIST-STYLE'])) {
  17325. $this->listtype = $this->_getListStyle($properties['LIST-STYLE']);
  17326. }
  17327. if (!$this->listtype) {
  17328. if ($tag == 'OL') $this->listtype = '1';
  17329. if ($tag == 'UL') {
  17330. if ($this->listlvl % 3 == 0) $this->listtype = 'disc';
  17331. elseif ($this->listlvl % 3 == 1) $this->listtype = 'circle';
  17332. else $this->listtype = 'square';
  17333. }
  17334. }
  17335. if ($this->listlvl == 0) {
  17336. $this->inherit_lineheight = 0;
  17337. $this->listlvl++; // first depth level
  17338. $this->listnum = 0; // reset
  17339. // mPDF 5.0.054
  17340. $this->listDir = $this->blk[$this->blklvl]['direction'];
  17341. $occur = $this->listoccur[$this->listlvl] = 1;
  17342. $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  17343. }
  17344. else {
  17345. if (!empty($this->textbuffer))
  17346. {
  17347. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17348. $this->listnum++;
  17349. }
  17350. // Save current lineheight to inherit
  17351. $this->textbuffer = array();
  17352. $occur = $this->listoccur[$this->listlvl];
  17353. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  17354. $this->listlvl++;
  17355. $this->listnum = 0; // reset
  17356. if (!isset($this->listoccur[$this->listlvl]) || $this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
  17357. else $this->listoccur[$this->listlvl]++;
  17358. $occur = $this->listoccur[$this->listlvl];
  17359. $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  17360. }
  17361. // TOP LEVEL ONLY
  17362. if ($this->listlvl == 1) {
  17363. if (isset($properties['MARGIN-TOP'])) {
  17364. if ($lastbottommargin) {
  17365. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  17366. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  17367. else { $properties['MARGIN-TOP'] = 0; }
  17368. }
  17369. $this->DivLn($this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false),$this->blklvl,true,1); // collapsible
  17370. }
  17371. if (isset($properties['MARGIN-BOTTOM'])) {
  17372. $this->list_margin_bottom = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  17373. }
  17374. if (isset($this->blk[$this->blklvl]['line_height'])) {
  17375. $this->list_lineheight[$this->listlvl][$occur] = $this->blk[$this->blklvl]['line_height'];
  17376. }
  17377. // mPDF 5.0.054
  17378. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) { $this->listDir = strtolower($properties['DIRECTION']); }
  17379. if (isset($attr['DIR']) && $attr['DIR']) { $this->listDir = strtolower($attr['DIR']); }
  17380. }
  17381. $this->list_indent[$this->listlvl][$occur] = 5; // mm default indent for each level
  17382. if (isset($properties['TEXT-INDENT'])) { $this->list_indent[$this->listlvl][$occur] = $this->ConvertSize($properties['TEXT-INDENT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  17383. // mPDF 5.0.054
  17384. if (isset($properties['TEXT-ALIGN'])) {
  17385. $this->list_align[$this->listlvl][$occur] = $align[strtolower($properties['TEXT-ALIGN'])];
  17386. }
  17387. if (isset($properties['LINE-HEIGHT'])) {
  17388. $this->list_lineheight[$this->listlvl][$occur] = $this->fixLineheight($properties['LINE-HEIGHT']);
  17389. }
  17390. else if ($this->listlvl>1 && isset($this->list_lineheight[($this->listlvl - 1)][1])) {
  17391. $this->list_lineheight[$this->listlvl][$occur] = end($this->list_lineheight[($this->listlvl - 1)]);
  17392. }
  17393. if (!isset($this->list_lineheight[$this->listlvl][$occur]) || !$this->list_lineheight[$this->listlvl][$occur]) {
  17394. $this->list_lineheight[$this->listlvl][$occur] = $this->normalLineheight;
  17395. }
  17396. $this->InlineProperties['LIST'][$this->listlvl][$occur] = $this->saveInlineProperties();
  17397. $properties = array();
  17398. break;
  17399. case 'LI':
  17400. // Start Block
  17401. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  17402. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17403. /*-- TABLES --*/
  17404. // A simple list for inside a table
  17405. if($this->tableLevel) {
  17406. $this->blockjustfinished=false;
  17407. // If already something in the Cell
  17408. if ((isset($this->cell[$this->row][$this->col]['maxs']) && $this->cell[$this->row][$this->col]['maxs'] > 0 ) || $this->cell[$this->row][$this->col]['s'] > 0 ) {
  17409. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  17410. $this->cell[$this->row][$this->col]['text'][] = "\n";
  17411. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17412. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17413. }
  17414. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17415. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17416. }
  17417. $this->cell[$this->row][$this->col]['s'] = 0 ;
  17418. }
  17419. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  17420. $this->listlvl++; // first depth level
  17421. $this->listnum = 0; // reset
  17422. $this->listlist[$this->listlvl] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  17423. }
  17424. $this->listnum++;
  17425. switch($this->listlist[$this->listlvl]['TYPE']) {
  17426. case 'A':
  17427. $blt = $this->dec2alpha($this->listnum,true).$this->list_number_suffix;
  17428. break;
  17429. case 'a':
  17430. $blt = $this->dec2alpha($this->listnum,false).$this->list_number_suffix;
  17431. break;
  17432. case 'I':
  17433. $blt = $this->dec2roman($this->listnum,true).$this->list_number_suffix;
  17434. break;
  17435. case 'i':
  17436. $blt = $this->dec2roman($this->listnum,false).$this->list_number_suffix;
  17437. break;
  17438. case '1':
  17439. $blt = $this->listnum.$this->list_number_suffix;
  17440. break;
  17441. default:
  17442. // mPDF 5.0
  17443. if ($this->listlvl % 3 == 1 && $this->_charDefined($this->CurrentFont['cw'],8226)) { $blt = "\xe2\x80\xa2"; } // &#8226;
  17444. else if ($this->listlvl % 3 == 2 && $this->_charDefined($this->CurrentFont['cw'],9900)) { $blt = "\xe2\x9a\xac"; } // &#9900;
  17445. else if ($this->listlvl % 3 == 0 && $this->_charDefined($this->CurrentFont['cw'],9642)) { $blt = "\xe2\x96\xaa"; } // &#9642;
  17446. else { $blt = '-'; }
  17447. break;
  17448. }
  17449. // change to &nbsp; spaces
  17450. if ($this->usingCoreFont) {
  17451. $ls = str_repeat(chr(160).chr(160),($this->listlvl-1)*2) . $blt . ' ';
  17452. }
  17453. else {
  17454. $ls = str_repeat("\xc2\xa0\xc2\xa0",($this->listlvl-1)*2) . $blt . ' ';
  17455. }
  17456. $this->cell[$this->row][$this->col]['textbuffer'][] = array($ls,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  17457. $this->cell[$this->row][$this->col]['text'][] = $ls;
  17458. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($ls);
  17459. break;
  17460. }
  17461. /*-- END TABLES --*/
  17462. //Observation: </LI> is ignored
  17463. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  17464. //First of all, skip a line
  17465. $this->listlvl++; // first depth level
  17466. $this->listnum = 0; // reset
  17467. $this->listoccur[$this->listlvl] = 1;
  17468. $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  17469. }
  17470. if ($this->listnum == 0) {
  17471. $this->listnum++;
  17472. $this->textbuffer = array();
  17473. }
  17474. else {
  17475. if (!empty($this->textbuffer)) {
  17476. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17477. $this->listnum++;
  17478. }
  17479. $this->textbuffer = array();
  17480. }
  17481. $this->listCSSlvl++;
  17482. $properties = $this->MergeCSS('LIST',$tag,$attr);
  17483. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  17484. $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listoccur[$this->listlvl]][$this->listnum] = $this->saveInlineProperties();
  17485. // List-type
  17486. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listitemtype = $attr['TYPE']; }
  17487. else if (isset($properties['LIST-STYLE-TYPE'])) {
  17488. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  17489. }
  17490. else if (isset($properties['LIST-STYLE'])) {
  17491. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE']);
  17492. }
  17493. else $this->listitemtype = '';
  17494. break;
  17495. /*-- END LISTS --*/
  17496. }//end of switch
  17497. }
  17498. /*-- LISTS --*/
  17499. function _getListStyle($ls) {
  17500. if (stristr($ls,'decimal')) { return '1'; }
  17501. // mPDF 5.0.057
  17502. /* CSS3 list-styles numeric (selected) + I added tamil
  17503. arabic-indic | bengali | devanagari | gujarati | gurmukhi | kannada | malayalam | oriya | persian | telugu | thai | urdu
  17504. */
  17505. else if (preg_match('/(disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu)/i',$ls,$m)) {
  17506. return strtolower(trim($m[1]));
  17507. }
  17508. else if (stristr($ls,'lower-roman')) { return 'i'; }
  17509. else if (stristr($ls,'upper-roman')) { return 'I'; }
  17510. else if (stristr($ls,'lower-latin')|| stristr($ls,'lower-alpha')) { return 'a'; }
  17511. else if (stristr($ls,'upper-latin') || stristr($ls,'upper-alpha')) { return 'A'; }
  17512. else if (stristr($ls,'none')) { return 'none'; }
  17513. // mPDF 5.1.018
  17514. else if (preg_match('/U\+([a-fA-F0-9]+)/i',$ls)) { return $ls; }
  17515. else { return ''; }
  17516. }
  17517. /*-- END LISTS --*/
  17518. function CloseTag($tag)
  17519. {
  17520. $this->ignorefollowingspaces = false; //Eliminate exceeding left-side spaces
  17521. //Closing tag
  17522. if($tag=='OPTION') { $this->selectoption['ACTIVE'] = false; $this->lastoptionaltag = ''; }
  17523. if($tag=='TTS' or $tag=='TTA' or $tag=='TTZ') {
  17524. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  17525. unset($this->InlineProperties[$tag]);
  17526. $ltag = strtolower($tag);
  17527. $this->$ltag = false;
  17528. }
  17529. if($tag=='FONT' || $tag=='SPAN' || $tag=='CODE' || $tag=='KBD' || $tag=='SAMP' || $tag=='TT' || $tag=='VAR'
  17530. || $tag=='INS' || $tag=='STRONG' || $tag=='CITE' || $tag=='SUB' || $tag=='SUP' || $tag=='S' || $tag=='STRIKE' || $tag=='DEL'
  17531. || $tag=='Q' || $tag=='EM' || $tag=='B' || $tag=='I' || $tag=='U' | $tag=='SMALL' || $tag=='BIG' || $tag=='ACRONYM') {
  17532. if ($tag == 'SPAN') {
  17533. if (isset($this->InlineProperties['SPAN'][$this->spanlvl]) && $this->InlineProperties['SPAN'][$this->spanlvl]) { $this->restoreInlineProperties($this->InlineProperties['SPAN'][$this->spanlvl]); }
  17534. unset($this->InlineProperties['SPAN'][$this->spanlvl]);
  17535. if (isset($this->InlineAnnots['SPAN'][$this->spanlvl]) && $this->InlineAnnots['SPAN'][$this->spanlvl]) { $annot = $this->InlineAnnots['SPAN'][$this->spanlvl]; } // *ANNOTATIONS*
  17536. unset($this->InlineAnnots['SPAN'][$this->spanlvl]); // *ANNOTATIONS*
  17537. $this->spanlvl--;
  17538. }
  17539. else {
  17540. if (isset($this->InlineProperties[$tag]) && $this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  17541. unset($this->InlineProperties[$tag]);
  17542. if (isset($this->InlineAnnots[$tag]) && $this->InlineAnnots[$tag]) { $annot = $this->InlineAnnots[$tag]; } // *ANNOTATIONS*
  17543. unset($this->InlineAnnots[$tag]); // *ANNOTATIONS*
  17544. }
  17545. /*-- ANNOTATIONS --*/
  17546. if (isset($annot)) {
  17547. if($this->tableLevel) { // *TABLES*
  17548. $this->cell[$this->row][$this->col]['textbuffer'][] = array($annot); // *TABLES*
  17549. } // *TABLES*
  17550. else { // *TABLES*
  17551. $this->textbuffer[] = array($annot);
  17552. } // *TABLES*
  17553. }
  17554. /*-- END ANNOTATIONS --*/
  17555. }
  17556. if($tag=='A') {
  17557. $this->HREF='';
  17558. if (isset($this->InlineProperties['A'])) { $this->restoreInlineProperties($this->InlineProperties['A']); }
  17559. unset($this->InlineProperties['A']);
  17560. }
  17561. /*-- FORMS --*/
  17562. // *********** FORM ELEMENTS ********************
  17563. if($tag=='TEXTAREA') {
  17564. $this->specialcontent = '';
  17565. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  17566. unset($this->InlineProperties[$tag]);
  17567. }
  17568. if($tag=='SELECT') {
  17569. $this->lastoptionaltag = '';
  17570. $texto = '';
  17571. if (isset($this->selectoption['SELECTED'])) { $texto = $this->selectoption['SELECTED']; }
  17572. $w = $this->GetStringWidth($texto);
  17573. if ($w == 0) { $w = 5; }
  17574. $objattr['type'] = 'select'; // need to add into objattr
  17575. $objattr['text'] = $texto;
  17576. // mPDD 1.4 Active Forms
  17577. if (isset($this->selectoption['NAME'])) { $objattr['name'] = $this->selectoption['NAME']; }
  17578. if (isset($this->selectoption['ITEMS'])) { $objattr['items'] = $this->selectoption['ITEMS']; }
  17579. if (isset($this->selectoption['MULTIPLE'])) { $objattr['multiple'] = $this->selectoption['MULTIPLE']; }
  17580. if (isset($this->selectoption['DISABLED'])) { $objattr['disabled'] = $this->selectoption['DISABLED']; }
  17581. if (isset($this->selectoption['TITLE'])) { $objattr['title'] = $this->selectoption['TITLE']; }
  17582. if (isset($this->selectoption['COLOR'])) { $objattr['color'] = $this->selectoption['COLOR']; }
  17583. if (isset($this->selectoption['SIZE'])) { $objattr['size'] = $this->selectoption['SIZE']; }
  17584. if (isset($objattr['size']) && $objattr['size']>1) { $rows=$objattr['size']; } else { $rows = 1; }
  17585. $objattr['fontfamily'] = $this->FontFamily;
  17586. $objattr['fontsize'] = $this->FontSizePt;
  17587. $objattr['width'] = $w + ($this->form_element_spacing['select']['outer']['h']*2)+($this->form_element_spacing['select']['inner']['h']*2) + ($this->FontSize*1.4);
  17588. $objattr['height'] = ($this->FontSize*$rows) + ($this->form_element_spacing['select']['outer']['v']*2)+($this->form_element_spacing['select']['inner']['v']*2);
  17589. $e = "\xbb\xa4\xactype=select,objattr=".serialize($objattr)."\xbb\xa4\xac";
  17590. // Clear properties - tidy up
  17591. $properties = array();
  17592. // Output it to buffers
  17593. if ($this->tableLevel) { // *TABLES*
  17594. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063 // *TABLES*
  17595. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  17596. } // *TABLES*
  17597. else { // *TABLES*
  17598. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  17599. } // *TABLES*
  17600. $this->selectoption = array();
  17601. $this->specialcontent = '';
  17602. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  17603. unset($this->InlineProperties[$tag]);
  17604. }
  17605. /*-- END FORMS --*/
  17606. // *********** BLOCKS ********************
  17607. if($tag=='P' || $tag=='DIV' || $tag=='H1' || $tag=='H2' || $tag=='H3' || $tag=='H4' || $tag=='H5' || $tag=='H6' || $tag=='PRE'
  17608. || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DT' || $tag=='DD' || $tag=='DL' ) {
  17609. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17610. $this->blockjustfinished=true;
  17611. $this->lastblockbottommargin = $this->blk[$this->blklvl]['margin_bottom'];
  17612. /*-- LISTS --*/
  17613. if ($this->listlvl>0) { return; }
  17614. /*-- END LISTS --*/
  17615. /*-- TABLES --*/
  17616. if($this->tableLevel) {
  17617. if ($this->linebreakjustfinished) { $this->blockjustfinished=false; }
  17618. if (isset($this->InlineProperties['BLOCKINTABLE'])) {
  17619. if ($this->InlineProperties['BLOCKINTABLE']) { $this->restoreInlineProperties($this->InlineProperties['BLOCKINTABLE']); }
  17620. unset($this->InlineProperties['BLOCKINTABLE']);
  17621. }
  17622. if($tag=='PRE') { $this->ispre=false; } // mPDF 5.0.057
  17623. return;
  17624. }
  17625. /*-- END TABLES --*/
  17626. $this->lastoptionaltag = '';
  17627. $this->divbegin=false;
  17628. $this->linebreakjustfinished=false;
  17629. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17630. /*-- CSS-FLOAT --*/
  17631. // If float contained in a float, need to extend bottom to allow for it
  17632. $currpos = $this->page*1000 + $this->y;
  17633. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  17634. $old_page = $this->page;
  17635. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  17636. if ($old_page != $new_page) {
  17637. $s = $this->PrintPageBackgrounds();
  17638. // Writes after the marker so not overwritten later by page background etc.
  17639. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  17640. $this->pageBackgrounds = array();
  17641. $this->page = $new_page;
  17642. $this->ResetMargins();
  17643. $this->Reset();
  17644. $this->pageoutput[$this->page] = array();
  17645. }
  17646. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  17647. }
  17648. /*-- END CSS-FLOAT --*/
  17649. //Print content
  17650. if ($this->lastblocklevelchange == 1) { $blockstate = 3; } // Top & bottom margins/padding
  17651. else if ($this->lastblocklevelchange == -1) { $blockstate = 2; } // Bottom margins/padding only
  17652. else { $blockstate = 0; }
  17653. // called from after e.g. </table> </div> </div> ... Outputs block margin/border and padding
  17654. if (count($this->textbuffer) && $this->textbuffer[count($this->textbuffer)-1]) {
  17655. if (substr($this->textbuffer[count($this->textbuffer)-1][0],0,3) != "\xbb\xa4\xac") { // not special content
  17656. if ($this->usingCoreFont) {
  17657. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/', '', $this->textbuffer[count($this->textbuffer)-1][0]);
  17658. }
  17659. else {
  17660. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/u', '', $this->textbuffer[count($this->textbuffer)-1][0]); }
  17661. }
  17662. }
  17663. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange != 0) {
  17664. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,2,true, $this->blk[$this->blklvl]['direction']); // mPDF 5.0.054
  17665. $this->finishFlowingBlock(true); // true = END of flowing block
  17666. $this->PaintDivBB('',$blockstate);
  17667. }
  17668. else {
  17669. $this->printbuffer($this->textbuffer,$blockstate);
  17670. }
  17671. $this->textbuffer=array();
  17672. if ($this->blk[$this->blklvl]['keep_block_together']) {
  17673. $this->printdivbuffer();
  17674. }
  17675. if ($this->kwt) {
  17676. $this->kwt_height = $this->y - $this->kwt_y0;
  17677. }
  17678. /*-- CSS-IMAGE-FLOAT --*/
  17679. $this->printfloatbuffer();
  17680. /*-- END CSS-IMAGE-FLOAT --*/
  17681. if($tag=='PRE') { $this->ispre=false; }
  17682. /*-- CSS-FLOAT --*/
  17683. if ($this->blk[$this->blklvl]['float'] == 'R') {
  17684. // If width not set, here would need to adjust and output buffer
  17685. $s = $this->PrintPageBackgrounds();
  17686. // Writes after the marker so not overwritten later by page background etc.
  17687. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  17688. $this->pageBackgrounds = array();
  17689. $this->Reset();
  17690. $this->pageoutput[$this->page] = array();
  17691. for($i=($this->blklvl-1); $i >= 0; $i--) {
  17692. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  17693. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  17694. }
  17695. $this->floatDivs[] = array(
  17696. 'side'=>'R',
  17697. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  17698. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  17699. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  17700. 'endpage'=>$this->page ,
  17701. 'y1'=>$this->y ,
  17702. 'endpos'=> ($this->page*1000 + $this->y),
  17703. 'w'=> $this->blk[$this->blklvl]['float_width'],
  17704. 'blklvl'=>$this->blklvl,
  17705. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  17706. );
  17707. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  17708. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  17709. $this->ResetMargins();
  17710. $this->pageoutput[$this->page] = array();
  17711. }
  17712. if ($this->blk[$this->blklvl]['float'] == 'L') {
  17713. // If width not set, here would need to adjust and output buffer
  17714. $s = $this->PrintPageBackgrounds();
  17715. // Writes after the marker so not overwritten later by page background etc.
  17716. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  17717. $this->pageBackgrounds = array();
  17718. $this->Reset();
  17719. $this->pageoutput[$this->page] = array();
  17720. for($i=($this->blklvl-1); $i >= 0; $i--) {
  17721. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  17722. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  17723. }
  17724. $this->floatDivs[] = array(
  17725. 'side'=>'L',
  17726. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  17727. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  17728. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  17729. 'endpage'=>$this->page ,
  17730. 'y1'=>$this->y ,
  17731. 'endpos'=> ($this->page*1000 + $this->y),
  17732. 'w'=> $this->blk[$this->blklvl]['float_width'],
  17733. 'blklvl'=>$this->blklvl,
  17734. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  17735. );
  17736. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  17737. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  17738. $this->ResetMargins();
  17739. $this->pageoutput[$this->page] = array();
  17740. }
  17741. /*-- END CSS-FLOAT --*/
  17742. //Reset values
  17743. $this->Reset();
  17744. if ($this->blklvl > 0) { // ==0 SHOULDN'T HAPPEN - NOT XHTML
  17745. if ($this->blk[$this->blklvl]['tag'] == $tag) {
  17746. unset($this->blk[$this->blklvl]);
  17747. $this->blklvl--;
  17748. }
  17749. //else { echo $tag; exit; } // debug - forces error if incorrectly nested html tags
  17750. }
  17751. $this->lastblocklevelchange = -1 ;
  17752. // Reset Inline-type properties
  17753. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']); }
  17754. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17755. }
  17756. /*-- TABLES --*/
  17757. if($tag=='TH') $this->SetStyle('B',false);
  17758. if(($tag=='TH' or $tag=='TD') && $this->tableLevel) {
  17759. $this->lastoptionaltag = 'TR';
  17760. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17761. $this->tbCSSlvl--;
  17762. $this->tdbegin = false;
  17763. // Added for correct calculation of cell column width - otherwise misses the last line if not end </p> etc.
  17764. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17765. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17766. }
  17767. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17768. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17769. }
  17770. // Remove last <br> if at end of cell
  17771. if (isset($this->cell[$this->row][$this->col]['textbuffer'])) { $ntb = count($this->cell[$this->row][$this->col]['textbuffer']); }
  17772. else { $ntb = 0; }
  17773. if ($ntb>1 && $this->cell[$this->row][$this->col]['textbuffer'][$ntb-1][0] == "\n") {
  17774. unset($this->cell[$this->row][$this->col]['textbuffer'][$ntb-1]);
  17775. }
  17776. if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; }
  17777. if ($this->usetableheader && ($this->row == 0 || $this->tablethead) && $this->tableLevel==1) {
  17778. $this->tableheadernrows = max($this->tableheadernrows, ($this->row+1));
  17779. }
  17780. if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; }
  17781. if ($this->tabletfoot && $this->tableLevel==1) {
  17782. $this->tablefooternrows = max($this->tablefooternrows, ($this->row+1 - $this->tableheadernrows));
  17783. }
  17784. $this->Reset();
  17785. }
  17786. if($tag=='TR' && $this->tableLevel) {
  17787. // mPDF 5.0.003 Border set on TR
  17788. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row])) {
  17789. $left = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row]);
  17790. $right = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row]);
  17791. $top = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-top'][$this->row]);
  17792. $bottom = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-bottom'][$this->row]);
  17793. for ($j=0; $j<=$this->col; $j++) {
  17794. $c =& $this->cell[$this->row][$j];
  17795. if ($this->packTableData) {
  17796. $cell = $this->_unpackCellBorder($c['borderbin'] );
  17797. }
  17798. else { $cell = $c; }
  17799. if ($cell) { // mpDF 5.0.021
  17800. if ($j==$this->col) {
  17801. $cell['border_details']['R'] = $right;
  17802. $this->setBorder($cell['border'], _BORDER_RIGHT, $cell['border_details']['R']['s']);
  17803. }
  17804. if ($j==0) {
  17805. $cell['border_details']['L'] = $left;
  17806. $this->setBorder($cell['border'], _BORDER_LEFT, $cell['border_details']['L']['s']);
  17807. }
  17808. $cell['border_details']['B'] = $bottom;
  17809. $this->setBorder($cell['border'], _BORDER_BOTTOM, $cell['border_details']['B']['s']);
  17810. $cell['border_details']['T'] = $top;
  17811. $this->setBorder($cell['border'], _BORDER_TOP, $cell['border_details']['T']['s']);
  17812. if ($this->packTableData) {
  17813. $c['borderbin'] = $this->_packCellBorder($cell);
  17814. unset($c['border']);
  17815. unset($c['border_details']);
  17816. }
  17817. else { $c = $cell; }
  17818. }
  17819. }
  17820. }
  17821. $this->lastoptionaltag = '';
  17822. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17823. $this->tbCSSlvl--;
  17824. $this->trow_text_rotate = '';
  17825. $this->tabletheadjustfinished = false;
  17826. }
  17827. if($tag=='TBODY') {
  17828. $this->lastoptionaltag = '';
  17829. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17830. $this->tbCSSlvl--;
  17831. }
  17832. if($tag=='THEAD') {
  17833. $this->lastoptionaltag = '';
  17834. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17835. $this->tbCSSlvl--;
  17836. $this->tablethead = 0;
  17837. $this->tabletheadjustfinished = true;
  17838. $this->ResetStyles(); // mPDF 5.0
  17839. $this->thead_font_weight = '';
  17840. $this->thead_font_style = '';
  17841. $this->thead_font_smCaps = '';
  17842. $this->thead_valign_default = '';
  17843. $this->thead_textalign_default = '';
  17844. }
  17845. if($tag=='TFOOT') {
  17846. $this->lastoptionaltag = '';
  17847. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17848. $this->tbCSSlvl--;
  17849. $this->tabletfoot = 0;
  17850. $this->ResetStyles(); // mPDF 5.0
  17851. $this->tfoot_font_weight = '';
  17852. $this->tfoot_font_style = '';
  17853. $this->tfoot_font_smCaps = '';
  17854. $this->tfoot_valign_default = '';
  17855. $this->tfoot_textalign_default = '';
  17856. }
  17857. if($tag=='TABLE') { // TABLE-END (
  17858. if ($this->progressBar) { $this->UpdateProgressBar(1,'','TABLE'); } // *PROGRESS-BAR*
  17859. if ($this->progressBar) { $this->UpdateProgressBar(7,0,''); } // *PROGRESS-BAR*
  17860. $this->lastoptionaltag = '';
  17861. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17862. $this->tbCSSlvl--;
  17863. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17864. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  17865. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['wc'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'],array('miw'=>0,'maw'=>0));
  17866. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['hr'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr'],0);
  17867. // Move table footer <tfoot> row to end of table
  17868. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) && count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'])) {
  17869. $tfrows = array();
  17870. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] AS $r=>$val) {
  17871. if ($val) { $tfrows[] = $r; }
  17872. }
  17873. $temp = array();
  17874. $temptf = array();
  17875. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] AS $k=>$row) {
  17876. if (in_array($k,$tfrows)) {
  17877. $temptf[] = $row;
  17878. }
  17879. else {
  17880. $temp[] = $row;
  17881. }
  17882. }
  17883. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] = array();
  17884. for($i=count($temp) ; $i<(count($temp)+count($temptf)); $i++) {
  17885. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$i] = true;
  17886. }
  17887. // Update nestedpos row references
  17888. if (count($this->table[($this->tableLevel+1)])) {
  17889. foreach($this->table[($this->tableLevel+1)] AS $nid=>$nested) {
  17890. $this->table[($this->tableLevel+1)][$nid]['nestedpos'][0] -= count($temptf);
  17891. }
  17892. }
  17893. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = array_merge($temp, $temptf);
  17894. // Update other arays set on row number // mPDF 5.0.018
  17895. // [trbackground-images] [trgradients]
  17896. $temptrbgi = array();
  17897. $temptrbgg = array();
  17898. $temptrbgc = array(); // mPDF 5.1.008
  17899. $temptrbgc[-1] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][-1]; // mPDF 5.1.008
  17900. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  17901. if (!in_array($k,$tfrows)) {
  17902. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  17903. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  17904. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k]; // mPDF 5.1.008
  17905. }
  17906. }
  17907. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  17908. if (in_array($k,$tfrows)) {
  17909. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  17910. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  17911. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k]; // mPDF 5.1.008
  17912. }
  17913. }
  17914. // mPDF 5.1.008
  17915. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'] = $temptrbgi;
  17916. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'] = $temptrbgg;
  17917. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'] = $temptrbgc ; // mPDF 5.1.008
  17918. // Should Update all other arays set on row number, but cell properties have been set so not needed
  17919. // [bgcolor] [trborder-left] [trborder-right] [trborder-top] [trborder-bottom]
  17920. }
  17921. // mPDF 5.0.055
  17922. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']=='rtl') {
  17923. $this->_reverseTableDir($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  17924. }
  17925. // Fix Borders *********************************************
  17926. $this->_fixTableBorders($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  17927. if ($this->progressBar) { $this->UpdateProgressBar(7,10,' '); } // *PROGRESS-BAR*
  17928. if ($this->ColActive) { $this->table_rotate = 0; } // *COLUMNS*
  17929. if ($this->table_rotate <> 0) {
  17930. $this->tablebuffer = '';
  17931. // Max width for rotated table
  17932. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 1); // mPDF 5.0.009
  17933. $this->tbrot_maxh = $this->blk[$this->blklvl]['inner_width'] ; // Max width for rotated table
  17934. $this->tbrot_align = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['a'] ;
  17935. }
  17936. $this->shrin_k = 1;
  17937. if ($this->shrink_tables_to_fit < 1) { $this->shrink_tables_to_fit = 1; }
  17938. if (!$this->shrink_this_table_to_fit) { $this->shrink_this_table_to_fit = $this->shrink_tables_to_fit; }
  17939. if ($this->tableLevel>1) {
  17940. // deal with nested table
  17941. $this->_tableColumnWidth($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]],true);
  17942. $tmiw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['miw'];
  17943. $tmaw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['maw'];
  17944. $tl = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tl'];
  17945. // Go down to lower table level
  17946. $this->tableLevel--;
  17947. // Reset lower level table
  17948. $this->base_table_properties = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties'];
  17949. $this->cell = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'];
  17950. $this->row = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'];
  17951. $this->col = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'];
  17952. $objattr = array();
  17953. $objattr['type'] = 'nestedtable';
  17954. $objattr['nestedcontent'] = $this->tbctr[($this->tableLevel+1)];
  17955. $objattr['table'] = $this->tbctr[$this->tableLevel];
  17956. $objattr['row'] = $this->row;
  17957. $objattr['col'] = $this->col;
  17958. $objattr['level'] = $this->tableLevel;
  17959. $e = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  17960. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  17961. $this->cell[$this->row][$this->col]['s'] += $tl ;
  17962. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17963. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17964. }
  17965. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17966. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17967. }
  17968. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  17969. if ((isset($this->cell[$this->row][$this->col]['nestedmaw']) && $this->cell[$this->row][$this->col]['nestedmaw'] < $tmaw) || !isset($this->cell[$this->row][$this->col]['nestedmaw'])) { $this->cell[$this->row][$this->col]['nestedmaw'] = $tmaw ; }
  17970. if ((isset($this->cell[$this->row][$this->col]['nestedmiw']) && $this->cell[$this->row][$this->col]['nestedmiw'] < $tmiw) || !isset($this->cell[$this->row][$this->col]['nestedmiw'])) { $this->cell[$this->row][$this->col]['nestedmiw'] = $tmiw ; }
  17971. $this->cell[$this->row][$this->col]['nestedcontent'][] = $this->tbctr[($this->tableLevel+1)];
  17972. $this->tdbegin = true;
  17973. $this->nestedtablejustfinished = true;
  17974. $this->ignorefollowingspaces = true;
  17975. return;
  17976. }
  17977. $this->cMarginL = 0;
  17978. $this->cMarginR = 0;
  17979. $this->cMarginT = 0;
  17980. $this->cMarginB = 0;
  17981. $this->cellPaddingL = 0;
  17982. $this->cellPaddingR = 0;
  17983. $this->cellPaddingT = 0;
  17984. $this->cellPaddingB = 0;
  17985. if (!$this->kwt_saved) { $this->kwt_height = 0; }
  17986. list($check,$tablemiw) = $this->_tableColumnWidth($this->table[1][1],true);
  17987. $save_table = $this->table;
  17988. $reset_to_minimum_width = false;
  17989. $added_page = false;
  17990. if ($check > 1) {
  17991. if ($check > $this->shrink_this_table_to_fit && $this->table_rotate) {
  17992. $this->AddPage($this->CurOrientation);
  17993. $this->kwt_moved = true;
  17994. $added_page = true;
  17995. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17996. //$check = $tablemiw/$this->tbrot_maxw; // undo any shrink
  17997. $check = 1; // undo any shrink
  17998. }
  17999. $reset_to_minimum_width = true;
  18000. }
  18001. if ($reset_to_minimum_width) {
  18002. $this->shrin_k = $check;
  18003. $this->default_font_size /= $this->shrin_k;
  18004. $this->SetFontSize($this->default_font_size, false );
  18005. $this->shrinkTable($this->table[1][1],$this->shrin_k);
  18006. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  18007. // Starting at $this->innermostTableLevel
  18008. // Shrink table values - and redo columnWidth
  18009. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  18010. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  18011. $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k);
  18012. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  18013. }
  18014. }
  18015. }
  18016. // Set table cell widths for top level table
  18017. // Use $shrin_k to resize but don't change again
  18018. $this->SetLineHeight('',$this->table_lineheight);
  18019. // Top level table
  18020. $this->_tableWidth($this->table[1][1]);
  18021. // Now work through any nested tables setting child table[w'] = parent cell['w']
  18022. // Now do nested tables _tableWidth
  18023. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  18024. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  18025. // HERE set child table width = cell width
  18026. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  18027. if (isset($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']) && $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']> 1) {
  18028. $parentwidth = 0;
  18029. for($cs=0;$cs<$this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan'] ; $cs++) {
  18030. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  18031. }
  18032. }
  18033. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  18034. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  18035. if (!$this->simpleTables){
  18036. if ($this->packTableData) {
  18037. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['borderbin']);
  18038. }
  18039. else {
  18040. $br = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['R']['w'];
  18041. $bl = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['L']['w'];
  18042. }
  18043. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  18044. $parentwidth -= $br + $bl
  18045. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18046. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  18047. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  18048. }
  18049. else {
  18050. $parentwidth -= $br/2 + $bl/2
  18051. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18052. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  18053. }
  18054. }
  18055. else if ($this->simpleTables){
  18056. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  18057. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  18058. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  18059. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18060. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  18061. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  18062. }
  18063. else {
  18064. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']/2
  18065. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']/2
  18066. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18067. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  18068. }
  18069. }
  18070. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  18071. $this->table[$lvl][$nid]['w'] = $parentwidth;
  18072. }
  18073. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  18074. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'];
  18075. }
  18076. else {
  18077. $this->table[$lvl][$nid]['w'] = $parentwidth;
  18078. }
  18079. $this->_tableWidth($this->table[$lvl][$nid]);
  18080. }
  18081. }
  18082. // Starting at $this->innermostTableLevel
  18083. // Cascade back up nested tables: setting heights back up the tree
  18084. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  18085. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  18086. // mPDF 5.0.014
  18087. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  18088. }
  18089. if ($this->progressBar) { $this->UpdateProgressBar(7,20,' '); } // *PROGRESS-BAR*
  18090. $recalculate = 1;
  18091. $forcerecalc = false;
  18092. // RESIZING ALGORITHM
  18093. if ($maxrowheight > $fullpage) {
  18094. $recalculate = $this->tbsqrt($maxrowheight / $fullpage, 1);
  18095. $forcerecalc = true;
  18096. }
  18097. else if ($this->table_rotate) { // NB $remainingpage == $fullpage == the width of the page
  18098. if ($tableheight > $remainingpage) {
  18099. // If can fit on remainder of page whilst respecting autsize value..
  18100. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  18101. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  18102. }
  18103. else if (!$added_page) {
  18104. $this->AddPage($this->CurOrientation);
  18105. $added_page = true;
  18106. $this->kwt_moved = true;
  18107. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  18108. // 0.001 to force it to recalculate
  18109. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  18110. }
  18111. }
  18112. else { $recalculate = 1; } // mPDF 5.0.002
  18113. }
  18114. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) { // mPDF 5.0.002) {
  18115. if ($tableheight > $fullpage) {
  18116. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, 1)) <= $this->shrink_this_table_to_fit) {
  18117. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  18118. }
  18119. else if ($this->tableMinSizePriority) {
  18120. $this->table_keep_together = false;
  18121. $recalculate = 1.001;
  18122. }
  18123. else {
  18124. if ($this->y != $this->tMargin) { // mPDF 5.1
  18125. $this->AddPage($this->CurOrientation);
  18126. $this->kwt_moved = true;
  18127. }
  18128. $added_page = true;
  18129. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  18130. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  18131. }
  18132. }
  18133. else if ($tableheight > $remainingpage) {
  18134. // If can fit on remainder of page whilst respecting autsize value..
  18135. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  18136. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  18137. }
  18138. else {
  18139. if ($this->y != $this->tMargin) { // mPDF 5.0.002
  18140. $this->AddPage($this->CurOrientation);
  18141. $this->kwt_moved = true;
  18142. }
  18143. $added_page = true;
  18144. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  18145. // mPDF 5.1.014
  18146. //$recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  18147. $recalculate = 1.001;
  18148. }
  18149. }
  18150. else { $recalculate = 1; } // mPDF 5.0.002
  18151. }
  18152. else { $recalculate = 1; }
  18153. if ($recalculate > $this->shrink_this_table_to_fit && !$forcerecalc) { $recalculate = $this->shrink_this_table_to_fit; }
  18154. $iteration = 1;
  18155. // RECALCULATE
  18156. while($recalculate <> 1) {
  18157. $this->shrin_k1 = $recalculate ;
  18158. $this->shrin_k *= $recalculate ;
  18159. $this->default_font_size /= ($this->shrin_k1) ;
  18160. $this->SetFontSize($this->default_font_size, false );
  18161. $this->SetLineHeight('',$this->table_lineheight);
  18162. $this->table = $save_table;
  18163. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[1][1],$this->shrin_k); }
  18164. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  18165. // Starting at $this->innermostTableLevel
  18166. // Shrink table values - and redo columnWidth
  18167. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  18168. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  18169. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k); }
  18170. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  18171. }
  18172. }
  18173. // Set table cell widths for top level table
  18174. // Top level table
  18175. $this->_tableWidth($this->table[1][1]);
  18176. // Now work through any nested tables setting child table[w'] = parent cell['w']
  18177. // Now do nested tables _tableWidth
  18178. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  18179. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  18180. // HERE set child table width = cell width
  18181. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  18182. if (isset($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']) && $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']> 1) {
  18183. $parentwidth = 0;
  18184. for($cs=0;$cs<$this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan'] ; $cs++) {
  18185. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  18186. }
  18187. }
  18188. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  18189. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  18190. if (!$this->simpleTables){
  18191. if ($this->packTableData) {
  18192. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['borderbin']);
  18193. }
  18194. else {
  18195. $br = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['R']['w'];
  18196. $bl = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['L']['w'];
  18197. }
  18198. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  18199. $parentwidth -= $br + $bl
  18200. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18201. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  18202. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  18203. }
  18204. else {
  18205. $parentwidth -= $br/2 + $bl/2
  18206. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18207. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  18208. }
  18209. }
  18210. else if ($this->simpleTables){
  18211. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  18212. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  18213. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  18214. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18215. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  18216. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  18217. }
  18218. else {
  18219. $parentwidth -= ($this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  18220. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']) /2
  18221. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  18222. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  18223. }
  18224. }
  18225. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  18226. $this->table[$lvl][$nid]['w'] = $parentwidth;
  18227. }
  18228. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  18229. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'] ;
  18230. }
  18231. else {
  18232. $this->table[$lvl][$nid]['w'] = $parentwidth;
  18233. }
  18234. $this->_tableWidth($this->table[$lvl][$nid]);
  18235. }
  18236. }
  18237. // Starting at $this->innermostTableLevel
  18238. // Cascade back up nested tables: setting heights back up the tree
  18239. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  18240. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  18241. // mPDF 5.0.014
  18242. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  18243. }
  18244. // RESIZING ALGORITHM
  18245. if ($maxrowheight > $fullpage) { $recalculate = $this->tbsqrt($maxrowheight / $fullpage, $iteration); $iteration++; }
  18246. else if ($this->table_rotate && $tableheight > $remainingpage && !$added_page) {
  18247. // If can fit on remainder of page whilst respecting autosize value..
  18248. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  18249. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  18250. }
  18251. else {
  18252. if (!$added_page) {
  18253. $this->AddPage($this->CurOrientation);
  18254. $added_page = true;
  18255. $this->kwt_moved = true;
  18256. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  18257. }
  18258. // 0.001 to force it to recalculate
  18259. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  18260. }
  18261. }
  18262. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) { // mPDF 5.0.002
  18263. if ($tableheight > $fullpage) {
  18264. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  18265. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  18266. }
  18267. else if ($this->tableMinSizePriority) {
  18268. $this->table_keep_together = false;
  18269. $recalculate = (1 / $this->shrin_k) + 0.001;
  18270. }
  18271. else {
  18272. if (!$added_page && $this->y != $this->tMargin) { // mPDF 5.0.002
  18273. $this->AddPage($this->CurOrientation);
  18274. $added_page = true;
  18275. $this->kwt_moved = true;
  18276. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  18277. }
  18278. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  18279. }
  18280. }
  18281. else if ($tableheight > $remainingpage) {
  18282. // If can fit on remainder of page whilst respecting autosize value..
  18283. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  18284. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  18285. }
  18286. else {
  18287. if (!$added_page) {
  18288. $this->AddPage($this->CurOrientation);
  18289. $added_page = true;
  18290. $this->kwt_moved = true;
  18291. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  18292. }
  18293. //$recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  18294. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  18295. }
  18296. }
  18297. else { $recalculate = 1; }
  18298. }
  18299. else { $recalculate = 1; }
  18300. }
  18301. // mPDF 5.0.014 // mPDF 5.0.051 // mPDF 5.0.056
  18302. if ($maxfirstrowheight > $remainingpage && !$added_page && !$this->table_rotate && !$this->ColActive && !$this->table_keep_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  18303. $this->AddPage($this->CurOrientation);
  18304. $this->kwt_moved = true; // mPDF 5.0.034
  18305. }
  18306. // keep-with-table: if page has advanced, print out buffer now, else done in fn. _Tablewrite()
  18307. if ($this->kwt_saved && $this->kwt_moved) {
  18308. $this->printkwtbuffer();
  18309. $this->kwt_moved = false;
  18310. $this->kwt_saved = false;
  18311. }
  18312. if ($this->progressBar) { $this->UpdateProgressBar(7,30,' '); } // *PROGRESS-BAR*
  18313. // Recursively writes all tables starting at top level
  18314. $this->_tableWrite($this->table[1][1]);
  18315. if ($this->table_rotate && $this->tablebuffer) {
  18316. $this->PageBreakTrigger=$this->h-$this->bMargin;
  18317. $save_tr = $this->table_rotate;
  18318. $save_y = $this->y;
  18319. $this->table_rotate = 0;
  18320. $this->y = $this->tbrot_y0;
  18321. $h = $this->tbrot_w;
  18322. $this->DivLn($h,$this->blklvl,true);
  18323. $this->table_rotate = $save_tr;
  18324. $this->y = $save_y;
  18325. $this->printtablebuffer();
  18326. }
  18327. $this->table_rotate = 0;
  18328. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  18329. $this->blockjustfinished=true;
  18330. $this->lastblockbottommargin = $this->table[1][1]['margin']['B'];
  18331. //Reset values
  18332. // Keep-with-table
  18333. $this->kwt = false;
  18334. $this->kwt_y0 = 0;
  18335. $this->kwt_x0 = 0;
  18336. $this->kwt_height = 0;
  18337. $this->kwt_buffer = array();
  18338. $this->kwt_Links = array();
  18339. $this->kwt_Annots = array();
  18340. $this->kwt_moved = false;
  18341. $this->kwt_saved = false;
  18342. $this->kwt_Reference = array();
  18343. $this->kwt_BMoutlines = array();
  18344. $this->kwt_toc = array();
  18345. $this->shrin_k = 1;
  18346. $this->shrink_this_table_to_fit = 0;
  18347. unset($this->table);
  18348. $this->table=array(); //array
  18349. $this->tableLevel=0;
  18350. $this->tbctr=array();
  18351. $this->innermostTableLevel=0;
  18352. $this->tbCSSlvl = 0;
  18353. $this->tablecascadeCSS = array();
  18354. unset($this->cell);
  18355. $this->cell=array(); //array
  18356. $this->col=-1; //int
  18357. $this->row=-1; //int
  18358. $this->Reset();
  18359. $this->cellPaddingL = 0;
  18360. $this->cellPaddingT = 0;
  18361. $this->cellPaddingR = 0;
  18362. $this->cellPaddingB = 0;
  18363. $this->cMarginL = 0;
  18364. $this->cMarginT = 0;
  18365. $this->cMarginR = 0;
  18366. $this->cMarginB = 0;
  18367. $this->default_font_size = $this->original_default_font_size;
  18368. $this->default_font = $this->original_default_font;
  18369. $this->SetFontSize($this->default_font_size, false);
  18370. $this->SetFont($this->default_font,'',0,false);
  18371. $this->SetLineHeight();
  18372. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  18373. if ($this->progressBar) { $this->UpdateProgressBar(7,100,' '); } // *PROGRESS-BAR*
  18374. }
  18375. /*-- END TABLES --*/
  18376. /*-- LISTS --*/
  18377. // *********** LISTS ********************
  18378. if($tag=='LI') {
  18379. $this->lastoptionaltag = '';
  18380. unset($this->listcascadeCSS[$this->listCSSlvl]);
  18381. $this->listCSSlvl--;
  18382. if (isset($this->listoccur[$this->listlvl]) && isset($this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]])) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]]); }
  18383. }
  18384. if(($tag=='UL') or ($tag=='OL')) {
  18385. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  18386. unset($this->listcascadeCSS[$this->listCSSlvl]);
  18387. $this->listCSSlvl--;
  18388. $this->lastoptionaltag = '';
  18389. /*-- TABLES --*/
  18390. // A simple list for inside a table
  18391. if($this->tableLevel) {
  18392. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  18393. unset($this->listlist[$this->listlvl]);
  18394. $this->listlvl--;
  18395. if (isset($this->listlist[$this->listlvl]['MAXNUM'])) { $this->listnum = $this->listlist[$this->listlvl]['MAXNUM']; } // restore previous levels
  18396. if ($this->listlvl == 0) { $this->listjustfinished = true; }
  18397. return;
  18398. }
  18399. /*-- END TABLES --*/
  18400. if ($this->listlvl > 1) { // returning one level
  18401. $this->listjustfinished=true;
  18402. if (!empty($this->textbuffer)) {
  18403. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  18404. }
  18405. else {
  18406. $this->listnum--;
  18407. }
  18408. $this->textbuffer = array();
  18409. $occur = $this->listoccur[$this->listlvl];
  18410. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  18411. $this->listlvl--;
  18412. $occur = $this->listoccur[$this->listlvl];
  18413. $this->listnum = $this->listlist[$this->listlvl][$occur]['MAXNUM']; // recover previous level's number
  18414. $this->listtype = $this->listlist[$this->listlvl][$occur]['TYPE']; // recover previous level's type
  18415. if ($this->InlineProperties['LIST'][$this->listlvl][$occur]) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$occur]); }
  18416. }
  18417. else { // We are closing the last OL/UL tag
  18418. if (!empty($this->textbuffer)) {
  18419. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  18420. }
  18421. else {
  18422. $this->listnum--;
  18423. }
  18424. $occur = $this->listoccur[$this->listlvl];
  18425. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum;
  18426. $this->textbuffer = array();
  18427. $this->listlvl--;
  18428. $this->printlistbuffer();
  18429. unset($this->InlineProperties['LIST']);
  18430. // SPACING AFTER LIST (Top level only)
  18431. $this->Ln(0);
  18432. if ($this->list_margin_bottom) {
  18433. $this->DivLn($this->list_margin_bottom,$this->blklvl,true,1); // collapsible
  18434. }
  18435. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  18436. $this->listjustfinished = true;
  18437. $this->listCSSlvl = 0;
  18438. $this->listcascadeCSS = array();
  18439. $this->blockjustfinished=true;
  18440. $this->lastblockbottommargin = $this->list_margin_bottom;
  18441. }
  18442. }
  18443. /*-- END LISTS --*/
  18444. }
  18445. /*-- TABLES --*/
  18446. // mPDF 5.0.002
  18447. // This function determines the shrink factor when resizing tables
  18448. // val is the table_height / page_height_available
  18449. // returns a scaling factor used as $shrin_k to resize the table
  18450. // Overcompensating will be quicker but may unnecessarily shrink table too much
  18451. // Undercompensating means it will reiterate more times (taking more processing time)
  18452. function tbsqrt($val, $iteration=3) {
  18453. $k = 4; // Alters number of iterations until it returns $val itself - Must be > 2
  18454. // Probably best guess and most accurate
  18455. if ($iteration==1) return sqrt($val);
  18456. // Faster than using sqrt (because it won't undercompensate), and gives reasonable results
  18457. //return 1+(($val-1)/2);
  18458. $x = 2-(($iteration-2)/($k-2));
  18459. if ($x == 0) { $ret = $val+0.00001; }
  18460. else if ($x < 0) { $ret = 1 + ( pow(2, ($iteration-2-$k))/1000 ); } // mPDF 5.0.002
  18461. else { $ret = 1+(($val-1)/$x); }
  18462. return $ret;
  18463. }
  18464. /*-- END TABLES --*/
  18465. /*-- LISTS --*/
  18466. function printlistbuffer() {
  18467. //Save x coordinate
  18468. $x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  18469. $this->cMarginL = 0;
  18470. $this->cMarginR = 0;
  18471. $currIndentLvl = -1;
  18472. $lastIndent = array();
  18473. $bak_page = $this->page;
  18474. $indent = 0;
  18475. foreach($this->listitem as $item)
  18476. {
  18477. // COLS
  18478. $oldcolumn = $this->CurrCol;
  18479. $this->bulletarray = array();
  18480. //Get list's buffered data
  18481. $this->listlvl = $lvl = $item[0];
  18482. $num = $item[1];
  18483. $this->textbuffer = $item[2];
  18484. $occur = $item[3];
  18485. if ($item[4]) { $type = $item[4]; } // listitemtype
  18486. else { $type = $this->listlist[$lvl][$occur]['TYPE']; }
  18487. $maxnum = $this->listlist[$lvl][$occur]['MAXNUM'];
  18488. $this->restoreInlineProperties($this->InlineProperties['LIST'][$lvl][$occur]);
  18489. $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); // force to write
  18490. $clh = $this->FontSize;
  18491. $this->SetLineHeight($this->FontSizePt,$this->list_lineheight[$lvl][$occur]);
  18492. $this->listOcc = $occur;
  18493. $this->listnum = $num;
  18494. // mPDF 5.0.054
  18495. if (isset($this->list_align[$this->listlvl][$occur])) { $this->divalign = $this->list_align[$this->listlvl][$occur]; }
  18496. else {
  18497. if ($this->blk[$this->blklvl]['direction']=='rtl') { $this->divalign = 'R'; }
  18498. else { $this->divalign = 'L'; }
  18499. }
  18500. // Set the bullet fontsize
  18501. $bullfs = $this->InlineProperties['LISTITEM'][$lvl][$occur][$num]['size'];
  18502. $space_width = $this->GetStringWidth(' ') * 1.5;
  18503. //Set default width & height values
  18504. $this->divwidth = $this->blk[$this->blklvl]['inner_width'];
  18505. $this->divheight = $this->lineheight;
  18506. $typefont = $this->FontFamily;
  18507. // mPDF 5.1.017 - throughout function (uses $list_item_marker instead of $type)
  18508. // mPDF 5.1.018
  18509. if (preg_match('/U\+([a-fA-F0-9]+)/i',$type,$m)) {
  18510. if ($this->_charDefined($this->CurrentFont['cw'],hexdec($m[1]))) { $list_item_marker = codeHex2utf($m[1]); }
  18511. else { $list_item_marker = '-'; }
  18512. $blt_width = $this->GetStringWidth($list_item_marker);
  18513. $typefont = '';
  18514. if (preg_match('/rgb\(.*?\)/',$type,$m)) {
  18515. $list_item_color = $this->ConvertColor($m[0]);
  18516. }
  18517. }
  18518. else {
  18519. $list_item_color = false;
  18520. switch($type) //Format type
  18521. {
  18522. case '1':
  18523. // mPDF 5.0.054
  18524. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  18525. else { $list_item_marker = $num . $this->list_number_suffix; }
  18526. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  18527. break;
  18528. case 'none':
  18529. $list_item_marker = '';
  18530. $blt_width = 0;
  18531. break;
  18532. case 'A':
  18533. $anum = $this->dec2alpha($num,true);
  18534. $maxnum = $this->dec2alpha($maxnum,true);
  18535. // mPDF 5.0.054
  18536. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18537. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18538. $blt_width = $this->GetStringWidth(str_repeat('W',strlen($maxnum)).$this->list_number_suffix);
  18539. break;
  18540. case 'a':
  18541. $anum = $this->dec2alpha($num,false);
  18542. $maxnum = $this->dec2alpha($maxnum,false);
  18543. // mPDF 5.0.054
  18544. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18545. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18546. $blt_width = $this->GetStringWidth(str_repeat('m',strlen($maxnum)).$this->list_number_suffix);
  18547. break;
  18548. case 'I':
  18549. $anum = $this->dec2roman($num,true);
  18550. // mPDF 5.0.054
  18551. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18552. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18553. if ($maxnum>87) { $bbit = 87; }
  18554. else if ($maxnum>86) { $bbit = 86; }
  18555. else if ($maxnum>37) { $bbit = 38; }
  18556. else if ($maxnum>36) { $bbit = 37; }
  18557. else if ($maxnum>27) { $bbit = 28; }
  18558. else if ($maxnum>26) { $bbit = 27; }
  18559. else if ($maxnum>17) { $bbit = 18; }
  18560. else if ($maxnum>16) { $bbit = 17; }
  18561. else if ($maxnum>7) { $bbit = 8; }
  18562. else if ($maxnum>6) { $bbit = 7; }
  18563. else if ($maxnum>3) { $bbit = 4; }
  18564. else { $bbit = $maxnum; }
  18565. $maxlnum = $this->dec2roman($bbit,true);
  18566. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  18567. break;
  18568. case 'i':
  18569. $anum = $this->dec2roman($num,false);
  18570. // mPDF 5.0.054
  18571. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18572. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18573. if ($maxnum>87) { $bbit = 87; }
  18574. else if ($maxnum>86) { $bbit = 86; }
  18575. else if ($maxnum>37) { $bbit = 38; }
  18576. else if ($maxnum>36) { $bbit = 37; }
  18577. else if ($maxnum>27) { $bbit = 28; }
  18578. else if ($maxnum>26) { $bbit = 27; }
  18579. else if ($maxnum>17) { $bbit = 18; }
  18580. else if ($maxnum>16) { $bbit = 17; }
  18581. else if ($maxnum>7) { $bbit = 8; }
  18582. else if ($maxnum>6) { $bbit = 7; }
  18583. else if ($maxnum>3) { $bbit = 4; }
  18584. else { $bbit = $maxnum; }
  18585. $maxlnum = $this->dec2roman($bbit,false);
  18586. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  18587. break;
  18588. case 'disc':
  18589. if ($this->PDFA || $this->PDFX) {
  18590. if ($this->_charDefined($this->CurrentFont['cw'],8226)) { $list_item_marker = "\xe2\x80\xa2"; } // &#8226;
  18591. else { $list_item_marker = '-'; }
  18592. $blt_width = $this->GetStringWidth($list_item_marker);
  18593. break;
  18594. }
  18595. $list_item_marker = $this->chrs[108]; // bullet disc in Zapfdingbats 'l'
  18596. $typefont = 'czapfdingbats';
  18597. $blt_width = (0.791 * $this->FontSize/2.5);
  18598. break;
  18599. case 'circle':
  18600. if ($this->PDFA || $this->PDFX) {
  18601. if ($this->_charDefined($this->CurrentFont['cw'],9900)) { $list_item_marker = "\xe2\x9a\xac"; } // &#9900;
  18602. else { $list_item_marker = '-'; }
  18603. $blt_width = $this->GetStringWidth($list_item_marker);
  18604. break;
  18605. }
  18606. $list_item_marker = $this->chrs[109]; // circle in Zapfdingbats 'm'
  18607. $typefont = 'czapfdingbats';
  18608. $blt_width = (0.873 * $this->FontSize/2.5);
  18609. break;
  18610. case 'square':
  18611. if ($this->PDFA || $this->PDFX) {
  18612. if ($this->_charDefined($this->CurrentFont['cw'],9642)) { $list_item_marker = "\xe2\x96\xaa"; } // &#9642;
  18613. else { $list_item_marker = '-'; }
  18614. $blt_width = $this->GetStringWidth($list_item_marker);
  18615. break;
  18616. }
  18617. $list_item_marker = $this->chrs[110]; //black square in Zapfdingbats font 'n'
  18618. $typefont = 'czapfdingbats';
  18619. $blt_width = (0.761 * $this->FontSize/2.5);
  18620. break;
  18621. // mPDF 5.0.057
  18622. /* CSS3 list-styles numeric + I added tamil
  18623. arabic-indic | bengali | cambodian | devanagari | gujarati | gurmukhi | kannada | khmer | lao | malayalam | mongolian | myanmar | oriya | persian | telugu | tibetan | thai | urdu
  18624. */
  18625. case 'arabic-indic':
  18626. $cp = 0x0660;
  18627. $rnum = $this->dec2other($num, $cp);
  18628. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  18629. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18630. break;
  18631. case 'persian':
  18632. case 'urdu':
  18633. $cp = 0x06F0;
  18634. $rnum = $this->dec2other($num, $cp);
  18635. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  18636. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18637. break;
  18638. case 'bengali':
  18639. $cp = 0x09E6;
  18640. $rnum = $this->dec2other($num, $cp);
  18641. $list_item_marker = $rnum . $this->list_number_suffix;
  18642. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18643. break;
  18644. case 'devanagari':
  18645. $cp = 0x0966;
  18646. $rnum = $this->dec2other($num, $cp);
  18647. $list_item_marker = $rnum . $this->list_number_suffix;
  18648. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18649. break;
  18650. case 'gujarati':
  18651. $cp = 0x0AE6;
  18652. $rnum = $this->dec2other($num, $cp);
  18653. $list_item_marker = $rnum . $this->list_number_suffix;
  18654. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18655. break;
  18656. case 'gurmukhi':
  18657. $cp = 0x0A66;
  18658. $rnum = $this->dec2other($num, $cp);
  18659. $list_item_marker = $rnum . $this->list_number_suffix;
  18660. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18661. break;
  18662. case 'kannada':
  18663. $cp = 0x0CE6;
  18664. $rnum = $this->dec2other($num, $cp);
  18665. $list_item_marker = $rnum . $this->list_number_suffix;
  18666. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18667. break;
  18668. case 'malayalam':
  18669. $cp = 0x0D66;
  18670. $rnum = $this->dec2other($num, $cp);
  18671. $list_item_marker = $rnum . $this->list_number_suffix;
  18672. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(6, $cp),strlen($maxnum)).$this->list_number_suffix);
  18673. break;
  18674. case 'oriya':
  18675. $cp = 0x0B66;
  18676. $rnum = $this->dec2other($num, $cp);
  18677. $list_item_marker = $rnum . $this->list_number_suffix;
  18678. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18679. break;
  18680. case 'telugu':
  18681. $cp = 0x0C66;
  18682. $rnum = $this->dec2other($num, $cp);
  18683. $list_item_marker = $rnum . $this->list_number_suffix;
  18684. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18685. break;
  18686. case 'tamil':
  18687. $cp = 0x0BE6;
  18688. $rnum = $this->dec2other($num, $cp);
  18689. $list_item_marker = $rnum . $this->list_number_suffix;
  18690. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(9, $cp),strlen($maxnum)).$this->list_number_suffix);
  18691. break;
  18692. case 'thai':
  18693. $cp = 0x0E50;
  18694. $rnum = $this->dec2other($num, $cp);
  18695. $list_item_marker = $rnum . $this->list_number_suffix;
  18696. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(5, $cp),strlen($maxnum)).$this->list_number_suffix);
  18697. break;
  18698. default:
  18699. // mPDF 5.0.054
  18700. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  18701. else { $list_item_marker = $num . $this->list_number_suffix; }
  18702. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  18703. break;
  18704. }
  18705. } // mPDF 5.1.018
  18706. if ($currIndentLvl < $lvl) {
  18707. if ($lvl > 1 || $this->list_indent_first_level) {
  18708. $indent += $this->list_indent[$lvl][$occur];
  18709. $lastIndent[$lvl] = $this->list_indent[$lvl][$occur];
  18710. }
  18711. }
  18712. else if ($currIndentLvl > $lvl) {
  18713. while ($currIndentLvl > $lvl) {
  18714. $indent -= $lastIndent[$currIndentLvl];
  18715. $currIndentLvl--;
  18716. }
  18717. }
  18718. $currIndentLvl = $lvl;
  18719. /*-- RTL --*/
  18720. // mPDF 5.0.054
  18721. if ($this->listDir == 'rtl') {
  18722. // list_align_style Determines alignment of numbers in numbered lists
  18723. if ($this->list_align_style == 'L') { $lalign = 'R'; }
  18724. else { $lalign = 'L'; }
  18725. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  18726. $xb = $this->blk[$this->blklvl]['inner_width'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'] - $indent - $blt_width; //Bullet position (relative)
  18727. //Output bullet
  18728. // mPDF 5.1.018
  18729. $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$list_item_marker,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs, 'col'=>$list_item_color );
  18730. $this->x = $x;
  18731. }
  18732. else {
  18733. /*-- END RTL --*/
  18734. if ($this->list_align_style == 'L') { $lalign = 'L'; }
  18735. else { $lalign = 'R'; }
  18736. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  18737. $xb = $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] - $blt_width - $space_width;
  18738. //Output bullet
  18739. // mPDF 5.1.018
  18740. $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$list_item_marker,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs, 'col'=>$list_item_color );
  18741. $this->x = $x + $indent + $blt_width + $space_width;
  18742. } // *RTL*
  18743. //Print content
  18744. $this->printbuffer($this->textbuffer,'',false,true);
  18745. $this->textbuffer=array();
  18746. // Added to correct for OddEven Margins
  18747. if ($this->page != $bak_page) {
  18748. if (($this->page-$bak_page) % 2 == 1) {
  18749. $x += $this->MarginCorrection;
  18750. }
  18751. $bak_page = $this->page;
  18752. }
  18753. /*-- COLUMNS --*/
  18754. // OR COLUMN CHANGE
  18755. if ($this->CurrCol != $oldcolumn) {
  18756. if ($this->directionality == 'rtl') { // *RTL*
  18757. $x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18758. } // *RTL*
  18759. else { // *RTL*
  18760. $x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18761. } // *RTL*
  18762. $oldcolumn = $this->CurrCol;
  18763. }
  18764. /*-- END COLUMNS --*/
  18765. }
  18766. //Reset all used values
  18767. $this->listoccur = array();
  18768. $this->listitem = array();
  18769. $this->listlist = array();
  18770. $this->listlvl = 0;
  18771. $this->listnum = 0;
  18772. $this->listtype = '';
  18773. $this->textbuffer = array();
  18774. $this->divwidth = 0;
  18775. $this->divheight = 0;
  18776. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  18777. }
  18778. /*-- END LISTS --*/
  18779. function printbuffer($arrayaux,$blockstate=0,$is_table=false,$is_list=false)
  18780. {
  18781. // $blockstate = 0; // NO margins/padding
  18782. // $blockstate = 1; // Top margins/padding only
  18783. // $blockstate = 2; // Bottom margins/padding only
  18784. // $blockstate = 3; // Top & bottom margins/padding
  18785. $this->spanbgcolorarray = array();
  18786. $this->spanbgcolor = false;
  18787. $paint_ht_corr = 0;
  18788. /*-- CSS-FLOAT --*/
  18789. if (count($this->floatDivs)) {
  18790. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  18791. if (($this->blk[$this->blklvl]['inner_width']-$l_width-$r_width) < $this->GetStringWidth('WW')) {
  18792. // Too narrow to fit - try to move down past L or R float
  18793. if ($l_max < $r_max && ($this->blk[$this->blklvl]['inner_width']-$r_width) > $this->GetStringWidth('WW')) {
  18794. $this->ClearFloats('LEFT', $this->blklvl);
  18795. }
  18796. else if ($r_max < $l_max && ($this->blk[$this->blklvl]['inner_width']-$l_width) > $this->GetStringWidth('WW')) {
  18797. $this->ClearFloats('RIGHT', $this->blklvl);
  18798. }
  18799. else { $this->ClearFloats('BOTH', $this->blklvl); }
  18800. }
  18801. }
  18802. /*-- END CSS-FLOAT --*/
  18803. $bak_y = $this->y;
  18804. $bak_x = $this->x;
  18805. $align = '';
  18806. if (!$is_table && !$is_list) {
  18807. if (isset($this->blk[$this->blklvl]['align']) && $this->blk[$this->blklvl]['align']) { $align = $this->blk[$this->blklvl]['align']; }
  18808. // Block-align is set by e.g. <.. align="center"> Takes priority for this block but not inherited
  18809. if (isset($this->blk[$this->blklvl]['block-align']) && $this->blk[$this->blklvl]['block-align']) { $align = $this->blk[$this->blklvl]['block-align']; }
  18810. $blockdir = $this->blk[$this->blklvl]['direction']; // mPDF 5.0.054
  18811. $this->divwidth = $this->blk[$this->blklvl]['width'];
  18812. }
  18813. else {
  18814. $align = $this->divalign;
  18815. // mPDF 5.0.054
  18816. if ($is_table) { $blockdir = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']; }
  18817. else { $blockdir = $this->listDir; } // mPDF 5.0.054
  18818. }
  18819. $oldpage = $this->page;
  18820. // ADDED for Out of Block now done as Flowing Block
  18821. if ($this->divwidth == 0) {
  18822. $this->divwidth = $this->pgwidth;
  18823. }
  18824. if (!$is_table && !$is_list) { $this->SetLineHeight($this->FontSizePt,$this->blk[$this->blklvl]['line_height']); }
  18825. $this->divheight = $this->lineheight;
  18826. $old_height = $this->divheight;
  18827. // As a failsafe - if font has been set but not output to page
  18828. $this->SetFont($this->default_font,'',$this->default_font_size,true,true); // force output to page
  18829. $array_size = count($arrayaux);
  18830. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,true,$blockdir); // mPDF 5.0.054
  18831. // Added - Otherwise <div><div><p> did not output top margins/padding for 1st/2nd div
  18832. if ($array_size == 0) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18833. for($i=0;$i < $array_size; $i++)
  18834. {
  18835. // COLS
  18836. $oldcolumn = $this->CurrCol;
  18837. $vetor = $arrayaux[$i];
  18838. if ($i == 0 and $vetor[0] != "\n" and !$this->ispre) {
  18839. $vetor[0] = ltrim($vetor[0]);
  18840. }
  18841. // FIXED TO ALLOW IT TO SHOW '0'
  18842. if (empty($vetor[0]) && !($vetor[0]==='0') && empty($vetor[7])) { //Ignore empty text and not carrying an internal link
  18843. //Check if it is the last element. If so then finish printing the block
  18844. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18845. continue;
  18846. }
  18847. //Activating buffer properties
  18848. if(isset($vetor[11]) and $vetor[11] != '') { // Font Size
  18849. if ($is_table && $this->shrin_k) {
  18850. $this->SetFontSize($vetor[11]/$this->shrin_k,false);
  18851. }
  18852. else {
  18853. $this->SetFontSize($vetor[11],false);
  18854. }
  18855. }
  18856. // mPDF 5.0.063
  18857. if(isset($vetor[15])) { // Word spacing
  18858. $this->wSpacingCSS = $vetor[15];
  18859. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  18860. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); // mPDF 5.0.066
  18861. }
  18862. }
  18863. if(isset($vetor[14])) { // Letter spacing
  18864. $this->lSpacingCSS = $vetor[14];
  18865. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { // mPDF 5.0.066
  18866. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); // mPDF 5.0.066
  18867. }
  18868. }
  18869. if(isset($vetor[13])) { // Font Kerning
  18870. $this->kerning = $vetor[13];
  18871. }
  18872. if(isset($vetor[10]) and !empty($vetor[10])) //Background color
  18873. {
  18874. $this->spanbgcolorarray = $vetor[10];
  18875. $this->spanbgcolor = true;
  18876. }
  18877. if(isset($vetor[9]) and !empty($vetor[9])) // Outline parameters
  18878. {
  18879. $cor = $vetor[9]['COLOR'];
  18880. $outlinewidth = $vetor[9]['WIDTH'];
  18881. $this->SetTextOutline($outlinewidth,$cor); // mPDF 5.0.051
  18882. $this->outline_on = true;
  18883. }
  18884. if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text
  18885. {
  18886. $this->strike = true;
  18887. }
  18888. if(isset($vetor[7]) and $vetor[7] != '') // internal link: <a name="anyvalue">
  18889. {
  18890. if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  18891. $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page );
  18892. if (empty($vetor[0])) { //Ignore empty text
  18893. //Check if it is the last element. If so then finish printing the block
  18894. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18895. continue;
  18896. }
  18897. }
  18898. if(isset($vetor[6]) and $vetor[6] === true) // Subscript
  18899. {
  18900. $this->SUB = true;
  18901. }
  18902. if(isset($vetor[5]) and $vetor[5] === true) // Superscript
  18903. {
  18904. $this->SUP = true;
  18905. }
  18906. if(isset($vetor[4]) and $vetor[4] != '') { // Font Family
  18907. $font = $this->SetFont($vetor[4],$this->FontStyle,0,false);
  18908. }
  18909. if (!empty($vetor[3])) //Font Color
  18910. {
  18911. $cor = $vetor[3];
  18912. $this->SetTColor($cor); // mPDF 5.0.020
  18913. }
  18914. if(isset($vetor[2]) and $vetor[2] != '') //Bold,Italic,Underline styles
  18915. {
  18916. $this->SetStyles($vetor[2]); // mPDF 5.0
  18917. }
  18918. if(isset($vetor[12]) and $vetor[12] != '') { //Requested Bold,Italic,Underline
  18919. $this->ReqFontStyle = $vetor[12];
  18920. }
  18921. if(isset($vetor[1]) and $vetor[1] != '') //LINK
  18922. {
  18923. if (strpos($vetor[1],".") === false && strpos($vetor[1],"@") !== 0) //assuming every external link has a dot indicating extension (e.g: .html .txt .zip www.somewhere.com etc.)
  18924. {
  18925. //Repeated reference to same anchor?
  18926. while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
  18927. $this->internallink[$vetor[1]] = $this->AddLink();
  18928. $vetor[1] = $this->internallink[$vetor[1]];
  18929. }
  18930. $this->HREF = $vetor[1]; // HREF link style set here ******
  18931. }
  18932. // SPECIAL CONTENT - IMAGES & FORM OBJECTS
  18933. //Print-out special content
  18934. if (substr($vetor[0],0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  18935. $objattr = $this->_getObjAttr($vetor[0]);
  18936. /*-- TABLES --*/
  18937. if ($objattr['type'] == 'nestedtable') {
  18938. $level = $objattr['level'];
  18939. $table = &$this->table[$level][$objattr['table']];
  18940. $cell = &$table['cells'][$objattr['row']][$objattr['col']];
  18941. if ($objattr['nestedcontent']) {
  18942. $this->finishFlowingBlock(false,'nestedtable');
  18943. $save_dw = $this->divwidth ;
  18944. $save_buffer = $this->cellBorderBuffer;
  18945. $this->cellBorderBuffer = array();
  18946. $ncx = $this->x;
  18947. list($dummyx,$w) = $this->_tableGetWidth($table, $objattr['row'], $objattr['col']);
  18948. $ntw = $this->table[($level+1)][$objattr['nestedcontent']]['w']; // nested table width
  18949. if (!$this->simpleTables){
  18950. if ($table['borders_separate']) {
  18951. $innerw = $w - $cell['border_details']['L']['w'] - $cell['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18952. }
  18953. else {
  18954. $innerw = $w - $cell['border_details']['L']['w']/2 - $cell['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18955. }
  18956. }
  18957. else if ($this->simpleTables){
  18958. if ($table['borders_separate']) {
  18959. $innerw = $w - $table['simple']['border_details']['L']['w'] - $table['simple']['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18960. }
  18961. else {
  18962. $innerw = $w - $table['simple']['border_details']['L']['w']/2 - $table['simple']['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18963. }
  18964. }
  18965. if ($cell['a']=='C' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='C') {
  18966. $ncx += ($innerw-$ntw)/2;
  18967. }
  18968. elseif ($cell['a']=='R' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='R') {
  18969. $ncx += $innerw- $ntw;
  18970. }
  18971. $this->x = $ncx ;
  18972. $this->_tableWrite($this->table[($level+1)][$objattr['nestedcontent']]);
  18973. $this->cellBorderBuffer = $save_buffer;
  18974. $this->x = $bak_x ;
  18975. $this->divwidth = $save_dw;
  18976. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir); // mPDF 5.0.054
  18977. }
  18978. }
  18979. else {
  18980. /*-- END TABLES --*/
  18981. if ($is_table) { // *TABLES*
  18982. $maxWidth = $this->divwidth; // *TABLES*
  18983. } // *TABLES*
  18984. else { // *TABLES*
  18985. $maxWidth = $this->divwidth - ($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']);
  18986. } // *TABLES*
  18987. /*-- CSS-IMAGE-FLOAT --*/
  18988. // If float (already) exists at this level
  18989. if (isset($this->floatmargins['R']) && $this->y <= $this->floatmargins['R']['y1'] && $this->y >= $this->floatmargins['R']['y0']) { $maxWidth -= $this->floatmargins['R']['w']; }
  18990. if (isset($this->floatmargins['L']) && $this->y <= $this->floatmargins['L']['y1'] && $this->y >= $this->floatmargins['L']['y0']) { $maxWidth -= $this->floatmargins['L']['w']; }
  18991. /*-- END CSS-IMAGE-FLOAT --*/
  18992. list($skipln) = $this->inlineObject($objattr['type'], '', $this->y, $objattr,$this->lMargin, ($this->flowingBlockAttr['contentWidth']/$this->k), $maxWidth, $this->flowingBlockAttr['height'], false, $is_table);
  18993. // 1 -> New line needed because of width
  18994. // -1 -> Will fit width on line but NEW PAGE REQUIRED because of height
  18995. // -2 -> Will not fit on line therefore needs new line but thus NEW PAGE REQUIRED
  18996. $iby = $this->y;
  18997. $oldpage = $this->page;
  18998. $oldcol = $this->CurrCol;
  18999. if (($skipln == 1 || $skipln == -2) && !isset($objattr['float'])) {
  19000. $this->finishFlowingBlock(false,$objattr['type']);
  19001. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir); // mPDF 5.0.054
  19002. }
  19003. $thispage = $this->page;
  19004. if ($this->CurrCol!=$oldcol) { $changedcol = true; }
  19005. else { $changedcol=false; }
  19006. // the previous lines can already have triggered page break or column change
  19007. if (!$changedcol && $skipln <0 && $this->AcceptPageBreak() && $thispage==$oldpage) {
  19008. $this->AddPage($this->CurOrientation);
  19009. // Added to correct Images already set on line before page advanced
  19010. // i.e. if second inline image on line is higher than first and forces new page
  19011. if (count($this->objectbuffer)) {
  19012. $yadj = $iby - $this->y;
  19013. foreach($this->objectbuffer AS $ib=>$val) {
  19014. if ($this->objectbuffer[$ib]['OUTER-Y'] ) $this->objectbuffer[$ib]['OUTER-Y'] -= $yadj;
  19015. if ($this->objectbuffer[$ib]['BORDER-Y']) $this->objectbuffer[$ib]['BORDER-Y'] -= $yadj;
  19016. if ($this->objectbuffer[$ib]['INNER-Y']) $this->objectbuffer[$ib]['INNER-Y'] -= $yadj;
  19017. }
  19018. }
  19019. }
  19020. // Added to correct for OddEven Margins
  19021. if ($this->page != $oldpage) {
  19022. if (($this->page-$oldpage) % 2 == 1) {
  19023. $bak_x += $this->MarginCorrection;
  19024. }
  19025. $oldpage = $this->page;
  19026. $y = $this->tMargin - $paint_ht_corr ;
  19027. $this->oldy = $this->tMargin - $paint_ht_corr ;
  19028. $old_height = 0;
  19029. }
  19030. $this->x = $bak_x;
  19031. /*-- COLUMNS --*/
  19032. // COLS
  19033. // OR COLUMN CHANGE
  19034. if ($this->CurrCol != $oldcolumn) {
  19035. if ($this->directionality == 'rtl') { // *RTL*
  19036. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  19037. } // *RTL*
  19038. else { // *RTL*
  19039. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  19040. } // *RTL*
  19041. $this->x = $bak_x;
  19042. $oldcolumn = $this->CurrCol;
  19043. $y = $this->y0 - $paint_ht_corr ;
  19044. $this->oldy = $this->y0 - $paint_ht_corr ;
  19045. $old_height = 0;
  19046. }
  19047. /*-- END COLUMNS --*/
  19048. /*-- CSS-IMAGE-FLOAT --*/
  19049. if ($objattr['type'] == 'image' && isset($objattr['float'])) {
  19050. $fy = $this->y;
  19051. // DIV TOP MARGIN/BORDER/PADDING
  19052. if ($this->flowingBlockAttr['newblock'] && ($this->flowingBlockAttr['blockstate']==1 || $this->flowingBlockAttr['blockstate']==3) && $this->flowingBlockAttr['lineCount']== 0) {
  19053. $fy += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  19054. }
  19055. if ($objattr['float']=='R') {
  19056. $fx = $this->w - $this->rMargin - $objattr['width'] - ($this->blk[$this->blklvl]['outer_right_margin'] + $this->blk[$this->blklvl]['border_right']['w'] + $this->blk[$this->blklvl]['padding_right']);
  19057. }
  19058. else if ($objattr['float']=='L') {
  19059. $fx = $this->lMargin + ($this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left']);
  19060. }
  19061. $w = $objattr['width'];
  19062. $h = abs($objattr['height']);
  19063. $widthLeft = $maxWidth - ($this->flowingBlockAttr['contentWidth']/$this->k);
  19064. $maxHeight = $this->h - ($this->tMargin + $this->margin_header + $this->bMargin + 10) ;
  19065. // For Images
  19066. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right']);
  19067. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom']);
  19068. if ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg') {
  19069. $file = $objattr['file'];
  19070. $info=$this->formobjects[$file];
  19071. }
  19072. else {
  19073. $file = $objattr['file'];
  19074. $info=$this->images[$file];
  19075. }
  19076. // Automatically resize to width remaining - ********** If > maxWidth *******
  19077. // if ($w > $widthLeft) {
  19078. // $w = $widthLeft ;
  19079. // $h=abs($w*$info['h']/$info['w']);
  19080. // }
  19081. $img_w = $w - $extraWidth ;
  19082. $img_h = $h - $extraHeight ;
  19083. if ($objattr['border_left']['w']) {
  19084. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w'] + $objattr['border_right']['w'])/2) ;
  19085. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w'] + $objattr['border_bottom']['w'])/2) ;
  19086. $objattr['BORDER-X'] = $fx + $objattr['margin_left'] + (($objattr['border_left']['w'])/2) ;
  19087. $objattr['BORDER-Y'] = $fy + $objattr['margin_top'] + (($objattr['border_top']['w'])/2) ;
  19088. }
  19089. $objattr['INNER-WIDTH'] = $img_w;
  19090. $objattr['INNER-HEIGHT'] = $img_h;
  19091. $objattr['INNER-X'] = $fx + $objattr['margin_left'] + ($objattr['border_left']['w']);
  19092. $objattr['INNER-Y'] = $fy + $objattr['margin_top'] + ($objattr['border_top']['w']) ;
  19093. $objattr['ID'] = $info['i'];
  19094. $objattr['OUTER-WIDTH'] = $w;
  19095. $objattr['OUTER-HEIGHT'] = $h;
  19096. $objattr['OUTER-X'] = $fx;
  19097. $objattr['OUTER-Y'] = $fy;
  19098. if ($objattr['float']=='R') {
  19099. // If R float already exists at this level
  19100. $this->floatmargins['R']['skipline'] = false;
  19101. if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  19102. $this->WriteFlowingBlock($vetor[0]);
  19103. }
  19104. // If L float already exists at this level
  19105. else if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  19106. // Final check distance between floats is not now too narrow to fit text
  19107. $mw = $this->GetStringWidth('WW');
  19108. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['L']['w']) < $mw) {
  19109. $this->WriteFlowingBlock($vetor[0]);
  19110. }
  19111. else {
  19112. $this->floatmargins['R']['x'] = $fx;
  19113. $this->floatmargins['R']['w'] = $w;
  19114. $this->floatmargins['R']['y0'] = $fy;
  19115. $this->floatmargins['R']['y1'] = $fy + $h;
  19116. if ($skipln == 1) {
  19117. $this->floatmargins['R']['skipline'] = true;
  19118. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  19119. $objattr['skipline'] = true;
  19120. }
  19121. $this->floatbuffer[] = $objattr;
  19122. }
  19123. }
  19124. else {
  19125. $this->floatmargins['R']['x'] = $fx;
  19126. $this->floatmargins['R']['w'] = $w;
  19127. $this->floatmargins['R']['y0'] = $fy;
  19128. $this->floatmargins['R']['y1'] = $fy + $h;
  19129. if ($skipln == 1) {
  19130. $this->floatmargins['R']['skipline'] = true;
  19131. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  19132. $objattr['skipline'] = true;
  19133. }
  19134. $this->floatbuffer[] = $objattr;
  19135. }
  19136. }
  19137. else if ($objattr['float']=='L') {
  19138. // If L float already exists at this level
  19139. $this->floatmargins['L']['skipline'] = false;
  19140. if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  19141. $this->floatmargins['L']['skipline'] = false;
  19142. $this->WriteFlowingBlock($vetor[0]);
  19143. }
  19144. // If R float already exists at this level
  19145. else if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  19146. // Final check distance between floats is not now too narrow to fit text
  19147. $mw = $this->GetStringWidth('WW');
  19148. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['R']['w']) < $mw) {
  19149. $this->WriteFlowingBlock($vetor[0]);
  19150. }
  19151. else {
  19152. $this->floatmargins['L']['x'] = $fx + $w;
  19153. $this->floatmargins['L']['w'] = $w;
  19154. $this->floatmargins['L']['y0'] = $fy;
  19155. $this->floatmargins['L']['y1'] = $fy + $h;
  19156. if ($skipln == 1) {
  19157. $this->floatmargins['L']['skipline'] = true;
  19158. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  19159. $objattr['skipline'] = true;
  19160. }
  19161. $this->floatbuffer[] = $objattr;
  19162. }
  19163. }
  19164. else {
  19165. $this->floatmargins['L']['x'] = $fx + $w;
  19166. $this->floatmargins['L']['w'] = $w;
  19167. $this->floatmargins['L']['y0'] = $fy;
  19168. $this->floatmargins['L']['y1'] = $fy + $h;
  19169. if ($skipln == 1) {
  19170. $this->floatmargins['L']['skipline'] = true;
  19171. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  19172. $objattr['skipline'] = true;
  19173. }
  19174. $this->floatbuffer[] = $objattr;
  19175. }
  19176. }
  19177. }
  19178. else {
  19179. /*-- END CSS-IMAGE-FLOAT --*/
  19180. $this->WriteFlowingBlock($vetor[0]);
  19181. /*-- CSS-IMAGE-FLOAT --*/
  19182. }
  19183. /*-- END CSS-IMAGE-FLOAT --*/
  19184. } // *TABLES*
  19185. } // END If special content
  19186. else { //THE text
  19187. if ($this->tableLevel) { $paint_ht_corr = 0; } // To move the y up when new column/page started if div border needed
  19188. else { $paint_ht_corr = $this->blk[$this->blklvl]['border_top']['w']; }
  19189. if ($vetor[0] == "\n") { //We are reading a <BR> now turned into newline ("\n")
  19190. if ($this->flowingBlockAttr['content']) {
  19191. $this->finishFlowingBlock(false,'br');
  19192. }
  19193. else if ($is_table) {
  19194. $this->y+= $this->_computeLineheight($this->table_lineheight);
  19195. }
  19196. else if (!$is_table) {
  19197. $this->DivLn($this->lineheight);
  19198. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  19199. }
  19200. // Added to correct for OddEven Margins
  19201. if ($this->page != $oldpage) {
  19202. if (($this->page-$oldpage) % 2 == 1) {
  19203. $bak_x += $this->MarginCorrection;
  19204. }
  19205. $oldpage = $this->page;
  19206. $y = $this->tMargin - $paint_ht_corr ;
  19207. $this->oldy = $this->tMargin - $paint_ht_corr ;
  19208. $old_height = 0;
  19209. }
  19210. $this->x = $bak_x;
  19211. /*-- COLUMNS --*/
  19212. // COLS
  19213. // OR COLUMN CHANGE
  19214. if ($this->CurrCol != $oldcolumn) {
  19215. if ($this->directionality == 'rtl') { // *RTL*
  19216. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  19217. } // *RTL*
  19218. else { // *RTL*
  19219. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  19220. } // *RTL*
  19221. $this->x = $bak_x;
  19222. $oldcolumn = $this->CurrCol;
  19223. $y = $this->y0 - $paint_ht_corr ;
  19224. $this->oldy = $this->y0 - $paint_ht_corr ;
  19225. $old_height = 0;
  19226. }
  19227. /*-- END COLUMNS --*/
  19228. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir); // mPDF 5.0.054
  19229. }
  19230. else {
  19231. $this->WriteFlowingBlock( $vetor[0]);
  19232. // Added to correct for OddEven Margins
  19233. if ($this->page != $oldpage) {
  19234. if (($this->page-$oldpage) % 2 == 1) {
  19235. $bak_x += $this->MarginCorrection;
  19236. $this->x = $bak_x;
  19237. }
  19238. $oldpage = $this->page;
  19239. $y = $this->tMargin - $paint_ht_corr ;
  19240. $this->oldy = $this->tMargin - $paint_ht_corr ;
  19241. $old_height = 0;
  19242. }
  19243. /*-- COLUMNS --*/
  19244. // COLS
  19245. // OR COLUMN CHANGE
  19246. if ($this->CurrCol != $oldcolumn) {
  19247. if ($this->directionality == 'rtl') { // *RTL*
  19248. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  19249. } // *RTL*
  19250. else { // *RTL*
  19251. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  19252. } // *RTL*
  19253. $this->x = $bak_x;
  19254. $oldcolumn = $this->CurrCol;
  19255. $y = $this->y0 - $paint_ht_corr ;
  19256. $this->oldy = $this->y0 - $paint_ht_corr ;
  19257. $old_height = 0;
  19258. }
  19259. /*-- END COLUMNS --*/
  19260. }
  19261. }
  19262. //Check if it is the last element. If so then finish printing the block
  19263. if ($i == ($array_size-1)) {
  19264. $this->finishFlowingBlock(true); // true = END of flowing block
  19265. // Added to correct for OddEven Margins
  19266. if ($this->page != $oldpage) {
  19267. if (($this->page-$oldpage) % 2 == 1) {
  19268. $bak_x += $this->MarginCorrection;
  19269. $this->x = $bak_x;
  19270. }
  19271. $oldpage = $this->page;
  19272. $y = $this->tMargin - $paint_ht_corr ;
  19273. $this->oldy = $this->tMargin - $paint_ht_corr ;
  19274. $old_height = 0;
  19275. }
  19276. /*-- COLUMNS --*/
  19277. // COLS
  19278. // OR COLUMN CHANGE
  19279. if ($this->CurrCol != $oldcolumn) {
  19280. if ($this->directionality == 'rtl') { // *RTL*
  19281. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  19282. } // *RTL*
  19283. else { // *RTL*
  19284. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  19285. } // *RTL*
  19286. $this->x = $bak_x;
  19287. $oldcolumn = $this->CurrCol;
  19288. $y = $this->y0 - $paint_ht_corr ;
  19289. $this->oldy = $this->y0 - $paint_ht_corr ;
  19290. $old_height = 0;
  19291. }
  19292. /*-- END COLUMNS --*/
  19293. }
  19294. // RESETTING VALUES
  19295. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  19296. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  19297. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  19298. $this->colorarray = array();
  19299. $this->spanbgcolorarray = array();
  19300. $this->spanbgcolor = false;
  19301. $this->issetcolor = false;
  19302. $this->HREF = '';
  19303. $this->outlineparam = array();
  19304. $this->SetTextOutline(false);
  19305. $this->outline_on = false;
  19306. $this->SUP = false;
  19307. $this->SUB = false;
  19308. $this->strike = false;
  19309. $this->currentfontfamily = '';
  19310. $this->currentfontsize = '';
  19311. $this->currentfontstyle = '';
  19312. /*-- TABLES --*/
  19313. if ($this->tableLevel) {
  19314. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  19315. }
  19316. else
  19317. /*-- END TABLES --*/
  19318. /*-- LISTS --*/
  19319. if ($is_list && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) {
  19320. //$this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height
  19321. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->listOcc]); // sets default line height
  19322. }
  19323. else
  19324. /*-- END LISTS --*/
  19325. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  19326. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  19327. }
  19328. $this->ResetStyles(); // mPDF 5.0
  19329. $this->toupper = false;
  19330. $this->tolower = false;
  19331. $this->capitalize = false; // mPDF 5.0.062
  19332. $this->kerning = false; // mPDF 5.0.063
  19333. $this->lSpacingCSS = ''; // mPDF 5.0.063
  19334. $this->wSpacingCSS = ''; // mPDF 5.0.063
  19335. $this->fixedlSpacing = false; // mPDF 5.0.063
  19336. $this->minwSpacing = 0; // mPDF 5.0.063
  19337. $this->SetDash(); //restore to no dash
  19338. $this->dash_on = false;
  19339. $this->dotted_on = false;
  19340. }//end of for(i=0;i<arraysize;i++)
  19341. // PAINT DIV BORDER // DISABLED IN COLUMNS AS DOESN'T WORK WHEN BROKEN ACROSS COLS??
  19342. if ((isset($this->blk[$this->blklvl]['border']) || isset($this->blk[$this->blklvl]['bgcolor'])) && $blockstate && ($this->y != $this->oldy)) {
  19343. $bottom_y = $this->y; // Does not include Bottom Margin
  19344. if (isset($this->blk[$this->blklvl]['startpage']) && $this->blk[$this->blklvl]['startpage'] != $this->page && $blockstate != 1) {
  19345. $this->PaintDivBB('pagetop',$blockstate);
  19346. }
  19347. else if ($blockstate != 1) {
  19348. $this->PaintDivBB('',$blockstate);
  19349. }
  19350. $this->y = $bottom_y;
  19351. $this->x = $bak_x;
  19352. }
  19353. // Reset Font
  19354. $this->SetFontSize($this->default_font_size,false);
  19355. }
  19356. function _setDashBorder($style, $div, $cp, $side) {
  19357. if ($style == 'dashed' && (($side=='L' || $side=='R') || ($side=='T' && $div != 'pagetop' && !$cp) || ($side=='B' && $div!='pagebottom') )) {
  19358. $dashsize = 2; // final dash will be this + 1*linewidth
  19359. $dashsizek = 1.5; // ratio of Dash/Blank
  19360. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  19361. }
  19362. else if ($style == 'dotted' || ($side=='T' && ($div == 'pagetop' || $cp)) || ($side=='B' && $div == 'pagebottom')) {
  19363. //Round join and cap
  19364. $this->SetLineJoin(1); // mPDF 5.0.051 n j
  19365. $this->SetLineCap(1); // mPDF 5.0.051 n J
  19366. $this->SetDash(0.001,($this->LineWidth*3));
  19367. }
  19368. }
  19369. function _setBorderLine($b, $k=1) {
  19370. $this->SetLineWidth($b['w']/$k);
  19371. $this->SetDColor($b['c']); // mPDF 5.0.051
  19372. if ($b['c'][0]==5) { // RGBa
  19373. $this->SetAlpha($b['c'][4], 'Normal', false, 'S')."\n"; // mPDF 5.0.051
  19374. }
  19375. else if ($b['c'][0]==6) { // CMYKa
  19376. $this->SetAlpha($b['c'][5], 'Normal', false, 'S')."\n"; // mPDF 5.0.051
  19377. }
  19378. }
  19379. function PaintDivBB($divider='',$blockstate=0,$blvl=0) {
  19380. // Borders & backgrounds are done elsewhere for columns - messes up the repositioning in printcolumnbuffer
  19381. if ($this->ColActive) { return ; } // *COLUMNS*
  19382. $save_y = $this->y;
  19383. if (!$blvl) { $blvl = $this->blklvl; }
  19384. $x0 = $x1 = $y0 = $y1 = 0;
  19385. // Added mPDF 3.0 Float DIV
  19386. if (isset($this->blk[$blvl]['bb_painted'][$this->page]) && $this->blk[$blvl]['bb_painted'][$this->page]) { return; } // *CSS-FLOAT*
  19387. if (isset($this->blk[$blvl]['x0'])) { $x0 = $this->blk[$blvl]['x0']; } // left
  19388. if (isset($this->blk[$blvl]['y1'])) { $y1 = $this->blk[$blvl]['y1']; } // bottom
  19389. // Added mPDF 3.0 Float DIV - ensures backgrounds/borders are drawn to bottom of page
  19390. if ($y1==0) {
  19391. if ($divider=='pagebottom') { $y1 = $this->h-$this->bMargin; }
  19392. else { $y1 = $this->y; }
  19393. }
  19394. if (isset($this->blk[$blvl]['startpage']) && $this->blk[$blvl]['startpage'] != $this->page) { $continuingpage = true; } else { $continuingpage = false; }
  19395. if (isset($this->blk[$blvl]['y0'])) { $y0 = $this->blk[$blvl]['y0']; }
  19396. $h = $y1 - $y0;
  19397. $w = $this->blk[$blvl]['width'];
  19398. $x1 = $x0 + $w;
  19399. // Set border-widths as used here
  19400. $border_top = $this->blk[$blvl]['border_top']['w'];
  19401. $border_bottom = $this->blk[$blvl]['border_bottom']['w'];
  19402. $border_left = $this->blk[$blvl]['border_left']['w'];
  19403. $border_right = $this->blk[$blvl]['border_right']['w'];
  19404. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) {
  19405. $border_top = 0;
  19406. }
  19407. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') {
  19408. $border_bottom = 0;
  19409. }
  19410. $brTL_H = 0;
  19411. $brTL_V = 0;
  19412. $brTR_H = 0;
  19413. $brTR_V = 0;
  19414. $brBL_H = 0;
  19415. $brBL_V = 0;
  19416. $brBR_H = 0;
  19417. $brBR_V = 0;
  19418. $brset = false;
  19419. /*-- BORDER-RADIUS --*/
  19420. if (isset($this->blk[$blvl]['border_radius_TL_H'])) { $brTL_H = $this->blk[$blvl]['border_radius_TL_H']; $brset = true; }
  19421. if (isset($this->blk[$blvl]['border_radius_TL_V'])) { $brTL_V = $this->blk[$blvl]['border_radius_TL_V']; $brset = true; }
  19422. if (isset($this->blk[$blvl]['border_radius_TR_H'])) { $brTR_H = $this->blk[$blvl]['border_radius_TR_H']; $brset = true; }
  19423. if (isset($this->blk[$blvl]['border_radius_TR_V'])) { $brTR_V = $this->blk[$blvl]['border_radius_TR_V']; $brset = true; }
  19424. if (isset($this->blk[$blvl]['border_radius_BR_H'])) { $brBR_H = $this->blk[$blvl]['border_radius_BR_H']; $brset = true; }
  19425. if (isset($this->blk[$blvl]['border_radius_BR_V'])) { $brBR_V = $this->blk[$blvl]['border_radius_BR_V']; $brset = true; }
  19426. if (isset($this->blk[$blvl]['border_radius_BL_H'])) { $brBL_H = $this->blk[$blvl]['border_radius_BL_H']; $brset = true; }
  19427. if (isset($this->blk[$blvl]['border_radius_BL_V'])) { $brBL_V = $this->blk[$blvl]['border_radius_BL_V']; $brset = true; }
  19428. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage || $this->keep_block_together) {
  19429. $brTL_H = 0;
  19430. $brTL_V = 0;
  19431. $brTR_H = 0;
  19432. $brTR_V = 0;
  19433. }
  19434. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom' || $this->keep_block_together) {
  19435. $brBL_H = 0;
  19436. $brBL_V = 0;
  19437. $brBR_H = 0;
  19438. $brBR_V = 0;
  19439. }
  19440. // Disallow border-radius if it is smaller than the border width.
  19441. if ($brTL_H < min($border_left, $border_top)) { $brTL_H = $brTL_V = 0; }
  19442. if ($brTL_V < min($border_left, $border_top)) { $brTL_V = $brTL_H = 0; }
  19443. if ($brTR_H < min($border_right, $border_top)) { $brTR_H = $brTR_V = 0; }
  19444. if ($brTR_V < min($border_right, $border_top)) { $brTR_V = $brTR_H = 0; }
  19445. if ($brBL_H < min($border_left, $border_bottom)) { $brBL_H = $brBL_V = 0; }
  19446. if ($brBL_V < min($border_left, $border_bottom)) { $brBL_V = $brBL_H = 0; }
  19447. if ($brBR_H < min($border_right, $border_bottom)) { $brBR_H = $brBR_V = 0; }
  19448. if ($brBR_V < min($border_right, $border_bottom)) { $brBR_V = $brBR_H = 0; }
  19449. // CHECK FOR radii that sum to > width or height of div ********
  19450. $f = min($h/($brTL_V + $brBL_V + 0.001), $h/($brTR_V + $brBR_V + 0.001), $w/($brTL_H + $brTR_H + 0.001), $w/($brBL_H + $brBR_H + 0.001));
  19451. if ($f < 1) {
  19452. $brTL_H *= $f;
  19453. $brTL_V *= $f;
  19454. $brTR_H *= $f;
  19455. $brTR_V *= $f;
  19456. $brBL_H *= $f;
  19457. $brBL_V *= $f;
  19458. $brBR_H *= $f;
  19459. $brBR_V *= $f;
  19460. }
  19461. /*-- END BORDER-RADIUS --*/
  19462. // BORDERS
  19463. if (isset($this->blk[$blvl]['y0']) && $this->blk[$blvl]['y0']) { $y0 = $this->blk[$blvl]['y0']; }
  19464. $h = $y1 - $y0;
  19465. $w = $this->blk[$blvl]['width'];
  19466. //if ($this->blk[$blvl]['border_top']) {
  19467. // Reinstate line above for dotted line divider when block border crosses a page
  19468. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19469. $tbd = $this->blk[$blvl]['border_top'];
  19470. if (isset($tbd['s']) && $tbd['s']) {
  19471. $this->_setBorderLine($tbd);
  19472. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'T'); }
  19473. /*-- BORDER-RADIUS --*/
  19474. else if (($brTL_V && $brTL_H) || ($brTR_V && $brTR_H)) {
  19475. $this->SetLineJoin(0); // mPDF 5.0.051 n j
  19476. $this->SetLineCap(0); // mPDF 5.0.051 n J
  19477. }
  19478. if ($brTR_H && $brTR_V) {
  19479. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_top/2 , $brTR_V - $border_top/2 , 1, 2, true));
  19480. }
  19481. else {
  19482. /*-- END BORDER-RADIUS --*/
  19483. $this->_out(sprintf('%.3f %.3f m ',($x0 + $w - ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k));
  19484. /*-- BORDER-RADIUS --*/
  19485. }
  19486. if ($brTL_H && $brTL_V ) {
  19487. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_top/2) + $brTL_H )*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k));
  19488. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_top/2 , $brTL_V - $border_top/2 , 2, 1));
  19489. }
  19490. else {
  19491. /*-- END BORDER-RADIUS --*/
  19492. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k));
  19493. /*-- BORDER-RADIUS --*/
  19494. }
  19495. /*-- END BORDER-RADIUS --*/
  19496. $this->_out('S');
  19497. // Reset Corners and Dash off
  19498. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19499. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19500. $this->SetDash();
  19501. }
  19502. }
  19503. //if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1) {
  19504. // Reinstate line above for dotted line divider when block border crosses a page
  19505. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19506. $tbd = $this->blk[$blvl]['border_bottom'];
  19507. if (isset($tbd['s']) && $tbd['s']) {
  19508. $this->_setBorderLine($tbd);
  19509. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'B'); }
  19510. /*-- BORDER-RADIUS --*/
  19511. else if (($brBL_V && $brBL_H) || ($brBR_V && $brBR_H)) {
  19512. $this->SetLineJoin(0); // mPDF 5.0.051 n j
  19513. $this->SetLineCap(0); // mPDF 5.0.051 n J
  19514. }
  19515. if ($brBL_H && $brBL_V) {
  19516. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_bottom/2 , $brBL_V - $border_bottom/2 , 3, 2, true));
  19517. }
  19518. else {
  19519. /*-- END BORDER-RADIUS --*/
  19520. $this->_out(sprintf('%.3f %.3f m ',($x0 + ($border_bottom/2))*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k));
  19521. /*-- BORDER-RADIUS --*/
  19522. }
  19523. if ($brBR_H && $brBR_V ) {
  19524. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_bottom/2) - $brBR_H )*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k));
  19525. $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_bottom/2 , $brBR_V - $border_bottom/2 , 4, 1));
  19526. }
  19527. else {
  19528. /*-- END BORDER-RADIUS --*/
  19529. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_bottom/2) )*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k));
  19530. /*-- BORDER-RADIUS --*/
  19531. }
  19532. /*-- END BORDER-RADIUS --*/
  19533. $this->_out('S');
  19534. // Reset Corners and Dash off
  19535. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19536. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19537. $this->SetDash();
  19538. }
  19539. }
  19540. if ($this->blk[$blvl]['border_left']) {
  19541. $tbd = $this->blk[$blvl]['border_left'];
  19542. if (isset($tbd['s']) && $tbd['s']) {
  19543. $this->_setBorderLine($tbd);
  19544. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'L'); }
  19545. /*-- BORDER-RADIUS --*/
  19546. else if (($brTL_V && $brTL_H) || ($brBL_V && $brBL_H)) {
  19547. $this->SetLineJoin(0); // mPDF 5.0.051 n j
  19548. $this->SetLineCap(0); // mPDF 5.0.051 n J
  19549. }
  19550. if ($brTL_V && $brTL_H) {
  19551. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_left/2 , $brTL_V - $border_left/2, 2, 2, true));
  19552. }
  19553. else {
  19554. /*-- END BORDER-RADIUS --*/
  19555. $this->_out(sprintf('%.3f %.3f m ',($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + ($border_left/2)))*$this->k));
  19556. /*-- BORDER-RADIUS --*/
  19557. }
  19558. if ($brBL_V && $brBL_H ) {
  19559. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + $h - ($border_left/2)- $brBL_V) )*$this->k));
  19560. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_left/2 , $brBL_V - $border_left/2, 3, 1));
  19561. }
  19562. else {
  19563. /*-- END BORDER-RADIUS --*/
  19564. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + $h - ($border_left/2)) )*$this->k));
  19565. /*-- BORDER-RADIUS --*/
  19566. }
  19567. /*-- END BORDER-RADIUS --*/
  19568. $this->_out('S');
  19569. // Reset Corners and Dash off
  19570. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19571. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19572. $this->SetDash();
  19573. }
  19574. }
  19575. if ($this->blk[$blvl]['border_right']) {
  19576. $tbd = $this->blk[$blvl]['border_right'];
  19577. if (isset($tbd['s']) && $tbd['s']) {
  19578. $this->_setBorderLine($tbd);
  19579. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'R'); }
  19580. /*-- BORDER-RADIUS --*/
  19581. else if (($brTR_V && $brTR_H) || ($brBR_V && $brBR_H)) {
  19582. $this->SetLineJoin(0); // mPDF 5.0.051 n j
  19583. $this->SetLineCap(0); // mPDF 5.0.051 n J
  19584. }
  19585. if ($brBR_V && $brBR_H) {
  19586. $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_right/2 , $brBR_V - $border_right/2, 4, 2, true));
  19587. }
  19588. else {
  19589. /*-- END BORDER-RADIUS --*/
  19590. $this->_out(sprintf('%.3f %.3f m ',($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + $h - ($border_right/2)))*$this->k));
  19591. /*-- BORDER-RADIUS --*/
  19592. }
  19593. if ($brTR_V && $brTR_H ) {
  19594. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + ($border_right/2) + $brTR_V) )*$this->k));
  19595. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_right/2 , $brTR_V - $border_right/2, 1, 1));
  19596. }
  19597. else {
  19598. /*-- END BORDER-RADIUS --*/
  19599. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + ($border_right/2)) )*$this->k));
  19600. /*-- BORDER-RADIUS --*/
  19601. }
  19602. /*-- END BORDER-RADIUS --*/
  19603. $this->_out('S');
  19604. // Reset Corners and Dash off
  19605. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19606. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19607. $this->SetDash();
  19608. }
  19609. }
  19610. if (!$brset) { // not if border-radius used
  19611. $tbcol = $this->ConvertColor(255); // mPDF 5.0.051
  19612. for($l=0; $l <= $blvl; $l++) {
  19613. if ($this->blk[$l]['bgcolor']) {
  19614. $tbcol = $this->blk[$l]['bgcolorarray']; // mPDF 5.0.020
  19615. }
  19616. }
  19617. }
  19618. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19619. $tbd = $this->blk[$blvl]['border_top'];
  19620. if (isset($tbd['s']) && $tbd['s']) {
  19621. if (!$brset && $tbd['style']=='double') {
  19622. $this->SetLineWidth($tbd['w']/3);
  19623. $this->SetDColor($tbcol); // mPDF 5.0.051
  19624. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + $w - ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k, ($x0 + ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k ));
  19625. }
  19626. }
  19627. }
  19628. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19629. $tbd = $this->blk[$blvl]['border_bottom'];
  19630. if (isset($tbd['s']) && $tbd['s']) {
  19631. if (!$brset && $tbd['style']=='double') {
  19632. $this->SetLineWidth($tbd['w']/3);
  19633. $this->SetDColor($tbcol); // mPDF 5.0.051
  19634. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + ($border_bottom/2))*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k, ($x0 + $w - ($border_bottom/2) )*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k ));
  19635. }
  19636. }
  19637. }
  19638. if ($this->blk[$blvl]['border_left']) {
  19639. $tbd = $this->blk[$blvl]['border_left'];
  19640. if (isset($tbd['s']) && $tbd['s']) {
  19641. if (!$brset && $tbd['style']=='double') {
  19642. $this->SetLineWidth($tbd['w']/3);
  19643. $this->SetDColor($tbcol); // mPDF 5.0.051
  19644. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + ($border_left/2)))*$this->k, ($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + $h - ($border_left/2)) )*$this->k));
  19645. }
  19646. }
  19647. }
  19648. if ($this->blk[$blvl]['border_right']) {
  19649. $tbd = $this->blk[$blvl]['border_right'];
  19650. if (isset($tbd['s']) && $tbd['s']) {
  19651. if (!$brset && $tbd['style']=='double') {
  19652. $this->SetLineWidth($tbd['w']/3);
  19653. $this->SetDColor($tbcol); // mPDF 5.0.051
  19654. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + $h - ($border_right/2)))*$this->k, ($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + ($border_right/2)) )*$this->k));
  19655. }
  19656. }
  19657. }
  19658. $this->SetDash();
  19659. $this->y = $save_y;
  19660. // BACKGROUNDS are disabled in columns/kbt/headers - messes up the repositioning in printcolumnbuffer
  19661. if ($this->ColActive || $this->kwt || $this->keep_block_together) { return ; }
  19662. $bgx0 = $x0;
  19663. $bgx1 = $x1;
  19664. $bgy0 = $y0;
  19665. $bgy1 = $y1;
  19666. /*-- BORDER-RADIUS --*/
  19667. // Defined br values represent the radius of the outer curve - need to take border-width/2 from each radius for drawing the borders
  19668. if (isset($this->blk[$blvl]['background_clip']) && $this->blk[$blvl]['background_clip'] == 'padding-box') {
  19669. $brbgTL_H = max(0, $brTL_H - $this->blk[$blvl]['border_left']['w']);
  19670. $brbgTL_V = max(0, $brTL_V - $this->blk[$blvl]['border_top']['w']);
  19671. $brbgTR_H = max(0, $brTR_H - $this->blk[$blvl]['border_right']['w']);
  19672. $brbgTR_V = max(0, $brTR_V - $this->blk[$blvl]['border_top']['w']);
  19673. $brbgBL_H = max(0, $brBL_H - $this->blk[$blvl]['border_left']['w']);
  19674. $brbgBL_V = max(0, $brBL_V - $this->blk[$blvl]['border_bottom']['w']);
  19675. $brbgBR_H = max(0, $brBR_H - $this->blk[$blvl]['border_right']['w']);
  19676. $brbgBR_V = max(0, $brBR_V - $this->blk[$blvl]['border_bottom']['w']);
  19677. $bgx0 += $this->blk[$blvl]['border_left']['w'];
  19678. $bgx1 -= $this->blk[$blvl]['border_right']['w'];
  19679. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19680. $bgy0 += $this->blk[$blvl]['border_top']['w'];
  19681. }
  19682. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19683. $bgy1 -= $this->blk[$blvl]['border_bottom']['w'];
  19684. }
  19685. }
  19686. else {
  19687. /*-- END BORDER-RADIUS --*/
  19688. $brbgTL_H = $brTL_H;
  19689. $brbgTL_V = $brTL_V;
  19690. $brbgTR_H = $brTR_H;
  19691. $brbgTR_V = $brTR_V;
  19692. $brbgBL_H = $brBL_H;
  19693. $brbgBL_V = $brBL_V;
  19694. $brbgBR_H = $brBR_H;
  19695. $brbgBR_V = $brBR_V;
  19696. /*-- BORDER-RADIUS --*/
  19697. }
  19698. /*-- END BORDER-RADIUS --*/
  19699. // Set clipping path
  19700. $s = ' q 0 w '; // Line width=0
  19701. $s .= sprintf('%.3f %.3f m ', ($bgx0+$brbgTL_H )*$this->k, ($this->h-$bgy0)*$this->k); // start point TL before the arc
  19702. /*-- BORDER-RADIUS --*/
  19703. if ($brbgTL_H || $brbgTL_V) {
  19704. $s .= $this->_EllipseArc($bgx0+$brbgTL_H, $bgy0+$brbgTL_V, $brbgTL_H , $brbgTL_V , 2); // segment 2 TL
  19705. }
  19706. /*-- END BORDER-RADIUS --*/
  19707. $s .= sprintf('%.3f %.3f l ', ($bgx0)*$this->k, ($this->h-($bgy1-$brbgBL_V ))*$this->k); // line to BL
  19708. /*-- BORDER-RADIUS --*/
  19709. if ($brbgBL_H || $brbgBL_V) {
  19710. $s .= $this->_EllipseArc($bgx0+$brbgBL_H, $bgy1-$brbgBL_V, $brbgBL_H , $brbgBL_V , 3); // segment 3 BL
  19711. }
  19712. /*-- END BORDER-RADIUS --*/
  19713. $s .= sprintf('%.3f %.3f l ', ($bgx1-$brbgBR_H )*$this->k, ($this->h-($bgy1))*$this->k); // line to BR
  19714. /*-- BORDER-RADIUS --*/
  19715. if ($brbgBR_H || $brbgBR_V) {
  19716. $s .= $this->_EllipseArc($bgx1-$brbgBR_H, $bgy1-$brbgBR_V, $brbgBR_H , $brbgBR_V , 4); // segment 4 BR
  19717. }
  19718. /*-- END BORDER-RADIUS --*/
  19719. $s .= sprintf('%.3f %.3f l ', ($bgx1)*$this->k, ($this->h-($bgy0+$brbgTR_V))*$this->k); // line to TR
  19720. /*-- BORDER-RADIUS --*/
  19721. if ($brbgTR_H || $brbgTR_V) {
  19722. $s .= $this->_EllipseArc($bgx1-$brbgTR_H, $bgy0+$brbgTR_V, $brbgTR_H , $brbgTR_V , 1); // segment 1 TR
  19723. }
  19724. /*-- END BORDER-RADIUS --*/
  19725. $s .= sprintf('%.3f %.3f l ', ($bgx0+$brbgTL_H )*$this->k, ($this->h-$bgy0)*$this->k); // line to TL
  19726. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  19727. if ($this->blk[$blvl]['bgcolor']) {
  19728. $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'col'=>$this->blk[$blvl]['bgcolorarray'], 'clippath'=>$s);
  19729. }
  19730. /*-- BACKGROUNDS --*/
  19731. if (isset($this->blk[$blvl]['gradient'])) {
  19732. $g = $this->parseBackgroundGradient($this->blk[$blvl]['gradient']);
  19733. if ($g) {
  19734. $gx = $x0;
  19735. $gy = $y0;
  19736. // mPDF 5.0.020
  19737. $this->pageBackgrounds[$blvl][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$w, 'h'=>$h, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  19738. }
  19739. }
  19740. if (isset($this->blk[$blvl]['background-image'])) {
  19741. // mPDF 5.0.023
  19742. if ($this->blk[$blvl]['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->blk[$blvl]['background-image']['gradient'] )) {
  19743. $g = $this->parseMozGradient( $this->blk[$blvl]['background-image']['gradient'] );
  19744. if ($g) {
  19745. $gx = $x0;
  19746. $gy = $y0;
  19747. // mPDF 5.0.020
  19748. $this->pageBackgrounds[$blvl][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$w, 'h'=>$h, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  19749. }
  19750. }
  19751. else {
  19752. $image_id = $this->blk[$blvl]['background-image']['image_id'];
  19753. $orig_w = $this->blk[$blvl]['background-image']['orig_w'];
  19754. $orig_h = $this->blk[$blvl]['background-image']['orig_h'];
  19755. $x_pos = $this->blk[$blvl]['background-image']['x_pos'];
  19756. $y_pos = $this->blk[$blvl]['background-image']['y_pos'];
  19757. $x_repeat = $this->blk[$blvl]['background-image']['x_repeat'];
  19758. $y_repeat = $this->blk[$blvl]['background-image']['y_repeat'];
  19759. $resize = $this->blk[$blvl]['background-image']['resize'];
  19760. $opacity = $this->blk[$blvl]['background-image']['opacity'];
  19761. $itype = $this->blk[$blvl]['background-image']['itype']; // mPDF 5.0.039
  19762. $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$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, 'itype'=>$itype); // mPDF 5.0.039
  19763. }
  19764. }
  19765. /*-- END BACKGROUNDS --*/
  19766. // Added mPDF 3.0 Float DIV
  19767. $this->blk[$blvl]['bb_painted'][$this->page] = true;
  19768. }
  19769. /*-- BORDER-RADIUS --*/
  19770. function _EllipseArc($x0, $y0, $rx, $ry, $seg = 1, $part=false, $start=false) { // Anticlockwise segment 1-4 TR-TL-BL-BR (part=1 or 2)
  19771. $s = '';
  19772. if ($rx<0) { $rx = 0; }
  19773. if ($ry<0) { $ry = 0; }
  19774. $rx *= $this->k;
  19775. $ry *= $this->k;
  19776. $astart = 0;
  19777. if ($seg == 1) { // Top Right
  19778. $afinish = 90;
  19779. $nSeg = 4;
  19780. }
  19781. else if ($seg == 2) { // Top Left
  19782. $afinish = 180;
  19783. $nSeg = 8;
  19784. }
  19785. else if ($seg == 3) { // Bottom Left
  19786. $afinish = 270;
  19787. $nSeg = 12;
  19788. }
  19789. else { // Bottom Right
  19790. $afinish = 360;
  19791. $nSeg = 16;
  19792. }
  19793. $astart = deg2rad((float) $astart);
  19794. $afinish = deg2rad((float) $afinish);
  19795. $totalAngle = $afinish - $astart;
  19796. $dt = $totalAngle / $nSeg; // segment angle
  19797. $dtm = $dt/3;
  19798. $x0 *= $this->k;
  19799. $y0 = ($this->h - $y0) * $this->k;
  19800. $t1 = $astart;
  19801. $a0 = $x0 + ($rx * cos($t1));
  19802. $b0 = $y0 + ($ry * sin($t1));
  19803. $c0 = -$rx * sin($t1);
  19804. $d0 = $ry * cos($t1);
  19805. $op = false;
  19806. for ($i = 1; $i <= $nSeg; $i++) {
  19807. // Draw this bit of the total curve
  19808. $t1 = ($i * $dt) + $astart;
  19809. $a1 = $x0 + ($rx * cos($t1));
  19810. $b1 = $y0 + ($ry * sin($t1));
  19811. $c1 = -$rx * sin($t1);
  19812. $d1 = $ry * cos($t1);
  19813. if ($i>($nSeg-4) && (!$part || ($part == 1 && $i<=$nSeg-2) || ($part == 2 && $i>$nSeg-2))) {
  19814. if ($start && !$op) {
  19815. $s .= sprintf('%.3f %.3f m ', $a0, $b0);
  19816. }
  19817. $s .= sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c ', ($a0 + ($c0 * $dtm)), ($b0 + ($d0 * $dtm)), ($a1 - ($c1 * $dtm)) , ($b1 - ($d1 * $dtm)), $a1 , $b1 );
  19818. $op = true;
  19819. }
  19820. $a0 = $a1;
  19821. $b0 = $b1;
  19822. $c0 = $c1;
  19823. $d0 = $d1;
  19824. }
  19825. return $s;
  19826. }
  19827. /*-- END BORDER-RADIUS --*/
  19828. function PaintDivLnBorder($state=0,$blvl=0,$h) {
  19829. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  19830. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y + $h;
  19831. $save_y = $this->y;
  19832. $w = $this->blk[$blvl]['width'];
  19833. $x0 = $this->x; // left
  19834. $y0 = $this->y; // top
  19835. $x1 = $this->x + $w; // bottom
  19836. $y1 = $this->y + $h; // bottom
  19837. if ($this->blk[$blvl]['border_top'] && ($state==1 || $state==3)) {
  19838. $tbd = $this->blk[$blvl]['border_top'];
  19839. if (isset($tbd['s']) && $tbd['s']) {
  19840. $this->_setBorderLine($tbd);
  19841. $this->y = $y0 + ($tbd['w']/2);
  19842. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'T'); }
  19843. $this->Line($x0 + ($tbd['w']/2) , $this->y , $x0 + $w - ($tbd['w']/2), $this->y);
  19844. $this->y += $tbd['w'];
  19845. // Reset Corners and Dash off
  19846. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19847. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19848. $this->SetDash();
  19849. }
  19850. }
  19851. if ($this->blk[$blvl]['border_left']) {
  19852. $tbd = $this->blk[$blvl]['border_left'];
  19853. if (isset($tbd['s']) && $tbd['s']) {
  19854. $this->_setBorderLine($tbd);
  19855. $this->y = $y0 + ($tbd['w']/2);
  19856. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'L'); }
  19857. $this->Line($x0 + ($tbd['w']/2), $this->y, $x0 + ($tbd['w']/2), $y0 + $h -($tbd['w']/2));
  19858. $this->y += $tbd['w'];
  19859. // Reset Corners and Dash off
  19860. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19861. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19862. $this->SetDash();
  19863. }
  19864. }
  19865. if ($this->blk[$blvl]['border_right']) {
  19866. $tbd = $this->blk[$blvl]['border_right'];
  19867. if (isset($tbd['s']) && $tbd['s']) {
  19868. $this->_setBorderLine($tbd);
  19869. $this->y = $y0 + ($tbd['w']/2);
  19870. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'R'); }
  19871. $this->Line($x0 + $w - ($tbd['w']/2), $this->y, $x0 + $w - ($tbd['w']/2), $y0 + $h - ($tbd['w']/2));
  19872. $this->y += $tbd['w'];
  19873. // Reset Corners and Dash off
  19874. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19875. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19876. $this->SetDash();
  19877. }
  19878. }
  19879. if ($this->blk[$blvl]['border_bottom'] && $state > 1) {
  19880. $tbd = $this->blk[$blvl]['border_bottom'];
  19881. if (isset($tbd['s']) && $tbd['s']) {
  19882. $this->_setBorderLine($tbd);
  19883. $this->y = $y0 + $h - ($tbd['w']/2);
  19884. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'B'); }
  19885. $this->Line($x0 + ($tbd['w']/2) , $this->y, $x0 + $w - ($tbd['w']/2), $this->y);
  19886. $this->y += $tbd['w'];
  19887. // Reset Corners and Dash off
  19888. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19889. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19890. $this->SetDash();
  19891. }
  19892. }
  19893. $this->SetDash();
  19894. $this->y = $save_y;
  19895. }
  19896. function PaintImgBorder($objattr,$is_table) {
  19897. // Borders are disabled in columns - messes up the repositioning in printcolumnbuffer
  19898. if ($this->ColActive) { return ; } // *COLUMNS*
  19899. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  19900. $h = $objattr['BORDER-HEIGHT'];
  19901. $w = $objattr['BORDER-WIDTH'];
  19902. $x0 = $objattr['BORDER-X'];
  19903. $y0 = $objattr['BORDER-Y'];
  19904. // BORDERS
  19905. if ($objattr['border_top']) {
  19906. $tbd = $objattr['border_top'];
  19907. if (!empty($tbd['s'])) { // mPDF 5.0.052
  19908. $this->_setBorderLine($tbd,$k);
  19909. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','T'); }
  19910. $this->Line($x0, $y0, $x0 + $w, $y0);
  19911. // Reset Corners and Dash off
  19912. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19913. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19914. $this->SetDash();
  19915. }
  19916. }
  19917. if ($objattr['border_left']) {
  19918. $tbd = $objattr['border_left'];
  19919. if (!empty($tbd['s'])) { // mPDF 5.0.052
  19920. $this->_setBorderLine($tbd,$k);
  19921. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','L'); }
  19922. $this->Line($x0, $y0, $x0, $y0 + $h);
  19923. // Reset Corners and Dash off
  19924. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19925. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19926. $this->SetDash();
  19927. }
  19928. }
  19929. if ($objattr['border_right']) {
  19930. $tbd = $objattr['border_right'];
  19931. if (!empty($tbd['s'])) { // mPDF 5.0.052
  19932. $this->_setBorderLine($tbd,$k);
  19933. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','R'); }
  19934. $this->Line($x0 + $w, $y0, $x0 + $w, $y0 + $h);
  19935. // Reset Corners and Dash off
  19936. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19937. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19938. $this->SetDash();
  19939. }
  19940. }
  19941. if ($objattr['border_bottom']) {
  19942. $tbd = $objattr['border_bottom'];
  19943. if (!empty($tbd['s'])) { // mPDF 5.0.052
  19944. $this->_setBorderLine($tbd,$k);
  19945. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','B'); }
  19946. $this->Line($x0, $y0 + $h, $x0 + $w, $y0 + $h);
  19947. // Reset Corners and Dash off
  19948. $this->SetLineJoin(2); // mPDF 5.0.051 n j
  19949. $this->SetLineCap(2); // mPDF 5.0.051 n J
  19950. $this->SetDash();
  19951. }
  19952. }
  19953. $this->SetDash();
  19954. $this->SetAlpha(1); // mPDF 5.0.051
  19955. }
  19956. function Reset() {
  19957. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  19958. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  19959. $this->SetFColor($this->ConvertColor(255)); // mPDF 5.0.051
  19960. $this->SetAlpha(1); // mPDF 5.0.051
  19961. $this->colorarray = array();
  19962. $this->issetcolor = false;
  19963. $this->spanbgcolorarray = array();
  19964. $this->spanbgcolor = false;
  19965. $this->ResetStyles(); // mPDF 5.0
  19966. $this->HREF = '';
  19967. $this->outlineparam = array();
  19968. $this->outline_on = false;
  19969. $this->SetTextOutline(false);
  19970. $this->SUP = false;
  19971. $this->SUB = false;
  19972. $this->strike = false;
  19973. $this->SetFont($this->default_font,'',0,false);
  19974. $this->SetFontSize($this->default_font_size,false);
  19975. $this->currentfontfamily = '';
  19976. $this->currentfontsize = '';
  19977. /*-- TABLES --*/
  19978. if ($this->tableLevel) {
  19979. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  19980. }
  19981. else
  19982. /*-- END TABLES --*/
  19983. /*-- LISTS --*/
  19984. if ($this->listlvl && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) {
  19985. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height
  19986. }
  19987. else
  19988. /*-- END LISTS --*/
  19989. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  19990. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  19991. }
  19992. $this->toupper = false;
  19993. $this->tolower = false;
  19994. $this->kerning = false; // mPDF 5.0.063
  19995. $this->lSpacingCSS = ''; // mPDF 5.0.063
  19996. $this->wSpacingCSS = ''; // mPDF 5.0.063
  19997. $this->fixedlSpacing = false; // mPDF 5.0.063
  19998. $this->minwSpacing = 0; // mPDF 5.0.063
  19999. $this->capitalize = false; // mPDF 5.0.062
  20000. $this->SetDash(); //restore to no dash
  20001. $this->dash_on = false;
  20002. $this->dotted_on = false;
  20003. $this->divwidth = 0;
  20004. $this->divheight = 0;
  20005. $this->divalign = ''; // mPDF 5.0.054
  20006. $this->divrevert = false;
  20007. $this->oldy = -1;
  20008. $bodystyle = array();
  20009. if (isset($this->CSS['BODY']['FONT-STYLE'])) { $bodystyle['FONT-STYLE'] = $this->CSS['BODY']['FONT-STYLE']; }
  20010. if (isset($this->CSS['BODY']['FONT-WEIGHT'])) { $bodystyle['FONT-WEIGHT'] = $this->CSS['BODY']['FONT-WEIGHT']; }
  20011. if (isset($this->CSS['BODY']['COLOR'])) { $bodystyle['COLOR'] = $this->CSS['BODY']['COLOR']; }
  20012. if (isset($bodystyle)) { $this->setCSS($bodystyle,'BLOCK','BODY'); }
  20013. }
  20014. function ReadMetaTags($html) {
  20015. // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
  20016. $regexp = '/ (\\w+?)=([^\\s>"]+)/si';
  20017. $html = preg_replace($regexp," \$1=\"\$2\"",$html);
  20018. if (preg_match('/<title>(.*?)<\/title>/si',$html,$m)) {
  20019. $this->SetTitle($m[1]);
  20020. }
  20021. preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|content)="([^>]*?)".*?>/si',$html,$aux);
  20022. $firstattr = $aux[1];
  20023. $secondattr = $aux[3];
  20024. for( $i = 0 ; $i < count($aux[0]) ; $i++) {
  20025. $name = ( strtoupper($firstattr[$i]) == "NAME" )? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]);
  20026. $content = ( strtoupper($firstattr[$i]) == "CONTENT" )? $aux[2][$i] : $aux[4][$i];
  20027. switch($name) {
  20028. case "KEYWORDS": $this->SetKeywords($content); break;
  20029. case "AUTHOR": $this->SetAuthor($content); break;
  20030. case "DESCRIPTION": $this->SetSubject($content); break;
  20031. }
  20032. }
  20033. }
  20034. function ReadCharset($html) {
  20035. // Charset conversion
  20036. if ($this->allow_charset_conversion) {
  20037. if (preg_match('/<head.*charset=([^\'\"\s]*).*<\/head>/si',$html,$m)) {
  20038. if (strtoupper($m[1]) != 'UTF-8') {
  20039. $this->charset_in = strtoupper($m[1]);
  20040. }
  20041. }
  20042. }
  20043. }
  20044. //////////////////
  20045. /// CSS parser ///
  20046. //////////////////
  20047. //////////////////
  20048. /// CSS parser ///
  20049. //////////////////
  20050. //////////////////
  20051. /// CSS parser ///
  20052. //////////////////
  20053. function ReadDefaultCSS($CSSstr) {
  20054. $CSS = array();
  20055. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  20056. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  20057. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  20058. if ($CSSstr ) {
  20059. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  20060. for($i=0; $i < count($styles[1]) ; $i++) {
  20061. $stylestr= trim($styles[2][$i]);
  20062. $stylearr = explode(';',$stylestr);
  20063. foreach($stylearr AS $sta) {
  20064. if (trim($sta)) {
  20065. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  20066. list($property,$value) = explode(':',$sta,2);
  20067. $property = trim($property);
  20068. $value = preg_replace('/\s*!important/i','',$value);
  20069. $value = trim($value);
  20070. if ($property && ($value || $value==='0')) {
  20071. $classproperties[strtoupper($property)] = $value;
  20072. }
  20073. }
  20074. }
  20075. $classproperties = $this->fixCSS($classproperties);
  20076. $tagstr = strtoupper(trim($styles[1][$i]));
  20077. $tagarr = explode(',',$tagstr);
  20078. foreach($tagarr AS $tg) {
  20079. $tags = preg_split('/\s+/',trim($tg));
  20080. $level = count($tags);
  20081. if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  20082. $t = trim($tags[0]);
  20083. if ($t) {
  20084. $tag = '';
  20085. if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20086. if ($this->CSS[$tag] && $tag) { $CSS[$tag] = $this->array_merge_recursive_unique($CSS[$tag], $classproperties); }
  20087. else if ($tag) { $CSS[$tag] = $classproperties; }
  20088. }
  20089. }
  20090. }
  20091. $properties = array();
  20092. $values = array();
  20093. $classproperties = array();
  20094. }
  20095. } // end of if
  20096. return $CSS;
  20097. }
  20098. function ReadCSS($html) {
  20099. preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m);
  20100. for($i=0; $i<count($m[0]); $i++) {
  20101. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  20102. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  20103. }
  20104. }
  20105. preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m);
  20106. for($i=0; $i<count($m[0]); $i++) {
  20107. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  20108. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  20109. }
  20110. }
  20111. // Remove Comment tags <!-- --> inside CSS as <style> in HTML document
  20112. // Remove Comment tags /* ... */ inside CSS as <style> in HTML document // mPDF 5.0.013
  20113. preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
  20114. if (count($m[1])) {
  20115. for($i=0;$i<count($m[1]);$i++) {
  20116. // Remove comment tags
  20117. $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
  20118. $sub = preg_replace('|/\*.*?\*/|s',' ',$sub); // mPDF 5.0.013
  20119. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  20120. }
  20121. }
  20122. $html = preg_replace('/<!--mpdf/i','',$html);
  20123. $html = preg_replace('/mpdf-->/i','',$html);
  20124. $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html);
  20125. $match = 0; // no match for instance
  20126. $regexp = ''; // This helps debugging: showing what is the REAL string being processed
  20127. $CSSext = array();
  20128. //CSS inside external files
  20129. $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si'; // EDIT mPDF 4.0
  20130. $x = preg_match_all($regexp,$html,$cxt);
  20131. if ($x) {
  20132. $match += $x;
  20133. $CSSext = $cxt[1];
  20134. }
  20135. $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si'; // EDIT mPDF 4.0
  20136. $x = preg_match_all($regexp,$html,$cxt);
  20137. if ($x) {
  20138. $match += $x;
  20139. $CSSext = array_merge($CSSext,$cxt[1]);
  20140. }
  20141. // look for @import stylesheets
  20142. $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si'; // EDIT mPDF 4.0
  20143. $x = preg_match_all($regexp,$html,$cxt);
  20144. if ($x) {
  20145. $match += $x;
  20146. $CSSext = array_merge($CSSext,$cxt[1]);
  20147. }
  20148. // look for @import without the url()
  20149. $regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
  20150. $x = preg_match_all($regexp,$html,$cxt);
  20151. if ($x) {
  20152. $match += $x;
  20153. $CSSext = array_merge($CSSext,$cxt[1]);
  20154. }
  20155. $ind = 0;
  20156. $CSSstr = '';
  20157. if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array();
  20158. while($match){
  20159. $path = $CSSext[$ind];
  20160. $this->GetFullPath($path);
  20161. $CSSextblock = $this->_get_file($path);
  20162. if ($CSSextblock) {
  20163. // look for embedded @import stylesheets in other stylesheets
  20164. // and fix url paths (including background-images) relative to stylesheet
  20165. $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
  20166. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  20167. $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/';
  20168. if ($xem) {
  20169. foreach($cxtem[1] AS $cxtembedded) {
  20170. // path is relative to original stlyesheet!!
  20171. $this->GetFullPath($cxtembedded, $cssBasePath );
  20172. $match++;
  20173. $CSSext[] = $cxtembedded;
  20174. }
  20175. }
  20176. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  20177. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  20178. if ($xem) {
  20179. for ($i=0;$i<count($cxtem[0]);$i++) {
  20180. // path is relative to original stlyesheet!!
  20181. $embedded = $cxtem[2][$i];
  20182. $this->GetFullPath($embedded, $cssBasePath );
  20183. $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock);
  20184. }
  20185. }
  20186. $CSSstr .= ' '.$CSSextblock;
  20187. }
  20188. $match--;
  20189. $ind++;
  20190. } //end of match
  20191. $match = 0; // reset value, if needed
  20192. // CSS as <style> in HTML document
  20193. $regexp = '/<style.*?>(.*?)<\/style>/si';
  20194. $match = preg_match_all($regexp,$html,$CSSblock);
  20195. if ($match) {
  20196. $tmpCSSstr = implode(' ',$CSSblock[1]);
  20197. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  20198. $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem);
  20199. if ($xem) {
  20200. for ($i=0;$i<count($cxtem[0]);$i++) {
  20201. $embedded = $cxtem[2][$i];
  20202. $this->GetFullPath($embedded);
  20203. $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr );
  20204. }
  20205. }
  20206. $CSSstr .= ' '.$tmpCSSstr;
  20207. }
  20208. // Remove comments
  20209. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  20210. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  20211. if (preg_match('/@media/',$CSSstr)) {
  20212. preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
  20213. for($i=0; $i<count($m[0]); $i++) {
  20214. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  20215. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
  20216. }
  20217. else {
  20218. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
  20219. }
  20220. }
  20221. }
  20222. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  20223. if ($CSSstr ) {
  20224. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  20225. for($i=0; $i < count($styles[1]) ; $i++) {
  20226. // SET array e.g. $classproperties['COLOR'] = '#ffffff';
  20227. $stylestr= trim($styles[2][$i]);
  20228. $stylearr = explode(';',$stylestr);
  20229. foreach($stylearr AS $sta) {
  20230. if (trim($sta)) {
  20231. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  20232. list($property,$value) = explode(':',$sta,2);
  20233. $property = trim($property);
  20234. $value = preg_replace('/\s*!important/i','',$value);
  20235. $value = trim($value);
  20236. if ($property && ($value || $value==='0')) {
  20237. // mPDF 5.0.023 Ignores -webkit-gradient so doesn't override -moz-
  20238. if ((strtoupper($property)=='BACKGROUND-IMAGE' || strtoupper($property)=='BACKGROUND') && preg_match('/-webkit-gradient/i',$value)) {
  20239. continue;
  20240. }
  20241. $classproperties[strtoupper($property)] = $value;
  20242. }
  20243. }
  20244. }
  20245. $classproperties = $this->fixCSS($classproperties);
  20246. $tagstr = strtoupper(trim($styles[1][$i]));
  20247. $tagarr = explode(',',$tagstr);
  20248. $pageselectors = false; // used to turn on $this->mirrorMargins
  20249. foreach($tagarr AS $tg) {
  20250. $tags = preg_split('/\s+/',trim($tg));
  20251. $level = count($tags);
  20252. $t = '';
  20253. $t2 = '';
  20254. $t3 = '';
  20255. if (trim($tags[0])=='@PAGE') {
  20256. if (isset($tags[0])) { $t = trim($tags[0]); }
  20257. if (isset($tags[1])) { $t2 = trim($tags[1]); }
  20258. if (isset($tags[2])) { $t3 = trim($tags[2]); }
  20259. $tag = '';
  20260. if ($level==1) { $tag = $t; }
  20261. else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) {
  20262. $tag = $t.'>>PSEUDO>>'.$m[1];
  20263. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  20264. }
  20265. else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; }
  20266. else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) {
  20267. $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1];
  20268. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  20269. }
  20270. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  20271. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  20272. }
  20273. else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  20274. if (isset($tags[0])) { $t = trim($tags[0]); }
  20275. if ($t) {
  20276. $tag = '';
  20277. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  20278. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  20279. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  20280. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  20281. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20282. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  20283. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  20284. }
  20285. }
  20286. else {
  20287. $tmp = array();
  20288. for($n=0;$n<$level;$n++) {
  20289. if (isset($tags[$n])) { $t = trim($tags[$n]); }
  20290. else { $t = ''; }
  20291. if ($t) {
  20292. $tag = '';
  20293. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  20294. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  20295. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  20296. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  20297. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20298. if ($tag) $tmp[] = $tag;
  20299. else { break; }
  20300. }
  20301. }
  20302. if ($tag) {
  20303. $x = &$this->cascadeCSS;
  20304. foreach($tmp AS $tp) { $x = &$x[$tp]; }
  20305. $x = $this->array_merge_recursive_unique($x, $classproperties);
  20306. $x['depth'] = $level;
  20307. }
  20308. }
  20309. }
  20310. if ($pageselectors) { $this->mirrorMargins = true; }
  20311. $properties = array();
  20312. $values = array();
  20313. $classproperties = array();
  20314. }
  20315. } // end of if
  20316. //Remove CSS (tags and content), if any
  20317. $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
  20318. $html = preg_replace($regexp,'',$html);
  20319. //print_r($this->CSS); exit;
  20320. //print_r($this->cascadeCSS); exit;
  20321. return $html;
  20322. }
  20323. function readInlineCSS($html) {
  20324. //Fix incomplete CSS code
  20325. $size = strlen($html)-1;
  20326. if (substr($html,$size,1) != ';') $html .= ';';
  20327. //Make CSS[Name-of-the-class] = array(key => value)
  20328. $regexp = '|\\s*?(\\S+?):(.+?);|i';
  20329. preg_match_all( $regexp, $html, $styleinfo);
  20330. $properties = $styleinfo[1];
  20331. $values = $styleinfo[2];
  20332. //Array-properties and Array-values must have the SAME SIZE!
  20333. $classproperties = array();
  20334. for($i = 0; $i < count($properties) ; $i++) {
  20335. // mPDF 5.0.023 Ignores -webkit-gradient so doesn't override -moz-
  20336. if ((strtoupper($properties[$i])=='BACKGROUND-IMAGE' || strtoupper($properties[$i])=='BACKGROUND') && preg_match('/-webkit-gradient/i',$values[$i])) {
  20337. continue;
  20338. }
  20339. $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
  20340. }
  20341. return $this->fixCSS($classproperties);
  20342. }
  20343. function setCSS($arrayaux,$type='',$tag='') { // type= INLINE | BLOCK // tag= BODY
  20344. if (!is_array($arrayaux)) return; //Removes PHP Warning
  20345. // Set font size first so that e.g. MARGIN 0.83em works on font size for this element
  20346. if (isset($arrayaux['FONT-SIZE'])) {
  20347. $v = $arrayaux['FONT-SIZE'];
  20348. if(is_numeric($v[0])) {
  20349. $mmsize = $this->ConvertSize($v,$this->FontSize);
  20350. $this->SetFontSize( $mmsize*($this->k),false ); //Get size in points (pt)
  20351. }
  20352. else{
  20353. $v = strtoupper($v);
  20354. if (isset($this->fontsizes[$v])) {
  20355. $this->SetFontSize( $this->fontsizes[$v]* $this->default_font_size,false);
  20356. }
  20357. }
  20358. if ($tag == 'BODY') { $this->SetDefaultFontSize($this->FontSizePt); }
  20359. }
  20360. if ($this->useLang && !$this->usingCoreFont) {
  20361. if (isset($arrayaux['LANG']) && $arrayaux['LANG'] && $arrayaux['LANG'] != $this->default_lang && ((strlen($arrayaux['LANG']) == 5 && $arrayaux['LANG'] != 'UTF-8') || strlen($arrayaux['LANG']) == 2)) {
  20362. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($arrayaux['LANG'], $this->useAdobeCJK);
  20363. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  20364. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  20365. if ($tag == 'BODY') {
  20366. $this->currentLang = $arrayaux['LANG'];
  20367. $this->default_lang = $arrayaux['LANG'];
  20368. if ($mpdf_pdf_unifonts) { $this->default_available_fonts = $mpdf_pdf_unifonts; }
  20369. }
  20370. }
  20371. else {
  20372. $this->RestrictUnicodeFonts($this->default_available_fonts );
  20373. }
  20374. }
  20375. // FOR INLINE and BLOCK OR 'BODY'
  20376. if (isset($arrayaux['FONT-FAMILY'])) {
  20377. $v = $arrayaux['FONT-FAMILY'];
  20378. //If it is a font list, get all font types
  20379. $aux_fontlist = explode(",",$v);
  20380. $found = 0;
  20381. foreach($aux_fontlist AS $f) {
  20382. $fonttype = trim($f);
  20383. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  20384. $fonttype = preg_replace('/ /','',$fonttype);
  20385. $v = strtolower(trim($fonttype));
  20386. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  20387. if ((!$this->usingCoreFont && in_array($v,$this->available_unifonts)) ||
  20388. ($this->usingCoreFont && in_array($v,array('courier','times','helvetica','arial'))) ||
  20389. in_array($v, array('sjis','uhc','big5','gb'))) {
  20390. $fonttype = $v;
  20391. $found = 1;
  20392. break;
  20393. }
  20394. }
  20395. if (!$found) {
  20396. foreach($aux_fontlist AS $f) {
  20397. $fonttype = trim($f);
  20398. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  20399. $fonttype = preg_replace('/ /','',$fonttype);
  20400. $v = strtolower(trim($fonttype));
  20401. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  20402. if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  20403. $fonttype = $v;
  20404. break;
  20405. }
  20406. }
  20407. }
  20408. if ($tag == 'BODY') {
  20409. $this->SetDefaultFont($fonttype);
  20410. }
  20411. $this->SetFont($fonttype,$this->currentfontstyle,0,false);
  20412. }
  20413. else {
  20414. $this->SetFont($this->currentfontfamily,$this->currentfontstyle,0,false);
  20415. }
  20416. foreach($arrayaux as $k => $v) {
  20417. if ($type != 'INLINE' && $tag != 'BODY') {
  20418. switch($k){
  20419. // BORDERS
  20420. case 'BORDER-TOP':
  20421. $this->blk[$this->blklvl]['border_top'] = $this->border_details($v);
  20422. if ($this->blk[$this->blklvl]['border_top']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20423. break;
  20424. case 'BORDER-BOTTOM':
  20425. $this->blk[$this->blklvl]['border_bottom'] = $this->border_details($v);
  20426. if ($this->blk[$this->blklvl]['border_bottom']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20427. break;
  20428. case 'BORDER-LEFT':
  20429. $this->blk[$this->blklvl]['border_left'] = $this->border_details($v);
  20430. if ($this->blk[$this->blklvl]['border_left']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20431. break;
  20432. case 'BORDER-RIGHT':
  20433. $this->blk[$this->blklvl]['border_right'] = $this->border_details($v);
  20434. if ($this->blk[$this->blklvl]['border_right']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20435. break;
  20436. // PADDING
  20437. case 'PADDING-TOP':
  20438. $this->blk[$this->blklvl]['padding_top'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20439. break;
  20440. case 'PADDING-BOTTOM':
  20441. $this->blk[$this->blklvl]['padding_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20442. break;
  20443. case 'PADDING-LEFT':
  20444. $this->blk[$this->blklvl]['padding_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20445. break;
  20446. case 'PADDING-RIGHT':
  20447. $this->blk[$this->blklvl]['padding_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20448. break;
  20449. // MARGINS
  20450. case 'MARGIN-TOP':
  20451. $tmp = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20452. if (isset($this->blk[$this->blklvl]['lastbottommargin'])) {
  20453. if ($tmp > $this->blk[$this->blklvl]['lastbottommargin']) {
  20454. $tmp -= $this->blk[$this->blklvl]['lastbottommargin'];
  20455. }
  20456. else {
  20457. $tmp = 0;
  20458. }
  20459. }
  20460. $this->blk[$this->blklvl]['margin_top'] = $tmp;
  20461. break;
  20462. case 'MARGIN-BOTTOM':
  20463. $this->blk[$this->blklvl]['margin_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20464. break;
  20465. case 'MARGIN-LEFT':
  20466. $this->blk[$this->blklvl]['margin_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20467. break;
  20468. case 'MARGIN-RIGHT':
  20469. $this->blk[$this->blklvl]['margin_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20470. break;
  20471. /*-- BORDER-RADIUS --*/
  20472. case 'BORDER-TOP-LEFT-RADIUS-H':
  20473. $this->blk[$this->blklvl]['border_radius_TL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20474. break;
  20475. case 'BORDER-TOP-LEFT-RADIUS-V':
  20476. $this->blk[$this->blklvl]['border_radius_TL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20477. break;
  20478. case 'BORDER-TOP-RIGHT-RADIUS-H':
  20479. $this->blk[$this->blklvl]['border_radius_TR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20480. break;
  20481. case 'BORDER-TOP-RIGHT-RADIUS-V':
  20482. $this->blk[$this->blklvl]['border_radius_TR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20483. break;
  20484. case 'BORDER-BOTTOM-LEFT-RADIUS-H':
  20485. $this->blk[$this->blklvl]['border_radius_BL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20486. break;
  20487. case 'BORDER-BOTTOM-LEFT-RADIUS-V':
  20488. $this->blk[$this->blklvl]['border_radius_BL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20489. break;
  20490. case 'BORDER-BOTTOM-RIGHT-RADIUS-H':
  20491. $this->blk[$this->blklvl]['border_radius_BR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20492. break;
  20493. case 'BORDER-BOTTOM-RIGHT-RADIUS-V':
  20494. $this->blk[$this->blklvl]['border_radius_BR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20495. break;
  20496. /*-- END BORDER-RADIUS --*/
  20497. case 'BACKGROUND-CLIP':
  20498. if (strtoupper($v) == 'PADDING-BOX') { $this->blk[$this->blklvl]['background_clip'] = 'padding-box'; }
  20499. break;
  20500. case 'PAGE-BREAK-AFTER':
  20501. if (strtoupper($v) == 'AVOID') { $this->blk[$this->blklvl]['page_break_after_avoid'] = true; }
  20502. break;
  20503. case 'WIDTH':
  20504. if (strtoupper($v) != 'AUTO') {
  20505. $this->blk[$this->blklvl]['css_set_width'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20506. }
  20507. break;
  20508. case 'TEXT-INDENT':
  20509. // Left as raw value (may include 1% or 2em)
  20510. $this->blk[$this->blklvl]['text_indent'] = $v;
  20511. break;
  20512. }//end of switch($k)
  20513. }
  20514. if ($type != 'INLINE') { // includes BODY tag
  20515. switch($k){
  20516. case 'MARGIN-COLLAPSE': // Custom tag to collapse margins at top and bottom of page
  20517. if (strtoupper($v) == 'COLLAPSE') { $this->blk[$this->blklvl]['margin_collapse'] = true; }
  20518. break;
  20519. case 'LINE-HEIGHT':
  20520. $this->blk[$this->blklvl]['line_height'] = $this->fixLineheight($v);
  20521. if (!$this->blk[$this->blklvl]['line_height'] ) { $this->blk[$this->blklvl]['line_height'] = $this->normalLineheight; }
  20522. break;
  20523. case 'TEXT-ALIGN': //left right center justify
  20524. switch (strtoupper($v)) {
  20525. case 'LEFT':
  20526. $this->blk[$this->blklvl]['align']="L";
  20527. break;
  20528. case 'CENTER':
  20529. $this->blk[$this->blklvl]['align']="C";
  20530. break;
  20531. case 'RIGHT':
  20532. $this->blk[$this->blklvl]['align']="R";
  20533. break;
  20534. case 'JUSTIFY':
  20535. $this->blk[$this->blklvl]['align']="J";
  20536. break;
  20537. }
  20538. break;
  20539. /*-- BACKGROUNDS --*/
  20540. case 'BACKGROUND-GRADIENT':
  20541. if ($type == 'BLOCK') {
  20542. $this->blk[$this->blklvl]['gradient'] = $v;
  20543. }
  20544. break;
  20545. /*-- END BACKGROUNDS --*/
  20546. // mPDF 5.0.054
  20547. case 'DIRECTION':
  20548. if ($v) { $this->blk[$this->blklvl]['direction'] = strtolower($v); }
  20549. break;
  20550. }//end of switch($k)
  20551. }
  20552. // mPDF 5.0
  20553. // FOR INLINE ONLY
  20554. if ($type == 'INLINE') {
  20555. switch($k){
  20556. case 'DISPLAY': // Custom tag to collapse margins at top and bottom of page
  20557. if (strtoupper($v) == 'NONE') { $this->inlineDisplayOff = true; }
  20558. break;
  20559. case 'DIRECTION':
  20560. // mPDF 5.0.054
  20561. break;
  20562. }//end of switch($k)
  20563. }
  20564. // FOR INLINE and BLOCK
  20565. switch($k){
  20566. case 'TEXT-ALIGN': //left right center justify
  20567. if (strtoupper($v) == 'NOJUSTIFY' && $this->blk[$this->blklvl]['align']=="J") {
  20568. $this->blk[$this->blklvl]['align']="";
  20569. }
  20570. break;
  20571. // bgcolor only - to stay consistent with original html2fpdf
  20572. case 'BACKGROUND':
  20573. case 'BACKGROUND-COLOR':
  20574. $cor = $this->ConvertColor($v);
  20575. if ($cor) {
  20576. if ($tag == 'BODY') {
  20577. $this->bodyBackgroundColor = $cor;
  20578. }
  20579. else if ($type == 'INLINE') {
  20580. $this->spanbgcolorarray = $cor;
  20581. $this->spanbgcolor = true;
  20582. }
  20583. else {
  20584. $this->blk[$this->blklvl]['bgcolorarray'] = $cor;
  20585. $this->blk[$this->blklvl]['bgcolor'] = true;
  20586. }
  20587. }
  20588. else if ($type != 'INLINE') {
  20589. if ($this->ColActive || $this->keep_block_together) {
  20590. $this->blk[$this->blklvl]['bgcolorarray'] = $this->blk[$this->blklvl-1]['bgcolorarray'] ;
  20591. $this->blk[$this->blklvl]['bgcolor'] = $this->blk[$this->blklvl-1]['bgcolor'] ;
  20592. }
  20593. }
  20594. break;
  20595. // mPDF 5.0.063 auto | normal | none
  20596. case 'FONT-KERNING':
  20597. if ((strtoupper($v) == 'NORMAL' || strtoupper($v) == 'AUTO') && $this->useKerning) { $this->kerning = true; }
  20598. else if (strtoupper($v) == 'NONE') { $this->kerning = false; }
  20599. break;
  20600. // mPDF 5.0.063 normal | <length>
  20601. case 'LETTER-SPACING':
  20602. $this->lSpacingCSS = $v;
  20603. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { // mPDF 5.0.066
  20604. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); // mPDF 5.0.066
  20605. }
  20606. break;
  20607. // mPDF 5.0.063 normal | <length>
  20608. case 'WORD-SPACING':
  20609. $this->wSpacingCSS = $v;
  20610. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20611. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); // mPDF 5.0.066
  20612. }
  20613. break;
  20614. case 'FONT-STYLE': // italic normal oblique
  20615. switch (strtoupper($v)) {
  20616. case 'ITALIC':
  20617. case 'OBLIQUE':
  20618. $this->SetStyle('I',true);
  20619. break;
  20620. case 'NORMAL':
  20621. $this->SetStyle('I',false);
  20622. break;
  20623. }
  20624. break;
  20625. case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100)
  20626. switch (strtoupper($v)) {
  20627. case 'BOLD':
  20628. $this->SetStyle('B',true);
  20629. break;
  20630. case 'NORMAL':
  20631. $this->SetStyle('B',false);
  20632. break;
  20633. }
  20634. break;
  20635. case 'VERTICAL-ALIGN': //super and sub only dealt with here e.g. <SUB> and <SUP>
  20636. switch (strtoupper($v)) {
  20637. case 'SUPER':
  20638. $this->SUP=true;
  20639. break;
  20640. case 'SUB':
  20641. $this->SUB=true;
  20642. break;
  20643. }
  20644. break;
  20645. case 'TEXT-DECORATION': // none underline line-through (strikeout) //Does not support: overline, blink
  20646. if (stristr($v,'LINE-THROUGH')) {
  20647. $this->strike = true;
  20648. }
  20649. if (stristr($v,'UNDERLINE')) {
  20650. $this->SetStyle('U',true);
  20651. }
  20652. break;
  20653. case 'FONT-VARIANT': // mPDF 5.0
  20654. switch (strtoupper($v)) {
  20655. case 'SMALL-CAPS':
  20656. $this->SetStyle('S',true);
  20657. break;
  20658. case 'NORMAL':
  20659. $this->SetStyle('S',false);
  20660. break;
  20661. }
  20662. break;
  20663. case 'TEXT-TRANSFORM': // none uppercase lowercase //Does support: capitalize
  20664. switch (strtoupper($v)) { //Not working 100%
  20665. case 'CAPITALIZE':
  20666. $this->capitalize=true; // mPDF 5.0.062
  20667. break;
  20668. case 'UPPERCASE':
  20669. $this->toupper=true;
  20670. break;
  20671. case 'LOWERCASE':
  20672. $this->tolower=true;
  20673. break;
  20674. case 'NONE': break;
  20675. }
  20676. break;
  20677. case 'OUTLINE-WIDTH':
  20678. switch(strtoupper($v)) {
  20679. case 'THIN': $v = '0.03em'; break;
  20680. case 'MEDIUM': $v = '0.05em'; break;
  20681. case 'THICK': $v = '0.07em'; break;
  20682. }
  20683. $this->outlineparam['WIDTH'] = $this->ConvertSize($v,$this->blk[$this->blklvl]['inner_width'],$this->FontSize);
  20684. break;
  20685. case 'OUTLINE-COLOR':
  20686. if (strtoupper($v) == 'INVERT') {
  20687. if ($this->colorarray) {
  20688. $cor = $this->colorarray;
  20689. $this->outlineparam['COLOR'] = $this->_invertColor($cor); // mPDF 5.0.051
  20690. }
  20691. else {
  20692. $this->outlineparam['COLOR'] = $this->ConvertColor(255); // mPDF 5.0.051
  20693. }
  20694. }
  20695. else {
  20696. $cor = $this->ConvertColor($v);
  20697. if ($cor) { $this->outlineparam['COLOR'] = $cor ; }
  20698. }
  20699. break;
  20700. case 'COLOR': // font color
  20701. $cor = $this->ConvertColor($v);
  20702. if ($cor) {
  20703. $this->colorarray = $cor;
  20704. $this->SetTColor($cor); // mPDF 5.0.020
  20705. $this->issetcolor = true;
  20706. }
  20707. break;
  20708. }//end of switch($k)
  20709. }//end of foreach
  20710. }
  20711. function SetStyle($tag,$enable) {
  20712. $this->$tag=$enable;
  20713. $style='';
  20714. foreach(array('B','I','U','S') as $s) { // mPDF 5.0
  20715. if($this->$s) {
  20716. $style.=$s;
  20717. }
  20718. }
  20719. $this->currentfontstyle=$style;
  20720. $this->SetFont('',$style,0,false);
  20721. }
  20722. // Set multiple styles at one $str e.g. "BIS"
  20723. function SetStylesArray($arr) { // mPDF 5.0
  20724. $style='';
  20725. foreach(array('B','I','U','S') as $s) {
  20726. if (isset($arr[$s])) {
  20727. if ($arr[$s]) {
  20728. $this->$s = true;
  20729. $style.=$s;
  20730. }
  20731. else { $this->$s = false; }
  20732. }
  20733. else if ($this->$s) { $style.=$s; }
  20734. }
  20735. $this->currentfontstyle=$style;
  20736. $this->SetFont('',$style,0,false);
  20737. }
  20738. // Set multiple styles at one $str e.g. "BIS"
  20739. function SetStyles($str) { // mPDF 5.0
  20740. $style='';
  20741. foreach(array('B','I','U','S') as $s) {
  20742. if (strpos($str,$s) !== false) {
  20743. $this->$s = true;
  20744. $style.=$s;
  20745. }
  20746. else { $this->$s = false; }
  20747. }
  20748. $this->currentfontstyle=$style;
  20749. $this->SetFont('',$style,0,false);
  20750. }
  20751. function ResetStyles() { // mPDF 5.0
  20752. foreach(array('B','I','U','S') as $s) {
  20753. $this->$s = false;
  20754. }
  20755. $this->currentfontstyle='';
  20756. $this->SetFont('','',0,false);
  20757. }
  20758. function DisableTags($str='')
  20759. {
  20760. if ($str == '') //enable all tags
  20761. {
  20762. //Insert new supported tags in the long string below.
  20763. ///////////////////////////////////////////////////////
  20764. // Added custom tags <indexentry>
  20765. $this->enabledtags = "<span><s><strike><del><bdo><big><small><ins><cite><acronym><font><sup><sub><b><u><i><a><strong><em><code><samp><tt><kbd><var><q><table><thead><tfoot><tbody><tr><th><td><ol><ul><li><dl><dt><dd><form><input><select><textarea><option><div><p><h1><h2><h3><h4><h5><h6><pre><center><blockquote><address><hr><img><br><indexentry><indexinsert><bookmark><watermarktext><watermarkimage><tts><ttz><tta><column_break><columnbreak><newcolumn><newpage><page_break><pagebreak><formfeed><columns><toc><tocentry><tocpagebreak><pageheader><pagefooter><setpageheader><setpagefooter><sethtmlpageheader><sethtmlpagefooter><annotation><template><jpgraph><barcode><dottab>";
  20766. }
  20767. else
  20768. {
  20769. $str = explode(",",$str);
  20770. foreach($str as $v) $this->enabledtags = str_replace(trim($v),'',$this->enabledtags);
  20771. }
  20772. }
  20773. /*-- TABLES --*/
  20774. function finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight) {
  20775. $af = 0; // Above font
  20776. $bf = 0; // Below font
  20777. $mta = 0; // Maximum top-aligned
  20778. $mba = 0; // Maximum bottom-aligned
  20779. if ($lhxt['BS']) {
  20780. $af = max($af, ($lhxt['BS'] - ($maxfontsize * (0.5 + $this->baselineC))));
  20781. }
  20782. if ($lhxt['M']) {
  20783. $af = max($af, ($lhxt['M'] - $maxfontsize)/2);
  20784. $bf = max($bf, ($lhxt['M'] - $maxfontsize)/2);
  20785. }
  20786. if ($lhxt['TT']) {
  20787. $bf = max($bf, ($lhxt['TT'] - $maxfontsize));
  20788. }
  20789. if ($lhxt['TB']) {
  20790. $af = max($af, ($lhxt['TB'] - $maxfontsize));
  20791. }
  20792. if ($lhxt['T']) {
  20793. $mta = max($mta, $lhxt['T']);
  20794. }
  20795. if ($lhxt['B']) {
  20796. $mba = max($mba, $lhxt['B']);
  20797. }
  20798. if ((!$lhfixed || !$forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  20799. $maxlineHeight = $maxfontsize + $af + $bf;
  20800. }
  20801. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  20802. if ($mta > $maxlineHeight) {
  20803. $bf += ($mta - $maxlineHeight);
  20804. $maxlineHeight = $mta;
  20805. }
  20806. if ($mba > $maxlineHeight) {
  20807. $af += ($mba - $maxlineHeight);
  20808. $maxlineHeight = $mba;
  20809. }
  20810. return $maxlineHeight;
  20811. }
  20812. function TableWordWrap($maxwidth, $forcewrap = 0, $textbuffer = '', $def_fontsize, $returnarray=false) { // NB ** returnarray used in flowchart
  20813. $biggestword=0;
  20814. $toonarrow=false;
  20815. $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  20816. $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  20817. $textbuffer[0][0] = preg_replace('/^[ ]*/','',$textbuffer[0][0]);
  20818. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  20819. $text = '';
  20820. $lhfixed = false;
  20821. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight)) { $lhfixed = true; }
  20822. if ($lhfixed) { $def_lineheight = $this->_computeLineheight($this->table_lineheight, $def_fontsize);}
  20823. else { $def_lineheight = 0; }
  20824. // START OF NEW LINE
  20825. // Initialise lineheight variables
  20826. $maxfontsize = 0;
  20827. $forceExactLineheight = true;
  20828. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20829. $maxlineHeight = $def_lineheight ;
  20830. $ch = 0;
  20831. $width = 0;
  20832. $ln = 1; // Counts line number
  20833. $mxw = $this->GetStringWidth('W'); // Keep tabs on Maxwidth of actual text
  20834. foreach ($textbuffer as $cctr=>$chunk) {
  20835. $line = $chunk[0];
  20836. //IMAGE
  20837. if (substr($line,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  20838. $objattr = $this->_getObjAttr($line);
  20839. if ($objattr['type'] == 'nestedtable') {
  20840. // END OF LINE
  20841. // Finalise & add lineheight
  20842. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20843. $level = $objattr['level'];
  20844. $ih = $this->table[($level+1)][$objattr['nestedcontent']]['h']; // nested table width
  20845. $ch += $ih;
  20846. // START OF NEW LINE
  20847. // Initialise lineheight variables
  20848. $ln++;
  20849. $maxfontsize = 0;
  20850. $forceExactLineheight = true;
  20851. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20852. $maxlineHeight = $def_lineheight ;
  20853. $width = 0;
  20854. $text = "";
  20855. continue;
  20856. }
  20857. list($skipln,$iw,$ih) = $this->inlineObject((isset($specialcontent['type']) ? $specialcontent['type'] : null),0,0, $objattr, $this->lMargin,$width,$maxwidth,$maxlineHeight,false,true); // mPDF 5.0.052
  20858. if ($objattr['type'] == 'hr') {
  20859. // END OF LINE
  20860. // Finalise & add lineheight
  20861. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20862. // Add HR height
  20863. $ch += $ih;
  20864. // START OF NEW LINE
  20865. // Initialise lineheight variables
  20866. $ln++;
  20867. $maxfontsize = 0;
  20868. $forceExactLineheight = true;
  20869. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20870. $maxlineHeight = $def_lineheight ;
  20871. $width = 0;
  20872. $text = "";
  20873. continue;
  20874. }
  20875. if ($skipln==1 || $skipln==-2) {
  20876. // Finish last line
  20877. // END OF LINE
  20878. // Finalise & add lineheight
  20879. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20880. // START OF NEW LINE
  20881. // Initialise lineheight variables
  20882. $maxfontsize = 0;
  20883. $forceExactLineheight = true;
  20884. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20885. $maxlineHeight = $def_lineheight ;
  20886. $ln++;
  20887. $width = 0;
  20888. $text = "";
  20889. }
  20890. $va = $objattr['vertical-align'];
  20891. if ($va) {
  20892. $lhxt[$va] = max($lhxt[$va], $ih);
  20893. }
  20894. if ($lhfixed && $ih > $def_fontsize) { $forceExactLineheight = false; }
  20895. $maxlineHeight = max($maxlineHeight ,$ih);
  20896. $width += $iw;
  20897. continue;
  20898. }
  20899. // SET FONT SIZE/STYLE from $chunk[n]
  20900. // FONTSIZE
  20901. if(isset($chunk[11]) and $chunk[11] != '') {
  20902. if ($this->shrin_k) {
  20903. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  20904. }
  20905. else {
  20906. $this->SetFontSize($chunk[11],false);
  20907. }
  20908. }
  20909. if ($line == "\n") {
  20910. // END OF LINE
  20911. $maxfontsize = max($maxfontsize,$this->FontSize);
  20912. $fh = $this->_computeLineheight($this->table_lineheight);
  20913. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20914. $fh = $this->FontSize;
  20915. $forceExactLineheight = false;
  20916. }
  20917. $maxlineHeight = max($maxlineHeight,$fh);
  20918. // Finalise & add lineheight
  20919. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20920. // START OF NEW LINE
  20921. // Initialise lineheight variables
  20922. $maxfontsize = 0;
  20923. $forceExactLineheight = true;
  20924. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20925. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20926. $ln++;
  20927. $text = "";
  20928. $width = 0;
  20929. if(isset($chunk[11]) and $chunk[11] != '') {
  20930. $this->SetFontSize($this->default_font_size,false);
  20931. }
  20932. continue;
  20933. }
  20934. // mPDF 5.0.063
  20935. if(isset($chunk[15])) { // Word spacing
  20936. $this->wSpacingCSS = $chunk[15];
  20937. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20938. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); // mPDF 5.0.066
  20939. }
  20940. }
  20941. if(isset($chunk[14])) { // Letter spacing
  20942. $this->lSpacingCSS = $chunk[14];
  20943. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { // mPDF 5.0.066
  20944. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); // mPDF 5.0.066
  20945. }
  20946. }
  20947. if(isset($chunk[12])) { // Font Kerning
  20948. $this->kerning = $chunk[13];
  20949. }
  20950. // FONTFAMILY
  20951. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  20952. // FONT STYLE B I U
  20953. if(isset($chunk[2]) and $chunk[2] != '') {
  20954. $this->SetStyles($chunk[2]); // mPDF 5.0
  20955. }
  20956. $space = $this->GetStringWidth(' ');
  20957. if (mb_substr($line,0,1,$this->mb_enc ) == ' ') { // line (chunk) starts with a space
  20958. $width += $space;
  20959. $text .= ' ';
  20960. }
  20961. if (mb_substr($line,(mb_strlen($line,$this->mb_enc )-1),1,$this->mb_enc ) == ' ') { $lsend = true; } // line (chunk) ends with a space
  20962. else { $lsend = false; }
  20963. $line= trim($line);
  20964. if ($line == '') { continue; }
  20965. // mPDF ITERATION
  20966. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  20967. $words = explode(' ', $line);
  20968. foreach ($words as $word) {
  20969. $word = trim($word);
  20970. $wordwidth = $this->GetStringWidth($word);
  20971. //maxwidth is insufficient for one word
  20972. if ($wordwidth > $maxwidth + 0.0001) {
  20973. $firstchunk=true;
  20974. while($wordwidth > $maxwidth + 0.0001) {
  20975. $chw = 0; // check width
  20976. // mPDF 5.1.009
  20977. $oneCJKorphan = false;
  20978. for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) {
  20979. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  20980. if ($chw > $maxwidth) {
  20981. if ($i==0 && $firstchunk) { // mPDF 5.1.004
  20982. // If first letter of line does not fit
  20983. $wordwidth = $maxwidth - 0.0001;
  20984. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for one character!"); }
  20985. break;
  20986. }
  20987. // mPDF 5.1.009
  20988. // mPDF 5.1.011
  20989. if (!$oneCJKorphan && (preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']$/',mb_substr($word,0,$i+1,$this->mb_enc )) || (!$this->usingCoreFont && preg_match('/['.$this->CJKoverflow.']$/u',mb_substr($word,0,$i+1,$this->mb_enc ))))) {
  20990. $wordwidth = $maxwidth - 0.0001;
  20991. $oneCJKorphan = true;
  20992. continue;
  20993. }
  20994. if ($text && $firstchunk) {
  20995. // END OF LINE
  20996. // Finalise & add lineheight
  20997. $maxfontsize = max($maxfontsize,$this->FontSize);
  20998. $fh = $this->_computeLineheight($this->table_lineheight);
  20999. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21000. $fh = $this->FontSize;
  21001. $forceExactLineheight = false;
  21002. }
  21003. $maxlineHeight = max($maxlineHeight,$fh);
  21004. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21005. // START OF NEW LINE
  21006. // Initialise lineheight variables
  21007. $maxfontsize = $this->FontSize;
  21008. $forceExactLineheight = true;
  21009. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  21010. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  21011. $ln++;
  21012. }
  21013. // END OF LINE
  21014. // Finalise & add lineheight
  21015. $maxfontsize = max($maxfontsize,$this->FontSize);
  21016. $fh = $this->_computeLineheight($this->table_lineheight);
  21017. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21018. $fh = $this->FontSize;
  21019. $forceExactLineheight = false;
  21020. }
  21021. $maxlineHeight = max($maxlineHeight,$fh);
  21022. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21023. // START OF NEW LINE
  21024. // Initialise lineheight variables
  21025. $maxfontsize = $this->FontSize;
  21026. $forceExactLineheight = true;
  21027. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  21028. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  21029. $ln++;
  21030. $mxw = $maxwidth;
  21031. $text = mb_substr($word,0,$i,$this->mb_enc );
  21032. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  21033. $wordwidth = $this->GetStringWidth($word);
  21034. $width = 0;
  21035. $firstchunk=false;
  21036. break;
  21037. }
  21038. }
  21039. if (mb_strlen($word, $this->mb_enc )<2 && $wordwidth > $maxwidth + 0.0001) { // mPDF 5.0.002 mPDF 5.1.009
  21040. $wordwidth = $maxwidth - 0.0001;
  21041. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for single character!"); }
  21042. }
  21043. $firstchunk=false;
  21044. }
  21045. }
  21046. // Word fits on line...
  21047. if ($width + $wordwidth < $maxwidth + 0.0001) {
  21048. $mxw = max($mxw, ($width+$wordwidth));
  21049. $width += $wordwidth + $space;
  21050. $text .= $word.' ';
  21051. }
  21052. // Word does not fit on line...
  21053. else {
  21054. $alloworphans = false;
  21055. // In case of orphan punctuation or SUB/SUP
  21056. // Strip end punctuation
  21057. // mPDF 5.0 Added "]"
  21058. // mPDF 5.1.009
  21059. // mPDF 5.1.011
  21060. $tmp = preg_replace('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']{1}$/','',$word);
  21061. if (!$this->usingCoreFont) { $tmp = preg_replace('/['.$this->CJKoverflow.']{1}$/u','',$tmp); }
  21062. if ($tmp !== $word && (($this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']$/',$tmp)) || (!$this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote .$this->CJKoverflow.']$/u',$tmp)))) {
  21063. $tmpwidth = $this->GetStringWidth($tmp);
  21064. if ($width + $tmpwidth < $maxwidth + 0.0001) { $alloworphans = true; }
  21065. }
  21066. // If line = SUB/SUP to max of orphansallowed ( $this->SUP || $this->SUB )
  21067. if(( (isset($chunk[5]) and $chunk[5]) || (isset($chunk[6]) and $chunk[6])) && strlen($word) <= $this->orphansAllowed) {
  21068. $alloworphans = true;
  21069. }
  21070. // if [stripped] word fits
  21071. if ($alloworphans) {
  21072. $mxw = $maxwidth;
  21073. $width += $wordwidth + $space;
  21074. $text .= $word.' ';
  21075. }
  21076. else {
  21077. /*-- HYPHENATION --*/
  21078. // Soft Hyphens chr(173)
  21079. if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$word)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$word) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) {
  21080. list($success,$pre,$post,$prelength) = $this->softHyphenate($word, ($maxwidth - $width));
  21081. if ($success) {
  21082. $text .= $pre.'-';
  21083. $word = $post;
  21084. $wordwidth = $this->GetStringWidth($word);
  21085. }
  21086. }
  21087. else if ($this->hyphenate || ($this->hyphenateTables)) {
  21088. list($success,$pre,$post,$prelength) = $this->hyphenateWord($word, ($maxwidth - $width));
  21089. if ($success) {
  21090. $text .= $pre.'-';
  21091. $word = $post;
  21092. $wordwidth = $this->GetStringWidth($word);
  21093. }
  21094. }
  21095. /*-- END HYPHENATION --*/
  21096. // END OF LINE
  21097. // Finalise & add lineheight
  21098. $maxfontsize = max($maxfontsize,$this->FontSize);
  21099. $fh = $this->_computeLineheight($this->table_lineheight);
  21100. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21101. $fh = $this->FontSize;
  21102. $forceExactLineheight = false;
  21103. }
  21104. $maxlineHeight = max($maxlineHeight,$fh);
  21105. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21106. $mxw = $maxwidth;
  21107. // START OF NEW LINE
  21108. // Initialise lineheight variables
  21109. $maxfontsize = $this->FontSize;
  21110. $forceExactLineheight = true;
  21111. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  21112. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  21113. $ln++;
  21114. $width = $wordwidth + $space;
  21115. $text = $word.' ';
  21116. }
  21117. }
  21118. $maxfontsize = max($maxfontsize,$this->FontSize);
  21119. $fh = $this->_computeLineheight($this->table_lineheight);
  21120. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21121. $fh = $this->FontSize;
  21122. $forceExactLineheight = false;
  21123. }
  21124. $maxlineHeight = max($maxlineHeight,$fh);
  21125. }
  21126. // End of textbuffer chunk
  21127. if (!$lsend) {
  21128. $width -= $space;
  21129. $text = rtrim($text);
  21130. }
  21131. // RESET FONT SIZE/STYLE
  21132. // RESETTING VALUES
  21133. //Now we must deactivate what we have used
  21134. if(isset($chunk[2]) and $chunk[2] != '') {
  21135. $this->ResetStyles(); // mPDF 5.0
  21136. }
  21137. if(isset($chunk[4]) and $chunk[4] != '') {
  21138. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  21139. }
  21140. if(isset($chunk[11]) and $chunk[11] != '') {
  21141. $this->SetFontSize($this->default_font_size,false);
  21142. }
  21143. $this->kerning = false; // mPDF 5.0.063
  21144. $this->lSpacingCSS = ''; // mPDF 5.0.063
  21145. $this->wSpacingCSS = ''; // mPDF 5.0.063
  21146. $this->fixedlSpacing = false; // mPDF 5.0.063
  21147. $this->minwSpacing = 0; // mPDF 5.0.063
  21148. }
  21149. // Finalise lineheight if something output on line and add
  21150. if ($width) {
  21151. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21152. }
  21153. if ($returnarray) { return array($ch,$ln,$mxw); }
  21154. else { return $ch; }
  21155. }
  21156. function TableCheckMinWidth(&$text, $maxwidth, $forcewrap = 0, $textbuffer = '') {
  21157. $biggestword=0;
  21158. $toonarrow=false;
  21159. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  21160. foreach ($textbuffer as $chunk) {
  21161. $line = $chunk[0];
  21162. // mPDF ITERATION
  21163. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  21164. // IMAGES & FORM ELEMENTS
  21165. if (substr($line,0,3) == "\xbb\xa4\xac") { //inline object - FORM element or IMAGE!
  21166. $objattr = $this->_getObjAttr($line);
  21167. if ($objattr['type']!='hr' && isset($objattr['width']) && ($objattr['width']/$this->shrin_k) > ($maxwidth + 0.0001) ) {
  21168. if (($objattr['width']/$this->shrin_k) > $biggestword) { $biggestword = ($objattr['width']/$this->shrin_k); }
  21169. $toonarrow=true;
  21170. }
  21171. continue;
  21172. }
  21173. if ($line == "\n") {
  21174. continue;
  21175. }
  21176. $line = trim($line );
  21177. // SET FONT SIZE/STYLE from $chunk[n]
  21178. // FONTSIZE
  21179. if(isset($chunk[11]) and $chunk[11] != '') {
  21180. if ($this->shrin_k) {
  21181. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  21182. }
  21183. else {
  21184. $this->SetFontSize($chunk[11],false);
  21185. }
  21186. }
  21187. // FONTFAMILY
  21188. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  21189. // B I U
  21190. if(isset($chunk[2]) and $chunk[2] != '') {
  21191. $this->SetStyles($chunk[2]); // mPDF 5.0
  21192. }
  21193. // mPDF 5.1.004
  21194. if(isset($chunk[15])) { // Word spacing
  21195. $this->wSpacingCSS = $chunk[15];
  21196. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  21197. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  21198. }
  21199. }
  21200. if(isset($chunk[14])) { // Letter spacing
  21201. $this->lSpacingCSS = $chunk[14];
  21202. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  21203. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  21204. }
  21205. }
  21206. if(isset($chunk[12])) { // Font Kerning
  21207. $this->kerning = $chunk[13];
  21208. }
  21209. $words = explode(' ', $line);
  21210. foreach ($words as $word) {
  21211. $word = trim($word);
  21212. $wordwidth = $this->GetStringWidth($word);
  21213. //Warn user that maxwidth is insufficient
  21214. if ($wordwidth > $maxwidth + 0.0001) {
  21215. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  21216. $toonarrow=true;
  21217. }
  21218. }
  21219. // RESET FONT SIZE/STYLE
  21220. // RESETTING VALUES
  21221. //Now we must deactivate what we have used
  21222. if(isset($chunk[2]) and $chunk[2] != '') {
  21223. $this->ResetStyles(); // mPDF 5.0
  21224. }
  21225. if(isset($chunk[4]) and $chunk[4] != '') {
  21226. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  21227. }
  21228. if(isset($chunk[11]) and $chunk[11] != '') {
  21229. $this->SetFontSize($this->default_font_size,false);
  21230. }
  21231. // mPDF 5.1.004
  21232. $this->kerning = false;
  21233. $this->lSpacingCSS = '';
  21234. $this->wSpacingCSS = '';
  21235. $this->fixedlSpacing = false;
  21236. $this->minwSpacing = 0;
  21237. }
  21238. //Return -(wordsize) if word is bigger than maxwidth
  21239. // ADDED
  21240. if (($toonarrow) && ($this->table_error_report)) {
  21241. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  21242. }
  21243. if ($toonarrow) return -$biggestword;
  21244. else return 1;
  21245. }
  21246. function shrinkTable(&$table,$k) {
  21247. $table['border_spacing_H'] /= $k;
  21248. $table['border_spacing_V'] /= $k;
  21249. $table['padding']['T'] /= $k;
  21250. $table['padding']['R'] /= $k;
  21251. $table['padding']['B'] /= $k;
  21252. $table['padding']['L'] /= $k;
  21253. $table['margin']['T'] /= $k;
  21254. $table['margin']['R'] /= $k;
  21255. $table['margin']['B'] /= $k;
  21256. $table['margin']['L'] /= $k;
  21257. $table['border_details']['T']['w'] /= $k;
  21258. $table['border_details']['R']['w'] /= $k;
  21259. $table['border_details']['B']['w'] /= $k;
  21260. $table['border_details']['L']['w'] /= $k;
  21261. if (isset($table['max_cell_border_width']['T'])) $table['max_cell_border_width']['T'] /= $k;
  21262. if (isset($table['max_cell_border_width']['R'])) $table['max_cell_border_width']['R'] /= $k;
  21263. if (isset($table['max_cell_border_width']['B'])) $table['max_cell_border_width']['B'] /= $k;
  21264. if (isset($table['max_cell_border_width']['L'])) $table['max_cell_border_width']['L'] /= $k;
  21265. if ($this->simpleTables){
  21266. $table['simple']['border_details']['T']['w'] /= $k;
  21267. $table['simple']['border_details']['R']['w'] /= $k;
  21268. $table['simple']['border_details']['B']['w'] /= $k;
  21269. $table['simple']['border_details']['L']['w'] /= $k;
  21270. }
  21271. $table['miw'] /= $k;
  21272. $table['maw'] /= $k;
  21273. for($j = 0 ; $j < $table['nc'] ; $j++ ) { //columns
  21274. $table['wc'][$j]['miw'] /= $k;
  21275. $table['wc'][$j]['maw'] /= $k;
  21276. if (isset($table['wc'][$j]['absmiw']) && $table['wc'][$j]['absmiw'] ) $table['wc'][$j]['absmiw'] /= $k;
  21277. for($i = 0 ; $i < $table['nr']; $i++ ) { //rows
  21278. $c = &$table['cells'][$i][$j];
  21279. if (isset($c) && $c) {
  21280. if (!$this->simpleTables){
  21281. if ($this->packTableData) {
  21282. $cell = $this->_unpackCellBorder($c['borderbin'] );
  21283. $cell['border_details']['T']['w'] /= $k;
  21284. $cell['border_details']['R']['w'] /= $k;
  21285. $cell['border_details']['B']['w'] /= $k;
  21286. $cell['border_details']['L']['w'] /= $k;
  21287. $cell['border_details']['mbw']['TL'] /= $k;
  21288. $cell['border_details']['mbw']['TR'] /= $k;
  21289. $cell['border_details']['mbw']['BL'] /= $k;
  21290. $cell['border_details']['mbw']['BR'] /= $k;
  21291. $cell['border_details']['mbw']['LT'] /= $k;
  21292. $cell['border_details']['mbw']['LB'] /= $k;
  21293. $cell['border_details']['mbw']['RT'] /= $k;
  21294. $cell['border_details']['mbw']['RB'] /= $k;
  21295. $c['borderbin'] = $this->_packCellBorder($cell);
  21296. }
  21297. else {
  21298. $c['border_details']['T']['w'] /= $k;
  21299. $c['border_details']['R']['w'] /= $k;
  21300. $c['border_details']['B']['w'] /= $k;
  21301. $c['border_details']['L']['w'] /= $k;
  21302. $c['border_details']['mbw']['TL'] /= $k;
  21303. $c['border_details']['mbw']['TR'] /= $k;
  21304. $c['border_details']['mbw']['BL'] /= $k;
  21305. $c['border_details']['mbw']['BR'] /= $k;
  21306. $c['border_details']['mbw']['LT'] /= $k;
  21307. $c['border_details']['mbw']['LB'] /= $k;
  21308. $c['border_details']['mbw']['RT'] /= $k;
  21309. $c['border_details']['mbw']['RB'] /= $k;
  21310. }
  21311. }
  21312. $c['padding']['T'] /= $k;
  21313. $c['padding']['R'] /= $k;
  21314. $c['padding']['B'] /= $k;
  21315. $c['padding']['L'] /= $k;
  21316. $c['maxs'] /= $k;
  21317. if (isset($c['w'])) { $c['w'] /= $k; }
  21318. $c['s'] /= $k;
  21319. $c['maw'] /= $k;
  21320. $c['miw'] /= $k;
  21321. if (isset($c['absmiw'])) $c['absmiw'] /= $k;
  21322. if (isset($c['nestedmaw'])) $c['nestedmaw'] /= $k;
  21323. if (isset($c['nestedmiw'])) $c['nestedmiw'] /= $k;
  21324. }
  21325. }//rows
  21326. }//columns
  21327. unset($c);
  21328. }
  21329. function _packCellBorder($cell) {
  21330. if (!is_array($cell) || !isset($cell)) { return ''; }
  21331. if (!$this->packTableData) { return $cell; }
  21332. // mPDF 5.0.051
  21333. $bindata = pack("nndn4d2A10nndn4d2A10nndn4d2A10nndn4d2A10nd9",
  21334. $cell['border'],
  21335. $cell['border_details']['R']['s'],
  21336. $cell['border_details']['R']['w'],
  21337. $cell['border_details']['R']['c'][0],
  21338. $cell['border_details']['R']['c'][1],
  21339. $cell['border_details']['R']['c'][2],
  21340. $cell['border_details']['R']['c'][3],
  21341. $cell['border_details']['R']['c'][4],
  21342. $cell['border_details']['R']['c'][5],
  21343. $cell['border_details']['R']['style'],
  21344. $cell['border_details']['R']['dom'],
  21345. $cell['border_details']['L']['s'],
  21346. $cell['border_details']['L']['w'],
  21347. $cell['border_details']['L']['c'][0],
  21348. $cell['border_details']['L']['c'][1],
  21349. $cell['border_details']['L']['c'][2],
  21350. $cell['border_details']['L']['c'][3],
  21351. $cell['border_details']['L']['c'][4],
  21352. $cell['border_details']['L']['c'][5],
  21353. $cell['border_details']['L']['style'],
  21354. $cell['border_details']['L']['dom'],
  21355. $cell['border_details']['T']['s'],
  21356. $cell['border_details']['T']['w'],
  21357. $cell['border_details']['T']['c'][0],
  21358. $cell['border_details']['T']['c'][1],
  21359. $cell['border_details']['T']['c'][2],
  21360. $cell['border_details']['T']['c'][3],
  21361. $cell['border_details']['T']['c'][4],
  21362. $cell['border_details']['T']['c'][5],
  21363. $cell['border_details']['T']['style'],
  21364. $cell['border_details']['T']['dom'],
  21365. $cell['border_details']['B']['s'],
  21366. $cell['border_details']['B']['w'],
  21367. $cell['border_details']['B']['c'][0],
  21368. $cell['border_details']['B']['c'][1],
  21369. $cell['border_details']['B']['c'][2],
  21370. $cell['border_details']['B']['c'][3],
  21371. $cell['border_details']['B']['c'][4],
  21372. $cell['border_details']['B']['c'][5],
  21373. $cell['border_details']['B']['style'],
  21374. $cell['border_details']['B']['dom'],
  21375. $cell['border_details']['mbw']['BL'],
  21376. $cell['border_details']['mbw']['BR'],
  21377. $cell['border_details']['mbw']['RT'],
  21378. $cell['border_details']['mbw']['RB'],
  21379. $cell['border_details']['mbw']['TL'],
  21380. $cell['border_details']['mbw']['TR'],
  21381. $cell['border_details']['mbw']['LT'],
  21382. $cell['border_details']['mbw']['LB'],
  21383. $cell['border_details']['cellposdom']
  21384. );
  21385. return $bindata;
  21386. }
  21387. function _getBorderWidths($bindata) {
  21388. if (!$bindata) { return array(0,0,0,0); }
  21389. if (!$this->packTableData) { return array($bindata['border_details']['T']['w'], $bindata['border_details']['R']['w'], $bindata['border_details']['B']['w'], $bindata['border_details']['L']['w']); }
  21390. // mPDF 5.0.051
  21391. $bd = unpack("nbord/nrs/drw/nrca/nrcb/nrcc/nrcd/drce/drcf/A10rst/nrd/nls/dlw/nlca/nlcb/nlcc/nlcd/dlce/dlcf/A10lst/nld/nts/dtw/ntca/ntcb/ntcc/ntcd/dtce/dtcf/A10tst/ntd/nbs/dbw/nbca/nbcb/nbcc/nbcd/dbce/dbcf/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata);
  21392. $cell['border_details']['R']['w'] = $bd['rw'];
  21393. $cell['border_details']['L']['w'] = $bd['lw'];
  21394. $cell['border_details']['T']['w'] = $bd['tw'];
  21395. $cell['border_details']['B']['w'] = $bd['bw'];
  21396. return array($bd['tw'], $bd['rw'], $bd['bw'], $bd['lw']);
  21397. }
  21398. function _unpackCellBorder($bindata) {
  21399. if (!$bindata) { return array(); }
  21400. if (!$this->packTableData) { return $bindata; }
  21401. // mPDF 5.0.051
  21402. $bd = unpack("nbord/nrs/drw/nrca/nrcb/nrcc/nrcd/drce/drcf/A10rst/nrd/nls/dlw/nlca/nlcb/nlcc/nlcd/dlce/dlcf/A10lst/nld/nts/dtw/ntca/ntcb/ntcc/ntcd/dtce/dtcf/A10tst/ntd/nbs/dbw/nbca/nbcb/nbcc/nbcd/dbce/dbcf/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata);
  21403. $cell['border'] = $bd['bord'];
  21404. $cell['border_details']['R']['s'] = $bd['rs'];
  21405. $cell['border_details']['R']['w'] = $bd['rw'];
  21406. $cell['border_details']['R']['c'][0] = $bd['rca'];
  21407. $cell['border_details']['R']['c'][1] = $bd['rcb'];
  21408. $cell['border_details']['R']['c'][2] = $bd['rcc'];
  21409. $cell['border_details']['R']['c'][3] = $bd['rcd'];
  21410. $cell['border_details']['R']['c'][4] = $bd['rce'];
  21411. $cell['border_details']['R']['c'][5] = $bd['rcf'];
  21412. $cell['border_details']['R']['style'] = trim($bd['rst']);
  21413. $cell['border_details']['R']['dom'] = $bd['rd'];
  21414. $cell['border_details']['L']['s'] = $bd['ls'];
  21415. $cell['border_details']['L']['w'] = $bd['lw'];
  21416. $cell['border_details']['L']['c'][0] = $bd['lca'];
  21417. $cell['border_details']['L']['c'][1] = $bd['lcb'];
  21418. $cell['border_details']['L']['c'][2] = $bd['lcc'];
  21419. $cell['border_details']['L']['c'][3] = $bd['lcd'];
  21420. $cell['border_details']['L']['c'][4] = $bd['lce'];
  21421. $cell['border_details']['L']['c'][5] = $bd['lcf'];
  21422. $cell['border_details']['L']['style'] = trim($bd['lst']);
  21423. $cell['border_details']['L']['dom'] = $bd['ld'];
  21424. $cell['border_details']['T']['s'] = $bd['ts'];
  21425. $cell['border_details']['T']['w'] = $bd['tw'];
  21426. $cell['border_details']['T']['c'][0] = $bd['tca'];
  21427. $cell['border_details']['T']['c'][1] = $bd['tcb'];
  21428. $cell['border_details']['T']['c'][2] = $bd['tcc'];
  21429. $cell['border_details']['T']['c'][3] = $bd['tcd'];
  21430. $cell['border_details']['T']['c'][4] = $bd['tce'];
  21431. $cell['border_details']['T']['c'][5] = $bd['tcf'];
  21432. $cell['border_details']['T']['style'] = trim($bd['tst']);
  21433. $cell['border_details']['T']['dom'] = $bd['td'];
  21434. $cell['border_details']['B']['s'] = $bd['bs'];
  21435. $cell['border_details']['B']['w'] = $bd['bw'];
  21436. $cell['border_details']['B']['c'][0] = $bd['bca'];
  21437. $cell['border_details']['B']['c'][1] = $bd['bcb'];
  21438. $cell['border_details']['B']['c'][2] = $bd['bcc'];
  21439. $cell['border_details']['B']['c'][3] = $bd['bcd'];
  21440. $cell['border_details']['B']['c'][4] = $bd['bce'];
  21441. $cell['border_details']['B']['c'][5] = $bd['bcf'];
  21442. $cell['border_details']['B']['style'] = trim($bd['bst']);
  21443. $cell['border_details']['B']['dom'] = $bd['bd'];
  21444. $cell['border_details']['mbw']['BL'] = $bd['mbl'];
  21445. $cell['border_details']['mbw']['BR'] = $bd['mbr'];
  21446. $cell['border_details']['mbw']['RT'] = $bd['mrt'];
  21447. $cell['border_details']['mbw']['RB'] = $bd['mrb'];
  21448. $cell['border_details']['mbw']['TL'] = $bd['mtl'];
  21449. $cell['border_details']['mbw']['TR'] = $bd['mtr'];
  21450. $cell['border_details']['mbw']['LT'] = $bd['mlt'];
  21451. $cell['border_details']['mbw']['LB'] = $bd['mlb'];
  21452. $cell['border_details']['cellposdom'] = $bd['cpd'];
  21453. return($cell);
  21454. }
  21455. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21456. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21457. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21458. //table Array of (w, h, bc, nr, wc, hr, cells)
  21459. //w Width of table
  21460. //h Height of table
  21461. //nc Number column
  21462. //nr Number row
  21463. //hr List of height of each row
  21464. //wc List of width of each column
  21465. //cells List of cells of each rows, cells[i][j] is a cell in the table
  21466. function _tableColumnWidth(&$table,$firstpass=false){
  21467. $cs = &$table['cells'];
  21468. $nc = $table['nc'];
  21469. $nr = $table['nr'];
  21470. $listspan = array();
  21471. if ($table['borders_separate']) {
  21472. $tblbw = $table['border_details']['L']['w'] + $table['border_details']['R']['w'] + $table['margin']['L'] + $table['margin']['R'] + $table['padding']['L'] + $table['padding']['R'] + $table['border_spacing_H'];
  21473. }
  21474. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  21475. // ADDED table['l'][colno]
  21476. // = total length of text approx (using $c['s']) in that column - used to approximately distribute col widths in _tableWidth
  21477. //
  21478. for($j = 0 ; $j < $nc ; $j++ ) { //columns
  21479. $wc = &$table['wc'][$j];
  21480. for($i = 0 ; $i < $nr ; $i++ ) { //rows
  21481. if (isset($cs[$i][$j]) && $cs[$i][$j]) {
  21482. $c = &$cs[$i][$j];
  21483. if ($this->simpleTables){
  21484. if ($table['borders_separate']) { // NB twice border width
  21485. $extrcw = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21486. }
  21487. else {
  21488. $extrcw = $table['simple']['border_details']['L']['w']/2 + $table['simple']['border_details']['R']['w']/2 + $c['padding']['L'] + $c['padding']['R'];
  21489. }
  21490. }
  21491. else {
  21492. if ($this->packTableData) {
  21493. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  21494. }
  21495. else {
  21496. $br = $c['border_details']['R']['w'];
  21497. $bl = $c['border_details']['L']['w'];
  21498. }
  21499. if ($table['borders_separate']) { // NB twice border width
  21500. $extrcw = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21501. }
  21502. else {
  21503. $extrcw = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  21504. }
  21505. }
  21506. //$mw = $this->GetStringWidth('W') + $extrcw ;
  21507. $mw = 0;
  21508. $c['absmiw'] = $mw;
  21509. if (isset($c['R']) && $c['R']) {
  21510. $c['maw'] = $c['miw'] = $this->FontSize + $extrcw ;
  21511. if (isset($c['w'])) { // If cell width is specified
  21512. if ($c['miw'] <$c['w']) { $c['miw'] = $c['w']; }
  21513. }
  21514. if (!isset($c['colspan'])) {
  21515. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; }
  21516. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21517. if ($firstpass) {
  21518. if (isset($table['l'][$j]) ) {
  21519. $table['l'][$j] += $c['miw'] ;
  21520. }
  21521. else {
  21522. $table['l'][$j] = $c['miw'] ;
  21523. }
  21524. }
  21525. }
  21526. if ($c['miw'] > $wc['miw']) { $wc['miw'] = $c['miw']; }
  21527. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; }
  21528. continue;
  21529. }
  21530. if ($firstpass) {
  21531. if (isset($c['s'])) { $c['s'] += $extrcw; }
  21532. if (isset($c['maxs'])) { $c['maxs'] += $extrcw; }
  21533. if (isset($c['nestedmiw'])) { $c['nestedmiw'] += $extrcw; }
  21534. if (isset($c['nestedmaw'])) { $c['nestedmaw'] += $extrcw; }
  21535. }
  21536. // If minimum width has already been set by a nested table or inline object (image/form), use it
  21537. if (isset($c['nestedmiw'])) { $miw = $c['nestedmiw']; }
  21538. else { $miw = $mw; }
  21539. if (isset($c['maxs']) && $c['maxs'] != '') { $c['s'] = $c['maxs']; }
  21540. // If maximum width has already been set by a nested table, use it
  21541. if (isset($c['nestedmaw'])) { $c['maw'] = $c['nestedmaw']; }
  21542. else $c['maw'] = $c['s'];
  21543. if (isset($c['nowrap']) && $c['nowrap']) { $miw = $c['maw']; }
  21544. if (isset($c['wpercent']) && $firstpass) {
  21545. if (isset($c['colspan'])) { // Not perfect - but % set on colspan is shared equally on cols.
  21546. for($k=0;$k<$c['colspan'];$k++) {
  21547. $table['wc'][($j+$k)]['wpercent'] = $c['wpercent'] / $c['colspan'];
  21548. }
  21549. }
  21550. else {
  21551. if (isset($table['w']) && $table['w']) { $c['w'] = $c['wpercent']/100 * ($table['w'] - $tblbw ); }
  21552. $wc['wpercent'] = $c['wpercent'];
  21553. }
  21554. }
  21555. if (isset($c['w'])) { // If cell width is specified
  21556. if ($miw<$c['w']) { $c['miw'] = $c['w']; } // Cell min width = that specified
  21557. if ($miw>$c['w']) { $c['miw'] = $c['w'] = $miw; } // If width specified is less than minimum allowed (W) increase it
  21558. if (!isset($wc['w'])) { $wc['w'] = 1; } // If the Col width is not specified = set it to 1
  21559. }
  21560. else { $c['miw'] = $miw; } // If cell width not specified -> set Cell min width it to minimum allowed (W)
  21561. if ($c['maw'] < $c['miw']) { $c['maw'] = $c['miw']; } // If Cell max width < Minwidth - increase it to =
  21562. if (!isset($c['colspan'])) {
  21563. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; } // Update Col Minimum and maximum widths
  21564. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21565. if ((isset($wc['absmiw']) && $wc['absmiw'] < $c['absmiw']) || !isset($wc['absmiw'])) { $wc['absmiw'] = $c['absmiw']; } // Update Col Minimum and maximum widths
  21566. if (isset($table['l'][$j]) ) {
  21567. $table['l'][$j] += $c['s'];
  21568. }
  21569. else {
  21570. $table['l'][$j] = $c['s'];
  21571. }
  21572. }
  21573. else {
  21574. $listspan[] = array($i,$j);
  21575. }
  21576. //Check if minimum width of the whole column is big enough for largest word to fit
  21577. $auxtext = implode("",$c['text']);
  21578. if (isset($c['textbuffer'])) {
  21579. $minwidth = $this->TableCheckMinWidth($auxtext,$wc['miw']- $extrcw ,0,$c['textbuffer']);
  21580. }
  21581. else { $minwidth = 0; }
  21582. if ($minwidth < 0) {
  21583. //increase minimum width
  21584. if (!isset($c['colspan'])) {
  21585. $wc['miw'] = max($wc['miw'],((-$minwidth) + $extrcw) );
  21586. }
  21587. else { // mPDF 5.0.008
  21588. $c['miw'] = max($c['miw'],((-$minwidth) + $extrcw) );
  21589. }
  21590. }
  21591. if (!isset($c['colspan'])) {
  21592. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; } //update maximum width, if needed
  21593. }
  21594. }
  21595. unset($c);
  21596. }//rows
  21597. }//columns
  21598. // COLUMN SPANS
  21599. $wc = &$table['wc'];
  21600. foreach ($listspan as $span) {
  21601. list($i,$j) = $span;
  21602. $c = &$cs[$i][$j];
  21603. $lc = $j + $c['colspan'];
  21604. if ($lc > $nc) { $lc = $nc; }
  21605. $wis = $wisa = 0;
  21606. $was = $wasa = 0;
  21607. $list = array();
  21608. for($k=$j;$k<$lc;$k++) {
  21609. if (isset($table['l'][$k]) ) {
  21610. if ($c['R']) { $table['l'][$k] += $c['miw']/$c['colspan'] ; }
  21611. else { $table['l'][$k] += $c['s']/$c['colspan']; }
  21612. }
  21613. else {
  21614. if ($c['R']) { $table['l'][$k] = $c['miw']/$c['colspan'] ; }
  21615. else { $table['l'][$k] = $c['s']/$c['colspan']; }
  21616. }
  21617. $wis += $wc[$k]['miw'];
  21618. $was += $wc[$k]['maw'];
  21619. if (!isset($c['w'])) {
  21620. $list[] = $k;
  21621. $wisa += $wc[$k]['miw'];
  21622. $wasa += $wc[$k]['maw'];
  21623. }
  21624. }
  21625. if ($c['miw'] > $wis) {
  21626. if (!$wis) {
  21627. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] = $c['miw']/$c['colspan']; }
  21628. }
  21629. else if (!count($list)) {
  21630. $wi = $c['miw'] - $wis;
  21631. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wis)*$wi; }
  21632. }
  21633. else {
  21634. $wi = $c['miw'] - $wis;
  21635. foreach ($list as $k) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wisa)*$wi; }
  21636. }
  21637. }
  21638. if ($c['maw'] > $was) {
  21639. if (!$wis) {
  21640. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] = $c['maw']/$c['colspan']; }
  21641. }
  21642. else if (!count($list)) {
  21643. $wi = $c['maw'] - $was;
  21644. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] += ($wc[$k]['maw']/$was)*$wi; }
  21645. }
  21646. else {
  21647. $wi = $c['maw'] - $was;
  21648. foreach ($list as $k) { $wc[$k]['maw'] += ($wc[$k]['maw']/$wasa)*$wi; }
  21649. }
  21650. }
  21651. unset($c);
  21652. }
  21653. $checkminwidth = 0;
  21654. $checkmaxwidth = 0;
  21655. $totallength = 0;
  21656. for( $i = 0 ; $i < $nc ; $i++ ) {
  21657. $checkminwidth += $table['wc'][$i]['miw'];
  21658. $checkmaxwidth += $table['wc'][$i]['maw'];
  21659. $totallength += $table['l'][$i];
  21660. }
  21661. if (!isset($table['w']) && $firstpass) {
  21662. $sumpc = 0;
  21663. $notset = 0;
  21664. for( $i = 0 ; $i < $nc ; $i++ ) {
  21665. if (isset($table['wc'][$i]['wpercent']) && $table['wc'][$i]['wpercent']) {
  21666. $sumpc += $table['wc'][$i]['wpercent'];
  21667. }
  21668. else { $notset++; }
  21669. }
  21670. // If sum of widths as % >= 100% and not all columns are set
  21671. // Set a nominal width of 1% for unset columns
  21672. if ($sumpc >= 100 && $notset) {
  21673. for( $i = 0 ; $i < $nc ; $i++ ) {
  21674. if ((!isset($table['wc'][$i]['wpercent']) || !$table['wc'][$i]['wpercent']) &&
  21675. (!isset($table['wc'][$i]['w']) || !$table['wc'][$i]['w'])) {
  21676. $table['wc'][$i]['wpercent'] = 1;
  21677. }
  21678. }
  21679. }
  21680. if ($sumpc) { // if any percents are set
  21681. $sumnonpc = (100 - $sumpc);
  21682. $sumpc = max($sumpc,100);
  21683. $miwleft = 0;
  21684. $miwleftcount = 0;
  21685. $miwsurplusnonpc = 0;
  21686. $maxcalcmiw = 0;
  21687. $mawleft = 0;
  21688. $mawleftcount = 0;
  21689. $mawsurplusnonpc = 0;
  21690. $maxcalcmaw = 0;
  21691. for( $i = 0 ; $i < $nc ; $i++ ) {
  21692. if (isset($table['wc'][$i]['wpercent'])) {
  21693. $maxcalcmiw = max($maxcalcmiw, ($table['wc'][$i]['miw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21694. $maxcalcmaw = max($maxcalcmaw, ($table['wc'][$i]['maw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21695. }
  21696. else {
  21697. $miwleft += $table['wc'][$i]['miw'];
  21698. $mawleft += $table['wc'][$i]['maw'];
  21699. if (!isset($table['wc'][$i]['w'])) { $miwleftcount++; $mawleftcount++; }
  21700. }
  21701. }
  21702. if ($miwleft && $sumnonpc > 0) { $miwnon = $miwleft * 100 / $sumnonpc; }
  21703. if ($mawleft && $sumnonpc > 0) { $mawnon = $mawleft * 100 / $sumnonpc; }
  21704. if (($miwnon > $checkminwidth || $maxcalcmiw > $checkminwidth) && $this->keep_table_proportions) {
  21705. if ($miwnon > $maxcalcmiw) {
  21706. $miwsurplusnonpc = round((($miwnon * $sumnonpc / 100) - $miwleft),3);
  21707. $checkminwidth = $miwnon;
  21708. }
  21709. else { $checkminwidth = $maxcalcmiw; }
  21710. for( $i = 0 ; $i < $nc ; $i++ ) {
  21711. if (isset($table['wc'][$i]['wpercent'])) {
  21712. $newmiw = $checkminwidth * $table['wc'][$i]['wpercent']/100;
  21713. if ($table['wc'][$i]['miw'] < $newmiw) {
  21714. $table['wc'][$i]['miw'] = $newmiw;
  21715. }
  21716. $table['wc'][$i]['w'] = 1;
  21717. }
  21718. else if ($miwsurplusnonpc && !$table['wc'][$i]['w']) {
  21719. $table['wc'][$i]['miw'] += $miwsurplusnonpc / $miwleftcount;
  21720. }
  21721. }
  21722. }
  21723. if (($mawnon > $checkmaxwidth || $maxcalcmaw > $checkmaxwidth )) {
  21724. if ($mawnon > $maxcalcmaw) {
  21725. $mawsurplusnonpc = round((($mawnon * $sumnonpc / 100) - $mawleft),3);
  21726. $checkmaxwidth = $mawnon;
  21727. }
  21728. else { $checkmaxwidth = $maxcalcmaw; }
  21729. for( $i = 0 ; $i < $nc ; $i++ ) {
  21730. if (isset($table['wc'][$i]['wpercent'])) {
  21731. $newmaw = $checkmaxwidth * $table['wc'][$i]['wpercent']/100;
  21732. if ($table['wc'][$i]['maw'] < $newmaw) {
  21733. $table['wc'][$i]['maw'] = $newmaw;
  21734. }
  21735. $table['wc'][$i]['w'] = 1;
  21736. }
  21737. else if ($mawsurplusnonpc && !$table['wc'][$i]['w']) {
  21738. $table['wc'][$i]['maw'] += $mawsurplusnonpc / $mawleftcount;
  21739. }
  21740. if ($table['wc'][$i]['maw'] < $table['wc'][$i]['miw']) { $table['wc'][$i]['maw'] = $table['wc'][$i]['miw']; }
  21741. }
  21742. }
  21743. if ($checkminwidth > $checkmaxwidth) { $checkmaxwidth = $checkminwidth; }
  21744. }
  21745. }
  21746. if (isset($table['wpercent']) && $table['wpercent']) {
  21747. $checkminwidth *= (100 / $table['wpercent']);
  21748. $checkmaxwidth *= (100 / $table['wpercent']);
  21749. }
  21750. $checkminwidth += $tblbw ;
  21751. $checkmaxwidth += $tblbw ;
  21752. // Table['miw'] set by percent in first pass may be larger than sum of column miw
  21753. if ((isset($table['miw']) && $checkminwidth > $table['miw']) || !isset($table['miw'])) { $table['miw'] = $checkminwidth; }
  21754. if ((isset($table['maw']) && $checkmaxwidth > $table['maw']) || !isset($table['maw'])) { $table['maw'] = $checkmaxwidth; }
  21755. $table['tl'] = $totallength ;
  21756. // mPDF 5.0
  21757. if (!$this->tableCJK) {
  21758. if ($this->table_rotate) {
  21759. $mxw = $this->tbrot_maxw;
  21760. }
  21761. else {
  21762. $mxw = $this->blk[$this->blklvl]['inner_width'];
  21763. }
  21764. if(!isset($table['overflow'])) { $table['overflow'] = null; } // mPDF 5.0.052
  21765. if (($table['overflow']=='visible' || $table['overflow']=='hidden') && !$this->table_rotate && !$this->ColActive && $checkminwidth > $mxw) {
  21766. $table['w'] = $table['miw'];
  21767. return array(0,0);
  21768. }
  21769. else if ($table['overflow']=='wrap') { return array(0,0); }
  21770. if (isset($table['w']) && $table['w'] ) {
  21771. if ($table['w'] >= $checkminwidth && $table['w'] <= $mxw) { $table['maw'] = $mxw = $table['w']; }
  21772. else if ($table['w'] >= $checkminwidth && $table['w'] > $mxw && $this->keep_table_proportions) { $checkminwidth = $table['w']; }
  21773. else {
  21774. unset($table['w']);
  21775. }
  21776. }
  21777. $ratio = $checkminwidth/$mxw;
  21778. if ($checkminwidth > $mxw) { return array(($ratio +0.001),$checkminwidth); } // 0.001 to allow for rounded numbers when resizing
  21779. }
  21780. return array(0,0);
  21781. }
  21782. function _tableWidth(&$table){
  21783. $widthcols = &$table['wc'];
  21784. $numcols = $table['nc'];
  21785. $tablewidth = 0;
  21786. // Added mPDF1.4 - table border width if separate
  21787. if ($table['borders_separate']) {
  21788. $tblbw = $table['border_details']['L']['w'] + $table['border_details']['R']['w'] + $table['margin']['L'] + $table['margin']['R'] + $table['padding']['L'] + $table['padding']['R'] + $table['border_spacing_H'];
  21789. }
  21790. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  21791. if ($table['level']>1 && isset($table['w'])) {
  21792. if (isset($table['wpercent']) && $table['wpercent']) {
  21793. $table['w'] = $temppgwidth = (($table['w']-$tblbw) * $table['wpercent'] / 100) + $tblbw ;
  21794. }
  21795. else {
  21796. $temppgwidth = $table['w'] ;
  21797. }
  21798. }
  21799. else if ($this->table_rotate) {
  21800. $temppgwidth = $this->tbrot_maxw;
  21801. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  21802. // then allow for this
  21803. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  21804. if ($enddiv/$temppgwidth <0.05) { $temppgwidth -= $enddiv; }
  21805. }
  21806. else {
  21807. if (isset($table['w']) && $table['w']< $this->blk[$this->blklvl]['inner_width']) {
  21808. $notfullwidth = 1;
  21809. $temppgwidth = $table['w'] ;
  21810. }
  21811. else if (($table['overflow']=='visible' || $table['overflow']=='hidden') && !$this->ColActive && isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width'] && $table['w']==$table['miw']) {
  21812. $temppgwidth = $table['w'] ;
  21813. }
  21814. else { $temppgwidth = $this->blk[$this->blklvl]['inner_width']; }
  21815. }
  21816. $totaltextlength = 0; // Added - to sum $table['l'][colno]
  21817. $totalatextlength = 0; // Added - to sum $table['l'][colno] for those columns where width not set
  21818. $percentages_set = 0;
  21819. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  21820. if (isset($widthcols[$i]['wpercent'])) { $tablewidth += $widthcols[$i]['maw']; $percentages_set = 1; }
  21821. else if (isset($widthcols[$i]['w'])) { $tablewidth += $widthcols[$i]['miw']; }
  21822. else { $tablewidth += $widthcols[$i]['maw']; }
  21823. $totaltextlength += $table['l'][$i];
  21824. }
  21825. if (!$totaltextlength) { $totaltextlength =1; }
  21826. $tablewidth += $tblbw; // Outer half of table borders
  21827. if ($tablewidth > $temppgwidth) {
  21828. $table['w'] = $temppgwidth;
  21829. }
  21830. // if any widths set as percentages and max width fits < page width
  21831. else if ($tablewidth < $temppgwidth && !isset($table['w']) && $percentages_set) {
  21832. $table['w'] = $table['maw'];
  21833. }
  21834. // if table width is set and is > allowed width
  21835. if (isset($table['w']) && $table['w'] > $temppgwidth) { $table['w'] = $temppgwidth; }
  21836. // IF the table width is now set - Need to distribute columns widths
  21837. if (isset($table['w'])) {
  21838. $wis = $wisa = 0;
  21839. $list = array();
  21840. $notsetlist = array();
  21841. for( $i = 0 ; $i < $numcols ; $i++ ) {
  21842. $wis += $widthcols[$i]['miw'];
  21843. if (!isset($widthcols[$i]['w']) || ($widthcols[$i]['w'] && $table['w'] > $temppgwidth && !$this->keep_table_proportions && !$notfullwidth )){
  21844. $list[] = $i;
  21845. $wisa += $widthcols[$i]['miw'];
  21846. $totalatextlength += $table['l'][$i];
  21847. }
  21848. }
  21849. if (!$totalatextlength) { $totalatextlength =1; }
  21850. // Allocate spare (more than col's minimum width) across the cols according to their approx total text length
  21851. // Do it by setting minimum width here
  21852. if ($table['w'] > $wis + $tblbw) {
  21853. // First set any cell widths set as percentages
  21854. if ($table['w'] < $temppgwidth || $this->keep_table_proportions) {
  21855. for($k=0;$k<$numcols;$k++) {
  21856. if (isset($widthcols[$k]['wpercent'])) {
  21857. $curr = $widthcols[$k]['miw'];
  21858. $widthcols[$k]['miw'] = ($table['w']-$tblbw) * $widthcols[$k]['wpercent']/100;
  21859. $wis += $widthcols[$k]['miw'] - $curr;
  21860. $wisa += $widthcols[$k]['miw'] - $curr;
  21861. }
  21862. }
  21863. }
  21864. // Now allocate surplus up to maximum width of each column
  21865. $surplus = 0; $ttl = 0; // number of surplus columns
  21866. if (!count($list)) {
  21867. $wi = ($table['w']-($wis + $tblbw)); // i.e. extra space to distribute
  21868. for($k=0;$k<$numcols;$k++) {
  21869. $spareratio = ($table['l'][$k] / $totaltextlength); // gives ratio to divide up free space
  21870. // Don't allocate more than Maximum required width - save rest in surplus
  21871. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  21872. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  21873. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  21874. }
  21875. else {
  21876. $notsetlist[] = $k;
  21877. $ttl += $table['l'][$k];
  21878. $widthcols[$k]['miw'] += ($wi * $spareratio);
  21879. }
  21880. }
  21881. }
  21882. else {
  21883. $wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra space to distribute
  21884. foreach ($list as $k) {
  21885. $spareratio = ($table['l'][$k] / $totalatextlength); // gives ratio to divide up free space
  21886. // Don't allocate more than Maximum required width - save rest in surplus
  21887. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  21888. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  21889. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  21890. }
  21891. else {
  21892. $notsetlist[] = $k;
  21893. $ttl += $table['l'][$k];
  21894. $widthcols[$k]['miw'] += ($wi * $spareratio);
  21895. }
  21896. }
  21897. }
  21898. // If surplus still left over apportion it across columns
  21899. if ($surplus) {
  21900. // if some are set only add to remaining - otherwise add to all of them
  21901. if (count($notsetlist) && count($notsetlist) < $numcols) {
  21902. foreach ($notsetlist AS $i) {
  21903. if ($ttl) $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl ;
  21904. }
  21905. }
  21906. // If some widths are defined, and others have been added up to their maxmum
  21907. else if (count($list) && count($list) < $numcols) {
  21908. foreach ($list AS $i) {
  21909. $widthcols[$i]['miw'] += $surplus / count($list) ;
  21910. }
  21911. }
  21912. else if ($numcols) { // If all columns
  21913. $ttl = array_sum($table['l']);
  21914. for ($i=0;$i<$numcols;$i++) {
  21915. $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl;
  21916. }
  21917. }
  21918. }
  21919. }
  21920. // This sets the columns all to minimum width (which has been increased above if appropriate)
  21921. for ($i=0;$i<$numcols;$i++) {
  21922. $widthcols[$i] = $widthcols[$i]['miw'];
  21923. }
  21924. // TABLE NOT WIDE ENOUGH EVEN FOR MINIMUM CONTENT WIDTH
  21925. // If sum of column widths set are too wide for table
  21926. $checktablewidth = 0;
  21927. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  21928. $checktablewidth += $widthcols[$i];
  21929. }
  21930. if ($checktablewidth > ($temppgwidth + 0.001 - $tblbw)) {
  21931. $usedup = 0; $numleft = 0;
  21932. for ($i=0;$i<$numcols;$i++) {
  21933. if ((isset($widthcols[$i]) && $widthcols[$i] > (($temppgwidth - $tblbw) / $numcols)) && (!isset($widthcols[$i]['w']))) {
  21934. $numleft++;
  21935. unset($widthcols[$i]);
  21936. }
  21937. else { $usedup += $widthcols[$i]; }
  21938. }
  21939. for ($i=0;$i<$numcols;$i++) {
  21940. if (!isset($widthcols[$i]) || !$widthcols[$i]) {
  21941. $widthcols[$i] = ((($temppgwidth - $tblbw) - $usedup)/ ($numleft));
  21942. }
  21943. }
  21944. }
  21945. }
  21946. else { //table has no width defined
  21947. $table['w'] = $tablewidth;
  21948. for ( $i = 0 ; $i < $numcols ; $i++) {
  21949. if (isset($widthcols[$i]['wpercent']) && $this->keep_table_proportions) { $colwidth = $widthcols[$i]['maw']; }
  21950. else if (isset($widthcols[$i]['w'])) { $colwidth = $widthcols[$i]['miw']; }
  21951. else { $colwidth = $widthcols[$i]['maw']; }
  21952. unset($widthcols[$i]);
  21953. $widthcols[$i] = $colwidth;
  21954. }
  21955. }
  21956. }
  21957. function _tableHeight(&$table){
  21958. $level = $table['level'];
  21959. $levelid = $table['levelid'];
  21960. $cells = &$table['cells'];
  21961. $numcols = $table['nc'];
  21962. $numrows = $table['nr'];
  21963. $listspan = array();
  21964. $checkmaxheight = 0;
  21965. $headerrowheight = 0;
  21966. $checkmaxheightplus = 0;
  21967. $headerrowheightplus = 0;
  21968. $firstrowheight = 0; // mPDF 5.0.014
  21969. $footerrowheight = 0;
  21970. $footerrowheightplus = 0;
  21971. if ($this->table_rotate) {
  21972. $temppgheight = $this->tbrot_maxh;
  21973. $remainingpage = $this->tbrot_maxh;
  21974. }
  21975. else {
  21976. $temppgheight = ($this->h - $this->bMargin - $this->tMargin) - $this->kwt_height;
  21977. $remainingpage = ($this->h - $this->bMargin - $this->y) - $this->kwt_height;
  21978. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  21979. // then allow for this
  21980. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $table['margin']['B'];
  21981. if ($remainingpage > $enddiv && $enddiv/$remainingpage <0.05) { $remainingpage -= $enddiv; }
  21982. else if ($remainingpage == 0) { $remainingpage = 0.001; }
  21983. if ($temppgheight > $enddiv && $enddiv/$temppgheight <0.05) { $temppgheight -= $enddiv; }
  21984. else if ($temppgheight == 0) { $temppgheight = 0.001; }
  21985. }
  21986. for( $i = 0 ; $i < $numrows ; $i++ ) { //rows
  21987. $heightrow = &$table['hr'][$i];
  21988. for( $j = 0 ; $j < $numcols ; $j++ ) { //columns
  21989. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  21990. $c = &$cells[$i][$j];
  21991. if ($this->simpleTables){
  21992. if ($table['borders_separate']) { // NB twice border width
  21993. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w']) + ($c['padding']['L']+$c['padding']['R'])+$table['border_spacing_H'];
  21994. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w']) + ($c['padding']['T']+$c['padding']['B'])+$table['border_spacing_V'];
  21995. }
  21996. else {
  21997. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w'])/2 + ($c['padding']['L']+$c['padding']['R']);
  21998. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w'])/2 + ($c['padding']['T']+$c['padding']['B']);
  21999. }
  22000. }
  22001. else {
  22002. if ($this->packTableData) {
  22003. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  22004. }
  22005. else {
  22006. $bt = $c['border_details']['T']['w'];
  22007. $bb = $c['border_details']['B']['w'];
  22008. $br = $c['border_details']['R']['w'];
  22009. $bl = $c['border_details']['L']['w'];
  22010. }
  22011. if ($table['borders_separate']) { // NB twice border width
  22012. $extraWLR = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  22013. $extrh = $bt + $bb + $c['padding']['T'] + $c['padding']['B'] + $table['border_spacing_V'];
  22014. }
  22015. else {
  22016. $extraWLR = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  22017. $extrh = $bt/2 + $bb/2 + $c['padding']['T']+$c['padding']['B'];
  22018. }
  22019. }
  22020. list($x,$cw) = $this->_tableGetWidth($table, $i,$j);
  22021. //Check whether width is enough for this cells' text
  22022. $auxtext = implode("",$c['text']);
  22023. $auxtext2 = $auxtext; //in case we have text with styles
  22024. $aux3 = $auxtext; //in case we have text with styles
  22025. // Get CELL HEIGHT
  22026. // ++ extra parameter forces wrap to break word
  22027. if ($c['R']) {
  22028. $aux4 = implode(" ",$c['text']);
  22029. $s_fs = $this->FontSizePt;
  22030. $s_f = $this->FontFamily;
  22031. $s_st = $this->FontStyle;
  22032. $this->SetFont($c['textbuffer'][0][4],$c['textbuffer'][0][2],$c['textbuffer'][0][11] / $this->shrin_k,true,true);
  22033. $aux4 = ltrim($aux4);
  22034. $aux4= rtrim($aux4);
  22035. $tempch = $this->GetStringWidth($aux4);
  22036. if ($c['R'] >= 45 && $c['R'] < 90) {
  22037. $tempch = ((sin(deg2rad($c['R']))) * $tempch ) + ((sin(deg2rad($c['R']))) * (($c['textbuffer'][0][11]/$this->k) / $this->shrin_k));
  22038. }
  22039. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  22040. $ch = ($tempch ) + $extrh ;
  22041. }
  22042. else {
  22043. if (isset($c['textbuffer'])) {
  22044. $tempch = $this->TableWordWrap(($cw-$extraWLR),1,$c['textbuffer'], $c['dfs']);
  22045. }
  22046. else { $tempch = 0; }
  22047. // Added cellpadding top and bottom. (Lineheight already adjusted to table_lineheight)
  22048. $ch = $tempch + $extrh ;
  22049. }
  22050. //If height is defined and it is bigger than calculated $ch then update values
  22051. if (isset($c['h']) && $c['h'] > $ch) {
  22052. $c['mih'] = $ch; //in order to keep valign working
  22053. $ch = $c['h'];
  22054. }
  22055. else $c['mih'] = $ch;
  22056. if (isset($c['rowspan'])) $listspan[] = array($i,$j);
  22057. elseif ($heightrow < $ch) $heightrow = $ch;
  22058. // this is the extra used in _tableWrite to determine whether to trigger a page change
  22059. if ($table['borders_separate']) {
  22060. if ($i == ($numrows-1) || (isset($c['rowspan']) && ($i+$c['rowspan']) == ($numrows)) ) {
  22061. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  22062. }
  22063. else {
  22064. $extra = $table['border_spacing_V']/2;
  22065. }
  22066. }
  22067. else {
  22068. if (!$this->simpleTables){
  22069. $extra = $bb/2;
  22070. }
  22071. else if ($this->simpleTables){
  22072. $extra = $table['simple']['border_details']['B']['w'] /2;
  22073. }
  22074. }
  22075. // mPDF 5.0.021
  22076. if ($i <$this->tableheadernrows && $this->usetableheader) {
  22077. if ($j==0) {
  22078. $headerrowheight += $ch;
  22079. $headerrowheightplus += $ch+$extra;
  22080. }
  22081. }
  22082. else if ($table['is_tfoot'][$i]) {
  22083. if ($j==0) {
  22084. $footerrowheight += $ch;
  22085. $footerrowheightplus += $ch+$extra;
  22086. }
  22087. }
  22088. else {
  22089. $checkmaxheight = max($checkmaxheight,$ch);
  22090. $checkmaxheightplus = max($checkmaxheightplus,$ch+$extra);
  22091. }
  22092. if ($i == $this->tableheadernrows) { $firstrowheight = max($ch,$firstrowheight); } // mPDF 5.0.014
  22093. unset($c);
  22094. }
  22095. }//end of columns
  22096. }//end of rows
  22097. $heightrow = &$table['hr'];
  22098. foreach ($listspan as $span) {
  22099. list($i,$j) = $span;
  22100. $c = &$cells[$i][$j];
  22101. $lr = $i + $c['rowspan'];
  22102. if ($lr > $numrows) $lr = $numrows;
  22103. $hs = $hsa = 0;
  22104. $list = array();
  22105. for($k=$i;$k<$lr;$k++) {
  22106. $hs += $heightrow[$k];
  22107. if (!isset($c['h'])) {
  22108. $list[] = $k;
  22109. $hsa += $heightrow[$k];
  22110. }
  22111. }
  22112. if ($table['borders_separate']) {
  22113. if ($i == ($numrows-1) || ($i+$c['rowspan']) == ($numrows) ) {
  22114. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  22115. }
  22116. else {
  22117. $extra = $table['border_spacing_V']/2;
  22118. }
  22119. }
  22120. else {
  22121. if (!$this->simpleTables){
  22122. if ($this->packTableData) {
  22123. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  22124. }
  22125. else {
  22126. $bb = $c['border_details']['B']['w'];
  22127. }
  22128. $extra = $bb/2;
  22129. }
  22130. else if ($this->simpleTables){
  22131. $extra = $table['simple']['border_details']['B']['w'] /2;
  22132. }
  22133. }
  22134. if ($i <$this->tableheadernrows && $this->usetableheader) {
  22135. $headerrowheight = max($headerrowheight,$hs);
  22136. $headerrowheightplus = max($headerrowheightplus,$hs+$extra);
  22137. }
  22138. else if (!empty($table['is_tfoot'][$i])) { // mPDF 5.0.052
  22139. $footerrowheight = max($footerrowheight,$hs);
  22140. $footerrowheightplus = max($footerrowheightplus,$hs+$extra);
  22141. }
  22142. else {
  22143. $checkmaxheight = max($checkmaxheight,$hs);
  22144. $checkmaxheightplus = max($checkmaxheightplus,$hs+$extra);
  22145. }
  22146. if ($i == $this->tableheadernrows) { $firstrowheight = max($hs,$firstrowheight); } // mPDF 5.0.014
  22147. if ($c['mih'] > $hs) {
  22148. if (!$hs) {
  22149. for($k=$i;$k<$lr;$k++) $heightrow[$k] = $c['mih']/$c['rowspan'];
  22150. }
  22151. elseif (!count($list)) {
  22152. $hi = $c['mih'] - $hs;
  22153. for($k=$i;$k<$lr;$k++) $heightrow[$k] += ($heightrow[$k]/$hs)*$hi;
  22154. }
  22155. else {
  22156. $hi = $c['mih'] - $hsa;
  22157. foreach ($list as $k) $heightrow[$k] += ($heightrow[$k]/$hsa)*$hi;
  22158. }
  22159. }
  22160. unset($c);
  22161. }
  22162. $table['h'] = array_sum($table['hr']);
  22163. if ($table['borders_separate']) {
  22164. $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['border_details']['T']['w'] + $table['border_details']['B']['w'] + $table['border_spacing_V'] + $table['padding']['T'] + $table['padding']['B'];
  22165. }
  22166. else {
  22167. $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['max_cell_border_width']['T']/2 + $table['max_cell_border_width']['B']/2;
  22168. }
  22169. $maxrowheight = $checkmaxheightplus + $headerrowheightplus + $footerrowheightplus;
  22170. $maxfirstrowheight = $firstrowheight + $headerrowheightplus + $footerrowheightplus; // mPDF 5.0.014 includes thead, 1st row and tfoot
  22171. return array($table['h'],$maxrowheight,$temppgheight,$remainingpage,$maxfirstrowheight); // mPDF 5.0.014
  22172. }
  22173. function _tableGetWidth(&$table, $i,$j){
  22174. $cell = &$table['cells'][$i][$j];
  22175. if ($cell) {
  22176. if (isset($cell['x0'])) return array($cell['x0'], $cell['w0']);
  22177. $x = 0;
  22178. $widthcols = &$table['wc'];
  22179. for( $k = 0 ; $k < $j ; $k++ ) $x += $widthcols[$k];
  22180. $w = $widthcols[$j];
  22181. if (isset($cell['colspan'])) {
  22182. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) $w += $widthcols[$k];
  22183. }
  22184. $cell['x0'] = $x;
  22185. $cell['w0'] = $w;
  22186. return array($x, $w);
  22187. }
  22188. return array(0,0);
  22189. }
  22190. function _tableGetHeight(&$table, $i,$j){
  22191. $cell = &$table['cells'][$i][$j];
  22192. if ($cell){
  22193. if (isset($cell['y0'])) return array($cell['y0'], $cell['h0']);
  22194. $y = 0;
  22195. $heightrow = &$table['hr'];
  22196. for ($k=0;$k<$i;$k++) $y += $heightrow[$k];
  22197. $h = $heightrow[$i];
  22198. if (isset($cell['rowspan'])){
  22199. for ($k=$i+$cell['rowspan']-1;$k>$i;$k--)
  22200. $h += $heightrow[$k];
  22201. }
  22202. $cell['y0'] = $y;
  22203. $cell['h0'] = $h;
  22204. return array($y, $h);
  22205. }
  22206. return array(0,0);
  22207. }
  22208. // CHANGED TO ALLOW TABLE BORDER TO BE SPECIFIED CORRECTLY - added border_details
  22209. function _tableRect($x, $y, $w, $h, $bord=-1, $details=array(), $buffer=false, $bSeparate=false, $cort='cell', $tablecorner='', $bsv=0, $bsh=0) {
  22210. $cellBorderOverlay = array();
  22211. if ($bord==-1) { $this->Rect($x, $y, $w, $h); }
  22212. else if ($this->simpleTables && ($cort=='cell')) {
  22213. $this->SetLineWidth($details['L']['w']);
  22214. if ($details['L']['c']) {
  22215. $this->SetDColor($details['L']['c']); // mPDF 5.0.020
  22216. }
  22217. else { $this->SetDColor($this->ConvertColor(0)); } // mPDF 5.0.051
  22218. $this->SetLineJoin(0); // mPDF 5.0.051 n j
  22219. $this->Rect($x, $y, $w, $h);
  22220. }
  22221. else if ($bord){
  22222. if (!$bSeparate && $buffer) {
  22223. $priority = 'LRTB';
  22224. for($p=0;$p<strlen($priority);$p++) {
  22225. $side = $priority[$p];
  22226. $details['p'] = $side ;
  22227. $dom = 0;
  22228. if (isset($details[$side]['w'])) { $dom += ($details[$side]['w'] * 100000); }
  22229. if (isset($details[$side]['style'])) { $dom += (array_search($details[$side]['style'],$this->borderstyles)*100) ; }
  22230. if (isset($details[$side]['dom'])) { $dom += ($details[$side]['dom']*10); }
  22231. // Precedence to darker colours at joins
  22232. $coldom = 0;
  22233. if (isset($details[$side]['c']) && is_array($details[$side]['c'])) {
  22234. // mPDF 5.0.051
  22235. if ($details[$side]['c'][0]==3) { // RGB
  22236. $coldom = 10-((($details[$side]['c'][1]*1.00)+($details[$side]['c'][2]*1.00)+($details[$side]['c'][3]*1.00))/76.5);
  22237. }
  22238. } // 10 black - 0 white
  22239. if ($coldom) { $dom += $coldom; }
  22240. // Lastly precedence to RIGHT and BOTTOM cells at joins
  22241. if (isset($details['cellposdom'])) { $dom += $details['cellposdom']; }
  22242. $save = false;
  22243. if ($side == 'T' && $this->issetBorder($bord, _BORDER_TOP)) { $cbord = _BORDER_TOP; $save = true; }
  22244. else if ($side == 'L' && $this->issetBorder($bord, _BORDER_LEFT)) { $cbord = _BORDER_LEFT; $save = true; }
  22245. else if ($side == 'R' && $this->issetBorder($bord, _BORDER_RIGHT)) { $cbord = _BORDER_RIGHT; $save = true; }
  22246. else if ($side == 'B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { $cbord = _BORDER_BOTTOM; $save = true; }
  22247. if ($save) {
  22248. // mPDF 5.0.051
  22249. $this->cellBorderBuffer[] = pack("A16nCndnnnnddA10d14",
  22250. str_pad(sprintf("%08.7f", $dom),16,"0",STR_PAD_LEFT),
  22251. $cbord,
  22252. ord($side),
  22253. $details[$side]['s'],
  22254. $details[$side]['w'],
  22255. $details[$side]['c'][0],
  22256. $details[$side]['c'][1],
  22257. $details[$side]['c'][2],
  22258. $details[$side]['c'][3],
  22259. $details[$side]['c'][4],
  22260. $details[$side]['c'][5],
  22261. $details[$side]['style'],
  22262. $x, $y, $w, $h,
  22263. $details['mbw']['BL'],
  22264. $details['mbw']['BR'],
  22265. $details['mbw']['RT'],
  22266. $details['mbw']['RB'],
  22267. $details['mbw']['TL'],
  22268. $details['mbw']['TR'],
  22269. $details['mbw']['LT'],
  22270. $details['mbw']['LB'],
  22271. $details['cellposdom'],
  22272. 0
  22273. );
  22274. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset' || $details[$side]['style'] == 'double' ) {
  22275. $details[$side]['overlay'] = true;
  22276. // mPDF 5.0.051
  22277. $this->cellBorderBuffer[] = pack("A16nCndnnnnddA10d14",
  22278. str_pad(sprintf("%08.7f", ($dom+4)),16,"0",STR_PAD_LEFT), /* mPDF 4.3.019 */
  22279. $cbord,
  22280. ord($side),
  22281. $details[$side]['s'],
  22282. $details[$side]['w'],
  22283. $details[$side]['c'][0],
  22284. $details[$side]['c'][1],
  22285. $details[$side]['c'][2],
  22286. $details[$side]['c'][3],
  22287. $details[$side]['c'][4],
  22288. $details[$side]['c'][5],
  22289. $details[$side]['style'],
  22290. $x, $y, $w, $h,
  22291. $details['mbw']['BL'],
  22292. $details['mbw']['BR'],
  22293. $details['mbw']['RT'],
  22294. $details['mbw']['RB'],
  22295. $details['mbw']['TL'],
  22296. $details['mbw']['TR'],
  22297. $details['mbw']['LT'],
  22298. $details['mbw']['LB'],
  22299. $details['cellposdom'],
  22300. 1
  22301. );
  22302. }
  22303. }
  22304. }
  22305. return;
  22306. }
  22307. if (isset($details['p']) && strlen($details['p'])>1) { $priority = $details['p']; }
  22308. else { $priority='LTRB'; }
  22309. $Tw = 0;
  22310. $Rw = 0;
  22311. $Bw = 0;
  22312. $Lw = 0;
  22313. if (isset($details['T']['w'])) { $Tw = $details['T']['w']; }
  22314. if (isset($details['R']['w'])) { $Rw = $details['R']['w']; }
  22315. if (isset($details['B']['w'])) { $Bw = $details['B']['w']; }
  22316. if (isset($details['L']['w'])) { $Lw = $details['L']['w']; }
  22317. $x2 = $x + $w; $y2 = $y + $h;
  22318. $oldlinewidth = $this->LineWidth;
  22319. for($p=0;$p<strlen($priority);$p++) {
  22320. $side = $priority[$p];
  22321. $xadj = 0;
  22322. $xadj2 = 0;
  22323. $yadj = 0;
  22324. $yadj2 = 0;
  22325. $print = false;
  22326. if ($Tw && $side=='T' && $this->issetBorder($bord, _BORDER_TOP)) { // TOP
  22327. $ly1 = $y;
  22328. $ly2 = $y;
  22329. $lx1 = $x;
  22330. $lx2 = $x2;
  22331. $this->SetLineWidth($Tw);
  22332. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22333. if ($Tw > $Lw) $xadj = ($Tw - $Lw)/2;
  22334. if ($Tw < $Lw) $xadj = ($Tw + $Lw)/2;
  22335. }
  22336. else { $xadj = $Tw/2 - $bsh/2; }
  22337. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22338. if ($Tw > $Rw) $xadj2 = ($Tw - $Rw)/2;
  22339. if ($Tw < $Rw) $xadj2 = ($Tw + $Rw)/2;
  22340. }
  22341. else { $xadj2 = $Tw/2 - $bsh/2; }
  22342. if (!$bSeparate && $details['mbw']['TL']) {
  22343. $xadj = ($Tw - $details['mbw']['TL'])/2 ;
  22344. }
  22345. if (!$bSeparate && $details['mbw']['TR']) {
  22346. $xadj2 = ($Tw - $details['mbw']['TR'])/2;
  22347. }
  22348. $print = true;
  22349. }
  22350. if ($Lw && $side=='L' && $this->issetBorder($bord, _BORDER_LEFT)) { // LEFT
  22351. $ly1 = $y;
  22352. $ly2 = $y2;
  22353. $lx1 = $x;
  22354. $lx2 = $x;
  22355. $this->SetLineWidth($Lw);
  22356. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22357. if ($Lw > $Tw) $yadj = ($Lw - $Tw)/2;
  22358. if ($Lw < $Tw) $yadj = ($Lw + $Tw)/2;
  22359. }
  22360. else { $yadj = $Lw/2 - $bsv/2; }
  22361. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22362. if ($Lw > $Bw) $yadj2 = ($Lw - $Bw)/2;
  22363. if ($Lw < $Bw) $yadj2 = ($Lw + $Bw)/2;
  22364. }
  22365. else { $yadj2 = $Lw/2 - $bsv/2; }
  22366. if (!$bSeparate && $details['mbw']['LT']) {
  22367. $yadj = ($Lw - $details['mbw']['LT'])/2;
  22368. }
  22369. if (!$bSeparate && $details['mbw']['LB']) {
  22370. $yadj2 = ($Lw - $details['mbw']['LB'])/2;
  22371. }
  22372. $print = true;
  22373. }
  22374. if ($Rw && $side=='R' && $this->issetBorder($bord, _BORDER_RIGHT)) { // RIGHT
  22375. $ly1 = $y;
  22376. $ly2 = $y2;
  22377. $lx1 = $x2;
  22378. $lx2 = $x2;
  22379. $this->SetLineWidth($Rw);
  22380. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22381. if ($Rw < $Tw) $yadj = ($Rw + $Tw)/2;
  22382. if ($Rw > $Tw) $yadj = ($Rw - $Tw)/2;
  22383. }
  22384. else { $yadj = $Rw/2 - $bsv/2; }
  22385. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22386. if ($Rw > $Bw) $yadj2 = ($Rw - $Bw)/2;
  22387. if ($Rw < $Bw) $yadj2 = ($Rw + $Bw)/2;
  22388. }
  22389. else { $yadj2 = $Rw/2 - $bsv/2; }
  22390. if (!$bSeparate && $details['mbw']['RT']) {
  22391. $yadj = ($Rw - $details['mbw']['RT'])/2;
  22392. }
  22393. if (!$bSeparate && $details['mbw']['RB']) {
  22394. $yadj2 = ($Rw - $details['mbw']['RB'])/2;
  22395. }
  22396. $print = true;
  22397. }
  22398. if ($Bw && $side=='B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { // BOTTOM
  22399. $ly1 = $y2;
  22400. $ly2 = $y2;
  22401. $lx1 = $x;
  22402. $lx2 = $x2;
  22403. $this->SetLineWidth($Bw);
  22404. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22405. if ($Bw > $Lw) $xadj = ($Bw - $Lw)/2;
  22406. if ($Bw < $Lw) $xadj = ($Bw + $Lw)/2;
  22407. }
  22408. else { $xadj = $Bw/2 - $bsh/2; }
  22409. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22410. if ($Bw > $Rw) $xadj2 = ($Bw - $Rw)/2;
  22411. if ($Bw < $Rw) $xadj2 = ($Bw + $Rw)/2;
  22412. }
  22413. else { $xadj2 = $Bw/2 - $bsh/2; }
  22414. if (!$bSeparate && $details['mbw']['BL']) {
  22415. $xadj = ($Bw - $details['mbw']['BL'])/2;
  22416. }
  22417. if (!$bSeparate && $details['mbw']['BR']) {
  22418. $xadj2 = ($Bw - $details['mbw']['BR'])/2;
  22419. }
  22420. $print = true;
  22421. }
  22422. // Now draw line
  22423. if ($print) {
  22424. /*-- TABLES-ADVANCED-BORDERS --*/
  22425. if ($details[$side]['style'] == 'double') {
  22426. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22427. if ($details[$side]['c']) {
  22428. $this->SetDColor($details[$side]['c']); // mPDF 5.0.020
  22429. }
  22430. else { $this->SetDColor($this->ConvertColor(0)); } // mPDF 5.0.051
  22431. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22432. }
  22433. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22434. if ($bSeparate && $cort=='table') {
  22435. if ($side=='T') {
  22436. $xadj -= $this->LineWidth/2;
  22437. $xadj2 -= $this->LineWidth;
  22438. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22439. $xadj += $this->LineWidth/2;
  22440. }
  22441. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22442. $xadj2 += $this->LineWidth;
  22443. }
  22444. }
  22445. if ($side=='L') {
  22446. $yadj -= $this->LineWidth/2;
  22447. $yadj2 -= $this->LineWidth;
  22448. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22449. $yadj += $this->LineWidth/2;
  22450. }
  22451. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22452. $yadj2 += $this->LineWidth;
  22453. }
  22454. }
  22455. if ($side=='B') {
  22456. $xadj -= $this->LineWidth/2;
  22457. $xadj2 -= $this->LineWidth;
  22458. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22459. $xadj += $this->LineWidth/2;
  22460. }
  22461. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22462. $xadj2 += $this->LineWidth;
  22463. }
  22464. }
  22465. if ($side=='R') {
  22466. $yadj -= $this->LineWidth/2;
  22467. $yadj2 -= $this->LineWidth;
  22468. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22469. $yadj += $this->LineWidth/2;
  22470. }
  22471. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22472. $yadj2 += $this->LineWidth;
  22473. }
  22474. }
  22475. }
  22476. $this->SetLineWidth($this->LineWidth/3);
  22477. $tbcol = $this->ConvertColor(255); // mPDF 5.0.051
  22478. for($l=0; $l <= $this->blklvl; $l++) {
  22479. if ($this->blk[$l]['bgcolor']) {
  22480. $tbcol = array($this->blk[$l]['bgcolorarray']); // mPDF 5.0.020
  22481. }
  22482. }
  22483. if ($bSeparate) {
  22484. $cellBorderOverlay[] = array(
  22485. 'x' => $lx1 + $xadj,
  22486. 'y' => $ly1 + $yadj,
  22487. 'x2' => $lx2 - $xadj2,
  22488. 'y2' => $ly2 - $yadj2,
  22489. 'col' => $tbcol, /* mPDF 4.2 */
  22490. 'lw' => $this->LineWidth,
  22491. );
  22492. }
  22493. else {
  22494. $this->SetDColor($tbcol); // mPDF 5.0.020
  22495. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22496. }
  22497. }
  22498. }
  22499. else if (isset($details[$side]['style']) && ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset')) {
  22500. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22501. if ($details[$side]['c']) {
  22502. $this->SetDColor($details[$side]['c']); // mPDF 5.0.020
  22503. }
  22504. else { $this->SetDColor($this->ConvertColor(0)); } // mPDF 5.0.051
  22505. if ($details[$side]['style'] == 'outset' || $details[$side]['style'] == 'groove') {
  22506. $nc = $this->_darkenColor($details[$side]['c']);
  22507. $this->SetDColor($nc); // mPDF 5.0.051
  22508. }
  22509. else if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22510. $nc = $this->_lightenColor($details[$side]['c']);
  22511. $this->SetDColor($nc); // mPDF 5.0.051
  22512. }
  22513. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22514. }
  22515. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22516. if ($details[$side]['c']) {
  22517. $this->SetDColor($details[$side]['c']); // mPDF 5.0.020
  22518. }
  22519. else { $this->SetDColor($this->ConvertColor(0)); } // mPDF 5.0.051
  22520. $doubleadj = ($this->LineWidth)/3;
  22521. $this->SetLineWidth($this->LineWidth/2);
  22522. $xadj3 = $yadj3 = $wadj3 = $hadj3 = 0;
  22523. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22524. $nc = $this->_darkenColor($details[$side]['c']);
  22525. if ($bSeparate && $cort=='table') {
  22526. if ($side=='T') {
  22527. $yadj3 = $this->LineWidth/2;
  22528. $xadj3 = -$this->LineWidth/2;
  22529. $wadj3 = $this->LineWidth;
  22530. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22531. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22532. }
  22533. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22534. $wadj3 -= $this->LineWidth*2;
  22535. }
  22536. }
  22537. if ($side=='L') {
  22538. $xadj3 = $this->LineWidth/2;
  22539. $yadj3 = -$this->LineWidth/2;
  22540. $hadj3 = $this->LineWidth;
  22541. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22542. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22543. }
  22544. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22545. $hadj3 -= $this->LineWidth*2;
  22546. }
  22547. }
  22548. if ($side=='B') {
  22549. $yadj3 = $this->LineWidth/2;
  22550. $xadj3 = -$this->LineWidth/2;
  22551. $wadj3 = $this->LineWidth;
  22552. }
  22553. if ($side=='R') {
  22554. $xadj3 = $this->LineWidth/2;
  22555. $yadj3 = -$this->LineWidth/2;
  22556. $hadj3 = $this->LineWidth;
  22557. }
  22558. }
  22559. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; $wadj3 = -$this->LineWidth*2; }
  22560. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; $hadj3 = -$this->LineWidth*2; }
  22561. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $wadj3 = $this->LineWidth/2; }
  22562. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $hadj3 = $this->LineWidth/2; }
  22563. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22564. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22565. }
  22566. else {
  22567. $nc = $this->_lightenColor($details[$side]['c']);
  22568. if ($bSeparate && $cort=='table') {
  22569. if ($side=='T') {
  22570. $yadj3 = $this->LineWidth/2;
  22571. $xadj3 = -$this->LineWidth/2;
  22572. $wadj3 = $this->LineWidth;
  22573. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22574. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22575. }
  22576. }
  22577. if ($side=='L') {
  22578. $xadj3 = $this->LineWidth/2;
  22579. $yadj3 = -$this->LineWidth/2;
  22580. $hadj3 = $this->LineWidth;
  22581. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22582. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22583. }
  22584. }
  22585. if ($side=='B') {
  22586. $yadj3 = $this->LineWidth/2;
  22587. $xadj3 = -$this->LineWidth/2;
  22588. $wadj3 = $this->LineWidth;
  22589. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22590. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22591. }
  22592. }
  22593. if ($side=='R') {
  22594. $xadj3 = $this->LineWidth/2;
  22595. $yadj3 = -$this->LineWidth/2;
  22596. $hadj3 = $this->LineWidth;
  22597. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22598. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22599. }
  22600. }
  22601. }
  22602. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22603. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22604. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22605. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22606. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; }
  22607. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; }
  22608. }
  22609. if ($bSeparate) {
  22610. $cellBorderOverlay[] = array(
  22611. 'x' => $lx1 + $xadj + $xadj3,
  22612. 'y' => $ly1 + $yadj + $yadj3,
  22613. 'x2' => $lx2 - $xadj2 + $xadj3 + $wadj3,
  22614. 'y2' => $ly2 - $yadj2 + $yadj3 + $hadj3,
  22615. 'col' => $nc, /* mPDF 5.0.051 */
  22616. 'lw' => $this->LineWidth,
  22617. );
  22618. }
  22619. else {
  22620. $this->SetDColor($nc); // mPDF 5.0.051
  22621. $this->Line($lx1 + $xadj + $xadj3, $ly1 + $yadj + $yadj3, $lx2 - $xadj2 + $xadj3 + $wadj3, $ly2 - $yadj2 + $yadj3 + $hadj3);
  22622. }
  22623. }
  22624. }
  22625. else {
  22626. /*-- END TABLES-ADVANCED-BORDERS --*/
  22627. if ($details[$side]['style'] == 'dashed') {
  22628. $dashsize = 2; // final dash will be this + 1*linewidth
  22629. $dashsizek = 1.5; // ratio of Dash/Blank
  22630. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  22631. }
  22632. else if ($details[$side]['style'] == 'dotted') {
  22633. $this->SetLineJoin(1); // mPDF 5.0.051 n j
  22634. $this->SetLineCap(1); // mPDF 5.0.051 n J
  22635. $this->SetDash(0.001,($this->LineWidth*2));
  22636. }
  22637. if ($details[$side]['c']) {
  22638. $this->SetDColor($details[$side]['c']); // mPDF 5.0.020
  22639. }
  22640. else { $this->SetDColor($this->ConvertColor(0)); } // mPDF 5.0.051
  22641. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22642. /*-- TABLES-ADVANCED-BORDERS --*/
  22643. }
  22644. /*-- END TABLES-ADVANCED-BORDERS --*/
  22645. // Reset Corners
  22646. $this->SetDash();
  22647. //BUTT style line cap
  22648. $this->SetLineCap(2); // mPDF 5.0.051 n J
  22649. }
  22650. }
  22651. if ($bSeparate && count($cellBorderOverlay)) {
  22652. foreach($cellBorderOverlay AS $cbo) {
  22653. $this->SetLineWidth($cbo['lw']);
  22654. $this->SetDColor($cbo['col']); // mPDF 5.0.051
  22655. $this->Line($cbo['x'], $cbo['y'], $cbo['x2'], $cbo['y2']);
  22656. }
  22657. }
  22658. // $this->SetLineWidth($oldlinewidth);
  22659. // $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  22660. }
  22661. }
  22662. /*-- TABLES --*/
  22663. /*-- TABLES-ADVANCED-BORDERS --*/
  22664. function _lightenColor($c) {
  22665. if (isset($c['R'])) { die('Color error in _lightencolor'); } // mPDF 5.0.051
  22666. if ($c[0]==3 || $c[0]==5) { // RGB // mPDF 5.0.051
  22667. list($h,$s,$l) = $this->rgb2hsl($c[1]/255,$c[2]/255,$c[3]/255);
  22668. $l += ((1 - $l)*0.8);
  22669. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  22670. return array(3,$r,$g,$b);
  22671. }
  22672. else if ($c[0]==4 || $c[0]==6) { // CMYK
  22673. return array(4, max(0,($c[1]-20)), max(0,($c[2]-20)), max(0,($c[3]-20)), max(0,($c[4]-20)) );
  22674. }
  22675. else if ($c[0]==1) { // Grayscale
  22676. return array(1,min(255,($c[1]+32)));
  22677. }
  22678. return $c;
  22679. }
  22680. function _darkenColor($c) {
  22681. if (isset($c['R'])) { die('Color error in _lightencolor'); } // mPDF 5.0.051
  22682. if ($c[0]==3 || $c[0]==5) { // RGB // mPDF 5.0.051
  22683. list($h,$s,$l) = $this->rgb2hsl($c[1]/255,$c[2]/255,$c[3]/255);
  22684. $s *= 0.25;
  22685. $l *= 0.75;
  22686. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  22687. return array(3,$r,$g,$b);
  22688. }
  22689. else if ($c[0]==4 || $c[0]==6) { // CMYK
  22690. return array(4, min(100,($c[1]+20)), min(100,($c[2]+20)), min(100,($c[3]+20)), min(100,($c[4]+20)) );
  22691. }
  22692. else if ($c[0]==1) { // Grayscale
  22693. return array(1,max(0,($c[1]-32)));
  22694. }
  22695. return $c;
  22696. }
  22697. // mPDF 5.0.051
  22698. // functions to convert rgb to hsl etc moved later and outside TABLES as needed for ConvertColor
  22699. /*-- END TABLES-ADVANCED-BORDERS --*/
  22700. /*-- END TABLES --*/
  22701. function setBorder(&$var, $flag, $set = true) {
  22702. $flag = intval($flag);
  22703. if ($set) { $set = true; }
  22704. $var = intval($var);
  22705. $var = $set ? ($var | $flag) : ($var & ~$flag);
  22706. }
  22707. function issetBorder($var, $flag) {
  22708. $flag = intval($flag);
  22709. $var = intval($var);
  22710. return (($var & $flag) == $flag);
  22711. }
  22712. function _table2cellBorder(&$tableb, &$cbdb, &$cellb, $bval) {
  22713. if ($tableb && $tableb['w'] > $cbdb['w']) {
  22714. $cbdb = $tableb;
  22715. $this->setBorder($cellb, $bval);
  22716. }
  22717. else if ($tableb && $tableb['w'] == $cbdb['w']
  22718. && array_search($tableb['style'],$this->borderstyles) > array_search($cbdb['style'],$this->borderstyles)) {
  22719. $cbdb = $tableb;
  22720. $this->setBorder($cellb, $bval);
  22721. }
  22722. }
  22723. // FIX BORDERS ********************************************
  22724. function _fixTableBorders(&$table){
  22725. if (!$table['borders_separate'] && $table['border_details']['L']['w']) {
  22726. $table['max_cell_border_width']['L'] = $table['border_details']['L']['w'];
  22727. }
  22728. if (!$table['borders_separate'] && $table['border_details']['R']['w']) {
  22729. $table['max_cell_border_width']['R'] = $table['border_details']['R']['w'];
  22730. }
  22731. if (!$table['borders_separate'] && $table['border_details']['T']['w']) {
  22732. $table['max_cell_border_width']['T'] = $table['border_details']['T']['w'];
  22733. }
  22734. if (!$table['borders_separate'] && $table['border_details']['B']['w']) {
  22735. $table['max_cell_border_width']['B'] = $table['border_details']['B']['w'];
  22736. }
  22737. if ($this->simpleTables) { return; }
  22738. $cells = &$table['cells'];
  22739. $numcols = $table['nc'];
  22740. $numrows = $table['nr'];
  22741. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  22742. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  22743. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  22744. $cell = &$cells[$i][$j];
  22745. if ($this->packTableData) {
  22746. $cbord = $this->_unpackCellBorder($cell['borderbin']);
  22747. }
  22748. else {
  22749. $cbord = &$cells[$i][$j];
  22750. }
  22751. if (!$cbord['border'] && isset($table['border']) && $table['border'] && $this->table_border_attr_set) {
  22752. $cbord['border'] = $table['border'];
  22753. $cbord['border_details'] = $table['border_details'];
  22754. }
  22755. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  22756. else { $ccolsp = 1; }
  22757. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  22758. else { $crowsp = 1; }
  22759. $cbord['border_details']['cellposdom'] = ((($i+1)/$numrows) / 10000 ) + ((($j+1)/$numcols) / 10 );
  22760. // Inherit Cell border from Table border
  22761. if ($this->table_border_css_set && !$table['borders_separate']) {
  22762. if ($i == 0) {
  22763. $this->_table2cellBorder($table['border_details']['T'], $cbord['border_details']['T'], $cbord['border'], _BORDER_TOP);
  22764. }
  22765. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  22766. $this->_table2cellBorder($table['border_details']['B'], $cbord['border_details']['B'], $cbord['border'], _BORDER_BOTTOM);
  22767. }
  22768. if ($j == 0) {
  22769. $this->_table2cellBorder($table['border_details']['L'], $cbord['border_details']['L'], $cbord['border'], _BORDER_LEFT);
  22770. }
  22771. if ($j == ($numcols-1) || ($j+$ccolsp) == ($numcols) ) {
  22772. $this->_table2cellBorder($table['border_details']['R'], $cbord['border_details']['R'], $cbord['border'], _BORDER_RIGHT);
  22773. }
  22774. }
  22775. /*-- TABLES-ADVANCED-BORDERS --*/
  22776. if (isset($table['topntail']) && $table['topntail']) {
  22777. if ($i == 0) {
  22778. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  22779. $this->setBorder($cbord['border'], _BORDER_TOP);
  22780. if ($table['borders_separate']) {
  22781. $cbord['border_details']['B'] = $this->border_details($table['topntail']);
  22782. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  22783. }
  22784. }
  22785. else if (($i == $this->tableheadernrows) && $this->usetableheader) {
  22786. if (!$table['borders_separate']) {
  22787. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  22788. $this->setBorder($cbord['border'], _BORDER_TOP);
  22789. }
  22790. }
  22791. // Added v1.4 for TFOOT
  22792. else if (($i == ($numrows-1) ) && $this->tabletfoot) {
  22793. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  22794. $this->setBorder($cbord['border'], _BORDER_TOP);
  22795. }
  22796. else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  22797. if (!$table['borders_separate']) {
  22798. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  22799. $this->setBorder($cbord['border'], _BORDER_TOP);
  22800. }
  22801. }
  22802. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  22803. $cbord['border_details']['B'] = $this->border_details($table['topntail']);
  22804. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  22805. }
  22806. }
  22807. if (isset($table['thead-underline']) && $table['thead-underline']) {
  22808. if ($table['borders_separate']) {
  22809. if ($i == 0) {
  22810. $cbord['border_details']['B'] = $this->border_details($table['thead-underline']);
  22811. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  22812. }
  22813. }
  22814. else {
  22815. if (($i == $this->tableheadernrows) && $this->usetableheader) {
  22816. $cbord['border_details']['T'] = $this->border_details($table['thead-underline']);
  22817. $this->setBorder($cbord['border'], _BORDER_TOP);
  22818. }
  22819. else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  22820. $cbord['border_details']['T'] = $this->border_details($table['thead-underline']);
  22821. $this->setBorder($cbord['border'], _BORDER_TOP);
  22822. }
  22823. }
  22824. }
  22825. // Collapse Border - Algorithm for conflicting borders
  22826. // Hidden >> Width >> double>solid>dashed>dotted... >> style set on cell>table >> top/left>bottom/right
  22827. // Do not turn off border which is overridden
  22828. // Needed for page break for TOP/BOTTOM both to be defined in Collapsed borders
  22829. // Means it is painted twice. (Left/Right can still disable overridden border)
  22830. if (!$table['borders_separate'] && (!$this->usetableheader || $i>($this->tableheadernrows-1)) ) {
  22831. if ($i < ($numrows-1) || ($i+$crowsp) < $numrows ) { // Bottom
  22832. for ($cspi = 0; $cspi<$ccolsp; $cspi++) {
  22833. // already defined Top for adjacent cell below
  22834. if (isset($cells[($i+$crowsp)][$j+$cspi])) {
  22835. if ($this->packTableData) {
  22836. $celladj = $this->_unpackCellBorder($cells[($i+$crowsp)][$j+$cspi]['borderbin']);
  22837. }
  22838. else { $celladj =& $cells[($i+$crowsp)][$j+$cspi]; }
  22839. }
  22840. else { $celladj = false; }
  22841. if ($celladj && $celladj['border_details']['T']['s'] == 1) {
  22842. $csadj = $celladj['border_details']['T']['w'];
  22843. $csthis = $cbord['border_details']['B']['w'];
  22844. // Hidden
  22845. if ($cbord['border_details']['B']['style']=='hidden') {
  22846. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22847. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  22848. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  22849. }
  22850. else if ($celladj['border_details']['T']['style']=='hidden') {
  22851. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22852. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  22853. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  22854. }
  22855. // Width
  22856. else if ($csthis > $csadj) {
  22857. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  22858. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22859. $this->setBorder($cbord['border'] , _BORDER_BOTTOM);
  22860. }
  22861. }
  22862. else if ($csadj > $csthis) {
  22863. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  22864. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22865. $this->setBorder($celladj['border'] , _BORDER_TOP);
  22866. }
  22867. }
  22868. // double>solid>dashed>dotted...
  22869. else if (array_search($cbord['border_details']['B']['style'],$this->borderstyles) > array_search($celladj['border_details']['T']['style'],$this->borderstyles)) {
  22870. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  22871. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22872. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  22873. }
  22874. }
  22875. else if (array_search($celladj['border_details']['T']['style'],$this->borderstyles) > array_search($cbord['border_details']['B']['style'],$this->borderstyles)) {
  22876. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  22877. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22878. $this->setBorder($celladj['border'] , _BORDER_TOP);
  22879. }
  22880. }
  22881. // Style set on cell vs. table
  22882. else if ($celladj['border_details']['T']['dom'] > $cbord['border_details']['B']['dom']) {
  22883. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  22884. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22885. $this->setBorder($celladj['border'] , _BORDER_TOP);
  22886. }
  22887. }
  22888. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  22889. else {
  22890. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  22891. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22892. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  22893. }
  22894. }
  22895. }
  22896. else if ($celladj) {
  22897. if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span
  22898. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22899. }
  22900. }
  22901. if ($celladj && $this->packTableData) { $cells[($i+$crowsp)][$j+$cspi]['borderbin'] = $this->_packCellBorder($celladj); }
  22902. unset($celladj);
  22903. }
  22904. }
  22905. if ($j < ($numcols-1) || ($j+$ccolsp) < $numcols ) { // Right
  22906. for ($cspi = 0; $cspi<$crowsp; $cspi++) {
  22907. // already defined Left for adjacent cell to R
  22908. if (isset($cells[$i+$cspi][$j+$ccolsp])) {
  22909. if ($this->packTableData) {
  22910. $celladj = $this->_unpackCellBorder($cells[$i+$cspi][$j+$ccolsp]['borderbin']);
  22911. }
  22912. else { $celladj =& $cells[$i+$cspi][$j+$ccolsp]; }
  22913. }
  22914. else { $celladj = false; }
  22915. if ($celladj && $celladj['border_details']['L']['s'] == 1) {
  22916. $csadj = $celladj['border_details']['L']['w'];
  22917. $csthis = $cbord['border_details']['R']['w'];
  22918. // Hidden
  22919. if ($cbord['border_details']['R']['style']=='hidden') {
  22920. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22921. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22922. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  22923. }
  22924. else if ($celladj['border_details']['L']['style']=='hidden') {
  22925. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22926. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  22927. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22928. }
  22929. // Width
  22930. else if ($csthis > $csadj) {
  22931. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  22932. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22933. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  22934. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22935. }
  22936. }
  22937. else if ($csadj > $csthis) {
  22938. if ($crowsp < 2) { // don't overwrite this cell if it spans
  22939. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22940. $this->setBorder($cbord['border'] , _BORDER_RIGHT, false);
  22941. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  22942. }
  22943. }
  22944. // double>solid>dashed>dotted...
  22945. else if (array_search($cbord['border_details']['R']['style'],$this->borderstyles) > array_search($celladj['border_details']['L']['style'],$this->borderstyles)) {
  22946. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  22947. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22948. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22949. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  22950. }
  22951. }
  22952. else if (array_search($celladj['border_details']['L']['style'],$this->borderstyles) > array_search($cbord['border_details']['R']['style'],$this->borderstyles)) {
  22953. if ($crowsp < 2) { // don't overwrite this cell if it spans
  22954. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22955. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  22956. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  22957. }
  22958. }
  22959. // Style set on cell vs. table
  22960. else if ($celladj['border_details']['L']['dom'] > $cbord['border_details']['R']['dom']) {
  22961. if ($crowsp < 2) { // don't overwrite this cell if it spans
  22962. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22963. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  22964. }
  22965. }
  22966. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  22967. else {
  22968. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  22969. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22970. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  22971. }
  22972. }
  22973. }
  22974. else if ($celladj) {
  22975. // if right-cell border is not set
  22976. if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span
  22977. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22978. }
  22979. }
  22980. if ($celladj && $this->packTableData) { $cells[$i+$cspi][$j+$ccolsp]['borderbin'] = $this->_packCellBorder($celladj); }
  22981. unset($celladj);
  22982. }
  22983. }
  22984. }
  22985. // Set maximum cell border width meeting at LRTB edges of cell - used for extended cell border
  22986. // ['border_details']['mbw']['LT'] = meeting border width - Left border - Top end
  22987. if (!$table['borders_separate']) {
  22988. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $cbord['border_details']['L']['w']);
  22989. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $cbord['border_details']['R']['w']);
  22990. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $cbord['border_details']['T']['w']);
  22991. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $cbord['border_details']['B']['w']);
  22992. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $cbord['border_details']['L']['w']);
  22993. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $cbord['border_details']['R']['w']);
  22994. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $cbord['border_details']['T']['w']);
  22995. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $cbord['border_details']['B']['w']);
  22996. if (($i+$crowsp) < $numrows && isset($cells[$i+$crowsp][$j])) { // Has Bottom adjoining cell
  22997. if ($this->packTableData) {
  22998. $celladj = $this->_unpackCellBorder($cells[$i+$crowsp][$j]['borderbin']);
  22999. }
  23000. else { $celladj =& $cells[$i+$crowsp][$j]; }
  23001. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['TL']);
  23002. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['TR']);
  23003. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['mbw']['LT']);
  23004. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['mbw']['RT']);
  23005. unset($celladj);
  23006. }
  23007. if (($j+$ccolsp) < $numcols && isset($cells[$i][$j+$ccolsp])) { // Has Right adjoining cell
  23008. if ($this->packTableData) {
  23009. $celladj = $this->_unpackCellBorder($cells[$i][$j+$ccolsp]['borderbin']);
  23010. }
  23011. else { $celladj =& $cells[$i][$j+$ccolsp]; }
  23012. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['LT']);
  23013. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['LB']);
  23014. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['mbw']['TL']);
  23015. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['mbw']['BL']);
  23016. unset($celladj);
  23017. }
  23018. if ($i > 0 && isset($cells[$i-1][$j]) && (($this->packTableData && $cells[$i-1][$j]['borderbin']) || $cells[$i-1][$j]['border'])) { // Has Top adjoining cell
  23019. if ($this->packTableData) {
  23020. $celladj = $this->_unpackCellBorder($cells[$i-1][$j]['borderbin']);
  23021. }
  23022. else { $celladj =& $cells[$i-1][$j]; }
  23023. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['BL']);
  23024. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['BR']);
  23025. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['mbw']['LB']);
  23026. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['mbw']['RB']);
  23027. if ($celladj['border_details']['mbw']['BL']) {
  23028. $celladj['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['BL']);
  23029. }
  23030. if ($celladj['border_details']['mbw']['BR'] ) {
  23031. $celladj['border_details']['mbw']['BR'] = max($celladj['border_details']['mbw']['BR'], $cbord['border_details']['mbw']['TR']);
  23032. }
  23033. if ($this->packTableData) { $cells[$i-1][$j]['borderbin'] = $this->_packCellBorder($celladj); }
  23034. unset($celladj);
  23035. }
  23036. if ($j > 0 && isset($cells[$i][$j-1]) && (($this->packTableData && $cells[$i][$j-1]['borderbin']) || $cells[$i][$j-1]['border'])) { // Has Left adjoining cell
  23037. if ($this->packTableData) {
  23038. $celladj = $this->_unpackCellBorder($cells[$i][$j-1]['borderbin']);
  23039. }
  23040. else { $celladj =& $cells[$i][$j-1]; }
  23041. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['RT']);
  23042. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['RB']);
  23043. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['mbw']['BR']);
  23044. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['TR']);
  23045. if ($celladj['border_details']['mbw']['RT']) {
  23046. $celladj['border_details']['mbw']['RT'] = max($celladj['border_details']['mbw']['RT'], $cbord['border_details']['mbw']['LT']);
  23047. }
  23048. if ($celladj['border_details']['mbw']['RB']) {
  23049. $celladj['border_details']['mbw']['RB'] = max($celladj['border_details']['mbw']['RB'], $cbord['border_details']['mbw']['LB']);
  23050. }
  23051. if ($this->packTableData) { $cells[$i][$j-1]['borderbin'] = $this->_packCellBorder($celladj); }
  23052. unset($celladj);
  23053. }
  23054. // Update maximum cell border width at LRTB edges of table - used for overall table width
  23055. if ($j == 0 && $cbord['border_details']['L']['w']) {
  23056. $table['max_cell_border_width']['L'] = max($table['max_cell_border_width']['L'],$cbord['border_details']['L']['w']);
  23057. }
  23058. if (($j == ($numcols-1) || ($j+$ccolsp) == $numcols ) && $cbord['border_details']['R']['w']) {
  23059. $table['max_cell_border_width']['R'] = max($table['max_cell_border_width']['R'],$cbord['border_details']['R']['w']);
  23060. }
  23061. if ($i == 0 && $cbord['border_details']['T']['w']) {
  23062. $table['max_cell_border_width']['T'] = max($table['max_cell_border_width']['T'],$cbord['border_details']['T']['w']);
  23063. }
  23064. if (($i == ($numrows-1) || ($i+$crowsp) == $numrows ) && $cbord['border_details']['B']['w']) {
  23065. $table['max_cell_border_width']['B'] = max($table['max_cell_border_width']['B'],$cbord['border_details']['B']['w']);
  23066. }
  23067. }
  23068. /*-- END TABLES-ADVANCED-BORDERS --*/
  23069. if ($this->packTableData) { $cell['borderbin'] = $this->_packCellBorder($cbord); }
  23070. unset($cbord );
  23071. unset($cell );
  23072. }
  23073. }
  23074. }
  23075. unset($cell );
  23076. }
  23077. // END FIX BORDERS ************************************************************************************
  23078. function _reverseTableDir(&$table) {
  23079. $cells = &$table['cells'];
  23080. $numcols = $table['nc'];
  23081. $numrows = $table['nr'];
  23082. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23083. $row = array();
  23084. for( $j = ($numcols-1) ; $j >= 0 ; $j-- ) { //Columns
  23085. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23086. $col = $numcols - $j - 1;
  23087. if (isset($cells[$i][$j]['colspan']) && $cells[$i][$j]['colspan'] > 1) { $col -= ($cells[$i][$j]['colspan']-1); }
  23088. // Nested content
  23089. for ($n=0; $n < count($cells[$i][$j]['textbuffer']); $n++) {
  23090. $t = $cells[$i][$j]['textbuffer'][$n][0];
  23091. if (substr($t,0,3) == "\xbb\xa4\xac") {
  23092. $objattr = $this->_getObjAttr($t);
  23093. $objattr['col'] = $col;
  23094. $cells[$i][$j]['textbuffer'][$n][0] = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  23095. $this->table[($this->tableLevel+1)][$objattr['nestedcontent']]['nestedpos'][1] = $col;
  23096. }
  23097. }
  23098. $row[$col] = $cells[$i][$j];
  23099. }
  23100. }
  23101. for($f=0; $f < $numcols; $f++) {
  23102. if (!isset($row[$f])) { $row[$f] = array(); }
  23103. }
  23104. $table['cells'][$i] = $row;
  23105. }
  23106. }
  23107. function _tableWrite(&$table){
  23108. $level = $table['level'];
  23109. $levelid = $table['levelid'];
  23110. $cells = &$table['cells'];
  23111. $numcols = $table['nc'];
  23112. $numrows = $table['nr'];
  23113. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  23114. // TABLE TOP MARGIN
  23115. if ($table['margin']['T']) {
  23116. if (!$this->table_rotate && $level==1) {
  23117. $this->DivLn($table['margin']['T'],$this->blklvl,true,1); // collapsible
  23118. }
  23119. else {
  23120. $this->y += ($table['margin']['T']);
  23121. }
  23122. }
  23123. // Advance down page by half width of top border
  23124. if ($table['borders_separate']) {
  23125. $adv = $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2;
  23126. }
  23127. else {
  23128. $adv = $table['max_cell_border_width']['T']/2;
  23129. }
  23130. if (!$this->table_rotate && $level==1) { $this->DivLn($adv); }
  23131. else { $this->y += $adv; }
  23132. if ($level==1) {
  23133. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'];
  23134. $x0 = $this->x;
  23135. $y0 = $this->y;
  23136. $right = $x0 + $this->blk[$this->blklvl]['inner_width'];
  23137. $outerfilled = $this->y; // Keep track of how far down the outer DIV bgcolor is painted (NB rowspans)
  23138. $this->outerfilled = $this->y;
  23139. }
  23140. else {
  23141. $x0 = $this->x;
  23142. $y0 = $this->y;
  23143. $right = $x0 + $table['w'];
  23144. }
  23145. if ($this->table_rotate) {
  23146. $temppgwidth = $this->tbrot_maxw;
  23147. $this->PageBreakTrigger = $pagetrigger = $y0 + ($this->blk[$this->blklvl]['inner_width']);
  23148. if ($level==1) {
  23149. $this->tbrot_y0 = $this->y - $adv - $table['margin']['T'] ;
  23150. $this->tbrot_x0 = $this->x;
  23151. $this->tbrot_w = $table['w'];
  23152. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  23153. else { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['max_cell_border_width']['T']; }
  23154. }
  23155. }
  23156. else {
  23157. $this->PageBreakTrigger = $pagetrigger = ($this->h - $this->bMargin);
  23158. if ($level==1) {
  23159. $temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  23160. if (isset($table['a']) and ($table['w'] < $this->blk[$this->blklvl]['inner_width'])) {
  23161. if ($table['a']=='C') { $x0 += ((($right-$x0) - $table['w'])/2); }
  23162. else if ($table['a']=='R') { $x0 = $right - $table['w']; }
  23163. }
  23164. }
  23165. else {
  23166. $temppgwidth = $table['w'];
  23167. }
  23168. }
  23169. if(!isset($table['overflow'])) { $table['overflow'] = null; } // mPDF 5.0.052
  23170. if ($table['overflow']=='hidden' && $level==1 && !$this->table_rotate && !$this->ColActive) {
  23171. //Bounding rectangle to clip
  23172. $this->tableClipPath = sprintf('q %.3f %.3f %.3f %.3f re W n',$x0*$this->k,$this->h*$this->k,$this->blk[$this->blklvl]['inner_width']*$this->k,-$this->h*$this->k);
  23173. $this->_out($this->tableClipPath);
  23174. }
  23175. else { $this->tableClipPath = ''; }
  23176. if ($table['borders_separate']) { $indent = $table['margin']['L'] + $table['border_details']['L']['w'] + $table['padding']['L'] + $table['border_spacing_H']/2; }
  23177. else { $indent = $table['margin']['L'] + $table['max_cell_border_width']['L']/2; }
  23178. $x0 += $indent;
  23179. $returny = 0;
  23180. $tableheader = array();
  23181. $tablefooter = array();
  23182. $tablefooterrowheight = 0;
  23183. $footery = 0;
  23184. // mPD 3.0 Set the Page & Column where table starts
  23185. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  23186. $tablestartpage = 'EVEN';
  23187. }
  23188. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  23189. $tablestartpage = 'ODD';
  23190. }
  23191. else { $tablestartpage = ''; }
  23192. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; }
  23193. else { $tablestartcolumn = ''; }
  23194. $y = $h = 0;
  23195. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23196. if ($this->progressBar) { $this->UpdateProgressBar(7,intval(30 + ($i*40/$numrows)),' '); } // *PROGRESS-BAR*
  23197. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i] && $level==1) {
  23198. $tablefooterrowheight += $table['hr'][$i];
  23199. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  23200. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23201. $cell = &$cells[$i][$j];
  23202. list($x,$w) = $this->_tableGetWidth($table, $i, $j);
  23203. list($y,$h) = $this->_tableGetHeight($table, $i, $j);
  23204. $x += $x0;
  23205. $y += $y0;
  23206. //Get info of tfoot ==>> table footer
  23207. $tablefooter[$i][0]['trbackground-images'] = $table['trbackground-images'][$i]; // mPDF 5.0.018
  23208. $tablefooter[$i][0]['trgradients'] = $table['trgradients'][$i]; // mPDF 5.0.018
  23209. $tablefooter[$i][0]['trbgcolor'] = $table['bgcolor'][$i]; // mPDF 5.1.008
  23210. $tablefooter[$i][$j]['x'] = $x;
  23211. $tablefooter[$i][$j]['y'] = $y;
  23212. $tablefooter[$i][$j]['h'] = $h;
  23213. $tablefooter[$i][$j]['w'] = $w;
  23214. $tablefooter[$i][$j]['text'] = $cell['text'];
  23215. if (isset($cell['textbuffer'])) { $tablefooter[$i][$j]['textbuffer'] = $cell['textbuffer']; }
  23216. else { $tablefooter[$i][$j]['textbuffer'] = ''; }
  23217. $tablefooter[$i][$j]['a'] = $cell['a'];
  23218. $tablefooter[$i][$j]['R'] = $cell['R'];
  23219. $tablefooter[$i][$j]['va'] = $cell['va'];
  23220. $tablefooter[$i][$j]['mih'] = $cell['mih'];
  23221. $tablefooter[$i][$j]['gradient'] = $cell['gradient']; // *BACKGROUNDS*
  23222. $tablefooter[$i][$j]['background-image'] = $cell['background-image']; // *BACKGROUNDS*
  23223. //CELL FILL BGCOLOR
  23224. if (!$this->simpleTables){
  23225. if ($this->packTableData) {
  23226. $c = $this->_unpackCellBorder($cell['borderbin']);
  23227. $tablefooter[$i][$j]['border'] = $c['border'];
  23228. $tablefooter[$i][$j]['border_details'] = $c['border_details'];
  23229. }
  23230. else {
  23231. $tablefooter[$i][$j]['border'] = $cell['border'];
  23232. $tablefooter[$i][$j]['border_details'] = $cell['border_details'];
  23233. }
  23234. }
  23235. else if ($this->simpleTables){
  23236. $tablefooter[$i][$j]['border'] = $table['simple']['border'];
  23237. $tablefooter[$i][$j]['border_details'] = $table['simple']['border_details'];
  23238. }
  23239. // $fill = isset($cell['bgcolor']) ? $cell['bgcolor'] : 0; // mPDF 5.1.008
  23240. // $tablefooter[$i][$j]['bgcolor'] = $fill; // mPDF 5.1.008
  23241. $tablefooter[$i][$j]['bgcolor'] = $cell['bgcolor']; // mPDF 5.1.008
  23242. $tablefooter[$i][$j]['padding'] = $cell['padding'];
  23243. $tablefooter[$i][$j]['rowspan'] = $cell['rowspan'];
  23244. $tablefooter[$i][$j]['colspan'] = $cell['colspan'];
  23245. }
  23246. }
  23247. }
  23248. }
  23249. if ($level==1) { $this->_out('___TABLE___BACKGROUNDS'.date('jY')); } // mPDF 5.0.018
  23250. $tableheaderadj = 0; // mPDF 5.0.018
  23251. $tablefooteradj = 0; // mPDF 5.0.018
  23252. $tablestartpageno = $this->page; // mPDF 5.1.008
  23253. //Draw Table Contents and Borders
  23254. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23255. // Get Maximum row/cell height in row - including rowspan>1 + 1 overlapping
  23256. $maxrowheight = 0;
  23257. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  23258. list($y,$h) = $this->_tableGetHeight($table, $i, $j);
  23259. $maxrowheight = max($maxrowheight,$h);
  23260. }
  23261. $skippage = false;
  23262. $newpagestarted = false;
  23263. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  23264. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23265. $cell = &$cells[$i][$j];
  23266. list($x,$w) = $this->_tableGetWidth($table, $i, $j);
  23267. list($y,$h) = $this->_tableGetHeight($table, $i, $j);
  23268. $x += $x0;
  23269. $y += $y0;
  23270. $y -= $returny;
  23271. if ($table['borders_separate']) {
  23272. if (!empty($tablefooter) || $i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) {
  23273. $extra = $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23274. //$extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23275. }
  23276. else {
  23277. $extra = $table['border_spacing_V']/2;
  23278. }
  23279. }
  23280. else { $extra = $table['max_cell_border_width']['B']/2; }
  23281. if ($j==0 && ((($y + $maxrowheight + $extra ) > ($pagetrigger+0.001)) || (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && ($y + $maxrowheight + $tablefooterrowheight + $extra) > $pagetrigger) && ($i < ($numrows - $this->tableheadernrows))) && ($y0 >0 || $x0 > 0) && !$this->InFooter && $this->autoPageBreak ) { // mPDF 5.0
  23282. if (!$skippage) {
  23283. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23284. $this->y = $y;
  23285. $ya = $this->y;
  23286. $this->TableHeaderFooter($tablefooter,$tablestartpage,$tablestartcolumn,'F',$level); // mPDF 5.0.018
  23287. if ($this->table_rotate) {
  23288. $this->tbrot_h += $this->y - $ya ;
  23289. }
  23290. $tablefooteradj = $this->y - $ya ; // mPDF 5.0.018
  23291. }
  23292. $y -= $y0;
  23293. $returny += $y;
  23294. $oldcolumn = $this->CurrCol;
  23295. if ($this->AcceptPageBreak()) {
  23296. $newpagestarted = true;
  23297. $this->y = $y + $y0;
  23298. // Move down to account for border-spacing or
  23299. // extra half border width in case page breaks in middle
  23300. if($i>0 && !$this->table_rotate && $level==1 && !$this->ColActive) {
  23301. if ($table['borders_separate']) {
  23302. $adv = $table['border_spacing_V']/2;
  23303. // mPDF 5.1.008 If table footer
  23304. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23305. $adv += ($table['padding']['B'] + $table['border_details']['B']['w']);
  23306. }
  23307. }
  23308. else {
  23309. $maxbwtop = 0; // mPDF 5.1.008
  23310. $maxbwbottom = 0;
  23311. // mPDF 5.1.008 (for() moved inside if() for better performance)
  23312. if (!$this->simpleTables){
  23313. if (!empty($tablefooter)) { $maxbwbottom = $table['max_cell_border_width']['B']; }
  23314. else {
  23315. $brow = $i-1;
  23316. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23317. if (isset($cells[$brow][$ctj]) && $cells[$brow][$ctj]) {
  23318. if ($this->packTableData) {
  23319. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$brow][$ctj]['borderbin']);
  23320. }
  23321. else {
  23322. $bb = $cells[$brow][$ctj]['border_details']['B']['w'];
  23323. }
  23324. $maxbwbottom = max($maxbwbottom , $bb);
  23325. }
  23326. }
  23327. }
  23328. // mPDF 5.1.008
  23329. if (!empty($tableheader)) { $maxbwtop = $table['max_cell_border_width']['T']; }
  23330. else {
  23331. $trow = $i-1;
  23332. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23333. if (isset($cells[$trow][$ctj]) && $cells[$trow][$ctj]) {
  23334. if ($this->packTableData) {
  23335. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$trow][$ctj]['borderbin']);
  23336. }
  23337. else {
  23338. $bt = $cells[$trow][$ctj]['border_details']['T']['w'];
  23339. }
  23340. $maxbwtop = max($maxbwtop , $bt);
  23341. }
  23342. }
  23343. }
  23344. }
  23345. else if ($this->simpleTables){
  23346. $maxbwtop = $table['simple']['border_details']['T']['w']; // mPDF 5.1.008
  23347. $maxbwbottom = $table['simple']['border_details']['B']['w'];
  23348. }
  23349. $adv = $maxbwbottom /2;
  23350. }
  23351. $this->y += $adv;
  23352. }
  23353. // Rotated table split over pages - needs this->y for borders/backgrounds
  23354. if($i>0 && $this->table_rotate && $level==1) {
  23355. $this->y = $y0 + $this->tbrot_w;
  23356. }
  23357. if ($this->tableClipPath ) { $this->_out("Q"); }
  23358. // mPDF 5.1.008
  23359. $bx = $x0;
  23360. $by = $y0;
  23361. if ($table['borders_separate']) {
  23362. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  23363. if ($tablestartpageno != $this->page) { // IF already broken across a previous pagebreak
  23364. $by += $table['max_cell_border_width']['T']/2;
  23365. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  23366. }
  23367. else {
  23368. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  23369. }
  23370. }
  23371. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  23372. $by -= $tableheaderadj;
  23373. $bh = $this->y - $by + $tablefooteradj;
  23374. if (!$table['borders_separate']) { $bh -= $adv ; }
  23375. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  23376. if (!$this->ColActive) { // mPDF 5.1.008
  23377. // mPDF 5.1.008
  23378. if (isset($table['bgcolor'][-1])) {
  23379. $color = $this->ConvertColor($table['bgcolor'][-1]);
  23380. if ($color) {
  23381. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  23382. $bw = $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
  23383. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  23384. }
  23385. }
  23386. // mPDF 5.0.018
  23387. /*-- BACKGROUNDS --*/
  23388. if (isset($table['gradient'])) {
  23389. $g = $this->parseBackgroundGradient($table['gradient']);
  23390. if ($g) {
  23391. // mPDF 5.0.020
  23392. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  23393. }
  23394. }
  23395. if (isset($table['background-image'])) {
  23396. // mPDF 5.0.023
  23397. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  23398. $g = $this->parseMozGradient( $table['background-image']['gradient'] );
  23399. if ($g) {
  23400. // mPDF 5.0.020
  23401. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  23402. }
  23403. }
  23404. else {
  23405. $image_id = $table['background-image']['image_id'];
  23406. $orig_w = $table['background-image']['orig_w'];
  23407. $orig_h = $table['background-image']['orig_h'];
  23408. $x_pos = $table['background-image']['x_pos'];
  23409. $y_pos = $table['background-image']['y_pos'];
  23410. $x_repeat = $table['background-image']['x_repeat'];
  23411. $y_repeat = $table['background-image']['y_repeat'];
  23412. $resize = $table['background-image']['resize'];
  23413. $opacity = $table['background-image']['opacity'];
  23414. // mPDF 5.1.008
  23415. $this->tableBackgrounds[$level*9+2][] = array('x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, '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);
  23416. }
  23417. }
  23418. /*-- END BACKGROUNDS --*/
  23419. }
  23420. // mPDF 5.1.008
  23421. // $this->AcceptPageBreak() has moved tablebuffer to $this->pages content
  23422. if ($this->tableBackgrounds) {
  23423. $s = $this->PrintTableBackgrounds();
  23424. if ($this->bufferoutput) {
  23425. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  23426. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer );
  23427. }
  23428. else {
  23429. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  23430. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]);
  23431. }
  23432. $this->tableBackgrounds = array();
  23433. }
  23434. $this->AddPage($this->CurOrientation);
  23435. $this->_out('___TABLE___BACKGROUNDS'.date('jY')); // mPDF 5.0.018
  23436. if ($this->tableClipPath ) { $this->_out($this->tableClipPath); }
  23437. // Added to correct for OddEven Margins
  23438. $x=$x +$this->MarginCorrection;
  23439. $x0=$x0 +$this->MarginCorrection;
  23440. // Move down to account for half of top border-spacing or
  23441. // extra half border width in case page was broken in middle
  23442. if($i>0 && !$this->table_rotate && $level==1 && !$this->usetableheader) {
  23443. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; }
  23444. else {
  23445. $maxbwtop = 0;
  23446. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23447. if (isset($cells[$i][$ctj]) && $cells[$i][$ctj]) {
  23448. if (!$this->simpleTables){
  23449. if ($this->packTableData) {
  23450. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$i][$ctj]['borderbin']);
  23451. }
  23452. else {
  23453. $bt = $cells[$i][$ctj]['border_details']['T']['w'];
  23454. }
  23455. $maxbwtop = max($maxbwtop, $bt);
  23456. }
  23457. else if ($this->simpleTables){
  23458. $maxbwtop = max($maxbwtop, $table['simple']['border_details']['T']['w']);
  23459. }
  23460. }
  23461. }
  23462. $adv = $maxbwtop /2;
  23463. }
  23464. $this->y += $adv;
  23465. }
  23466. if ($this->table_rotate) {
  23467. $this->tbrot_x0 = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'];
  23468. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  23469. else { $this->tbrot_h = $table['margin']['T'] + $table['max_cell_border_width']['T'] ; }
  23470. $this->tbrot_y0 = $this->y;
  23471. $pagetrigger = $y0 - $tableheaderadj + ($this->blk[$this->blklvl]['inner_width']); // mPDF 5.1.008
  23472. }
  23473. else {
  23474. $pagetrigger = $this->PageBreakTrigger;
  23475. }
  23476. if ($this->kwt_saved && $level==1) {
  23477. $this->kwt_moved = true;
  23478. }
  23479. // Disable Table header repeat if Keep Block together
  23480. if ($this->usetableheader && !$this->keep_block_together && !empty($tableheader)) {
  23481. $ya = $this->y;
  23482. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level); // mPDF 5.0.018
  23483. if ($this->table_rotate) {
  23484. $this->tbrot_h = $this->y - $ya ;
  23485. }
  23486. $tableheaderadj = $this->y - $ya ; // mPDF 5.0.018
  23487. }
  23488. else if ($i==0 && !$this->keep_block_together && !$this->table_rotate && $level==1 && !$this->ColActive) {
  23489. // Advance down page
  23490. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  23491. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  23492. if ($adv) {
  23493. if ($this->table_rotate) {
  23494. $this->y += ($adv);
  23495. }
  23496. else {
  23497. $this->DivLn($adv,$this->blklvl,true);
  23498. }
  23499. }
  23500. }
  23501. $outerfilled = 0;
  23502. $y = $y0 = $this->y;
  23503. }
  23504. /*-- COLUMNS --*/
  23505. // COLS
  23506. // COLUMN CHANGE
  23507. if ($this->CurrCol != $oldcolumn) {
  23508. // Added to correct for Columns
  23509. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  23510. $x0 += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  23511. if ($this->CurrCol == 0) { // just added a page - possibly with tableheader
  23512. $y0 = $this->y; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  23513. }
  23514. else {
  23515. $y0 = $this->y0; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  23516. }
  23517. $y = $y0;
  23518. $outerfilled = 0;
  23519. if ($this->CurrCol != 0 && ($this->keepColumns && $this->ColActive) && !empty($tableheader) && $i > 0 ) {
  23520. $this->x = $x;
  23521. $this->y = $y;
  23522. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level); // mPDF 5.0.018
  23523. $y0 = $y=$this->y;
  23524. }
  23525. }
  23526. /*-- END COLUMNS --*/
  23527. }
  23528. $skippage = true;
  23529. }
  23530. $this->x = $x;
  23531. $this->y = $y;
  23532. if ($this->kwt_saved && $level==1) {
  23533. $this->printkwtbuffer();
  23534. $x0 = $x = $this->x;
  23535. $y0 = $y = $this->y;
  23536. $this->kwt_moved = false;
  23537. $this->kwt_saved = false;
  23538. }
  23539. // Set the Page & Column where table actually starts
  23540. if ($i==0 && $j==0 && $level==1) {
  23541. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  23542. $tablestartpage = 'EVEN';
  23543. }
  23544. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  23545. $tablestartpage = 'ODD';
  23546. }
  23547. else { $tablestartpage = ''; }
  23548. $tablestartpageno = $this->page; // mPDF 5.1.008
  23549. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; } // *COLUMNS*
  23550. }
  23551. //ALIGN
  23552. $align = $cell['a'];
  23553. /*-- COLUMNS --*/
  23554. // If outside columns, this is done in PaintDivBB
  23555. if ($this->ColActive) {
  23556. //OUTER FILL BGCOLOR of DIVS
  23557. if ($this->blklvl > 0 && ($j==0) && !$this->table_rotate && $level==1) {
  23558. $firstblockfill = $this->GetFirstBlockFill();
  23559. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  23560. $divh = $maxrowheight;
  23561. // Last row
  23562. if (isset($cell['rowspan']) && (($i == $numrows-1 && $cell['rowspan']<2) || ($cell['rowspan']>1 && ($i + $cell['rowspan']-1) == $numrows-1))) {
  23563. if ($table['borders_separate']) {
  23564. $adv = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23565. }
  23566. else {
  23567. $adv = $table['margin']['B'] + $table['max_cell_border_width']['B']/2;
  23568. }
  23569. $divh += $adv; //last row: fill bottom half of bottom border (y advanced at end)
  23570. }
  23571. if (($this->y + $divh) > $outerfilled ) { // if not already painted by previous rowspan
  23572. $bak_x = $this->x;
  23573. $bak_y = $this->y;
  23574. if ($outerfilled > $this->y) {
  23575. $divh = ($this->y + $divh) - $outerfilled;
  23576. $this->y = $outerfilled;
  23577. }
  23578. $this->DivLn($divh,-3,false);
  23579. $outerfilled = $this->y + $divh;
  23580. // Reset current block fill
  23581. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  23582. if ($bcor ) $this->SetFColor($bcor); // mPDF 5.0.020
  23583. $this->x = $bak_x;
  23584. $this->y = $bak_y;
  23585. }
  23586. }
  23587. }
  23588. }
  23589. //TABLE BACKGROUND FILL BGCOLOR - for cellSpacing
  23590. // mPDF 5.1.008
  23591. if ($this->ColActive) { // mPDF 5.1.008
  23592. if ($table['borders_separate']) {
  23593. $fill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  23594. if ($fill) {
  23595. $color = $this->ConvertColor($fill);
  23596. if ($color) { // mPDF 5.0.017
  23597. $xadj = ($table['border_spacing_H']/2);
  23598. $yadj = ($table['border_spacing_V']/2);
  23599. $wadj = $table['border_spacing_H'];
  23600. $hadj = $table['border_spacing_V'];
  23601. if ($i == 0) { // Top
  23602. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  23603. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  23604. }
  23605. if ($j == 0) { // Left
  23606. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  23607. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  23608. }
  23609. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows)) { // Bottom
  23610. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  23611. }
  23612. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right
  23613. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  23614. }
  23615. $this->SetFColor($color); // mPDF 5.0.020
  23616. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  23617. }
  23618. }
  23619. }
  23620. }
  23621. /*-- END COLUMNS --*/
  23622. // TABLE BORDER - if separate
  23623. if ($table['borders_separate'] && $table['border']) {
  23624. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  23625. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  23626. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  23627. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  23628. $tbx = $x;
  23629. $tby = $y;
  23630. $tbw = $w;
  23631. $tbh = $h;
  23632. $tab_bord = 0;
  23633. $corner = '';
  23634. if ($i == 0) { // Top
  23635. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  23636. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  23637. $this->setBorder($tab_bord , _BORDER_TOP);
  23638. $corner .= 'T';
  23639. }
  23640. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) { // Bottom
  23641. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  23642. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  23643. $corner .= 'B';
  23644. }
  23645. if ($j == 0) { // Left
  23646. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  23647. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  23648. $this->setBorder($tab_bord , _BORDER_LEFT);
  23649. $corner .= 'L';
  23650. }
  23651. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right
  23652. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  23653. $this->setBorder($tab_bord , _BORDER_RIGHT);
  23654. $corner .= 'R';
  23655. }
  23656. $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'] );
  23657. }
  23658. if ($table['empty_cells']!='hide' || !empty($cell['textbuffer']) || (isset($cell['nestedcontent']) && $cell['nestedcontent']) || !$table['borders_separate'] ) { $paintcell = true; }
  23659. else { $paintcell = false; }
  23660. //Set Borders
  23661. $bord = 0;
  23662. $bord_det = array();
  23663. if (!$this->simpleTables){
  23664. if ($this->packTableData) {
  23665. if ($cell['borderbin']) {
  23666. $c = $this->_unpackCellBorder($cell['borderbin']);
  23667. $bord = $c['border'];
  23668. $bord_det = $c['border_details'];
  23669. }
  23670. }
  23671. else if ($cell['border']) {
  23672. $bord = $cell['border'];
  23673. $bord_det = $cell['border_details'];
  23674. }
  23675. }
  23676. else if ($this->simpleTables){
  23677. if ($table['simple']['border']) {
  23678. $bord = $table['simple']['border'];
  23679. $bord_det = $table['simple']['border_details'];
  23680. }
  23681. }
  23682. //TABLE ROW OR CELL FILL BGCOLOR
  23683. // mPDF 5.1.008
  23684. $fill = 0;
  23685. if (isset($cell['bgcolor']) && $cell['bgcolor'] && $cell['bgcolor']!='transparent') {
  23686. $fill = $cell['bgcolor'];
  23687. $leveladj = 6;
  23688. }
  23689. else if (isset($table['bgcolor'][$i]) && $table['bgcolor'][$i] && $table['bgcolor'][$i]!='transparent') { // Row color
  23690. $fill = $table['bgcolor'][$i];
  23691. $leveladj = 3;
  23692. }
  23693. // $fill = isset($cell['bgcolor']) ? $cell['bgcolor'] : 0;
  23694. if ($fill && $paintcell) {
  23695. $color = $this->ConvertColor($fill);
  23696. if ($color) { // mPDF 5.0.017
  23697. if ($table['borders_separate']) {
  23698. // mPDF 5.1.008
  23699. if ($this->ColActive) { // mPDF 5.1.008
  23700. $this->SetFColor($color); // mPDF 5.0.020
  23701. $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');
  23702. }
  23703. else {
  23704. $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);
  23705. }
  23706. }
  23707. else {
  23708. // mPDF 5.1.008
  23709. if ($this->ColActive) { // mPDF 5.1.008
  23710. $this->SetFColor($color); // mPDF 5.0.020
  23711. $this->Rect($x, $y, $w, $h, 'F');
  23712. }
  23713. else {
  23714. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  23715. }
  23716. }
  23717. }
  23718. }
  23719. /*-- BACKGROUNDS --*/
  23720. if (isset($cell['gradient']) && $cell['gradient'] && $paintcell){
  23721. $g = $this->parseBackgroundGradient($cell['gradient']);
  23722. if ($g) {
  23723. if ($table['borders_separate']) {
  23724. $px = $x+ ($table['border_spacing_H']/2);
  23725. $py = $y+ ($table['border_spacing_V']/2);
  23726. $pw = $w- $table['border_spacing_H'];
  23727. $ph = $h- $table['border_spacing_V'];
  23728. }
  23729. else {
  23730. $px = $x;
  23731. $py = $y;
  23732. $pw = $w;
  23733. $ph = $h;
  23734. }
  23735. if ($this->ColActive) { // mPDF 5.1.008
  23736. $this->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  23737. }
  23738. else {
  23739. // mPDF 5.1.008
  23740. $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'=>'');
  23741. }
  23742. }
  23743. }
  23744. if (isset($cell['background-image']) && $paintcell) {
  23745. // mPDF 5.0.023
  23746. if ($cell['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $cell['background-image']['gradient'] )) {
  23747. $g = $this->parseMozGradient( $cell['background-image']['gradient'] );
  23748. if ($g) {
  23749. if ($table['borders_separate']) {
  23750. $px = $x+ ($table['border_spacing_H']/2);
  23751. $py = $y+ ($table['border_spacing_V']/2);
  23752. $pw = $w- $table['border_spacing_H'];
  23753. $ph = $h- $table['border_spacing_V'];
  23754. }
  23755. else {
  23756. $px = $x;
  23757. $py = $y;
  23758. $pw = $w;
  23759. $ph = $h;
  23760. }
  23761. if ($this->ColActive) { // mPDF 5.1.008
  23762. $this->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  23763. }
  23764. else {
  23765. // mPDF 5.1.008
  23766. $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'=>'');
  23767. }
  23768. }
  23769. }
  23770. else if ($cell['background-image']['image_id']) { // Background pattern
  23771. $n = count($this->patterns)+1;
  23772. if ($table['borders_separate']) {
  23773. $px = $x+ ($table['border_spacing_H']/2);
  23774. $py = $y+ ($table['border_spacing_V']/2);
  23775. $pw = $w- $table['border_spacing_H'];
  23776. $ph = $h- $table['border_spacing_V'];
  23777. }
  23778. else {
  23779. $px = $x;
  23780. $py = $y;
  23781. $pw = $w;
  23782. $ph = $h;
  23783. }
  23784. if ($this->ColActive) { // mPDF 5.1.008
  23785. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($cell['background-image']['orig_w'], $cell['background-image']['orig_h'], $pw, $ph, $cell['background-image']['resize'], $cell['background-image']['x_repeat'], $cell['background-image']['y_repeat']);
  23786. $this->patterns[$n] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'pgh'=>$this->h, 'image_id'=>$cell['background-image']['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$cell['background-image']['x_pos'] , 'y_pos'=>$cell['background-image']['y_pos'] , 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat);
  23787. if ($cell['background-image']['opacity']>0 && $cell['background-image']['opacity']<1) { $opac = $this->SetAlpha($cell['background-image']['opacity'],'Normal',true); }
  23788. else { $opac = ''; }
  23789. $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));
  23790. }
  23791. else {
  23792. // mPDF 5.1.008
  23793. $image_id = $cell['background-image']['image_id'];
  23794. $orig_w = $cell['background-image']['orig_w'];
  23795. $orig_h = $cell['background-image']['orig_h'];
  23796. $x_pos = $cell['background-image']['x_pos'];
  23797. $y_pos = $cell['background-image']['y_pos'];
  23798. $x_repeat = $cell['background-image']['x_repeat'];
  23799. $y_repeat = $cell['background-image']['y_repeat'];
  23800. $resize = $cell['background-image']['resize'];
  23801. $opacity = $cell['background-image']['opacity'];
  23802. $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);
  23803. }
  23804. }
  23805. }
  23806. /*-- END BACKGROUNDS --*/
  23807. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  23808. else { $ccolsp = 1; }
  23809. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  23810. else { $crowsp = 1; }
  23811. // but still need to do this for repeated headers...
  23812. if (!$table['borders_separate'] && $this->tabletheadjustfinished && !$this->simpleTables){
  23813. if (isset($table['topntail']) && $table['topntail']) {
  23814. $bord_det['T'] = $this->border_details($table['topntail']);
  23815. $bord_det['T']['w'] /= $this->shrin_k;
  23816. $this->setBorder($bord, _BORDER_TOP);
  23817. }
  23818. if (isset($table['thead-underline']) && $table['thead-underline']) {
  23819. $bord_det['T'] = $this->border_details($table['thead-underline']);
  23820. $bord_det['T']['w'] /= $this->shrin_k;
  23821. $this->setBorder($bord, _BORDER_TOP);
  23822. }
  23823. }
  23824. //Get info of first row ==>> table header
  23825. //Use > 1 row if THEAD
  23826. if ($this->usetableheader && ($i == 0 || (isset($table['is_thead'][$i]) && $table['is_thead'][$i])) && $level==1) {
  23827. $tableheader[$i][0]['trbackground-images'] = $table['trbackground-images'][$i]; // mPDF 5.0.018
  23828. $tableheader[$i][0]['trgradients'] = $table['trgradients'][$i]; // mPDF 5.0.018
  23829. $tableheader[$i][0]['trbgcolor'] = $table['bgcolor'][$i]; // mPDF 5.1.008
  23830. $tableheader[$i][$j]['x'] = $x;
  23831. $tableheader[$i][$j]['y'] = $y;
  23832. $tableheader[$i][$j]['h'] = $h;
  23833. $tableheader[$i][$j]['w'] = $w;
  23834. $tableheader[$i][$j]['text'] = $cell['text'];
  23835. if (isset($cell['textbuffer'])) { $tableheader[$i][$j]['textbuffer'] = $cell['textbuffer']; }
  23836. else { $tableheader[$i][$j]['textbuffer'] = ''; }
  23837. $tableheader[$i][$j]['a'] = $cell['a'];
  23838. $tableheader[$i][$j]['R'] = $cell['R'];
  23839. $tableheader[$i][$j]['va'] = $cell['va'];
  23840. $tableheader[$i][$j]['mih'] = $cell['mih'];
  23841. $tableheader[$i][$j]['gradient'] = $cell['gradient']; // *BACKGROUNDS*
  23842. $tableheader[$i][$j]['background-image'] = $cell['background-image']; // *BACKGROUNDS*
  23843. $tableheader[$i][$j]['rowspan'] = $cell['rowspan'];
  23844. $tableheader[$i][$j]['colspan'] = $cell['colspan'];
  23845. // $tableheader[$i][$j]['bgcolor'] = $fill; // mPDF 5.1.008
  23846. $tableheader[$i][$j]['bgcolor'] = $cell['bgcolor']; // mPDF 5.1.008
  23847. if (!$this->simpleTables){
  23848. $tableheader[$i][$j]['border'] = $bord;
  23849. $tableheader[$i][$j]['border_details'] = $bord_det;
  23850. }
  23851. else if ($this->simpleTables){
  23852. $tableheader[$i][$j]['border'] = $table['simple']['border'];
  23853. $tableheader[$i][$j]['border_details'] = $table['simple']['border_details'];
  23854. }
  23855. $tableheader[$i][$j]['padding'] = $cell['padding'];
  23856. }
  23857. // CELL BORDER
  23858. if ($bord || $bord_det) {
  23859. if ($table['borders_separate'] && $paintcell) {
  23860. $this->_tableRect($x + ($table['border_spacing_H']/2)+($bord_det['L']['w'] /2), $y+ ($table['border_spacing_V']/2)+($bord_det['T']['w'] /2), $w-$table['border_spacing_H']-($bord_det['L']['w'] /2)-($bord_det['R']['w'] /2), $h- $table['border_spacing_V']-($bord_det['T']['w'] /2)-($bord_det['B']['w']/2), $bord, $bord_det, false, $table['borders_separate']);
  23861. }
  23862. else if (!$table['borders_separate']) {
  23863. $this->_tableRect($x, $y, $w, $h, $bord, $bord_det, true, $table['borders_separate']); // true causes buffer
  23864. }
  23865. }
  23866. //VERTICAL ALIGN
  23867. if ($cell['R'] && INTVAL($cell['R']) > 0 && INTVAL($cell['R']) < 90 && isset($cell['va']) && $cell['va']!='B') { $cell['va']='B';}
  23868. if (!isset($cell['va']) || $cell['va']=='M') $this->y += ($h-$cell['mih'])/2;
  23869. elseif (isset($cell['va']) && $cell['va']=='B') $this->y += $h-$cell['mih'];
  23870. // NESTED CONTENT
  23871. // TEXT (and nested tables)
  23872. $this->divalign=$align;
  23873. $this->divwidth=$w;
  23874. if (!empty($cell['textbuffer'])) {
  23875. $opy = $this->y;
  23876. // mPDF ITERATION
  23877. if ($this->iterationCounter) {
  23878. foreach($cell['text'] AS $k=>$t) {
  23879. if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t, $m)) {
  23880. $vname = '__'.$m[1].'_';
  23881. if (!isset($this->$vname)) { $this->$vname = 1; }
  23882. else { $this->$vname++; }
  23883. $cell['text'][$k] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $cell['text'][$k]);
  23884. $cell['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $cell['textbuffer'][$k][0]);
  23885. }
  23886. }
  23887. }
  23888. if ($cell['R']) {
  23889. $cellPtSize = $cell['textbuffer'][0][11] / $this->shrin_k;
  23890. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  23891. $cellFontHeight = ($cellPtSize/$this->k);
  23892. $opx = $this->x;
  23893. $angle = INTVAL($cell['R']);
  23894. // Only allow 45 to 89 degrees (when bottom-aligned) or exactly 90 or -90
  23895. if ($angle > 90) { $angle = 90; }
  23896. else if ($angle > 0 && $angle <45) { $angle = 45; }
  23897. else if ($angle < 0) { $angle = -90; }
  23898. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  23899. if (isset($cell['a']) && $cell['a']=='R') {
  23900. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($cell['padding']['R'] + ($table['border_spacing_H']/2));
  23901. }
  23902. else if (!isset($cell['a']) || $cell['a']=='C') {
  23903. $this->x += ($w/2) + ($offset);
  23904. }
  23905. else {
  23906. $this->x += ($offset) + ($cellFontHeight/3)+($cell['padding']['L'] +($table['border_spacing_H']/2));
  23907. }
  23908. $str = trim(implode(' ',$cell['text']));
  23909. if (!isset($cell['va']) || $cell['va']=='M') {
  23910. $this->y -= ($h-$cell['mih'])/2; //Undo what was added earlier VERTICAL ALIGN
  23911. if ($angle > 0) { $this->y += (($h-$cell['mih'])/2) + $cell['padding']['T'] + ($cell['mih']-($cell['padding']['T'] + $cell['padding']['B'])); }
  23912. else if ($angle < 0) { $this->y += (($h-$cell['mih'])/2)+ ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  23913. }
  23914. elseif (isset($cell['va']) && $cell['va']=='B') {
  23915. $this->y -= $h-$cell['mih']; //Undo what was added earlier VERTICAL ALIGN
  23916. if ($angle > 0) { $this->y += $h-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  23917. else if ($angle < 0) { $this->y += $h-$cell['mih'] + ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  23918. }
  23919. elseif (isset($cell['va']) && $cell['va']=='T') {
  23920. if ($angle > 0) { $this->y += $cell['mih']-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  23921. else if ($angle < 0) { $this->y += ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  23922. }
  23923. $this->Rotate($angle,$this->x,$this->y);
  23924. $s_fs = $this->FontSizePt;
  23925. $s_f = $this->FontFamily;
  23926. $s_st = $this->FontStyle;
  23927. $this->SetFont($cell['textbuffer'][0][4],$cell['textbuffer'][0][2],$cellPtSize,true,true);
  23928. $this->Text($this->x,$this->y,$str);
  23929. $this->Rotate(0);
  23930. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  23931. $this->x = $opx;
  23932. }
  23933. else {
  23934. if (!$this->simpleTables){
  23935. if ($table['borders_separate']) {
  23936. $xadj = $bord_det['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2);
  23937. $wadj = $bord_det['L']['w'] + $bord_det['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  23938. $yadj = $bord_det['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  23939. }
  23940. else {
  23941. $xadj = $bord_det['L']['w']/2 + $cell['padding']['L'];
  23942. $wadj = ($bord_det['L']['w'] + $bord_det['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R'];
  23943. $yadj = $bord_det['T']['w']/2 + $cell['padding']['T'];
  23944. }
  23945. }
  23946. else if ($this->simpleTables){
  23947. if ($table['borders_separate']) { // NB twice border width
  23948. $xadj = $table['simple']['border_details']['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2);
  23949. $wadj = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  23950. $yadj = $table['simple']['border_details']['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  23951. }
  23952. else {
  23953. $xadj = $table['simple']['border_details']['L']['w']/2 + $cell['padding']['L'];
  23954. $wadj = ($table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R'];
  23955. $yadj = $table['simple']['border_details']['T']['w']/2 + $cell['padding']['T'];
  23956. }
  23957. }
  23958. $this->divwidth=$w-$wadj;
  23959. if ($this->divwidth == 0) { $this->divwidth = 0.0001; }
  23960. $this->x += $xadj;
  23961. $this->y += $yadj;
  23962. $this->printbuffer($cell['textbuffer'],'',true);
  23963. }
  23964. $this->y = $opy;
  23965. }
  23966. unset($cell );
  23967. //Reset values
  23968. $this->Reset();
  23969. // mPDF 5.0.018
  23970. /*-- BACKGROUNDS --*/
  23971. if (!$this->ColActive) { // mPDF 5.1.008
  23972. if (isset($table['trgradients'][$i]) && ($j==0 || $table['borders_separate'])) {
  23973. $g = $this->parseBackgroundGradient($table['trgradients'][$i]);
  23974. if ($g) {
  23975. $gx = $x0;
  23976. $gy = $y;
  23977. $gh = $h;
  23978. $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
  23979. if ($table['borders_separate']) {
  23980. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  23981. $s = '';
  23982. $clx = $x+ ($table['border_spacing_H']/2);
  23983. $cly = $y+ ($table['border_spacing_V']/2);
  23984. $clw = $w- $table['border_spacing_H'];
  23985. $clh = $h- $table['border_spacing_V'];
  23986. // Set clipping path
  23987. $s = ' q 0 w '; // Line width=0
  23988. $s .= sprintf('%.3f %.3f m ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // start point TL before the arc
  23989. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BL
  23990. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BR
  23991. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly))*$this->k); // line to TR
  23992. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // line to TL
  23993. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  23994. // mPDF 5.0.020 / mPDF 5.0.022 // mPDF 5.1.008
  23995. $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);
  23996. }
  23997. else {
  23998. // mPDF 5.0.020 // mPDF 5.1.008
  23999. $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'=>'');
  24000. }
  24001. }
  24002. }
  24003. if (isset($table['trbackground-images'][$i]) && ($j==0 || $table['borders_separate'])) {
  24004. // mPDF 5.0.023
  24005. if ($table['trbackground-images'][$i]['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['trbackground-images'][$i]['gradient'] )) {
  24006. $g = $this->parseMozGradient( $table['trbackground-images'][$i]['gradient'] );
  24007. if ($g) {
  24008. $gx = $x0;
  24009. $gy = $y;
  24010. $gh = $h;
  24011. $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
  24012. if ($table['borders_separate']) {
  24013. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24014. $s = '';
  24015. $clx = $x+ ($table['border_spacing_H']/2);
  24016. $cly = $y+ ($table['border_spacing_V']/2);
  24017. $clw = $w- $table['border_spacing_H'];
  24018. $clh = $h- $table['border_spacing_V'];
  24019. // Set clipping path
  24020. $s = ' q 0 w '; // Line width=0
  24021. $s .= sprintf('%.3f %.3f m ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // start point TL before the arc
  24022. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BL
  24023. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BR
  24024. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly))*$this->k); // line to TR
  24025. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // line to TL
  24026. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24027. // mPDF 5.0.020 / mPDF 5.0.022 // mPDF 5.1.008
  24028. $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);
  24029. }
  24030. else {
  24031. // mPDF 5.0.020 // mPDF 5.1.008
  24032. $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'=>'');
  24033. }
  24034. }
  24035. }
  24036. else {
  24037. $image_id = $table['trbackground-images'][$i]['image_id'];
  24038. $orig_w = $table['trbackground-images'][$i]['orig_w'];
  24039. $orig_h = $table['trbackground-images'][$i]['orig_h'];
  24040. $x_pos = $table['trbackground-images'][$i]['x_pos'];
  24041. $y_pos = $table['trbackground-images'][$i]['y_pos'];
  24042. $x_repeat = $table['trbackground-images'][$i]['x_repeat'];
  24043. $y_repeat = $table['trbackground-images'][$i]['y_repeat'];
  24044. $resize = $table['trbackground-images'][$i]['resize'];
  24045. $opacity = $table['trbackground-images'][$i]['opacity'];
  24046. $clippath = '';
  24047. $gx = $x0;
  24048. $gy = $y;
  24049. $gh = $h;
  24050. $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
  24051. if ($table['borders_separate']) {
  24052. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24053. $s = '';
  24054. $clx = $x + ($table['border_spacing_H']/2);
  24055. $cly = $y + ($table['border_spacing_V']/2);
  24056. $clw = $w - $table['border_spacing_H'];
  24057. $clh = $h - $table['border_spacing_V'];
  24058. // Set clipping path
  24059. $s = ' q 0 w '; // Line width=0
  24060. $s .= sprintf('%.3f %.3f m ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // start point TL
  24061. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BL
  24062. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly+$clh))*$this->k); // line to BR
  24063. $s .= sprintf('%.3f %.3f l ', ($clx+$clw)*$this->k, ($this->h-($cly))*$this->k); // line to TR
  24064. $s .= sprintf('%.3f %.3f l ', ($clx)*$this->k, ($this->h-($cly))*$this->k); // line to TL
  24065. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24066. // mPDF 5.0.022 // mPDF 5.1.008
  24067. $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);
  24068. }
  24069. else { // mPDF 5.1.008
  24070. $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);
  24071. }
  24072. }
  24073. }
  24074. }
  24075. /*-- END BACKGROUNDS --*/
  24076. }//end of (if isset(cells)...)
  24077. }// end of columns
  24078. $newpagestarted = false;
  24079. $this->tabletheadjustfinished = false;
  24080. if ($this->ColActive && $i < $numrows-1 && $level==1) { $this->breakpoints[$this->CurrCol][] = $y + $h; } // *COLUMNS*
  24081. /*-- COLUMNS --*/
  24082. if ($this->ColActive) {
  24083. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24084. }
  24085. /*-- END COLUMNS --*/
  24086. if ($i == $numrows-1) { $this->y = $y + $h; } //last row jump (update this->y position)
  24087. if ($this->table_rotate && $level==1) {
  24088. $this->tbrot_h += $h;
  24089. }
  24090. }// end of rows
  24091. if ($this->progressBar) { $this->UpdateProgressBar(7,70,' '); } // *PROGRESS-BAR*
  24092. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24093. if ($this->tableClipPath ) { $this->_out("Q"); }
  24094. $this->tableClipPath = '';
  24095. // Advance down page by half width of bottom border
  24096. if ($table['borders_separate']) { $this->y += $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; }
  24097. else { $this->y += $table['max_cell_border_width']['B']/2; }
  24098. if ($table['borders_separate'] && $level==1) { $this->tbrot_h += $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; }
  24099. else if ($level==1) { $this->tbrot_h += $table['margin']['B'] + $table['max_cell_border_width']['B']/2; }
  24100. // mPDF 5.1.008
  24101. $bx = $x0;
  24102. $by = $y0;
  24103. if ($table['borders_separate']) {
  24104. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  24105. if ($tablestartpageno != $this->page) { // IF broken across page
  24106. $by += $table['max_cell_border_width']['T']/2;
  24107. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  24108. }
  24109. else {
  24110. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  24111. }
  24112. }
  24113. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  24114. $by -= $tableheaderadj;
  24115. $bh = $this->y - $by;
  24116. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  24117. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24118. if (!$this->ColActive) { // mPDF 5.1.008
  24119. // mPDF 5.1.008
  24120. if (isset($table['bgcolor'][-1])) {
  24121. $color = $this->ConvertColor($table['bgcolor'][-1]);
  24122. if ($color) {
  24123. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  24124. }
  24125. }
  24126. // mPDF 5.0.018
  24127. /*-- BACKGROUNDS --*/
  24128. if (isset($table['gradient'])) {
  24129. $g = $this->parseBackgroundGradient($table['gradient']);
  24130. if ($g) {
  24131. // mPDF 5.0.020
  24132. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24133. }
  24134. }
  24135. if (isset($table['background-image'])) {
  24136. // mPDF 5.0.023
  24137. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  24138. $g = $this->parseMozGradient( $table['background-image']['gradient'] );
  24139. if ($g) {
  24140. // mPDF 5.0.020 // mPDF 5.1.008
  24141. $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>'');
  24142. }
  24143. }
  24144. else {
  24145. $image_id = $table['background-image']['image_id'];
  24146. $orig_w = $table['background-image']['orig_w'];
  24147. $orig_h = $table['background-image']['orig_h'];
  24148. $x_pos = $table['background-image']['x_pos'];
  24149. $y_pos = $table['background-image']['y_pos'];
  24150. $x_repeat = $table['background-image']['x_repeat'];
  24151. $y_repeat = $table['background-image']['y_repeat'];
  24152. $resize = $table['background-image']['resize'];
  24153. $opacity = $table['background-image']['opacity'];
  24154. // mPDF 5.1.008
  24155. $this->tableBackgrounds[$level*9+2][] = array('x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, '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);
  24156. }
  24157. }
  24158. /*-- END BACKGROUNDS --*/
  24159. }
  24160. // mPDF 5.1.008
  24161. if ($this->tableBackgrounds && $level == 1) {
  24162. $s = $this->PrintTableBackgrounds();
  24163. if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  24164. $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->tablebuffer);
  24165. if ($level == 1) { $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->tablebuffer); }
  24166. }
  24167. else if ($this->bufferoutput) {
  24168. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  24169. if ($level == 1) { $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer ); }
  24170. }
  24171. else {
  24172. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  24173. if ($level == 1) { $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]); }
  24174. }
  24175. $this->tableBackgrounds = array();
  24176. }
  24177. // TABLE BOTTOM MARGIN
  24178. if ($table['margin']['B']) {
  24179. if (!$this->table_rotate && $level==1) {
  24180. $this->DivLn($table['margin']['B'],$this->blklvl,true); // collapsible
  24181. }
  24182. else {
  24183. $this->y += ($table['margin']['B']);
  24184. }
  24185. }
  24186. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  24187. }//END OF FUNCTION _tableWrite()
  24188. /////////////////////////END OF TABLE CODE//////////////////////////////////
  24189. /*-- END TABLES --*/
  24190. function _putextgstates() {
  24191. for ($i = 1; $i <= count($this->extgstates); $i++) {
  24192. $this->_newobj();
  24193. $this->extgstates[$i]['n'] = $this->n;
  24194. $this->_out('<</Type /ExtGState');
  24195. foreach ($this->extgstates[$i]['parms'] as $k=>$v)
  24196. $this->_out('/'.$k.' '.$v);
  24197. $this->_out('>>');
  24198. $this->_out('endobj');
  24199. }
  24200. }
  24201. /*-- ENCRYPTION --*/
  24202. function SetProtection($permissions=array(),$user_pass='',$owner_pass=null) {
  24203. $this->encrypted=false;
  24204. if (is_string($permissions) && strlen($permissions)>0) { $permissions = array($permissions); }
  24205. else if (!is_array($permissions)) { return 0; }
  24206. // if (count($permissions)<1 && !$user_pass && !$owner_pass) { return 0; }
  24207. $this->last_rc4_key='';
  24208. $this->padding="\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
  24209. "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  24210. $options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 );
  24211. $protection = 192;
  24212. foreach($permissions as $permission){
  24213. if (!isset($options[$permission]))
  24214. $this->Error('Incorrect permission: '.$permission);
  24215. $protection += $options[$permission];
  24216. }
  24217. if ($owner_pass === null)
  24218. $owner_pass = uniqid(rand());
  24219. $this->encrypted = true;
  24220. $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
  24221. }
  24222. // Compute key depending on object number where the encrypted data is stored
  24223. function _objectkey($n) {
  24224. return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,10);
  24225. }
  24226. /*-- END ENCRYPTION --*/
  24227. /*-- IMPORTS --*/
  24228. // from mPDFI
  24229. function _putimportedobjects() {
  24230. if (is_array($this->parsers) && count($this->parsers) > 0) {
  24231. foreach($this->parsers AS $filename => $p) {
  24232. $this->current_parser =& $this->parsers[$filename];
  24233. if (is_array($this->_obj_stack[$filename])) {
  24234. while($n = key($this->_obj_stack[$filename])) {
  24235. $nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c,$this->_obj_stack[$filename][$n][1]);
  24236. $this->_newobj($this->_obj_stack[$filename][$n][0]);
  24237. if ($nObj[0] == PDF_TYPE_STREAM) {
  24238. $this->pdf_write_value($nObj);
  24239. }
  24240. else {
  24241. $this->pdf_write_value($nObj[1]);
  24242. }
  24243. $this->_out('endobj');
  24244. $this->_obj_stack[$filename][$n] = null; // free memory
  24245. unset($this->_obj_stack[$filename][$n]);
  24246. reset($this->_obj_stack[$filename]);
  24247. }
  24248. }
  24249. }
  24250. }
  24251. }
  24252. function _putformxobjects() {
  24253. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  24254. reset($this->tpls);
  24255. foreach($this->tpls AS $tplidx => $tpl) {
  24256. $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
  24257. $this->_newobj();
  24258. $this->tpls[$tplidx]['n'] = $this->n;
  24259. $this->_out('<<'.$filter.'/Type /XObject');
  24260. $this->_out('/Subtype /Form');
  24261. $this->_out('/FormType 1');
  24262. // Left/Bottom/Right/Top
  24263. $this->_out(sprintf('/BBox [%.2f %.2f %.2f %.2f]',
  24264. $tpl['box']['x']*$this->k,
  24265. $tpl['box']['y']*$this->k,
  24266. ($tpl['box']['x'] + $tpl['box']['w'])*$this->k,
  24267. ($tpl['box']['y'] + $tpl['box']['h'])*$this->k )
  24268. );
  24269. if (isset($tpl['box']))
  24270. $this->_out(sprintf('/Matrix [1 0 0 1 %.5f %.5f]',-$tpl['box']['x']*$this->k, -$tpl['box']['y']*$this->k));
  24271. $this->_out('/Resources ');
  24272. if (isset($tpl['resources'])) {
  24273. $this->current_parser =& $tpl['parser'];
  24274. $this->pdf_write_value($tpl['resources']);
  24275. } else {
  24276. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24277. if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
  24278. $this->_out('/Font <<');
  24279. foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
  24280. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24281. $this->_out('>>');
  24282. }
  24283. if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
  24284. isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
  24285. {
  24286. $this->_out('/XObject <<');
  24287. if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
  24288. foreach($this->_res['tpl'][$tplidx]['images'] as $image)
  24289. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  24290. }
  24291. if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
  24292. foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $itpl)
  24293. $this->_out($this->tplprefix.$i.' '.$itpl['n'].' 0 R');
  24294. }
  24295. $this->_out('>>');
  24296. }
  24297. $this->_out('>>');
  24298. }
  24299. $this->_out('/Length '.strlen($p).' >>');
  24300. $this->_putstream($p);
  24301. $this->_out('endobj');
  24302. }
  24303. }
  24304. /*-- END IMPORTS --*/
  24305. function _putpatterns() {
  24306. for ($i = 1; $i <= count($this->patterns); $i++) {
  24307. $x = $this->patterns[$i]['x'];
  24308. $y = $this->patterns[$i]['y'];
  24309. $w = $this->patterns[$i]['w'];
  24310. $h = $this->patterns[$i]['h'];
  24311. $pgh = $this->patterns[$i]['pgh'];
  24312. $orig_w = $this->patterns[$i]['orig_w'];
  24313. $orig_h = $this->patterns[$i]['orig_h'];
  24314. $image_id = $this->patterns[$i]['image_id'];
  24315. $itype = $this->patterns[$i]['itype']; // mPDF 5.0.039
  24316. if ($this->patterns[$i]['x_repeat']) { $x_repeat = true; }
  24317. else { $x_repeat = false; }
  24318. if ($this->patterns[$i]['y_repeat']) { $y_repeat = true; }
  24319. else { $y_repeat = false; }
  24320. $x_pos = $this->patterns[$i]['x_pos'];
  24321. if (stristr($x_pos ,'%') ) {
  24322. $x_pos += 0;
  24323. $x_pos /= 100;
  24324. $x_pos = ($w * $x_pos) - ($orig_w/$this->k * $x_pos);
  24325. }
  24326. $y_pos = $this->patterns[$i]['y_pos'];
  24327. if (stristr($y_pos ,'%') ) {
  24328. $y_pos += 0;
  24329. $y_pos /= 100;
  24330. $y_pos = ($h * $y_pos) - ($orig_h/$this->k * $y_pos);
  24331. }
  24332. $adj_x = ($x_pos + $x) *$this->k;
  24333. $adj_y = (($pgh - $y_pos - $y)*$this->k) - $orig_h ;
  24334. $img_obj = false;
  24335. // mPDF 5.0.039
  24336. if ($itype == 'svg' || $itype == 'wmf') {
  24337. foreach($this->formobjects AS $fo) {
  24338. if ($fo['i'] == $image_id) {
  24339. $img_obj = $fo['n'];
  24340. $fo_w = $fo['w'];
  24341. $fo_h = -$fo['h'];
  24342. $wmf_x = $fo['x'];
  24343. $wmf_y = $fo['y'];
  24344. break;
  24345. }
  24346. }
  24347. }
  24348. else {
  24349. foreach($this->images AS $img) {
  24350. if ($img['i'] == $image_id) { $img_obj = $img['n']; break; }
  24351. }
  24352. }
  24353. if (!$img_obj ) { echo "Problem: Image object not found for background pattern ".$img['i']; exit; }
  24354. $this->_newobj();
  24355. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24356. // mPDF 5.0.039
  24357. if ($itype == 'svg' || $itype == 'wmf') {
  24358. $this->_out('/XObject <</FO'.$image_id.' '.$img_obj.' 0 R >>'); // mPDF 5.0.039
  24359. // ******* ADD ANY ExtGStates, Shading AND Fonts needed for the FormObject
  24360. // Set in classes/svg array['fo'] = true
  24361. // Required that _putshaders comes before _putpatterns in _putresources
  24362. // This adds any resources associated with any FormObject to every Formobject - overkill but works!
  24363. if (count($this->extgstates)) {
  24364. $this->_out('/ExtGState <<');
  24365. foreach($this->extgstates as $k=>$extgstate)
  24366. if (isset($extgstate['fo']) && $extgstate['fo']) {
  24367. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  24368. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  24369. }
  24370. $this->_out('>>');
  24371. }
  24372. /*-- BACKGROUNDS --*/
  24373. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  24374. $this->_out('/Shading <<');
  24375. foreach ($this->gradients as $id => $grad) {
  24376. if (isset($grad['fo']) && $grad['fo']) {
  24377. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  24378. }
  24379. }
  24380. $this->_out('>>');
  24381. }
  24382. /*-- END BACKGROUNDS --*/
  24383. $this->_out('/Font <<');
  24384. foreach($this->fonts as $font) {
  24385. if (!$font['used'] && $font['type']=='TTF') { continue; }
  24386. if (isset($font['fo']) && $font['fo']) {
  24387. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) {
  24388. foreach($font['n'] AS $k => $fid) {
  24389. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  24390. }
  24391. }
  24392. else {
  24393. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24394. }
  24395. }
  24396. }
  24397. $this->_out('>>');
  24398. }
  24399. else {
  24400. $this->_out('/XObject <</I'.$image_id.' '.$img_obj.' 0 R >>');
  24401. }
  24402. $this->_out('>>');
  24403. $this->_out('endobj');
  24404. $this->_newobj();
  24405. $this->patterns[$i]['n'] = $this->n;
  24406. $this->_out('<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 2');
  24407. $this->_out('/Resources '. ($this->n-1) .' 0 R');
  24408. $this->_out(sprintf('/BBox [0 0 %.3f %.3f]',$orig_w,$orig_h));
  24409. if ($x_repeat) { $this->_out(sprintf('/XStep %.3f',$orig_w)); }
  24410. else { $this->_out(sprintf('/XStep %d',99999)); }
  24411. if ($y_repeat) { $this->_out(sprintf('/YStep %.3f',$orig_h)); }
  24412. else { $this->_out(sprintf('/YStep %d',99999)); }
  24413. // mPDF 5.0.039
  24414. if ($itype == 'svg' || $itype == 'wmf') {
  24415. $this->_out(sprintf('/Matrix [1 0 0 -1 %.3f %.3f]', $adj_x, ($adj_y+$orig_h)));
  24416. $s = sprintf("q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q",($orig_w/$fo_w), (-$orig_h/$fo_h), -($orig_w/$fo_w)*$wmf_x, ($orig_w/$fo_w)*$wmf_y, $image_id);
  24417. }
  24418. else {
  24419. $this->_out(sprintf('/Matrix [1 0 0 1 %.3f %.3f]',$adj_x,$adj_y));
  24420. $s = sprintf("q %.3f 0 0 %.3f 0 0 cm /I%d Do Q",$orig_w,$orig_h,$image_id);
  24421. }
  24422. if ($this->compress) {
  24423. $this->_out('/Filter /FlateDecode');
  24424. $s = gzcompress($s);
  24425. }
  24426. $this->_out('/Length '.strlen($s).'>>');
  24427. $this->_putstream($s);
  24428. $this->_out('endobj');
  24429. }
  24430. }
  24431. /*-- BACKGROUNDS --*/
  24432. function _putshaders() {
  24433. $maxid = count($this->gradients); //index for transparency gradients
  24434. foreach ($this->gradients as $id => $grad) {
  24435. // mPDF 5.0.033
  24436. if (($grad['type'] == 2 || $grad['type'] == 3) && !$grad['is_mask']) {
  24437. $this->_newobj();
  24438. $this->_out('<<');
  24439. $this->_out('/FunctionType 3');
  24440. $this->_out('/Domain [0 1]');
  24441. $fn = array();
  24442. $bd = array();
  24443. $en = array();
  24444. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24445. $fn[] = ($this->n+1+$i).' 0 R';
  24446. $en[] = '0 1';
  24447. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  24448. }
  24449. $this->_out('/Functions ['.implode(' ',$fn).']');
  24450. $this->_out('/Bounds ['.implode(' ',$bd).']');
  24451. $this->_out('/Encode ['.implode(' ',$en).']');
  24452. $this->_out('>>');
  24453. $this->_out('endobj');
  24454. $f1 = $this->n;
  24455. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24456. $this->_newobj();
  24457. $this->_out('<<');
  24458. $this->_out('/FunctionType 2');
  24459. $this->_out('/Domain [0 1]');
  24460. $this->_out('/C0 ['.$grad['stops'][$i]['col'].']');
  24461. $this->_out('/C1 ['.$grad['stops'][$i+1]['col'].']');
  24462. $this->_out('/N 1');
  24463. $this->_out('>>');
  24464. $this->_out('endobj');
  24465. }
  24466. }
  24467. if ($grad['trans']) {
  24468. $this->_newobj();
  24469. $this->_out('<<');
  24470. $this->_out('/FunctionType 3');
  24471. $this->_out('/Domain [0 1]');
  24472. $fn = array();
  24473. $bd = array();
  24474. $en = array();
  24475. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24476. $fn[] = ($this->n+1+$i).' 0 R';
  24477. $en[] = '0 1';
  24478. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  24479. }
  24480. $this->_out('/Functions ['.implode(' ',$fn).']');
  24481. $this->_out('/Bounds ['.implode(' ',$bd).']');
  24482. $this->_out('/Encode ['.implode(' ',$en).']');
  24483. $this->_out('>>');
  24484. $this->_out('endobj');
  24485. $f2 = $this->n;
  24486. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24487. $this->_newobj();
  24488. $this->_out('<<');
  24489. $this->_out('/FunctionType 2');
  24490. $this->_out('/Domain [0 1]');
  24491. $this->_out(sprintf('/C0 [%.3F]', $grad['stops'][$i]['opacity']));
  24492. $this->_out(sprintf('/C1 [%.3F]', $grad['stops'][$i+1]['opacity']));
  24493. $this->_out('/N 1');
  24494. $this->_out('>>');
  24495. $this->_out('endobj');
  24496. }
  24497. }
  24498. // mPDF 5.0.033
  24499. if (!$grad['is_mask']) {
  24500. $this->_newobj();
  24501. $this->_out('<<');
  24502. $this->_out('/ShadingType '.$grad['type']);
  24503. if (isset($grad['colorspace'])) {
  24504. $this->_out('/ColorSpace /Device'.$grad['colorspace']); // Can use CMYK if all C0 and C1 above have 4 values
  24505. } else {
  24506. $this->_out('/ColorSpace /DeviceRGB');
  24507. }
  24508. if ($grad['type'] == 2) {
  24509. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  24510. $this->_out('/Function '.$f1.' 0 R');
  24511. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24512. $this->_out('>>');
  24513. }
  24514. else if ($grad['type'] == 3) {
  24515. //x0, y0, r0, x1, y1, r1
  24516. //at this this time radius of inner circle is 0
  24517. $ir = 0;
  24518. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  24519. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $ir, $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]));
  24520. $this->_out('/Function '.$f1.' 0 R');
  24521. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24522. $this->_out('>>');
  24523. }
  24524. $this->_out('endobj');
  24525. }
  24526. $this->gradients[$id]['id'] = $this->n;
  24527. // set pattern object
  24528. $this->_newobj();
  24529. $out = '<< /Type /Pattern /PatternType 2';
  24530. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  24531. $out .= ' >>';
  24532. $out .= "\n".'endobj';
  24533. $this->_out($out);
  24534. $this->gradients[$id]['pattern'] = $this->n;
  24535. if ($grad['trans']) {
  24536. // luminosity pattern
  24537. $transid = $id + $maxid;
  24538. $this->_newobj();
  24539. $this->_out('<<');
  24540. $this->_out('/ShadingType '.$grad['type']);
  24541. $this->_out('/ColorSpace /DeviceGray');
  24542. if ($grad['type'] == 2) {
  24543. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  24544. $this->_out('/Function '.$f2.' 0 R');
  24545. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24546. $this->_out('>>');
  24547. }
  24548. else if ($grad['type'] == 3) {
  24549. //x0, y0, r0, x1, y1, r1
  24550. //at this this time radius of inner circle is 0
  24551. $ir = 0;
  24552. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  24553. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $ir, $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]));
  24554. $this->_out('/Function '.$f2.' 0 R');
  24555. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24556. $this->_out('>>');
  24557. }
  24558. $this->_out('endobj');
  24559. $this->gradients[$transid]['id'] = $this->n;
  24560. $this->_newobj();
  24561. $this->_out('<< /Type /Pattern /PatternType 2');
  24562. $this->_out('/Shading '.$this->gradients[$transid]['id'].' 0 R');
  24563. $this->_out('>>');
  24564. $this->_out('endobj');
  24565. $this->gradients[$transid]['pattern'] = $this->n;
  24566. $this->_newobj();
  24567. // Need to extend size of viewing box in case of transformations
  24568. $str = 'q /a0 gs /Pattern cs /p'.$transid.' scn -'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).' re f Q'; // mPDF 5.0.027 // mPDF 5.0.039
  24569. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  24570. $p=($this->compress) ? gzcompress($str) : $str;
  24571. $this->_out('<< /Type /XObject /Subtype /Form /FormType 1 '.$filter);
  24572. $this->_out('/Length '.strlen($p));
  24573. $this->_out('/BBox [-'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).']'); // mPDF 5.0.027 // mPDF 5.0.039
  24574. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >>');
  24575. $this->_out('/Resources <<');
  24576. $this->_out('/ExtGState << /a0 << /ca 1 /CA 1 >> >>');
  24577. $this->_out('/Pattern << /p'.$transid.' '.$this->gradients[$transid]['pattern'].' 0 R >>');
  24578. $this->_out('>>');
  24579. $this->_out('>>');
  24580. $this->_putstream($p);
  24581. $this->_out('endobj');
  24582. $this->_newobj();
  24583. $this->_out('<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj');
  24584. $this->_newobj();
  24585. $this->_out('<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj');
  24586. // mPDF 5.0.039
  24587. if ($grad['fo']) { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id, 'fo'=>true); }
  24588. else { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id); }
  24589. }
  24590. }
  24591. }
  24592. /*-- END BACKGROUNDS --*/
  24593. // mPDF 5.0.051
  24594. function _putspotcolors() {
  24595. foreach($this->spotColors as $name=>$color) {
  24596. $this->_newobj();
  24597. $this->_out('[/Separation /'.str_replace(' ','#20',$name));
  24598. $this->_out('/DeviceCMYK <<');
  24599. $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  24600. $this->_out(sprintf('/C1 [%.3F %.3F %.3F %.3F] ',$color['c']/100,$color['m']/100,$color['y']/100,$color['k']/100));
  24601. $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  24602. $this->_out('endobj');
  24603. $this->spotColors[$name]['n']=$this->n;
  24604. }
  24605. }
  24606. function _putresources() {
  24607. $this->_putextgstates();
  24608. $this->_putspotcolors(); // mPDF 5.0.051
  24609. if ($this->progressBar) { $this->UpdateProgressBar(2,'40','Compiling Fonts'); } // *PROGRESS-BAR*
  24610. $this->_putfonts();
  24611. if ($this->progressBar) { $this->UpdateProgressBar(2,'50','Compiling Images'); } // *PROGRESS-BAR*
  24612. $this->_putimages();
  24613. $this->_putformobjects(); // *IMAGES-CORE*
  24614. /*-- IMPORTS --*/
  24615. if ($this->enableImports) {
  24616. $this->_putformxobjects();
  24617. $this->_putimportedobjects();
  24618. }
  24619. /*-- END IMPORTS --*/
  24620. /*-- BACKGROUNDS --*/
  24621. // mPDF 5.0.039 - Changed order - shaders first
  24622. $this->_putshaders();
  24623. $this->_putpatterns();
  24624. /*-- END BACKGROUNDS --*/
  24625. //Resource dictionary
  24626. $this->offsets[2]=strlen($this->buffer);
  24627. $this->_out('2 0 obj');
  24628. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24629. $this->_out('/Font <<');
  24630. foreach($this->fonts as $font) {
  24631. if (!$font['used'] && $font['type']=='TTF') { continue; }
  24632. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) { // mPDF 5.0.03 Added SMP
  24633. foreach($font['n'] AS $k => $fid) {
  24634. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  24635. }
  24636. }
  24637. else {
  24638. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24639. }
  24640. }
  24641. $this->_out('>>');
  24642. // mPDF 5.0.051
  24643. if (count($this->spotColors)) {
  24644. $this->_out('/ColorSpace <<');
  24645. foreach($this->spotColors as $color)
  24646. $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  24647. $this->_out('>>');
  24648. }
  24649. if (count($this->extgstates)) {
  24650. $this->_out('/ExtGState <<');
  24651. foreach($this->extgstates as $k=>$extgstate)
  24652. // mPDF 5.0.020
  24653. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  24654. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  24655. $this->_out('>>');
  24656. }
  24657. /*-- BACKGROUNDS --*/
  24658. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  24659. $this->_out('/Shading <<');
  24660. foreach ($this->gradients as $id => $grad) {
  24661. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  24662. }
  24663. $this->_out('>>');
  24664. /*
  24665. // mPDF 5.0.020 // ??? Not needed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  24666. $this->_out('/Pattern <<');
  24667. foreach ($this->gradients as $id => $grad) {
  24668. $this->_out('/P'.$id.' '.$grad['pattern'].' 0 R');
  24669. }
  24670. $this->_out('>>');
  24671. */
  24672. }
  24673. /*-- END BACKGROUNDS --*/
  24674. if(count($this->images) || count($this->formobjects) || ($this->enableImports && count($this->tpls))) {
  24675. $this->_out('/XObject <<');
  24676. foreach($this->images as $image)
  24677. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  24678. foreach($this->formobjects as $formobject)
  24679. $this->_out('/FO'.$formobject['i'].' '.$formobject['n'].' 0 R');
  24680. /*-- IMPORTS --*/
  24681. if ($this->enableImports && count($this->tpls)) {
  24682. foreach($this->tpls as $tplidx => $tpl) {
  24683. $this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R');
  24684. }
  24685. }
  24686. /*-- END IMPORTS --*/
  24687. $this->_out('>>');
  24688. }
  24689. /*-- BACKGROUNDS --*/
  24690. if (count($this->patterns)) {
  24691. $this->_out('/Pattern <<');
  24692. foreach($this->patterns as $k=>$patterns)
  24693. $this->_out('/P'.$k.' '.$patterns['n'].' 0 R');
  24694. $this->_out('>>');
  24695. }
  24696. /*-- END BACKGROUNDS --*/
  24697. $this->_out('>>');
  24698. $this->_out('endobj'); // end resource dictionary
  24699. $this->_putbookmarks(); // *BOOKMARKS*
  24700. /*-- ENCRYPTION --*/
  24701. if ($this->encrypted) {
  24702. $this->_newobj();
  24703. $this->enc_obj_id = $this->n;
  24704. $this->_out('<<');
  24705. $this->_putencryption();
  24706. $this->_out('>>');
  24707. $this->_out('endobj');
  24708. }
  24709. /*-- END ENCRYPTION --*/
  24710. }
  24711. /*-- ENCRYPTION --*/
  24712. function _putencryption()
  24713. {
  24714. $this->_out('/Filter /Standard');
  24715. $this->_out('/V 1');
  24716. $this->_out('/R 2');
  24717. $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  24718. $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  24719. $this->_out('/P '.$this->Pvalue);
  24720. }
  24721. /*-- END ENCRYPTION --*/
  24722. function _puttrailer()
  24723. {
  24724. $this->_out('/Size '.($this->n+1));
  24725. $this->_out('/Root '.$this->n.' 0 R');
  24726. $this->_out('/Info '.$this->InfoRoot.' 0 R');
  24727. /*-- ENCRYPTION --*/
  24728. if ($this->encrypted) {
  24729. $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  24730. $this->_out('/ID [()()]');
  24731. }
  24732. else {
  24733. /*-- END ENCRYPTION --*/
  24734. $uniqid = md5(time() . $this->buffer);
  24735. $this->_out('/ID [<'.$uniqid.'> <'.$uniqid.'>]');
  24736. /*-- ENCRYPTION --*/
  24737. }
  24738. /*-- END ENCRYPTION --*/
  24739. }
  24740. /*-- ENCRYPTION --*/
  24741. // RC4 is the standard encryption algorithm used in PDF format
  24742. function _RC4($key, $text)
  24743. {
  24744. if ($this->last_rc4_key != $key) {
  24745. $k = str_repeat($key, 256/strlen($key)+1);
  24746. $rc4 = range(0,255);
  24747. $j = 0;
  24748. for ($i=0; $i<256; $i++){
  24749. $t = $rc4[$i];
  24750. $j = ($j + $t + ord($k[$i])) % 256;
  24751. $rc4[$i] = $rc4[$j];
  24752. $rc4[$j] = $t;
  24753. }
  24754. $this->last_rc4_key = $key;
  24755. $this->last_rc4_key_c = $rc4;
  24756. } else {
  24757. $rc4 = $this->last_rc4_key_c;
  24758. }
  24759. $len = strlen($text);
  24760. $a = 0;
  24761. $b = 0;
  24762. $out = '';
  24763. for ($i=0; $i<$len; $i++){
  24764. $a = ($a+1)%256;
  24765. $t= $rc4[$a];
  24766. $b = ($b+$t)%256;
  24767. $rc4[$a] = $rc4[$b];
  24768. $rc4[$b] = $t;
  24769. $k = $rc4[($rc4[$a]+$rc4[$b])%256];
  24770. $out.= $this->chrs[ord($text[$i]) ^ $k];
  24771. }
  24772. return $out;
  24773. }
  24774. // Get MD5 as binary string
  24775. function _md5_16($string)
  24776. {
  24777. return pack('H*',md5($string));
  24778. }
  24779. // Compute O value
  24780. function _Ovalue($user_pass, $owner_pass)
  24781. {
  24782. $tmp = $this->_md5_16($owner_pass);
  24783. $owner_RC4_key = substr($tmp,0,5);
  24784. return $this->_RC4($owner_RC4_key, $user_pass);
  24785. }
  24786. // Compute U value
  24787. function _Uvalue()
  24788. {
  24789. return $this->_RC4($this->encryption_key, $this->padding);
  24790. }
  24791. // Compute encryption key
  24792. function _generateencryptionkey($user_pass, $owner_pass, $protection)
  24793. {
  24794. // Pad passwords
  24795. $user_pass = substr($user_pass.$this->padding,0,32);
  24796. $owner_pass = substr($owner_pass.$this->padding,0,32);
  24797. // Compute O value
  24798. $this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
  24799. // Compute encyption key
  24800. $tmp = $this->_md5_16($user_pass.$this->Ovalue.$this->chrs[$protection]."\xFF\xFF\xFF");
  24801. $this->encryption_key = substr($tmp,0,5);
  24802. // Compute U value
  24803. $this->Uvalue = $this->_Uvalue();
  24804. // Compute P value
  24805. $this->Pvalue = -(($protection^255)+1);
  24806. }
  24807. /*-- END ENCRYPTION --*/
  24808. //=========================================
  24809. /*-- BOOKMARKS --*/
  24810. // FROM class PDF_Bookmark
  24811. function Bookmark($txt,$level=0,$y=0)
  24812. {
  24813. $txt = $this->purify_utf8_text($txt);
  24814. if ($this->text_input_as_HTML) {
  24815. $txt = $this->all_entities_to_utf8($txt);
  24816. }
  24817. if($y==-1) {
  24818. if (!$this->ColActive){ $y=$this->y; }
  24819. else { $y = $this->y0; } // If columns are on - mark top of columns
  24820. }
  24821. // else y is used as set, or =0 i.e. top of page
  24822. // DIRECTIONALITY RTL
  24823. if ($this->keep_block_together) {
  24824. $this->ktBMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  24825. }
  24826. /*-- TABLES --*/
  24827. else if ($this->table_rotate) {
  24828. $this->tbrot_BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  24829. }
  24830. else if ($this->kwt) {
  24831. $this->kwt_BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  24832. }
  24833. /*-- END TABLES --*/
  24834. else if ($this->ColActive) { // *COLUMNS*
  24835. $this->col_BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page); // *COLUMNS*
  24836. } // *COLUMNS*
  24837. else {
  24838. $this->BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  24839. }
  24840. }
  24841. function _putbookmarks()
  24842. {
  24843. $nb=count($this->BMoutlines);
  24844. if($nb==0)
  24845. return;
  24846. $lru=array();
  24847. $level=0;
  24848. foreach($this->BMoutlines as $i=>$o)
  24849. {
  24850. if($o['l']>0)
  24851. {
  24852. $parent=$lru[$o['l']-1];
  24853. //Set parent and last pointers
  24854. $this->BMoutlines[$i]['parent']=$parent;
  24855. $this->BMoutlines[$parent]['last']=$i;
  24856. if($o['l']>$level)
  24857. {
  24858. //Level increasing: set first pointer
  24859. $this->BMoutlines[$parent]['first']=$i;
  24860. }
  24861. }
  24862. else
  24863. $this->BMoutlines[$i]['parent']=$nb;
  24864. if($o['l']<=$level and $i>0)
  24865. {
  24866. //Set prev and next pointers
  24867. $prev=$lru[$o['l']];
  24868. $this->BMoutlines[$prev]['next']=$i;
  24869. $this->BMoutlines[$i]['prev']=$prev;
  24870. }
  24871. $lru[$o['l']]=$i;
  24872. $level=$o['l'];
  24873. }
  24874. //Outline items
  24875. $n=$this->n+1;
  24876. foreach($this->BMoutlines as $i=>$o)
  24877. {
  24878. $this->_newobj();
  24879. $this->_out('<</Title '.$this->_UTF16BEtextstring($o['t']));
  24880. $this->_out('/Parent '.($n+$o['parent']).' 0 R');
  24881. if(isset($o['prev']))
  24882. $this->_out('/Prev '.($n+$o['prev']).' 0 R');
  24883. if(isset($o['next']))
  24884. $this->_out('/Next '.($n+$o['next']).' 0 R');
  24885. if(isset($o['first']))
  24886. $this->_out('/First '.($n+$o['first']).' 0 R');
  24887. if(isset($o['last']))
  24888. $this->_out('/Last '.($n+$o['last']).' 0 R');
  24889. if (isset($this->pageDim[$o['p']]['h'])) { $h=$this->pageDim[$o['p']]['h']; }
  24890. else { $h = 0; }
  24891. $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.3f null]',1+2*($o['p']),($h-$o['y'])*$this->k));
  24892. $this->_out('/Count 0>>');
  24893. $this->_out('endobj');
  24894. }
  24895. //Outline root
  24896. $this->_newobj();
  24897. $this->OutlineRoot=$this->n;
  24898. $this->_out('<</Type /BMoutlines /First '.$n.' 0 R');
  24899. $this->_out('/Last '.($n+$lru[0]).' 0 R>>');
  24900. $this->_out('endobj');
  24901. }
  24902. /*-- END BOOKMARKS --*/
  24903. // *BOOKMARKS*
  24904. //======================================================
  24905. // DEPRACATED but included for backwards compatability
  24906. function startPageNums() {
  24907. }
  24908. //======================================================
  24909. /*-- TOC --*/
  24910. // ToC TABLE OF CONTENTS
  24911. // Initiate, and Mark a place for the Table of Contents to be inserted
  24912. function TOC($tocfont='', $tocfontsize=8, $tocindent=5, $resetpagenum='', $pagenumstyle='', $suppress='', $toc_orientation='', $TOCusePaging=true, $TOCuseLinking=false, $toc_id=0) {
  24913. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  24914. else if (!$toc_id) { $toc_id = 0; }
  24915. else { $toc_id = strtolower($toc_id); }
  24916. // To use odd and even pages
  24917. // Cannot start table of contents on an even page
  24918. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  24919. /*-- COLUMNS --*/
  24920. if ($this->ColActive) {
  24921. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  24922. }
  24923. /*-- END COLUMNS --*/
  24924. $this->AddPage($this->CurOrientation,'',$resetpagenum, $pagenumstyle, $suppress);
  24925. }
  24926. else {
  24927. $this->PageNumSubstitutions[] = array('from'=>$this->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  24928. }
  24929. if (!$tocfont) { $tocfont = $this->default_font; }
  24930. if (!$tocfontsize) { $tocfontsize = $this->default_font_size; }
  24931. if ($toc_id) {
  24932. $this->m_TOC[$toc_id]['TOCmark'] = $this->page;
  24933. $this->m_TOC[$toc_id]['TOCfont'] = $tocfont;
  24934. $this->m_TOC[$toc_id]['TOCfontsize'] = $tocfontsize;
  24935. $this->m_TOC[$toc_id]['TOCindent'] = $tocindent;
  24936. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  24937. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  24938. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  24939. }
  24940. else {
  24941. $this->TOCmark = $this->page;
  24942. $this->TOCfont = $tocfont;
  24943. $this->TOCfontsize = $tocfontsize;
  24944. $this->TOCindent = $tocindent;
  24945. $this->TOCorientation = $toc_orientation;
  24946. $this->TOCuseLinking = $TOCuseLinking;
  24947. $this->TOCusePaging = $TOCusePaging;
  24948. }
  24949. }
  24950. function TOCpagebreakByArray($a) {
  24951. if (!is_array($a)) { $a = array(); }
  24952. $tocfont = (isset($a['tocfont']) ? $a['tocfont'] : '');
  24953. $tocfontsize = (isset($a['tocfontsize']) ? $a['tocfontsize'] : '');
  24954. $tocindent = (isset($a['tocindent']) ? $a['tocindent'] : '');
  24955. $TOCusePaging = (isset($a['TOCusePaging']) ? $a['TOCusePaging'] : true);
  24956. $TOCuseLinking = (isset($a['TOCuseLinking']) ? $a['TOCuseLinking'] : '');
  24957. $toc_orientation = (isset($a['toc_orientation']) ? $a['toc_orientation'] : '');
  24958. $toc_mgl = (isset($a['toc_mgl']) ? $a['toc_mgl'] : '');
  24959. $toc_mgr = (isset($a['toc_mgr']) ? $a['toc_mgr'] : '');
  24960. $toc_mgt = (isset($a['toc_mgt']) ? $a['toc_mgt'] : '');
  24961. $toc_mgb = (isset($a['toc_mgb']) ? $a['toc_mgb'] : '');
  24962. $toc_mgh = (isset($a['toc_mgh']) ? $a['toc_mgh'] : '');
  24963. $toc_mgf = (isset($a['toc_mgf']) ? $a['toc_mgf'] : '');
  24964. $toc_ohname = (isset($a['toc_ohname']) ? $a['toc_ohname'] : '');
  24965. $toc_ehname = (isset($a['toc_ehname']) ? $a['toc_ehname'] : '');
  24966. $toc_ofname = (isset($a['toc_ofname']) ? $a['toc_ofname'] : '');
  24967. $toc_efname = (isset($a['toc_efname']) ? $a['toc_efname'] : '');
  24968. $toc_ohvalue = (isset($a['toc_ohvalue']) ? $a['toc_ohvalue'] : 0);
  24969. $toc_ehvalue = (isset($a['toc_ehvalue']) ? $a['toc_ehvalue'] : 0);
  24970. $toc_ofvalue = (isset($a['toc_ofvalue']) ? $a['toc_ofvalue'] : 0);
  24971. $toc_efvalue = (isset($a['toc_efvalue']) ? $a['toc_efvalue'] : 0);
  24972. $toc_preHTML = (isset($a['toc_preHTML']) ? $a['toc_preHTML'] : '');
  24973. $toc_postHTML = (isset($a['toc_postHTML']) ? $a['toc_postHTML'] : '');
  24974. $toc_bookmarkText = (isset($a['toc_bookmarkText']) ? $a['toc_bookmarkText'] : '');
  24975. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  24976. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  24977. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  24978. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  24979. $mgl = (isset($a['mgl']) ? $a['mgl'] : '');
  24980. $mgr = (isset($a['mgr']) ? $a['mgr'] : '');
  24981. $mgt = (isset($a['mgt']) ? $a['mgt'] : '');
  24982. $mgb = (isset($a['mgb']) ? $a['mgb'] : '');
  24983. $mgh = (isset($a['mgh']) ? $a['mgh'] : '');
  24984. $mgf = (isset($a['mgf']) ? $a['mgf'] : '');
  24985. $ohname = (isset($a['ohname']) ? $a['ohname'] : '');
  24986. $ehname = (isset($a['ehname']) ? $a['ehname'] : '');
  24987. $ofname = (isset($a['ofname']) ? $a['ofname'] : '');
  24988. $efname = (isset($a['efname']) ? $a['efname'] : '');
  24989. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : 0);
  24990. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : 0);
  24991. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : 0);
  24992. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : 0);
  24993. $toc_id = (isset($a['toc_id']) ? $a['toc_id'] : 0);
  24994. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : '');
  24995. $toc_pagesel = (isset($a['toc_pagesel']) ? $a['toc_pagesel'] : '');
  24996. $sheetsize = (isset($a['sheetsize']) ? $a['sheetsize'] : '');
  24997. $toc_sheetsize = (isset($a['toc_sheetsize']) ? $a['toc_sheetsize'] : '');
  24998. $this->TOCpagebreak($tocfont, $tocfontsize, $tocindent, $TOCusePaging, $TOCuseLinking, $toc_orientation, $toc_mgl, $toc_mgr, $toc_mgt, $toc_mgb, $toc_mgh, $toc_mgf, $toc_ohname, $toc_ehname, $toc_ofname, $toc_efname, $toc_ohvalue, $toc_ehvalue, $toc_ofvalue, $toc_efvalue, $toc_preHTML, $toc_postHTML, $toc_bookmarkText, $resetpagenum, $pagenumstyle, $suppress, $orientation, $mgl, $mgr, $mgt, $mgb, $mgh, $mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue, $toc_id, $pagesel, $toc_pagesel, $sheetsize, $toc_sheetsize);
  24999. }
  25000. function TOCpagebreak($tocfont='', $tocfontsize='', $tocindent='', $TOCusePaging=true, $TOCuseLinking='', $toc_orientation='', $toc_mgl='',$toc_mgr='',$toc_mgt='',$toc_mgb='',$toc_mgh='',$toc_mgf='',$toc_ohname='',$toc_ehname='',$toc_ofname='',$toc_efname='',$toc_ohvalue=0,$toc_ehvalue=0,$toc_ofvalue=0,$toc_efvalue=0, $toc_preHTML='', $toc_postHTML='', $toc_bookmarkText='', $resetpagenum='', $pagenumstyle='', $suppress='', $orientation='', $mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0, $toc_id=0, $pagesel='', $toc_pagesel='', $sheetsize='', $toc_sheetsize='') {
  25001. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  25002. else if (!$toc_id) { $toc_id = 0; }
  25003. else { $toc_id = strtolower($toc_id); }
  25004. //Start a new page
  25005. if($this->state==0) $this->AddPage();
  25006. if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) {
  25007. // Don't add a page
  25008. if ($this->page==1 && count($this->PageNumSubstitutions)==0) {
  25009. if (!$suppress) { $suppress = 'off'; }
  25010. if (!$resetpagenum) { $resetpagenum= 1; }
  25011. //$this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress); // mPDF 5.1.006
  25012. }
  25013. $this->PageNumSubstitutions[] = array('from'=>$this->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress); // mPDF 5.1.006
  25014. }
  25015. else {
  25016. $this->AddPage($orientation,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$sheetsize);
  25017. }
  25018. if (!$tocfont) { $tocfont = $this->default_font; }
  25019. if (!$tocfontsize) { $tocfontsize = $this->default_font_size; }
  25020. if (!$tocindent && $tocindent !== 0) { $tocindent = 5; }
  25021. if ($TOCusePaging === false || strtolower($TOCusePaging) == "off" || $TOCusePaging === 0 || $TOCusePaging === "0" || $TOCusePaging === "") { $TOCusePaging = false; }
  25022. else { $TOCusePaging = true; }
  25023. if (!$TOCuseLinking) { $TOCuseLinking = false; }
  25024. if ($toc_id) {
  25025. $this->m_TOC[$toc_id]['TOCmark'] = $this->page;
  25026. $this->m_TOC[$toc_id]['TOCfont'] = $tocfont;
  25027. $this->m_TOC[$toc_id]['TOCfontsize'] = $tocfontsize;
  25028. $this->m_TOC[$toc_id]['TOCindent'] = $tocindent;
  25029. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  25030. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  25031. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  25032. if ($toc_preHTML) { $this->m_TOC[$toc_id]['TOCpreHTML'] = $toc_preHTML; }
  25033. if ($toc_postHTML) { $this->m_TOC[$toc_id]['TOCpostHTML'] = $toc_postHTML; }
  25034. if ($toc_bookmarkText) { $this->m_TOC[$toc_id]['TOCbookmarkText'] = $toc_bookmarkText; } // *BOOKMARKS*
  25035. $this->m_TOC[$toc_id]['TOC_margin_left'] = $toc_mgl;
  25036. $this->m_TOC[$toc_id]['TOC_margin_right'] = $toc_mgr;
  25037. $this->m_TOC[$toc_id]['TOC_margin_top'] = $toc_mgt;
  25038. $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $toc_mgb;
  25039. $this->m_TOC[$toc_id]['TOC_margin_header'] = $toc_mgh;
  25040. $this->m_TOC[$toc_id]['TOC_margin_footer'] = $toc_mgf;
  25041. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $toc_ohname;
  25042. $this->m_TOC[$toc_id]['TOC_even_header_name'] = $toc_ehname;
  25043. $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $toc_ofname;
  25044. $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $toc_efname;
  25045. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = $toc_ohvalue;
  25046. $this->m_TOC[$toc_id]['TOC_even_header_value'] = $toc_ehvalue;
  25047. $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = $toc_ofvalue;
  25048. $this->m_TOC[$toc_id]['TOC_even_footer_value'] = $toc_efvalue;
  25049. $this->m_TOC[$toc_id]['TOC_page_selector'] = $toc_pagesel;
  25050. $this->m_TOC[$toc_id]['TOCsheetsize'] = $toc_sheetsize;
  25051. }
  25052. else {
  25053. $this->TOCmark = $this->page;
  25054. $this->TOCfont = $tocfont;
  25055. $this->TOCfontsize = $tocfontsize;
  25056. $this->TOCindent = $tocindent;
  25057. $this->TOCorientation = $toc_orientation;
  25058. $this->TOCuseLinking = $TOCuseLinking;
  25059. $this->TOCusePaging = $TOCusePaging;
  25060. if ($toc_preHTML) { $this->TOCpreHTML = $toc_preHTML; }
  25061. if ($toc_postHTML) { $this->TOCpostHTML = $toc_postHTML; }
  25062. if ($toc_bookmarkText) { $this->TOCbookmarkText = $toc_bookmarkText; } // *BOOKMARKS*
  25063. $this->TOC_margin_left = $toc_mgl;
  25064. $this->TOC_margin_right = $toc_mgr;
  25065. $this->TOC_margin_top = $toc_mgt;
  25066. $this->TOC_margin_bottom = $toc_mgb;
  25067. $this->TOC_margin_header = $toc_mgh;
  25068. $this->TOC_margin_footer = $toc_mgf;
  25069. $this->TOC_odd_header_name = $toc_ohname;
  25070. $this->TOC_even_header_name = $toc_ehname;
  25071. $this->TOC_odd_footer_name = $toc_ofname;
  25072. $this->TOC_even_footer_name = $toc_efname;
  25073. $this->TOC_odd_header_value = $toc_ohvalue;
  25074. $this->TOC_even_header_value = $toc_ehvalue;
  25075. $this->TOC_odd_footer_value = $toc_ofvalue;
  25076. $this->TOC_even_footer_value = $toc_efvalue;
  25077. $this->TOC_page_selector = $toc_pagesel;
  25078. $this->TOCsheetsize = $toc_sheetsize;
  25079. }
  25080. }
  25081. function TOC_Entry($txt, $level=0, $toc_id=0) {
  25082. $txt = $this->purify_utf8_text($txt);
  25083. if ($this->text_input_as_HTML) {
  25084. $txt = $this->all_entities_to_utf8($txt);
  25085. }
  25086. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  25087. if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  25088. $linkn = $this->AddLink();
  25089. $this->SetLink($linkn,$ily,$this->page);
  25090. /*-- RTL --*/
  25091. if ($this->biDirectional) { // mPDF 5.0.054
  25092. $txt = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $txt );
  25093. }
  25094. /*-- END RTL --*/
  25095. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  25096. else if (!$toc_id) { $toc_id = 0; }
  25097. else { $toc_id = strtolower($toc_id); }
  25098. if ($this->keep_block_together) {
  25099. $this->_kttoc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  25100. }
  25101. /*-- TABLES --*/
  25102. else if ($this->table_rotate) {
  25103. $this->tbrot_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  25104. }
  25105. else if ($this->kwt) {
  25106. $this->kwt_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  25107. }
  25108. /*-- END TABLES --*/
  25109. else if ($this->ColActive) { // *COLUMNS*
  25110. $this->col_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id); // *COLUMNS*
  25111. } // *COLUMNS*
  25112. else {
  25113. $this->_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  25114. }
  25115. }
  25116. function insertTOC() {
  25117. $notocs = 0;
  25118. if ($this->TOCmark) { $notocs = 1; }
  25119. $notocs += count($this->m_TOC);
  25120. if ($notocs==0) { return; }
  25121. if (count($this->m_TOC)) { reset($this->m_TOC); }
  25122. $added_toc_pages = 0;
  25123. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  25124. if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  25125. $this->AddPage($this->CurOrientation);
  25126. $extrapage = true;
  25127. }
  25128. else { $extrapage = false; }
  25129. for ($toci = 0; $toci<$notocs; $toci++) {
  25130. if ($toci==0 && $this->TOCmark) {
  25131. $toc_id = 0;
  25132. $toc_page = $this->TOCmark;
  25133. $tocfont = $this->TOCfont;
  25134. $tocfontsize = $this->TOCfontsize;
  25135. $tocindent = $this->TOCindent;
  25136. $toc_orientation = $this->TOCorientation;
  25137. $TOCuseLinking = $this->TOCuseLinking;
  25138. $TOCusePaging = $this->TOCusePaging;
  25139. $toc_preHTML = $this->TOCpreHTML;
  25140. $toc_postHTML = $this->TOCpostHTML;
  25141. $toc_bookmarkText = $this->TOCbookmarkText; // *BOOKMARKS*
  25142. $toc_mgl = $this->TOC_margin_left;
  25143. $toc_mgr = $this->TOC_margin_right;
  25144. $toc_mgt = $this->TOC_margin_top;
  25145. $toc_mgb = $this->TOC_margin_bottom;
  25146. $toc_mgh = $this->TOC_margin_header;
  25147. $toc_mgf = $this->TOC_margin_footer;
  25148. $toc_ohname = $this->TOC_odd_header_name;
  25149. $toc_ehname = $this->TOC_even_header_name;
  25150. $toc_ofname = $this->TOC_odd_footer_name;
  25151. $toc_efname = $this->TOC_even_footer_name;
  25152. $toc_ohvalue = $this->TOC_odd_header_value;
  25153. $toc_ehvalue = $this->TOC_even_header_value;
  25154. $toc_ofvalue = $this->TOC_odd_footer_value;
  25155. $toc_efvalue = $this->TOC_even_footer_value;
  25156. $toc_page_selector = $this->TOC_page_selector;
  25157. $toc_sheet_size = $this->TOCsheetsize;
  25158. }
  25159. else {
  25160. $arr = current($this->m_TOC);
  25161. $toc_id = key($this->m_TOC);
  25162. $toc_page = $this->m_TOC[$toc_id]['TOCmark'];
  25163. $tocfont = $this->m_TOC[$toc_id]['TOCfont'];
  25164. $tocfontsize = $this->m_TOC[$toc_id]['TOCfontsize'];
  25165. $tocindent = $this->m_TOC[$toc_id]['TOCindent'];
  25166. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  25167. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  25168. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  25169. if (isset($this->m_TOC[$toc_id]['TOCpreHTML'])) { $toc_preHTML = $this->m_TOC[$toc_id]['TOCpreHTML']; }
  25170. else { $toc_preHTML = ''; }
  25171. if (isset($this->m_TOC[$toc_id]['TOCpostHTML'])) { $toc_postHTML = $this->m_TOC[$toc_id]['TOCpostHTML']; }
  25172. else { $toc_postHTML = ''; }
  25173. if (isset($this->m_TOC[$toc_id]['TOCbookmarkText'])) { $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText']; } // *BOOKMARKS*
  25174. else { $toc_bookmarkText = ''; } // *BOOKMARKS*
  25175. $toc_mgl = $this->m_TOC[$toc_id]['TOC_margin_left'];
  25176. $toc_mgr = $this->m_TOC[$toc_id]['TOC_margin_right'];
  25177. $toc_mgt = $this->m_TOC[$toc_id]['TOC_margin_top'];
  25178. $toc_mgb = $this->m_TOC[$toc_id]['TOC_margin_bottom'];
  25179. $toc_mgh = $this->m_TOC[$toc_id]['TOC_margin_header'];
  25180. $toc_mgf = $this->m_TOC[$toc_id]['TOC_margin_footer'];
  25181. $toc_ohname = $this->m_TOC[$toc_id]['TOC_odd_header_name'];
  25182. $toc_ehname = $this->m_TOC[$toc_id]['TOC_even_header_name'];
  25183. $toc_ofname = $this->m_TOC[$toc_id]['TOC_odd_footer_name'];
  25184. $toc_efname = $this->m_TOC[$toc_id]['TOC_even_footer_name'];
  25185. $toc_ohvalue = $this->m_TOC[$toc_id]['TOC_odd_header_value'];
  25186. $toc_ehvalue = $this->m_TOC[$toc_id]['TOC_even_header_value'];
  25187. $toc_ofvalue = $this->m_TOC[$toc_id]['TOC_odd_footer_value'];
  25188. $toc_efvalue = $this->m_TOC[$toc_id]['TOC_even_footer_value'];
  25189. $toc_page_selector = $this->m_TOC[$toc_id]['TOC_page_selector'];
  25190. $toc_sheet_size = $this->m_TOC[$toc_id]['TOCsheetsize'];
  25191. next($this->m_TOC);
  25192. }
  25193. if ($this->TOCheader) { $this->SetHeader($this->TOCheader); }
  25194. else if ($this->TOCheader !== false) { $this->SetHeader(); }
  25195. if (!$tocindent && $tocindent !== 0) { $tocindent = 5; }
  25196. if (!$toc_orientation) { $toc_orientation= $this->DefOrientation; }
  25197. $this->AddPage($toc_orientation, '', '', '', "on", $toc_mgl, $toc_mgr, $toc_mgt, $toc_mgb, $toc_mgh, $toc_mgf, $toc_ohname, $toc_ehname, $toc_ofname, $toc_efname, $toc_ohvalue, $toc_ehvalue, $toc_ofvalue, $toc_efvalue, $toc_page_selector, $toc_sheet_size );
  25198. if ($this->TOCfooter) { $this->SetFooter($this->TOCfooter); }
  25199. else if ($this->TOCfooter !== false) { $this->SetFooter(); }
  25200. $tocstart=count($this->pages);
  25201. if ($toc_preHTML) { $this->WriteHTML($toc_preHTML); }
  25202. foreach($this->_toc as $t) {
  25203. if ($t['toc_id']==='_mpdf_all' || $t['toc_id']===$toc_id ) {
  25204. $tpgno = $this->docPageNum($t['p']);
  25205. $lineheightcorr = 2-$t['l'];
  25206. //Offset
  25207. $level=$t['l'];
  25208. if ($TOCuseLinking) { $tlink = $t['link']; }
  25209. else { $tlink = ''; }
  25210. /*-- RTL --*/
  25211. if ($this->directionality == 'rtl') {
  25212. $weight='';
  25213. if($level==0)
  25214. $weight='B';
  25215. $str=$t['t'];
  25216. $fullstr = $str;
  25217. $this->SetFont($tocfont,$weight,$tocfontsize,true,true);
  25218. $PageCellSize=$this->GetStringWidth($tpgno )+2;
  25219. $strsize=$this->GetStringWidth($str);
  25220. $cw = count(explode(' ',$str));
  25221. while (($strsize + $this->GetStringWidth(str_repeat('.',5))+4 + $PageCellSize) > $this->pgwidth && $cw>1) {
  25222. $str = implode(' ',explode(' ',$str,-1));
  25223. $strsize=$this->GetStringWidth($str);
  25224. $cw = count(explode(' ',$str));
  25225. }
  25226. $sl = strlen($str);
  25227. $rem = substr($fullstr, ($sl+1));
  25228. // mPDF 5.0.054
  25229. $this->magic_reverse_dir($str, true, $this->directionality); // *RTL*
  25230. if ($TOCusePaging) {
  25231. //Page number
  25232. $this->SetFont($tocfont,'',$tocfontsize);
  25233. $this->Cell($PageCellSize,$this->FontSize+$lineheightcorr,$tpgno ,0,0,'L',0,$tlink);
  25234. //Filling dots
  25235. $w=$this->w-$this->lMargin-$this->rMargin-$PageCellSize-($level*$tocindent)-($strsize+2);
  25236. $nb=intval($w/$this->GetStringWidth('.'));
  25237. if ($nb>0) {
  25238. $dots=str_repeat('.',$nb);
  25239. $this->Cell($w+2,$this->FontSize+$lineheightcorr,$dots,0,0,'L');
  25240. }
  25241. // Text
  25242. $this->SetFont($tocfont,$weight,$tocfontsize);
  25243. $this->Cell($strsize-($level*$tocindent),$this->FontSize+$lineheightcorr,$str,0,1,'R',0,$tlink);
  25244. }
  25245. else {
  25246. // Text
  25247. $this->SetFont($tocfont,$weight,$tocfontsize);
  25248. $this->Cell($this->pgwidth -($level*$tocindent),$this->FontSize+$lineheightcorr,$str,0,1,'R',0,$tlink);
  25249. }
  25250. if ($rem) {
  25251. $this->x += 10;
  25252. $this->MultiCell($this->pgwidth -($level*$tocindent)-15,$this->FontSize+$lineheightcorr,$rem,0,R,0,$tlink,'rtl',true);
  25253. }
  25254. }
  25255. // LTR
  25256. else {
  25257. /*-- END RTL --*/
  25258. // Text
  25259. $weight='';
  25260. if($level==0)
  25261. $weight='B';
  25262. $str=$t['t'];
  25263. $fullstr = $str;
  25264. $this->SetFont($tocfont,$weight,$tocfontsize,true,true);
  25265. if($level>0 && $tocindent) { $this->Cell($level*$tocindent,$this->FontSize+$lineheightcorr); }
  25266. // Font-specific ligature substitution for Indic fonts
  25267. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($str); // *INDIC*
  25268. $PageCellSize=$this->GetStringWidth($tpgno )+2;
  25269. $strsize=$this->GetStringWidth($str);
  25270. $cw = count(explode(' ',$str));
  25271. while (($strsize + $this->GetStringWidth(str_repeat('.',5))+4+ $PageCellSize + ($level*$tocindent)) > $this->pgwidth && $cw>1) {
  25272. $str = implode(' ',explode(' ',$str,-1));
  25273. $strsize=$this->GetStringWidth($str);
  25274. $cw = count(explode(' ',$str));
  25275. }
  25276. $sl = strlen($str);
  25277. $rem = substr($fullstr, ($sl+1));
  25278. if ($TOCusePaging) {
  25279. // Text
  25280. $this->Cell($strsize+2,$this->FontSize+$lineheightcorr,$str,0,0,'',0,$tlink);
  25281. //Filling dots
  25282. $this->SetFont($tocfont,'',$tocfontsize);
  25283. $w=$this->w-$this->lMargin-$this->rMargin-$PageCellSize-($level*$tocindent)-($strsize+2);
  25284. $nb=intval($w/$this->GetStringWidth('.'));
  25285. if ($nb>0) { $dots=str_repeat('.',$nb); }
  25286. else { $this->y += $this->lineheight; $dots=str_repeat('.',5); } // ..... 5 dots?
  25287. $this->Cell($w,$this->FontSize+$lineheightcorr,$dots,0,0,'R');
  25288. //Page number
  25289. $this->Cell($PageCellSize,$this->FontSize+$lineheightcorr,$tpgno ,0,1,'R',0,$tlink);
  25290. }
  25291. else {
  25292. // Text only
  25293. $this->Cell($strsize+2,$this->FontSize+$lineheightcorr,$str,0,1,'',0,$tlink); // forces new line
  25294. }
  25295. if ($rem) {
  25296. $this->x += 5 + $PageCellSize + ($level*$tocindent);
  25297. $this->MultiCell($strsize+2,$this->FontSize+$lineheightcorr,$rem,0,L,0,$tlink,'ltr',true);
  25298. }
  25299. } // *RTL*
  25300. }
  25301. }
  25302. if ($toc_postHTML) { $this->WriteHTML($toc_postHTML); }
  25303. $this->AddPage($toc_orientation,'E');
  25304. $n_toc = $this->page - $tocstart + 1;
  25305. if ($toci==0 && $this->TOCmark) {
  25306. $this->TOC_start = $tocstart ;
  25307. $this->TOC_end = $this->page;
  25308. $this->TOC_npages = $n_toc;
  25309. }
  25310. else {
  25311. $this->m_TOC[$toc_id]['start'] = $tocstart ;
  25312. $this->m_TOC[$toc_id]['end'] = $this->page;
  25313. $this->m_TOC[$toc_id]['npages'] = $n_toc;
  25314. }
  25315. }
  25316. $s = '';
  25317. // mPDF 5.0.023 5.0.047
  25318. $s .= $this->PrintBodyBackgrounds();
  25319. $s .= $this->PrintPageBackgrounds();
  25320. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  25321. $this->pageBackgrounds = array();
  25322. //Page footer
  25323. $this->InFooter=true;
  25324. $this->Footer();
  25325. $this->InFooter=false;
  25326. // 2nd time through to move pages etc.
  25327. $added_toc_pages = 0;
  25328. if (count($this->m_TOC)) { reset($this->m_TOC); }
  25329. for ($toci = 0; $toci<$notocs; $toci++) {
  25330. if ($toci==0 && $this->TOCmark) {
  25331. $toc_id = 0;
  25332. $toc_page = $this->TOCmark + $added_toc_pages;
  25333. $toc_orientation = $this->TOCorientation;
  25334. $TOCuseLinking = $this->TOCuseLinking;
  25335. $TOCusePaging = $this->TOCusePaging;
  25336. $toc_bookmarkText = $this->TOCbookmarkText; // *BOOKMARKS*
  25337. $tocstart = $this->TOC_start ;
  25338. $tocend = $n = $this->TOC_end;
  25339. $n_toc = $this->TOC_npages;
  25340. }
  25341. else {
  25342. $arr = current($this->m_TOC);
  25343. $toc_id = key($this->m_TOC);
  25344. $toc_page = $this->m_TOC[$toc_id]['TOCmark'] + $added_toc_pages;
  25345. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  25346. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  25347. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  25348. $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText']; // *BOOKMARKS*
  25349. $tocstart = $this->m_TOC[$toc_id]['start'] ;
  25350. $tocend = $n = $this->m_TOC[$toc_id]['end'] ;
  25351. $n_toc = $this->m_TOC[$toc_id]['npages'] ;
  25352. next($this->m_TOC);
  25353. }
  25354. // Now pages moved
  25355. $added_toc_pages += $n_toc;
  25356. $this->MovePages($toc_page, $tocstart, $tocend) ;
  25357. $this->pgsIns[$toc_page] = $tocend - $tocstart + 1;
  25358. /*-- BOOKMARKS --*/
  25359. // Insert new Bookmark for Bookmark
  25360. if ($toc_bookmarkText) {
  25361. $insert = -1;
  25362. foreach($this->BMoutlines as $i=>$o) {
  25363. if($o['p']<$toc_page) { // i.e. before point of insertion
  25364. $insert = $i;
  25365. }
  25366. }
  25367. $txt = $this->purify_utf8_text($toc_bookmarkText);
  25368. if ($this->text_input_as_HTML) {
  25369. $txt = $this->all_entities_to_utf8($txt);
  25370. }
  25371. $newBookmark[0] = array('t'=>$txt,'l'=>0,'y'=>0,'p'=>$toc_page );
  25372. array_splice($this->BMoutlines,($insert+1),0,$newBookmark);
  25373. }
  25374. /*-- END BOOKMARKS --*/
  25375. }
  25376. // Delete empty page that was inserted earlier
  25377. if ($extrapage) {
  25378. unset($this->pages[count($this->pages)]);
  25379. $this->page--; // Reset page pointer
  25380. }
  25381. }
  25382. //======================================================
  25383. function MovePages($target_page, $start_page, $end_page=-1) {
  25384. // move a page/pages EARLIER in the document
  25385. if ($end_page<1) { $end_page = $start_page; }
  25386. $n_toc = $end_page - $start_page + 1;
  25387. // Set/Update PageNumSubstitutions changes before moving anything
  25388. if (count($this->PageNumSubstitutions)) {
  25389. $tp_present = false;
  25390. $sp_present = false;
  25391. $ep_present = false;
  25392. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25393. if ($this->PageNumSubstitutions[$k]['from']==$target_page) {
  25394. $tp_present = true;
  25395. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25396. $this->PageNumSubstitutions[$k]['suppress']='off';
  25397. }
  25398. }
  25399. if ($this->PageNumSubstitutions[$k]['from']==$start_page) {
  25400. $sp_present = true;
  25401. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25402. $this->PageNumSubstitutions[$k]['suppress']='off';
  25403. }
  25404. }
  25405. if ($this->PageNumSubstitutions[$k]['from']==($end_page+1)) {
  25406. $ep_present = true;
  25407. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25408. $this->PageNumSubstitutions[$k]['suppress']='off';
  25409. }
  25410. }
  25411. }
  25412. if (!$tp_present) {
  25413. list($tp_type, $tp_suppress, $tp_reset) = $this->docPageSettings($target_page);
  25414. }
  25415. if (!$sp_present) {
  25416. list($sp_type, $sp_suppress, $sp_reset) = $this->docPageSettings($start_page);
  25417. }
  25418. if (!$ep_present) {
  25419. list($ep_type, $ep_suppress, $ep_reset) = $this->docPageSettings($start_page-1);
  25420. }
  25421. }
  25422. $last = array();
  25423. //store pages
  25424. for($i = $start_page;$i <= $end_page ;$i++)
  25425. $last[]=$this->pages[$i];
  25426. //move pages
  25427. for($i=$start_page - 1;$i>=($target_page);$i--) {
  25428. $this->pages[$i+$n_toc]=$this->pages[$i];
  25429. }
  25430. //Put toc pages at insert point
  25431. for($i = 0;$i < $n_toc;$i++) {
  25432. $this->pages[$target_page + $i]=$last[$i];
  25433. }
  25434. /*-- BOOKMARKS --*/
  25435. // Update Bookmarks
  25436. foreach($this->BMoutlines as $i=>$o) {
  25437. if($o['p']>=$target_page) {
  25438. $this->BMoutlines[$i]['p'] += $n_toc;
  25439. }
  25440. }
  25441. /*-- END BOOKMARKS --*/
  25442. // Update Page Links
  25443. if (count($this->PageLinks)) {
  25444. $newarr = array();
  25445. foreach($this->PageLinks as $i=>$o) {
  25446. foreach($this->PageLinks[$i] as $key => $pl) {
  25447. if (strpos($pl[4],'@')===0) {
  25448. $p=substr($pl[4],1);
  25449. if($p>=$start_page && $p<=$end_page) {
  25450. $this->PageLinks[$i][$key][4] = '@'.($p + ($target_page - $start_page));
  25451. }
  25452. else if($p>=$target_page && $p<$start_page) {
  25453. $this->PageLinks[$i][$key][4] = '@'.($p+$n_toc);
  25454. }
  25455. }
  25456. }
  25457. if($i>=$start_page && $i<=$end_page) {
  25458. $newarr[($i + ($target_page - $start_page))] = $this->PageLinks[$i];
  25459. }
  25460. else if($i>=$target_page && $i<$start_page) {
  25461. $newarr[($i + $n_toc)] = $this->PageLinks[$i];
  25462. }
  25463. else {
  25464. $newarr[$i] = $this->PageLinks[$i];
  25465. }
  25466. }
  25467. $this->PageLinks = $newarr;
  25468. }
  25469. // OrientationChanges
  25470. if (count($this->OrientationChanges)) {
  25471. $newarr = array();
  25472. foreach($this->OrientationChanges AS $p=>$v) {
  25473. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->OrientationChanges[$p]; }
  25474. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->OrientationChanges[$p]; }
  25475. else { $newarr[$p] = $this->OrientationChanges[$p]; }
  25476. }
  25477. ksort($newarr);
  25478. $this->OrientationChanges = $newarr;
  25479. }
  25480. // Page Dimensions
  25481. if (count($this->pageDim)) {
  25482. $newarr = array();
  25483. foreach($this->pageDim AS $p=>$v) {
  25484. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->pageDim[$p]; }
  25485. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->pageDim[$p]; }
  25486. else { $newarr[$p] = $this->pageDim[$p]; }
  25487. }
  25488. ksort($newarr);
  25489. $this->pageDim = $newarr;
  25490. }
  25491. // HTML Headers & Footers
  25492. if (count($this->saveHTMLHeader)) {
  25493. $newarr = array();
  25494. foreach($this->saveHTMLHeader AS $p=>$v) {
  25495. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLHeader[$p]; }
  25496. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLHeader[$p]; }
  25497. else { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  25498. }
  25499. ksort($newarr);
  25500. $this->saveHTMLHeader = $newarr;
  25501. }
  25502. if (count($this->saveHTMLFooter)) {
  25503. $newarr = array();
  25504. foreach($this->saveHTMLFooter AS $p=>$v) {
  25505. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLFooter[$p]; }
  25506. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLFooter[$p]; }
  25507. else { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  25508. }
  25509. ksort($newarr);
  25510. $this->saveHTMLFooter = $newarr;
  25511. }
  25512. // Update Internal Links
  25513. if (count($this->internallink)) {
  25514. foreach($this->internallink as $key=>$o) {
  25515. if($o['PAGE']>=$start_page && $o['PAGE']<=$end_page) {
  25516. $this->internallink[$key]['PAGE'] += ($target_page - $start_page);
  25517. }
  25518. else if($o['PAGE']>=$target_page && $o['PAGE']<$start_page) {
  25519. $this->internallink[$key]['PAGE'] += $n_toc;
  25520. }
  25521. }
  25522. }
  25523. // Update Links
  25524. if (count($this->links)) {
  25525. foreach($this->links as $key=>$o) {
  25526. if($o[0]>=$start_page && $o[0]<=$end_page) {
  25527. $this->links[$key][0] += ($target_page - $start_page);
  25528. }
  25529. if($o[0]>=$target_page && $o[0]<$start_page) {
  25530. $this->links[$key][0] += $n_toc;
  25531. }
  25532. }
  25533. }
  25534. /*-- ANNOTATIONS --*/
  25535. // Update Annotations
  25536. if (count($this->PageAnnots)) {
  25537. $newarr = array();
  25538. foreach($this->PageAnnots as $p=>$anno) {
  25539. if($p>=$start_page && $p<=$end_page) {
  25540. $np = $p + ($target_page - $start_page);
  25541. foreach($anno as $o) {
  25542. $newarr[$np][] = $o;
  25543. }
  25544. }
  25545. else if($p>=$target_page && $p<$start_page) {
  25546. $np = $p + $n_toc;
  25547. foreach($anno as $o) {
  25548. $newarr[$np][] = $o;
  25549. }
  25550. }
  25551. else {
  25552. $newarr[$p] = $this->PageAnnots[$p];
  25553. }
  25554. }
  25555. $this->PageAnnots = $newarr;
  25556. unset($newarr);
  25557. }
  25558. /*-- END ANNOTATIONS --*/
  25559. // Update PageNumSubstitutions
  25560. if (count($this->PageNumSubstitutions)) {
  25561. $newarr = array();
  25562. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25563. if($this->PageNumSubstitutions[$k]['from']>=$start_page && $this->PageNumSubstitutions[$k]['from']<=$end_page) {
  25564. $this->PageNumSubstitutions[$k]['from'] += ($target_page - $start_page);
  25565. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25566. }
  25567. else if($this->PageNumSubstitutions[$k]['from']>=$target_page && $this->PageNumSubstitutions[$k]['from']<$start_page) {
  25568. $this->PageNumSubstitutions[$k]['from'] += $n_toc;
  25569. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25570. }
  25571. else {
  25572. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25573. }
  25574. }
  25575. if (!$sp_present) {
  25576. $newarr[$target_page] = array('from'=>$target_page, 'suppress'=>$sp_suppress, 'reset'=>$sp_reset, 'type'=>$sp_type);
  25577. }
  25578. if (!$tp_present) {
  25579. $newarr[($target_page + $n_toc)] = array('from'=>($target_page+$n_toc), 'suppress'=>$tp_suppress, 'reset'=>$tp_reset, 'type'=>$tp_type);
  25580. }
  25581. if (!$ep_present && $end_page>count($this->pages)) {
  25582. $newarr[($end_page+1)] = array('from'=>($end_page+1), 'suppress'=>$ep_suppress, 'reset'=>$ep_reset, 'type'=>$ep_type);
  25583. }
  25584. ksort($newarr);
  25585. $this->PageNumSubstitutions = array();
  25586. foreach($newarr as $v) {
  25587. $this->PageNumSubstitutions[] = $v;
  25588. }
  25589. }
  25590. }
  25591. /*-- END TOC --*/
  25592. //======================================================
  25593. /*-- INDEX --*/
  25594. // FROM class PDF_Ref == INDEX
  25595. function Reference($txt) {
  25596. $this->IndexEntry($txt);
  25597. }
  25598. function IndexEntry($txt, $xref='') {
  25599. if ($xref) {
  25600. $this->IndexEntrySee($txt,$xref);
  25601. return;
  25602. }
  25603. $txt = strip_tags($txt);
  25604. $txt = $this->purify_utf8_text($txt);
  25605. if ($this->text_input_as_HTML) {
  25606. $txt = $this->all_entities_to_utf8($txt);
  25607. }
  25608. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  25609. $Present=0;
  25610. $size=sizeof($this->Reference);
  25611. if ($this->directionality == 'rtl') { // *RTL*
  25612. $txt = str_replace(':',' - ',$txt); // *RTL*
  25613. } // *RTL*
  25614. else { // *RTL*
  25615. $txt = str_replace(':',', ',$txt);
  25616. } // *RTL*
  25617. //Search the reference (AND Ref/PageNo) in the array
  25618. for ($i=0;$i<$size;$i++){
  25619. if ($this->keep_block_together) {
  25620. if (isset($this->ktReference[$i]['t']) && $this->ktReference[$i]['t']==$txt){
  25621. $Present=1;
  25622. if (!in_array($this->page,$this->ktReference[$i]['p'])) {
  25623. $this->ktReference[$i]['op'] = $this->page;
  25624. }
  25625. }
  25626. }
  25627. /*-- TABLES --*/
  25628. else if ($this->table_rotate) {
  25629. if (isset($this->tbrot_Reference[$i]['t']) && $this->tbrot_Reference[$i]['t']==$txt){
  25630. $Present=1;
  25631. if (!in_array($this->page,$this->tbrot_Reference[$i]['p'])) {
  25632. $this->tbrot_Reference[$i]['op'] = $this->page;
  25633. }
  25634. }
  25635. }
  25636. else if ($this->kwt) {
  25637. if (isset($this->kwt_Reference[$i]['t']) && $this->kwt_Reference[$i]['t']==$txt){
  25638. $Present=1;
  25639. if (!in_array($this->page,$this->kwt_Reference[$i]['p'])) {
  25640. $this->kwt_Reference[$i]['op'] = $this->page;
  25641. }
  25642. }
  25643. }
  25644. /*-- END TABLES --*/
  25645. /*-- COLUMNS --*/
  25646. else if ($this->ColActive) {
  25647. if (isset($this->col_Reference[$i]['t']) && $this->col_Reference[$i]['t']==$txt){
  25648. $Present=1;
  25649. if (!in_array($this->page,$this->col_Reference[$i]['p'])) {
  25650. $this->col_Reference[$i]['op'] = $this->page;
  25651. }
  25652. }
  25653. }
  25654. /*-- END COLUMNS --*/
  25655. else {
  25656. if (isset($this->Reference[$i]['t']) && $this->Reference[$i]['t']==$txt){
  25657. $Present=1;
  25658. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  25659. $this->Reference[$i]['p'][] = $this->page;
  25660. }
  25661. }
  25662. }
  25663. }
  25664. //If not found, add it
  25665. if ($Present==0) {
  25666. if ($this->keep_block_together) {
  25667. $this->ktReference[]=array('t'=>$txt, 'op'=>$this->page);
  25668. }
  25669. /*-- TABLES --*/
  25670. else if ($this->table_rotate) {
  25671. $this->tbrot_Reference[]=array('t'=>$txt, 'op'=>$this->page);
  25672. }
  25673. else if ($this->kwt) {
  25674. $this->kwt_Reference[]=array('t'=>$txt, 'op'=>$this->page);
  25675. }
  25676. /*-- END TABLES --*/
  25677. /*-- COLUMNS --*/
  25678. else if ($this->ColActive) {
  25679. $this->col_Reference[]=array('t'=>$txt, 'op'=>$this->page);
  25680. }
  25681. /*-- END COLUMNS --*/
  25682. else {
  25683. $this->Reference[]=array('t'=>$txt,'p'=>array($this->page));
  25684. }
  25685. }
  25686. }
  25687. // Added function to add a reference "Elephants. See Chickens"
  25688. function ReferenceSee($txta,$txtb) {
  25689. $this->IndexEntrySee($txta,$txtb);
  25690. }
  25691. function IndexEntrySee($txta,$txtb) {
  25692. $txta = strip_tags($txta);
  25693. $txtb = strip_tags($txtb);
  25694. $txta = $this->purify_utf8_text($txta);
  25695. $txtb = $this->purify_utf8_text($txtb);
  25696. if ($this->text_input_as_HTML) {
  25697. $txta = $this->all_entities_to_utf8($txta);
  25698. $txtb = $this->all_entities_to_utf8($txtb);
  25699. }
  25700. if ($this->usingCoreFont) {
  25701. $txta = mb_convert_encoding($txta,$this->mb_enc,'UTF-8');
  25702. $txtb = mb_convert_encoding($txtb,$this->mb_enc,'UTF-8');
  25703. }
  25704. if ($this->directionality == 'rtl') { // *RTL*
  25705. $txta = str_replace(':',' - ',$txta); // *RTL*
  25706. $txtb = str_replace(':',' - ',$txtb); // *RTL*
  25707. } // *RTL*
  25708. else { // *RTL*
  25709. $txta = str_replace(':',', ',$txta);
  25710. $txtb = str_replace(':',', ',$txtb);
  25711. } // *RTL*
  25712. $this->Reference[]=array('t'=>$txta.' - see '.$txtb,'p'=>array());
  25713. }
  25714. function CreateReference($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  25715. $this->CreateIndex($NbCol, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont, $divlettfont, $useLinking);
  25716. }
  25717. function CreateIndex($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  25718. if (!$reffontsize) { $reffontsize = $this->default_font_size; }
  25719. if (!$divlettfontsize) { $divlettfontsize = ($this->default_font_size * 1.8); }
  25720. if (!$reffont) { $reffont = $this->default_font; }
  25721. if (!$divlettfont) { $divlettfont = $reffont; }
  25722. if (!$linespacing) { $linespacing= $this->default_lineheight_correction; }
  25723. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  25724. $size=sizeof($this->Reference);
  25725. if ($size == 0) { return false; }
  25726. if ($NbCol<2) {
  25727. $NbCol = 1;
  25728. $colWidth = $this->pgwidth;
  25729. }
  25730. else {
  25731. $this->SetColumns($NbCol,'',$gap);
  25732. $colWidth = $this->ColWidth;
  25733. }
  25734. if ($this->directionality == 'rtl') { $align = 'R'; }
  25735. else { $align = 'L'; }
  25736. $lett = '';
  25737. function cmp ($a, $b) {
  25738. return strnatcmp(strtolower($a['t']), strtolower($b['t']));
  25739. }
  25740. //Alphabetic sort of the references
  25741. usort($this->Reference, 'cmp');
  25742. $size=sizeof($this->Reference);
  25743. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  25744. $divlettjuststarted = false;
  25745. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  25746. $last_lett = '';
  25747. for ($i=0;$i<$size;$i++){
  25748. if ($this->Reference[$i]['t']) {
  25749. if ($usedivletters) {
  25750. $lett = mb_strtoupper(mb_substr($this->Reference[$i]['t'],0,1,$this->mb_enc ),$this->mb_enc );
  25751. if ($lett != $last_lett) {
  25752. $save_bp = $this->breakpoints[$this->CurrCol]; // *COLUMNS*
  25753. $divlettjuststarted = true;
  25754. if ($i>0) {
  25755. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; margin-top: 0.5em; margin-collapse: collapse; '));
  25756. }
  25757. else {
  25758. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; '));
  25759. }
  25760. $this->textbuffer[] = array($lett,'',$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25761. $this->CloseTag('DIV');
  25762. }
  25763. }
  25764. $this->OpenTag('DIV',array('STYLE'=>'text-indent: -'.$offset.'mm; line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  25765. /*-- RTL --*/
  25766. // Change Arabic + Persian. to Presentation Forms
  25767. if ($this->biDirectional) { // mPDF 5.0.054
  25768. $this->Reference[$i]['t'] = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $this->Reference[$i]['t'] );
  25769. }
  25770. /*-- END RTL --*/
  25771. // Font-specific ligature substitution for Indic fonts
  25772. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($this->Reference[$i]['t']); // *INDIC*
  25773. $this->textbuffer[] = array($this->Reference[$i]['t'], '',$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25774. $ppp = $this->Reference[$i]['p']; // = array of page numbers to point to
  25775. if (count($ppp)) {
  25776. sort($ppp);
  25777. $newarr = array();
  25778. $range_start = $ppp[0];
  25779. $range_end = 0;
  25780. if (!$this->usingCoreFont) { $spacer = "\xc2\xa0 "; }
  25781. else { $spacer = chr(160).' '; }
  25782. $this->textbuffer[] = array($spacer, '',$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25783. if ($this->directionality == 'rtl') { $sep = '.'; $joiner = '-'; }
  25784. else { $sep = ', '; $joiner = '-'; }
  25785. for ($zi=1;$zi<count($ppp);$zi++) {
  25786. // RTL - Each number separately
  25787. if ($this->directionality == 'rtl') { // mPDF 5.0
  25788. /*-- RTL --*/
  25789. if ($zi<count($ppp)-1) {
  25790. $txt = $sep . $this->docPageNum($ppp[$zi]);
  25791. if ($useLinking) { $href = '@'.$ppp[$zi]; }
  25792. else { $href = ''; }
  25793. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25794. }
  25795. /*-- END RTL --*/
  25796. }
  25797. else if ($ppp[$zi] == ($ppp[($zi-1)]+1)) {
  25798. $range_end = $ppp[$zi];
  25799. }
  25800. else {
  25801. if ($range_end) {
  25802. if ($range_end == $range_start+1) {
  25803. if ($useLinking) { $href = '@'.$range_start; }
  25804. else { $href = ''; }
  25805. $txt = $this->docPageNum($range_start) . $sep;
  25806. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25807. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  25808. else { $href = ''; }
  25809. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  25810. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25811. }
  25812. else {
  25813. if ($useLinking) { $href = '@'.$range_start; }
  25814. else { $href = ''; }
  25815. }
  25816. }
  25817. else {
  25818. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  25819. else { $href = ''; }
  25820. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  25821. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25822. }
  25823. $range_start = $ppp[$zi];
  25824. $range_end = 0;
  25825. }
  25826. }
  25827. if ($range_end) {
  25828. if ($range_end == $range_start+1) {
  25829. if ($useLinking) { $href = '@'.$range_start; }
  25830. else { $href = ''; }
  25831. $txt = $this->docPageNum($range_start) . $sep;
  25832. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25833. if ($useLinking) { $href = '@'.$range_end; }
  25834. else { $href = ''; }
  25835. $txt = $this->docPageNum($range_end);
  25836. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25837. }
  25838. else {
  25839. if ($useLinking) { $href = '@'.$range_start; }
  25840. else { $href = ''; }
  25841. $txt = $this->docPageNum($range_start) . $joiner;
  25842. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25843. if ($useLinking) { $href = '@'.$range_end; }
  25844. else { $href = ''; }
  25845. $txt = $this->docPageNum($range_end);
  25846. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25847. }
  25848. }
  25849. else {
  25850. if ($useLinking) { $href = '@'.$ppp[(count($ppp)-1)]; }
  25851. else { $href = ''; }
  25852. $txt = $this->docPageNum($ppp[(count($ppp)-1)]);
  25853. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS); // mPDF 5.0.063
  25854. }
  25855. }
  25856. }
  25857. $this->CloseTag('DIV');
  25858. if ($divlettjuststarted) { $this->breakpoints[$this->CurrCol] = $save_bp; } // *COLUMNS*
  25859. $divlettjuststarted = false;
  25860. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  25861. $last_lett = $lett;
  25862. }
  25863. $this->CloseTag('DIV');
  25864. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  25865. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  25866. }
  25867. /*-- END INDEX --*/
  25868. function AcceptPageBreak() {
  25869. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  25870. /*-- COLUMNS --*/
  25871. if ($this->ColActive==1) {
  25872. if($this->CurrCol<$this->NbCol-1) {
  25873. //Go to the next column
  25874. $this->CurrCol++;
  25875. $this->SetCol($this->CurrCol);
  25876. $this->y=$this->y0;
  25877. $this->ChangeColumn=1; // Number (and direction) of columns changed +1, +2, -2 etc.
  25878. // DIRECTIONALITY RTL
  25879. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  25880. //Stay on the page
  25881. return false;
  25882. }
  25883. else {
  25884. //Go back to the first column - NEW PAGE
  25885. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  25886. $this->SetCol(0);
  25887. $this->ChangePage=1;
  25888. $this->y0 = $this->tMargin;
  25889. $this->ChangeColumn= -($this->NbCol-1);
  25890. // DIRECTIONALITY RTL
  25891. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  25892. //Page break
  25893. return true;
  25894. }
  25895. }
  25896. /*-- END COLUMNS --*/
  25897. /*-- TABLES --*/
  25898. else if ($this->table_rotate) {
  25899. if ($this->tablebuffer) { $this->printtablebuffer(); }
  25900. return true;
  25901. }
  25902. /*-- END TABLES --*/
  25903. else { // *COLUMNS*
  25904. $this->ChangeColumn=0;
  25905. return $this->autoPageBreak;
  25906. } // *COLUMNS*
  25907. return $this->autoPageBreak;
  25908. }
  25909. //----------- COLUMNS ---------------------
  25910. /*-- COLUMNS --*/
  25911. function SetColumns($NbCol,$vAlign='',$gap=5) {
  25912. // NbCol = number of columns
  25913. // CurrCol = Number of the current column starting at 0
  25914. // Called externally to set columns on/off and number
  25915. // Integer 2 upwards sets columns on to that number
  25916. // Anything less than 2 turns columns off
  25917. if ($NbCol<2) { // SET COLUMNS OFF
  25918. if ($this->ColActive) {
  25919. $this->ColActive=0;
  25920. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  25921. $this->NbCol=1;
  25922. $this->ResetMargins();
  25923. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  25924. $this->divwidth = 0;
  25925. $this->Ln();
  25926. }
  25927. $this->ColActive=0;
  25928. $this->columnbuffer = array();
  25929. $this->ColDetails = array();
  25930. $this->columnLinks = array();
  25931. $this->columnAnnots = array();
  25932. $this->col_Reference = array();
  25933. $this->col_BMoutlines = array();
  25934. $this->col_toc = array();
  25935. $this->breakpoints = array();
  25936. }
  25937. else { // SET COLUMNS ON
  25938. if ($this->ColActive) {
  25939. $this->ColActive=0;
  25940. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  25941. $this->ResetMargins();
  25942. }
  25943. if (isset($this->y) && $this->y>$this->tMargin) $this->Ln();
  25944. $this->NbCol=$NbCol;
  25945. $this->ColGap = $gap;
  25946. $this->divwidth = 0;
  25947. $this->ColActive=1;
  25948. $this->ColumnAdjust = true; // enables column height adjustment for the page
  25949. $this->columnbuffer = array();
  25950. $this->ColDetails = array();
  25951. $this->columnLinks = array();
  25952. $this->columnAnnots = array();
  25953. $this->col_Reference = array();
  25954. $this->col_BMoutlines = array();
  25955. $this->col_toc = array();
  25956. $this->breakpoints = array();
  25957. if ((strtoupper($vAlign) == 'J') || (strtoupper($vAlign) == 'JUSTIFY')) { $vAlign = 'J'; }
  25958. else { $vAlign = ''; }
  25959. $this->colvAlign = $vAlign;
  25960. //Save the ordinate
  25961. $absL = $this->DeflMargin-($gap/2);
  25962. $absR = $this->DefrMargin-($gap/2);
  25963. $PageWidth = $this->w-$absL-$absR; // virtual pagewidth for calculation only
  25964. $ColWidth = (($PageWidth - ($gap * ($NbCol)))/$NbCol);
  25965. $this->ColWidth = $ColWidth;
  25966. /*-- RTL --*/
  25967. if ($this->directionality == 'rtl') {
  25968. for ($i=0;$i<$this->NbCol;$i++) {
  25969. $this->ColL[$i] = $absL + ($gap/2) + (($NbCol - ($i+1))*($PageWidth/$NbCol)) ;
  25970. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  25971. }
  25972. }
  25973. else {
  25974. /*-- END RTL --*/
  25975. for ($i=0;$i<$this->NbCol;$i++) {
  25976. $this->ColL[$i] = $absL + ($gap/2) + ($i* ($PageWidth/$NbCol) );
  25977. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  25978. }
  25979. } // *RTL*
  25980. $this->pgwidth = $ColWidth;
  25981. $this->SetCol(0);
  25982. $this->y0=$this->GetY();
  25983. }
  25984. $this->x = $this->lMargin;
  25985. }
  25986. function SetCol($CurrCol) {
  25987. // Used internally to set column by number: 0 is 1st column
  25988. //Set position on a column
  25989. $this->CurrCol=$CurrCol;
  25990. $x = $this->ColL[$CurrCol];
  25991. $xR = $this->ColR[$CurrCol]; // NB This is not R margin -> R pos
  25992. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  25993. $x += $this->MarginCorrection ;
  25994. $xR += $this->MarginCorrection ;
  25995. }
  25996. $this->SetMargins($x,($this->w - $xR),$this->tMargin);
  25997. }
  25998. function AddColumn() {
  25999. $this->NewColumn();
  26000. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  26001. }
  26002. function NewColumn() {
  26003. if ($this->ColActive==1) {
  26004. if($this->CurrCol<$this->NbCol-1) {
  26005. //Go to the next column
  26006. $this->CurrCol++;
  26007. $this->SetCol($this->CurrCol);
  26008. $this->y = $this->y0;
  26009. $this->ChangeColumn=1;
  26010. // DIRECTIONALITY RTL
  26011. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26012. //Stay on the page
  26013. }
  26014. else {
  26015. //Go back to the first column
  26016. //Page break
  26017. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26018. $this->AddPage($this->CurOrientation);
  26019. $this->SetCol(0);
  26020. $this->ChangePage=1;
  26021. $this->y0 = $this->tMargin;
  26022. $this->ChangeColumn= -($this->NbCol-1);
  26023. // DIRECTIONALITY RTL
  26024. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26025. }
  26026. $this->x = $this->lMargin;
  26027. }
  26028. else {
  26029. $this->AddPage($this->CurOrientation);
  26030. }
  26031. }
  26032. function printcolumnbuffer() {
  26033. $k = $this->k;
  26034. // Columns ended (but page not ended) -> try to match all columns - unless disabled by using a custom column-break
  26035. if (!$this->ColActive && $this->ColumnAdjust && !$this->keepColumns) {
  26036. // Calculate adjustment to add to each column to calculate rel_y value
  26037. $this->ColDetails[0]['add_y'] = 0;
  26038. $last_col = 0;
  26039. // Recursively add previous column's height
  26040. for($i=1;$i<$this->NbCol;$i++) {
  26041. if (isset($this->ColDetails[$i]['bottom_margin']) && $this->ColDetails[$i]['bottom_margin']) { // If any entries in the column
  26042. $this->ColDetails[$i]['add_y'] = ($this->ColDetails[$i-1]['bottom_margin'] - $this->y0) + $this->ColDetails[$i-1]['add_y'];
  26043. $last_col = $i; // Last column actually printed
  26044. }
  26045. }
  26046. // Calculate value for each position sensitive entry as though for one column
  26047. foreach($this->columnbuffer AS $key=>$s) {
  26048. $t = $s['s'];
  26049. if (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) {
  26050. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26051. }
  26052. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) {
  26053. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26054. }
  26055. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) {
  26056. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26057. }
  26058. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) {
  26059. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26060. }
  26061. else if (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) {
  26062. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26063. }
  26064. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) {
  26065. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26066. }
  26067. }
  26068. $breaks = array();
  26069. foreach($this->breakpoints AS $c => $bpa) {
  26070. foreach($bpa AS $rely) {
  26071. $breaks[] = $rely + $this->ColDetails[$c]['add_y'] - $this->y0;
  26072. }
  26073. }
  26074. if (isset($this->ColDetails[$last_col]['bottom_margin'])) { $lcbm = $this->ColDetails[$last_col]['bottom_margin']; }
  26075. else { $lcbm = 0; }
  26076. $sum_h = $this->ColDetails[$last_col]['add_y'] + $lcbm - $this->y0;
  26077. //$sum_h = max($this->ColDetails[$last_col]['add_y'] + $this->ColDetails[$last_col]['bottom_margin'] - $this->y0, end($breaks));
  26078. $target_h = ($sum_h / $this->NbCol);
  26079. $cbr = array();
  26080. for($i=1;$i<$this->NbCol;$i++) {
  26081. $th = ($sum_h * $i / $this->NbCol);
  26082. foreach($breaks AS $bk=>$val) {
  26083. if ($val > $th) {
  26084. if (($val-$th) < ($th-$breaks[$bk-1])) { $cbr[$i-1] = $val; }
  26085. else { $cbr[$i-1] = $breaks[$bk-1]; }
  26086. break;
  26087. }
  26088. }
  26089. }
  26090. $cbr[($this->NbCol-1)] = $sum_h;
  26091. // Now update the columns - divide into columns of approximately equal value
  26092. $last_new_col = 0;
  26093. $yadj = 0; // mm
  26094. $xadj = 0;
  26095. $last_col_bottom = 0;
  26096. $lowest_bottom_y = 0;
  26097. $block_bottom = 0;
  26098. $newcolumn = 0;
  26099. foreach($this->columnbuffer AS $key=>$s) {
  26100. if (isset($s['rel_y'])) { // only process position sensitive data
  26101. if ($s['rel_y'] >= $cbr[$newcolumn]) {
  26102. $newcolumn++;
  26103. }
  26104. else {
  26105. $newcolumn = $last_new_col ;
  26106. }
  26107. $block_bottom = max($block_bottom,($s['rel_y']+$s['h']));
  26108. if ($this->directionality == 'rtl') { // *RTL*
  26109. $xadj = -(($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap)); // *RTL*
  26110. } // *RTL*
  26111. else { // *RTL*
  26112. $xadj = ($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap);
  26113. } // *RTL*
  26114. if ($last_new_col != $newcolumn) { // Added new column
  26115. $last_col_bottom = $this->columnbuffer[$key]['rel_y'];
  26116. $block_bottom = 0;
  26117. }
  26118. $yadj = ($s['rel_y'] - $s['y']) - ($last_col_bottom)+$this->y0;
  26119. // callback function in htmltoolkit
  26120. $t = $s['s'];
  26121. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->columnAdjustAdd('Td',$k,$xadj,$yadj,'\\1','\\2')",$t);
  26122. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->columnAdjustAdd('re',$k,$xadj,$yadj,'\\1','\\2','\\3','\\4')",$t);
  26123. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->columnAdjustAdd('l',$k,$xadj,$yadj,'\\1','\\2')",$t);
  26124. $t = preg_replace('/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/e',"\$this->columnAdjustAdd('img',$k,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5')",$t);
  26125. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->columnAdjustAdd('draw',$k,$xadj,$yadj,'\\1','\\2')",$t);
  26126. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) c/e',"\$this->columnAdjustAdd('bezier',$k,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  26127. $this->columnbuffer[$key]['s'] = $t;
  26128. $this->columnbuffer[$key]['newcol'] = $newcolumn;
  26129. $this->columnbuffer[$key]['newy'] = $s['y'] + $yadj;
  26130. $last_new_col = $newcolumn;
  26131. $clb = $s['y'] + $yadj + $s['h'] ; // bottom_margin of current
  26132. if ((isset($this->ColDetails[$newcolumn]['max_bottom']) && $clb > $this->ColDetails[$newcolumn]['max_bottom']) || (!isset($this->ColDetails[$newcolumn]['max_bottom']) && $clb)) { $this->ColDetails[$newcolumn]['max_bottom'] = $clb; }
  26133. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26134. // Adjust LINKS
  26135. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26136. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26137. $this->PageLinks[$this->page][$ref][0] += ($xadj*$k);
  26138. $this->PageLinks[$this->page][$ref][1] -= ($yadj*$k);
  26139. }
  26140. /*-- ANNOTATIONS --*/
  26141. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26142. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26143. if ($this->PageAnnots[$this->page][$ref]['x'] < 0) {
  26144. $this->PageAnnots[$this->page][$ref]['x'] -= ($xadj);
  26145. }
  26146. else {
  26147. $this->PageAnnots[$this->page][$ref]['x'] += ($xadj);
  26148. }
  26149. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); // unlike PageLinks, Page annots has y values from top in mm
  26150. }
  26151. /*-- END ANNOTATIONS --*/
  26152. }
  26153. }
  26154. /*-- BOOKMARKS --*/
  26155. // Adjust Bookmarks
  26156. foreach($this->col_BMoutlines AS $v) {
  26157. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26158. }
  26159. /*-- END BOOKMARKS --*/
  26160. /*-- INDEX --*/
  26161. // Adjust Reference (index)
  26162. foreach($this->col_Reference AS $v) {
  26163. $Present=0;
  26164. //Search the reference (AND Ref/PageNo) in the array
  26165. for ($i=0;$i<count($this->Reference);$i++){
  26166. if ($this->Reference[$i]['t']==$v['t']){
  26167. $Present=1;
  26168. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26169. $this->Reference[$i]['p'][] = $v['op'];
  26170. }
  26171. }
  26172. }
  26173. if ($Present==0) {
  26174. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26175. }
  26176. }
  26177. /*-- END INDEX --*/
  26178. /*-- TOC --*/
  26179. // Adjust ToC
  26180. foreach($this->col_toc AS $v) {
  26181. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26182. $this->links[$v['link']][1] = $this->y0;
  26183. }
  26184. /*-- END TOC --*/
  26185. // Adjust column length to be equal
  26186. if ($this->colvAlign == 'J') {
  26187. foreach($this->columnbuffer AS $key=>$s) {
  26188. if (isset($s['rel_y'])) { // only process position sensitive data
  26189. // Set ratio to expand y values or heights
  26190. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) { // mPDF 5.0.069
  26191. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26192. }
  26193. else { $ratio = 1; }
  26194. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26195. $yadj = ($s['newy'] - $this->y0) * ($ratio - 1);
  26196. // Adjust LINKS
  26197. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26198. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26199. $this->PageLinks[$this->page][$ref][1] -= ($yadj*$k); // y value
  26200. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26201. }
  26202. /*-- ANNOTATIONS --*/
  26203. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26204. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26205. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26206. }
  26207. /*-- END ANNOTATIONS --*/
  26208. }
  26209. }
  26210. }
  26211. $last_col = -1;
  26212. $trans_on = false;
  26213. foreach($this->columnbuffer AS $key=>$s) {
  26214. if (isset($s['rel_y'])) { // only process position sensitive data
  26215. // Set ratio to expand y values or heights
  26216. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) { // mPDF 5.0.069
  26217. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26218. }
  26219. else { $ratio = 1; }
  26220. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26221. //Start Transformation
  26222. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26223. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26224. $trans_on = true;
  26225. }
  26226. }
  26227. // Now output the adjusted values
  26228. $this->pages[$this->page] .= $s['s']."\n";
  26229. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) { // only process position sensitive data
  26230. //Stop Transformation
  26231. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26232. $trans_on = false; // mPDF 5.1.001
  26233. }
  26234. }
  26235. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; } // mPDF 5.1.001
  26236. }
  26237. else { // if NOT $this->colvAlign == 'J'
  26238. // Now output the adjusted values
  26239. foreach($this->columnbuffer AS $s) {
  26240. $this->pages[$this->page] .= $s['s']."\n";
  26241. }
  26242. }
  26243. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26244. }
  26245. // Columns not ended but new page -> align columns (can leave the columns alone - just tidy up the height)
  26246. else if ($this->colvAlign == 'J' && $this->ColumnAdjust && !$this->keepColumns) {
  26247. $k = $this->k;
  26248. // calculate the lowest bottom margin
  26249. $lowest_bottom_y = 0;
  26250. foreach($this->columnbuffer AS $key=>$s) {
  26251. // Only process output data
  26252. $t = $s['s'];
  26253. if ((preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) ||
  26254. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  26255. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  26256. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  26257. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  26258. $clb = $s['y'] + $s['h'];
  26259. if ((isset($this->ColDetails[$s['col']]['max_bottom']) && $clb > $this->ColDetails[$s['col']]['max_bottom']) || !isset($this->ColDetails[$s['col']]['max_bottom'])) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; }
  26260. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26261. $this->columnbuffer[$key]['rel_y'] = $s['y']; // Marks position sensitive data to process later
  26262. }
  26263. }
  26264. // Adjust column length equal
  26265. foreach($this->columnbuffer AS $key=>$s) {
  26266. // Set ratio to expand y values or heights
  26267. if (isset($this->ColDetails[$s['col']]['max_bottom']) && $this->ColDetails[$s['col']]['max_bottom']) {
  26268. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26269. }
  26270. else { $ratio = 1; }
  26271. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26272. $yadj = ($s['y'] - $this->y0) * ($ratio - 1);
  26273. // Adjust LINKS
  26274. if (isset($s['rel_y'])) { // only process position sensitive data
  26275. // otherwise triggers for all entries in column buffer (.e.g. formatting) and makes below adjustments more than once
  26276. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26277. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26278. $this->PageLinks[$this->page][$ref][1] -= ($yadj*$k); // y value
  26279. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26280. }
  26281. /*-- ANNOTATIONS --*/
  26282. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26283. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26284. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26285. }
  26286. /*-- END ANNOTATIONS --*/
  26287. }
  26288. }
  26289. }
  26290. /*-- BOOKMARKS --*/
  26291. // Adjust Bookmarks
  26292. foreach($this->col_BMoutlines AS $v) {
  26293. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26294. }
  26295. /*-- END BOOKMARKS --*/
  26296. /*-- INDEX --*/
  26297. // Adjust Reference (index)
  26298. foreach($this->col_Reference AS $v) {
  26299. $Present=0;
  26300. //Search the reference (AND Ref/PageNo) in the array
  26301. for ($i=0;$i<count($this->Reference);$i++){
  26302. if ($this->Reference[$i]['t']==$v['t']){
  26303. $Present=1;
  26304. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26305. $this->Reference[$i]['p'][] = $v['op'];
  26306. }
  26307. }
  26308. }
  26309. if ($Present==0) {
  26310. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26311. }
  26312. }
  26313. /*-- END INDEX --*/
  26314. /*-- TOC --*/
  26315. // Adjust ToC
  26316. foreach($this->col_toc AS $v) {
  26317. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26318. $this->links[$v['link']][1] = $this->y0;
  26319. }
  26320. /*-- END TOC --*/
  26321. $trans_on = false; // mPDF 5.1.001
  26322. foreach($this->columnbuffer AS $key=>$s) {
  26323. if (isset($s['rel_y'])) { // only process position sensitive data
  26324. // Set ratio to expand y values or heights
  26325. if ($this->ColDetails[$s['col']]['max_bottom']) {
  26326. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26327. }
  26328. else { $ratio = 1; }
  26329. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26330. //Start Transformation
  26331. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26332. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26333. $trans_on = true; // mPDF 5.1.001
  26334. }
  26335. }
  26336. // Now output the adjusted values
  26337. $this->pages[$this->page] .= $s['s']."\n";
  26338. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26339. //Stop Transformation
  26340. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26341. $trans_on = false; // mPDF 5.1.001
  26342. }
  26343. }
  26344. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; } // mPDF 5.1.001
  26345. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26346. }
  26347. // Just reproduce the page as it was
  26348. else {
  26349. // If page has not ended but height adjustment was disabled by custom column-break - adjust y
  26350. $k = $this->k;
  26351. $lowest_bottom_y = 0;
  26352. // if ((!$this->ColumnAdjust && !$this->ColActive) || $this->keepColumns) {
  26353. if (!$this->ColActive && (!$this->ColumnAdjust || $this->keepColumns)) {
  26354. // calculate the lowest bottom margin
  26355. foreach($this->columnbuffer AS $key=>$s) {
  26356. // Only process output data
  26357. $t = $s['s'];
  26358. if ((preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) ||
  26359. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  26360. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  26361. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  26362. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  26363. $clb = $s['y'] + $s['h'];
  26364. if ($clb > $this->ColDetails[$s['col']]['max_bottom']) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; }
  26365. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26366. }
  26367. }
  26368. }
  26369. foreach($this->columnbuffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  26370. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26371. /*-- INDEX --*/
  26372. // Output Reference (index)
  26373. foreach($this->col_Reference AS $v) {
  26374. $Present=0;
  26375. for ($i=0;$i<count($this->Reference);$i++){
  26376. if ($this->Reference[$i]['t']==$v['t']){
  26377. $Present=1;
  26378. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26379. $this->Reference[$i]['p'][] = $v['op'];
  26380. }
  26381. }
  26382. }
  26383. if ($Present==0) {
  26384. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26385. }
  26386. }
  26387. /*-- END INDEX --*/
  26388. /*-- BOOKMARKS --*/
  26389. // Output Bookmarks
  26390. foreach($this->col_BMoutlines AS $v) {
  26391. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26392. }
  26393. /*-- END BOOKMARKS --*/
  26394. /*-- TOC --*/
  26395. // Output ToC
  26396. foreach($this->col_toc AS $v) {
  26397. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26398. }
  26399. /*-- END TOC --*/
  26400. }
  26401. $this->columnbuffer = array();
  26402. $this->ColDetails = array();
  26403. $this->columnLinks = array();
  26404. $this->columnAnnots = array();
  26405. $this->col_Reference = array();
  26406. $this->col_BMoutlines = array();
  26407. $this->col_toc = array();
  26408. $this->breakpoints = array();
  26409. }
  26410. /*-- END COLUMNS --*/
  26411. //==================================================================
  26412. /*-- TABLES --*/
  26413. function printcellbuffer() {
  26414. if (count($this->cellBorderBuffer )) {
  26415. sort($this->cellBorderBuffer);
  26416. foreach($this->cellBorderBuffer AS $cbb) { // mPDF 5.0.051
  26417. $cba = unpack("A16dom/nbord/A1side/ns/dbw/nca/ncb/ncc/ncd/dce/dcf/A10style/dx/dy/dw/dh/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd/dover/", $cbb);
  26418. $side = $cba['side'];
  26419. $details = array();
  26420. $details[$side]['dom'] = (float) $cba['dom'];
  26421. $details[$side]['s'] = $cba['s'];
  26422. $details[$side]['w'] = $cba['bw'];
  26423. $details[$side]['c'][0] = $cba['ca']; // mPDF 5.0.051
  26424. $details[$side]['c'][1] = $cba['cb']; // mPDF 5.0.051
  26425. $details[$side]['c'][2] = $cba['cc']; // mPDF 5.0.051
  26426. $details[$side]['c'][3] = $cba['cd']; // mPDF 5.0.051
  26427. $details[$side]['c'][4] = $cba['ce']; // mPDF 5.0.051
  26428. $details[$side]['c'][5] = $cba['cf']; // mPDF 5.0.051
  26429. $details[$side]['style'] = trim($cba['style']);
  26430. $details['mbw']['BL'] = $cba['mbl'];
  26431. $details['mbw']['BR'] = $cba['mbr'];
  26432. $details['mbw']['RT'] = $cba['mrt'];
  26433. $details['mbw']['RB'] = $cba['mrb'];
  26434. $details['mbw']['TL'] = $cba['mtl'];
  26435. $details['mbw']['TR'] = $cba['mtr'];
  26436. $details['mbw']['LT'] = $cba['mlt'];
  26437. $details['mbw']['LB'] = $cba['mlb'];
  26438. $details['cellposdom'] = $cba['cpd'];
  26439. $details['p'] = $side;
  26440. if ($cba['over']==1) { $details[$side]['overlay'] = true; }
  26441. else { $details[$side]['overlay'] = false; }
  26442. $this->_tableRect($cba['x'],$cba['y'],$cba['w'],$cba['h'],$cba['bord'],$details, false, false);
  26443. }
  26444. $this->cellBorderBuffer = array();
  26445. }
  26446. }
  26447. //==================================================================
  26448. function printtablebuffer() {
  26449. if (!$this->table_rotate) {
  26450. $this->pages[$this->page] .= $this->tablebuffer;
  26451. foreach($this->tbrot_Links AS $p => $l) {
  26452. foreach($l AS $v) {
  26453. $this->PageLinks[$p][] = $v;
  26454. }
  26455. }
  26456. $this->tbrot_Links = array();
  26457. /*-- ANNOTATIONS --*/
  26458. foreach($this->tbrot_Annots AS $p => $l) {
  26459. foreach($l AS $v) {
  26460. $this->PageAnnots[$p][] = $v;
  26461. }
  26462. }
  26463. $this->tbrot_Annots = array();
  26464. /*-- END ANNOTATIONS --*/
  26465. /*-- INDEX --*/
  26466. // Output Reference (index)
  26467. foreach($this->tbrot_Reference AS $v) {
  26468. $Present=0;
  26469. for ($i=0;$i<count($this->Reference);$i++){
  26470. if ($this->Reference[$i]['t']==$v['t']){
  26471. $Present=1;
  26472. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26473. $this->Reference[$i]['p'][] = $v['op'];
  26474. }
  26475. }
  26476. }
  26477. if ($Present==0) {
  26478. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26479. }
  26480. }
  26481. $this->tbrot_Reference = array();
  26482. /*-- END INDEX --*/
  26483. /*-- BOOKMARKS --*/
  26484. // Output Bookmarks
  26485. foreach($this->tbrot_BMoutlines AS $v) {
  26486. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26487. }
  26488. $this->tbrot_BMoutlines = array();
  26489. /*-- END BOOKMARKS --*/
  26490. /*-- TOC --*/
  26491. // Output ToC
  26492. foreach($this->tbrot_toc AS $v) {
  26493. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26494. }
  26495. $this->tbrot_toc = array();
  26496. /*-- END TOC --*/
  26497. return;
  26498. }
  26499. // else if rotated
  26500. $lm = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'];
  26501. $pw = $this->blk[$this->blklvl]['inner_width'];
  26502. //Start Transformation
  26503. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26504. if ($this->table_rotate > 1) { // clockwise
  26505. if ($this->tbrot_align == 'L') {
  26506. $xadj = $this->tbrot_h ; // align L (as is)
  26507. }
  26508. else if ($this->tbrot_align == 'R') {
  26509. $xadj = $lm-$this->tbrot_x0+($pw) ; // align R
  26510. }
  26511. else {
  26512. $xadj = $lm-$this->tbrot_x0+(($pw + $this->tbrot_h)/2) ; // align C
  26513. }
  26514. $yadj = 0;
  26515. }
  26516. else { // anti-clockwise
  26517. if ($this->tbrot_align == 'L') {
  26518. $xadj = 0 ; // align L (as is)
  26519. }
  26520. else if ($this->tbrot_align == 'R') {
  26521. $xadj = $lm-$this->tbrot_x0+($pw - $this->tbrot_h) ; // align R
  26522. }
  26523. else {
  26524. $xadj = $lm-$this->tbrot_x0+(($pw - $this->tbrot_h)/2) ; // align C
  26525. }
  26526. $yadj = $this->tbrot_w;
  26527. }
  26528. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  26529. $this->pages[$this->page] .= $this->transformRotate($this->table_rotate, $this->tbrot_x0 , $this->tbrot_y0 , true)."\n";
  26530. // Now output the adjusted values
  26531. $this->pages[$this->page] .= $this->tablebuffer;
  26532. foreach($this->tbrot_Links AS $p => $l) {
  26533. foreach($l AS $v) {
  26534. $w = $v[2]/$this->k;
  26535. $h = $v[3]/$this->k;
  26536. $ax = ($v[0]/$this->k) - $this->tbrot_x0;
  26537. $ay = (($this->hPt-$v[1])/$this->k) - $this->tbrot_y0;
  26538. if ($this->table_rotate > 1) { // clockwise
  26539. $bx = $this->tbrot_x0+$xadj-$ay-$h;
  26540. $by = $this->tbrot_y0+$yadj+$ax;
  26541. }
  26542. else {
  26543. $bx = $this->tbrot_x0+$xadj+$ay;
  26544. $by = $this->tbrot_y0+$yadj-$ax-$w;
  26545. }
  26546. $v[0] = $bx*$this->k;
  26547. $v[1] = ($this->h-$by)*$this->k;
  26548. $v[2] = $h*$this->k; // swap width and height
  26549. $v[3] = $w*$this->k;
  26550. $this->PageLinks[$p][] = $v;
  26551. }
  26552. }
  26553. $this->tbrot_Links = array();
  26554. /*-- ANNOTATIONS --*/
  26555. foreach($this->tbrot_Annots AS $p => $l) {
  26556. foreach($l AS $v) {
  26557. // mPDF 5.0.048 annotSize removed as not required
  26558. $ax = abs($v['x']) - $this->tbrot_x0; // abs because -ve values are internally set and held for reference if annotMargin set
  26559. $ay = $v['y'] - $this->tbrot_y0;
  26560. if ($this->table_rotate > 1) { // clockwise
  26561. $bx = $this->tbrot_x0+$xadj-$ay;
  26562. $by = $this->tbrot_y0+$yadj+$ax;
  26563. }
  26564. else {
  26565. $bx = $this->tbrot_x0+$xadj+$ay;
  26566. $by = $this->tbrot_y0+$yadj-$ax;
  26567. }
  26568. if ($v['x'] < 0) {
  26569. $v['x'] = -$bx;
  26570. }
  26571. else {
  26572. $v['x'] = $bx;
  26573. }
  26574. $v['y'] = ($by);
  26575. $this->PageAnnots[$p][] = $v;
  26576. }
  26577. }
  26578. $this->tbrot_Annots = array();
  26579. /*-- END ANNOTATIONS --*/
  26580. /*-- BOOKMARKS --*/
  26581. // Adjust Bookmarks
  26582. foreach($this->tbrot_BMoutlines AS $v) {
  26583. $v['y'] = $this->tbrot_y0;
  26584. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  26585. }
  26586. /*-- END BOOKMARKS --*/
  26587. /*-- INDEX --*/
  26588. // Adjust Reference (index)
  26589. foreach($this->tbrot_Reference AS $v) {
  26590. $Present=0;
  26591. //Search the reference (AND Ref/PageNo) in the array
  26592. for ($i=0;$i<count($this->Reference);$i++){
  26593. if ($this->Reference[$i]['t']==$v['t']){
  26594. $Present=1;
  26595. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  26596. $this->Reference[$i]['p'][] = $this->page;
  26597. }
  26598. }
  26599. }
  26600. if ($Present==0) {
  26601. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  26602. }
  26603. }
  26604. /*-- END INDEX --*/
  26605. /*-- TOC --*/
  26606. // Adjust ToC - uses document page number
  26607. foreach($this->tbrot_toc AS $v) {
  26608. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26609. $this->links[$v['link']][1] = $this->tbrot_y0;
  26610. }
  26611. /*-- END TOC --*/
  26612. $this->tbrot_Reference = array();
  26613. $this->tbrot_BMoutlines = array();
  26614. $this->tbrot_toc = array();
  26615. //Stop Transformation
  26616. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26617. $this->y = $this->tbrot_y0 + $this->tbrot_w;
  26618. $this->x = $this->lMargin;
  26619. $this->tablebuffer = '';
  26620. }
  26621. //==================================================================
  26622. // Keep-with-table This buffers contents of h1-6 to keep on page with table
  26623. function printkwtbuffer() {
  26624. if (!$this->kwt_moved) {
  26625. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  26626. foreach($this->kwt_Links AS $p => $l) {
  26627. foreach($l AS $v) {
  26628. $this->PageLinks[$p][] = $v;
  26629. }
  26630. }
  26631. $this->kwt_Links = array();
  26632. /*-- ANNOTATIONS --*/
  26633. foreach($this->kwt_Annots AS $p => $l) {
  26634. foreach($l AS $v) {
  26635. $this->PageAnnots[$p][] = $v;
  26636. }
  26637. }
  26638. $this->kwt_Annots = array();
  26639. /*-- END ANNOTATIONS --*/
  26640. /*-- INDEX --*/
  26641. // Output Reference (index)
  26642. foreach($this->kwt_Reference AS $v) {
  26643. $Present=0;
  26644. for ($i=0;$i<count($this->Reference);$i++){
  26645. if ($this->Reference[$i]['t']==$v['t']){
  26646. $Present=1;
  26647. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26648. $this->Reference[$i]['p'][] = $v['op'];
  26649. }
  26650. }
  26651. }
  26652. if ($Present==0) {
  26653. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26654. }
  26655. }
  26656. $this->kwt_Reference = array();
  26657. /*-- END INDEX --*/
  26658. /*-- BOOKMARKS --*/
  26659. // Output Bookmarks
  26660. foreach($this->kwt_BMoutlines AS $v) {
  26661. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26662. }
  26663. $this->kwt_BMoutlines = array();
  26664. /*-- END BOOKMARKS --*/
  26665. /*-- TOC --*/
  26666. // Output ToC
  26667. foreach($this->kwt_toc AS $v) {
  26668. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26669. }
  26670. $this->kwt_toc = array();
  26671. /*-- END TOC --*/
  26672. return;
  26673. }
  26674. //Start Transformation
  26675. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26676. $xadj = $this->lMargin - $this->kwt_x0 ;
  26677. //$yadj = $this->y - $this->kwt_y0 ;
  26678. $yadj = $this->tMargin - $this->kwt_y0 ;
  26679. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  26680. // Now output the adjusted values
  26681. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  26682. // Adjust hyperLinks
  26683. foreach($this->kwt_Links AS $p => $l) {
  26684. foreach($l AS $v) {
  26685. $bx = $this->kwt_x0+$xadj;
  26686. $by = $this->kwt_y0+$yadj;
  26687. $v[0] = $bx*$this->k;
  26688. $v[1] = ($this->h-$by)*$this->k;
  26689. $this->PageLinks[$p][] = $v;
  26690. }
  26691. }
  26692. /*-- ANNOTATIONS --*/
  26693. foreach($this->kwt_Annots AS $p => $l) {
  26694. foreach($l AS $v) {
  26695. // mPDF 5.0.048 annotSize removed as not required
  26696. $bx = $this->kwt_x0+$xadj;
  26697. $by = $this->kwt_y0+$yadj;
  26698. if ($v['x'] < 0) {
  26699. $v['x'] = -$bx;
  26700. }
  26701. else {
  26702. $v['x'] = $bx;
  26703. }
  26704. $v['y'] = $by;
  26705. $this->PageAnnots[$p][] = $v;
  26706. }
  26707. }
  26708. /*-- END ANNOTATIONS --*/
  26709. /*-- BOOKMARKS --*/
  26710. // Adjust Bookmarks
  26711. foreach($this->kwt_BMoutlines AS $v) {
  26712. if ($v['y'] != 0) { $v['y'] += $yadj; }
  26713. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  26714. }
  26715. /*-- END BOOKMARKS --*/
  26716. /*-- INDEX --*/
  26717. // Adjust Reference (index)
  26718. foreach($this->kwt_Reference AS $v) {
  26719. $Present=0;
  26720. //Search the reference (AND Ref/PageNo) in the array
  26721. for ($i=0;$i<count($this->Reference);$i++){
  26722. if ($this->Reference[$i]['t']==$v['t']){
  26723. $Present=1;
  26724. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  26725. $this->Reference[$i]['p'][] = $this->page;
  26726. }
  26727. }
  26728. }
  26729. if ($Present==0) {
  26730. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  26731. }
  26732. }
  26733. /*-- END INDEX --*/
  26734. /*-- TOC --*/
  26735. // Adjust ToC
  26736. foreach($this->kwt_toc AS $v) {
  26737. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26738. $this->links[$v['link']][0] = $this->page;
  26739. $this->links[$v['link']][1] += $yadj;
  26740. }
  26741. /*-- END TOC --*/
  26742. $this->kwt_Links = array();
  26743. $this->kwt_Annots = array();
  26744. $this->kwt_Reference = array();
  26745. $this->kwt_BMoutlines = array();
  26746. $this->kwt_toc = array();
  26747. //Stop Transformation
  26748. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26749. $this->kwt_buffer = array();
  26750. $this->y += $this->kwt_height;
  26751. }
  26752. /*-- END TABLES --*/
  26753. //==================================================================
  26754. function printfloatbuffer() {
  26755. if (count($this->floatbuffer)) {
  26756. $this->objectbuffer = $this->floatbuffer;
  26757. $this->printobjectbuffer(false);
  26758. $this->objectbuffer = array();
  26759. $this->floatbuffer = array();
  26760. $this->floatmargins = array();
  26761. }
  26762. }
  26763. //==================================================================
  26764. function printdivbuffer() {
  26765. $k = $this->k;
  26766. $p1 = $this->blk[$this->blklvl]['startpage'];
  26767. $p2 = $this->page;
  26768. $bottom[$p1] = $this->ktBlock[$p1]['bottom_margin'];
  26769. $bottom[$p2] = $this->y; // $this->ktBlock[$p2]['bottom_margin'];
  26770. $top[$p1] = $this->kt_y00; // mPDF 5.0
  26771. $top2 = $this->h;
  26772. foreach($this->divbuffer AS $key=>$s) {
  26773. if ($s['page'] == $p2) {
  26774. $top2 = MIN($s['y'], $top2);
  26775. }
  26776. }
  26777. $top[$p2] = $top2;
  26778. $height[$p1] = ($bottom[$p1] - $top[$p1]);
  26779. $height[$p2] = ($bottom[$p2] - $top[$p2]);
  26780. $xadj[$p1] = $this->MarginCorrection;
  26781. $yadj[$p1] = -($top[$p1] - $top[$p2]);
  26782. $xadj[$p2] = 0;
  26783. $yadj[$p2] = $height[$p1];
  26784. if ($this->ColActive || !$this->keep_block_together || $this->blk[$this->blklvl]['startpage'] == $this->page || ($this->page - $this->blk[$this->blklvl]['startpage']) > 1 || ($height[$p1]+$height[$p2]) > $this->h) {
  26785. foreach($this->divbuffer AS $s) { $this->pages[$s['page']] .= $s['s']."\n"; }
  26786. foreach($this->ktLinks AS $p => $l) {
  26787. foreach($l AS $v) {
  26788. $this->PageLinks[$p][] = $v;
  26789. }
  26790. }
  26791. /*-- ANNOTATIONS --*/
  26792. foreach($this->ktAnnots AS $p => $l) {
  26793. foreach($l AS $v) {
  26794. $this->PageAnnots[$p][] = $v;
  26795. }
  26796. }
  26797. /*-- END ANNOTATIONS --*/
  26798. /*-- INDEX --*/
  26799. // Adjust Reference (index)
  26800. foreach($this->ktReference AS $v) {
  26801. $Present=0;
  26802. //Search the reference (AND Ref/PageNo) in the array
  26803. for ($i=0;$i<count($this->Reference);$i++){
  26804. if ($this->Reference[$i]['t']==$v['t']){
  26805. $Present=1;
  26806. if (!in_array($p2,$this->Reference[$i]['p'])) {
  26807. $this->Reference[$i]['p'][] = $p2;
  26808. }
  26809. }
  26810. }
  26811. //If not found, add it
  26812. if ($Present==0) {
  26813. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  26814. }
  26815. }
  26816. /*-- END INDEX --*/
  26817. /*-- BOOKMARKS --*/
  26818. // Adjust Bookmarks
  26819. foreach($this->ktBMoutlines AS $v) {
  26820. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26821. }
  26822. /*-- END BOOKMARKS --*/
  26823. /*-- TOC --*/
  26824. // Adjust ToC
  26825. foreach($this->_kttoc AS $v) {
  26826. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26827. }
  26828. /*-- END TOC --*/
  26829. $this->divbuffer = array();
  26830. $this->ktLinks = array();
  26831. $this->ktAnnots = array();
  26832. $this->ktBlock = array();
  26833. $this->ktReference = array();
  26834. $this->ktBMoutlines = array();
  26835. $this->_kttoc = array();
  26836. $this->keep_block_together = 0;
  26837. return;
  26838. }
  26839. else {
  26840. // mPDF 5.0 Move stuff before ___PAGE___START marker and put it after ___HEADER_MARKER
  26841. $np = '';
  26842. $pre = '';
  26843. $ispre = true;
  26844. foreach($this->divbuffer AS $key=>$s) {
  26845. // callback function
  26846. $t = $s['s'];
  26847. $p = $s['page'];
  26848. if (preg_match('/(___PAGE___START'.date('jY').')/', $t)) { $ispre = false; }
  26849. else if (preg_match('/(___HEADER___MARKER'.date('jY').')/', $t)) {
  26850. $np .= $t."\n".$pre;
  26851. continue;
  26852. }
  26853. else {
  26854. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->blockAdjust('Td',$k,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  26855. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->blockAdjust('re',$k,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4')",$t);
  26856. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->blockAdjust('l',$k,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  26857. $t = preg_replace('/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/e',"\$this->blockAdjust('img',$k,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5')",$t);
  26858. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->blockAdjust('draw',$k,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  26859. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) c/e',"\$this->blockAdjust('bezier',$k,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  26860. }
  26861. // mPDF 5.0
  26862. if ($ispre) $pre .= $t."\n";
  26863. else $np .= $t."\n";
  26864. }
  26865. // mPDF 5.0
  26866. if ($ispre && $pre) $np = $pre ."\n". $np; // Failsafe
  26867. $this->pages[$this->page] .= $np;
  26868. // Adjust hyperLinks
  26869. foreach($this->ktLinks AS $p => $l) {
  26870. foreach($l AS $v) {
  26871. $v[0] += ($xadj[$p]*$k);
  26872. $v[1] -= ($yadj[$p]*$k);
  26873. $this->PageLinks[$p2][] = $v;
  26874. }
  26875. }
  26876. /*-- ANNOTATIONS --*/
  26877. foreach($this->ktAnnots AS $p => $l) {
  26878. foreach($l AS $v) {
  26879. if ($v['x']>0) { $v['x'] += $xadj[$p]; }
  26880. else if ($v['x']<0) { $v['x'] -= $xadj[$p]; }
  26881. $v['y'] += $yadj[$p];
  26882. $this->PageAnnots[$p2][] = $v;
  26883. }
  26884. }
  26885. /*-- END ANNOTATIONS --*/
  26886. /*-- BOOKMARKS --*/
  26887. // Adjust Bookmarks
  26888. foreach($this->ktBMoutlines AS $v) {
  26889. if ($v['y'] != 0) { $v['y'] += ($yadj[$v['p']]); }
  26890. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$p2);
  26891. }
  26892. /*-- END BOOKMARKS --*/
  26893. /*-- INDEX --*/
  26894. // Adjust Reference (index)
  26895. foreach($this->ktReference AS $v) {
  26896. $Present=0;
  26897. //Search the reference (AND Ref/PageNo) in the array
  26898. for ($i=0;$i<count($this->Reference);$i++){
  26899. if ($this->Reference[$i]['t']==$v['t']){
  26900. $Present=1;
  26901. if (!in_array($p2,$this->Reference[$i]['p'])) {
  26902. $this->Reference[$i]['p'][] = $p2;
  26903. }
  26904. }
  26905. }
  26906. //If not found, add it
  26907. if ($Present==0) {
  26908. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  26909. }
  26910. }
  26911. /*-- END INDEX --*/
  26912. /*-- TOC --*/
  26913. // Adjust ToC
  26914. foreach($this->_kttoc AS $v) {
  26915. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$p2,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26916. $this->links[$v['link']][0] = $p2;
  26917. $this->links[$v['link']][1] += $yadj[$p];
  26918. }
  26919. /*-- END TOC --*/
  26920. $this->y = $top[$p2] + $height[$p1] + $height[$p2];
  26921. $this->x = $this->lMargin;
  26922. $this->divbuffer = array();
  26923. $this->ktLinks = array();
  26924. $this->ktAnnots = array();
  26925. $this->ktBlock = array();
  26926. $this->ktReference = array();
  26927. $this->ktBMoutlines = array();
  26928. $this->_kttoc = array();
  26929. $this->keep_block_together = 0;
  26930. }
  26931. }
  26932. //==================================================================
  26933. // Added ELLIPSES and CIRCLES
  26934. function Circle($x,$y,$r,$style='S') {
  26935. $this->Ellipse($x,$y,$r,$r,$style);
  26936. }
  26937. function Ellipse($x,$y,$rx,$ry,$style='S') {
  26938. if($style=='F') { $op='f'; }
  26939. elseif($style=='FD' or $style=='DF') { $op='B'; }
  26940. else { $op='S'; }
  26941. $lx=4/3*(M_SQRT2-1)*$rx;
  26942. $ly=4/3*(M_SQRT2-1)*$ry;
  26943. $k=$this->k;
  26944. $h=$this->h;
  26945. $this->_out(sprintf('%.3f %.3f m %.3f %.3f %.3f %.3f %.3f %.3f c', ($x+$rx)*$k,($h-$y)*$k, ($x+$rx)*$k,($h-($y-$ly))*$k, ($x+$lx)*$k,($h-($y-$ry))*$k, $x*$k,($h-($y-$ry))*$k));
  26946. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c', ($x-$lx)*$k,($h-($y-$ry))*$k, ($x-$rx)*$k,($h-($y-$ly))*$k, ($x-$rx)*$k,($h-$y)*$k));
  26947. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c', ($x-$rx)*$k,($h-($y+$ly))*$k, ($x-$lx)*$k,($h-($y+$ry))*$k, $x*$k,($h-($y+$ry))*$k));
  26948. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c %s', ($x+$lx)*$k,($h-($y+$ry))*$k, ($x+$rx)*$k,($h-($y+$ly))*$k, ($x+$rx)*$k,($h-$y)*$k, $op));
  26949. }
  26950. /*-- DIRECTW --*/
  26951. // Added adaptation of shaded_box = AUTOSIZE-TEXT
  26952. function AutosizeText($text,$w,$font,$style,$szfont=72) {
  26953. $text = $this->purify_utf8_text($text);
  26954. if ($this->text_input_as_HTML) {
  26955. $text = $this->all_entities_to_utf8($text);
  26956. }
  26957. if ($this->onlyCoreFonts) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  26958. $text = ' '.$text.' ';
  26959. $width = $this->ConvertSize($w);
  26960. $loop = 0;
  26961. while ( $loop == 0 ) {
  26962. $this->SetFont($font,$style,$szfont);
  26963. $sz = $this->GetStringWidth( $text );
  26964. if ( $sz > $w ) { $szfont --; }
  26965. else { $loop ++; }
  26966. }
  26967. $this->SetFont($font,$style,$szfont);
  26968. $this->Cell($w, 0, $text, 0, 0, "C");
  26969. }
  26970. /*-- END DIRECTW --*/
  26971. // ====================================================
  26972. // ====================================================
  26973. /*-- RTL --*/
  26974. function reverse_letters($str) {
  26975. $str = strtr($str, '{}[]()', '}{][)(');
  26976. return $this->mb_strrev($str, $this->mb_enc);
  26977. }
  26978. function magic_reverse_dir(&$chunk, $join=true, $dir) { // mPDF 5.0.054
  26979. if ($this->usingCoreFont) { return 0; }
  26980. if ($this->biDirectional) { // mPDF 5.0.054
  26981. // Change Arabic + Persian. to Presentation Forms
  26982. if ($join) {
  26983. $chunk = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $chunk );
  26984. }
  26985. $contains_rtl = false;
  26986. $all_rtl = true;
  26987. $initSpace = false; // mPDF 5.0.071
  26988. $endSpace = false; // mPDF 5.0.071
  26989. $nonDirchars = "\x{A0}\"\'\(\)\{\}\[\].,:\-=";
  26990. if (preg_match("/[".$this->pregRTLchars."]/u",$chunk)) { // Chunk contains RTL characters
  26991. if (preg_match("/^[ ]/",$chunk)) { $initSpace = true; $chunk = preg_replace("/^[ ]/",'',$chunk); } // mPDF 5.0.071
  26992. if (preg_match("/[ ]$/",$chunk)) { $endSpace = true; $chunk = preg_replace("/[ ]$/",'',$chunk); } // mPDF 5.0.071
  26993. if (preg_match("/[^".$this->pregRTLchars.$nonDirchars." ]/u",$chunk)) { // Chunk also contains LTR characters (added , mPDF 4.0)
  26994. $all_rtl = false;
  26995. // mPDF 5.0.054
  26996. if ($dir == 'rtl') { // mPDF 5.0.071
  26997. $chunk = preg_replace("/([^".$this->pregRTLchars.$nonDirchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[^".$this->pregRTLchars.$nonDirchars."])/u","\\1\x07\\2",$chunk);
  26998. }
  26999. $chunk = preg_replace("/([".$this->pregRTLchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[".$this->pregRTLchars."])/u","\\1\x07\\2",$chunk);
  27000. $bits = explode(' ',$chunk);
  27001. foreach($bits AS $bitkey=>$bit) {
  27002. $bit = preg_replace("/\x07/"," ",$bit); // mPDF 5.0.054
  27003. if (preg_match("/^[".$this->pregRTLchars.$nonDirchars." ]*$/u",$bit)) { // mPDF 5.0.071
  27004. $bits[$bitkey] = $this->reverse_letters($bit);
  27005. }
  27006. // mPDF 5.0.071
  27007. else if (preg_match("/[".$this->pregRTLchars."]/u",$bit)) {
  27008. if ($dir == 'rtl') {
  27009. $bit = preg_replace("/([^".$this->pregRTLchars.$nonDirchars." ])([".$nonDirchars."]*[".$this->pregRTLchars."])/u","\\1\x07\\2",$bit );
  27010. $bit = preg_replace("/([".$this->pregRTLchars."][".$nonDirchars."]*)([^".$this->pregRTLchars.$nonDirchars." ])/u","\\1\x07\\2",$bit );
  27011. }
  27012. else {
  27013. $bit = preg_replace("/([^".$this->pregRTLchars." ][".$nonDirchars."]*)([".$this->pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27014. $bit = preg_replace("/([".$this->pregRTLchars." ])([".$nonDirchars."]*[^".$this->pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27015. }
  27016. $sbits = explode("\x07",$bit );
  27017. foreach($sbits AS $sbitkey=>$sbit) {
  27018. $sbit = preg_replace("/\x07/","",$sbit);
  27019. if (preg_match("/^[".$this->pregRTLchars.$nonDirchars." ]*$/u",$sbit)) {
  27020. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27021. }
  27022. else if (preg_match("/[".$this->pregRTLchars."]/u",$sbit) && $dir=='rtl') {
  27023. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27024. }
  27025. else {
  27026. $sbits[$sbitkey] = $sbit;
  27027. }
  27028. }
  27029. if ($dir == 'rtl') { $sbits = array_reverse($sbits,false); }
  27030. $bits[$bitkey] = implode('',$sbits);
  27031. }
  27032. else if (preg_match("/[".$this->pregRTLchars."]/u",$bit) && $dir=='rtl') { // mPDF 5.0.071
  27033. $bits[$bitkey] = $this->reverse_letters($bit);
  27034. }
  27035. else {
  27036. $bits[$bitkey] = $bit;
  27037. }
  27038. }
  27039. if ($dir == 'rtl') { $bits = array_reverse($bits,false); } // mPDF 5.0.054
  27040. $chunk = implode(' ',$bits);
  27041. }
  27042. else { $chunk = $this->reverse_letters($chunk); }
  27043. $contains_rtl = true;
  27044. // mPDF 5.0.054 Un-Reverse numerals back to ltr
  27045. $chunk = preg_replace("/([\x{0660}-\x{0669}]+)/ue", '$this->reverse_letters(\'\\1\')', $chunk );
  27046. // mPDF 5.0.071
  27047. if ($dir == 'rtl') {
  27048. if ($endSpace) { $chunk = ' '.$chunk; }
  27049. if ($initSpace) { $chunk .= ' '; }
  27050. }
  27051. else {
  27052. if ($initSpace) { $chunk = ' '.$chunk; }
  27053. if ($endSpace) { $chunk .= ' '; }
  27054. }
  27055. }
  27056. else { $all_rtl = false; }
  27057. if ($all_rtl) { return 2; }
  27058. else if ($contains_rtl) { return 1; }
  27059. else { return 0; }
  27060. }
  27061. return 0;
  27062. }
  27063. /*-- END RTL --*/
  27064. //
  27065. // ****************************
  27066. // ****************************
  27067. function SetSubstitutions() {
  27068. $subsarray = array();
  27069. @include(_MPDF_PATH.'includes/subs_win-1252.php');
  27070. $this->substitute = array();
  27071. foreach($subsarray AS $key => $val) {
  27072. $this->substitute[code2utf($key)] = $val;
  27073. }
  27074. }
  27075. function SubstituteChars($html) {
  27076. // only substitute characters between tags
  27077. if (count($this->substitute)) {
  27078. $a=preg_split('/(<.*?>)/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  27079. $html = '';
  27080. foreach($a as $i => $e) {
  27081. if($i%2==0) {
  27082. $e = strtr($e, $this->substitute);
  27083. }
  27084. $html .= $e;
  27085. }
  27086. }
  27087. return $html;
  27088. }
  27089. // mPDF 5.0
  27090. function SubstituteCharsSIP(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27091. if (preg_match("/^(.*?)([\x{20000}-\x{2FFFF}]+)(.*)/u", $writehtml_e, $m)) {
  27092. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27093. $font = $this->CurrentFont['sipext'];
  27094. if (!in_array($font, $this->available_unifonts)) { return 0; }
  27095. $writehtml_a[$writehtml_i] = $writehtml_e = $m[1];
  27096. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27097. $this->subPos = $writehtml_i;
  27098. return 4;
  27099. }
  27100. }
  27101. return 0;
  27102. }
  27103. function SubstituteCharsMB(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27104. $cw = &$this->CurrentFont['cw'];
  27105. $unicode = $this->UTF8StringToArray($writehtml_e, false);
  27106. $start = -1;
  27107. $end = 0;
  27108. $flag = 0;
  27109. $ftype = '';
  27110. $u = array();
  27111. foreach($unicode AS $c => $char) {
  27112. // mPDF 5.0
  27113. if (($flag == 0 || $flag==2) && (!$this->_charDefined($cw,$char) || ($flag==2 && $char==32)) && $this->checkSIP && $char > 131071) { // Unicode Plane 2 (SIP)
  27114. if (in_array($this->FontFamily ,$this->available_CJK_fonts)) { return 0; }
  27115. if ($flag==0) { $start=$c; }
  27116. $flag=2;
  27117. $u[] = $char;
  27118. }
  27119. // mPDF5.0
  27120. //else if (($flag == 0 || $flag==1) && $char != 173 && !$this->_charDefined($cw,$char) && ($char<1423 || ($char>3583 && $char < 11263))) {
  27121. else if (($flag == 0 || $flag==1) && $char != 173 && (!$this->_charDefined($cw,$char) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) {
  27122. if ($flag==0) { $start=$c; }
  27123. $flag=1;
  27124. $u[] = $char;
  27125. }
  27126. else if ($flag>0) { $end=$c-1; break; }
  27127. }
  27128. if ($flag>0 && !$end) { $end=count($unicode)-1; }
  27129. if ($start==-1) { return 0; }
  27130. if ($flag == 2) { // SIP
  27131. // Check if current CJK font has a ext-B related font
  27132. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27133. $font = $this->CurrentFont['sipext'];
  27134. unset($cw);
  27135. $cw = '';
  27136. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27137. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27138. else {
  27139. $prevFontFamily = $this->FontFamily;
  27140. $prevFontStyle = $this->currentfontstyle;
  27141. $prevFontSizePt = $this->FontSizePt;
  27142. $this->SetFont($font, '', '', false);
  27143. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27144. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27145. }
  27146. if (!$cw) { return 0; }
  27147. $l = 0;
  27148. foreach($u AS $char) {
  27149. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27150. $l++;
  27151. }
  27152. else { break; }
  27153. }
  27154. if ($l > 0) {
  27155. $patt = mb_substr($writehtml_e, $start, $l);
  27156. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27157. $writehtml_e = $m[1];
  27158. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27159. $this->subPos = $writehtml_i+3;
  27160. return 4;
  27161. }
  27162. }
  27163. }
  27164. // Check Backup SIP font (defined in config_fonts.php)
  27165. if (isset($this->backupSIPFont) && $this->backupSIPFont) {
  27166. if ($this->currentfontfamily != $this->backupSIPFont) { $font = $this->backupSIPFont; }
  27167. else { unset($cw); return 0; }
  27168. unset($cw);
  27169. $cw = '';
  27170. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27171. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27172. else {
  27173. $prevFontFamily = $this->FontFamily;
  27174. $prevFontStyle = $this->currentfontstyle;
  27175. $prevFontSizePt = $this->FontSizePt;
  27176. $this->SetFont($this->backupSIPFont, '', '', false);
  27177. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27178. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27179. }
  27180. if (!$cw) { return 0; }
  27181. $l = 0;
  27182. foreach($u AS $char) {
  27183. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27184. $l++;
  27185. }
  27186. else { break; }
  27187. }
  27188. if ($l > 0) {
  27189. $patt = mb_substr($writehtml_e, $start, $l);
  27190. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27191. $writehtml_e = $m[1];
  27192. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27193. $this->subPos = $writehtml_i+3;
  27194. return 4;
  27195. }
  27196. }
  27197. }
  27198. return 0;
  27199. }
  27200. // FIRST TRY CORE FONTS
  27201. if (!$this->PDFA && !$this->PDFX) {
  27202. $repl = array(); // mPDF 5.0
  27203. if (!$this->subArrMB) {
  27204. include(_MPDF_PATH.'includes/subs_core.php');
  27205. $this->subArrMB['a'] = $aarr;
  27206. $this->subArrMB['s'] = $sarr;
  27207. $this->subArrMB['z'] = $zarr;
  27208. }
  27209. if (isset($this->subArrMB['a'][$u[0]])) {
  27210. $font = 'tta'; $ftype = 'C';
  27211. foreach($u AS $char) {
  27212. if ($this->subArrMB['a'][$char]) { $repl[] = $this->subArrMB['a'][$char]; }
  27213. else { break; }
  27214. }
  27215. }
  27216. else if (isset($this->subArrMB['z'][$u[0]])) {
  27217. $font = 'ttz'; $ftype = 'C';
  27218. foreach($u AS $char) {
  27219. if ($this->subArrMB['z'][$char]) { $repl[] = $this->subArrMB['z'][$char]; }
  27220. else { break; }
  27221. }
  27222. }
  27223. else if (isset($this->subArrMB['s'][$u[0]])) {
  27224. $font = 'tts'; $ftype = 'C';
  27225. foreach($u AS $char) {
  27226. if ($this->subArrMB['s'][$char]) { $repl[] = $this->subArrMB['s'][$char]; }
  27227. else { break; }
  27228. }
  27229. }
  27230. if ($ftype=='C') {
  27231. $patt = mb_substr($writehtml_e, $start, count($repl));
  27232. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27233. $writehtml_e = $m[1];
  27234. array_splice($writehtml_a, $writehtml_i+1, 0, array($font, implode('|', $repl), '/'.$font, $m[3])); // e.g. <tts>
  27235. $this->subPos = $writehtml_i+3;
  27236. return 4;
  27237. }
  27238. return 0;
  27239. }
  27240. }
  27241. // FIND IN DEFAULT FONT - removed mPDF 5.0
  27242. // LASTLY TRY IN BACKUP SUBS FONT
  27243. if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); }
  27244. foreach($this->backupSubsFont AS $bsfctr=>$bsf) { // mPDF 5.0Beta.02
  27245. if ($this->currentfontfamily != $bsf) { $font = $bsf; } // mPDF 5.0 not font['name']
  27246. else { continue; }
  27247. unset($cw);
  27248. $cw = '';
  27249. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27250. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27251. else {
  27252. $prevFontFamily = $this->FontFamily;
  27253. $prevFontStyle = $this->currentfontstyle;
  27254. $prevFontSizePt = $this->FontSizePt;
  27255. $this->SetFont($bsf, '', '', false);
  27256. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27257. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27258. }
  27259. if (!$cw) { continue; }
  27260. $l = 0;
  27261. foreach($u AS $char) {
  27262. // mPDF 5.0
  27263. //if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1422 && $char<3584) || $char > 11262) { // Arabic and Indic & CJK
  27264. if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) { // Arabic and Indic
  27265. $l++;
  27266. }
  27267. else { // mPDF 5.0
  27268. if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font
  27269. $cont = mb_substr($writehtml_e, $start+1);
  27270. $writehtml_e = mb_substr($writehtml_e, 0, $start+1);
  27271. array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont));
  27272. $this->subPos = $writehtml_i+1;
  27273. return 2;
  27274. }
  27275. else { break; }
  27276. }
  27277. }
  27278. if ($l > 0) {
  27279. $patt = mb_substr($writehtml_e, $start, $l);
  27280. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27281. $writehtml_e = $m[1];
  27282. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27283. $this->subPos = $writehtml_i+3;
  27284. return 4;
  27285. }
  27286. }
  27287. }
  27288. unset($cw);
  27289. return 0;
  27290. }
  27291. function setHiEntitySubstitutions() {
  27292. $entarr = array (
  27293. 'nbsp' => '160', 'iexcl' => '161', 'cent' => '162', 'pound' => '163', 'curren' => '164', 'yen' => '165', 'brvbar' => '166', 'sect' => '167',
  27294. 'uml' => '168', 'copy' => '169', 'ordf' => '170', 'laquo' => '171', 'not' => '172', 'shy' => '173', 'reg' => '174', 'macr' => '175',
  27295. 'deg' => '176', 'plusmn' => '177', 'sup2' => '178', 'sup3' => '179', 'acute' => '180', 'micro' => '181', 'para' => '182', 'middot' => '183',
  27296. 'cedil' => '184', 'sup1' => '185', 'ordm' => '186', 'raquo' => '187', 'frac14' => '188', 'frac12' => '189', 'frac34' => '190',
  27297. 'iquest' => '191', 'Agrave' => '192', 'Aacute' => '193', 'Acirc' => '194', 'Atilde' => '195', 'Auml' => '196', 'Aring' => '197',
  27298. 'AElig' => '198', 'Ccedil' => '199', 'Egrave' => '200', 'Eacute' => '201', 'Ecirc' => '202', 'Euml' => '203', 'Igrave' => '204',
  27299. 'Iacute' => '205', 'Icirc' => '206', 'Iuml' => '207', 'ETH' => '208', 'Ntilde' => '209', 'Ograve' => '210', 'Oacute' => '211',
  27300. 'Ocirc' => '212', 'Otilde' => '213', 'Ouml' => '214', 'times' => '215', 'Oslash' => '216', 'Ugrave' => '217', 'Uacute' => '218',
  27301. 'Ucirc' => '219', 'Uuml' => '220', 'Yacute' => '221', 'THORN' => '222', 'szlig' => '223', 'agrave' => '224', 'aacute' => '225',
  27302. 'acirc' => '226', 'atilde' => '227', 'auml' => '228', 'aring' => '229', 'aelig' => '230', 'ccedil' => '231', 'egrave' => '232',
  27303. 'eacute' => '233', 'ecirc' => '234', 'euml' => '235', 'igrave' => '236', 'iacute' => '237', 'icirc' => '238', 'iuml' => '239',
  27304. 'eth' => '240', 'ntilde' => '241', 'ograve' => '242', 'oacute' => '243', 'ocirc' => '244', 'otilde' => '245', 'ouml' => '246',
  27305. 'divide' => '247', 'oslash' => '248', 'ugrave' => '249', 'uacute' => '250', 'ucirc' => '251', 'uuml' => '252', 'yacute' => '253',
  27306. 'thorn' => '254', 'yuml' => '255', 'OElig' => '338', 'oelig' => '339', 'Scaron' => '352', 'scaron' => '353', 'Yuml' => '376',
  27307. 'fnof' => '402', 'circ' => '710', 'tilde' => '732', 'Alpha' => '913', 'Beta' => '914', 'Gamma' => '915', 'Delta' => '916',
  27308. 'Epsilon' => '917', 'Zeta' => '918', 'Eta' => '919', 'Theta' => '920', 'Iota' => '921', 'Kappa' => '922', 'Lambda' => '923',
  27309. 'Mu' => '924', 'Nu' => '925', 'Xi' => '926', 'Omicron' => '927', 'Pi' => '928', 'Rho' => '929', 'Sigma' => '931', 'Tau' => '932',
  27310. 'Upsilon' => '933', 'Phi' => '934', 'Chi' => '935', 'Psi' => '936', 'Omega' => '937', 'alpha' => '945', 'beta' => '946', 'gamma' => '947',
  27311. 'delta' => '948', 'epsilon' => '949', 'zeta' => '950', 'eta' => '951', 'theta' => '952', 'iota' => '953', 'kappa' => '954',
  27312. 'lambda' => '955', 'mu' => '956', 'nu' => '957', 'xi' => '958', 'omicron' => '959', 'pi' => '960', 'rho' => '961', 'sigmaf' => '962',
  27313. 'sigma' => '963', 'tau' => '964', 'upsilon' => '965', 'phi' => '966', 'chi' => '967', 'psi' => '968', 'omega' => '969',
  27314. 'thetasym' => '977', 'upsih' => '978', 'piv' => '982', 'ensp' => '8194', 'emsp' => '8195', 'thinsp' => '8201', 'zwnj' => '8204',
  27315. 'zwj' => '8205', 'lrm' => '8206', 'rlm' => '8207', 'ndash' => '8211', 'mdash' => '8212', 'lsquo' => '8216', 'rsquo' => '8217',
  27316. 'sbquo' => '8218', 'ldquo' => '8220', 'rdquo' => '8221', 'bdquo' => '8222', 'dagger' => '8224', 'Dagger' => '8225', 'bull' => '8226',
  27317. 'hellip' => '8230', 'permil' => '8240', 'prime' => '8242', 'Prime' => '8243', 'lsaquo' => '8249', 'rsaquo' => '8250', 'oline' => '8254',
  27318. 'frasl' => '8260', 'euro' => '8364', 'image' => '8465', 'weierp' => '8472', 'real' => '8476', 'trade' => '8482', 'alefsym' => '8501',
  27319. 'larr' => '8592', 'uarr' => '8593', 'rarr' => '8594', 'darr' => '8595', 'harr' => '8596', 'crarr' => '8629', 'lArr' => '8656',
  27320. 'uArr' => '8657', 'rArr' => '8658', 'dArr' => '8659', 'hArr' => '8660', 'forall' => '8704', 'part' => '8706', 'exist' => '8707',
  27321. 'empty' => '8709', 'nabla' => '8711', 'isin' => '8712', 'notin' => '8713', 'ni' => '8715', 'prod' => '8719', 'sum' => '8721',
  27322. 'minus' => '8722', 'lowast' => '8727', 'radic' => '8730', 'prop' => '8733', 'infin' => '8734', 'ang' => '8736', 'and' => '8743',
  27323. 'or' => '8744', 'cap' => '8745', 'cup' => '8746', 'int' => '8747', 'there4' => '8756', 'sim' => '8764', 'cong' => '8773',
  27324. 'asymp' => '8776', 'ne' => '8800', 'equiv' => '8801', 'le' => '8804', 'ge' => '8805', 'sub' => '8834', 'sup' => '8835', 'nsub' => '8836',
  27325. 'sube' => '8838', 'supe' => '8839', 'oplus' => '8853', 'otimes' => '8855', 'perp' => '8869', 'sdot' => '8901', 'lceil' => '8968',
  27326. 'rceil' => '8969', 'lfloor' => '8970', 'rfloor' => '8971', 'lang' => '9001', 'rang' => '9002', 'loz' => '9674', 'spades' => '9824',
  27327. 'clubs' => '9827', 'hearts' => '9829', 'diams' => '9830',
  27328. );
  27329. foreach($entarr AS $key => $val) {
  27330. $this->entsearch[] = '&'.$key.';';
  27331. $this->entsubstitute[] = code2utf($val);
  27332. }
  27333. }
  27334. function SubstituteHiEntities($html) {
  27335. // converts html_entities > ASCII 127 to unicode (defined in includes/pdf/config.php
  27336. // Leaves in particular &lt; to distinguish from tag marker
  27337. if (count($this->entsearch)) {
  27338. $html = str_replace($this->entsearch,$this->entsubstitute,$html);
  27339. }
  27340. return $html;
  27341. }
  27342. // Edited v1.2 Pass by reference; option to continue if invalid UTF-8 chars
  27343. function is_utf8(&$string) {
  27344. if ($string === mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
  27345. return true;
  27346. }
  27347. else {
  27348. if ($this->ignore_invalid_utf8) {
  27349. $string = mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") ;
  27350. return true;
  27351. }
  27352. else {
  27353. return false;
  27354. }
  27355. }
  27356. }
  27357. function purify_utf8($html,$lo=true) {
  27358. // For HTML
  27359. // Checks string is valid UTF-8 encoded
  27360. // converts html_entities > ASCII 127 to UTF-8
  27361. // Only exception - leaves low ASCII entities e.g. &lt; &amp; etc.
  27362. // Leaves in particular &lt; to distinguish from tag marker
  27363. if (!$this->is_utf8($html)) {
  27364. // mPDF 5.0
  27365. echo "<p><b>HTML contains invalid UTF-8 character(s)</b></p>";
  27366. while (mb_convert_encoding(mb_convert_encoding($html, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") != $html) {
  27367. $a = iconv('UTF-8', 'UTF-8', $html);
  27368. echo ($a);
  27369. $pos = $start = strlen($a);
  27370. $err = '';
  27371. while ( ord(substr($html,$pos,1)) > 128 ) {
  27372. $err .= '[[#'.ord(substr($html,$pos,1)).']]';
  27373. $pos++;
  27374. }
  27375. echo '<span style="color:red; font-weight:bold">'.$err.'</span>';
  27376. $html = substr($html, $pos);
  27377. }
  27378. echo $html;
  27379. $this->Error("");
  27380. }
  27381. $html = preg_replace("/\r/", "", $html );
  27382. // converts html_entities > ASCII 127 to UTF-8
  27383. // Leaves in particular &lt; to distinguish from tag marker
  27384. $html = $this->SubstituteHiEntities($html);
  27385. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  27386. // If $lo==true then includes ASCII < 128
  27387. $html = strcode2utf($html,$lo);
  27388. return ($html);
  27389. }
  27390. function purify_utf8_text($txt) {
  27391. // For TEXT
  27392. // Make sure UTF-8 string of characters
  27393. if (!$this->is_utf8($txt)) { $this->Error("Text contains invalid UTF-8 character(s)"); }
  27394. $txt = preg_replace("/\r/", "", $txt );
  27395. return ($txt);
  27396. }
  27397. function all_entities_to_utf8($txt) {
  27398. // converts txt_entities > ASCII 127 to UTF-8
  27399. // Leaves in particular &lt; to distinguish from tag marker
  27400. $txt = $this->SubstituteHiEntities($txt);
  27401. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  27402. $txt = strcode2utf($txt);
  27403. $txt = $this->lesser_entity_decode($txt);
  27404. return ($txt);
  27405. }
  27406. // ====================================================
  27407. /*-- BARCODES --*/
  27408. // UPC/EAN barcode
  27409. // EAN13, EAN8, UPCA, UPCE, ISBN, ISSN
  27410. // Accepts 12 or 13 digits with or without - hyphens
  27411. function WriteBarcode($code, $showtext=1, $x='', $y='', $size=1, $border=0, $paddingL=1, $paddingR=1, $paddingT=2, $paddingB=2, $height=1, $bgcol=false, $col=false, $btype='ISBN', $supplement='0', $supplement_code='', $k=1) {
  27412. if (empty($code)) {
  27413. return;
  27414. }
  27415. $codestr = $code;
  27416. $code = preg_replace('/\-/','',$code);
  27417. if (!class_exists('PDFBarcode', false)) {
  27418. include(_MPDF_PATH.'classes/barcode.php');
  27419. }
  27420. $this->barcode = new PDFBarcode(); // mPDF 5.0.012
  27421. if ($btype == 'ISSN' || $btype == 'ISBN') {
  27422. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  27423. }
  27424. else { $arrcode = $this->barcode->getBarcodeArray($code, $btype); }
  27425. if ($arrcode === false) { $this->Error('Error in barcode string: '.$codestr); }
  27426. if((($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') && strlen($code) == 12) || ($btype=='UPCA' && strlen($code) == 11)
  27427. || ($btype=='UPCE' && strlen($code) == 11) || ($btype=='EAN8' && strlen($code) == 7)) {
  27428. $code .= $arrcode['checkdigit'];
  27429. if (stristr($codestr,'-')) { $codestr .= '-' . $arrcode['checkdigit']; }
  27430. else { $codestr .= $arrcode['checkdigit']; }
  27431. }
  27432. if ($btype == 'ISBN') { $codestr = 'ISBN '.$codestr; }
  27433. if ($btype == 'ISSN') { $codestr = 'ISSN '.$codestr; }
  27434. if (empty($x)) {
  27435. $x = $this->GetX();
  27436. }
  27437. if (empty($y)) {
  27438. $y = $this->GetY();
  27439. }
  27440. // set foreground color
  27441. $prevDrawColor = $this->DrawColor;
  27442. $prevTextColor = $this->TextColor;
  27443. $prevFillColor = $this->FillColor;
  27444. $lw = $this->LineWidth;
  27445. $this->SetLineWidth(0.01);
  27446. $size /= $k; // in case resized in a table
  27447. $xres = $arrcode['nom-X'] * $size;
  27448. $llm = $arrcode['lightmL'] * $arrcode['nom-X'] * $size; // Left Light margin
  27449. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  27450. $bcw = ($arrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  27451. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  27452. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  27453. $fbwi = $fbw - 2; // Full barcode width incl. light margins - 2mm - for isbn string
  27454. // cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf
  27455. $num_height = 3 * $size; // Height of numerals
  27456. $fbh = $arrcode['nom-H'] * $size * $height; // Full barcode height incl. numerals
  27457. $bch = $fbh - (1.5 * $size); // Barcode height of bars (3mm for numerals)
  27458. if (($btype=='EAN13' && $showtext) || $btype == 'ISSN' || $btype == 'ISBN') { // Add height for ISBN string + margin from top of bars
  27459. $tisbnm = 1.5 * $size; // Top margin between isbn (if shown) & bars
  27460. $codestr_fontsize = 2.1 * $size;
  27461. $paddingT += $codestr_fontsize + $tisbnm ;
  27462. }
  27463. $oh = $fbh + $paddingT + $paddingB; // Full overall height incl. user-defined padding
  27464. // PRINT border background color
  27465. $xpos = $x;
  27466. $ypos = $y;
  27467. if (is_array($col)) { // from <barcode />
  27468. $this->SetDColor($col); // mPDF 5.0.020
  27469. $this->SetTColor($col); // mPDF 5.0.020
  27470. }
  27471. else {
  27472. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  27473. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  27474. }
  27475. if (is_array($bgcol)) { // from <barcode />
  27476. $this->SetFColor($bgcol); // mPDF 5.0.020
  27477. }
  27478. else { $this->SetFColor($this->ConvertColor(255)); } // mPDF 5.0.051
  27479. if (!$bgcol && !$col) { // fn. called directly - not via HTML
  27480. if ($border) { $fillb = 'DF'; } else { $fillb = 'F'; }
  27481. $this->Rect($xpos, $ypos, $ow, $oh, $fillb);
  27482. }
  27483. // PRINT BARS
  27484. $xpos = $x + $paddingL + $llm ;
  27485. $ypos = $y + $paddingT;
  27486. if (is_array($col)) { $this->SetFColor($col); } // mPDF 5.0.020
  27487. else { $this->SetFColor($this->ConvertColor(0)); } // mPDF 5.0.051
  27488. if ($arrcode !== false) {
  27489. foreach ($arrcode["bcode"] AS $v) {
  27490. $bw = ($v["w"] * $xres);
  27491. if ($v["t"]) {
  27492. // draw a vertical bar
  27493. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  27494. }
  27495. $xpos += $bw;
  27496. }
  27497. }
  27498. // print text
  27499. $prevFontFamily = $this->FontFamily;
  27500. $prevFontStyle = $this->FontStyle;
  27501. $prevFontSizePt = $this->FontSizePt;
  27502. // ISBN string
  27503. // mPDF 5.0.01
  27504. if (($btype=='EAN13' && $showtext) || $btype=='ISBN' || $btype=='ISSN') {
  27505. if ($this->onlyCoreFonts) {
  27506. $this->SetFont('chelvetica');
  27507. }
  27508. else {
  27509. $this->SetFont('sans');
  27510. }
  27511. if (is_array($bgcol)) { $this->SetFColor($bgcol); } // mPDF 5.0.020
  27512. else { $this->SetFColor($this->ConvertColor(255)); } // mPDF 5.0.051
  27513. $this->x = $x + $paddingL + 1; // 1mm left margin (cf. $fbwi above)
  27514. // max width is $fbwi
  27515. $loop = 0;
  27516. while ( $loop == 0 ) {
  27517. $this->SetFontSize($codestr_fontsize*1.4*$this->k, false); // don't write
  27518. $sz = $this->GetStringWidth( $codestr );
  27519. if ($sz > $fbwi)
  27520. $codestr_fontsize -= 0.1;
  27521. else
  27522. $loop ++;
  27523. }
  27524. $this->SetFont('','',$codestr_fontsize*1.4*$this->k, true, true); // * 1.4 because font height is only 7/10 of given mm
  27525. // WORD SPACING
  27526. if ($fbwi > $sz) {
  27527. $xtra = $fbwi - $sz;
  27528. $charspacing = $xtra / (strlen($codestr)-1);
  27529. if ($charspacing) { $this->_out(sprintf('BT %.3f Tc ET',$charspacing*$this->k)); }
  27530. }
  27531. $this->y = $y + $paddingT - ($codestr_fontsize ) - $tisbnm ;
  27532. $this->Cell($fbw , $codestr_fontsize, $codestr);
  27533. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  27534. }
  27535. // Bottom NUMERALS
  27536. // mPDF 5.0.01
  27537. if ($this->onlyCoreFonts) {
  27538. $this->SetFont('mono');
  27539. }
  27540. else {
  27541. if (in_array('ocrb',$this->available_unifonts)) { $this->SetFont('ocrb'); }
  27542. else { $this->SetFont('mono'); }
  27543. }
  27544. // mPDF 5.0.01
  27545. $fh = 1.35;
  27546. $charRO = '';
  27547. if ($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') {
  27548. $outerfontsize = 3; // Inner fontsize = 3
  27549. $outerp = $xres * 4;
  27550. $innerp = $xres * 2.5;
  27551. $textw = ($bcw*0.5) - $outerp - $innerp;
  27552. $chars = 6; // number of numerals in each half
  27553. $charLO = substr($code,0,1); // Left Outer
  27554. $charLI = substr($code,1,6); // Left Inner
  27555. $charRI = substr($code,7,6); // Right Inner
  27556. if (!$supplement) $charRO = '>'; // Right Outer
  27557. }
  27558. else if ($btype=='UPCA') {
  27559. $outerfontsize = 2.3; // Inner fontsize = 3
  27560. $outerp = $xres * 10;
  27561. $innerp = $xres * 2.5;
  27562. $textw = ($bcw*0.5) - $outerp - $innerp;
  27563. $chars = 5;
  27564. $charLO = substr($code,0,1); // Left Outer
  27565. $charLI = substr($code,1,5); // Left Inner
  27566. $charRI = substr($code,6,5); // Right Inner
  27567. $charRO = substr($code,11,1); // Right Outer
  27568. }
  27569. else if ($btype=='UPCE') {
  27570. $outerfontsize = 2.3; // Inner fontsize = 3
  27571. $outerp = $xres * 4;
  27572. $innerp = 0;
  27573. $textw = ($bcw*0.5) - $outerp - $innerp;
  27574. $chars = 3;
  27575. $upce_code = $arrcode['code'];
  27576. $charLO = substr($code,0,1); // Left Outer
  27577. $charLI = substr($upce_code,0,3); // Left Inner
  27578. $charRI = substr($upce_code,3,3); // Right Inner
  27579. $charRO = substr($code,11,1); // Right Outer
  27580. }
  27581. else if ($btype=='EAN8') {
  27582. $outerfontsize = 3; // Inner fontsize = 3
  27583. $outerp = $xres * 4;
  27584. $innerp = $xres * 2.5;
  27585. $textw = ($bcw*0.5) - $outerp - $innerp;
  27586. $chars = 4;
  27587. $charLO = '<'; // Left Outer
  27588. $charLI = substr($code,0,4); // Left Inner
  27589. $charRI = substr($code,4,4); // Right Inner
  27590. if (!$supplement) $charRO = '>'; // Right Outer
  27591. }
  27592. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27593. // mPDF 5.0.01
  27594. if (!$this->usingCoreFont) { $cw = $this->_getCharWidth($this->CurrentFont['cw'],32)*3*$fh*$size/1000; } // character width at 3mm
  27595. else { $cw = $this->_getCharWidth($this->CurrentFont['cw'],48)*3*$fh*$size/1000; } // 48 == char "0"
  27596. // Outer left character
  27597. $y_text = $y + $paddingT + $bch - ($num_height/2);
  27598. $y_text_outer = $y + $paddingT + $bch - ($num_height*($outerfontsize/3)/2);
  27599. $this->x = $x + $paddingL - ($cw*($outerfontsize/3)*0.1); // 0.1 is correction as char does not fill full width;
  27600. $this->y = $y_text_outer;
  27601. $this->Cell($cw, $num_height, $charLO );
  27602. // WORD SPACING for inner chars
  27603. $xtra = $textw - ($cw*$chars);
  27604. $charspacing = $xtra / ($chars-1);
  27605. if ($charspacing) { $this->_out(sprintf('BT %.3f Tc ET',$charspacing*$this->k)); }
  27606. if (is_array($bgcol)) { $this->SetFColor($bgcol); } // mPDF 5.0.020
  27607. else { $this->SetFColor($this->ConvertColor(255)); } // mPDF 5.0.051
  27608. $this->SetFontSize(3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27609. // Inner left half characters
  27610. $this->x = $x + $paddingL + $llm + $outerp;
  27611. $this->y = $y_text;
  27612. $this->Cell($textw, $num_height, $charLI , 0, 0, '', 1);
  27613. // Inner right half characters
  27614. $this->x = $x + $paddingL + $llm + ($bcw*0.5) + $innerp;
  27615. $this->y = $y_text;
  27616. $this->Cell($textw, $num_height, $charRI , 0, 0, '', 1);
  27617. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  27618. // Outer Right character
  27619. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27620. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*($outerfontsize/3)*0.9); // 0.9 is correction as char does not fill full width
  27621. $this->y = $y_text_outer;
  27622. $this->Cell($cw*($outerfontsize/3), $num_height, $charRO , 0, 0, 'R');
  27623. if ($supplement) { // EAN-2 or -5 Supplement
  27624. // PRINT BARS
  27625. $supparrcode = $this->barcode->getBarcodeArray($supplement_code, 'EAN'.$supplement);
  27626. if ($supparrcode === false) { $this->Error('Error in barcode string (supplement): '.$codestr.' '.$supplement_code); }
  27627. if(strlen($supplement_code) != $supplement) {
  27628. $this->Error('Barcode supplement incorrect: '.$supplement_code);
  27629. }
  27630. $llm = $fbw - (($arrcode['lightmR'] - $supparrcode['sepM']) * $arrcode['nom-X'] * $size); // Left Light margin
  27631. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  27632. $bcw = ($supparrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  27633. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  27634. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  27635. $bch = $fbh - (1.5 * $size) - ($num_height + 0.5); // Barcode height of bars (3mm for numerals)
  27636. $xpos = $x + $paddingL + $llm ;
  27637. $ypos = $y + $paddingT + $num_height + 0.5;
  27638. if (is_array($col)) { $this->SetFColor($col); } // mPDF 5.0.020
  27639. else { $this->SetFColor($this->ConvertColor(0)); } // mPDF 5.0.051
  27640. if ($supparrcode !== false) {
  27641. foreach ($supparrcode["bcode"] AS $v) {
  27642. $bw = ($v["w"] * $xres);
  27643. if ($v["t"]) {
  27644. // draw a vertical bar
  27645. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  27646. }
  27647. $xpos += $bw;
  27648. }
  27649. }
  27650. // Characters
  27651. if (is_array($bgcol)) { $this->SetFColor($bgcol); } // mPDF 5.0.020
  27652. else { $this->SetFColor($this->ConvertColor(255)); } // mPDF 5.0.051
  27653. $this->SetFontSize(3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27654. $this->x = $x + $paddingL + $llm;
  27655. $this->y = $y + $paddingT;
  27656. $this->Cell($bcw, $num_height, $supplement_code, 0, 0, 'C');
  27657. // Outer Right character (light margin)
  27658. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27659. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*0.9); // 0.9 is correction as char does not fill full width
  27660. $this->y = $y + $paddingT;
  27661. $this->Cell($cw*($outerfontsize/3), $num_height, '>', 0, 0, 'R');
  27662. }
  27663. // Restore **************
  27664. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  27665. $this->DrawColor = $prevDrawColor;
  27666. $this->TextColor = $prevTextColor;
  27667. $this->FillColor = $prevFillColor;
  27668. $this->SetLineWidth($lw);
  27669. $this->SetY($y);
  27670. }
  27671. // ====================================================
  27672. // POSTAL and OTHER barcodes
  27673. function WriteBarcode2($code, $x='', $y='', $size=1, $height=1, $bgcol=false, $col=false, $btype='IMB', $print_ratio='', $k=1) {
  27674. if (empty($code)) { return; }
  27675. if (!class_exists('PDFBarcode', false)) {
  27676. include(_MPDF_PATH.'classes/barcode.php');
  27677. }
  27678. $this->barcode = new PDFBarcode(); // mPDF 5.0.012
  27679. $arrcode = $this->barcode->getBarcodeArray($code, $btype, $print_ratio);
  27680. if ($arrcode === false) { $this->Error('Error in barcode string: '.$code); }
  27681. if (empty($x)) { $x = $this->GetX(); }
  27682. if (empty($y)) { $y = $this->GetY(); }
  27683. $prevDrawColor = $this->DrawColor;
  27684. $prevTextColor = $this->TextColor;
  27685. $prevFillColor = $this->FillColor;
  27686. $lw = $this->LineWidth;
  27687. $this->SetLineWidth(0.01);
  27688. $size /= $k; // in case resized in a table
  27689. $xres = $arrcode['nom-X'] * $size;
  27690. if ($btype == 'IMB' || $btype == 'RM4SCC' || $btype == 'KIX' || $btype == 'POSTNET' || $btype == 'PLANET') {
  27691. $llm = $arrcode['quietL'] / $k; // Left Quiet margin
  27692. $rlm = $arrcode['quietR'] / $k; // Right Quiet margin
  27693. $tlm = $blm = $arrcode['quietTB'] / $k;
  27694. $height=1; // Overrides
  27695. }
  27696. else if (in_array($btype, array('C128A','C128B','C128C','EAN128A','EAN128B','EAN128C','C39','C39+','C39E','C39E+','S25','S25+','I25','I25+','I25B','I25B+','C93','MSI','MSI+','CODABAR','CODE11'))) {
  27697. $llm = $arrcode['lightmL'] * $xres; // Left Quiet margin
  27698. $rlm = $arrcode['lightmR'] * $xres; // Right Quiet margin
  27699. $tlm = $blm = $arrcode['lightTB'] * $xres * $height;
  27700. }
  27701. $bcw = ($arrcode["maxw"] * $xres);
  27702. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  27703. $bch = ($arrcode["nom-H"] * $size * $height);
  27704. $fbh = $bch + $tlm + $blm; // Full barcode height
  27705. // PRINT border background color
  27706. $xpos = $x;
  27707. $ypos = $y;
  27708. if (is_array($col)) { // from <barcode />
  27709. $this->SetDColor($col); // mPDF 5.0.020
  27710. $this->SetTColor($col); // mPDF 5.0.020
  27711. }
  27712. else {
  27713. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  27714. $this->SetTColor($this->ConvertColor(0)); // mPDF 5.0.051
  27715. }
  27716. if (is_array($bgcol)) { // from <barcode />
  27717. $this->SetFColor($bgcol); // mPDF 5.0.020
  27718. }
  27719. else { $this->SetFColor($this->ConvertColor(255)); } // mPDF 5.0.051
  27720. // PRINT BARS
  27721. if (is_array($col)) { $this->SetFColor($col); } // mPDF 5.0.020
  27722. else { $this->SetFColor($this->ConvertColor(0)); } // mPDF 5.0.051
  27723. $xpos = $x + $llm ;
  27724. if ($arrcode !== false) {
  27725. foreach ($arrcode["bcode"] AS $v) {
  27726. $bw = ($v["w"] * $xres);
  27727. if ($v["t"]) {
  27728. $ypos = $y + $tlm + ($bch * $v['p'] / $arrcode['maxh']);
  27729. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $bch / $arrcode['maxh']), 'F');
  27730. }
  27731. $xpos += $bw;
  27732. }
  27733. }
  27734. // PRINT BEARER BARS
  27735. if ($btype == 'I25B' || $btype == 'I25B+') {
  27736. $this->Rect($x, $y, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  27737. $this->Rect($x, $y+$tlm+$bch, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  27738. }
  27739. // Restore **************
  27740. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  27741. $this->DrawColor = $prevDrawColor;
  27742. $this->TextColor = $prevTextColor;
  27743. $this->FillColor = $prevFillColor;
  27744. $this->SetLineWidth($lw);
  27745. $this->SetY($y);
  27746. }
  27747. /*-- END BARCODES --*/
  27748. // ====================================================
  27749. // ====================================================
  27750. // START TRANSFORMATIONS SECTION -----------------------
  27751. // authors: Moritz Wagner, Andreas Wurmser, Nicola Asuni
  27752. // From TCPDF
  27753. // Starts a 2D tranformation saving current graphic state.
  27754. function StartTransform($returnstring=false) {
  27755. if ($returnstring) { return('q'); }
  27756. else { $this->_out('q'); }
  27757. }
  27758. function StopTransform($returnstring=false) {
  27759. if ($returnstring) { return('Q'); }
  27760. else { $this->_out('Q'); }
  27761. }
  27762. // Vertical and horizontal non-proportional Scaling.
  27763. function transformScale($s_x, $s_y, $x='', $y='', $returnstring=false) {
  27764. if ($x === '') {
  27765. $x=$this->x;
  27766. }
  27767. if ($y === '') {
  27768. $y=$this->y;
  27769. }
  27770. if (($s_x == 0) OR ($s_y == 0)) {
  27771. $this->Error('Please do not use values equal to zero for scaling');
  27772. }
  27773. $y = ($this->h - $y) * $this->k;
  27774. $x *= $this->k;
  27775. //calculate elements of transformation matrix
  27776. $s_x /= 100;
  27777. $s_y /= 100;
  27778. $tm[0] = $s_x;
  27779. $tm[1] = 0;
  27780. $tm[2] = 0;
  27781. $tm[3] = $s_y;
  27782. $tm[4] = $x * (1 - $s_x);
  27783. $tm[5] = $y * (1 - $s_y);
  27784. //scale the coordinate system
  27785. if ($returnstring) { return($this->_transform($tm, true)); }
  27786. else { $this->_transform($tm); }
  27787. }
  27788. // Translate graphic object horizontally and vertically.
  27789. function transformTranslate($t_x, $t_y, $returnstring=false) {
  27790. //calculate elements of transformation matrix
  27791. $tm[0] = 1;
  27792. $tm[1] = 0;
  27793. $tm[2] = 0;
  27794. $tm[3] = 1;
  27795. $tm[4] = $t_x * $this->k;
  27796. $tm[5] = -$t_y * $this->k;
  27797. //translate the coordinate system
  27798. if ($returnstring) { return($this->_transform($tm, true)); }
  27799. else { $this->_transform($tm); }
  27800. }
  27801. // Rotate object.
  27802. function transformRotate($angle, $x='', $y='', $returnstring=false) {
  27803. if ($x === '') {
  27804. $x=$this->x;
  27805. }
  27806. if ($y === '') {
  27807. $y=$this->y;
  27808. }
  27809. $angle = -$angle;
  27810. $y = ($this->h - $y) * $this->k;
  27811. $x *= $this->k;
  27812. //calculate elements of transformation matrix
  27813. $tm[0] = cos(deg2rad($angle));
  27814. $tm[1] = sin(deg2rad($angle));
  27815. $tm[2] = -$tm[1];
  27816. $tm[3] = $tm[0];
  27817. $tm[4] = $x + $tm[1] * $y - $tm[0] * $x;
  27818. $tm[5] = $y - $tm[0] * $y - $tm[1] * $x;
  27819. //rotate the coordinate system around ($x,$y)
  27820. if ($returnstring) { return($this->_transform($tm, true)); }
  27821. else { $this->_transform($tm); }
  27822. }
  27823. function _transform($tm, $returnstring=false) {
  27824. if ($returnstring) { return(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  27825. else { $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  27826. }
  27827. // END TRANSFORMATIONS SECTION -------------------------
  27828. /*-- INDIC --*/
  27829. // INDIC ============================
  27830. // This conversion can only be done when font is set
  27831. function ConvertIndic(&$str) {
  27832. if (preg_match('/^ind_([a-z]{2})_/',$this->currentfontfamily, $m)) { // mPDF 5.0 not font['name']
  27833. if (!class_exists('indic', false)) { include(_MPDF_PATH.'classes/indic.php'); }
  27834. if (empty($this->indic)) { $this->indic = new indic($this); }
  27835. $earr = $this->UTF8StringToArray($str, false);
  27836. $str = $this->indic->substituteIndic($earr, $m[1], $this->currentfontfamily);
  27837. }
  27838. }
  27839. /*-- END INDIC --*/
  27840. // AUTOFONT =========================
  27841. function AutoFont($html) {
  27842. if ($this->usingCoreFont) { return $html; }
  27843. $this->useLang = true;
  27844. if ($this->autoFontGroupSize == 1) { $extra = $this->pregASCIIchars1; }
  27845. else if ($this->autoFontGroupSize == 3) { $extra = $this->pregASCIIchars3; }
  27846. else { $extra = $this->pregASCIIchars2; }
  27847. $n = '';
  27848. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  27849. foreach($a as $i => $e) {
  27850. if($i%2==0) {
  27851. $e = strcode2utf($e);
  27852. $e = $this->lesser_entity_decode($e);
  27853. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  27854. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  27855. // CJK
  27856. if ($this->autoFontGroups & AUTOFONT_CJK) {
  27857. $e = preg_replace("/([".$this->pregCJKchars.$extra."]*[".$this->pregCJKchars."][".$this->pregCJKchars.$extra."]*)/ue", '$this->replaceCJK(stripslashes(\'\\1\'))', $e);
  27858. }
  27859. /*-- RTL --*/
  27860. if ($this->autoFontGroups & AUTOFONT_RTL) {
  27861. // HEBREW
  27862. $e = preg_replace("/([".$this->pregHEBchars .$extra."]*[".$this->pregHEBchars ."][".$this->pregHEBchars .$extra."]*)/u", "\xef\xbf\xb0span lang=\"he\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27863. // All Arabic
  27864. $e = preg_replace("/([".$this->pregARABICchars .$extra."]*[".$this->pregARABICchars ."][".$this->pregARABICchars .$extra."]*)/ue", '$this->replaceArabic(stripslashes(\'\\1\'))', $e);
  27865. }
  27866. /*-- END RTL --*/
  27867. /*-- INDIC --*/
  27868. // INDIC
  27869. if ($this->autoFontGroups & AUTOFONT_INDIC) {
  27870. // Bengali
  27871. $e = preg_replace("/([".$this->pregBNchars .$this->pregINDextra."]*[".$this->pregBNchars ."][".$this->pregBNchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"bn\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27872. // Devanagari (= script for Hindi, Nepali + Sindhi)
  27873. $e = preg_replace("/([".$this->pregHIchars .$this->pregINDextra."]*[".$this->pregHIchars ."][".$this->pregHIchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"hi\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27874. // Gujarati
  27875. $e = preg_replace("/([".$this->pregGUchars .$this->pregINDextra."]*[".$this->pregGUchars ."][".$this->pregGUchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"gu\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27876. // Malayalam
  27877. $e = preg_replace("/([".$this->pregMLchars .$this->pregINDextra."]*[".$this->pregMLchars ."][".$this->pregMLchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"ml\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27878. // Kannada
  27879. $e = preg_replace("/([".$this->pregKNchars .$this->pregINDextra."]*[".$this->pregKNchars ."][".$this->pregKNchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"kn\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27880. // Oriya
  27881. $e = preg_replace("/([".$this->pregORchars .$this->pregINDextra."]*[".$this->pregORchars ."][".$this->pregORchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"or\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27882. // Punjabi ?= Gurmuhki
  27883. $e = preg_replace("/([".$this->pregPAchars .$this->pregINDextra."]*[".$this->pregPAchars ."][".$this->pregPAchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"pa\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27884. // Tamil
  27885. $e = preg_replace("/([".$this->pregTAchars .$this->pregINDextra."]*[".$this->pregTAchars ."][".$this->pregTAchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"ta\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27886. // Telugu
  27887. $e = preg_replace("/([".$this->pregTEchars .$this->pregINDextra."]*[".$this->pregTEchars ."][".$this->pregTEchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"te\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27888. }
  27889. /*-- END INDIC --*/
  27890. if ($this->autoFontGroups & AUTOFONT_THAIVIET) {
  27891. // THAI
  27892. $e = preg_replace("/([\x{0E00}-\x{0E7F}".$extra."]*[\x{0E00}-\x{0E7F}][\x{0E00}-\x{0E7F}".$extra."]*)/u", "\xef\xbf\xb0span lang=\"th\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27893. // Vietnamese
  27894. $e = preg_replace("/([".$this->pregVIETchars .$this->pregVIETPluschars ."]*[".$this->pregVIETchars ."][".$this->pregVIETchars .$this->pregVIETPluschars ."]*)/u", "\xef\xbf\xb0span lang=\"vi\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e);
  27895. }
  27896. $e = preg_replace('/[&]/','&amp;',$e);
  27897. $e = preg_replace('/[<]/','&lt;',$e);
  27898. $e = preg_replace('/[>]/','&gt;',$e);
  27899. $e = preg_replace("/(\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1)\s+/",' \\1',$e);
  27900. $e = preg_replace("/[ ]+(\xef\xbf\xb0\/span\xef\xbf\xb1)/",'\\1 ',$e);
  27901. $e = preg_replace("/\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1/","\xef\xbf\xb0span lang=\"\\1\" class=\"lang_\\1\"\xef\xbf\xb1",$e);
  27902. $e = preg_replace("/\xef\xbf\xb0/",'<',$e);
  27903. $e = preg_replace("/\xef\xbf\xb1/",'>',$e);
  27904. $a[$i] = $e;
  27905. }
  27906. else {
  27907. $a[$i] = '<'.$e.'>';
  27908. }
  27909. }
  27910. $n = implode('',$a);
  27911. return $n;
  27912. }
  27913. function replaceCJK($str) {
  27914. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  27915. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  27916. if (preg_match("/[".$this->pregUHCchars."]/u", $str)) {
  27917. return "\xef\xbf\xb0span lang=\"ko\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  27918. }
  27919. else if (preg_match("/[".$this->pregSJISchars."]/u", $str)) {
  27920. return "\xef\xbf\xb0span lang=\"ja\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  27921. }
  27922. // if in Unicode Plane 2, probably HKCS (incl in BIG5) if not Japanese
  27923. else if (preg_match("/[\x{20000}-\x{2FFFF}]/u", $str)) {
  27924. return "\xef\xbf\xb0span lang=\"zh-HK\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  27925. }
  27926. else{
  27927. return "\xef\xbf\xb0span lang=\"zh-CN\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  27928. }
  27929. return $str;
  27930. }
  27931. /*-- RTL --*/
  27932. function replaceArabic($str) {
  27933. // PASHTO, SINDHI, URDU, ARABIC, PERSIAN
  27934. $persian = "\x{067E}\x{0686}\x{0698}\x{06AF}";
  27935. $urdu = "\x{0679}\x{0688}\x{0691}\x{06BA}\x{06BE}\x{06C1}\x{06D2}";
  27936. $pashto = "\x{067C}\x{0681}\x{0685}\x{0689}\x{0693}\x{0696}\x{069A}\x{06BC}\x{06D0}";
  27937. $sindhi = "\x{067A}\x{067B}\x{067D}\x{067F}\x{0680}\x{0684}\x{068D}\x{068A}\x{068F}\x{068C}\x{0687}\x{0683}\x{0699}\x{06AA}\x{06A6}\x{06BB}\x{06B1}\x{06B3}";
  27938. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  27939. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  27940. if (preg_match("/[".$this->pregNonARABICchars ."]/u", $str) ) {
  27941. if (preg_match("/[".$sindhi ."]/u", $str) ) {
  27942. return "\xef\xbf\xb0span lang=\"sd\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  27943. }
  27944. else if (preg_match("/[".$urdu ."]/u", $str) ) {
  27945. return "\xef\xbf\xb0span lang=\"ur\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  27946. }
  27947. else if (preg_match("/[".$pashto ."]/u", $str) ) {
  27948. return "\xef\xbf\xb0span lang=\"ps\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  27949. }
  27950. else if (preg_match("/[".$persian ."]/u", $str) ) {
  27951. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  27952. }
  27953. else {
  27954. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  27955. }
  27956. }
  27957. if (preg_match("/[".$persian ."]/u", $str) ) {
  27958. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  27959. }
  27960. else {
  27961. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  27962. }
  27963. return $str;
  27964. }
  27965. // ARABIC ===========================
  27966. function InitArabic() {
  27967. // JOIN TO FOLLOWING LETTER IN LOGICAL ORDER
  27968. // U+060c U+061f; U+061b; U+0640; U+0626; U+0628; U+062a; U+062b; U+062c; U+062d; U+062e; U+0633; U+0634; U+0635; U+0636; U+0637;
  27969. // U+0638; U+0639; U+063a; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; U+0647; U+064a; U+06a9; U+06cc; U+0686; U+06af; U+067e;
  27970. // U+06D0; U+0681; U+06C1;
  27971. $this->arabPrevLink = "\xd8\x8c\xd8\x9f\xd8\x9b\xd9\x80\xd8\xa6\xd8\xa8\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x8a\xda\xa9\xdb\x8c\xda\x86\xda\xaf\xd9\xbe\xdb\x90\xda\x81\xdb\x81";
  27972. // \xda\x98 (U+0698) removed from arabPrevLink
  27973. // \xd9\xb1 (U+0671) added to arabNextLink & final form added to Persian Glyphs (FB51)
  27974. // JOIN TO PREVIOUS LETTER IN LOGICAL ORDER
  27975. // U+0640 U+0622; U+0623; U+0624; U+0625; U+0627; U+0626; U+0628; U+0629; U+062a; U+062b; U+062c; U+062d; U+062e; U+062f; U+0630;
  27976. // U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; U+0639; U+063a; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646;
  27977. // U+0647; U+0648; U+0649; U+064a; U+06a9; U+06cc; U+0686; U+06af; U+0698; U+067e;
  27978. // U+0671; U+06D0; U+0696; U+0693; U+06D2; U+06C1;
  27979. $this->arabNextLink = "\xd9\x80\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa7\xd8\xa6\xd8\xa8\xd8\xa9\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf\xd8\xb0\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x88\xd9\x89\xd9\x8a\xda\xa9\xdb\x8c\xda\x86\xda\xaf\xda\x98\xd9\xbe\xd9\xb1\xdb\x90\xda\x96\xda\x93\xdb\x92\xdb\x81";
  27980. // U+064b U+064c; U+064d; U+064e; U+064f; U+0650; U+0651; U+0652;
  27981. $this->arabVowels = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  27982. // Added chars that may not be vowels but should not interrupt joining
  27983. // U+0670; U+0653;
  27984. $this->arabVowels .= "\xd9\xb0\xd9\x93";
  27985. // ? should also add - U+615, 616, 617-61A, 653-65E, 6D6-6DC, 6DF-6E4, 6E7, 6E8, 6EA-6ED
  27986. // DON'T ADD ANY MORE TO ARABGLYPHS - cf. ArabJoin() counts 48 then does ligatures - use PersianGlyphs below
  27987. // ISOLATED FORM :: FINAL :: INITIAL :: MEDIAL
  27988. // U+064B; U+064C; U+064D; U+064E; U+064F; U+0650; U+0651; U+0652;
  27989. $this->arabGlyphs = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  27990. $this->arabHex = '064B064B064B064B064C064C064C064C064D064D064D064D064E064E064E064E064F064F064F064F065006500650065006510651065106510652065206520652';
  27991. // U+0621; U+0622; U+0623; U+0624; U+0625; U+0626; U+0627; U+0628;
  27992. $this->arabGlyphs .= "\xd8\xa1\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa6\xd8\xa7\xd8\xa8";
  27993. $this->arabHex .= '06210621062106210622FE820622FE820623FE840623FE840624FE860624FE860625FE880625FE880626FE8AFE8BFE8C0627FE8E0627FE8E0628FE90FE91FE92';
  27994. // U+0629; U+062A; U+062B; U+062C; U+062D; U+062E; U+062F; U+0630;
  27995. $this->arabGlyphs .= "\xd8\xa9\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf\xd8\xb0";
  27996. $this->arabHex .= '0629FE940629FE94062AFE96FE97FE98062BFE9AFE9BFE9C062CFE9EFE9FFEA0062DFEA2FEA3FEA4062EFEA6FEA7FEA8062FFEAA062FFEAA0630FEAC0630FEAC';
  27997. // U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638;
  27998. $this->arabGlyphs .= "\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8";
  27999. $this->arabHex .= '0631FEAE0631FEAE0632FEB00632FEB00633FEB2FEB3FEB40634FEB6FEB7FEB80635FEBAFEBBFEBC0636FEBEFEBFFEC00637FEC2FEC3FEC40638FEC6FEC7FEC8';
  28000. // U+0639; U+063A; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646;
  28001. $this->arabGlyphs .= "\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86";
  28002. $this->arabHex .= '0639FECAFECBFECC063AFECEFECFFED00641FED2FED3FED40642FED6FED7FED80643FEDAFEDBFEDC0644FEDEFEDFFEE00645FEE2FEE3FEE40646FEE6FEE7FEE8';
  28003. // U+0647; U+0648; U+0649; U+064A; U+0640; U+060C; U+061F; U+061B;
  28004. $this->arabGlyphs .= "\xd9\x87\xd9\x88\xd9\x89\xd9\x8a\xd9\x80\xd8\x8c\xd8\x9f\xd8\x9b";
  28005. // 0649 Initial or medial probably meant to be YEH (064A) so Initial and Medial forms of YEH given
  28006. $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FEF3FEF4064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  28007. // 0649 Alef Maksura should only appear at end of word (in Arabic) So final form given as FEF0. Initial and medial are shown as isolated/final
  28008. // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF00649FEF0064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  28009. // 0649 Alef Maksura Initial and Medial forms as given in Unicode FBE8 and FBE9 (not in most fonts) - dotless vesions of above
  28010. // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FBE8FBE9064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  28011. // LAM with ALEF ligatures
  28012. // U+0644; U+0622; U+0644; U+0623; U+0644; U+0625; U+0644; U+0627;
  28013. $this->arabGlyphs .= "\xd9\x84\xd8\xa2\xd9\x84\xd8\xa3\xd9\x84\xd8\xa5\xd9\x84\xd8\xa7";
  28014. $this->arabHex .= 'FEF5FEF6FEF5FEF6FEF7FEF8FEF7FEF8FEF9FEFAFEF9FEFAFEFBFEFCFEFBFEFC';
  28015. // Added Arabic Presentation Forms - A - for Persian and other langauges
  28016. // U+067B; U+067E; U+0680; U+067A; U+067F; U+0679; U+06A4; U+06A6;
  28017. $this->persianGlyphs = "\xd9\xbb\xd9\xbe\xda\x80\xd9\xba\xd9\xbf\xd9\xb9\xda\xa4\xda\xa6";
  28018. $this->persianHex = '067BFB53FB54FB55067EFB57FB58FB590680FB5BFB5CFB5D067AFB5FFB60FB61067FFB63FB64FB650679FB67FB68FB6906A4FB6BFB6CFB6D06A6FB6FFB70FB71';
  28019. // U+0684; U+0683; U+0686; U+0687; U+0698; U+0691; U+06A9; U+06Af;
  28020. $this->persianGlyphs .= "\xda\x84\xda\x83\xda\x86\xda\x87\xda\x98\xda\x91\xda\xa9\xda\xaf";
  28021. $this->persianHex .= '0684FB73FB74FB750683FB77FB78FB790686FB7BFB7CFB7D0687FB7FFB80FB810698FB8B0698FB8B0691FB8D0691FB8D06A9FB8FFB90FB9106AfFB93FB94FB95';
  28022. // U+06BA; U+06CC; U+06C1; U+0671; U+06D0; U+06D2;
  28023. // 06C1 final form is same as isolated so use 06C1
  28024. $this->persianGlyphs .= "\xda\xba\xdb\x8c\xdb\x81\xd9\xb1\xdb\x90\xdb\x92";
  28025. $this->persianHex .= '06BAFB9F06BAFB9F06CCFBFDFBFEFBFF06C106C1FBA8FBA90671FB510671FB5106D0FBE5FBE6FBE706D2FBAF06D2FBAF';
  28026. }
  28027. // ----------------------------------------------------------------------
  28028. // Derived from ArPHP
  28029. // by Khaled Al-Shamaa
  28030. // http://www.ar-php.org
  28031. // ----------------------------------------------------------------------
  28032. function ArabJoin($str) {
  28033. if (!$this->arabGlyphs) { $this->InitArabic(); }
  28034. $crntChar = null;
  28035. $prevChar = null;
  28036. $nextChar = null;
  28037. $output = array();
  28038. $chars = preg_split('//u', $str);
  28039. $max = count($chars);
  28040. for ($i = $max - 1; $i >= 0; $i--) {
  28041. $crntChar = $chars[$i];
  28042. if ($i > 0){ $prevChar = $chars[$i - 1]; }
  28043. else{ $prevChar = NULL; }
  28044. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28045. $prevChar = $chars[$i - 2];
  28046. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28047. $prevChar = $chars[$i - 3];
  28048. }
  28049. }
  28050. if ($crntChar && mb_strpos($this->arabVowels, $crntChar, 0, 'utf-8') !== false) {
  28051. // If next_char = nextLink && prev_char = prevLink:
  28052. // Added && $prevchar (defined) else error on mb_strpos()
  28053. if ($chars[$i + 1] && (mb_strpos($this->arabNextLink, $chars[$i + 1], 0, 'utf-8') !== false) && $prevChar && (mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false)) {
  28054. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 1) . ';'; // <final> form
  28055. }
  28056. else {
  28057. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 0) . ';'; // <isolated> form
  28058. }
  28059. continue;
  28060. }
  28061. // NB = &#x622 &#x623; &#x625; &#x627; &#x644;
  28062. if (isset($chars[$i + 1]) && in_array($chars[$i + 1], array("\xd8\xa2","\xd8\xa3","\xd8\xa5","\xd8\xa7")) && $crntChar == "\xd9\x84"){
  28063. continue;
  28064. }
  28065. if (ord($crntChar) < 128) {
  28066. $output[] = $crntChar;
  28067. $nextChar = $crntChar;
  28068. continue;
  28069. }
  28070. $form = 0;
  28071. if (in_array($crntChar, array("\xd8\xa2", "\xd8\xa3", "\xd8\xa5", "\xd8\xa7")) && $prevChar == "\xd9\x84") {
  28072. if ($chars[$i - 2] && mb_strpos($this->arabPrevLink, $chars[$i - 2], 0, 'utf-8') !== false) {
  28073. $form++; // <final> form
  28074. }
  28075. $output[] = '&#x' . $this->get_arab_glyphs($prevChar . $crntChar, $form) . ';';
  28076. $nextChar = $prevChar;
  28077. continue;
  28078. }
  28079. if ($prevChar && mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false) {
  28080. $form++;
  28081. }
  28082. if ($nextChar && mb_strpos($this->arabNextLink, $nextChar, 0, 'utf-8') !== false) {
  28083. $form += 2;
  28084. }
  28085. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, $form) . ';';
  28086. $nextChar = $crntChar;
  28087. }
  28088. $ra = array_reverse($output);
  28089. $s = implode($ra);
  28090. $s = strcode2utf($s);
  28091. return $s;
  28092. }
  28093. function get_arab_glyphs($char, $type) {
  28094. $pos = mb_strpos($this->arabGlyphs, $char, 0, 'utf-8');
  28095. if ($pos === false) { // If character not covered here
  28096. $pos = mb_strpos($this->persianGlyphs, $char, 0, 'utf-8'); // Try Persian additions
  28097. if ($pos === false) { // return original character
  28098. $x = mb_encode_numericentity ($char, array (0x0, 0xffff, 0, 0xffff), 'UTF-8');
  28099. preg_match('/&#(\d+);/', $x, $m);
  28100. return dechex($m[1]);
  28101. }
  28102. else { // if covered by Added Persian chars
  28103. $pos = $pos*16 + $type*4;
  28104. return mb_substr($this->persianHex, $pos, 4, 'utf-8');
  28105. }
  28106. }
  28107. if ($pos > 48){
  28108. $pos = ($pos-48)/2 + 48;
  28109. }
  28110. $pos = $pos*16 + $type*4;
  28111. return mb_substr($this->arabHex, $pos, 4, 'utf-8');
  28112. }
  28113. /*-- END RTL --*/
  28114. // mPDF 5.0
  28115. function _getMQR() {
  28116. $mqr=ini_get("magic_quotes_runtime");
  28117. if (PHP_VERSION_ID < 50300) { return @get_magic_quotes_runtime(); }
  28118. else { return 0; }
  28119. }
  28120. //===========================
  28121. // Functions originally in htmltoolkit - moved mPDF 4.0
  28122. // Call-back function Used for usort in fn _tableWrite
  28123. function _cmpdom($a, $b) {
  28124. return ($a["dom"] < $b["dom"]) ? -1 : 1;
  28125. }
  28126. function mb_strrev($str, $enc = 'utf-8'){
  28127. $ch = array();
  28128. $ch = preg_split('//u',$str);
  28129. $revch = array_reverse($ch);
  28130. return implode('',$revch);
  28131. }
  28132. /*-- COLUMNS --*/
  28133. // Callback function from function printcolumnbuffer in mpdf
  28134. function columnAdjustAdd($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  28135. if ($type == 'Td') { // xpos,ypos
  28136. $a += ($xadj * $k);
  28137. $b -= ($yadj * $k);
  28138. return 'BT '.sprintf('%.3f %.3f',$a,$b).' Td';
  28139. }
  28140. else if ($type == 're') { // xpos,ypos,width,height
  28141. $a += ($xadj * $k);
  28142. $b -= ($yadj * $k);
  28143. return sprintf('%.3f %.3f %.3f %.3f',$a,$b,$c,$d).' re';
  28144. }
  28145. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  28146. $a += ($xadj * $k);
  28147. $b -= ($yadj * $k);
  28148. return sprintf('%.3f %.3f l',$a,$b);
  28149. }
  28150. else if ($type == 'img') { // width,height,xpos,ypos
  28151. $c += ($xadj * $k);
  28152. $d -= ($yadj * $k);
  28153. return sprintf('q %.3f 0 0 %.3f %.3f %.3f',$a,$b,$c,$d).' cm /'.$e;
  28154. }
  28155. else if ($type == 'draw') { // xpos,ypos
  28156. $a += ($xadj * $k);
  28157. $b -= ($yadj * $k);
  28158. return sprintf('%.3f %.3f m',$a,$b);
  28159. }
  28160. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  28161. $a += ($xadj * $k);
  28162. $b -= ($yadj * $k);
  28163. $c += ($xadj * $k);
  28164. $d -= ($yadj * $k);
  28165. $e += ($xadj * $k);
  28166. $f -= ($yadj * $k);
  28167. return sprintf('%.3f %.3f %.3f %.3f %.3f %.3f',$a,$b,$c,$d,$e,$f).' c';
  28168. }
  28169. }
  28170. /*-- END COLUMNS --*/
  28171. // Callback function from function printdivbuffer in mpdf - keeping block together on one page
  28172. function blockAdjust($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  28173. if ($type == 'Td') { // xpos,ypos
  28174. $a += ($xadj * $k);
  28175. $b -= ($yadj * $k);
  28176. return 'BT '.sprintf('%.3f %.3f',$a,$b).' Td';
  28177. }
  28178. else if ($type == 're') { // xpos,ypos,width,height
  28179. $a += ($xadj * $k);
  28180. $b -= ($yadj * $k);
  28181. return sprintf('%.3f %.3f %.3f %.3f',$a,$b,$c,$d).' re';
  28182. }
  28183. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  28184. $a += ($xadj * $k);
  28185. $b -= ($yadj * $k);
  28186. return sprintf('%.3f %.3f l',$a,$b);
  28187. }
  28188. else if ($type == 'img') { // width,height,xpos,ypos
  28189. $c += ($xadj * $k);
  28190. $d -= ($yadj * $k);
  28191. return sprintf('q %.3f 0 0 %.3f %.3f %.3f',$a,$b,$c,$d).' cm /'.$e;
  28192. }
  28193. else if ($type == 'draw') { // xpos,ypos
  28194. $a += ($xadj * $k);
  28195. $b -= ($yadj * $k);
  28196. return sprintf('%.3f %.3f m',$a,$b);
  28197. }
  28198. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  28199. $a += ($xadj * $k);
  28200. $b -= ($yadj * $k);
  28201. $c += ($xadj * $k);
  28202. $d -= ($yadj * $k);
  28203. $e += ($xadj * $k);
  28204. $f -= ($yadj * $k);
  28205. return sprintf('%.3f %.3f %.3f %.3f %.3f %.3f',$a,$b,$c,$d,$e,$f).' c';
  28206. }
  28207. }
  28208. // mPDF 5.0.005 5.0.051
  28209. function ConvertColor($color="#000000"){
  28210. $color = trim(strtolower($color));
  28211. $c = false;
  28212. if ($color=='transparent') { return false; }
  28213. else if ($color=='inherit') { return false; }
  28214. else if (isset($this->SVGcolors[$color])) $color = $this->SVGcolors[$color];
  28215. if (preg_match('/^[\d]+$/',$color)) { $c = (array(1,$color)); } // i.e. integer only
  28216. else if ($color[0] == '#') { //case of #nnnnnn or #nnn
  28217. $cor = preg_replace('/\s+.*/','',$color); // in case of Background: #CCC url() x-repeat etc.
  28218. if (strlen($cor) == 4) { // Turn #RGB into #RRGGBB
  28219. $cor = "#" . $cor[1] . $cor[1] . $cor[2] . $cor[2] . $cor[3] . $cor[3];
  28220. }
  28221. $r = hexdec(substr($cor, 1, 2));
  28222. $g = hexdec(substr($cor, 3, 2));
  28223. $b = hexdec(substr($cor, 5, 2));
  28224. $c = array(3,$r,$g,$b);
  28225. }
  28226. else if (preg_match('/(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\((.*?)\)/',$color,$m)) {
  28227. $type= $m[1];
  28228. $cores = explode(",", $m[2]);
  28229. if (stristr($cores[0],'%') ) {
  28230. $cores[0] += 0;
  28231. if ($type=='rgb' || $type=='rgba') { $cores[0] = intval($cores[0]*255/100); }
  28232. }
  28233. if (stristr($cores[1],'%') ) {
  28234. $cores[1] += 0;
  28235. if ($type=='rgb' || $type=='rgba') { $cores[1] = intval($cores[1]*255/100); }
  28236. if ($type=='hsl' || $type=='hsla') { $cores[1] = $cores[1]/100; }
  28237. }
  28238. if (stristr($cores[2],'%') ) {
  28239. $cores[2] += 0;
  28240. if ($type=='rgb' || $type=='rgba') { $cores[2] = intval($cores[2]*255/100); }
  28241. if ($type=='hsl' || $type=='hsla') { $cores[2] = $cores[2]/100; }
  28242. }
  28243. if (stristr($cores[3],'%') ) {
  28244. $cores[3] += 0;
  28245. }
  28246. if ($type=='rgb') { $c = array(3,$cores[0],$cores[1],$cores[2]); }
  28247. else if ($type=='rgba') { $c = array(5,$cores[0],$cores[1],$cores[2],$cores[3]); }
  28248. else if ($type=='cmyk') { $c = array(4,$cores[0],$cores[1],$cores[2],$cores[3]); }
  28249. else if ($type=='cmyka') { $c = array(6,$cores[0],$cores[1],$cores[2],$cores[3],$cores[4]); }
  28250. else if ($type=='hsl' || $type=='hsla') {
  28251. $conv = $this->hsl2rgb($cores[0]/360,$cores[1],$cores[2]);
  28252. if ($type=='hsl') { $c = array(3,$conv[0],$conv[1],$conv[2]); }
  28253. else if ($type=='hsla') { $c = array(5,$conv[0],$conv[1],$conv[2],$cores[3]); }
  28254. }
  28255. else if ($type=='spot') {
  28256. $name = strtoupper(trim($cores[0]));
  28257. if(!isset($this->spotColors[$name])) $this->Error('Undefined spot color: '.$name);
  28258. $c = array(2,$this->spotColors[$name]['i'],$cores[1]);
  28259. }
  28260. }
  28261. // mPDF 5.0.051
  28262. // $this->restrictColorSpace
  28263. // 1 - allow GRAYSCALE only [convert CMYK/RGB->gray]
  28264. // 2 - allow RGB / SPOT COLOR / Grayscale [convert CMYK->RGB]
  28265. // 3 - allow CMYK / SPOT COLOR / Grayscale [convert RGB->CMYK]
  28266. if ($this->PDFA || $this->PDFX || $this->restrictColorSpace) {
  28267. if ($c[0]==1) { // GRAYSCALE
  28268. }
  28269. else if ($c[0]==2) { // SPOT COLOR
  28270. if (!isset($this->spotColorIDs[$c[1]])) { die('Error: Spot colour has not been defined - '.$this->spotColorIDs[$c[1]]); }
  28271. if ($this->PDFA) {
  28272. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "Spot color specified '".$this->spotColorIDs[$c[1]]."' (converted to process color)"; }
  28273. if ($this->restrictColorSpace!=3) {
  28274. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  28275. $c = $this->cmyk2rgb(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  28276. }
  28277. }
  28278. else if ($this->restrictColorSpace==1) {
  28279. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  28280. $c = $this->cmyk2gray(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  28281. }
  28282. //else if ($this->restrictColorSpace==2) { //******* ??? allow (CMYK) Spot in RGB space
  28283. // $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  28284. // $c = $this->cmyk2rgb(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  28285. //}
  28286. }
  28287. else if ($c[0]==3) { // RGB
  28288. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28289. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color specified '".$color."' (converted to CMYK)"; }
  28290. $c = $this->rgb2cmyk($c);
  28291. }
  28292. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  28293. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  28294. }
  28295. else if ($c[0]==4) { // CMYK
  28296. if ($this->PDFA && $this->restrictColorSpace!=3) {
  28297. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "CMYK color specified '".$color."' (converted to RGB)"; }
  28298. $c = $this->cmyk2rgb($c);
  28299. }
  28300. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  28301. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  28302. }
  28303. else if ($c[0]==5) { // RGBa
  28304. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28305. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  28306. $c = $this->rgb2cmyk($c);
  28307. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  28308. }
  28309. else if ($this->PDFA && $this->restrictColorSpace!=3) {
  28310. if (!$this->PDFAauto) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  28311. $c = $this->rgb2cmyk($c);
  28312. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  28313. }
  28314. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  28315. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  28316. }
  28317. else if ($c[0]==6) { // CMYKa
  28318. if ($this->PDFA && $this->restrictColorSpace!=3) {
  28319. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  28320. $c = $this->cmyk2rgb($c);
  28321. $c = array(3, $c[1], $c[2], $c[3]);
  28322. }
  28323. else if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28324. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  28325. $c = $this->cmyk2rgb($c);
  28326. $c = array(3, $c[1], $c[2], $c[3]);
  28327. }
  28328. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  28329. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  28330. }
  28331. }
  28332. return $c;
  28333. }
  28334. function rgb2gray($c) {
  28335. if (isset($c[4])) { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07)), $c[4]); }
  28336. else { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07))); }
  28337. }
  28338. function cmyk2gray($c) {
  28339. $rgb = $this->cmyk2rgb($c);
  28340. return $this->rgb2gray($rgb);
  28341. }
  28342. // mPDF 5.0.051
  28343. function rgb2cmyk($c) {
  28344. $cyan = 1 - ($c[1] / 255);
  28345. $magenta = 1 - ($c[2] / 255);
  28346. $yellow = 1 - ($c[3] / 255);
  28347. $min = min($cyan, $magenta, $yellow);
  28348. if ($min == 1) {
  28349. if ($c[0]==5) { return array (6,100,100,100,100, $c[4]); }
  28350. else { return array (4,100,100,100,100); }
  28351. // For K-Black
  28352. //if ($c[0]==5) { return array (6,0,0,0,100, $c[4]); }
  28353. //else { return array (4,0,0,0,100); }
  28354. }
  28355. $K = $min;
  28356. $black = 1 - $K;
  28357. if ($c[0]==5) { return array (6,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100, $c[4]); }
  28358. else { return array (4,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100); }
  28359. }
  28360. // mPDF 5.0.051
  28361. function cmyk2rgb($c) {
  28362. $rgb = array();
  28363. $colors = 255 - ($c[4]*2.55);
  28364. $rgb[0] = intval($colors * (255 - ($c[1]*2.55))/255);
  28365. $rgb[1] = intval($colors * (255 - ($c[2]*2.55))/255);
  28366. $rgb[2] = intval($colors * (255 - ($c[3]*2.55))/255);
  28367. if ($c[0]==6) { return array (5,$rgb[0],$rgb[1],$rgb[2], $c[5]); }
  28368. else { return array (3,$rgb[0],$rgb[1],$rgb[2]); }
  28369. }
  28370. function rgb2hsl($var_r, $var_g, $var_b) {
  28371. $var_min = min($var_r,$var_g,$var_b);
  28372. $var_max = max($var_r,$var_g,$var_b);
  28373. $del_max = $var_max - $var_min;
  28374. $l = ($var_max + $var_min) / 2;
  28375. if ($del_max == 0) {
  28376. $h = 0;
  28377. $s = 0;
  28378. }
  28379. else {
  28380. if ($l < 0.5) { $s = $del_max / ($var_max + $var_min); }
  28381. else { $s = $del_max / (2 - $var_max - $var_min); }
  28382. $del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max;
  28383. $del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max;
  28384. $del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max;
  28385. if ($var_r == $var_max) { $h = $del_b - $del_g; }
  28386. elseif ($var_g == $var_max) { $h = (1 / 3) + $del_r - $del_b; }
  28387. elseif ($var_b == $var_max) { $h = (2 / 3) + $del_g - $del_r; };
  28388. if ($h < 0) { $h += 1; }
  28389. if ($h > 1) { $h -= 1; }
  28390. }
  28391. return array($h,$s,$l);
  28392. }
  28393. function hsl2rgb($h2,$s2,$l2) {
  28394. // Input is HSL value of complementary colour, held in $h2, $s, $l as fractions of 1
  28395. // Output is RGB in normal 255 255 255 format, held in $r, $g, $b
  28396. // Hue is converted using function hue_2_rgb, shown at the end of this code
  28397. if ($s2 == 0) {
  28398. $r = $l2 * 255;
  28399. $g = $l2 * 255;
  28400. $b = $l2 * 255;
  28401. }
  28402. else {
  28403. if ($l2 < 0.5) { $var_2 = $l2 * (1 + $s2); }
  28404. else { $var_2 = ($l2 + $s2) - ($s2 * $l2); }
  28405. $var_1 = 2 * $l2 - $var_2;
  28406. $r = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 + (1 / 3)));
  28407. $g = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2));
  28408. $b = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 - (1 / 3)));
  28409. }
  28410. return array($r,$g,$b);
  28411. }
  28412. function hue_2_rgb($v1,$v2,$vh) {
  28413. // Function to convert hue to RGB, called from above
  28414. if ($vh < 0) { $vh += 1; };
  28415. if ($vh > 1) { $vh -= 1; };
  28416. if ((6 * $vh) < 1) { return ($v1 + ($v2 - $v1) * 6 * $vh); };
  28417. if ((2 * $vh) < 1) { return ($v2); };
  28418. if ((3 * $vh) < 2) { return ($v1 + ($v2 - $v1) * ((2 / 3 - $vh) * 6)); };
  28419. return ($v1);
  28420. }
  28421. // mPDF 5.0.051
  28422. function _invertColor($cor) {
  28423. if ($cor[0]==3 || $cor[0]==5) { // RGB
  28424. return array(3, (255-$cor[1]), (255-$cor[2]), (255-$cor[3]));
  28425. }
  28426. else if ($cor[0]==4 || $cor[0]==6) { // CMYK
  28427. return array(4, (100-$cor[1]), (100-$cor[2]), (100-$cor[3]), (100-$cor[4]));
  28428. }
  28429. else if ($cor[0]==1) { // Grayscale
  28430. return array(1, (255-$cor[1]));
  28431. }
  28432. // Cannot cope with non-RGB colors at present
  28433. die('Error in _invertColor - trying to invert non-RGB color');
  28434. }
  28435. // mPDF 5.0.051
  28436. function _colAtoString($cor) {
  28437. $s = '';
  28438. if ($cor[0]==1) $s = 'rgb('.$cor[1].','.$cor[1].','.$cor[1].')';
  28439. else if ($cor[0]==2) $s = 'spot('.$cor[1].','.$cor[2].')'; // SPOT COLOR
  28440. else if ($cor[0]==3) $s = 'rgb('.$cor[1].','.$cor[2].','.$cor[3].')';
  28441. else if ($cor[0]==4) $s = 'cmyk('.$cor[1].','.$cor[2].','.$cor[3].','.$cor[4].')';
  28442. else if ($cor[0]==5) $s = 'rgba('.$cor[1].','.$cor[2].','.$cor[3].','.$cor[4].')';
  28443. else if ($cor[0]==6) $s = 'cmyka('.$cor[1].','.$cor[2].','.$cor[3].','.$cor[4].','.$cor[5].')';
  28444. return $s;
  28445. }
  28446. function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){
  28447. // usefontsize - setfalse for e.g. margins - will ignore fontsize for % values
  28448. // Depends of maxsize value to make % work properly. Usually maxsize == pagewidth
  28449. // For text $maxsize = Fontsize
  28450. // Setting e.g. margin % will use maxsize (pagewidth) and em will use fontsize
  28451. //Identify size (remember: we are using 'mm' units here)
  28452. $size = trim(strtolower($size)); // mPDF 5.0.051
  28453. if ( $size == 'thin' ) $size = 1*(25.4/$this->dpi); //1 pixel width for table borders
  28454. elseif ( stristr($size,'px') ) $size *= (25.4/$this->dpi); //pixels
  28455. elseif ( stristr($size,'cm') ) $size *= 10; //centimeters
  28456. elseif ( stristr($size,'mm') ) $size += 0; //millimeters
  28457. elseif ( stristr($size,'pt') ) $size *= 25.4/72; //72 pts/inch
  28458. elseif ( stristr($size,'em') ) {
  28459. $size += 0; //make "0.83em" become simply "0.83"
  28460. if ($fontsize) { $size *= $fontsize; }
  28461. else { $size *= $maxsize; }
  28462. }
  28463. elseif ( stristr($size,'%') ) {
  28464. $size += 0; //make "90%" become simply "90"
  28465. if ($fontsize && $usefontsize) { $size *= $fontsize/100; }
  28466. else { $size *= $maxsize/100; }
  28467. }
  28468. elseif ( stristr($size,'in') ) $size *= 25.4; //inches
  28469. elseif ( stristr($size,'pc') ) $size *= 38.1/9; //PostScript picas
  28470. elseif ( stristr($size,'ex') ) { // Approximates "ex" as half of font height
  28471. $size += 0; //make "3.5ex" become simply "3.5"
  28472. if ($fontsize) { $size *= $fontsize/2; }
  28473. else { $size *= $maxsize/2; }
  28474. }
  28475. elseif ( $size == 'medium' ) $size = 3*(25.4/$this->dpi); //3 pixel width for table borders
  28476. elseif ( $size == 'thick' ) $size = 5*(25.4/$this->dpi); //5 pixel width for table borders
  28477. elseif ($size == 'xx-small') {
  28478. if ($fontsize) { $size *= $fontsize*0.7; }
  28479. else { $size *= $maxsize*0.7; }
  28480. }
  28481. elseif ($size == 'x-small') {
  28482. if ($fontsize) { $size *= $fontsize*0.77; }
  28483. else { $size *= $maxsize*0.77; }
  28484. }
  28485. elseif ($size == 'small') {
  28486. if ($fontsize) { $size *= $fontsize*0.86; }
  28487. else { $size *= $maxsize*0.86; }
  28488. }
  28489. elseif ($size == 'medium') {
  28490. if ($fontsize) { $size *= $fontsize; }
  28491. else { $size *= $maxsize; }
  28492. }
  28493. elseif ($size == 'large') {
  28494. if ($fontsize) { $size *= $fontsize*1.2; }
  28495. else { $size *= $maxsize*1.2; }
  28496. }
  28497. elseif ($size == 'x-large') {
  28498. if ($fontsize) { $size *= $fontsize*1.5; }
  28499. else { $size *= $maxsize*1.5; }
  28500. }
  28501. elseif ($size == 'xx-large') {
  28502. if ($fontsize) { $size *= $fontsize*2; }
  28503. else { $size *= $maxsize*2; }
  28504. }
  28505. else $size *= (25.4/$this->dpi); //nothing == px
  28506. return $size;
  28507. }
  28508. function lesser_entity_decode($html) {
  28509. //supports the most used entity codes (only does ascii safe characters)
  28510. $html = str_replace("&nbsp;"," ",$html);
  28511. $html = str_replace("&lt;","<",$html);
  28512. $html = str_replace("&gt;",">",$html);
  28513. $html = str_replace("&apos;","'",$html);
  28514. $html = str_replace("&quot;",'"',$html);
  28515. $html = str_replace("&amp;","&",$html);
  28516. return $html;
  28517. }
  28518. function AdjustHTML($html,$directionality='ltr',$usepre=true, $tabSpaces=8) {
  28519. //Try to make the html text more manageable (turning it into XHTML)
  28520. /*-- ANNOTATIONS --*/
  28521. preg_match_all("/(<annotation.*?>)/si", $html, $m);
  28522. if (count($m[1])) {
  28523. for($i=0;$i<count($m[1]);$i++) {
  28524. $sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]);
  28525. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  28526. }
  28527. }
  28528. /*-- END ANNOTATIONS --*/
  28529. //Remove javascript code from HTML (should not appear in the PDF file)
  28530. $html = preg_replace('/<script.*?<\/script>/is','',$html);
  28531. //Remove special comments
  28532. $html = preg_replace('/<!--mpdf/i','',$html);
  28533. $html = preg_replace('/mpdf-->/i','',$html);
  28534. //Remove comments from HTML (should not appear in the PDF file)
  28535. $html = preg_replace('/<!--.*?-->/s','',$html);
  28536. $html = preg_replace('/\f/','',$html); //replace formfeed by nothing
  28537. $html = preg_replace('/\r/','',$html); //replace carriage return by nothing
  28538. // Well formed XHTML end tags
  28539. $html = preg_replace('/<(br|hr)\/>/i',"<\\1 />",$html);
  28540. // Get rid of empty <thead></thead>
  28541. $html = preg_replace('/<thead>\s*<\/thead>/i','',$html);
  28542. $html = preg_replace('/<tfoot>\s*<\/tfoot>/i','',$html);
  28543. $html = preg_replace('/<table[^>]*>\s*<\/table>/i','',$html);
  28544. $html = preg_replace('/<tr>\s*<\/tr>/i','',$html); // mPDF 5.1.007
  28545. // Remove spaces at end of table cells
  28546. $html = preg_replace("/[ ]+<\/t(d|h)/",'</t\\1',$html);
  28547. $html = preg_replace("/[ ]*<dottab\s*[\/]*>[ ]*/",'<dottab />',$html);
  28548. // Concatenates any Substitute characters from symbols/dingbats
  28549. $html = str_replace('</tts><tts>','|',$html);
  28550. $html = str_replace('</ttz><ttz>','|',$html);
  28551. $html = str_replace('</tta><tta>','|',$html);
  28552. $html = mb_eregi_replace('/<br \/>\s*/is',"<br />",$html);
  28553. if ($usepre) //used to keep \n on content inside <pre> and inside <textarea>
  28554. {
  28555. // Preserve '\n's in content between the tags <pre> and </pre>
  28556. // mPDF 5.0.053
  28557. if (preg_match('/<pre/',$html)) {
  28558. $html_a = preg_split('/(\<\/?pre[^\>]*\>)/', $html, -1, 2);
  28559. $h = array();
  28560. $c=0;
  28561. foreach($html_a AS $s) {
  28562. if ($c>1 && preg_match('/^<\/pre/i',$s)) { $c--; $s=preg_replace('/<\/pre/i','</innerpre',$s); }
  28563. else if ($c>0 && preg_match('/^<pre/i',$s)) { $c++; $s=preg_replace('/<pre/i','<innerpre',$s); }
  28564. else if (preg_match('/^<pre/i',$s)) { $c++; }
  28565. else if (preg_match('/^<\/pre/i',$s)) { $c--; }
  28566. array_push($h, $s);
  28567. }
  28568. $html = implode("", $h);
  28569. }
  28570. $thereispre = preg_match_all('#<pre(.*?)>(.*?)</pre>#si',$html,$temp);
  28571. // Preserve '\n's in content between the tags <textarea> and </textarea>
  28572. $thereistextarea = preg_match_all('#<textarea(.*?)>(.*?)</textarea>#si',$html,$temp2);
  28573. $html = preg_replace('/[\n]/',' ',$html); //replace linefeed by spaces
  28574. $html = preg_replace('/[\t]/',' ',$html); //replace tabs by spaces
  28575. // Converts < to &lt; when not a tag
  28576. $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
  28577. // mPDF changed to prevent &nbsp; chars replaced
  28578. $html = preg_replace("/[ ]+/",' ',$html);
  28579. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  28580. $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html);
  28581. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  28582. $html = preg_replace('/\/li>\s+<li/i','/li><li',$html);
  28583. $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
  28584. $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html);
  28585. $iterator = 0;
  28586. while($thereispre) //Recover <pre attributes>content</pre>
  28587. {
  28588. // mPDF 5.0.053
  28589. $temp[2][$iterator] = preg_replace("/^([^\n\t]*?)\t/me", "stripslashes('\\1') . str_repeat(' ', ( $tabSpaces - (mb_strlen(stripslashes('\\1')) % $tabSpaces)) )",$temp[2][$iterator]);
  28590. // mPDF 5.0.053
  28591. $temp[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp[2][$iterator]);
  28592. $temp[2][$iterator] = preg_replace('/\n/',"<br />",$temp[2][$iterator]);
  28593. $html = preg_replace('#<pre(.*?)>(.*?)</pre>#si','<erp'.$temp[1][$iterator].'>'.$temp[2][$iterator].'</erp>',$html,1);
  28594. $thereispre--;
  28595. $iterator++;
  28596. }
  28597. $iterator = 0;
  28598. while($thereistextarea) //Recover <textarea attributes>content</textarea>
  28599. {
  28600. $temp2[2][$iterator] = preg_replace('/&/',"&amp;",$temp2[2][$iterator]);
  28601. $temp2[2][$iterator] = preg_replace('/</',"&lt;",$temp2[2][$iterator]);
  28602. $temp2[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp2[2][$iterator]);
  28603. $temp2[2][$iterator] = preg_replace('/[ ]/',"&nbsp;",$temp2[2][$iterator]);
  28604. $html = preg_replace('#<textarea(.*?)>(.*?)</textarea>#si','<aeratxet'.$temp2[1][$iterator].'>'.trim($temp2[2][$iterator]) .'</aeratxet>',$html,1);
  28605. $thereistextarea--;
  28606. $iterator++;
  28607. }
  28608. //Restore original tag names
  28609. $html = str_replace("<erp","<pre",$html);
  28610. $html = str_replace("</erp>","</pre>",$html);
  28611. $html = str_replace("<aeratxet","<textarea",$html);
  28612. $html = str_replace("</aeratxet>","</textarea>",$html);
  28613. // mPDF 5.0.053
  28614. $html = str_replace("</innerpre","</pre",$html);
  28615. $html = str_replace("<innerpre","<pre",$html);
  28616. // (the code above might slowdown overall performance?)
  28617. } //end of if($usepre)
  28618. else
  28619. {
  28620. $html = preg_replace('/\n/',' ',$html); //replace linefeed by spaces
  28621. $html = preg_replace('/\t/',' ',$html); //replace tabs by spaces
  28622. // Converts < to &lt; when not a tag
  28623. $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
  28624. // mPDF changed to prevent &nbsp; chars replaced
  28625. $html = preg_replace("/[ ]+/",' ',$html);
  28626. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  28627. $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html);
  28628. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  28629. $html = preg_replace('/\/li>\s+<li/i','/li><li',$html);
  28630. $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
  28631. $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html);
  28632. }
  28633. $html = preg_replace('/<textarea([^>]*)><\/textarea>/si','<textarea\\1> </textarea>',$html);
  28634. $html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html); // *TABLES*
  28635. $html = preg_replace("/\xbb\xa4\xac/", "\n", $html);
  28636. return $html;
  28637. }
  28638. /*-- LISTS --*/
  28639. // mPDF 5.0.057
  28640. function dec2other($num, $cp) {
  28641. $nstr = (string) $num;
  28642. $rnum = '';
  28643. for ($i=0;$i<strlen($nstr);$i++) {
  28644. if ($this->_charDefined($this->CurrentFont['cw'],$cp+intval($nstr[$i]))) { // contains arabic-indic numbers
  28645. $rnum .= code2utf($cp+intval($nstr[$i]));
  28646. }
  28647. else { $rnum .= $nstr[$i]; }
  28648. }
  28649. return $rnum;
  28650. }
  28651. function dec2alpha($valor,$toupper="true"){
  28652. // returns a string from A-Z to AA-ZZ to AAA-ZZZ
  28653. // OBS: A = 65 ASCII TABLE VALUE
  28654. if (($valor < 1) || ($valor > 18278)) return "?"; //supports 'only' up to 18278
  28655. $c1 = $c2 = $c3 = '';
  28656. if ($valor > 702) // 3 letters (up to 18278)
  28657. {
  28658. $c1 = 65 + floor(($valor-703)/676);
  28659. $c2 = 65 + floor((($valor-703)%676)/26);
  28660. $c3 = 65 + floor((($valor-703)%676)%26);
  28661. }
  28662. elseif ($valor > 26) // 2 letters (up to 702)
  28663. {
  28664. $c1 = (64 + (int)(($valor-1) / 26));
  28665. $c2 = (64 + (int)($valor % 26));
  28666. if ($c2 == 64) $c2 += 26;
  28667. }
  28668. else // 1 letter (up to 26)
  28669. {
  28670. $c1 = (64 + $valor);
  28671. }
  28672. $alpha = chr($c1);
  28673. if ($c2 != '') $alpha .= chr($c2);
  28674. if ($c3 != '') $alpha .= chr($c3);
  28675. if (!$toupper) $alpha = strtolower($alpha);
  28676. return $alpha;
  28677. }
  28678. function dec2roman($valor,$toupper=true){
  28679. //returns a string as a roman numeral
  28680. $r1=$r2=$r3=$r4='';
  28681. if (($valor >= 5000) || ($valor < 1)) return "?"; //supports 'only' up to 4999
  28682. $aux = (int)($valor/1000);
  28683. if ($aux!==0)
  28684. {
  28685. $valor %= 1000;
  28686. while($aux!==0)
  28687. {
  28688. $r1 .= "M";
  28689. $aux--;
  28690. }
  28691. }
  28692. $aux = (int)($valor/100);
  28693. if ($aux!==0)
  28694. {
  28695. $valor %= 100;
  28696. switch($aux){
  28697. case 3: $r2="C";
  28698. case 2: $r2.="C";
  28699. case 1: $r2.="C"; break;
  28700. case 9: $r2="CM"; break;
  28701. case 8: $r2="C";
  28702. case 7: $r2.="C";
  28703. case 6: $r2.="C";
  28704. case 5: $r2="D".$r2; break;
  28705. case 4: $r2="CD"; break;
  28706. default: break;
  28707. }
  28708. }
  28709. $aux = (int)($valor/10);
  28710. if ($aux!==0)
  28711. {
  28712. $valor %= 10;
  28713. switch($aux){
  28714. case 3: $r3="X";
  28715. case 2: $r3.="X";
  28716. case 1: $r3.="X"; break;
  28717. case 9: $r3="XC"; break;
  28718. case 8: $r3="X";
  28719. case 7: $r3.="X";
  28720. case 6: $r3.="X";
  28721. case 5: $r3="L".$r3; break;
  28722. case 4: $r3="XL"; break;
  28723. default: break;
  28724. }
  28725. }
  28726. switch($valor){
  28727. case 3: $r4="I";
  28728. case 2: $r4.="I";
  28729. case 1: $r4.="I"; break;
  28730. case 9: $r4="IX"; break;
  28731. case 8: $r4="I";
  28732. case 7: $r4.="I";
  28733. case 6: $r4.="I";
  28734. case 5: $r4="V".$r4; break;
  28735. case 4: $r4="IV"; break;
  28736. default: break;
  28737. }
  28738. $roman = $r1.$r2.$r3.$r4;
  28739. if (!$toupper) $roman = strtolower($roman);
  28740. return $roman;
  28741. }
  28742. /*-- END LISTS --*/
  28743. //===========================
  28744. /*-- IMPORTS --*/
  28745. function SetImportUse() {
  28746. $this->enableImports = true;
  28747. ini_set('auto_detect_line_endings',1);
  28748. require_once(_MPDF_PATH."mpdfi/pdf_context.php");
  28749. require_once(_MPDF_PATH."mpdfi/pdf_parser.php");
  28750. require_once(_MPDF_PATH."mpdfi/fpdi_pdf_parser.php");
  28751. }
  28752. // from mPDFI
  28753. function hex2str($hex) {
  28754. return pack("H*", str_replace(array("\r","\n"," "),"", $hex));
  28755. }
  28756. function str2hex($str) {
  28757. return current(unpack("H*",$str));
  28758. }
  28759. function pdf_write_value(&$value) {
  28760. switch ($value[0]) {
  28761. case PDF_TYPE_NUMERIC :
  28762. case PDF_TYPE_TOKEN :
  28763. // A numeric value or a token.
  28764. // Simply output them
  28765. $this->_out($value[1]." ", false);
  28766. break;
  28767. case PDF_TYPE_ARRAY :
  28768. // An array. Output the proper
  28769. // structure and move on.
  28770. $this->_out("[",false);
  28771. for ($i = 0; $i < count($value[1]); $i++) {
  28772. $this->pdf_write_value($value[1][$i]);
  28773. }
  28774. $this->_out("]");
  28775. break;
  28776. case PDF_TYPE_DICTIONARY :
  28777. // A dictionary.
  28778. $this->_out("<<",false);
  28779. reset ($value[1]);
  28780. while (list($k, $v) = each($value[1])) {
  28781. $this->_out($k . " ",false);
  28782. $this->pdf_write_value($v);
  28783. }
  28784. $this->_out(">>");
  28785. break;
  28786. case PDF_TYPE_OBJREF :
  28787. // An indirect object reference
  28788. // Fill the object stack if needed
  28789. $cpfn =& $this->current_parser->filename;
  28790. if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
  28791. $this->_newobj(false,true);
  28792. $this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  28793. $this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  28794. }
  28795. $objid = $this->_don_obj_stack[$cpfn][$value[1]][0];
  28796. $this->_out("{$objid} 0 R"); //{$value[2]}
  28797. break;
  28798. case PDF_TYPE_STRING :
  28799. if ($this->encrypted) {
  28800. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  28801. $value[1] = $this->_escape($value[1]);
  28802. }
  28803. // A string.
  28804. $this->_out('('.$value[1].')');
  28805. break;
  28806. case PDF_TYPE_STREAM :
  28807. // A stream. First, output the
  28808. // stream dictionary, then the
  28809. // stream data itself.
  28810. $this->pdf_write_value($value[1]);
  28811. if ($this->encrypted) {
  28812. $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
  28813. }
  28814. $this->_out("stream");
  28815. $this->_out($value[2][1]);
  28816. $this->_out("endstream");
  28817. break;
  28818. case PDF_TYPE_HEX :
  28819. if ($this->encrypted) {
  28820. $value[1] = $this->hex2str($value[1]);
  28821. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  28822. // remake hexstring of encrypted string
  28823. $value[1] = $this->str2hex($value[1]);
  28824. }
  28825. $this->_out("<".$value[1].">");
  28826. break;
  28827. case PDF_TYPE_NULL :
  28828. // The null object.
  28829. $this->_out("null");
  28830. break;
  28831. }
  28832. }
  28833. // ========== OVERWRITE SEARCH STRING IN A PDF FILE ================
  28834. function OverWrite($file_in, $search, $replacement, $dest="D", $file_out="mpdf" ) {
  28835. $pdf = file_get_contents($file_in);
  28836. if (!is_array($search)) {
  28837. $x = $search;
  28838. $search = array($x);
  28839. }
  28840. if (!is_array($replacement)) {
  28841. $x = $replacement;
  28842. $search = array($x);
  28843. }
  28844. if (!$this->onlyCoreFonts && !$this->usingCoreFont) { // mPDF 5.0
  28845. foreach($search AS $k=>$val) {
  28846. $search[$k] = $this->UTF8ToUTF16BE($search[$k] , false);
  28847. $search[$k] = $this->_escape($search[$k]);
  28848. $replacement[$k] = $this->UTF8ToUTF16BE($replacement[$k], false);
  28849. $replacement[$k] = $this->_escape($replacement[$k]);
  28850. }
  28851. }
  28852. else {
  28853. foreach($replacement AS $k=>$val) {
  28854. $replacement[$k] = mb_convert_encoding($replacement[$k],$this->mb_enc,'utf-8');
  28855. $replacement[$k] = $this->_escape($replacement[$k]);
  28856. }
  28857. }
  28858. // Get xref into array
  28859. $xref = array();
  28860. preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s",$pdf,$m);
  28861. $xref_objid = $m[1];
  28862. preg_match_all('/(\d{10}) (\d{5}) (f|n)/',$m[2],$x);
  28863. for($i=0; $i<count($x[0]); $i++) {
  28864. $xref[] = array(intval($x[1][$i]), $x[2][$i], $x[3][$i]);
  28865. }
  28866. $changes = array();
  28867. preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s",$pdf,$m);
  28868. preg_match_all("/(\d+) 0 R /s",$m[1],$o);
  28869. $objlist = $o[1];
  28870. foreach($objlist AS $obj) {
  28871. if ($this->compress) {
  28872. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  28873. }
  28874. else {
  28875. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  28876. }
  28877. $s = $m[2];
  28878. if (!$s) { continue; }
  28879. $oldlen = $m[1];
  28880. if ($this->encrypted) {
  28881. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  28882. }
  28883. if ($this->compress) {
  28884. $s = gzuncompress($s);
  28885. }
  28886. foreach($search AS $k=>$val) {
  28887. $s = str_replace($search[$k],$replacement[$k],$s);
  28888. }
  28889. if ($this->compress) {
  28890. $s = gzcompress($s);
  28891. }
  28892. if ($this->encrypted) {
  28893. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  28894. }
  28895. $newlen = strlen($s);
  28896. $changes[($xref[$obj+1][0])] = ($newlen - $oldlen) + (strlen($newlen) - strlen($oldlen ));
  28897. if ($this->compress) {
  28898. $newstr = ($obj+1) . " 0 obj\n<</Filter /FlateDecode /Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  28899. }
  28900. else {
  28901. $newstr = ($obj+1) . " 0 obj\n<</Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  28902. }
  28903. $pdf = str_replace($m[0],$newstr,$pdf);
  28904. }
  28905. // Update xref in PDF
  28906. krsort($changes);
  28907. $newxref = "xref\n0 ".$xref_objid."\n";
  28908. foreach($xref AS $v) {
  28909. foreach($changes AS $ck => $cv) {
  28910. if ($v[0] > $ck) { $v[0] += $cv; }
  28911. }
  28912. $newxref .= sprintf('%010d',$v[0]) . ' ' . $v[1] . ' ' .$v[2] . " \n";
  28913. }
  28914. $newxref .= "trailer";
  28915. $pdf = preg_replace("/xref\n0 \d+\n.*?\ntrailer/s",$newxref,$pdf);
  28916. // Update startxref in PDF
  28917. preg_match("/startxref\n(\d+)\n%%EOF/s", $pdf, $m);
  28918. $startxref = $m[1];
  28919. $startxref += array_sum($changes);
  28920. $pdf = preg_replace("/startxref\n(\d+)\n%%EOF/s","startxref\n".$startxref."\n%%EOF",$pdf);
  28921. // OUTPUT
  28922. switch($dest) {
  28923. case 'I':
  28924. //Send to standard output
  28925. if(isset($_SERVER['SERVER_NAME']))
  28926. {
  28927. //We send to a browser
  28928. Header('Content-Type: application/pdf');
  28929. Header('Content-Length: '.strlen($pdf));
  28930. Header('Content-disposition: inline; filename='.$file_out);
  28931. }
  28932. echo $pdf;
  28933. break;
  28934. case 'F':
  28935. //Save to local file
  28936. if (!$file_out) { $file_out = 'mpdf.pdf'; }
  28937. $f=fopen($file_out,'wb');
  28938. if(!$f) die('Unable to create output file: '.$file_out);
  28939. fwrite($f,$pdf,strlen($pdf));
  28940. fclose($f);
  28941. break;
  28942. case 'S':
  28943. //Return as a string
  28944. return $pdf;
  28945. case 'D':
  28946. default:
  28947. //Download file
  28948. if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  28949. Header('Content-Type: application/force-download');
  28950. else
  28951. Header('Content-Type: application/octet-stream');
  28952. Header('Content-Length: '.strlen($pdf));
  28953. Header('Content-disposition: attachment; filename='.$file_out);
  28954. echo $pdf;
  28955. break;
  28956. }
  28957. }
  28958. function GetTemplateSize($tplidx, $_w=0, $_h=0) {
  28959. if (!$this->tpls[$tplidx])
  28960. return false;
  28961. $w = $this->tpls[$tplidx]['box']['w'];
  28962. $h = $this->tpls[$tplidx]['box']['h'];
  28963. if ($_w == 0 and $_h == 0) {
  28964. $_w = $w;
  28965. $_h = $h;
  28966. }
  28967. if($_w==0)
  28968. $_w=$_h*$w/$h;
  28969. if($_h==0)
  28970. $_h=$_w*$h/$w;
  28971. return array("w" => $_w, "h" => $_h);
  28972. }
  28973. // Thumbnails
  28974. function Thumbnail($file, $npr=3, $spacing=10) { //$npr = number per row
  28975. $w = (($this->pgwidth + $spacing)/$npr) - $spacing;
  28976. $oldlinewidth = $this->LineWidth;
  28977. $this->SetLineWidth(0.02);
  28978. $this->SetDColor($this->ConvertColor(0)); // mPDF 5.0.051
  28979. $h = 0;
  28980. $maxh = 0;
  28981. $x = $_x = $this->lMargin;
  28982. $_y = $this->tMargin;
  28983. if ($this->y==0) { $y = $_y; } else { $y = $this->y; }
  28984. $pagecount = $this->SetSourceFile($file);
  28985. for ($n = 1; $n <= $pagecount; $n++) {
  28986. $tplidx = $this->ImportPage($n);
  28987. $size = $this->useTemplate($tplidx, $x, $y, $w);
  28988. $this->Rect($x, $y, $size['w'], $size['h']);
  28989. $h = max($h, $size['h']);
  28990. $maxh = max($h, $maxh);
  28991. if ($n % $npr == 0) {
  28992. if (($y + $h + $spacing + $maxh)>$this->PageBreakTrigger && $n != $pagecount) {
  28993. $this->AddPage();
  28994. $x = $_x;
  28995. $y = $_y;
  28996. }
  28997. else {
  28998. $y += $h+$spacing ;
  28999. $x = $_x;
  29000. $h = 0;
  29001. }
  29002. }
  29003. else {
  29004. $x += $w+$spacing ;
  29005. }
  29006. }
  29007. $this->SetLineWidth($oldlinewidth);
  29008. }
  29009. function SetSourceFile($filename) {
  29010. $this->current_filename = $filename;
  29011. $fn =& $this->current_filename;
  29012. if (!isset($this->parsers[$fn]))
  29013. // $this->parsers[$fn] =& new fpdi_pdf_parser($fn,$this);
  29014. $this->parsers[$fn] = new fpdi_pdf_parser($fn,$this);
  29015. if (!$this->parsers[$fn]->success) {
  29016. $this->Error($this->parsers[$fn]->errormsg); // Delete this line to return false on fail
  29017. return false;
  29018. }
  29019. $this->current_parser =& $this->parsers[$fn];
  29020. return $this->parsers[$fn]->getPageCount();
  29021. }
  29022. function ImportPage($pageno=1, $crop_x=null, $crop_y=null, $crop_w=0, $crop_h=0, $boxName='/CropBox') {
  29023. $fn =& $this->current_filename;
  29024. $parser =& $this->parsers[$fn];
  29025. $parser->setPageno($pageno);
  29026. $this->tpl++;
  29027. $this->tpls[$this->tpl] = array();
  29028. $tpl =& $this->tpls[$this->tpl];
  29029. $tpl['parser'] =& $parser;
  29030. $tpl['resources'] = $parser->getPageResources();
  29031. $tpl['buffer'] = $parser->getContent();
  29032. if (!in_array($boxName, $parser->availableBoxes))
  29033. return $this->Error(sprintf("Unknown box: %s", $boxName));
  29034. $pageboxes = $parser->getPageBoxes($pageno);
  29035. /**
  29036. * MediaBox
  29037. * CropBox: Default -> MediaBox
  29038. * BleedBox: Default -> CropBox
  29039. * TrimBox: Default -> CropBox
  29040. * ArtBox: Default -> CropBox
  29041. */
  29042. if (!isset($pageboxes[$boxName]) && ($boxName == "/BleedBox" || $boxName == "/TrimBox" || $boxName == "/ArtBox"))
  29043. $boxName = "/CropBox";
  29044. if (!isset($pageboxes[$boxName]) && $boxName == "/CropBox")
  29045. $boxName = "/MediaBox";
  29046. if (!isset($pageboxes[$boxName]))
  29047. return false;
  29048. $box = $pageboxes[$boxName];
  29049. $tpl['box'] = $box;
  29050. // To build an array that can be used by useTemplate()
  29051. $this->tpls[$this->tpl] = array_merge($this->tpls[$this->tpl],$box);
  29052. // An imported page will start at 0,0 everytime. Translation will be set in _putformxobjects()
  29053. $tpl['x'] = 0;
  29054. $tpl['y'] = 0;
  29055. $tpl['w'] = $tpl['box']['w'] ;
  29056. $tpl['h'] = $tpl['box']['h'] ;
  29057. if ($crop_w) { $tpl['box']['w'] = $crop_w; }
  29058. if ($crop_h) { $tpl['box']['h'] = $crop_h; }
  29059. if (isset($crop_x)) { $tpl['box']['x'] = $crop_x; }
  29060. if (isset($crop_y)) {$tpl['box']['y'] = $tpl['h'] - $crop_y - $crop_h ; }
  29061. $page =& $parser->pages[$parser->pageno];
  29062. // fix for rotated pages
  29063. $rotation = $parser->getPageRotation($pageno);
  29064. if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0 && $tpl['box']['w'] == $tpl['w']) {
  29065. $steps = $angle / 90;
  29066. $_w = $tpl['w'];
  29067. $_h = $tpl['h'];
  29068. $tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
  29069. $tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
  29070. if ($steps % 2 != 0) {
  29071. $x = $y = ($steps == 1 || $steps == -3) ? $tpl['h'] : $tpl['w'];
  29072. } else {
  29073. $x = $tpl['w'];
  29074. $y = $tpl['h'];
  29075. }
  29076. $cx=($x/2+$tpl['box']['x'])*$this->k;
  29077. $cy=($y/2+$tpl['box']['y'])*$this->k;
  29078. $angle*=-1;
  29079. $angle*=M_PI/180;
  29080. $c=cos($angle);
  29081. $s=sin($angle);
  29082. $tpl['box']['w'] = $tpl['w'] ;
  29083. $tpl['box']['h'] = $tpl['h'] ;
  29084. $tpl['buffer'] = sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm %s Q',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy, $tpl['buffer']);
  29085. }
  29086. return $this->tpl;
  29087. }
  29088. function UseTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
  29089. if (!isset($this->tpls[$tplidx]))
  29090. $this->Error("Template does not exist!");
  29091. if($this->state==0) { $this->AddPage(); }
  29092. $out = 'q 0 J 1 w 0 j 0 G'."\n"; // reset standard values
  29093. $x = $this->tpls[$tplidx]['x'];
  29094. $y = $this->tpls[$tplidx]['y'];
  29095. $w = $this->tpls[$tplidx]['w'];
  29096. $h = $this->tpls[$tplidx]['h'];
  29097. if ($_x == null) { $_x = $x; }
  29098. if ($_y == null) { $_y = $y; }
  29099. if ($_x === -1) { $_x = $this->x; }
  29100. if ($_y === -1) { $_y = $this->y; }
  29101. $wh = $this->getTemplateSize($tplidx,$_w,$_h);
  29102. $_w = $wh['w'];
  29103. $_h = $wh['h'];
  29104. $out .= sprintf("q %.4f 0 0 %.4f %.2f %.2f cm", ($_w/$this->tpls[$tplidx]['box']['w']), ($_h/$this->tpls[$tplidx]['box']['h']), $_x*$this->k, ($this->h-($_y+$_h))*$this->k)."\n";
  29105. $out .= $this->tplprefix.$tplidx." Do Q\n";
  29106. $s = array("w" => $_w, "h" => $_h);
  29107. $out .= "Q\n";
  29108. $this->pages[$this->page] = $out . $this->pages[$this->page];
  29109. return $s;
  29110. }
  29111. function SetPageTemplate($tplidx='') {
  29112. if (!isset($this->tpls[$tplidx])) {
  29113. $this->pageTemplate = '';
  29114. return false;
  29115. }
  29116. $this->pageTemplate = $tplidx;
  29117. }
  29118. function SetDocTemplate($file='', $continue=0) {
  29119. $this->docTemplate = $file;
  29120. $this->docTemplateContinue = $continue;
  29121. }
  29122. /*-- END IMPORTS --*/
  29123. }//end of Class
  29124. ?>