/php/codeigniter/pdf/application/third_party/mpdf/mpdf.php

https://github.com/4vconnect/api · PHP · 32723 lines · 29222 code · 1782 blank · 1719 comment · 6746 complexity · f4f475cdb5506e9156998951b51e7bcc MD5 · raw file

  1. <?php
  2. // ******************************************************************************
  3. // Software: mPDF, Unicode-HTML Free PDF generator *
  4. // Version: 5.7 based on *
  5. // FPDF by Olivier PLATHEY *
  6. // HTML2FPDF by Renato Coelho *
  7. // Date: 2013-07-14 *
  8. // Author: Ian Back <ianb@bpm1.com> *
  9. // License: GPL *
  10. // *
  11. // Changes: See changelog.txt *
  12. // ******************************************************************************
  13. define('mPDF_VERSION','5.7');
  14. //Scale factor
  15. define('_MPDFK', (72/25.4));
  16. /*-- HTML-CSS --*/
  17. define('AUTOFONT_CJK',1);
  18. define('AUTOFONT_THAIVIET',2);
  19. define('AUTOFONT_RTL',4);
  20. define('AUTOFONT_INDIC',8);
  21. define('AUTOFONT_ALL',15);
  22. define('_BORDER_ALL',15);
  23. define('_BORDER_TOP',8);
  24. define('_BORDER_RIGHT',4);
  25. define('_BORDER_BOTTOM',2);
  26. define('_BORDER_LEFT',1);
  27. /*-- END HTML-CSS --*/
  28. if (!defined('_MPDF_PATH')) define('_MPDF_PATH', dirname(preg_replace('/\\\\/','/',__FILE__)) . '/');
  29. if (!defined('_MPDF_URI')) define('_MPDF_URI',_MPDF_PATH);
  30. require_once(_MPDF_PATH.'includes/functions.php');
  31. require_once(_MPDF_PATH.'config_cp.php');
  32. if (!defined('_JPGRAPH_PATH')) define("_JPGRAPH_PATH", _MPDF_PATH.'jpgraph/');
  33. if (!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", _MPDF_PATH.'tmp/');
  34. if (!defined('_MPDF_TTFONTPATH')) { define('_MPDF_TTFONTPATH',_MPDF_PATH.'ttfonts/'); }
  35. if (!defined('_MPDF_TTFONTDATAPATH')) { define('_MPDF_TTFONTDATAPATH',_MPDF_PATH.'ttfontdata/'); }
  36. $errorlevel=error_reporting();
  37. $errorlevel=error_reporting($errorlevel & ~E_NOTICE);
  38. //error_reporting(E_ALL);
  39. if(function_exists("date_default_timezone_set")) {
  40. if (ini_get("date.timezone")=="") { date_default_timezone_set("Europe/London"); }
  41. }
  42. if (!function_exists("mb_strlen")) { die("Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled."); }
  43. if (!defined('PHP_VERSION_ID')) {
  44. $version = explode('.', PHP_VERSION);
  45. define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
  46. }
  47. // Machine dependent number of bytes used to pack "double" into binary (used in cacheTables)
  48. $test = pack("d", 134455.474557333333666);
  49. define("_DSIZE", strlen($test));
  50. class mPDF
  51. {
  52. ///////////////////////////////
  53. // EXTERNAL (PUBLIC) VARIABLES
  54. // Define these in config.php
  55. ///////////////////////////////
  56. var $CJKforceend; // mPDF 5.6.40
  57. // mPDF 5.6.34
  58. var $h2bookmarks;
  59. var $h2toc;
  60. var $decimal_align; // mPDF 5.6.13
  61. var $margBuffer; // mPDF 5.4.04
  62. var $splitTableBorderWidth; // mPDF 5.4.16
  63. var $cacheTables;
  64. var $bookmarkStyles;
  65. var $useActiveForms;
  66. var $repackageTTF;
  67. var $allowCJKorphans;
  68. var $allowCJKoverflow;
  69. var $useKerning;
  70. var $restrictColorSpace;
  71. var $bleedMargin;
  72. var $crossMarkMargin;
  73. var $cropMarkMargin;
  74. var $cropMarkLength;
  75. var $nonPrintMargin;
  76. var $PDFX;
  77. var $PDFXauto;
  78. var $PDFA;
  79. var $PDFAauto;
  80. var $ICCProfile;
  81. var $printers_info;
  82. var $iterationCounter;
  83. var $smCapsScale;
  84. var $smCapsStretch;
  85. var $backupSubsFont;
  86. var $backupSIPFont;
  87. var $debugfonts;
  88. var $useAdobeCJK;
  89. var $percentSubset;
  90. var $maxTTFFilesize;
  91. var $BMPonly;
  92. var $tableMinSizePriority;
  93. var $dpi;
  94. var $watermarkImgAlphaBlend;
  95. var $watermarkImgBehind;
  96. var $justifyB4br;
  97. var $packTableData;
  98. var $pgsIns;
  99. var $simpleTables;
  100. var $enableImports;
  101. var $debug;
  102. var $showStats;
  103. var $setAutoTopMargin;
  104. var $setAutoBottomMargin;
  105. var $autoMarginPadding;
  106. var $collapseBlockMargins;
  107. var $falseBoldWeight;
  108. var $normalLineheight;
  109. var $progressBar;
  110. var $incrementFPR1;
  111. var $incrementFPR2;
  112. var $incrementFPR3;
  113. var $incrementFPR4;
  114. var $SHYlang;
  115. var $SHYleftmin;
  116. var $SHYrightmin;
  117. var $SHYcharmin;
  118. var $SHYcharmax;
  119. var $SHYlanguages;
  120. // PageNumber Conditional Text
  121. var $pagenumPrefix;
  122. var $pagenumSuffix;
  123. var $nbpgPrefix;
  124. var $nbpgSuffix;
  125. var $showImageErrors;
  126. var $allow_output_buffering;
  127. var $autoPadding;
  128. var $useGraphs;
  129. var $autoFontGroupSize;
  130. var $tabSpaces;
  131. var $useLang;
  132. var $restoreBlockPagebreaks;
  133. var $watermarkTextAlpha;
  134. var $watermarkImageAlpha;
  135. var $watermark_size;
  136. var $watermark_pos;
  137. var $annotSize;
  138. var $annotMargin;
  139. var $annotOpacity;
  140. var $title2annots;
  141. var $keepColumns;
  142. var $keep_table_proportions;
  143. var $ignore_table_widths;
  144. var $ignore_table_percents;
  145. var $list_align_style;
  146. var $list_number_suffix;
  147. var $useSubstitutions;
  148. var $CSSselectMedia;
  149. var $forcePortraitHeaders;
  150. var $forcePortraitMargins;
  151. var $displayDefaultOrientation;
  152. var $ignore_invalid_utf8;
  153. var $allowedCSStags;
  154. var $onlyCoreFonts;
  155. var $allow_charset_conversion;
  156. var $jSWord;
  157. var $jSmaxChar;
  158. var $jSmaxCharLast;
  159. var $jSmaxWordLast;
  160. var $max_colH_correction;
  161. var $table_error_report;
  162. var $table_error_report_param;
  163. var $biDirectional;
  164. var $text_input_as_HTML;
  165. var $anchor2Bookmark;
  166. var $list_indent_first_level;
  167. var $shrink_tables_to_fit;
  168. var $allow_html_optional_endtags;
  169. var $img_dpi;
  170. var $defaultheaderfontsize;
  171. var $defaultheaderfontstyle;
  172. var $defaultheaderline;
  173. var $defaultfooterfontsize;
  174. var $defaultfooterfontstyle;
  175. var $defaultfooterline;
  176. var $header_line_spacing;
  177. var $footer_line_spacing;
  178. var $pregUHCchars;
  179. var $pregSJISchars;
  180. var $pregCJKchars;
  181. var $pregASCIIchars1;
  182. var $pregASCIIchars2;
  183. var $pregASCIIchars3;
  184. var $pregVIETchars;
  185. var $pregVIETPluschars;
  186. var $pregRTLchars;
  187. var $pregHEBchars;
  188. var $pregARABICchars;
  189. var $pregNonARABICchars;
  190. // INDIC
  191. var $pregHIchars;
  192. var $pregBNchars;
  193. var $pregPAchars;
  194. var $pregGUchars;
  195. var $pregORchars;
  196. var $pregTAchars;
  197. var $pregTEchars;
  198. var $pregKNchars;
  199. var $pregMLchars;
  200. var $pregSHchars;
  201. var $pregINDextra;
  202. var $mirrorMargins;
  203. var $default_lineheight_correction;
  204. var $watermarkText;
  205. var $watermarkImage;
  206. var $showWatermarkText;
  207. var $showWatermarkImage;
  208. var $fontsizes;
  209. // Aliases for backward compatability
  210. var $UnvalidatedText; // alias = $watermarkText
  211. var $TopicIsUnvalidated; // alias = $showWatermarkText
  212. var $useOddEven; // alias = $mirrorMargins
  213. var $useSubstitutionsMB; // alias = $useSubstitutions
  214. //////////////////////
  215. // CLASS OBJECTS
  216. //////////////////////
  217. var $cssmgr;
  218. var $grad;
  219. var $bmp;
  220. var $wmf;
  221. var $tocontents;
  222. var $form;
  223. var $directw;
  224. //////////////////////
  225. // INTERNAL VARIABLES
  226. //////////////////////
  227. var $writingToC; // mPDF 5.6.38
  228. // mPDF 5.6.01
  229. var $layers;
  230. var $current_layer;
  231. var $open_layer_pane;
  232. var $decimal_offset; // mPDF 5.6.13
  233. var $inMeter; // mPDF 5.5.09
  234. var $CJKleading;
  235. var $CJKfollowing;
  236. var $CJKoverflow;
  237. var $textshadow;
  238. var $colsums;
  239. var $spanborder;
  240. var $spanborddet;
  241. var $visibility;
  242. var $useRC128encryption;
  243. var $uniqid;
  244. var $kerning;
  245. var $fixedlSpacing;
  246. var $minwSpacing;
  247. var $lSpacingCSS;
  248. var $wSpacingCSS;
  249. var $listDir;
  250. var $spotColorIDs;
  251. var $SVGcolors;
  252. var $spotColors;
  253. var $defTextColor;
  254. var $defDrawColor;
  255. var $defFillColor;
  256. var $tableBackgrounds;
  257. var $inlineDisplayOff;
  258. var $kt_y00;
  259. var $kt_p00;
  260. var $upperCase;
  261. var $checkSIP;
  262. var $checkSMP;
  263. var $checkCJK;
  264. var $tableCJK;
  265. var $watermarkImgAlpha;
  266. var $PDFAXwarnings;
  267. var $MetadataRoot;
  268. var $OutputIntentRoot;
  269. var $InfoRoot;
  270. var $current_filename;
  271. var $parsers;
  272. var $current_parser;
  273. var $_obj_stack;
  274. var $_don_obj_stack;
  275. var $_current_obj_id;
  276. var $tpls;
  277. var $tpl;
  278. var $tplprefix;
  279. var $_res;
  280. var $pdf_version;
  281. var $noImageFile;
  282. var $lastblockbottommargin;
  283. var $baselineC;
  284. var $subPos;
  285. var $subArrMB;
  286. var $ReqFontStyle;
  287. var $tableClipPath ;
  288. var $forceExactLineheight;
  289. var $listOcc;
  290. var $fullImageHeight;
  291. var $inFixedPosBlock; // Internal flag for position:fixed block
  292. var $fixedPosBlock; // Buffer string for position:fixed block
  293. var $fixedPosBlockDepth;
  294. var $fixedPosBlockBBox;
  295. var $fixedPosBlockSave;
  296. var $maxPosL;
  297. var $maxPosR;
  298. var $loaded;
  299. var $extraFontSubsets;
  300. var $docTemplateStart; // Internal flag for page (page no. -1) that docTemplate starts on
  301. var $time0;
  302. // Classes
  303. var $indic;
  304. var $barcode;
  305. var $SHYpatterns;
  306. var $loadedSHYpatterns;
  307. var $loadedSHYdictionary;
  308. var $SHYdictionary;
  309. var $SHYdictionaryWords;
  310. var $spanbgcolorarray;
  311. var $default_font;
  312. var $list_lineheight;
  313. var $headerbuffer;
  314. var $lastblocklevelchange;
  315. var $nestedtablejustfinished;
  316. var $linebreakjustfinished;
  317. var $cell_border_dominance_L;
  318. var $cell_border_dominance_R;
  319. var $cell_border_dominance_T;
  320. var $cell_border_dominance_B;
  321. var $table_keep_together;
  322. var $plainCell_properties;
  323. var $inherit_lineheight;
  324. var $listitemtype;
  325. var $shrin_k1;
  326. var $outerfilled;
  327. var $blockContext;
  328. var $floatDivs;
  329. var $patterns;
  330. var $pageBackgrounds;
  331. var $bodyBackgroundGradient;
  332. var $bodyBackgroundImage;
  333. var $bodyBackgroundColor;
  334. var $writingHTMLheader; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  335. var $writingHTMLfooter;
  336. var $autoFontGroups;
  337. var $angle;
  338. var $gradients;
  339. var $kwt_Reference;
  340. var $kwt_BMoutlines;
  341. var $kwt_toc;
  342. var $tbrot_Reference;
  343. var $tbrot_BMoutlines;
  344. var $tbrot_toc;
  345. var $col_Reference;
  346. var $col_BMoutlines;
  347. var $col_toc;
  348. var $currentGraphId;
  349. var $graphs;
  350. var $floatbuffer;
  351. var $floatmargins;
  352. var $bullet;
  353. var $bulletarray;
  354. var $rtlAsArabicFarsi; // DEPRACATED
  355. var $currentLang;
  356. var $default_lang;
  357. var $default_available_fonts;
  358. var $pageTemplate;
  359. var $docTemplate;
  360. var $docTemplateContinue;
  361. var $arabGlyphs;
  362. var $arabHex;
  363. var $persianGlyphs;
  364. var $persianHex;
  365. var $arabVowels;
  366. var $arabPrevLink;
  367. var $arabNextLink;
  368. var $formobjects; // array of Form Objects for WMF
  369. var $InlineProperties;
  370. var $InlineAnnots;
  371. var $ktAnnots;
  372. var $tbrot_Annots;
  373. var $kwt_Annots;
  374. var $columnAnnots;
  375. var $columnForms;
  376. var $PageAnnots;
  377. var $pageDim; // Keep track of page wxh for orientation changes - set in _beginpage, used in _putannots
  378. var $breakpoints;
  379. var $tableLevel;
  380. var $tbctr;
  381. var $innermostTableLevel;
  382. var $saveTableCounter;
  383. var $cellBorderBuffer;
  384. var $saveHTMLFooter_height;
  385. var $saveHTMLFooterE_height;
  386. var $firstPageBoxHeader;
  387. var $firstPageBoxHeaderEven;
  388. var $firstPageBoxFooter;
  389. var $firstPageBoxFooterEven;
  390. var $page_box;
  391. var $show_marks; // crop or cross marks
  392. var $basepathIsLocal;
  393. var $use_kwt;
  394. var $kwt;
  395. var $kwt_height;
  396. var $kwt_y0;
  397. var $kwt_x0;
  398. var $kwt_buffer;
  399. var $kwt_Links;
  400. var $kwt_moved;
  401. var $kwt_saved;
  402. var $PageNumSubstitutions;
  403. var $table_borders_separate;
  404. var $base_table_properties;
  405. var $borderstyles;
  406. var $listjustfinished;
  407. var $blockjustfinished;
  408. var $orig_bMargin;
  409. var $orig_tMargin;
  410. var $orig_lMargin;
  411. var $orig_rMargin;
  412. var $orig_hMargin;
  413. var $orig_fMargin;
  414. var $pageheaders;
  415. var $pagefooters;
  416. var $pageHTMLheaders;
  417. var $pageHTMLfooters;
  418. var $saveHTMLHeader;
  419. var $saveHTMLFooter;
  420. var $HTMLheaderPageLinks;
  421. var $HTMLheaderPageAnnots;
  422. var $HTMLheaderPageForms;
  423. // See config_fonts.php for these next 5 values
  424. var $available_unifonts;
  425. var $sans_fonts;
  426. var $serif_fonts;
  427. var $mono_fonts;
  428. var $defaultSubsFont;
  429. // List of ALL available CJK fonts (incl. styles) (Adobe add-ons) hw removed
  430. var $available_CJK_fonts;
  431. var $HTMLHeader;
  432. var $HTMLFooter;
  433. var $HTMLHeaderE;
  434. var $HTMLFooterE;
  435. var $bufferoutput;
  436. var $showdefaultpagenos; // DEPRACATED -left for backward compatability
  437. // CJK fonts
  438. var $Big5_widths;
  439. var $GB_widths;
  440. var $SJIS_widths;
  441. var $UHC_widths;
  442. // SetProtection
  443. var $encrypted; //whether document is protected
  444. var $Uvalue; //U entry in pdf document
  445. var $Ovalue; //O entry in pdf document
  446. var $Pvalue; //P entry in pdf document
  447. var $enc_obj_id; //encryption object id
  448. var $last_rc4_key; //last RC4 key encrypted (cached for optimisation)
  449. var $last_rc4_key_c; //last RC4 computed key
  450. var $encryption_key;
  451. var $padding; //used for encryption
  452. // Bookmark
  453. var $BMoutlines;
  454. var $OutlineRoot;
  455. // INDEX
  456. var $ColActive;
  457. var $Reference;
  458. var $CurrCol;
  459. var $NbCol;
  460. var $y0; //Top ordinate of columns
  461. var $ColL;
  462. var $ColWidth;
  463. var $ColGap;
  464. // COLUMNS
  465. var $ColR;
  466. var $ChangeColumn;
  467. var $columnbuffer;
  468. var $ColDetails;
  469. var $columnLinks;
  470. var $colvAlign;
  471. // Substitutions
  472. var $substitute; // Array of substitution strings e.g. <ttz>112</ttz>
  473. var $entsearch; // Array of HTML entities (>ASCII 127) to substitute
  474. var $entsubstitute; // Array of substitution decimal unicode for the Hi entities
  475. // Default values if no style sheet offered (cf. http://www.w3.org/TR/CSS21/sample.html)
  476. var $defaultCSS;
  477. var $linemaxfontsize;
  478. var $lineheight_correction;
  479. var $lastoptionaltag; // Save current block item which HTML specifies optionsl endtag
  480. var $pageoutput;
  481. var $charset_in;
  482. var $blk;
  483. var $blklvl;
  484. var $ColumnAdjust;
  485. var $ws; // Word spacing
  486. var $HREF;
  487. var $pgwidth;
  488. var $fontlist;
  489. var $oldx;
  490. var $oldy;
  491. var $B;
  492. var $U; //underlining flag
  493. var $S; // SmallCaps flag
  494. var $I;
  495. var $tdbegin;
  496. var $table;
  497. var $cell;
  498. var $col;
  499. var $row;
  500. var $divbegin;
  501. var $divalign;
  502. var $divwidth;
  503. var $divheight;
  504. var $divrevert;
  505. var $spanbgcolor;
  506. var $spanlvl;
  507. var $listlvl;
  508. var $listnum;
  509. var $listtype;
  510. var $listoccur;
  511. var $listlist;
  512. var $listitem;
  513. var $pjustfinished;
  514. var $ignorefollowingspaces;
  515. var $SUP;
  516. var $SUB;
  517. var $SMALL;
  518. var $BIG;
  519. var $toupper;
  520. var $tolower;
  521. var $capitalize;
  522. var $dash_on;
  523. var $dotted_on;
  524. var $strike;
  525. var $textbuffer;
  526. var $currentfontstyle;
  527. var $currentfontfamily;
  528. var $currentfontsize;
  529. var $colorarray;
  530. var $bgcolorarray;
  531. var $internallink;
  532. var $enabledtags;
  533. var $lineheight;
  534. var $basepath;
  535. var $textparam;
  536. var $specialcontent;
  537. var $selectoption;
  538. var $objectbuffer;
  539. // Table Rotation
  540. var $table_rotate;
  541. var $tbrot_maxw;
  542. var $tbrot_maxh;
  543. var $tablebuffer;
  544. var $tbrot_align;
  545. var $tbrot_Links;
  546. var $divbuffer; // Buffer used when keeping DIV on one page
  547. var $keep_block_together; // Keep a Block from page-break-inside: avoid
  548. var $ktLinks; // Keep-together Block links array
  549. var $ktBlock; // Keep-together Block array
  550. var $ktForms;
  551. var $ktReference;
  552. var $ktBMoutlines;
  553. var $_kttoc;
  554. var $tbrot_y0;
  555. var $tbrot_x0;
  556. var $tbrot_w;
  557. var $tbrot_h;
  558. var $mb_enc;
  559. var $directionality;
  560. var $extgstates; // Used for alpha channel - Transparency (Watermark)
  561. var $mgl;
  562. var $mgt;
  563. var $mgr;
  564. var $mgb;
  565. var $tts;
  566. var $ttz;
  567. var $tta;
  568. var $headerDetails;
  569. var $footerDetails;
  570. // Best to alter the below variables using default stylesheet above
  571. var $page_break_after_avoid;
  572. var $margin_bottom_collapse;
  573. var $list_indent;
  574. var $list_align;
  575. var $list_margin_bottom;
  576. var $default_font_size; // in pts
  577. var $original_default_font_size; // used to save default sizes when using table default
  578. var $original_default_font;
  579. var $watermark_font;
  580. var $defaultAlign;
  581. // TABLE
  582. var $defaultTableAlign;
  583. var $tablethead;
  584. var $thead_font_weight;
  585. var $thead_font_style;
  586. var $thead_font_smCaps;
  587. var $thead_valign_default;
  588. var $thead_textalign_default;
  589. var $tabletfoot;
  590. var $tfoot_font_weight;
  591. var $tfoot_font_style;
  592. var $tfoot_font_smCaps;
  593. var $tfoot_valign_default;
  594. var $tfoot_textalign_default;
  595. var $trow_text_rotate;
  596. var $cellPaddingL;
  597. var $cellPaddingR;
  598. var $cellPaddingT;
  599. var $cellPaddingB;
  600. var $table_lineheight;
  601. var $table_border_attr_set;
  602. var $table_border_css_set;
  603. var $shrin_k; // factor with which to shrink tables - used internally - do not change
  604. var $shrink_this_table_to_fit; // 0 or false to disable; value (if set) gives maximum factor to reduce fontsize
  605. var $MarginCorrection; // corrects for OddEven Margins
  606. var $margin_footer;
  607. var $margin_header;
  608. var $tabletheadjustfinished;
  609. var $usingCoreFont;
  610. var $charspacing;
  611. //Private properties FROM FPDF
  612. var $DisplayPreferences;
  613. var $flowingBlockAttr;
  614. var $page; //current page number
  615. var $n; //current object number
  616. var $offsets; //array of object offsets
  617. var $buffer; //buffer holding in-memory PDF
  618. var $pages; //array containing pages
  619. var $state; //current document state
  620. var $compress; //compression flag
  621. var $DefOrientation; //default orientation
  622. var $CurOrientation; //current orientation
  623. var $OrientationChanges; //array indicating orientation changes
  624. var $k; //scale factor (number of points in user unit)
  625. var $fwPt;
  626. var $fhPt; //dimensions of page format in points
  627. var $fw;
  628. var $fh; //dimensions of page format in user unit
  629. var $wPt;
  630. var $hPt; //current dimensions of page in points
  631. var $w;
  632. var $h; //current dimensions of page in user unit
  633. var $lMargin; //left margin
  634. var $tMargin; //top margin
  635. var $rMargin; //right margin
  636. var $bMargin; //page break margin
  637. var $cMarginL; //cell margin Left
  638. var $cMarginR; //cell margin Right
  639. var $cMarginT; //cell margin Left
  640. var $cMarginB; //cell margin Right
  641. var $DeflMargin; //Default left margin
  642. var $DefrMargin; //Default right margin
  643. var $x;
  644. var $y; //current position in user unit for cell positioning
  645. var $lasth; //height of last cell printed
  646. var $LineWidth; //line width in user unit
  647. var $CoreFonts; //array of standard font names
  648. var $fonts; //array of used fonts
  649. var $FontFiles; //array of font files
  650. var $images; //array of used images
  651. var $PageLinks; //array of links in pages
  652. var $links; //array of internal links
  653. var $FontFamily; //current font family
  654. var $FontStyle; //current font style
  655. var $CurrentFont; //current font info
  656. var $FontSizePt; //current font size in points
  657. var $FontSize; //current font size in user unit
  658. var $DrawColor; //commands for drawing color
  659. var $FillColor; //commands for filling color
  660. var $TextColor; //commands for text color
  661. var $ColorFlag; //indicates whether fill and text colors are different
  662. var $autoPageBreak; //automatic page breaking
  663. var $PageBreakTrigger; //threshold used to trigger page breaks
  664. var $InFooter; //flag set when processing footer
  665. var $InHTMLFooter;
  666. var $processingFooter; //flag set when processing footer - added for columns
  667. var $processingHeader; //flag set when processing header - added for columns
  668. var $ZoomMode; //zoom display mode
  669. var $LayoutMode; //layout display mode
  670. var $title; //title
  671. var $subject; //subject
  672. var $author; //author
  673. var $keywords; //keywords
  674. var $creator; //creator
  675. var $aliasNbPg; //alias for total number of pages
  676. var $aliasNbPgGp; //alias for total number of pages in page group
  677. var $aliasNbPgHex;
  678. var $aliasNbPgGpHex;
  679. var $ispre;
  680. var $outerblocktags;
  681. var $innerblocktags;
  682. // **********************************
  683. // **********************************
  684. // **********************************
  685. // **********************************
  686. // **********************************
  687. // **********************************
  688. // **********************************
  689. // **********************************
  690. // **********************************
  691. 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') {
  692. /*-- BACKGROUNDS --*/
  693. if (!class_exists('grad', false)) { include(_MPDF_PATH.'classes/grad.php'); }
  694. if (empty($this->grad)) { $this->grad = new grad($this); }
  695. /*-- END BACKGROUNDS --*/
  696. /*-- FORMS --*/
  697. if (!class_exists('form', false)) { include(_MPDF_PATH.'classes/form.php'); }
  698. if (empty($this->form)) { $this->form = new form($this); }
  699. /*-- END FORMS --*/
  700. $this->time0 = microtime(true);
  701. //Some checks
  702. $this->_dochecks();
  703. // Set up Aliases for backwards compatability
  704. $this->UnvalidatedText =& $this->watermarkText;
  705. $this->TopicIsUnvalidated =& $this->showWatermarkText;
  706. $this->AliasNbPg =& $this->aliasNbPg;
  707. $this->AliasNbPgGp =& $this->aliasNbPgGp;
  708. $this->BiDirectional =& $this->biDirectional;
  709. $this->Anchor2Bookmark =& $this->anchor2Bookmark;
  710. $this->KeepColumns =& $this->keepColumns;
  711. $this->useOddEven =& $this->mirrorMargins;
  712. $this->useSubstitutionsMB =& $this->useSubstitutions;
  713. $this->writingToC = false; // mPDF 5.6.38
  714. // mPDF 5.6.01
  715. $this->layers = array();
  716. $this->current_layer = 0;
  717. $this->open_layer_pane = false;
  718. $this->visibility='visible';
  719. //Initialization of properties
  720. $this->spotColors=array();
  721. $this->spotColorIDs = array();
  722. $this->tableBackgrounds = array();
  723. $this->kt_y00 = '';
  724. $this->kt_p00 = '';
  725. $this->iterationCounter = false;
  726. $this->BMPonly = array();
  727. $this->page=0;
  728. $this->n=2;
  729. $this->buffer='';
  730. $this->objectbuffer = array();
  731. $this->pages=array();
  732. $this->OrientationChanges=array();
  733. $this->state=0;
  734. $this->fonts=array();
  735. $this->FontFiles=array();
  736. $this->images=array();
  737. $this->links=array();
  738. $this->InFooter=false;
  739. $this->processingFooter=false;
  740. $this->processingHeader=false;
  741. $this->lasth=0;
  742. $this->FontFamily='';
  743. $this->FontStyle='';
  744. $this->FontSizePt=9;
  745. $this->U=false;
  746. // Small Caps
  747. $this->upperCase = array();
  748. $this->S = false;
  749. $this->smCapsScale = 1;
  750. $this->smCapsStretch = 100;
  751. $this->margBuffer = 0; // mPDF 5.4.04
  752. $this->inMeter = false; // mPDF 5.5.09
  753. $this->decimal_offset = 0;
  754. $this->defTextColor = $this->TextColor = $this->SetTColor($this->ConvertColor(0),true);
  755. $this->defDrawColor = $this->DrawColor = $this->SetDColor($this->ConvertColor(0),true);
  756. $this->defFillColor = $this->FillColor = $this->SetFColor($this->ConvertColor(255),true);
  757. //SVG color names array
  758. //http://www.w3schools.com/css/css_colornames.asp
  759. $this->SVGcolors = array('antiquewhite'=>'#FAEBD7','aqua'=>'#00FFFF','aquamarine'=>'#7FFFD4','beige'=>'#F5F5DC','black'=>'#000000',
  760. 'blue'=>'#0000FF','brown'=>'#A52A2A','cadetblue'=>'#5F9EA0','chocolate'=>'#D2691E','cornflowerblue'=>'#6495ED','crimson'=>'#DC143C',
  761. 'darkblue'=>'#00008B','darkgoldenrod'=>'#B8860B','darkgreen'=>'#006400','darkmagenta'=>'#8B008B','darkorange'=>'#FF8C00',
  762. 'darkred'=>'#8B0000','darkseagreen'=>'#8FBC8F','darkslategray'=>'#2F4F4F','darkviolet'=>'#9400D3','deepskyblue'=>'#00BFFF',
  763. 'dodgerblue'=>'#1E90FF','firebrick'=>'#B22222','forestgreen'=>'#228B22','fuchsia'=>'#FF00FF','gainsboro'=>'#DCDCDC','gold'=>'#FFD700',
  764. 'gray'=>'#808080','green'=>'#008000','greenyellow'=>'#ADFF2F','hotpink'=>'#FF69B4','indigo'=>'#4B0082','khaki'=>'#F0E68C',
  765. 'lavenderblush'=>'#FFF0F5','lemonchiffon'=>'#FFFACD','lightcoral'=>'#F08080','lightgoldenrodyellow'=>'#FAFAD2','lightgreen'=>'#90EE90',
  766. 'lightsalmon'=>'#FFA07A','lightskyblue'=>'#87CEFA','lightslategray'=>'#778899','lightyellow'=>'#FFFFE0','lime'=>'#00FF00','limegreen'=>'#32CD32',
  767. 'magenta'=>'#FF00FF','maroon'=>'#800000','mediumaquamarine'=>'#66CDAA','mediumorchid'=>'#BA55D3','mediumseagreen'=>'#3CB371',
  768. 'mediumspringgreen'=>'#00FA9A','mediumvioletred'=>'#C71585','midnightblue'=>'#191970','mintcream'=>'#F5FFFA','moccasin'=>'#FFE4B5','navy'=>'#000080',
  769. 'olive'=>'#808000','orange'=>'#FFA500','orchid'=>'#DA70D6','palegreen'=>'#98FB98',
  770. 'palevioletred'=>'#D87093','peachpuff'=>'#FFDAB9','pink'=>'#FFC0CB','powderblue'=>'#B0E0E6','purple'=>'#800080',
  771. 'red'=>'#FF0000','royalblue'=>'#4169E1','salmon'=>'#FA8072','seagreen'=>'#2E8B57','sienna'=>'#A0522D','silver'=>'#C0C0C0','skyblue'=>'#87CEEB',
  772. 'slategray'=>'#708090','springgreen'=>'#00FF7F','steelblue'=>'#4682B4','tan'=>'#D2B48C','teal'=>'#008080','thistle'=>'#D8BFD8','turquoise'=>'#40E0D0',
  773. 'violetred'=>'#D02090','white'=>'#FFFFFF','yellow'=>'#FFFF00',
  774. 'aliceblue'=>'#f0f8ff', 'azure'=>'#f0ffff', 'bisque'=>'#ffe4c4', 'blanchedalmond'=>'#ffebcd', 'blueviolet'=>'#8a2be2', 'burlywood'=>'#deb887',
  775. 'chartreuse'=>'#7fff00', 'coral'=>'#ff7f50', 'cornsilk'=>'#fff8dc', 'cyan'=>'#00ffff', 'darkcyan'=>'#008b8b', 'darkgray'=>'#a9a9a9',
  776. 'darkgrey'=>'#a9a9a9', 'darkkhaki'=>'#bdb76b', 'darkolivegreen'=>'#556b2f', 'darkorchid'=>'#9932cc', 'darksalmon'=>'#e9967a',
  777. 'darkslateblue'=>'#483d8b', 'darkslategrey'=>'#2f4f4f', 'darkturquoise'=>'#00ced1', 'deeppink'=>'#ff1493', 'dimgray'=>'#696969',
  778. 'dimgrey'=>'#696969', 'floralwhite'=>'#fffaf0', 'ghostwhite'=>'#f8f8ff', 'goldenrod'=>'#daa520', 'grey'=>'#808080', 'honeydew'=>'#f0fff0',
  779. 'indianred'=>'#cd5c5c', 'ivory'=>'#fffff0', 'lavender'=>'#e6e6fa', 'lawngreen'=>'#7cfc00', 'lightblue'=>'#add8e6', 'lightcyan'=>'#e0ffff',
  780. 'lightgray'=>'#d3d3d3', 'lightgrey'=>'#d3d3d3', 'lightpink'=>'#ffb6c1', 'lightseagreen'=>'#20b2aa', 'lightslategrey'=>'#778899',
  781. 'lightsteelblue'=>'#b0c4de', 'linen'=>'#faf0e6', 'mediumblue'=>'#0000cd', 'mediumpurple'=>'#9370db', 'mediumslateblue'=>'#7b68ee',
  782. 'mediumturquoise'=>'#48d1cc', 'mistyrose'=>'#ffe4e1', 'navajowhite'=>'#ffdead', 'oldlace'=>'#fdf5e6', 'olivedrab'=>'#6b8e23', 'orangered'=>'#ff4500',
  783. 'palegoldenrod'=>'#eee8aa', 'paleturquoise'=>'#afeeee', 'papayawhip'=>'#ffefd5', 'peru'=>'#cd853f', 'plum'=>'#dda0dd', 'rosybrown'=>'#bc8f8f',
  784. 'saddlebrown'=>'#8b4513', 'sandybrown'=>'#f4a460', 'seashell'=>'#fff5ee', 'slateblue'=>'#6a5acd', 'slategrey'=>'#708090', 'snow'=>'#fffafa',
  785. 'tomato'=>'#ff6347', 'violet'=>'#ee82ee', 'wheat'=>'#f5deb3', 'whitesmoke'=>'#f5f5f5', 'yellowgreen'=>'#9acd32');
  786. $this->ColorFlag=false;
  787. $this->extgstates = array();
  788. $this->mb_enc='windows-1252';
  789. $this->directionality='ltr';
  790. $this->defaultAlign = 'L';
  791. $this->defaultTableAlign = 'L';
  792. $this->fixedPosBlockSave = array();
  793. $this->extraFontSubsets = 0;
  794. $this->SHYpatterns = array();
  795. $this->loadedSHYdictionary = false;
  796. $this->SHYdictionary = array();
  797. $this->SHYdictionaryWords = array();
  798. $this->blockContext = 1;
  799. $this->floatDivs = array();
  800. $this->DisplayPreferences='';
  801. $this->patterns = array(); // Tiling patterns used for backgrounds
  802. $this->pageBackgrounds = array();
  803. $this->writingHTMLheader = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  804. $this->writingHTMLfooter = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  805. $this->gradients = array();
  806. $this->kwt_Reference = array();
  807. $this->kwt_BMoutlines = array();
  808. $this->kwt_toc = array();
  809. $this->tbrot_Reference = array();
  810. $this->tbrot_BMoutlines = array();
  811. $this->tbrot_toc = array();
  812. $this->col_Reference = array();
  813. $this->col_BMoutlines = array();
  814. $this->col_toc = array();
  815. $this->graphs = array();
  816. $this->pgsIns = array();
  817. $this->PDFAXwarnings = array();
  818. $this->inlineDisplayOff = false;
  819. $this->kerning = false;
  820. $this->lSpacingCSS = '';
  821. $this->wSpacingCSS = '';
  822. $this->fixedlSpacing = false;
  823. $this->minwSpacing = 0;
  824. $this->baselineC = 0.35; // Baseline for text
  825. $this->noImageFile = str_replace("\\","/",dirname(__FILE__)) . '/includes/no_image.jpg';
  826. $this->subPos = 0;
  827. $this->forceExactLineheight = false;
  828. $this->listOcc = 0;
  829. $this->normalLineheight = 1.3;
  830. // These are intended as configuration variables, and should be set in config.php - which will override these values;
  831. // set here as failsafe as will cause an error if not defined
  832. $this->incrementFPR1 = 10;
  833. $this->incrementFPR2 = 10;
  834. $this->incrementFPR3 = 10;
  835. $this->incrementFPR4 = 10;
  836. $this->fullImageHeight = false;
  837. $this->floatbuffer = array();
  838. $this->floatmargins = array();
  839. $this->autoFontGroups = 0;
  840. $this->formobjects=array(); // array of Form Objects for WMF
  841. $this->InlineProperties=array();
  842. $this->InlineAnnots=array();
  843. $this->ktAnnots=array();
  844. $this->tbrot_Annots=array();
  845. $this->kwt_Annots=array();
  846. $this->columnAnnots=array();
  847. $this->pageDim=array();
  848. $this->breakpoints = array(); // used in columnbuffer
  849. $this->tableLevel=0;
  850. $this->tbctr=array(); // counter for nested tables at each level
  851. $this->page_box = array();
  852. $this->show_marks = ''; // crop or cross marks
  853. $this->kwt = false;
  854. $this->kwt_height = 0;
  855. $this->kwt_y0 = 0;
  856. $this->kwt_x0 = 0;
  857. $this->kwt_buffer = array();
  858. $this->kwt_Links = array();
  859. $this->kwt_moved = false;
  860. $this->kwt_saved = false;
  861. $this->PageNumSubstitutions = array();
  862. $this->base_table_properties=array();
  863. $this->borderstyles = array('inset','groove','outset','ridge','dotted','dashed','solid','double');
  864. $this->tbrot_align = 'C';
  865. $this->pageheaders=array();
  866. $this->pagefooters=array();
  867. $this->pageHTMLheaders=array();
  868. $this->pageHTMLfooters=array();
  869. $this->HTMLheaderPageLinks = array();
  870. $this->HTMLheaderPageAnnots = array();
  871. $this->ktForms = array();
  872. $this->HTMLheaderPageForms = array();
  873. $this->columnForms = array();
  874. $this->tbrotForms = array();
  875. $this->useRC128encryption = false;
  876. $this->uniqid = '';
  877. $this->bufferoutput = false;
  878. $this->encrypted=false; //whether document is protected
  879. $this->BMoutlines=array();
  880. $this->ColActive=0; //Flag indicating that columns are on (the index is being processed)
  881. $this->Reference=array(); //Array containing the references
  882. $this->CurrCol=0; //Current column number
  883. $this->ColL = array(0); // Array of Left pos of columns - absolute - needs Margin correction for Odd-Even
  884. $this->ColR = array(0); // Array of Right pos of columns - absolute pos - needs Margin correction for Odd-Even
  885. $this->ChangeColumn = 0;
  886. $this->columnbuffer = array();
  887. $this->ColDetails = array(); // Keeps track of some column details
  888. $this->columnLinks = array(); // Cross references PageLinks
  889. $this->substitute = array(); // Array of substitution strings e.g. <ttz>112</ttz>
  890. $this->entsearch = array(); // Array of HTML entities (>ASCII 127) to substitute
  891. $this->entsubstitute = array(); // Array of substitution decimal unicode for the Hi entities
  892. $this->lastoptionaltag = '';
  893. $this->charset_in = '';
  894. $this->blk = array();
  895. $this->blklvl = 0;
  896. $this->tts = false;
  897. $this->ttz = false;
  898. $this->tta = false;
  899. $this->ispre=false;
  900. $this->checkSIP = false;
  901. $this->checkSMP = false;
  902. $this->checkCJK = false;
  903. $this->tableCJK = false;
  904. $this->headerDetails=array();
  905. $this->footerDetails=array();
  906. $this->page_break_after_avoid = false;
  907. $this->margin_bottom_collapse = false;
  908. $this->tablethead = 0;
  909. $this->tabletfoot = 0;
  910. $this->table_border_attr_set = 0;
  911. $this->table_border_css_set = 0;
  912. $this->shrin_k = 1.0;
  913. $this->shrink_this_table_to_fit = 0;
  914. $this->MarginCorrection = 0;
  915. $this->tabletheadjustfinished = false;
  916. $this->usingCoreFont = false;
  917. $this->charspacing=0;
  918. $this->autoPageBreak = true;
  919. require(_MPDF_PATH.'config.php'); // config data
  920. $this->_setPageSize($format, $orientation);
  921. $this->DefOrientation=$orientation;
  922. $this->margin_header=$mgh;
  923. $this->margin_footer=$mgf;
  924. $bmargin=$mgb;
  925. $this->DeflMargin = $mgl;
  926. $this->DefrMargin = $mgr;
  927. $this->orig_tMargin = $mgt;
  928. $this->orig_bMargin = $bmargin;
  929. $this->orig_lMargin = $this->DeflMargin;
  930. $this->orig_rMargin = $this->DefrMargin;
  931. $this->orig_hMargin = $this->margin_header;
  932. $this->orig_fMargin = $this->margin_footer;
  933. if ($this->setAutoTopMargin=='pad') { $mgt += $this->margin_header; }
  934. if ($this->setAutoBottomMargin=='pad') { $mgb += $this->margin_footer; }
  935. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$mgt); // sets l r t margin
  936. //Automatic page break
  937. $this->SetAutoPageBreak($this->autoPageBreak,$bmargin); // sets $this->bMargin & PageBreakTrigger
  938. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  939. //Interior cell margin (1 mm) ? not used
  940. $this->cMarginL = 1;
  941. $this->cMarginR = 1;
  942. //Line width (0.2 mm)
  943. $this->LineWidth=.567/_MPDFK;
  944. //To make the function Footer() work - replaces {nb} with page number
  945. $this->AliasNbPages();
  946. $this->AliasNbPageGroups();
  947. $this->aliasNbPgHex = '{nbHEXmarker}';
  948. $this->aliasNbPgGpHex = '{nbpgHEXmarker}';
  949. //Enable all tags as default
  950. $this->DisableTags();
  951. //Full width display mode
  952. $this->SetDisplayMode(100); // fullwidth? 'fullpage'
  953. //Compression
  954. $this->SetCompression(true);
  955. //Set default display preferences
  956. $this->SetDisplayPreferences('');
  957. // Font data
  958. require(_MPDF_PATH.'config_fonts.php');
  959. // Available fonts
  960. $this->available_unifonts = array();
  961. foreach ($this->fontdata AS $f => $fs) {
  962. if (isset($fs['R']) && $fs['R']) { $this->available_unifonts[] = $f; }
  963. if (isset($fs['B']) && $fs['B']) { $this->available_unifonts[] = $f.'B'; }
  964. if (isset($fs['I']) && $fs['I']) { $this->available_unifonts[] = $f.'I'; }
  965. if (isset($fs['BI']) && $fs['BI']) { $this->available_unifonts[] = $f.'BI'; }
  966. }
  967. $this->default_available_fonts = $this->available_unifonts;
  968. $optcore = false;
  969. $onlyCoreFonts = false;
  970. if (preg_match('/([\-+])aCJK/i',$mode, $m)) {
  971. preg_replace('/([\-+])aCJK/i','',$mode);
  972. if ($m[1]=='+') { $this->useAdobeCJK = true; }
  973. else { $this->useAdobeCJK = false; }
  974. }
  975. if (strlen($mode)==1) {
  976. if ($mode=='s') { $this->percentSubset = 100; $mode = ''; }
  977. else if ($mode=='c') { $onlyCoreFonts = true; $mode = ''; }
  978. }
  979. else if (substr($mode,-2)=='-s') {
  980. $this->percentSubset = 100;
  981. $mode = substr($mode,0,strlen($mode)-2);
  982. }
  983. else if (substr($mode,-2)=='-c') {
  984. $onlyCoreFonts = true;
  985. $mode = substr($mode,0,strlen($mode)-2);
  986. }
  987. else if (substr($mode,-2)=='-x') {
  988. $optcore = true;
  989. $mode = substr($mode,0,strlen($mode)-2);
  990. }
  991. // Autodetect if mode is a language_country string (en-GB or en_GB or en)
  992. if ((strlen($mode) == 5 && $mode != 'UTF-8') || strlen($mode) == 2) {
  993. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($mode, $this->useAdobeCJK);
  994. if ($coreSuitable && $optcore) { $onlyCoreFonts = true; }
  995. if ($mpdf_pdf_unifonts) {
  996. $this->RestrictUnicodeFonts($mpdf_pdf_unifonts);
  997. $this->default_available_fonts = $mpdf_pdf_unifonts;
  998. }
  999. $this->currentLang = $mode;
  1000. $this->default_lang = $mode;
  1001. }
  1002. $this->onlyCoreFonts = $onlyCoreFonts;
  1003. if ($this->onlyCoreFonts) {
  1004. $this->setMBencoding('windows-1252'); // sets $this->mb_enc
  1005. }
  1006. else {
  1007. $this->setMBencoding('UTF-8'); // sets $this->mb_enc
  1008. }
  1009. @mb_regex_encoding('UTF-8'); // required only for mb_ereg... and mb_split functions
  1010. // Adobe CJK fonts
  1011. $this->available_CJK_fonts = array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  1012. 'gbBI','big5BI','sjisBI','uhcBI');
  1013. //Standard fonts
  1014. $this->CoreFonts=array('ccourier'=>'Courier','ccourierB'=>'Courier-Bold','ccourierI'=>'Courier-Oblique','ccourierBI'=>'Courier-BoldOblique',
  1015. 'chelvetica'=>'Helvetica','chelveticaB'=>'Helvetica-Bold','chelveticaI'=>'Helvetica-Oblique','chelveticaBI'=>'Helvetica-BoldOblique',
  1016. 'ctimes'=>'Times-Roman','ctimesB'=>'Times-Bold','ctimesI'=>'Times-Italic','ctimesBI'=>'Times-BoldItalic',
  1017. 'csymbol'=>'Symbol','czapfdingbats'=>'ZapfDingbats');
  1018. $this->fontlist=array("ctimes","ccourier","chelvetica","csymbol","czapfdingbats");
  1019. // Substitutions
  1020. $this->setHiEntitySubstitutions();
  1021. if ($this->onlyCoreFonts) {
  1022. $this->useSubstitutions = true;
  1023. $this->SetSubstitutions();
  1024. }
  1025. else { $this->useSubstitutions = false; }
  1026. /*-- HTML-CSS --*/
  1027. if (!class_exists('cssmgr', false)) { include(_MPDF_PATH .'classes/cssmgr.php'); }
  1028. $this->cssmgr = new cssmgr($this);
  1029. if (file_exists(_MPDF_PATH.'mpdf.css')) {
  1030. $css = file_get_contents(_MPDF_PATH.'mpdf.css');
  1031. $css2 = $this->cssmgr->ReadDefaultCSS($css);
  1032. $this->defaultCSS = $this->cssmgr->array_merge_recursive_unique($this->defaultCSS,$css2);
  1033. }
  1034. /*-- END HTML-CSS --*/
  1035. if ($default_font=='') {
  1036. if ($this->onlyCoreFonts) {
  1037. if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->mono_fonts)) { $default_font = 'ccourier'; }
  1038. else if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->sans_fonts)) { $default_font = 'chelvetica'; }
  1039. else { $default_font = 'ctimes'; }
  1040. }
  1041. else { $default_font = $this->defaultCSS['BODY']['FONT-FAMILY']; }
  1042. }
  1043. if (!$default_font_size) {
  1044. $mmsize = $this->ConvertSize($this->defaultCSS['BODY']['FONT-SIZE']);
  1045. $default_font_size = $mmsize*(_MPDFK);
  1046. }
  1047. if ($default_font) { $this->SetDefaultFont($default_font); }
  1048. if ($default_font_size) { $this->SetDefaultFontSize($default_font_size); }
  1049. $this->SetLineHeight(); // lineheight is in mm
  1050. $this->SetFColor($this->ConvertColor(255));
  1051. $this->HREF='';
  1052. $this->oldy=-1;
  1053. $this->B=0;
  1054. $this->U=false;
  1055. $this->S=false;
  1056. $this->I=0;
  1057. $this->listlvl=0;
  1058. $this->listnum=0;
  1059. $this->listtype='';
  1060. $this->listoccur=array();
  1061. $this->listlist=array();
  1062. $this->listitem=array();
  1063. $this->tdbegin=false;
  1064. $this->table=array();
  1065. $this->cell=array();
  1066. $this->col=-1;
  1067. $this->row=-1;
  1068. $this->cellBorderBuffer = array();
  1069. $this->divbegin=false;
  1070. $this->divalign='';
  1071. $this->divwidth=0;
  1072. $this->divheight=0;
  1073. $this->spanbgcolor=false;
  1074. $this->divrevert=false;
  1075. $this->spanborder=false;
  1076. $this->spanborddet=array();
  1077. $this->blockjustfinished=false;
  1078. $this->listjustfinished=false;
  1079. $this->ignorefollowingspaces = true; //in order to eliminate exceeding left-side spaces
  1080. $this->toupper=false;
  1081. $this->tolower=false;
  1082. $this->capitalize=false;
  1083. $this->dash_on=false;
  1084. $this->dotted_on=false;
  1085. $this->SUP=false;
  1086. $this->SUB=false;
  1087. $this->strike=false;
  1088. $this->textshadow='';
  1089. $this->currentfontfamily='';
  1090. $this->currentfontsize='';
  1091. $this->currentfontstyle='';
  1092. $this->colorarray=array();
  1093. $this->spanbgcolorarray=array();
  1094. $this->textbuffer=array();
  1095. $this->internallink=array();
  1096. $this->basepath = "";
  1097. $this->SetBasePath('');
  1098. $this->textparam = array();
  1099. $this->specialcontent = '';
  1100. $this->selectoption = array();
  1101. /*-- IMPORTS --*/
  1102. $this->tpls = array();
  1103. $this->tpl = 0;
  1104. $this->tplprefix = "/TPL";
  1105. $this->res = array();
  1106. if ($this->enableImports) {
  1107. $this->SetImportUse();
  1108. }
  1109. /*-- END IMPORTS --*/
  1110. if ($this->progressBar) { $this->StartProgressBarOutput($this->progressBar) ; } // *PROGRESS-BAR*
  1111. }
  1112. function _setPageSize($format, &$orientation) {
  1113. //Page format
  1114. if(is_string($format))
  1115. {
  1116. if ($format=='') { $format = 'A4'; }
  1117. $pfo = 'P';
  1118. if(preg_match('/([0-9a-zA-Z]*)-L/i',$format,$m)) { // e.g. A4-L = A4 landscape
  1119. $format=$m[1];
  1120. $pfo='L';
  1121. }
  1122. $format = $this->_getPageFormat($format);
  1123. if (!$format) { $this->Error('Unknown page format: '.$format); }
  1124. else { $orientation = $pfo; }
  1125. $this->fwPt=$format[0];
  1126. $this->fhPt=$format[1];
  1127. }
  1128. else
  1129. {
  1130. if (!$format[0] || !$format[1]) { $this->Error('Invalid page format: '.$format[0].' '.$format[1]); }
  1131. $this->fwPt=$format[0]*_MPDFK;
  1132. $this->fhPt=$format[1]*_MPDFK;
  1133. }
  1134. $this->fw=$this->fwPt/_MPDFK;
  1135. $this->fh=$this->fhPt/_MPDFK;
  1136. //Page orientation
  1137. $orientation=strtolower($orientation);
  1138. if($orientation=='p' or $orientation=='portrait')
  1139. {
  1140. $orientation='P';
  1141. $this->wPt=$this->fwPt;
  1142. $this->hPt=$this->fhPt;
  1143. }
  1144. elseif($orientation=='l' or $orientation=='landscape')
  1145. {
  1146. $orientation='L';
  1147. $this->wPt=$this->fhPt;
  1148. $this->hPt=$this->fwPt;
  1149. }
  1150. else $this->Error('Incorrect orientation: '.$orientation);
  1151. $this->CurOrientation=$orientation;
  1152. $this->w=$this->wPt/_MPDFK;
  1153. $this->h=$this->hPt/_MPDFK;
  1154. }
  1155. function _getPageFormat($format) {
  1156. switch (strtoupper($format)) {
  1157. case '4A0': {$format = array(4767.87,6740.79); break;}
  1158. case '2A0': {$format = array(3370.39,4767.87); break;}
  1159. case 'A0': {$format = array(2383.94,3370.39); break;}
  1160. case 'A1': {$format = array(1683.78,2383.94); break;}
  1161. case 'A2': {$format = array(1190.55,1683.78); break;}
  1162. case 'A3': {$format = array(841.89,1190.55); break;}
  1163. case 'A4': default: {$format = array(595.28,841.89); break;}
  1164. case 'A5': {$format = array(419.53,595.28); break;}
  1165. case 'A6': {$format = array(297.64,419.53); break;}
  1166. case 'A7': {$format = array(209.76,297.64); break;}
  1167. case 'A8': {$format = array(147.40,209.76); break;}
  1168. case 'A9': {$format = array(104.88,147.40); break;}
  1169. case 'A10': {$format = array(73.70,104.88); break;}
  1170. case 'B0': {$format = array(2834.65,4008.19); break;}
  1171. case 'B1': {$format = array(2004.09,2834.65); break;}
  1172. case 'B2': {$format = array(1417.32,2004.09); break;}
  1173. case 'B3': {$format = array(1000.63,1417.32); break;}
  1174. case 'B4': {$format = array(708.66,1000.63); break;}
  1175. case 'B5': {$format = array(498.90,708.66); break;}
  1176. case 'B6': {$format = array(354.33,498.90); break;}
  1177. case 'B7': {$format = array(249.45,354.33); break;}
  1178. case 'B8': {$format = array(175.75,249.45); break;}
  1179. case 'B9': {$format = array(124.72,175.75); break;}
  1180. case 'B10': {$format = array(87.87,124.72); break;}
  1181. case 'C0': {$format = array(2599.37,3676.54); break;}
  1182. case 'C1': {$format = array(1836.85,2599.37); break;}
  1183. case 'C2': {$format = array(1298.27,1836.85); break;}
  1184. case 'C3': {$format = array(918.43,1298.27); break;}
  1185. case 'C4': {$format = array(649.13,918.43); break;}
  1186. case 'C5': {$format = array(459.21,649.13); break;}
  1187. case 'C6': {$format = array(323.15,459.21); break;}
  1188. case 'C7': {$format = array(229.61,323.15); break;}
  1189. case 'C8': {$format = array(161.57,229.61); break;}
  1190. case 'C9': {$format = array(113.39,161.57); break;}
  1191. case 'C10': {$format = array(79.37,113.39); break;}
  1192. case 'RA0': {$format = array(2437.80,3458.27); break;}
  1193. case 'RA1': {$format = array(1729.13,2437.80); break;}
  1194. case 'RA2': {$format = array(1218.90,1729.13); break;}
  1195. case 'RA3': {$format = array(864.57,1218.90); break;}
  1196. case 'RA4': {$format = array(609.45,864.57); break;}
  1197. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  1198. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  1199. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  1200. case 'SRA3': {$format = array(907.09,1275.59); break;}
  1201. case 'SRA4': {$format = array(637.80,907.09); break;}
  1202. case 'LETTER': {$format = array(612.00,792.00); break;}
  1203. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  1204. case 'LEDGER': {$format = array(279.00,432.00); break;}
  1205. case 'TABLOID': {$format = array(279.00,432.00); break;}
  1206. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  1207. case 'FOLIO': {$format = array(612.00,936.00); break;}
  1208. case 'B': {$format=array(362.83,561.26 ); break;} // 'B' format paperback size 128x198mm
  1209. case 'A': {$format=array(314.65,504.57 ); break;} // 'A' format paperback size 111x178mm
  1210. case 'DEMY': {$format=array(382.68,612.28 ); break;} // 'Demy' format paperback size 135x216mm
  1211. case 'ROYAL': {$format=array(433.70,663.30 ); break;} // 'Royal' format paperback size 153x234mm
  1212. default: $format = false;
  1213. }
  1214. return $format;
  1215. }
  1216. /*-- PROGRESS-BAR --*/
  1217. function StartProgressBarOutput($mode=1) {
  1218. // must be relative path, or URI (not a file system path)
  1219. if (!defined('_MPDF_URI')) {
  1220. $this->progressBar = false;
  1221. if ($this->debug) { $this->Error("You need to define _MPDF_URI to use the progress bar!"); }
  1222. else return false;
  1223. }
  1224. $this->progressBar = $mode;
  1225. if ($this->progbar_altHTML) {
  1226. echo $this->progbar_altHTML;
  1227. }
  1228. else {
  1229. echo '<html>
  1230. <head>
  1231. <title>mPDF File Progress</title>
  1232. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1233. <link rel="stylesheet" type="text/css" href="'._MPDF_URI.'progbar.css" />
  1234. </head>
  1235. <body>
  1236. <div class="main">
  1237. <div class="heading">'.$this->progbar_heading.'</div>
  1238. <div class="demo">
  1239. ';
  1240. if ($this->progressBar==2) { echo ' <table width="100%"><tr><td style="width: 50%;">
  1241. <span class="barheading">Writing HTML code</span> <br/>
  1242. <div class="progressBar">
  1243. <div id="element1" class="innerBar">&nbsp;</div>
  1244. </div>
  1245. <span class="code" id="box1"></span>
  1246. </td><td style="width: 50%;">
  1247. <span class="barheading">Autosizing elements</span> <br/>
  1248. <div class="progressBar">
  1249. <div id="element4" class="innerBar">&nbsp;</div>
  1250. </div>
  1251. <span class="code" id="box4"></span>
  1252. <br/><br/>
  1253. <span class="barheading">Writing Tables</span> <br/>
  1254. <div class="progressBar">
  1255. <div id="element7" class="innerBar">&nbsp;</div>
  1256. </div>
  1257. <span class="code" id="box7"></span>
  1258. </td></tr>
  1259. <tr><td><br /><br /></td><td></td></tr>
  1260. <tr><td style="width: 50%;">
  1261. '; }
  1262. echo ' <span class="barheading">Writing PDF file</span> <br/>
  1263. <div class="progressBar">
  1264. <div id="element2" class="innerBar">&nbsp;</div>
  1265. </div>
  1266. <span class="code" id="box2"></span>
  1267. ';
  1268. if ($this->progressBar==2) { echo '
  1269. </td><td style="width: 50%;">
  1270. <span class="barheading">Memory usage</span> <br/>
  1271. <div class="progressBar">
  1272. <div id="element5" class="innerBar">&nbsp;</div>
  1273. </div>
  1274. <span id="box5">0</span> '.ini_get("memory_limit").'<br />
  1275. <br/><br/>
  1276. <span class="barheading">Memory usage (peak)</span> <br/>
  1277. <div class="progressBar">
  1278. <div id="element6" class="innerBar">&nbsp;</div>
  1279. </div>
  1280. <span id="box6">0</span> '.ini_get("memory_limit").'<br />
  1281. </td></tr>
  1282. </table>
  1283. '; }
  1284. echo ' <br/><br/>
  1285. <span id="box3"></span>
  1286. </div>
  1287. ';
  1288. }
  1289. ob_flush();
  1290. flush();
  1291. }
  1292. function UpdateProgressBar($el,$val,$txt='') {
  1293. // $val should be a string - 5 = actual value, +15 = increment
  1294. if ($this->progressBar<2) {
  1295. if ($el>3) { return; }
  1296. else if ($el ==1) { $el = 2; }
  1297. }
  1298. echo '<script type="text/javascript">';
  1299. if ($val) { echo ' document.getElementById(\'element'.$el.'\').style.width=\''.$val.'%\'; '; }
  1300. if ($txt) { echo ' document.getElementById(\'box'.$el.'\').innerHTML=\''.$txt.'\'; '; }
  1301. if ($this->progressBar==2) {
  1302. $m = round(memory_get_usage(true)/1048576);
  1303. $m2 = round(memory_get_peak_usage(true)/1048576);
  1304. $mem = $m * 100 / (ini_get("memory_limit")+0);
  1305. $mem2 = $m2 * 100 / (ini_get("memory_limit")+0);
  1306. echo ' document.getElementById(\'element5\').style.width=\''.$mem.'%\'; ';
  1307. echo ' document.getElementById(\'element6\').style.width=\''.$mem2.'%\'; ';
  1308. echo ' document.getElementById(\'box5\').innerHTML=\''.$m.'MB / \'; ';
  1309. echo ' document.getElementById(\'box6\').innerHTML=\''.$m2.'MB / \'; ';
  1310. }
  1311. echo '</script>'."\n";
  1312. ob_flush();
  1313. flush();
  1314. }
  1315. /*-- END PROGRESS-BAR --*/
  1316. function RestrictUnicodeFonts($res) {
  1317. // $res = array of (Unicode) fonts to restrict to: e.g. norasi|norasiB - language specific
  1318. if (count($res)) { // Leave full list of available fonts if passed blank array
  1319. $this->available_unifonts = $res;
  1320. }
  1321. else { $this->available_unifonts = $this->default_available_fonts; }
  1322. if (count($this->available_unifonts) == 0) { $this->available_unifonts[] = $this->default_available_fonts[0]; }
  1323. $this->available_unifonts = array_values($this->available_unifonts);
  1324. }
  1325. function setMBencoding($enc) {
  1326. if ($this->mb_enc != $enc) {
  1327. $this->mb_enc = $enc;
  1328. mb_internal_encoding($this->mb_enc);
  1329. }
  1330. }
  1331. function SetMargins($left,$right,$top) {
  1332. //Set left, top and right margins
  1333. $this->lMargin=$left;
  1334. $this->rMargin=$right;
  1335. $this->tMargin=$top;
  1336. }
  1337. function ResetMargins() {
  1338. //ReSet left, top margins
  1339. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P' && $this->CurOrientation=='L') {
  1340. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1341. $this->tMargin=$this->orig_rMargin;
  1342. $this->bMargin=$this->orig_lMargin;
  1343. }
  1344. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1345. $this->tMargin=$this->orig_lMargin;
  1346. $this->bMargin=$this->orig_rMargin;
  1347. }
  1348. $this->lMargin=$this->DeflMargin;
  1349. $this->rMargin=$this->DefrMargin;
  1350. $this->MarginCorrection = 0;
  1351. $this->PageBreakTrigger=$this->h-$this->bMargin;
  1352. }
  1353. else if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1354. $this->lMargin=$this->DefrMargin;
  1355. $this->rMargin=$this->DeflMargin;
  1356. $this->MarginCorrection = $this->DefrMargin-$this->DeflMargin;
  1357. }
  1358. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1359. $this->lMargin=$this->DeflMargin;
  1360. $this->rMargin=$this->DefrMargin;
  1361. if ($this->mirrorMargins) { $this->MarginCorrection = $this->DeflMargin-$this->DefrMargin; }
  1362. }
  1363. $this->x=$this->lMargin;
  1364. }
  1365. function SetLeftMargin($margin) {
  1366. //Set left margin
  1367. $this->lMargin=$margin;
  1368. if($this->page>0 and $this->x<$margin) $this->x=$margin;
  1369. }
  1370. function SetTopMargin($margin) {
  1371. //Set top margin
  1372. $this->tMargin=$margin;
  1373. }
  1374. function SetRightMargin($margin) {
  1375. //Set right margin
  1376. $this->rMargin=$margin;
  1377. }
  1378. function SetAutoPageBreak($auto,$margin=0) {
  1379. //Set auto page break mode and triggering margin
  1380. $this->autoPageBreak=$auto;
  1381. $this->bMargin=$margin;
  1382. $this->PageBreakTrigger=$this->h-$margin;
  1383. }
  1384. function SetDisplayMode($zoom,$layout='continuous') {
  1385. //Set display mode in viewer
  1386. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
  1387. $this->ZoomMode=$zoom;
  1388. else
  1389. $this->Error('Incorrect zoom display mode: '.$zoom);
  1390. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='twoleft' or $layout=='tworight' or $layout=='default')
  1391. $this->LayoutMode=$layout;
  1392. else
  1393. $this->Error('Incorrect layout display mode: '.$layout);
  1394. }
  1395. function SetCompression($compress) {
  1396. //Set page compression
  1397. if(function_exists('gzcompress')) $this->compress=$compress;
  1398. else $this->compress=false;
  1399. }
  1400. function SetTitle($title) {
  1401. //Title of document // Arrives as UTF-8
  1402. $this->title = $title;
  1403. }
  1404. function SetSubject($subject) {
  1405. //Subject of document
  1406. $this->subject= $subject;
  1407. }
  1408. function SetAuthor($author) {
  1409. //Author of document
  1410. $this->author= $author;
  1411. }
  1412. function SetKeywords($keywords) {
  1413. //Keywords of document
  1414. $this->keywords= $keywords;
  1415. }
  1416. function SetCreator($creator) {
  1417. //Creator of document
  1418. $this->creator= $creator;
  1419. }
  1420. function SetAnchor2Bookmark($x) {
  1421. $this->anchor2Bookmark = $x;
  1422. }
  1423. function AliasNbPages($alias='{nb}') {
  1424. //Define an alias for total number of pages
  1425. $this->aliasNbPg=$alias;
  1426. }
  1427. function AliasNbPageGroups($alias='{nbpg}') {
  1428. //Define an alias for total number of pages in a group
  1429. $this->aliasNbPgGp=$alias;
  1430. }
  1431. function SetAlpha($alpha, $bm='Normal', $return=false, $mode='B') {
  1432. // alpha: real value from 0 (transparent) to 1 (opaque)
  1433. // bm: blend mode, one of the following:
  1434. // Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
  1435. // HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  1436. // set alpha for stroking (CA) and non-stroking (ca) operations
  1437. // mode determines F (fill) S (stroke) B (both)
  1438. if (($this->PDFA || $this->PDFX) && $alpha!=1) {
  1439. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Image opacity must be 100% (Opacity changed to 100%)"; }
  1440. $alpha = 1;
  1441. }
  1442. $a = array('BM'=>'/'.$bm);
  1443. if ($mode=='F' || $mode='B') $a['ca'] = $alpha;
  1444. if ($mode=='S' || $mode='B') $a['CA'] = $alpha;
  1445. $gs = $this->AddExtGState($a);
  1446. if ($return) { return sprintf('/GS%d gs', $gs); }
  1447. else { $this->_out(sprintf('/GS%d gs', $gs)); }
  1448. }
  1449. function AddExtGState($parms) {
  1450. $n = count($this->extgstates);
  1451. // check if graphics state already exists
  1452. for ($i=1; $i<=$n; $i++) {
  1453. if (count($this->extgstates[$i]['parms']) == count($parms)) {
  1454. $same = true;
  1455. foreach($this->extgstates[$i]['parms'] AS $k=>$v) {
  1456. if (!isset($parms[$k]) || $parms[$k] != $v) { $same = false; break; }
  1457. }
  1458. if ($same) { return $i; }
  1459. }
  1460. }
  1461. $n++;
  1462. $this->extgstates[$n]['parms'] = $parms;
  1463. return $n;
  1464. }
  1465. function SetVisibility($v) {
  1466. if (($this->PDFA || $this->PDFX) && $this->visibility!='visible') { $this->PDFAXwarnings[] = "Cannot set visibility to anything other than full when using PDFA or PDFX"; return ''; }
  1467. else if (!$this->PDFA && !$this->PDFX)
  1468. $this->pdf_version='1.5';
  1469. if($this->visibility!='visible') {
  1470. $this->_out('EMC');
  1471. $this->hasOC=intval($this->hasOC ); // mPDF 5.6.01
  1472. }
  1473. if($v=='printonly') {
  1474. $this->_out('/OC /OC1 BDC');
  1475. $this->hasOC=($this->hasOC | 1); // mPDF 5.6.01
  1476. }
  1477. elseif($v=='screenonly') {
  1478. $this->_out('/OC /OC2 BDC');
  1479. $this->hasOC=($this->hasOC | 2); // mPDF 5.6.01
  1480. }
  1481. elseif($v=='hidden') {
  1482. $this->_out('/OC /OC3 BDC');
  1483. $this->hasOC=($this->hasOC | 4); // mPDF 5.6.01
  1484. }
  1485. elseif($v!='visible')
  1486. $this->Error('Incorrect visibility: '.$v);
  1487. $this->visibility=$v;
  1488. }
  1489. function Error($msg) {
  1490. //Fatal error
  1491. header('Content-Type: text/html; charset=utf-8');
  1492. die('<B>mPDF error: </B>'.$msg);
  1493. }
  1494. function Open() {
  1495. //Begin document
  1496. if($this->state==0) $this->_begindoc();
  1497. }
  1498. function Close() {
  1499. if ($this->progressBar) { $this->UpdateProgressBar(2,'2','Closing last page'); } // *PROGRESS-BAR*
  1500. //Terminate document
  1501. if($this->state==3) return;
  1502. if($this->page==0) $this->AddPage($this->CurOrientation);
  1503. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  1504. if ($this->tablebuffer) { $this->printtablebuffer(); } // *TABLES*
  1505. /*-- COLUMNS --*/
  1506. if ($this->ColActive) {
  1507. $this->SetColumns(0);
  1508. $this->ColActive = 0;
  1509. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  1510. }
  1511. /*-- END COLUMNS --*/
  1512. if (count($this->divbuffer)) { $this->printdivbuffer(); }
  1513. // BODY Backgrounds
  1514. $s = '';
  1515. $s .= $this->PrintBodyBackgrounds();
  1516. $s .= $this->PrintPageBackgrounds();
  1517. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1518. $this->pageBackgrounds = array();
  1519. if($this->visibility!='visible')
  1520. $this->SetVisibility('visible');
  1521. // mPDF 5.6.01 - LAYERS
  1522. $this->EndLayer();
  1523. if (!$this->tocontents || !$this->tocontents->TOCmark) { //Page footer
  1524. $this->InFooter=true;
  1525. $this->Footer();
  1526. $this->InFooter=false;
  1527. }
  1528. if ($this->tocontents && ($this->tocontents->TOCmark || count($this->tocontents->m_TOC))) { $this->tocontents->insertTOC(); } // *TOC*
  1529. //Close page
  1530. $this->_endpage();
  1531. //Close document
  1532. $this->_enddoc();
  1533. }
  1534. /*-- BACKGROUNDS --*/
  1535. function _resizeBackgroundImage($imw, $imh, $cw, $ch, $resize=0, $repx, $repy, $pba=array(), $size=array()) { // mPDF 5.6.10
  1536. // pba is background positioning area (from CSS background-origin) may not always be set [x,y,w,h]
  1537. // size is from CSS3 background-size - takes precendence over old resize
  1538. // $w - absolute length or % or auto or cover | contain
  1539. // $h - absolute length or % or auto or cover | contain
  1540. // mPDF 5.6.10
  1541. if (isset($pba['w'])) $cw = $pba['w'];
  1542. if (isset($pba['h'])) $ch = $pba['h'];
  1543. $cw = $cw*_MPDFK;
  1544. $ch = $ch*_MPDFK;
  1545. if (empty($size) && !$resize) { return array($imw, $imh, $repx, $repy); }
  1546. // mPDF 5.6.10
  1547. if (isset($size['w']) && $size['w']) {
  1548. if ($size['w']=='contain') {
  1549. // Scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.
  1550. // Same as resize==3
  1551. $h = $imh * $cw/$imw;
  1552. $w = $cw;
  1553. if ($h > $ch) {
  1554. $w = $w * $ch/$h;
  1555. $h = $ch;
  1556. }
  1557. }
  1558. else if ($size['w']=='cover') {
  1559. // Scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.
  1560. $h = $imh * $cw/$imw;
  1561. $w = $cw;
  1562. if ($h < $ch) {
  1563. $w = $w * $h/$ch;
  1564. $h = $ch;
  1565. }
  1566. }
  1567. else {
  1568. if (stristr($size['w'] ,'%')) {
  1569. $size['w'] += 0;
  1570. $size['w'] /= 100;
  1571. $size['w'] = ($cw * $size['w']);
  1572. }
  1573. if (stristr($size['h'] ,'%')) {
  1574. $size['h'] += 0;
  1575. $size['h'] /= 100;
  1576. $size['h'] = ($ch * $size['h']);
  1577. }
  1578. if ($size['w']=='auto' && $size['h']=='auto') {
  1579. $w = $imw;
  1580. $h = $imh;
  1581. }
  1582. else if ($size['w']=='auto' && $size['h']!='auto') {
  1583. $w = $imw * $size['h']/$imh;
  1584. $h = $size['h'];
  1585. }
  1586. else if ($size['w']!='auto' && $size['h']=='auto') {
  1587. $h = $imh * $size['w']/$imw;
  1588. $w = $size['w'];
  1589. }
  1590. else {
  1591. $w = $size['w'];
  1592. $h = $size['h'];
  1593. }
  1594. }
  1595. return array($w, $h, $repx, $repy);
  1596. }
  1597. else if ($resize==1 && $imw > $cw) {
  1598. $h = $imh * $cw/$imw;
  1599. return array($cw, $h, $repx, $repy);
  1600. }
  1601. else if ($resize==2 && $imh > $ch) {
  1602. $w = $imw * $ch/$imh;
  1603. return array($w, $ch, $repx, $repy);
  1604. }
  1605. else if ($resize==3) {
  1606. $w = $imw;
  1607. $h = $imh;
  1608. if ($w > $cw) {
  1609. $h = $h * $cw/$w;
  1610. $w = $cw;
  1611. }
  1612. if ($h > $ch) {
  1613. $w = $w * $ch/$h;
  1614. $h = $ch;
  1615. }
  1616. return array($w, $h, $repx, $repy);
  1617. }
  1618. else if ($resize==4) {
  1619. $h = $imh * $cw/$imw;
  1620. return array($cw, $h, $repx, $repy);
  1621. }
  1622. else if ($resize==5) {
  1623. $w = $imw * $ch/$imh;
  1624. return array($w, $ch, $repx, $repy);
  1625. }
  1626. else if ($resize==6) {
  1627. return array($cw, $ch, $repx, $repy);
  1628. }
  1629. return array($imw, $imh, $repx, $repy);
  1630. }
  1631. function SetBackground(&$properties, &$maxwidth) {
  1632. // mPDF 5.6.10 5.6.11
  1633. if (isset($properties['BACKGROUND-ORIGIN']) && ($properties['BACKGROUND-ORIGIN']=='border-box' || $properties['BACKGROUND-ORIGIN']== 'content-box')) { $origin = $properties['BACKGROUND-ORIGIN']; }
  1634. else { $origin = 'padding-box'; }
  1635. // mPDF 5.6.10
  1636. if (isset($properties['BACKGROUND-SIZE'])) {
  1637. if (stristr($properties['BACKGROUND-SIZE'] ,'contain') ) { $bsw = $bsh = 'contain'; }
  1638. else if (stristr($properties['BACKGROUND-SIZE'] ,'cover') ) { $bsw = $bsh = 'cover'; }
  1639. else {
  1640. $bsw = $bsh = 'auto';
  1641. $sz = preg_split('/\s+/',trim($properties['BACKGROUND-SIZE']));
  1642. if (count($sz)==2) { $bsw = $sz[0]; $bsh = $sz[1]; }
  1643. else { $bsw = $sz[0]; }
  1644. if (!stristr($bsw ,'%') && !stristr($bsw ,'auto') ) { $bsw = $this->ConvertSize($bsw ,$maxwidth,$this->FontSize); }
  1645. if (!stristr($bsh ,'%') && !stristr($bsh ,'auto') ) { $bsh = $this->ConvertSize($bsh ,$maxwidth,$this->FontSize); }
  1646. }
  1647. $size = array('w'=>$bsw, 'h'=>$bsh);
  1648. }
  1649. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['BACKGROUND-IMAGE'])) {
  1650. return array('gradient'=>$properties['BACKGROUND-IMAGE'], 'origin'=>$origin, 'size'=>$size ); // mPDF 5.6.10
  1651. }
  1652. else {
  1653. $file = $properties['BACKGROUND-IMAGE'];
  1654. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, true);
  1655. if (isset($sizesarray['IMAGE_ID'])) {
  1656. $image_id = $sizesarray['IMAGE_ID'];
  1657. $orig_w = $sizesarray['WIDTH']*_MPDFK; // in user units i.e. mm
  1658. $orig_h = $sizesarray['HEIGHT']*_MPDFK; // (using $this->img_dpi)
  1659. if (isset($properties['BACKGROUND-IMAGE-RESOLUTION'])) {
  1660. if (preg_match('/from-image/i', $properties['BACKGROUND-IMAGE-RESOLUTION']) && isset($sizesarray['set-dpi']) && $sizesarray['set-dpi']>0) {
  1661. $orig_w *= $this->img_dpi / $sizesarray['set-dpi'];
  1662. $orig_h *= $this->img_dpi / $sizesarray['set-dpi'];
  1663. }
  1664. else if (preg_match('/(\d+)dpi/i', $properties['BACKGROUND-IMAGE-RESOLUTION'], $m)) {
  1665. $dpi = $m[1];
  1666. if ($dpi > 0) {
  1667. $orig_w *= $this->img_dpi / $dpi;
  1668. $orig_h *= $this->img_dpi / $dpi;
  1669. }
  1670. }
  1671. }
  1672. $x_repeat = true;
  1673. $y_repeat = true;
  1674. if (isset($properties['BACKGROUND-REPEAT'])) {
  1675. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  1676. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  1677. }
  1678. $x_pos = 0;
  1679. $y_pos = 0;
  1680. if (isset($properties['BACKGROUND-POSITION'])) {
  1681. $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']);
  1682. $x_pos = $ppos[0];
  1683. $y_pos = $ppos[1];
  1684. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$maxwidth,$this->FontSize); }
  1685. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$maxwidth,$this->FontSize); }
  1686. }
  1687. if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; }
  1688. else { $resize = 0; }
  1689. if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; }
  1690. else { $opacity = 1; }
  1691. 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'], 'origin'=>$origin, 'size'=>$size );
  1692. }
  1693. }
  1694. return false;
  1695. }
  1696. /*-- END BACKGROUNDS --*/
  1697. function PrintBodyBackgrounds() {
  1698. $s = '';
  1699. $clx = 0;
  1700. $cly = 0;
  1701. $clw = $this->w;
  1702. $clh = $this->h;
  1703. // If using bleed and trim margins in paged media
  1704. if ($this->pageDim[$this->page]['outer_width_LR'] || $this->pageDim[$this->page]['outer_width_TB']) {
  1705. $clx = $this->pageDim[$this->page]['outer_width_LR'] - $this->pageDim[$this->page]['bleedMargin'];
  1706. $cly = $this->pageDim[$this->page]['outer_width_TB'] - $this->pageDim[$this->page]['bleedMargin'];
  1707. $clw = $this->w - 2*$clx;
  1708. $clh = $this->h - 2*$cly;
  1709. }
  1710. if ($this->bodyBackgroundColor) {
  1711. $s .= 'q ' .$this->SetFColor($this->bodyBackgroundColor, true)."\n";
  1712. if ($this->bodyBackgroundColor{0}==5) { // RGBa
  1713. $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{4})/100, 'Normal', true, 'F')."\n";
  1714. }
  1715. else if ($this->bodyBackgroundColor{0}==6) { // CMYKa
  1716. $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{5})/100, 'Normal', true, 'F')."\n";
  1717. }
  1718. $s .= sprintf('%.3F %.3F %.3F %.3F re f Q', ($clx*_MPDFK), ($cly*_MPDFK),$clw*_MPDFK,$clh*_MPDFK)."\n";
  1719. }
  1720. /*-- BACKGROUNDS --*/
  1721. if ($this->bodyBackgroundGradient) {
  1722. $g = $this->grad->parseBackgroundGradient($this->bodyBackgroundGradient);
  1723. if ($g) {
  1724. $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, (isset($g['gradtype']) ? $g['gradtype'] : null), $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
  1725. }
  1726. }
  1727. if ($this->bodyBackgroundImage) {
  1728. if ( $this->bodyBackgroundImage['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->bodyBackgroundImage['gradient'])) {
  1729. $g = $this->grad->parseMozGradient( $this->bodyBackgroundImage['gradient']);
  1730. if ($g) {
  1731. $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
  1732. }
  1733. }
  1734. else if ($this->bodyBackgroundImage['image_id']) { // Background pattern
  1735. $n = count($this->patterns)+1;
  1736. // If using resize, uses TrimBox (not including the bleed)
  1737. 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']);
  1738. $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']);
  1739. if (($this->bodyBackgroundImage['opacity']>0 || $this->bodyBackgroundImage['opacity']==='0') && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); }
  1740. else { $opac = ''; }
  1741. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, ($clx*_MPDFK), ($cly*_MPDFK),$clw*_MPDFK, $clh*_MPDFK) ."\n";
  1742. }
  1743. }
  1744. /*-- END BACKGROUNDS --*/
  1745. return $s;
  1746. }
  1747. function PrintPageBackgrounds($adjustmenty=0) {
  1748. $s = '';
  1749. ksort($this->pageBackgrounds);
  1750. foreach($this->pageBackgrounds AS $bl=>$pbs) {
  1751. foreach ($pbs AS $pb) {
  1752. if ((!isset($pb['image_id']) && !isset($pb['gradient'])) || isset($pb['shadowonly'])) { // Background colour or boxshadow
  1753. // mPDF 5.6.01 - LAYERS
  1754. if($pb['z-index']>0) {
  1755. $this->current_layer = $pb['z-index'];
  1756. $s .= "\n".'/OCBZ-index /ZI'.$pb['z-index'].' BDC'."\n";
  1757. }
  1758. if($pb['visibility']!='visible') {
  1759. if($pb['visibility']=='printonly')
  1760. $s .= '/OC /OC1 BDC'."\n";
  1761. else if($pb['visibility']=='screenonly')
  1762. $s .= '/OC /OC2 BDC'."\n";
  1763. else if($pb['visibility']=='hidden')
  1764. $s .= '/OC /OC3 BDC'."\n";
  1765. }
  1766. // Box shadow
  1767. if (isset($pb['shadow']) && $pb['shadow']) { $s .= $pb['shadow']."\n"; }
  1768. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1769. $s .= 'q '.$this->SetFColor($pb['col'], true)."\n";
  1770. if ($pb['col']{0}==5) { // RGBa
  1771. $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n";
  1772. }
  1773. else if ($pb['col']{0}==6) { // CMYKa
  1774. $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n";
  1775. }
  1776. $s .= sprintf('%.3F %.3F %.3F %.3F re f Q',$pb['x']*_MPDFK,($this->h-$pb['y'])*_MPDFK,$pb['w']*_MPDFK,-$pb['h']*_MPDFK)."\n";
  1777. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1778. if($pb['visibility']!='visible')
  1779. $s .= 'EMC'."\n";
  1780. // mPDF 5.6.01 - LAYERS
  1781. if($pb['z-index']>0) {
  1782. $s .= "\n".'EMCBZ-index'."\n";
  1783. $this->current_layer = 0;
  1784. }
  1785. }
  1786. }
  1787. /*-- BACKGROUNDS --*/
  1788. foreach ($pbs AS $pb) {
  1789. // mPDF 5.6.01 - LAYERS
  1790. if ((isset($pb['gradient']) && $pb['gradient']) || (isset($pb['image_id']) && $pb['image_id'])) {
  1791. if($pb['z-index']>0) {
  1792. $this->current_layer = $pb['z-index'];
  1793. $s .= "\n".'/OCGZ-index /ZI'.$pb['z-index'].' BDC'."\n";
  1794. }
  1795. if($pb['visibility']!='visible') {
  1796. if($pb['visibility']=='printonly')
  1797. $s .= '/OC /OC1 BDC'."\n";
  1798. else if($pb['visibility']=='screenonly')
  1799. $s .= '/OC /OC2 BDC'."\n";
  1800. else if($pb['visibility']=='hidden')
  1801. $s .= '/OC /OC3 BDC'."\n";
  1802. }
  1803. }
  1804. if (isset($pb['gradient']) && $pb['gradient']) {
  1805. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1806. $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1807. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1808. }
  1809. else if (isset($pb['image_id']) && $pb['image_id']) { // Background Image
  1810. $pb['y'] -= $adjustmenty;
  1811. $pb['h'] += $adjustmenty;
  1812. $n = count($this->patterns)+1;
  1813. 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'], $pb['bpa'], $pb['size']); // mPDF 5.6.10
  1814. $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'], 'bpa'=>$pb['bpa']); // mPDF 5.6.10
  1815. $x = $pb['x']*_MPDFK;
  1816. $y = ($this->h - $pb['y'])*_MPDFK;
  1817. $w = $pb['w']*_MPDFK;
  1818. $h = -$pb['h']*_MPDFK;
  1819. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1820. if ($this->writingHTMLfooter || $this->writingHTMLheader) { // Write each (tiles) image rather than use as a pattern
  1821. $iw = $pb['orig_w']/_MPDFK;
  1822. $ih = $pb['orig_h']/_MPDFK;
  1823. $w = $pb['w'];
  1824. $h = $pb['h'];
  1825. $x0 = $pb['x'];
  1826. $y0 = $pb['y'];
  1827. // mPDF 5.6.11
  1828. if (isset($pb['bpa']) && $pb['bpa']) {
  1829. $w = $pb['bpa']['w'];
  1830. $h = $pb['bpa']['h'];
  1831. $x0 = $pb['bpa']['x'];
  1832. $y0 = $pb['bpa']['y'];
  1833. }
  1834. // mPDF 5.6.11
  1835. if (isset($pb['size']['w']) && $pb['size']['w']) {
  1836. $size = $pb['size'];
  1837. if ($size['w']=='contain') {
  1838. // Scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.
  1839. // Same as resize==3
  1840. $ih = $ih * $pb['bpa']['w']/$iw;
  1841. $iw = $pb['bpa']['w'];
  1842. if ($ih > $pb['bpa']['h']) {
  1843. $iw = $iw * $pb['bpa']['h']/$ih;
  1844. $ih = $pb['bpa']['h'];
  1845. }
  1846. }
  1847. else if ($size['w']=='cover') {
  1848. // Scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.
  1849. $ih = $ih * $pb['bpa']['w']/$iw;
  1850. $iw = $pb['bpa']['w'];
  1851. if ($ih < $pb['bpa']['h']) {
  1852. $iw = $iw * $ih/$pb['bpa']['h'];
  1853. $ih = $pb['bpa']['h'];
  1854. }
  1855. }
  1856. else {
  1857. if (stristr($size['w'] ,'%')) {
  1858. $size['w'] += 0;
  1859. $size['w'] /= 100;
  1860. $size['w'] = ($pb['bpa']['w'] * $size['w']);
  1861. }
  1862. if (stristr($size['h'] ,'%')) {
  1863. $size['h'] += 0;
  1864. $size['h'] /= 100;
  1865. $size['h'] = ($pb['bpa']['h'] * $size['h']);
  1866. }
  1867. if ($size['w']=='auto' && $size['h']=='auto') {
  1868. $iw = $iw;
  1869. $ih = $ih;
  1870. }
  1871. else if ($size['w']=='auto' && $size['h']!='auto') {
  1872. $iw = $iw * $size['h']/$ih;
  1873. $ih = $size['h'];
  1874. }
  1875. else if ($size['w']!='auto' && $size['h']=='auto') {
  1876. $ih = $ih * $size['w']/$iw;
  1877. $iw = $size['w'];
  1878. }
  1879. else {
  1880. $iw = $size['w'];
  1881. $ih = $size['h'];
  1882. }
  1883. }
  1884. }
  1885. // Number to repeat
  1886. if ($pb['x_repeat']) { $nx = ceil($pb['w']/$iw)+1; } // mPDF 5.6.11
  1887. else { $nx = 1; }
  1888. if ($pb['y_repeat']) { $ny = ceil($pb['h']/$ih)+1; } // mPDF 5.6.11
  1889. else { $ny = 1; }
  1890. $x_pos = $pb['x_pos'];
  1891. if (stristr($x_pos ,'%') ) {
  1892. $x_pos += 0;
  1893. $x_pos /= 100;
  1894. $x_pos = ($pb['bpa']['w'] * $x_pos) - ($iw * $x_pos); // mPDF 5.6.11
  1895. }
  1896. $y_pos = $pb['y_pos'];
  1897. if (stristr($y_pos ,'%') ) {
  1898. $y_pos += 0;
  1899. $y_pos /= 100;
  1900. $y_pos = ($pb['bpa']['h'] * $y_pos) - ($ih * $y_pos); // mPDF 5.6.11
  1901. }
  1902. if ($nx>1) {
  1903. while($x_pos>($pb['x']-$pb['bpa']['x'])) { $x_pos -= $iw; } // mPDF 5.6.11
  1904. }
  1905. if ($ny>1) {
  1906. while($y_pos>($pb['y']-$pb['bpa']['y'])) { $y_pos -= $ih; } // mPDF 5.6.11
  1907. }
  1908. for($xi=0;$xi<$nx;$xi++) {
  1909. for($yi=0;$yi<$ny;$yi++) {
  1910. $x = $x0 + $x_pos + ($iw*$xi);
  1911. $y = $y0 + $y_pos + ($ih*$yi);
  1912. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1913. else { $opac = ''; }
  1914. $s .= sprintf("q %s %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q", $opac,$iw*_MPDFK,$ih*_MPDFK,$x*_MPDFK,($this->h-($y+$ih))*_MPDFK,$pb['image_id']) ."\n";
  1915. }
  1916. }
  1917. }
  1918. else {
  1919. if (($pb['opacity']>0 || $pb['opacity']==='0') && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1920. else { $opac = ''; }
  1921. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1922. }
  1923. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1924. }
  1925. if ((isset($pb['gradient']) && $pb['gradient']) || (isset($pb['image_id']) && $pb['image_id'])) {
  1926. if($pb['visibility']!='visible')
  1927. $s .= 'EMC'."\n";
  1928. // mPDF 5.6.01 - LAYERS
  1929. if($pb['z-index']>0) {
  1930. $s .= "\n".'EMCGZ-index'."\n";
  1931. $this->current_layer = 0;
  1932. }
  1933. }
  1934. }
  1935. /*-- END BACKGROUNDS --*/
  1936. }
  1937. return $s;
  1938. }
  1939. function PrintTableBackgrounds($adjustmenty=0) {
  1940. $s = '';
  1941. /*-- BACKGROUNDS --*/
  1942. ksort($this->tableBackgrounds);
  1943. foreach($this->tableBackgrounds AS $bl=>$pbs) {
  1944. foreach ($pbs AS $pb) {
  1945. if ((!isset($pb['gradient']) || !$pb['gradient']) && (!isset($pb['image_id']) || !$pb['image_id'])) {
  1946. $s .= 'q '.$this->SetFColor($pb['col'], true)."\n";
  1947. if ($pb['col']{0}==5) { // RGBa
  1948. $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n";
  1949. }
  1950. else if ($pb['col']{0}==6) { // CMYKa
  1951. $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n";
  1952. }
  1953. $s .= sprintf('%.3F %.3F %.3F %.3F re %s Q',$pb['x']*_MPDFK,($this->h-$pb['y'])*_MPDFK,$pb['w']*_MPDFK,-$pb['h']*_MPDFK,'f')."\n";
  1954. }
  1955. if (isset($pb['gradient']) && $pb['gradient']) {
  1956. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1957. $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1958. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1959. }
  1960. if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1961. $pb['y'] -= $adjustmenty;
  1962. $pb['h'] += $adjustmenty;
  1963. $n = count($this->patterns)+1;
  1964. 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']);
  1965. $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']);
  1966. $x = $pb['x']*_MPDFK;
  1967. $y = ($this->h - $pb['y'])*_MPDFK;
  1968. $w = $pb['w']*_MPDFK;
  1969. $h = -$pb['h']*_MPDFK;
  1970. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1971. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1972. else { $opac = ''; }
  1973. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1974. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1975. }
  1976. }
  1977. }
  1978. /*-- END BACKGROUNDS --*/
  1979. return $s;
  1980. }
  1981. // mPDF 5.6.01 - LAYERS
  1982. function BeginLayer($id) {
  1983. if($this->current_layer>0) $this->EndLayer();
  1984. if ($id < 1) { return false; }
  1985. if (!isset($this->layers[$id])) {
  1986. $this->layers[$id] = array('name'=>'Layer '.($id) );
  1987. if (($this->PDFA || $this->PDFX)) { $this->PDFAXwarnings[] = "Cannot use layers when using PDFA or PDFX"; return ''; }
  1988. else if (!$this->PDFA && !$this->PDFX) { $this->pdf_version='1.5'; }
  1989. }
  1990. $this->current_layer = $id;
  1991. $this->_out('/OCZ-index /ZI'.$id.' BDC');
  1992. $this->pageoutput[$this->page] = array();
  1993. }
  1994. function EndLayer() {
  1995. if($this->current_layer>0) {
  1996. $this->_out('EMCZ-index');
  1997. $this->current_layer = 0;
  1998. }
  1999. }
  2000. // Depracated - can use AddPage for all
  2001. 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='')
  2002. {
  2003. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  2004. }
  2005. function AddPageByArray($a) {
  2006. if (!is_array($a)) { $a = array(); }
  2007. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  2008. $condition = (isset($a['condition']) ? $a['condition'] : (isset($a['type']) ? $a['type'] : ''));
  2009. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  2010. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  2011. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  2012. $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : ''));
  2013. $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : ''));
  2014. $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : ''));
  2015. $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : ''));
  2016. $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : ''));
  2017. $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : ''));
  2018. $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : ''));
  2019. $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : ''));
  2020. $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : ''));
  2021. $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : ''));
  2022. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0));
  2023. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0));
  2024. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0));
  2025. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0));
  2026. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : ''));
  2027. $newformat = (isset($a['newformat']) ? $a['newformat'] : (isset($a['sheet-size']) ? $a['sheet-size'] : ''));
  2028. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  2029. }
  2030. 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='')
  2031. {
  2032. /*-- CSS-FLOAT --*/
  2033. // Float DIV
  2034. // Cannot do with columns on, or if any change in page orientation/margins etc.
  2035. // If next page already exists - i.e background /headers and footers already written
  2036. if ($this->state > 0 && $this->page < count($this->pages)) {
  2037. $bak_cml = $this->cMarginL;
  2038. $bak_cmr = $this->cMarginR;
  2039. $bak_dw = $this->divwidth;
  2040. // Paint Div Border if necessary
  2041. if ($this->blklvl > 0) {
  2042. $save_tr = $this->table_rotate; // *TABLES*
  2043. $this->table_rotate = 0; // *TABLES*
  2044. if ($this->y == $this->blk[$this->blklvl]['y0']) { $this->blk[$this->blklvl]['startpage']++; }
  2045. if (($this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  2046. else { $toplvl = $this->blklvl-1; }
  2047. $sy = $this->y;
  2048. for ($bl=1;$bl<=$toplvl;$bl++) {
  2049. $this->PaintDivBB('pagebottom',0,$bl);
  2050. }
  2051. $this->y = $sy;
  2052. $this->table_rotate = $save_tr; // *TABLES*
  2053. }
  2054. $s = $this->PrintPageBackgrounds();
  2055. // Writes after the marker so not overwritten later by page background etc.
  2056. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  2057. $this->pageBackgrounds = array();
  2058. $family=$this->FontFamily;
  2059. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2060. $size=$this->FontSizePt;
  2061. $lw=$this->LineWidth;
  2062. $dc=$this->DrawColor;
  2063. $fc=$this->FillColor;
  2064. $tc=$this->TextColor;
  2065. $cf=$this->ColorFlag;
  2066. $this->printfloatbuffer();
  2067. //Move to next page
  2068. $this->page++;
  2069. $this->ResetMargins();
  2070. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  2071. $this->x=$this->lMargin;
  2072. $this->y=$this->tMargin;
  2073. $this->FontFamily='';
  2074. $this->_out('2 J');
  2075. $this->LineWidth=$lw;
  2076. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  2077. if($family) $this->SetFont($family,$style,$size,true,true);
  2078. $this->DrawColor=$dc;
  2079. if($dc!=$this->defDrawColor) $this->_out($dc);
  2080. $this->FillColor=$fc;
  2081. if($fc!=$this->defFillColor) $this->_out($fc);
  2082. $this->TextColor=$tc;
  2083. $this->ColorFlag=$cf;
  2084. for($bl=1;$bl<=$this->blklvl;$bl++) {
  2085. $this->blk[$bl]['y0'] = $this->y;
  2086. // Don't correct more than once for background DIV containing a Float
  2087. if (!isset($this->blk[$bl]['marginCorrected'][$this->page])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  2088. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  2089. }
  2090. $this->cMarginL = $bak_cml;
  2091. $this->cMarginR = $bak_cmr;
  2092. $this->divwidth = $bak_dw;
  2093. return '';
  2094. }
  2095. /*-- END CSS-FLOAT --*/
  2096. //Start a new page
  2097. if($this->state==0) $this->Open();
  2098. $bak_cml = $this->cMarginL;
  2099. $bak_cmr = $this->cMarginR;
  2100. $bak_dw = $this->divwidth;
  2101. $bak_lh = $this->lineheight;
  2102. $orientation = substr(strtoupper($orientation),0,1);
  2103. $condition = strtoupper($condition);
  2104. if ($condition == 'NEXT-EVEN') { // always adds at least one new page to create an Even page
  2105. if (!$this->mirrorMargins) { $condition = ''; }
  2106. else {
  2107. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  2108. else { $pbch = false; } // *CSS-PAGE*
  2109. $this->AddPage($this->CurOrientation,'O');
  2110. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  2111. $condition = '';
  2112. }
  2113. }
  2114. if ($condition == 'NEXT-ODD') { // always adds at least one new page to create an Odd page
  2115. if (!$this->mirrorMargins) { $condition = ''; }
  2116. else {
  2117. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  2118. else { $pbch = false; } // *CSS-PAGE*
  2119. $this->AddPage($this->CurOrientation,'E');
  2120. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  2121. $condition = '';
  2122. }
  2123. }
  2124. if ($condition == 'E') { // only adds new page if needed to create an Even page
  2125. if (!$this->mirrorMargins || ($this->page)%2==0) { return false; }
  2126. }
  2127. if ($condition == 'O') { // only adds new page if needed to create an Odd page
  2128. if (!$this->mirrorMargins || ($this->page)%2==1) { return false; }
  2129. }
  2130. if ($resetpagenum || $pagenumstyle || $suppress) {
  2131. $this->PageNumSubstitutions[] = array('from'=>($this->page+1), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  2132. }
  2133. $save_tr = $this->table_rotate; // *TABLES*
  2134. $this->table_rotate = 0; // *TABLES*
  2135. $save_kwt = $this->kwt;
  2136. $this->kwt = 0;
  2137. // mPDF 5.6.01 - LAYERS
  2138. $save_layer = $this->current_layer;
  2139. $save_vis = $this->visibility;
  2140. if($this->visibility!='visible')
  2141. $this->SetVisibility('visible');
  2142. // mPDF 5.6.01 - LAYERS
  2143. $this->EndLayer();
  2144. // Paint Div Border if necessary
  2145. //PAINTS BACKGROUND COLOUR OR BORDERS for DIV - DISABLED FOR COLUMNS (cf. AcceptPageBreak) AT PRESENT in ->PaintDivBB
  2146. if (!$this->ColActive && $this->blklvl > 0) {
  2147. if (isset($this->blk[$this->blklvl]['y0']) && $this->y == $this->blk[$this->blklvl]['y0']) {
  2148. if (isset($this->blk[$this->blklvl]['startpage'])) { $this->blk[$this->blklvl]['startpage']++; }
  2149. else { $this->blk[$this->blklvl]['startpage'] = 1; }
  2150. }
  2151. if ((isset($this->blk[$this->blklvl]['y0']) && $this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  2152. else { $toplvl = $this->blklvl-1; }
  2153. $sy = $this->y;
  2154. for ($bl=1;$bl<=$toplvl;$bl++) {
  2155. // mPDF 5.6.01 - LAYERS
  2156. if ($this->blk[$bl]['z-index']>0) {
  2157. $this->BeginLayer($this->blk[$bl]['z-index']);
  2158. }
  2159. if (isset($this->blk[$bl]['visibility']) && $this->blk[$bl]['visibility'] && $this->blk[$bl]['visibility']!='visible') {
  2160. $this->SetVisibility($this->blk[$bl]['visibility']);
  2161. }
  2162. $this->PaintDivBB('pagebottom',0,$bl);
  2163. }
  2164. $this->y = $sy;
  2165. // RESET block y0 and x0 - see below
  2166. }
  2167. if($this->visibility!='visible')
  2168. $this->SetVisibility('visible');
  2169. // mPDF 5.6.01 - LAYERS
  2170. $this->EndLayer();
  2171. // BODY Backgrounds
  2172. if ($this->page > 0) {
  2173. $s = '';
  2174. $s .= $this->PrintBodyBackgrounds();
  2175. $s .= $this->PrintPageBackgrounds();
  2176. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  2177. $this->pageBackgrounds = array();
  2178. }
  2179. $save_kt = $this->keep_block_together;
  2180. $this->keep_block_together = 0;
  2181. $save_cols = false;
  2182. /*-- COLUMNS --*/
  2183. if ($this->ColActive) {
  2184. $save_cols = true;
  2185. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  2186. $this->SetColumns(0);
  2187. }
  2188. /*-- END COLUMNS --*/
  2189. $family=$this->FontFamily;
  2190. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2191. $size=$this->FontSizePt;
  2192. $this->ColumnAdjust = true; // enables column height adjustment for the page
  2193. $lw=$this->LineWidth;
  2194. $dc=$this->DrawColor;
  2195. $fc=$this->FillColor;
  2196. $tc=$this->TextColor;
  2197. $cf=$this->ColorFlag;
  2198. if($this->page>0)
  2199. {
  2200. //Page footer
  2201. $this->InFooter=true;
  2202. $this->Reset();
  2203. $this->pageoutput[$this->page] = array();
  2204. $this->Footer();
  2205. //Close page
  2206. $this->_endpage();
  2207. }
  2208. //Start new page
  2209. $this->_beginpage($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat);
  2210. if ($this->docTemplate) {
  2211. $pagecount = $this->SetSourceFile($this->docTemplate);
  2212. if (($this->page - $this->docTemplateStart) > $pagecount) {
  2213. if ($this->docTemplateContinue) {
  2214. $tplIdx = $this->ImportPage($pagecount);
  2215. $this->UseTemplate($tplIdx);
  2216. }
  2217. }
  2218. else {
  2219. $tplIdx = $this->ImportPage(($this->page - $this->docTemplateStart));
  2220. $this->UseTemplate($tplIdx);
  2221. }
  2222. }
  2223. if ($this->pageTemplate) {
  2224. $this->UseTemplate($this->pageTemplate);
  2225. }
  2226. // Tiling Patterns
  2227. $this->_out('___PAGE___START'.date('jY'));
  2228. $this->_out('___BACKGROUND___PATTERNS'.date('jY'));
  2229. $this->_out('___HEADER___MARKER'.date('jY'));
  2230. $this->pageBackgrounds = array();
  2231. //Set line cap style to square
  2232. $this->SetLineCap(2);
  2233. //Set line width
  2234. $this->LineWidth=$lw;
  2235. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  2236. //Set font
  2237. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2238. //Set colors
  2239. $this->DrawColor=$dc;
  2240. if($dc!=$this->defDrawColor) $this->_out($dc);
  2241. $this->FillColor=$fc;
  2242. if($fc!=$this->defFillColor) $this->_out($fc);
  2243. $this->TextColor=$tc;
  2244. $this->ColorFlag=$cf;
  2245. //Page header
  2246. $this->Header();
  2247. //Restore line width
  2248. if($this->LineWidth!=$lw)
  2249. {
  2250. $this->LineWidth=$lw;
  2251. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  2252. }
  2253. //Restore font
  2254. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2255. //Restore colors
  2256. if($this->DrawColor!=$dc)
  2257. {
  2258. $this->DrawColor=$dc;
  2259. $this->_out($dc);
  2260. }
  2261. if($this->FillColor!=$fc)
  2262. {
  2263. $this->FillColor=$fc;
  2264. $this->_out($fc);
  2265. }
  2266. $this->TextColor=$tc;
  2267. $this->ColorFlag=$cf;
  2268. $this->InFooter=false;
  2269. // mPDF 5.6.01 - LAYERS
  2270. if ($save_layer>0)
  2271. $this->BeginLayer($save_layer);
  2272. if($save_vis!='visible')
  2273. $this->SetVisibility($save_vis);
  2274. /*-- COLUMNS --*/
  2275. if ($save_cols) {
  2276. // Restore columns
  2277. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  2278. }
  2279. if ($this->ColActive) { $this->SetCol(0); }
  2280. /*-- END COLUMNS --*/
  2281. //RESET BLOCK BORDER TOP
  2282. if (!$this->ColActive) {
  2283. for($bl=1;$bl<=$this->blklvl;$bl++) {
  2284. $this->blk[$bl]['y0'] = $this->y;
  2285. if (isset($this->blk[$bl]['x0'])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  2286. else { $this->blk[$bl]['x0'] = $this->MarginCorrection; }
  2287. // Added mPDF 3.0 Float DIV
  2288. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  2289. }
  2290. }
  2291. $this->table_rotate = $save_tr; // *TABLES*
  2292. $this->kwt = $save_kwt;
  2293. $this->keep_block_together = $save_kt ;
  2294. $this->cMarginL = $bak_cml;
  2295. $this->cMarginR = $bak_cmr;
  2296. $this->divwidth = $bak_dw;
  2297. $this->lineheight = $bak_lh;
  2298. }
  2299. function PageNo() {
  2300. //Get current page number
  2301. return $this->page;
  2302. }
  2303. function AddSpotColorsFromFile($file) {
  2304. $colors = @file($file) or die("Cannot load spot colors file - ".$file);
  2305. foreach($colors AS $sc) {
  2306. list($name, $c, $m, $y, $k) = preg_split("/\t/",$sc);
  2307. $c = intval($c);
  2308. $m = intval($m);
  2309. $y = intval($y);
  2310. $k = intval($k);
  2311. $this->AddSpotColor($name, $c, $m, $y, $k);
  2312. }
  2313. }
  2314. function AddSpotColor($name, $c, $m, $y, $k) {
  2315. $name = strtoupper(trim($name));
  2316. if(!isset($this->spotColors[$name])) {
  2317. $i=count($this->spotColors)+1;
  2318. $this->spotColors[$name]=array('i'=>$i,'c'=>$c,'m'=>$m,'y'=>$y,'k'=>$k);
  2319. $this->spotColorIDs[$i]=$name;
  2320. }
  2321. }
  2322. function SetColor($col, $type='') {
  2323. $out = '';
  2324. if ($col{0}==3 || $col{0}==5) { // RGB / RGBa
  2325. $out = sprintf('%.3F %.3F %.3F rg',ord($col{1})/255,ord($col{2})/255,ord($col{3})/255);
  2326. }
  2327. else if ($col{0}==1) { // GRAYSCALE
  2328. $out = sprintf('%.3F g',ord($col{1})/255);
  2329. }
  2330. else if ($col{0}==2) { // SPOT COLOR
  2331. $out = sprintf('/CS%d cs %.3F scn',ord($col{1}),ord($col{2})/100);
  2332. }
  2333. else if ($col{0}==4 || $col{0}==6) { // CMYK / CMYKa
  2334. $out = sprintf('%.3F %.3F %.3F %.3F k', ord($col{1})/100, ord($col{2})/100, ord($col{3})/100, ord($col{4})/100);
  2335. }
  2336. if ($type=='Draw') { $out = strtoupper($out); } // e.g. rg => RG
  2337. else if ($type=='CodeOnly') { $out = preg_replace('/\s(rg|g|k)/','',$out); }
  2338. return $out;
  2339. }
  2340. function SetDColor($col, $return=false) {
  2341. $out = $this->SetColor($col, 'Draw');
  2342. if ($return) { return $out; }
  2343. if ($out=='') { return ''; }
  2344. $this->DrawColor = $out;
  2345. 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); }
  2346. $this->pageoutput[$this->page]['DrawColor'] = $this->DrawColor;
  2347. }
  2348. function SetFColor($col, $return=false) {
  2349. $out = $this->SetColor($col, 'Fill');
  2350. if ($return) { return $out; }
  2351. if ($out=='') { return ''; }
  2352. $this->FillColor = $out;
  2353. $this->ColorFlag = ($out != $this->TextColor);
  2354. 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); }
  2355. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  2356. }
  2357. function SetTColor($col, $return=false) {
  2358. $out = $this->SetColor($col, 'Text');
  2359. if ($return) { return $out; }
  2360. if ($out=='') { return ''; }
  2361. $this->TextColor = $out;
  2362. $this->ColorFlag = ($this->FillColor != $out);
  2363. }
  2364. function SetDrawColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2365. //Set color for all stroking operations
  2366. $col = array();
  2367. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2368. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2369. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2370. $out = $this->SetDColor($col, $return);
  2371. return $out;
  2372. }
  2373. function SetFillColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2374. //Set color for all filling operations
  2375. $col = array();
  2376. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2377. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2378. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2379. $out = $this->SetFColor($col, $return);
  2380. return $out;
  2381. }
  2382. function SetTextColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2383. //Set color for text
  2384. $col = array();
  2385. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2386. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2387. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2388. $out = $this->SetTColor($col, $return);
  2389. return $out;
  2390. }
  2391. function _getCharWidth(&$cw, $u, $isdef=true) {
  2392. if ($u==0) { $w = false; }
  2393. else { $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); }
  2394. if ($w == 65535) { return 0; }
  2395. else if ($w) { return $w; }
  2396. else if ($isdef) { return false; }
  2397. else { return 0; }
  2398. }
  2399. function _charDefined(&$cw, $u) {
  2400. if ($u==0) { return false; }
  2401. $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]);
  2402. if ($w) { return true; }
  2403. else { return false; }
  2404. }
  2405. function GetCharWidthCore($c) {
  2406. //Get width of a single character in the current Core font
  2407. $c = (string)$c;
  2408. $w = 0;
  2409. // Soft Hyphens chr(173)
  2410. if ($c == chr(173) && $this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  2411. return 0;
  2412. }
  2413. else if ($this->S && isset($this->upperCase[ord($c)])) {
  2414. $charw = $this->CurrentFont['cw'][chr($this->upperCase[ord($c)])];
  2415. if ($charw!==false) {
  2416. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2417. $w+=$charw;
  2418. }
  2419. }
  2420. else if (isset($this->CurrentFont['cw'][$c])) {
  2421. $w += $this->CurrentFont['cw'][$c];
  2422. }
  2423. else if (isset($this->CurrentFont['cw'][ord($c)])) {
  2424. $w += $this->CurrentFont['cw'][ord($c)];
  2425. }
  2426. $w *= ($this->FontSize/ 1000);
  2427. if ($this->minwSpacing || $this->fixedlSpacing) {
  2428. if ($c==' ') $nb_spaces = 1;
  2429. else $nb_spaces = 0;
  2430. $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing);
  2431. }
  2432. return ($w);
  2433. }
  2434. function GetCharWidthNonCore($c, $addSubset=true) {
  2435. //Get width of a single character in the current Non-Core font
  2436. $c = (string)$c;
  2437. $w = 0;
  2438. $unicode = $this->UTF8StringToArray($c, $addSubset);
  2439. $char = $unicode[0];
  2440. /*-- CJK-FONTS --*/
  2441. if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts
  2442. if ($char == 173) { return 0; } // Soft Hyphens
  2443. elseif (isset($this->CurrentFont['cw'][$char])) { $w+=$this->CurrentFont['cw'][$char]; }
  2444. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2445. else { $w += 500; }
  2446. }
  2447. else {
  2448. /*-- END CJK-FONTS --*/
  2449. if ($char == 173) { return 0; } // Soft Hyphens
  2450. else if ($this->S && isset($this->upperCase[$char])) {
  2451. $charw = $this->_getCharWidth($this->CurrentFont['cw'],$this->upperCase[$char]);
  2452. if ($charw!==false) {
  2453. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2454. $w+=$charw;
  2455. }
  2456. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2457. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2458. else { $w += 500; }
  2459. }
  2460. else {
  2461. $charw = $this->_getCharWidth($this->CurrentFont['cw'],$char);
  2462. if ($charw!==false) { $w+=$charw; }
  2463. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2464. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2465. else { $w += 500; }
  2466. }
  2467. } // *CJK-FONTS*
  2468. $w *= ($this->FontSize/ 1000);
  2469. if ($this->minwSpacing || $this->fixedlSpacing) {
  2470. if ($c==' ') $nb_spaces = 1;
  2471. else $nb_spaces = 0;
  2472. $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing);
  2473. }
  2474. return ($w);
  2475. }
  2476. function GetCharWidth($c, $addSubset=true) {
  2477. if (!$this->usingCoreFont) {
  2478. return $this->GetCharWidthNonCore($c, $addSubset);
  2479. }
  2480. else {
  2481. return $this->GetCharWidthCore($c);
  2482. }
  2483. }
  2484. function GetStringWidth($s, $addSubset=true) {
  2485. //Get width of a string in the current font
  2486. $s = (string)$s;
  2487. $cw = &$this->CurrentFont['cw'];
  2488. $w = 0;
  2489. $kerning = 0;
  2490. $lastchar = 0;
  2491. $nb_carac = 0;
  2492. $nb_spaces = 0;
  2493. // mPDF ITERATION
  2494. if ($this->iterationCounter) $s = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/', '\\1', $s);
  2495. if (!$this->usingCoreFont) {
  2496. $s = str_replace("\xc2\xad",'',$s );
  2497. $unicode = $this->UTF8StringToArray($s, $addSubset);
  2498. if ($this->minwSpacing || $this->fixedlSpacing) {
  2499. $nb_carac = count($unicode);
  2500. $nb_spaces = mb_substr_count($s,' ', $this->mb_enc);
  2501. }
  2502. /*-- CJK-FONTS --*/
  2503. if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts
  2504. foreach($unicode as $char) {
  2505. if (isset($cw[$char])) { $w+=$cw[$char]; }
  2506. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2507. else { $w += 500; }
  2508. }
  2509. }
  2510. else {
  2511. /*-- END CJK-FONTS --*/
  2512. foreach($unicode as $char) {
  2513. if ($this->S && isset($this->upperCase[$char])) {
  2514. $charw = $this->_getCharWidth($cw,$this->upperCase[$char]);
  2515. if ($charw!==false) {
  2516. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2517. $w+=$charw;
  2518. }
  2519. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2520. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2521. else { $w += 500; }
  2522. }
  2523. else {
  2524. $charw = $this->_getCharWidth($cw,$char);
  2525. if ($charw!==false) { $w+=$charw; }
  2526. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2527. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2528. else { $w += 500; }
  2529. if ($this->kerning && $this->useKerning && $lastchar) {
  2530. if (isset($this->CurrentFont['kerninfo'][$lastchar][$char])) {
  2531. $kerning += $this->CurrentFont['kerninfo'][$lastchar][$char];
  2532. }
  2533. }
  2534. $lastchar = $char;
  2535. }
  2536. }
  2537. } // *CJK-FONTS*
  2538. }
  2539. else {
  2540. if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  2541. $s = str_replace(chr(173),'',$s );
  2542. }
  2543. $nb_carac = $l = strlen($s);
  2544. if ($this->minwSpacing || $this->fixedlSpacing) {
  2545. $nb_spaces = substr_count($s,' ');
  2546. }
  2547. for($i=0; $i<$l; $i++) {
  2548. if ($this->S && isset($this->upperCase[ord($s[$i])])) {
  2549. $charw = $cw[chr($this->upperCase[ord($s[$i])])];
  2550. if ($charw!==false) {
  2551. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2552. $w+=$charw;
  2553. }
  2554. }
  2555. else if (isset($cw[$s[$i]])) {
  2556. $w += $cw[$s[$i]];
  2557. }
  2558. else if (isset($cw[ord($s[$i])])) {
  2559. $w += $cw[ord($s[$i])];
  2560. }
  2561. if ($this->kerning && $this->useKerning && $i>0) {
  2562. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]])) {
  2563. $kerning += $this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]];
  2564. }
  2565. }
  2566. }
  2567. }
  2568. unset($cw);
  2569. if ($this->kerning && $this->useKerning) { $w += $kerning; }
  2570. $w *= ($this->FontSize/ 1000);
  2571. $w += (($nb_carac + $nb_spaces) * $this->fixedlSpacing) + ($nb_spaces * $this->minwSpacing);
  2572. return ($w);
  2573. }
  2574. function SetLineWidth($width) {
  2575. //Set line width
  2576. $this->LineWidth=$width;
  2577. $lwout = (sprintf('%.3F w',$width*_MPDFK));
  2578. 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)) {
  2579. $this->_out($lwout);
  2580. }
  2581. $this->pageoutput[$this->page]['LineWidth'] = $lwout;
  2582. }
  2583. function Line($x1,$y1,$x2,$y2) {
  2584. //Draw a line
  2585. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x2*_MPDFK,($this->h-$y2)*_MPDFK));
  2586. }
  2587. function Arrow($x1,$y1,$x2,$y2,$headsize=3,$fill='B',$angle=25) {
  2588. //F == fill //S == stroke //B == stroke and fill
  2589. // angle = splay of arrowhead - 1 - 89 degrees
  2590. if($fill=='F') $fill='f';
  2591. elseif($fill=='FD' or $fill=='DF' or $fill=='B') $fill='B';
  2592. else $fill='S';
  2593. $a = atan2(($y2-$y1),($x2-$x1));
  2594. $b = $a + deg2rad($angle);
  2595. $c = $a - deg2rad($angle);
  2596. $x3 = $x2 - ($headsize* cos($b));
  2597. $y3 = $this->h-($y2 - ($headsize* sin($b)));
  2598. $x4 = $x2 - ($headsize* cos($c));
  2599. $y4 = $this->h-($y2 - ($headsize* sin($c)));
  2600. $x5 = $x3-($x3-$x4)/2; // mid point of base of arrowhead - to join arrow line to
  2601. $y5 = $y3-($y3-$y4)/2;
  2602. $s = '';
  2603. $s.=sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x5*_MPDFK,$y5*_MPDFK);
  2604. $this->_out($s);
  2605. $s = '';
  2606. $s.=sprintf('%.3F %.3F m %.3F %.3F l %.3F %.3F l %.3F %.3F l %.3F %.3F l ',$x5*_MPDFK,$y5*_MPDFK,$x3*_MPDFK,$y3*_MPDFK,$x2*_MPDFK,($this->h-$y2)*_MPDFK,$x4*_MPDFK,$y4*_MPDFK,$x5*_MPDFK,$y5*_MPDFK);
  2607. $s.=$fill;
  2608. $this->_out($s);
  2609. }
  2610. function Rect($x,$y,$w,$h,$style='') {
  2611. //Draw a rectangle
  2612. if($style=='F') $op='f';
  2613. elseif($style=='FD' or $style=='DF') $op='B';
  2614. else $op='S';
  2615. $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$h*_MPDFK,$op));
  2616. }
  2617. function AddFont($family,$style='') {
  2618. if(empty($family)) { return; }
  2619. $family = strtolower($family);
  2620. $style=strtoupper($style);
  2621. $style=str_replace('U','',$style);
  2622. if($style=='IB') $style='BI';
  2623. $fontkey = $family.$style;
  2624. // check if the font has been already added
  2625. if(isset($this->fonts[$fontkey])) {
  2626. return;
  2627. }
  2628. /*-- CJK-FONTS --*/
  2629. if (in_array($family,$this->available_CJK_fonts)) {
  2630. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2631. $this->AddCJKFont($family); // don't need to add style
  2632. return;
  2633. }
  2634. /*-- END CJK-FONTS --*/
  2635. if ($this->usingCoreFont) { die("mPDF Error - problem with Font management"); }
  2636. $stylekey = $style;
  2637. if (!$style) { $stylekey = 'R'; }
  2638. if (!isset($this->fontdata[$family][$stylekey]) || !$this->fontdata[$family][$stylekey]) {
  2639. die('mPDF Error - Font is not supported - '.$family.' '.$style);
  2640. }
  2641. $name = '';
  2642. $originalsize = 0;
  2643. $sip = false;
  2644. $smp = false;
  2645. $unAGlyphs = false; // mPDF 5.4.05
  2646. $haskerninfo = false;
  2647. $BMPselected = false;
  2648. @include(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php');
  2649. $ttffile = '';
  2650. if (defined('_MPDF_SYSTEM_TTFONTS')) {
  2651. $ttffile = _MPDF_SYSTEM_TTFONTS.$this->fontdata[$family][$stylekey];
  2652. if (!file_exists($ttffile)) { $ttffile = ''; }
  2653. }
  2654. if (!$ttffile) {
  2655. $ttffile = _MPDF_TTFONTPATH.$this->fontdata[$family][$stylekey];
  2656. if (!file_exists($ttffile)) { die("mPDF Error - cannot find TTF TrueType font file - ".$ttffile); }
  2657. }
  2658. $ttfstat = stat($ttffile);
  2659. if (isset($this->fontdata[$family]['TTCfontID'][$stylekey])) { $TTCfontID = $this->fontdata[$family]['TTCfontID'][$stylekey]; }
  2660. else { $TTCfontID = 0; }
  2661. $BMPonly = false;
  2662. if (in_array($family,$this->BMPonly)) { $BMPonly = true; }
  2663. $regenerate = false;
  2664. if ($BMPonly && !$BMPselected) { $regenerate = true; }
  2665. else if (!$BMPonly && $BMPselected) { $regenerate = true; }
  2666. if ($this->useKerning && !$haskerninfo) { $regenerate = true; }
  2667. // mPDF 5.4.05
  2668. if (isset($this->fontdata[$family]['unAGlyphs']) && $this->fontdata[$family]['unAGlyphs'] && !$unAGlyphs) {
  2669. $regenerate = true;
  2670. $unAGlyphs = true;
  2671. }
  2672. else if ((!isset($this->fontdata[$family]['unAGlyphs']) || !$this->fontdata[$family]['unAGlyphs']) && $unAGlyphs) {
  2673. $regenerate = true;
  2674. $unAGlyphs = false;
  2675. }
  2676. if (!isset($name) || $originalsize != $ttfstat['size'] || $regenerate) {
  2677. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  2678. $ttf = new TTFontFile();
  2679. $ttf->getMetrics($ttffile, $TTCfontID, $this->debugfonts, $BMPonly, $this->useKerning, $unAGlyphs); // mPDF 5.4.05
  2680. $cw = $ttf->charWidths;
  2681. $kerninfo = $ttf->kerninfo;
  2682. $haskerninfo = true;
  2683. $name = preg_replace('/[ ()]/','',$ttf->fullName);
  2684. $sip = $ttf->sipset;
  2685. $smp = $ttf->smpset;
  2686. $desc= array('Ascent'=>round($ttf->ascent),
  2687. 'Descent'=>round($ttf->descent),
  2688. 'CapHeight'=>round($ttf->capHeight),
  2689. 'Flags'=>$ttf->flags,
  2690. 'FontBBox'=>'['.round($ttf->bbox[0])." ".round($ttf->bbox[1])." ".round($ttf->bbox[2])." ".round($ttf->bbox[3]).']',
  2691. 'ItalicAngle'=>$ttf->italicAngle,
  2692. 'StemV'=>round($ttf->stemV),
  2693. 'MissingWidth'=>round($ttf->defaultWidth));
  2694. $panose = '';
  2695. // mPDF 5.5.19
  2696. if (count($ttf->panose)) {
  2697. $panoseArray = array_merge(array($ttf->sFamilyClass, $ttf->sFamilySubClass), $ttf->panose);
  2698. foreach($panoseArray as $value)
  2699. $panose .= ' '.dechex($value);
  2700. }
  2701. $up = round($ttf->underlinePosition);
  2702. $ut = round($ttf->underlineThickness);
  2703. $originalsize = $ttfstat['size']+0;
  2704. $type = 'TTF';
  2705. //Generate metrics .php file
  2706. $s='<?php'."\n";
  2707. $s.='$name=\''.$name."';\n";
  2708. $s.='$type=\''.$type."';\n";
  2709. $s.='$desc='.var_export($desc,true).";\n";
  2710. $s.='$up='.$up.";\n";
  2711. $s.='$ut='.$ut.";\n";
  2712. $s.='$ttffile=\''.$ttffile."';\n";
  2713. $s.='$TTCfontID=\''.$TTCfontID."';\n";
  2714. $s.='$originalsize='.$originalsize.";\n";
  2715. if ($sip) $s.='$sip=true;'."\n";
  2716. else $s.='$sip=false;'."\n";
  2717. if ($smp) $s.='$smp=true;'."\n";
  2718. else $s.='$smp=false;'."\n";
  2719. if ($BMPonly) $s.='$BMPselected=true;'."\n";
  2720. else $s.='$BMPselected=false;'."\n";
  2721. $s.='$fontkey=\''.$fontkey."';\n";
  2722. $s.='$panose=\''.$panose."';\n";
  2723. if ($this->useKerning) {
  2724. $s.='$kerninfo='.var_export($kerninfo,true).";\n";
  2725. $s.='$haskerninfo=true;'."\n";
  2726. }
  2727. else $s.='$haskerninfo=false;'."\n";
  2728. // mPDF 5.4.05
  2729. if ($this->fontdata[$family]['unAGlyphs']) {
  2730. $s.='$unAGlyphs=true;'."\n";
  2731. }
  2732. else $s.='$unAGlyphs=false;'."\n";
  2733. $s.="?>";
  2734. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  2735. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php',"w");
  2736. fwrite($fh,$s,strlen($s));
  2737. fclose($fh);
  2738. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat',"wb");
  2739. fwrite($fh,$cw,strlen($cw));
  2740. fclose($fh);
  2741. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cgm');
  2742. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.z');
  2743. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw127.php');
  2744. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw');
  2745. }
  2746. else if ($this->debugfonts) { $this->Error('Cannot write to the font caching directory - '._MPDF_TTFONTDATAPATH); }
  2747. unset($ttf);
  2748. }
  2749. else {
  2750. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat');
  2751. }
  2752. if (isset($this->fontdata[$family]['indic']) && $this->fontdata[$family]['indic']) { $indic = true; }
  2753. else { $indic = false; }
  2754. if (isset($this->fontdata[$family]['sip-ext']) && $this->fontdata[$family]['sip-ext']) { $sipext = $this->fontdata[$family]['sip-ext']; }
  2755. else { $sipext = ''; }
  2756. $i = count($this->fonts)+$this->extraFontSubsets+1;
  2757. if ($sip || $smp) {
  2758. $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, 'unAGlyphs' => false); // mPDF 5.4.05
  2759. }
  2760. else {
  2761. $ss = array();
  2762. for ($s=32; $s<128; $s++) { $ss[$s] = $s; }
  2763. $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'=>$ss, 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID, 'unAGlyphs' => $unAGlyphs); // mPDF 5.4.05
  2764. }
  2765. if ($this->useKerning && $haskerninfo) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; }
  2766. $this->FontFiles[$fontkey]=array('length1'=>$originalsize, 'type'=>"TTF", 'ttffile'=>$ttffile, 'sip'=>$sip, 'smp'=>$smp);
  2767. unset($cw);
  2768. }
  2769. function SetFont($family,$style='',$size=0, $write=true, $forcewrite=false) {
  2770. $family=strtolower($family);
  2771. if (!$this->onlyCoreFonts) {
  2772. if ($family == 'sans' || $family == 'sans-serif') { $family = $this->sans_fonts[0]; }
  2773. if ($family == 'serif') { $family = $this->serif_fonts[0]; }
  2774. if ($family == 'mono' || $family == 'monospace') { $family = $this->mono_fonts[0]; }
  2775. }
  2776. if (isset($this->fonttrans[$family]) && $this->fonttrans[$family]) { $family = $this->fonttrans[$family]; }
  2777. if($family=='') {
  2778. if ($this->FontFamily) { $family=$this->FontFamily; }
  2779. else if ($this->default_font) { $family=$this->default_font; }
  2780. else { $this->Error("No font or default font set!"); }
  2781. }
  2782. $this->ReqFontStyle = $style; // required or requested style - used later for artificial bold/italic
  2783. if (($family == 'csymbol') || ($family == 'czapfdingbats') || ($family == 'ctimes') || ($family == 'ccourier') || ($family == 'chelvetica')) {
  2784. if ($this->PDFA || $this->PDFX) {
  2785. if ($family == 'csymbol' || $family == 'czapfdingbats') {
  2786. $this->Error("Symbol and Zapfdingbats cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a).");
  2787. }
  2788. if ($family == 'ctimes' || $family == 'ccourier' || $family == 'chelvetica') {
  2789. 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.)"; }
  2790. if ($family == 'chelvetica') { $family = 'sans'; }
  2791. if ($family == 'ctimes') { $family = 'serif'; }
  2792. if ($family == 'ccourier') { $family = 'mono'; }
  2793. }
  2794. $this->usingCoreFont = false;
  2795. }
  2796. else { $this->usingCoreFont = true; }
  2797. if($family=='csymbol' || $family=='czapfdingbats') { $style=''; }
  2798. }
  2799. else { $this->usingCoreFont = false; }
  2800. $this->U=false;
  2801. $this->S=false;
  2802. if ($style) {
  2803. $style=strtoupper($style);
  2804. if(strpos($style,'U')!==false) {
  2805. $this->U=true;
  2806. $style=str_replace('U','',$style);
  2807. }
  2808. if(strpos($style,'S')!==false) {
  2809. $this->S=true;
  2810. // Small Caps
  2811. if (empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); }
  2812. $style=str_replace('S','',$style);
  2813. }
  2814. if ($style=='IB') $style='BI';
  2815. }
  2816. if ($size==0) $size=$this->FontSizePt;
  2817. $fontkey=$family.$style;
  2818. $stylekey = $style;
  2819. if (!$stylekey) { $stylekey = "R"; }
  2820. if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  2821. if(!isset($this->fonts[$fontkey]) || count($this->default_available_fonts) != count($this->available_unifonts) ) { // not already added
  2822. /*-- CJK-FONTS --*/
  2823. // CJK fonts
  2824. if (in_array($fontkey,$this->available_CJK_fonts)) {
  2825. if(!isset($this->fonts[$fontkey])) { // already added
  2826. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2827. $this->AddCJKFont($family); // don't need to add style
  2828. }
  2829. }
  2830. // Test to see if requested font/style is available - or substitute
  2831. else
  2832. /*-- END CJK-FONTS --*/
  2833. if (!in_array($fontkey,$this->available_unifonts)) {
  2834. // If font[nostyle] exists - set it
  2835. if (in_array($family,$this->available_unifonts)) {
  2836. $style = '';
  2837. }
  2838. // Else if only one font available - set it (assumes if only one font available it will not have a style)
  2839. else if (count($this->available_unifonts) == 1) {
  2840. $family = $this->available_unifonts[0];
  2841. $style = '';
  2842. }
  2843. else {
  2844. $found = 0;
  2845. // else substitute font of similar type
  2846. if (in_array($family,$this->sans_fonts)) {
  2847. $i = array_intersect($this->sans_fonts,$this->available_unifonts);
  2848. if (count($i)) {
  2849. $i = array_values($i);
  2850. // with requested style if possible
  2851. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2852. $style = '';
  2853. }
  2854. $family = $i[0];
  2855. $found = 1;
  2856. }
  2857. }
  2858. else if (in_array($family,$this->serif_fonts)) {
  2859. $i = array_intersect($this->serif_fonts,$this->available_unifonts);
  2860. if (count($i)) {
  2861. $i = array_values($i);
  2862. // with requested style if possible
  2863. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2864. $style = '';
  2865. }
  2866. $family = $i[0];
  2867. $found = 1;
  2868. }
  2869. }
  2870. else if (in_array($family,$this->mono_fonts)) {
  2871. $i = array_intersect($this->mono_fonts,$this->available_unifonts);
  2872. if (count($i)) {
  2873. $i = array_values($i);
  2874. // with requested style if possible
  2875. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2876. $style = '';
  2877. }
  2878. $family = $i[0];
  2879. $found = 1;
  2880. }
  2881. }
  2882. if (!$found) {
  2883. // set first available font
  2884. $fs = $this->available_unifonts[0];
  2885. preg_match('/^([a-z_0-9\-]+)([BI]{0,2})$/',$fs,$fas); // Allow "-"
  2886. // with requested style if possible
  2887. $ws = $fas[1].$style;
  2888. if (in_array($ws,$this->available_unifonts)) {
  2889. $family = $fas[1]; // leave $style as is
  2890. }
  2891. else if (in_array($fas[1],$this->available_unifonts)) {
  2892. // or without style
  2893. $family = $fas[1];
  2894. $style = '';
  2895. }
  2896. else {
  2897. // or with the style specified
  2898. $family = $fas[1];
  2899. $style = $fas[2];
  2900. }
  2901. }
  2902. }
  2903. $fontkey = $family.$style;
  2904. }
  2905. }
  2906. // try to add font (if not already added)
  2907. $this->AddFont($family, $style);
  2908. //Test if font is already selected
  2909. if($this->FontFamily == $family && $this->FontFamily == $this->currentfontfamily && $this->FontStyle == $style && $this->FontStyle == $this->currentfontstyle && $this->FontSizePt == $size && $this->FontSizePt == $this->currentfontsize && !$forcewrite) {
  2910. return $family;
  2911. }
  2912. $fontkey = $family.$style;
  2913. //Select it
  2914. $this->FontFamily = $family;
  2915. $this->FontStyle = $style;
  2916. $this->FontSizePt = $size;
  2917. $this->FontSize = $size / _MPDFK;
  2918. $this->CurrentFont = &$this->fonts[$fontkey];
  2919. if ($write) {
  2920. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2921. 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); }
  2922. $this->pageoutput[$this->page]['Font'] = $fontout;
  2923. }
  2924. // Added - currentfont (lowercase) used in HTML2PDF
  2925. $this->currentfontfamily=$family;
  2926. $this->currentfontsize=$size;
  2927. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2928. $this->setMBencoding('UTF-8');
  2929. }
  2930. else { // if using core fonts
  2931. if ($this->PDFA || $this->PDFX) {
  2932. $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.');
  2933. }
  2934. $this->setMBencoding('windows-1252');
  2935. //Test if font is already selected
  2936. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2937. return $family;
  2938. }
  2939. if (!isset($this->CoreFonts[$fontkey])) {
  2940. if (in_array($family,$this->serif_fonts)) { $family = 'ctimes'; }
  2941. else if (in_array($family,$this->mono_fonts)) { $family = 'ccourier'; }
  2942. else { $family = 'chelvetica'; }
  2943. $this->usingCoreFont = true;
  2944. $fontkey = $family.$style;
  2945. }
  2946. if(!isset($this->fonts[$fontkey])) {
  2947. // STANDARD CORE FONTS
  2948. if (isset($this->CoreFonts[$fontkey])) {
  2949. //Load metric file
  2950. $file=$family;
  2951. if($family=='ctimes' || $family=='chelvetica' || $family=='ccourier') { $file.=strtolower($style); }
  2952. $file.='.php';
  2953. include(_MPDF_PATH.'font/'.$file);
  2954. if(!isset($cw)) { $this->Error('Could not include font metric file'); }
  2955. $i=count($this->fonts)+$this->extraFontSubsets+1;
  2956. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw);
  2957. if ($this->useKerning) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; }
  2958. }
  2959. else {
  2960. die('mPDF error - Font not defined');
  2961. }
  2962. }
  2963. //Test if font is already selected
  2964. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2965. return $family;
  2966. }
  2967. //Select it
  2968. $this->FontFamily=$family;
  2969. $this->FontStyle=$style;
  2970. $this->FontSizePt=$size;
  2971. $this->FontSize=$size/_MPDFK;
  2972. $this->CurrentFont=&$this->fonts[$fontkey];
  2973. if ($write) {
  2974. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2975. 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); }
  2976. $this->pageoutput[$this->page]['Font'] = $fontout;
  2977. }
  2978. // Added - currentfont (lowercase) used in HTML2PDF
  2979. $this->currentfontfamily=$family;
  2980. $this->currentfontsize=$size;
  2981. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2982. }
  2983. return $family;
  2984. }
  2985. function SetFontSize($size,$write=true) {
  2986. //Set font size in points
  2987. if($this->FontSizePt==$size) return;
  2988. $this->FontSizePt=$size;
  2989. $this->FontSize=$size/_MPDFK;
  2990. $this->currentfontsize=$size;
  2991. if ($write) {
  2992. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2993. // Edited mPDF 3.0
  2994. 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); }
  2995. $this->pageoutput[$this->page]['Font'] = $fontout;
  2996. }
  2997. }
  2998. function AddLink() {
  2999. //Create a new internal link
  3000. $n=count($this->links)+1;
  3001. $this->links[$n]=array(0,0);
  3002. return $n;
  3003. }
  3004. function SetLink($link,$y=0,$page=-1) {
  3005. //Set destination of internal link
  3006. if($y==-1) $y=$this->y;
  3007. if($page==-1) $page=$this->page;
  3008. $this->links[$link]=array($page,$y);
  3009. }
  3010. function Link($x,$y,$w,$h,$link) {
  3011. $l = array($x*_MPDFK,$this->hPt-$y*_MPDFK,$w*_MPDFK,$h*_MPDFK,$link);
  3012. if ($this->keep_block_together) { // Save to array - don't write yet
  3013. $this->ktLinks[$this->page][]= $l;
  3014. return;
  3015. }
  3016. else if ($this->table_rotate) { // *TABLES*
  3017. $this->tbrot_Links[$this->page][]= $l; // *TABLES*
  3018. return; // *TABLES*
  3019. } // *TABLES*
  3020. else if ($this->kwt) {
  3021. $this->kwt_Links[$this->page][]= $l;
  3022. return;
  3023. }
  3024. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  3025. $this->HTMLheaderPageLinks[]= $l;
  3026. return;
  3027. }
  3028. //Put a link on the page
  3029. $this->PageLinks[$this->page][]= $l;
  3030. // Save cross-reference to Column buffer
  3031. $ref = count($this->PageLinks[$this->page])-1; // *COLUMNS*
  3032. $this->columnLinks[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref; // *COLUMNS*
  3033. }
  3034. function Text($x,$y,$txt) {
  3035. // Output a string
  3036. // Called (internally) by Watermark and _tableWrite [rotated cells]
  3037. // Expects input to be mb_encoded if necessary and RTL reversed
  3038. // ARTIFICIAL BOLD AND ITALIC
  3039. $s = 'q ';
  3040. if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false) {
  3041. $s .= '2 Tr 1 J 1 j ';
  3042. $s .= sprintf('%.3F w ',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight);
  3043. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3044. if($this->FillColor!=$tc) { $s .= $tc.' '; } // stroke (outline) = same colour as text(fill)
  3045. }
  3046. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) {
  3047. $aix = '1 0 0.261799 1 %.3F %.3F Tm';
  3048. }
  3049. else { $aix = '%.3F %.3F Td'; }
  3050. if($this->ColorFlag) $s.=$this->TextColor.' ';
  3051. $this->CurrentFont['used']= true;
  3052. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) {
  3053. $txt2 = str_replace(chr(194).chr(160),chr(32),$txt);
  3054. $txt2 = $this->UTF8toSubset($txt2);
  3055. $s.=sprintf('BT '.$aix.' %s Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$txt2);
  3056. }
  3057. else if (!$this->usingCoreFont) {
  3058. $txt2 = str_replace(chr(194).chr(160),chr(32),$txt);
  3059. $this->UTF8StringToArray($txt2); // this is just to add chars to subset list
  3060. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); }
  3061. else {
  3062. //Convert string to UTF-16BE without BOM
  3063. $txt2= $this->UTF8ToUTF16BE($txt2, false);
  3064. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2));
  3065. }
  3066. }
  3067. else {
  3068. $txt2 = str_replace(chr(160),chr(32),$txt);
  3069. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); }
  3070. else {
  3071. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2));
  3072. }
  3073. }
  3074. if($this->U && $txt!='') {
  3075. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3076. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  3077. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  3078. else { $up = -100; }
  3079. $adjusty = (-$up/1000* $this->FontSize);
  3080. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3081. else { $ut = 60/1000* $this->FontSize; }
  3082. $olw = $this->LineWidth;
  3083. $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK));
  3084. $s.=' '.$this->_dounderline($x,$y + $adjusty,$txt);
  3085. $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK));
  3086. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  3087. }
  3088. // STRIKETHROUGH
  3089. if($this->strike && $txt!='') {
  3090. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3091. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  3092. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  3093. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  3094. else { $ch = 700; }
  3095. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  3096. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3097. else { $ut = 60/1000* $this->FontSize; }
  3098. $olw = $this->LineWidth;
  3099. $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK));
  3100. $s.=' '.$this->_dounderline($x,$y+$adjusty,$txt);
  3101. $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK));
  3102. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  3103. }
  3104. $s .= 'Q';
  3105. $this->_out($s);
  3106. }
  3107. /*-- DIRECTW --*/
  3108. function WriteText($x,$y,$txt) {
  3109. // Output a string using Text() but does encoding and text reversing of RTL
  3110. $txt = $this->purify_utf8_text($txt);
  3111. if ($this->text_input_as_HTML) {
  3112. $txt = $this->all_entities_to_utf8($txt);
  3113. }
  3114. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  3115. // DIRECTIONALITY
  3116. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  3117. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  3118. // Font-specific ligature substitution for Indic fonts
  3119. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  3120. $this->Text($x,$y,$txt);
  3121. }
  3122. function WriteCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0) {
  3123. //Output a cell using Cell() but does encoding and text reversing of RTL
  3124. $txt = $this->purify_utf8_text($txt);
  3125. if ($this->text_input_as_HTML) {
  3126. $txt = $this->all_entities_to_utf8($txt);
  3127. }
  3128. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  3129. // DIRECTIONALITY
  3130. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  3131. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  3132. // Font-specific ligature substitution for Indic fonts
  3133. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  3134. $this->Cell($w,$h,$txt,$border,$ln,$align,$fill,$link, $currentx);
  3135. }
  3136. /*-- END DIRECTW --*/
  3137. function ResetSpacing() {
  3138. if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  3139. $this->ws=0;
  3140. if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  3141. $this->charspacing=0;
  3142. }
  3143. function SetSpacing($cs,$ws) {
  3144. if (intval($cs*1000)==0) { $cs = 0; }
  3145. if ($cs) { $this->_out(sprintf('BT %.3F Tc ET',$cs)); }
  3146. else if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  3147. $this->charspacing=$cs;
  3148. if (intval($ws*1000)==0) { $ws = 0; }
  3149. if ($ws) { $this->_out(sprintf('BT %.3F Tw ET',$ws)); }
  3150. else if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  3151. $this->ws=$ws;
  3152. }
  3153. // WORD SPACING
  3154. function GetJspacing($nc,$ns,$w,$inclCursive) {
  3155. $ws = 0;
  3156. $charspacing = 0;
  3157. $ww = $this->jSWord;
  3158. $ncx = $nc-1;
  3159. if ($nc == 0) { return array(0,0); }
  3160. else if ($nc==1) { $charspacing = $w; }
  3161. // Only word spacing allowed / possible
  3162. else if ($this->fixedlSpacing !== false || $inclCursive) {
  3163. if ($ns) { $ws = $w / $ns; }
  3164. }
  3165. else if (!$ns) {
  3166. $charspacing = $w / ($ncx );
  3167. if (($this->jSmaxChar > 0) && ($charspacing > $this->jSmaxChar)) {
  3168. $charspacing = $this->jSmaxChar;
  3169. }
  3170. }
  3171. else if ($ns == ($ncx )) {
  3172. $charspacing = $w / $ns;
  3173. }
  3174. else {
  3175. if ($this->usingCoreFont) {
  3176. $cs = ($w * (1 - $this->jSWord)) / ($ncx );
  3177. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  3178. $cs = $this->jSmaxChar;
  3179. $ww = 1 - (($cs * ($ncx ))/$w);
  3180. }
  3181. $charspacing = $cs;
  3182. $ws = ($w * ($ww) ) / $ns;
  3183. }
  3184. else {
  3185. $cs = ($w * (1 - $this->jSWord)) / ($ncx -$ns);
  3186. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  3187. $cs = $this->jSmaxChar;
  3188. $ww = 1 - (($cs * ($ncx -$ns))/$w);
  3189. }
  3190. $charspacing = $cs;
  3191. $ws = (($w * ($ww) ) / $ns) - $charspacing;
  3192. }
  3193. }
  3194. return array($charspacing,$ws);
  3195. }
  3196. 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, $exactWidth=false) {
  3197. //Output a cell
  3198. // Expects input to be mb_encoded if necessary and RTL reversed
  3199. // NON_BREAKING SPACE
  3200. if ($this->usingCoreFont) {
  3201. $txt = str_replace(chr(160),chr(32),$txt);
  3202. }
  3203. else {
  3204. $txt = str_replace(chr(194).chr(160),chr(32),$txt);
  3205. }
  3206. $oldcolumn = $this->CurrCol;
  3207. // Automatic page break
  3208. // Allows PAGE-BREAK-AFTER = avoid to work
  3209. if (!$this->tableLevel && (($this->y+$this->divheight>$this->PageBreakTrigger) || ($this->y+$h>$this->PageBreakTrigger) ||
  3210. ($this->y+($h*2)>$this->PageBreakTrigger && $this->blk[$this->blklvl]['page_break_after_avoid'])) and !$this->InFooter and $this->AcceptPageBreak()) {
  3211. $x=$this->x;//Current X position
  3212. // WORD SPACING
  3213. $ws=$this->ws;//Word Spacing
  3214. $charspacing=$this->charspacing;//Character Spacing
  3215. $this->ResetSpacing();
  3216. $this->AddPage($this->CurOrientation);
  3217. // Added to correct for OddEven Margins
  3218. $x += $this->MarginCorrection;
  3219. if ($currentx) {
  3220. $currentx += $this->MarginCorrection;
  3221. }
  3222. $this->x=$x;
  3223. // WORD SPACING
  3224. $this->SetSpacing($charspacing,$ws);
  3225. }
  3226. // Test: to put line through centre of cell: $this->Line($this->x,$this->y+($h/2),$this->x+50,$this->y+($h/2));
  3227. /*-- COLUMNS --*/
  3228. // COLS
  3229. // COLUMN CHANGE
  3230. if ($this->CurrCol != $oldcolumn) {
  3231. if ($currentx) {
  3232. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3233. }
  3234. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3235. }
  3236. // COLUMNS Update/overwrite the lowest bottom of printing y value for a column
  3237. if ($this->ColActive) {
  3238. if ($h) { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h; }
  3239. else { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$this->divheight; }
  3240. }
  3241. /*-- END COLUMNS --*/
  3242. // KEEP BLOCK TOGETHER Update/overwrite the lowest bottom of printing y value on first page
  3243. if ($this->keep_block_together) {
  3244. if ($h) { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h; }
  3245. // else { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$this->divheight; }
  3246. }
  3247. if($w==0) $w = $this->w-$this->rMargin-$this->x;
  3248. $s='';
  3249. if($fill==1 && $this->FillColor) {
  3250. 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.' '; }
  3251. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  3252. }
  3253. $boxtop = $this->y;
  3254. $boxheight = $h;
  3255. $boxbottom = $this->y+$h;
  3256. if($txt!='') {
  3257. // FONT SIZE - this determines the baseline caculation
  3258. if ($this->linemaxfontsize && !$this->processingHeader) { $bfs = $this->linemaxfontsize; }
  3259. else { $bfs = $this->FontSize; }
  3260. //Calculate baseline Superscript and Subscript Y coordinate adjustment
  3261. $bfx = $this->baselineC;
  3262. $baseline = $bfx*$bfs;
  3263. if($this->SUP) { $baseline += ($bfx-1.05)*$this->FontSize; }
  3264. else if($this->SUB) { $baseline += ($bfx + 0.04)*$this->FontSize; }
  3265. else if($this->bullet) { $baseline += ($bfx-0.7)*$this->FontSize; }
  3266. // Vertical align (for Images)
  3267. if ($abovefont || $belowfont) { // from flowing block - valign always M
  3268. $va = $abovefont + (0.5*$bfs);
  3269. }
  3270. else if ($this->lineheight_correction) {
  3271. if ($valign == 'T') { $va = (0.5 * $bfs * $this->lineheight_correction); }
  3272. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->lineheight_correction); }
  3273. else { $va = 0.5*$h; } // Middle
  3274. }
  3275. else {
  3276. if ($valign == 'T') { $va = (0.5 * $bfs * $this->default_lineheight_correction); }
  3277. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->default_lineheight_correction); }
  3278. else { $va = 0.5*$h; } // Middle
  3279. }
  3280. // ONLY SET THESE IF WANT TO CONFINE BORDER +/- FILL TO FIT FONTSIZE - NOT FULL CELL AS IS ORIGINAL FUNCTION
  3281. // spanfill or spanborder are set in FlowingBlock functions
  3282. if ($spanfill || !empty($this->spanborddet) || $link!='') {
  3283. $exth = 0.2; // Add to fontsize to increase height of background / link / border
  3284. $boxtop = $this->y+$baseline+$va-($this->FontSize*(1+$exth/2)*(0.5+$bfx));
  3285. $boxheight = $this->FontSize * (1+$exth);
  3286. $boxbottom = $boxtop + $boxheight;
  3287. }
  3288. }
  3289. $bbw = $tbw = $lbw = $rbw = 0; // Border widths
  3290. if (!empty($this->spanborddet)) {
  3291. if (!isset($this->spanborddet['B'])) { $this->spanborddet['B'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3292. if (!isset($this->spanborddet['T'])) { $this->spanborddet['T'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3293. if (!isset($this->spanborddet['L'])) { $this->spanborddet['L'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3294. if (!isset($this->spanborddet['R'])) { $this->spanborddet['R'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3295. $bbw = $this->spanborddet['B']['w'];
  3296. $tbw = $this->spanborddet['T']['w'];
  3297. $lbw = $this->spanborddet['L']['w'];
  3298. $rbw = $this->spanborddet['R']['w'];
  3299. }
  3300. if($fill==1 || $border==1 || !empty($this->spanborddet)) {
  3301. if (!empty($this->spanborddet)) {
  3302. if ($fill==1) {
  3303. $s.=sprintf('%.3F %.3F %.3F %.3F re f ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($w+$lbw+$rbw)*_MPDFK,(-$boxheight-$tbw-$bbw)*_MPDFK);
  3304. }
  3305. $s.= ' q ';
  3306. $dashon = 3;
  3307. $dashoff = 3.5;
  3308. $dot = 2.5;
  3309. if($tbw) {
  3310. $short = 0;
  3311. if ($this->spanborddet['T']['style'] == 'dashed') {
  3312. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$tbw*$dashon*_MPDFK,$tbw*$dashoff*_MPDFK);
  3313. }
  3314. else if ($this->spanborddet['T']['style'] == 'dotted') {
  3315. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$tbw*$dot*_MPDFK,-$tbw/2*_MPDFK);
  3316. $short = $tbw/2;
  3317. }
  3318. else {
  3319. $s.=' 0 j 0 J [] 0 d ';
  3320. }
  3321. $c = $this->SetDColor($this->spanborddet['T']['c'],true);
  3322. if ($this->spanborddet['T']['style'] == 'double') {
  3323. $s.=sprintf(' %s %.3F w ',$c,$tbw/3*_MPDFK);
  3324. $xadj = $xadj2 = 0;
  3325. if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; }
  3326. if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; }
  3327. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw*5/6)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxtop+$tbw*5/6)*_MPDFK);
  3328. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw+$xadj)*_MPDFK,($this->h-$boxtop+$tbw/6)*_MPDFK,($this->x+$w+$rbw-$short-$xadj2)*_MPDFK,($this->h-$boxtop+$tbw/6)*_MPDFK);
  3329. }
  3330. else {
  3331. $s.=sprintf(' %s %.3F w ',$c,$tbw*_MPDFK);
  3332. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw/2)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxtop+$tbw/2)*_MPDFK);
  3333. }
  3334. }
  3335. if($bbw) {
  3336. $short = 0;
  3337. if ($this->spanborddet['B']['style'] == 'dashed') {
  3338. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$bbw*$dashon*_MPDFK,$bbw*$dashoff*_MPDFK);
  3339. }
  3340. else if ($this->spanborddet['B']['style'] == 'dotted') {
  3341. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$bbw*$dot*_MPDFK,-$bbw/2*_MPDFK);
  3342. $short = $bbw/2;
  3343. }
  3344. else {
  3345. $s.=' 0 j 0 J [] 0 d ';
  3346. }
  3347. $c = $this->SetDColor($this->spanborddet['B']['c'],true);
  3348. if ($this->spanborddet['B']['style'] == 'double') {
  3349. $s.=sprintf(' %s %.3F w ',$c,$bbw/3*_MPDFK);
  3350. $xadj = $xadj2 = 0;
  3351. if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; }
  3352. if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; }
  3353. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw+$xadj)*_MPDFK,($this->h-$boxbottom-$bbw/6)*_MPDFK,($this->x+$w+$rbw-$short-$xadj2)*_MPDFK,($this->h-$boxbottom-$bbw/6)*_MPDFK);
  3354. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxbottom-$bbw*5/6)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxbottom-$bbw*5/6)*_MPDFK);
  3355. }
  3356. else {
  3357. $s.=sprintf(' %s %.3F w ',$c,$bbw*_MPDFK);
  3358. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxbottom-$bbw/2)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxbottom-$bbw/2)*_MPDFK);
  3359. }
  3360. }
  3361. if($lbw) {
  3362. $short = 0;
  3363. if ($this->spanborddet['L']['style'] == 'dashed') {
  3364. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$lbw*$dashon*_MPDFK,$lbw*$dashoff*_MPDFK);
  3365. }
  3366. else if ($this->spanborddet['L']['style'] == 'dotted') {
  3367. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$lbw*$dot*_MPDFK,-$lbw/2*_MPDFK);
  3368. $short = $lbw/2;
  3369. }
  3370. else {
  3371. $s.=' 0 j 0 J [] 0 d ';
  3372. }
  3373. $c = $this->SetDColor($this->spanborddet['L']['c'],true);
  3374. if ($this->spanborddet['L']['style'] == 'double') {
  3375. $s.=sprintf(' %s %.3F w ',$c,$lbw/3*_MPDFK);
  3376. $yadj = $yadj2 = 0;
  3377. if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; }
  3378. if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; }
  3379. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw/6)*_MPDFK,($this->h-$boxtop+$tbw-$yadj)*_MPDFK,($this->x-$lbw/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short+$yadj2)*_MPDFK);
  3380. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw*5/6)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x-$lbw*5/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3381. }
  3382. else {
  3383. $s.=sprintf(' %s %.3F w ',$c,$lbw*_MPDFK);
  3384. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw/2)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x-$lbw/2)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3385. }
  3386. }
  3387. if($rbw) {
  3388. $short = 0;
  3389. if ($this->spanborddet['R']['style'] == 'dashed') {
  3390. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$rbw*$dashon*_MPDFK,$rbw*$dashoff*_MPDFK);
  3391. }
  3392. else if ($this->spanborddet['R']['style'] == 'dotted') {
  3393. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$rbw*$dot*_MPDFK,-$rbw/2*_MPDFK);
  3394. $short = $rbw/2;
  3395. }
  3396. else {
  3397. $s.=' 0 j 0 J [] 0 d ';
  3398. }
  3399. $c = $this->SetDColor($this->spanborddet['R']['c'],true);
  3400. if ($this->spanborddet['R']['style'] == 'double') {
  3401. $s.=sprintf(' %s %.3F w ',$c,$rbw/3*_MPDFK);
  3402. $yadj = $yadj2 = 0;
  3403. if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; }
  3404. if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; }
  3405. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw/6)*_MPDFK,($this->h-$boxtop+$tbw-$yadj)*_MPDFK,($this->x+$w+$rbw/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short+$yadj2)*_MPDFK);
  3406. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw*5/6)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x+$w+$rbw*5/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3407. }
  3408. else {
  3409. $s.=sprintf(' %s %.3F w ',$c,$rbw*_MPDFK);
  3410. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw/2)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x+$w+$rbw/2)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK);
  3411. }
  3412. }
  3413. $s.= ' Q ';
  3414. }
  3415. else {
  3416. if ($fill==1) $op=($border==1) ? 'B' : 'f';
  3417. else $op='S';
  3418. $s.=sprintf('%.3F %.3F %.3F %.3F re %s ',$this->x*_MPDFK,($this->h-$boxtop)*_MPDFK,$w*_MPDFK,-$boxheight*_MPDFK,$op);
  3419. }
  3420. }
  3421. if(is_string($border)) {
  3422. $x=$this->x;
  3423. $y=$this->y;
  3424. if(is_int(strpos($border,'L')))
  3425. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,$x*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3426. if(is_int(strpos($border,'T')))
  3427. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK);
  3428. if(is_int(strpos($border,'R')))
  3429. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3430. if(is_int(strpos($border,'B')))
  3431. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-($boxbottom))*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3432. }
  3433. if($txt!='') {
  3434. if ($exactWidth)
  3435. $stringWidth = $w;
  3436. else
  3437. $stringWidth = $this->GetStringWidth($txt) + ( $this->charspacing * mb_strlen( $txt, $this->mb_enc ) / _MPDFK )
  3438. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ) / _MPDFK );
  3439. // Set x OFFSET FOR PRINTING
  3440. if($align=='R') {
  3441. $dx=$w-$this->cMarginR - $stringWidth - $lcpaddingR;
  3442. }
  3443. elseif($align=='C') {
  3444. $dx=(($w - $stringWidth )/2);
  3445. }
  3446. elseif($align=='L' or $align=='J') $dx=$this->cMarginL + $lcpaddingL;
  3447. else $dx = 0;
  3448. if($this->ColorFlag) $s .='q '.$this->TextColor.' ';
  3449. // OUTLINE
  3450. if($this->textparam['outline-s'] && !$this->S) { // mPDF 5.6.07
  3451. $s .=' '.sprintf('%.3F w',$this->LineWidth*_MPDFK).' ';
  3452. $s .=" $this->DrawColor ";
  3453. $s .=" 2 Tr ";
  3454. }
  3455. 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
  3456. $s .= ' 2 Tr 1 J 1 j ';
  3457. $s .= ' '.sprintf('%.3F w',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight).' ';
  3458. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3459. if($this->FillColor!=$tc) { $s .= ' '.$tc.' '; } // stroke (outline) = same colour as text(fill)
  3460. }
  3461. else { $s .=" 0 Tr "; } // mPDF 5.6.07
  3462. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) { // Artificial italic
  3463. $aix = '1 0 0.261799 1 %.3F %.3F Tm ';
  3464. }
  3465. else { $aix = '%.3F %.3F Td '; }
  3466. // THE TEXT
  3467. $sub = '';
  3468. $this->CurrentFont['used']= true;
  3469. // WORD SPACING
  3470. // IF multibyte - Tw has no effect - need to use alternative method - do word spacing using an adjustment before each space
  3471. if ($this->ws && !$this->usingCoreFont && !$this->CurrentFont['sip'] && !$this->CurrentFont['smp'] && !$this->S) {
  3472. $sub .= ' BT 0 Tw ET ';
  3473. if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt, 'MBTw', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); }
  3474. else {
  3475. $space = " ";
  3476. //Convert string to UTF-16BE without BOM
  3477. $space= $this->UTF8ToUTF16BE($space , false);
  3478. $space=$this->_escape($space );
  3479. $sub .=sprintf('BT '.$aix,($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK);
  3480. $t = explode(' ',$txt);
  3481. $sub .=sprintf(' %.3F Tc [',$this->charspacing);
  3482. $numt = count($t);
  3483. for($i=0;$i<$numt;$i++) {
  3484. $tx = $t[$i];
  3485. //Convert string to UTF-16BE without BOM
  3486. $tx = $this->UTF8ToUTF16BE($tx , false);
  3487. $tx = $this->_escape($tx);
  3488. $sub .=sprintf('(%s) ',$tx);
  3489. if (($i+1)<$numt) {
  3490. $adj = -($this->ws)*1000/$this->FontSizePt;
  3491. $sub .=sprintf('%d(%s) ',$adj,$space);
  3492. }
  3493. }
  3494. $sub .='] TJ ';
  3495. $sub .=' ET';
  3496. }
  3497. }
  3498. else {
  3499. $txt2= $txt;
  3500. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) {
  3501. if ($this->S) { $sub .= $this->_smallCaps($txt2, 'SIPSMP', $aix, $dx, _MPDFK, $baseline, $va); }
  3502. else {
  3503. $txt2 = $this->UTF8toSubset($txt2);
  3504. $sub .=sprintf('BT '.$aix.' %s Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2);
  3505. }
  3506. }
  3507. else {
  3508. if ($this->S) { $sub .= $this->_smallCaps($txt2, '', $aix, $dx, _MPDFK, $baseline, $va); }
  3509. else if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt2, '', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); }
  3510. else {
  3511. if (!$this->usingCoreFont) {
  3512. $txt2 = $this->UTF8ToUTF16BE($txt2, false);
  3513. }
  3514. $txt2=$this->_escape($txt2);
  3515. $sub .=sprintf('BT '.$aix.' (%s) Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2);
  3516. }
  3517. }
  3518. }
  3519. // UNDERLINE
  3520. if($this->U) {
  3521. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3522. if($this->FillColor!=$c) { $sub .= ' '.$c.' '; }
  3523. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  3524. else { $up = -100; }
  3525. $adjusty = (-$up/1000* $this->FontSize);
  3526. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3527. else { $ut = 60/1000* $this->FontSize; }
  3528. $olw = $this->LineWidth;
  3529. $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK));
  3530. $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3531. $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK));
  3532. if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; }
  3533. }
  3534. // STRIKETHROUGH
  3535. if($this->strike) {
  3536. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3537. if($this->FillColor!=$c) { $sub .= ' '.$c.' '; }
  3538. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  3539. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  3540. else { $ch = 700; }
  3541. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  3542. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3543. else { $ut = 60/1000* $this->FontSize; }
  3544. $olw = $this->LineWidth;
  3545. $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK));
  3546. $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3547. $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK));
  3548. if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; }
  3549. }
  3550. // TEXT SHADOW
  3551. if ($this->textshadow) { // First to process is last in CSS comma separated shadows
  3552. foreach($this->textshadow AS $ts) {
  3553. $s .= ' q ';
  3554. $s .= $this->SetTColor($ts['col'], true)."\n";
  3555. if ($ts['col']{0}==5 && ord($ts['col']{4})<100) { // RGBa
  3556. $s .= $this->SetAlpha(ord($ts['col']{4})/100, 'Normal', true, 'F')."\n";
  3557. }
  3558. else if ($ts['col']{0}==6 && ord($ts['col']{5})<100) { // CMYKa
  3559. $s .= $this->SetAlpha(ord($ts['col']{5})/100, 'Normal', true, 'F')."\n";
  3560. }
  3561. else if ($ts['col']{0}==1 && $ts['col']{2}==1 && ord($ts['col']{3})<100) { // Gray
  3562. $s .= $this->SetAlpha(ord($ts['col']{3})/100, 'Normal', true, 'F')."\n";
  3563. }
  3564. $s .= sprintf(' 1 0 0 1 %.4F %.4F cm', $ts['x']*_MPDFK, -$ts['y']*_MPDFK)."\n";
  3565. $s .= $sub;
  3566. $s .= ' Q ';
  3567. }
  3568. }
  3569. $s .= $sub;
  3570. // COLOR
  3571. if($this->ColorFlag) $s .=' Q';
  3572. // LINK
  3573. if($link!='') {
  3574. $this->Link($this->x,$boxtop,$w,$boxheight,$link);
  3575. }
  3576. }
  3577. if($s) $this->_out($s);
  3578. // WORD SPACING
  3579. if ($this->ws && !$this->usingCoreFont) {
  3580. $this->_out(sprintf('BT %.3F Tc ET',$this->charspacing));
  3581. }
  3582. $this->lasth=$h;
  3583. if( strpos($txt,"\n") !== false) $ln=1; // cell recognizes \n from <BR> tag
  3584. if($ln>0)
  3585. {
  3586. //Go to next line
  3587. $this->y += $h;
  3588. if($ln==1) {
  3589. //Move to next line
  3590. if ($currentx != 0) { $this->x=$currentx; }
  3591. else { $this->x=$this->lMargin; }
  3592. }
  3593. }
  3594. else $this->x+=$w;
  3595. }
  3596. function _kern($txt, $mode, $aix, $x, $y) {
  3597. if ($mode == 'MBTw') { // Multibyte requiring word spacing
  3598. $space = ' ';
  3599. //Convert string to UTF-16BE without BOM
  3600. $space= $this->UTF8ToUTF16BE($space , false);
  3601. $space=$this->_escape($space );
  3602. $s = sprintf(' BT '.$aix,$x*_MPDFK,($this->h-$y)*_MPDFK);
  3603. $t = explode(' ',$txt);
  3604. for($i=0;$i<count($t);$i++) {
  3605. $tx = $t[$i];
  3606. $tj = '(';
  3607. $unicode = $this->UTF8StringToArray($tx);
  3608. for($ti=0;$ti<count($unicode);$ti++) {
  3609. if ($ti > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]])) {
  3610. $kern = -$this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]];
  3611. $tj .= sprintf(')%d(',$kern);
  3612. }
  3613. $tc = code2utf($unicode[$ti]);
  3614. $tc = $this->UTF8ToUTF16BE($tc, false);
  3615. $tj .= $this->_escape($tc);
  3616. }
  3617. $tj .= ')';
  3618. $s.=sprintf(' %.3F Tc [%s] TJ',$this->charspacing,$tj);
  3619. if (($i+1)<count($t)) {
  3620. $s.=sprintf(' %.3F Tc (%s) Tj',$this->ws+$this->charspacing,$space);
  3621. }
  3622. }
  3623. $s.=' ET ';
  3624. }
  3625. else if (!$this->usingCoreFont) {
  3626. $s = '';
  3627. $tj = '(';
  3628. $unicode = $this->UTF8StringToArray($txt);
  3629. for($i=0;$i<count($unicode);$i++) {
  3630. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]])) {
  3631. $kern = -$this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]];
  3632. $tj .= sprintf(')%d(',$kern);
  3633. }
  3634. $tx = code2utf($unicode[$i]);
  3635. $tx = $this->UTF8ToUTF16BE($tx, false);
  3636. $tj .= $this->_escape($tx);
  3637. }
  3638. $tj .= ')';
  3639. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj);
  3640. }
  3641. else { // CORE Font
  3642. $s = '';
  3643. $tj = '(';
  3644. $l = strlen($txt);
  3645. for($i=0;$i<$l;$i++) {
  3646. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]])) {
  3647. $kern = -$this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]];
  3648. $tj .= sprintf(')%d(',$kern);
  3649. }
  3650. $tj .= $this->_escape($txt[$i]);
  3651. }
  3652. $tj .= ')';
  3653. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj);
  3654. }
  3655. return $s;
  3656. }
  3657. function _smallCaps($txt, $mode, $aix, $dx, $k, $baseline, $va) {
  3658. $upp = false;
  3659. $str = array();
  3660. $bits = array();
  3661. if (!$this->usingCoreFont) {
  3662. $unicode = $this->UTF8StringToArray($txt);
  3663. foreach($unicode as $char) {
  3664. if ($this->ws && $char == 32) { // space
  3665. if (count($str)) { $bits[] = array($upp, $str, false); }
  3666. $bits[] = array(false, array(32), true);
  3667. $str = array();
  3668. $upp = false;
  3669. }
  3670. else if (isset($this->upperCase[$char])) {
  3671. if (!$upp) {
  3672. if (count($str)) { $bits[] = array($upp, $str, false); }
  3673. $str = array();
  3674. }
  3675. $str[] = $this->upperCase[$char];
  3676. if ((!isset($this->CurrentFont['sip']) || !$this->CurrentFont['sip']) && (!isset($this->CurrentFont['smp']) || !$this->CurrentFont['smp'])) {
  3677. $this->CurrentFont['subset'][$this->upperCase[$char]] = $this->upperCase[$char];
  3678. }
  3679. $upp = true;
  3680. }
  3681. else {
  3682. if ($upp) {
  3683. if (count($str)) { $bits[] = array($upp, $str, false); }
  3684. $str = array();
  3685. }
  3686. $str[] = $char;
  3687. $upp = false;
  3688. }
  3689. }
  3690. }
  3691. else {
  3692. for($i=0;$i<strlen($txt);$i++) {
  3693. if (isset($this->upperCase[ord($txt[$i])]) && $this->upperCase[ord($txt[$i])] < 256) {
  3694. if (!$upp) {
  3695. if (count($str)) { $bits[] = array($upp, $str, false); }
  3696. $str = array();
  3697. }
  3698. $str[] = $this->upperCase[ord($txt[$i])];
  3699. $upp = true;
  3700. }
  3701. else {
  3702. if ($upp) {
  3703. if (count($str)) { $bits[] = array($upp, $str, false); }
  3704. $str = array();
  3705. }
  3706. $str[] = ord($txt[$i]);
  3707. $upp = false;
  3708. }
  3709. }
  3710. }
  3711. if (count($str)) { $bits[] = array($upp, $str, false); }
  3712. $fid = $this->CurrentFont['i'];
  3713. $s=sprintf(' BT '.$aix,($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k);
  3714. foreach($bits AS $b) {
  3715. if ($b[0]) { $upp = true; }
  3716. else { $upp = false; }
  3717. $size = count ($b[1]);
  3718. $txt = '';
  3719. for ($i = 0; $i < $size; $i++) {
  3720. $txt .= code2utf($b[1][$i]);
  3721. }
  3722. if ($this->usingCoreFont) {
  3723. $txt = utf8_decode($txt);
  3724. }
  3725. if ($mode == 'SIPSMP') {
  3726. $txt = $this->UTF8toSubset($txt);
  3727. }
  3728. else {
  3729. if (!$this->usingCoreFont) {
  3730. $txt = $this->UTF8ToUTF16BE($txt, false);
  3731. }
  3732. $txt=$this->_escape($txt);
  3733. $txt = '('.$txt.')';
  3734. }
  3735. if ($b[2]) { // space
  3736. $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100);
  3737. $s.=sprintf(' %.3F Tc', ($this->charspacing+$this->ws));
  3738. $s.=sprintf(' %s Tj', $txt);
  3739. }
  3740. else if ($upp) {
  3741. $s.=sprintf(' /F%d %.3F Tf', $fid, $this->FontSizePt*$this->smCapsScale);
  3742. $s.=sprintf(' %d Tz', $this->smCapsStretch);
  3743. $s.=sprintf(' %.3F Tc', ($this->charspacing*100/$this->smCapsStretch));
  3744. $s.=sprintf(' %s Tj', $txt);
  3745. }
  3746. else {
  3747. $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100);
  3748. $s.=sprintf(' %.3F Tc', ($this->charspacing));
  3749. $s.=sprintf(' %s Tj', $txt);
  3750. }
  3751. }
  3752. $s.=' ET ';
  3753. return $s;
  3754. }
  3755. function MultiCell($w,$h,$txt,$border=0,$align='',$fill=0,$link='',$directionality='ltr',$encoded=false)
  3756. {
  3757. // Parameter (pre-)encoded - When called internally from ToC or textarea: mb_encoding already done - but not reverse RTL/Indic
  3758. if (!$encoded) {
  3759. $txt = $this->purify_utf8_text($txt);
  3760. if ($this->text_input_as_HTML) {
  3761. $txt = $this->all_entities_to_utf8($txt);
  3762. }
  3763. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  3764. // Font-specific ligature substitution for Indic fonts
  3765. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { // *INDIC*
  3766. $this->ConvertIndic($tmp); // *INDIC*
  3767. } // *INDIC*
  3768. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  3769. }
  3770. if (!$align) { $align = $this->defaultAlign; }
  3771. //Output text with automatic or explicit line breaks
  3772. $cw=&$this->CurrentFont['cw'];
  3773. if($w==0) $w=$this->w-$this->rMargin-$this->x;
  3774. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3775. if ($this->usingCoreFont) {
  3776. $s=str_replace("\r",'',$txt);
  3777. $nb=strlen($s);
  3778. while($nb>0 and $s[$nb-1]=="\n") $nb--;
  3779. }
  3780. else {
  3781. $s=str_replace("\r",'',$txt);
  3782. $nb=mb_strlen($s, $this->mb_enc );
  3783. while($nb>0 and mb_substr($s,$nb-1,1,$this->mb_enc )=="\n") $nb--;
  3784. }
  3785. $b=0;
  3786. if($border) {
  3787. if($border==1) {
  3788. $border='LTRB';
  3789. $b='LRT';
  3790. $b2='LR';
  3791. }
  3792. else {
  3793. $b2='';
  3794. if(is_int(strpos($border,'L'))) $b2.='L';
  3795. if(is_int(strpos($border,'R'))) $b2.='R';
  3796. $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
  3797. }
  3798. }
  3799. $sep=-1;
  3800. $i=0;
  3801. $j=0;
  3802. $l=0;
  3803. $ns=0;
  3804. $nl=1;
  3805. if (!$this->usingCoreFont) {
  3806. $checkCursive=false;
  3807. if ($this->biDirectional) { $checkCursive=true; }
  3808. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  3809. while($i<$nb) {
  3810. //Get next character
  3811. $c = mb_substr($s,$i,1,$this->mb_enc );
  3812. if($c == "\n") {
  3813. //Explicit line break
  3814. // WORD SPACING
  3815. $this->ResetSpacing();
  3816. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3817. // DIRECTIONALITY
  3818. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3819. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3820. $i++;
  3821. $sep=-1;
  3822. $j=$i;
  3823. $l=0;
  3824. $ns=0;
  3825. $nl++;
  3826. if($border and $nl==2) $b=$b2;
  3827. continue;
  3828. }
  3829. if($c == " ") {
  3830. $sep=$i;
  3831. $ls=$l;
  3832. $ns++;
  3833. }
  3834. $l += $this->GetCharWidthNonCore($c);
  3835. if($l>$wmax) {
  3836. //Automatic line break
  3837. if($sep==-1) { // Only one word
  3838. if($i==$j) $i++;
  3839. // WORD SPACING
  3840. $this->ResetSpacing();
  3841. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3842. // DIRECTIONALITY
  3843. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3844. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3845. }
  3846. else {
  3847. $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc));
  3848. if($align=='J') {
  3849. //////////////////////////////////////////
  3850. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3851. // WORD SPACING UNICODE
  3852. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3853. $tmp = str_replace(chr(194).chr(160),chr(32),$tmp );
  3854. $len_ligne = $this->GetStringWidth($tmp );
  3855. $nb_carac = mb_strlen( $tmp , $this->mb_enc ) ;
  3856. $nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3857. $inclCursive=false;
  3858. if ($checkCursive) {
  3859. if (preg_match("/([".$this->pregRTLchars."])/u", $tmp)) { $inclCursive = true; } // *RTL*
  3860. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $tmp)) { $inclCursive = true; } // *INDIC*
  3861. }
  3862. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),$inclCursive);
  3863. $this->SetSpacing($charspacing,$ws);
  3864. //////////////////////////////////////////
  3865. }
  3866. // DIRECTIONALITY
  3867. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3868. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3869. $i=$sep+1;
  3870. }
  3871. $sep=-1;
  3872. $j=$i;
  3873. $l=0;
  3874. $ns=0;
  3875. $nl++;
  3876. if($border and $nl==2) $b=$b2;
  3877. }
  3878. else $i++;
  3879. }
  3880. //Last chunk
  3881. // WORD SPACING
  3882. $this->ResetSpacing();
  3883. }
  3884. else {
  3885. while($i<$nb) {
  3886. //Get next character
  3887. $c=$s[$i];
  3888. if($c == "\n") {
  3889. //Explicit line break
  3890. // WORD SPACING
  3891. $this->ResetSpacing();
  3892. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3893. $i++;
  3894. $sep=-1;
  3895. $j=$i;
  3896. $l=0;
  3897. $ns=0;
  3898. $nl++;
  3899. if($border and $nl==2) $b=$b2;
  3900. continue;
  3901. }
  3902. if($c == " ") {
  3903. $sep=$i;
  3904. $ls=$l;
  3905. $ns++;
  3906. }
  3907. $l += $this->GetCharWidthCore($c);
  3908. if($l>$wmax) {
  3909. //Automatic line break
  3910. if($sep==-1) {
  3911. if($i==$j) $i++;
  3912. // WORD SPACING
  3913. $this->ResetSpacing();
  3914. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3915. }
  3916. else {
  3917. if($align=='J') {
  3918. $tmp = rtrim(substr($s,$j,$sep-$j));
  3919. //////////////////////////////////////////
  3920. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3921. // WORD SPACING NON_UNICDOE/CJK
  3922. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3923. $tmp = str_replace(chr(160),chr(32),$tmp);
  3924. $len_ligne = $this->GetStringWidth($tmp );
  3925. $nb_carac = strlen( $tmp ) ;
  3926. $nb_spaces = substr_count( $tmp ,' ' ) ;
  3927. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),false);
  3928. $this->SetSpacing($charspacing,$ws);
  3929. //////////////////////////////////////////
  3930. }
  3931. $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link);
  3932. $i=$sep+1;
  3933. }
  3934. $sep=-1;
  3935. $j=$i;
  3936. $l=0;
  3937. $ns=0;
  3938. $nl++;
  3939. if($border and $nl==2) $b=$b2;
  3940. }
  3941. else $i++;
  3942. }
  3943. //Last chunk
  3944. // WORD SPACING
  3945. $this->ResetSpacing();
  3946. }
  3947. //Last chunk
  3948. if($border and is_int(strpos($border,'B'))) $b.='B';
  3949. if (!$this->usingCoreFont) {
  3950. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3951. // DIRECTIONALITY
  3952. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3953. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3954. }
  3955. else { $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); }
  3956. $this->x=$this->lMargin;
  3957. }
  3958. /*-- DIRECTW --*/
  3959. function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
  3960. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  3961. if (empty($this->directw)) { $this->directw = new directw($this); }
  3962. $this->directw->Write($h,$txt,$currentx,$link,$directionality,$align);
  3963. }
  3964. /*-- END DIRECTW --*/
  3965. /*-- HTML-CSS --*/
  3966. function saveInlineProperties() {
  3967. $saved = array();
  3968. $saved[ 'family' ] = $this->FontFamily;
  3969. $saved[ 'style' ] = $this->FontStyle;
  3970. $saved[ 'sizePt' ] = $this->FontSizePt;
  3971. $saved[ 'size' ] = $this->FontSize;
  3972. $saved[ 'HREF' ] = $this->HREF;
  3973. $saved[ 'underline' ] = $this->U;
  3974. $saved[ 'smCaps' ] = $this->S;
  3975. $saved[ 'strike' ] = $this->strike;
  3976. $saved[ 'textshadow' ] = $this->textshadow;
  3977. $saved[ 'SUP' ] = $this->SUP;
  3978. $saved[ 'SUB' ] = $this->SUB;
  3979. $saved[ 'linewidth' ] = $this->LineWidth;
  3980. $saved[ 'drawcolor' ] = $this->DrawColor;
  3981. $saved[ 'textparam' ] = $this->textparam;
  3982. $saved[ 'toupper' ] = $this->toupper;
  3983. $saved[ 'tolower' ] = $this->tolower;
  3984. $saved[ 'capitalize' ] = $this->capitalize;
  3985. $saved[ 'fontkerning' ] = $this->kerning;
  3986. $saved[ 'lSpacingCSS' ] = $this->lSpacingCSS;
  3987. $saved[ 'wSpacingCSS' ] = $this->wSpacingCSS;
  3988. $saved[ 'I' ] = $this->I;
  3989. $saved[ 'B' ] = $this->B;
  3990. $saved[ 'colorarray' ] = $this->colorarray;
  3991. $saved[ 'bgcolorarray' ] = $this->spanbgcolorarray;
  3992. $saved[ 'border' ] = $this->spanborddet;
  3993. $saved[ 'color' ] = $this->TextColor;
  3994. $saved[ 'bgcolor' ] = $this->FillColor;
  3995. $saved[ 'lang' ] = $this->currentLang;
  3996. $saved[ 'display_off' ] = $this->inlineDisplayOff;
  3997. return $saved;
  3998. }
  3999. function restoreInlineProperties( &$saved) {
  4000. $FontFamily = $saved[ 'family' ];
  4001. $this->FontStyle = $saved[ 'style' ];
  4002. $this->FontSizePt = $saved[ 'sizePt' ];
  4003. $this->FontSize = $saved[ 'size' ];
  4004. $this->currentLang = $saved['lang'];
  4005. if ($this->useLang && !$this->usingCoreFont) {
  4006. if ($this->currentLang != $this->default_lang && ((strlen($this->currentLang) == 5 && $this->currentLang != 'UTF-8') || strlen($this->currentLang ) == 2)) {
  4007. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($this->currentLang, $this->useAdobeCJK);
  4008. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  4009. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  4010. }
  4011. else {
  4012. $this->RestrictUnicodeFonts($this->default_available_fonts );
  4013. }
  4014. }
  4015. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  4016. $this->HREF = $saved[ 'HREF' ];
  4017. $this->U = $saved[ 'underline' ];
  4018. $this->S = $saved[ 'smCaps' ];
  4019. $this->strike = $saved[ 'strike' ];
  4020. $this->textshadow = $saved[ 'textshadow' ];
  4021. $this->SUP = $saved[ 'SUP' ];
  4022. $this->SUB = $saved[ 'SUB' ];
  4023. $this->LineWidth = $saved[ 'linewidth' ];
  4024. $this->DrawColor = $saved[ 'drawcolor' ];
  4025. $this->textparam = $saved[ 'textparam' ];
  4026. $this->inlineDisplayOff = $saved['display_off'];
  4027. $this->toupper = $saved[ 'toupper' ];
  4028. $this->tolower = $saved[ 'tolower' ];
  4029. $this->capitalize = $saved[ 'capitalize' ];
  4030. $this->kerning = $saved[ 'fontkerning' ];
  4031. $this->lSpacingCSS = $saved[ 'lSpacingCSS' ];
  4032. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  4033. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  4034. }
  4035. else { $this->fixedlSpacing = false; }
  4036. $this->wSpacingCSS = $saved[ 'wSpacingCSS' ];
  4037. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  4038. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  4039. }
  4040. else { $this->minwSpacing = 0; }
  4041. $this->SetFont($FontFamily, $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],false);
  4042. $this->currentfontstyle = $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : '');
  4043. $this->currentfontsize = $saved[ 'sizePt' ];
  4044. $this->SetStylesArray(array('S'=>$this->S, 'U'=>$this->U, 'B'=>$saved[ 'B' ], 'I'=>$saved[ 'I' ]));
  4045. $this->TextColor = $saved[ 'color' ];
  4046. $this->FillColor = $saved[ 'bgcolor' ];
  4047. $this->colorarray = $saved[ 'colorarray' ];
  4048. $cor = $saved[ 'colorarray' ];
  4049. if ($cor) $this->SetTColor($cor);
  4050. $this->spanbgcolorarray = $saved[ 'bgcolorarray' ];
  4051. $cor = $saved[ 'bgcolorarray' ];
  4052. if ($cor) $this->SetFColor($cor);
  4053. $this->spanborddet = $saved[ 'border' ];
  4054. }
  4055. // Used when ColActive for tables - updated to return first block with background fill OR borders
  4056. function GetFirstBlockFill() {
  4057. // Returns the first blocklevel that uses a bgcolor fill
  4058. $startfill = 0;
  4059. for ($i=1;$i<=$this->blklvl;$i++) {
  4060. 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'] ) {
  4061. $startfill = $i;
  4062. break;
  4063. }
  4064. }
  4065. return $startfill;
  4066. }
  4067. function SetBlockFill($blvl) {
  4068. if ($this->blk[$blvl]['bgcolor']) {
  4069. $this->SetFColor($this->blk[$blvl]['bgcolorarray']);
  4070. return 1;
  4071. }
  4072. else {
  4073. $this->SetFColor($this->ConvertColor(255));
  4074. return 0;
  4075. }
  4076. }
  4077. //-------------------------FLOWING BLOCK------------------------------------//
  4078. //The following functions were originally written by Damon Kohler //
  4079. //--------------------------------------------------------------------------//
  4080. function saveFont() {
  4081. $saved = array();
  4082. $saved[ 'family' ] = $this->FontFamily;
  4083. $saved[ 'style' ] = $this->FontStyle;
  4084. $saved[ 'sizePt' ] = $this->FontSizePt;
  4085. $saved[ 'size' ] = $this->FontSize;
  4086. $saved[ 'curr' ] = &$this->CurrentFont;
  4087. $saved[ 'color' ] = $this->TextColor;
  4088. $saved[ 'spanbgcolor' ] = $this->spanbgcolor;
  4089. $saved[ 'spanbgcolorarray' ] = $this->spanbgcolorarray;
  4090. $saved[ 'bord' ] = $this->spanborder;
  4091. $saved[ 'border' ] = $this->spanborddet;
  4092. $saved[ 'HREF' ] = $this->HREF;
  4093. $saved[ 'underline' ] = $this->U;
  4094. $saved[ 'smCaps' ] = $this->S;
  4095. $saved[ 'strike' ] = $this->strike;
  4096. $saved[ 'textshadow' ] = $this->textshadow;
  4097. $saved[ 'SUP' ] = $this->SUP;
  4098. $saved[ 'SUB' ] = $this->SUB;
  4099. $saved[ 'linewidth' ] = $this->LineWidth;
  4100. $saved[ 'drawcolor' ] = $this->DrawColor;
  4101. $saved[ 'textparam' ] = $this->textparam;
  4102. $saved[ 'ReqFontStyle' ] = $this->ReqFontStyle;
  4103. $saved[ 'fontkerning' ] = $this->kerning;
  4104. $saved[ 'fixedlSpacing' ] = $this->fixedlSpacing;
  4105. $saved[ 'minwSpacing' ] = $this->minwSpacing;
  4106. return $saved;
  4107. }
  4108. function restoreFont( &$saved, $write=true) {
  4109. if (!isset($saved) || empty($saved)) return;
  4110. $this->FontFamily = $saved[ 'family' ];
  4111. $this->FontStyle = $saved[ 'style' ];
  4112. $this->FontSizePt = $saved[ 'sizePt' ];
  4113. $this->FontSize = $saved[ 'size' ];
  4114. $this->CurrentFont = &$saved[ 'curr' ];
  4115. $this->TextColor = $saved[ 'color' ];
  4116. $this->spanbgcolor = $saved[ 'spanbgcolor' ];
  4117. $this->spanbgcolorarray = $saved[ 'spanbgcolorarray' ];
  4118. $this->spanborder = $saved[ 'bord' ];
  4119. $this->spanborddet = $saved[ 'border' ];
  4120. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  4121. $this->HREF = $saved[ 'HREF' ];
  4122. $this->U = $saved[ 'underline' ];
  4123. $this->S = $saved[ 'smCaps' ];
  4124. $this->kerning = $saved[ 'fontkerning' ];
  4125. $this->fixedlSpacing = $saved[ 'fixedlSpacing' ];
  4126. $this->minwSpacing = $saved[ 'minwSpacing' ];
  4127. $this->strike = $saved[ 'strike' ];
  4128. $this->textshadow = $saved[ 'textshadow' ];
  4129. $this->SUP = $saved[ 'SUP' ];
  4130. $this->SUB = $saved[ 'SUB' ];
  4131. $this->LineWidth = $saved[ 'linewidth' ];
  4132. $this->DrawColor = $saved[ 'drawcolor' ];
  4133. $this->textparam = $saved[ 'textparam' ];
  4134. if ($write) {
  4135. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],true,true); // force output
  4136. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4137. 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); }
  4138. $this->pageoutput[$this->page]['Font'] = $fontout;
  4139. }
  4140. else
  4141. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ]);
  4142. $this->ReqFontStyle = $saved[ 'ReqFontStyle' ];
  4143. }
  4144. function newFlowingBlock( $w, $h, $a = '', $is_table = false, $is_list = false, $blockstate = 0, $newblock=true, $blockdir='ltr')
  4145. {
  4146. if (!$a) {
  4147. if ($blockdir=='rtl') { $a = 'R'; }
  4148. else { $a = 'L'; }
  4149. }
  4150. $this->flowingBlockAttr[ 'width' ] = ($w * _MPDFK);
  4151. // line height in user units
  4152. $this->flowingBlockAttr[ 'is_table' ] = $is_table;
  4153. $this->flowingBlockAttr[ 'is_list' ] = $is_list;
  4154. $this->flowingBlockAttr[ 'height' ] = $h;
  4155. $this->flowingBlockAttr[ 'lineCount' ] = 0;
  4156. $this->flowingBlockAttr[ 'align' ] = $a;
  4157. $this->flowingBlockAttr[ 'font' ] = array();
  4158. $this->flowingBlockAttr[ 'content' ] = array();
  4159. $this->flowingBlockAttr[ 'contentB' ] = array();
  4160. $this->flowingBlockAttr[ 'contentWidth' ] = 0;
  4161. $this->flowingBlockAttr[ 'blockstate' ] = $blockstate;
  4162. $this->flowingBlockAttr[ 'newblock' ] = $newblock;
  4163. $this->flowingBlockAttr[ 'valign' ] = 'M';
  4164. $this->flowingBlockAttr['blockdir'] = $blockdir;
  4165. }
  4166. function finishFlowingBlock($endofblock=false, $next='') {
  4167. $currentx = $this->x;
  4168. //prints out the last chunk
  4169. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  4170. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  4171. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  4172. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  4173. $align =& $this->flowingBlockAttr[ 'align' ];
  4174. $content =& $this->flowingBlockAttr[ 'content' ];
  4175. $contentB =& $this->flowingBlockAttr[ 'contentB' ];
  4176. $font =& $this->flowingBlockAttr[ 'font' ];
  4177. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  4178. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  4179. $valign =& $this->flowingBlockAttr[ 'valign' ];
  4180. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  4181. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  4182. $blockdir = $this->flowingBlockAttr['blockdir'];
  4183. // *********** BLOCK BACKGROUND COLOR *****************//
  4184. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  4185. $fill = 0;
  4186. }
  4187. else {
  4188. $this->SetFColor($this->ConvertColor(255));
  4189. $fill = 0;
  4190. }
  4191. $hanger = ''; // mPDF 5.6.40
  4192. // Always right trim!
  4193. // Right trim content and adjust width if need to justify (later)
  4194. if (isset($content[count($content)-1]) && preg_match('/[ ]+$/',$content[count($content)-1], $m)) {
  4195. $strip = strlen($m[0]);
  4196. $content[count($content)-1] = substr($content[count($content)-1],0,(strlen($content[count($content)-1])-$strip));
  4197. $this->restoreFont( $font[ count($content)-1 ],false );
  4198. $contentWidth -= $this->GetStringWidth($m[0]) * _MPDFK;
  4199. }
  4200. // the amount of space taken up so far in user units
  4201. $usedWidth = 0;
  4202. // COLS
  4203. $oldcolumn = $this->CurrCol;
  4204. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4205. // Print out each chunk
  4206. /*-- TABLES --*/
  4207. if ($is_table) {
  4208. $ipaddingL = 0;
  4209. $ipaddingR = 0;
  4210. $paddingL = 0;
  4211. $paddingR = 0;
  4212. }
  4213. else {
  4214. /*-- END TABLES --*/
  4215. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4216. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4217. $paddingL = ($ipaddingL * _MPDFK);
  4218. $paddingR = ($ipaddingR * _MPDFK);
  4219. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4220. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4221. // Added mPDF 3.0 Float DIV
  4222. $fpaddingR = 0;
  4223. $fpaddingL = 0;
  4224. /*-- CSS-FLOAT --*/
  4225. if (count($this->floatDivs)) {
  4226. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4227. if ($r_exists) { $fpaddingR = $r_width; }
  4228. if ($l_exists) { $fpaddingL = $l_width; }
  4229. }
  4230. /*-- END CSS-FLOAT --*/
  4231. $usey = $this->y + 0.002;
  4232. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4233. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4234. }
  4235. /*-- CSS-IMAGE-FLOAT --*/
  4236. // If float exists at this level
  4237. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4238. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4239. /*-- END CSS-IMAGE-FLOAT --*/
  4240. } // *TABLES*
  4241. // Set Current lineheight (correction factor)
  4242. $lhfixed = false;
  4243. /*-- LISTS --*/
  4244. if ($is_list) {
  4245. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  4246. $lhfixed = true;
  4247. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  4248. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4249. }
  4250. else {
  4251. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  4252. }
  4253. }
  4254. else
  4255. /*-- END LISTS --*/
  4256. /*-- TABLES --*/
  4257. if ($is_table) {
  4258. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  4259. $lhfixed = true;
  4260. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  4261. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  4262. }
  4263. else {
  4264. $this->lineheight_correction = $this->table_lineheight;
  4265. }
  4266. }
  4267. else
  4268. /*-- END TABLES --*/
  4269. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  4270. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  4271. $lhfixed = true;
  4272. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  4273. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4274. }
  4275. else {
  4276. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  4277. }
  4278. }
  4279. else {
  4280. $this->lineheight_correction = $this->normalLineheight;
  4281. }
  4282. // correct lineheight to maximum fontsize
  4283. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  4284. else { $maxlineHeight = 0; }
  4285. $this->forceExactLineheight = true;
  4286. $maxfontsize = 0;
  4287. // While we're at it, check if contains cursive text
  4288. $checkCursive=false;
  4289. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  4290. foreach ( $content as $k => $chunk )
  4291. {
  4292. $this->restoreFont( $font[ $k ],false );
  4293. if (!isset($this->objectbuffer[$k])) {
  4294. // Soft Hyphens chr(173)
  4295. if (!$this->usingCoreFont) {
  4296. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  4297. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  4298. }
  4299. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  4300. $content[$k] = $chunk = str_replace(chr(173),'',$chunk );
  4301. }
  4302. // Special case of sub/sup carried over on its own to last line
  4303. if (($this->SUB || $this->SUP) && count($content)==1) { $actfs = $this->FontSize*100/55; } // 55% is font change for sub/sup
  4304. else { $actfs = $this->FontSize; }
  4305. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4306. if ($lhfixed && ($actfs > $def_fontsize || ($actfs > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  4307. $this->forceExactLineheight = false;
  4308. }
  4309. $maxfontsize = max($maxfontsize,$actfs);
  4310. }
  4311. }
  4312. if(isset($font[count($font)-1])) {
  4313. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  4314. $lastfontstyle = $font[count($font)-1]['style'];
  4315. }
  4316. else {
  4317. $lastfontreqstyle=null;
  4318. $lastfontstyle=null;
  4319. }
  4320. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  4321. $lastitalic = $this->FontSize*0.15*_MPDFK;
  4322. }
  4323. else { $lastitalic = 0; }
  4324. /*-- LISTS --*/
  4325. if ($is_list && is_array($this->bulletarray) && count($this->bulletarray)) {
  4326. $actfs = $this->bulletarray['fontsize'];
  4327. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4328. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  4329. $maxfontsize = max($maxfontsize,$actfs);
  4330. }
  4331. /*-- END LISTS --*/
  4332. // when every text item checked i.e. $maxfontsize is set properly
  4333. $af = 0; // Above font
  4334. $bf = 0; // Below font
  4335. $mta = 0; // Maximum top-aligned
  4336. $mba = 0; // Maximum bottom-aligned
  4337. foreach ( $content as $k => $chunk )
  4338. {
  4339. if (isset($this->objectbuffer[$k])) {
  4340. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  4341. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  4342. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  4343. if ($va == 'BS') { // (BASELINE default)
  4344. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  4345. }
  4346. else if ($va == 'M') {
  4347. $af = max($af, ($oh - $maxfontsize)/2);
  4348. $bf = max($bf, ($oh - $maxfontsize)/2);
  4349. }
  4350. else if ($va == 'TT') {
  4351. $bf = max($bf, ($oh - $maxfontsize));
  4352. }
  4353. else if ($va == 'TB') {
  4354. $af = max($af, ($oh - $maxfontsize));
  4355. }
  4356. else if ($va == 'T') {
  4357. $mta = max($mta, $oh);
  4358. }
  4359. else if ($va == 'B') {
  4360. $mba = max($mba, $oh);
  4361. }
  4362. }
  4363. }
  4364. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  4365. $maxlineHeight = $maxfontsize + $af + $bf;
  4366. }
  4367. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  4368. if ($mta > $maxlineHeight) {
  4369. $bf += ($mta - $maxlineHeight);
  4370. $maxlineHeight = $mta;
  4371. }
  4372. if ($mba > $maxlineHeight) {
  4373. $af += ($mba - $maxlineHeight);
  4374. $maxlineHeight = $mba;
  4375. }
  4376. $lineHeight = $maxlineHeight;
  4377. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  4378. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  4379. $this->linemaxfontsize = $def_fontsize;
  4380. }
  4381. else { $this->linemaxfontsize = $maxfontsize; }
  4382. // Get PAGEBREAK TO TEST for height including the bottom border/padding
  4383. $check_h = max($this->divheight,$lineHeight);
  4384. // This fixes a proven bug...
  4385. if ($endofblock && $newblock && $blockstate==0 && !$content) { $check_h = 0; }
  4386. // but ? needs to fix potentially more widespread...
  4387. // if (!$content) { $check_h = 0; }
  4388. if ($this->blklvl > 0 && !$is_table) {
  4389. if ($endofblock && $blockstate > 1) {
  4390. if ($this->blk[$this->blklvl]['page_break_after_avoid']) { $check_h += $lineHeight; }
  4391. $check_h += ($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4392. }
  4393. // mPDF 5.4.03
  4394. if (($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0) || ($endofblock && $blockstate ==3 && $lineCount == 0)) {
  4395. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  4396. }
  4397. }
  4398. // Force PAGE break if column height cannot take check-height
  4399. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  4400. $this->SetCol($this->NbCol-1);
  4401. }
  4402. // mPDF 5.4.04
  4403. // Avoid just border/background-color moved on to next page
  4404. if ($endofblock && $blockstate > 1 && !$content) { $buff = $this->margBuffer; }
  4405. else { $buff = 0; }
  4406. // PAGEBREAK
  4407. // mPDF 5.4.04
  4408. if(!$is_table && ($this->y+$check_h) > ($this->PageBreakTrigger + $buff) and !$this->InFooter and $this->AcceptPageBreak()) {
  4409. $bak_x=$this->x;//Current X position
  4410. // WORD SPACING
  4411. $ws=$this->ws;//Word Spacing
  4412. $charspacing=$this->charspacing;//Character Spacing
  4413. $this->ResetSpacing();
  4414. $this->AddPage($this->CurOrientation);
  4415. $this->x=$bak_x;
  4416. // Added to correct for OddEven Margins
  4417. $currentx += $this->MarginCorrection;
  4418. $this->x += $this->MarginCorrection;
  4419. // WORD SPACING
  4420. $this->SetSpacing($charspacing,$ws);
  4421. }
  4422. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  4423. $this->printdivbuffer();
  4424. $this->keep_block_together = 0;
  4425. }
  4426. /*-- COLUMNS --*/
  4427. // COLS
  4428. // COLUMN CHANGE
  4429. if ($this->CurrCol != $oldcolumn) {
  4430. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4431. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4432. $oldcolumn = $this->CurrCol;
  4433. }
  4434. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; }
  4435. /*-- END COLUMNS --*/
  4436. // TOP MARGIN
  4437. if ($newblock && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && $lineCount == 0 && !$is_table && !$is_list) {
  4438. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4439. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4440. }
  4441. if ($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0 && !$is_table && !$is_list) {
  4442. $this->blk[$this->blklvl]['y0'] = $this->y;
  4443. $this->blk[$this->blklvl]['startpage'] = $this->page;
  4444. if ($this->blk[$this->blklvl]['float']) { $this->blk[$this->blklvl]['float_start_y'] = $this->y; } // mPDF 5.6.63
  4445. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4446. }
  4447. // ADDED for Paragraph_indent
  4448. $WidthCorrection = 0;
  4449. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  4450. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4451. $WidthCorrection = ($ti*_MPDFK);
  4452. }
  4453. // PADDING and BORDER spacing/fill
  4454. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 0) && (!$is_table) && (!$is_list)) {
  4455. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4456. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  4457. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4458. $this->x = $currentx;
  4459. }
  4460. // Added mPDF 3.0 Float DIV
  4461. $fpaddingR = 0;
  4462. $fpaddingL = 0;
  4463. /*-- CSS-FLOAT --*/
  4464. if (count($this->floatDivs)) {
  4465. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4466. if ($r_exists) { $fpaddingR = $r_width; }
  4467. if ($l_exists) { $fpaddingL = $l_width; }
  4468. }
  4469. /*-- END CSS-FLOAT --*/
  4470. $usey = $this->y + 0.002;
  4471. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4472. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4473. }
  4474. /*-- CSS-IMAGE-FLOAT --*/
  4475. // If float exists at this level
  4476. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4477. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4478. /*-- END CSS-IMAGE-FLOAT --*/
  4479. if ($content) {
  4480. // In FinishFlowing Block no lines are justified as it is always last line
  4481. // but if CJKorphan has allowed content width to go over max width, use J charspacing to compress line
  4482. // JUSTIFICATION J - NOT!
  4483. $nb_carac = 0;
  4484. $nb_spaces = 0;
  4485. $jcharspacing = 0;
  4486. $jws = 0;
  4487. $inclCursive=false;
  4488. $dottab = false; // mPDF 5.6.19
  4489. foreach ( $content as $k => $chunk ) {
  4490. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  4491. if ($this->usingCoreFont) {
  4492. $chunk = str_replace(chr(160),chr(32),$chunk );
  4493. }
  4494. else {
  4495. $chunk = str_replace(chr(194).chr(160),chr(32),$chunk );
  4496. }
  4497. $nb_carac += mb_strlen( $chunk, $this->mb_enc );
  4498. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc );
  4499. if ($checkCursive) {
  4500. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  4501. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  4502. }
  4503. }
  4504. else if ($this->objectbuffer[$k]['type']=='dottab') { $dottab = $this->objectbuffer[$k]['outdent']; } // mPDF 5.6.19
  4505. }
  4506. // 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)
  4507. // If "orphans" in fact is just a final space - ignore this
  4508. // mPDF 5.6.40
  4509. $lastchar = mb_substr($content[(count($content)-1)],mb_strlen($content[(count($content)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  4510. if (preg_match("/[".$this->CJKoverflow."]/u", $lastchar)) { $CJKoverflow = true; }
  4511. else {$CJKoverflow = false; }
  4512. if ((((($contentWidth + $lastitalic) > $maxWidth) && ($content[count($content)-1] != ' ') ) ||
  4513. (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br)))) && !($CJKoverflow && $this->allowCJKoverflow) ) { // mPDF 5.6.40
  4514. // WORD SPACING
  4515. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$contentWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive);
  4516. }
  4517. /*-- CJK-FONTS --*/
  4518. // mPDF 5.6.40
  4519. else if ($this->checkCJK && $align=='J' && $CJKoverflow && $this->allowCJKoverflow && $this->CJKforceend) {
  4520. // force-end overhang
  4521. $hanger = mb_substr($content[count($content)-1],mb_strlen($content[count($content)-1],$this->mb_enc)-1,1,$this->mb_enc );
  4522. if (preg_match("/[".$this->CJKoverflow."]/u", $hanger)) {
  4523. $content[count($content)-1] = mb_substr($content[count($content)-1],0,mb_strlen($content[count($content)-1],$this->mb_enc)-1,$this->mb_enc );
  4524. $this->restoreFont( $font[ count($content)-1 ],false );
  4525. $contentWidth -= $this->GetStringWidth($hanger) * _MPDFK;
  4526. $nb_carac -= 1;
  4527. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$contentWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive);
  4528. }
  4529. }
  4530. /*-- END CJK-FONTS --*/
  4531. // Check if will fit at word/char spacing of previous line - if so continue it
  4532. // but only allow a maximum of $this->jSmaxWordLast and $this->jSmaxCharLast
  4533. else if ($contentWidth < ($maxWidth - $lastitalic-$WidthCorrection - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK))) && !$this->fixedlSpacing) {
  4534. if ($this->ws > $this->jSmaxWordLast) {
  4535. $jws = $this->jSmaxWordLast;
  4536. }
  4537. if ($this->charspacing > $this->jSmaxCharLast) {
  4538. $jcharspacing = $this->jSmaxCharLast;
  4539. }
  4540. $check = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) - ( $jcharspacing * $nb_carac) - ( $jws * $nb_spaces);
  4541. if ($check <= 0) {
  4542. $jcharspacing = 0;
  4543. $jws = 0;
  4544. }
  4545. }
  4546. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  4547. $empty -= ($jcharspacing * $nb_carac);
  4548. $empty -= ($jws * $nb_spaces);
  4549. $empty /= _MPDFK;
  4550. if (!$is_table) {
  4551. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin'] - $empty));
  4552. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $empty));
  4553. }
  4554. $arraysize = count($content);
  4555. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  4556. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  4557. // DIRECTIONALITY RTL
  4558. $all_rtl = false;
  4559. $contains_rtl = false;
  4560. /*-- RTL --*/
  4561. if ($blockdir == 'rtl' || $this->biDirectional) {
  4562. $all_rtl = true;
  4563. foreach ( $content as $k => $chunk ) {
  4564. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir);
  4565. if ($reversed > 0) { $contains_rtl = true; }
  4566. if ($reversed < 2) { $all_rtl = false; }
  4567. $content[$k] = $chunk;
  4568. }
  4569. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) {
  4570. $content = array_reverse($content,false);
  4571. $contentB = array_reverse($contentB,false);
  4572. }
  4573. }
  4574. /*-- END RTL --*/
  4575. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL;
  4576. if ($dottab !== false && $blockdir=='rtl') { $this->x -= $dottab; } // mPDF 5.6.19
  4577. else if ($align == 'R') { $this->x += $empty; }
  4578. else if ($align == 'J' && $blockdir == 'rtl') { $this->x += $empty; }
  4579. else if ($align == 'C') { $this->x += ($empty / 2); }
  4580. // Paragraph INDENT
  4581. $WidthCorrection = 0;
  4582. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align !='C')) {
  4583. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4584. $this->x += $ti;
  4585. }
  4586. foreach ( $content as $k => $chunk )
  4587. {
  4588. // FOR IMAGES
  4589. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $dirk = $arraysize-1 - $k; } else { $dirk = $k; }
  4590. $va = 'M'; // default for text
  4591. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  4592. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'];
  4593. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  4594. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  4595. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  4596. $va = $this->objectbuffer[$dirk]['vertical-align'];
  4597. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  4598. if ($va == 'BS') {
  4599. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4600. }
  4601. else if ($va == 'M' || $va == '') {
  4602. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  4603. }
  4604. else if ($va == 'TB') {
  4605. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4606. }
  4607. else if ($va == 'TT') {
  4608. $yadj += $af;
  4609. }
  4610. else if ($va == 'B') {
  4611. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4612. }
  4613. else if ($va == 'T') {
  4614. $yadj += 0;
  4615. }
  4616. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  4617. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  4618. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  4619. }
  4620. // DIRECTIONALITY RTL
  4621. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $this->restoreFont( $font[ $arraysize-1 - $k ] ); }
  4622. else { $this->restoreFont( $font[ $k ] ); }
  4623. // mPDF 5.6.13 Decimal alignment - set in _tableWrite
  4624. if ($is_table && substr($align,0,1)=='D' && $k==0 ) {
  4625. $dp = $this->decimal_align[substr($align,0,2)];
  4626. $s = preg_split('/'.preg_quote($dp,'/').'/', $content[0], 2); // ? needs to be /u if not core
  4627. $s0 = $this->GetStringWidth($s[0], false);
  4628. $this->x += ($this->decimal_offset - $s0);
  4629. }
  4630. $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws);
  4631. $this->fixedlSpacing = false;
  4632. $this->minwSpacing = 0;
  4633. // mPDF 5.6.26
  4634. $save_vis = $this->visibility;
  4635. if (isset($this->textparam['visibility']) && $this->textparam['visibility'] && $this->textparam['visibility'] != $this->visibility) {
  4636. $this->SetVisibility($this->textparam['visibility']);
  4637. }
  4638. // *********** SPAN BACKGROUND COLOR ***************** //
  4639. if (isset($this->spanbgcolor) && $this->spanbgcolor) {
  4640. $cor = $this->spanbgcolorarray;
  4641. $this->SetFColor($cor);
  4642. $save_fill = $fill; $spanfill = 1; $fill = 1;
  4643. }
  4644. if (!empty($this->spanborddet)) {
  4645. if (strpos($contentB[$k],'L')!==false && isset($this->spanborddet['L'])) $this->x += $this->spanborddet['L']['w'];
  4646. if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0;
  4647. if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0;
  4648. }
  4649. // WORD SPACING
  4650. $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK )
  4651. + ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK );
  4652. if (isset($this->objectbuffer[$dirk])) {
  4653. if ($this->objectbuffer[$dirk]['type']=='dottab') {
  4654. $this->objectbuffer[$dirk]['OUTER-WIDTH'] +=$empty;
  4655. $this->objectbuffer[$dirk]['OUTER-WIDTH'] +=$this->objectbuffer[$dirk]['outdent']; // mPDF 5.6.19
  4656. }
  4657. $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH'];
  4658. }
  4659. if ($stringWidth==0) { $stringWidth = 0.000001; }
  4660. if ($k == $arraysize-1) {
  4661. // mPDF 5.6.40
  4662. if ($this->checkCJK && $CJKoverflow && $align=='J' && $this->allowCJKoverflow && $hanger && $this->CJKforceend) {
  4663. // force-end overhang
  4664. $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true );
  4665. $this->Cell( $this->GetStringWidth($hanger), $lineHeight, $hanger, '', 1, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true );
  4666. }
  4667. else {
  4668. $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true );
  4669. }
  4670. }
  4671. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part
  4672. if (!empty($this->spanborddet)) {
  4673. if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w'];
  4674. }
  4675. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  4676. if (isset($spanfill) && $spanfill) {
  4677. $fill = $save_fill; $spanfill = 0;
  4678. if ($fill) { $this->SetFColor($bcor); }
  4679. }
  4680. // mPDF 5.6.26
  4681. if (isset($this->textparam['visibility']) && $this->textparam['visibility'] && $this->visibility != $save_vis) {
  4682. $this->SetVisibility($save_vis);
  4683. }
  4684. }
  4685. $this->printobjectbuffer($is_table, $blockdir);
  4686. $this->objectbuffer = array();
  4687. $this->ResetSpacing();
  4688. /*-- LISTS --*/
  4689. // LIST BULLETS/NUMBERS
  4690. if ($is_list && is_array($this->bulletarray) && ($lineCount == 0) ) {
  4691. $savedFont = $this->saveFont();
  4692. $bull = $this->bulletarray;
  4693. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  4694. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  4695. }
  4696. 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']]); }
  4697. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4698. $this->bullet = true;
  4699. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  4700. }
  4701. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  4702. //Output bullet
  4703. $this->x = $currentx;
  4704. if (isset($bull['x'])) { $this->x += $bull['x']; }
  4705. $this->y -= $lineHeight;
  4706. if (isset($bull['col']) && $bull['col']) { $this->SetTColor($bull['col']); } // mPDF 5.6.67
  4707. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  4708. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4709. $this->bullet = false;
  4710. }
  4711. $this->x = $currentx; // Reset
  4712. $this->y += $lineHeight;
  4713. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4714. $this->restoreFont( $savedFont );
  4715. // $font = array( $savedFont );
  4716. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  4717. }
  4718. /*-- END LISTS --*/
  4719. } // END IF CONTENT
  4720. /*-- CSS-IMAGE-FLOAT --*/
  4721. // Update values if set to skipline
  4722. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  4723. if ($endofblock && $blockstate>1) {
  4724. // If float exists at this level
  4725. if (isset($this->floatmargins['R']['y1'])) { $fry1 = $this->floatmargins['R']['y1']; }
  4726. else { $fry1 = 0; }
  4727. if (isset($this->floatmargins['L']['y1'])) { $fly1 = $this->floatmargins['L']['y1']; }
  4728. else { $fly1 = 0; }
  4729. if ($this->y < $fry1 || $this->y < $fly1) {
  4730. $drop = max($fry1,$fly1) - $this->y;
  4731. $this->DivLn($drop);
  4732. $this->x = $currentx;
  4733. }
  4734. }
  4735. /*-- END CSS-IMAGE-FLOAT --*/
  4736. // PADDING and BORDER spacing/fill
  4737. 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)) {
  4738. // If CSS height set, extend bottom - if on same page as block started, and CSS HEIGHT > actual height,
  4739. // and does not force pagebreak
  4740. $extra = 0;
  4741. if ($this->blk[$this->blklvl]['css_set_height'] && $this->blk[$this->blklvl]['startpage']==$this->page) {
  4742. // predicted height
  4743. $h1 = ($this->y-$this->blk[$this->blklvl]['y0']) + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  4744. 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; }
  4745. if($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra > $this->PageBreakTrigger) {
  4746. $extra = $this->PageBreakTrigger - ($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4747. }
  4748. }
  4749. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4750. $this->DivLn($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra,-3,true,false,2);
  4751. $this->x = $currentx;
  4752. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4753. }
  4754. // SET Bottom y1 of block (used for painting borders)
  4755. if (($endofblock) && ($blockstate > 1) && (!$is_table) && (!$is_list)) {
  4756. $this->blk[$this->blklvl]['y1'] = $this->y;
  4757. }
  4758. // BOTTOM MARGIN
  4759. if (($endofblock) && ($blockstate > 1) && ($this->blk[$this->blklvl]['margin_bottom']) && (!$is_table) && (!$is_list)) {
  4760. if($this->y+$this->blk[$this->blklvl]['margin_bottom'] < $this->PageBreakTrigger and !$this->InFooter) {
  4761. $this->DivLn($this->blk[$this->blklvl]['margin_bottom'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4762. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4763. }
  4764. }
  4765. // Reset lineheight
  4766. $lineHeight = $this->divheight;
  4767. }
  4768. function printobjectbuffer($is_table=false, $blockdir=false) {
  4769. if (!$blockdir) { $blockdir = $this->directionality; }
  4770. if ($is_table && $this->shrin_k > 1) { $k = $this->shrin_k; }
  4771. else { $k = 1; }
  4772. $save_y = $this->y;
  4773. $save_x = $this->x;
  4774. $save_currentfontfamily = $this->FontFamily;
  4775. $save_currentfontsize = $this->FontSizePt;
  4776. $save_currentfontstyle = $this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  4777. if ($blockdir == 'rtl') { $rtlalign = 'R'; } else { $rtlalign = 'L'; }
  4778. foreach ($this->objectbuffer AS $ib => $objattr) {
  4779. if ($objattr['type'] == 'bookmark' || $objattr['type'] == 'indexentry' || $objattr['type'] == 'toc') {
  4780. $x = $objattr['OUTER-X'];
  4781. $y = $objattr['OUTER-Y'];
  4782. $this->y = $y - $this->FontSize/2;
  4783. $this->x = $x;
  4784. if ($objattr['type'] == 'bookmark' ) { $this->Bookmark($objattr['CONTENT'],$objattr['bklevel'] ,$y - $this->FontSize); } // *BOOKMARKS*
  4785. if ($objattr['type'] == 'indexentry') { $this->IndexEntry($objattr['CONTENT']); } // *INDEX*
  4786. if ($objattr['type'] == 'toc') { $this->TOC_Entry($objattr['CONTENT'], $objattr['toclevel'], $objattr['toc_id']); } // *TOC*
  4787. }
  4788. /*-- ANNOTATIONS --*/
  4789. else if ($objattr['type'] == 'annot') {
  4790. if ($objattr['POS-X']) { $x = $objattr['POS-X']; }
  4791. else if ($this->annotMargin<>0) { $x = -$objattr['OUTER-X']; }
  4792. else { $x = $objattr['OUTER-X']; }
  4793. if ($objattr['POS-Y']) { $y = $objattr['POS-Y']; }
  4794. else { $y = $objattr['OUTER-Y'] - $this->FontSize/2; }
  4795. // Create a dummy entry in the _out/columnBuffer with position sensitive data,
  4796. // linking $y-1 in the Columnbuffer with entry in $this->columnAnnots
  4797. // and when columns are split in length will not break annotation from current line
  4798. $this->y = $y-1;
  4799. $this->x = $x-1;
  4800. $this->Line($x-1,$y-1,$x-1,$y-1);
  4801. $this->Annotation($objattr['CONTENT'], $x , $y , $objattr['ICON'], $objattr['AUTHOR'], $objattr['SUBJECT'], $objattr['OPACITY'], $objattr['COLOR'], $objattr['POPUP'], $objattr['FILE']);
  4802. }
  4803. /*-- END ANNOTATIONS --*/
  4804. else {
  4805. $y = $objattr['OUTER-Y'];
  4806. $x = $objattr['OUTER-X'];
  4807. $w = $objattr['OUTER-WIDTH'];
  4808. $h = $objattr['OUTER-HEIGHT'];
  4809. if (isset($objattr['text'])) { $texto = $objattr['text']; }
  4810. $this->y = $y;
  4811. $this->x = $x;
  4812. if (isset($objattr['fontfamily'])) { $this->SetFont($objattr['fontfamily'],'',$objattr['fontsize'] ); }
  4813. }
  4814. // HR
  4815. if ($objattr['type'] == 'hr') {
  4816. $this->SetDColor($objattr['color']);
  4817. switch($objattr['align']) {
  4818. case 'C':
  4819. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4820. $empty /= 2;
  4821. $x += $empty;
  4822. break;
  4823. case 'R':
  4824. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4825. $x += $empty;
  4826. break;
  4827. }
  4828. $oldlinewidth = $this->LineWidth;
  4829. $this->SetLineWidth($objattr['linewidth']/$k );
  4830. $this->y += ($objattr['linewidth']/2) + $objattr['margin_top']/$k;
  4831. $this->Line($x,$this->y,$x+$objattr['INNER-WIDTH'],$this->y);
  4832. $this->SetLineWidth($oldlinewidth);
  4833. $this->SetDColor($this->ConvertColor(0));
  4834. }
  4835. // IMAGE
  4836. if ($objattr['type'] == 'image') {
  4837. // mPDF 5.6.01 - LAYERS
  4838. if (isset($objattr['z-index']) && $objattr['z-index'] > 0 && $this->currentlayer==0) {
  4839. $this->BeginLayer($objattr['z-index']);
  4840. }
  4841. if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) {
  4842. $this->SetVisibility($objattr['visibility']);
  4843. }
  4844. if (isset($objattr['opacity'])) { $this->SetAlpha($objattr['opacity']); }
  4845. $rotate = 0;
  4846. $obiw = $objattr['INNER-WIDTH'];
  4847. $obih = $objattr['INNER-HEIGHT'];
  4848. $sx = $objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w'];
  4849. $sy = abs($objattr['INNER-HEIGHT'])*_MPDFK / abs($objattr['orig_h']);
  4850. $sx = ($objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w']);
  4851. $sy = ($objattr['INNER-HEIGHT']*_MPDFK / $objattr['orig_h']);
  4852. if (isset($objattr['ROTATE'])) { $rotate = $objattr['ROTATE']; }
  4853. if ($rotate==90) {
  4854. // Clockwise
  4855. $obiw = $objattr['INNER-HEIGHT'];
  4856. $obih = $objattr['INNER-WIDTH'];
  4857. $tr = $this->transformTranslate(0, -$objattr['INNER-WIDTH'], true) ;
  4858. $tr .= ' '. $this->transformRotate(90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4859. $sx = $obiw*_MPDFK / $objattr['orig_h'];
  4860. $sy = $obih*_MPDFK / $objattr['orig_w'];
  4861. }
  4862. else if ($rotate==-90 || $rotate==270) {
  4863. // AntiClockwise
  4864. $obiw = $objattr['INNER-HEIGHT'];
  4865. $obih = $objattr['INNER-WIDTH'];
  4866. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], ($objattr['INNER-HEIGHT']-$objattr['INNER-WIDTH']), true) ;
  4867. $tr .= ' '. $this->transformRotate(-90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4868. $sx = $obiw*_MPDFK / $objattr['orig_h'];
  4869. $sy = $obih*_MPDFK / $objattr['orig_w'];
  4870. }
  4871. else if ($rotate==180) {
  4872. // Mirror
  4873. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], -$objattr['INNER-HEIGHT'], true) ;
  4874. $tr .= ' '. $this->transformRotate(180, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ),true) ;
  4875. }
  4876. else { $tr = ''; }
  4877. $tr = trim($tr);
  4878. if ($tr) { $tr .= ' '; }
  4879. $gradmask = '';
  4880. /*-- BACKGROUNDS --*/
  4881. if (isset($objattr['GRADIENT-MASK'])) {
  4882. $g = $this->grad->parseMozGradient( $objattr['GRADIENT-MASK'] );
  4883. if ($g) {
  4884. $dummy = $this->grad->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true, true);
  4885. $gradmask = '/TGS'.count($this->gradients).' gs ';
  4886. // $this->_out("q ".$tr.$this->grad->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true)." Q");
  4887. }
  4888. }
  4889. /*-- END BACKGROUNDS --*/
  4890. /*-- IMAGES-WMF --*/
  4891. if (isset($objattr['itype']) && $objattr['itype']=='wmf') {
  4892. $outstring = sprintf('q '.$tr.'%.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*_MPDFK-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*_MPDFK)+$sy*$objattr['wmf_y'], $objattr['ID']);
  4893. }
  4894. else
  4895. /*-- END IMAGES-WMF --*/
  4896. if (isset($objattr['itype']) && $objattr['itype']=='svg') {
  4897. $outstring = sprintf('q '.$tr.'%.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*_MPDFK-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*_MPDFK)+$sy*$objattr['wmf_y'], $objattr['ID']);
  4898. }
  4899. else {
  4900. $outstring = sprintf("q ".$tr."%.3F 0 0 %.3F %.3F %.3F cm ".$gradmask."/I%d Do Q",$obiw*_MPDFK, $obih*_MPDFK, $objattr['INNER-X'] *_MPDFK, ($this->h-($objattr['INNER-Y'] +$obih ))*_MPDFK,$objattr['ID'] );
  4901. }
  4902. $this->_out($outstring);
  4903. // LINK
  4904. if (isset($objattr['link'])) $this->Link($objattr['INNER-X'],$objattr['INNER-Y'],$objattr['INNER-WIDTH'],$objattr['INNER-HEIGHT'],$objattr['link']);
  4905. if (isset($objattr['opacity'])) { $this->SetAlpha(1); }
  4906. 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); }
  4907. if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) {
  4908. $this->SetVisibility('visible');
  4909. }
  4910. // mPDF 5.6.01 - LAYERS
  4911. if (isset($objattr['z-index']) && $objattr['z-index'] > 0 && $this->currentlayer==0) {
  4912. $this->EndLayer();
  4913. }
  4914. }
  4915. /*-- BARCODES --*/
  4916. // BARCODE
  4917. if ($objattr['type'] == 'barcode') {
  4918. $bgcol = $this->ConvertColor(255);
  4919. if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
  4920. $bgcol = $objattr['bgcolor'];
  4921. }
  4922. $col = $this->ConvertColor(0);
  4923. if (isset($objattr['color']) && $objattr['color']) {
  4924. $col = $objattr['color'];
  4925. }
  4926. $this->SetFColor($bgcol);
  4927. $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
  4928. $this->SetFColor($this->ConvertColor(255));
  4929. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4930. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  4931. $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);
  4932. }
  4933. // QR-code
  4934. else if ($objattr['btype']=='QR') {
  4935. if (!class_exists('QRcode', false)) {
  4936. include(_MPDF_PATH.'qrcode/qrcode.class.php');
  4937. }
  4938. $this->qrcode = new QRcode($objattr['code'], $objattr['errorlevel']);
  4939. $this->qrcode->displayFPDF($this, $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize']*25, array(255,255,255), array(0,0,0));
  4940. }
  4941. else {
  4942. $this->WriteBarcode2($objattr['code'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k);
  4943. }
  4944. }
  4945. /*-- END BARCODES --*/
  4946. // TEXT CIRCLE
  4947. if ($objattr['type'] == 'textcircle') {
  4948. $bgcol = ''; // mPDF 5.5.14
  4949. if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
  4950. $bgcol = $objattr['bgcolor'];
  4951. }
  4952. $col = $this->ConvertColor(0);
  4953. if (isset($objattr['color']) && $objattr['color']) {
  4954. $col = $objattr['color'];
  4955. }
  4956. $this->SetTColor($col);
  4957. $this->SetFColor($bgcol);
  4958. if ($bgcol) $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F'); // mPDF 5.5.14
  4959. $this->SetFColor($this->ConvertColor(255));
  4960. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4961. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  4962. if (empty($this->directw)) { $this->directw = new directw($this); }
  4963. $save_lmfs = $this->linemaxfontsize;
  4964. $this->linemaxfontsize = 0;
  4965. if (isset($objattr['top-text'])) {
  4966. $this->directw->CircularText($objattr['INNER-X']+$objattr['INNER-WIDTH']/2, $objattr['INNER-Y']+$objattr['INNER-HEIGHT']/2, $objattr['r']/$k, $objattr['top-text'], 'top', $objattr['fontfamily'], $objattr['fontsize']/$k, $objattr['fontstyle'], $objattr['space-width'], $objattr['char-width'], $objattr['divider']); // mPDF 5.5.23
  4967. }
  4968. if (isset($objattr['bottom-text'])) {
  4969. $this->directw->CircularText($objattr['INNER-X']+$objattr['INNER-WIDTH']/2, $objattr['INNER-Y']+$objattr['INNER-HEIGHT']/2, $objattr['r']/$k, $objattr['bottom-text'], 'bottom', $objattr['fontfamily'], $objattr['fontsize']/$k, $objattr['fontstyle'], $objattr['space-width'], $objattr['char-width'], $objattr['divider']); // mPDF 5.5.23
  4970. }
  4971. $this->linemaxfontsize = $save_lmfs;
  4972. }
  4973. $this->ResetSpacing();
  4974. // DOT-TAB
  4975. if ($objattr['type'] == 'dottab') {
  4976. // mPDF 5.6.19
  4977. if (isset($objattr['fontfamily'])) { $this->SetFont($objattr['fontfamily'],'',$objattr['fontsize'] ); }
  4978. $sp = $this->GetStringWidth(' ');
  4979. $nb=floor(($w-2*$sp)/$this->GetStringWidth('.'));
  4980. if ($nb>0) { $dots=' '.str_repeat('.',$nb).' '; }
  4981. else { $dots=' '; }
  4982. $col = $this->ConvertColor(0);
  4983. if (isset($objattr['colorarray']) && ($objattr['colorarray'])) { // mPDF 5.6.19
  4984. $col = $objattr['colorarray'];
  4985. }
  4986. $this->SetTColor($col);
  4987. $save_dh = $this->divheight; // mPDF 5.6.19
  4988. $save_sbd = $this->spanborddet;
  4989. $save_u = $this->U;
  4990. $save_s = $this->strike;
  4991. $this->spanborddet = '';
  4992. $this->divheight = 0; // mPDF 5.6.19
  4993. $this->U = false;
  4994. $this->strike = false;
  4995. $this->Cell($w,$h,$dots,0,0,'C');
  4996. $this->spanborddet = $save_sbd;
  4997. $this->U = $save_u;
  4998. $this->strike = $save_s;
  4999. $this->divheight = $save_dh; // mPDF 5.6.19
  5000. // mPDF 5.0
  5001. $this->SetTColor($this->ConvertColor(0));
  5002. }
  5003. /*-- FORMS --*/
  5004. // TEXT/PASSWORD INPUT
  5005. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD')) {
  5006. $this->form->print_ob_text($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  5007. }
  5008. // TEXTAREA
  5009. if ($objattr['type'] == 'textarea') {
  5010. $this->form->print_ob_textarea($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  5011. }
  5012. // SELECT
  5013. if ($objattr['type'] == 'select') {
  5014. $this->form->print_ob_select($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  5015. }
  5016. // INPUT/BUTTON as IMAGE
  5017. if ($objattr['type'] == 'input' && $objattr['subtype'] == 'IMAGE') {
  5018. $this->form->print_ob_imageinput($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  5019. }
  5020. // BUTTON
  5021. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'SUBMIT' || $objattr['subtype'] == 'RESET' || $objattr['subtype'] == 'BUTTON')) {
  5022. $this->form->print_ob_button($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  5023. }
  5024. // CHECKBOX
  5025. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'CHECKBOX')) {
  5026. $this->form->print_ob_checkbox($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y);
  5027. }
  5028. // RADIO
  5029. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'RADIO')) {
  5030. $this->form->print_ob_radio($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y);
  5031. }
  5032. /*-- END FORMS --*/
  5033. }
  5034. $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize);
  5035. $this->y = $save_y;
  5036. $this->x = $save_x;
  5037. unset($content);
  5038. }
  5039. function WriteFlowingBlock( $s)
  5040. {
  5041. $currentx = $this->x;
  5042. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  5043. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  5044. // width of all the content so far in points
  5045. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  5046. // cell width in points
  5047. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  5048. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  5049. // line height in user units
  5050. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  5051. $align =& $this->flowingBlockAttr[ 'align' ];
  5052. $content =& $this->flowingBlockAttr[ 'content' ];
  5053. $contentB =& $this->flowingBlockAttr[ 'contentB' ];
  5054. $font =& $this->flowingBlockAttr[ 'font' ];
  5055. $valign =& $this->flowingBlockAttr[ 'valign' ];
  5056. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  5057. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  5058. $blockdir = $this->flowingBlockAttr['blockdir'];
  5059. // *********** BLOCK BACKGROUND COLOR ***************** //
  5060. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  5061. $fill = 0;
  5062. }
  5063. else {
  5064. $this->SetFColor($this->ConvertColor(255));
  5065. $fill = 0;
  5066. }
  5067. $font[] = $this->saveFont();
  5068. $content[] = '';
  5069. $contentB[] = '';
  5070. $currContent =& $content[ count( $content ) - 1 ];
  5071. // where the line should be cutoff if it is to be justified
  5072. $cutoffWidth = $contentWidth;
  5073. $CJKoverflow = false;
  5074. $hanger = ''; // mPDF 5.6.40
  5075. // COLS
  5076. $oldcolumn = $this->CurrCol;
  5077. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5078. /*-- TABLES --*/
  5079. if ($is_table) {
  5080. $ipaddingL = 0;
  5081. $ipaddingR = 0;
  5082. $paddingL = 0;
  5083. $paddingR = 0;
  5084. $cpaddingadjustL = 0;
  5085. $cpaddingadjustR = 0;
  5086. // Added mPDF 3.0
  5087. $fpaddingR = 0;
  5088. $fpaddingL = 0;
  5089. }
  5090. else {
  5091. /*-- END TABLES --*/
  5092. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  5093. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  5094. $paddingL = ($ipaddingL * _MPDFK);
  5095. $paddingR = ($ipaddingR * _MPDFK);
  5096. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  5097. $cpaddingadjustL = -$this->cMarginL;
  5098. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  5099. $cpaddingadjustR = -$this->cMarginR;
  5100. // Added mPDF 3.0 Float DIV
  5101. $fpaddingR = 0;
  5102. $fpaddingL = 0;
  5103. /*-- CSS-FLOAT --*/
  5104. if (count($this->floatDivs)) {
  5105. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  5106. if ($r_exists) { $fpaddingR = $r_width; }
  5107. if ($l_exists) { $fpaddingL = $l_width; }
  5108. }
  5109. /*-- END CSS-FLOAT --*/
  5110. $usey = $this->y + 0.002;
  5111. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  5112. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  5113. }
  5114. /*-- CSS-IMAGE-FLOAT --*/
  5115. // If float exists at this level
  5116. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  5117. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  5118. /*-- END CSS-IMAGE-FLOAT --*/
  5119. } // *TABLES*
  5120. //OBJECTS - IMAGES & FORM Elements (NB has already skipped line/page if required - in printbuffer)
  5121. if (substr($s,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  5122. $objattr = $this->_getObjAttr($s);
  5123. $h_corr = 0;
  5124. if ($is_table) { // *TABLES*
  5125. $maximumW = ($maxWidth/_MPDFK) - ($this->cellPaddingL + $this->cMarginL + $this->cellPaddingR + $this->cMarginR); // *TABLES*
  5126. } // *TABLES*
  5127. else { // *TABLES*
  5128. 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']; }
  5129. $maximumW = ($maxWidth/_MPDFK) - ($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 );
  5130. } // *TABLES*
  5131. $objattr = $this->inlineObject($objattr['type'],$this->lMargin + $fpaddingL + ($contentWidth/_MPDFK),($this->y + $h_corr), $objattr, $this->lMargin,($contentWidth/_MPDFK),$maximumW,$lineHeight,true,$is_table);
  5132. // SET LINEHEIGHT for this line ================ RESET AT END
  5133. $lineHeight = MAX($lineHeight,$objattr['OUTER-HEIGHT']);
  5134. $this->objectbuffer[count($content)-1] = $objattr;
  5135. // if (isset($objattr['vertical-align'])) { $valign = $objattr['vertical-align']; }
  5136. // else { $valign = ''; }
  5137. $contentWidth += ($objattr['OUTER-WIDTH'] * _MPDFK);
  5138. return;
  5139. }
  5140. $lbw = $rbw = 0; // Border widths
  5141. if (!empty($this->spanborddet)) {
  5142. if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w'];
  5143. if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w'];
  5144. }
  5145. if ($this->usingCoreFont) {
  5146. $tmp = strlen( $s );
  5147. }
  5148. else {
  5149. $tmp = mb_strlen( $s, $this->mb_enc );
  5150. }
  5151. // for every character in the string
  5152. for ( $i = 0; $i < $tmp; $i++ ) {
  5153. // extract the current character
  5154. // get the width of the character in points
  5155. if ($this->usingCoreFont) {
  5156. $c = $s[$i];
  5157. // Soft Hyphens chr(173)
  5158. $cw = ($this->GetCharWidthCore($c) * _MPDFK);
  5159. if ($this->kerning && $this->useKerning && $i > 0) {
  5160. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$c])) {
  5161. $cw += ($this->CurrentFont['kerninfo'][$s[($i-1)]][$c] * $this->FontSizePt / 1000 );
  5162. }
  5163. }
  5164. }
  5165. else {
  5166. $c = mb_substr($s,$i,1,$this->mb_enc );
  5167. $cw = ($this->GetCharWidthNonCore($c, false) * _MPDFK);
  5168. if ($this->kerning && $this->useKerning && $i > 0) {
  5169. $lastc = mb_substr($s,($i-1),1,$this->mb_enc );
  5170. $ulastc = $this->UTF8StringToArray($lastc, false);
  5171. $uc = $this->UTF8StringToArray($c, false);
  5172. if (isset($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]])) {
  5173. $cw += ($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]] * $this->FontSizePt / 1000 );
  5174. }
  5175. }
  5176. }
  5177. if ($i==0) {
  5178. $cw += $lbw*_MPDFK;
  5179. $contentB[(count($contentB)-1)] .= 'L';
  5180. }
  5181. if ($i==($tmp-1)) {
  5182. $cw += $rbw*_MPDFK;
  5183. $contentB[(count($contentB)-1)] .= 'R';
  5184. }
  5185. // mPDF 5.6.45
  5186. if ($c==' ') {
  5187. $currContent .= $c;
  5188. $cutoffWidth = $contentWidth;
  5189. $contentWidth += $cw;
  5190. continue;
  5191. }
  5192. // ADDED for Paragraph_indent
  5193. $WidthCorrection = 0;
  5194. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  5195. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5196. $WidthCorrection = ($ti*_MPDFK);
  5197. }
  5198. // Added mPDF 3.0 Float DIV
  5199. $fpaddingR = 0;
  5200. $fpaddingL = 0;
  5201. /*-- CSS-FLOAT --*/
  5202. if (count($this->floatDivs)) {
  5203. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  5204. if ($r_exists) { $fpaddingR = $r_width; }
  5205. if ($l_exists) { $fpaddingL = $l_width; }
  5206. }
  5207. /*-- END CSS-FLOAT --*/
  5208. $usey = $this->y + 0.002;
  5209. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  5210. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  5211. }
  5212. /*-- CSS-IMAGE-FLOAT --*/
  5213. // If float exists at this level
  5214. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  5215. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  5216. /*-- END CSS-IMAGE-FLOAT --*/
  5217. // try adding another char
  5218. if (( $contentWidth + $cw > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) + 0.001)) {// 0.001 is to correct for deviations converting mm=>pts
  5219. // it won't fit, output what we already have
  5220. $lineCount++;
  5221. // contains any content that didn't make it into this print
  5222. $savedContent = '';
  5223. $savedContentB = '';
  5224. $savedFont = array();
  5225. $savedObj = array();
  5226. // mPDF 5.6.20
  5227. $savedPreContent = array();
  5228. $savedPreContentB = array();
  5229. $savedPreFont = array();
  5230. // cut off and save any partial words at the end of the string
  5231. $words = explode( ' ', $currContent );
  5232. ///////////////////
  5233. // HYPHENATION
  5234. $currWord = $words[count($words)-1] ;
  5235. $success = false;
  5236. // mPDF 5.6.21 Hard Hyphens -
  5237. $hardsuccess = false;
  5238. if ($this->textparam['hyphens'] != 2 && preg_match("/\-/",$currWord)) {
  5239. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5240. list($hardsuccess,$pre,$post,$prelength) = $this->hardHyphenate($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidth("-", false)) );
  5241. if ($hardsuccess) {
  5242. $already = array_pop( $words );
  5243. $forward = mb_substr($already,$prelength+1,mb_strlen($already, $this->mb_enc), $this->mb_enc);
  5244. $words[] = $pre.'-';
  5245. $words[] = $forward;
  5246. $currContent = mb_substr($currContent,0,mb_strlen($currContent, $this->mb_enc)+1-mb_strlen($post, $this->mb_enc), $this->mb_enc) . '-';
  5247. }
  5248. }
  5249. /*-- HYPHENATION --*/
  5250. // Soft Hyphens chr(173)
  5251. else if ($this->textparam['hyphens'] != 2 && (!$this->usingCoreFont && preg_match("/\xc2\xad/",$currWord)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$currWord) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) { // mPDF 5.6.06
  5252. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5253. list($success,$pre,$post,$prelength) = $this->softHyphenate($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidth(" ", false)) );
  5254. }
  5255. if (!$success && !$hardsuccess && $this->textparam['hyphens'] == 1 ) { // mPDF 5.6.06 // mPDF 5.6.21
  5256. // Look ahead to get current word
  5257. for($ac = $i; $ac<(mb_strlen($s)-1); $ac++) {
  5258. $addc = mb_substr($s,$ac,1,$this->mb_enc );
  5259. if ($addc == ' ') { break; }
  5260. $currWord .= $addc;
  5261. }
  5262. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5263. list($success,$pre,$post,$prelength) = $this->hyphenateWord($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidth(" ", false)) );
  5264. }
  5265. if ($success) {
  5266. $already = array_pop( $words );
  5267. $forward = mb_substr($already,$prelength,mb_strlen($already, $this->mb_enc), $this->mb_enc);
  5268. $words[] = $pre.'-';
  5269. $words[] = $forward;
  5270. $currContent = mb_substr($currContent,0,mb_strlen($currContent, $this->mb_enc)+1-mb_strlen($post, $this->mb_enc), $this->mb_enc) . '-';
  5271. }
  5272. /*-- END HYPHENATION --*/
  5273. // mPDF 5.6.13 Decimal alignment (cancel if wraps to > 1 line)
  5274. if ($is_table && substr($align,0,1)=='D' ) { $align=substr($align,2,1); }
  5275. /*-- CJK-FONTS --*/
  5276. // mPDF 5.6.42
  5277. if ($this->checkCJK) {
  5278. $lastchar = mb_substr($words[(count($words)-1)],mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  5279. }
  5280. // Next character is suitable to add as overhanging or squeezed punctuation
  5281. if ($this->checkCJK && preg_match("/[".$this->CJKoverflow."]/u", $c) && $this->allowCJKorphans && !$CJKoverflow) {
  5282. // add character onto this line
  5283. $currContent .= $c;
  5284. $cutoffWidth = $contentWidth;
  5285. $contentWidth += $cw;
  5286. $CJKoverflow = true;
  5287. continue;
  5288. }
  5289. // Last character that fits is not allowed to end a line - move lastchar(s) to start of next line
  5290. else if ($this->checkCJK && preg_match("/[".$this->CJKleading."]/u", $lastchar)) {
  5291. //move lastchar(s) to next line
  5292. $m0 = $lastchar;
  5293. $m1 = $c;
  5294. while(preg_match("/[".$this->CJKleading."]/u", $m0) && mb_strlen($words[(count($words)-1)], $this->mb_enc)>2) {
  5295. // trim last letter off word[0]
  5296. $words[(count($words)-1)] = mb_substr($words[(count($words)-1)],0,mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, $this->mb_enc);
  5297. // and add it to savedContent for next line
  5298. $savedContent = $m0.$savedContent;
  5299. $m1 = $lastchar;
  5300. $lastchar = mb_substr($words[(count($words)-1)],mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  5301. $m0 = $lastchar;
  5302. }
  5303. $lastContent = '';
  5304. for ( $w = 0; $w < count( $words ) ; $w++) { $lastContent .= $words[ $w ]." "; }
  5305. $savedFont = $this->saveFont();
  5306. // replace the current content with the cropped version
  5307. $currContent = rtrim( $lastContent );
  5308. }
  5309. // Next character is not allowed to start a new line
  5310. else if ($this->checkCJK && preg_match("/[".$this->CJKfollowing."]/u", $c)) {
  5311. // try squeezing another character(s) onto this line = Oikomi
  5312. if ($this->allowCJKorphans && !$CJKoverflow) { // mPDF 5.6.40
  5313. $lookahead = mb_substr($s,$i+1,1,$this->mb_enc );
  5314. //if lookahead is not another following char
  5315. if (!$lookahead || ($lookahead && !preg_match("/[".$this->CJKfollowing."]/u", $lookahead))) {
  5316. $currContent .= $c;
  5317. $cutoffWidth = $contentWidth;
  5318. $contentWidth += $cw;
  5319. if ($this->allowCJKoverflow && preg_match("/[".$this->CJKoverflow."]/u", $c)) { $CJKoverflow = true; }
  5320. continue;
  5321. }
  5322. }
  5323. // or move lastchar(s) to next line to keep $c company = Oidashi
  5324. $m0 = $lastchar;
  5325. $m1 = $c;
  5326. while(preg_match("/[".$this->CJKfollowing."]/u", $m1) && mb_strlen($words[(count($words)-1)], $this->mb_enc)>2) {
  5327. // trim last letter off word[0]
  5328. $words[(count($words)-1)] = mb_substr($words[(count($words)-1)],0,mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, $this->mb_enc);
  5329. // and add it to savedContent for next line
  5330. $savedContent = $m0.$savedContent;
  5331. $m1 = $lastchar;
  5332. $lastchar = mb_substr($words[(count($words)-1)],mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  5333. $m0 = $lastchar;
  5334. }
  5335. $lastContent = '';
  5336. for ( $w = 0; $w < count( $words ) ; $w++) { $lastContent .= $words[ $w ]." "; }
  5337. $savedFont = $this->saveFont();
  5338. // replace the current content with the cropped version
  5339. $currContent = rtrim( $lastContent );
  5340. }
  5341. // mPDF 5.6.42
  5342. else if ($this->checkCJK && preg_match("/([".$this->pregCJKchars."]+[0-9\x{ff10}-\x{ff19}]+$)/u", $words[0])) {
  5343. $lookahead = mb_substr($s,$i,16,$this->mb_enc );
  5344. //and if lookahead starts with a few numerals
  5345. if ($lookahead && (preg_match("/^([0-9\x{ff10}-\x{ff19}]+[".$this->pregCJKchars."]+)/u", $lookahead) || preg_match("/^([0-9\x{ff10}-\x{ff19}]+$)/u", $lookahead)) ) {
  5346. // or move lastchar(s) to next line to keep numerals together
  5347. $m0 = $lastchar;
  5348. while(preg_match("/[0-9\x{ff10}-\x{ff19}]/u", $m0) && mb_strlen($words[(count($words)-1)], $this->mb_enc)>2) {
  5349. // trim last letter off word[0]
  5350. $words[(count($words)-1)] = mb_substr($words[(count($words)-1)],0,mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, $this->mb_enc);
  5351. // and add it to savedContent for next line
  5352. $savedContent = $m0.$savedContent;
  5353. $lastchar = mb_substr($words[(count($words)-1)],mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  5354. $m0 = $lastchar;
  5355. }
  5356. }
  5357. $lastContent = '';
  5358. for ( $w = 0; $w < count( $words ) ; $w++) { $lastContent .= $words[ $w ]." "; }
  5359. $savedFont = $this->saveFont();
  5360. // replace the current content with the cropped version
  5361. $currContent = rtrim( $lastContent );
  5362. }
  5363. else
  5364. /*-- END CJK-FONTS --*/
  5365. // if it looks like we didn't finish any words for this chunk
  5366. if ( count( $words ) == 1 ) {
  5367. // TO correct for error when word too wide for page - but only when one long word from left to right margin
  5368. if (count($content) == 1 && $currContent != ' ') {
  5369. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5370. $lastContent = $words[0];
  5371. $savedFont = $this->saveFont();
  5372. // replace the current content with the cropped version
  5373. $currContent = rtrim( $lastContent );
  5374. }
  5375. // mPDF 5.6.20
  5376. else if ( count($content)>1
  5377. && (!isset($this->objectbuffer[(count($content)-1)]) && !isset($this->objectbuffer[(count($content)-2)]))
  5378. && substr($content[count($content)-2],-1,1) != ' '
  5379. && substr($currContent,0,1) != ' '
  5380. ) {
  5381. // Go back to find a space in a previous chunk of content
  5382. $found = false;
  5383. for ($ix=count($content)-1;$ix>=0;$ix--) {
  5384. // mPDF 5.6.29
  5385. if ($this->usingCoreFont && preg_match('/[ '.chr(173).']/',$content[$ix],$m)) { $match = $m[0]; $found = $ix; break; }
  5386. else if (!$this->usingCoreFont) {
  5387. if (preg_match('/[ ]/',$content[$ix])) { $match = ' '; $found = $ix; break; }
  5388. else if (preg_match('/[\x{00AD}]/u',$content[$ix])) {
  5389. // even though it is UTF-8 replace it temporarily with chr(173)
  5390. $content[$ix] = preg_replace('/[\x{00AD}]/u',chr(173),$content[$ix]);
  5391. $match = chr(173); $found = $ix; break;
  5392. }
  5393. }
  5394. }
  5395. if ($found !== false) {
  5396. $charpos = strrpos($content[$found],$match); // mPDF 5.6.29
  5397. for ($ix=count($content)-1;$ix>$found;$ix--) {
  5398. // save and crop off any subsequent chunks
  5399. $savedPreContent[] = array_pop($content);
  5400. $savedPreContentB[] = array_pop($contentB);
  5401. $savedPreFont[] = array_pop($font);
  5402. }
  5403. if (substr($content[count($content)-1],$charpos+1,strlen($content[count($content)-1])-1) != '') {
  5404. $savedPreContent[] = substr($content[count($content)-1],$charpos+1,strlen($content[count($content)-1])-1);
  5405. $savedPreContentB[] = preg_replace('/L/','',$contentB[count($content)-1]); // ???
  5406. $savedPreFont[] = $font[count($content)-1];
  5407. }
  5408. $savedContent = '';
  5409. $savedContentB = '';
  5410. $savedFont = array();
  5411. $currContent =& $content[ count( $content ) - 1 ];
  5412. $currContent = substr($currContent,0,$charpos);
  5413. if ($match == chr(173)) { $currContent .= '-'; } // mPDF 5.6.29
  5414. if (strpos($contentB[(count($contentB)-1)],'R')!==false) { // ???
  5415. $contentB[count($content)-1] = preg_replace('/R/','',$contentB[count($content)-1]); // ???
  5416. }
  5417. $currContent = rtrim( $currContent );
  5418. }
  5419. else {
  5420. $savedContent = array_pop( $content );
  5421. $savedContentB = array_pop($contentB);
  5422. $savedFont = array_pop( $font );
  5423. $currContent =& $content[ count( $content ) - 1 ];
  5424. $currContent = rtrim( $currContent );
  5425. }
  5426. }
  5427. else {
  5428. // save and crop off the content currently on the stack
  5429. $savedContent = array_pop( $content );
  5430. $savedContentB = array_pop($contentB); // mPDF 5.6.20
  5431. $savedFont = array_pop( $font );
  5432. // trim any trailing spaces off the last bit of content
  5433. $currContent =& $content[ count( $content ) - 1 ];
  5434. $currContent = rtrim( $currContent );
  5435. }
  5436. }
  5437. else { // otherwise, we need to find which bit to cut off
  5438. $lastContent = '';
  5439. for ( $w = 0; $w < count( $words ) - 1; $w++) { $lastContent .= $words[ $w ]." "; }
  5440. $savedContent = $words[ count( $words ) - 1 ];
  5441. $savedFont = $this->saveFont();
  5442. // replace the current content with the cropped version
  5443. $currContent = rtrim( $lastContent );
  5444. }
  5445. // CJK - strip CJK space at end of line
  5446. // &#x3000; = \xe3\x80\x80 = CJK space
  5447. if ($this->checkCJK) { $currContent = preg_replace("/\xe3\x80\x80$/",'',$currContent) ; } // *CJK-FONTS*
  5448. if (isset($this->objectbuffer[(count($content)-1)]) && $this->objectbuffer[(count($content)-1)]['type']=='dottab') {
  5449. $savedObj = array_pop( $this->objectbuffer );
  5450. $contentWidth -= ($this->objectbuffer[(count($content)-1)]['OUTER-WIDTH'] * _MPDFK);
  5451. }
  5452. // Set Current lineheight (correction factor)
  5453. $lhfixed = false;
  5454. /*-- LISTS --*/
  5455. if ($is_list) {
  5456. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  5457. $lhfixed = true;
  5458. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  5459. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5460. }
  5461. else {
  5462. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  5463. }
  5464. }
  5465. else
  5466. /*-- END LISTS --*/
  5467. /*-- TABLES --*/
  5468. if ($is_table) {
  5469. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  5470. $lhfixed = true;
  5471. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  5472. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  5473. }
  5474. else {
  5475. $this->lineheight_correction = $this->table_lineheight;
  5476. }
  5477. }
  5478. else
  5479. /*-- END TABLES --*/
  5480. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  5481. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  5482. $lhfixed = true;
  5483. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  5484. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5485. }
  5486. else {
  5487. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  5488. }
  5489. }
  5490. else {
  5491. $this->lineheight_correction = $this->normalLineheight;
  5492. }
  5493. // update $contentWidth and $cutoffWidth since they changed with cropping
  5494. // Also correct lineheight to maximum fontsize (not for tables)
  5495. $contentWidth = 0;
  5496. // correct lineheight to maximum fontsize
  5497. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  5498. else { $maxlineHeight = 0; }
  5499. $this->forceExactLineheight = true;
  5500. $maxfontsize = 0;
  5501. // While we're at it, check for cursive text
  5502. $checkCursive=false;
  5503. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  5504. foreach ( $content as $k => $chunk )
  5505. {
  5506. $this->restoreFont( $font[ $k ]);
  5507. if (!isset($this->objectbuffer[$k])) {
  5508. // mPDF 5.6.40
  5509. if ($this->checkCJK && $k == count($content)-1 && $CJKoverflow && $align=='J' && $this->allowCJKoverflow && $this->CJKforceend) {
  5510. // force-end overhang
  5511. $hanger = mb_substr($chunk,mb_strlen($chunk,$this->mb_enc)-1,1,$this->mb_enc );
  5512. $content[$k] = $chunk = mb_substr($chunk,0,mb_strlen($chunk,$this->mb_enc)-1,$this->mb_enc );
  5513. }
  5514. if (!$this->usingCoreFont) {
  5515. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  5516. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  5517. }
  5518. // Soft Hyphens chr(173)
  5519. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  5520. $content[$k] = $chunk = str_replace(chr(173),'',$chunk );
  5521. }
  5522. $contentWidth += $this->GetStringWidth( $chunk ) * _MPDFK;
  5523. if (!empty($this->spanborddet)) {
  5524. if (strpos($contentB[$k],'L')!==false) $contentWidth += $this->spanborddet['L']['w'] * _MPDFK;
  5525. if (strpos($contentB[$k],'R')!==false) $contentWidth += $this->spanborddet['R']['w'] * _MPDFK;
  5526. }
  5527. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$this->FontSize * $this->lineheight_correction ); }
  5528. if ($lhfixed && ($this->FontSize > $def_fontsize || ($this->FontSize > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  5529. $this->forceExactLineheight = false;
  5530. }
  5531. $maxfontsize = max($maxfontsize,$this->FontSize);
  5532. }
  5533. }
  5534. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  5535. $lastfontstyle = $font[count($font)-1]['style'];
  5536. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  5537. $lastitalic = $this->FontSize*0.15*_MPDFK;
  5538. }
  5539. else { $lastitalic = 0; }
  5540. /*-- LISTS --*/
  5541. if ($is_list && is_array($this->bulletarray) && $this->bulletarray) {
  5542. $actfs = $this->bulletarray['fontsize'];
  5543. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  5544. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  5545. $maxfontsize = max($maxfontsize,$actfs);
  5546. }
  5547. /*-- END LISTS --*/
  5548. // when every text item checked i.e. $maxfontsize is set properly
  5549. $af = 0; // Above font
  5550. $bf = 0; // Below font
  5551. $mta = 0; // Maximum top-aligned
  5552. $mba = 0; // Maximum bottom-aligned
  5553. foreach ( $content as $k => $chunk ) {
  5554. if (isset($this->objectbuffer[$k]) && $this->objectbuffer[$k]) {
  5555. $contentWidth += $this->objectbuffer[$k]['OUTER-WIDTH'] * _MPDFK;
  5556. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  5557. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  5558. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  5559. if ($va == 'BS') { // (BASELINE default)
  5560. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  5561. }
  5562. else if ($va == 'M') {
  5563. $af = max($af, ($oh - $maxfontsize)/2);
  5564. $bf = max($bf, ($oh - $maxfontsize)/2);
  5565. }
  5566. else if ($va == 'TT') {
  5567. $bf = max($bf, ($oh - $maxfontsize));
  5568. }
  5569. else if ($va == 'TB') {
  5570. $af = max($af, ($oh - $maxfontsize));
  5571. }
  5572. else if ($va == 'T') {
  5573. $mta = max($mta, $oh);
  5574. }
  5575. else if ($va == 'B') {
  5576. $mba = max($mba, $oh);
  5577. }
  5578. }
  5579. }
  5580. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  5581. $maxlineHeight = $maxfontsize + $af + $bf;
  5582. }
  5583. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  5584. if ($mta > $maxlineHeight) {
  5585. $bf += ($mta - $maxlineHeight);
  5586. $maxlineHeight = $mta;
  5587. }
  5588. if ($mba > $maxlineHeight) {
  5589. $af += ($mba - $maxlineHeight);
  5590. $maxlineHeight = $mba;
  5591. }
  5592. $lineHeight = $maxlineHeight;
  5593. $cutoffWidth = $contentWidth;
  5594. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  5595. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  5596. $this->linemaxfontsize = $def_fontsize;
  5597. }
  5598. else { $this->linemaxfontsize = $maxfontsize; }
  5599. $inclCursive=false;
  5600. foreach ( $content as $k => $chunk ) {
  5601. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5602. if ($this->usingCoreFont) {
  5603. $content[$k] = str_replace(chr(160),chr(32),$chunk );
  5604. }
  5605. else {
  5606. $content[$k] = str_replace(chr(194).chr(160),chr(32),$chunk );
  5607. if ($checkCursive) {
  5608. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  5609. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  5610. }
  5611. }
  5612. }
  5613. }
  5614. // JUSTIFICATION J
  5615. $jcharspacing = 0;
  5616. $jws = 0;
  5617. $nb_carac = 0;
  5618. $nb_spaces = 0;
  5619. // 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)
  5620. if ( ($align == 'J' && !$CJKoverflow) || (($cutoffWidth + $lastitalic > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) + 0.001) && (!$CJKoverflow || ($CJKoverflow && !$this->allowCJKoverflow))) || $CJKoverflow && $align=='J' && $this->allowCJKoverflow && $hanger && $this->CJKforceend) { // 0.001 is to correct for deviations converting mm=>pts // mPDF 5.6.40
  5621. // JUSTIFY J (Use character spacing)
  5622. // WORD SPACING
  5623. foreach ( $content as $k => $chunk ) {
  5624. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5625. $nb_carac += mb_strlen( $chunk, $this->mb_enc ) ;
  5626. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc ) ;
  5627. }
  5628. }
  5629. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$cutoffWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive);
  5630. }
  5631. // WORD SPACING
  5632. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5633. $empty -= ($jcharspacing * $nb_carac);
  5634. $empty -= ($jws * $nb_spaces);
  5635. $empty /= _MPDFK;
  5636. $b = ''; //do not use borders
  5637. // Get PAGEBREAK TO TEST for height including the top border/padding
  5638. $check_h = max($this->divheight,$lineHeight);
  5639. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blklvl > 0) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5640. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  5641. }
  5642. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  5643. $this->SetCol($this->NbCol-1);
  5644. }
  5645. // PAGEBREAK
  5646. // 'If' below used in order to fix "first-line of other page with justify on" bug
  5647. if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5648. $bak_x=$this->x;//Current X position
  5649. // WORD SPACING
  5650. $ws=$this->ws;//Word Spacing
  5651. $charspacing=$this->charspacing;//Character Spacing
  5652. $this->ResetSpacing();
  5653. $this->AddPage($this->CurOrientation);
  5654. $this->x = $bak_x;
  5655. // Added to correct for OddEven Margins
  5656. $currentx += $this->MarginCorrection;
  5657. $this->x += $this->MarginCorrection;
  5658. // WORD SPACING
  5659. $this->SetSpacing($charspacing,$ws);
  5660. }
  5661. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  5662. $this->printdivbuffer();
  5663. $this->keep_block_together = 0;
  5664. }
  5665. /*-- COLUMNS --*/
  5666. // COLS
  5667. // COLUMN CHANGE
  5668. if ($this->CurrCol != $oldcolumn) {
  5669. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5670. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5671. $oldcolumn = $this->CurrCol;
  5672. }
  5673. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5674. /*-- END COLUMNS --*/
  5675. // TOP MARGIN
  5676. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5677. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  5678. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5679. }
  5680. // Update y0 for top of block (used to paint border)
  5681. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5682. $this->blk[$this->blklvl]['y0'] = $this->y;
  5683. $this->blk[$this->blklvl]['startpage'] = $this->page;
  5684. if ($this->blk[$this->blklvl]['float']) { $this->blk[$this->blklvl]['float_start_y'] = $this->y; } // mPDF 5.6.63
  5685. }
  5686. // TOP PADDING and BORDER spacing/fill
  5687. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5688. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  5689. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  5690. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5691. }
  5692. $arraysize = count($content);
  5693. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  5694. // PAINT BACKGROUND FOR THIS LINE
  5695. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  5696. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL ;
  5697. if ($align == 'R') { $this->x += $empty; }
  5698. else if ($align == 'C') { $this->x += ($empty / 2); }
  5699. // Paragraph INDENT
  5700. if (isset($this->blk[$this->blklvl]['text_indent']) && ($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && ($blockdir !='rtl') && ($align !='C')) {
  5701. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5702. $this->x += $ti;
  5703. }
  5704. // DIRECTIONALITY RTL
  5705. $all_rtl = false;
  5706. $contains_rtl = false;
  5707. /*-- RTL --*/
  5708. if ($blockdir == 'rtl' || $this->biDirectional) {
  5709. $all_rtl = true;
  5710. foreach ( $content as $k => $chunk ) {
  5711. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir);
  5712. if ($reversed > 0) { $contains_rtl = true; }
  5713. if ($reversed < 2) { $all_rtl = false; }
  5714. $content[$k] = $chunk;
  5715. }
  5716. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) {
  5717. $content = array_reverse($content,false);
  5718. $contentB = array_reverse($contentB,false);
  5719. }
  5720. }
  5721. /*-- END RTL --*/
  5722. foreach ( $content as $k => $chunk ) {
  5723. // FOR IMAGES - UPDATE POSITION
  5724. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $dirk = $arraysize-1 - $k ; } else { $dirk = $k; }
  5725. $va = 'M'; // default for text
  5726. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  5727. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'] ;
  5728. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  5729. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  5730. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  5731. $va = $this->objectbuffer[$dirk]['vertical-align'];
  5732. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  5733. if ($va == 'BS') {
  5734. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5735. }
  5736. else if ($va == 'M' || $va == '') {
  5737. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  5738. }
  5739. else if ($va == 'TB') {
  5740. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5741. }
  5742. else if ($va == 'TT') {
  5743. $yadj += $af;
  5744. }
  5745. else if ($va == 'B') {
  5746. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5747. }
  5748. else if ($va == 'T') {
  5749. $yadj += 0;
  5750. }
  5751. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  5752. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  5753. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  5754. }
  5755. // DIRECTIONALITY RTL
  5756. if ((($blockdir == 'rtl') && ($contains_rtl )) || ($all_rtl )) { $this->restoreFont($font[$arraysize-1 - $k]); }
  5757. else { $this->restoreFont( $font[ $k ] ); }
  5758. $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws);
  5759. // Now unset these values so they don't influence GetStringwidth below or in fn. Cell
  5760. $this->fixedlSpacing = false;
  5761. $this->minwSpacing = 0;
  5762. // mPDF 5.6.26
  5763. $save_vis = $this->visibility;
  5764. if (isset($this->textparam['visibility']) && $this->textparam['visibility'] && $this->textparam['visibility'] != $this->visibility) {
  5765. $this->SetVisibility($this->textparam['visibility']);
  5766. }
  5767. // *********** SPAN BACKGROUND COLOR ***************** //
  5768. if ($this->spanbgcolor) {
  5769. $cor = $this->spanbgcolorarray;
  5770. $this->SetFColor($cor);
  5771. $save_fill = $fill; $spanfill = 1; $fill = 1;
  5772. }
  5773. if (!empty($this->spanborddet)) {
  5774. if (strpos($contentB[$k],'L')!==false) $this->x += $this->spanborddet['L']['w'];
  5775. if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0;
  5776. if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0;
  5777. }
  5778. // WORD SPACING
  5779. $stringWidth = $this->GetStringWidth($chunk );
  5780. $stringWidth += ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK );
  5781. $stringWidth += ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK );
  5782. if (isset($this->objectbuffer[$dirk])) { $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH']; }
  5783. if ($stringWidth==0) { $stringWidth = 0.000001; }
  5784. if ($k == $arraysize-1) {
  5785. $stringWidth -= ( $this->charspacing / _MPDFK );
  5786. // mPDF 5.6.40
  5787. if ($this->checkCJK && $CJKoverflow && $align=='J' && $this->allowCJKoverflow && $hanger && $this->CJKforceend) {
  5788. // force-end overhang
  5789. $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true );
  5790. $this->Cell( $this->GetStringWidth($hanger), $lineHeight, $hanger, '', 1, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true );
  5791. }
  5792. else {
  5793. $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true ); //mono-style line or last part (skips line)
  5794. }
  5795. }
  5796. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part
  5797. if (!empty($this->spanborddet)) {
  5798. if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w'];
  5799. }
  5800. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  5801. if (isset($spanfill) && $spanfill) {
  5802. $fill = $save_fill; $spanfill = 0;
  5803. if ($fill) { $this->SetFColor($bcor); }
  5804. }
  5805. // mPDF 5.6.26
  5806. if (isset($this->textparam['visibility']) && $this->textparam['visibility'] && $this->visibility != $save_vis) {
  5807. $this->SetVisibility($save_vis);
  5808. }
  5809. }
  5810. if (!$is_table) {
  5811. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin']));
  5812. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']));
  5813. }
  5814. // move on to the next line, reset variables, tack on saved content and current char
  5815. $this->printobjectbuffer($is_table, $blockdir);
  5816. $this->objectbuffer = array();
  5817. /*-- LISTS --*/
  5818. // LIST BULLETS/NUMBERS
  5819. if ($is_list && is_array($this->bulletarray) && ($lineCount == 1) ) {
  5820. $this->ResetSpacing();
  5821. $bull = $this->bulletarray;
  5822. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  5823. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  5824. }
  5825. 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']]); }
  5826. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5827. $this->bullet = true;
  5828. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  5829. }
  5830. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  5831. //Output bullet
  5832. $this->x = $currentx;
  5833. if (isset($bull['x'])) { $this->x += $bull['x']; }
  5834. $this->y -= $lineHeight;
  5835. if (isset($bull['col']) && $bull['col']) { $this->SetTColor($bull['col']); } // mPDF 5.6.67
  5836. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  5837. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5838. $this->bullet = false;
  5839. }
  5840. $this->x = $currentx; // Reset
  5841. $this->y += $lineHeight;
  5842. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5843. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  5844. }
  5845. /*-- END LISTS --*/
  5846. /*-- CSS-IMAGE-FLOAT --*/
  5847. // Update values if set to skipline
  5848. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  5849. /*-- END CSS-IMAGE-FLOAT --*/
  5850. // Reset lineheight
  5851. $lineHeight = $this->divheight;
  5852. $valign = 'M';
  5853. $font = array();
  5854. $content = array();
  5855. $contentB = array();
  5856. $contentWidth = 0;
  5857. if (!empty($savedObj)) {
  5858. $this->objectbuffer[] = $savedObj;
  5859. $font[] = $savedFont;
  5860. $content[] = '';
  5861. $contentB[] = '';
  5862. $contentWidth += $savedObj['OUTER-WIDTH'] * _MPDFK;
  5863. }
  5864. // mPDF 5.6.20
  5865. if (count($savedPreContent) > 0) {
  5866. for($ix=count($savedPreContent)-1;$ix>=0;$ix--) {
  5867. $font[] = $savedPreFont[$ix];
  5868. $content[] = $savedPreContent[$ix];
  5869. $contentB[] = $savedPreContentB[$ix];
  5870. $this->restoreFont( $savedPreFont[$ix] );
  5871. $lbw = $rbw = 0; // Border widths
  5872. if (!empty($this->spanborddet)) {
  5873. $lbw = $this->spanborddet['L']['w'];
  5874. $rbw = $this->spanborddet['R']['w'];
  5875. }
  5876. if ($ix>0) {
  5877. $contentWidth += $this->GetStringWidth( $savedPreContent[$ix] ) * _MPDFK;
  5878. if (strpos($savedPreContentB[$ix],'L')!==false) $contentWidth += $lbw;
  5879. if (strpos($savedPreContentB[$ix],'R')!==false) $contentWidth += $rbw;
  5880. }
  5881. }
  5882. $savedPreContent = array();
  5883. $savedPreContentB = array();
  5884. $savedPreFont = array();
  5885. $content[ (count($content)-1) ] .= $c;
  5886. }
  5887. else {
  5888. $font[] = $savedFont;
  5889. $content[] = $savedContent . $c;
  5890. $contentB[] = $savedContentB ;
  5891. }
  5892. $currContent =& $content[ (count($content)-1) ];
  5893. // CJK - strip CJK space at end of line
  5894. // &#x3000; = \xe3\x80\x80 = CJK space
  5895. if ($this->checkCJK && $currContent == "\xe3\x80\x80") { $currContent = '' ; } // *CJK-FONTS*
  5896. $this->restoreFont( $savedFont );
  5897. $lbw = $rbw = 0; // Border widths
  5898. if (!empty($this->spanborddet)) {
  5899. $lbw = $this->spanborddet['L']['w'];
  5900. $rbw = $this->spanborddet['R']['w'];
  5901. }
  5902. $contentWidth += $this->GetStringWidth( $currContent ) * _MPDFK;
  5903. if (strpos($savedContentB,'L')!==false) $contentWidth += $lbw;
  5904. $cutoffWidth = $contentWidth;
  5905. $CJKoverflow = false;
  5906. $hanger = ''; // mPDF 5.6.40
  5907. }
  5908. // another character will fit, so add it on
  5909. else {
  5910. $contentWidth += $cw;
  5911. $currContent .= $c;
  5912. }
  5913. }
  5914. unset($content);
  5915. unset($contentB);
  5916. }
  5917. //----------------------END OF FLOWING BLOCK------------------------------------//
  5918. /*-- CSS-IMAGE-FLOAT --*/
  5919. // Update values if set to skipline
  5920. function _advanceFloatMargins() {
  5921. // Update floatmargins - L
  5922. if (isset($this->floatmargins['L']) && $this->floatmargins['L']['skipline'] && $this->floatmargins['L']['y0'] != $this->y) {
  5923. $yadj = $this->y - $this->floatmargins['L']['y0'];
  5924. $this->floatmargins['L']['y0'] = $this->y;
  5925. $this->floatmargins['L']['y1'] += $yadj;
  5926. // Update objattr in floatbuffer
  5927. if ($this->floatbuffer[$this->floatmargins['L']['id']]['border_left']['w']) {
  5928. $this->floatbuffer[$this->floatmargins['L']['id']]['BORDER-Y'] += $yadj;
  5929. }
  5930. $this->floatbuffer[$this->floatmargins['L']['id']]['INNER-Y'] += $yadj;
  5931. $this->floatbuffer[$this->floatmargins['L']['id']]['OUTER-Y'] += $yadj;
  5932. // Unset values
  5933. $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false;
  5934. $this->floatmargins['L']['skipline'] = false;
  5935. $this->floatmargins['L']['id'] = '';
  5936. }
  5937. // Update floatmargins - R
  5938. if (isset($this->floatmargins['R']) && $this->floatmargins['R']['skipline'] && $this->floatmargins['R']['y0'] != $this->y) {
  5939. $yadj = $this->y - $this->floatmargins['R']['y0'];
  5940. $this->floatmargins['R']['y0'] = $this->y;
  5941. $this->floatmargins['R']['y1'] += $yadj;
  5942. // Update objattr in floatbuffer
  5943. if ($this->floatbuffer[$this->floatmargins['R']['id']]['border_left']['w']) {
  5944. $this->floatbuffer[$this->floatmargins['R']['id']]['BORDER-Y'] += $yadj;
  5945. }
  5946. $this->floatbuffer[$this->floatmargins['R']['id']]['INNER-Y'] += $yadj;
  5947. $this->floatbuffer[$this->floatmargins['R']['id']]['OUTER-Y'] += $yadj;
  5948. // Unset values
  5949. $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false;
  5950. $this->floatmargins['R']['skipline'] = false;
  5951. $this->floatmargins['R']['id'] = '';
  5952. }
  5953. }
  5954. /*-- END CSS-IMAGE-FLOAT --*/
  5955. ////////////////////////////////////////////////////////////////////////////////
  5956. // ADDED forcewrap - to call from inline OBJECT functions to breakwords if necessary in cell
  5957. ////////////////////////////////////////////////////////////////////////////////
  5958. function WordWrap(&$text, $maxwidth, $forcewrap = 0) {
  5959. $biggestword=0;
  5960. $toonarrow=false;
  5961. $text = trim($text);
  5962. if ($text==='') return 0;
  5963. $space = $this->GetCharWidth(' ',false);
  5964. $lines = explode("\n", $text);
  5965. $text = '';
  5966. $count = 0;
  5967. foreach ($lines as $line) {
  5968. $words = explode(' ', $line);
  5969. $width = 0;
  5970. foreach ($words as $word) {
  5971. $word = trim($word);
  5972. $wordwidth = $this->GetStringWidth($word);
  5973. //Warn user that maxwidth is insufficient
  5974. if ($wordwidth > $maxwidth + 0.0001) {
  5975. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  5976. $toonarrow=true;
  5977. // ADDED
  5978. if ($forcewrap) {
  5979. while($wordwidth > $maxwidth) {
  5980. $chw = 0; // check width
  5981. for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) {
  5982. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  5983. if ($chw > $maxwidth ) {
  5984. if ($text) {
  5985. $text = rtrim($text)."\n".mb_substr($word,0,$i,$this->mb_enc );
  5986. $count++;
  5987. }
  5988. else {
  5989. $text = mb_substr($word,0,$i,$this->mb_enc );
  5990. }
  5991. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  5992. $wordwidth = $this->GetStringWidth($word);
  5993. $width = $maxwidth;
  5994. break;
  5995. }
  5996. }
  5997. }
  5998. }
  5999. }
  6000. if ($width + $wordwidth < $maxwidth - 0.0001) {
  6001. $width += $wordwidth + $space;
  6002. $text .= $word.' ';
  6003. }
  6004. else {
  6005. $width = $wordwidth + $space;
  6006. $text = rtrim($text)."\n".$word.' ';
  6007. $count++;
  6008. }
  6009. }
  6010. $text .= "\n";
  6011. $count++;
  6012. }
  6013. $text = rtrim($text);
  6014. //Return -(wordsize) if word is bigger than maxwidth
  6015. // ADDED
  6016. if ($forcewrap) { return $count; }
  6017. if (($toonarrow) && ($this->table_error_report)) {
  6018. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  6019. }
  6020. if ($toonarrow) return -$biggestword;
  6021. else return $count;
  6022. }
  6023. /*-- END HTML-CSS --*/
  6024. function _SetTextRendering($mode) {
  6025. if (!(($mode == 0) || ($mode == 1) || ($mode == 2)))
  6026. $this->Error("Text rendering mode should be 0, 1 or 2 (value : $mode)");
  6027. $tr = ($mode.' Tr');
  6028. 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); }
  6029. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  6030. }
  6031. function SetTextOutline($params=array()) { // mPDF 5.6.07
  6032. if (isset($params['outline-s']) && $params['outline-s'])
  6033. {
  6034. $this->SetLineWidth($params['outline-WIDTH']);
  6035. $this->SetDColor($params['outline-COLOR']);
  6036. $tr = ('2 Tr');
  6037. 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); }
  6038. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  6039. }
  6040. else //Now resets all values
  6041. {
  6042. $this->SetLineWidth(0.2);
  6043. $this->SetDColor($this->ConvertColor(0));
  6044. $this->_SetTextRendering(0);
  6045. $tr = ('0 Tr');
  6046. 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); }
  6047. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  6048. }
  6049. }
  6050. function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$paint=true, $constrain=true, $watermark=false, $shownoimg=true, $allowvector=true) {
  6051. $orig_srcpath = $file;
  6052. $this->GetFullPath($file);
  6053. $info=$this->_getImage($file, true, $allowvector, $orig_srcpath );
  6054. if(!$info && $paint) {
  6055. $info = $this->_getImage($this->noImageFile);
  6056. if ($info) {
  6057. $file = $this->noImageFile;
  6058. $w = ($info['w'] * (25.4/$this->dpi)); // 14 x 16px
  6059. $h = ($info['h'] * (25.4/$this->dpi)); // 14 x 16px
  6060. }
  6061. }
  6062. if(!$info) return false;
  6063. //Automatic width and height calculation if needed
  6064. if($w==0 and $h==0) {
  6065. /*-- IMAGES-WMF --*/
  6066. if ($info['type']=='wmf') {
  6067. // WMF units are twips (1/20pt)
  6068. // divide by 20 to get points
  6069. // divide by k to get user units
  6070. $w = abs($info['w'])/(20*_MPDFK);
  6071. $h = abs($info['h']) / (20*_MPDFK);
  6072. }
  6073. else
  6074. /*-- END IMAGES-WMF --*/
  6075. if ($info['type']=='svg') {
  6076. // returned SVG units are pts
  6077. // divide by k to get user units (mm)
  6078. $w = abs($info['w'])/_MPDFK;
  6079. $h = abs($info['h']) /_MPDFK;
  6080. }
  6081. else {
  6082. //Put image at default image dpi
  6083. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  6084. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  6085. }
  6086. }
  6087. if($w==0) $w=abs($h*$info['w']/$info['h']);
  6088. if($h==0) $h=abs($w*$info['h']/$info['w']);
  6089. /*-- WATERMARK --*/
  6090. if ($watermark) {
  6091. $maxw = $this->w;
  6092. $maxh = $this->h;
  6093. // Size = D PF or array
  6094. if (is_array($this->watermark_size)) {
  6095. $w = $this->watermark_size[0];
  6096. $h = $this->watermark_size[1];
  6097. }
  6098. else if (!is_string($this->watermark_size)) {
  6099. $maxw -= $this->watermark_size*2;
  6100. $maxh -= $this->watermark_size*2;
  6101. $w = $maxw;
  6102. $h=abs($w*$info['h']/$info['w']);
  6103. if ($h > $maxh ) {
  6104. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  6105. }
  6106. }
  6107. else if ($this->watermark_size == 'F') {
  6108. if ($this->ColActive) { $maxw = $this->w - ($this->DeflMargin + $this->DefrMargin); }
  6109. else { $maxw = $this->pgwidth; }
  6110. $maxh = $this->h - ($this->tMargin + $this->bMargin);
  6111. $w = $maxw;
  6112. $h=abs($w*$info['h']/$info['w']);
  6113. if ($h > $maxh ) {
  6114. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  6115. }
  6116. }
  6117. else if ($this->watermark_size == 'P') { // Default P
  6118. $w = $maxw;
  6119. $h=abs($w*$info['h']/$info['w']);
  6120. if ($h > $maxh ) {
  6121. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  6122. }
  6123. }
  6124. // Automatically resize to maximum dimensions of page if too large
  6125. if ($w > $maxw) {
  6126. $w = $maxw;
  6127. $h=abs($w*$info['h']/$info['w']);
  6128. }
  6129. if ($h > $maxh ) {
  6130. $h = $maxh ;
  6131. $w=abs($h*$info['w']/$info['h']);
  6132. }
  6133. // Position
  6134. if (is_array($this->watermark_pos)) {
  6135. $x = $this->watermark_pos[0];
  6136. $y = $this->watermark_pos[1];
  6137. }
  6138. else if ($this->watermark_pos == 'F') { // centred on printable area
  6139. if ($this->ColActive) { // *COLUMNS*
  6140. if (($this->mirrorMargins) && (($this->page)%2==0)) { $xadj = $this->DeflMargin-$this->DefrMargin; } // *COLUMNS*
  6141. else { $xadj = 0; } // *COLUMNS*
  6142. $x = ($this->DeflMargin - $xadj + ($this->w - ($this->DeflMargin + $this->DefrMargin))/2) - ($w/2); // *COLUMNS*
  6143. } // *COLUMNS*
  6144. else { // *COLUMNS*
  6145. $x = ($this->lMargin + ($this->pgwidth)/2) - ($w/2);
  6146. } // *COLUMNS*
  6147. $y = ($this->tMargin + ($this->h - ($this->tMargin + $this->bMargin))/2) - ($h/2);
  6148. }
  6149. else { // default P - centred on whole page
  6150. $x = ($this->w/2) - ($w/2);
  6151. $y = ($this->h/2) - ($h/2);
  6152. }
  6153. /*-- IMAGES-WMF --*/
  6154. if ($info['type']=='wmf') {
  6155. $sx = $w*_MPDFK / $info['w'];
  6156. $sy = -$h*_MPDFK / $info['h'];
  6157. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  6158. }
  6159. else
  6160. /*-- END IMAGES-WMF --*/
  6161. if ($info['type']=='svg') {
  6162. $sx = $w*_MPDFK / $info['w'];
  6163. $sy = -$h*_MPDFK / $info['h'];
  6164. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  6165. }
  6166. else {
  6167. $outstring = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q",$w*_MPDFK,$h*_MPDFK,$x*_MPDFK,($this->h-($y+$h))*_MPDFK,$info['i']);
  6168. }
  6169. if ($this->watermarkImgBehind) {
  6170. $outstring = $this->watermarkImgAlpha . "\n" . $outstring . "\n" . $this->SetAlpha(1, 'Normal', true) . "\n";
  6171. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$outstring."\n".'\\1', $this->pages[$this->page]);
  6172. }
  6173. else { $this->_out($outstring); }
  6174. return 0;
  6175. } // end of IF watermark
  6176. /*-- END WATERMARK --*/
  6177. if ($constrain) {
  6178. // Automatically resize to maximum dimensions of page if too large
  6179. if (isset($this->blk[$this->blklvl]['inner_width']) && $this->blk[$this->blklvl]['inner_width']) { $maxw = $this->blk[$this->blklvl]['inner_width']; }
  6180. else { $maxw = $this->pgwidth; }
  6181. if ($w > $maxw) {
  6182. $w = $maxw;
  6183. $h=abs($w*$info['h']/$info['w']);
  6184. }
  6185. if ($h > $this->h - ($this->tMargin + $this->bMargin + 1)) { // see below - +10 to avoid drawing too close to border of page
  6186. $h = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  6187. if ($this->fullImageHeight) { $h = $this->fullImageHeight; }
  6188. $w=abs($h*$info['w']/$info['h']);
  6189. }
  6190. //Avoid drawing out of the paper(exceeding width limits).
  6191. //if ( ($x + $w) > $this->fw ) {
  6192. if ( ($x + $w) > $this->w ) {
  6193. $x = $this->lMargin;
  6194. $y += 5;
  6195. }
  6196. $changedpage = false;
  6197. $oldcolumn = $this->CurrCol;
  6198. //Avoid drawing out of the page.
  6199. if($y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  6200. $this->AddPage($this->CurOrientation);
  6201. // Added to correct for OddEven Margins
  6202. $x=$x +$this->MarginCorrection;
  6203. $y = $tMargin + $this->margin_header;
  6204. $changedpage = true;
  6205. }
  6206. /*-- COLUMNS --*/
  6207. // COLS
  6208. // COLUMN CHANGE
  6209. if ($this->CurrCol != $oldcolumn) {
  6210. $y = $this->y0;
  6211. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  6212. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  6213. }
  6214. /*-- END COLUMNS --*/
  6215. } // end of IF constrain
  6216. /*-- IMAGES-WMF --*/
  6217. if ($info['type']=='wmf') {
  6218. $sx = $w*_MPDFK / $info['w'];
  6219. $sy = -$h*_MPDFK / $info['h'];
  6220. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  6221. }
  6222. else
  6223. /*-- END IMAGES-WMF --*/
  6224. if ($info['type']=='svg') {
  6225. $sx = $w*_MPDFK / $info['w'];
  6226. $sy = -$h*_MPDFK / $info['h'];
  6227. $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']);
  6228. }
  6229. else {
  6230. $outstring = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q",$w*_MPDFK,$h*_MPDFK,$x*_MPDFK,($this->h-($y+$h))*_MPDFK,$info['i']);
  6231. }
  6232. if($paint) {
  6233. $this->_out($outstring);
  6234. if($link) $this->Link($x,$y,$w,$h,$link);
  6235. // Avoid writing text on top of the image. // THIS WAS OUTSIDE THE if ($paint) bit!!!!!!!!!!!!!!!!
  6236. $this->y = $y + $h;
  6237. }
  6238. //Return width-height array
  6239. $sizesarray['WIDTH'] = $w;
  6240. $sizesarray['HEIGHT'] = $h;
  6241. $sizesarray['X'] = $x; //Position before painting image
  6242. $sizesarray['Y'] = $y; //Position before painting image
  6243. $sizesarray['OUTPUT'] = $outstring;
  6244. $sizesarray['IMAGE_ID'] = $info['i'];
  6245. $sizesarray['itype'] = $info['type'];
  6246. $sizesarray['set-dpi'] = $info['set-dpi'];
  6247. return $sizesarray;
  6248. }
  6249. //=============================================================
  6250. //=============================================================
  6251. //=============================================================
  6252. //=============================================================
  6253. //=============================================================
  6254. /*-- HTML-CSS --*/
  6255. function _getObjAttr($t) {
  6256. $c = explode("\xbb\xa4\xac",$t,2);
  6257. $c = explode(",",$c[1],2);
  6258. foreach($c as $v) {
  6259. $v = explode("=",$v,2);
  6260. $sp[$v[0]] = $v[1];
  6261. }
  6262. return (unserialize($sp['objattr']));
  6263. }
  6264. function inlineObject($type,$x,$y,$objattr,$Lmargin,$widthUsed,$maxWidth,$lineHeight,$paint=false,$is_table=false)
  6265. {
  6266. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  6267. // NB $x is only used when paint=true
  6268. // Lmargin not used
  6269. $w = 0;
  6270. if (isset($objattr['width'])) { $w = $objattr['width']/$k; }
  6271. $h = 0;
  6272. if (isset($objattr['height'])) { $h = abs($objattr['height']/$k); }
  6273. $widthLeft = $maxWidth - $widthUsed;
  6274. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  6275. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  6276. // For Images
  6277. if (isset($objattr['border_left'])) {
  6278. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right'])/$k;
  6279. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom'])/$k;
  6280. if ($type == 'image' || $type == 'barcode' || $type == 'textcircle') {
  6281. $extraWidth += ($objattr['padding_left'] + $objattr['padding_right'])/$k;
  6282. $extraHeight += ($objattr['padding_top'] + $objattr['padding_bottom'])/$k;
  6283. }
  6284. }
  6285. if (!isset($objattr['vertical-align'])) { $objattr['vertical-align'] = 'M'; }
  6286. if ($type == 'image' || (isset($objattr['subtype']) && $objattr['subtype'] == 'IMAGE')) {
  6287. if (isset($objattr['itype']) && ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg')) {
  6288. $file = $objattr['file'];
  6289. $info=$this->formobjects[$file];
  6290. }
  6291. else if (isset($objattr['file'])) {
  6292. $file = $objattr['file'];
  6293. $info=$this->images[$file];
  6294. }
  6295. }
  6296. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  6297. $w = 0.00001;
  6298. $h = 0.00001;
  6299. }
  6300. // TEST whether need to skipline
  6301. if (!$paint) {
  6302. if ($type == 'hr') { // always force new line
  6303. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-2, $w ,$h ); } // New page + new line
  6304. else { return array(1, $w ,$h ); } // new line
  6305. }
  6306. else {
  6307. if ($widthUsed > 0 && $w > $widthLeft && (!$is_table || $type != 'image')) { // New line needed
  6308. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter) { return array(-2,$w ,$h ); } // New page + new line
  6309. return array(1,$w ,$h ); // new line
  6310. }
  6311. else if ($widthUsed > 0 && $w > $widthLeft && $is_table) { // New line needed in TABLE
  6312. return array(1,$w ,$h ); // new line
  6313. }
  6314. // Will fit on line but NEW PAGE REQUIRED
  6315. else if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-1,$w ,$h ); }
  6316. else { return array(0,$w ,$h ); }
  6317. }
  6318. }
  6319. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  6320. $w = 0.00001;
  6321. $h = 0.00001;
  6322. $objattr['BORDER-WIDTH'] = 0;
  6323. $objattr['BORDER-HEIGHT'] = 0;
  6324. $objattr['BORDER-X'] = $x;
  6325. $objattr['BORDER-Y'] = $y;
  6326. $objattr['INNER-WIDTH'] = 0;
  6327. $objattr['INNER-HEIGHT'] = 0;
  6328. $objattr['INNER-X'] = $x;
  6329. $objattr['INNER-Y'] = $y;
  6330. }
  6331. if ($type == 'image') {
  6332. // Automatically resize to width remaining
  6333. if ($w > $widthLeft && !$is_table) {
  6334. $w = $widthLeft ;
  6335. $h=abs($w*$info['h']/$info['w']);
  6336. }
  6337. $img_w = $w - $extraWidth ;
  6338. $img_h = $h - $extraHeight ;
  6339. $objattr['BORDER-WIDTH'] = $img_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6340. $objattr['BORDER-HEIGHT'] = $img_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6341. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6342. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6343. $objattr['INNER-WIDTH'] = $img_w;
  6344. $objattr['INNER-HEIGHT'] = $img_h;
  6345. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6346. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6347. $objattr['ID'] = $info['i'];
  6348. }
  6349. if ($type == 'input' && $objattr['subtype'] == 'IMAGE') {
  6350. $img_w = $w - $extraWidth ;
  6351. $img_h = $h - $extraHeight ;
  6352. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6353. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6354. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6355. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6356. $objattr['INNER-WIDTH'] = $img_w;
  6357. $objattr['INNER-HEIGHT'] = $img_h;
  6358. $objattr['INNER-X'] = $x + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6359. $objattr['INNER-Y'] = $y + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6360. $objattr['ID'] = $info['i'];
  6361. }
  6362. if ($type == 'barcode' || $type == 'textcircle') {
  6363. $b_w = $w - $extraWidth ;
  6364. $b_h = $h - $extraHeight ;
  6365. $objattr['BORDER-WIDTH'] = $b_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  6366. $objattr['BORDER-HEIGHT'] = $b_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  6367. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  6368. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  6369. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  6370. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  6371. $objattr['INNER-WIDTH'] = $b_w;
  6372. $objattr['INNER-HEIGHT'] = $b_h;
  6373. }
  6374. if ($type == 'textarea') {
  6375. // Automatically resize to width remaining
  6376. if ($w > $widthLeft && !$is_table) {
  6377. $w = $widthLeft ;
  6378. }
  6379. if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter) {
  6380. $h=$this->h - $y - $this->bMargin;
  6381. }
  6382. }
  6383. if ($type == 'hr') {
  6384. if ($is_table) {
  6385. $objattr['INNER-WIDTH'] = $maxWidth * $objattr['W-PERCENT']/100;
  6386. $objattr['width'] = $objattr['INNER-WIDTH'];
  6387. $w = $maxWidth;
  6388. }
  6389. else {
  6390. if ($w>$maxWidth) { $w = $maxWidth; }
  6391. $objattr['INNER-WIDTH'] = $w;
  6392. $w = $maxWidth;
  6393. }
  6394. }
  6395. if (($type == 'select') || ($type == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD'))) {
  6396. // Automatically resize to width remaining
  6397. if ($w > $widthLeft && !$is_table) {
  6398. $w = $widthLeft;
  6399. }
  6400. }
  6401. if ($type == 'textarea' || $type == 'select' || $type == 'input') {
  6402. if (isset($objattr['fontsize'])) $objattr['fontsize'] /= $k;
  6403. if (isset($objattr['linewidth'])) $objattr['linewidth'] /= $k;
  6404. }
  6405. if (!isset($objattr['BORDER-Y'])) { $objattr['BORDER-Y'] = 0; }
  6406. if (!isset($objattr['BORDER-X'])) { $objattr['BORDER-X'] = 0; }
  6407. if (!isset($objattr['INNER-Y'])) { $objattr['INNER-Y'] = 0; }
  6408. if (!isset($objattr['INNER-X'])) { $objattr['INNER-X'] = 0; }
  6409. //Return width-height array
  6410. $objattr['OUTER-WIDTH'] = $w;
  6411. $objattr['OUTER-HEIGHT'] = $h;
  6412. $objattr['OUTER-X'] = $x;
  6413. $objattr['OUTER-Y'] = $y;
  6414. return $objattr;
  6415. }
  6416. /*-- END HTML-CSS --*/
  6417. //=============================================================
  6418. //=============================================================
  6419. //=============================================================
  6420. //=============================================================
  6421. //=============================================================
  6422. function SetLineJoin($mode=0)
  6423. {
  6424. $s=sprintf('%d j',$mode);
  6425. 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); }
  6426. $this->pageoutput[$this->page]['LineJoin'] = $s;
  6427. }
  6428. function SetLineCap($mode=2) {
  6429. $s=sprintf('%d J',$mode);
  6430. 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); }
  6431. $this->pageoutput[$this->page]['LineCap'] = $s;
  6432. }
  6433. function SetDash($black=false,$white=false)
  6434. {
  6435. if($black and $white) $s=sprintf('[%.3F %.3F] 0 d',$black*_MPDFK,$white*_MPDFK);
  6436. else $s='[] 0 d';
  6437. 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); }
  6438. $this->pageoutput[$this->page]['Dash'] = $s;
  6439. }
  6440. function SetDisplayPreferences($preferences) {
  6441. // String containing any or none of /HideMenubar/HideToolbar/HideWindowUI/DisplayDocTitle/CenterWindow/FitWindow
  6442. $this->DisplayPreferences .= $preferences;
  6443. }
  6444. function Ln($h='',$collapsible=0)
  6445. {
  6446. // Added collapsible to allow collapsible top-margin on new page
  6447. //Line feed; default value is last cell height
  6448. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  6449. if ($collapsible && ($this->y==$this->tMargin) && (!$this->ColActive)) { $h = 0; }
  6450. if(is_string($h)) $this->y+=$this->lasth;
  6451. else $this->y+=$h;
  6452. }
  6453. /*-- HTML-CSS --*/
  6454. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6455. function DivLn($h,$level=-3,$move_y=true,$collapsible=false,$state=0) {
  6456. // this->x is returned as it was
  6457. // adds lines (y) where DIV bgcolors are filled in
  6458. // allows .00001 as nominal height used for bookmarks/annotations etc.
  6459. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)) && (!$this->ColActive)) { return; }
  6460. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->y0)) && ($this->ColActive) && $this->CurrCol == 0) { return; } // *COLUMNS*
  6461. // Still use this method if columns or page-break-inside: avoid, as it allows repositioning later
  6462. // otherwise, now uses PaintDivBB()
  6463. if (!$this->ColActive && !$this->keep_block_together && !$this->kwt) {
  6464. if ($move_y && !$this->ColActive) { $this->y += $h; }
  6465. return;
  6466. }
  6467. if ($level == -3) { $level = $this->blklvl; }
  6468. $firstblockfill = $this->GetFirstBlockFill();
  6469. if ($firstblockfill && $this->blklvl > 0 && $this->blklvl >= $firstblockfill) {
  6470. $last_x = 0;
  6471. $last_w = 0;
  6472. $last_fc = $this->FillColor;
  6473. $bak_x = $this->x;
  6474. $bak_h = $this->divheight;
  6475. $this->divheight = 0; // Temporarily turn off divheight - as Cell() uses it to check for PageBreak
  6476. for ($blvl=$firstblockfill;$blvl<=$level;$blvl++) {
  6477. $this->SetBlockFill($blvl);
  6478. $this->x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6479. if ($last_x != $this->lMargin + $this->blk[$blvl]['outer_left_margin'] || $last_w != $this->blk[$blvl]['width'] || $last_fc != $this->FillColor || $this->blk[$blvl]['border_top']['s'] || $this->blk[$blvl]['border_bottom']['s'] || $this->blk[$blvl]['border_left']['s'] || $this->blk[$blvl]['border_right']['s']) { // mPDF 5.6.55
  6480. $x = $this->x;
  6481. $this->Cell( ($this->blk[$blvl]['width']), $h, '', '', 0, '', 1);
  6482. if (!$this->keep_block_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  6483. $this->x = $x;
  6484. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6485. if ($blvl == $this->blklvl) { $this->PaintDivLnBorder($state,$blvl,$h); }
  6486. else { $this->PaintDivLnBorder(0,$blvl,$h); }
  6487. }
  6488. }
  6489. $last_x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6490. $last_w = $this->blk[$blvl]['width'];
  6491. $last_fc = $this->FillColor;
  6492. }
  6493. // Reset current block fill
  6494. if (isset($this->blk[$this->blklvl]['bgcolorarray'])) {
  6495. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  6496. $this->SetFColor($bcor);
  6497. }
  6498. $this->x = $bak_x;
  6499. $this->divheight = $bak_h;
  6500. }
  6501. if ($move_y) { $this->y += $h; }
  6502. }
  6503. /*-- END HTML-CSS --*/
  6504. function SetX($x)
  6505. {
  6506. //Set x position
  6507. if($x >= 0) $this->x=$x;
  6508. else $this->x = $this->w + $x;
  6509. }
  6510. function SetY($y)
  6511. {
  6512. //Set y position and reset x
  6513. $this->x=$this->lMargin;
  6514. if($y>=0)
  6515. $this->y=$y;
  6516. else
  6517. $this->y=$this->h+$y;
  6518. }
  6519. function SetXY($x,$y)
  6520. {
  6521. //Set x and y positions
  6522. $this->SetY($y);
  6523. $this->SetX($x);
  6524. }
  6525. function Output($name='',$dest='')
  6526. {
  6527. //Output PDF to some destination
  6528. if ($this->showStats) {
  6529. echo '<div>Generated in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds</div>';
  6530. }
  6531. //Finish document if necessary
  6532. if ($this->progressBar) { $this->UpdateProgressBar(1,'100','Finished'); } // *PROGRESS-BAR*
  6533. if($this->state < 3) $this->Close();
  6534. if ($this->progressBar) { $this->UpdateProgressBar(2,'100','Finished'); } // *PROGRESS-BAR*
  6535. // fn. error_get_last is only in PHP>=5.2
  6536. if ($this->debug && function_exists('error_get_last') && error_get_last()) {
  6537. $e = error_get_last();
  6538. if (($e['type'] < 2048 && $e['type'] != 8) || (intval($e['type']) & intval(ini_get("error_reporting")))) {
  6539. echo "<p>Error message detected - PDF file generation aborted.</p>";
  6540. echo $e['message'].'<br />';
  6541. echo 'File: '.$e['file'].'<br />';
  6542. echo 'Line: '.$e['line'].'<br />';
  6543. exit;
  6544. }
  6545. }
  6546. if (($this->PDFA || $this->PDFX) && $this->encrypted) { $this->Error("PDFA1-b or PDFX/1-a does not permit encryption of documents."); }
  6547. if (count($this->PDFAXwarnings) && (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto))) {
  6548. if ($this->PDFA) {
  6549. echo '<div>WARNING - This file could not be generated as it stands as a PDFA1-b compliant file.</div>';
  6550. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFAauto=true;</i></div>';
  6551. echo '<div>Action that mPDF will take to automatically force PDFA1-b compliance are shown in brackets.</div>';
  6552. }
  6553. else {
  6554. echo '<div>WARNING - This file could not be generated as it stands as a PDFX/1-a compliant file.</div>';
  6555. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFXauto=true;</i></div>';
  6556. echo '<div>Action that mPDF will take to automatically force PDFX/1-a compliance are shown in brackets.</div>';
  6557. }
  6558. echo '<div>Warning(s) generated:</div><ul>';
  6559. $this->PDFAXwarnings = array_unique($this->PDFAXwarnings);
  6560. foreach($this->PDFAXwarnings AS $w) {
  6561. echo '<li>'.$w.'</li>';
  6562. }
  6563. echo '</ul>';
  6564. exit;
  6565. }
  6566. if ($this->showStats) {
  6567. echo '<div>Compiled in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds (total)</div>';
  6568. echo '<div>Peak Memory usage '.number_format((memory_get_peak_usage(true)/(1024*1024)),2).' MB</div>';
  6569. echo '<div>PDF file size '.number_format((strlen($this->buffer)/1024)).' kB</div>';
  6570. echo '<div>Number of fonts '.count($this->fonts).'</div>';
  6571. exit;
  6572. }
  6573. if(is_bool($dest)) $dest=$dest ? 'D' : 'F';
  6574. $dest=strtoupper($dest);
  6575. if($dest=='') {
  6576. if($name=='') {
  6577. $name='mpdf.pdf';
  6578. $dest='I';
  6579. }
  6580. else { $dest='F'; }
  6581. }
  6582. /*-- PROGRESS-BAR --*/
  6583. if ($this->progressBar && ($dest=='D' || $dest=='I')) {
  6584. if($name=='') { $name='mpdf.pdf'; }
  6585. $tempfile = '_tempPDF'.RAND(1,10000);
  6586. //Save to local file
  6587. $f=fopen(_MPDF_TEMP_PATH.$tempfile.'.pdf','wb');
  6588. if(!$f) $this->Error('Unable to create temporary output file: '.$tempfile.'.pdf');
  6589. fwrite($f,$this->buffer,strlen($this->buffer));
  6590. fclose($f);
  6591. $this->UpdateProgressBar(3,'','Finished');
  6592. echo '<script type="text/javascript">
  6593. var form = document.createElement("form");
  6594. form.setAttribute("method", "post");
  6595. form.setAttribute("action", "'._MPDF_URI.'includes/out.php");
  6596. var hiddenField = document.createElement("input");
  6597. hiddenField.setAttribute("type", "hidden");
  6598. hiddenField.setAttribute("name", "filename");
  6599. hiddenField.setAttribute("value", "'.$tempfile.'");
  6600. form.appendChild(hiddenField);
  6601. var hiddenField = document.createElement("input");
  6602. hiddenField.setAttribute("type", "hidden");
  6603. hiddenField.setAttribute("name", "dest");
  6604. hiddenField.setAttribute("value", "'.$dest.'");
  6605. form.appendChild(hiddenField);
  6606. var hiddenField = document.createElement("input");
  6607. hiddenField.setAttribute("type", "hidden");
  6608. hiddenField.setAttribute("name", "opname");
  6609. hiddenField.setAttribute("value", "'.$name.'");
  6610. form.appendChild(hiddenField);
  6611. var hiddenField = document.createElement("input");
  6612. hiddenField.setAttribute("type", "hidden");
  6613. hiddenField.setAttribute("name", "path");
  6614. hiddenField.setAttribute("value", "'.urlencode(_MPDF_TEMP_PATH).'");
  6615. form.appendChild(hiddenField);
  6616. document.body.appendChild(form);
  6617. form.submit();
  6618. </script>
  6619. </div>
  6620. </body>
  6621. </html>';
  6622. exit;
  6623. }
  6624. else {
  6625. if ($this->progressBar) { $this->UpdateProgressBar(3,'','Finished'); }
  6626. /*-- END PROGRESS-BAR --*/
  6627. switch($dest) {
  6628. case 'I':
  6629. 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; }
  6630. //Send to standard output
  6631. if(PHP_SAPI!='cli') {
  6632. //We send to a browser
  6633. header('Content-Type: application/pdf');
  6634. if(headers_sent())
  6635. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6636. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  6637. // don't use length if server using compression
  6638. header('Content-Length: '.strlen($this->buffer));
  6639. }
  6640. header('Content-disposition: inline; filename="'.$name.'"');
  6641. header('Cache-Control: public, must-revalidate, max-age=0');
  6642. header('Pragma: public');
  6643. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6644. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6645. }
  6646. echo $this->buffer;
  6647. break;
  6648. case 'D':
  6649. //Download file
  6650. header('Content-Description: File Transfer');
  6651. if (headers_sent())
  6652. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6653. header('Content-Transfer-Encoding: binary');
  6654. header('Cache-Control: public, must-revalidate, max-age=0');
  6655. header('Pragma: public');
  6656. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6657. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6658. header('Content-Type: application/force-download');
  6659. header('Content-Type: application/octet-stream', false);
  6660. header('Content-Type: application/download', false);
  6661. header('Content-Type: application/pdf', false);
  6662. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  6663. // don't use length if server using compression
  6664. header('Content-Length: '.strlen($this->buffer));
  6665. }
  6666. header('Content-disposition: attachment; filename="'.$name.'"');
  6667. echo $this->buffer;
  6668. break;
  6669. case 'F':
  6670. //Save to local file
  6671. $f=fopen($name,'wb');
  6672. if(!$f) $this->Error('Unable to create output file: '.$name);
  6673. fwrite($f,$this->buffer,strlen($this->buffer));
  6674. fclose($f);
  6675. break;
  6676. case 'S':
  6677. //Return as a string
  6678. return $this->buffer;
  6679. default:
  6680. $this->Error('Incorrect output destination: '.$dest);
  6681. }
  6682. } // *PROGRESS-BAR*
  6683. //======================================================================================================
  6684. // DELETE OLD TMP FILES - Housekeeping
  6685. // Delete any files in tmp/ directory that are >1 hrs old
  6686. $interval = 3600;
  6687. if ($handle = opendir(preg_replace('/\/$/','',_MPDF_TEMP_PATH))) {
  6688. while (false !== ($file = readdir($handle))) {
  6689. if (!is_dir($file) && ((filemtime(_MPDF_TEMP_PATH.$file)+$interval) < time()) && ($file != "..") && ($file != ".")) { // mPDF 5.4.19
  6690. unlink(_MPDF_TEMP_PATH.$file);
  6691. }
  6692. }
  6693. closedir($handle);
  6694. }
  6695. //==============================================================================================================
  6696. return '';
  6697. }
  6698. // *****************************************************************************
  6699. // *
  6700. // Protected methods *
  6701. // *
  6702. // *****************************************************************************
  6703. function _dochecks()
  6704. {
  6705. //Check for locale-related bug
  6706. if(1.1==1)
  6707. $this->Error('Don\'t alter the locale before including mPDF');
  6708. //Check for decimal separator
  6709. if(sprintf('%.1f',1.0)!='1.0')
  6710. setlocale(LC_NUMERIC,'C');
  6711. // mPDF 5.4.11
  6712. $mqr=ini_get("magic_quotes_runtime");
  6713. if ($mqr) { $this->Error('mPDF requires magic_quotes_runtime to be turned off e.g. by using ini_set("magic_quotes_runtime", 0);'); }
  6714. }
  6715. function _begindoc()
  6716. {
  6717. //Start document
  6718. $this->state=1;
  6719. $this->_out('%PDF-'.$this->pdf_version);
  6720. $this->_out('%'.chr(226).chr(227).chr(207).chr(211)); // 4 chars > 128 to show binary file
  6721. }
  6722. /*-- HTMLHEADERS-FOOTERS --*/
  6723. function _puthtmlheaders() {
  6724. $this->state=2;
  6725. $nb=$this->page;
  6726. for($n=1;$n<=$nb;$n++) {
  6727. if ($this->mirrorMargins && $n%2==0) { $OE = 'E'; } // EVEN
  6728. else { $OE = 'O'; }
  6729. $this->page = $n;
  6730. if (isset($this->saveHTMLHeader[$n][$OE])) {
  6731. $html = $this->saveHTMLHeader[$n][$OE]['html'];
  6732. $this->lMargin = $this->saveHTMLHeader[$n][$OE]['ml'];
  6733. $this->rMargin = $this->saveHTMLHeader[$n][$OE]['mr'];
  6734. $this->tMargin = $this->saveHTMLHeader[$n][$OE]['mh'];
  6735. $this->bMargin = $this->saveHTMLHeader[$n][$OE]['mf'];
  6736. $this->margin_header = $this->saveHTMLHeader[$n][$OE]['mh'];
  6737. $this->margin_footer = $this->saveHTMLHeader[$n][$OE]['mf'];
  6738. $this->w = $this->saveHTMLHeader[$n][$OE]['pw'];
  6739. $this->h = $this->saveHTMLHeader[$n][$OE]['ph'];
  6740. $rotate = (isset($this->saveHTMLHeader[$n][$OE]['rotate']) ? $this->saveHTMLHeader[$n][$OE]['rotate'] : null);
  6741. $this->Reset();
  6742. $this->pageoutput[$n] = array();
  6743. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6744. $this->x = $this->lMargin;
  6745. $this->y = $this->margin_header;
  6746. // mPDF 5.6.47
  6747. $pn = $this->docPageNum($n);
  6748. if ($pn)
  6749. $pnstr = $this->pagenumPrefix.$pn.$this->pagenumSuffix;
  6750. else { $pnstr = ''; }
  6751. $html = str_replace('{PAGENO}',$pnstr,$html);
  6752. $pnt = $this->docPageNumTotal($n);
  6753. if ($pnt)
  6754. $pntstr = $this->nbpgPrefix.$pnt.$this->nbpgSuffix;
  6755. else { $pntstr = ''; }
  6756. $html = str_replace($this->aliasNbPgGp,$pntstr,$html ); // {nbpg}
  6757. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6758. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6759. $this->HTMLheaderPageLinks = array();
  6760. $this->HTMLheaderPageAnnots = array();
  6761. $this->HTMLheaderPageForms = array();
  6762. $this->pageBackgrounds = array();
  6763. $this->writingHTMLheader = true;
  6764. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6765. $this->writingHTMLheader = false;
  6766. $this->Reset();
  6767. $this->pageoutput[$n] = array();
  6768. $s = $this->PrintPageBackgrounds();
  6769. $this->headerbuffer = $s . $this->headerbuffer;
  6770. $os = '';
  6771. if ($rotate) {
  6772. $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK));
  6773. }
  6774. $os .= $this->headerbuffer ;
  6775. if ($rotate) {
  6776. $os .= ' Q' . "\n";
  6777. }
  6778. // Writes over the page background but behind any other output on page
  6779. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6780. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6781. $lks = $this->HTMLheaderPageLinks;
  6782. foreach($lks AS $lk) {
  6783. if ($rotate) {
  6784. $lw = $lk[2];
  6785. $lh = $lk[3];
  6786. $lk[2] = $lh;
  6787. $lk[3] = $lw; // swap width and height
  6788. $ax = $lk[0]/_MPDFK;
  6789. $ay = $lk[1]/_MPDFK;
  6790. $bx = $ay-($lh/_MPDFK);
  6791. $by = $this->w-$ax;
  6792. $lk[0] = $bx*_MPDFK;
  6793. $lk[1] = ($this->h-$by)*_MPDFK - $lw;
  6794. }
  6795. $this->PageLinks[$n][]=$lk;
  6796. }
  6797. /*-- FORMS --*/
  6798. foreach($this->HTMLheaderPageForms AS $f) {
  6799. $this->form->forms[$f['n']] = $f;
  6800. }
  6801. /*-- END FORMS --*/
  6802. }
  6803. if (isset($this->saveHTMLFooter[$n][$OE])) {
  6804. $html = $this->saveHTMLFooter[$this->page][$OE]['html'];
  6805. $this->lMargin = $this->saveHTMLFooter[$n][$OE]['ml'];
  6806. $this->rMargin = $this->saveHTMLFooter[$n][$OE]['mr'];
  6807. $this->tMargin = $this->saveHTMLFooter[$n][$OE]['mh'];
  6808. $this->bMargin = $this->saveHTMLFooter[$n][$OE]['mf'];
  6809. $this->margin_header = $this->saveHTMLFooter[$n][$OE]['mh'];
  6810. $this->margin_footer = $this->saveHTMLFooter[$n][$OE]['mf'];
  6811. $this->w = $this->saveHTMLFooter[$n][$OE]['pw'];
  6812. $this->h = $this->saveHTMLFooter[$n][$OE]['ph'];
  6813. $rotate = (isset($this->saveHTMLFooter[$n][$OE]['rotate']) ? $this->saveHTMLFooter[$n][$OE]['rotate'] : null);
  6814. $this->Reset();
  6815. $this->pageoutput[$n] = array();
  6816. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6817. $this->x = $this->lMargin;
  6818. $top_y = $this->y = $this->h - $this->margin_footer;
  6819. // if bottom-margin==0, corrects to avoid division by zero
  6820. if ($this->y == $this->h) { $top_y = $this->y = ($this->h - 0.1); }
  6821. // mPDF 5.6.47
  6822. $pn = $this->docPageNum($n);
  6823. if ($pn)
  6824. $pnstr = $this->pagenumPrefix.$pn.$this->pagenumSuffix;
  6825. else { $pnstr = ''; }
  6826. $html = str_replace('{PAGENO}',$pnstr,$html);
  6827. $pnt = $this->docPageNumTotal($n);
  6828. if ($pnt)
  6829. $pntstr = $this->nbpgPrefix.$pnt.$this->nbpgSuffix;
  6830. else { $pntstr = ''; }
  6831. $html = str_replace($this->aliasNbPgGp,$pntstr,$html ); // {nbpg}
  6832. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6833. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6834. $this->HTMLheaderPageLinks = array();
  6835. $this->HTMLheaderPageAnnots = array();
  6836. $this->HTMLheaderPageForms = array();
  6837. $this->pageBackgrounds = array();
  6838. $this->writingHTMLfooter = true;
  6839. $this->InFooter = true;
  6840. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6841. $this->writingHTMLfooter = false;
  6842. $this->InFooter = false;
  6843. $this->Reset();
  6844. $this->pageoutput[$n] = array();
  6845. $fheight = $this->y - $top_y;
  6846. $adj = -$fheight;
  6847. $s = $this->PrintPageBackgrounds(-$adj);
  6848. $this->headerbuffer = $s . $this->headerbuffer;
  6849. $os = '';
  6850. $os .= $this->StartTransform(true)."\n";
  6851. if ($rotate) {
  6852. $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK));
  6853. }
  6854. $os .= $this->transformTranslate(0, $adj, true)."\n";
  6855. $os .= $this->headerbuffer ;
  6856. if ($rotate) {
  6857. $os .= ' Q' . "\n";
  6858. }
  6859. $os .= $this->StopTransform(true)."\n";
  6860. // Writes over the page background but behind any other output on page
  6861. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6862. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6863. $lks = $this->HTMLheaderPageLinks;
  6864. foreach($lks AS $lk) {
  6865. $lk[1] -= $adj*_MPDFK;
  6866. if ($rotate) {
  6867. $lw = $lk[2];
  6868. $lh = $lk[3];
  6869. $lk[2] = $lh;
  6870. $lk[3] = $lw; // swap width and height
  6871. $ax = $lk[0]/_MPDFK;
  6872. $ay = $lk[1]/_MPDFK;
  6873. $bx = $ay-($lh/_MPDFK);
  6874. $by = $this->w-$ax;
  6875. $lk[0] = $bx*_MPDFK;
  6876. $lk[1] = ($this->h-$by)*_MPDFK - $lw;
  6877. }
  6878. $this->PageLinks[$n][]=$lk;
  6879. }
  6880. /*-- FORMS --*/
  6881. foreach($this->HTMLheaderPageForms AS $f) {
  6882. $f['y'] += $adj;
  6883. $this->form->forms[$f['n']] = $f;
  6884. }
  6885. /*-- END FORMS --*/
  6886. }
  6887. }
  6888. $this->page=$nb;
  6889. $this->state=1;
  6890. }
  6891. /*-- END HTMLHEADERS-FOOTERS --*/
  6892. function _putpages()
  6893. {
  6894. $nb=$this->page;
  6895. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  6896. if($this->DefOrientation=='P') {
  6897. $defwPt=$this->fwPt;
  6898. $defhPt=$this->fhPt;
  6899. }
  6900. else {
  6901. $defwPt=$this->fhPt;
  6902. $defhPt=$this->fwPt;
  6903. }
  6904. $annotid=(3+2*$nb);
  6905. // Active Forms
  6906. $totaladdnum = 0;
  6907. for($n=1;$n<=$nb;$n++) {
  6908. if (isset($this->PageLinks[$n])) { $totaladdnum += count($this->PageLinks[$n]); }
  6909. /*-- ANNOTATIONS --*/
  6910. if (isset($this->PageAnnots[$n])) {
  6911. foreach ($this->PageAnnots[$n] as $k => $pl) {
  6912. if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $totaladdnum += 2 ; }
  6913. else { $totaladdnum++; }
  6914. }
  6915. }
  6916. /*-- END ANNOTATIONS --*/
  6917. /*-- FORMS --*/
  6918. if ( count($this->form->forms) > 0 ) {
  6919. $this->form->countPageForms($n, $totaladdnum);
  6920. }
  6921. /*-- END FORMS --*/
  6922. }
  6923. /*-- FORMS --*/
  6924. // Make a note in the radio button group of the obj_id it will have
  6925. $ctr = 0;
  6926. if (count($this->form->form_radio_groups)) {
  6927. foreach($this->form->form_radio_groups AS $name=>$frg) {
  6928. $this->form->form_radio_groups[$name]['obj_id'] = $annotid + $totaladdnum + $ctr;
  6929. $ctr++;
  6930. }
  6931. }
  6932. /*-- END FORMS --*/
  6933. // Select unused fonts (usually default font)
  6934. $unused = array();
  6935. foreach($this->fonts as $fk=>$font) {
  6936. if (!$font['used'] && ($font['type']=='TTF')) {
  6937. $unused[] = $fk;
  6938. }
  6939. }
  6940. for($n=1;$n<=$nb;$n++)
  6941. {
  6942. $thispage = $this->pages[$n];
  6943. // unset($this->pages[$n]); // mPDF 5.6.47
  6944. if(isset($this->OrientationChanges[$n])) {
  6945. $hPt=$this->pageDim[$n]['w']*_MPDFK;
  6946. $wPt=$this->pageDim[$n]['h']*_MPDFK;
  6947. $owidthPt_LR = $this->pageDim[$n]['outer_width_TB']*_MPDFK;
  6948. $owidthPt_TB = $this->pageDim[$n]['outer_width_LR']*_MPDFK;
  6949. }
  6950. else {
  6951. $wPt=$this->pageDim[$n]['w']*_MPDFK;
  6952. $hPt=$this->pageDim[$n]['h']*_MPDFK;
  6953. $owidthPt_LR = $this->pageDim[$n]['outer_width_LR']*_MPDFK;
  6954. $owidthPt_TB = $this->pageDim[$n]['outer_width_TB']*_MPDFK;
  6955. }
  6956. // Remove references to unused fonts (usually default font)
  6957. foreach($unused as $fk) {
  6958. if ($this->fonts[$fk]['sip'] || $this->fonts[$fk]['smp']) {
  6959. foreach($this->fonts[$fk]['subsetfontids'] AS $k => $fid) {
  6960. $thispage = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$thispage);
  6961. }
  6962. }
  6963. else {
  6964. $thispage = preg_replace('/\s\/F'.$this->fonts[$fk]['i'].' \d[\d.]* Tf\s/is',' ',$thispage);
  6965. }
  6966. }
  6967. //Replace number of pages
  6968. if(!empty($this->aliasNbPg)) {
  6969. if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPg, false); }
  6970. $s2 = $this->aliasNbPg;
  6971. if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nb, false); }
  6972. $r2 = $nb;
  6973. if (preg_match_all('/{mpdfheadernbpg (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) {
  6974. for($hi=0;$hi<count($m[0]);$hi++) {
  6975. $pos = $m[1][$hi];
  6976. $hff = $m[2][$hi];
  6977. $hfst = $m[3][$hi];
  6978. $hfsz = $m[4][$hi];
  6979. $this->SetFont($hff,$hfst,$hfsz, false);
  6980. $x1 = $this->GetStringWidth($this->aliasNbPg);
  6981. $x2 = $this->GetStringWidth($nb);
  6982. $xadj = $x1 - $x2;
  6983. if ($pos=='C') { $xadj /= 2; }
  6984. $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK);
  6985. $thispage = str_replace($m[0][$hi], $rep, $thispage);
  6986. }
  6987. }
  6988. if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); }
  6989. $thispage=str_replace($s2,$r2,$thispage);
  6990. // And now for any SMP/SIP fonts subset using <HH> format
  6991. $r = '';
  6992. $nstr = "$nb";
  6993. for($i=0;$i<strlen($nstr);$i++) {
  6994. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  6995. }
  6996. $thispage=str_replace($this->aliasNbPgHex,$r,$thispage);
  6997. }
  6998. //Replace number of pages in group
  6999. if(!empty($this->aliasNbPgGp)) {
  7000. if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPgGp, false); }
  7001. $s2 = $this->aliasNbPgGp;
  7002. $nbt = $this->docPageNumTotal($n);
  7003. if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nbt, false); }
  7004. $r2 = $nbt;
  7005. if (preg_match_all('/{mpdfheadernbpggp (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) {
  7006. for($hi=0;$hi<count($m[0]);$hi++) {
  7007. $pos = $m[1][$hi];
  7008. $hff = $m[2][$hi];
  7009. $hfst = $m[3][$hi];
  7010. $hfsz = $m[4][$hi];
  7011. $this->SetFont($hff,$hfst,$hfsz, false);
  7012. $x1 = $this->GetStringWidth($this->aliasNbPgGp);
  7013. $x2 = $this->GetStringWidth($nbt);
  7014. $xadj = $x1 - $x2;
  7015. if ($pos=='C') { $xadj /= 2; }
  7016. $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK);
  7017. $thispage = str_replace($m[0][$hi], $rep, $thispage);
  7018. }
  7019. }
  7020. if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); }
  7021. $thispage=str_replace($s2,$r2,$thispage);
  7022. // And now for any SMP/SIP fonts subset using <HH> format
  7023. $r = '';
  7024. $nstr = "$nbt";
  7025. for($i=0;$i<strlen($nstr);$i++) {
  7026. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  7027. }
  7028. $thispage=str_replace($this->aliasNbPgGpHex,$r,$thispage);
  7029. }
  7030. $thispage = preg_replace('/(\s*___BACKGROUND___PATTERNS'.date('jY').'\s*)/', " ", $thispage);
  7031. $thispage = preg_replace('/(\s*___HEADER___MARKER'.date('jY').'\s*)/', " ", $thispage);
  7032. $thispage = preg_replace('/(\s*___PAGE___START'.date('jY').'\s*)/', " ", $thispage);
  7033. $thispage = preg_replace('/(\s*___TABLE___BACKGROUNDS'.date('jY').'\s*)/', " ", $thispage);
  7034. //Page
  7035. $this->_newobj();
  7036. $this->_out('<</Type /Page');
  7037. $this->_out('/Parent 1 0 R');
  7038. if(isset($this->OrientationChanges[$n])) {
  7039. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$hPt,$wPt));
  7040. //If BleedBox is defined, it must be larger than the TrimBox, but smaller than the MediaBox
  7041. $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK;
  7042. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  7043. $x0 = $owidthPt_TB-$bleedMargin;
  7044. $y0 = $owidthPt_LR-$bleedMargin;
  7045. $x1 = $hPt-$owidthPt_TB+$bleedMargin;
  7046. $y1 = $wPt-$owidthPt_LR+$bleedMargin;
  7047. $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1));
  7048. }
  7049. $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_TB, $owidthPt_LR, ($hPt-$owidthPt_TB), ($wPt-$owidthPt_LR)));
  7050. if (isset($this->OrientationChanges[$n]) && $this->displayDefaultOrientation) {
  7051. if ($this->DefOrientation=='P') { $this->_out('/Rotate 270'); }
  7052. else { $this->_out('/Rotate 90'); }
  7053. }
  7054. }
  7055. //else if($wPt != $defwPt || $hPt != $defhPt) {
  7056. else {
  7057. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$wPt,$hPt));
  7058. $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK;
  7059. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  7060. $x0 = $owidthPt_LR-$bleedMargin;
  7061. $y0 = $owidthPt_TB-$bleedMargin;
  7062. $x1 = $wPt-$owidthPt_LR+$bleedMargin;
  7063. $y1 = $hPt-$owidthPt_TB+$bleedMargin;
  7064. $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1));
  7065. }
  7066. $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_LR, $owidthPt_TB, ($wPt-$owidthPt_LR), ($hPt-$owidthPt_TB)));
  7067. }
  7068. $this->_out('/Resources 2 0 R');
  7069. // Important to keep in RGB colorSpace when using transparency
  7070. if (!$this->PDFA && !$this->PDFX) {
  7071. if ($this->restrictColorSpace == 3)
  7072. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceCMYK >> ');
  7073. else if ($this->restrictColorSpace == 1)
  7074. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >> ');
  7075. else
  7076. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceRGB >> ');
  7077. }
  7078. $annotsnum = 0;
  7079. if (isset($this->PageLinks[$n])) { $annotsnum += count($this->PageLinks[$n]); }
  7080. /*-- ANNOTATIONS --*/
  7081. if (isset($this->PageAnnots[$n])) {
  7082. foreach ($this->PageAnnots[$n] as $k => $pl) {
  7083. if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $annotsnum += 2 ; }
  7084. else { $annotsnum++; }
  7085. $this->PageAnnots[$n][$k]['pageobj'] = $this->n;
  7086. }
  7087. }
  7088. /*-- END ANNOTATIONS --*/
  7089. /*-- FORMS --*/
  7090. // Active Forms
  7091. $formsnum = 0;
  7092. if ( count($this->form->forms) > 0 ) {
  7093. foreach( $this->form->forms as $val ) {
  7094. if ( $val['page'] == $n )
  7095. $formsnum++;
  7096. }
  7097. }
  7098. /*-- END FORMS --*/
  7099. if ($annotsnum || $formsnum) {
  7100. $s = '/Annots [ ';
  7101. for($i=0;$i<$annotsnum;$i++) {
  7102. $s .= ($annotid + $i) . ' 0 R ';
  7103. }
  7104. $annotid += $annotsnum;
  7105. /*-- FORMS --*/
  7106. if ( count($this->form->forms) > 0 ) {
  7107. $this->form->addFormIds($n, $s, $annotid);
  7108. }
  7109. /*-- END FORMS --*/
  7110. $s .= '] ';
  7111. $this->_out($s);
  7112. }
  7113. $this->_out('/Contents '.($this->n+1).' 0 R>>');
  7114. $this->_out('endobj');
  7115. //Page content
  7116. $this->_newobj();
  7117. $p=($this->compress) ? gzcompress($thispage) : $thispage;
  7118. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  7119. $this->_putstream($p);
  7120. $this->_out('endobj');
  7121. }
  7122. $this->_putannots($n);
  7123. //Pages root
  7124. $this->offsets[1]=strlen($this->buffer);
  7125. $this->_out('1 0 obj');
  7126. $this->_out('<</Type /Pages');
  7127. $kids='/Kids [';
  7128. for($i=0;$i<$nb;$i++)
  7129. $kids.=(3+2*$i).' 0 R ';
  7130. $this->_out($kids.']');
  7131. $this->_out('/Count '.$nb);
  7132. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$defwPt,$defhPt));
  7133. $this->_out('>>');
  7134. $this->_out('endobj');
  7135. }
  7136. function _putannots($n) {
  7137. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  7138. $nb=$this->page;
  7139. for($n=1;$n<=$nb;$n++)
  7140. {
  7141. $annotobjs = array();
  7142. if(isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n]) || count($this->form->forms) > 0 ) {
  7143. $wPt=$this->pageDim[$n]['w']*_MPDFK;
  7144. $hPt=$this->pageDim[$n]['h']*_MPDFK;
  7145. //Links
  7146. if(isset($this->PageLinks[$n])) {
  7147. foreach($this->PageLinks[$n] as $key => $pl) {
  7148. $this->_newobj();
  7149. $annot='';
  7150. $rect=sprintf('%.3F %.3F %.3F %.3F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  7151. $annot .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.']';
  7152. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl[4]);
  7153. $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, $key));
  7154. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  7155. $annot .= ' /Border [0 0 0]';
  7156. // Use this (instead of /Border) to specify border around link
  7157. // $annot .= ' /BS <</W 1'; // Width on points; 0 = no line
  7158. // $annot .= ' /S /D'; // style - [S]olid, [D]ashed, [B]eveled, [I]nset, [U]nderline
  7159. // $annot .= ' /D [3 2]'; // Dash array - if dashed
  7160. // $annot .= ' >>';
  7161. // $annot .= ' /C [1 0 0]'; // Color RGB
  7162. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  7163. if (strpos($pl[4],'@')===0) {
  7164. $p=substr($pl[4],1);
  7165. // $h=isset($this->OrientationChanges[$p]) ? $wPt : $hPt;
  7166. $htarg=$this->pageDim[$p]['h']*_MPDFK;
  7167. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$p,$htarg);
  7168. }
  7169. else if(is_string($pl[4])) {
  7170. $annot .= ' /A <</S /URI /URI '.$this->_textstring($pl[4]).'>> >>';
  7171. }
  7172. else {
  7173. $l=$this->links[$pl[4]];
  7174. // may not be set if #link points to non-existent target
  7175. if (isset($this->pageDim[$l[0]]['h'])) { $htarg=$this->pageDim[$l[0]]['h']*_MPDFK; }
  7176. else { $htarg=$this->h*_MPDFK; } // doesn't really matter
  7177. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$l[0],$htarg-$l[1]*_MPDFK);
  7178. }
  7179. $this->_out($annot);
  7180. $this->_out('endobj');
  7181. }
  7182. }
  7183. /*-- ANNOTATIONS --*/
  7184. if(isset($this->PageAnnots[$n])) {
  7185. foreach ($this->PageAnnots[$n] as $key => $pl) {
  7186. if ($pl['opt']['file']) { $FileAttachment=true; }
  7187. else { $FileAttachment=false; }
  7188. $this->_newobj();
  7189. $annot='';
  7190. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7191. $x = $pl['x'];
  7192. if ($this->annotMargin <> 0 || $x==0 || $x<0) { // Odd page
  7193. $x = ($wPt/_MPDFK) - $this->annotMargin;
  7194. }
  7195. $w = $h = 0;
  7196. $a = $x * _MPDFK;
  7197. $b = $hPt - ($pl['y'] * _MPDFK);
  7198. $annot .= '<</Type /Annot ';
  7199. if ($FileAttachment) {
  7200. $annot .= '/Subtype /FileAttachment';
  7201. // Need to set a size for FileAttachment icons
  7202. if ($pl['opt']['icon']=='Paperclip') { $w=8.235; $h=20; } // 7,17
  7203. else if ($pl['opt']['icon']=='Tag') { $w=20; $h=16; }
  7204. else if ($pl['opt']['icon']=='Graph') { $w=20; $h=20; }
  7205. else { $w=14; $h=20; } // PushPin
  7206. $f = $pl['opt']['file'];
  7207. $f = preg_replace('/^.*\//', '', $f);
  7208. $f = preg_replace('/[^a-zA-Z0-9._]/', '', $f);
  7209. $annot .= '/FS <</Type /Filespec /F ('.$f.')';
  7210. $annot .= '/EF <</F '.($this->n+1).' 0 R>>';
  7211. $annot .= '>>';
  7212. }
  7213. else {
  7214. $annot .= '/Subtype /Text';
  7215. }
  7216. $rect = sprintf('%.3F %.3F %.3F %.3F', $a, $b-$h, $a+$w, $b);
  7217. $annot .= '/Rect ['.$rect.']';
  7218. // contents = description of file in free text
  7219. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl['txt']);
  7220. $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, (2000 + $key)));
  7221. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  7222. $annot .= ' /CreationDate '.$this->_textstring('D:'.date('YmdHis'));
  7223. $annot .= ' /Border [0 0 0]';
  7224. if ($this->PDFA || $this->PDFX) {
  7225. $annot .= ' /F 28';
  7226. $annot .= ' /CA 1';
  7227. }
  7228. else if ($pl['opt']['ca']>0) { $annot .= ' /CA '.$pl['opt']['ca']; }
  7229. $annotcolor = ' /C [';
  7230. if (isset($pl['opt']['c']) AND $pl['opt']['c']) {
  7231. $col = $pl['opt']['c'];
  7232. if ($col{0}==3 || $col{0}==5) { $annotcolor .= sprintf("%.3F %.3F %.3F", ord($col{1})/255,ord($col{2})/255,ord($col{3})/255); }
  7233. else if ($col{0}==1) { $annotcolor .= sprintf("%.3F", ord($col{1})/255); }
  7234. else if ($col{0}==4 || $col{0}==6) { $annotcolor .= sprintf("%.3F %.3F %.3F %.3F", ord($col{1})/100,ord($col{2})/100,ord($col{3})/100,ord($col{4})/100); }
  7235. else { $annotcolor .= '1 1 0'; }
  7236. }
  7237. else { $annotcolor .= '1 1 0'; }
  7238. $annotcolor .= ']';
  7239. $annot .= $annotcolor;
  7240. // Usually Author
  7241. // Use as Title for fileattachment
  7242. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  7243. $annot .= ' /T '.$this->_UTF16BEtextstring($pl['opt']['t']);
  7244. }
  7245. if ($FileAttachment) {
  7246. $iconsapp = array('Paperclip', 'Graph', 'PushPin', 'Tag');
  7247. }
  7248. else { $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); }
  7249. if (isset($pl['opt']['icon']) AND in_array($pl['opt']['icon'], $iconsapp)) {
  7250. $annot .= ' /Name /'.$pl['opt']['icon'];
  7251. }
  7252. else if ($FileAttachment) { $annot .= ' /Name /PushPin'; }
  7253. else { $annot .= ' /Name /Note'; }
  7254. if (!$FileAttachment) {
  7255. // /Subj is PDF 1.5 spec.
  7256. if (isset($pl['opt']['subj']) && !$this->PDFA && !$this->PDFX) {
  7257. $annot .= ' /Subj '.$this->_UTF16BEtextstring($pl['opt']['subj']);
  7258. }
  7259. if (!empty($pl['opt']['popup'])) {
  7260. $annot .= ' /Open true';
  7261. $annot .= ' /Popup '.($this->n+1).' 0 R';
  7262. }
  7263. else { $annot .= ' /Open false'; }
  7264. }
  7265. $annot .= ' /P '.$pl['pageobj'].' 0 R';
  7266. $annot .= '>>';
  7267. $this->_out($annot);
  7268. $this->_out('endobj');
  7269. if ($FileAttachment) {
  7270. $file = @file_get_contents($pl['opt']['file']) or die('mPDF Error: Cannot access file attachment - '.$pl['opt']['file']);
  7271. $filestream = gzcompress($file);
  7272. $this->_newobj();
  7273. $this->_out('<</Type /EmbeddedFile');
  7274. $this->_out('/Length '.strlen($filestream));
  7275. $this->_out('/Filter /FlateDecode');
  7276. $this->_out('>>');
  7277. $this->_putstream($filestream);
  7278. $this->_out('endobj');
  7279. }
  7280. else if (!empty($pl['opt']['popup'])) {
  7281. $this->_newobj();
  7282. $annot='';
  7283. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][0])) { $x = $pl['opt']['popup'][0] * _MPDFK; }
  7284. else { $x = $pl['x'] * _MPDFK; }
  7285. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][1])) { $y = $hPt - ($pl['opt']['popup'][1] * _MPDFK); }
  7286. else { $y = $hPt - ($pl['y'] * _MPDFK); }
  7287. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][2])) { $w = $pl['opt']['popup'][2] * _MPDFK; }
  7288. else { $w = 180; }
  7289. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][3])) { $h = $pl['opt']['popup'][3] * _MPDFK; }
  7290. else { $h = 120; }
  7291. $rect = sprintf('%.3F %.3F %.3F %.3F', $x, $y-$h, $x+$w, $y);
  7292. $annot .= '<</Type /Annot /Subtype /Popup /Rect ['.$rect.']';
  7293. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  7294. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  7295. $annot .= ' /Parent '.($this->n-1).' 0 R';
  7296. $annot .= '>>';
  7297. $this->_out($annot);
  7298. $this->_out('endobj');
  7299. }
  7300. }
  7301. }
  7302. /*-- END ANNOTATIONS --*/
  7303. /*-- FORMS --*/
  7304. // Active Forms
  7305. if ( count($this->form->forms) > 0 ) {
  7306. $this->form->_putFormItems($n, $hPt);
  7307. }
  7308. /*-- END FORMS --*/
  7309. }
  7310. }
  7311. /*-- FORMS --*/
  7312. // Active Forms - Radio Button Group entries
  7313. // Output Radio Button Group form entries (radio_on_obj_id already determined)
  7314. if (count($this->form->form_radio_groups)) {
  7315. $this->form->_putRadioItems($n);
  7316. }
  7317. /*-- END FORMS --*/
  7318. }
  7319. /*-- ANNOTATIONS --*/
  7320. function Annotation($text, $x=0, $y=0, $icon='Note', $author='', $subject='', $opacity=0, $colarray=false, $popup='', $file='') {
  7321. if (is_array($colarray) && count($colarray)==3) { $colarray = $this->ConvertColor('rgb('.$colarray[0].','.$colarray[1].','.$colarray[2].')'); }
  7322. if ($colarray === false) { $colarray = $this->ConvertColor('yellow'); }
  7323. if ($x==0) { $x = $this->x; }
  7324. if ($y==0) { $y = $this->y; }
  7325. $page = $this->page;
  7326. if ($page < 1) { // Document has not been started - assume it's for first page
  7327. $page = 1;
  7328. if ($x==0) { $x = $this->lMargin; }
  7329. if ($y==0) { $y = $this->tMargin; }
  7330. }
  7331. if ($this->PDFA || $this->PDFX) {
  7332. 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)"; }
  7333. $x = ($this->w) - $this->rMargin*0.66;
  7334. }
  7335. if (!$this->annotMargin) { $y -= $this->FontSize / 2; }
  7336. if (!$opacity && $this->annotMargin) { $opacity = 1; }
  7337. else if (!$opacity) { $opacity = $this->annotOpacity; }
  7338. $an = array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file));
  7339. if ($this->keep_block_together) { // Save to array - don't write yet
  7340. $this->ktAnnots[$this->page][]= $an;
  7341. return;
  7342. }
  7343. else if ($this->table_rotate) {
  7344. $this->tbrot_Annots[$this->page][]= $an;
  7345. return;
  7346. }
  7347. else if ($this->kwt) {
  7348. $this->kwt_Annots[$this->page][]= $an;
  7349. return;
  7350. }
  7351. // mPDF 5.0
  7352. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  7353. $this->HTMLheaderPageAnnots[]= $an;
  7354. return;
  7355. }
  7356. //Put an Annotation on the page
  7357. $this->PageAnnots[$page][] = $an;
  7358. /*-- COLUMNS --*/
  7359. // Save cross-reference to Column buffer
  7360. $ref = count($this->PageAnnots[$this->page])-1;
  7361. $this->columnAnnots[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref;
  7362. /*-- END COLUMNS --*/
  7363. }
  7364. /*-- END ANNOTATIONS --*/
  7365. function _putfonts() {
  7366. $nf=$this->n;
  7367. foreach($this->FontFiles as $fontkey=>$info) {
  7368. // TrueType embedded
  7369. if (isset($info['type']) && $info['type']=='TTF' && !$info['sip'] && !$info['smp']) {
  7370. $used = true;
  7371. $asSubset = false;
  7372. foreach($this->fonts AS $k=>$f) {
  7373. if ($f['fontkey'] == $fontkey && $f['type']=='TTF') {
  7374. $used = $f['used'];
  7375. if ($used) {
  7376. $nChars = (ord($f['cw'][0]) << 8) + ord($f['cw'][1]);
  7377. $usage = intval(count($f['subset'])*100 / $nChars);
  7378. $fsize = $info['length1'];
  7379. // Always subset the very large TTF files
  7380. if ($fsize > ($this->maxTTFFilesize *1024)) { $asSubset = true; }
  7381. else if ($usage < $this->percentSubset) { $asSubset = true; }
  7382. }
  7383. if ($f['unAGlyphs']) $aaSubset = true; // mPDF 5.4.05
  7384. if ($this->PDFA || $this->PDFX) $asSubset = false;
  7385. $this->fonts[$k]['asSubset'] = $asSubset;
  7386. break;
  7387. }
  7388. }
  7389. if ($used && !$asSubset) {
  7390. //Font file embedding
  7391. $this->_newobj();
  7392. $this->FontFiles[$fontkey]['n']=$this->n;
  7393. $font='';
  7394. $originalsize = $info['length1'];
  7395. if ($this->repackageTTF || $this->fonts[$fontkey]['TTCfontID']>0) {
  7396. // First see if there is a cached compressed file
  7397. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z')) {
  7398. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z','rb');
  7399. if(!$f) { $this->Error('Font file .ps.z not found'); }
  7400. while(!feof($f)) { $font .= fread($f, 2048); }
  7401. fclose($f);
  7402. include(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php'); // sets $originalsize (of repackaged font)
  7403. }
  7404. else {
  7405. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7406. $ttf = new TTFontFile();
  7407. $font = $ttf->repackageTTF($this->FontFiles[$fontkey]['ttffile'], $this->fonts[$fontkey]['TTCfontID'], $this->debugfonts, $this->fonts[$fontkey]['unAGlyphs']); // mPDF 5.4.05
  7408. $originalsize = strlen($font);
  7409. $font = gzcompress($font);
  7410. unset($ttf);
  7411. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7412. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z',"wb");
  7413. fwrite($fh,$font,strlen($font));
  7414. fclose($fh);
  7415. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php',"wb");
  7416. $len = "<?php \n";
  7417. $len.='$originalsize='.$originalsize.";\n";
  7418. $len.="?>";
  7419. fwrite($fh,$len,strlen($len));
  7420. fclose($fh);
  7421. }
  7422. }
  7423. }
  7424. else {
  7425. // First see if there is a cached compressed file
  7426. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.z')) {
  7427. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z','rb');
  7428. if(!$f) { $this->Error('Font file not found'); }
  7429. while(!feof($f)) { $font .= fread($f, 2048); }
  7430. fclose($f);
  7431. }
  7432. else {
  7433. $f=fopen($this->FontFiles[$fontkey]['ttffile'],'rb');
  7434. if(!$f) { $this->Error('Font file not found'); }
  7435. while(!feof($f)) { $font .= fread($f, 2048); }
  7436. fclose($f);
  7437. $font = gzcompress($font);
  7438. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7439. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z',"wb");
  7440. fwrite($fh,$font,strlen($font));
  7441. fclose($fh);
  7442. }
  7443. }
  7444. }
  7445. $this->_out('<</Length '.strlen($font));
  7446. $this->_out('/Filter /FlateDecode');
  7447. $this->_out('/Length1 '.$originalsize);
  7448. $this->_out('>>');
  7449. $this->_putstream($font);
  7450. $this->_out('endobj');
  7451. }
  7452. }
  7453. }
  7454. $nfonts = count($this->fonts);
  7455. $fctr = 1;
  7456. foreach($this->fonts as $k=>$font) {
  7457. //Font objects
  7458. $type=$font['type'];
  7459. $name=$font['name'];
  7460. if ((!isset($font['used']) || !$font['used']) && $type=='TTF') { continue; }
  7461. if ($this->progressBar) { $this->UpdateProgressBar(2,intval($fctr*100/$nfonts),'Writing Fonts'); $fctr++; } // *PROGRESS-BAR*
  7462. if (isset($font['asSubset'])) { $asSubset = $font['asSubset']; }
  7463. else { $asSubset = ''; }
  7464. /*-- CJK-FONTS --*/
  7465. if($type=='Type0') { // = Adobe CJK Fonts
  7466. $this->fonts[$k]['n']=$this->n+1;
  7467. $this->_newobj();
  7468. $this->_out('<</Type /Font');
  7469. $this->_putType0($font);
  7470. }
  7471. else
  7472. /*-- END CJK-FONTS --*/
  7473. if($type=='core') {
  7474. //Standard font
  7475. $this->fonts[$k]['n']=$this->n+1;
  7476. 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.)'); }
  7477. $this->_newobj();
  7478. $this->_out('<</Type /Font');
  7479. $this->_out('/BaseFont /'.$name);
  7480. $this->_out('/Subtype /Type1');
  7481. if($name!='Symbol' && $name!='ZapfDingbats') {
  7482. $this->_out('/Encoding /WinAnsiEncoding');
  7483. }
  7484. $this->_out('>>');
  7485. $this->_out('endobj');
  7486. }
  7487. // TrueType embedded SUBSETS for SIP (CJK extB containing Supplementary Ideographic Plane 2)
  7488. // Or Unicode Plane 1 - Supplementary Multilingual Plane
  7489. else if ($type=='TTF' && ($font['sip'] || $font['smp'])) {
  7490. if (!$font['used']) { continue; }
  7491. $ssfaid="AA";
  7492. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7493. $ttf = new TTFontFile();
  7494. for($sfid=0;$sfid<count($font['subsetfontids']);$sfid++) {
  7495. $this->fonts[$k]['n'][$sfid]=$this->n+1; // NB an array for subset
  7496. $subsetname = 'MPDF'.$ssfaid.'+'.$font['name'];
  7497. $ssfaid++;
  7498. $subset = $font['subsets'][$sfid];
  7499. unset($subset[0]);
  7500. $ttfontstream = $ttf->makeSubsetSIP($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts);
  7501. $ttfontsize = strlen($ttfontstream);
  7502. $fontstream = gzcompress($ttfontstream);
  7503. $widthstring = '';
  7504. $toUnistring = '';
  7505. foreach($font['subsets'][$sfid] AS $cp=>$u) {
  7506. $w = $this->_getCharWidth($font['cw'], $u);
  7507. if ($w !== false) {
  7508. $widthstring .= $w.' ';
  7509. }
  7510. else {
  7511. $widthstring .= round($ttf->defaultWidth).' ';
  7512. }
  7513. if ($u > 65535) {
  7514. $utf8 = chr(($u>>18)+240).chr((($u>>12)&63)+128).chr((($u>>6)&63)+128) .chr(($u&63)+128);
  7515. $utf16 = mb_convert_encoding($utf8, 'UTF-16BE', 'UTF-8');
  7516. $l1 = ord($utf16[0]);
  7517. $h1 = ord($utf16[1]);
  7518. $l2 = ord($utf16[2]);
  7519. $h2 = ord($utf16[3]);
  7520. $toUnistring .= sprintf("<%02s> <%02s%02s%02s%02s>\n", strtoupper(dechex($cp)), strtoupper(dechex($l1)), strtoupper(dechex($h1)), strtoupper(dechex($l2)), strtoupper(dechex($h2)));
  7521. }
  7522. else {
  7523. $toUnistring .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), strtoupper(dechex($u)));
  7524. }
  7525. }
  7526. //Additional Type1 or TrueType font
  7527. $this->_newobj();
  7528. $this->_out('<</Type /Font');
  7529. $this->_out('/BaseFont /'.$subsetname);
  7530. $this->_out('/Subtype /TrueType');
  7531. $this->_out('/FirstChar 0 /LastChar '.(count($font['subsets'][$sfid])-1));
  7532. $this->_out('/Widths '.($this->n+1).' 0 R');
  7533. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  7534. $this->_out('/ToUnicode '.($this->n + 3).' 0 R');
  7535. $this->_out('>>');
  7536. $this->_out('endobj');
  7537. //Widths
  7538. $this->_newobj();
  7539. $this->_out('['.$widthstring.']');
  7540. $this->_out('endobj');
  7541. //Descriptor
  7542. $this->_newobj();
  7543. $s='<</Type /FontDescriptor /FontName /'.$subsetname."\n";
  7544. foreach($font['desc'] as $kd=>$v) {
  7545. if ($kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7546. $s.=' /'.$kd.' '.$v."\n";
  7547. }
  7548. $s.='/FontFile2 '.($this->n + 2).' 0 R';
  7549. $this->_out($s.'>>');
  7550. $this->_out('endobj');
  7551. // ToUnicode
  7552. $this->_newobj();
  7553. $toUni = "/CIDInit /ProcSet findresource begin\n";
  7554. $toUni .= "12 dict begin\n";
  7555. $toUni .= "begincmap\n";
  7556. $toUni .= "/CIDSystemInfo\n";
  7557. $toUni .= "<</Registry (Adobe)\n";
  7558. $toUni .= "/Ordering (UCS)\n";
  7559. $toUni .= "/Supplement 0\n";
  7560. $toUni .= ">> def\n";
  7561. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  7562. $toUni .= "/CMapType 2 def\n";
  7563. $toUni .= "1 begincodespacerange\n";
  7564. $toUni .= "<00> <FF>\n";
  7565. $toUni .= "endcodespacerange\n";
  7566. $toUni .= count($font['subsets'][$sfid])." beginbfchar\n";
  7567. $toUni .= $toUnistring;
  7568. $toUni .= "endbfchar\n";
  7569. $toUni .= "endcmap\n";
  7570. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  7571. $toUni .= "end\n";
  7572. $toUni .= "end\n";
  7573. $this->_out('<</Length '.(strlen($toUni)).'>>');
  7574. $this->_putstream($toUni);
  7575. $this->_out('endobj');
  7576. //Font file
  7577. $this->_newobj();
  7578. $this->_out('<</Length '.strlen($fontstream));
  7579. $this->_out('/Filter /FlateDecode');
  7580. $this->_out('/Length1 '.$ttfontsize);
  7581. $this->_out('>>');
  7582. $this->_putstream($fontstream);
  7583. $this->_out('endobj');
  7584. } // foreach subset
  7585. unset($ttf);
  7586. }
  7587. // TrueType embedded SUBSETS or FULL
  7588. else if ($type=='TTF') {
  7589. $this->fonts[$k]['n']=$this->n+1;
  7590. if ($asSubset ) {
  7591. $ssfaid="A";
  7592. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7593. $ttf = new TTFontFile();
  7594. $fontname = 'MPDFA'.$ssfaid.'+'.$font['name'];
  7595. $subset = $font['subset'];
  7596. unset($subset[0]);
  7597. $ttfontstream = $ttf->makeSubset($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts, $font['unAGlyphs']); // mPDF 5.4.05
  7598. $ttfontsize = strlen($ttfontstream);
  7599. $fontstream = gzcompress($ttfontstream);
  7600. $codeToGlyph = $ttf->codeToGlyph;
  7601. unset($codeToGlyph[0]);
  7602. }
  7603. else { $fontname = $font['name']; }
  7604. // Type0 Font
  7605. // A composite font - a font composed of other fonts, organized hierarchically
  7606. $this->_newobj();
  7607. $this->_out('<</Type /Font');
  7608. $this->_out('/Subtype /Type0');
  7609. $this->_out('/BaseFont /'.$fontname.'');
  7610. $this->_out('/Encoding /Identity-H');
  7611. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  7612. $this->_out('/ToUnicode '.($this->n + 2).' 0 R');
  7613. $this->_out('>>');
  7614. $this->_out('endobj');
  7615. // CIDFontType2
  7616. // A CIDFont whose glyph descriptions are based on TrueType font technology
  7617. $this->_newobj();
  7618. $this->_out('<</Type /Font');
  7619. $this->_out('/Subtype /CIDFontType2');
  7620. $this->_out('/BaseFont /'.$fontname.'');
  7621. $this->_out('/CIDSystemInfo '.($this->n + 2).' 0 R');
  7622. $this->_out('/FontDescriptor '.($this->n + 3).' 0 R');
  7623. if (isset($font['desc']['MissingWidth'])){
  7624. $this->_out('/DW '.$font['desc']['MissingWidth'].'');
  7625. }
  7626. if (!$asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw')) {
  7627. $w = '';
  7628. $w=file_get_contents(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw');
  7629. $this->_out($w);
  7630. }
  7631. else {
  7632. $this->_putTTfontwidths($font, $asSubset, $ttf->maxUni);
  7633. }
  7634. $this->_out('/CIDToGIDMap '.($this->n + 4).' 0 R');
  7635. $this->_out('>>');
  7636. $this->_out('endobj');
  7637. // ToUnicode
  7638. $this->_newobj();
  7639. $toUni = "/CIDInit /ProcSet findresource begin\n";
  7640. $toUni .= "12 dict begin\n";
  7641. $toUni .= "begincmap\n";
  7642. $toUni .= "/CIDSystemInfo\n";
  7643. $toUni .= "<</Registry (Adobe)\n";
  7644. $toUni .= "/Ordering (UCS)\n";
  7645. $toUni .= "/Supplement 0\n";
  7646. $toUni .= ">> def\n";
  7647. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  7648. $toUni .= "/CMapType 2 def\n";
  7649. $toUni .= "1 begincodespacerange\n";
  7650. $toUni .= "<0000> <FFFF>\n";
  7651. $toUni .= "endcodespacerange\n";
  7652. $toUni .= "1 beginbfrange\n";
  7653. $toUni .= "<0000> <FFFF> <0000>\n";
  7654. $toUni .= "endbfrange\n";
  7655. $toUni .= "endcmap\n";
  7656. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  7657. $toUni .= "end\n";
  7658. $toUni .= "end\n";
  7659. $this->_out('<</Length '.(strlen($toUni)).'>>');
  7660. $this->_putstream($toUni);
  7661. $this->_out('endobj');
  7662. // CIDSystemInfo dictionary
  7663. $this->_newobj();
  7664. $this->_out('<</Registry (Adobe)');
  7665. $this->_out('/Ordering (UCS)');
  7666. $this->_out('/Supplement 0');
  7667. $this->_out('>>');
  7668. $this->_out('endobj');
  7669. // Font descriptor
  7670. $this->_newobj();
  7671. $this->_out('<</Type /FontDescriptor');
  7672. $this->_out('/FontName /'.$fontname);
  7673. foreach($font['desc'] as $kd=>$v) {
  7674. if ($asSubset && $kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7675. $this->_out(' /'.$kd.' '.$v);
  7676. }
  7677. if ($font['panose']) {
  7678. $this->_out(' /Style << /Panose <'.$font['panose'].'> >>');
  7679. }
  7680. if ($asSubset ) {
  7681. $this->_out('/FontFile2 '.($this->n + 2).' 0 R');
  7682. }
  7683. else if ($font['fontkey']) {
  7684. // obj ID of a stream containing a TrueType font program
  7685. $this->_out('/FontFile2 '.$this->FontFiles[$font['fontkey']]['n'].' 0 R');
  7686. }
  7687. $this->_out('>>');
  7688. $this->_out('endobj');
  7689. // Embed CIDToGIDMap
  7690. // A specification of the mapping from CIDs to glyph indices
  7691. if ($asSubset ) {
  7692. $cidtogidmap = '';
  7693. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7694. foreach($codeToGlyph as $cc=>$glyph) {
  7695. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7696. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7697. }
  7698. $cidtogidmap = gzcompress($cidtogidmap);
  7699. }
  7700. else {
  7701. // First see if there is a cached CIDToGIDMapfile
  7702. $cidtogidmap = '';
  7703. if (file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm')) {
  7704. $f=fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm','rb');
  7705. while(!feof($f)) { $cidtogidmap .= fread($f, 2048); }
  7706. fclose($f);
  7707. }
  7708. else {
  7709. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7710. $ttf = new TTFontFile();
  7711. $charToGlyph = $ttf->getCTG($font['ttffile'], $font['TTCfontID'], $this->debugfonts, $font['unAGlyphs']); // mPDF 5.4.05
  7712. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7713. foreach($charToGlyph as $cc=>$glyph) {
  7714. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7715. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7716. }
  7717. unset($ttf);
  7718. $cidtogidmap = gzcompress($cidtogidmap);
  7719. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7720. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm',"wb");
  7721. fwrite($fh,$cidtogidmap,strlen($cidtogidmap));
  7722. fclose($fh);
  7723. }
  7724. }
  7725. }
  7726. $this->_newobj();
  7727. $this->_out('<</Length '.strlen($cidtogidmap).'');
  7728. $this->_out('/Filter /FlateDecode');
  7729. $this->_out('>>');
  7730. $this->_putstream($cidtogidmap);
  7731. $this->_out('endobj');
  7732. //Font file
  7733. if ($asSubset ) {
  7734. $this->_newobj();
  7735. $this->_out('<</Length '.strlen($fontstream));
  7736. $this->_out('/Filter /FlateDecode');
  7737. $this->_out('/Length1 '.$ttfontsize);
  7738. $this->_out('>>');
  7739. $this->_putstream($fontstream);
  7740. $this->_out('endobj');
  7741. unset($ttf);
  7742. }
  7743. }
  7744. else { $this->Error('Unsupported font type: '.$type.' ('.$name.')'); }
  7745. }
  7746. }
  7747. function _putTTfontwidths(&$font, $asSubset, $maxUni) {
  7748. if ($asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php')) {
  7749. include(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php') ;
  7750. $startcid = 128;
  7751. }
  7752. else {
  7753. $rangeid = 0;
  7754. $range = array();
  7755. $prevcid = -2;
  7756. $prevwidth = -1;
  7757. $interval = false;
  7758. $startcid = 1;
  7759. }
  7760. if ($asSubset) { $cwlen = $maxUni + 1; }
  7761. else { $cwlen = (strlen($font['cw'])/2); }
  7762. // for each character
  7763. for ($cid=$startcid; $cid<$cwlen; $cid++) {
  7764. if ($cid==128 && $asSubset && (!file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php'))) {
  7765. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7766. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php',"wb");
  7767. $cw127='<?php'."\n";
  7768. $cw127.='$rangeid='.$rangeid.";\n";
  7769. $cw127.='$prevcid='.$prevcid.";\n";
  7770. $cw127.='$prevwidth='.$prevwidth.";\n";
  7771. if ($interval) { $cw127.='$interval=true'.";\n"; }
  7772. else { $cw127.='$interval=false'.";\n"; }
  7773. $cw127.='$range='.var_export($range,true).";\n";
  7774. $cw127.="?>";
  7775. fwrite($fh,$cw127,strlen($cw127));
  7776. fclose($fh);
  7777. }
  7778. }
  7779. if ($font['cw'][$cid*2] == "\00" && $font['cw'][$cid*2+1] == "\00") { continue; }
  7780. $width = (ord($font['cw'][$cid*2]) << 8) + ord($font['cw'][$cid*2+1]);
  7781. if ($width == 65535) { $width = 0; }
  7782. if ($asSubset && $cid > 255 && (!isset($font['subset'][$cid]) || !$font['subset'][$cid])) {
  7783. continue;
  7784. }
  7785. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7786. if ($cid == ($prevcid + 1)) {
  7787. // consecutive CID
  7788. if ($width == $prevwidth) {
  7789. if ($width == $range[$rangeid][0]) {
  7790. $range[$rangeid][] = $width;
  7791. } else {
  7792. array_pop($range[$rangeid]);
  7793. // new range
  7794. $rangeid = $prevcid;
  7795. $range[$rangeid] = array();
  7796. $range[$rangeid][] = $prevwidth;
  7797. $range[$rangeid][] = $width;
  7798. }
  7799. $interval = true;
  7800. $range[$rangeid]['interval'] = true;
  7801. } else {
  7802. if ($interval) {
  7803. // new range
  7804. $rangeid = $cid;
  7805. $range[$rangeid] = array();
  7806. $range[$rangeid][] = $width;
  7807. } else {
  7808. $range[$rangeid][] = $width;
  7809. }
  7810. $interval = false;
  7811. }
  7812. } else {
  7813. // new range
  7814. $rangeid = $cid;
  7815. $range[$rangeid] = array();
  7816. $range[$rangeid][] = $width;
  7817. $interval = false;
  7818. }
  7819. $prevcid = $cid;
  7820. $prevwidth = $width;
  7821. }
  7822. }
  7823. $w = $this->_putfontranges($range);
  7824. $this->_out($w);
  7825. if (!$asSubset) {
  7826. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7827. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw',"wb");
  7828. fwrite($fh,$w,strlen($w));
  7829. fclose($fh);
  7830. }
  7831. }
  7832. }
  7833. function _putfontranges(&$range) {
  7834. // optimize ranges
  7835. $prevk = -1;
  7836. $nextk = -1;
  7837. $prevint = false;
  7838. foreach ($range as $k => $ws) {
  7839. $cws = count($ws);
  7840. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  7841. if (isset($range[$k]['interval'])) {
  7842. unset($range[$k]['interval']);
  7843. }
  7844. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  7845. unset($range[$k]);
  7846. } else {
  7847. $prevk = $k;
  7848. }
  7849. $nextk = $k + $cws;
  7850. if (isset($ws['interval'])) {
  7851. if ($cws > 3) {
  7852. $prevint = true;
  7853. } else {
  7854. $prevint = false;
  7855. }
  7856. unset($range[$k]['interval']);
  7857. --$nextk;
  7858. } else {
  7859. $prevint = false;
  7860. }
  7861. }
  7862. // output data
  7863. $w = '';
  7864. foreach ($range as $k => $ws) {
  7865. if (count(array_count_values($ws)) == 1) {
  7866. // interval mode is more compact
  7867. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  7868. } else {
  7869. // range mode
  7870. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]' . "\n";
  7871. }
  7872. }
  7873. return '/W ['.$w.' ]';
  7874. }
  7875. function _putfontwidths(&$font, $cidoffset=0) {
  7876. ksort($font['cw']);
  7877. unset($font['cw'][65535]);
  7878. $rangeid = 0;
  7879. $range = array();
  7880. $prevcid = -2;
  7881. $prevwidth = -1;
  7882. $interval = false;
  7883. // for each character
  7884. foreach ($font['cw'] as $cid => $width) {
  7885. $cid -= $cidoffset;
  7886. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7887. if ($cid == ($prevcid + 1)) {
  7888. // consecutive CID
  7889. if ($width == $prevwidth) {
  7890. if ($width == $range[$rangeid][0]) {
  7891. $range[$rangeid][] = $width;
  7892. } else {
  7893. array_pop($range[$rangeid]);
  7894. // new range
  7895. $rangeid = $prevcid;
  7896. $range[$rangeid] = array();
  7897. $range[$rangeid][] = $prevwidth;
  7898. $range[$rangeid][] = $width;
  7899. }
  7900. $interval = true;
  7901. $range[$rangeid]['interval'] = true;
  7902. } else {
  7903. if ($interval) {
  7904. // new range
  7905. $rangeid = $cid;
  7906. $range[$rangeid] = array();
  7907. $range[$rangeid][] = $width;
  7908. } else {
  7909. $range[$rangeid][] = $width;
  7910. }
  7911. $interval = false;
  7912. }
  7913. } else {
  7914. // new range
  7915. $rangeid = $cid;
  7916. $range[$rangeid] = array();
  7917. $range[$rangeid][] = $width;
  7918. $interval = false;
  7919. }
  7920. $prevcid = $cid;
  7921. $prevwidth = $width;
  7922. }
  7923. }
  7924. $this->_out($this->_putfontranges($range));
  7925. }
  7926. /*-- CJK-FONTS --*/
  7927. // from class PDF_Chinese CJK EXTENSIONS
  7928. function _putType0(&$font)
  7929. {
  7930. //Type0
  7931. $this->_out('/Subtype /Type0');
  7932. $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']);
  7933. $this->_out('/Encoding /'.$font['CMap']);
  7934. $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]');
  7935. $this->_out('>>');
  7936. $this->_out('endobj');
  7937. //CIDFont
  7938. $this->_newobj();
  7939. $this->_out('<</Type /Font');
  7940. $this->_out('/Subtype /CIDFontType0');
  7941. $this->_out('/BaseFont /'.$font['name']);
  7942. $cidinfo = '/Registry '.$this->_textstring('Adobe');
  7943. $cidinfo .= ' /Ordering '.$this->_textstring($font['registry']['ordering']);
  7944. $cidinfo .= ' /Supplement '.$font['registry']['supplement'];
  7945. $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  7946. $this->_out('/FontDescriptor '.($this->n+1).' 0 R');
  7947. if (isset($font['MissingWidth'])){
  7948. $this->_out('/DW '.$font['MissingWidth'].'');
  7949. }
  7950. $this->_putfontwidths($font, 31);
  7951. $this->_out('>>');
  7952. $this->_out('endobj');
  7953. //Font descriptor
  7954. $this->_newobj();
  7955. $s = '<</Type /FontDescriptor /FontName /'.$font['name'];
  7956. foreach ($font['desc'] as $k => $v) {
  7957. if ($k != 'Style') {
  7958. $s .= ' /'.$k.' '.$v.'';
  7959. }
  7960. }
  7961. $this->_out($s.'>>');
  7962. $this->_out('endobj');
  7963. }
  7964. /*-- END CJK-FONTS --*/
  7965. function _putimages()
  7966. {
  7967. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  7968. reset($this->images);
  7969. while(list($file,$info)=each($this->images)) {
  7970. $this->_newobj();
  7971. $this->images[$file]['n']=$this->n;
  7972. $this->_out('<</Type /XObject');
  7973. $this->_out('/Subtype /Image');
  7974. $this->_out('/Width '.$info['w']);
  7975. $this->_out('/Height '.$info['h']);
  7976. if (isset($info['masked'])) {
  7977. $this->_out('/SMask '.($this->n - 1).' 0 R');
  7978. }
  7979. if($info['cs']=='Indexed') {
  7980. 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.")."); }
  7981. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  7982. }
  7983. else {
  7984. $this->_out('/ColorSpace /'.$info['cs']);
  7985. if($info['cs']=='DeviceCMYK') {
  7986. if ($this->PDFA && $this->restrictColorSpace!=3) { $this->Error("PDFA1-b does not permit Images using mixed colour space (".$file.")."); }
  7987. if($info['type']=='jpg') { $this->_out('/Decode [1 0 1 0 1 0 1 0]'); }
  7988. }
  7989. 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.")."); }
  7990. }
  7991. $this->_out('/BitsPerComponent '.$info['bpc']);
  7992. if (isset($info['f']) && $info['f']) { $this->_out('/Filter /'.$info['f']); }
  7993. if(isset($info['parms'])) { $this->_out($info['parms']); }
  7994. if(isset($info['trns']) and is_array($info['trns'])) {
  7995. $trns='';
  7996. for($i=0;$i<count($info['trns']);$i++)
  7997. $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  7998. $this->_out('/Mask ['.$trns.']');
  7999. }
  8000. $this->_out('/Length '.strlen($info['data']).'>>');
  8001. $this->_putstream($info['data']);
  8002. unset($this->images[$file]['data']);
  8003. $this->_out('endobj');
  8004. //Palette
  8005. if($info['cs']=='Indexed') {
  8006. $this->_newobj();
  8007. $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  8008. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  8009. $this->_putstream($pal);
  8010. $this->_out('endobj');
  8011. }
  8012. }
  8013. }
  8014. function _putinfo()
  8015. {
  8016. $this->_out('/Producer '.$this->_UTF16BEtextstring('mPDF '.mPDF_VERSION));
  8017. if(!empty($this->title))
  8018. $this->_out('/Title '.$this->_UTF16BEtextstring($this->title));
  8019. if(!empty($this->subject))
  8020. $this->_out('/Subject '.$this->_UTF16BEtextstring($this->subject));
  8021. if(!empty($this->author))
  8022. $this->_out('/Author '.$this->_UTF16BEtextstring($this->author));
  8023. if(!empty($this->keywords))
  8024. $this->_out('/Keywords '.$this->_UTF16BEtextstring($this->keywords));
  8025. if(!empty($this->creator))
  8026. $this->_out('/Creator '.$this->_UTF16BEtextstring($this->creator));
  8027. $z = date('O'); // +0200
  8028. $offset = substr($z,0,3)."'".substr($z,3,2)."'";
  8029. $this->_out('/CreationDate '.$this->_textstring(date('YmdHis').$offset));
  8030. $this->_out('/ModDate '.$this->_textstring(date('YmdHis').$offset));
  8031. if ($this->PDFX) {
  8032. $this->_out('/Trapped/False');
  8033. $this->_out('/GTS_PDFXVersion(PDF/X-1a:2003)');
  8034. }
  8035. }
  8036. function _putmetadata() {
  8037. $this->_newobj();
  8038. $this->MetadataRoot = $this->n;
  8039. $Producer = 'mPDF '.mPDF_VERSION;
  8040. $z = date('O'); // +0200
  8041. $offset = substr($z,0,3).':'.substr($z,3,2);
  8042. $CreationDate = date('Y-m-d\TH:i:s').$offset; // 2006-03-10T10:47:26-05:00 2006-06-19T09:05:17Z
  8043. $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  8044. mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
  8045. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) );
  8046. $m = '<?xpacket begin="'.chr(239).chr(187).chr(191).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; // begin = FEFF BOM
  8047. $m .= ' <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701">'."\n";
  8048. $m .= ' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  8049. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  8050. $m .= ' <pdf:Producer>'.$Producer.'</pdf:Producer>'."\n";
  8051. if(!empty($this->keywords)) { $m .= ' <pdf:Keywords>'.$this->keywords.'</pdf:Keywords>'."\n"; }
  8052. $m .= ' </rdf:Description>'."\n";
  8053. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  8054. $m .= ' <xmp:CreateDate>'.$CreationDate.'</xmp:CreateDate>'."\n";
  8055. $m .= ' <xmp:ModifyDate>'.$CreationDate.'</xmp:ModifyDate>'."\n";
  8056. $m .= ' <xmp:MetadataDate>'.$CreationDate.'</xmp:MetadataDate>'."\n";
  8057. if(!empty($this->creator)) { $m .= ' <xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n"; }
  8058. $m .= ' </rdf:Description>'."\n";
  8059. // DC elements
  8060. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  8061. $m .= ' <dc:format>application/pdf</dc:format>'."\n";
  8062. if(!empty($this->title)) {
  8063. $m .= ' <dc:title>
  8064. <rdf:Alt>
  8065. <rdf:li xml:lang="x-default">'.$this->title.'</rdf:li>
  8066. </rdf:Alt>
  8067. </dc:title>'."\n";
  8068. }
  8069. if(!empty($this->keywords)) {
  8070. $m .= ' <dc:subject>
  8071. <rdf:Bag>
  8072. <rdf:li>'.$this->keywords.'</rdf:li>
  8073. </rdf:Bag>
  8074. </dc:subject>'."\n";
  8075. }
  8076. if(!empty($this->subject)) {
  8077. $m .= ' <dc:description>
  8078. <rdf:Alt>
  8079. <rdf:li xml:lang="x-default">'.$this->subject.'</rdf:li>
  8080. </rdf:Alt>
  8081. </dc:description>'."\n";
  8082. }
  8083. if(!empty($this->author)) {
  8084. $m .= ' <dc:creator>
  8085. <rdf:Seq>
  8086. <rdf:li>'.$this->author.'</rdf:li>
  8087. </rdf:Seq>
  8088. </dc:creator>'."\n";
  8089. }
  8090. $m .= ' </rdf:Description>'."\n";
  8091. // This bit is specific to PDFX-1a
  8092. if ($this->PDFX) {
  8093. $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";
  8094. }
  8095. // This bit is specific to PDFA-1b
  8096. else if ($this->PDFA) {
  8097. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" >'."\n";
  8098. $m .= ' <pdfaid:part>1</pdfaid:part>'."\n";
  8099. $m .= ' <pdfaid:conformance>B</pdfaid:conformance>'."\n";
  8100. $m .= ' <pdfaid:amd>2005</pdfaid:amd>'."\n";
  8101. $m .= ' </rdf:Description>'."\n";
  8102. }
  8103. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  8104. $m .= ' <xmpMM:DocumentID>uuid:'.$uuid.'</xmpMM:DocumentID>'."\n";
  8105. $m .= ' </rdf:Description>'."\n";
  8106. $m .= ' </rdf:RDF>'."\n";
  8107. $m .= ' </x:xmpmeta>'."\n";
  8108. $m .= str_repeat(str_repeat(' ',100)."\n",20); // 2-4kB whitespace padding required
  8109. $m .= '<?xpacket end="w"?>'; // "r" read only
  8110. $this->_out('<</Type/Metadata/Subtype/XML/Length '.strlen($m).'>>');
  8111. $this->_putstream($m);
  8112. $this->_out('endobj');
  8113. }
  8114. function _putoutputintent() {
  8115. $this->_newobj();
  8116. $this->OutputIntentRoot = $this->n;
  8117. $this->_out('<</Type /OutputIntent');
  8118. if ($this->PDFA) {
  8119. $this->_out('/S /GTS_PDFA1');
  8120. if ($this->ICCProfile) {
  8121. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  8122. $this->_out('/OutputConditionIdentifier (Custom)');
  8123. $this->_out('/OutputCondition ()');
  8124. }
  8125. else {
  8126. $this->_out('/Info (sRGB IEC61966-2.1)');
  8127. $this->_out('/OutputConditionIdentifier (sRGB IEC61966-2.1)');
  8128. $this->_out('/OutputCondition ()');
  8129. }
  8130. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  8131. }
  8132. else if ($this->PDFX) { // always a CMYK profile
  8133. $this->_out('/S /GTS_PDFX');
  8134. if ($this->ICCProfile) {
  8135. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  8136. $this->_out('/OutputConditionIdentifier (Custom)');
  8137. $this->_out('/OutputCondition ()');
  8138. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  8139. }
  8140. else {
  8141. $this->_out('/Info (CGATS TR 001)');
  8142. $this->_out('/OutputConditionIdentifier (CGATS TR 001)');
  8143. $this->_out('/OutputCondition (CGATS TR 001 (SWOP))');
  8144. $this->_out('/RegistryName (http://www.color.org)');
  8145. }
  8146. }
  8147. $this->_out('>>');
  8148. $this->_out('endobj');
  8149. if ($this->PDFX && !$this->ICCProfile) { return; } // no ICCProfile embedded
  8150. $this->_newobj();
  8151. if ($this->ICCProfile)
  8152. $s = file_get_contents(_MPDF_PATH.'iccprofiles/'.$this->ICCProfile.'.icc');
  8153. else
  8154. $s = file_get_contents(_MPDF_PATH.'iccprofiles/sRGB_IEC61966-2-1.icc');
  8155. if ($this->compress) { $s = gzcompress($s); }
  8156. $this->_out('<<');
  8157. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace == 3)) { $this->_out('/N 4'); }
  8158. else { $this->_out('/N 3'); }
  8159. if ($this->compress)
  8160. $this->_out('/Filter /FlateDecode ');
  8161. $this->_out('/Length '.strlen($s).'>>');
  8162. $this->_putstream($s);
  8163. $this->_out('endobj');
  8164. }
  8165. function _putcatalog() {
  8166. $this->_out('/Type /Catalog');
  8167. $this->_out('/Pages 1 0 R');
  8168. if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]');
  8169. elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]');
  8170. elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  8171. elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  8172. else $this->_out('/OpenAction [3 0 R /XYZ null null null]');
  8173. if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage');
  8174. elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn');
  8175. elseif($this->LayoutMode=='twoleft') $this->_out('/PageLayout /TwoColumnLeft');
  8176. elseif($this->LayoutMode=='tworight') $this->_out('/PageLayout /TwoColumnRight');
  8177. elseif($this->LayoutMode=='two') {
  8178. if ($this->mirrorMargins) { $this->_out('/PageLayout /TwoColumnRight'); }
  8179. else { $this->_out('/PageLayout /TwoColumnLeft'); }
  8180. }
  8181. /*-- BOOKMARKS --*/
  8182. if(count($this->BMoutlines)>0) {
  8183. $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  8184. $this->_out('/PageMode /UseOutlines');
  8185. }
  8186. /*-- END BOOKMARKS --*/
  8187. if(is_int(strpos($this->DisplayPreferences,'FullScreen'))) $this->_out('/PageMode /FullScreen');
  8188. // Metadata
  8189. if ($this->PDFA || $this->PDFX) {
  8190. $this->_out('/Metadata '.$this->MetadataRoot.' 0 R');
  8191. }
  8192. // OutputIntents
  8193. if ($this->PDFA || $this->PDFX || $this->ICCProfile) {
  8194. $this->_out('/OutputIntents ['.$this->OutputIntentRoot.' 0 R]');
  8195. }
  8196. /*-- FORMS --*/
  8197. if (count($this->form->forms)>0) {
  8198. $this->form->_putFormsCatalog();
  8199. }
  8200. /*-- END FORMS --*/
  8201. if ( isset($this->js) ) {
  8202. $this->_out('/Names << /JavaScript '.($this->n_js).' 0 R >> ');
  8203. }
  8204. if($this->DisplayPreferences || $this->directionality == 'rtl' || $this->mirrorMargins) {
  8205. $this->_out('/ViewerPreferences<<');
  8206. if(is_int(strpos($this->DisplayPreferences,'HideMenubar'))) $this->_out('/HideMenubar true');
  8207. if(is_int(strpos($this->DisplayPreferences,'HideToolbar'))) $this->_out('/HideToolbar true');
  8208. if(is_int(strpos($this->DisplayPreferences,'HideWindowUI'))) $this->_out('/HideWindowUI true');
  8209. if(is_int(strpos($this->DisplayPreferences,'DisplayDocTitle'))) $this->_out('/DisplayDocTitle true');
  8210. if(is_int(strpos($this->DisplayPreferences,'CenterWindow'))) $this->_out('/CenterWindow true');
  8211. if(is_int(strpos($this->DisplayPreferences,'FitWindow'))) $this->_out('/FitWindow true');
  8212. // /PrintScaling is PDF 1.6 spec.
  8213. if(is_int(strpos($this->DisplayPreferences,'NoPrintScaling')) && !$this->PDFA && !$this->PDFX)
  8214. $this->_out('/PrintScaling /None');
  8215. if($this->directionality == 'rtl') $this->_out('/Direction /R2L');
  8216. // /Duplex is PDF 1.7 spec.
  8217. if($this->mirrorMargins && !$this->PDFA && !$this->PDFX) {
  8218. // if ($this->DefOrientation=='P') $this->_out('/Duplex /DuplexFlipShortEdge');
  8219. $this->_out('/Duplex /DuplexFlipLongEdge'); // PDF v1.7+
  8220. }
  8221. $this->_out('>>');
  8222. }
  8223. // mPDF 5.6.01
  8224. if($this->open_layer_pane && ($this->hasOC || count($this->layers)))
  8225. $this->_out('/PageMode /UseOC');
  8226. // mPDF 5.6.01
  8227. if ($this->hasOC || count($this->layers)) {
  8228. $p = $v = $h = $l = $loff = $lall = $as = ''; // mPDF 5.6.28
  8229. if ($this->hasOC) {
  8230. if (($this->hasOC & 1) == 1) $p=$this->n_ocg_print.' 0 R';
  8231. if (($this->hasOC & 2) == 2) $v=$this->n_ocg_view.' 0 R';
  8232. if (($this->hasOC & 4) == 4) $h=$this->n_ocg_hidden.' 0 R';
  8233. $as="<</Event /Print /OCGs [$p $v $h] /Category [/Print]>> <</Event /View /OCGs [$p $v $h] /Category [/View]>>";
  8234. }
  8235. if(count($this->layers)) {
  8236. foreach($this->layers as $k=>$layer) { // mPDF 5.6.28
  8237. if (strtolower($this->layerDetails[$k]['state'])=='hidden') { $loff .= $layer['n'].' 0 R '; }
  8238. else { $l .= $layer['n'].' 0 R '; }
  8239. $lall .= $layer['n'].' 0 R ';
  8240. }
  8241. }
  8242. $this->_out("/OCProperties <</OCGs [$p $v $h $lall] /D <</ON [$p $l] /OFF [$v $h $loff] "); // mPDF 5.6.28
  8243. $this->_out("/Order [$v $p $h $lall] "); // mPDF 5.6.28
  8244. if ($as) $this->_out("/AS [$as] ");
  8245. $this->_out(">>>>");
  8246. }
  8247. }
  8248. // Inactive function left for backwards compatability
  8249. function SetUserRights($enable=true, $annots="", $form="", $signature="") {
  8250. // Does nothing
  8251. }
  8252. function _enddoc() {
  8253. if ($this->progressBar) { $this->UpdateProgressBar(2,'10','Writing Headers & Footers'); } // *PROGRESS-BAR*
  8254. $this->_puthtmlheaders(); // *HTMLHEADERS-FOOTERS*
  8255. if ($this->progressBar) { $this->UpdateProgressBar(2,'20','Writing Pages'); } // *PROGRESS-BAR*
  8256. // Remove references to unused fonts (usually default font)
  8257. foreach($this->fonts as $fk=>$font) {
  8258. if (!$font['used'] && ($font['type']=='TTF')) {
  8259. if ($font['sip'] || $font['smp']) {
  8260. foreach($font['subsetfontids'] AS $k => $fid) {
  8261. foreach($this->pages AS $pn=>$page) {
  8262. $this->pages[$pn] = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  8263. }
  8264. }
  8265. }
  8266. else {
  8267. foreach($this->pages AS $pn=>$page) {
  8268. $this->pages[$pn] = preg_replace('/\s\/F'.$font['i'].' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  8269. }
  8270. }
  8271. }
  8272. }
  8273. // mPDF 5.6.01 - LAYERS
  8274. if (count($this->layers)) {
  8275. foreach($this->pages AS $pn=>$page) {
  8276. preg_match_all('/\/OCZ-index \/ZI(\d+) BDC(.*?)(EMCZ)-index/is',$this->pages[$pn],$m1);
  8277. preg_match_all('/\/OCBZ-index \/ZI(\d+) BDC(.*?)(EMCBZ)-index/is',$this->pages[$pn],$m2);
  8278. preg_match_all('/\/OCGZ-index \/ZI(\d+) BDC(.*?)(EMCGZ)-index/is',$this->pages[$pn],$m3);
  8279. $m = array();
  8280. for ($i=0;$i<4;$i++) {
  8281. $m[$i] = array_merge($m1[$i],$m2[$i],$m3[$i]);
  8282. }
  8283. if (count($m[0])) {
  8284. $sortarr = array();
  8285. for($i=0;$i<count($m[0]);$i++) {
  8286. $key = $m[1][$i]*2;
  8287. if ($m[3][$i]=='EMCZ') $key +=2; // background first then gradient then normal
  8288. else if ($m[3][$i]=='EMCGZ') $key +=1;
  8289. $sortarr[$i] = $key;
  8290. }
  8291. asort($sortarr);
  8292. foreach($sortarr AS $i=>$k) {
  8293. $this->pages[$pn] = str_replace($m[0][$i],'',$this->pages[$pn] );
  8294. $this->pages[$pn] .= "\n".$m[0][$i]."\n";
  8295. }
  8296. $this->pages[$pn] = preg_replace('/\/OC[BG]{0,1}Z-index \/ZI(\d+) BDC/is','/OC /ZI\\1 BDC ',$this->pages[$pn]);
  8297. $this->pages[$pn] = preg_replace('/EMC[BG]{0,1}Z-index/is','EMC',$this->pages[$pn]);
  8298. }
  8299. }
  8300. }
  8301. $this->_putpages();
  8302. if ($this->progressBar) { $this->UpdateProgressBar(2,'30','Writing document resources'); } // *PROGRESS-BAR*
  8303. $this->_putresources();
  8304. //Info
  8305. $this->_newobj();
  8306. $this->InfoRoot = $this->n;
  8307. $this->_out('<<');
  8308. if ($this->progressBar) { $this->UpdateProgressBar(2,'80','Writing document info'); } // *PROGRESS-BAR*
  8309. $this->_putinfo();
  8310. $this->_out('>>');
  8311. $this->_out('endobj');
  8312. // METADATA
  8313. if ($this->PDFA || $this->PDFX) { $this->_putmetadata(); }
  8314. // OUTPUTINTENT
  8315. if ($this->PDFA || $this->PDFX || $this->ICCProfile) { $this->_putoutputintent(); }
  8316. //Catalog
  8317. $this->_newobj();
  8318. $this->_out('<<');
  8319. if ($this->progressBar) { $this->UpdateProgressBar(2,'90','Writing document catalog'); } // *PROGRESS-BAR*
  8320. $this->_putcatalog();
  8321. $this->_out('>>');
  8322. $this->_out('endobj');
  8323. //Cross-ref
  8324. $o=strlen($this->buffer);
  8325. $this->_out('xref');
  8326. $this->_out('0 '.($this->n+1));
  8327. $this->_out('0000000000 65535 f ');
  8328. for($i=1; $i <= $this->n ; $i++)
  8329. $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  8330. //Trailer
  8331. $this->_out('trailer');
  8332. $this->_out('<<');
  8333. $this->_puttrailer();
  8334. $this->_out('>>');
  8335. $this->_out('startxref');
  8336. $this->_out($o);
  8337. $this->buffer .= '%%EOF';
  8338. $this->state=3;
  8339. /*-- IMPORTS --*/
  8340. if ($this->enableImports && count($this->parsers) > 0) {
  8341. foreach ($this->parsers as $k => $_){
  8342. $this->parsers[$k]->closeFile();
  8343. $this->parsers[$k] = null;
  8344. unset($this->parsers[$k]);
  8345. }
  8346. }
  8347. /*-- END IMPORTS --*/
  8348. }
  8349. function _beginpage($orientation,$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') {
  8350. if (!($pagesel && $this->page==1 && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)))) {
  8351. $this->page++;
  8352. $this->pages[$this->page]='';
  8353. }
  8354. $this->state=2;
  8355. $resetHTMLHeadersrequired = false;
  8356. if ($newformat) { $this->_setPageSize($newformat, $orientation); }
  8357. /*-- CSS-PAGE --*/
  8358. // Paged media (page-box)
  8359. if ($pagesel || (isset($this->page_box['using']) && $this->page_box['using'])) {
  8360. if ($pagesel || $this->page==1) { $first = true; }
  8361. else { $first = false; }
  8362. if ($this->mirrorMargins && ($this->page % 2==0)) { $oddEven = 'E'; }
  8363. else { $oddEven = 'O'; }
  8364. if ($pagesel) { $psel = $pagesel; }
  8365. else if ($this->page_box['current']) { $psel = $this->page_box['current']; }
  8366. else { $psel = ''; }
  8367. list($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS($psel, $first, $oddEven);
  8368. if ($this->mirrorMargins && ($this->page % 2==0)) {
  8369. if ($hname) { $ehvalue = 1; $ehname = $hname; } else { $ehvalue = -1; }
  8370. if ($fname) { $efvalue = 1; $efname = $fname; } else { $efvalue = -1; }
  8371. }
  8372. else {
  8373. if ($hname) { $ohvalue = 1; $ohname = $hname; } else { $ohvalue = -1; }
  8374. if ($fname) { $ofvalue = 1; $ofname = $fname; } else { $ofvalue = -1; }
  8375. }
  8376. if ($resetpagenum || $pagenumstyle || $suppress) {
  8377. $this->PageNumSubstitutions[] = array('from'=>($this->page), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  8378. }
  8379. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  8380. $this->show_marks = $marks;
  8381. // Background color
  8382. if (isset($bg['BACKGROUND-COLOR'])) {
  8383. $cor = $this->ConvertColor($bg['BACKGROUND-COLOR']);
  8384. if ($cor) {
  8385. $this->bodyBackgroundColor = $cor;
  8386. }
  8387. }
  8388. else { $this->bodyBackgroundColor = false; }
  8389. /*-- BACKGROUNDS --*/
  8390. if (isset($bg['BACKGROUND-GRADIENT'])) {
  8391. $this->bodyBackgroundGradient = $bg['BACKGROUND-GRADIENT'];
  8392. }
  8393. else { $this->bodyBackgroundGradient = false; }
  8394. // Tiling Patterns
  8395. if (isset($bg['BACKGROUND-IMAGE']) && $bg['BACKGROUND-IMAGE']) {
  8396. $ret = $this->SetBackground($bg, $this->pgwidth);
  8397. if ($ret) { $this->bodyBackgroundImage = $ret; }
  8398. }
  8399. else { $this->bodyBackgroundImage = false; }
  8400. /*-- END BACKGROUNDS --*/
  8401. $this->page_box['current'] = $psel;
  8402. $this->page_box['using'] = true;
  8403. }
  8404. /*-- END CSS-PAGE --*/
  8405. //Page orientation
  8406. if(!$orientation)
  8407. $orientation=$this->DefOrientation;
  8408. else {
  8409. $orientation=strtoupper(substr($orientation,0,1));
  8410. if($orientation!=$this->DefOrientation)
  8411. $this->OrientationChanges[$this->page]=true;
  8412. }
  8413. if($orientation!=$this->CurOrientation || $newformat) {
  8414. //Change orientation
  8415. if($orientation=='P') {
  8416. $this->wPt=$this->fwPt;
  8417. $this->hPt=$this->fhPt;
  8418. $this->w=$this->fw;
  8419. $this->h=$this->fh;
  8420. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  8421. $this->tMargin = $this->orig_tMargin;
  8422. $this->bMargin = $this->orig_bMargin;
  8423. $this->DeflMargin = $this->orig_lMargin;
  8424. $this->DefrMargin = $this->orig_rMargin;
  8425. $this->margin_header = $this->orig_hMargin;
  8426. $this->margin_footer = $this->orig_fMargin;
  8427. }
  8428. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  8429. }
  8430. else {
  8431. $this->wPt=$this->fhPt;
  8432. $this->hPt=$this->fwPt;
  8433. $this->w=$this->fh;
  8434. $this->h=$this->fw;
  8435. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  8436. $this->tMargin = $this->orig_lMargin;
  8437. $this->bMargin = $this->orig_rMargin;
  8438. $this->DeflMargin = $this->orig_bMargin;
  8439. $this->DefrMargin = $this->orig_tMargin;
  8440. $this->margin_header = $this->orig_hMargin;
  8441. $this->margin_footer = $this->orig_fMargin;
  8442. }
  8443. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  8444. }
  8445. $this->CurOrientation=$orientation;
  8446. $this->ResetMargins();
  8447. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8448. $this->PageBreakTrigger=$this->h-$this->bMargin;
  8449. }
  8450. $this->pageDim[$this->page]['w']=$this->w ;
  8451. $this->pageDim[$this->page]['h']=$this->h ;
  8452. $this->pageDim[$this->page]['outer_width_LR'] = isset($this->page_box['outer_width_LR']) ? $this->page_box['outer_width_LR'] : 0;
  8453. $this->pageDim[$this->page]['outer_width_TB'] = isset($this->page_box['outer_width_TB']) ? $this->page_box['outer_width_TB'] : 0;
  8454. if (!isset($this->page_box['outer_width_LR']) && !isset($this->page_box['outer_width_TB'])) {
  8455. $this->pageDim[$this->page]['bleedMargin'] = 0;
  8456. }
  8457. else if ($this->bleedMargin <= $this->page_box['outer_width_LR'] && $this->bleedMargin <= $this->page_box['outer_width_TB']) {
  8458. $this->pageDim[$this->page]['bleedMargin'] = $this->bleedMargin;
  8459. }
  8460. else {
  8461. $this->pageDim[$this->page]['bleedMargin'] = min($this->page_box['outer_width_LR'], $this->page_box['outer_width_TB'])-0.01;
  8462. }
  8463. // If Page Margins are re-defined
  8464. // strlen()>0 is used to pick up (integer) 0, (string) '0', or set value
  8465. 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)) {
  8466. if (strlen($mgl)>0) $this->DeflMargin = $mgl;
  8467. if (strlen($mgr)>0) $this->DefrMargin = $mgr;
  8468. if (strlen($mgt)>0) $this->tMargin = $mgt;
  8469. if (strlen($mgb)>0) $this->bMargin = $mgb;
  8470. if (strlen($mgh)>0) $this->margin_header=$mgh;
  8471. if (strlen($mgf)>0) $this->margin_footer=$mgf;
  8472. $this->ResetMargins();
  8473. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8474. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8475. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8476. }
  8477. $this->ResetMargins();
  8478. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8479. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8480. // Reset column top margin
  8481. $this->y0 = $this->tMargin;
  8482. $this->x=$this->lMargin;
  8483. $this->y=$this->tMargin;
  8484. $this->FontFamily='';
  8485. // HEADERS AND FOOTERS
  8486. if ($ohvalue<0 || strtoupper($ohvalue)=='OFF') {
  8487. $this->HTMLHeader = '';
  8488. $this->headerDetails['odd'] = array();
  8489. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8490. }
  8491. else if ($ohname && $ohvalue>0) {
  8492. /*-- HTMLHEADERS-FOOTERS --*/
  8493. if (preg_match('/^html_(.*)$/i',$ohname,$n)) {
  8494. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeader = $this->pageHTMLheaders[$n[1]]; }
  8495. else { $this->HTMLHeader = ''; }
  8496. $this->headerDetails['odd'] = array();
  8497. $resetHTMLHeadersrequired = true;
  8498. }
  8499. else {
  8500. /*-- END HTMLHEADERS-FOOTERS --*/
  8501. if (isset($this->pageheaders[$ohname])) { $this->headerDetails['odd'] = $this->pageheaders[$ohname]; }
  8502. else if ($ohname!='_default') { $this->headerDetails['odd'] = array(); }
  8503. $this->HTMLHeader = '';
  8504. /*-- HTMLHEADERS-FOOTERS --*/
  8505. $resetHTMLHeadersrequired = false;
  8506. }
  8507. /*-- END HTMLHEADERS-FOOTERS --*/
  8508. }
  8509. if ($ehvalue<0 || strtoupper($ehvalue)=='OFF') {
  8510. $this->HTMLHeaderE = '';
  8511. $this->headerDetails['even'] = array();
  8512. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8513. }
  8514. else if ($ehname && $ehvalue>0) {
  8515. /*-- HTMLHEADERS-FOOTERS --*/
  8516. if (preg_match('/^html_(.*)$/i',$ehname,$n)) {
  8517. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeaderE = $this->pageHTMLheaders[$n[1]]; }
  8518. else { $this->HTMLHeaderE = ''; }
  8519. $this->headerDetails['even'] = array();
  8520. $resetHTMLHeadersrequired = true;
  8521. }
  8522. else {
  8523. /*-- END HTMLHEADERS-FOOTERS --*/
  8524. if (isset($this->pageheaders[$ehname])) { $this->headerDetails['even'] = $this->pageheaders[$ehname]; }
  8525. else if ($ehname!='_default') { $this->headerDetails['even'] = array(); }
  8526. $this->HTMLHeaderE = '';
  8527. /*-- HTMLHEADERS-FOOTERS --*/
  8528. $resetHTMLHeadersrequired = false;
  8529. }
  8530. /*-- END HTMLHEADERS-FOOTERS --*/
  8531. }
  8532. if ($ofvalue<0 || strtoupper($ofvalue)=='OFF') {
  8533. $this->HTMLFooter = '';
  8534. $this->footerDetails['odd'] = array();
  8535. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8536. }
  8537. else if ($ofname && $ofvalue>0) {
  8538. /*-- HTMLHEADERS-FOOTERS --*/
  8539. if (preg_match('/^html_(.*)$/i',$ofname,$n)) {
  8540. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooter = $this->pageHTMLfooters[$n[1]]; }
  8541. else { $this->HTMLFooter = ''; }
  8542. $this->footerDetails['odd'] = array();
  8543. $resetHTMLHeadersrequired = true;
  8544. }
  8545. else {
  8546. /*-- END HTMLHEADERS-FOOTERS --*/
  8547. if (isset($this->pagefooters[$ofname])) { $this->footerDetails['odd'] = $this->pagefooters[$ofname]; }
  8548. else if ($ofname!='_default') { $this->footerDetails['odd'] = array(); }
  8549. $this->HTMLFooter = '';
  8550. /*-- HTMLHEADERS-FOOTERS --*/
  8551. $resetHTMLHeadersrequired = true;
  8552. }
  8553. /*-- END HTMLHEADERS-FOOTERS --*/
  8554. }
  8555. if ($efvalue<0 || strtoupper($efvalue)=='OFF') {
  8556. $this->HTMLFooterE = '';
  8557. $this->footerDetails['even'] = array();
  8558. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8559. }
  8560. else if ($efname && $efvalue>0) {
  8561. /*-- HTMLHEADERS-FOOTERS --*/
  8562. if (preg_match('/^html_(.*)$/i',$efname,$n)) {
  8563. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooterE = $this->pageHTMLfooters[$n[1]]; }
  8564. else { $this->HTMLFooterE = ''; }
  8565. $this->footerDetails['even'] = array();
  8566. $resetHTMLHeadersrequired = true;
  8567. }
  8568. else {
  8569. /*-- END HTMLHEADERS-FOOTERS --*/
  8570. if (isset($this->pagefooters[$efname])) { $this->footerDetails['even'] = $this->pagefooters[$efname]; }
  8571. else if ($efname!='_default') { $this->footerDetails['even'] = array(); }
  8572. $this->HTMLFooterE = '';
  8573. /*-- HTMLHEADERS-FOOTERS --*/
  8574. $resetHTMLHeadersrequired = true;
  8575. }
  8576. /*-- END HTMLHEADERS-FOOTERS --*/
  8577. }
  8578. /*-- HTMLHEADERS-FOOTERS --*/
  8579. if ($resetHTMLHeadersrequired) {
  8580. $this->SetHTMLHeader($this->HTMLHeader );
  8581. $this->SetHTMLHeader($this->HTMLHeaderE ,'E');
  8582. $this->SetHTMLFooter($this->HTMLFooter );
  8583. $this->SetHTMLFooter($this->HTMLFooterE ,'E');
  8584. }
  8585. /*-- END HTMLHEADERS-FOOTERS --*/
  8586. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  8587. $this->_setAutoHeaderHeight($this->headerDetails['even'], $this->HTMLHeaderE);
  8588. $this->_setAutoFooterHeight($this->footerDetails['even'], $this->HTMLFooterE);
  8589. }
  8590. else { // ODD or DEFAULT
  8591. $this->_setAutoHeaderHeight($this->headerDetails['odd'], $this->HTMLHeader);
  8592. $this->_setAutoFooterHeight($this->footerDetails['odd'], $this->HTMLFooter);
  8593. }
  8594. // Reset column top margin
  8595. $this->y0 = $this->tMargin;
  8596. $this->x=$this->lMargin;
  8597. $this->y=$this->tMargin;
  8598. }
  8599. function _setAutoHeaderHeight(&$det, &$htmlh) {
  8600. if ($this->setAutoTopMargin=='pad') {
  8601. if ($htmlh['h']) { $h = $htmlh['h']; }
  8602. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8603. else { $h = 0; }
  8604. $this->tMargin = $this->margin_header + $h + $this->orig_tMargin;
  8605. }
  8606. else if ($this->setAutoTopMargin=='stretch') {
  8607. if ($htmlh['h']) { $h = $htmlh['h']; }
  8608. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8609. else { $h = 0; }
  8610. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $h + $this->autoMarginPadding);
  8611. }
  8612. }
  8613. function _setAutoFooterHeight(&$det, &$htmlf) {
  8614. if ($this->setAutoBottomMargin=='pad') {
  8615. if ($htmlf['h']) { $h = $htmlf['h']; }
  8616. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8617. else { $h = 0; }
  8618. $this->bMargin = $this->margin_footer + $h + $this->orig_bMargin;
  8619. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8620. }
  8621. else if ($this->setAutoBottomMargin=='stretch') {
  8622. if ($htmlf['h']) { $h = $htmlf['h']; }
  8623. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8624. else { $h = 0; }
  8625. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $h + $this->autoMarginPadding);
  8626. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8627. }
  8628. }
  8629. function _getHFHeight(&$det,$end) {
  8630. $h = 0;
  8631. if(count($det)) {
  8632. foreach(array('L','C','R') AS $pos) {
  8633. if (isset($det[$pos]['content']) && $det[$pos]['content']) {
  8634. if (isset($det[$pos]['font-size']) && $det[$pos]['font-size']) { $hfsz = $det[$pos]['font-size']; }
  8635. else { $hfsz = $this->default_font_size; }
  8636. $h = max($h,$hfsz/_MPDFK);
  8637. }
  8638. }
  8639. if ($det['line'] && $end=='H') { $h += $h/_MPDFK*$this->header_line_spacing; }
  8640. else if ($det['line'] && $end=='F') { $h += $h/_MPDFK*$this->footer_line_spacing; }
  8641. }
  8642. return $h;
  8643. }
  8644. function _endpage() {
  8645. /*-- CSS-IMAGE-FLOAT --*/
  8646. $this->printfloatbuffer();
  8647. /*-- END CSS-IMAGE-FLOAT --*/
  8648. if($this->visibility!='visible')
  8649. $this->SetVisibility('visible');
  8650. $this->EndLayer(); // mPDF 5.6.01
  8651. //End of page contents
  8652. $this->state=1;
  8653. }
  8654. function _newobj($obj_id=false,$onlynewobj=false) {
  8655. if (!$obj_id) {
  8656. $obj_id = ++$this->n;
  8657. }
  8658. //Begin a new object
  8659. if (!$onlynewobj) {
  8660. $this->offsets[$obj_id] = strlen($this->buffer);
  8661. $this->_out($obj_id.' 0 obj');
  8662. $this->_current_obj_id = $obj_id; // for later use with encryption
  8663. }
  8664. }
  8665. function _dounderline($x,$y,$txt) {
  8666. // Now print line exactly where $y secifies - called from Text() and Cell() - adjust position there
  8667. // WORD SPACING
  8668. $w =($this->GetStringWidth($txt)*_MPDFK) + ($this->charspacing * mb_strlen( $txt, $this->mb_enc ))
  8669. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ));
  8670. //Draw a line
  8671. return sprintf('%.3F %.3F m %.3F %.3F l S',$x*_MPDFK,($this->h-$y)*_MPDFK,($x*_MPDFK)+$w,($this->h-$y)*_MPDFK);
  8672. }
  8673. function _imageError($file, $firsttime, $msg) {
  8674. // Save re-trying image URL's which have already failed
  8675. $this->failedimages[$file] = true;
  8676. if ($firsttime && ($this->showImageErrors || $this->debug)) {
  8677. $this->Error("IMAGE Error (".$file."): ".$msg);
  8678. }
  8679. return false;
  8680. }
  8681. function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false) {
  8682. // firsttime i.e. whether to add to this->images - use false when calling iteratively
  8683. // Image Data passed directly as var:varname
  8684. if (preg_match('/var:\s*(.*)/',$file, $v)) {
  8685. $data = $this->$v[1];
  8686. $file = md5($data);
  8687. }
  8688. // mPDF 5.5.13
  8689. if (preg_match('/data:image\/(gif|jpeg|png);base64,(.*)/',$file, $v)) {
  8690. $type = $v[1];
  8691. $data = base64_decode($v[2]);
  8692. $file = md5($data);
  8693. }
  8694. // mPDF 5.6.02
  8695. if ($firsttime && $file && substr($file,0,5)!='data:') { $file = urlencode_part($file); }
  8696. if ($firsttime && $orig_srcpath && substr($orig_srcpath,0,5)!='data:') { $orig_srcpath = urlencode_part($orig_srcpath); }
  8697. $ppUx = 0;
  8698. if ($orig_srcpath && isset($this->images[$orig_srcpath])) { $file=$orig_srcpath; return $this->images[$orig_srcpath]; }
  8699. if (isset($this->images[$file])) { return $this->images[$file]; }
  8700. else if ($orig_srcpath && isset($this->formobjects[$orig_srcpath])) { $file=$orig_srcpath; return $this->formobjects[$file]; }
  8701. else if (isset($this->formobjects[$file])) { return $this->formobjects[$file]; }
  8702. // Save re-trying image URL's which have already failed
  8703. else if ($firsttime && isset($this->failedimages[$file])) { return $this->_imageError($file, $firsttime, ''); }
  8704. if (empty($data)) {
  8705. $type = '';
  8706. $data = '';
  8707. if ($orig_srcpath && $this->basepathIsLocal && $check = @fopen($orig_srcpath,"rb")) {
  8708. fclose($check);
  8709. $file=$orig_srcpath;
  8710. $data = file_get_contents($file);
  8711. $type = $this->_imageTypeFromString($data);
  8712. }
  8713. if (!$data && $check = @fopen($file,"rb")) {
  8714. fclose($check);
  8715. $data = file_get_contents($file);
  8716. $type = $this->_imageTypeFromString($data);
  8717. }
  8718. if ((!$data || !$type) && !ini_get('allow_url_fopen') ) { // only worth trying if remote file and !ini_get('allow_url_fopen')
  8719. $this->file_get_contents_by_socket($file, $data); // needs full url?? even on local (never needed for local)
  8720. if ($data) { $type = $this->_imageTypeFromString($data); }
  8721. }
  8722. if ((!$data || !$type) && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  8723. $this->file_get_contents_by_curl($file, $data); // needs full url?? even on local (never needed for local)
  8724. if ($data) { $type = $this->_imageTypeFromString($data); }
  8725. }
  8726. }
  8727. if (!$data) { return $this->_imageError($file, $firsttime, 'Could not find image file'); }
  8728. if (empty($type)) { $type = $this->_imageTypeFromString($data); }
  8729. if (($type == 'wmf' || $type == 'svg') && !$allowvector) { return $this->_imageError($file, $firsttime, 'WMF or SVG image file not supported in this context'); }
  8730. // SVG
  8731. if ($type == 'svg') {
  8732. if (!class_exists('SVG', false)) { include(_MPDF_PATH .'classes/svg.php'); }
  8733. $svg = new SVG($this);
  8734. $family=$this->FontFamily;
  8735. $style=$this->FontStyle;
  8736. $size=$this->FontSizePt;
  8737. $info = $svg->ImageSVG($data);
  8738. //Restore font
  8739. if($family) $this->SetFont($family,$style,$size,false);
  8740. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing SVG file'); }
  8741. $info['type']='svg';
  8742. $info['i']=count($this->formobjects)+1;
  8743. $this->formobjects[$file]=$info;
  8744. return $info;
  8745. }
  8746. // JPEG
  8747. if ($type == 'jpeg' || $type == 'jpg') {
  8748. $hdr = $this->_jpgHeaderFromString($data);
  8749. if (!$hdr) { return $this->_imageError($file, $firsttime, 'Error parsing JPG header'); }
  8750. $a = $this->_jpgDataFromHeader($hdr);
  8751. $j = strpos($data,'JFIF');
  8752. if ($j) {
  8753. //Read resolution
  8754. $unitSp=ord(substr($data,($j+7),1));
  8755. if ($unitSp > 0) {
  8756. $ppUx=$this->_twobytes2int(substr($data,($j+8),2)); // horizontal pixels per meter, usually set to zero
  8757. if ($unitSp == 2) { // = dots per cm (if == 1 set as dpi)
  8758. $ppUx=round($ppUx/10 *25.4);
  8759. }
  8760. }
  8761. }
  8762. if ($a[2] == 'DeviceCMYK' && (($this->PDFA && $this->restrictColorSpace!=3) || $this->restrictColorSpace==2)) {
  8763. // convert to RGB image
  8764. if (!function_exists("gd_info")) { $this->Error("JPG image may not use CMYK color space (".$file.")."); }
  8765. 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.)"; }
  8766. $im = @imagecreatefromstring($data);
  8767. if ($im) {
  8768. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8769. imageinterlace($im, false);
  8770. $check = @imagepng($im, $tempfile);
  8771. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse JPG(CMYK) image'); }
  8772. $info = $this->_getImage($tempfile, false);
  8773. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse JPG(CMYK) image'); }
  8774. imagedestroy($im);
  8775. unlink($tempfile);
  8776. $info['type']='jpg';
  8777. if ($firsttime) {
  8778. $info['i']=count($this->images)+1;
  8779. $this->images[$file]=$info;
  8780. }
  8781. return $info;
  8782. }
  8783. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from JPG(CMYK) image'); }
  8784. }
  8785. else if ($a[2] == 'DeviceRGB' && ($this->PDFX || $this->restrictColorSpace==3)) {
  8786. // Convert to CMYK image stream - nominally returned as type='png'
  8787. $info = $this->_convImage($data, $a[2], 'DeviceCMYK', $a[0], $a[1], $ppUx, false);
  8788. 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.)"; }
  8789. }
  8790. else if (($a[2] == 'DeviceRGB' || $a[2] == 'DeviceCMYK') && $this->restrictColorSpace==1) {
  8791. // Convert to Grayscale image stream - nominally returned as type='png'
  8792. $info = $this->_convImage($data, $a[2], 'DeviceGray', $a[0], $a[1], $ppUx, false);
  8793. }
  8794. else {
  8795. $info = array('w'=>$a[0],'h'=>$a[1],'cs'=>$a[2],'bpc'=>$a[3],'f'=>'DCTDecode','data'=>$data, 'type'=>'jpg');
  8796. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8797. }
  8798. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting JPG image'); }
  8799. if ($firsttime) {
  8800. $info['i']=count($this->images)+1;
  8801. $this->images[$file]=$info;
  8802. }
  8803. return $info;
  8804. }
  8805. // PNG
  8806. else if ($type == 'png') {
  8807. //Check signature
  8808. if(substr($data,0,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  8809. return $this->_imageError($file, $firsttime, 'Error parsing PNG identifier');
  8810. }
  8811. //Read header chunk
  8812. if(substr($data,12,4)!='IHDR') {
  8813. return $this->_imageError($file, $firsttime, 'Incorrect PNG file (no IHDR block found)');
  8814. }
  8815. $w=$this->_fourbytes2int(substr($data,16,4));
  8816. $h=$this->_fourbytes2int(substr($data,20,4));
  8817. $bpc=ord(substr($data,24,1));
  8818. $errpng = false;
  8819. $pngalpha = false;
  8820. if($bpc>8) { $errpng = 'not 8-bit depth'; }
  8821. $ct=ord(substr($data,25,1));
  8822. if($ct==0) { $colspace='DeviceGray'; }
  8823. elseif($ct==2) { $colspace='DeviceRGB'; }
  8824. elseif($ct==3) { $colspace='Indexed'; }
  8825. elseif($ct==4) { $colspace='DeviceGray'; $errpng = 'alpha channel'; $pngalpha = true; }
  8826. else { $colspace='DeviceRGB'; $errpng = 'alpha channel'; $pngalpha = true; }
  8827. if(ord(substr($data,26,1))!=0) { $errpng = 'compression method'; }
  8828. if(ord(substr($data,27,1))!=0) { $errpng = 'filter method'; }
  8829. if(ord(substr($data,28,1))!=0) { $errpng = 'interlaced file'; }
  8830. $j = strpos($data,'pHYs');
  8831. if ($j) {
  8832. //Read resolution
  8833. $unitSp=ord(substr($data,($j+12),1));
  8834. if ($unitSp == 1) {
  8835. $ppUx=$this->_fourbytes2int(substr($data,($j+4),4)); // horizontal pixels per meter, usually set to zero
  8836. $ppUx=round($ppUx/1000 *25.4);
  8837. }
  8838. }
  8839. if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && ($this->PDFX || $this->restrictColorSpace==3)) {
  8840. // Convert to CMYK image stream - nominally returned as type='png'
  8841. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8842. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "PNG image may not use RGB color space - ".$file." - (Image converted to CMYK. NB This will alter the colour profile of the image.)"; }
  8843. }
  8844. else if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && $this->restrictColorSpace==1) {
  8845. // Convert to Grayscale image stream - nominally returned as type='png'
  8846. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8847. }
  8848. else if (($this->PDFA || $this->PDFX) && $pngalpha) {
  8849. // Remove alpha channel
  8850. if ($this->restrictColorSpace==1) { // Grayscale
  8851. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8852. }
  8853. else if ($this->restrictColorSpace==3) { // CMYK
  8854. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8855. }
  8856. else if ($this->PDFA ) { // RGB
  8857. $info = $this->_convImage($data, $colspace, 'DeviceRGB', $w, $h, $ppUx, $pngalpha);
  8858. }
  8859. 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.)"; }
  8860. }
  8861. else if ($errpng || $pngalpha) {
  8862. if (function_exists('gd_info')) { $gd = gd_info(); }
  8863. else {$gd = array(); }
  8864. if (!isset($gd['PNG Support'])) { return $this->_imageError($file, $firsttime, 'GD library required for PNG image ('.$errpng.')'); }
  8865. $im = imagecreatefromstring($data);
  8866. if (!$im) { return $this->_imageError($file, $firsttime, 'Error creating GD image from PNG file ('.$errpng.')'); }
  8867. $w = imagesx($im);
  8868. $h = imagesy($im);
  8869. if ($im) {
  8870. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8871. // Alpha channel set
  8872. if ($pngalpha) {
  8873. if ($this->PDFA) { $this->Error("PDFA1-b does not permit images with alpha channel transparency (".$file.")."); }
  8874. $imgalpha = imagecreate($w, $h);
  8875. // generate gray scale pallete
  8876. for ($c = 0; $c < 256; ++$c) { ImageColorAllocate($imgalpha, $c, $c, $c); }
  8877. // extract alpha channel
  8878. $gammacorr = 2.2; // gamma correction
  8879. for ($xpx = 0; $xpx < $w; ++$xpx) {
  8880. for ($ypx = 0; $ypx < $h; ++$ypx) {
  8881. //$colorindex = imagecolorat($im, $xpx, $ypx);
  8882. //$col = imagecolorsforindex($im, $colorindex);
  8883. //$gamma2 = (pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255);
  8884. $alpha = (imagecolorat($im, $xpx, $ypx) & 0x7F000000) >> 24;
  8885. if ($alpha < 127) {
  8886. if ($alpha==0) { $gamma = 255; }
  8887. else
  8888. $gamma = (pow((((127 - $alpha) * 255 / 127) / 255), $gammacorr) * 255);
  8889. imagesetpixel($imgalpha, $xpx, $ypx, $gamma);
  8890. }
  8891. }
  8892. }
  8893. // create temp alpha file
  8894. $tempfile_alpha = _MPDF_TEMP_PATH.'_tempMskPNG'.RAND(1,10000).'.png';
  8895. if (!is_writable($tempfile_alpha)) {
  8896. ob_start();
  8897. $check = @imagepng($imgalpha);
  8898. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8899. imagedestroy($imgalpha);
  8900. $this->_tempimg = ob_get_contents();
  8901. $this->_tempimglnk = 'var:_tempimg';
  8902. ob_end_clean();
  8903. // extract image without alpha channel
  8904. $imgplain = imagecreatetruecolor($w, $h);
  8905. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8906. // create temp image file
  8907. $minfo = $this->_getImage($this->_tempimglnk, false);
  8908. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8909. ob_start();
  8910. $check = @imagepng($imgplain);
  8911. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8912. $this->_tempimg = ob_get_contents();
  8913. $this->_tempimglnk = 'var:_tempimg';
  8914. ob_end_clean();
  8915. $info = $this->_getImage($this->_tempimglnk, false);
  8916. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8917. imagedestroy($imgplain);
  8918. $imgmask = count($this->images)+1;
  8919. $minfo['cs'] = 'DeviceGray';
  8920. $minfo['i']=$imgmask ;
  8921. $this->images[$tempfile_alpha] = $minfo;
  8922. }
  8923. else {
  8924. $check = @imagepng($imgalpha, $tempfile_alpha);
  8925. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile_alpha.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8926. imagedestroy($imgalpha);
  8927. // extract image without alpha channel
  8928. $imgplain = imagecreatetruecolor($w, $h);
  8929. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8930. // create temp image file
  8931. $check = @imagepng($imgplain, $tempfile);
  8932. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8933. imagedestroy($imgplain);
  8934. // embed mask image
  8935. $minfo = $this->_getImage($tempfile_alpha, false);
  8936. unlink($tempfile_alpha);
  8937. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile_alpha.') created with GD library to parse PNG image'); }
  8938. $imgmask = count($this->images)+1;
  8939. $minfo['cs'] = 'DeviceGray';
  8940. $minfo['i']=$imgmask ;
  8941. $this->images[$tempfile_alpha] = $minfo;
  8942. // embed image, masked with previously embedded mask
  8943. $info = $this->_getImage($tempfile, false);
  8944. unlink($tempfile);
  8945. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8946. }
  8947. $info['masked'] = $imgmask;
  8948. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8949. $info['type']='png';
  8950. if ($firsttime) {
  8951. $info['i']=count($this->images)+1;
  8952. $this->images[$file]=$info;
  8953. }
  8954. return $info;
  8955. }
  8956. else { // No alpha/transparency set
  8957. imagealphablending($im, false);
  8958. imagesavealpha($im, false);
  8959. imageinterlace($im, false);
  8960. if (!is_writable($tempfile)) {
  8961. ob_start();
  8962. $check = @imagepng($im);
  8963. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8964. $this->_tempimg = ob_get_contents();
  8965. $this->_tempimglnk = 'var:_tempimg';
  8966. ob_end_clean();
  8967. $info = $this->_getImage($this->_tempimglnk, false);
  8968. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8969. imagedestroy($im);
  8970. }
  8971. else {
  8972. $check = @imagepng($im, $tempfile );
  8973. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image ('.$errpng.')'); }
  8974. imagedestroy($im);
  8975. $info = $this->_getImage($tempfile, false) ;
  8976. unlink($tempfile );
  8977. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8978. }
  8979. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8980. $info['type']='png';
  8981. if ($firsttime) {
  8982. $info['i']=count($this->images)+1;
  8983. $this->images[$file]=$info;
  8984. }
  8985. return $info;
  8986. }
  8987. }
  8988. }
  8989. else {
  8990. $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  8991. //Scan chunks looking for palette, transparency and image data
  8992. $pal='';
  8993. $trns='';
  8994. $pngdata='';
  8995. $p = 33;
  8996. do {
  8997. $n=$this->_fourbytes2int(substr($data,$p,4)); $p += 4;
  8998. $type=substr($data,$p,4); $p += 4;
  8999. if($type=='PLTE') {
  9000. //Read palette
  9001. $pal=substr($data,$p,$n); $p += $n;
  9002. $p += 4;
  9003. }
  9004. elseif($type=='tRNS') {
  9005. //Read transparency info
  9006. $t=substr($data,$p,$n); $p += $n;
  9007. if($ct==0) $trns=array(ord(substr($t,1,1)));
  9008. elseif($ct==2) $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  9009. else
  9010. {
  9011. $pos=strpos($t,chr(0));
  9012. if(is_int($pos)) $trns=array($pos);
  9013. }
  9014. $p += 4;
  9015. }
  9016. elseif($type=='IDAT') {
  9017. $pngdata.=substr($data,$p,$n); $p += $n;
  9018. $p += 4;
  9019. }
  9020. elseif($type=='IEND') { break; }
  9021. else if (preg_match('/[a-zA-Z]{4}/',$type)) { $p += $n+4; }
  9022. else { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data'); }
  9023. }
  9024. while($n);
  9025. if (!$pngdata) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - no IDAT data found'); }
  9026. if($colspace=='Indexed' and empty($pal)) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - missing colour palette'); }
  9027. $info = array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$pngdata);
  9028. $info['type']='png';
  9029. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  9030. }
  9031. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting PNG image'); }
  9032. if ($firsttime) {
  9033. $info['i']=count($this->images)+1;
  9034. $this->images[$file]=$info;
  9035. }
  9036. return $info;
  9037. }
  9038. // GIF
  9039. else if ($type == 'gif') {
  9040. if (function_exists('gd_info')) { $gd = gd_info(); }
  9041. else {$gd = array(); }
  9042. if (isset($gd['GIF Read Support']) && $gd['GIF Read Support']) {
  9043. $im = @imagecreatefromstring($data);
  9044. if ($im) {
  9045. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  9046. imagealphablending($im, false);
  9047. imagesavealpha($im, false);
  9048. imageinterlace($im, false);
  9049. if (!is_writable($tempfile)) {
  9050. ob_start();
  9051. $check = @imagepng($im);
  9052. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse GIF image'); }
  9053. $this->_tempimg = ob_get_contents();
  9054. $this->_tempimglnk = 'var:_tempimg';
  9055. ob_end_clean();
  9056. $info = $this->_getImage($this->_tempimglnk, false);
  9057. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse GIF image'); }
  9058. imagedestroy($im);
  9059. }
  9060. else {
  9061. $check = @imagepng($im, $tempfile);
  9062. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse GIF image'); }
  9063. $info = $this->_getImage($tempfile, false);
  9064. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse GIF image'); }
  9065. imagedestroy($im);
  9066. unlink($tempfile);
  9067. }
  9068. $info['type']='gif';
  9069. if ($firsttime) {
  9070. $info['i']=count($this->images)+1;
  9071. $this->images[$file]=$info;
  9072. }
  9073. return $info;
  9074. }
  9075. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from GIF image'); }
  9076. }
  9077. if (!class_exists('gif', false)) {
  9078. include_once(_MPDF_PATH.'classes/gif.php');
  9079. }
  9080. $gif=new CGIF();
  9081. $h=0;
  9082. $w=0;
  9083. $gif->loadFile($data, 0);
  9084. if(isset($gif->m_img->m_gih->m_bLocalClr) && $gif->m_img->m_gih->m_bLocalClr) {
  9085. $nColors = $gif->m_img->m_gih->m_nTableSize;
  9086. $pal = $gif->m_img->m_gih->m_colorTable->toString();
  9087. if($bgColor != -1) {
  9088. $bgColor = $gif->m_img->m_gih->m_colorTable->colorIndex($bgColor);
  9089. }
  9090. $colspace='Indexed';
  9091. } elseif(isset($gif->m_gfh->m_bGlobalClr) && $gif->m_gfh->m_bGlobalClr) {
  9092. $nColors = $gif->m_gfh->m_nTableSize;
  9093. $pal = $gif->m_gfh->m_colorTable->toString();
  9094. if((isset($bgColor)) and $bgColor != -1) {
  9095. $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor);
  9096. }
  9097. $colspace='Indexed';
  9098. } else {
  9099. $nColors = 0;
  9100. $bgColor = -1;
  9101. $colspace='DeviceGray';
  9102. $pal='';
  9103. }
  9104. $trns='';
  9105. if(isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans && ($nColors > 0)) {
  9106. $trns=array($gif->m_img->m_nTrans);
  9107. }
  9108. $gifdata=$gif->m_img->m_data;
  9109. $w=$gif->m_gfh->m_nWidth;
  9110. $h=$gif->m_gfh->m_nHeight;
  9111. $gif->ClearData();
  9112. if($colspace=='Indexed' and empty($pal)) {
  9113. return $this->_imageError($file, $firsttime, 'Error parsing GIF image - missing colour palette');
  9114. }
  9115. if ($this->compress) {
  9116. $gifdata=gzcompress($gifdata);
  9117. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  9118. }
  9119. else {
  9120. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  9121. }
  9122. $info['type']='gif';
  9123. if ($firsttime) {
  9124. $info['i']=count($this->images)+1;
  9125. $this->images[$file]=$info;
  9126. }
  9127. return $info;
  9128. }
  9129. /*-- IMAGES-BMP --*/
  9130. // BMP (Windows Bitmap)
  9131. else if ($type == 'bmp') {
  9132. if (!class_exists('bmp', false)) { include(_MPDF_PATH.'classes/bmp.php'); }
  9133. if (empty($this->bmp)) { $this->bmp = new bmp($this); }
  9134. $info = $this->bmp->_getBMPimage($data, $file);
  9135. if (isset($info['error'])) {
  9136. return $this->_imageError($file, $firsttime, $info['error']);
  9137. }
  9138. if ($firsttime) {
  9139. $info['i']=count($this->images)+1;
  9140. $this->images[$file]=$info;
  9141. }
  9142. return $info;
  9143. }
  9144. /*-- END IMAGES-BMP --*/
  9145. /*-- IMAGES-WMF --*/
  9146. // WMF
  9147. else if ($type == 'wmf') {
  9148. if (!class_exists('wmf', false)) { include(_MPDF_PATH.'classes/wmf.php'); }
  9149. if (empty($this->wmf)) { $this->wmf = new wmf($this); }
  9150. $wmfres = $this->wmf->_getWMFimage($data);
  9151. if ($wmfres[0]==0) {
  9152. if ($wmfres[1]) { return $this->_imageError($file, $firsttime, $wmfres[1]); }
  9153. return $this->_imageError($file, $firsttime, 'Error parsing WMF image');
  9154. }
  9155. $info = array('x'=>$wmfres[2][0],'y'=>$wmfres[2][1],'w'=>$wmfres[3][0],'h'=>$wmfres[3][1],'data'=>$wmfres[1]);
  9156. $info['i']=count($this->formobjects)+1;
  9157. $info['type']='wmf';
  9158. $this->formobjects[$file]=$info;
  9159. return $info;
  9160. }
  9161. /*-- END IMAGES-WMF --*/
  9162. // UNKNOWN TYPE - try GD imagecreatefromstring
  9163. else {
  9164. if (function_exists('gd_info')) { $gd = gd_info(); }
  9165. else {$gd = array(); }
  9166. if (isset($gd['PNG Support']) && $gd['PNG Support']) {
  9167. $im = @imagecreatefromstring($data);
  9168. if (!$im) { return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised, and not supported by GD imagecreate'); }
  9169. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  9170. imagealphablending($im, false);
  9171. imagesavealpha($im, false);
  9172. imageinterlace($im, false);
  9173. $check = @imagepng($im, $tempfile);
  9174. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse unknown image type'); }
  9175. $info = $this->_getImage($tempfile, false);
  9176. imagedestroy($im);
  9177. unlink($tempfile);
  9178. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse unknown image type'); }
  9179. $info['type']='png';
  9180. if ($firsttime) {
  9181. $info['i']=count($this->images)+1;
  9182. $this->images[$file]=$info;
  9183. }
  9184. return $info;
  9185. }
  9186. }
  9187. return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised');
  9188. }
  9189. //==============================================================
  9190. function _convImage(&$data, $colspace, $targetcs, $w, $h, $dpi, $mask) {
  9191. if ($this->PDFA || $this->PDFX) { $mask=false; }
  9192. $im = @imagecreatefromstring($data);
  9193. $info = array();
  9194. if ($im) {
  9195. $imgdata = '';
  9196. $mimgdata = '';
  9197. $minfo = array();
  9198. //Read transparency info
  9199. $trns=array();
  9200. $trnsrgb = false;
  9201. if (!$this->PDFA && !$this->PDFX) {
  9202. $p = strpos($data,'tRNS');
  9203. if ($p) {
  9204. $n=$this->_fourbytes2int(substr($data,($p-4),4));
  9205. $t = substr($data,($p+4),$n);
  9206. if ($colspace=='DeviceGray') {
  9207. $trns=array(ord(substr($t,1,1)));
  9208. $trnsrgb = array($trns[0],$trns[0],$trns[0]);
  9209. }
  9210. else if ($colspace=='DeviceRGB') {
  9211. $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  9212. $trnsrgb = $trns;
  9213. if ($targetcs=='DeviceCMYK') {
  9214. $col = $this->rgb2cmyk(array(3,$trns[0],$trns[1],$trns[2]));
  9215. $c1 = intval($col[1]*2.55);
  9216. $c2 = intval($col[2]*2.55);
  9217. $c3 = intval($col[3]*2.55);
  9218. $c4 = intval($col[4]*2.55);
  9219. $trns = array($c1,$c2,$c3,$c4);
  9220. }
  9221. else if ($targetcs=='DeviceGray') {
  9222. $c = intval(($trns[0] * .21) + ($trns[1] * .71) + ($trns[2] * .07));
  9223. $trns = array($c);
  9224. }
  9225. }
  9226. else { // Indexed
  9227. $pos = strpos($t,chr(0));
  9228. if (is_int($pos)) {
  9229. $pal = imagecolorsforindex($im, $pos);
  9230. $r = $pal['red'];
  9231. $g = $pal['green'];
  9232. $b = $pal['blue'];
  9233. $trns=array($r,$g,$b); // ****
  9234. $trnsrgb = $trns;
  9235. if ($targetcs=='DeviceCMYK') {
  9236. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  9237. $c1 = intval($col[1]*2.55);
  9238. $c2 = intval($col[2]*2.55);
  9239. $c3 = intval($col[3]*2.55);
  9240. $c4 = intval($col[4]*2.55);
  9241. $trns = array($c1,$c2,$c3,$c4);
  9242. }
  9243. else if ($targetcs=='DeviceGray') {
  9244. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  9245. $trns = array($c);
  9246. }
  9247. }
  9248. }
  9249. }
  9250. }
  9251. for ($i = 0; $i < $h; $i++) {
  9252. for ($j = 0; $j < $w; $j++) {
  9253. $rgb = imagecolorat($im, $j, $i);
  9254. $r = ($rgb >> 16) & 0xFF;
  9255. $g = ($rgb >> 8) & 0xFF;
  9256. $b = $rgb & 0xFF;
  9257. if ($colspace=='Indexed') {
  9258. $pal = imagecolorsforindex($im, $rgb);
  9259. $r = $pal['red'];
  9260. $g = $pal['green'];
  9261. $b = $pal['blue'];
  9262. }
  9263. if ($targetcs=='DeviceCMYK') {
  9264. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  9265. $c1 = intval($col[1]*2.55);
  9266. $c2 = intval($col[2]*2.55);
  9267. $c3 = intval($col[3]*2.55);
  9268. $c4 = intval($col[4]*2.55);
  9269. if ($trnsrgb) {
  9270. // original pixel was not set as transparent but processed color does match
  9271. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c1,$c2,$c3,$c4)) {
  9272. if ($c4==0) { $c4=1; } else { $c4--; }
  9273. }
  9274. }
  9275. $imgdata .= chr($c1).chr($c2).chr($c3).chr($c4);
  9276. }
  9277. else if ($targetcs=='DeviceGray') {
  9278. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  9279. if ($trnsrgb) {
  9280. // original pixel was not set as transparent but processed color does match
  9281. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c)) {
  9282. if ($c==0) { $c=1; } else { $c--; }
  9283. }
  9284. }
  9285. $imgdata .= chr($c);
  9286. }
  9287. else if ($targetcs=='DeviceRGB') {
  9288. $imgdata .= chr($r).chr($g).chr($b);
  9289. }
  9290. if ($mask) {
  9291. $col = imagecolorsforindex($im, $rgb);
  9292. $gammacorr = 2.2; // gamma correction
  9293. $gamma = intval((pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255));
  9294. $mimgdata .= chr($gamma);
  9295. }
  9296. }
  9297. }
  9298. if ($targetcs=='DeviceGray') { $ncols = 1; }
  9299. else if ($targetcs=='DeviceRGB') { $ncols = 3; }
  9300. else if ($targetcs=='DeviceCMYK') { $ncols = 4; }
  9301. $imgdata = gzcompress($imgdata);
  9302. $info = array('w'=>$w,'h'=>$h,'cs'=>$targetcs,'bpc'=>8,'f'=>'FlateDecode','data'=>$imgdata, 'type'=>'png',
  9303. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  9304. if ($dpi) { $info['set-dpi'] = $dpi; }
  9305. if ($mask) {
  9306. $mimgdata = gzcompress($mimgdata);
  9307. $minfo = array('w'=>$w,'h'=>$h,'cs'=>'DeviceGray','bpc'=>8,'f'=>'FlateDecode','data'=>$mimgdata, 'type'=>'png',
  9308. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  9309. if ($dpi) { $minfo['set-dpi'] = $dpi; }
  9310. $tempfile = '_tempImgPNG'.RAND(1,10000).'.png';
  9311. $imgmask = count($this->images)+1;
  9312. $minfo['i']=$imgmask ;
  9313. $this->images[$tempfile] = $minfo;
  9314. $info['masked'] = $imgmask;
  9315. }
  9316. else if ($trns) { $info['trns'] = $trns; }
  9317. imagedestroy($im);
  9318. }
  9319. return $info;
  9320. }
  9321. function _fourbytes2int($s) {
  9322. //Read a 4-byte integer from string
  9323. return (ord($s[0])<<24) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]);
  9324. }
  9325. function _twobytes2int($s) {
  9326. //Read a 2-byte integer from string
  9327. return (ord(substr($s, 0, 1))<<8) + ord(substr($s, 1, 1));
  9328. }
  9329. function _jpgHeaderFromString(&$data) {
  9330. $p = 4;
  9331. $p += $this->_twobytes2int(substr($data, $p, 2)); // Length of initial marker block
  9332. $marker = substr($data, $p, 2);
  9333. while($marker != chr(255).chr(192) && $marker != chr(255).chr(194) && $p<strlen($data)) {
  9334. // Start of frame marker (FFC0) or (FFC2) mPDF 4.4.004
  9335. $p += ($this->_twobytes2int(substr($data, $p+2, 2))) + 2; // Length of marker block
  9336. $marker = substr($data, $p, 2);
  9337. }
  9338. if ($marker != chr(255).chr(192) && $marker != chr(255).chr(194)) { return false; }
  9339. return substr($data, $p+2, 10);
  9340. }
  9341. function _jpgDataFromHeader($hdr) {
  9342. $bpc = ord(substr($hdr, 2, 1));
  9343. if (!$bpc) { $bpc = 8; }
  9344. $h = $this->_twobytes2int(substr($hdr, 3, 2));
  9345. $w = $this->_twobytes2int(substr($hdr, 5, 2));
  9346. $channels = ord(substr($hdr, 7, 1));
  9347. if ($channels==3) { $colspace='DeviceRGB'; }
  9348. elseif($channels==4) { $colspace='DeviceCMYK'; }
  9349. else { $colspace='DeviceGray'; }
  9350. return array($w, $h, $colspace, $bpc);
  9351. }
  9352. function file_get_contents_by_curl($url, &$data) {
  9353. $timeout = 5;
  9354. $ch = curl_init($url);
  9355. curl_setopt($ch, CURLOPT_HEADER, 0);
  9356. curl_setopt($ch, CURLOPT_NOBODY, 0);
  9357. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  9358. curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , $timeout );
  9359. $data = curl_exec($ch);
  9360. curl_close($ch);
  9361. }
  9362. function file_get_contents_by_socket($url, &$data) {
  9363. $timeout = 1;
  9364. $p = parse_url($url);
  9365. $file = $p['path'];
  9366. if ($p['query']) { $file .= '?'.$p['query']; }
  9367. if(!($fh = @fsockopen($p['host'], 80, $errno, $errstr, $timeout))) { return false; }
  9368. $getstring =
  9369. "GET ".$file." HTTP/1.0 \r\n" .
  9370. "Host: ".$p['host']." \r\n" .
  9371. "Connection: close\r\n\r\n";
  9372. fwrite($fh, $getstring);
  9373. // Get rid of HTTP header
  9374. $s = fgets($fh, 1024);
  9375. if (!$s) { return false; }
  9376. $httpheader .= $s;
  9377. while (!feof($fh)) {
  9378. $s = fgets($fh, 1024);
  9379. if ( $s == "\r\n" ) { break; }
  9380. }
  9381. $data = '';
  9382. while (!feof($fh)) {
  9383. $data .= fgets($fh, 1024);
  9384. }
  9385. fclose($fh);
  9386. }
  9387. //==============================================================
  9388. function _imageTypeFromString(&$data) {
  9389. $type = '';
  9390. if (substr($data, 6, 4)== 'JFIF' || substr($data, 6, 4)== 'Exif') {
  9391. $type = 'jpeg';
  9392. }
  9393. else if (substr($data, 0, 6)== "GIF87a" || substr($data, 0, 6)== "GIF89a") {
  9394. $type = 'gif';
  9395. }
  9396. else if (substr($data, 0, 8)== chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  9397. $type = 'png';
  9398. }
  9399. /*-- IMAGES-WMF --*/
  9400. else if (substr($data, 0, 4)== chr(215).chr(205).chr(198).chr(154)) {
  9401. $type = 'wmf';
  9402. }
  9403. /*-- END IMAGES-WMF --*/
  9404. else if (preg_match('/<svg.*<\/svg>/is',$data)) {
  9405. $type = 'svg';
  9406. }
  9407. // BMP images
  9408. else if (substr($data, 0, 2)== "BM") {
  9409. $type = 'bmp';
  9410. }
  9411. return $type;
  9412. }
  9413. //==============================================================
  9414. // Moved outside WMF as also needed for SVG
  9415. function _putformobjects() {
  9416. reset($this->formobjects);
  9417. while(list($file,$info)=each($this->formobjects)) {
  9418. $this->_newobj();
  9419. $this->formobjects[$file]['n']=$this->n;
  9420. $this->_out('<</Type /XObject');
  9421. $this->_out('/Subtype /Form');
  9422. $this->_out('/Group '.($this->n+1).' 0 R');
  9423. $this->_out('/BBox ['.$info['x'].' '.$info['y'].' '.($info['w']+$info['x']).' '.($info['h']+$info['y']).']');
  9424. if ($this->compress)
  9425. $this->_out('/Filter /FlateDecode');
  9426. $data=($this->compress) ? gzcompress($info['data']) : $info['data'];
  9427. $this->_out('/Length '.strlen($data).'>>');
  9428. $this->_putstream($data);
  9429. unset($this->formobjects[$file]['data']);
  9430. $this->_out('endobj');
  9431. // Required for SVG transparency (opacity) to work
  9432. $this->_newobj();
  9433. $this->_out('<</Type /Group');
  9434. $this->_out('/S /Transparency');
  9435. $this->_out('>>');
  9436. $this->_out('endobj');
  9437. }
  9438. }
  9439. function _freadint($f)
  9440. {
  9441. //Read a 4-byte integer from file
  9442. $i=ord(fread($f,1))<<24;
  9443. $i+=ord(fread($f,1))<<16;
  9444. $i+=ord(fread($f,1))<<8;
  9445. $i+=ord(fread($f,1));
  9446. return $i;
  9447. }
  9448. function _UTF16BEtextstring($s) {
  9449. $s = $this->UTF8ToUTF16BE($s, true);
  9450. /*-- ENCRYPTION --*/
  9451. if ($this->encrypted) {
  9452. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9453. }
  9454. /*-- END ENCRYPTION --*/
  9455. return '('. $this->_escape($s).')';
  9456. }
  9457. function _textstring($s) {
  9458. /*-- ENCRYPTION --*/
  9459. if ($this->encrypted) {
  9460. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9461. }
  9462. /*-- END ENCRYPTION --*/
  9463. return '('. $this->_escape($s).')';
  9464. }
  9465. function _escape($s)
  9466. {
  9467. // the chr(13) substitution fixes the Bugs item #1421290.
  9468. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  9469. }
  9470. function _putstream($s) {
  9471. /*-- ENCRYPTION --*/
  9472. if ($this->encrypted) {
  9473. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9474. }
  9475. /*-- END ENCRYPTION --*/
  9476. $this->_out('stream');
  9477. $this->_out($s);
  9478. $this->_out('endstream');
  9479. }
  9480. function _out($s,$ln=true) {
  9481. if($this->state==2) {
  9482. if ($this->bufferoutput) {
  9483. $this->headerbuffer.= $s."\n";
  9484. }
  9485. /*-- COLUMNS --*/
  9486. else if (($this->ColActive) && !$this->processingHeader && !$this->processingFooter) {
  9487. // Captures everything in buffer for columns; Almost everything is sent from fn. Cell() except:
  9488. // Images sent from Image() or
  9489. // later sent as _out($textto) in printbuffer
  9490. // Line()
  9491. 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
  9492. $h = ($m[1]/_MPDFK);
  9493. // Update/overwrite the lowest bottom of printing y value for a column
  9494. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h;
  9495. }
  9496. /*-- TABLES --*/
  9497. 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
  9498. $h = ($m[1]/_MPDFK);
  9499. // Update/overwrite the lowest bottom of printing y value for a column
  9500. $this->ColDetails[$this->CurrCol]['bottom_margin'] = max($this->ColDetails[$this->CurrCol]['bottom_margin'],($this->y+$h));
  9501. }
  9502. /*-- END TABLES --*/
  9503. else { // Td Text Set in Cell()
  9504. if (isset($this->ColDetails[$this->CurrCol]['bottom_margin'])) { $h = $this->ColDetails[$this->CurrCol]['bottom_margin'] - $this->y; }
  9505. else { $h = 0; }
  9506. }
  9507. if ($h < 0) { $h = -$h; }
  9508. $this->columnbuffer[] = array(
  9509. 's' => $s, // Text string to output
  9510. 'col' => $this->CurrCol, // Column when printed
  9511. 'x' => $this->x, // x when printed
  9512. 'y' => $this->y, // this->y when printed (after column break)
  9513. 'h' => $h // actual y at bottom when printed = y+h
  9514. );
  9515. }
  9516. /*-- END COLUMNS --*/
  9517. /*-- TABLES --*/
  9518. else if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  9519. // Captures eveything in buffer for rotated tables;
  9520. $this->tablebuffer .= $s . "\n";
  9521. }
  9522. /*-- END TABLES --*/
  9523. else if ($this->kwt && !$this->processingHeader && !$this->processingFooter) {
  9524. // Captures eveything in buffer for keep-with-table (h1-6);
  9525. $this->kwt_buffer[] = array(
  9526. 's' => $s, // Text string to output
  9527. 'x' => $this->x, // x when printed
  9528. 'y' => $this->y, // y when printed
  9529. );
  9530. }
  9531. else if (($this->keep_block_together) && !$this->processingHeader && !$this->processingFooter) {
  9532. if (!isset($this->ktBlock[$this->page]['bottom_margin'])) {
  9533. $this->ktBlock[$this->page]['bottom_margin'] = $this->y;
  9534. }
  9535. // Captures eveything in buffer;
  9536. 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
  9537. $h = ($m[1]/_MPDFK);
  9538. // Update/overwrite the lowest bottom of printing y value for Keep together block
  9539. $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h;
  9540. }
  9541. else { // Td Text Set in Cell()
  9542. if (isset($this->ktBlock[$this->page]['bottom_margin'])) { $h = $this->ktBlock[$this->page]['bottom_margin'] - $this->y; }
  9543. else { $h = 0; }
  9544. }
  9545. if ($h < 0) { $h = -$h; }
  9546. $this->divbuffer[] = array(
  9547. 'page' => $this->page,
  9548. 's' => $s, // Text string to output
  9549. 'x' => $this->x, // x when printed
  9550. 'y' => $this->y, // y when printed (after column break)
  9551. 'h' => $h // actual y at bottom when printed = y+h
  9552. );
  9553. }
  9554. else {
  9555. $this->pages[$this->page] .= $s.($ln == true ? "\n" : '');
  9556. }
  9557. }
  9558. else {
  9559. $this->buffer .= $s.($ln == true ? "\n" : '');
  9560. }
  9561. }
  9562. /*-- WATERMARK --*/
  9563. // add a watermark
  9564. function watermark( $texte, $angle=45, $fontsize=96, $alpha=0.2 ) {
  9565. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9566. if (!$this->watermark_font) { $this->watermark_font = $this->default_font; }
  9567. $this->SetFont( $this->watermark_font, "B", $fontsize, false ); // Don't output
  9568. $texte= $this->purify_utf8_text($texte);
  9569. if ($this->text_input_as_HTML) {
  9570. $texte= $this->all_entities_to_utf8($texte);
  9571. }
  9572. if ($this->usingCoreFont) { $texte = mb_convert_encoding($texte,$this->mb_enc,'UTF-8'); }
  9573. // DIRECTIONALITY
  9574. $this->magic_reverse_dir($texte, true, $this->directionality); // *RTL*
  9575. // Font-specific ligature substitution for Indic fonts
  9576. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($texte); // *INDIC*
  9577. $this->SetAlpha($alpha);
  9578. $this->SetTColor($this->ConvertColor(0));
  9579. $szfont = $fontsize;
  9580. $loop = 0;
  9581. $maxlen = (min($this->w,$this->h) ); // sets max length of text as 7/8 width/height of page
  9582. while ( $loop == 0 )
  9583. {
  9584. $this->SetFont( $this->watermark_font, "B", $szfont, false ); // Don't output
  9585. $offset = ((sin(deg2rad($angle))) * ($szfont/_MPDFK));
  9586. $strlen = $this->GetStringWidth($texte);
  9587. if ( $strlen > $maxlen - $offset )
  9588. $szfont --;
  9589. else
  9590. $loop ++;
  9591. }
  9592. $this->SetFont( $this->watermark_font, "B", $szfont-0.1, true, true); // Output The -0.1 is because SetFont above is not written to PDF
  9593. // Repeating it will not output anything as mPDF thinks it is set
  9594. $adj = ((cos(deg2rad($angle))) * ($strlen/2));
  9595. $opp = ((sin(deg2rad($angle))) * ($strlen/2));
  9596. $wx = ($this->w/2) - $adj + $offset/3;
  9597. $wy = ($this->h/2) + $opp;
  9598. $this->Rotate($angle,$wx,$wy);
  9599. $this->Text($wx,$wy,$texte);
  9600. $this->Rotate(0);
  9601. $this->SetTColor($this->ConvertColor(0));
  9602. $this->SetAlpha(1);
  9603. }
  9604. function watermarkImg( $src, $alpha=0.2 ) {
  9605. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9606. if ($this->watermarkImgBehind) { $this->watermarkImgAlpha = $this->SetAlpha($alpha, 'Normal', true); }
  9607. else { $this->SetAlpha($alpha, $this->watermarkImgAlphaBlend); }
  9608. $this->Image($src,0,0,0,0,'','', true, true, true);
  9609. if (!$this->watermarkImgBehind) { $this->SetAlpha(1); }
  9610. }
  9611. /*-- END WATERMARK --*/
  9612. function Rotate($angle,$x=-1,$y=-1)
  9613. {
  9614. if($x==-1)
  9615. $x=$this->x;
  9616. if($y==-1)
  9617. $y=$this->y;
  9618. if($this->angle!=0)
  9619. $this->_out('Q');
  9620. $this->angle=$angle;
  9621. if($angle!=0)
  9622. {
  9623. $angle*=M_PI/180;
  9624. $c=cos($angle);
  9625. $s=sin($angle);
  9626. $cx=$x*_MPDFK;
  9627. $cy=($this->h-$y)*_MPDFK;
  9628. $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));
  9629. }
  9630. }
  9631. function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsize=0, $fontstyle='', $kerning=120, $fontwidth=100, $divider) { // mPDF 5.5.23
  9632. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  9633. if (empty($this->directw)) { $this->directw = new directw($this); }
  9634. $this->directw->CircularText($x, $y, $r, $text, $align, $fontfamily, $fontsize, $fontstyle, $kerning, $fontwidth, $divider); // mPDF 5.5.23
  9635. }
  9636. // From Invoice
  9637. function RoundedRect($x, $y, $w, $h, $r, $style = '')
  9638. {
  9639. $hp = $this->h;
  9640. if($style=='F')
  9641. $op='f';
  9642. elseif($style=='FD' or $style=='DF')
  9643. $op='B';
  9644. else
  9645. $op='S';
  9646. $MyArc = 4/3 * (sqrt(2) - 1);
  9647. $this->_out(sprintf('%.3F %.3F m',($x+$r)*_MPDFK,($hp-$y)*_MPDFK ));
  9648. $xc = $x+$w-$r ;
  9649. $yc = $y+$r;
  9650. $this->_out(sprintf('%.3F %.3F l', $xc*_MPDFK,($hp-$y)*_MPDFK ));
  9651. $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
  9652. $xc = $x+$w-$r ;
  9653. $yc = $y+$h-$r;
  9654. $this->_out(sprintf('%.3F %.3F l',($x+$w)*_MPDFK,($hp-$yc)*_MPDFK));
  9655. $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
  9656. $xc = $x+$r ;
  9657. $yc = $y+$h-$r;
  9658. $this->_out(sprintf('%.3F %.3F l',$xc*_MPDFK,($hp-($y+$h))*_MPDFK));
  9659. $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
  9660. $xc = $x+$r ;
  9661. $yc = $y+$r;
  9662. $this->_out(sprintf('%.3F %.3F l',($x)*_MPDFK,($hp-$yc)*_MPDFK ));
  9663. $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
  9664. $this->_out($op);
  9665. }
  9666. function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
  9667. {
  9668. $h = $this->h;
  9669. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', $x1*_MPDFK, ($h-$y1)*_MPDFK,
  9670. $x2*_MPDFK, ($h-$y2)*_MPDFK, $x3*_MPDFK, ($h-$y3)*_MPDFK));
  9671. }
  9672. //====================================================
  9673. /*-- DIRECTW --*/
  9674. function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 ) {
  9675. // F (shading - no line),S (line, no shading),DF (both)
  9676. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  9677. if (empty($this->directw)) { $this->directw = new directw($this); }
  9678. $this->directw->Shaded_box( $text,$font,$fontstyle,$szfont,$width,$style,$radius,$fill,$color,$pad);
  9679. }
  9680. /*-- END DIRECTW --*/
  9681. function UTF8StringToArray($str, $addSubset=true) {
  9682. $out = array();
  9683. $len = strlen($str);
  9684. for ($i = 0; $i < $len; $i++) {
  9685. $uni = -1;
  9686. $h = ord($str[$i]);
  9687. if ( $h <= 0x7F )
  9688. $uni = $h;
  9689. elseif ( $h >= 0xC2 ) {
  9690. if ( ($h <= 0xDF) && ($i < $len -1) )
  9691. $uni = ($h & 0x1F) << 6 | (ord($str[++$i]) & 0x3F);
  9692. elseif ( ($h <= 0xEF) && ($i < $len -2) )
  9693. $uni = ($h & 0x0F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  9694. elseif ( ($h <= 0xF4) && ($i < $len -3) )
  9695. $uni = ($h & 0x0F) << 18 | (ord($str[++$i]) & 0x3F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  9696. }
  9697. if ($uni >= 0) {
  9698. $out[] = $uni;
  9699. if ($addSubset && isset($this->CurrentFont['subset'])) {
  9700. $this->CurrentFont['subset'][$uni] = $uni;
  9701. }
  9702. }
  9703. }
  9704. return $out;
  9705. }
  9706. //Convert utf-8 string to <HHHHHH> for Font Subsets
  9707. function UTF8toSubset($str) {
  9708. $ret = '<';
  9709. $str = preg_replace('/'.preg_quote($this->aliasNbPg,'/').'/', chr(7), $str );
  9710. $str = preg_replace('/'.preg_quote($this->aliasNbPgGp,'/').'/', chr(8), $str );
  9711. $unicode = $this->UTF8StringToArray($str);
  9712. $orig_fid = $this->CurrentFont['subsetfontids'][0];
  9713. $last_fid = $this->CurrentFont['subsetfontids'][0];
  9714. foreach($unicode as $c) {
  9715. if ($c == 7 || $c == 8) {
  9716. if ($orig_fid != $last_fid) {
  9717. $ret .= '> Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <';
  9718. $last_fid = $orig_fid;
  9719. }
  9720. if ($c == 7) { $ret .= $this->aliasNbPgHex; }
  9721. else { $ret .= $this->aliasNbPgGpHex; }
  9722. continue;
  9723. }
  9724. for ($i=0; $i<99; $i++) {
  9725. // return c as decimal char
  9726. $init = array_search($c, $this->CurrentFont['subsets'][$i]);
  9727. if ($init!==false) {
  9728. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9729. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9730. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9731. }
  9732. $ret .= sprintf("%02s", strtoupper(dechex($init)));
  9733. break;
  9734. }
  9735. // TrueType embedded SUBSETS
  9736. else if (count($this->CurrentFont['subsets'][$i]) < 255) {
  9737. $n = count($this->CurrentFont['subsets'][$i]);
  9738. $this->CurrentFont['subsets'][$i][$n] = $c;
  9739. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9740. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9741. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9742. }
  9743. $ret .= sprintf("%02s", strtoupper(dechex($n)));
  9744. break;
  9745. }
  9746. else if (!isset($this->CurrentFont['subsets'][($i+1)])) {
  9747. // TrueType embedded SUBSETS
  9748. $this->CurrentFont['subsets'][($i+1)] = array(0=>0);
  9749. $new_fid = count($this->fonts)+$this->extraFontSubsets+1;
  9750. $this->CurrentFont['subsetfontids'][($i+1)] = $new_fid;
  9751. $this->extraFontSubsets++;
  9752. }
  9753. }
  9754. }
  9755. $ret .= '>';
  9756. if ($last_fid != $orig_fid) {
  9757. $ret .= ' Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <> ';
  9758. }
  9759. return $ret;
  9760. }
  9761. // Converts UTF-8 strings to UTF16-BE.
  9762. function UTF8ToUTF16BE($str, $setbom=true) {
  9763. if ($this->checkSIP && preg_match("/([\x{20000}-\x{2FFFF}])/u", $str)) {
  9764. if (!in_array($this->currentfontfamily, array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  9765. 'gbBI','big5BI','sjisBI','uhcBI'))) {
  9766. $str = preg_replace("/[\x{20000}-\x{2FFFF}]/u", chr(0), $str);
  9767. }
  9768. }
  9769. if ($this->checkSMP && preg_match("/([\x{10000}-\x{1FFFF}])/u", $str )) {
  9770. $str = preg_replace("/[\x{10000}-\x{1FFFF}]/u", chr(0), $str );
  9771. }
  9772. $outstr = ""; // string to be returned
  9773. if ($setbom) {
  9774. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  9775. }
  9776. $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8');
  9777. return $outstr;
  9778. }
  9779. // ====================================================
  9780. // ====================================================
  9781. /*-- CJK-FONTS --*/
  9782. // from class PDF_Chinese CJK EXTENSIONS
  9783. function AddCIDFont($family,$style,$name,&$cw,$CMap,$registry,$desc)
  9784. {
  9785. $fontkey=strtolower($family).strtoupper($style);
  9786. if(isset($this->fonts[$fontkey]))
  9787. $this->Error("Font already added: $family $style");
  9788. $i=count($this->fonts)+$this->extraFontSubsets+1;
  9789. $name=str_replace(' ','',$name);
  9790. if ($family == 'sjis') { $up = -120; } else { $up = -130; }
  9791. // ? 'up' and 'ut' do not seem to be referenced anywhere
  9792. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>$up,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry,'MissingWidth'=>1000,'desc'=>$desc);
  9793. }
  9794. function AddCJKFont($family) {
  9795. if ($this->PDFA || $this->PDFX) {
  9796. $this->Error("Adobe CJK fonts cannot be embedded in mPDF (required for PDFA1-b and PDFX/1-a).");
  9797. }
  9798. if ($family == 'big5') { $this->AddBig5Font(); }
  9799. else if ($family == 'gb') { $this->AddGBFont(); }
  9800. else if ($family == 'sjis') { $this->AddSJISFont(); }
  9801. else if ($family == 'uhc') { $this->AddUHCFont(); }
  9802. }
  9803. function AddBig5Font()
  9804. {
  9805. //Add Big5 font with proportional Latin
  9806. $family='big5';
  9807. $name='MSungStd-Light-Acro';
  9808. $cw=$this->Big5_widths;
  9809. $CMap='UniCNS-UTF16-H';
  9810. $registry=array('ordering'=>'CNS1','supplement'=>4);
  9811. $desc = array(
  9812. 'Ascent' => 880,
  9813. 'Descent' => -120,
  9814. 'CapHeight' => 880,
  9815. 'Flags' => 6,
  9816. 'FontBBox' => '[-160 -249 1015 1071]',
  9817. 'ItalicAngle' => 0,
  9818. 'StemV' => 93,
  9819. );
  9820. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9821. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9822. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9823. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9824. }
  9825. function AddGBFont()
  9826. {
  9827. //Add GB font with proportional Latin
  9828. $family='gb';
  9829. $name='STSongStd-Light-Acro';
  9830. $cw=$this->GB_widths;
  9831. $CMap='UniGB-UTF16-H';
  9832. $registry=array('ordering'=>'GB1','supplement'=>4);
  9833. $desc = array(
  9834. 'Ascent' => 752,
  9835. 'Descent' => -271,
  9836. 'CapHeight' => 737,
  9837. 'Flags' => 6,
  9838. 'FontBBox' => '[-25 -254 1000 880]',
  9839. 'ItalicAngle' => 0,
  9840. 'StemV' => 58,
  9841. 'Style' => '<< /Panose <000000000400000000000000> >>',
  9842. );
  9843. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9844. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9845. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9846. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9847. }
  9848. function AddSJISFont()
  9849. {
  9850. //Add SJIS font with proportional Latin
  9851. $family='sjis';
  9852. $name='KozMinPro-Regular-Acro';
  9853. $cw=$this->SJIS_widths;
  9854. $CMap='UniJIS-UTF16-H';
  9855. $registry=array('ordering'=>'Japan1','supplement'=>5);
  9856. $desc = array(
  9857. 'Ascent' => 880,
  9858. 'Descent' => -120,
  9859. 'CapHeight' => 740,
  9860. 'Flags' => 6,
  9861. 'FontBBox' => '[-195 -272 1110 1075]',
  9862. 'ItalicAngle' => 0,
  9863. 'StemV' => 86,
  9864. 'XHeight' => 502,
  9865. );
  9866. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9867. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9868. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9869. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9870. }
  9871. function AddUHCFont()
  9872. {
  9873. //Add UHC font with proportional Latin
  9874. $family='uhc';
  9875. $name='HYSMyeongJoStd-Medium-Acro';
  9876. $cw=$this->UHC_widths;
  9877. $CMap='UniKS-UTF16-H';
  9878. $registry=array('ordering'=>'Korea1','supplement'=>2);
  9879. $desc = array(
  9880. 'Ascent' => 880,
  9881. 'Descent' => -120,
  9882. 'CapHeight' => 720,
  9883. 'Flags' => 6,
  9884. 'FontBBox' => '[-28 -148 1001 880]',
  9885. 'ItalicAngle' => 0,
  9886. 'StemV' => 60,
  9887. 'Style' => '<< /Panose <000000000600000000000000> >>',
  9888. );
  9889. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9890. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9891. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9892. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9893. }
  9894. /*-- END CJK-FONTS --*/
  9895. //////////////////////////////////////////////////////////////////////////////
  9896. //////////////////////////////////////////////////////////////////////////////
  9897. //////////////////////////////////////////////////////////////////////////////
  9898. //////////////////////////////////////////////////////////////////////////////
  9899. //////////////////////////////////////////////////////////////////////////////
  9900. //////////////////////////////////////////////////////////////////////////////
  9901. //////////////////////////////////////////////////////////////////////////////
  9902. function SetAutoFont($af = AUTOFONT_ALL) {
  9903. if ($this->onlyCoreFonts) { return false; }
  9904. if (!$af && $af !== 0) { $af = AUTOFONT_ALL; }
  9905. $this->autoFontGroups = $af;
  9906. if ($this->autoFontGroups ) {
  9907. $this->useLang = true;
  9908. }
  9909. }
  9910. function SetDefaultFont($font) {
  9911. // Disallow embedded fonts to be used as defaults in PDFA
  9912. if ($this->PDFA || $this->PDFX) {
  9913. if (strtolower($font) == 'ctimes') { $font = 'serif'; }
  9914. if (strtolower($font) == 'ccourier') { $font = 'monospace'; }
  9915. if (strtolower($font) == 'chelvetica') { $font = 'sans-serif'; }
  9916. }
  9917. $font = $this->SetFont($font); // returns substituted font if necessary
  9918. $this->default_font = $font;
  9919. $this->original_default_font = $font;
  9920. if (!$this->watermark_font ) { $this->watermark_font = $font; } // *WATERMARK*
  9921. $this->defaultCSS['BODY']['FONT-FAMILY'] = $font;
  9922. $this->cssmgr->CSS['BODY']['FONT-FAMILY'] = $font;
  9923. }
  9924. function SetDefaultFontSize($fontsize) {
  9925. $this->default_font_size = $fontsize;
  9926. $this->original_default_font_size = $fontsize;
  9927. $this->SetFontSize($fontsize);
  9928. $this->defaultCSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  9929. $this->cssmgr->CSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  9930. }
  9931. function SetDefaultBodyCSS($prop, $val) {
  9932. if ($prop) {
  9933. $this->defaultCSS['BODY'][strtoupper($prop)] = $val;
  9934. $this->cssmgr->CSS['BODY'][strtoupper($prop)] = $val;
  9935. }
  9936. }
  9937. function SetDirectionality($dir='ltr') {
  9938. /*-- RTL --*/
  9939. if (strtolower($dir) == 'rtl') {
  9940. if ($this->directionality != 'rtl') {
  9941. // Swop L/R Margins so page 1 RTL is an 'even' page
  9942. $tmp = $this->DeflMargin;
  9943. $this->DeflMargin = $this->DefrMargin;
  9944. $this->DefrMargin = $tmp;
  9945. $this->orig_lMargin = $this->DeflMargin;
  9946. $this->orig_rMargin = $this->DefrMargin;
  9947. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$this->tMargin);
  9948. }
  9949. $this->directionality = 'rtl';
  9950. $this->defaultAlign = 'R';
  9951. $this->defaultTableAlign = 'R';
  9952. }
  9953. else {
  9954. /*-- END RTL --*/
  9955. $this->directionality = 'ltr';
  9956. $this->defaultAlign = 'L';
  9957. $this->defaultTableAlign = 'L';
  9958. } // *RTL*
  9959. $this->cssmgr->CSS['BODY']['DIRECTION'] = $this->directionality;
  9960. }
  9961. // Added to set line-height-correction
  9962. function SetLineHeightCorrection($val) {
  9963. if ($val > 0) { $this->default_lineheight_correction = $val; }
  9964. else { $this->default_lineheight_correction = 1.2; }
  9965. }
  9966. // Set a (fixed) lineheight to an actual value - either to named fontsize(pts) or default
  9967. function SetLineHeight($FontPt='',$spacing = '') {
  9968. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9969. else { $k = 1; }
  9970. if ($spacing > 0) {
  9971. if (preg_match('/mm/',$spacing)) {
  9972. $this->lineheight = ($spacing + 0.0) / $k; // convert to number
  9973. }
  9974. else {
  9975. if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$spacing); }
  9976. else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$spacing); }
  9977. }
  9978. }
  9979. else {
  9980. if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$this->normalLineheight); }
  9981. else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$this->normalLineheight); }
  9982. }
  9983. }
  9984. function _computeLineheight($lh, $fs='') {
  9985. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9986. else { $k = 1; }
  9987. if (!$fs) { $fs = $this->FontSize; }
  9988. if (preg_match('/mm/',$lh)) {
  9989. return (($lh + 0.0) / $k); // convert to number
  9990. }
  9991. else if ($lh > 0) {
  9992. return ($fs * $lh);
  9993. }
  9994. else if (isset($this->normalLineheight)) { return ($fs * $this->normalLineheight); }
  9995. else return ($fs * $this->default_lineheight_correction);
  9996. }
  9997. function SetBasePath($str='') {
  9998. if ( isset($_SERVER['HTTP_HOST']) ) { $host = $_SERVER['HTTP_HOST']; }
  9999. else if ( isset($_SERVER['SERVER_NAME']) ) { $host = $_SERVER['SERVER_NAME']; }
  10000. else { $host = ''; }
  10001. if (!$str) {
  10002. if ($_SERVER['SCRIPT_NAME']) { $currentPath = dirname($_SERVER['SCRIPT_NAME']); }
  10003. else { $currentPath = dirname($_SERVER['PHP_SELF']); }
  10004. $currentPath = str_replace("\\","/",$currentPath);
  10005. if ($currentPath == '/') { $currentPath = ''; }
  10006. if ($host) { $currpath = 'http://' . $host . $currentPath .'/'; }
  10007. else { $currpath = ''; }
  10008. $this->basepath = $currpath;
  10009. $this->basepathIsLocal = true;
  10010. return;
  10011. }
  10012. $str = preg_replace('/\?.*/','',$str);
  10013. if (!preg_match('/(http|https|ftp):\/\/.*\//i',$str)) { $str .= '/'; }
  10014. $str .= 'xxx'; // in case $str ends in / e.g. http://www.bbc.co.uk/
  10015. $this->basepath = dirname($str) . "/"; // returns e.g. e.g. http://www.google.com/dir1/dir2/dir3/
  10016. $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
  10017. $tr = parse_url($this->basepath);
  10018. if (isset($tr['host']) && ($tr['host'] == $host)) { $this->basepathIsLocal = true; }
  10019. else { $this->basepathIsLocal = false; }
  10020. }
  10021. function GetFullPath(&$path,$basepath='') {
  10022. // When parsing CSS need to pass temporary basepath - so links are relative to current stylesheet
  10023. if (!$basepath) { $basepath = $this->basepath; }
  10024. //Fix path value
  10025. $path = str_replace("\\","/",$path); //If on Windows
  10026. $path = preg_replace('/^\/\//','http://',$path); // mPDF 5.6.27
  10027. $regexp = '|^./|'; // Inadvertently corrects "./path/etc" and "//www.domain.com/etc"
  10028. $path = preg_replace($regexp,'',$path);
  10029. if(substr($path,0,1) == '#') { return; }
  10030. if (stristr($path,"mailto:") !== false) { return; }
  10031. if (strpos($path,"../") !== false ) { //It is a Relative Link
  10032. $backtrackamount = substr_count($path,"../");
  10033. $maxbacktrack = substr_count($basepath,"/") - 3; // mPDF 5.6.18
  10034. $filepath = str_replace("../",'',$path);
  10035. $path = $basepath;
  10036. //If it is an invalid relative link, then make it go to directory root
  10037. if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
  10038. //Backtrack some directories
  10039. for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
  10040. $path = $path . "/" . $filepath; //Make it an absolute path
  10041. }
  10042. else if( strpos($path,":/") === false || strpos($path,":/") > 10) { //It is a Local Link
  10043. if (substr($path,0,1) == "/") {
  10044. $tr = parse_url($basepath);
  10045. $root = $tr['scheme'].'://'.$tr['host'];
  10046. $path = $root . $path;
  10047. }
  10048. else { $path = $basepath . $path; }
  10049. }
  10050. //Do nothing if it is an Absolute Link
  10051. }
  10052. // Used for external CSS files
  10053. function _get_file($path) {
  10054. // If local file try using local path (? quicker, but also allowed even if allow_url_fopen false)
  10055. $contents = '';
  10056. $contents = @file_get_contents($path);
  10057. if ($contents) { return $contents; }
  10058. if ($this->basepathIsLocal) {
  10059. $tr = parse_url($path);
  10060. $lp=getenv("SCRIPT_NAME");
  10061. $ap=realpath($lp);
  10062. $ap=str_replace("\\","/",$ap);
  10063. $docroot=substr($ap,0,strpos($ap,$lp));
  10064. // WriteHTML parses all paths to full URLs; may be local file name
  10065. if ($tr['scheme'] && $tr['host'] && $_SERVER["DOCUMENT_ROOT"] ) {
  10066. $localpath = $_SERVER["DOCUMENT_ROOT"] . $tr['path'];
  10067. }
  10068. // DOCUMENT_ROOT is not returned on IIS
  10069. else if ($docroot) {
  10070. $localpath = $docroot . $tr['path'];
  10071. }
  10072. else { $localpath = $path; }
  10073. $contents = @file_get_contents($localpath);
  10074. }
  10075. // if not use full URL
  10076. else if (!$contents && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  10077. $ch = curl_init($path);
  10078. curl_setopt($ch, CURLOPT_HEADER, 0);
  10079. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  10080. $contents = curl_exec($ch);
  10081. curl_close($ch);
  10082. }
  10083. return $contents;
  10084. }
  10085. function docPageNum($num = 0, $extras = false) {
  10086. if ($num < 1) { $num = $this->page; }
  10087. $type = '1'; // set default decimal
  10088. $ppgno = $num;
  10089. $suppress = 0;
  10090. $offset = 0;
  10091. $lastreset = 0;
  10092. foreach($this->PageNumSubstitutions AS $psarr) {
  10093. if ($num >= $psarr['from']) {
  10094. if ($psarr['reset']) {
  10095. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  10096. $ppgno = $num - $psarr['from'] + 1 + $offset;
  10097. $lastreset = $psarr['from'];
  10098. }
  10099. if ($psarr['type']) { $type = $psarr['type']; }
  10100. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  10101. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  10102. }
  10103. }
  10104. if ($suppress) { return ''; }
  10105. foreach($this->pgsIns AS $k=>$v) {
  10106. if ($k>$lastreset && $k<$num) {
  10107. $ppgno -= $v;
  10108. }
  10109. }
  10110. if ($type=='A') { $ppgno = $this->dec2alpha($ppgno,true); }
  10111. else if ($type=='a') { $ppgno = $this->dec2alpha($ppgno,false);}
  10112. else if ($type=='I') { $ppgno = $this->dec2roman($ppgno,true); }
  10113. else if ($type=='i') { $ppgno = $this->dec2roman($ppgno,false); }
  10114. if ($extras) { $ppgno = $this->pagenumPrefix . $ppgno . $this->pagenumSuffix; }
  10115. return $ppgno;
  10116. }
  10117. function docPageSettings($num = 0) {
  10118. // Returns current type (numberstyle), suppression state for this page number;
  10119. // reset is only returned if set for this page number
  10120. if ($num < 1) { $num = $this->page; }
  10121. $type = '1'; // set default decimal
  10122. $ppgno = $num;
  10123. $suppress = 0;
  10124. $offset = 0;
  10125. $reset = '';
  10126. foreach($this->PageNumSubstitutions AS $psarr) {
  10127. if ($num >= $psarr['from']) {
  10128. if ($psarr['reset']) {
  10129. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  10130. $ppgno = $num - $psarr['from'] + 1 + $offset;
  10131. }
  10132. if ($psarr['type']) { $type = $psarr['type']; }
  10133. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  10134. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  10135. }
  10136. if ($num == $psarr['from']) { $reset = $psarr['reset']; }
  10137. }
  10138. if ($suppress) { $suppress = 'on'; }
  10139. else { $suppress = 'off'; }
  10140. return array($type, $suppress, $reset);
  10141. }
  10142. function docPageNumTotal($num = 0, $extras = false) {
  10143. if ($num < 1) { $num = $this->page; }
  10144. $type = '1'; // set default decimal
  10145. $ppgstart = 1;
  10146. $ppgend = count($this->pages)+1;
  10147. $suppress = 0;
  10148. $offset = 0;
  10149. foreach($this->PageNumSubstitutions AS $psarr) {
  10150. if ($num >= $psarr['from']) {
  10151. if ($psarr['reset']) {
  10152. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  10153. $ppgstart = $psarr['from'] + $offset;
  10154. $ppgend = count($this->pages)+1 + $offset;
  10155. }
  10156. if ($psarr['type']) { $type = $psarr['type']; }
  10157. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  10158. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  10159. }
  10160. if ($num < $psarr['from']) {
  10161. if ($psarr['reset']) {
  10162. $ppgend = $psarr['from'] + $offset;
  10163. break;
  10164. }
  10165. }
  10166. }
  10167. if ($suppress) { return ''; }
  10168. $ppgno = $ppgend-$ppgstart+$offset;
  10169. // mPDF 5.6.47
  10170. foreach($this->pgsIns AS $k => $v) {
  10171. if ($k>$ppgstart && $k<$ppgend) {
  10172. $ppgno -= $v;
  10173. }
  10174. }
  10175. if ($extras) { $ppgno = $this->nbpgPrefix . $ppgno . $this->nbpgSuffix; }
  10176. return $ppgno;
  10177. }
  10178. function RestartDocTemplate() {
  10179. $this->docTemplateStart = $this->page;
  10180. }
  10181. //Page header
  10182. function Header($content='') {
  10183. $this->cMarginL = 0;
  10184. $this->cMarginR = 0;
  10185. /*-- HTMLHEADERS-FOOTERS --*/
  10186. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLHeaderE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLHeader) || (!$this->mirrorMargins && $this->HTMLHeader)) {
  10187. $this->writeHTMLHeaders();
  10188. return;
  10189. }
  10190. /*-- END HTMLHEADERS-FOOTERS --*/
  10191. $this->processingHeader=true;
  10192. $h = $this->headerDetails;
  10193. if(count($h)) {
  10194. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10195. $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK)));
  10196. $yadj = $this->w - $this->h;
  10197. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  10198. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10199. $headerlmargin = $this->orig_rMargin;
  10200. }
  10201. else {
  10202. $headerlmargin = $this->orig_lMargin;
  10203. }
  10204. }
  10205. else {
  10206. $yadj = 0;
  10207. $headerpgwidth = $this->pgwidth;
  10208. $headerlmargin = $this->lMargin;
  10209. }
  10210. $this->y = $this->margin_header - $yadj ;
  10211. $this->SetTColor($this->ConvertColor(0));
  10212. $this->SUP = false;
  10213. $this->SUB = false;
  10214. $this->bullet = false;
  10215. // only show pagenumber if numbering on
  10216. $pgno = $this->docPageNum($this->page, true);
  10217. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10218. $side = 'even';
  10219. }
  10220. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  10221. $side = 'odd';
  10222. }
  10223. $maxfontheight = 0;
  10224. foreach(array('L','C','R') AS $pos) {
  10225. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10226. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10227. else { $hfsz = $this->default_font_size; }
  10228. $maxfontheight = max($maxfontheight,$hfsz);
  10229. }
  10230. }
  10231. // LEFT-CENTER-RIGHT
  10232. foreach(array('L','C','R') AS $pos) {
  10233. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10234. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  10235. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  10236. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  10237. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  10238. else { $hff = $this->original_default_font; }
  10239. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10240. else { $hfsz = $this->original_default_font_size; } // pts
  10241. $maxfontheight = max($maxfontheight,$hfsz);
  10242. $hfst = '';
  10243. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) {
  10244. $hfst = $h[$side][$pos]['font-style'];
  10245. }
  10246. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  10247. $hfcol = $h[$side][$pos]['color'];
  10248. $cor = $this->ConvertColor($hfcol);
  10249. if ($cor) { $this->SetTColor($cor); }
  10250. }
  10251. else { $hfcol = ''; }
  10252. $this->SetFont($hff,$hfst,$hfsz,true,true);
  10253. $this->x = $headerlmargin ;
  10254. $this->y = $this->margin_header - $yadj ;
  10255. $hd = $this->purify_utf8_text($hd);
  10256. if ($this->text_input_as_HTML) {
  10257. $hd = $this->all_entities_to_utf8($hd);
  10258. }
  10259. // CONVERT CODEPAGE
  10260. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  10261. // DIRECTIONALITY RTL
  10262. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  10263. // Font-specific ligature substitution for Indic fonts
  10264. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  10265. $align = $pos;
  10266. /*-- RTL --*/
  10267. if ($this->directionality == 'rtl') {
  10268. if ($pos == 'L') { $align = 'R'; }
  10269. else if ($pos == 'R') { $align = 'L'; }
  10270. }
  10271. /*-- END RTL --*/
  10272. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  10273. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  10274. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  10275. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  10276. $this->_out('Q');
  10277. }
  10278. else {
  10279. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  10280. }
  10281. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); }
  10282. }
  10283. }
  10284. //Return Font to normal
  10285. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  10286. // LINE
  10287. if (isset($h[$side]['line']) && $h[$side]['line']) {
  10288. $this->SetLineWidth(0.1);
  10289. $this->SetDColor($this->ConvertColor(0));
  10290. $this->Line($headerlmargin , $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/_MPDFK) - $yadj , $headerlmargin + $headerpgwidth, $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/_MPDFK) - $yadj );
  10291. }
  10292. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10293. $this->_out('Q');
  10294. }
  10295. }
  10296. $this->SetY($this->tMargin);
  10297. if ($this->ColActive) { $this->pgwidth = $this->ColWidth; } // *COLUMNS*
  10298. $this->processingHeader=false;
  10299. }
  10300. /*-- TABLES --*/
  10301. function TableHeaderFooter($content='',$tablestartpage='',$tablestartcolumn ='',$horf = 'H',$level, $firstSpread=true, $finalSpread=true) {
  10302. if(($horf=='H' || $horf=='F') && !empty($content) && !empty($content[0])) { // mPDF 5.6.61
  10303. $table = &$this->table[1][1];
  10304. // Advance down page by half width of top border
  10305. if ($horf=='H') { // Only if header
  10306. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  10307. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  10308. if ($adv) {
  10309. if ($this->table_rotate) {
  10310. $this->y += ($adv);
  10311. }
  10312. else {
  10313. $this->DivLn($adv,$this->blklvl,true);
  10314. }
  10315. }
  10316. }
  10317. if ($horf=='F') { // Table Footer
  10318. $firstrow = count($table['cells']) - $table['footernrows'];
  10319. $lastrow = count($table['cells']) - 1;
  10320. }
  10321. else { // Table Header
  10322. $firstrow = 0;
  10323. $lastrow = $table['headernrows'] - 1;
  10324. }
  10325. $topy = $content[$firstrow][0]['y']-$this->y;
  10326. for ($i=$firstrow ; $i<=$lastrow; $i++) {
  10327. $y = $this->y;
  10328. /*-- COLUMNS --*/
  10329. // If outside columns, this is done in PaintDivBB
  10330. if ($this->ColActive) {
  10331. //OUTER FILL BGCOLOR of DIVS
  10332. if ($this->blklvl > 0) {
  10333. $firstblockfill = $this->GetFirstBlockFill();
  10334. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  10335. $divh = $content[$i][0]['h'];
  10336. $bak_x = $this->x;
  10337. $this->DivLn($divh,-3,false);
  10338. // Reset current block fill
  10339. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  10340. $this->SetFColor($bcor);
  10341. $this->x = $bak_x;
  10342. }
  10343. }
  10344. }
  10345. /*-- END COLUMNS --*/
  10346. $colctr = 0;
  10347. foreach($content[$i] as $tablehf) {
  10348. $colctr++;
  10349. $y = $tablehf['y'] - $topy;
  10350. $this->y = $y;
  10351. //Set some cell values
  10352. $x = $tablehf['x'];
  10353. if (($this->mirrorMargins) && ($tablestartpage == 'ODD') && (($this->page)%2==0)) { // EVEN
  10354. $x = $x +$this->MarginCorrection;
  10355. }
  10356. else if (($this->mirrorMargins) && ($tablestartpage == 'EVEN') && (($this->page)%2==1)) { // ODD
  10357. $x = $x +$this->MarginCorrection;
  10358. }
  10359. /*-- COLUMNS --*/
  10360. // Added to correct for Columns
  10361. if ($this->ColActive) {
  10362. if ($this->directionality == 'rtl') { // *RTL*
  10363. $x -= ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  10364. } // *RTL*
  10365. else { // *RTL*
  10366. $x += ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap);
  10367. } // *RTL*
  10368. }
  10369. /*-- END COLUMNS --*/
  10370. if ($colctr==1) { $x0 = $x; }
  10371. // mPDF ITERATION
  10372. if ($this->iterationCounter) {
  10373. foreach($tablehf['textbuffer'] AS $k=>$t) {
  10374. if (!is_array($t[0]) && preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t[0], $m)) { // mPDF 5.5.06
  10375. $vname = '__'.$m[1].'_';
  10376. if (!isset($this->$vname)) { $this->$vname = 1; }
  10377. else { $this->$vname++; }
  10378. $tablehf['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $tablehf['textbuffer'][$k][0]);
  10379. }
  10380. }
  10381. }
  10382. $w = $tablehf['w'];
  10383. $h = $tablehf['h'];
  10384. $va = $tablehf['va'];
  10385. $R = $tablehf['R'];
  10386. $mih = $tablehf['mih'];
  10387. $border = $tablehf['border'];
  10388. $border_details = $tablehf['border_details'];
  10389. $padding = $tablehf['padding'];
  10390. $this->tabletheadjustfinished = true;
  10391. $textbuffer = $tablehf['textbuffer'];
  10392. $align = $tablehf['a'];
  10393. //Align
  10394. $this->divalign=$align;
  10395. $this->x = $x;
  10396. if ($this->ColActive) {
  10397. if ($table['borders_separate']) {
  10398. $tablefill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  10399. if ($tablefill) {
  10400. $color = $this->ConvertColor($tablefill);
  10401. if ($color) {
  10402. $xadj = ($table['border_spacing_H']/2);
  10403. $yadj = ($table['border_spacing_V']/2);
  10404. $wadj = $table['border_spacing_H'];
  10405. $hadj = $table['border_spacing_V'];
  10406. if ($i == $firstrow && $horf=='H') { // Top
  10407. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  10408. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  10409. }
  10410. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom
  10411. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  10412. }
  10413. if ($colctr == 1) { // Left
  10414. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  10415. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  10416. }
  10417. if ($colctr == count($content[$i]) ) { // Right
  10418. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  10419. }
  10420. $this->SetFColor($color);
  10421. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  10422. }
  10423. }
  10424. }
  10425. }
  10426. if ($table['empty_cells']!='hide' || !empty($textbuffer) || !$table['borders_separate']) { $paintcell = true; }
  10427. else { $paintcell = false; }
  10428. //Vertical align
  10429. if ($R && INTVAL($R) > 0 && isset($va) && $va!='B') { $va='B';}
  10430. if (!isset($va) || empty($va) || $va=='M') $this->y += ($h-$mih)/2;
  10431. elseif (isset($va) && $va=='B') $this->y += $h-$mih;
  10432. //TABLE ROW OR CELL FILL BGCOLOR
  10433. $fill = 0;
  10434. if (isset($tablehf['bgcolor']) && $tablehf['bgcolor'] && $tablehf['bgcolor']!='transparent') {
  10435. $fill = $tablehf['bgcolor'];
  10436. $leveladj = 6;
  10437. }
  10438. else if (isset($content[$i][0]['trbgcolor']) && $content[$i][0]['trbgcolor'] && $content[$i][0]['trbgcolor']!='transparent') { // Row color
  10439. $fill = $content[$i][0]['trbgcolor'];
  10440. $leveladj = 3;
  10441. }
  10442. if ($fill && $paintcell) {
  10443. $color = $this->ConvertColor($fill);
  10444. if ($color) {
  10445. if ($table['borders_separate']) {
  10446. if ($this->ColActive) {
  10447. $this->SetFColor($color);
  10448. $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');
  10449. }
  10450. else {
  10451. $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);
  10452. }
  10453. }
  10454. else {
  10455. if ($this->ColActive) {
  10456. $this->SetFColor($color);
  10457. $this->Rect($x, $y, $w, $h, 'F');
  10458. }
  10459. else {
  10460. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  10461. }
  10462. }
  10463. }
  10464. }
  10465. /*-- BACKGROUNDS --*/
  10466. if (isset($tablehf['gradient']) && $tablehf['gradient'] && $paintcell){
  10467. $g = $this->grad->parseBackgroundGradient($tablehf['gradient']);
  10468. if ($g) {
  10469. if ($table['borders_separate']) {
  10470. $px = $x+ ($table['border_spacing_H']/2);
  10471. $py = $y+ ($table['border_spacing_V']/2);
  10472. $pw = $w- $table['border_spacing_H'];
  10473. $ph = $h- $table['border_spacing_V'];
  10474. }
  10475. else {
  10476. $px = $x;
  10477. $py = $y;
  10478. $pw = $w;
  10479. $ph = $h;
  10480. }
  10481. if ($this->ColActive) {
  10482. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10483. }
  10484. else {
  10485. $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'=>'');
  10486. }
  10487. }
  10488. }
  10489. if (isset($tablehf['background-image']) && $paintcell){
  10490. if ($tablehf['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $tablehf['background-image']['gradient'] )) {
  10491. $g = $this->grad->parseMozGradient( $tablehf['background-image']['gradient'] );
  10492. if ($g) {
  10493. if ($table['borders_separate']) {
  10494. $px = $x+ ($table['border_spacing_H']/2);
  10495. $py = $y+ ($table['border_spacing_V']/2);
  10496. $pw = $w- $table['border_spacing_H'];
  10497. $ph = $h- $table['border_spacing_V'];
  10498. }
  10499. else {
  10500. $px = $x;
  10501. $py = $y;
  10502. $pw = $w;
  10503. $ph = $h;
  10504. }
  10505. if ($this->ColActive) {
  10506. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10507. }
  10508. else {
  10509. $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'=>'');
  10510. }
  10511. }
  10512. }
  10513. else if ($tablehf['background-image']['image_id']) { // Background pattern
  10514. $n = count($this->patterns)+1;
  10515. if ($table['borders_separate']) {
  10516. $px = $x+ ($table['border_spacing_H']/2);
  10517. $py = $y+ ($table['border_spacing_V']/2);
  10518. $pw = $w- $table['border_spacing_H'];
  10519. $ph = $h- $table['border_spacing_V'];
  10520. }
  10521. else {
  10522. $px = $x;
  10523. $py = $y;
  10524. $pw = $w;
  10525. $ph = $h;
  10526. }
  10527. if ($this->ColActive) {
  10528. 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']);
  10529. $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, 'itype'=>$tablehf['background-image']['itype']);
  10530. if ($tablehf['background-image']['opacity']>0 && $tablehf['background-image']['opacity']<1) { $opac = $this->SetAlpha($tablehf['background-image']['opacity'],'Normal',true); }
  10531. else { $opac = ''; }
  10532. $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $px*_MPDFK, ($this->h-$py)*_MPDFK, $pw*_MPDFK, -$ph*_MPDFK));
  10533. }
  10534. else {
  10535. $this->tableBackgrounds[$level*9+8][] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'image_id'=>$tablehf['background-image']['image_id'], 'orig_w'=>$tablehf['background-image']['orig_w'], 'orig_h'=>$tablehf['background-image']['orig_h'], 'x_pos'=>$tablehf['background-image']['x_pos'], 'y_pos'=>$tablehf['background-image']['y_pos'], 'x_repeat'=>$tablehf['background-image']['x_repeat'], 'y_repeat'=>$tablehf['background-image']['y_repeat'], 'clippath'=>'', 'resize'=>$tablehf['background-image']['resize'], 'opacity'=>$tablehf['background-image']['opacity'], 'itype'=>$tablehf['background-image']['itype']);
  10536. }
  10537. }
  10538. }
  10539. /*-- END BACKGROUNDS --*/
  10540. //Cell Border
  10541. if ($table['borders_separate'] && $paintcell && $border) {
  10542. $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']);
  10543. }
  10544. else if ($paintcell && $border) {
  10545. $this->_tableRect($x, $y, $w, $h, $border, $border_details, true, $table['borders_separate']); // true causes buffer
  10546. }
  10547. //Print cell content
  10548. //$this->divheight = $this->table_lineheight*$this->lineheight;
  10549. if (!empty($textbuffer)) {
  10550. if ($horf=='F' && preg_match('/{colsum([0-9]*)[_]*}/', $textbuffer[0][0], $m)) {
  10551. $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$colctr-1]);
  10552. $textbuffer[0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$textbuffer[0][0]);
  10553. }
  10554. if ($R) {
  10555. $cellPtSize = $textbuffer[0][11] / $this->shrin_k;
  10556. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  10557. $cellFontHeight = ($cellPtSize/_MPDFK);
  10558. $opx = $this->x;
  10559. $opy = $this->y;
  10560. $angle = INTVAL($R);
  10561. // Only allow 45 - 90 degrees (when bottom-aligned) or -90
  10562. if ($angle > 90) { $angle = 90; }
  10563. else if ($angle > 0 && (isset($va) && $va!='B')) { $angle = 90; }
  10564. else if ($angle > 0 && $angle <45) { $angle = 45; }
  10565. else if ($angle < 0) { $angle = -90; }
  10566. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  10567. if (isset($align) && $align =='R') {
  10568. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($padding['R'] + $border_details['R']['w']);
  10569. }
  10570. else if (!isset($align ) || $align =='C') {
  10571. $this->x += ($w/2) + ($offset);
  10572. }
  10573. else {
  10574. $this->x += ($offset) + ($cellFontHeight/3)+($padding['L'] + $border_details['L']['w']);
  10575. }
  10576. $str = '';
  10577. foreach($tablehf['textbuffer'] AS $t) { $str .= $t[0].' '; }
  10578. $str = trim($str);
  10579. if (!isset($va) || $va=='M') {
  10580. $this->y -= ($h-$mih)/2; //Undo what was added earlier VERTICAL ALIGN
  10581. 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'])); }
  10582. else if ($angle < 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']); }
  10583. }
  10584. else if (isset($va) && $va=='B') {
  10585. $this->y -= $h-$mih; //Undo what was added earlier VERTICAL ALIGN
  10586. if ($angle > 0) { $this->y += $h-($border_details['B']['w']+$padding['B']); }
  10587. else if ($angle < 0) { $this->y += $h-$mih+($padding['T'] + $border_details['T']['w']); }
  10588. }
  10589. else if (isset($va) && $va=='T') {
  10590. if ($angle > 0) { $this->y += $mih-($border_details['B']['w']+$padding['B']); }
  10591. else if ($angle < 0) { $this->y += ($padding['T'] + $border_details['T']['w']); }
  10592. }
  10593. $this->Rotate($angle,$this->x,$this->y);
  10594. $s_fs = $this->FontSizePt;
  10595. $s_f = $this->FontFamily;
  10596. $s_st = $this->FontStyle;
  10597. if (!empty($textbuffer[0][3])) { //Font Color
  10598. $cor = $textbuffer[0][3];
  10599. $this->SetTColor($cor);
  10600. }
  10601. $s_str = $this->strike;
  10602. $this->strike = $textbuffer[0][8]; //Strikethrough
  10603. $this->SetFont($textbuffer[0][4],$textbuffer[0][2],$cellPtSize,true,true);
  10604. $this->Text($this->x,$this->y,$str);
  10605. $this->Rotate(0);
  10606. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  10607. $this->SetTColor(0);
  10608. $this->strike = $s_str;
  10609. $this->x = $opx;
  10610. $this->y = $opy;
  10611. }
  10612. else {
  10613. if ($table['borders_separate']) { // NB twice border width
  10614. $xadj = $border_details['L']['w'] + $padding['L'] +($table['border_spacing_H']/2);
  10615. $wadj = $border_details['L']['w'] + $border_details['R']['w'] + $padding['L'] +$padding['R'] + $table['border_spacing_H'];
  10616. $yadj = $border_details['T']['w'] + $padding['T'] + ($table['border_spacing_H']/2);
  10617. }
  10618. else {
  10619. $xadj = $border_details['L']['w']/2 + $padding['L'];
  10620. $wadj = ($border_details['L']['w'] + $border_details['R']['w'])/2 + $padding['L'] + $padding['R'];
  10621. $yadj = $border_details['T']['w']/2 + $padding['T'];
  10622. }
  10623. $this->divwidth=$w-($wadj);
  10624. $this->x += $xadj;
  10625. $this->y += $yadj;
  10626. $this->printbuffer($textbuffer,'',true);
  10627. }
  10628. }
  10629. $textbuffer = array();
  10630. /*-- BACKGROUNDS --*/
  10631. if (!$this->ColActive) {
  10632. if (isset($content[$i][0]['trgradients']) && ($colctr==1 || $table['borders_separate'])) {
  10633. $g = $this->grad->parseBackgroundGradient($content[$i][0]['trgradients']);
  10634. if ($g) {
  10635. $gx = $x0;
  10636. $gy = $y;
  10637. $gh = $h;
  10638. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10639. if ($table['borders_separate']) {
  10640. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10641. $s = '';
  10642. $clx = $x+ ($table['border_spacing_H']/2);
  10643. $cly = $y+ ($table['border_spacing_V']/2);
  10644. $clw = $w- $table['border_spacing_H'];
  10645. $clh = $h- $table['border_spacing_V'];
  10646. // Set clipping path
  10647. $s = ' q 0 w '; // Line width=0
  10648. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10649. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10650. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10651. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10652. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10653. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10654. $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);
  10655. }
  10656. else {
  10657. $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'=>'');
  10658. }
  10659. }
  10660. }
  10661. if (isset($content[$i][0]['trbackground-images']) && ($colctr==1 || $table['borders_separate'])) {
  10662. if ($content[$i][0]['trbackground-images']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $content[$i][0]['trbackground-images']['gradient'] )) {
  10663. $g = $this->grad->parseMozGradient( $content[$i][0]['trbackground-images']['gradient'] );
  10664. if ($g) {
  10665. $gx = $x0;
  10666. $gy = $y;
  10667. $gh = $h;
  10668. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10669. if ($table['borders_separate']) {
  10670. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10671. $s = '';
  10672. $clx = $x+ ($table['border_spacing_H']/2);
  10673. $cly = $y+ ($table['border_spacing_V']/2);
  10674. $clw = $w- $table['border_spacing_H'];
  10675. $clh = $h- $table['border_spacing_V'];
  10676. // Set clipping path
  10677. $s = ' q 0 w '; // Line width=0
  10678. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10679. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10680. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10681. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10682. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10683. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10684. $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);
  10685. }
  10686. else {
  10687. $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'=>'');
  10688. }
  10689. }
  10690. }
  10691. else {
  10692. $image_id = $content[$i][0]['trbackground-images']['image_id'];
  10693. $orig_w = $content[$i][0]['trbackground-images']['orig_w'];
  10694. $orig_h = $content[$i][0]['trbackground-images']['orig_h'];
  10695. $x_pos = $content[$i][0]['trbackground-images']['x_pos'];
  10696. $y_pos = $content[$i][0]['trbackground-images']['y_pos'];
  10697. $x_repeat = $content[$i][0]['trbackground-images']['x_repeat'];
  10698. $y_repeat = $content[$i][0]['trbackground-images']['y_repeat'];
  10699. $resize = $content[$i][0]['trbackground-images']['resize'];
  10700. $opacity = $content[$i][0]['trbackground-images']['opacity'];
  10701. $itype = $content[$i][0]['trbackground-images']['itype'];
  10702. $clippath = '';
  10703. $gx = $x0;
  10704. $gy = $y;
  10705. $gh = $h;
  10706. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10707. if ($table['borders_separate']) {
  10708. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10709. $s = '';
  10710. $clx = $x+ ($table['border_spacing_H']/2);
  10711. $cly = $y+ ($table['border_spacing_V']/2);
  10712. $clw = $w- $table['border_spacing_H'];
  10713. $clh = $h- $table['border_spacing_V'];
  10714. // Set clipping path
  10715. $s = ' q 0 w '; // Line width=0
  10716. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10717. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10718. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10719. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10720. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10721. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10722. $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, 'itype'=>$itype);
  10723. }
  10724. else {
  10725. $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, 'itype'=>$itype);
  10726. }
  10727. }
  10728. }
  10729. }
  10730. /*-- END BACKGROUNDS --*/
  10731. // TABLE BORDER - if separate OR collapsed and only table border
  10732. if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) {
  10733. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  10734. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  10735. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  10736. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  10737. $tbx = $x;
  10738. $tby = $y;
  10739. $tbw = $w;
  10740. $tbh = $h;
  10741. $tab_bord = 0;
  10742. $corner = '';
  10743. if ($i == $firstrow && $horf=='H') { // Top
  10744. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  10745. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  10746. $this->setBorder($tab_bord , _BORDER_TOP);
  10747. $corner .= 'T';
  10748. }
  10749. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1))) && $horf=='F') { // Bottom
  10750. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  10751. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  10752. $corner .= 'B';
  10753. }
  10754. if ($colctr == 1 && $firstSpread) { // Left
  10755. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  10756. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  10757. $this->setBorder($tab_bord , _BORDER_LEFT);
  10758. $corner .= 'L';
  10759. }
  10760. if ($colctr == count($content[$i]) && $finalSpread) { // Right
  10761. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  10762. $this->setBorder($tab_bord , _BORDER_RIGHT);
  10763. $corner .= 'R';
  10764. }
  10765. $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'] );
  10766. }
  10767. }// end column $content
  10768. $this->y = $y + $h; //Update y coordinate
  10769. }// end row $i
  10770. unset($table );
  10771. $this->colsums = array();
  10772. }
  10773. }
  10774. /*-- END TABLES --*/
  10775. /*-- HTMLHEADERS-FOOTERS --*/
  10776. function SetHTMLHeader($header='',$OE='',$write=false) {
  10777. $height = 0;
  10778. if (is_array($header) && isset($header['html']) && $header['html']) {
  10779. $Hhtml = $header['html'];
  10780. if ($this->setAutoTopMargin) {
  10781. if (isset($header['h'])) { $height = $header['h']; }
  10782. else { $height = $this->_gethtmlheight($Hhtml); }
  10783. }
  10784. }
  10785. else if (!is_array($header) && $header) {
  10786. $Hhtml = $header;
  10787. if ($this->setAutoTopMargin) { $height = $this->_gethtmlheight($Hhtml); }
  10788. }
  10789. else { $Hhtml = ''; }
  10790. if ($OE != 'E') { $OE = 'O'; }
  10791. if ($OE == 'E') {
  10792. if ($Hhtml) {
  10793. $this->HTMLHeaderE['html'] = $Hhtml;
  10794. $this->HTMLHeaderE['h'] = $height;
  10795. }
  10796. else { $this->HTMLHeaderE = ''; }
  10797. }
  10798. else {
  10799. if ($Hhtml) {
  10800. $this->HTMLHeader['html'] = $Hhtml;
  10801. $this->HTMLHeader['h'] = $height;
  10802. }
  10803. else { $this->HTMLHeader = ''; }
  10804. }
  10805. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10806. if ($Hhtml=='') { return; }
  10807. if ($OE == 'E') {
  10808. $this->headerDetails['even'] = array(); // override and clear any other non-HTML header/footer
  10809. }
  10810. else {
  10811. $this->headerDetails['odd'] = array(); // override and clear any non-HTML other header/footer
  10812. }
  10813. if ($this->setAutoTopMargin=='pad') {
  10814. $this->tMargin = $this->margin_header + $height + $this->orig_tMargin;
  10815. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10816. }
  10817. else if ($this->setAutoTopMargin=='stretch') {
  10818. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $height + $this->autoMarginPadding);
  10819. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10820. }
  10821. 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(); }
  10822. }
  10823. function SetHTMLFooter($footer='',$OE='') {
  10824. $height = 0;
  10825. if (is_array($footer) && isset($footer['html']) && $footer['html']) {
  10826. $Fhtml = $footer['html'];
  10827. if ($this->setAutoBottomMargin) {
  10828. if (isset($footer['h'])) { $height = $footer['h']; }
  10829. else { $height = $this->_gethtmlheight($Fhtml); }
  10830. }
  10831. }
  10832. else if (!is_array($footer) && $footer) {
  10833. $Fhtml = $footer;
  10834. if ($this->setAutoBottomMargin) { $height = $this->_gethtmlheight($Fhtml); }
  10835. }
  10836. else { $Fhtml = ''; }
  10837. if ($OE != 'E') { $OE = 'O'; }
  10838. if ($OE == 'E') {
  10839. if ($Fhtml) {
  10840. $this->HTMLFooterE['html'] = $Fhtml;
  10841. $this->HTMLFooterE['h'] = $height;
  10842. }
  10843. else { $this->HTMLFooterE = ''; }
  10844. }
  10845. else {
  10846. if ($Fhtml) {
  10847. $this->HTMLFooter['html'] = $Fhtml;
  10848. $this->HTMLFooter['h'] = $height;
  10849. }
  10850. else { $this->HTMLFooter = ''; }
  10851. }
  10852. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10853. if ($Fhtml=='') { return false; }
  10854. if ($OE == 'E') {
  10855. $this->footerDetails['even'] = array(); // override and clear any other header/footer
  10856. }
  10857. else {
  10858. $this->footerDetails['odd'] = array(); // override and clear any other header/footer
  10859. }
  10860. if ($this->setAutoBottomMargin=='pad') {
  10861. $this->bMargin = $this->margin_footer + $height + $this->orig_bMargin;
  10862. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10863. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10864. }
  10865. else if ($this->setAutoBottomMargin=='stretch') {
  10866. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $height + $this->autoMarginPadding);
  10867. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10868. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10869. }
  10870. }
  10871. function _getHtmlHeight($html) {
  10872. $save_state = $this->state;
  10873. if($this->state==0) {
  10874. $this->AddPage($this->CurOrientation);
  10875. }
  10876. $this->state = 2;
  10877. $this->Reset();
  10878. $this->pageoutput[$this->page] = array();
  10879. $save_x = $this->x;
  10880. $save_y = $this->y;
  10881. $this->x = $this->lMargin;
  10882. $this->y = $this->margin_header;
  10883. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($this->page).$this->pagenumSuffix,$html);
  10884. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($this->page).$this->nbpgSuffix,$html );
  10885. $html = str_replace($this->aliasNbPg,$this->page,$html );
  10886. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  10887. $this->HTMLheaderPageLinks = array();
  10888. $this->HTMLheaderPageAnnots = array();
  10889. $this->HTMLheaderPageForms = array();
  10890. $savepb = $this->pageBackgrounds;
  10891. $this->writingHTMLheader = true;
  10892. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  10893. $this->writingHTMLheader = false;
  10894. $h = ($this->y - $this->margin_header);
  10895. $this->Reset();
  10896. $this->pageoutput[$this->page] = array();
  10897. $this->headerbuffer = '';
  10898. $this->pageBackgrounds = $savepb;
  10899. $this->x = $save_x;
  10900. $this->y = $save_y;
  10901. $this->state = $save_state;
  10902. if($save_state==0) {
  10903. unset($this->pages[1]);
  10904. $this->page = 0;
  10905. }
  10906. return $h;
  10907. }
  10908. // Called internally from Header
  10909. function writeHTMLHeaders() {
  10910. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10911. else { $OE = 'O'; }
  10912. if ($OE == 'E') {
  10913. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeaderE['html'] ;
  10914. }
  10915. else {
  10916. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeader['html'] ;
  10917. }
  10918. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10919. $this->saveHTMLHeader[$this->page][$OE]['rotate'] = true;
  10920. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->tMargin;
  10921. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->bMargin;
  10922. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10923. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10924. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->h;
  10925. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->w;
  10926. }
  10927. else {
  10928. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->lMargin;
  10929. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->rMargin;
  10930. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10931. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10932. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->w;
  10933. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->h;
  10934. }
  10935. }
  10936. function writeHTMLFooters() {
  10937. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10938. else { $OE = 'O'; }
  10939. if ($OE == 'E') {
  10940. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooterE['html'] ;
  10941. }
  10942. else {
  10943. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooter['html'] ;
  10944. }
  10945. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10946. $this->saveHTMLFooter[$this->page][$OE]['rotate'] = true;
  10947. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->tMargin;
  10948. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->bMargin;
  10949. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->rMargin;
  10950. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->lMargin;
  10951. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10952. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10953. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->h;
  10954. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->w;
  10955. }
  10956. else {
  10957. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->lMargin;
  10958. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->rMargin;
  10959. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->tMargin;
  10960. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->bMargin;
  10961. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10962. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10963. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->w;
  10964. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->h;
  10965. }
  10966. }
  10967. /*-- END HTMLHEADERS-FOOTERS --*/
  10968. function DefHeaderByName($name,$arr) {
  10969. if (!$name) { $name = '_default'; }
  10970. $this->pageheaders[$name] = $arr;
  10971. }
  10972. function DefFooterByName($name,$arr) {
  10973. if (!$name) { $name = '_default'; }
  10974. $this->pagefooters[$name] = $arr;
  10975. }
  10976. function SetHeaderByName($name,$side='O',$write=false) {
  10977. if (!$name) { $name = '_default'; }
  10978. if ($side=='E') { $this->headerDetails['even'] = $this->pageheaders[$name]; }
  10979. else { $this->headerDetails['odd'] = $this->pageheaders[$name]; }
  10980. if ($write) { $this->Header(); }
  10981. }
  10982. function SetFooterByName($name,$side='O') {
  10983. if (!$name) { $name = '_default'; }
  10984. if ($side=='E') { $this->footerDetails['even'] = $this->pagefooters[$name]; }
  10985. else { $this->footerDetails['odd'] = $this->pagefooters[$name]; }
  10986. }
  10987. /*-- HTMLHEADERS-FOOTERS --*/
  10988. function DefHTMLHeaderByName($name,$html) {
  10989. if (!$name) { $name = '_default'; }
  10990. $this->pageHTMLheaders[$name]['html'] = $html;
  10991. $this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html);
  10992. }
  10993. function DefHTMLFooterByName($name,$html) {
  10994. if (!$name) { $name = '_default'; }
  10995. $this->pageHTMLfooters[$name]['html'] = $html;
  10996. $this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html);
  10997. }
  10998. function SetHTMLHeaderByName($name,$side='O',$write=false) {
  10999. if (!$name) { $name = '_default'; }
  11000. $this->SetHTMLHeader($this->pageHTMLheaders[$name],$side,$write);
  11001. }
  11002. function SetHTMLFooterByName($name,$side='O') {
  11003. if (!$name) { $name = '_default'; }
  11004. $this->SetHTMLFooter($this->pageHTMLfooters[$name],$side,$write);
  11005. }
  11006. /*-- END HTMLHEADERS-FOOTERS --*/
  11007. function SetHeader($Harray=array(),$side='',$write=false) {
  11008. if (is_string($Harray)) {
  11009. if (strlen($Harray)==0) {
  11010. if ($side=='O') { $this->headerDetails['odd'] = array(); }
  11011. else if ($side=='E') { $this->headerDetails['even'] = array(); }
  11012. else { $this->headerDetails = array(); }
  11013. }
  11014. else if (strpos($Harray,'|') || strpos($Harray,'|')===0) {
  11015. $hdet = explode('|',$Harray);
  11016. $this->headerDetails = array (
  11017. 'odd' => array (
  11018. 'L' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11019. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11020. 'R' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11021. 'line' => $this->defaultheaderline,
  11022. ),
  11023. 'even' => array (
  11024. 'R' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11025. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11026. 'L' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11027. 'line' => $this->defaultheaderline,
  11028. )
  11029. );
  11030. }
  11031. else {
  11032. $this->headerDetails = array (
  11033. 'odd' => array (
  11034. 'R' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11035. 'line' => $this->defaultheaderline,
  11036. ),
  11037. 'even' => array (
  11038. 'L' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  11039. 'line' => $this->defaultheaderline,
  11040. )
  11041. );
  11042. }
  11043. }
  11044. else if (is_array($Harray)) {
  11045. if ($side=='O') { $this->headerDetails['odd'] = $Harray; }
  11046. else if ($side=='E') { $this->headerDetails['even'] = $Harray; }
  11047. else { $this->headerDetails = $Harray; }
  11048. }
  11049. /*-- HTMLHEADERS-FOOTERS --*/
  11050. // Overwrite any HTML Header previously set
  11051. if ($side=='E') { $this->SetHTMLHeader('','E'); }
  11052. else if ($side=='O') { $this->SetHTMLHeader(''); }
  11053. else {
  11054. $this->SetHTMLHeader('');
  11055. $this->SetHTMLHeader('','E');
  11056. }
  11057. /*-- END HTMLHEADERS-FOOTERS --*/
  11058. if ($write) {
  11059. $save_y = $this->y;
  11060. $this->Header();
  11061. $this->SetY($save_y) ;
  11062. }
  11063. }
  11064. function SetFooter($Farray=array(),$side='') {
  11065. if (is_string($Farray)) {
  11066. if (strlen($Farray)==0) {
  11067. if ($side=='O') { $this->footerDetails['odd'] = array(); }
  11068. else if ($side=='E') { $this->footerDetails['even'] = array(); }
  11069. else { $this->footerDetails = array(); }
  11070. }
  11071. else if (strpos($Farray,'|') || strpos($Farray,'|')===0) {
  11072. $fdet = explode('|',$Farray);
  11073. $this->footerDetails = array (
  11074. 'odd' => array (
  11075. 'L' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11076. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11077. 'R' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11078. 'line' => $this->defaultfooterline,
  11079. ),
  11080. 'even' => array (
  11081. 'R' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11082. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11083. 'L' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11084. 'line' => $this->defaultfooterline,
  11085. )
  11086. );
  11087. }
  11088. else {
  11089. $this->footerDetails = array (
  11090. 'odd' => array (
  11091. 'R' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11092. 'line' => $this->defaultfooterline,
  11093. ),
  11094. 'even' => array (
  11095. 'L' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  11096. 'line' => $this->defaultfooterline,
  11097. )
  11098. );
  11099. }
  11100. }
  11101. else if (is_array($Farray)) {
  11102. if ($side=='O') { $this->footerDetails['odd'] = $Farray; }
  11103. else if ($side=='E') { $this->footerDetails['even'] = $Farray; }
  11104. else { $this->footerDetails = $Farray; }
  11105. }
  11106. /*-- HTMLHEADERS-FOOTERS --*/
  11107. // Overwrite any HTML Footer previously set
  11108. if ($side=='E') { $this->SetHTMLFooter('','E'); }
  11109. else if ($side=='O') { $this->SetHTMLFooter(''); }
  11110. else {
  11111. $this->SetHTMLFooter('');
  11112. $this->SetHTMLFooter('','E');
  11113. }
  11114. /*-- END HTMLHEADERS-FOOTERS --*/
  11115. }
  11116. /*-- WATERMARK --*/
  11117. function setUnvalidatedText($txt='', $alpha=-1) {
  11118. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  11119. $this->watermarkText = $txt;
  11120. }
  11121. function SetWatermarkText($txt='', $alpha=-1) {
  11122. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  11123. $this->watermarkText = $txt;
  11124. }
  11125. function SetWatermarkImage($src, $alpha=-1, $size='D', $pos='F') {
  11126. if ($alpha>=0) $this->watermarkImageAlpha = $alpha;
  11127. $this->watermarkImage = $src;
  11128. $this->watermark_size = $size;
  11129. $this->watermark_pos = $pos;
  11130. }
  11131. /*-- END WATERMARK --*/
  11132. //Page footer
  11133. function Footer() {
  11134. /*-- CSS-PAGE --*/
  11135. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  11136. if ($this->show_marks == 'CROP' || $this->show_marks == 'CROPCROSS') {
  11137. // Show TICK MARKS
  11138. $this->SetLineWidth(0.1); // = 0.1 mm
  11139. $this->SetDColor($this->ConvertColor(0));
  11140. $l = $this->cropMarkLength;
  11141. $m = $this->cropMarkMargin; // Distance of crop mark from margin
  11142. $b = $this->nonPrintMargin; // Non-printable border at edge of paper sheet
  11143. $ax1 = $b;
  11144. $bx = $this->page_box['outer_width_LR'] - $m;
  11145. $ax = max($ax1, $bx-$l);
  11146. $cx1 = $this->w - $b;
  11147. $dx = $this->w - $this->page_box['outer_width_LR'] + $m;
  11148. $cx = min($cx1, $dx+$l);
  11149. $ay1 = $b;
  11150. $by = $this->page_box['outer_width_TB'] - $m;
  11151. $ay = max($ay1, $by-$l);
  11152. $cy1 = $this->h - $b;
  11153. $dy = $this->h - $this->page_box['outer_width_TB'] + $m;
  11154. $cy = min($cy1, $dy+$l);
  11155. $this->Line($ax, $this->page_box['outer_width_TB'], $bx, $this->page_box['outer_width_TB']);
  11156. $this->Line($cx, $this->page_box['outer_width_TB'], $dx, $this->page_box['outer_width_TB']);
  11157. $this->Line($ax, $this->h - $this->page_box['outer_width_TB'], $bx, $this->h - $this->page_box['outer_width_TB']);
  11158. $this->Line($cx, $this->h - $this->page_box['outer_width_TB'], $dx, $this->h - $this->page_box['outer_width_TB']);
  11159. $this->Line($this->page_box['outer_width_LR'], $ay, $this->page_box['outer_width_LR'], $by);
  11160. $this->Line($this->page_box['outer_width_LR'], $cy, $this->page_box['outer_width_LR'], $dy);
  11161. $this->Line($this->w - $this->page_box['outer_width_LR'], $ay, $this->w - $this->page_box['outer_width_LR'], $by);
  11162. $this->Line($this->w - $this->page_box['outer_width_LR'], $cy, $this->w - $this->page_box['outer_width_LR'], $dy);
  11163. if ($this->printers_info) {
  11164. $hd = date('Y-m-d H:i').' Page '.$this->page.' of {nb}';
  11165. $this->SetTColor($this->ConvertColor(0));
  11166. $this->SetFont('arial','',7.5,true,true);
  11167. $this->x = $this->page_box['outer_width_LR'] + 1.5;
  11168. $this->y = 1;
  11169. $this->Cell($headerpgwidth ,$this->FontSize,$hd,0,0,'L',0,'',0,0,0,'M');
  11170. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  11171. }
  11172. }
  11173. if ($this->show_marks == 'CROSS' || $this->show_marks == 'CROPCROSS') {
  11174. $this->SetLineWidth(0.1); // = 0.1 mm
  11175. $this->SetDColor($this->ConvertColor(0));
  11176. $l = 14 /2; // longer length of the cross line (half)
  11177. $w = 6 /2; // shorter width of the cross line (half)
  11178. $r = 1.2; // radius of circle
  11179. $m = $this->crossMarkMargin; // Distance of cross mark from margin
  11180. $x1 = $this->page_box['outer_width_LR'] - $m;
  11181. $x2 = $this->w - $this->page_box['outer_width_LR'] + $m;
  11182. $y1 = $this->page_box['outer_width_TB'] - $m;
  11183. $y2 = $this->h - $this->page_box['outer_width_TB'] + $m;
  11184. // Left
  11185. $this->Circle($x1, $this->h/2, $r, 'S') ;
  11186. $this->Line($x1-$w, $this->h/2, $x1+$w, $this->h/2);
  11187. $this->Line($x1, $this->h/2-$l, $x1, $this->h/2+$l);
  11188. // Right
  11189. $this->Circle($x2, $this->h/2, $r, 'S') ;
  11190. $this->Line($x2-$w, $this->h/2, $x2+$w, $this->h/2);
  11191. $this->Line($x2, $this->h/2-$l, $x2, $this->h/2+$l);
  11192. // Top
  11193. $this->Circle($this->w/2, $y1, $r, 'S') ;
  11194. $this->Line($this->w/2, $y1-$w, $this->w/2, $y1+$w);
  11195. $this->Line($this->w/2-$l, $y1, $this->w/2+$l, $y1);
  11196. // Bottom
  11197. $this->Circle($this->w/2, $y2, $r, 'S') ;
  11198. $this->Line($this->w/2, $y2-$w, $this->w/2, $y2+$w);
  11199. $this->Line($this->w/2-$l, $y2, $this->w/2+$l, $y2);
  11200. }
  11201. // If @page set non-HTML headers/footers named, they were not read until later in the HTML code - so now set them
  11202. if ($this->page==1) {
  11203. if ($this->firstPageBoxHeader) {
  11204. $this->headerDetails['odd'] = $this->pageheaders[$this->firstPageBoxHeader];
  11205. $this->Header();
  11206. }
  11207. if ($this->firstPageBoxFooter) {
  11208. $this->footerDetails['odd'] = $this->pagefooters[$this->firstPageBoxFooter];
  11209. }
  11210. $this->firstPageBoxHeader='';
  11211. $this->firstPageBoxFooter='';
  11212. }
  11213. /*-- END CSS-PAGE --*/
  11214. /*-- HTMLHEADERS-FOOTERS --*/
  11215. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLFooterE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLFooter) || (!$this->mirrorMargins && $this->HTMLFooter)) {
  11216. $this->writeHTMLFooters();
  11217. /*-- WATERMARK --*/
  11218. if (($this->watermarkText) && ($this->showWatermarkText)) {
  11219. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  11220. }
  11221. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  11222. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  11223. }
  11224. /*-- END WATERMARK --*/
  11225. return;
  11226. }
  11227. /*-- END HTMLHEADERS-FOOTERS --*/
  11228. $this->processingHeader=true;
  11229. $this->ResetMargins(); // necessary after columns
  11230. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11231. /*-- WATERMARK --*/
  11232. if (($this->watermarkText) && ($this->showWatermarkText)) {
  11233. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  11234. }
  11235. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  11236. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  11237. }
  11238. /*-- END WATERMARK --*/
  11239. $h = $this->footerDetails;
  11240. if(count($h)) {
  11241. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  11242. $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK)));
  11243. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  11244. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  11245. $headerlmargin = $this->orig_rMargin;
  11246. }
  11247. else {
  11248. $headerlmargin = $this->orig_lMargin;
  11249. }
  11250. }
  11251. else {
  11252. $yadj = 0;
  11253. $headerpgwidth = $this->pgwidth;
  11254. $headerlmargin = $this->lMargin;
  11255. }
  11256. $this->SetY(-$this->margin_footer);
  11257. $this->SetTColor($this->ConvertColor(0));
  11258. $this->SUP = false;
  11259. $this->SUB = false;
  11260. $this->bullet = false;
  11261. // only show pagenumber if numbering on
  11262. $pgno = $this->docPageNum($this->page, true);
  11263. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  11264. $side = 'even';
  11265. }
  11266. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  11267. $side = 'odd';
  11268. }
  11269. $maxfontheight = 0;
  11270. foreach(array('L','C','R') AS $pos) {
  11271. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  11272. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  11273. else { $hfsz = $this->default_font_size; }
  11274. $maxfontheight = max($maxfontheight,$hfsz);
  11275. }
  11276. }
  11277. // LEFT-CENTER-RIGHT
  11278. foreach(array('L','C','R') AS $pos) {
  11279. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  11280. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  11281. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  11282. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  11283. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  11284. else { $hff = $this->original_default_font; }
  11285. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  11286. else { $hfsz = $this->original_default_font_size; }
  11287. $maxfontheight = max($maxfontheight,$hfsz);
  11288. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) { $hfst = $h[$side][$pos]['font-style']; }
  11289. else { $hfst = ''; }
  11290. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  11291. $hfcol = $h[$side][$pos]['color'];
  11292. $cor = $this->ConvertColor($hfcol);
  11293. if ($cor) { $this->SetTColor($cor); }
  11294. }
  11295. else { $hfcol = ''; }
  11296. $this->SetFont($hff,$hfst,$hfsz,true,true);
  11297. $this->x = $headerlmargin ;
  11298. $this->y = $this->h - $this->margin_footer - ($maxfontheight/_MPDFK);
  11299. $hd = $this->purify_utf8_text($hd);
  11300. if ($this->text_input_as_HTML) {
  11301. $hd = $this->all_entities_to_utf8($hd);
  11302. }
  11303. // CONVERT CODEPAGE
  11304. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  11305. // DIRECTIONALITY RTL
  11306. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  11307. // Font-specific ligature substitution for Indic fonts
  11308. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  11309. $align = $pos;
  11310. if ($this->directionality == 'rtl') {
  11311. if ($pos == 'L') { $align = 'R'; }
  11312. else if ($pos == 'R') { $align = 'L'; }
  11313. }
  11314. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  11315. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  11316. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  11317. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  11318. $this->_out('Q');
  11319. }
  11320. else {
  11321. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  11322. }
  11323. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); }
  11324. }
  11325. }
  11326. // Return Font to normal
  11327. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  11328. // LINE
  11329. if (isset($h[$side]['line']) && $h[$side]['line']) {
  11330. $this->SetLineWidth(0.1);
  11331. $this->SetDColor($this->ConvertColor(0));
  11332. $this->Line($headerlmargin , $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK), $headerlmargin +$headerpgwidth, $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK));
  11333. }
  11334. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  11335. $this->_out('Q');
  11336. }
  11337. }
  11338. $this->processingHeader=false;
  11339. }
  11340. ///////////////////
  11341. // HYPHENATION
  11342. ///////////////////
  11343. // mPDF 5.6.21
  11344. // Hard hyphens
  11345. function hardHyphenate($word, $maxWidth) {
  11346. // Don't hyphenate web addresses
  11347. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  11348. // Get dictionary
  11349. $poss = array();
  11350. $softhyphens = array();
  11351. $offset = 0;
  11352. $p = true;
  11353. if ($this->usingCoreFont) {
  11354. $wl = strlen($word);
  11355. }
  11356. else {
  11357. $wl = mb_strlen($word,'UTF-8');
  11358. }
  11359. while($offset < $wl) {
  11360. if (!$this->usingCoreFont) {
  11361. $p = mb_strpos($word, "-", $offset, 'UTF-8');
  11362. }
  11363. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  11364. $p = strpos($word, "-", $offset);
  11365. }
  11366. if ($p !== false) { $poss[] = $p - count($poss); }
  11367. else { break; }
  11368. $offset = $p+1;
  11369. }
  11370. $success = false;
  11371. foreach($poss AS $i) {
  11372. if ($this->usingCoreFont) {
  11373. $a = substr($word,0,$i);
  11374. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  11375. $pre = $a;
  11376. $post = substr($word,$i,strlen($word));
  11377. $prelength = strlen($pre);
  11378. }
  11379. else {
  11380. $a = mb_substr($word,0,$i,'UTF-8');
  11381. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  11382. $pre = $a;
  11383. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8');
  11384. $prelength = mb_strlen($pre, 'UTF-8');
  11385. }
  11386. $success = true;
  11387. }
  11388. return array($success,$pre,$post,$prelength);
  11389. }
  11390. /*-- HYPHENATION --*/
  11391. ///////////////////
  11392. ///////////////////
  11393. // HYPHENATION
  11394. ///////////////////
  11395. // Soft hyphs
  11396. function softHyphenate($word, $maxWidth) {
  11397. // Don't hyphenate web addresses
  11398. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  11399. // Get dictionary
  11400. $poss = array();
  11401. $softhyphens = array();
  11402. $offset = 0;
  11403. $p = true;
  11404. if ($this->usingCoreFont) {
  11405. $wl = strlen($word);
  11406. }
  11407. else {
  11408. $wl = mb_strlen($word,'UTF-8');
  11409. }
  11410. while($offset < $wl) {
  11411. // Soft Hyphens chr(173)
  11412. if (!$this->usingCoreFont) {
  11413. $p = mb_strpos($word, "\xc2\xad", $offset, 'UTF-8');
  11414. }
  11415. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  11416. $p = strpos($word, chr(173), $offset);
  11417. }
  11418. if ($p !== false) { $poss[] = $p - count($poss); }
  11419. else { break; }
  11420. $offset = $p+1;
  11421. }
  11422. $success = false;
  11423. foreach($poss AS $i) {
  11424. if ($this->usingCoreFont) {
  11425. $a = substr($word,0,$i);
  11426. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  11427. $pre = $a;
  11428. $post = substr($word,$i,strlen($word));
  11429. $prelength = strlen($pre);
  11430. }
  11431. else {
  11432. $a = mb_substr($word,0,$i,'UTF-8');
  11433. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  11434. $pre = $a;
  11435. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8');
  11436. $prelength = mb_strlen($pre, 'UTF-8');
  11437. }
  11438. $success = true;
  11439. }
  11440. return array($success,$pre,$post,$prelength);
  11441. }
  11442. ///////////////////
  11443. // Word hyphenation
  11444. function hyphenateWord($word, $maxWidth) {
  11445. // Do everything inside this function in utf-8
  11446. // Don't hyphenate web addresses
  11447. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  11448. // Get dictionary
  11449. if (!$this->loadedSHYdictionary) {
  11450. if (file_exists(_MPDF_PATH.'patterns/dictionary.txt')) {
  11451. $this->SHYdictionary = file(_MPDF_PATH.'patterns/dictionary.txt',FILE_SKIP_EMPTY_LINES);
  11452. foreach($this->SHYdictionary as $entry) {
  11453. $entry = trim($entry);
  11454. $poss = array();
  11455. $offset = 0;
  11456. $p = true;
  11457. $wl = mb_strlen($entry ,'UTF-8');
  11458. while($offset < $wl) {
  11459. $p = mb_strpos($entry, '/', $offset, 'UTF-8');
  11460. if ($p !== false) { $poss[] = $p - count($poss); }
  11461. else { break; }
  11462. $offset = $p+1;
  11463. }
  11464. if (count($poss)) { $this->SHYdictionaryWords[str_replace('/', '', mb_strtolower($entry))] = $poss; }
  11465. }
  11466. }
  11467. $this->loadedSHYdictionary = true;
  11468. }
  11469. if (!in_array($this->SHYlang,$this->SHYlanguages)) { return array(false,'','',''); }
  11470. // If no pattern loaded or not the best one
  11471. if (count($this->SHYpatterns) < 1 || ($this->loadedSHYpatterns && $this->loadedSHYpatterns != $this->SHYlang)) {
  11472. include(_MPDF_PATH."patterns/" . $this->SHYlang . ".php");
  11473. $patterns = explode(' ', $patterns);
  11474. $new_patterns = array();
  11475. for($i = 0; $i < count($patterns); $i++) {
  11476. $value = $patterns[$i];
  11477. $new_patterns[preg_replace('/[0-9]/', '', $value)] = $value;
  11478. }
  11479. $this->SHYpatterns = $new_patterns;
  11480. $this->loadedSHYpatterns = $this->SHYlang;
  11481. }
  11482. if ($this->usingCoreFont) { $word = mb_convert_encoding($word,'UTF-8',$this->mb_enc); }
  11483. $prepre = '';
  11484. $postpost = '';
  11485. $startpunctuation = "\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f";
  11486. $endpunctuation = "\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb";
  11487. $pre = '';
  11488. $post = '';
  11489. if (preg_match('/^(["\''.$startpunctuation .'])+(.{'.$this->SHYcharmin.',})$/u',$word,$m)) {
  11490. $prepre = $m[1];
  11491. $word = $m[2];
  11492. }
  11493. if (preg_match('/^(.{'.$this->SHYcharmin.',})([\'\.,;:!?"'.$endpunctuation .']+)$/u',$word,$m)) {
  11494. $word = $m[1];
  11495. $postpost = $m[2];
  11496. }
  11497. if(mb_strlen($word,'UTF-8') < $this->SHYcharmin) {
  11498. return array(false,'','','');
  11499. }
  11500. $success = false;
  11501. if(isset($this->SHYdictionaryWords[mb_strtolower($word)])) {
  11502. foreach($this->SHYdictionaryWords[mb_strtolower($word)] AS $i) {
  11503. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11504. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11505. else { $testa = $a; }
  11506. if ($this->GetStringWidth($testa.'-') > $maxWidth) { break ; }
  11507. $pre = $a;
  11508. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11509. $success = true;
  11510. }
  11511. }
  11512. if (!$success) {
  11513. $text_word = '_' . $word . '_';
  11514. $word_length = mb_strlen($text_word,'UTF-8');
  11515. $single_character = preg_split('//u', $text_word);
  11516. $text_word = mb_strtolower($text_word,'UTF-8');
  11517. $hyphenated_word = array();
  11518. $numb3rs = array('0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true);
  11519. for($position = 0; $position <= ($word_length - $this->SHYcharmin); $position++) {
  11520. $maxwins = min(($word_length - $position), $this->SHYcharmax);
  11521. for($win = $this->SHYcharmin; $win <= $maxwins; $win++) {
  11522. if(isset($this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')])) {
  11523. $pattern = $this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')];
  11524. $digits = 1;
  11525. $pattern_length = mb_strlen($pattern,'UTF-8');
  11526. for($i = 0; $i < $pattern_length; $i++) {
  11527. $char = $pattern[$i];
  11528. if(isset($numb3rs[$char])) {
  11529. $zero = ($i == 0) ? $position - 1 : $position + $i - $digits;
  11530. if(!isset($hyphenated_word[$zero]) || $hyphenated_word[$zero] != $char) $hyphenated_word[$zero] = $char;
  11531. $digits++;
  11532. }
  11533. }
  11534. }
  11535. }
  11536. }
  11537. for($i = $this->SHYleftmin; $i <= (mb_strlen($word,'UTF-8') - $this->SHYrightmin); $i++) {
  11538. if(isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 != 0) {
  11539. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11540. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11541. else { $testa = $a; }
  11542. if ($this->GetStringWidth($testa.'-') > $maxWidth + 0.0001) { break ; }
  11543. $pre = $a;
  11544. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11545. $success = true;
  11546. }
  11547. }
  11548. }
  11549. if ($this->usingCoreFont) {
  11550. $pre = mb_convert_encoding($pre,$this->mb_enc,'UTF-8');
  11551. $post = mb_convert_encoding($post,$this->mb_enc,'UTF-8');
  11552. $prelength = strlen($pre);
  11553. }
  11554. else {
  11555. $prelength = mb_strlen($pre);
  11556. }
  11557. return array($success,$pre,$post,$prelength);
  11558. }
  11559. /*-- END HYPHENATION --*/
  11560. /*-- HTML-CSS --*/
  11561. ///////////////////
  11562. /// HTML parser ///
  11563. ///////////////////
  11564. function WriteHTML($html,$sub=0,$init=true,$close=true) {
  11565. // $sub ADDED - 0 = default; 1=headerCSS only; 2=HTML body (parts) only; 3 - HTML parses only
  11566. // 4 - writes HTML headers
  11567. // $close Leaves buffers etc. in current state, so that it can continue a block etc.
  11568. // $init - Clears and sets buffers to Top level block etc.
  11569. if (empty($html)) { $html = ''; }
  11570. if ($this->progressBar) { $this->UpdateProgressBar(1,0,'Parsing CSS & Headers'); } // *PROGRESS-BAR*
  11571. if ($init) {
  11572. $this->headerbuffer='';
  11573. $this->textbuffer = array();
  11574. $this->fixedPosBlockSave = array();
  11575. }
  11576. if ($sub == 1) { $html = '<style> '.$html.' </style>'; } // stylesheet only
  11577. if ($this->allow_charset_conversion) {
  11578. if ($sub < 1) {
  11579. $this->ReadCharset($html);
  11580. }
  11581. if ($this->charset_in && $sub!=4) { // mPDF 5.4.14
  11582. $success = iconv($this->charset_in,'UTF-8//TRANSLIT',$html);
  11583. if ($success) { $html = $success; }
  11584. }
  11585. }
  11586. $html = $this->purify_utf8($html,false);
  11587. if ($init) {
  11588. $this->blklvl = 0;
  11589. $this->lastblocklevelchange = 0;
  11590. $this->blk = array();
  11591. $this->initialiseBlock($this->blk[0]);
  11592. $this->blk[0]['width'] =& $this->pgwidth;
  11593. $this->blk[0]['inner_width'] =& $this->pgwidth;
  11594. $this->blk[0]['blockContext'] = $this->blockContext;
  11595. }
  11596. $zproperties = array();
  11597. if ($sub < 2) {
  11598. $this->ReadMetaTags($html);
  11599. // mPDF 5.6.18
  11600. if (preg_match('/<base[^>]*href=["\']([^"\'>]*)["\']/i', $html, $m)) {
  11601. $this->SetBasePath($m[1]);
  11602. }
  11603. // NB default stylesheet now in mPDF.css - read on initialising class
  11604. $html = $this->cssmgr->ReadCSS($html);
  11605. if ($this->useLang && !$this->usingCoreFont && preg_match('/<html [^>]*lang=[\'\"](.*?)[\'\"]/ism',$html,$m)) {
  11606. $html_lang = $m[1];
  11607. }
  11608. if (preg_match('/<html [^>]*dir=[\'\"]\s*rtl\s*[\'\"]/ism',$html)) {
  11609. $zproperties['DIRECTION'] = 'rtl';
  11610. }
  11611. // allow in-line CSS for body tag to be parsed // Get <body> tag inline CSS
  11612. if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism',$html,$m) || preg_match('/<body([^>]*)>(.*)$/ism',$html,$m)) {
  11613. $html = $m[2];
  11614. // Changed to allow style="background: url('bg.jpg')"
  11615. if (preg_match('/style=[\"](.*?)[\"]/ism',$m[1],$mm) || preg_match('/style=[\'](.*?)[\']/ism',$m[1],$mm)) {
  11616. $zproperties = $this->cssmgr->readInlineCSS($mm[1]);
  11617. }
  11618. if (preg_match('/dir=[\'\"]\s*rtl\s*[\'\"]/ism',$m[1])) {
  11619. $zproperties['DIRECTION'] = 'rtl';
  11620. }
  11621. if (isset($html_lang) && $html_lang) { $zproperties['LANG'] = $html_lang; }
  11622. if ($this->useLang && !$this->onlyCoreFonts && preg_match('/lang=[\'\"](.*?)[\'\"]/ism',$m[1],$mm)) {
  11623. $zproperties['LANG'] = $mm[1];
  11624. }
  11625. }
  11626. }
  11627. $properties = $this->cssmgr->MergeCSS('BLOCK','BODY','');
  11628. if ($zproperties) { $properties = $this->cssmgr->array_merge_recursive_unique($properties,$zproperties); }
  11629. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) {
  11630. $this->cssmgr->CSS['BODY']['DIRECTION'] = $properties['DIRECTION'];
  11631. }
  11632. if (!isset($this->cssmgr->CSS['BODY']['DIRECTION'])) {
  11633. $this->cssmgr->CSS['BODY']['DIRECTION'] = $this->directionality;
  11634. }
  11635. else { $this->SetDirectionality($this->cssmgr->CSS['BODY']['DIRECTION']); }
  11636. $this->setCSS($properties,'','BODY');
  11637. $this->blk[0]['InlineProperties'] = $this->saveInlineProperties();
  11638. if ($sub == 1) { return ''; }
  11639. if (!isset($this->cssmgr->CSS['BODY'])) { $this->cssmgr->CSS['BODY'] = array(); }
  11640. /*-- BACKGROUNDS --*/
  11641. if (isset($properties['BACKGROUND-GRADIENT'])) {
  11642. $this->bodyBackgroundGradient = $properties['BACKGROUND-GRADIENT'];
  11643. }
  11644. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE']) {
  11645. $ret = $this->SetBackground($properties, $this->pgwidth);
  11646. if ($ret) { $this->bodyBackgroundImage = $ret; }
  11647. }
  11648. /*-- END BACKGROUNDS --*/
  11649. /*-- CSS-PAGE --*/
  11650. // If page-box is set
  11651. if ($this->state==0 && isset($this->cssmgr->CSS['@PAGE']) && $this->cssmgr->CSS['@PAGE'] ) {
  11652. $this->page_box['current'] = '';
  11653. $this->page_box['using'] = true;
  11654. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', false, 'O');
  11655. $this->DefOrientation = $this->CurOrientation = $pborientation;
  11656. $this->orig_lMargin = $this->DeflMargin = $pbmgl;
  11657. $this->orig_rMargin = $this->DefrMargin = $pbmgr;
  11658. $this->orig_tMargin = $this->tMargin = $pbmgt;
  11659. $this->orig_bMargin = $this->bMargin = $pbmgb;
  11660. $this->orig_hMargin = $this->margin_header = $pbmgh;
  11661. $this->orig_fMargin = $this->margin_footer = $pbmgf;
  11662. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', true, 'O'); // first page
  11663. $this->show_marks = $marks;
  11664. if ($hname && !preg_match('/^html_(.*)$/i',$hname)) $this->firstPageBoxHeader = $hname;
  11665. if ($fname && !preg_match('/^html_(.*)$/i',$fname)) $this->firstPageBoxFooter = $fname;
  11666. }
  11667. /*-- END CSS-PAGE --*/
  11668. $parseonly = false;
  11669. $this->bufferoutput = false;
  11670. if ($sub == 3) {
  11671. $parseonly = true;
  11672. // Close any open block tags
  11673. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11674. // Output any text left in buffer
  11675. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  11676. $this->textbuffer=array();
  11677. }
  11678. else if ($sub == 4) {
  11679. // Close any open block tags
  11680. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11681. // Output any text left in buffer
  11682. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  11683. $this->bufferoutput = true;
  11684. $this->textbuffer=array();
  11685. $this->headerbuffer='';
  11686. $properties = $this->cssmgr->MergeCSS('BLOCK','BODY','');
  11687. $this->setCSS($properties,'','BODY');
  11688. }
  11689. mb_internal_encoding('UTF-8');
  11690. $html = $this->AdjustHTML($html, $this->tabSpaces); //Try to make HTML look more like XHTML
  11691. if ($this->autoFontGroups) { $html = $this->AutoFont($html); }
  11692. /*-- HTMLHEADERS-FOOTERS --*/
  11693. preg_match_all('/<htmlpageheader([^>]*)>(.*?)<\/htmlpageheader>/si',$html,$h);
  11694. for($i=0;$i<count($h[1]);$i++) {
  11695. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$h[1][$i],$n)) {
  11696. $this->pageHTMLheaders[$n[1]]['html'] = $h[2][$i];
  11697. $this->pageHTMLheaders[$n[1]]['h'] = $this->_gethtmlheight($h[2][$i]);
  11698. }
  11699. }
  11700. preg_match_all('/<htmlpagefooter([^>]*)>(.*?)<\/htmlpagefooter>/si',$html,$f);
  11701. for($i=0;$i<count($f[1]);$i++) {
  11702. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$f[1][$i],$n)) {
  11703. $this->pageHTMLfooters[$n[1]]['html'] = $f[2][$i];
  11704. $this->pageHTMLfooters[$n[1]]['h'] = $this->_gethtmlheight($f[2][$i]);
  11705. }
  11706. }
  11707. /*-- END HTMLHEADERS-FOOTERS --*/
  11708. $html = preg_replace('/<htmlpageheader.*?<\/htmlpageheader>/si','',$html);
  11709. $html = preg_replace('/<htmlpagefooter.*?<\/htmlpagefooter>/si','',$html);
  11710. if($this->state==0 && $sub!=1 && $sub!=3 && $sub!=4) {
  11711. $this->AddPage($this->CurOrientation);
  11712. }
  11713. /*-- HTMLHEADERS-FOOTERS --*/
  11714. if (isset($hname) && preg_match('/^html_(.*)$/i',$hname,$n)) $this->SetHTMLHeader($this->pageHTMLheaders[$n[1]],'O',true);
  11715. if (isset($fname) && preg_match('/^html_(.*)$/i',$fname,$n)) $this->SetHTMLFooter($this->pageHTMLfooters[$n[1]],'O');
  11716. /*-- END HTMLHEADERS-FOOTERS --*/
  11717. $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word
  11718. $this->checkSIP = false;
  11719. $this->checkSMP = false;
  11720. $this->checkCJK = false;
  11721. if ($this->onlyCoreFonts) { $html = $this->SubstituteChars($html); }
  11722. else {
  11723. if (preg_match("/([".$this->pregRTLchars."])/u", $html)) { $this->biDirectional = true; } // *RTL*
  11724. if (preg_match("/([\x{20000}-\x{2FFFF}])/u", $html)) { $this->checkSIP = true; }
  11725. if (preg_match("/([\x{10000}-\x{1FFFF}])/u", $html)) { $this->checkSMP = true; }
  11726. /*-- CJK-FONTS --*/
  11727. if (preg_match("/([".$this->pregCJKchars."])/u", $html)) { $this->checkCJK = true; }
  11728. /*-- END CJK-FONTS --*/
  11729. }
  11730. // Don't allow non-breaking spaces that are converted to substituted chars or will break anyway and mess up table width calc.
  11731. $html = str_replace('<tta>160</tta>',chr(32),$html);
  11732. $html = str_replace('</tta><tta>','|',$html);
  11733. $html = str_replace('</tts><tts>','|',$html);
  11734. $html = str_replace('</ttz><ttz>','|',$html);
  11735. //Add new supported tags in the DisableTags function
  11736. $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string
  11737. //Explode the string in order to parse the HTML code
  11738. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  11739. // ? more accurate regexp that allows e.g. <a name="Silly <name>">
  11740. // if changing - also change in fn.SubstituteChars()
  11741. // $a = preg_split ('/<((?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+)>/ms', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
  11742. if ($this->mb_enc) {
  11743. mb_internal_encoding($this->mb_enc);
  11744. }
  11745. $pbc = 0;
  11746. if ($this->progressBar) { $this->UpdateProgressBar(1,0); } // *PROGRESS-BAR*
  11747. $this->subPos = -1;
  11748. $cnt = count($a);
  11749. for($i=0;$i<$cnt; $i++) {
  11750. $e = $a[$i];
  11751. if($i%2==0) {
  11752. //TEXT
  11753. if ($this->blk[$this->blklvl]['hide']) { continue; }
  11754. if ($this->inlineDisplayOff) { continue; }
  11755. if ($this->inMeter) { continue; } // mPDF 5.5.09
  11756. if ($this->inFixedPosBlock) { $this->fixedPosBlock .= $e; continue; } // *CSS-POSITION*
  11757. if (strlen($e) == 0) { continue; }
  11758. $e = strcode2utf($e);
  11759. $e = $this->lesser_entity_decode($e);
  11760. if ($this->usingCoreFont) {
  11761. // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font
  11762. if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->subPos<$i && !$this->specialcontent) {
  11763. $cnt += $this->SubstituteCharsNonCore($a, $i, $e);
  11764. }
  11765. // CONVERT ENCODING
  11766. $e = mb_convert_encoding($e,$this->mb_enc,'UTF-8');
  11767. // mPDF 5.6.41
  11768. if ($this->toupper) { $e = mb_strtoupper($e,$this->mb_enc); }
  11769. if ($this->tolower) { $e = mb_strtolower($e,$this->mb_enc); }
  11770. if ($this->capitalize) { $e = mb_convert_case($e, MB_CASE_TITLE, "UTF-8"); }
  11771. }
  11772. else {
  11773. if ($this->checkSIP && $this->CurrentFont['sipext'] && $this->subPos<$i && !$this->specialcontent) {
  11774. $cnt += $this->SubstituteCharsSIP($a, $i, $e);
  11775. }
  11776. if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->CurrentFont['type']!='Type0' && $this->subPos<$i && !$this->specialcontent) {
  11777. // mPDF 5.6.62 removes U+200E/U+200F LTR and RTL mark and U+200C/U+200D Zero-width Joiner and Non-joiner
  11778. $e = preg_replace("/[\xe2\x80\x8c\xe2\x80\x8d\xe2\x80\x8e\xe2\x80\x8f]/u",'',$e);
  11779. $cnt += $this->SubstituteCharsMB($a, $i, $e);
  11780. }
  11781. if ($this->biDirectional) { // *RTL*
  11782. $e = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $e); // *RTL*
  11783. } // *RTL*
  11784. // Font-specific ligature substitution for Indic fonts
  11785. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($e); // *INDIC*
  11786. // mPDF 5.6.62 removes U+200E/U+200F LTR and RTL mark and U+200C/U+200D Zero-width Joiner and Non-joiner
  11787. $e = preg_replace("/[\xe2\x80\x8c\xe2\x80\x8d\xe2\x80\x8e\xe2\x80\x8f]/u",'',$e);
  11788. if ($this->toupper) { $e = mb_strtoupper($e,$this->mb_enc); }
  11789. if ($this->tolower) { $e = mb_strtolower($e,$this->mb_enc); }
  11790. if ($this->capitalize) { $e = mb_convert_case($e, MB_CASE_TITLE, "UTF-8"); }
  11791. }
  11792. if (($this->tts) || ($this->ttz) || ($this->tta)) {
  11793. $es = explode('|',$e);
  11794. $e = '';
  11795. foreach($es AS $val) {
  11796. $e .= chr($val);
  11797. }
  11798. }
  11799. //Adjust lineheight
  11800. // FORM ELEMENTS
  11801. if ($this->specialcontent) {
  11802. /*-- FORMS --*/
  11803. //SELECT tag (form element)
  11804. if ($this->specialcontent == "type=select") {
  11805. $e = ltrim($e);
  11806. $stringwidth = $this->GetStringWidth($e);
  11807. if (!isset($this->selectoption['MAXWIDTH']) || $stringwidth > $this->selectoption['MAXWIDTH']) { $this->selectoption['MAXWIDTH'] = $stringwidth; }
  11808. if (!isset($this->selectoption['SELECTED']) || $this->selectoption['SELECTED'] == '') { $this->selectoption['SELECTED'] = $e; }
  11809. // mPDD 1.4 Active Forms
  11810. if (isset($this->selectoption['ACTIVE']) && $this->selectoption['ACTIVE']) {
  11811. $this->selectoption['ITEMS'][]=array('exportValue'=>$this->selectoption['currentVAL'], 'content'=>$e, 'selected'=>$this->selectoption['currentSEL']);
  11812. }
  11813. }
  11814. // TEXTAREA
  11815. else {
  11816. $objattr = unserialize($this->specialcontent);
  11817. $objattr['text'] = $e;
  11818. $te = "\xbb\xa4\xactype=textarea,objattr=".serialize($objattr)."\xbb\xa4\xac";
  11819. if ($this->tdbegin) {
  11820. $this->_saveCellTextBuffer($te, $this->HREF);
  11821. }
  11822. else {
  11823. $this->_saveTextBuffer($te, $this->HREF);
  11824. }
  11825. }
  11826. /*-- END FORMS --*/
  11827. }
  11828. // TABLE
  11829. else if ($this->tableLevel) {
  11830. /*-- TABLES --*/
  11831. if ($this->tdbegin) {
  11832. if (($this->ignorefollowingspaces) && !$this->ispre) { $e = ltrim($e); }
  11833. if ($e || $e==='0') {
  11834. if (($this->blockjustfinished || $this->listjustfinished) && $this->cell[$this->row][$this->col]['s']>0) {
  11835. $this->_saveCellTextBuffer("\n");
  11836. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  11837. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11838. }
  11839. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  11840. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11841. }
  11842. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  11843. }
  11844. $this->blockjustfinished=false;
  11845. $this->listjustfinished=false;
  11846. $this->_saveCellTextBuffer($e, $this->HREF);
  11847. if (!isset($this->cell[$this->row][$this->col]['R']) || !$this->cell[$this->row][$this->col]['R']) {
  11848. if (isset($this->cell[$this->row][$this->col]['s'])) {
  11849. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e, false);
  11850. }
  11851. else { $this->cell[$this->row][$this->col]['s'] = $this->GetStringWidth($e, false); }
  11852. if (!empty($this->spanborddet)) {
  11853. $this->cell[$this->row][$this->col]['s'] += $this->spanborddet['L']['w'] + $this->spanborddet['R']['w'];
  11854. }
  11855. }
  11856. if ($this->checkCJK && preg_match("/([".$this->pregCJKchars."])/u", $e)) { $this->tableCJK = true; } // *CJK-FONTS*
  11857. // mPDF 5.6.13 Decimal mark alignment
  11858. if (substr($this->cell[$this->row][$this->col]['a'],0,1) == 'D') {
  11859. $dp = $this->decimal_align[substr($this->cell[$this->row][$this->col]['a'],0,2)];
  11860. $s = preg_split('/'.preg_quote($dp,'/').'/', $e, 2); // ? needs to be /u if not core
  11861. $s0 = $this->GetStringWidth($s[0], false);
  11862. if ($s[1]) { $s1 = $this->GetStringWidth(($s[1].$dp), false); }
  11863. else $s1 = 0;
  11864. if (!isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs0'])) {
  11865. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs0'] = $s0;
  11866. }
  11867. else {
  11868. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs0'] = max($s0, $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs0']);
  11869. }
  11870. if (!isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs1'])) {
  11871. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs1'] = $s1;
  11872. }
  11873. else {
  11874. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs1'] = max($s1, $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs1']);
  11875. }
  11876. }
  11877. if ($this->tableLevel==1 && $this->useGraphs) {
  11878. $this->graphs[$this->currentGraphId]['data'][$this->row][$this->col] = $e;
  11879. }
  11880. $this->nestedtablejustfinished = false;
  11881. $this->linebreakjustfinished=false;
  11882. }
  11883. }
  11884. /*-- END TABLES --*/
  11885. }
  11886. // ALL ELSE
  11887. else {
  11888. if ($this->ignorefollowingspaces and !$this->ispre) { $e = ltrim($e); }
  11889. if ($e || $e==='0') $this->_saveTextBuffer($e, $this->HREF);
  11890. }
  11891. }
  11892. else { // TAG **
  11893. if($e[0]=='/') {
  11894. /*-- PROGRESS-BAR --*/
  11895. if ($this->progressBar) { // 10% increments
  11896. if (intval($i*10/$cnt) != $pbc) { $pbc = intval($i*10/$cnt); $this->UpdateProgressBar(1,$pbc*10,$tag); }
  11897. }
  11898. /*-- END PROGRESS-BAR --*/
  11899. // Check for tags where HTML specifies optional end tags,
  11900. // and/or does not allow nesting e.g. P inside P, or
  11901. $endtag = trim(strtoupper(substr($e,1))); // mPDF 5.4.20
  11902. if($this->blk[$this->blklvl]['hide']) {
  11903. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) {
  11904. unset($this->blk[$this->blklvl]);
  11905. $this->blklvl--;
  11906. }
  11907. continue;
  11908. }
  11909. /*-- CSS-POSITION --*/
  11910. if ($this->inFixedPosBlock) {
  11911. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) { $this->fixedPosBlockDepth--; }
  11912. if ($this->fixedPosBlockDepth == 0) {
  11913. $this->fixedPosBlockSave[] = array($this->fixedPosBlock, $this->fixedPosBlockBBox, $this->page);
  11914. $this->fixedPosBlock = '';
  11915. $this->inFixedPosBlock = false;
  11916. continue;
  11917. }
  11918. $this->fixedPosBlock .= '<'.$e.'>';
  11919. continue;
  11920. }
  11921. /*-- END CSS-POSITION --*/
  11922. if ($this->allow_html_optional_endtags && !$parseonly) {
  11923. if (($endtag == 'DIV' || $endtag =='FORM' || $endtag =='CENTER') && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); }
  11924. if ($this->lastoptionaltag == 'LI' && $endtag == 'OL') { $this->CloseTag($this->lastoptionaltag ); }
  11925. if ($this->lastoptionaltag == 'LI' && $endtag == 'UL') { $this->CloseTag($this->lastoptionaltag ); }
  11926. if ($this->lastoptionaltag == 'DD' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11927. if ($this->lastoptionaltag == 'DT' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11928. if ($this->lastoptionaltag == 'OPTION' && $endtag == 'SELECT') { $this->CloseTag($this->lastoptionaltag ); }
  11929. /*-- TABLES --*/
  11930. if ($endtag == 'TABLE') {
  11931. if ($this->lastoptionaltag == 'THEAD' || $this->lastoptionaltag == 'TBODY' || $this->lastoptionaltag == 'TFOOT') {
  11932. $this->CloseTag($this->lastoptionaltag);
  11933. }
  11934. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11935. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11936. }
  11937. if ($endtag == 'THEAD' || $endtag == 'TBODY' || $endtag == 'TFOOT') {
  11938. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11939. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11940. }
  11941. if ($endtag == 'TR') {
  11942. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); }
  11943. }
  11944. /*-- END TABLES --*/
  11945. }
  11946. $this->CloseTag($endtag);
  11947. }
  11948. else { // OPENING TAG
  11949. if($this->blk[$this->blklvl]['hide']) {
  11950. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11951. else { $te = strtoupper($e); }
  11952. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) {
  11953. $this->blklvl++;
  11954. $this->blk[$this->blklvl]['hide']=true;
  11955. }
  11956. continue;
  11957. }
  11958. /*-- CSS-POSITION --*/
  11959. if ($this->inFixedPosBlock) {
  11960. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11961. else { $te = strtoupper($e); }
  11962. $this->fixedPosBlock .= '<'.$e.'>';
  11963. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) { $this->fixedPosBlockDepth++; }
  11964. continue;
  11965. }
  11966. /*-- END CSS-POSITION --*/
  11967. $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any
  11968. $e = preg_replace($regexp,"=\"\$1\"",$e);
  11969. // changes anykey=anyvalue to anykey="anyvalue" (only do this inside [some] tags)
  11970. if (substr($e,0,10)!='pageheader' && substr($e,0,10)!='pagefooter' && substr($e,0,12)!='tocpagebreak') { // mPDF 5.6.69
  11971. $regexp = '| (\\w+?)=([^\\s>"]+)|si';
  11972. $e = preg_replace($regexp," \$1=\"\$2\"",$e);
  11973. }
  11974. $e = preg_replace('/ (\\S+?)\s*=\s*"/i', " \\1=\"", $e);
  11975. //Fix path values, if needed
  11976. $orig_srcpath = '';
  11977. if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) ) {
  11978. $regexp = '/ (href|src)\s*=\s*"(.*?)"/i';
  11979. preg_match($regexp,$e,$auxiliararray);
  11980. if (isset($auxiliararray[2])) { $path = $auxiliararray[2]; }
  11981. else { $path = ''; }
  11982. if (trim($path) != '' && !(stristr($e,"src=") !== false && substr($path,0,4)=='var:')) {
  11983. $orig_srcpath = $path;
  11984. $this->GetFullPath($path);
  11985. $regexp = '/ (href|src)="(.*?)"/i';
  11986. $e = preg_replace($regexp,' \\1="'.$path.'"',$e);
  11987. }
  11988. }//END of Fix path values
  11989. //Extract attributes
  11990. $contents=array();
  11991. $contents1=array(); // mPDF 5.5.17
  11992. $contents2=array();
  11993. // Changed to allow style="background: url('bg.jpg')"
  11994. // mPDF 5.5.17 Changed to improve performance; maximum length of \S (attribute) = 16
  11995. // mPDF 5.6.30 Increase allowed attribute name to 32 - cutting off "toc-even-header-name" etc.
  11996. preg_match_all('/\\S{1,32}=["][^"]*["]/',$e,$contents1);
  11997. preg_match_all('/\\S{1,32}=[\'][^\']*[\']/i',$e,$contents2);
  11998. $contents = array_merge($contents1, $contents2);
  11999. preg_match('/\\S+/',$e,$a2);
  12000. $tag=strtoupper($a2[0]);
  12001. $attr=array();
  12002. if ($orig_srcpath) { $attr['ORIG_SRC'] = $orig_srcpath; }
  12003. if (!empty($contents)) {
  12004. foreach($contents[0] as $v) {
  12005. // Changed to allow style="background: url('bg.jpg')"
  12006. if(preg_match('/^([^=]*)=["]?([^"]*)["]?$/',$v,$a3) || preg_match('/^([^=]*)=[\']?([^\']*)[\']?$/',$v,$a3)) {
  12007. if (strtoupper($a3[1])=='ID' || strtoupper($a3[1])=='CLASS') { // 4.2.013 Omits STYLE
  12008. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  12009. }
  12010. // includes header-style-right etc. used for <pageheader>
  12011. else if (preg_match('/^(HEADER|FOOTER)-STYLE/i',$a3[1])) {
  12012. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  12013. }
  12014. else {
  12015. $attr[strtoupper($a3[1])]=trim($a3[2]);
  12016. }
  12017. }
  12018. }
  12019. }
  12020. $this->OpenTag($tag,$attr);
  12021. /*-- CSS-POSITION --*/
  12022. if ($this->inFixedPosBlock) {
  12023. $this->fixedPosBlockBBox = array($tag,$attr, $this->x, $this->y);
  12024. $this->fixedPosBlock = '';
  12025. $this->fixedPosBlockDepth = 1;
  12026. }
  12027. /*-- END CSS-POSITION --*/
  12028. // mPDF 5.5.09
  12029. if (preg_match('/\/$/',$e)) { $this->closeTag($tag); }
  12030. }
  12031. } // end TAG
  12032. } //end of foreach($a as $i=>$e)
  12033. if ($close) {
  12034. // Close any open block tags
  12035. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  12036. // Output any text left in buffer
  12037. if (count($this->textbuffer) && !$parseonly) { $this->printbuffer($this->textbuffer); }
  12038. if (!$parseonly) $this->textbuffer=array();
  12039. /*-- CSS-FLOAT --*/
  12040. // If ended with a float, need to move to end page
  12041. $currpos = $this->page*1000 + $this->y;
  12042. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  12043. $old_page = $this->page;
  12044. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  12045. if ($old_page != $new_page) {
  12046. $s = $this->PrintPageBackgrounds();
  12047. // Writes after the marker so not overwritten later by page background etc.
  12048. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  12049. $this->pageBackgrounds = array();
  12050. $this->page = $new_page;
  12051. $this->ResetMargins();
  12052. $this->Reset();
  12053. $this->pageoutput[$this->page] = array();
  12054. }
  12055. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  12056. }
  12057. /*-- END CSS-FLOAT --*/
  12058. /*-- CSS-IMAGE-FLOAT --*/
  12059. $this->printfloatbuffer();
  12060. /*-- END CSS-IMAGE-FLOAT --*/
  12061. //Create Internal Links, if needed
  12062. if (!empty($this->internallink) ) {
  12063. foreach($this->internallink as $k=>$v) {
  12064. if (strpos($k,"#") !== false ) { continue; } //ignore
  12065. $ypos = $v['Y'];
  12066. $pagenum = $v['PAGE'];
  12067. $sharp = "#";
  12068. while (array_key_exists($sharp.$k,$this->internallink)) {
  12069. $internallink = $this->internallink[$sharp.$k];
  12070. $this->SetLink($internallink,$ypos,$pagenum);
  12071. $sharp .= "#";
  12072. }
  12073. }
  12074. }
  12075. $this->linemaxfontsize = '';
  12076. $this->lineheight_correction = $this->default_lineheight_correction;
  12077. $this->bufferoutput = false;
  12078. /*-- CSS-POSITION --*/
  12079. if (count($this->fixedPosBlockSave) && $sub != 4) {
  12080. foreach($this->fixedPosBlockSave AS $fpbs) {
  12081. $old_page = $this->page;
  12082. $this->page = $fpbs[2];
  12083. $this->WriteFixedPosHTML($fpbs[0], 0, 0, 100, 100,'auto', $fpbs[1]); // 0,0,10,10 are overwritten by bbox
  12084. $this->page = $old_page;
  12085. }
  12086. }
  12087. /*-- END CSS-POSITION --*/
  12088. }
  12089. }
  12090. /*-- CSS-POSITION --*/
  12091. function WriteFixedPosHTML($html='',$x, $y, $w, $h, $overflow='visible', $bounding=array()) {
  12092. // $overflow can be 'hidden', 'visible' or 'auto' - 'auto' causes autofit to size
  12093. // Annotations disabled - enabled in mPDF 5.0
  12094. // Links do work
  12095. // Will always go on current page (or start Page 1 if required)
  12096. // Probably INCOMPATIBLE WITH keep with table, columns etc.
  12097. // Called externally or interally via <div style="position: [fixed|absolute]">
  12098. // When used internally, $x $y $w $h and $overflow are all overridden by $bounding
  12099. $overflow = strtolower($overflow);
  12100. if($this->state==0) {
  12101. $this->AddPage($this->CurOrientation);
  12102. }
  12103. $save_y = $this->y;
  12104. $save_x = $this->x;
  12105. $this->fullImageHeight = $this->h;
  12106. $save_cols = false;
  12107. /*-- COLUMNS --*/
  12108. if ($this->ColActive) {
  12109. $save_cols = true;
  12110. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  12111. $this->SetColumns(0);
  12112. }
  12113. /*-- END COLUMNS --*/
  12114. $save_annots = $this->title2annots; // *ANNOTATIONS*
  12115. $this->writingHTMLheader = true; // a FIX to stop pagebreaks etc.
  12116. $this->writingHTMLfooter = true;
  12117. $this->InFooter = true; // suppresses autopagebreaks
  12118. $save_bgs = $this->pageBackgrounds;
  12119. $checkinnerhtml = preg_replace('/\s/','',$html);
  12120. if ($w > $this->w) { $x = 0; $w = $this->w; }
  12121. if ($h > $this->h) { $y = 0; $h = $this->h; }
  12122. if ($x > $this->w) { $x = $this->w - $w; }
  12123. if ($y > $this->h) { $y = $this->h - $h; }
  12124. if (!empty($bounding)) {
  12125. // $cont_ containing block = full physical page (position: absolute) or page inside margins (position: fixed)
  12126. // $bbox_ Bounding box is the <div> which is positioned absolutely/fixed
  12127. // top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken from bounding
  12128. // font*[family/size/style/weight]/line-height/text*[align/decoration/transform/indent]/color are transferred to $inner
  12129. // as an enclosing <div> (after having checked ID/CLASS)
  12130. // $x, $y, $w, $h are inside of $bbox_ = containing box for $inner_
  12131. // $inner_ InnerHTML is the contents of that block to be output
  12132. $tag = $bounding[0];
  12133. $attr = $bounding[1];
  12134. $orig_x0 = $bounding[2];
  12135. $orig_y0 = $bounding[3];
  12136. // As in WriteHTML() initialising
  12137. $this->blklvl = 0;
  12138. $this->lastblocklevelchange = 0;
  12139. $this->blk = array();
  12140. $this->initialiseBlock($this->blk[0]);
  12141. $this->blk[0]['width'] =& $this->pgwidth;
  12142. $this->blk[0]['inner_width'] =& $this->pgwidth;
  12143. $this->blk[0]['blockContext'] = $this->blockContext;
  12144. $properties = $this->cssmgr->MergeCSS('BLOCK','BODY','');
  12145. $this->setCSS($properties,'','BODY');
  12146. $this->blklvl = 1;
  12147. $this->initialiseBlock($this->blk[1]);
  12148. $this->blk[1]['tag'] = $tag;
  12149. $this->blk[1]['attr'] = $attr;
  12150. $this->Reset();
  12151. $p = $this->cssmgr->MergeCSS('BLOCK',$tag,$attr);
  12152. if (isset($p['ROTATE']) && ($p['ROTATE']==90 || $p['ROTATE']==-90)) { $rotate = $p['ROTATE']; }
  12153. else { $rotate = 0; }
  12154. if (isset($p['OVERFLOW'])) { $overflow = strtolower($p['OVERFLOW']); }
  12155. if (strtolower($p['POSITION']) == 'fixed') {
  12156. $cont_w = $this->pgwidth; // $this->blk[0]['inner_width'];
  12157. $cont_h = $this->h - $this->tMargin - $this->bMargin;
  12158. $cont_x = $this->lMargin;
  12159. $cont_y = $this->tMargin;
  12160. }
  12161. else {
  12162. $cont_w = $this->w; // ABSOLUTE;
  12163. $cont_h = $this->h;
  12164. $cont_x = 0;
  12165. $cont_y = 0;
  12166. }
  12167. // Pass on in-line properties to the innerhtml
  12168. $css = '';
  12169. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; }
  12170. if (isset($p['TEXT-TRANSFORM'])) { $css .= 'text-transform: '.strtolower($p['TEXT-TRANSFORM']).'; '; }
  12171. if (isset($p['TEXT-INDENT'])) { $css .= 'text-indent: '.strtolower($p['TEXT-INDENT']).'; '; }
  12172. if (isset($p['TEXT-DECORATION'])) { $css .= 'text-decoration: '.strtolower($p['TEXT-DECORATION']).'; '; }
  12173. if (isset($p['FONT-FAMILY'])) { $css .= 'font-family: '.strtolower($p['FONT-FAMILY']).'; '; }
  12174. if (isset($p['FONT-STYLE'])) { $css .= 'font-style: '.strtolower($p['FONT-STYLE']).'; '; }
  12175. if (isset($p['FONT-WEIGHT'])) { $css .= 'font-weight: '.strtolower($p['FONT-WEIGHT']).'; '; }
  12176. if (isset($p['FONT-SIZE'])) { $css .= 'font-size: '.strtolower($p['FONT-SIZE']).'; '; }
  12177. if (isset($p['LINE-HEIGHT'])) { $css .= 'line-height: '.strtolower($p['LINE-HEIGHT']).'; '; }
  12178. if (isset($p['TEXT-SHADOW'])) { $css .= 'text-shadow: '.strtolower($p['TEXT-SHADOW']).'; '; }
  12179. if (isset($p['LETTER-SPACING'])) { $css .= 'letter-spacing: '.strtolower($p['LETTER-SPACING']).'; '; }
  12180. if (isset($p['FONT-VARIANT'])) { $css .= 'font-variant: '.strtolower($p['FONT-VARIANT']).'; '; }
  12181. if (isset($p['COLOR'])) { $css .= 'color: '.strtolower($p['COLOR']).'; '; }
  12182. if (isset($p['Z-INDEX'])) { $css .= 'z-index: '.$p['Z-INDEX'].'; '; } // mPDF 5.6.01
  12183. if ($css) {
  12184. $html = '<div style="'.$css.'">'.$html.'</div>';
  12185. }
  12186. // Copy over (only) the properties to set for border and background
  12187. $pb = array();
  12188. $pb['MARGIN-TOP'] = $p['MARGIN-TOP'];
  12189. $pb['MARGIN-RIGHT'] = $p['MARGIN-RIGHT'];
  12190. $pb['MARGIN-BOTTOM'] = $p['MARGIN-BOTTOM'];
  12191. $pb['MARGIN-LEFT'] = $p['MARGIN-LEFT'];
  12192. $pb['PADDING-TOP'] = $p['PADDING-TOP'];
  12193. $pb['PADDING-RIGHT'] = $p['PADDING-RIGHT'];
  12194. $pb['PADDING-BOTTOM'] = $p['PADDING-BOTTOM'];
  12195. $pb['PADDING-LEFT'] = $p['PADDING-LEFT'];
  12196. $pb['BORDER-TOP'] = $p['BORDER-TOP'];
  12197. $pb['BORDER-RIGHT'] = $p['BORDER-RIGHT'];
  12198. $pb['BORDER-BOTTOM'] = $p['BORDER-BOTTOM'];
  12199. $pb['BORDER-LEFT'] = $p['BORDER-LEFT'];
  12200. $pb['BORDER-TOP-LEFT-RADIUS-H'] = $p['BORDER-TOP-LEFT-RADIUS-H'];
  12201. $pb['BORDER-TOP-LEFT-RADIUS-V'] = $p['BORDER-TOP-LEFT-RADIUS-V'];
  12202. $pb['BORDER-TOP-RIGHT-RADIUS-H'] = $p['BORDER-TOP-RIGHT-RADIUS-H'];
  12203. $pb['BORDER-TOP-RIGHT-RADIUS-V'] = $p['BORDER-TOP-RIGHT-RADIUS-V'];
  12204. $pb['BORDER-BOTTOM-LEFT-RADIUS-H'] = $p['BORDER-BOTTOM-LEFT-RADIUS-H'];
  12205. $pb['BORDER-BOTTOM-LEFT-RADIUS-V'] = $p['BORDER-BOTTOM-LEFT-RADIUS-V'];
  12206. $pb['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-H'];
  12207. $pb['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-V'];
  12208. if (isset($p['BACKGROUND-COLOR'])) { $pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  12209. if (isset($p['BOX-SHADOW'])) { $pb['BOX-SHADOW'] = $p['BOX-SHADOW']; }
  12210. /*-- BACKGROUNDS --*/
  12211. if (isset($p['BACKGROUND-IMAGE'])) { $pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  12212. if (isset($p['BACKGROUND-IMAGE-RESIZE'])) { $pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  12213. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; }
  12214. if (isset($p['BACKGROUND-REPEAT'])) { $pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  12215. if (isset($p['BACKGROUND-POSITION'])) { $pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  12216. if (isset($p['BACKGROUND-GRADIENT'])) { $pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  12217. if (isset($p['BACKGROUND-SIZE'])) { $pb['BACKGROUND-SIZE'] = $p['BACKGROUND-SIZE']; } // mPDF 5.6.12
  12218. if (isset($p['BACKGROUND-ORIGIN'])) { $pb['BACKGROUND-ORIGIN'] = $p['BACKGROUND-ORIGIN']; } // mPDF 5.6.12
  12219. if (isset($p['BACKGROUND-CLIP'])) { $pb['BACKGROUND-CLIP'] = $p['BACKGROUND-CLIP']; } // mPDF 5.6.12
  12220. /*-- END BACKGROUNDS --*/
  12221. $this->setCSS($pb,'BLOCK',$tag);
  12222. //================================================================
  12223. $bbox_br = $this->blk[1]['border_right']['w'];
  12224. $bbox_bl = $this->blk[1]['border_left']['w'];
  12225. $bbox_bt = $this->blk[1]['border_top']['w'];
  12226. $bbox_bb = $this->blk[1]['border_bottom']['w'];
  12227. $bbox_pr = $this->blk[1]['padding_right'];
  12228. $bbox_pl = $this->blk[1]['padding_left'];
  12229. $bbox_pt = $this->blk[1]['padding_top'];
  12230. $bbox_pb = $this->blk[1]['padding_bottom'];
  12231. $bbox_mr = $this->blk[1]['margin_right'];
  12232. if (strtolower($p['MARGIN-RIGHT'])=='auto') { $bbox_mr = 'auto'; }
  12233. $bbox_ml = $this->blk[1]['margin_left'];
  12234. if (strtolower($p['MARGIN-LEFT'])=='auto') { $bbox_ml = 'auto'; }
  12235. $bbox_mt = $this->blk[1]['margin_top'];
  12236. if (strtolower($p['MARGIN-TOP'])=='auto') { $bbox_mt = 'auto'; }
  12237. $bbox_mb = $this->blk[1]['margin_bottom'];
  12238. if (strtolower($p['MARGIN-BOTTOM'])=='auto') { $bbox_mb = 'auto'; }
  12239. if (isset($p['LEFT']) && strtolower($p['LEFT'])!='auto') { $bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this->FontSize,false); }
  12240. else { $bbox_left = 'auto'; }
  12241. if (isset($p['TOP']) && strtolower($p['TOP'])!='auto') { $bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this->FontSize,false); }
  12242. else { $bbox_top = 'auto'; }
  12243. if (isset($p['RIGHT']) && strtolower($p['RIGHT'])!='auto') { $bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w, $this->FontSize,false); }
  12244. else { $bbox_right = 'auto'; }
  12245. if (isset($p['BOTTOM']) && strtolower($p['BOTTOM'])!='auto') { $bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h, $this->FontSize,false); }
  12246. else { $bbox_bottom = 'auto'; }
  12247. if (isset($p['WIDTH']) && strtolower($p['WIDTH'])!='auto') { $inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this->FontSize,false); }
  12248. else { $inner_w = 'auto'; }
  12249. if (isset($p['HEIGHT']) && strtolower($p['HEIGHT'])!='auto') { $inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this->FontSize,false); }
  12250. else { $inner_h = 'auto'; }
  12251. // If bottom or right pos are set and not left / top - save this to adjust rotated block later
  12252. if ($rotate) {
  12253. if ($bbox_left === 'auto' && $bbox_right !== 'auto') { $rot_rpos = $bbox_right; }
  12254. else { $rot_rpos = false; }
  12255. if ($bbox_top === 'auto' && $bbox_bottom !== 'auto') { $rot_bpos = $bbox_bottom; }
  12256. else { $rot_bpos = false; }
  12257. }
  12258. //================================================================
  12259. if ($checkinnerhtml=='' && $inner_h==='auto') { $inner_h = 0.0001; }
  12260. if ($checkinnerhtml=='' && $inner_w==='auto') { $inner_w = 2*$this->GetCharWidth('W',false); }
  12261. //================================================================
  12262. // Algorithm from CSS2.1 See http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height
  12263. // mPD 5.3.14
  12264. // Special case (not CSS) if all not specified, centre vertically on page
  12265. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto' && $bbox_mt==='auto' && $bbox_mb==='auto') {
  12266. $bbox_top_orig = $bbox_top;
  12267. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  12268. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  12269. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  12270. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  12271. }
  12272. // mPD 5.3.14
  12273. else if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto') {
  12274. $bbox_top_orig = $bbox_top = $orig_y0 - $cont_y;
  12275. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  12276. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  12277. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  12278. }
  12279. else if ($bbox_top!=='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  12280. if ($bbox_mt==='auto' && $bbox_mb==='auto') {
  12281. $x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  12282. $bbox_mt = $bbox_mb = ($x/2);
  12283. }
  12284. else if ($bbox_mt==='auto') {
  12285. $bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12286. }
  12287. else if ($bbox_mb==='auto') {
  12288. $bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  12289. }
  12290. else {
  12291. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  12292. }
  12293. }
  12294. else {
  12295. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  12296. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  12297. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom!=='auto') {
  12298. // solve for $bbox_top when content_h known - $inner_h=='auto' && $bbox_top =='auto'
  12299. }
  12300. else if ($bbox_top==='auto' && $bbox_bottom==='auto' && $inner_h!=='auto') {
  12301. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  12302. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  12303. }
  12304. else if ($inner_h==='auto' && $bbox_bottom==='auto' && $bbox_top!=='auto') {
  12305. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  12306. }
  12307. else if ($bbox_top==='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  12308. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  12309. }
  12310. else if ($inner_h==='auto' && $bbox_top!=='auto' && $bbox_bottom!=='auto') {
  12311. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  12312. }
  12313. else if ($bbox_bottom==='auto' && $bbox_top!=='auto' && $inner_h!=='auto') {
  12314. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  12315. }
  12316. }
  12317. // THEN DO SAME FOR WIDTH
  12318. // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width
  12319. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right==='auto') {
  12320. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  12321. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  12322. // IF containing element RTL, should set $bbox_right
  12323. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  12324. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  12325. }
  12326. else if ($bbox_left!=='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  12327. if ($bbox_ml==='auto' && $bbox_mr==='auto') {
  12328. $x = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  12329. $bbox_ml = $bbox_mr = ($x/2);
  12330. }
  12331. else if ($bbox_ml==='auto') {
  12332. $bbox_ml = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  12333. }
  12334. else if ($bbox_mr==='auto') {
  12335. $bbox_mr = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  12336. }
  12337. else {
  12338. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12339. }
  12340. }
  12341. else {
  12342. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  12343. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  12344. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right!=='auto') {
  12345. // solve for $bbox_left when content_w known - $inner_w=='auto' && $bbox_left =='auto'
  12346. }
  12347. else if ($bbox_left==='auto' && $bbox_right==='auto' && $inner_w!=='auto') {
  12348. // IF containing element RTL, should set $bbox_right
  12349. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  12350. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12351. }
  12352. else if ($inner_w==='auto' && $bbox_right==='auto' && $bbox_left!=='auto') {
  12353. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  12354. }
  12355. else if ($bbox_left==='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  12356. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  12357. }
  12358. else if ($inner_w==='auto' && $bbox_left!=='auto' && $bbox_right!=='auto') {
  12359. $inner_w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  12360. }
  12361. else if ($bbox_right==='auto' && $bbox_left!=='auto' && $inner_w!=='auto') {
  12362. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12363. }
  12364. }
  12365. //================================================================
  12366. //================================================================
  12367. /*-- BACKGROUNDS --*/
  12368. if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) {
  12369. $ret = $this->SetBackground($pb, $this->blk[1]['inner_width']);
  12370. if ($ret) { $this->blk[1]['background-image'] = $ret; }
  12371. }
  12372. /*-- END BACKGROUNDS --*/
  12373. //================================================================
  12374. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  12375. $h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12376. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  12377. $w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  12378. // Set (temporary) values for x y w h to do first paint, if values are auto
  12379. if ($inner_h==='auto' && $bbox_top==='auto') {
  12380. $y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt;
  12381. $h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  12382. }
  12383. else if ($inner_h==='auto' && $bbox_bottom==='auto') {
  12384. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  12385. $h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  12386. }
  12387. if ($inner_w==='auto' && $bbox_left==='auto') {
  12388. $x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl;
  12389. $w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  12390. }
  12391. else if ($inner_w==='auto' && $bbox_right==='auto') {
  12392. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  12393. $w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  12394. }
  12395. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12396. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  12397. $saved_block1 = $this->blk[1];
  12398. unset($p);
  12399. unset($pb);
  12400. //================================================================
  12401. if ($inner_w==='auto') { // do a first write
  12402. $this->lMargin=$x;
  12403. $this->rMargin=$this->w - $w - $x;
  12404. // SET POSITION & FONT VALUES
  12405. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12406. $this->pageoutput[$this->page]=array();
  12407. $this->x = $x;
  12408. $this->y = $y;
  12409. $this->HTMLheaderPageLinks = array();
  12410. $this->HTMLheaderPageAnnots = array();
  12411. $this->HTMLheaderPageForms = array();
  12412. $this->pageBackgrounds = array();
  12413. $this->maxPosR = 0;
  12414. $this->maxPosL = $this->w; // For RTL
  12415. $this->WriteHTML($html , 4);
  12416. $inner_w = $this->maxPosR - $this->lMargin;
  12417. if ($bbox_right==='auto') {
  12418. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  12419. }
  12420. else if ($bbox_left==='auto') {
  12421. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  12422. $bbox_x = $cont_x + $bbox_left + $bbox_ml ;
  12423. $inner_x = $bbox_x + $bbox_bl + $bbox_pl;
  12424. $x = $inner_x;
  12425. }
  12426. $w = $inner_w;
  12427. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12428. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  12429. }
  12430. if ($inner_h==='auto') { // do a first write
  12431. $this->lMargin=$x;
  12432. $this->rMargin=$this->w - $w - $x;
  12433. // SET POSITION & FONT VALUES
  12434. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12435. $this->pageoutput[$this->page]=array();
  12436. $this->x = $x;
  12437. $this->y = $y;
  12438. $this->HTMLheaderPageLinks = array();
  12439. $this->HTMLheaderPageAnnots = array();
  12440. $this->HTMLheaderPageForms = array();
  12441. $this->pageBackgrounds = array();
  12442. $this->WriteHTML($html , 4);
  12443. $inner_h = $this->y - $y;
  12444. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  12445. if (($this->y + $bbox_pb + $bbox_bb) > ($cont_y + $cont_h)) {
  12446. $adj = ($this->y + $bbox_pb + $bbox_bb) - ($cont_y + $cont_h);
  12447. $inner_h -= $adj;
  12448. }
  12449. }
  12450. if ($bbox_bottom==='auto' && $bbox_top_orig==='auto') {
  12451. $bbox_bottom = $bbox_top = ($cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb)/2;
  12452. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  12453. if ($bbox_top < 0) {
  12454. $bbox_top = 0;
  12455. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12456. }
  12457. }
  12458. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12459. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  12460. $y = $inner_y;
  12461. }
  12462. else if ($bbox_bottom==='auto') {
  12463. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb;
  12464. }
  12465. else if ($bbox_top==='auto') {
  12466. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12467. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  12468. if ($bbox_top < 0) {
  12469. $bbox_top = 0;
  12470. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  12471. }
  12472. }
  12473. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12474. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  12475. $y = $inner_y;
  12476. }
  12477. $h = $inner_h;
  12478. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  12479. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  12480. }
  12481. $inner_w = $w;
  12482. $inner_h = $h;
  12483. }
  12484. $this->lMargin=$x;
  12485. $this->rMargin=$this->w - $w - $x;
  12486. // SET POSITION & FONT VALUES
  12487. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12488. $this->pageoutput[$this->page]=array();
  12489. $this->x = $x;
  12490. $this->y = $y;
  12491. $this->HTMLheaderPageLinks = array();
  12492. $this->HTMLheaderPageAnnots = array();
  12493. $this->HTMLheaderPageForms = array();
  12494. $this->pageBackgrounds = array();
  12495. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  12496. $actual_h = $this->y - $y;
  12497. $use_w = $w;
  12498. $use_h = $h;
  12499. $ratio = $actual_h / $use_w;
  12500. if ($overflow!='hidden' && $overflow!='visible') {
  12501. $target = $h/$w;
  12502. if (($ratio / $target ) > 1) {
  12503. $nl = CEIL($actual_h / $this->lineheight);
  12504. $l = $use_w * $nl;
  12505. $est_w = sqrt(($l * $this->lineheight) / $target) * 0.8;
  12506. $use_w += ($est_w - $use_w) - ($w/100);
  12507. }
  12508. $bpcstart = ($ratio / $target);
  12509. $bpcctr = 1;
  12510. while(($ratio / $target ) > 1) {
  12511. if ($this->progressBar) { $this->UpdateProgressBar(4,intval(100/($ratio/$target)),('Auto-sizing fixed-position block: '.$bpcctr++)); } // *PROGRESS-BAR*
  12512. $this->x = $x;
  12513. $this->y = $y;
  12514. if (($ratio / $target) > 1.5 || ($ratio / $target) < 0.6) {
  12515. $use_w += ($w/$this->incrementFPR1);
  12516. }
  12517. else if (($ratio / $target) > 1.2 || ($ratio / $target) < 0.85) {
  12518. $use_w += ($w/$this->incrementFPR2);
  12519. }
  12520. else if (($ratio / $target) > 1.1 || ($ratio / $target) < 0.91) {
  12521. $use_w += ($w/$this->incrementFPR3);
  12522. }
  12523. else {
  12524. $use_w += ($w/$this->incrementFPR4);
  12525. }
  12526. $use_h = $use_w * $target ;
  12527. $this->rMargin=$this->w - $use_w - $x;
  12528. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12529. $this->HTMLheaderPageLinks = array();
  12530. $this->HTMLheaderPageAnnots = array();
  12531. $this->HTMLheaderPageForms = array();
  12532. $this->pageBackgrounds = array();
  12533. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  12534. $actual_h = $this->y - $y;
  12535. $ratio = $actual_h / $use_w;
  12536. }
  12537. if ($this->progressBar) { $this->UpdateProgressBar(4,'100',' '); } // *PROGRESS-BAR*
  12538. }
  12539. $shrink_f = $w/$use_w;
  12540. //================================================================
  12541. $this->pages[$this->page] .= '___BEFORE_BORDERS___';
  12542. $block_s = $this->PrintPageBackgrounds(); // Save to print later inside clipping path
  12543. $this->pageBackgrounds = array();
  12544. //================================================================
  12545. if ($rotate) {
  12546. $prerotw = $bbox_bl + $bbox_pl + $inner_w + $bbox_pr + $bbox_br;
  12547. $preroth = $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb;
  12548. $rot_start = " q\n";
  12549. if ($rotate == 90) {
  12550. if ($rot_rpos !== false) { $adjw = $prerotw; } // width before rotation
  12551. else { $adjw = $preroth; } // height before rotation
  12552. if ($rot_bpos !== false) { $adjh = -$prerotw + $preroth; }
  12553. else { $adjh = 0; }
  12554. }
  12555. else {
  12556. if ($rot_rpos !== false) { $adjw = $prerotw - $preroth; }
  12557. else { $adjw = 0; }
  12558. if ($rot_bpos !== false) { $adjh = $preroth; } // height before rotation
  12559. else { $adjh = $prerotw; } // width before rotation
  12560. }
  12561. $rot_start .= $this->transformTranslate($adjw, $adjh, true)."\n";
  12562. $rot_start .= $this->transformRotate($rotate, $bbox_x, $bbox_y, true)."\n";
  12563. $rot_end = " Q\n";
  12564. }
  12565. else {
  12566. $rot_start = '';
  12567. $rot_end = '';
  12568. }
  12569. //================================================================
  12570. if (!empty($bounding)) {
  12571. // WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the bottom
  12572. // Re-instate saved $this->blk[1]
  12573. $this->blk[1] = $saved_block1;
  12574. // These are only needed when painting border/background
  12575. $this->blk[1]['width'] = $bbox_w = $cont_w - $bbox_left - $bbox_ml - $bbox_mr - $bbox_right;
  12576. $this->blk[1]['x0'] = $bbox_x;
  12577. $this->blk[1]['y0'] = $bbox_y;
  12578. $this->blk[1]['startpage'] = $this->page;
  12579. $this->blk[1]['y1'] = $bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ;
  12580. $this->_out($rot_start); // mPDF 5.0
  12581. $this->PaintDivBB('',0,1); // Prints borders and sets backgrounds in $this->pageBackgrounds
  12582. $this->_out($rot_end);
  12583. }
  12584. $s = $this->PrintPageBackgrounds();
  12585. $s = $rot_start.$s.$rot_end;
  12586. $this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n".$s."\n", $this->pages[$this->page]);
  12587. $this->pageBackgrounds = array();
  12588. $this->_out($rot_start);
  12589. // Clipping Output
  12590. if ($overflow=='hidden') {
  12591. //Bounding rectangle to clip
  12592. $clip_y1 = $this->y;
  12593. if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) > ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) {
  12594. $clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb);
  12595. }
  12596. //$op = 'W* n'; // Clipping
  12597. $op = 'W n'; // Clipping alternative mode
  12598. $this->_out("q");
  12599. $ch = $clip_y1 - $y;
  12600. $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op));
  12601. if (!empty($block_s)) {
  12602. $tmp = "q\n".sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op);
  12603. $tmp .= "\n".$block_s."\nQ";
  12604. $block_s = $tmp ;
  12605. }
  12606. }
  12607. if (!empty($block_s)) {
  12608. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12609. $tmp = "q\n".$this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y, true);
  12610. $tmp .= "\n".$block_s."\nQ";
  12611. $block_s = $tmp ;
  12612. }
  12613. $this->_out($block_s);
  12614. }
  12615. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12616. $this->StartTransform();
  12617. $this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y);
  12618. }
  12619. $this->_out($this->headerbuffer);
  12620. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12621. $this->StopTransform();
  12622. }
  12623. if ($overflow=='hidden') {
  12624. //End clipping
  12625. $this->_out("Q");
  12626. }
  12627. $this->_out($rot_end);
  12628. // Page Links
  12629. foreach($this->HTMLheaderPageLinks AS $lk) {
  12630. if ($rotate) {
  12631. $tmp = $lk[2]; // Switch h - w
  12632. $lk[2] = $lk[3];
  12633. $lk[3] = $tmp;
  12634. $lx1 = (($lk[0]/_MPDFK));
  12635. $ly1 = (($this->h-($lk[1]/_MPDFK)));
  12636. if ($rotate == 90) {
  12637. $adjx = -($lx1-$bbox_x) + ($preroth - ($ly1-$bbox_y));
  12638. $adjy = -($ly1-$bbox_y) + ($lx1-$bbox_x);
  12639. $lk[2] = -$lk[2];
  12640. }
  12641. else if ($rotate == -90) {
  12642. $adjx = -($lx1-$bbox_x) + ($ly1-$bbox_y);
  12643. $adjy = -($ly1-$bbox_y) - ($lx1-$bbox_x) + $prerotw;
  12644. $lk[3] = -$lk[3];
  12645. }
  12646. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12647. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12648. $lx1 += $adjx;
  12649. $ly1 += $adjy;
  12650. $lk[0] = $lx1*_MPDFK;
  12651. $lk[1] = ($this->h-$ly1)*_MPDFK;
  12652. }
  12653. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12654. $lx1 = (($lk[0]/_MPDFK)-$x);
  12655. $lx2 = $x + ($lx1 * $shrink_f);
  12656. $lk[0] = $lx2*_MPDFK;
  12657. $ly1 = (($this->h-($lk[1]/_MPDFK))-$y);
  12658. $ly2 = $y + ($ly1 * $shrink_f);
  12659. $lk[1] = ($this->h-$ly2)*_MPDFK;
  12660. $lk[2] *= $shrink_f; // width
  12661. $lk[3] *= $shrink_f; // height
  12662. }
  12663. $this->PageLinks[$this->page][]=$lk;
  12664. }
  12665. foreach($this->HTMLheaderPageForms AS $n=>$f) {
  12666. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12667. $f['x'] = $x + (($f['x'] -$x) * $shrink_f);
  12668. $f['y'] = $y + (($f['y'] -$y) * $shrink_f);
  12669. $f['w'] *= $shrink_f;
  12670. $f['h'] *= $shrink_f;
  12671. $f['style']['fontsize'] *= $shrink_f;
  12672. }
  12673. $this->form->forms[$f['n']] = $f;
  12674. }
  12675. // Page Annotations
  12676. foreach($this->HTMLheaderPageAnnots AS $lk) {
  12677. if ($rotate) {
  12678. if ($rotate == 90) {
  12679. $adjx = -($lk['x']-$bbox_x) + ($preroth - ($lk['y']-$bbox_y));
  12680. $adjy = -($lk['y']-$bbox_y) + ($lk['x']-$bbox_x);
  12681. }
  12682. else if ($rotate == -90) {
  12683. $adjx = -($lk['x']-$bbox_x) + ($lk['y']-$bbox_y);
  12684. $adjy = -($lk['y']-$bbox_y) - ($lk['x']-$bbox_x) + $prerotw;
  12685. }
  12686. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12687. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12688. $lk['x'] += $adjx;
  12689. $lk['y'] += $adjy;
  12690. }
  12691. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12692. $lk['x'] = $x + (($lk['x']-$x) * $shrink_f);
  12693. $lk['y'] = $y + (($lk['y']-$y) * $shrink_f);
  12694. }
  12695. $this->PageAnnots[$this->page][]=$lk;
  12696. }
  12697. // Restore
  12698. $this->headerbuffer = '';
  12699. $this->HTMLheaderPageLinks = array();
  12700. $this->HTMLheaderPageAnnots = array();
  12701. $this->HTMLheaderPageForms = array();
  12702. $this->pageBackgrounds = $save_bgs;
  12703. $this->writingHTMLheader = false;
  12704. $this->writingHTMLfooter = false;
  12705. $this->fullImageHeight = false;
  12706. $this->ResetMargins();
  12707. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12708. $this->SetXY($save_x,$save_y) ;
  12709. $this->title2annots = $save_annots; // *ANNOTATIONS*
  12710. $this->InFooter = false; // turns back on autopagebreaks
  12711. $this->pageoutput[$this->page]=array();
  12712. $this->pageoutput[$this->page]['Font']='';
  12713. /*-- COLUMNS --*/
  12714. if ($save_cols) {
  12715. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  12716. }
  12717. /*-- END COLUMNS --*/
  12718. }
  12719. /*-- END CSS-POSITION --*/
  12720. function initialiseBlock(&$blk) {
  12721. $blk['margin_top'] = 0;
  12722. $blk['margin_left'] = 0;
  12723. $blk['margin_bottom'] = 0;
  12724. $blk['margin_right'] = 0;
  12725. $blk['padding_top'] = 0;
  12726. $blk['padding_left'] = 0;
  12727. $blk['padding_bottom'] = 0;
  12728. $blk['padding_right'] = 0;
  12729. $blk['border_top']['w'] = 0;
  12730. $blk['border_left']['w'] = 0;
  12731. $blk['border_bottom']['w'] = 0;
  12732. $blk['border_right']['w'] = 0;
  12733. $blk['hide'] = false;
  12734. $blk['outer_left_margin'] = 0;
  12735. $blk['outer_right_margin'] = 0;
  12736. $blk['cascadeCSS'] = array();
  12737. $blk['block-align'] = false;
  12738. $blk['bgcolor'] = false;
  12739. $blk['page_break_after_avoid'] = false;
  12740. $blk['keep_block_together'] = false;
  12741. $blk['float'] = false;
  12742. $blk['line_height'] = '';
  12743. $blk['margin_collapse'] = false;
  12744. }
  12745. function border_details($bd) {
  12746. $prop = preg_split('/\s+/',trim($bd));
  12747. if (isset($this->blk[$this->blklvl]['inner_width'])) { $refw = $this->blk[$this->blklvl]['inner_width']; }
  12748. else if (isset($this->blk[$this->blklvl-1]['inner_width'])) { $refw = $this->blk[$this->blklvl-1]['inner_width']; }
  12749. else { $refw = $this->w; }
  12750. if ( count($prop) == 1 ) {
  12751. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  12752. if ($bsize > 0) {
  12753. return array('s' => 1, 'w' => $bsize, 'c' => $this->ConvertColor(0), 'style'=>'solid');
  12754. }
  12755. else { return array('w' => 0, 's' => 0); }
  12756. }
  12757. else if (count($prop) == 2 ) {
  12758. // 1px solid
  12759. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $prop[2] = ''; }
  12760. // solid #000000
  12761. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $prop[0] = ''; $prop[1] = $prop[0]; $prop[2] = $prop[1]; }
  12762. // 1px #000000
  12763. else { $prop[1] = ''; $prop[2] = $prop[1]; }
  12764. }
  12765. else if ( count($prop) == 3 ) {
  12766. // Change #000000 1px solid to 1px solid #000000 (proper)
  12767. if (substr($prop[0],0,1) == '#') { $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $prop[2]; $prop[2] = $tmp; }
  12768. // Change solid #000000 1px to 1px solid #000000 (proper)
  12769. else if (substr($prop[0],1,1) == '#') { $tmp = $prop[1]; $prop[0] = $prop[2]; $prop[1] = $prop[0]; $prop[2] = $tmp; }
  12770. // Change solid 1px #000000 to 1px solid #000000 (proper)
  12771. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  12772. $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $tmp;
  12773. }
  12774. }
  12775. else { return array(); }
  12776. // Size
  12777. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  12778. //color
  12779. $coul = $this->ConvertColor($prop[2]); // returns array
  12780. // Style
  12781. $prop[1] = strtolower($prop[1]);
  12782. if (in_array($prop[1],$this->borderstyles) && $bsize > 0) { $on = 1; }
  12783. else if ($prop[1] == 'hidden') { $on = 1; $bsize = 0; $coul = ''; }
  12784. else if ($prop[1] == 'none') { $on = 0; $bsize = 0; $coul = ''; }
  12785. else { $on = 0; $bsize = 0; $coul = ''; $prop[1] = ''; }
  12786. return array('s' => $on, 'w' => $bsize, 'c' => $coul, 'style'=> $prop[1] );
  12787. }
  12788. /*-- END HTML-CSS --*/
  12789. // Return either a number (factor) - based on current set fontsize (if % or em) - or exact lineheight (with 'mm' after it)
  12790. function fixLineheight($v) {
  12791. $lh = false;
  12792. if (preg_match('/^[0-9\.,]*$/',$v) && $v >= 0) { return ($v + 0); }
  12793. else if (strtoupper($v) == 'NORMAL') {
  12794. return $this->normalLineheight;
  12795. }
  12796. else {
  12797. $tlh = $this->ConvertSize($v,$this->FontSize,$this->FontSize,true);
  12798. if ($tlh) { return ($tlh.'mm'); }
  12799. }
  12800. return $this->normalLineheight;
  12801. }
  12802. /*-- BORDER-RADIUS --*/
  12803. function _borderPadding($a, $b, &$px, &$py) {
  12804. // $px and py are padding long axis (x) and short axis (y)
  12805. $added = 0; // extra padding
  12806. $x = $a-$px;
  12807. $y = $b-$py;
  12808. // Check if Falls within ellipse of border radius
  12809. if ( ( (($x+$added)*($x+$added))/($a*$a) + (($y+$added)*($y+$added))/($b*$b) ) <=1 ) { return false; }
  12810. $t = atan2($y,$x);
  12811. $newx = $b / sqrt((($b*$b)/($a*$a)) + ( tan($t) * tan($t) ) );
  12812. $newy = $a / sqrt((($a*$a)/($b*$b)) + ( (1/tan($t)) * (1/tan($t)) ) );
  12813. $px = max($px, $a - $newx + $added);
  12814. $py = max($py, $b - $newy + $added);
  12815. }
  12816. /*-- END BORDER-RADIUS --*/
  12817. /*-- HTML-CSS --*/
  12818. /*-- CSS-PAGE --*/
  12819. function SetPagedMediaCSS($name='', $first, $oddEven) {
  12820. if ($oddEven == 'E') {
  12821. if ($this->directionality=='rtl') { $side = 'R'; }
  12822. else { $side = 'L'; }
  12823. }
  12824. else {
  12825. if ($this->directionality=='rtl') { $side = 'L'; }
  12826. else { $side = 'R'; }
  12827. }
  12828. $name = strtoupper($name);
  12829. $p = array();
  12830. $p['SIZE'] = 'AUTO';
  12831. // Uses mPDF original margins as default
  12832. $p['MARGIN-RIGHT'] = strval($this->orig_rMargin).'mm';
  12833. $p['MARGIN-LEFT'] = strval($this->orig_lMargin).'mm';
  12834. $p['MARGIN-TOP'] = strval($this->orig_tMargin).'mm';
  12835. $p['MARGIN-BOTTOM'] = strval($this->orig_bMargin).'mm';
  12836. $p['MARGIN-HEADER'] = strval($this->orig_hMargin).'mm';
  12837. $p['MARGIN-FOOTER'] = strval($this->orig_fMargin).'mm';
  12838. // Basic page + selector
  12839. if (isset($this->cssmgr->CSS['@PAGE'])) { $zp = $this->cssmgr->CSS['@PAGE']; }
  12840. else { $zp = array(); }
  12841. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12842. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  12843. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  12844. }
  12845. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  12846. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  12847. }
  12848. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  12849. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  12850. }
  12851. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  12852. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  12853. }
  12854. // If right/Odd page
  12855. if (isset($this->cssmgr->CSS['@PAGE>>PSEUDO>>RIGHT']) && $side=='R') {
  12856. $zp = $this->cssmgr->CSS['@PAGE>>PSEUDO>>RIGHT'];
  12857. }
  12858. else { $zp = array(); }
  12859. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  12860. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  12861. // Disallow margin-left or -right on :LEFT or :RIGHT
  12862. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  12863. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  12864. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12865. // If left/Even page
  12866. if (isset($this->cssmgr->CSS['@PAGE>>PSEUDO>>LEFT']) && $side=='L') {
  12867. $zp = $this->cssmgr->CSS['@PAGE>>PSEUDO>>LEFT'];
  12868. }
  12869. else { $zp = array(); }
  12870. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  12871. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  12872. // Disallow margin-left or -right on :LEFT or :RIGHT
  12873. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  12874. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  12875. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12876. // If first page
  12877. if (isset($this->cssmgr->CSS['@PAGE>>PSEUDO>>FIRST']) && $first) { $zp = $this->cssmgr->CSS['@PAGE>>PSEUDO>>FIRST']; }
  12878. else { $zp = array(); }
  12879. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  12880. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  12881. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12882. // If named page
  12883. if ($name) {
  12884. if (isset($this->cssmgr->CSS['@PAGE>>NAMED>>'.$name])) { $zp = $this->cssmgr->CSS['@PAGE>>NAMED>>'.$name]; }
  12885. else { $zp = array(); }
  12886. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12887. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  12888. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  12889. }
  12890. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  12891. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  12892. }
  12893. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  12894. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  12895. }
  12896. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  12897. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  12898. }
  12899. // If named right/Odd page
  12900. if (isset($this->cssmgr->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']) && $side=='R') { $zp = $this->cssmgr->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']; }
  12901. else { $zp = array(); }
  12902. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  12903. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  12904. // Disallow margin-left or -right on :LEFT or :RIGHT
  12905. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  12906. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  12907. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12908. // If named left/Even page
  12909. if (isset($this->cssmgr->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']) && $side=='L') { $zp = $this->cssmgr->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']; }
  12910. else { $zp = array(); }
  12911. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  12912. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  12913. // Disallow margin-left or -right on :LEFT or :RIGHT
  12914. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  12915. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  12916. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12917. // If named first page
  12918. if (isset($this->cssmgr->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']) && $first) { $zp = $this->cssmgr->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']; }
  12919. else { $zp = array(); }
  12920. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  12921. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  12922. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12923. }
  12924. $orientation = $mgl = $mgr = $mgt = $mgb = $mgh = $mgf = '';
  12925. $header = $footer = '';
  12926. $resetpagenum = $pagenumstyle = $suppress = '';
  12927. $marks = '';
  12928. $bg = array();
  12929. $newformat = '';
  12930. if (isset($p['SHEET-SIZE']) && is_array($p['SHEET-SIZE'])) {
  12931. $newformat = $p['SHEET-SIZE'];
  12932. if ($newformat[0] > $newformat[1]) { // landscape
  12933. $newformat = array_reverse($newformat);
  12934. $p['ORIENTATION'] = 'L';
  12935. }
  12936. else { $p['ORIENTATION'] = 'P'; }
  12937. $this->_setPageSize($newformat, $p['ORIENTATION']);
  12938. }
  12939. if (isset($p['SIZE']) && is_array($p['SIZE']) && !$newformat) {
  12940. if ($p['SIZE']['W'] > $p['SIZE']['H']) { $p['ORIENTATION'] = 'L'; }
  12941. else { $p['ORIENTATION'] = 'P'; }
  12942. }
  12943. if (is_array($p['SIZE'])) {
  12944. if ($p['SIZE']['W'] > $this->fw) { $p['SIZE']['W'] = $this->fw; } // mPD 4.2 use fw not fPt
  12945. if ($p['SIZE']['H'] > $this->fh) { $p['SIZE']['H'] = $this->fh; }
  12946. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  12947. $outer_width_LR = ($this->fw - $p['SIZE']['W'])/2;
  12948. $outer_width_TB = ($this->fh - $p['SIZE']['H'])/2;
  12949. }
  12950. else {
  12951. $outer_width_LR = ($this->fh - $p['SIZE']['W'])/2;
  12952. $outer_width_TB = ($this->fw - $p['SIZE']['H'])/2;
  12953. }
  12954. $pgw = $p['SIZE']['W'];
  12955. $pgh = $p['SIZE']['H'];
  12956. }
  12957. else { // AUTO LANDSCAPE PORTRAIT
  12958. $outer_width_LR = 0;
  12959. $outer_width_TB = 0;
  12960. if (!$newformat) {
  12961. if (strtoupper($p['SIZE']) == 'AUTO') { $p['ORIENTATION']=$this->DefOrientation; }
  12962. else if (strtoupper($p['SIZE']) == 'LANDSCAPE') { $p['ORIENTATION']='L'; }
  12963. else { $p['ORIENTATION']='P'; }
  12964. }
  12965. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  12966. $pgw = $this->fw;
  12967. $pgh = $this->fh;
  12968. }
  12969. else {
  12970. $pgw = $this->fh;
  12971. $pgh = $this->fw;
  12972. }
  12973. }
  12974. if (isset($p['HEADER']) && $p['HEADER']) { $header = $p['HEADER']; }
  12975. if (isset($p['FOOTER']) && $p['FOOTER']) { $footer = $p['FOOTER']; }
  12976. if (isset($p['RESETPAGENUM']) && $p['RESETPAGENUM']) { $resetpagenum = $p['RESETPAGENUM']; }
  12977. if (isset($p['PAGENUMSTYLE']) && $p['PAGENUMSTYLE']) { $pagenumstyle = $p['PAGENUMSTYLE']; }
  12978. if (isset($p['SUPPRESS']) && $p['SUPPRESS']) { $suppress = $p['SUPPRESS']; }
  12979. if (preg_match('/cross/i', $p['MARKS']) && preg_match('/crop/i', $p['MARKS'])) { $marks = 'CROPCROSS'; }
  12980. else if (strtoupper($p['MARKS']) == 'CROP') { $marks = 'CROP'; }
  12981. else if (strtoupper($p['MARKS']) == 'CROSS') { $marks = 'CROSS'; }
  12982. if (isset($p['BACKGROUND-COLOR']) && $p['BACKGROUND-COLOR']) { $bg['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  12983. /*-- BACKGROUNDS --*/
  12984. if (isset($p['BACKGROUND-GRADIENT']) && $p['BACKGROUND-GRADIENT']) { $bg['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  12985. if (isset($p['BACKGROUND-IMAGE']) && $p['BACKGROUND-IMAGE']) { $bg['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  12986. if (isset($p['BACKGROUND-REPEAT']) && $p['BACKGROUND-REPEAT']) { $bg['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  12987. if (isset($p['BACKGROUND-POSITION']) && $p['BACKGROUND-POSITION']) { $bg['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  12988. if (isset($p['BACKGROUND-IMAGE-RESIZE']) && $p['BACKGROUND-IMAGE-RESIZE']) { $bg['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  12989. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $bg['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; }
  12990. /*-- END BACKGROUNDS --*/
  12991. if (isset($p['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($p['MARGIN-LEFT'],$pgw) + $outer_width_LR; }
  12992. if (isset($p['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($p['MARGIN-RIGHT'],$pgw) + $outer_width_LR; }
  12993. if (isset($p['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($p['MARGIN-BOTTOM'],$pgh) + $outer_width_TB; }
  12994. if (isset($p['MARGIN-TOP'])) { $mgt = $this->ConvertSize($p['MARGIN-TOP'],$pgh) + $outer_width_TB; }
  12995. if (isset($p['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($p['MARGIN-HEADER'],$pgh) + $outer_width_TB; }
  12996. if (isset($p['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($p['MARGIN-FOOTER'],$pgh) + $outer_width_TB; }
  12997. if (isset($p['ORIENTATION']) && $p['ORIENTATION']) { $orientation = $p['ORIENTATION']; }
  12998. $this->page_box['outer_width_LR'] = $outer_width_LR; // Used in MARKS:crop etc.
  12999. $this->page_box['outer_width_TB'] = $outer_width_TB;
  13000. return array($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$header,$footer,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat);
  13001. }
  13002. /*-- END CSS-PAGE --*/
  13003. /*-- CSS-FLOAT --*/
  13004. // Added mPDF 3.0 Float DIV - CLEAR
  13005. function ClearFloats($clear, $blklvl=0) {
  13006. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($blklvl,true);
  13007. $end = $currpos = ($this->page*1000 + $this->y);
  13008. if ($clear == 'BOTH' && ($l_exists || $r_exists)) {
  13009. $this->pageoutput[$this->page] = array();
  13010. $end = max($l_max, $r_max, $currpos);
  13011. }
  13012. else if ($clear == 'RIGHT' && $r_exists) {
  13013. $this->pageoutput[$this->page] = array();
  13014. $end = max($r_max, $currpos);
  13015. }
  13016. else if ($clear == 'LEFT' && $l_exists ) {
  13017. $this->pageoutput[$this->page] = array();
  13018. $end = max($l_max, $currpos);
  13019. }
  13020. else { return; }
  13021. $old_page = $this->page;
  13022. $new_page = intval($end/1000);
  13023. if ($old_page != $new_page) {
  13024. $s = $this->PrintPageBackgrounds();
  13025. // Writes after the marker so not overwritten later by page background etc.
  13026. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  13027. $this->pageBackgrounds = array();
  13028. $this->page = $new_page;
  13029. }
  13030. $this->ResetMargins();
  13031. $this->pageoutput[$this->page] = array();
  13032. $this->y = (($end*1000) % 1000000)/1000; // mod changes operands to integers before processing
  13033. }
  13034. // Added mPDF 3.0 Float DIV
  13035. function GetFloatDivInfo($blklvl=0,$clear=false) {
  13036. // If blklvl specified, only returns floats at that level - for ClearFloats
  13037. $l_exists = false;
  13038. $r_exists = false;
  13039. $l_max = 0;
  13040. $r_max = 0;
  13041. $l_width = 0;
  13042. $r_width = 0;
  13043. if (count($this->floatDivs)) {
  13044. $currpos = ($this->page*1000 + $this->y);
  13045. foreach($this->floatDivs AS $f) {
  13046. 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'])) {
  13047. if ($f['side']=='L') {
  13048. $l_exists= true;
  13049. $l_max = max($l_max, $f['endpos']);
  13050. $l_width = max($l_width , $f['w']);
  13051. }
  13052. if ($f['side']=='R') {
  13053. $r_exists= true;
  13054. $r_max = max($r_max, $f['endpos']);
  13055. $r_width = max($r_width , $f['w']);
  13056. }
  13057. }
  13058. }
  13059. }
  13060. return array($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width);
  13061. }
  13062. /*-- END CSS-FLOAT --*/
  13063. function OpenTag($tag,$attr)
  13064. {
  13065. // What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here>
  13066. // Correct tags where HTML specifies optional end tags,
  13067. // and/or does not allow nesting e.g. P inside P, or
  13068. if ($this->allow_html_optional_endtags) {
  13069. 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 ); }
  13070. if ($tag == 'DD' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13071. if ($tag == 'DD' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13072. if ($tag == 'DT' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13073. if ($tag == 'DT' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13074. if ($tag == 'LI' && $this->lastoptionaltag == 'LI') { $this->CloseTag($this->lastoptionaltag ); }
  13075. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13076. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13077. if ($tag == 'TR' && $this->lastoptionaltag == 'TR') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13078. if ($tag == 'TR' && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13079. if ($tag == 'TR' && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13080. if ($tag == 'OPTION' && $this->lastoptionaltag == 'OPTION') { $this->CloseTag($this->lastoptionaltag ); }
  13081. }
  13082. $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','text-top'=>'TT','middle'=>'M','baseline'=>'BS','bottom'=>'B','text-bottom'=>'TB','justify'=>'J');
  13083. $this->ignorefollowingspaces=false;
  13084. //Opening tag
  13085. switch($tag){
  13086. case 'DOTTAB':
  13087. $objattr = array();
  13088. $objattr['type'] = 'dottab';
  13089. $dots=str_repeat('.', 3)." "; // minimum number of dots
  13090. $objattr['width'] = $this->GetStringWidth($dots);
  13091. $objattr['margin_top'] = 0;
  13092. $objattr['margin_bottom'] = 0;
  13093. $objattr['margin_left'] = 0;
  13094. $objattr['margin_right'] = 0;
  13095. $objattr['height'] = 0;
  13096. $objattr['colorarray'] = $this->colorarray;
  13097. $objattr['border_top']['w'] = 0;
  13098. $objattr['border_bottom']['w'] = 0;
  13099. $objattr['border_left']['w'] = 0;
  13100. $objattr['border_right']['w'] = 0;
  13101. // mPDF 5.6.19
  13102. $properties = $this->cssmgr->MergeCSS('INLINE',$tag,$attr); // mPDF 5.6.33
  13103. if (isset($properties['OUTDENT'])) { // mPDF 5.6.33
  13104. $objattr['outdent'] = $this->ConvertSize($properties['OUTDENT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  13105. }
  13106. else if (isset($attr['OUTDENT'])) {
  13107. $objattr['outdent'] = $this->ConvertSize($attr['OUTDENT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  13108. }
  13109. else { $objattr['outdent'] = 0; }
  13110. $objattr['fontfamily'] = $this->FontFamily;
  13111. $objattr['fontsize'] = $this->FontSizePt;
  13112. $e = "\xbb\xa4\xactype=dottab,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13113. /*-- TABLES --*/
  13114. // Output it to buffers
  13115. if ($this->tableLevel) {
  13116. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  13117. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13118. }
  13119. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  13120. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13121. }
  13122. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  13123. $this->_saveCellTextBuffer($e);
  13124. }
  13125. else {
  13126. /*-- END TABLES --*/
  13127. $this->_saveTextBuffer($e);
  13128. } // *TABLES*
  13129. break;
  13130. case 'PAGEHEADER':
  13131. case 'PAGEFOOTER':
  13132. $this->ignorefollowingspaces = true;
  13133. if ($attr['NAME']) { $pname = $attr['NAME']; }
  13134. else { $pname = '_default'; }
  13135. if ($tag=='PAGEHEADER') { $p = &$this->pageheaders[$pname]; }
  13136. else { $p = &$this->pagefooters[$pname]; }
  13137. $p['L']=array();
  13138. $p['C']=array();
  13139. $p['R']=array();
  13140. $p['L']['font-style'] = '';
  13141. $p['C']['font-style'] = '';
  13142. $p['R']['font-style'] = '';
  13143. if (isset($attr['CONTENT-LEFT'])) {
  13144. $p['L']['content'] = $attr['CONTENT-LEFT'];
  13145. }
  13146. if (isset($attr['CONTENT-CENTER'])) {
  13147. $p['C']['content'] = $attr['CONTENT-CENTER'];
  13148. }
  13149. if (isset($attr['CONTENT-RIGHT'])) {
  13150. $p['R']['content'] = $attr['CONTENT-RIGHT'];
  13151. }
  13152. if (isset($attr['HEADER-STYLE']) || isset($attr['FOOTER-STYLE'])) { // font-family,size,weight,style,color
  13153. if ($tag=='PAGEHEADER') { $properties = $this->cssmgr->readInlineCSS($attr['HEADER-STYLE']); }
  13154. else { $properties = $this->cssmgr->readInlineCSS($attr['FOOTER-STYLE']); }
  13155. if (isset($properties['FONT-FAMILY'])) {
  13156. $p['L']['font-family'] = $properties['FONT-FAMILY'];
  13157. $p['C']['font-family'] = $properties['FONT-FAMILY'];
  13158. $p['R']['font-family'] = $properties['FONT-FAMILY'];
  13159. }
  13160. if (isset($properties['FONT-SIZE'])) {
  13161. $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13162. $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13163. $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13164. }
  13165. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') {
  13166. $p['L']['font-style'] = 'B';
  13167. $p['C']['font-style'] = 'B';
  13168. $p['R']['font-style'] = 'B';
  13169. }
  13170. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') {
  13171. $p['L']['font-style'] .= 'I';
  13172. $p['C']['font-style'] .= 'I';
  13173. $p['R']['font-style'] .= 'I';
  13174. }
  13175. if (isset($properties['COLOR'])) {
  13176. $p['L']['color'] = $properties['COLOR'];
  13177. $p['C']['color'] = $properties['COLOR'];
  13178. $p['R']['color'] = $properties['COLOR'];
  13179. }
  13180. }
  13181. if (isset($attr['HEADER-STYLE-LEFT']) || isset($attr['FOOTER-STYLE-LEFT'])) {
  13182. if ($tag=='PAGEHEADER') { $properties = $this->cssmgr->readInlineCSS($attr['HEADER-STYLE-LEFT']); }
  13183. else { $properties = $this->cssmgr->readInlineCSS($attr['FOOTER-STYLE-LEFT']); }
  13184. if (isset($properties['FONT-FAMILY'])) { $p['L']['font-family'] = $properties['FONT-FAMILY']; }
  13185. if (isset($properties['FONT-SIZE'])) { $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13186. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['L']['font-style'] ='B'; }
  13187. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['L']['font-style'] .='I'; }
  13188. if (isset($properties['COLOR'])) { $p['L']['color'] = $properties['COLOR']; }
  13189. }
  13190. if (isset($attr['HEADER-STYLE-CENTER']) || isset($attr['FOOTER-STYLE-CENTER'])) {
  13191. if ($tag=='PAGEHEADER') { $properties = $this->cssmgr->readInlineCSS($attr['HEADER-STYLE-CENTER']); }
  13192. else { $properties = $this->cssmgr->readInlineCSS($attr['FOOTER-STYLE-CENTER']); }
  13193. if (isset($properties['FONT-FAMILY'])) { $p['C']['font-family'] = $properties['FONT-FAMILY']; }
  13194. if (isset($properties['FONT-SIZE'])) { $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13195. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['C']['font-style'] = 'B'; }
  13196. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['C']['font-style'] .= 'I'; }
  13197. if (isset($properties['COLOR'])) { $p['C']['color'] = $properties['COLOR']; }
  13198. }
  13199. if (isset($attr['HEADER-STYLE-RIGHT']) || isset($attr['FOOTER-STYLE-RIGHT'])) {
  13200. if ($tag=='PAGEHEADER') { $properties = $this->cssmgr->readInlineCSS($attr['HEADER-STYLE-RIGHT']); }
  13201. else { $properties = $this->cssmgr->readInlineCSS($attr['FOOTER-STYLE-RIGHT']); }
  13202. if (isset($properties['FONT-FAMILY'])) { $p['R']['font-family'] = $properties['FONT-FAMILY']; }
  13203. if (isset($properties['FONT-SIZE'])) { $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13204. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['R']['font-style'] = 'B'; }
  13205. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['R']['font-style'] .= 'I'; }
  13206. if (isset($properties['COLOR'])) { $p['R']['color'] = $properties['COLOR']; }
  13207. }
  13208. if (isset($attr['LINE']) && $attr['LINE']) { // 0|1|on|off
  13209. if ($attr['LINE']=='1' || strtoupper($attr['LINE'])=='ON') { $lineset=1; }
  13210. else { $lineset=0; }
  13211. $p['line'] = $lineset;
  13212. }
  13213. break;
  13214. /*-- HTMLHEADERS-FOOTERS --*/
  13215. case 'SETHTMLPAGEHEADER':
  13216. case 'SETHTMLPAGEFOOTER':
  13217. $this->ignorefollowingspaces = true;
  13218. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13219. else { $pname = '_default'; }
  13220. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13221. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13222. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13223. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13224. else { $side='odd'; }
  13225. }
  13226. else { $side='odd'; }
  13227. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13228. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13229. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13230. else { $set=1; }
  13231. }
  13232. else { $set=1; }
  13233. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETHTMLPAGEHEADER') { $write = 1; }
  13234. else { $write = 0; }
  13235. if ($side=='odd' || $side=='both') {
  13236. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'O',$write); }
  13237. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'O'); }
  13238. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','O'); }
  13239. else { $this->SetHTMLFooter('','O'); }
  13240. }
  13241. if ($side=='even' || $side=='both') {
  13242. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'E',$write); }
  13243. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'E'); }
  13244. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','E'); }
  13245. else { $this->SetHTMLFooter('','E'); }
  13246. }
  13247. break;
  13248. /*-- END HTMLHEADERS-FOOTERS --*/
  13249. case 'SETPAGEHEADER':
  13250. case 'SETPAGEFOOTER':
  13251. $this->ignorefollowingspaces = true;
  13252. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13253. else { $pname = '_default'; }
  13254. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13255. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13256. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13257. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13258. else { $side='odd'; }
  13259. }
  13260. else { $side='odd'; }
  13261. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13262. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13263. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13264. else { $set=1; }
  13265. }
  13266. else { $set=1; }
  13267. if ($side=='odd' || $side=='both') {
  13268. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = $this->pageheaders[$pname]; }
  13269. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['odd'] = $this->pagefooters[$pname]; }
  13270. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = array(); }
  13271. else { $this->footerDetails['odd'] = array(); }
  13272. if (!$this->mirrorMargins || ($this->page)%2!=0) { // ODD
  13273. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['odd'],$this->HTMLHeader); }
  13274. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['odd'],$this->HTMLFooter); }
  13275. }
  13276. }
  13277. if ($side=='even' || $side=='both') {
  13278. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['even'] = $this->pageheaders[$pname]; }
  13279. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['even'] = $this->pagefooters[$pname]; }
  13280. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['even'] = array(); }
  13281. else { $this->footerDetails['even'] = array(); }
  13282. if ($this->mirrorMargins && ($this->page)%2==0) { // EVEN
  13283. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['even'],$this->HTMLHeaderE); }
  13284. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['even'],$this->HTMLFooterE); }
  13285. }
  13286. }
  13287. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETPAGEHEADER') {
  13288. $this->Header();
  13289. }
  13290. break;
  13291. /*-- TOC --*/
  13292. case 'TOC': //added custom-tag - set Marker for insertion later of ToC
  13293. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  13294. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  13295. $this->tocontents->openTagTOC($attr);
  13296. break;
  13297. case 'TOCPAGEBREAK': // custom-tag - set Marker for insertion later of ToC AND adds PAGEBREAK
  13298. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  13299. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  13300. list($isbreak,$toc_id) = $this->tocontents->openTagTOCPAGEBREAK($attr);
  13301. if ($isbreak) break;
  13302. // No break - continues as PAGEBREAK...
  13303. /*-- END TOC --*/
  13304. case 'PAGE_BREAK': //custom-tag
  13305. case 'PAGEBREAK': //custom-tag
  13306. case 'NEWPAGE': //custom-tag
  13307. case 'FORMFEED': //custom-tag
  13308. $save_blklvl = $this->blklvl;
  13309. $save_blk = $this->blk;
  13310. $save_silp = $this->saveInlineProperties();
  13311. $save_spanlvl = $this->spanlvl;
  13312. $save_ilp = $this->InlineProperties;
  13313. // Close any open block tags
  13314. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  13315. if(!empty($this->textbuffer)) { //Output previously buffered content
  13316. $this->printbuffer($this->textbuffer);
  13317. $this->textbuffer=array();
  13318. }
  13319. $this->ignorefollowingspaces = true;
  13320. $save_cols = false;
  13321. /*-- COLUMNS --*/
  13322. if ($this->ColActive) {
  13323. $save_cols = true;
  13324. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  13325. $this->SetColumns(0);
  13326. }
  13327. /*-- END COLUMNS --*/
  13328. if (isset($attr['SHEET-SIZE']) && $tag != 'FORMFEED' && !$this->restoreBlockPageBreaks) {
  13329. // Convert to same types as accepted in initial mPDF() A4, A4-L, or array(w,h)
  13330. $prop = preg_split('/\s+/',trim($attr['SHEET-SIZE']));
  13331. if (count($prop) == 2 ) {
  13332. $newformat = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  13333. }
  13334. else { $newformat = $attr['SHEET-SIZE']; }
  13335. }
  13336. else { $newformat = ''; }
  13337. $mgr = $mgl = $mgt = $mgb = $mgh = $mgf = '';
  13338. if (isset($attr['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($attr['MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  13339. if (isset($attr['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($attr['MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  13340. if (isset($attr['MARGIN-TOP'])) { $mgt = $this->ConvertSize($attr['MARGIN-TOP'],$this->w,$this->FontSize,false); }
  13341. if (isset($attr['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($attr['MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  13342. if (isset($attr['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($attr['MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  13343. if (isset($attr['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($attr['MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  13344. $ohname = $ehname = $ofname = $efname = '';
  13345. if (isset($attr['ODD-HEADER-NAME'])) { $ohname = $attr['ODD-HEADER-NAME']; }
  13346. if (isset($attr['EVEN-HEADER-NAME'])) { $ehname = $attr['EVEN-HEADER-NAME']; }
  13347. if (isset($attr['ODD-FOOTER-NAME'])) { $ofname = $attr['ODD-FOOTER-NAME']; }
  13348. if (isset($attr['EVEN-FOOTER-NAME'])) { $efname = $attr['EVEN-FOOTER-NAME']; }
  13349. $ohvalue = $ehvalue = $ofvalue = $efvalue = 0;
  13350. if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='1' || strtoupper($attr['ODD-HEADER-VALUE'])=='ON')) { $ohvalue = 1; }
  13351. else if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='-1' || strtoupper($attr['ODD-HEADER-VALUE'])=='OFF')) { $ohvalue = -1; }
  13352. if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='ON')) { $ehvalue = 1; }
  13353. else if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='OFF')) { $ehvalue = -1; }
  13354. if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='ON')) { $ofvalue = 1; }
  13355. else if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='OFF')) { $ofvalue = -1; }
  13356. if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='ON')) { $efvalue = 1; }
  13357. else if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='OFF')) { $efvalue = -1; }
  13358. if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='L' || strtoupper($attr['ORIENTATION'])=='LANDSCAPE')) { $orient = 'L'; }
  13359. else if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='P' || strtoupper($attr['ORIENTATION'])=='PORTRAIT')) { $orient = 'P'; }
  13360. else { $orient = $this->CurOrientation; }
  13361. if (isset($attr['PAGE-SELECTOR']) && $attr['PAGE-SELECTOR']) { $pagesel = $attr['PAGE-SELECTOR']; }
  13362. else { $pagesel = ''; }
  13363. $resetpagenum = '';
  13364. $pagenumstyle = '';
  13365. $suppress = '';
  13366. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  13367. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  13368. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  13369. if ($tag == 'TOCPAGEBREAK') { $type = 'NEXT-ODD'; }
  13370. else if(isset($attr['TYPE'])) { $type = strtoupper($attr['TYPE']); }
  13371. else { $type = ''; }
  13372. 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); }
  13373. 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); }
  13374. 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); }
  13375. 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); }
  13376. else { $this->AddPage($orient,'', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13377. /*-- TOC --*/
  13378. if ($tag == 'TOCPAGEBREAK') {
  13379. if ($toc_id) { $this->tocontents->m_TOC[$toc_id]['TOCmark'] = $this->page; }
  13380. else { $this->tocontents->TOCmark = $this->page; }
  13381. }
  13382. /*-- END TOC --*/
  13383. /*-- COLUMNS --*/
  13384. if ($save_cols) {
  13385. // Restore columns
  13386. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  13387. }
  13388. /*-- END COLUMNS --*/
  13389. if (($tag == 'FORMFEED' || $this->restoreBlockPagebreaks) && !$this->tableLevel && !$this->listlvl) {
  13390. $this->blk = $save_blk;
  13391. // Re-open block tags
  13392. $t = $this->blk[0]['tag'];
  13393. $a = $this->blk[0]['attr'];
  13394. $this->blklvl = 0;
  13395. for ($b=0; $b<=$save_blklvl;$b++) {
  13396. $tc = $t;
  13397. $ac = $a;
  13398. $t = $this->blk[$b+1]['tag'];
  13399. $a = $this->blk[$b+1]['attr'];
  13400. unset($this->blk[$b+1]);
  13401. $this->OpenTag($tc,$ac);
  13402. }
  13403. $this->spanlvl = $save_spanlvl;
  13404. $this->InlineProperties = $save_ilp;
  13405. $this->restoreInlineProperties($save_silp);
  13406. }
  13407. break;
  13408. /*-- TOC --*/
  13409. case 'TOCENTRY':
  13410. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  13411. $objattr = array();
  13412. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13413. $objattr['type'] = 'toc';
  13414. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['toclevel'] = $attr['LEVEL']; } else { $objattr['toclevel'] = 0; }
  13415. if (isset($attr['NAME']) && $attr['NAME']) { $objattr['toc_id'] = $attr['NAME']; } else { $objattr['toc_id'] = 0; }
  13416. $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13417. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13418. else { // *TABLES*
  13419. $this->textbuffer[] = array($e);
  13420. } // *TABLES*
  13421. }
  13422. break;
  13423. /*-- END TOC --*/
  13424. /*-- INDEX --*/
  13425. case 'INDEXENTRY':
  13426. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  13427. if (isset($attr['XREF']) && $attr['XREF']) {
  13428. $this->IndexEntry(htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES),$attr['XREF']);
  13429. break;
  13430. }
  13431. $objattr = array();
  13432. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13433. $objattr['type'] = 'indexentry';
  13434. $e = "\xbb\xa4\xactype=indexentry,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13435. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13436. else { // *TABLES*
  13437. $this->textbuffer[] = array($e);
  13438. } // *TABLES*
  13439. }
  13440. break;
  13441. case 'INDEXINSERT':
  13442. if (isset($attr['FONT-SIZE'])) { $reffontsize = $attr['FONT-SIZE']; } else { $reffontsize = ''; }
  13443. if (isset($attr['LINE-SPACING']) && $attr['LINE-SPACING']) { $linespacing = $attr['LINE-SPACING']; } else { $linespacing = ''; }
  13444. if (isset($attr['DIV-FONT-SIZE']) && $attr['DIV-FONT-SIZE']) { $divlettfontsize = $attr['DIV-FONT-SIZE']; } else { $divlettfontsize = ''; }
  13445. if (isset($attr['FONT']) && $attr['FONT']) { $reffont = $attr['FONT']; } else { $reffont = ''; }
  13446. if (isset($attr['DIV-FONT']) && $attr['DIV-FONT']) { $divlettfont = $attr['DIV-FONT']; } else { $divlettfont = ''; }
  13447. if (isset($attr['COLS']) && $attr['COLS']) { $cols = $attr['COLS']; } else { $cols = 1; }
  13448. if (isset($attr['OFFSET']) && $attr['OFFSET']) { $offset = $attr['OFFSET']; } else { $offset = 3; }
  13449. if (isset($attr['GAP']) && $attr['GAP']) { $gap = $attr['GAP']; } else { $gap = 5; }
  13450. if (isset($attr['USEDIVLETTERS']) && (strtoupper($attr['USEDIVLETTERS'])=='OFF' || $attr['USEDIVLETTERS']==-1 || $attr['USEDIVLETTERS']==='0')) { $usedivletters = 0; }
  13451. else { $usedivletters = 1; }
  13452. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  13453. else { $links = false; }
  13454. $this->CreateIndex($cols, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont,$divlettfont, $links);
  13455. break;
  13456. /*-- END INDEX --*/
  13457. /*-- WATERMARK --*/
  13458. case 'WATERMARKTEXT':
  13459. if (isset($attr['CONTENT']) && $attr['CONTENT']) { $txt = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); } else { $txt = ''; }
  13460. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  13461. $this->SetWatermarkText($txt, $alpha);
  13462. break;
  13463. case 'WATERMARKIMAGE':
  13464. if (isset($attr['SRC'])) { $src = $attr['SRC']; } else { $src = ''; }
  13465. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  13466. if (isset($attr['SIZE']) && $attr['SIZE']) {
  13467. $size = $attr['SIZE'];
  13468. if (strpos($size,',')) { $size = explode(',',$size); }
  13469. }
  13470. else { $size = 'D'; }
  13471. if (isset($attr['POS']) && $attr['POS']) {
  13472. $pos = $attr['POS'];
  13473. if (strpos($pos,',')) { $pos = explode(',',$pos); }
  13474. }
  13475. else { $pos = 'P'; }
  13476. $this->SetWatermarkImage($src, $alpha, $size, $pos);
  13477. break;
  13478. /*-- END WATERMARK --*/
  13479. /*-- BOOKMARKS --*/
  13480. case 'BOOKMARK':
  13481. if (isset($attr['CONTENT'])) {
  13482. $objattr = array();
  13483. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13484. $objattr['type'] = 'bookmark';
  13485. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  13486. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13487. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13488. else { // *TABLES*
  13489. $this->textbuffer[] = array($e);
  13490. } // *TABLES*
  13491. }
  13492. break;
  13493. /*-- END BOOKMARKS --*/
  13494. /*-- ANNOTATIONS --*/
  13495. case 'ANNOTATION':
  13496. //if (isset($attr['CONTENT']) && !$this->writingHTMLheader && !$this->writingHTMLfooter) { // Stops annotations in FixedPos
  13497. if (isset($attr['CONTENT'])) {
  13498. $objattr = array();
  13499. $objattr['margin_top'] = 0;
  13500. $objattr['margin_bottom'] = 0;
  13501. $objattr['margin_left'] = 0;
  13502. $objattr['margin_right'] = 0;
  13503. $objattr['width'] = 0;
  13504. $objattr['height'] = 0;
  13505. $objattr['border_top']['w'] = 0;
  13506. $objattr['border_bottom']['w'] = 0;
  13507. $objattr['border_left']['w'] = 0;
  13508. $objattr['border_right']['w'] = 0;
  13509. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13510. $objattr['type'] = 'annot';
  13511. $objattr['POPUP'] = '';
  13512. }
  13513. else { break; }
  13514. if (isset($attr['POS-X'])) { $objattr['POS-X'] = $attr['POS-X']; } else { $objattr['POS-X'] = 0; }
  13515. if (isset($attr['POS-Y'])) { $objattr['POS-Y'] = $attr['POS-Y']; } else { $objattr['POS-Y'] = 0; }
  13516. if (isset($attr['ICON'])) { $objattr['ICON'] = $attr['ICON']; } else { $objattr['ICON'] = 'Note'; }
  13517. if (isset($attr['AUTHOR'])) { $objattr['AUTHOR'] = $attr['AUTHOR']; }
  13518. else if (isset($attr['TITLE'])) { $objattr['AUTHOR'] = $attr['TITLE']; } else { $objattr['AUTHOR'] = ''; }
  13519. if (isset($attr['FILE'])) { $objattr['FILE'] = $attr['FILE']; } else { $objattr['FILE'] = ''; }
  13520. if (isset($attr['SUBJECT'])) { $objattr['SUBJECT'] = $attr['SUBJECT']; } else { $objattr['SUBJECT'] = ''; }
  13521. if (isset($attr['OPACITY']) && $attr['OPACITY']>0 && $attr['OPACITY']<=1) { $objattr['OPACITY'] = $attr['OPACITY']; }
  13522. else if ($this->annotMargin) { $objattr['OPACITY'] = 1; }
  13523. else { $objattr['OPACITY'] = $this->annotOpacity; }
  13524. if (isset($attr['COLOR'])) {
  13525. $cor = $this->ConvertColor($attr['COLOR']);
  13526. if ($cor) { $objattr['COLOR'] = $cor; }
  13527. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); }
  13528. }
  13529. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); }
  13530. if (isset($attr['POPUP']) && !empty($attr['POPUP'])) {
  13531. $pop = preg_split('/\s+/',trim($attr['POPUP']));
  13532. if (count($pop)>1) { $objattr['POPUP'] = $pop; }
  13533. else { $objattr['POPUP'] = true; }
  13534. }
  13535. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13536. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13537. else { // *TABLES*
  13538. $this->textbuffer[] = array($e);
  13539. } // *TABLES*
  13540. break;
  13541. /*-- END ANNOTATIONS --*/
  13542. /*-- COLUMNS --*/
  13543. case 'COLUMNS': //added custom-tag
  13544. if (isset($attr['COLUMN-COUNT']) && ($attr['COLUMN-COUNT'] || $attr['COLUMN-COUNT']==='0')) {
  13545. // Close any open block tags
  13546. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  13547. if(!empty($this->textbuffer)) { //Output previously buffered content
  13548. $this->printbuffer($this->textbuffer);
  13549. $this->textbuffer=array();
  13550. }
  13551. if (isset($attr['VALIGN']) && $attr['VALIGN']) {
  13552. if ($attr['VALIGN'] == 'J') { $valign = 'J'; }
  13553. else { $valign = $align[$attr['VALIGN']]; }
  13554. }
  13555. else { $valign = ''; }
  13556. if (isset($attr['COLUMN-GAP']) && $attr['COLUMN-GAP']) { $this->SetColumns($attr['COLUMN-COUNT'],$valign,$attr['COLUMN-GAP']); }
  13557. else { $this->SetColumns($attr['COLUMN-COUNT'],$valign); }
  13558. }
  13559. $this->ignorefollowingspaces = true;
  13560. break;
  13561. case 'COLUMN_BREAK': //custom-tag
  13562. case 'COLUMNBREAK': //custom-tag
  13563. case 'NEWCOLUMN': //custom-tag
  13564. $this->ignorefollowingspaces = true;
  13565. $this->NewColumn();
  13566. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  13567. break;
  13568. /*-- END COLUMNS --*/
  13569. case 'BDO':
  13570. // $this->biDirectional = true;
  13571. break;
  13572. case 'TTZ':
  13573. $this->ttz = true;
  13574. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  13575. $this->setCSS(array('FONT-FAMILY'=>'czapfdingbats','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  13576. break;
  13577. case 'TTS':
  13578. $this->tts = true;
  13579. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  13580. $this->setCSS(array('FONT-FAMILY'=>'csymbol','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  13581. break;
  13582. case 'TTA':
  13583. $this->tta = true;
  13584. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  13585. if (in_array($this->FontFamily,$this->mono_fonts)) {
  13586. $this->setCSS(array('FONT-FAMILY'=>'ccourier'),'INLINE');
  13587. }
  13588. else if (in_array($this->FontFamily,$this->serif_fonts)) {
  13589. $this->setCSS(array('FONT-FAMILY'=>'ctimes'),'INLINE');
  13590. }
  13591. else {
  13592. $this->setCSS(array('FONT-FAMILY'=>'chelvetica'),'INLINE');
  13593. }
  13594. break;
  13595. // INLINE PHRASES OR STYLES
  13596. case 'SUB':
  13597. case 'SUP':
  13598. case 'ACRONYM':
  13599. case 'BIG':
  13600. case 'SMALL':
  13601. case 'INS':
  13602. case 'S':
  13603. case 'STRIKE':
  13604. case 'DEL':
  13605. case 'STRONG':
  13606. case 'CITE':
  13607. case 'Q':
  13608. case 'EM':
  13609. case 'B':
  13610. case 'I':
  13611. case 'U':
  13612. case 'SAMP':
  13613. case 'CODE':
  13614. case 'KBD':
  13615. case 'TT':
  13616. case 'VAR':
  13617. case 'FONT':
  13618. case 'MARK': // mPDF 5.5.09
  13619. case 'TIME':
  13620. case 'SPAN':
  13621. /*-- ANNOTATIONS --*/
  13622. if ($this->title2annots && isset($attr['TITLE'])) {
  13623. $objattr = array();
  13624. $objattr['margin_top'] = 0;
  13625. $objattr['margin_bottom'] = 0;
  13626. $objattr['margin_left'] = 0;
  13627. $objattr['margin_right'] = 0;
  13628. $objattr['width'] = 0;
  13629. $objattr['height'] = 0;
  13630. $objattr['border_top']['w'] = 0;
  13631. $objattr['border_bottom']['w'] = 0;
  13632. $objattr['border_left']['w'] = 0;
  13633. $objattr['border_right']['w'] = 0;
  13634. $objattr['CONTENT'] = $attr['TITLE'];
  13635. $objattr['type'] = 'annot';
  13636. $objattr['POS-X'] = 0;
  13637. $objattr['POS-Y'] = 0;
  13638. $objattr['ICON'] = 'Comment';
  13639. $objattr['AUTHOR'] = '';
  13640. $objattr['SUBJECT'] = '';
  13641. $objattr['OPACITY'] = $this->annotOpacity;
  13642. $objattr['COLOR'] = $this->ConvertColor('yellow');
  13643. $annot = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13644. }
  13645. /*-- END ANNOTATIONS --*/
  13646. if ($tag == 'SPAN') {
  13647. $this->spanlvl++;
  13648. $this->InlineProperties['SPAN'][$this->spanlvl] = $this->saveInlineProperties();
  13649. if (isset($annot)) { $this->InlineAnnots[$tag][$this->spanlvl] = $annot; } // *ANNOTATIONS*
  13650. }
  13651. else {
  13652. if (!isset($this->InlineProperties[$tag])) $this->InlineProperties[$tag] = $this->saveInlineProperties(); // mPDF 5.4.13
  13653. if (isset($annot)) { $this->InlineAnnots[$tag] = $annot; } // *ANNOTATIONS*
  13654. }
  13655. $properties = $this->cssmgr->MergeCSS('INLINE',$tag,$attr);
  13656. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  13657. break;
  13658. case 'A':
  13659. if (isset($attr['NAME']) and $attr['NAME'] != '') {
  13660. $e = '';
  13661. /*-- BOOKMARKS --*/
  13662. if ($this->anchor2Bookmark) {
  13663. $objattr = array();
  13664. $objattr['CONTENT'] = htmlspecialchars_decode($attr['NAME'],ENT_QUOTES);
  13665. $objattr['type'] = 'bookmark';
  13666. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  13667. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13668. }
  13669. /*-- END BOOKMARKS --*/
  13670. if($this->tableLevel) { // *TABLES*
  13671. $this->_saveCellTextBuffer($e, '', $attr['NAME']); // *TABLES*
  13672. } // *TABLES*
  13673. else { // *TABLES*
  13674. $this->_saveTextBuffer($e, '', $attr['NAME']); //an internal link (adds a space for recognition)
  13675. } // *TABLES*
  13676. }
  13677. if (isset($attr['HREF'])) {
  13678. $this->InlineProperties['A'] = $this->saveInlineProperties();
  13679. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  13680. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  13681. $this->HREF=htmlspecialchars_decode(urldecode($attr['HREF']));
  13682. }
  13683. break;
  13684. case 'LEGEND': // mPDF 5.4.18
  13685. $this->InlineProperties['LEGEND'] = $this->saveInlineProperties();
  13686. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  13687. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  13688. break;
  13689. case 'PROGRESS': // mPDF 5.5.09
  13690. case 'METER': // mPDF 5.5.09
  13691. $this->inMeter = true; // mPDF 5.5.09
  13692. if (isset($attr['MAX']) && $attr['MAX']) { $max = $attr['MAX']; }
  13693. else { $max = 1; }
  13694. if (isset($attr['MIN']) && $attr['MIN'] && $tag=='METER') { $min = $attr['MIN']; }
  13695. else { $min = 0; }
  13696. if ($max < $min) { $max = $min; }
  13697. if (isset($attr['VALUE']) && ($attr['VALUE'] || $attr['VALUE']==='0')) {
  13698. $value = $attr['VALUE'];
  13699. if ($value < $min) { $value = $min; }
  13700. else if ($value > $max) { $value = $max; }
  13701. }
  13702. else { $value = ''; }
  13703. if (isset($attr['LOW']) && $attr['LOW']) { $low = $attr['LOW']; }
  13704. else { $low = $min; }
  13705. if ($low < $min) { $low = $min; }
  13706. else if ($low > $max) { $low = $max; }
  13707. if (isset($attr['HIGH']) && $attr['HIGH']) { $high = $attr['HIGH']; }
  13708. else { $high = $max; }
  13709. if ($high < $low) { $high = $low; }
  13710. else if ($high > $max) { $high = $max; }
  13711. if (isset($attr['OPTIMUM']) && $attr['OPTIMUM']) { $optimum = $attr['OPTIMUM']; }
  13712. else { $optimum = $min + (($max-$min)/2); }
  13713. if ($optimum < $min) { $optimum = $min; }
  13714. else if ($optimum > $max) { $optimum = $max; }
  13715. if (isset($attr['TYPE']) && $attr['TYPE']) { $type = $attr['TYPE']; }
  13716. else { $type = ''; }
  13717. $objattr = array();
  13718. $objattr['margin_top'] = 0;
  13719. $objattr['margin_bottom'] = 0;
  13720. $objattr['margin_left'] = 0;
  13721. $objattr['margin_right'] = 0;
  13722. $objattr['padding_top'] = 0;
  13723. $objattr['padding_bottom'] = 0;
  13724. $objattr['padding_left'] = 0;
  13725. $objattr['padding_right'] = 0;
  13726. $objattr['width'] = 0;
  13727. $objattr['height'] = 0;
  13728. $objattr['border_top']['w'] = 0;
  13729. $objattr['border_bottom']['w'] = 0;
  13730. $objattr['border_left']['w'] = 0;
  13731. $objattr['border_right']['w'] = 0;
  13732. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  13733. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  13734. return;
  13735. }
  13736. $objattr['visibility'] = 'visible';
  13737. if (isset($properties['VISIBILITY'])) {
  13738. $v = strtolower($properties['VISIBILITY']);
  13739. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  13740. $objattr['visibility'] = $v;
  13741. }
  13742. }
  13743. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13744. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13745. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13746. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13747. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13748. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13749. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13750. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  13751. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  13752. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  13753. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  13754. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  13755. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  13756. $w = 0;
  13757. $h = 0;
  13758. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  13759. else if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  13760. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  13761. else if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  13762. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  13763. if ($this->HREF) {
  13764. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  13765. $href = $this->HREF;
  13766. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  13767. $this->internallink[$href] = $this->AddLink();
  13768. $objattr['link'] = $this->internallink[$href];
  13769. }
  13770. else { $objattr['link'] = $this->HREF; }
  13771. }
  13772. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  13773. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  13774. // Image file
  13775. if (!class_exists('meter', false)) {
  13776. include(_MPDF_PATH.'classes/meter.php');
  13777. }
  13778. $this->meter = new meter();
  13779. $svg = $this->meter->makeSVG(strtolower($tag), $type, $value, $max, $min, $optimum, $low, $high);
  13780. //Save to local file
  13781. $srcpath= _MPDF_TEMP_PATH.'_tempSVG'.RAND(1,10000).'_'.strtolower($tag).'.svg';
  13782. file_put_contents($srcpath, $svg);
  13783. $orig_srcpath = $srcpath;
  13784. $this->GetFullPath($srcpath);
  13785. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  13786. if(!$info) {
  13787. $info = $this->_getImage($this->noImageFile);
  13788. if ($info) {
  13789. $srcpath = $this->noImageFile;
  13790. $w = ($info['w'] * (25.4/$this->dpi));
  13791. $h = ($info['h'] * (25.4/$this->dpi));
  13792. }
  13793. }
  13794. if(!$info) break;
  13795. $objattr['file'] = $srcpath;
  13796. //Default width and height calculation if needed
  13797. if($w==0 and $h==0) {
  13798. // SVG units are pixels
  13799. $w = $this->FontSize/(10/_MPDFK) * abs($info['w'])/_MPDFK; // mPDF 5.5.21
  13800. $h = $this->FontSize/(10/_MPDFK) * abs($info['h'])/_MPDFK;
  13801. }
  13802. // IF WIDTH OR HEIGHT SPECIFIED
  13803. if($w==0) $w=abs($h*$info['w']/$info['h']);
  13804. if($h==0) $h=abs($w*$info['h']/$info['w']);
  13805. // Resize to maximum dimensions of page
  13806. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  13807. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  13808. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  13809. if ($w + $extrawidth > $maxWidth ) {
  13810. $w = $maxWidth - $extrawidth;
  13811. $h=abs($w*$info['h']/$info['w']);
  13812. }
  13813. if ($h + $extraheight > $maxHeight ) {
  13814. $h = $maxHeight - $extraheight;
  13815. $w=abs($h*$info['w']/$info['h']);
  13816. }
  13817. $objattr['type'] = 'image';
  13818. $objattr['itype'] = $info['type'];
  13819. $objattr['orig_h'] = $info['h'];
  13820. $objattr['orig_w'] = $info['w'];
  13821. $objattr['wmf_x'] = $info['x'];
  13822. $objattr['wmf_y'] = $info['y'];
  13823. $objattr['height'] = $h + $extraheight;
  13824. $objattr['width'] = $w + $extrawidth;
  13825. $objattr['image_height'] = $h;
  13826. $objattr['image_width'] = $w;
  13827. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13828. $properties = array();
  13829. if ($this->tableLevel) {
  13830. $this->_saveCellTextBuffer($e, $this->HREF);
  13831. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  13832. }
  13833. else {
  13834. $this->_saveTextBuffer($e, $this->HREF);
  13835. }
  13836. break;
  13837. case 'BR':
  13838. // Added mPDF 3.0 Float DIV - CLEAR
  13839. if (isset($attr['STYLE'])) {
  13840. $properties = $this->cssmgr->readInlineCSS($attr['STYLE']);
  13841. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  13842. }
  13843. /*-- TABLES --*/
  13844. if($this->tableLevel) {
  13845. if ($this->blockjustfinished || $this->listjustfinished) {
  13846. $this->_saveCellTextBuffer("\n");
  13847. }
  13848. $this->_saveCellTextBuffer("\n");
  13849. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  13850. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13851. }
  13852. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  13853. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13854. }
  13855. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  13856. }
  13857. else {
  13858. /*-- END TABLES --*/
  13859. if (count($this->textbuffer)) {
  13860. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/ $/','',$this->textbuffer[count($this->textbuffer)-1][0]);
  13861. }
  13862. $this->_saveTextBuffer("\n");
  13863. } // *TABLES*
  13864. $this->ignorefollowingspaces = true;
  13865. $this->blockjustfinished=false;
  13866. $this->listjustfinished=false;
  13867. $this->linebreakjustfinished=true;
  13868. break;
  13869. // *********** BLOCKS ********************
  13870. case 'PRE':
  13871. $this->ispre=true; // ADDED - Prevents left trim of textbuffer in printbuffer()
  13872. case 'DIV':
  13873. case 'FORM':
  13874. case 'CENTER':
  13875. case 'BLOCKQUOTE':
  13876. case 'ADDRESS':
  13877. case 'CAPTION':
  13878. case 'P':
  13879. case 'H1':
  13880. case 'H2':
  13881. case 'H3':
  13882. case 'H4':
  13883. case 'H5':
  13884. case 'H6':
  13885. case 'DL':
  13886. case 'DT':
  13887. case 'DD':
  13888. case 'FIELDSET':
  13889. // mPDF 5.5.22
  13890. case 'DETAILS':
  13891. case 'SUMMARY':
  13892. // mPDF 5.5.09
  13893. case 'ARTICLE':
  13894. case 'ASIDE':
  13895. case 'FIGURE':
  13896. case 'FIGCAPTION':
  13897. case 'FOOTER':
  13898. case 'HEADER':
  13899. case 'HGROUP':
  13900. case 'NAV':
  13901. case 'SECTION':
  13902. $p = $this->cssmgr->PreviewBlockCSS($tag,$attr);
  13903. if(isset($p['DISPLAY']) && strtolower($p['DISPLAY'])=='none') {
  13904. $this->blklvl++;
  13905. $this->blk[$this->blklvl]['hide'] = true;
  13906. return;
  13907. }
  13908. if($tag == 'CAPTION') {
  13909. // position is written in AdjstHTML
  13910. if (isset($attr['POSITION']) && strtolower($attr['POSITION'])=='bottom') { $divpos = 'B'; }
  13911. else { $divpos = 'T'; }
  13912. if (isset($attr['ALIGN']) && strtolower($attr['ALIGN'])=='bottom') { $cappos = 'B'; }
  13913. else if (isset($p['CAPTION-SIDE']) && strtolower($p['CAPTION-SIDE'])=='bottom') { $cappos = 'B'; }
  13914. else { $cappos = 'T'; }
  13915. if (isset($attr['ALIGN'])) { unset($attr['ALIGN']); }
  13916. if ($cappos != $divpos) {
  13917. $this->blklvl++;
  13918. $this->blk[$this->blklvl]['hide'] = true;
  13919. return;
  13920. }
  13921. }
  13922. /*-- FORMS --*/
  13923. if($tag == 'FORM') {
  13924. if (isset($attr['METHOD']) && strtolower($attr['METHOD'])=='get') { $this->form->formMethod = 'GET'; }
  13925. else { $this->form->formMethod = 'POST'; }
  13926. if (isset($attr['ACTION'])) { $this->form->formAction = $attr['ACTION']; }
  13927. else { $this->form->formAction = ''; }
  13928. }
  13929. /*-- END FORMS --*/
  13930. /*-- CSS-POSITION --*/
  13931. if ((isset($p['POSITION']) && (strtolower($p['POSITION'])=='fixed' || strtolower($p['POSITION'])=='absolute')) && $this->blklvl==0) {
  13932. if ($this->inFixedPosBlock) {
  13933. $this->Error("Cannot nest block with position:fixed or position:absolute");
  13934. }
  13935. $this->inFixedPosBlock = true;
  13936. return;
  13937. }
  13938. /*-- END CSS-POSITION --*/
  13939. // Start Block
  13940. $this->ignorefollowingspaces = true;
  13941. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  13942. else { $lastbottommargin = 0; }
  13943. $this->lastblockbottommargin = 0;
  13944. $this->blockjustfinished=false;
  13945. /*-- LISTS --*/
  13946. if ($this->listlvl>0) { return; }
  13947. /*-- END LISTS --*/
  13948. $this->InlineProperties = array();
  13949. $this->spanlvl = 0;
  13950. $this->listjustfinished=false;
  13951. $this->divbegin=true;
  13952. $this->linebreakjustfinished=false;
  13953. /*-- TABLES --*/
  13954. if ($this->tableLevel) {
  13955. // If already something on the line
  13956. if ($this->cell[$this->row][$this->col]['s'] > 0 && !$this->nestedtablejustfinished ) {
  13957. $this->_saveCellTextBuffer("\n");
  13958. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  13959. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13960. }
  13961. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  13962. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13963. }
  13964. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  13965. }
  13966. // Cannot set block properties inside table - use Bold to indicate h1-h6
  13967. if ($tag == 'CENTER' && $this->tdbegin) { $this->cell[$this->row][$this->col]['a'] = $align['center']; }
  13968. $this->InlineProperties['BLOCKINTABLE'] = $this->saveInlineProperties();
  13969. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  13970. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  13971. break;
  13972. }
  13973. /*-- END TABLES --*/
  13974. if ($tag == 'P' || $tag == 'DT' || $tag == 'DD') { $this->lastoptionaltag = $tag; } // Save current HTML specified optional endtag
  13975. else { $this->lastoptionaltag = ''; }
  13976. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  13977. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  13978. $this->printbuffer($this->textbuffer,$blockstate);
  13979. $this->textbuffer=array();
  13980. $save_blklvl = $this->blklvl;
  13981. $save_blk = $this->blk;
  13982. $save_silp = $this->saveInlineProperties();
  13983. $save_spanlvl = $this->spanlvl;
  13984. $save_ilp = $this->InlineProperties;
  13985. $this->blklvl++;
  13986. $currblk =& $this->blk[$this->blklvl];
  13987. $this->initialiseBlock($currblk);
  13988. $prevblk =& $this->blk[$this->blklvl-1];
  13989. $currblk['tag'] = $tag;
  13990. $currblk['attr'] = $attr;
  13991. $this->Reset();
  13992. $properties = $this->cssmgr->MergeCSS('BLOCK',$tag,$attr);
  13993. $pagesel = '';
  13994. /*-- CSS-PAGE --*/
  13995. if (isset($properties['PAGE'])) { $pagesel = $properties['PAGE']; }
  13996. /*-- END CSS-PAGE --*/
  13997. // If page-box has changed AND/OR PAGE-BREAK-BEFORE
  13998. $save_cols = false;
  13999. if (($pagesel && $pagesel != $this->page_box['current']) || (isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  14000. if ($this->blklvl>1) {
  14001. // Close any open block tags
  14002. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  14003. // Output any text left in buffer
  14004. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  14005. }
  14006. /*-- COLUMNS --*/
  14007. if ($this->ColActive) {
  14008. $save_cols = true;
  14009. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  14010. $this->SetColumns(0);
  14011. }
  14012. /*-- END COLUMNS --*/
  14013. // Must Add new page if changed page properties
  14014. if (isset($properties['PAGE-BREAK-BEFORE'])) {
  14015. if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14016. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14017. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'ALWAYS') { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14018. else if ($this->page_box['current'] != $pagesel) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } // *CSS-PAGE*
  14019. }
  14020. /*-- CSS-PAGE --*/
  14021. else if ($pagesel != $this->page_box['current']) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14022. /*-- END CSS-PAGE --*/
  14023. // if using htmlheaders, the headers need to be rewritten when new page
  14024. // done by calling WriteHTML() within resethtmlheaders
  14025. // so block is reset to 0 - now we need to resurrect it
  14026. // As in WriteHTML() initialising
  14027. if (!($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  14028. $this->blklvl = 0;
  14029. $this->lastblocklevelchange = 0;
  14030. $this->blk = array();
  14031. $this->initialiseBlock($this->blk[0]);
  14032. $this->blk[0]['width'] =& $this->pgwidth;
  14033. $this->blk[0]['inner_width'] =& $this->pgwidth;
  14034. $this->blk[0]['blockContext'] = $this->blockContext;
  14035. $properties = $this->cssmgr->MergeCSS('BLOCK','BODY','');
  14036. $this->setCSS($properties,'','BODY');
  14037. $this->blklvl++;
  14038. $currblk =& $this->blk[$this->blklvl];
  14039. $prevblk =& $this->blk[$this->blklvl-1];
  14040. $this->initialiseBlock($currblk);
  14041. $currblk['tag'] = $tag;
  14042. $currblk['attr'] = $attr;
  14043. $this->Reset();
  14044. $properties = $this->cssmgr->MergeCSS('BLOCK',$tag,$attr);
  14045. }
  14046. /*-- COLUMNS --*/
  14047. if ($save_cols) {
  14048. // Restore columns
  14049. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  14050. }
  14051. /*-- END COLUMNS --*/
  14052. if ($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE']) {
  14053. $this->blk = $save_blk;
  14054. // Re-open block tags
  14055. $t = $this->blk[0]['tag'];
  14056. $a = $this->blk[0]['attr'];
  14057. $this->blklvl = 0;
  14058. for ($b=0; $b<=$save_blklvl;$b++) {
  14059. $tc = $t;
  14060. $ac = $a;
  14061. $t = $this->blk[$b+1]['tag'];
  14062. $a = $this->blk[$b+1]['attr'];
  14063. unset($this->blk[$b+1]);
  14064. $this->OpenTag($tc,$ac);
  14065. }
  14066. $this->spanlvl = $save_spanlvl;
  14067. $this->InlineProperties = $save_ilp;
  14068. $this->restoreInlineProperties($save_silp);
  14069. }
  14070. }
  14071. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE']) == 'AVOID' && !$this->ColActive && !$this->keep_block_together) {
  14072. $currblk['keep_block_together'] = 1;
  14073. $this->kt_y00 = $this->y;
  14074. $this->kt_p00 = $this->page;
  14075. $this->keep_block_together = 1;
  14076. $this->divbuffer = array();
  14077. $this->ktLinks = array();
  14078. $this->ktAnnots = array();
  14079. $this->ktForms = array();
  14080. $this->ktBlock = array();
  14081. $this->ktReference = array();
  14082. $this->ktBMoutlines = array();
  14083. $this->_kttoc = array();
  14084. }
  14085. if ($lastbottommargin && isset($properties['MARGIN-TOP']) && $properties['MARGIN-TOP'] && empty($properties['FLOAT'])) { $currblk['lastbottommargin'] = $lastbottommargin; }
  14086. // mPDF 5.6.01 - LAYERS
  14087. if (isset($properties['Z-INDEX']) && $this->currentlayer==0) {
  14088. $v = intval($properties['Z-INDEX']);
  14089. if ($v > 0) {
  14090. $currblk['z-index'] = $v;
  14091. $this->BeginLayer($v);
  14092. }
  14093. }
  14094. $this->setCSS($properties,'BLOCK',$tag); //name(id/class/style) found in the CSS array!
  14095. $currblk['InlineProperties'] = $this->saveInlineProperties();
  14096. if (isset($properties['VISIBILITY'])) {
  14097. $v = strtolower($properties['VISIBILITY']);
  14098. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible' && !$this->tableLevel) {
  14099. $currblk['visibility'] = $v;
  14100. $this->SetVisibility($v);
  14101. }
  14102. }
  14103. if(isset($attr['DIR']) && $attr['DIR']) { $currblk['direction'] = strtolower($attr['DIR']); }
  14104. if(isset($attr['ALIGN']) && $attr['ALIGN']) { $currblk['block-align'] = $align[strtolower($attr['ALIGN'])]; }
  14105. if (isset($properties['HEIGHT'])) {
  14106. $currblk['css_set_height'] = $this->ConvertSize($properties['HEIGHT'],($this->h - $this->tMargin - $this->bMargin),$this->FontSize,false);
  14107. 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); }
  14108. }
  14109. else { $currblk['css_set_height'] = false; }
  14110. // Added mPDF 3.0 Float DIV
  14111. if (isset($prevblk['blockContext'])) { $currblk['blockContext'] = $prevblk['blockContext'] ; } // *CSS-FLOAT*
  14112. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']), $this->blklvl-1); } // *CSS-FLOAT*
  14113. $container_w = $prevblk['inner_width'];
  14114. $bdr = $currblk['border_right']['w'];
  14115. $bdl = $currblk['border_left']['w'];
  14116. $pdr = $currblk['padding_right'];
  14117. $pdl = $currblk['padding_left'];
  14118. if (isset($currblk['css_set_width'])) { $setwidth = $currblk['css_set_width']; }
  14119. else { $setwidth = 0; }
  14120. /*-- CSS-FLOAT --*/
  14121. if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'RIGHT' && !$this->ColActive) {
  14122. // Cancel Keep-Block-together
  14123. $currblk['keep_block_together'] = false;
  14124. $this->kt_y00 = '';
  14125. $this->keep_block_together = 0;
  14126. $this->blockContext++;
  14127. $currblk['blockContext'] = $this->blockContext;
  14128. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14129. // DIV is too narrow for text to fit!
  14130. $maxw = $container_w - $l_width - $r_width;
  14131. if (($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) {
  14132. // Too narrow to fit - try to move down past L or R float
  14133. 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)) > (2*$this->GetCharWidth('W',false))) {
  14134. $this->ClearFloats('LEFT', $this->blklvl-1);
  14135. }
  14136. 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)) > (2*$this->GetCharWidth('W',false))) {
  14137. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14138. }
  14139. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14140. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14141. }
  14142. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14143. $currblk['float'] = 'R';
  14144. $currblk['float_start_y'] = $this->y;
  14145. if ($currblk['css_set_width']) {
  14146. $currblk['margin_left'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14147. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14148. }
  14149. else {
  14150. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14151. // and do borders and backgrounds - For now - just set to maximum width left
  14152. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14153. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14154. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14155. }
  14156. }
  14157. else if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'LEFT' && !$this->ColActive) {
  14158. // Cancel Keep-Block-together
  14159. $currblk['keep_block_together'] = false;
  14160. $this->kt_y00 = '';
  14161. $this->keep_block_together = 0;
  14162. $this->blockContext++;
  14163. $currblk['blockContext'] = $this->blockContext;
  14164. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14165. // DIV is too narrow for text to fit!
  14166. $maxw = $container_w - $l_width - $r_width;
  14167. if (($setwidth + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) {
  14168. // Too narrow to fit - try to move down past L or R float
  14169. 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)) > (2*$this->GetCharWidth('W',false))) {
  14170. $this->ClearFloats('LEFT', $this->blklvl-1);
  14171. }
  14172. 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)) > (2*$this->GetCharWidth('W',false))) {
  14173. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14174. }
  14175. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14176. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14177. }
  14178. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14179. $currblk['float'] = 'L';
  14180. $currblk['float_start_y'] = $this->y;
  14181. if ($setwidth) {
  14182. $currblk['margin_right'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14183. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14184. }
  14185. else {
  14186. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14187. // and do borders and backgrounds - For now - just set to maximum width left
  14188. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14189. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14190. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14191. }
  14192. }
  14193. else {
  14194. // Don't allow overlap - if floats present - adjust padding to avoid overlap with Floats
  14195. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14196. $maxw = $container_w - $l_width - $r_width;
  14197. if (($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) {
  14198. // Too narrow to fit - try to move down past L or R float
  14199. 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)) > (2*$this->GetCharWidth('W',false))) {
  14200. $this->ClearFloats('LEFT', $this->blklvl-1);
  14201. }
  14202. 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)) > (2*$this->GetCharWidth('W',false))) {
  14203. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14204. }
  14205. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14206. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14207. }
  14208. if ($r_exists) { $currblk['padding_right'] = max(($r_width-$currblk['margin_right']-$bdr), $pdr); }
  14209. if ($l_exists) { $currblk['padding_left'] = max(($l_width-$currblk['margin_left']-$bdl), $pdl); }
  14210. }
  14211. /*-- END CSS-FLOAT --*/
  14212. /*-- BORDER-RADIUS --*/
  14213. // Automatically increase padding if required for border-radius
  14214. if ($this->autoPadding && !$this->ColActive && !$this->keep_block_together) {
  14215. if ($currblk['border_radius_TL_H']>$currblk['padding_left'] && $currblk['border_radius_TL_V']>$currblk['padding_top']) {
  14216. if ($currblk['border_radius_TL_H']>$currblk['border_radius_TL_V']) {
  14217. $this->_borderPadding($currblk['border_radius_TL_H'],$currblk['border_radius_TL_V'], $currblk['padding_left'], $currblk['padding_top']);
  14218. }
  14219. else {
  14220. $this->_borderPadding($currblk['border_radius_TL_V'],$currblk['border_radius_TL_H'], $currblk['padding_top'], $currblk['padding_left']);
  14221. }
  14222. }
  14223. if ($currblk['border_radius_TR_H']>$currblk['padding_right'] && $currblk['border_radius_TR_V']>$currblk['padding_top']) {
  14224. if ($currblk['border_radius_TR_H']>$currblk['border_radius_TR_V']) {
  14225. $this->_borderPadding($currblk['border_radius_TR_H'],$currblk['border_radius_TR_V'], $currblk['padding_right'], $currblk['padding_top']);
  14226. }
  14227. else {
  14228. $this->_borderPadding($currblk['border_radius_TR_V'],$currblk['border_radius_TR_H'], $currblk['padding_top'], $currblk['padding_right']);
  14229. }
  14230. }
  14231. if ($currblk['border_radius_BL_H']>$currblk['padding_left'] && $currblk['border_radius_BL_V']>$currblk['padding_bottom']) {
  14232. if ($currblk['border_radius_BL_H']>$currblk['border_radius_BL_V']) {
  14233. $this->_borderPadding($currblk['border_radius_BL_H'],$currblk['border_radius_BL_V'], $currblk['padding_left'], $currblk['padding_bottom']);
  14234. }
  14235. else {
  14236. $this->_borderPadding($currblk['border_radius_BL_V'],$currblk['border_radius_BL_H'], $currblk['padding_bottom'], $currblk['padding_left']);
  14237. }
  14238. }
  14239. if ($currblk['border_radius_BR_H']>$currblk['padding_right'] && $currblk['border_radius_BR_V']>$currblk['padding_bottom']) {
  14240. if ($currblk['border_radius_BR_H']>$currblk['border_radius_BR_V']) {
  14241. $this->_borderPadding($currblk['border_radius_BR_H'],$currblk['border_radius_BR_V'], $currblk['padding_right'], $currblk['padding_bottom']);
  14242. }
  14243. else {
  14244. $this->_borderPadding($currblk['border_radius_BR_V'],$currblk['border_radius_BR_H'], $currblk['padding_bottom'], $currblk['padding_right']);
  14245. }
  14246. }
  14247. }
  14248. /*-- END BORDER-RADIUS --*/
  14249. // Hanging indent - if negative indent: ensure padding is >= indent
  14250. if(!isset($currblk['text_indent'])) { $currblk['text_indent'] = null; }
  14251. if(!isset($currblk['inner_width'])) { $currblk['inner_width'] = null; }
  14252. $cbti = $this->ConvertSize($currblk['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14253. if ($cbti < 0) {
  14254. $hangind = -($cbti);
  14255. if ($currblk['direction'] == 'rtl') { // *RTL*
  14256. $currblk['padding_right'] = max($currblk['padding_right'],$hangind); // *RTL*
  14257. } // *RTL*
  14258. else { // *RTL*
  14259. $currblk['padding_left'] = max($currblk['padding_left'],$hangind);
  14260. } // *RTL*
  14261. }
  14262. if (isset($currblk['css_set_width'])) {
  14263. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14264. // Try to reduce margins to accomodate - if still too wide, set margin-right/left=0 (reduces width)
  14265. $anyextra = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14266. if ($anyextra>0) {
  14267. $currblk['margin_left'] = $currblk['margin_right'] = $anyextra /2;
  14268. }
  14269. else {
  14270. $currblk['margin_left'] = $currblk['margin_right'] = 0;
  14271. }
  14272. }
  14273. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14274. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14275. $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']);
  14276. if ($currblk['margin_left'] < 0) {
  14277. $currblk['margin_left'] = 0;
  14278. }
  14279. }
  14280. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14281. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14282. $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']);
  14283. if ($currblk['margin_right'] < 0) {
  14284. $currblk['margin_right'] = 0;
  14285. }
  14286. }
  14287. else {
  14288. if ($currblk['direction'] == 'rtl') { // *RTL*
  14289. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14290. $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*
  14291. if ($currblk['margin_left'] < 0) { // *RTL*
  14292. $currblk['margin_left'] = 0; // *RTL*
  14293. } // *RTL*
  14294. } // *RTL*
  14295. else { // *RTL*
  14296. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14297. $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']);
  14298. if ($currblk['margin_right'] < 0) {
  14299. $currblk['margin_right'] = 0;
  14300. }
  14301. } // *RTL*
  14302. }
  14303. }
  14304. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14305. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14306. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14307. $currblk['inner_width'] = $currblk['width'] - ($currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14308. // Check DIV is not now too narrow to fit text
  14309. $mw = 2*$this->GetCharWidth('W',false);
  14310. if ($currblk['inner_width'] < $mw) {
  14311. $currblk['padding_left'] = 0;
  14312. $currblk['padding_right'] = 0;
  14313. $currblk['border_left']['w'] = 0.2;
  14314. $currblk['border_right']['w'] = 0.2;
  14315. $currblk['margin_left'] = 0;
  14316. $currblk['margin_right'] = 0;
  14317. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14318. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14319. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14320. $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']);
  14321. // if ($currblk['inner_width'] < $mw) { $this->Error("DIV is too narrow for text to fit!"); }
  14322. }
  14323. $this->x = $this->lMargin + $currblk['outer_left_margin'];
  14324. /*-- BACKGROUNDS --*/
  14325. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive && !$this->keep_block_together) {
  14326. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  14327. if ($ret) { $currblk['background-image'] = $ret; }
  14328. }
  14329. /*-- END BACKGROUNDS --*/
  14330. /*-- TABLES --*/
  14331. if ($this->use_kwt && isset($attr['KEEP-WITH-TABLE']) && !$this->ColActive && !$this->keep_block_together) {
  14332. $this->kwt = true;
  14333. $this->kwt_y0 = $this->y;
  14334. $this->kwt_x0 = $this->x;
  14335. $this->kwt_height = 0;
  14336. $this->kwt_buffer = array();
  14337. $this->kwt_Links = array();
  14338. $this->kwt_Annots = array();
  14339. $this->kwt_moved = false;
  14340. $this->kwt_saved = false;
  14341. $this->kwt_Reference = array();
  14342. $this->kwt_BMoutlines = array();
  14343. $this->kwt_toc = array();
  14344. }
  14345. else {
  14346. /*-- END TABLES --*/
  14347. $this->kwt = false;
  14348. } // *TABLES*
  14349. //Save x,y coords in case we need to print borders...
  14350. $currblk['y0'] = $this->y;
  14351. $currblk['x0'] = $this->x;
  14352. $currblk['startpage'] = $this->page;
  14353. $this->oldy = $this->y;
  14354. $this->lastblocklevelchange = 1 ;
  14355. break;
  14356. case 'HR':
  14357. // Added mPDF 3.0 Float DIV - CLEAR
  14358. if (isset($attr['STYLE'])) {
  14359. $properties = $this->cssmgr->readInlineCSS($attr['STYLE']);
  14360. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  14361. }
  14362. $this->ignorefollowingspaces = true;
  14363. $objattr = array();
  14364. $objattr['margin_top'] = 0;
  14365. $objattr['margin_bottom'] = 0;
  14366. $objattr['margin_left'] = 0;
  14367. $objattr['margin_right'] = 0;
  14368. $objattr['width'] = 0;
  14369. $objattr['height'] = 0;
  14370. $objattr['border_top']['w'] = 0;
  14371. $objattr['border_bottom']['w'] = 0;
  14372. $objattr['border_left']['w'] = 0;
  14373. $objattr['border_right']['w'] = 0;
  14374. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  14375. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14376. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14377. if (isset($properties['WIDTH'])) { $objattr['width'] = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); }
  14378. else if(isset($attr['WIDTH']) && $attr['WIDTH'] != '') $objattr['width'] = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14379. if (isset($properties['TEXT-ALIGN'])) { $objattr['align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  14380. else if(isset($attr['ALIGN']) && $attr['ALIGN'] != '') $objattr['align'] = $align[strtolower($attr['ALIGN'])];
  14381. if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14382. $objattr['align'] = 'R';
  14383. }
  14384. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14385. $objattr['align'] = 'L';
  14386. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto' && isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14387. $objattr['align'] = 'C';
  14388. }
  14389. }
  14390. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14391. else if(isset($attr['COLOR']) && $attr['COLOR'] != '') $objattr['color'] = $this->ConvertColor($attr['COLOR']);
  14392. if (isset($properties['HEIGHT'])) { $objattr['linewidth'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14393. /*-- TABLES --*/
  14394. if ($this->tableLevel) {
  14395. $objattr['W-PERCENT'] = 100;
  14396. if (isset($properties['WIDTH']) && stristr($properties['WIDTH'],'%')) {
  14397. $properties['WIDTH'] += 0; //make "90%" become simply "90"
  14398. $objattr['W-PERCENT'] = $properties['WIDTH'];
  14399. }
  14400. if (isset($attr['WIDTH']) && stristr($attr['WIDTH'],'%')) {
  14401. $attr['WIDTH'] += 0; //make "90%" become simply "90"
  14402. $objattr['W-PERCENT'] = $attr['WIDTH'];
  14403. }
  14404. }
  14405. /*-- END TABLES --*/
  14406. $objattr['type'] = 'hr';
  14407. $objattr['height'] = $objattr['linewidth'] + $objattr['margin_top'] + $objattr['margin_bottom'];
  14408. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14409. // Clear properties - tidy up
  14410. $properties = array();
  14411. /*-- TABLES --*/
  14412. // Output it to buffers
  14413. if ($this->tableLevel) {
  14414. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14415. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14416. }
  14417. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14418. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14419. }
  14420. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14421. $this->_saveCellTextBuffer($e, $this->HREF);
  14422. }
  14423. else {
  14424. /*-- END TABLES --*/
  14425. $this->_saveTextBuffer($e, $this->HREF);
  14426. } // *TABLES*
  14427. break;
  14428. /*-- BARCODES --*/
  14429. case 'BARCODE':
  14430. if(isset($attr['CODE']) && $attr['CODE']) {
  14431. $objattr = array();
  14432. $objattr['margin_top'] = 0;
  14433. $objattr['margin_bottom'] = 0;
  14434. $objattr['margin_left'] = 0;
  14435. $objattr['margin_right'] = 0;
  14436. $objattr['padding_top'] = 0;
  14437. $objattr['padding_bottom'] = 0;
  14438. $objattr['padding_left'] = 0;
  14439. $objattr['padding_right'] = 0;
  14440. $objattr['width'] = 0;
  14441. $objattr['height'] = 0;
  14442. $objattr['border_top']['w'] = 0;
  14443. $objattr['border_bottom']['w'] = 0;
  14444. $objattr['border_left']['w'] = 0;
  14445. $objattr['border_right']['w'] = 0;
  14446. $objattr['code'] = $attr['CODE'];
  14447. if(isset($attr['TYPE'])) {
  14448. $objattr['btype'] = trim(strtoupper($attr['TYPE']));
  14449. }
  14450. else { $objattr['btype'] = 'EAN13'; } // default
  14451. if (preg_match('/^(EAN13|ISBN|ISSN|EAN8|UPCA|UPCE)P([25])$/',$objattr['btype'],$m)) {
  14452. $objattr['btype'] = $m[1];
  14453. $objattr['bsupp'] = $m[2];
  14454. if (preg_match('/^(\S+)\s+(.*)$/',$objattr['code'],$mm)) {
  14455. $objattr['code'] = $mm[1];
  14456. $objattr['bsupp_code'] = $mm[2];
  14457. }
  14458. }
  14459. else { $objattr['bsupp'] = 0; }
  14460. if(isset($attr['TEXT']) && $attr['TEXT']==1) { $objattr['showtext'] = 1; }
  14461. else { $objattr['showtext'] = 0; }
  14462. if(isset($attr['SIZE']) && $attr['SIZE']>0) { $objattr['bsize'] = $attr['SIZE']; }
  14463. else { $objattr['bsize'] = 1; }
  14464. if(isset($attr['HEIGHT']) && $attr['HEIGHT']>0) { $objattr['bheight'] = $attr['HEIGHT']; }
  14465. else { $objattr['bheight'] = 1; }
  14466. if(isset($attr['PR']) && $attr['PR']>0) { $objattr['pr_ratio'] = $attr['PR']; }
  14467. else { $objattr['pr_ratio'] = ''; }
  14468. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  14469. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  14470. return;
  14471. }
  14472. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14473. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14474. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14475. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14476. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14477. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14478. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14479. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14480. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  14481. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  14482. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  14483. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  14484. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14485. if (isset($properties['COLOR']) && $properties['COLOR'] != '') { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14486. else { $objattr['color'] = false; }
  14487. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  14488. else { $objattr['bgcolor'] = false; }
  14489. if (!class_exists('PDFBarcode', false)) {
  14490. include(_MPDF_PATH.'classes/barcode.php');
  14491. }
  14492. $this->barcode = new PDFBarcode();
  14493. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  14494. $code = preg_replace('/\-/','',$objattr['code']);
  14495. if ($objattr['btype'] == 'ISSN' || $objattr['btype'] == 'ISBN') {
  14496. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  14497. }
  14498. else { $arrcode = $this->barcode->getBarcodeArray($code, $objattr['btype'] ); }
  14499. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14500. if ($objattr['bsupp'] == 2 || $objattr['bsupp'] == 5) { // EAN-2 or -5 Supplement
  14501. $supparrcode = $this->barcode->getBarcodeArray($objattr['bsupp_code'], 'EAN'.$objattr['bsupp'] );
  14502. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR'] + $supparrcode["maxw"] + $supparrcode['sepM']) * $arrcode['nom-X'] * $objattr['bsize'];
  14503. }
  14504. else {
  14505. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  14506. }
  14507. $h = $arrcode['nom-H'] * $objattr['bsize'] * $objattr['bheight'];
  14508. // Add height for ISBN string + margin from top of bars
  14509. if (($objattr['showtext'] && $objattr['btype'] == 'EAN13') || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN') {
  14510. $tisbnm = 1.5 * $objattr['bsize']; // Top margin between TOP TEXT (isbn - if shown) & bars
  14511. $isbn_fontsize = 2.1 * $objattr['bsize'];
  14512. $h += $isbn_fontsize + $tisbnm ;
  14513. }
  14514. }
  14515. // QR-code
  14516. else if ($objattr['btype'] == 'QR') {
  14517. $w = $h = $objattr['bsize']*25; // Factor of 25mm (default)
  14518. $objattr['errorlevel'] = 'L';
  14519. if (isset($attr['ERROR'])) { $objattr['errorlevel'] = $attr['ERROR']; }
  14520. }
  14521. else if ($objattr['btype'] == 'IMB' || $objattr['btype'] == 'RM4SCC' || $objattr['btype'] == 'KIX' || $objattr['btype'] == 'POSTNET' || $objattr['btype'] == 'PLANET') {
  14522. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'] );
  14523. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14524. $w = ($arrcode["maxw"] * $arrcode['nom-X'] * $objattr['bsize']) + $arrcode['quietL'] + $arrcode['quietR'];
  14525. $h = ($arrcode['nom-H'] * $objattr['bsize']) + (2*$arrcode['quietTB']);
  14526. }
  14527. 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'))) {
  14528. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'], $objattr['pr_ratio'] );
  14529. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14530. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  14531. $h = ((2*$arrcode['lightTB'] * $arrcode['nom-X']) + $arrcode['nom-H']) * $objattr['bsize'] * $objattr['bheight'];
  14532. }
  14533. else { break; }
  14534. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  14535. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  14536. $objattr['type'] = 'barcode';
  14537. $objattr['height'] = $h + $extraheight;
  14538. $objattr['width'] = $w + $extrawidth;
  14539. $objattr['barcode_height'] = $h;
  14540. $objattr['barcode_width'] = $w;
  14541. /*-- CSS-IMAGE-FLOAT --*/
  14542. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  14543. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  14544. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  14545. }
  14546. }
  14547. /*-- END CSS-IMAGE-FLOAT --*/
  14548. $e = "\xbb\xa4\xactype=barcode,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14549. // Clear properties - tidy up
  14550. $properties = array();
  14551. /*-- TABLES --*/
  14552. // Output it to buffers
  14553. if ($this->tableLevel) {
  14554. $this->_saveCellTextBuffer($e, $this->HREF);
  14555. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  14556. }
  14557. else {
  14558. /*-- END TABLES --*/
  14559. $this->_saveTextBuffer($e, $this->HREF);
  14560. } // *TABLES*
  14561. }
  14562. break;
  14563. /*-- END BARCODES --*/
  14564. // *********** FORM ELEMENTS ********************
  14565. /*-- FORMS --*/
  14566. case 'SELECT':
  14567. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  14568. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14569. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  14570. if (isset($properties['FONT-FAMILY'])) {
  14571. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  14572. }
  14573. if (isset($properties['FONT-SIZE'])) {
  14574. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  14575. $this->SetFontSize($mmsize*_MPDFK,false);
  14576. }
  14577. if (isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') {
  14578. $this->selectoption['SPELLCHECK'] = true;
  14579. }
  14580. if (isset($properties['COLOR'])) { $this->selectoption['COLOR'] = $this->ConvertColor($properties['COLOR']); }
  14581. $this->specialcontent = "type=select";
  14582. if(isset($attr['DISABLED'])) { $this->selectoption['DISABLED'] = $attr['DISABLED']; }
  14583. if(isset($attr['READONLY'])) { $this->selectoption['READONLY'] = $attr['READONLY']; }
  14584. if(isset($attr['REQUIRED'])) { $this->selectoption['REQUIRED'] = $attr['REQUIRED']; }
  14585. if(isset($attr['EDITABLE'])) { $this->selectoption['EDITABLE'] = $attr['EDITABLE']; }
  14586. if(isset($attr['TITLE'])) { $this->selectoption['TITLE'] = $attr['TITLE']; }
  14587. if(isset($attr['MULTIPLE'])) { $this->selectoption['MULTIPLE'] = $attr['MULTIPLE']; }
  14588. if(isset($attr['SIZE']) && $attr['SIZE']>1) { $this->selectoption['SIZE'] = $attr['SIZE']; }
  14589. if ($this->useActiveForms) {
  14590. if(isset($attr['NAME'])) { $this->selectoption['NAME'] = $attr['NAME']; }
  14591. if (isset($attr['ONCHANGE'])) { $this->selectoption['ONCHANGE'] = $attr['ONCHANGE']; }
  14592. }
  14593. $properties = array();
  14594. break;
  14595. case 'OPTION':
  14596. $this->lastoptionaltag = 'OPTION'; // Save current HTML specified optional endtag
  14597. $this->selectoption['ACTIVE'] = true;
  14598. $this->selectoption['currentSEL'] = false;
  14599. if (empty($this->selectoption)) {
  14600. $this->selectoption['MAXWIDTH'] = '';
  14601. $this->selectoption['SELECTED'] = '';
  14602. }
  14603. if (isset($attr['SELECTED'])) {
  14604. $this->selectoption['SELECTED'] = '';
  14605. $this->selectoption['currentSEL'] = true;
  14606. }
  14607. if(isset($attr['VALUE'])) {
  14608. $attr['VALUE'] = strcode2utf($attr['VALUE']);
  14609. $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']);
  14610. if ($this->onlyCoreFonts)
  14611. $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8');
  14612. }
  14613. $this->selectoption['currentVAL'] = $attr['VALUE'];
  14614. break;
  14615. case 'TEXTAREA':
  14616. $objattr = array();
  14617. $objattr['margin_top'] = 0;
  14618. $objattr['margin_bottom'] = 0;
  14619. $objattr['margin_left'] = 0;
  14620. $objattr['margin_right'] = 0;
  14621. $objattr['width'] = 0;
  14622. $objattr['height'] = 0;
  14623. $objattr['border_top']['w'] = 0;
  14624. $objattr['border_bottom']['w'] = 0;
  14625. $objattr['border_left']['w'] = 0;
  14626. $objattr['border_right']['w'] = 0;
  14627. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  14628. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  14629. if(isset($attr['REQUIRED'])) { $objattr['required'] = true; }
  14630. if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; }
  14631. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  14632. if ($this->onlyCoreFonts)
  14633. $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8');
  14634. if ($this->useActiveForms) {
  14635. if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; }
  14636. $this->form->form_element_spacing['textarea']['outer']['v'] = 0;
  14637. $this->form->form_element_spacing['textarea']['inner']['v'] = 0;
  14638. if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; }
  14639. else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; }
  14640. if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; }
  14641. if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; }
  14642. if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; }
  14643. }
  14644. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14645. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  14646. if (isset($properties['FONT-FAMILY'])) {
  14647. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  14648. }
  14649. if (isset($properties['FONT-SIZE'])) {
  14650. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  14651. $this->SetFontSize($mmsize*_MPDFK,false);
  14652. }
  14653. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14654. $objattr['fontfamily'] = $this->FontFamily;
  14655. $objattr['fontsize'] = $this->FontSizePt;
  14656. if ($this->useActiveForms) {
  14657. if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  14658. else if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; }
  14659. if (isset($properties['OVERFLOW']) && strtolower($properties['OVERFLOW'])=='hidden') { $objattr['donotscroll'] = true; }
  14660. if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); }
  14661. if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  14662. }
  14663. $this->SetLineHeight('',$this->form->textarea_lineheight);
  14664. $formLineHeight = $this->lineheight;
  14665. $w = 0;
  14666. $h = 0;
  14667. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14668. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14669. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14670. $colsize = 20; //HTML default value
  14671. $rowsize = 2; //HTML default value
  14672. if (isset($attr['COLS'])) $colsize = intval($attr['COLS']);
  14673. if (isset($attr['ROWS'])) $rowsize = intval($attr['ROWS']);
  14674. $charsize = $this->GetCharWidth('w',false);
  14675. if ($w) { $colsize = round(($w-($this->form->form_element_spacing['textarea']['outer']['h']*2)-($this->form->form_element_spacing['textarea']['inner']['h']*2))/$charsize); }
  14676. if ($h) { $rowsize = round(($h-($this->form->form_element_spacing['textarea']['outer']['v']*2)-($this->form->form_element_spacing['textarea']['inner']['v']*2))/$formLineHeight); }
  14677. $objattr['type'] = 'textarea';
  14678. $objattr['width'] = ($colsize * $charsize) + ($this->form->form_element_spacing['textarea']['outer']['h']*2)+($this->form->form_element_spacing['textarea']['inner']['h']*2);
  14679. $objattr['height'] = ($rowsize * $formLineHeight) + ($this->form->form_element_spacing['textarea']['outer']['v']*2)+($this->form->form_element_spacing['textarea']['inner']['v']*2);
  14680. $objattr['rows'] = $rowsize;
  14681. $objattr['cols'] = $colsize;
  14682. $this->specialcontent = serialize($objattr);
  14683. if ($this->tableLevel) { // *TABLES*
  14684. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  14685. } // *TABLES*
  14686. // Clear properties - tidy up
  14687. $properties = array();
  14688. break;
  14689. // *********** FORM - INPUT ********************
  14690. case 'INPUT':
  14691. if (!isset($attr['TYPE'])) $attr['TYPE'] == 'TEXT';
  14692. $objattr = array();
  14693. $objattr['margin_top'] = 0;
  14694. $objattr['margin_bottom'] = 0;
  14695. $objattr['margin_left'] = 0;
  14696. $objattr['margin_right'] = 0;
  14697. $objattr['width'] = 0;
  14698. $objattr['height'] = 0;
  14699. $objattr['border_top']['w'] = 0;
  14700. $objattr['border_bottom']['w'] = 0;
  14701. $objattr['border_left']['w'] = 0;
  14702. $objattr['border_right']['w'] = 0;
  14703. $objattr['type'] = 'input';
  14704. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  14705. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  14706. if(isset($attr['REQUIRED'])) { $objattr['required'] = true; }
  14707. if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; }
  14708. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  14709. else if(isset($attr['ALT'])) { $objattr['title'] = $attr['ALT']; }
  14710. else $objattr['title'] = '';
  14711. $objattr['title'] = strcode2utf($objattr['title']);
  14712. $objattr['title'] = $this->lesser_entity_decode($objattr['title']);
  14713. if ($this->onlyCoreFonts)
  14714. $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8');
  14715. if ($this->useActiveForms) {
  14716. if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; }
  14717. }
  14718. if(isset($attr['VALUE'])) {
  14719. $attr['VALUE'] = strcode2utf($attr['VALUE']);
  14720. $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']);
  14721. if ($this->onlyCoreFonts)
  14722. $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8');
  14723. $objattr['value'] = $attr['VALUE'];
  14724. }
  14725. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14726. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  14727. $objattr['vertical-align'] = '';
  14728. if (isset($properties['FONT-FAMILY'])) {
  14729. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  14730. }
  14731. if (isset($properties['FONT-SIZE'])) {
  14732. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK));
  14733. $this->SetFontSize($mmsize*_MPDFK,false);
  14734. }
  14735. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14736. $objattr['fontfamily'] = $this->FontFamily;
  14737. $objattr['fontsize'] = $this->FontSizePt;
  14738. if ($this->useActiveForms) {
  14739. if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; }
  14740. else if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  14741. if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); }
  14742. if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  14743. }
  14744. $type = '';
  14745. $texto='';
  14746. $height = $this->FontSize;
  14747. $width = 0;
  14748. $spacesize = $this->GetCharWidth(' ',false);
  14749. $w = 0;
  14750. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14751. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14752. switch(strtoupper($attr['TYPE'])){
  14753. case 'HIDDEN':
  14754. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  14755. if ($this->useActiveForms) {
  14756. $this->form->SetFormText( 0, 0, $objattr['fieldname'], $objattr['value'], $objattr['value'], '', 0, '', true );
  14757. }
  14758. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  14759. unset($this->InlineProperties[$tag]);
  14760. break 2;
  14761. case 'CHECKBOX': //Draw Checkbox
  14762. $type = 'CHECKBOX';
  14763. if (isset($attr['CHECKED'])) { $objattr['checked'] = true; }
  14764. else { $objattr['checked'] = false; }
  14765. $width = $this->FontSize;
  14766. $height = $this->FontSize;
  14767. break;
  14768. case 'RADIO': //Draw Radio button
  14769. $type = 'RADIO';
  14770. if (isset($attr['CHECKED'])) $objattr['checked'] = true;
  14771. $width = $this->FontSize;
  14772. $height = $this->FontSize;
  14773. break;
  14774. /*-- IMAGES-CORE --*/
  14775. case 'IMAGE': // Draw an Image button
  14776. if(isset($attr['SRC'])) {
  14777. $type = 'IMAGE';
  14778. $srcpath = $attr['SRC'];
  14779. $orig_srcpath = $attr['ORIG_SRC'];
  14780. // VSPACE and HSPACE converted to margins in MergeCSS
  14781. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14782. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14783. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14784. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14785. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  14786. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  14787. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  14788. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  14789. $objattr['padding_top'] = 0;
  14790. $objattr['padding_bottom'] = 0;
  14791. $objattr['padding_left'] = 0;
  14792. $objattr['padding_right'] = 0;
  14793. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14794. $w = 0;
  14795. $h = 0;
  14796. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14797. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width']);
  14798. $extraheight = $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  14799. $extrawidth = $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  14800. // Image file
  14801. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  14802. if(!$info) {
  14803. $info = $this->_getImage($this->noImageFile);
  14804. if ($info) {
  14805. $srcpath = $this->noImageFile;
  14806. $w = ($info['w'] * (25.4/$this->dpi));
  14807. $h = ($info['h'] * (25.4/$this->dpi));
  14808. }
  14809. }
  14810. if(!$info) break;
  14811. if ($info['cs']=='Indexed') { $objattr['Indexed'] = true; }
  14812. $objattr['file'] = $srcpath;
  14813. //Default width and height calculation if needed
  14814. if($w==0 and $h==0) {
  14815. /*-- IMAGES-WMF --*/
  14816. if ($info['type']=='wmf') {
  14817. // WMF units are twips (1/20pt)
  14818. // divide by 20 to get points
  14819. // divide by k to get user units
  14820. $w = abs($info['w'])/(20*_MPDFK);
  14821. $h = abs($info['h']) / (20*_MPDFK);
  14822. }
  14823. else
  14824. /*-- END IMAGES-WMF --*/
  14825. if ($info['type']=='svg') {
  14826. // SVG units are pixels
  14827. $w = abs($info['w'])/_MPDFK;
  14828. $h = abs($info['h'])/_MPDFK;
  14829. }
  14830. else {
  14831. //Put image at default image dpi
  14832. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  14833. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  14834. }
  14835. if (isset($properties['IMAGE-RESOLUTION'])) {
  14836. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  14837. $w *= $this->img_dpi / $info['set-dpi'];
  14838. $h *= $this->img_dpi / $info['set-dpi'];
  14839. }
  14840. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  14841. $dpi = $m[1];
  14842. if ($dpi > 0) {
  14843. $w *= $this->img_dpi / $dpi;
  14844. $h *= $this->img_dpi / $dpi;
  14845. }
  14846. }
  14847. }
  14848. }
  14849. // IF WIDTH OR HEIGHT SPECIFIED
  14850. if($w==0) $w=$h*$info['w']/$info['h'];
  14851. if($h==0) $h=$w*$info['h']/$info['w'];
  14852. // Resize to maximum dimensions of page
  14853. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  14854. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  14855. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  14856. if ($w + $extrawidth > $maxWidth ) {
  14857. $w = $maxWidth - $extrawidth;
  14858. $h=$w*$info['h']/$info['w'];
  14859. }
  14860. if ($h + $extraheight > $maxHeight ) {
  14861. $h = $maxHeight - $extraheight;
  14862. $w=$h*$info['w']/$info['h'];
  14863. }
  14864. $height = $h + $extraheight;
  14865. $width = $w + $extrawidth;
  14866. $objattr['type'] = 'image';
  14867. $objattr['itype'] = $info['type'];
  14868. $objattr['orig_h'] = $info['h'];
  14869. $objattr['orig_w'] = $info['w'];
  14870. /*-- IMAGES-WMF --*/
  14871. if ($info['type']=='wmf') {
  14872. $objattr['wmf_x'] = $info['x'];
  14873. $objattr['wmf_y'] = $info['y'];
  14874. }
  14875. else
  14876. /*-- END IMAGES-WMF --*/
  14877. if ($info['type']=='svg') {
  14878. $objattr['wmf_x'] = $info['x'];
  14879. $objattr['wmf_y'] = $info['y'];
  14880. }
  14881. $objattr['height'] = $h + $extraheight;
  14882. $objattr['width'] = $w + $extrawidth;
  14883. $objattr['image_height'] = $h;
  14884. $objattr['image_width'] = $w;
  14885. $objattr['ID'] = $info['i'];
  14886. $texto = 'X';
  14887. if ($this->useActiveForms) {
  14888. if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; }
  14889. $objattr['type'] = 'input';
  14890. $type = 'IMAGE';
  14891. }
  14892. break;
  14893. }
  14894. /*-- END IMAGES-CORE --*/
  14895. case 'BUTTON': // Draw a button
  14896. case 'SUBMIT':
  14897. case 'RESET':
  14898. $type = strtoupper($attr['TYPE']);
  14899. if ($type=='IMAGE') { $type = 'BUTTON'; } // src path not found
  14900. if(isset($attr['NOPRINT'])) { $objattr['noprint'] = true; }
  14901. if (!isset($attr['VALUE'])) {
  14902. $objattr['value'] = ucfirst(strtolower($type));
  14903. }
  14904. $texto = " " . $objattr['value'] . " ";
  14905. $width = $this->GetStringWidth($texto) + ($this->form->form_element_spacing['button']['outer']['h']*2)+($this->form->form_element_spacing['button']['inner']['h']*2);
  14906. $height = $this->FontSize + ($this->form->form_element_spacing['button']['outer']['v']*2)+($this->form->form_element_spacing['button']['inner']['v']*2);
  14907. if ($this->useActiveForms) {
  14908. if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; }
  14909. }
  14910. break;
  14911. case 'PASSWORD':
  14912. case 'TEXT':
  14913. default:
  14914. if ($type == '') { $type = 'TEXT'; }
  14915. if(strtoupper($attr['TYPE'])=='PASSWORD') { $type = 'PASSWORD'; }
  14916. if (isset($attr['VALUE'])) {
  14917. if ($type == 'PASSWORD') {
  14918. $num_stars = mb_strlen($attr['VALUE'],$this->mb_enc );
  14919. $texto = str_repeat('*',$num_stars);
  14920. }
  14921. else { $texto = $attr['VALUE']; }
  14922. }
  14923. $xw = ($this->form->form_element_spacing['input']['outer']['h']*2)+($this->form->form_element_spacing['input']['inner']['h']*2);
  14924. $xh = ($this->form->form_element_spacing['input']['outer']['v']*2)+($this->form->form_element_spacing['input']['inner']['v']*2);
  14925. if ($w) { $width = $w + $xw; }
  14926. else { $width = (20 * $spacesize) + $xw; } // Default width in chars
  14927. if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $width = ($attr['SIZE'] * $spacesize) + $xw;
  14928. $height = $this->FontSize + $xh;
  14929. if (isset($attr['MAXLENGTH']) and ctype_digit($attr['MAXLENGTH']) ) $objattr['maxlength'] = $attr['MAXLENGTH'];
  14930. if ($this->useActiveForms) {
  14931. if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; }
  14932. else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; }
  14933. if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; }
  14934. if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; }
  14935. if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; }
  14936. }
  14937. break;
  14938. }
  14939. $objattr['subtype'] = $type;
  14940. $objattr['text'] = $texto;
  14941. $objattr['width'] = $width;
  14942. $objattr['height'] = $height;
  14943. $e = "\xbb\xa4\xactype=input,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14944. // Clear properties - tidy up
  14945. $properties = array();
  14946. /*-- TABLES --*/
  14947. // Output it to buffers
  14948. if ($this->tableLevel) {
  14949. $this->_saveCellTextBuffer($e, $this->HREF);
  14950. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  14951. }
  14952. else {
  14953. /*-- END TABLES --*/
  14954. $this->_saveTextBuffer($e, $this->HREF);
  14955. } // *TABLES*
  14956. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  14957. unset($this->InlineProperties[$tag]);
  14958. break; // END of INPUT
  14959. /*-- END FORMS --*/
  14960. // *********** GRAPH ********************
  14961. case 'JPGRAPH':
  14962. if (!$this->useGraphs) { break; }
  14963. if ($attr['TABLE']) { $gid = strtoupper($attr['TABLE']); }
  14964. else { $gid = '0'; }
  14965. if (!is_array($this->graphs[$gid]) || count($this->graphs[$gid])==0 ) { break; }
  14966. include_once(_MPDF_PATH.'graph.php');
  14967. $this->graphs[$gid]['attr'] = $attr;
  14968. if (isset($this->graphs[$gid]['attr']['WIDTH']) && $this->graphs[$gid]['attr']['WIDTH']) {
  14969. $this->graphs[$gid]['attr']['cWIDTH']=$this->ConvertSize($this->graphs[$gid]['attr']['WIDTH'],$pgwidth);
  14970. } // mm
  14971. if (isset($this->graphs[$gid]['attr']['HEIGHT']) && $this->graphs[$gid]['attr']['HEIGHT']) {
  14972. $this->graphs[$gid]['attr']['cHEIGHT']=$this->ConvertSize($this->graphs[$gid]['attr']['HEIGHT'],$pgwidth);
  14973. }
  14974. $graph_img = print_graph($this->graphs[$gid],$this->blk[$this->blklvl]['inner_width']);
  14975. if ($graph_img) {
  14976. if(isset($attr['ROTATE'])) {
  14977. if ($attr['ROTATE']==90 || $attr['ROTATE']==-90) {
  14978. $tmpw = $graph_img['w'];
  14979. $graph_img['w']= $graph_img['h'];
  14980. $graph_img['h']= $tmpw;
  14981. }
  14982. }
  14983. $attr['SRC'] = $graph_img['file'];
  14984. $attr['WIDTH'] = $graph_img['w'];
  14985. $attr['HEIGHT'] = $graph_img['h'];
  14986. }
  14987. else { break; }
  14988. // *********** IMAGE ********************
  14989. /*-- IMAGES-CORE --*/
  14990. case 'IMG':
  14991. if ($this->progressBar) { $this->UpdateProgressBar(1,'','IMG'); } // *PROGRESS-BAR*
  14992. $objattr = array();
  14993. $objattr['margin_top'] = 0;
  14994. $objattr['margin_bottom'] = 0;
  14995. $objattr['margin_left'] = 0;
  14996. $objattr['margin_right'] = 0;
  14997. $objattr['padding_top'] = 0;
  14998. $objattr['padding_bottom'] = 0;
  14999. $objattr['padding_left'] = 0;
  15000. $objattr['padding_right'] = 0;
  15001. $objattr['width'] = 0;
  15002. $objattr['height'] = 0;
  15003. $objattr['border_top']['w'] = 0;
  15004. $objattr['border_bottom']['w'] = 0;
  15005. $objattr['border_left']['w'] = 0;
  15006. $objattr['border_right']['w'] = 0;
  15007. if(isset($attr['SRC'])) {
  15008. $srcpath = $attr['SRC'];
  15009. $orig_srcpath = $attr['ORIG_SRC'];
  15010. $properties = $this->cssmgr->MergeCSS('',$tag,$attr);
  15011. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15012. return;
  15013. }
  15014. // mPDF 5.6.01 - LAYERS
  15015. if (isset($properties['Z-INDEX']) && $this->currentlayer==0) {
  15016. $v = intval($properties['Z-INDEX']);
  15017. if ($v > 0) {
  15018. $objattr['z-index'] = $v;
  15019. }
  15020. }
  15021. $objattr['visibility'] = 'visible';
  15022. if (isset($properties['VISIBILITY'])) {
  15023. $v = strtolower($properties['VISIBILITY']);
  15024. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  15025. $objattr['visibility'] = $v;
  15026. }
  15027. }
  15028. // VSPACE and HSPACE converted to margins in MergeCSS
  15029. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15030. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15031. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15032. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15033. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15034. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15035. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15036. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15037. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15038. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15039. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15040. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15041. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15042. $w = 0;
  15043. $h = 0;
  15044. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15045. else if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15046. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15047. else if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15048. // mPDF 5.5.15 // mPDF 5.6.60
  15049. $maxw=$maxh=$minw=$minh=false;
  15050. if(isset($properties['MAX-WIDTH'])) $maxw = $this->ConvertSize($properties['MAX-WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15051. else if(isset($attr['MAX-WIDTH'])) $maxw = $this->ConvertSize($attr['MAX-WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15052. if(isset($properties['MAX-HEIGHT'])) $maxh = $this->ConvertSize($properties['MAX-HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15053. else if(isset($attr['MAX-HEIGHT'])) $maxh = $this->ConvertSize($attr['MAX-HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15054. if(isset($properties['MIN-WIDTH'])) $minw = $this->ConvertSize($properties['MIN-WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15055. else if(isset($attr['MIN-WIDTH'])) $minw = $this->ConvertSize($attr['MIN-WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15056. if(isset($properties['MIN-HEIGHT'])) $minh = $this->ConvertSize($properties['MIN-HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15057. else if(isset($attr['MIN-HEIGHT'])) $minh = $this->ConvertSize($attr['MIN-HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15058. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  15059. if ($this->HREF) {
  15060. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  15061. $href = $this->HREF;
  15062. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  15063. $this->internallink[$href] = $this->AddLink();
  15064. $objattr['link'] = $this->internallink[$href];
  15065. }
  15066. else { $objattr['link'] = $this->HREF; }
  15067. }
  15068. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15069. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15070. /*-- BACKGROUNDS --*/
  15071. if(isset($properties['GRADIENT-MASK']) && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['GRADIENT-MASK'])) {
  15072. $objattr['GRADIENT-MASK'] = $properties['GRADIENT-MASK'];
  15073. }
  15074. /*-- END BACKGROUNDS --*/
  15075. // Image file
  15076. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  15077. if(!$info) {
  15078. $info = $this->_getImage($this->noImageFile);
  15079. if ($info) {
  15080. $srcpath = $this->noImageFile;
  15081. $w = ($info['w'] * (25.4/$this->dpi));
  15082. $h = ($info['h'] * (25.4/$this->dpi));
  15083. }
  15084. }
  15085. if(!$info) break;
  15086. if(isset($attr['ROTATE'])) { $image_orientation = $attr['ROTATE']; }
  15087. else if(isset($properties['IMAGE-ORIENTATION'])) { $image_orientation = $properties['IMAGE-ORIENTATION']; }
  15088. else { $image_orientation = 0; }
  15089. if($image_orientation) {
  15090. if ($image_orientation==90 || $image_orientation==-90 || $image_orientation==270) {
  15091. $tmpw = $info['w'];
  15092. $info['w'] = $info['h'];
  15093. $info['h'] = $tmpw;
  15094. }
  15095. $objattr['ROTATE'] = $image_orientation;
  15096. }
  15097. $objattr['file'] = $srcpath;
  15098. //Default width and height calculation if needed
  15099. if($w==0 and $h==0) {
  15100. /*-- IMAGES-WMF --*/
  15101. if ($info['type']=='wmf') {
  15102. // WMF units are twips (1/20pt)
  15103. // divide by 20 to get points
  15104. // divide by k to get user units
  15105. $w = abs($info['w'])/(20*_MPDFK);
  15106. $h = abs($info['h']) / (20*_MPDFK);
  15107. }
  15108. else
  15109. /*-- END IMAGES-WMF --*/
  15110. if ($info['type']=='svg') {
  15111. // SVG units are pixels
  15112. $w = abs($info['w'])/_MPDFK;
  15113. $h = abs($info['h'])/_MPDFK;
  15114. }
  15115. else {
  15116. //Put image at default image dpi
  15117. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  15118. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  15119. }
  15120. if (isset($properties['IMAGE-RESOLUTION'])) {
  15121. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  15122. $w *= $this->img_dpi / $info['set-dpi'];
  15123. $h *= $this->img_dpi / $info['set-dpi'];
  15124. }
  15125. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  15126. $dpi = $m[1];
  15127. if ($dpi > 0) {
  15128. $w *= $this->img_dpi / $dpi;
  15129. $h *= $this->img_dpi / $dpi;
  15130. }
  15131. }
  15132. }
  15133. }
  15134. // IF WIDTH OR HEIGHT SPECIFIED
  15135. if($w==0) $w=abs($h*$info['w']/$info['h']);
  15136. if($h==0) $h=abs($w*$info['h']/$info['w']);
  15137. // mPDF 5.5.15
  15138. if ($minw && $w<$minw) { $w = $minw; $h=abs($w*$info['h']/$info['w']); }
  15139. if ($maxw && $w>$maxw) { $w = $maxw; $h=abs($w*$info['h']/$info['w']); }
  15140. if ($minh && $h<$minh) { $h = $minh; $w=abs($h*$info['w']/$info['h']); }
  15141. if ($maxh && $h>$maxh) { $h = $maxh; $w=abs($h*$info['w']/$info['h']); }
  15142. // Resize to maximum dimensions of page
  15143. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  15144. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  15145. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  15146. if ($w + $extrawidth > $maxWidth ) {
  15147. $w = $maxWidth - $extrawidth;
  15148. $h=abs($w*$info['h']/$info['w']);
  15149. }
  15150. if ($h + $extraheight > $maxHeight ) {
  15151. $h = $maxHeight - $extraheight;
  15152. $w=abs($h*$info['w']/$info['h']);
  15153. }
  15154. $objattr['type'] = 'image';
  15155. $objattr['itype'] = $info['type'];
  15156. $objattr['orig_h'] = $info['h'];
  15157. $objattr['orig_w'] = $info['w'];
  15158. /*-- IMAGES-WMF --*/
  15159. if ($info['type']=='wmf') {
  15160. $objattr['wmf_x'] = $info['x'];
  15161. $objattr['wmf_y'] = $info['y'];
  15162. }
  15163. else
  15164. /*-- END IMAGES-WMF --*/
  15165. if ($info['type']=='svg') {
  15166. $objattr['wmf_x'] = $info['x'];
  15167. $objattr['wmf_y'] = $info['y'];
  15168. }
  15169. $objattr['height'] = $h + $extraheight;
  15170. $objattr['width'] = $w + $extrawidth;
  15171. $objattr['image_height'] = $h;
  15172. $objattr['image_width'] = $w;
  15173. /*-- CSS-IMAGE-FLOAT --*/
  15174. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  15175. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  15176. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  15177. }
  15178. }
  15179. /*-- END CSS-IMAGE-FLOAT --*/
  15180. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15181. // Clear properties - tidy up
  15182. $properties = array();
  15183. /*-- TABLES --*/
  15184. // Output it to buffers
  15185. if ($this->tableLevel) {
  15186. $this->_saveCellTextBuffer($e, $this->HREF);
  15187. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15188. }
  15189. else {
  15190. /*-- END TABLES --*/
  15191. $this->_saveTextBuffer($e, $this->HREF);
  15192. } // *TABLES*
  15193. /*-- ANNOTATIONS --*/
  15194. if ($this->title2annots && isset($attr['TITLE'])) {
  15195. $objattr = array();
  15196. $objattr['margin_top'] = 0;
  15197. $objattr['margin_bottom'] = 0;
  15198. $objattr['margin_left'] = 0;
  15199. $objattr['margin_right'] = 0;
  15200. $objattr['width'] = 0;
  15201. $objattr['height'] = 0;
  15202. $objattr['border_top']['w'] = 0;
  15203. $objattr['border_bottom']['w'] = 0;
  15204. $objattr['border_left']['w'] = 0;
  15205. $objattr['border_right']['w'] = 0;
  15206. $objattr['CONTENT'] = $attr['TITLE'];
  15207. $objattr['type'] = 'annot';
  15208. $objattr['POS-X'] = 0;
  15209. $objattr['POS-Y'] = 0;
  15210. $objattr['ICON'] = 'Comment';
  15211. $objattr['AUTHOR'] = '';
  15212. $objattr['SUBJECT'] = '';
  15213. $objattr['OPACITY'] = $this->annotOpacity;
  15214. $objattr['COLOR'] = $this->ConvertColor('yellow');
  15215. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15216. if($this->tableLevel) { // *TABLES*
  15217. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); // *TABLES*
  15218. } // *TABLES*
  15219. else { // *TABLES*
  15220. $this->textbuffer[] = array($e);
  15221. } // *TABLES*
  15222. }
  15223. /*-- END ANNOTATIONS --*/
  15224. }
  15225. break;
  15226. /*-- END IMAGES-CORE --*/
  15227. // *********** CIRCULAR TEXT = TEXTCIRCLE ********************
  15228. case 'TEXTCIRCLE':
  15229. $objattr = array();
  15230. $objattr['margin_top'] = 0;
  15231. $objattr['margin_bottom'] = 0;
  15232. $objattr['margin_left'] = 0;
  15233. $objattr['margin_right'] = 0;
  15234. $objattr['padding_top'] = 0;
  15235. $objattr['padding_bottom'] = 0;
  15236. $objattr['padding_left'] = 0;
  15237. $objattr['padding_right'] = 0;
  15238. $objattr['width'] = 0;
  15239. $objattr['height'] = 0;
  15240. $objattr['border_top']['w'] = 0;
  15241. $objattr['border_bottom']['w'] = 0;
  15242. $objattr['border_left']['w'] = 0;
  15243. $objattr['border_right']['w'] = 0;
  15244. $objattr['top-text'] = '';
  15245. $objattr['bottom-text'] = '';
  15246. $objattr['r'] = 20; // radius (default value here for safety)
  15247. $objattr['space-width'] = 120;
  15248. $objattr['char-width'] = 100;
  15249. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15250. $properties = $this->cssmgr->MergeCSS('INLINE',$tag,$attr);
  15251. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15252. return;
  15253. }
  15254. if (isset($attr['R'])) { $objattr['r']=$this->ConvertSize($attr['R'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15255. if(isset($attr['TOP-TEXT'])) {
  15256. $objattr['top-text'] = strcode2utf($attr['TOP-TEXT']);
  15257. $objattr['top-text'] = $this->lesser_entity_decode($objattr['top-text']);
  15258. if ($this->onlyCoreFonts)
  15259. $objattr['top-text'] = mb_convert_encoding($objattr['top-text'], $this->mb_enc,'UTF-8');
  15260. }
  15261. if(isset($attr['BOTTOM-TEXT'])) {
  15262. $objattr['bottom-text'] = strcode2utf($attr['BOTTOM-TEXT']);
  15263. $objattr['bottom-text'] = $this->lesser_entity_decode($objattr['bottom-text']);
  15264. if ($this->onlyCoreFonts)
  15265. $objattr['bottom-text'] = mb_convert_encoding($objattr['bottom-text'], $this->mb_enc,'UTF-8');
  15266. }
  15267. if(isset($attr['SPACE-WIDTH']) && $attr['SPACE-WIDTH']) { $objattr['space-width'] = $attr['SPACE-WIDTH']; }
  15268. if(isset($attr['CHAR-WIDTH']) && $attr['CHAR-WIDTH']) { $objattr['char-width'] = $attr['CHAR-WIDTH']; }
  15269. // VISIBILITY
  15270. $objattr['visibility'] = 'visible';
  15271. if (isset($properties['VISIBILITY'])) {
  15272. $v = strtolower($properties['VISIBILITY']);
  15273. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  15274. $objattr['visibility'] = $v;
  15275. }
  15276. }
  15277. // mPDF 5.5.23
  15278. if (isset($properties['FONT-SIZE'])) {
  15279. if (strtolower($properties['FONT-SIZE'])=='auto') {
  15280. if ($objattr['top-text'] && $objattr['bottom-text']) {
  15281. $objattr['fontsize'] = -2;
  15282. }
  15283. else {
  15284. $objattr['fontsize'] = -1;
  15285. }
  15286. }
  15287. else {
  15288. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK));
  15289. $this->SetFontSize($mmsize*_MPDFK,false);
  15290. $objattr['fontsize'] = $this->FontSizePt;
  15291. }
  15292. }
  15293. // mPDF 5.5.23
  15294. if(isset($attr['DIVIDER'])) {
  15295. $objattr['divider'] = strcode2utf($attr['DIVIDER']);
  15296. $objattr['divider'] = $this->lesser_entity_decode($objattr['divider']);
  15297. if ($this->onlyCoreFonts)
  15298. $objattr['divider'] = mb_convert_encoding($objattr['divider'], $this->mb_enc,'UTF-8');
  15299. }
  15300. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15301. $objattr['fontstyle'] = '';
  15302. if (isset($properties['FONT-WEIGHT'])) {
  15303. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $objattr['fontstyle'] .= 'B'; }
  15304. }
  15305. if (isset($properties['FONT-STYLE'])) {
  15306. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $objattr['fontstyle'] .= 'I'; }
  15307. }
  15308. if (isset($properties['FONT-FAMILY'])) {
  15309. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15310. }
  15311. $objattr['fontfamily'] = $this->FontFamily;
  15312. // VSPACE and HSPACE converted to margins in MergeCSS
  15313. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15314. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15315. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15316. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15317. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15318. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15319. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15320. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15321. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15322. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15323. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15324. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15325. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  15326. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15327. else { $objattr['bgcolor'] = false; }
  15328. if ($this->HREF) {
  15329. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  15330. $href = $this->HREF;
  15331. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  15332. $this->internallink[$href] = $this->AddLink();
  15333. $objattr['link'] = $this->internallink[$href];
  15334. }
  15335. else { $objattr['link'] = $this->HREF; }
  15336. }
  15337. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15338. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15339. $w = $objattr['r']*2;
  15340. $h = $w;
  15341. $objattr['height'] = $h + $extraheight;
  15342. $objattr['width'] = $w + $extrawidth;
  15343. $objattr['type'] = 'textcircle';
  15344. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15345. // Clear properties - tidy up
  15346. $properties = array();
  15347. /*-- TABLES --*/
  15348. // Output it to buffers
  15349. if ($this->tableLevel) {
  15350. $this->_saveCellTextBuffer($e, $this->HREF);
  15351. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15352. }
  15353. else {
  15354. /*-- END TABLES --*/
  15355. $this->_saveTextBuffer($e, $this->HREF);
  15356. } // *TABLES*
  15357. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  15358. unset($this->InlineProperties[$tag]);
  15359. break;
  15360. /*-- TABLES --*/
  15361. case 'TABLE': // TABLE-BEGIN
  15362. $this->tdbegin = false;
  15363. $this->lastoptionaltag = '';
  15364. // Disable vertical justification in columns
  15365. if ($this->ColActive) { $this->colvAlign = ''; } // *COLUMNS*
  15366. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  15367. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  15368. // called from block after new div e.g. <div> ... <table> ... Outputs block top margin/border and padding
  15369. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  15370. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']);
  15371. $this->finishFlowingBlock(true); // true = END of flowing block
  15372. }
  15373. else if (!$this->tableLevel && count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  15374. $this->textbuffer=array();
  15375. $this->lastblocklevelchange = -1;
  15376. if ($this->tableLevel) { // i.e. now a nested table coming...
  15377. // Save current level table
  15378. // mPDF 5.4.10
  15379. $this->cell['PARENTCELL'] = $this->saveInlineProperties();
  15380. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties']= $this->base_table_properties;
  15381. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  15382. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'] = $this->row;
  15383. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'] = $this->col;
  15384. }
  15385. $this->tableLevel++;
  15386. $this->cssmgr->tbCSSlvl++;
  15387. if ($this->tableLevel>1) { // inherit table properties from cell in which nested
  15388. $this->base_table_properties['FONT-KERNING'] = $this->kerning ;
  15389. $this->base_table_properties['LETTER-SPACING'] = $this->lSpacingCSS ;
  15390. $this->base_table_properties['WORD-SPACING'] = $this->wSpacingCSS ;
  15391. }
  15392. if (isset($this->tbctr[$this->tableLevel])) { $this->tbctr[$this->tableLevel]++; }
  15393. else { $this->tbctr[$this->tableLevel] = 1; }
  15394. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['level'] = $this->tableLevel;
  15395. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['levelid'] = $this->tbctr[$this->tableLevel];
  15396. if ($this->tableLevel > $this->innermostTableLevel) { $this->innermostTableLevel = $this->tableLevel; }
  15397. if ($this->tableLevel > 1) {
  15398. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nestedpos'] = array($this->row,$this->col,$this->tbctr[($this->tableLevel-1)]);
  15399. }
  15400. //++++++++++++++++++++++++++++
  15401. $this->cell = array();
  15402. $this->col=-1; //int
  15403. $this->row=-1; //int
  15404. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  15405. // New table - any level
  15406. if ($this->cacheTables) {
  15407. $this->packTableData = true; // required for cacheTables
  15408. $this->simpleTables = false; // Cannot co-exist with cacheTables
  15409. $table['cache'] = _MPDF_TEMP_PATH.'_tempTblCache'.RAND(1,1000000).'.dat';
  15410. $fh = fopen($table['cache'] , "wb") or $this->Error("When using cacheTables, you must have read/write access to cache files (".$table['cache'] .")");
  15411. fwrite($fh, "\x00");
  15412. fclose($fh);
  15413. $table['ptr'] = 1 ; // Must not be 0
  15414. }
  15415. $table['direction'] = $this->directionality;
  15416. $table['bgcolor'] = false;
  15417. $table['va'] = false;
  15418. $table['txta'] = false;
  15419. $table['topntail'] = false;
  15420. $table['thead-underline'] = false;
  15421. $table['border'] = false;
  15422. $table['border_details']['R']['w'] = 0;
  15423. $table['border_details']['L']['w'] = 0;
  15424. $table['border_details']['T']['w'] = 0;
  15425. $table['border_details']['B']['w'] = 0;
  15426. $table['border_details']['R']['style'] = '';
  15427. $table['border_details']['L']['style'] = '';
  15428. $table['border_details']['T']['style'] = '';
  15429. $table['border_details']['B']['style'] = '';
  15430. $table['max_cell_border_width']['R'] = 0;
  15431. $table['max_cell_border_width']['L'] = 0;
  15432. $table['max_cell_border_width']['T'] = 0;
  15433. $table['max_cell_border_width']['B'] = 0;
  15434. $table['padding']['L'] = false;
  15435. $table['padding']['R'] = false;
  15436. $table['padding']['T'] = false;
  15437. $table['padding']['B'] = false;
  15438. $table['margin']['L'] = false;
  15439. $table['margin']['R'] = false;
  15440. $table['margin']['T'] = false;
  15441. $table['margin']['B'] = false;
  15442. $table['a'] = false;
  15443. $table['border_spacing_H'] = false;
  15444. $table['border_spacing_V'] = false;
  15445. $table['decimal_align'] = false; // mPDF 5.6.13
  15446. $this->Reset();
  15447. $this->InlineProperties = array();
  15448. $this->spanlvl = 0;
  15449. $table['nc'] = $table['nr'] = 0;
  15450. $this->tablethead = 0;
  15451. $this->tabletfoot = 0;
  15452. $this->tabletheadjustfinished = false;
  15453. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins && $this->tableLevel==1) { $lastbottommargin = $this->lastblockbottommargin; }
  15454. else { $lastbottommargin = 0; }
  15455. $this->lastblockbottommargin = 0;
  15456. $this->blockjustfinished=false;
  15457. if ($this->tableLevel==1) {
  15458. $this->tableCJK = false;
  15459. $this->table_lineheight = $this->normalLineheight;
  15460. $table['headernrows'] = 0;
  15461. $table['footernrows'] = 0;
  15462. $this->base_table_properties = array();
  15463. }
  15464. // ADDED CSS FUNCIONS FOR TABLE
  15465. if ($this->cssmgr->tbCSSlvl==1) {
  15466. $properties = $this->cssmgr->MergeCSS('TOPTABLE',$tag,$attr);
  15467. }
  15468. else {
  15469. $properties = $this->cssmgr->MergeCSS('TABLE',$tag,$attr);
  15470. }
  15471. $w = '';
  15472. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  15473. else if (isset($attr['WIDTH']) && $attr['WIDTH']) { $w = $attr['WIDTH']; }
  15474. if(isset($properties['DIRECTION']) && $properties['DIRECTION']) { $table['direction'] = strtolower($properties['DIRECTION']); }
  15475. else if(isset($attr['DIR']) && $attr['DIR']) { $table['direction'] = strtolower($attr['DIR']); }
  15476. else if (!isset($table['direction'])){ $table['direction'] = $this->blk[$this->blklvl]['direction']; }
  15477. if (isset($properties['BACKGROUND-COLOR'])) { $table['bgcolor'][-1] = $properties['BACKGROUND-COLOR']; }
  15478. else if (isset($properties['BACKGROUND'])) { $table['bgcolor'][-1] = $properties['BACKGROUND']; }
  15479. else if (isset($attr['BGCOLOR'])) { $table['bgcolor'][-1] = $attr['BGCOLOR']; }
  15480. if (isset($properties['VERTICAL-ALIGN'])) { $table['va'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15481. if (isset($properties['TEXT-ALIGN'])) { $table['txta'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15482. if (isset($attr['ALIGN'])) { $table['a'] = $align[strtolower($attr['ALIGN'])]; }
  15483. if (!$table['a']) {
  15484. if ($table['direction'] == 'rtl' ) { $table['a'] = 'R'; }
  15485. else { $table['a'] = 'L'; }
  15486. }
  15487. if (isset($properties['AUTOSIZE']) && $properties['AUTOSIZE'] && $this->tableLevel ==1) {
  15488. $this->shrink_this_table_to_fit = $properties['AUTOSIZE'];
  15489. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 0; }
  15490. }
  15491. if (isset($properties['ROTATE']) && $properties['ROTATE'] && $this->tableLevel ==1) {
  15492. $this->table_rotate = $properties['ROTATE'];
  15493. }
  15494. if (isset($properties['TOPNTAIL'])) { $table['topntail'] = $properties['TOPNTAIL']; }
  15495. if (isset($properties['THEAD-UNDERLINE'])) { $table['thead-underline'] = $properties['THEAD-UNDERLINE']; }
  15496. if (isset($properties['BORDER'])) {
  15497. $bord = $this->border_details($properties['BORDER']);
  15498. if ($bord['s']) {
  15499. $table['border'] = _BORDER_ALL;
  15500. $table['border_details']['R'] = $bord;
  15501. $table['border_details']['L'] = $bord;
  15502. $table['border_details']['T'] = $bord;
  15503. $table['border_details']['B'] = $bord;
  15504. }
  15505. }
  15506. if (isset($properties['BORDER-RIGHT'])) {
  15507. if ($table['direction'] == 'rtl') { // *RTL*
  15508. $table['border_details']['R'] = $this->border_details($properties['BORDER-LEFT']); // *RTL*
  15509. } // *RTL*
  15510. else { // *RTL*
  15511. $table['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  15512. } // *RTL*
  15513. $this->setBorder($table['border'], _BORDER_RIGHT, $table['border_details']['R']['s']);
  15514. }
  15515. if (isset($properties['BORDER-LEFT'])) {
  15516. if ($table['direction'] == 'rtl') { // *RTL*
  15517. $table['border_details']['L'] = $this->border_details($properties['BORDER-RIGHT']); // *RTL*
  15518. } // *RTL*
  15519. else { // *RTL*
  15520. $table['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  15521. } // *RTL*
  15522. $this->setBorder($table['border'], _BORDER_LEFT, $table['border_details']['L']['s']);
  15523. }
  15524. if (isset($properties['BORDER-BOTTOM'])) {
  15525. $table['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  15526. $this->setBorder($table['border'], _BORDER_BOTTOM, $table['border_details']['B']['s']);
  15527. }
  15528. if (isset($properties['BORDER-TOP'])) {
  15529. $table['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  15530. $this->setBorder($table['border'], _BORDER_TOP, $table['border_details']['T']['s']);
  15531. }
  15532. if ($table['border']){
  15533. $this->table_border_css_set = 1;
  15534. }
  15535. else {
  15536. $this->table_border_css_set = 0;
  15537. }
  15538. if (isset($properties['FONT-FAMILY'])) {
  15539. $this->default_font = $properties['FONT-FAMILY'];
  15540. $this->SetFont($this->default_font,'',0,false);
  15541. }
  15542. $this->base_table_properties['FONT-FAMILY'] = $this->FontFamily; // mPDF 5.4.10
  15543. if (isset($properties['FONT-SIZE'])) {
  15544. // mPDF 5.4.10
  15545. if ($this->tableLevel>1) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'], $this->base_table_properties['FONT-SIZE']); }
  15546. else { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK); }
  15547. if ($mmsize) {
  15548. $this->default_font_size = $mmsize*(_MPDFK);
  15549. $this->SetFontSize($this->default_font_size,false);
  15550. }
  15551. }
  15552. $this->base_table_properties['FONT-SIZE'] = $this->FontSize.'mm'; // mPDF 5.4.10
  15553. if (isset($properties['FONT-WEIGHT'])) {
  15554. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->base_table_properties['FONT-WEIGHT'] = 'BOLD'; }
  15555. }
  15556. if (isset($properties['FONT-STYLE'])) {
  15557. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->base_table_properties['FONT-STYLE'] = 'ITALIC'; }
  15558. }
  15559. if (isset($properties['COLOR'])) {
  15560. $this->base_table_properties['COLOR'] = $properties['COLOR'];
  15561. }
  15562. if (isset($properties['FONT-KERNING'])) {
  15563. $this->base_table_properties['FONT-KERNING'] = $properties['FONT-KERNING'];
  15564. }
  15565. if (isset($properties['LETTER-SPACING'])) {
  15566. $this->base_table_properties['LETTER-SPACING'] = $properties['LETTER-SPACING'];
  15567. }
  15568. if (isset($properties['WORD-SPACING'])) {
  15569. $this->base_table_properties['WORD-SPACING'] = $properties['WORD-SPACING'];
  15570. }
  15571. if (isset($properties['PADDING-LEFT'])) {
  15572. $table['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15573. }
  15574. if (isset($properties['PADDING-RIGHT'])) {
  15575. $table['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15576. }
  15577. if (isset($properties['PADDING-TOP'])) {
  15578. $table['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15579. }
  15580. if (isset($properties['PADDING-BOTTOM'])) {
  15581. $table['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15582. }
  15583. if (isset($properties['MARGIN-TOP'])) {
  15584. if ($lastbottommargin) {
  15585. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15586. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  15587. else { $properties['MARGIN-TOP'] = 0; }
  15588. }
  15589. $table['margin']['T'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15590. }
  15591. if (isset($properties['MARGIN-BOTTOM'])) {
  15592. $table['margin']['B'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15593. }
  15594. if (isset($properties['MARGIN-LEFT'])) {
  15595. $table['margin']['L'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15596. }
  15597. if (isset($properties['MARGIN-RIGHT'])) {
  15598. $table['margin']['R'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15599. }
  15600. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  15601. $table['a'] = 'C';
  15602. }
  15603. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  15604. $table['a'] = 'R';
  15605. }
  15606. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  15607. $table['a'] = 'L';
  15608. }
  15609. if (isset($properties['LINE-HEIGHT']) && $this->tableLevel==1) {
  15610. $this->table_lineheight = $this->fixLineheight($properties['LINE-HEIGHT']);
  15611. if (!$this->table_lineheight) { $this->table_lineheight = $this->normalLineheight; }
  15612. }
  15613. if (isset($properties['BORDER-COLLAPSE']) && strtoupper($properties['BORDER-COLLAPSE'])=='SEPARATE') {
  15614. $table['borders_separate'] = true;
  15615. }
  15616. else {
  15617. $table['borders_separate'] = false;
  15618. }
  15619. if (!$table['borders_separate']) { $table['border_spacing_H'] = $table['border_spacing_V'] = 0; }
  15620. else if (isset($attr['CELLSPACING'])) {
  15621. $table['border_spacing_H'] = $table['border_spacing_V'] = $this->ConvertSize($attr['CELLSPACING'],$this->blk[$this->blklvl]['inner_width']);
  15622. }
  15623. if (isset($properties['BORDER-SPACING-H'])) {
  15624. $table['border_spacing_H'] = $this->ConvertSize($properties['BORDER-SPACING-H'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15625. }
  15626. if (isset($properties['BORDER-SPACING-V'])) {
  15627. $table['border_spacing_V'] = $this->ConvertSize($properties['BORDER-SPACING-V'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15628. }
  15629. if (isset($properties['EMPTY-CELLS'])) {
  15630. $table['empty_cells'] = strtolower($properties['EMPTY-CELLS']); // 'hide' or 'show'
  15631. }
  15632. else { $table['empty_cells'] = ''; }
  15633. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE'])=='AVOID' && $this->tableLevel==1 && !$this->writingHTMLfooter) {
  15634. $this->table_keep_together = true;
  15635. }
  15636. else if ($this->tableLevel==1) {
  15637. $this->table_keep_together = false;
  15638. }
  15639. if (isset($properties['PAGE-BREAK-AFTER']) && $this->tableLevel==1) {
  15640. $table['page_break_after'] = strtoupper($properties['PAGE-BREAK-AFTER']);
  15641. }
  15642. /*-- BACKGROUNDS --*/
  15643. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $table['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  15644. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  15645. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  15646. if ($ret) { $table['background-image'] = $ret; }
  15647. }
  15648. /*-- END BACKGROUNDS --*/
  15649. if (isset($properties['OVERFLOW'])) {
  15650. $table['overflow'] = strtolower($properties['OVERFLOW']); // 'hidden' 'wrap' or 'visible' or 'auto'
  15651. if (($this->ColActive || $this->tableLevel>1) && $table['overflow']=='visible') { unset($table['overflow']); }
  15652. }
  15653. $properties = array();
  15654. if (isset($attr['CELLPADDING'])) {
  15655. $table['cell_padding'] = $attr['CELLPADDING'];
  15656. }
  15657. else {
  15658. $table['cell_padding'] = false;
  15659. }
  15660. if (isset($attr['BORDER']) && $attr['BORDER']=='1') { // mPDF 5.5.08
  15661. $this->table_border_attr_set = 1; // mPDF 5.5.08
  15662. $bord = $this->border_details('#000000 1px solid');
  15663. if ($bord['s']) {
  15664. $table['border'] = _BORDER_ALL;
  15665. $table['border_details']['R'] = $bord;
  15666. $table['border_details']['L'] = $bord;
  15667. $table['border_details']['T'] = $bord;
  15668. $table['border_details']['B'] = $bord;
  15669. }
  15670. }
  15671. else {
  15672. $this->table_border_attr_set = 0;
  15673. }
  15674. if ($w) {
  15675. $maxwidth = $this->blk[$this->blklvl]['inner_width'];
  15676. if ($table['borders_separate']) {
  15677. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['border_details']['L']['w']/2 + $table['border_details']['R']['w']/2;
  15678. }
  15679. else {
  15680. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2;
  15681. }
  15682. if (strpos($w,'%') && $this->tableLevel == 1 && !$this->ignore_table_percents ) {
  15683. // % needs to be of inner box without table margins etc.
  15684. $maxwidth -= $tblblw ;
  15685. $wmm = $this->ConvertSize($w,$maxwidth,$this->FontSize,false);
  15686. $table['w'] = $wmm + $tblblw ;
  15687. }
  15688. if (strpos($w,'%') && $this->tableLevel > 1 && !$this->ignore_table_percents && $this->keep_table_proportions) {
  15689. $table['wpercent'] = $w + 0; // makes 80% -> 80
  15690. }
  15691. if (!strpos($w,'%') && !$this->ignore_table_widths ) {
  15692. $wmm = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15693. $table['w'] = $wmm + $tblblw ;
  15694. }
  15695. if (!$this->keep_table_proportions) {
  15696. if (isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width']) { $table['w'] = $this->blk[$this->blklvl]['inner_width']; }
  15697. }
  15698. }
  15699. if (isset($attr['AUTOSIZE']) && $this->tableLevel==1) {
  15700. $this->shrink_this_table_to_fit = $attr['AUTOSIZE'];
  15701. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 1; }
  15702. }
  15703. if (isset($attr['ROTATE']) && $this->tableLevel==1) {
  15704. $this->table_rotate = $attr['ROTATE'];
  15705. }
  15706. //++++++++++++++++++++++++++++
  15707. // keeping block together on one page
  15708. // Autosize is now forced therefore keep block together disabled
  15709. if ($this->keep_block_together) {
  15710. $this->keep_block_together = 0;
  15711. $this->printdivbuffer();
  15712. $this->blk[$this->blklvl]['keep_block_together'] = 0;
  15713. }
  15714. if ($this->table_rotate) {
  15715. $this->tbrot_Links = array();
  15716. $this->tbrot_Annots = array();
  15717. $this->tbrotForms = array();
  15718. $this->tbrot_Reference = array();
  15719. $this->tbrot_BMoutlines = array();
  15720. $this->tbrot_toc = array();
  15721. }
  15722. if ($this->kwt) {
  15723. if ($this->table_rotate) { $this->table_keep_together = true; }
  15724. $this->kwt = false;
  15725. $this->kwt_saved = true;
  15726. }
  15727. if ($this->tableLevel==1 && $this->useGraphs) {
  15728. if (isset($attr['ID']) && $attr['ID']) { $this->currentGraphId = strtoupper($attr['ID']); }
  15729. else { $this->currentGraphId = '0'; }
  15730. $this->graphs[$this->currentGraphId] = array();
  15731. }
  15732. //++++++++++++++++++++++++++++
  15733. $this->plainCell_properties = array();
  15734. unset($table);
  15735. break;
  15736. case 'THEAD':
  15737. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15738. $this->cssmgr->tbCSSlvl++;
  15739. $this->tablethead = 1;
  15740. $this->tabletfoot = 0;
  15741. $properties = $this->cssmgr->MergeCSS('TABLE',$tag,$attr);
  15742. if (isset($properties['FONT-WEIGHT'])) {
  15743. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->thead_font_weight = 'B'; }
  15744. else { $this->thead_font_weight = ''; }
  15745. }
  15746. if (isset($properties['FONT-STYLE'])) {
  15747. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->thead_font_style = 'I'; }
  15748. else { $this->thead_font_style = ''; }
  15749. }
  15750. if (isset($properties['FONT-VARIANT'])) {
  15751. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->thead_font_smCaps = 'S'; }
  15752. else { $this->thead_font_smCaps = ''; }
  15753. }
  15754. if (isset($properties['VERTICAL-ALIGN'])) {
  15755. $this->thead_valign_default = $properties['VERTICAL-ALIGN'];
  15756. }
  15757. if (isset($properties['TEXT-ALIGN'])) {
  15758. $this->thead_textalign_default = $properties['TEXT-ALIGN'];
  15759. }
  15760. $properties = array();
  15761. break;
  15762. case 'TFOOT':
  15763. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15764. $this->cssmgr->tbCSSlvl++;
  15765. $this->tabletfoot = 1;
  15766. $this->tablethead = 0;
  15767. $properties = $this->cssmgr->MergeCSS('TABLE',$tag,$attr);
  15768. if (isset($properties['FONT-WEIGHT'])) {
  15769. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->tfoot_font_weight = 'B'; }
  15770. else { $this->tfoot_font_weight = ''; }
  15771. }
  15772. if (isset($properties['FONT-STYLE'])) {
  15773. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->tfoot_font_style = 'I'; }
  15774. else { $this->tfoot_font_style = ''; }
  15775. }
  15776. if (isset($properties['FONT-VARIANT'])) {
  15777. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->tfoot_font_smCaps = 'S'; }
  15778. else { $this->tfoot_font_smCaps = ''; }
  15779. }
  15780. if (isset($properties['VERTICAL-ALIGN'])) {
  15781. $this->tfoot_valign_default = $properties['VERTICAL-ALIGN'];
  15782. }
  15783. if (isset($properties['TEXT-ALIGN'])) {
  15784. $this->tfoot_textalign_default = $properties['TEXT-ALIGN'];
  15785. }
  15786. $properties = array();
  15787. break;
  15788. case 'TBODY':
  15789. $this->tablethead = 0;
  15790. $this->tabletfoot = 0;
  15791. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15792. $this->cssmgr->tbCSSlvl++;
  15793. $this->cssmgr->MergeCSS('TABLE',$tag,$attr);
  15794. break;
  15795. case 'TR':
  15796. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15797. $this->cssmgr->tbCSSlvl++;
  15798. $this->row++;
  15799. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']++;
  15800. $this->col = -1;
  15801. $properties = $this->cssmgr->MergeCSS('TABLE',$tag,$attr);
  15802. if (!$this->simpleTables && (!isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate']) || !$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate'])) {
  15803. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row] = $properties['BORDER-LEFT']; }
  15804. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row] = $properties['BORDER-RIGHT']; }
  15805. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-top'][$this->row] = $properties['BORDER-TOP']; }
  15806. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-bottom'][$this->row] = $properties['BORDER-BOTTOM']; }
  15807. }
  15808. if (isset($properties['BACKGROUND-COLOR'])) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $properties['BACKGROUND-COLOR']; }
  15809. else if (isset($attr['BGCOLOR'])) $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $attr['BGCOLOR'];
  15810. /*-- BACKGROUNDS --*/
  15811. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$this->row] = $properties['BACKGROUND-GRADIENT']; }
  15812. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  15813. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  15814. if ($ret) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$this->row] = $ret; }
  15815. }
  15816. /*-- END BACKGROUNDS --*/
  15817. if (isset($properties['TEXT-ROTATE'])) {
  15818. $this->trow_text_rotate = $properties['TEXT-ROTATE'];
  15819. }
  15820. if (isset($attr['TEXT-ROTATE'])) $this->trow_text_rotate = $attr['TEXT-ROTATE'];
  15821. if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; }
  15822. if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; }
  15823. $properties = array();
  15824. break;
  15825. case 'TH':
  15826. case 'TD':
  15827. $this->ignorefollowingspaces = true;
  15828. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15829. $this->cssmgr->tbCSSlvl++;
  15830. $this->InlineProperties = array();
  15831. $this->spanlvl = 0;
  15832. $this->tdbegin = true;
  15833. $this->col++;
  15834. while (isset($this->cell[$this->row][$this->col])) { $this->col++; }
  15835. //Update number column
  15836. 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; }
  15837. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  15838. $c = array('a' => false,
  15839. 'R' => false,
  15840. 'nowrap' => false,
  15841. 'bgcolor' => false,
  15842. 'padding' => array('L' => false,
  15843. 'R' => false,
  15844. 'T' => false,
  15845. 'B' => false
  15846. )
  15847. );
  15848. if ($this->simpleTables && $this->row==0 && $this->col==0){
  15849. $table['simple']['border'] = false;
  15850. $table['simple']['border_details']['R']['w'] = 0;
  15851. $table['simple']['border_details']['L']['w'] = 0;
  15852. $table['simple']['border_details']['T']['w'] = 0;
  15853. $table['simple']['border_details']['B']['w'] = 0;
  15854. $table['simple']['border_details']['R']['style'] = '';
  15855. $table['simple']['border_details']['L']['style'] = '';
  15856. $table['simple']['border_details']['T']['style'] = '';
  15857. $table['simple']['border_details']['B']['style'] = '';
  15858. }
  15859. else if (!$this->simpleTables) {
  15860. $c['border'] = false;
  15861. $c['border_details']['R']['w'] = 0;
  15862. $c['border_details']['L']['w'] = 0;
  15863. $c['border_details']['T']['w'] = 0;
  15864. $c['border_details']['B']['w'] = 0;
  15865. $c['border_details']['mbw']['BL'] = 0;
  15866. $c['border_details']['mbw']['BR'] = 0;
  15867. $c['border_details']['mbw']['RT'] = 0;
  15868. $c['border_details']['mbw']['RB'] = 0;
  15869. $c['border_details']['mbw']['TL'] = 0;
  15870. $c['border_details']['mbw']['TR'] = 0;
  15871. $c['border_details']['mbw']['LT'] = 0;
  15872. $c['border_details']['mbw']['LB'] = 0;
  15873. $c['border_details']['R']['style'] = '';
  15874. $c['border_details']['L']['style'] = '';
  15875. $c['border_details']['T']['style'] = '';
  15876. $c['border_details']['B']['style'] = '';
  15877. $c['border_details']['R']['s'] = 0;
  15878. $c['border_details']['L']['s'] = 0;
  15879. $c['border_details']['T']['s'] = 0;
  15880. $c['border_details']['B']['s'] = 0;
  15881. $c['border_details']['R']['c'] = $this->ConvertColor(0);
  15882. $c['border_details']['L']['c'] = $this->ConvertColor(0);
  15883. $c['border_details']['T']['c'] = $this->ConvertColor(0);
  15884. $c['border_details']['B']['c'] = $this->ConvertColor(0);
  15885. $c['border_details']['R']['dom'] = 0;
  15886. $c['border_details']['L']['dom'] = 0;
  15887. $c['border_details']['T']['dom'] = 0;
  15888. $c['border_details']['B']['dom'] = 0;
  15889. }
  15890. if ($table['va']) { $c['va'] = $table['va']; }
  15891. if ($table['txta']) { $c['a'] = $table['txta']; }
  15892. if ($this->table_border_attr_set) {
  15893. if ($table['border_details']) {
  15894. if (!$this->simpleTables){
  15895. $c['border_details']['R'] = $table['border_details']['R'];
  15896. $c['border_details']['L'] = $table['border_details']['L'];
  15897. $c['border_details']['T'] = $table['border_details']['T'];
  15898. $c['border_details']['B'] = $table['border_details']['B'];
  15899. $c['border'] = $table['border'];
  15900. $c['border_details']['L']['dom'] = 1;
  15901. $c['border_details']['R']['dom'] = 1;
  15902. $c['border_details']['T']['dom'] = 1;
  15903. $c['border_details']['B']['dom'] = 1;
  15904. }
  15905. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  15906. $table['simple']['border_details']['R'] = $table['border_details']['R'];
  15907. $table['simple']['border_details']['L'] = $table['border_details']['L'];
  15908. $table['simple']['border_details']['T'] = $table['border_details']['T'];
  15909. $table['simple']['border_details']['B'] = $table['border_details']['B'];
  15910. $table['simple']['border'] = $table['border'];
  15911. }
  15912. }
  15913. }
  15914. // INHERITED THEAD CSS Properties
  15915. if ($this->tablethead) {
  15916. if ($this->thead_valign_default) $c['va'] = $align[strtolower($this->thead_valign_default)];
  15917. if ($this->thead_textalign_default) $c['a'] = $align[strtolower($this->thead_textalign_default)];
  15918. if ($this->thead_font_weight == 'B') { $this->SetStyle('B',true); }
  15919. if ($this->thead_font_style == 'I') { $this->SetStyle('I',true); }
  15920. if ($this->thead_font_smCaps == 'S') { $this->SetStyle('S',true); }
  15921. }
  15922. // INHERITED TFOOT CSS Properties
  15923. if ($this->tabletfoot) {
  15924. if ($this->tfoot_valign_default) $c['va'] = $align[strtolower($this->tfoot_valign_default)];
  15925. if ($this->tfoot_textalign_default) $c['a'] = $align[strtolower($this->tfoot_textalign_default)];
  15926. if ($this->tfoot_font_weight == 'B') { $this->SetStyle('B',true); }
  15927. if ($this->tfoot_font_style == 'I') { $this->SetStyle('I',true); }
  15928. if ($this->tfoot_font_style == 'S') { $this->SetStyle('S',true); }
  15929. }
  15930. if ($this->trow_text_rotate){
  15931. $c['R'] = $this->trow_text_rotate;
  15932. }
  15933. $this->cell_border_dominance_L = 0;
  15934. $this->cell_border_dominance_R = 0;
  15935. $this->cell_border_dominance_T = 0;
  15936. $this->cell_border_dominance_B = 0;
  15937. $properties = $this->cssmgr->MergeCSS('TABLE',$tag,$attr);
  15938. $properties = $this->cssmgr->array_merge_recursive_unique($this->base_table_properties, $properties);
  15939. if (isset($properties['FONT-KERNING']) && (strtoupper($properties['FONT-KERNING'])=='NORMAL' || strtoupper($properties['FONT-KERNING'])=='AUTO')) {
  15940. $this->kerning = true;
  15941. }
  15942. else { $this->kerning = false; }
  15943. if (isset($properties['LETTER-SPACING']) && ($properties['LETTER-SPACING'] || $properties['LETTER-SPACING']==='0') && strtoupper($properties['LETTER-SPACING']) != 'NORMAL') {
  15944. $this->lSpacingCSS = strtoupper($properties['LETTER-SPACING']);
  15945. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  15946. }
  15947. else {
  15948. $this->lSpacingCSS = '';
  15949. $this->fixedlSpacing = false;
  15950. }
  15951. if (isset($properties['WORD-SPACING']) && strtoupper($properties['WORD-SPACING']) != 'NORMAL') {
  15952. $this->wSpacingCSS = strtoupper($properties['WORD-SPACING']);
  15953. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  15954. }
  15955. else {
  15956. $this->minwSpacing = 0;
  15957. $this->wSpacingCSS = '';
  15958. }
  15959. // mPDF 5.6.08
  15960. if (isset($properties['HYPHENS']) && $properties['HYPHENS']) {
  15961. if (strtoupper($properties['HYPHENS']) == 'NONE') { $this->textparam['hyphens'] = 2; }
  15962. else if (strtoupper($properties['HYPHENS']) == 'AUTO') { $this->textparam['hyphens'] = 1; }
  15963. else if (strtoupper($properties['HYPHENS']) == 'MANUAL') { $this->textparam['hyphens'] = 0; }
  15964. }
  15965. if (isset($properties['BACKGROUND-COLOR'])) { $c['bgcolor'] = $properties['BACKGROUND-COLOR']; }
  15966. else if (isset($properties['BACKGROUND'])) { $c['bgcolor'] = $properties['BACKGROUND']; }
  15967. else if (isset($attr['BGCOLOR'])) $c['bgcolor'] = $attr['BGCOLOR'];
  15968. /*-- BACKGROUNDS --*/
  15969. if (isset($properties['BACKGROUND-GRADIENT'])) { $c['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  15970. else { $c['gradient'] = false; }
  15971. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->keep_block_together) {
  15972. $ret = $this->SetBackground($properties, $this->blk[$this->blklvl]['inner_width']);
  15973. if ($ret) { $c['background-image'] = $ret; }
  15974. }
  15975. /*-- END BACKGROUNDS --*/
  15976. if (isset($properties['VERTICAL-ALIGN'])) { $c['va']=$align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15977. else if (isset($attr['VALIGN'])) $c['va'] = $align[strtolower($attr['VALIGN'])];
  15978. // mPDF 5.6.13
  15979. if (isset($properties['TEXT-ALIGN']) && $properties['TEXT-ALIGN']) {
  15980. if (substr($properties['TEXT-ALIGN'],0,1)=='D') { $c['a'] = $properties['TEXT-ALIGN']; }
  15981. else { $c['a'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15982. }
  15983. // mPDF 5.6.13
  15984. if (isset($attr['ALIGN']) && $attr['ALIGN']) {
  15985. if (strtolower($attr['ALIGN']) == 'char') {
  15986. if (isset($attr['CHAR']) && $attr['CHAR']) {
  15987. $char = html_entity_decode($attr['CHAR']);
  15988. $char = strcode2utf($char);
  15989. $d = array_search($char,$this->decimal_align);
  15990. if ($d !== false) { $c['a'] = $d.'R'; }
  15991. }
  15992. else { $c['a'] = 'DPR'; }
  15993. }
  15994. else { $c['a'] = $align[strtolower($attr['ALIGN'])]; }
  15995. }
  15996. if (!$c['a']) {
  15997. if (isset($table['direction']) && $table['direction'] == 'rtl' ) { $c['a'] = 'R'; }
  15998. else { $c['a'] = 'L'; }
  15999. }
  16000. if (isset($properties['TEXT-ROTATE']) && ($properties['TEXT-ROTATE'] || $properties['TEXT-ROTATE']==="0")){
  16001. $c['R'] = $properties['TEXT-ROTATE'];
  16002. }
  16003. if (isset($properties['BORDER'])) {
  16004. $bord = $this->border_details($properties['BORDER']);
  16005. if ($bord['s']) {
  16006. if (!$this->simpleTables){
  16007. $c['border'] = _BORDER_ALL;
  16008. $c['border_details']['R'] = $bord;
  16009. $c['border_details']['L'] = $bord;
  16010. $c['border_details']['T'] = $bord;
  16011. $c['border_details']['B'] = $bord;
  16012. $c['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  16013. $c['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  16014. $c['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  16015. $c['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  16016. }
  16017. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16018. $table['simple']['border'] = _BORDER_ALL;
  16019. $table['simple']['border_details']['R'] = $bord;
  16020. $table['simple']['border_details']['L'] = $bord;
  16021. $table['simple']['border_details']['T'] = $bord;
  16022. $table['simple']['border_details']['B'] = $bord;
  16023. }
  16024. }
  16025. }
  16026. if (!$this->simpleTables){
  16027. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) {
  16028. $c['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  16029. $this->setBorder($c['border'], _BORDER_RIGHT, $c['border_details']['R']['s']);
  16030. $c['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  16031. }
  16032. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  16033. $c['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  16034. $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']);
  16035. $c['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  16036. }
  16037. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) {
  16038. $c['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  16039. $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']);
  16040. $c['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  16041. }
  16042. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) {
  16043. $c['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  16044. $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']);
  16045. $c['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  16046. }
  16047. }
  16048. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16049. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  16050. $bord = $this->border_details($properties['BORDER-LEFT']);
  16051. if ($bord['s']) { $table['simple']['border'] = _BORDER_ALL; }
  16052. else { $table['simple']['border'] = 0; }
  16053. $table['simple']['border_details']['R'] = $bord;
  16054. $table['simple']['border_details']['L'] = $bord;
  16055. $table['simple']['border_details']['T'] = $bord;
  16056. $table['simple']['border_details']['B'] = $bord;
  16057. }
  16058. }
  16059. if ($this->simpleTables && $this->row==0 && $this->col==0 && !$table['borders_separate'] && $table['simple']['border'] ){
  16060. $table['border_details'] = $table['simple']['border_details'];
  16061. $table['border'] = $table['simple']['border'];
  16062. }
  16063. // Border set on TR (if collapsed only)
  16064. if (!$table['borders_separate'] && !$this->simpleTables && isset($table['trborder-left'][$this->row])) {
  16065. if ($this->col==0) {
  16066. $left = $this->border_details($table['trborder-left'][$this->row]);
  16067. $c['border_details']['L'] = $left;
  16068. $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']);
  16069. }
  16070. $c['border_details']['B'] = $this->border_details($table['trborder-bottom'][$this->row]);
  16071. $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']);
  16072. $c['border_details']['T'] = $this->border_details($table['trborder-top'][$this->row]);
  16073. $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']);
  16074. }
  16075. if ($this->packTableData && !$this->simpleTables) {
  16076. $c['borderbin'] = $this->_packCellBorder($c);
  16077. unset($c['border']);
  16078. unset($c['border_details']);
  16079. }
  16080. if (isset($properties['PADDING-LEFT'])) {
  16081. $c['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16082. }
  16083. if (isset($properties['PADDING-RIGHT'])) {
  16084. $c['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16085. }
  16086. if (isset($properties['PADDING-BOTTOM'])) {
  16087. $c['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16088. }
  16089. if (isset($properties['PADDING-TOP'])) {
  16090. $c['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16091. }
  16092. $w = '';
  16093. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  16094. else if (isset($attr['WIDTH'])) { $w = $attr['WIDTH']; }
  16095. if ($w) {
  16096. if (strpos($w,'%') && !$this->ignore_table_percents ) { $c['wpercent'] = $w + 0; } // makes 80% -> 80
  16097. else if (!strpos($w,'%') && !$this->ignore_table_widths ) { $c['w'] = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16098. }
  16099. if (isset($properties['HEIGHT']) && !strpos($properties['HEIGHT'],'%')) { $c['h'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16100. else if (isset($attr['HEIGHT']) && !strpos($attr['HEIGHT'],'%')) $c['h'] = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16101. if (isset($properties['COLOR'])) {
  16102. $cor = $this->ConvertColor($properties['COLOR']);
  16103. if ($cor) {
  16104. $this->colorarray = $cor;
  16105. $this->SetTColor($cor);
  16106. }
  16107. }
  16108. if (isset($properties['FONT-FAMILY'])) {
  16109. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  16110. }
  16111. if (isset($properties['FONT-SIZE'])) {
  16112. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  16113. if ($mmsize) {
  16114. $this->SetFontSize($mmsize*(_MPDFK),false);
  16115. }
  16116. }
  16117. $c['dfs'] = $this->FontSize; // Default Font size
  16118. if (isset($properties['FONT-WEIGHT'])) {
  16119. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->SetStyle('B',true); }
  16120. }
  16121. if (isset($properties['FONT-STYLE'])) {
  16122. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->SetStyle('I',true); }
  16123. }
  16124. if (isset($properties['FONT-VARIANT'])) {
  16125. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->SetStyle('S',true); }
  16126. }
  16127. if (isset($properties['TEXT-DECORATION'])) {
  16128. if (strtoupper($properties['TEXT-DECORATION']) == 'LINE-THROUGH') { $this->strike = true; }
  16129. else if (strtoupper($properties['TEXT-DECORATION']) == 'UNDERLINE') { $this->SetStyle('U',true); }
  16130. }
  16131. if (isset($properties['TEXT-SHADOW'])) {
  16132. $ts = $this->cssmgr->setCSStextshadow($properties['TEXT-SHADOW']);
  16133. if ($ts) { $this->textshadow = $ts; }
  16134. }
  16135. if (isset($properties['TEXT-TRANSFORM'])) {
  16136. if (strtoupper($properties['TEXT-TRANSFORM']) == 'CAPITALIZE') { $this->capitalize = true; }
  16137. else if (strtoupper($properties['TEXT-TRANSFORM']) == 'UPPERCASE') { $this->toupper = true; }
  16138. else if (strtoupper($properties['TEXT-TRANSFORM']) == 'LOWERCASE') { $this->tolower = true; }
  16139. }
  16140. if (isset($properties['WHITE-SPACE'])) {
  16141. if (strtoupper($properties['WHITE-SPACE']) == 'NOWRAP') { $c['nowrap']= 1; }
  16142. }
  16143. $properties = array();
  16144. if (isset($attr['TEXT-ROTATE'])) {
  16145. $c['R'] = $attr['TEXT-ROTATE'];
  16146. }
  16147. if (isset($attr['NOWRAP']) && $attr['NOWRAP']) $c['nowrap']= 1;
  16148. $this->cell[$this->row][$this->col] = $c;
  16149. unset($c);
  16150. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16151. $cs = $rs = 1;
  16152. if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $this->cell[$this->row][$this->col]['colspan'] = $attr['COLSPAN'];
  16153. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+$cs) {
  16154. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+$cs;
  16155. } // following code moved outside if...
  16156. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  16157. if ($l-$this->col) $this->cell[$this->row][$l] = 0;
  16158. }
  16159. if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $this->cell[$this->row][$this->col]['rowspan'] = $attr['ROWSPAN'];
  16160. for ($k=$this->row ; $k < $this->row+$rs ;$k++) {
  16161. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  16162. if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0;
  16163. }
  16164. }
  16165. unset($table);
  16166. break;
  16167. /*-- END TABLES --*/
  16168. /*-- LISTS --*/
  16169. // *********** LISTS ********************
  16170. case 'OL':
  16171. case 'UL':
  16172. $this->listjustfinished = false;
  16173. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  16174. else { $lastbottommargin = 0; }
  16175. $this->lastblockbottommargin = 0;
  16176. $this->blockjustfinished=false;
  16177. $this->linebreakjustfinished=false;
  16178. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  16179. $this->cssmgr->listCSSlvl++;
  16180. if((!$this->tableLevel) && ($this->listlvl == 0)) {
  16181. $blockstate = 0;
  16182. //if ($this->lastblocklevelchange == 1) { $blockstate = -1; } // Top margins/padding only
  16183. //else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  16184. // called from block after new div e.g. <div> ... <ol> ... Outputs block top margin/border and padding
  16185. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  16186. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']);
  16187. $this->finishFlowingBlock(true); // true = END of flowing block
  16188. }
  16189. else if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  16190. $this->textbuffer=array();
  16191. $this->lastblocklevelchange = -1;
  16192. }
  16193. // ol and ul types are mixed here
  16194. if ($this->listlvl == 0) {
  16195. $this->list_indent = array();
  16196. $this->list_align = array();
  16197. $this->list_lineheight = array();
  16198. $this->InlineProperties['LIST'] = array();
  16199. $this->InlineProperties['LISTITEM'] = array();
  16200. }
  16201. /*-- TABLES --*/
  16202. // A simple list for inside a table
  16203. if($this->tableLevel) {
  16204. $this->list_indent[$this->listlvl] = 0; // mm default indent for each level
  16205. if ($tag == 'OL') $this->listtype = '1';
  16206. else if ($tag == 'UL') $this->listtype = 'disc';
  16207. if ($this->listlvl > 0) {
  16208. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16209. }
  16210. $this->listlvl++;
  16211. // mPDF 5.6.15
  16212. if (isset($attr['START'])) { $this->listnum = intval($attr['START']); }
  16213. else { $this->listnum = 0; }
  16214. $this->listlist[$this->listlvl] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16215. break;
  16216. }
  16217. /*-- END TABLES --*/
  16218. if (($this->PDFA || $this->PDFX) && $tag == 'UL') {
  16219. 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 '-')"; }
  16220. }
  16221. if ($this->cssmgr->listCSSlvl==1) {
  16222. $properties = $this->cssmgr->MergeCSS('TOPLIST',$tag,$attr);
  16223. }
  16224. else {
  16225. $properties = $this->cssmgr->MergeCSS('LIST',$tag,$attr);
  16226. }
  16227. if (!empty($properties)) $this->setCSS($properties,'LIST');
  16228. // List-type
  16229. $this->listtype = '';
  16230. if (isset($properties['LIST-STYLE-TYPE'])) {
  16231. $this->listtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  16232. }
  16233. else if (isset($properties['LIST-STYLE'])) {
  16234. $this->listtype = $this->_getListStyle($properties['LIST-STYLE']);
  16235. }
  16236. else if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listtype = $attr['TYPE']; }
  16237. if (!$this->listtype) {
  16238. if ($tag == 'OL') $this->listtype = '1';
  16239. if ($tag == 'UL') {
  16240. if ($this->listlvl % 3 == 0) $this->listtype = 'disc';
  16241. elseif ($this->listlvl % 3 == 1) $this->listtype = 'circle';
  16242. else $this->listtype = 'square';
  16243. }
  16244. }
  16245. if ($this->listlvl == 0) {
  16246. $this->inherit_lineheight = 0;
  16247. $this->listlvl++; // first depth level
  16248. // mPDF 5.6.15
  16249. if (isset($attr['START'])) { $this->listnum = intval($attr['START']); }
  16250. else { $this->listnum = 0; }
  16251. $this->listDir = (isset($this->blk[$this->blklvl]['direction']) ? $this->blk[$this->blklvl]['direction'] : null);
  16252. $occur = $this->listoccur[$this->listlvl] = 1;
  16253. $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16254. }
  16255. else {
  16256. if (!empty($this->textbuffer))
  16257. {
  16258. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16259. $this->listnum++;
  16260. }
  16261. // Save current lineheight to inherit
  16262. $this->textbuffer = array();
  16263. $occur = $this->listoccur[$this->listlvl];
  16264. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16265. $this->listlvl++;
  16266. // mPDF 5.6.15
  16267. if (isset($attr['START'])) { $this->listnum = intval($attr['START']); }
  16268. else { $this->listnum = 0; }
  16269. if (!isset($this->listoccur[$this->listlvl]) || $this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
  16270. else $this->listoccur[$this->listlvl]++;
  16271. $occur = $this->listoccur[$this->listlvl];
  16272. $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16273. }
  16274. // TOP LEVEL ONLY
  16275. if ($this->listlvl == 1) {
  16276. if (isset($properties['MARGIN-TOP'])) {
  16277. if ($lastbottommargin) {
  16278. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16279. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  16280. else { $properties['MARGIN-TOP'] = 0; }
  16281. }
  16282. $this->DivLn($this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false),$this->blklvl,true,1); // collapsible
  16283. }
  16284. if (isset($properties['MARGIN-BOTTOM'])) {
  16285. $this->list_margin_bottom = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16286. }
  16287. if (isset($this->blk[$this->blklvl]['line_height'])) {
  16288. $this->list_lineheight[$this->listlvl][$occur] = $this->blk[$this->blklvl]['line_height'];
  16289. }
  16290. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) { $this->listDir = strtolower($properties['DIRECTION']); }
  16291. else if (isset($attr['DIR']) && $attr['DIR']) { $this->listDir = strtolower($attr['DIR']); }
  16292. }
  16293. $this->list_indent[$this->listlvl][$occur] = 5; // mm default indent for each level
  16294. 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); }
  16295. if (isset($properties['TEXT-ALIGN'])) {
  16296. $this->list_align[$this->listlvl][$occur] = $align[strtolower($properties['TEXT-ALIGN'])];
  16297. }
  16298. if (isset($properties['LINE-HEIGHT'])) {
  16299. $this->list_lineheight[$this->listlvl][$occur] = $this->fixLineheight($properties['LINE-HEIGHT']);
  16300. }
  16301. else if ($this->listlvl>1 && isset($this->list_lineheight[($this->listlvl - 1)][1])) {
  16302. $this->list_lineheight[$this->listlvl][$occur] = end($this->list_lineheight[($this->listlvl - 1)]);
  16303. }
  16304. if (!isset($this->list_lineheight[$this->listlvl][$occur]) || !$this->list_lineheight[$this->listlvl][$occur]) {
  16305. $this->list_lineheight[$this->listlvl][$occur] = $this->normalLineheight;
  16306. }
  16307. $this->InlineProperties['LIST'][$this->listlvl][$occur] = $this->saveInlineProperties();
  16308. $properties = array();
  16309. break;
  16310. case 'LI':
  16311. // Start Block
  16312. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16313. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16314. /*-- TABLES --*/
  16315. // A simple list for inside a table
  16316. if($this->tableLevel) {
  16317. $this->blockjustfinished=false;
  16318. // If already something in the Cell
  16319. 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 ) {
  16320. $this->_saveCellTextBuffer("\n");
  16321. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  16322. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16323. }
  16324. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  16325. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16326. }
  16327. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16328. }
  16329. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16330. $this->listlvl++; // first depth level
  16331. $this->listnum = 0; // reset
  16332. $this->listlist[$this->listlvl] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16333. }
  16334. $this->listnum++;
  16335. switch($this->listlist[$this->listlvl]['TYPE']) {
  16336. case 'A':
  16337. $blt = $this->dec2alpha($this->listnum,true).$this->list_number_suffix;
  16338. break;
  16339. case 'a':
  16340. $blt = $this->dec2alpha($this->listnum,false).$this->list_number_suffix;
  16341. break;
  16342. case 'I':
  16343. $blt = $this->dec2roman($this->listnum,true).$this->list_number_suffix;
  16344. break;
  16345. case 'i':
  16346. $blt = $this->dec2roman($this->listnum,false).$this->list_number_suffix;
  16347. break;
  16348. case '1':
  16349. $blt = $this->listnum.$this->list_number_suffix;
  16350. break;
  16351. default:
  16352. if ($this->listlvl % 3 == 1 && $this->_charDefined($this->CurrentFont['cw'],8226)) { $blt = "\xe2\x80\xa2"; } // &#8226;
  16353. else if ($this->listlvl % 3 == 2 && $this->_charDefined($this->CurrentFont['cw'],9900)) { $blt = "\xe2\x9a\xac"; } // &#9900;
  16354. else if ($this->listlvl % 3 == 0 && $this->_charDefined($this->CurrentFont['cw'],9642)) { $blt = "\xe2\x96\xaa"; } // &#9642;
  16355. else { $blt = '-'; }
  16356. break;
  16357. }
  16358. // change to &nbsp; spaces
  16359. if ($this->usingCoreFont) {
  16360. $ls = str_repeat(chr(160).chr(160),($this->listlvl-1)*2) . $blt . ' ';
  16361. }
  16362. else {
  16363. $ls = str_repeat("\xc2\xa0\xc2\xa0",($this->listlvl-1)*2) . $blt . ' ';
  16364. }
  16365. $this->_saveCellTextBuffer($ls, $this->HREF);
  16366. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($ls);
  16367. break;
  16368. }
  16369. /*-- END TABLES --*/
  16370. //Observation: </LI> is ignored
  16371. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16372. //First of all, skip a line
  16373. $this->listlvl++; // first depth level
  16374. $this->listnum = 0; // reset
  16375. $this->listoccur[$this->listlvl] = 1;
  16376. $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16377. }
  16378. if ($this->listnum == 0) {
  16379. $this->listnum++;
  16380. $this->textbuffer = array();
  16381. }
  16382. else {
  16383. if (!empty($this->textbuffer)) {
  16384. if (!$this->listjustfinished) {
  16385. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16386. $this->listnum++;
  16387. }
  16388. else {
  16389. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype, true);
  16390. }
  16391. }
  16392. $this->textbuffer = array();
  16393. }
  16394. $this->listjustfinished = false;
  16395. $this->cssmgr->listCSSlvl++;
  16396. $properties = $this->cssmgr->MergeCSS('LIST',$tag,$attr);
  16397. if (!empty($properties)) $this->setCSS($properties,'LIST');
  16398. $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listoccur[$this->listlvl]][$this->listnum] = $this->saveInlineProperties();
  16399. // List-type
  16400. if (isset($properties['LIST-STYLE-TYPE'])) {
  16401. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  16402. }
  16403. else if (isset($properties['LIST-STYLE'])) {
  16404. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE']);
  16405. }
  16406. else if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listitemtype = $attr['TYPE']; }
  16407. else $this->listitemtype = '';
  16408. break;
  16409. /*-- END LISTS --*/
  16410. }//end of switch
  16411. }
  16412. /*-- LISTS --*/
  16413. function _getListStyle($ls) {
  16414. if (stristr($ls,'decimal')) { return '1'; }
  16415. /* CSS3 list-styles numeric (selected) + I added tamil
  16416. arabic-indic | bengali | devanagari | gujarati | gurmukhi | kannada | malayalam | oriya | persian | telugu | thai | urdu
  16417. */
  16418. else if (preg_match('/(disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu)/i',$ls,$m)) {
  16419. return strtolower(trim($m[1]));
  16420. }
  16421. else if (stristr($ls,'lower-roman')) { return 'i'; }
  16422. else if (stristr($ls,'upper-roman')) { return 'I'; }
  16423. else if (stristr($ls,'lower-latin')|| stristr($ls,'lower-alpha')) { return 'a'; }
  16424. else if (stristr($ls,'upper-latin') || stristr($ls,'upper-alpha')) { return 'A'; }
  16425. else if (stristr($ls,'none')) { return 'none'; }
  16426. else if (preg_match('/U\+([a-fA-F0-9]+)/i',$ls)) { return $ls; }
  16427. else { return ''; }
  16428. }
  16429. /*-- END LISTS --*/
  16430. function CloseTag($tag)
  16431. {
  16432. $this->ignorefollowingspaces = false; //Eliminate exceeding left-side spaces
  16433. //Closing tag
  16434. if($tag=='OPTION') { $this->selectoption['ACTIVE'] = false; $this->lastoptionaltag = ''; }
  16435. if($tag=='TTS' or $tag=='TTA' or $tag=='TTZ') {
  16436. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16437. unset($this->InlineProperties[$tag]);
  16438. $ltag = strtolower($tag);
  16439. $this->$ltag = false;
  16440. }
  16441. if($tag=='FONT' || $tag=='SPAN' || $tag=='CODE' || $tag=='KBD' || $tag=='SAMP' || $tag=='TT' || $tag=='VAR'
  16442. || $tag=='INS' || $tag=='STRONG' || $tag=='CITE' || $tag=='SUB' || $tag=='SUP' || $tag=='S' || $tag=='STRIKE' || $tag=='DEL'
  16443. || $tag=='Q' || $tag=='EM' || $tag=='B' || $tag=='I' || $tag=='U' | $tag=='SMALL' || $tag=='BIG' || $tag=='ACRONYM'
  16444. || $tag=='MARK' || $tag=='TIME' || $tag=='PROGRESS' || $tag=='METER'
  16445. ) { // mPDF 5.5.09
  16446. if ($tag == 'SPAN') {
  16447. if (isset($this->InlineProperties['SPAN'][$this->spanlvl]) && $this->InlineProperties['SPAN'][$this->spanlvl]) { $this->restoreInlineProperties($this->InlineProperties['SPAN'][$this->spanlvl]); }
  16448. unset($this->InlineProperties['SPAN'][$this->spanlvl]);
  16449. if (isset($this->InlineAnnots['SPAN'][$this->spanlvl]) && $this->InlineAnnots['SPAN'][$this->spanlvl]) { $annot = $this->InlineAnnots['SPAN'][$this->spanlvl]; } // *ANNOTATIONS*
  16450. unset($this->InlineAnnots['SPAN'][$this->spanlvl]); // *ANNOTATIONS*
  16451. $this->spanlvl--;
  16452. }
  16453. else {
  16454. if (isset($this->InlineProperties[$tag]) && $this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16455. unset($this->InlineProperties[$tag]);
  16456. if (isset($this->InlineAnnots[$tag]) && $this->InlineAnnots[$tag]) { $annot = $this->InlineAnnots[$tag]; } // *ANNOTATIONS*
  16457. unset($this->InlineAnnots[$tag]); // *ANNOTATIONS*
  16458. }
  16459. /*-- ANNOTATIONS --*/
  16460. if (isset($annot)) {
  16461. if($this->tableLevel) { // *TABLES*
  16462. $this->cell[$this->row][$this->col]['textbuffer'][] = array($annot); // *TABLES*
  16463. } // *TABLES*
  16464. else { // *TABLES*
  16465. $this->textbuffer[] = array($annot);
  16466. } // *TABLES*
  16467. }
  16468. /*-- END ANNOTATIONS --*/
  16469. }
  16470. if($tag=='METER' || $tag=='PROGRESS') {
  16471. $this->inMeter = false; // mPDF 5.5.09
  16472. }
  16473. if($tag=='A') {
  16474. $this->HREF='';
  16475. if (isset($this->InlineProperties['A'])) { $this->restoreInlineProperties($this->InlineProperties['A']); }
  16476. unset($this->InlineProperties['A']);
  16477. }
  16478. if($tag=='LEGEND') { // mPDF 5.4.18
  16479. if (count($this->textbuffer) && !$this->tableLevel) {
  16480. $leg = $this->textbuffer[(count($this->textbuffer)-1)];
  16481. unset($this->textbuffer[(count($this->textbuffer)-1)]);
  16482. $this->textbuffer = array_values($this->textbuffer);
  16483. $this->blk[$this->blklvl]['border_legend'] = $leg;
  16484. $this->blk[$this->blklvl]['margin_top'] += ($leg[11]/2)/_MPDFK;
  16485. $this->blk[$this->blklvl]['padding_top'] += ($leg[11]/2)/_MPDFK;
  16486. }
  16487. if (isset($this->InlineProperties['LEGEND'])) { $this->restoreInlineProperties($this->InlineProperties['LEGEND']); }
  16488. unset($this->InlineProperties['LEGEND']);
  16489. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16490. }
  16491. /*-- FORMS --*/
  16492. // *********** FORM ELEMENTS ********************
  16493. if($tag=='TEXTAREA') {
  16494. $this->specialcontent = '';
  16495. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16496. unset($this->InlineProperties[$tag]);
  16497. }
  16498. if($tag=='SELECT') {
  16499. $this->lastoptionaltag = '';
  16500. $texto = '';
  16501. if (isset($this->selectoption['SELECTED'])) { $texto = $this->selectoption['SELECTED']; }
  16502. if ($this->useActiveForms) { $w = $this->selectoption['MAXWIDTH']; }
  16503. else { $w = $this->GetStringWidth($texto); }
  16504. if ($w == 0) { $w = 5; }
  16505. $objattr['type'] = 'select';
  16506. $objattr['text'] = $texto;
  16507. if (isset($this->selectoption['NAME'])) { $objattr['fieldname'] = $this->selectoption['NAME']; }
  16508. if (isset($this->selectoption['READONLY'])) { $objattr['readonly'] = true; }
  16509. if (isset($this->selectoption['REQUIRED'])) { $objattr['required'] = true; }
  16510. if (isset($this->selectoption['SPELLCHECK'])) { $objattr['spellcheck'] = true; }
  16511. if (isset($this->selectoption['EDITABLE'])) { $objattr['editable'] = true; }
  16512. if (isset($this->selectoption['ONCHANGE'])) { $objattr['onChange'] = $this->selectoption['ONCHANGE']; }
  16513. if (isset($this->selectoption['ITEMS'])) { $objattr['items'] = $this->selectoption['ITEMS']; }
  16514. if (isset($this->selectoption['MULTIPLE'])) { $objattr['multiple'] = $this->selectoption['MULTIPLE']; }
  16515. if (isset($this->selectoption['DISABLED'])) { $objattr['disabled'] = $this->selectoption['DISABLED']; }
  16516. if (isset($this->selectoption['TITLE'])) { $objattr['title'] = $this->selectoption['TITLE']; }
  16517. if (isset($this->selectoption['COLOR'])) { $objattr['color'] = $this->selectoption['COLOR']; }
  16518. if (isset($this->selectoption['SIZE'])) { $objattr['size'] = $this->selectoption['SIZE']; }
  16519. if (isset($objattr['size']) && $objattr['size']>1) { $rows=$objattr['size']; } else { $rows = 1; }
  16520. $objattr['fontfamily'] = $this->FontFamily;
  16521. $objattr['fontsize'] = $this->FontSizePt;
  16522. $objattr['width'] = $w + ($this->form->form_element_spacing['select']['outer']['h']*2)+($this->form->form_element_spacing['select']['inner']['h']*2) + ($this->FontSize*1.4);
  16523. $objattr['height'] = ($this->FontSize*$rows) + ($this->form->form_element_spacing['select']['outer']['v']*2)+($this->form->form_element_spacing['select']['inner']['v']*2);
  16524. $e = "\xbb\xa4\xactype=select,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16525. // Clear properties - tidy up
  16526. $properties = array();
  16527. // Output it to buffers
  16528. if ($this->tableLevel) { // *TABLES*
  16529. $this->_saveCellTextBuffer($e, $this->HREF);
  16530. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  16531. } // *TABLES*
  16532. else { // *TABLES*
  16533. $this->_saveTextBuffer($e, $this->HREF);
  16534. } // *TABLES*
  16535. $this->selectoption = array();
  16536. $this->specialcontent = '';
  16537. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16538. unset($this->InlineProperties[$tag]);
  16539. }
  16540. /*-- END FORMS --*/
  16541. // *********** BLOCKS ********************
  16542. // mPDF 5.4.18
  16543. if($tag=='P' || $tag=='DIV' || $tag=='H1' || $tag=='H2' || $tag=='H3' || $tag=='H4' || $tag=='H5' || $tag=='H6' || $tag=='PRE'
  16544. || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DT' || $tag=='DD' || $tag=='DL'
  16545. || $tag=='CAPTION' || $tag=='FIELDSET'
  16546. || $tag=='ARTICLE' || $tag=='ASIDE' || $tag=='FIGURE' || $tag=='FIGCAPTION' || $tag=='FOOTER' || $tag=='HEADER' || $tag=='HGROUP'
  16547. || $tag=='NAV' || $tag=='SECTION' || $tag=='DETAILS' || $tag=='SUMMARY'
  16548. ) { // mPDF 5.5.09 // mPDF 5.5.22
  16549. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16550. $this->blockjustfinished=true;
  16551. $this->lastblockbottommargin = $this->blk[$this->blklvl]['margin_bottom'];
  16552. /*-- LISTS --*/
  16553. if ($this->listlvl>0) { return; }
  16554. /*-- END LISTS --*/
  16555. // mPDF 5.6.34
  16556. if (preg_match('/^H\d/',$tag) && !$this->tableLevel && !$this->writingToC) { // mPDF 5.6.38
  16557. if (isset($this->h2toc[$tag]) || isset($this->h2bookmarks[$tag])) {
  16558. $content = '';
  16559. if (count($this->textbuffer)==1) { $content = $this->textbuffer[0][0]; }
  16560. else {
  16561. for ($i=0;$i<count($this->textbuffer);$i++) {
  16562. if (substr($this->textbuffer[$i][0],0,3) != "\xbb\xa4\xac") { //inline object
  16563. $content .= $this->textbuffer[$i][0];
  16564. }
  16565. }
  16566. }
  16567. /*-- TOC --*/
  16568. if (isset($this->h2toc[$tag])) {
  16569. $objattr = array();
  16570. $objattr['type'] = 'toc';
  16571. $objattr['toclevel'] = $this->h2toc[$tag];
  16572. $objattr['CONTENT'] = htmlspecialchars($content); // mPDF 5.6.37
  16573. $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16574. array_unshift($this->textbuffer,array($e));
  16575. }
  16576. /*-- END TOC --*/
  16577. /*-- BOOKMARKS --*/
  16578. if (isset($this->h2bookmarks[$tag])) {
  16579. $objattr = array();
  16580. $objattr['type'] = 'bookmark';
  16581. $objattr['bklevel'] = $this->h2bookmarks[$tag];
  16582. $objattr['CONTENT'] = $content;
  16583. $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16584. array_unshift($this->textbuffer,array($e));
  16585. }
  16586. /*-- END BOOKMARKS --*/
  16587. }
  16588. }
  16589. /*-- TABLES --*/
  16590. if($this->tableLevel) {
  16591. if ($this->linebreakjustfinished) { $this->blockjustfinished=false; }
  16592. if (isset($this->InlineProperties['BLOCKINTABLE'])) {
  16593. if ($this->InlineProperties['BLOCKINTABLE']) { $this->restoreInlineProperties($this->InlineProperties['BLOCKINTABLE']); }
  16594. unset($this->InlineProperties['BLOCKINTABLE']);
  16595. }
  16596. if($tag=='PRE') { $this->ispre=false; }
  16597. return;
  16598. }
  16599. /*-- END TABLES --*/
  16600. $this->lastoptionaltag = '';
  16601. $this->divbegin=false;
  16602. $this->linebreakjustfinished=false;
  16603. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  16604. /*-- CSS-FLOAT --*/
  16605. // If float contained in a float, need to extend bottom to allow for it
  16606. $currpos = $this->page*1000 + $this->y;
  16607. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  16608. $old_page = $this->page;
  16609. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  16610. if ($old_page != $new_page) {
  16611. $s = $this->PrintPageBackgrounds();
  16612. // Writes after the marker so not overwritten later by page background etc.
  16613. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16614. $this->pageBackgrounds = array();
  16615. $this->page = $new_page;
  16616. $this->ResetMargins();
  16617. $this->Reset();
  16618. $this->pageoutput[$this->page] = array();
  16619. }
  16620. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  16621. }
  16622. /*-- END CSS-FLOAT --*/
  16623. //Print content
  16624. if ($this->lastblocklevelchange == 1) { $blockstate = 3; } // Top & bottom margins/padding
  16625. else if ($this->lastblocklevelchange == -1) { $blockstate = 2; } // Bottom margins/padding only
  16626. else { $blockstate = 0; }
  16627. // called from after e.g. </table> </div> </div> ... Outputs block margin/border and padding
  16628. if (count($this->textbuffer) && $this->textbuffer[count($this->textbuffer)-1]) {
  16629. if (substr($this->textbuffer[count($this->textbuffer)-1][0],0,3) != "\xbb\xa4\xac") { // not special content
  16630. if ($this->usingCoreFont) {
  16631. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/', '', $this->textbuffer[count($this->textbuffer)-1][0]);
  16632. }
  16633. else {
  16634. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/u', '', $this->textbuffer[count($this->textbuffer)-1][0]); }
  16635. }
  16636. }
  16637. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange != 0) {
  16638. //$this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,2,true, $this->blk[$this->blklvl]['direction']);
  16639. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,$blockstate,true, $this->blk[$this->blklvl]['direction']);
  16640. $this->finishFlowingBlock(true); // true = END of flowing block
  16641. $this->PaintDivBB('',$blockstate);
  16642. }
  16643. else {
  16644. $this->printbuffer($this->textbuffer,$blockstate);
  16645. }
  16646. $this->textbuffer=array();
  16647. if ($this->blk[$this->blklvl]['keep_block_together']) {
  16648. $this->printdivbuffer();
  16649. }
  16650. if ($this->kwt) {
  16651. $this->kwt_height = $this->y - $this->kwt_y0;
  16652. }
  16653. /*-- CSS-IMAGE-FLOAT --*/
  16654. $this->printfloatbuffer();
  16655. /*-- END CSS-IMAGE-FLOAT --*/
  16656. if($tag=='PRE') { $this->ispre=false; }
  16657. /*-- CSS-FLOAT --*/
  16658. if ($this->blk[$this->blklvl]['float'] == 'R') {
  16659. // If width not set, here would need to adjust and output buffer
  16660. $s = $this->PrintPageBackgrounds();
  16661. // Writes after the marker so not overwritten later by page background etc.
  16662. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16663. $this->pageBackgrounds = array();
  16664. $this->Reset();
  16665. $this->pageoutput[$this->page] = array();
  16666. for($i=($this->blklvl-1); $i >= 0; $i--) {
  16667. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  16668. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  16669. }
  16670. $this->floatDivs[] = array(
  16671. 'side'=>'R',
  16672. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  16673. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  16674. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  16675. 'endpage'=>$this->page ,
  16676. 'y1'=>$this->y ,
  16677. 'endpos'=> ($this->page*1000 + $this->y),
  16678. 'w'=> $this->blk[$this->blklvl]['float_width'],
  16679. 'blklvl'=>$this->blklvl,
  16680. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  16681. );
  16682. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  16683. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  16684. $this->ResetMargins();
  16685. $this->pageoutput[$this->page] = array();
  16686. }
  16687. if ($this->blk[$this->blklvl]['float'] == 'L') {
  16688. // If width not set, here would need to adjust and output buffer
  16689. $s = $this->PrintPageBackgrounds();
  16690. // Writes after the marker so not overwritten later by page background etc.
  16691. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16692. $this->pageBackgrounds = array();
  16693. $this->Reset();
  16694. $this->pageoutput[$this->page] = array();
  16695. for($i=($this->blklvl-1); $i >= 0; $i--) {
  16696. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  16697. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  16698. }
  16699. $this->floatDivs[] = array(
  16700. 'side'=>'L',
  16701. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  16702. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  16703. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  16704. 'endpage'=>$this->page ,
  16705. 'y1'=>$this->y ,
  16706. 'endpos'=> ($this->page*1000 + $this->y),
  16707. 'w'=> $this->blk[$this->blklvl]['float_width'],
  16708. 'blklvl'=>$this->blklvl,
  16709. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  16710. );
  16711. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  16712. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  16713. $this->ResetMargins();
  16714. $this->pageoutput[$this->page] = array();
  16715. }
  16716. /*-- END CSS-FLOAT --*/
  16717. if (isset($this->blk[$this->blklvl]['visibility']) && $this->blk[$this->blklvl]['visibility']!='visible') {
  16718. $this->SetVisibility('visible');
  16719. }
  16720. if (isset($this->blk[$this->blklvl]['page_break_after'])) { $page_break_after = $this->blk[$this->blklvl]['page_break_after']; }
  16721. else { $page_break_after = ''; }
  16722. //Reset values
  16723. $this->Reset();
  16724. // mPDF 5.6.01 - LAYERS
  16725. if (isset($this->blk[$this->blklvl]['z-index']) && $this->blk[$this->blklvl]['z-index'] > 0) {
  16726. $this->EndLayer();
  16727. }
  16728. if ($this->blklvl > 0) { // ==0 SHOULDN'T HAPPEN - NOT XHTML
  16729. if ($this->blk[$this->blklvl]['tag'] == $tag) {
  16730. unset($this->blk[$this->blklvl]);
  16731. $this->blklvl--;
  16732. }
  16733. //else { echo $tag; exit; } // debug - forces error if incorrectly nested html tags
  16734. }
  16735. $this->lastblocklevelchange = -1 ;
  16736. // Reset Inline-type properties
  16737. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']); }
  16738. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  16739. if ($page_break_after) {
  16740. $save_blklvl = $this->blklvl;
  16741. $save_blk = $this->blk;
  16742. $save_silp = $this->saveInlineProperties();
  16743. $save_spanlvl = $this->spanlvl;
  16744. $save_ilp = $this->InlineProperties;
  16745. if ($this->blklvl>1) {
  16746. // Close any open block tags
  16747. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  16748. // Output any text left in buffer
  16749. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  16750. }
  16751. /*-- COLUMNS --*/
  16752. $save_cols = false;
  16753. if ($this->ColActive) {
  16754. $save_cols = true;
  16755. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  16756. $this->SetColumns(0);
  16757. }
  16758. /*-- END COLUMNS --*/
  16759. if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  16760. else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  16761. else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  16762. if (!$this->restoreBlockPagebreaks) {
  16763. $this->blklvl = 0;
  16764. $this->lastblocklevelchange = 0;
  16765. $this->blk = array();
  16766. $this->initialiseBlock($this->blk[0]);
  16767. $this->blk[0]['width'] =& $this->pgwidth;
  16768. $this->blk[0]['inner_width'] =& $this->pgwidth;
  16769. $this->blk[0]['blockContext'] = $this->blockContext;
  16770. $properties = $this->cssmgr->MergeCSS('BLOCK','BODY','');
  16771. $this->setCSS($properties,'','BODY');
  16772. $this->blklvl++;
  16773. $currblk =& $this->blk[$this->blklvl];
  16774. $prevblk =& $this->blk[$this->blklvl-1];
  16775. $this->initialiseBlock($currblk);
  16776. $currblk['tag'] = $tag;
  16777. $currblk['attr'] = $attr;
  16778. $this->Reset();
  16779. $properties = $this->cssmgr->MergeCSS('BLOCK',$tag,$attr);
  16780. }
  16781. /*-- COLUMNS --*/
  16782. if ($save_cols) {
  16783. // Restore columns
  16784. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  16785. }
  16786. /*-- END COLUMNS --*/
  16787. if ($this->restoreBlockPagebreaks && !$this->tableLevel && !$this->listlvl) {
  16788. $this->blk = $save_blk;
  16789. // Re-open block tags
  16790. $t = $this->blk[0]['tag'];
  16791. $a = $this->blk[0]['attr'];
  16792. $this->blklvl = 0;
  16793. for ($b=0; $b<=$save_blklvl;$b++) {
  16794. $tc = $t;
  16795. $ac = $a;
  16796. $t = $this->blk[$b+1]['tag'];
  16797. $a = $this->blk[$b+1]['attr'];
  16798. unset($this->blk[$b+1]);
  16799. $this->OpenTag($tc,$ac);
  16800. }
  16801. $this->spanlvl = $save_spanlvl;
  16802. $this->InlineProperties = $save_ilp;
  16803. $this->restoreInlineProperties($save_silp);
  16804. }
  16805. }
  16806. }
  16807. /*-- TABLES --*/
  16808. if($tag=='TH') $this->SetStyle('B',false);
  16809. if(($tag=='TH' or $tag=='TD') && $this->tableLevel) {
  16810. $this->lastoptionaltag = 'TR';
  16811. unset($this->cssmgr->tablecascadeCSS[$this->cssmgr->tbCSSlvl]);
  16812. $this->cssmgr->tbCSSlvl--;
  16813. if (!$this->tdbegin) { return; }
  16814. $this->tdbegin = false;
  16815. // Added for correct calculation of cell column width - otherwise misses the last line if not end </p> etc.
  16816. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  16817. if (!is_array($this->cell[$this->row][$this->col])) { $this->Error("You may have an error in your HTML code e.g. &lt;/td&gt;&lt;/td&gt;"); }
  16818. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16819. }
  16820. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  16821. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16822. }
  16823. // Remove last <br> if at end of cell
  16824. if (isset($this->cell[$this->row][$this->col]['textbuffer'])) { $ntb = count($this->cell[$this->row][$this->col]['textbuffer']); }
  16825. else { $ntb = 0; }
  16826. if ($ntb>1 && $this->cell[$this->row][$this->col]['textbuffer'][$ntb-1][0] == "\n") {
  16827. unset($this->cell[$this->row][$this->col]['textbuffer'][$ntb-1]);
  16828. }
  16829. if ($this->cacheTables) {
  16830. $clen = $this->_cacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache']);
  16831. $this->cell[$this->row][$this->col] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr'];
  16832. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr'] += $clen;
  16833. }
  16834. if ($this->tablethead) {
  16835. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true;
  16836. if ($this->tableLevel==1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] = max($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] , ($this->row+1)); }
  16837. }
  16838. if ($this->tabletfoot) {
  16839. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true;
  16840. if ($this->tableLevel==1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['footernrows'] = max($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['footernrows'] , ($this->row+1 - $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] )); }
  16841. }
  16842. $this->Reset();
  16843. }
  16844. if($tag=='TR' && $this->tableLevel) {
  16845. // If Border set on TR - Update right border
  16846. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row])) {
  16847. if ($this->cacheTables) {
  16848. $c = $this->_uncacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], null);
  16849. }
  16850. else { $c =& $this->cell[$this->row][$this->col]; }
  16851. if ($c) {
  16852. if ($this->packTableData) {
  16853. $cell = $this->_unpackCellBorder($c['borderbin'] );
  16854. }
  16855. else { $cell = $c; }
  16856. $cell['border_details']['R'] = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row]);
  16857. $this->setBorder($cell['border'], _BORDER_RIGHT, $cell['border_details']['R']['s']);
  16858. if ($this->packTableData) {
  16859. $c['borderbin'] = $this->_packCellBorder($cell);
  16860. unset($c['border']);
  16861. unset($c['border_details']);
  16862. }
  16863. else { $c = $cell; }
  16864. }
  16865. if ($this->cacheTables) {
  16866. $fh = fopen($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], "r+b");
  16867. $this->_cacheUpdateBorder($c, $fh, $this->cell[$this->row][$this->col]);
  16868. fclose($fh);
  16869. }
  16870. }
  16871. $this->lastoptionaltag = '';
  16872. unset($this->cssmgr->tablecascadeCSS[$this->cssmgr->tbCSSlvl]);
  16873. $this->cssmgr->tbCSSlvl--;
  16874. $this->trow_text_rotate = '';
  16875. $this->tabletheadjustfinished = false;
  16876. }
  16877. if($tag=='TBODY') {
  16878. $this->lastoptionaltag = '';
  16879. unset($this->cssmgr->tablecascadeCSS[$this->cssmgr->tbCSSlvl]);
  16880. $this->cssmgr->tbCSSlvl--;
  16881. }
  16882. if($tag=='THEAD') {
  16883. $this->lastoptionaltag = '';
  16884. unset($this->cssmgr->tablecascadeCSS[$this->cssmgr->tbCSSlvl]);
  16885. $this->cssmgr->tbCSSlvl--;
  16886. $this->tablethead = 0;
  16887. $this->tabletheadjustfinished = true;
  16888. $this->ResetStyles();
  16889. $this->thead_font_weight = '';
  16890. $this->thead_font_style = '';
  16891. $this->thead_font_smCaps = '';
  16892. $this->thead_valign_default = '';
  16893. $this->thead_textalign_default = '';
  16894. }
  16895. if($tag=='TFOOT') {
  16896. $this->lastoptionaltag = '';
  16897. unset($this->cssmgr->tablecascadeCSS[$this->cssmgr->tbCSSlvl]);
  16898. $this->cssmgr->tbCSSlvl--;
  16899. $this->tabletfoot = 0;
  16900. $this->ResetStyles();
  16901. $this->tfoot_font_weight = '';
  16902. $this->tfoot_font_style = '';
  16903. $this->tfoot_font_smCaps = '';
  16904. $this->tfoot_valign_default = '';
  16905. $this->tfoot_textalign_default = '';
  16906. }
  16907. if($tag=='TABLE') { // TABLE-END (
  16908. if ($this->progressBar) { $this->UpdateProgressBar(1,'','TABLE'); } // *PROGRESS-BAR*
  16909. if ($this->progressBar) { $this->UpdateProgressBar(7,0,''); } // *PROGRESS-BAR*
  16910. $this->lastoptionaltag = '';
  16911. unset($this->cssmgr->tablecascadeCSS[$this->cssmgr->tbCSSlvl]);
  16912. $this->cssmgr->tbCSSlvl--;
  16913. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16914. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  16915. $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));
  16916. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['hr'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr'],0);
  16917. // Move table footer <tfoot> row to end of table
  16918. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) && count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'])) {
  16919. $tfrows = array();
  16920. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] AS $r=>$val) {
  16921. if ($val) { $tfrows[] = $r; }
  16922. }
  16923. $temp = array();
  16924. $temptf = array();
  16925. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] AS $k=>$row) {
  16926. if (in_array($k,$tfrows)) {
  16927. $temptf[] = $row;
  16928. }
  16929. else {
  16930. $temp[] = $row;
  16931. }
  16932. }
  16933. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] = array();
  16934. for($i=count($temp) ; $i<(count($temp)+count($temptf)); $i++) {
  16935. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$i] = true;
  16936. }
  16937. // Update nestedpos row references
  16938. if (count($this->table[($this->tableLevel+1)])) {
  16939. foreach($this->table[($this->tableLevel+1)] AS $nid=>$nested) {
  16940. $this->table[($this->tableLevel+1)][$nid]['nestedpos'][0] -= count($temptf);
  16941. }
  16942. }
  16943. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = array_merge($temp, $temptf);
  16944. // Update other arays set on row number
  16945. // [trbackground-images] [trgradients]
  16946. $temptrbgi = array();
  16947. $temptrbgg = array();
  16948. $temptrbgc = array();
  16949. $temptrbgc[-1] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][-1];
  16950. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  16951. if (!in_array($k,$tfrows)) {
  16952. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  16953. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  16954. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k];
  16955. }
  16956. }
  16957. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  16958. if (in_array($k,$tfrows)) {
  16959. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  16960. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  16961. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k];
  16962. }
  16963. }
  16964. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'] = $temptrbgi;
  16965. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'] = $temptrbgg;
  16966. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'] = $temptrbgc ;
  16967. // Should Update all other arays set on row number, but cell properties have been set so not needed
  16968. // [bgcolor] [trborder-left] [trborder-right] [trborder-top] [trborder-bottom]
  16969. }
  16970. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']=='rtl') {
  16971. $this->_reverseTableDir($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  16972. }
  16973. // Fix Borders *********************************************
  16974. $this->_fixTableBorders($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  16975. if ($this->progressBar) { $this->UpdateProgressBar(7,10,' '); } // *PROGRESS-BAR*
  16976. if ($this->ColActive) { $this->table_rotate = 0; } // *COLUMNS*
  16977. if ($this->table_rotate <> 0) {
  16978. $this->tablebuffer = '';
  16979. // Max width for rotated table
  16980. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 1);
  16981. $this->tbrot_maxh = $this->blk[$this->blklvl]['inner_width'] ; // Max width for rotated table
  16982. $this->tbrot_align = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['a'] ;
  16983. }
  16984. $this->shrin_k = 1;
  16985. if ($this->shrink_tables_to_fit < 1) { $this->shrink_tables_to_fit = 1; }
  16986. if (!$this->shrink_this_table_to_fit) { $this->shrink_this_table_to_fit = $this->shrink_tables_to_fit; }
  16987. if ($this->tableLevel>1) {
  16988. // deal with nested table
  16989. $this->_tableColumnWidth($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]],true);
  16990. $tmiw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['miw'];
  16991. $tmaw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['maw'];
  16992. $tl = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tl'];
  16993. // Go down to lower table level
  16994. $this->tableLevel--;
  16995. // Reset lower level table
  16996. $this->base_table_properties = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties'];
  16997. $this->cell = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'];
  16998. // mPDF 5.4.10
  16999. if (isset($this->cell['PARENTCELL'])) {
  17000. if ($this->cell['PARENTCELL']) { $this->restoreInlineProperties($this->cell['PARENTCELL']); }
  17001. unset($this->cell['PARENTCELL']);
  17002. }
  17003. $this->row = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'];
  17004. $this->col = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'];
  17005. $objattr = array();
  17006. $objattr['type'] = 'nestedtable';
  17007. $objattr['nestedcontent'] = $this->tbctr[($this->tableLevel+1)];
  17008. $objattr['table'] = $this->tbctr[$this->tableLevel];
  17009. $objattr['row'] = $this->row;
  17010. $objattr['col'] = $this->col;
  17011. $objattr['level'] = $this->tableLevel;
  17012. $e = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  17013. $this->_saveCellTextBuffer($e);
  17014. $this->cell[$this->row][$this->col]['s'] += $tl ;
  17015. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17016. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17017. }
  17018. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17019. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17020. }
  17021. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  17022. 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 ; }
  17023. 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 ; }
  17024. $this->tdbegin = true;
  17025. $this->nestedtablejustfinished = true;
  17026. $this->ignorefollowingspaces = true;
  17027. return;
  17028. }
  17029. $this->cMarginL = 0;
  17030. $this->cMarginR = 0;
  17031. $this->cMarginT = 0;
  17032. $this->cMarginB = 0;
  17033. $this->cellPaddingL = 0;
  17034. $this->cellPaddingR = 0;
  17035. $this->cellPaddingT = 0;
  17036. $this->cellPaddingB = 0;
  17037. if (isset($this->table[1][1]['overflow']) && $this->table[1][1]['overflow']=='visible') {
  17038. if ($this->kwt || $this->table_rotate || $this->table_keep_together || $this->ColActive) {
  17039. $this->kwt = false;
  17040. $this->table_rotate = 0;
  17041. $this->table_keep_together = false;
  17042. //die("mPDF Warning: You cannot use CSS overflow:visible together with any of these functions: 'Keep-with-table', rotated tables, page-break-inside:avoid, or columns");
  17043. }
  17044. $this->_tableColumnWidth($this->table[1][1],true);
  17045. $this->_tableWidth($this->table[1][1]);
  17046. }
  17047. else {
  17048. if (!$this->kwt_saved) { $this->kwt_height = 0; }
  17049. list($check,$tablemiw) = $this->_tableColumnWidth($this->table[1][1],true);
  17050. $save_table = $this->table;
  17051. if ($this->cacheTables) { $this->_backupCacheFiles(); }
  17052. $reset_to_minimum_width = false;
  17053. $added_page = false;
  17054. if ($check > 1) {
  17055. if ($check > $this->shrink_this_table_to_fit && $this->table_rotate) {
  17056. if ($this->y != $this->tMargin) {
  17057. $this->AddPage($this->CurOrientation);
  17058. $this->kwt_moved = true;
  17059. }
  17060. $added_page = true;
  17061. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17062. //$check = $tablemiw/$this->tbrot_maxw; // undo any shrink
  17063. $check = 1; // undo any shrink
  17064. }
  17065. $reset_to_minimum_width = true;
  17066. }
  17067. if ($reset_to_minimum_width) {
  17068. $this->shrin_k = $check;
  17069. $this->default_font_size /= $this->shrin_k;
  17070. $this->SetFontSize($this->default_font_size, false );
  17071. $this->shrinkTable($this->table[1][1],$this->shrin_k);
  17072. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  17073. // Starting at $this->innermostTableLevel
  17074. // Shrink table values - and redo columnWidth
  17075. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17076. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17077. $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k);
  17078. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  17079. }
  17080. }
  17081. }
  17082. // Set table cell widths for top level table
  17083. // Use $shrin_k to resize but don't change again
  17084. $this->SetLineHeight('',$this->table_lineheight);
  17085. // Top level table
  17086. $this->_tableWidth($this->table[1][1]);
  17087. }
  17088. // Now work through any nested tables setting child table[w'] = parent cell['w']
  17089. // Now do nested tables _tableWidth
  17090. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17091. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17092. // HERE set child table width = cell width
  17093. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  17094. if ($this->cacheTables) {
  17095. $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null);
  17096. }
  17097. else
  17098. $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol];
  17099. if (isset($c['colspan']) && $c['colspan']> 1) {
  17100. $parentwidth = 0;
  17101. for($cs=0;$cs<$c['colspan'] ; $cs++) {
  17102. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  17103. }
  17104. }
  17105. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  17106. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  17107. if (!$this->simpleTables){
  17108. if ($this->packTableData) {
  17109. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  17110. }
  17111. else {
  17112. $br = $c['border_details']['R']['w'];
  17113. $bl = $c['border_details']['L']['w'];
  17114. }
  17115. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17116. $parentwidth -= $br + $bl
  17117. + $c['padding']['L']
  17118. + $c['padding']['R']
  17119. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17120. }
  17121. else {
  17122. $parentwidth -= $br/2 + $bl/2
  17123. + $c['padding']['L']
  17124. + $c['padding']['R'];
  17125. }
  17126. }
  17127. else if ($this->simpleTables){
  17128. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17129. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17130. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  17131. + $c['padding']['L']
  17132. + $c['padding']['R']
  17133. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17134. }
  17135. else {
  17136. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']/2
  17137. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']/2
  17138. + $c['padding']['L']
  17139. + $c['padding']['R'];
  17140. }
  17141. }
  17142. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  17143. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17144. }
  17145. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  17146. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'];
  17147. }
  17148. else {
  17149. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17150. }
  17151. unset($c);
  17152. $this->_tableWidth($this->table[$lvl][$nid]);
  17153. }
  17154. }
  17155. // Starting at $this->innermostTableLevel
  17156. // Cascade back up nested tables: setting heights back up the tree
  17157. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  17158. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17159. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  17160. }
  17161. if ($this->progressBar) { $this->UpdateProgressBar(7,20,' '); } // *PROGRESS-BAR*
  17162. if ($this->table[1][1]['overflow']=='visible') {
  17163. if ($maxrowheight > $fullpage) { die("mPDF Warning: A Table row is greater than available height. You cannot use CSS overflow:visible"); }
  17164. if ($maxfirstrowheight > $remainingpage) { $this->AddPage($this->CurOrientation); }
  17165. $r = 0; $c = 0; $p = 0; $y = 0;
  17166. while (!$finished) {
  17167. list($finished,$r,$c,$p,$y,$y0) = $this->_tableWrite($this->table[1][1],true,$r,$c,$p,$y);
  17168. if (!$finished) {
  17169. $this->AddPage($this->CurOrientation);
  17170. // If printed something on first spread, set same y
  17171. if ($r==0 && $y0 > -1) { $this->y = $y0; }
  17172. }
  17173. }
  17174. }
  17175. else {
  17176. $recalculate = 1;
  17177. $forcerecalc = false;
  17178. // RESIZING ALGORITHM
  17179. if ($maxrowheight > $fullpage) {
  17180. $recalculate = $this->tbsqrt($maxrowheight / $fullpage, 1);
  17181. $forcerecalc = true;
  17182. }
  17183. else if ($this->table_rotate) { // NB $remainingpage == $fullpage == the width of the page
  17184. if ($tableheight > $remainingpage) {
  17185. // If can fit on remainder of page whilst respecting autsize value..
  17186. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  17187. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  17188. }
  17189. else if (!$added_page) {
  17190. if ($this->y != $this->tMargin) {
  17191. $this->AddPage($this->CurOrientation);
  17192. $this->kwt_moved = true;
  17193. }
  17194. $added_page = true;
  17195. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17196. // 0.001 to force it to recalculate
  17197. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17198. }
  17199. }
  17200. else { $recalculate = 1; }
  17201. }
  17202. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) {
  17203. if ($tableheight > $fullpage) {
  17204. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, 1)) <= $this->shrink_this_table_to_fit) {
  17205. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  17206. }
  17207. else if ($this->tableMinSizePriority) {
  17208. $this->table_keep_together = false;
  17209. $recalculate = 1.001;
  17210. }
  17211. else {
  17212. if ($this->y != $this->tMargin) { // mPDF 5.1
  17213. $this->AddPage($this->CurOrientation);
  17214. $this->kwt_moved = true;
  17215. }
  17216. $added_page = true;
  17217. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17218. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  17219. }
  17220. }
  17221. else if ($tableheight > $remainingpage) {
  17222. // If can fit on remainder of page whilst respecting autsize value..
  17223. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  17224. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  17225. }
  17226. else {
  17227. if ($this->y != $this->tMargin) {
  17228. $this->AddPage($this->CurOrientation);
  17229. $this->kwt_moved = true;
  17230. }
  17231. $added_page = true;
  17232. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17233. $recalculate = 1.001;
  17234. }
  17235. }
  17236. else { $recalculate = 1; }
  17237. }
  17238. else { $recalculate = 1; }
  17239. if ($recalculate > $this->shrink_this_table_to_fit && !$forcerecalc) { $recalculate = $this->shrink_this_table_to_fit; }
  17240. $iteration = 1;
  17241. // RECALCULATE
  17242. while($recalculate <> 1) {
  17243. $this->shrin_k1 = $recalculate ;
  17244. $this->shrin_k *= $recalculate ;
  17245. $this->default_font_size /= ($this->shrin_k1) ;
  17246. $this->SetFontSize($this->default_font_size, false );
  17247. $this->SetLineHeight('',$this->table_lineheight);
  17248. $this->table = $save_table;
  17249. if ($this->cacheTables) { $this->_restoreCacheFiles(); }
  17250. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[1][1],$this->shrin_k); }
  17251. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  17252. // Starting at $this->innermostTableLevel
  17253. // Shrink table values - and redo columnWidth
  17254. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17255. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17256. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k); }
  17257. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  17258. }
  17259. }
  17260. // Set table cell widths for top level table
  17261. // Top level table
  17262. $this->_tableWidth($this->table[1][1]);
  17263. // Now work through any nested tables setting child table[w'] = parent cell['w']
  17264. // Now do nested tables _tableWidth
  17265. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17266. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17267. // HERE set child table width = cell width
  17268. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  17269. if ($this->cacheTables) {
  17270. $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null);
  17271. }
  17272. else
  17273. $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol];
  17274. if (isset($c['colspan']) && $c['colspan']> 1) {
  17275. $parentwidth = 0;
  17276. for($cs=0;$cs<$c['colspan'] ; $cs++) {
  17277. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  17278. }
  17279. }
  17280. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  17281. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  17282. if (!$this->simpleTables){
  17283. if ($this->packTableData) {
  17284. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  17285. }
  17286. else {
  17287. $br = $c['border_details']['R']['w'];
  17288. $bl = $c['border_details']['L']['w'];
  17289. }
  17290. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17291. $parentwidth -= $br + $bl
  17292. + $c['padding']['L']
  17293. + $c['padding']['R']
  17294. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17295. }
  17296. else {
  17297. $parentwidth -= $br/2 + $bl/2
  17298. + $c['padding']['L']
  17299. + $c['padding']['R'];
  17300. }
  17301. }
  17302. else if ($this->simpleTables){
  17303. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17304. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17305. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  17306. + $c['padding']['L']
  17307. + $c['padding']['R']
  17308. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17309. }
  17310. else {
  17311. $parentwidth -= ($this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17312. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']) /2
  17313. + $c['padding']['L']
  17314. + $c['padding']['R'];
  17315. }
  17316. }
  17317. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  17318. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17319. }
  17320. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  17321. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'] ;
  17322. }
  17323. else {
  17324. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17325. }
  17326. unset($c);
  17327. $this->_tableWidth($this->table[$lvl][$nid]);
  17328. }
  17329. }
  17330. // Starting at $this->innermostTableLevel
  17331. // Cascade back up nested tables: setting heights back up the tree
  17332. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  17333. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17334. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  17335. }
  17336. // RESIZING ALGORITHM
  17337. if ($maxrowheight > $fullpage) { $recalculate = $this->tbsqrt($maxrowheight / $fullpage, $iteration); $iteration++; }
  17338. else if ($this->table_rotate && $tableheight > $remainingpage && !$added_page) {
  17339. // If can fit on remainder of page whilst respecting autosize value..
  17340. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17341. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  17342. }
  17343. else {
  17344. if (!$added_page) {
  17345. $this->AddPage($this->CurOrientation);
  17346. $added_page = true;
  17347. $this->kwt_moved = true;
  17348. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17349. }
  17350. // 0.001 to force it to recalculate
  17351. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17352. }
  17353. }
  17354. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) {
  17355. if ($tableheight > $fullpage) {
  17356. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17357. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17358. }
  17359. else if ($this->tableMinSizePriority) {
  17360. $this->table_keep_together = false;
  17361. $recalculate = (1 / $this->shrin_k) + 0.001;
  17362. }
  17363. else {
  17364. if (!$added_page && $this->y != $this->tMargin) {
  17365. $this->AddPage($this->CurOrientation);
  17366. $added_page = true;
  17367. $this->kwt_moved = true;
  17368. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17369. }
  17370. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17371. }
  17372. }
  17373. else if ($tableheight > $remainingpage) {
  17374. // If can fit on remainder of page whilst respecting autosize value..
  17375. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17376. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  17377. }
  17378. else {
  17379. if (!$added_page) {
  17380. $this->AddPage($this->CurOrientation);
  17381. $added_page = true;
  17382. $this->kwt_moved = true;
  17383. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17384. }
  17385. //$recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17386. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17387. }
  17388. }
  17389. else { $recalculate = 1; }
  17390. }
  17391. else { $recalculate = 1; }
  17392. }
  17393. if ($maxfirstrowheight > $remainingpage && !$added_page && !$this->table_rotate && !$this->ColActive && !$this->table_keep_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  17394. $this->AddPage($this->CurOrientation);
  17395. $this->kwt_moved = true;
  17396. }
  17397. // keep-with-table: if page has advanced, print out buffer now, else done in fn. _Tablewrite()
  17398. if ($this->kwt_saved && $this->kwt_moved) {
  17399. $this->printkwtbuffer();
  17400. $this->kwt_moved = false;
  17401. $this->kwt_saved = false;
  17402. }
  17403. if ($this->progressBar) { $this->UpdateProgressBar(7,30,' '); } // *PROGRESS-BAR*
  17404. // Recursively writes all tables starting at top level
  17405. $this->_tableWrite($this->table[1][1]);
  17406. if ($this->table_rotate && $this->tablebuffer) {
  17407. $this->PageBreakTrigger=$this->h-$this->bMargin;
  17408. $save_tr = $this->table_rotate;
  17409. $save_y = $this->y;
  17410. $this->table_rotate = 0;
  17411. $this->y = $this->tbrot_y0;
  17412. $h = $this->tbrot_w;
  17413. $this->DivLn($h,$this->blklvl,true);
  17414. $this->table_rotate = $save_tr;
  17415. $this->y = $save_y;
  17416. $this->printtablebuffer();
  17417. }
  17418. $this->table_rotate = 0;
  17419. }
  17420. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17421. $this->maxPosR = max($this->maxPosR , ($this->x + $this->table[1][1]['w']));
  17422. $this->blockjustfinished=true;
  17423. $this->lastblockbottommargin = $this->table[1][1]['margin']['B'];
  17424. //Reset values
  17425. if (isset($this->table[1][1]['page_break_after'])) { $page_break_after = $this->table[1][1]['page_break_after']; }
  17426. else { $page_break_after = ''; }
  17427. // Keep-with-table
  17428. $this->kwt = false;
  17429. $this->kwt_y0 = 0;
  17430. $this->kwt_x0 = 0;
  17431. $this->kwt_height = 0;
  17432. $this->kwt_buffer = array();
  17433. $this->kwt_Links = array();
  17434. $this->kwt_Annots = array();
  17435. $this->kwt_moved = false;
  17436. $this->kwt_saved = false;
  17437. $this->kwt_Reference = array();
  17438. $this->kwt_BMoutlines = array();
  17439. $this->kwt_toc = array();
  17440. $this->shrin_k = 1;
  17441. $this->shrink_this_table_to_fit = 0;
  17442. unset($this->table);
  17443. $this->table=array(); //array
  17444. $this->tableLevel=0;
  17445. $this->tbctr=array();
  17446. $this->innermostTableLevel=0;
  17447. $this->cssmgr->tbCSSlvl = 0;
  17448. $this->cssmgr->tablecascadeCSS = array();
  17449. unset($this->cell);
  17450. $this->cell=array(); //array
  17451. $this->col=-1; //int
  17452. $this->row=-1; //int
  17453. $this->Reset();
  17454. $this->cellPaddingL = 0;
  17455. $this->cellPaddingT = 0;
  17456. $this->cellPaddingR = 0;
  17457. $this->cellPaddingB = 0;
  17458. $this->cMarginL = 0;
  17459. $this->cMarginT = 0;
  17460. $this->cMarginR = 0;
  17461. $this->cMarginB = 0;
  17462. $this->default_font_size = $this->original_default_font_size;
  17463. $this->default_font = $this->original_default_font;
  17464. $this->SetFontSize($this->default_font_size, false);
  17465. $this->SetFont($this->default_font,'',0,false);
  17466. $this->SetLineHeight();
  17467. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  17468. if ($this->progressBar) { $this->UpdateProgressBar(7,100,' '); } // *PROGRESS-BAR*
  17469. if ($page_break_after) {
  17470. $save_blklvl = $this->blklvl;
  17471. $save_blk = $this->blk;
  17472. $save_silp = $this->saveInlineProperties();
  17473. $save_spanlvl = $this->spanlvl;
  17474. $save_ilp = $this->InlineProperties;
  17475. if ($this->blklvl>1) {
  17476. // Close any open block tags
  17477. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  17478. // Output any text left in buffer
  17479. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  17480. }
  17481. /*-- COLUMNS --*/
  17482. $save_cols = false;
  17483. if ($this->ColActive) {
  17484. $save_cols = true;
  17485. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  17486. $this->SetColumns(0);
  17487. }
  17488. /*-- END COLUMNS --*/
  17489. if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17490. else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17491. else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17492. if (!$this->restoreBlockPagebreaks) {
  17493. $this->blklvl = 0;
  17494. $this->lastblocklevelchange = 0;
  17495. $this->blk = array();
  17496. $this->initialiseBlock($this->blk[0]);
  17497. $this->blk[0]['width'] =& $this->pgwidth;
  17498. $this->blk[0]['inner_width'] =& $this->pgwidth;
  17499. $this->blk[0]['blockContext'] = $this->blockContext;
  17500. $properties = $this->cssmgr->MergeCSS('BLOCK','BODY','');
  17501. $this->setCSS($properties,'','BODY');
  17502. }
  17503. /*-- COLUMNS --*/
  17504. if ($save_cols) {
  17505. // Restore columns
  17506. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  17507. }
  17508. /*-- END COLUMNS --*/
  17509. if ($this->restoreBlockPagebreaks) {
  17510. $this->blk = $save_blk;
  17511. // Re-open block tags
  17512. $t = $this->blk[0]['tag'];
  17513. $a = $this->blk[0]['attr'];
  17514. $this->blklvl = 0;
  17515. for ($b=0; $b<=$save_blklvl;$b++) {
  17516. $tc = $t;
  17517. $ac = $a;
  17518. $t = $this->blk[$b+1]['tag'];
  17519. $a = $this->blk[$b+1]['attr'];
  17520. unset($this->blk[$b+1]);
  17521. $this->OpenTag($tc,$ac);
  17522. }
  17523. $this->spanlvl = $save_spanlvl;
  17524. $this->InlineProperties = $save_ilp;
  17525. $this->restoreInlineProperties($save_silp);
  17526. }
  17527. }
  17528. }
  17529. /*-- END TABLES --*/
  17530. /*-- LISTS --*/
  17531. // *********** LISTS ********************
  17532. if($tag=='LI') {
  17533. $this->lastoptionaltag = '';
  17534. unset($this->cssmgr->listcascadeCSS[$this->cssmgr->listCSSlvl]);
  17535. $this->cssmgr->listCSSlvl--;
  17536. 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]]); }
  17537. }
  17538. if(($tag=='UL') or ($tag=='OL')) {
  17539. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17540. unset($this->cssmgr->listcascadeCSS[$this->cssmgr->listCSSlvl]);
  17541. $this->cssmgr->listCSSlvl--;
  17542. $this->lastoptionaltag = '';
  17543. /*-- TABLES --*/
  17544. // A simple list for inside a table
  17545. if($this->tableLevel) {
  17546. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  17547. unset($this->listlist[$this->listlvl]);
  17548. $this->listlvl--;
  17549. if (isset($this->listlist[$this->listlvl]['MAXNUM'])) { $this->listnum = $this->listlist[$this->listlvl]['MAXNUM']; } // restore previous levels
  17550. if ($this->listlvl == 0) { $this->listjustfinished = true; }
  17551. return;
  17552. }
  17553. /*-- END TABLES --*/
  17554. if ($this->listlvl > 1) { // returning one level
  17555. $this->listjustfinished=true;
  17556. if (!empty($this->textbuffer)) {
  17557. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17558. }
  17559. else {
  17560. $this->listnum--;
  17561. }
  17562. $this->textbuffer = array();
  17563. $occur = $this->listoccur[$this->listlvl];
  17564. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  17565. $this->listlvl--;
  17566. $occur = $this->listoccur[$this->listlvl];
  17567. $this->listnum = $this->listlist[$this->listlvl][$occur]['MAXNUM']; // recover previous level's number
  17568. $this->listtype = $this->listlist[$this->listlvl][$occur]['TYPE']; // recover previous level's type
  17569. if ($this->InlineProperties['LIST'][$this->listlvl][$occur]) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$occur]); }
  17570. }
  17571. else { // We are closing the last OL/UL tag
  17572. if (!empty($this->textbuffer)) {
  17573. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17574. }
  17575. else {
  17576. $this->listnum--;
  17577. }
  17578. $occur = $this->listoccur[$this->listlvl];
  17579. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum;
  17580. $this->textbuffer = array();
  17581. $this->listlvl--;
  17582. $this->printlistbuffer();
  17583. unset($this->InlineProperties['LIST']);
  17584. // SPACING AFTER LIST (Top level only)
  17585. $this->Ln(0);
  17586. if ($this->list_margin_bottom) {
  17587. $this->DivLn($this->list_margin_bottom,$this->blklvl,true,1); // collapsible
  17588. }
  17589. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  17590. $this->listjustfinished = true;
  17591. $this->cssmgr->listCSSlvl = 0;
  17592. $this->cssmgr->listcascadeCSS = array();
  17593. $this->blockjustfinished=true;
  17594. $this->lastblockbottommargin = $this->list_margin_bottom;
  17595. }
  17596. }
  17597. /*-- END LISTS --*/
  17598. }
  17599. /*-- TABLES --*/
  17600. // This function determines the shrink factor when resizing tables
  17601. // val is the table_height / page_height_available
  17602. // returns a scaling factor used as $shrin_k to resize the table
  17603. // Overcompensating will be quicker but may unnecessarily shrink table too much
  17604. // Undercompensating means it will reiterate more times (taking more processing time)
  17605. function tbsqrt($val, $iteration=3) {
  17606. $k = 4; // Alters number of iterations until it returns $val itself - Must be > 2
  17607. // Probably best guess and most accurate
  17608. if ($iteration==1) return sqrt($val);
  17609. // Faster than using sqrt (because it won't undercompensate), and gives reasonable results
  17610. //return 1+(($val-1)/2);
  17611. $x = 2-(($iteration-2)/($k-2));
  17612. if ($x == 0) { $ret = $val+0.00001; }
  17613. else if ($x < 0) { $ret = 1 + ( pow(2, ($iteration-2-$k))/1000 ); }
  17614. else { $ret = 1+(($val-1)/$x); }
  17615. return $ret;
  17616. }
  17617. /*-- END TABLES --*/
  17618. /*-- LISTS --*/
  17619. function printlistbuffer() {
  17620. //Save x coordinate
  17621. $x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17622. $this->cMarginL = 0;
  17623. $this->cMarginR = 0;
  17624. $currIndentLvl = -1;
  17625. $lastIndent = array();
  17626. $bak_page = $this->page;
  17627. $indent = 0;
  17628. foreach($this->listitem as $item)
  17629. {
  17630. // COLS
  17631. $oldcolumn = $this->CurrCol;
  17632. $this->bulletarray = array();
  17633. //Get list's buffered data
  17634. $this->listlvl = $lvl = $item[0];
  17635. $num = $item[1];
  17636. $this->textbuffer = $item[2];
  17637. $occur = $item[3];
  17638. if ($item[4]) { $type = $item[4]; } // listitemtype
  17639. else { $type = $this->listlist[$lvl][$occur]['TYPE']; }
  17640. $maxnum = $this->listlist[$lvl][$occur]['MAXNUM'];
  17641. $this->restoreInlineProperties($this->InlineProperties['LIST'][$lvl][$occur]);
  17642. $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); // force to write
  17643. $clh = $this->FontSize;
  17644. $this->SetLineHeight($this->FontSizePt,$this->list_lineheight[$lvl][$occur]);
  17645. $this->listOcc = $occur;
  17646. $this->listnum = $num;
  17647. if (isset($this->list_align[$this->listlvl][$occur])) { $this->divalign = $this->list_align[$this->listlvl][$occur]; }
  17648. else {
  17649. if (isset($this->blk[$this->blklvl]['direction']) && $this->blk[$this->blklvl]['direction']=='rtl') { $this->divalign = 'R'; }
  17650. else { $this->divalign = 'L'; }
  17651. }
  17652. // Set the bullet fontsize
  17653. $bullfs = $this->InlineProperties['LISTITEM'][$lvl][$occur][$num]['size'];
  17654. $space_width = $this->GetCharWidth(' ',false) * 1.5;
  17655. //Set default width & height values
  17656. $this->divwidth = $this->blk[$this->blklvl]['inner_width'];
  17657. $this->divheight = $this->lineheight;
  17658. $typefont = $this->FontFamily;
  17659. if (preg_match('/U\+([a-fA-F0-9]+)/i',$type,$m)) {
  17660. if ($this->_charDefined($this->CurrentFont['cw'],hexdec($m[1]))) { $list_item_marker = codeHex2utf($m[1]); }
  17661. else { $list_item_marker = '-'; }
  17662. $blt_width = $this->GetStringWidth($list_item_marker);
  17663. $typefont = '';
  17664. if (preg_match('/rgb\(.*?\)/',$type,$m)) {
  17665. $list_item_color = $this->ConvertColor($m[0]);
  17666. }
  17667. }
  17668. else {
  17669. $list_item_color = false;
  17670. switch($type) //Format type
  17671. {
  17672. case '1':
  17673. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  17674. else { $list_item_marker = $num . $this->list_number_suffix; }
  17675. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  17676. break;
  17677. case 'none':
  17678. $list_item_marker = '';
  17679. $blt_width = 0;
  17680. break;
  17681. case 'A':
  17682. $anum = $this->dec2alpha($num,true);
  17683. $maxnum = $this->dec2alpha($maxnum,true);
  17684. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  17685. else { $list_item_marker = $anum . $this->list_number_suffix; }
  17686. $blt_width = $this->GetStringWidth(str_repeat('W',strlen($maxnum)).$this->list_number_suffix);
  17687. break;
  17688. case 'a':
  17689. $anum = $this->dec2alpha($num,false);
  17690. $maxnum = $this->dec2alpha($maxnum,false);
  17691. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  17692. else { $list_item_marker = $anum . $this->list_number_suffix; }
  17693. $blt_width = $this->GetStringWidth(str_repeat('m',strlen($maxnum)).$this->list_number_suffix);
  17694. break;
  17695. case 'I':
  17696. $anum = $this->dec2roman($num,true);
  17697. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  17698. else { $list_item_marker = $anum . $this->list_number_suffix; }
  17699. if ($maxnum>87) { $bbit = 87; }
  17700. else if ($maxnum>86) { $bbit = 86; }
  17701. else if ($maxnum>37) { $bbit = 38; }
  17702. else if ($maxnum>36) { $bbit = 37; }
  17703. else if ($maxnum>27) { $bbit = 28; }
  17704. else if ($maxnum>26) { $bbit = 27; }
  17705. else if ($maxnum>17) { $bbit = 18; }
  17706. else if ($maxnum>16) { $bbit = 17; }
  17707. else if ($maxnum>7) { $bbit = 8; }
  17708. else if ($maxnum>6) { $bbit = 7; }
  17709. else if ($maxnum>3) { $bbit = 4; }
  17710. else { $bbit = $maxnum; }
  17711. $maxlnum = $this->dec2roman($bbit,true);
  17712. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  17713. break;
  17714. case 'i':
  17715. $anum = $this->dec2roman($num,false);
  17716. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  17717. else { $list_item_marker = $anum . $this->list_number_suffix; }
  17718. if ($maxnum>87) { $bbit = 87; }
  17719. else if ($maxnum>86) { $bbit = 86; }
  17720. else if ($maxnum>37) { $bbit = 38; }
  17721. else if ($maxnum>36) { $bbit = 37; }
  17722. else if ($maxnum>27) { $bbit = 28; }
  17723. else if ($maxnum>26) { $bbit = 27; }
  17724. else if ($maxnum>17) { $bbit = 18; }
  17725. else if ($maxnum>16) { $bbit = 17; }
  17726. else if ($maxnum>7) { $bbit = 8; }
  17727. else if ($maxnum>6) { $bbit = 7; }
  17728. else if ($maxnum>3) { $bbit = 4; }
  17729. else { $bbit = $maxnum; }
  17730. $maxlnum = $this->dec2roman($bbit,false);
  17731. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  17732. break;
  17733. case 'disc':
  17734. if ($this->PDFA || $this->PDFX) {
  17735. if ($this->_charDefined($this->CurrentFont['cw'],8226)) { $list_item_marker = "\xe2\x80\xa2"; } // &#8226;
  17736. else { $list_item_marker = '-'; }
  17737. $blt_width = $this->GetCharWidth($list_item_marker);
  17738. break;
  17739. }
  17740. $list_item_marker = chr(108); // bullet disc in Zapfdingbats 'l'
  17741. $typefont = 'czapfdingbats';
  17742. $blt_width = (0.791 * $this->FontSize/2.5);
  17743. break;
  17744. case 'circle':
  17745. if ($this->PDFA || $this->PDFX) {
  17746. if ($this->_charDefined($this->CurrentFont['cw'],9900)) { $list_item_marker = "\xe2\x9a\xac"; } // &#9900;
  17747. else { $list_item_marker = '-'; }
  17748. $blt_width = $this->GetCharWidth($list_item_marker);
  17749. break;
  17750. }
  17751. $list_item_marker = chr(109); // circle in Zapfdingbats 'm'
  17752. $typefont = 'czapfdingbats';
  17753. $blt_width = (0.873 * $this->FontSize/2.5);
  17754. break;
  17755. case 'square':
  17756. if ($this->PDFA || $this->PDFX) {
  17757. if ($this->_charDefined($this->CurrentFont['cw'],9642)) { $list_item_marker = "\xe2\x96\xaa"; } // &#9642;
  17758. else { $list_item_marker = '-'; }
  17759. $blt_width = $this->GetCharWidth($list_item_marker);
  17760. break;
  17761. }
  17762. $list_item_marker = chr(110); //black square in Zapfdingbats font 'n'
  17763. $typefont = 'czapfdingbats';
  17764. $blt_width = (0.761 * $this->FontSize/2.5);
  17765. break;
  17766. /* CSS3 list-styles numeric + I added tamil
  17767. arabic-indic | bengali | cambodian | devanagari | gujarati | gurmukhi | kannada | khmer | lao | malayalam | mongolian | myanmar | oriya | persian | telugu | tibetan | thai | urdu
  17768. */
  17769. case 'arabic-indic':
  17770. $cp = 0x0660;
  17771. $rnum = $this->dec2other($num, $cp);
  17772. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  17773. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17774. break;
  17775. case 'persian':
  17776. case 'urdu':
  17777. $cp = 0x06F0;
  17778. $rnum = $this->dec2other($num, $cp);
  17779. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  17780. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17781. break;
  17782. case 'bengali':
  17783. $cp = 0x09E6;
  17784. $rnum = $this->dec2other($num, $cp);
  17785. $list_item_marker = $rnum . $this->list_number_suffix;
  17786. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17787. break;
  17788. case 'devanagari':
  17789. $cp = 0x0966;
  17790. $rnum = $this->dec2other($num, $cp);
  17791. $list_item_marker = $rnum . $this->list_number_suffix;
  17792. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17793. break;
  17794. case 'gujarati':
  17795. $cp = 0x0AE6;
  17796. $rnum = $this->dec2other($num, $cp);
  17797. $list_item_marker = $rnum . $this->list_number_suffix;
  17798. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17799. break;
  17800. case 'gurmukhi':
  17801. $cp = 0x0A66;
  17802. $rnum = $this->dec2other($num, $cp);
  17803. $list_item_marker = $rnum . $this->list_number_suffix;
  17804. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17805. break;
  17806. case 'kannada':
  17807. $cp = 0x0CE6;
  17808. $rnum = $this->dec2other($num, $cp);
  17809. $list_item_marker = $rnum . $this->list_number_suffix;
  17810. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17811. break;
  17812. case 'malayalam':
  17813. $cp = 0x0D66;
  17814. $rnum = $this->dec2other($num, $cp);
  17815. $list_item_marker = $rnum . $this->list_number_suffix;
  17816. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(6, $cp),strlen($maxnum)).$this->list_number_suffix);
  17817. break;
  17818. case 'oriya':
  17819. $cp = 0x0B66;
  17820. $rnum = $this->dec2other($num, $cp);
  17821. $list_item_marker = $rnum . $this->list_number_suffix;
  17822. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17823. break;
  17824. case 'telugu':
  17825. $cp = 0x0C66;
  17826. $rnum = $this->dec2other($num, $cp);
  17827. $list_item_marker = $rnum . $this->list_number_suffix;
  17828. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  17829. break;
  17830. case 'tamil':
  17831. $cp = 0x0BE6;
  17832. $rnum = $this->dec2other($num, $cp);
  17833. $list_item_marker = $rnum . $this->list_number_suffix;
  17834. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(9, $cp),strlen($maxnum)).$this->list_number_suffix);
  17835. break;
  17836. case 'thai':
  17837. $cp = 0x0E50;
  17838. $rnum = $this->dec2other($num, $cp);
  17839. $list_item_marker = $rnum . $this->list_number_suffix;
  17840. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(5, $cp),strlen($maxnum)).$this->list_number_suffix);
  17841. break;
  17842. default:
  17843. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  17844. else { $list_item_marker = $num . $this->list_number_suffix; }
  17845. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  17846. break;
  17847. }
  17848. }
  17849. if (isset($item[5]) && $item[5]) { $list_item_marker = ''; }
  17850. if ($currIndentLvl < $lvl) {
  17851. if ($lvl > 1 || $this->list_indent_first_level) {
  17852. $indent += $this->list_indent[$lvl][$occur];
  17853. $lastIndent[$lvl] = $this->list_indent[$lvl][$occur];
  17854. }
  17855. }
  17856. else if ($currIndentLvl > $lvl) {
  17857. while ($currIndentLvl > $lvl) {
  17858. $indent -= $lastIndent[$currIndentLvl];
  17859. $currIndentLvl--;
  17860. }
  17861. }
  17862. $currIndentLvl = $lvl;
  17863. /*-- RTL --*/
  17864. if ($this->listDir == 'rtl') {
  17865. // list_align_style Determines alignment of numbers in numbered lists
  17866. if ($this->list_align_style == 'L') { $lalign = 'R'; }
  17867. else { $lalign = 'L'; }
  17868. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  17869. $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)
  17870. //Output bullet
  17871. $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 );
  17872. $this->x = $x;
  17873. }
  17874. else {
  17875. /*-- END RTL --*/
  17876. if ($this->list_align_style == 'L') { $lalign = 'L'; }
  17877. else { $lalign = 'R'; }
  17878. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  17879. $xb = $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] - $blt_width - $space_width;
  17880. //Output bullet
  17881. $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 );
  17882. $this->x = $x + $indent + $blt_width + $space_width;
  17883. } // *RTL*
  17884. //Print content
  17885. $this->printbuffer($this->textbuffer,'',false,true);
  17886. $this->textbuffer=array();
  17887. // Added to correct for OddEven Margins
  17888. if ($this->page != $bak_page) {
  17889. if (($this->page-$bak_page) % 2 == 1) {
  17890. $x += $this->MarginCorrection;
  17891. }
  17892. $bak_page = $this->page;
  17893. }
  17894. /*-- COLUMNS --*/
  17895. // OR COLUMN CHANGE
  17896. if ($this->CurrCol != $oldcolumn) {
  17897. if ($this->directionality == 'rtl') { // *RTL*
  17898. $x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  17899. } // *RTL*
  17900. else { // *RTL*
  17901. $x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  17902. } // *RTL*
  17903. $oldcolumn = $this->CurrCol;
  17904. }
  17905. /*-- END COLUMNS --*/
  17906. }
  17907. //Reset all used values
  17908. $this->listoccur = array();
  17909. $this->listitem = array();
  17910. $this->listlist = array();
  17911. $this->listlvl = 0;
  17912. $this->listnum = 0;
  17913. $this->listtype = '';
  17914. $this->textbuffer = array();
  17915. $this->divwidth = 0;
  17916. $this->divheight = 0;
  17917. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17918. }
  17919. /*-- END LISTS --*/
  17920. function _saveTextBuffer($t, $link = '', $intlink = '') {
  17921. // $this->textbuffer[] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->textparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow);
  17922. // mPDF 5.6.14
  17923. $arr = array();
  17924. $arr[0] = $t;
  17925. if (isset($link) && $link) $arr[1] = $link;
  17926. $arr[2] = $this->currentfontstyle;
  17927. if (isset($this->colorarray) && $this->colorarray) $arr[3] = $this->colorarray;
  17928. $arr[4] = $this->currentfontfamily;
  17929. if (isset($this->SUP) && $this->SUP) $arr[5] = $this->SUP;
  17930. if (isset($this->SUB) && $this->SUB) $arr[6] = $this->SUB;
  17931. if (isset($intlink) && $intlink) $arr[7] = $intlink;
  17932. if (isset($this->strike) && $this->strike) $arr[8] = $this->strike;
  17933. if (isset($this->textparam) && $this->textparam) $arr[9] = $this->textparam;
  17934. if (isset($this->spanbgcolorarray) && $this->spanbgcolorarray) $arr[10] = $this->spanbgcolorarray;
  17935. $arr[11] = $this->currentfontsize;
  17936. if (isset($this->ReqFontStyle) && $this->ReqFontStyle) $arr[12] = $this->ReqFontStyle;
  17937. if (isset($this->kerning) && $this->kerning) $arr[13] = $this->kerning;
  17938. if (isset($this->lSpacingCSS) && $this->lSpacingCSS) $arr[14] = $this->lSpacingCSS;
  17939. if (isset($this->wSpacingCSS) && $this->wSpacingCSS) $arr[15] = $this->wSpacingCSS;
  17940. if (isset($this->spanborddet) && $this->spanborddet) $arr[16] = $this->spanborddet;
  17941. if (isset($this->textshadow) && $this->textshadow) $arr[17] = $this->textshadow;
  17942. $this->textbuffer[] = $arr;
  17943. }
  17944. function _saveCellTextBuffer($t, $link = '', $intlink = '') {
  17945. // $this->cell[$this->row][$this->col]['textbuffer'][] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->textparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow);
  17946. // mPDF 5.6.14
  17947. $arr = array();
  17948. $arr[0] = $t;
  17949. if (isset($link) && $link) $arr[1] = $link;
  17950. $arr[2] = $this->currentfontstyle;
  17951. if (isset($this->colorarray) && $this->colorarray) $arr[3] = $this->colorarray;
  17952. $arr[4] = $this->currentfontfamily;
  17953. if (isset($this->SUP) && $this->SUP) $arr[5] = $this->SUP;
  17954. if (isset($this->SUB) && $this->SUB) $arr[6] = $this->SUB;
  17955. if (isset($intlink) && $intlink) $arr[7] = $intlink;
  17956. if (isset($this->strike) && $this->strike) $arr[8] = $this->strike;
  17957. if (isset($this->textparam) && $this->textparam) $arr[9] = $this->textparam;
  17958. if (isset($this->spanbgcolorarray) && $this->spanbgcolorarray) $arr[10] = $this->spanbgcolorarray;
  17959. $arr[11] = $this->currentfontsize;
  17960. if (isset($this->ReqFontStyle) && $this->ReqFontStyle) $arr[12] = $this->ReqFontStyle;
  17961. if (isset($this->kerning) && $this->kerning) $arr[13] = $this->kerning;
  17962. if (isset($this->lSpacingCSS) && $this->lSpacingCSS) $arr[14] = $this->lSpacingCSS;
  17963. if (isset($this->wSpacingCSS) && $this->wSpacingCSS) $arr[15] = $this->wSpacingCSS;
  17964. if (isset($this->spanborddet) && $this->spanborddet) $arr[16] = $this->spanborddet;
  17965. if (isset($this->textshadow) && $this->textshadow) $arr[17] = $this->textshadow;
  17966. $this->cell[$this->row][$this->col]['textbuffer'][] = $arr;
  17967. }
  17968. function printbuffer($arrayaux,$blockstate=0,$is_table=false,$is_list=false)
  17969. {
  17970. // $blockstate = 0; // NO margins/padding
  17971. // $blockstate = 1; // Top margins/padding only
  17972. // $blockstate = 2; // Bottom margins/padding only
  17973. // $blockstate = 3; // Top & bottom margins/padding
  17974. $this->spanbgcolorarray = '';
  17975. $this->spanbgcolor = false;
  17976. $this->spanborder = false;
  17977. $this->spanborddet = array();
  17978. $paint_ht_corr = 0;
  17979. /*-- CSS-FLOAT --*/
  17980. if (count($this->floatDivs)) {
  17981. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  17982. if (($this->blk[$this->blklvl]['inner_width']-$l_width-$r_width) < (2*$this->GetCharWidth('W',false))) {
  17983. // Too narrow to fit - try to move down past L or R float
  17984. if ($l_max < $r_max && ($this->blk[$this->blklvl]['inner_width']-$r_width) > (2*$this->GetCharWidth('W',false))) {
  17985. $this->ClearFloats('LEFT', $this->blklvl);
  17986. }
  17987. else if ($r_max < $l_max && ($this->blk[$this->blklvl]['inner_width']-$l_width) > (2*$this->GetCharWidth('W',false))) {
  17988. $this->ClearFloats('RIGHT', $this->blklvl);
  17989. }
  17990. else { $this->ClearFloats('BOTH', $this->blklvl); }
  17991. }
  17992. }
  17993. /*-- END CSS-FLOAT --*/
  17994. $bak_y = $this->y;
  17995. $bak_x = $this->x;
  17996. $align = '';
  17997. if (!$is_table && !$is_list) {
  17998. if (isset($this->blk[$this->blklvl]['align']) && $this->blk[$this->blklvl]['align']) { $align = $this->blk[$this->blklvl]['align']; }
  17999. // Block-align is set by e.g. <.. align="center"> Takes priority for this block but not inherited
  18000. if (isset($this->blk[$this->blklvl]['block-align']) && $this->blk[$this->blklvl]['block-align']) { $align = $this->blk[$this->blklvl]['block-align']; }
  18001. if (isset($this->blk[$this->blklvl]['direction'])) $blockdir = $this->blk[$this->blklvl]['direction'];
  18002. else $blockdir = "";
  18003. $this->divwidth = $this->blk[$this->blklvl]['width'];
  18004. }
  18005. else {
  18006. $align = $this->divalign;
  18007. if ($is_table) { $blockdir = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']; }
  18008. else { $blockdir = $this->listDir; }
  18009. }
  18010. $oldpage = $this->page;
  18011. // ADDED for Out of Block now done as Flowing Block
  18012. if ($this->divwidth == 0) {
  18013. $this->divwidth = $this->pgwidth;
  18014. }
  18015. if (!$is_table && !$is_list) { $this->SetLineHeight($this->FontSizePt,$this->blk[$this->blklvl]['line_height']); }
  18016. $this->divheight = $this->lineheight;
  18017. $old_height = $this->divheight;
  18018. // As a failsafe - if font has been set but not output to page
  18019. $this->SetFont($this->default_font,'',$this->default_font_size,true,true); // force output to page
  18020. $array_size = count($arrayaux);
  18021. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,true,$blockdir);
  18022. // Added - Otherwise <div><div><p> did not output top margins/padding for 1st/2nd div
  18023. if ($array_size == 0) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18024. for($i=0;$i < $array_size; $i++)
  18025. {
  18026. // COLS
  18027. $oldcolumn = $this->CurrCol;
  18028. $vetor = $arrayaux[$i];
  18029. if ($i == 0 and $vetor[0] != "\n" and !$this->ispre) {
  18030. $vetor[0] = ltrim($vetor[0]);
  18031. }
  18032. // FIXED TO ALLOW IT TO SHOW '0'
  18033. if (empty($vetor[0]) && !($vetor[0]==='0') && empty($vetor[7])) { //Ignore empty text and not carrying an internal link
  18034. //Check if it is the last element. If so then finish printing the block
  18035. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18036. continue;
  18037. }
  18038. //Activating buffer properties
  18039. if(isset($vetor[11]) and $vetor[11] != '') { // Font Size
  18040. if ($is_table && $this->shrin_k) {
  18041. $this->SetFontSize($vetor[11]/$this->shrin_k,false);
  18042. }
  18043. else {
  18044. $this->SetFontSize($vetor[11],false);
  18045. }
  18046. }
  18047. if(isset($vetor[17]) && !empty($vetor[17])) { //TextShadow
  18048. $this->textshadow = $vetor[17];
  18049. }
  18050. if(isset($vetor[16]) && !empty($vetor[16])) { //Border
  18051. $this->spanborddet = $vetor[16];
  18052. $this->spanborder = true;
  18053. }
  18054. if(isset($vetor[15])) { // Word spacing
  18055. $this->wSpacingCSS = $vetor[15];
  18056. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  18057. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  18058. }
  18059. }
  18060. if(isset($vetor[14])) { // Letter spacing
  18061. $this->lSpacingCSS = $vetor[14];
  18062. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  18063. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  18064. }
  18065. }
  18066. if(isset($vetor[13])) { // Font Kerning
  18067. $this->kerning = $vetor[13];
  18068. }
  18069. if(isset($vetor[10]) and !empty($vetor[10])) //Background color
  18070. {
  18071. $this->spanbgcolorarray = $vetor[10];
  18072. $this->spanbgcolor = true;
  18073. }
  18074. if(isset($vetor[9]) and !empty($vetor[9])) // Text parameters - Outline + hyphens
  18075. {
  18076. $this->textparam = $vetor[9] ; // mPDF 5.6.14
  18077. $this->SetTextOutline($this->textparam); // mPDF 5.6.07
  18078. }
  18079. if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text
  18080. {
  18081. $this->strike = true;
  18082. }
  18083. if(isset($vetor[7]) and $vetor[7] != '') // internal target: <a name="anyvalue">
  18084. {
  18085. $ily = $this->y;
  18086. if ($this->keep_block_together) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kt"=>true ); }
  18087. else if ($this->table_rotate) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "tbrot"=>true ); }
  18088. else if ($this->kwt) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kwt"=>true ); }
  18089. else if ($this->ColActive) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "col"=>$this->CurrCol ); }
  18090. else
  18091. $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page );
  18092. if (empty($vetor[0])) { //Ignore empty text
  18093. //Check if it is the last element. If so then finish printing the block
  18094. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18095. continue;
  18096. }
  18097. }
  18098. if(isset($vetor[6]) and $vetor[6] === true) // Subscript
  18099. {
  18100. $this->SUB = true;
  18101. }
  18102. if(isset($vetor[5]) and $vetor[5] === true) // Superscript
  18103. {
  18104. $this->SUP = true;
  18105. }
  18106. if(isset($vetor[4]) and $vetor[4] != '') { // Font Family
  18107. $font = $this->SetFont($vetor[4],$this->FontStyle,0,false);
  18108. }
  18109. if (!empty($vetor[3])) //Font Color
  18110. {
  18111. $cor = $vetor[3];
  18112. $this->SetTColor($cor);
  18113. }
  18114. if(isset($vetor[2]) and $vetor[2] != '') //Bold,Italic,Underline styles
  18115. {
  18116. $this->SetStyles($vetor[2]);
  18117. }
  18118. if(isset($vetor[12]) and $vetor[12] != '') { //Requested Bold,Italic,Underline
  18119. $this->ReqFontStyle = $vetor[12];
  18120. }
  18121. if(isset($vetor[1]) and $vetor[1] != '') //LINK
  18122. {
  18123. 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.)
  18124. {
  18125. //Repeated reference to same anchor?
  18126. while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
  18127. $this->internallink[$vetor[1]] = $this->AddLink();
  18128. $vetor[1] = $this->internallink[$vetor[1]];
  18129. }
  18130. $this->HREF = $vetor[1]; // HREF link style set here ******
  18131. }
  18132. // SPECIAL CONTENT - IMAGES & FORM OBJECTS
  18133. //Print-out special content
  18134. if (substr($vetor[0],0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  18135. $objattr = $this->_getObjAttr($vetor[0]);
  18136. /*-- TABLES --*/
  18137. if ($objattr['type'] == 'nestedtable') {
  18138. if ($objattr['nestedcontent']) {
  18139. $level = $objattr['level'];
  18140. $table = &$this->table[$level][$objattr['table']];
  18141. if ($this->cacheTables) {
  18142. $fh = fopen($table['cache'], "r+b");
  18143. $cell = $this->_uncacheCell($table['cells'][$objattr['row']][$objattr['col']], '', $fh);
  18144. }
  18145. else {
  18146. $fh = null;
  18147. $cell = &$table['cells'][$objattr['row']][$objattr['col']];
  18148. }
  18149. $this->finishFlowingBlock(false,'nestedtable');
  18150. $save_dw = $this->divwidth ;
  18151. $save_buffer = $this->cellBorderBuffer;
  18152. $this->cellBorderBuffer = array();
  18153. $ncx = $this->x;
  18154. list($dummyx,$w) = $this->_tableGetWidth($table, $objattr['row'], $objattr['col'], $fh);
  18155. $ntw = $this->table[($level+1)][$objattr['nestedcontent']]['w']; // nested table width
  18156. if (!$this->simpleTables){
  18157. if ($this->packTableData) {
  18158. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cell['borderbin']);
  18159. }
  18160. else {
  18161. $br = $cell['border_details']['R']['w'];
  18162. $bl = $cell['border_details']['L']['w'];
  18163. }
  18164. if ($table['borders_separate']) {
  18165. $innerw = $w - $bl - $br - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18166. }
  18167. else {
  18168. $innerw = $w - $bl/2 - $br/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18169. }
  18170. }
  18171. else if ($this->simpleTables){
  18172. if ($table['borders_separate']) {
  18173. $innerw = $w - $table['simple']['border_details']['L']['w'] - $table['simple']['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18174. }
  18175. else {
  18176. $innerw = $w - $table['simple']['border_details']['L']['w']/2 - $table['simple']['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18177. }
  18178. }
  18179. if ($cell['a']=='C' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='C') {
  18180. $ncx += ($innerw-$ntw)/2;
  18181. }
  18182. elseif ($cell['a']=='R' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='R') {
  18183. $ncx += $innerw- $ntw;
  18184. }
  18185. $this->x = $ncx ;
  18186. if ($this->cacheTables) { fclose($fh); }
  18187. $this->_tableWrite($this->table[($level+1)][$objattr['nestedcontent']]);
  18188. $this->cellBorderBuffer = $save_buffer;
  18189. $this->x = $bak_x ;
  18190. $this->divwidth = $save_dw;
  18191. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18192. }
  18193. }
  18194. else {
  18195. /*-- END TABLES --*/
  18196. if ($is_table) { // *TABLES*
  18197. $maxWidth = $this->divwidth; // *TABLES*
  18198. } // *TABLES*
  18199. else { // *TABLES*
  18200. $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']);
  18201. } // *TABLES*
  18202. /*-- CSS-IMAGE-FLOAT --*/
  18203. // If float (already) exists at this level
  18204. if (isset($this->floatmargins['R']) && $this->y <= $this->floatmargins['R']['y1'] && $this->y >= $this->floatmargins['R']['y0']) { $maxWidth -= $this->floatmargins['R']['w']; }
  18205. if (isset($this->floatmargins['L']) && $this->y <= $this->floatmargins['L']['y1'] && $this->y >= $this->floatmargins['L']['y0']) { $maxWidth -= $this->floatmargins['L']['w']; }
  18206. /*-- END CSS-IMAGE-FLOAT --*/
  18207. list($skipln) = $this->inlineObject($objattr['type'], '', $this->y, $objattr,$this->lMargin, ($this->flowingBlockAttr['contentWidth']/_MPDFK), $maxWidth, $this->flowingBlockAttr['height'], false, $is_table);
  18208. // 1 -> New line needed because of width
  18209. // -1 -> Will fit width on line but NEW PAGE REQUIRED because of height
  18210. // -2 -> Will not fit on line therefore needs new line but thus NEW PAGE REQUIRED
  18211. $iby = $this->y;
  18212. $oldpage = $this->page;
  18213. $oldcol = $this->CurrCol;
  18214. if (($skipln == 1 || $skipln == -2) && !isset($objattr['float'])) {
  18215. $this->finishFlowingBlock(false,$objattr['type']);
  18216. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18217. }
  18218. $thispage = $this->page;
  18219. if ($this->CurrCol!=$oldcol) { $changedcol = true; }
  18220. else { $changedcol=false; }
  18221. // the previous lines can already have triggered page break or column change
  18222. if (!$changedcol && $skipln <0 && $this->AcceptPageBreak() && $thispage==$oldpage) {
  18223. $this->AddPage($this->CurOrientation);
  18224. // Added to correct Images already set on line before page advanced
  18225. // i.e. if second inline image on line is higher than first and forces new page
  18226. if (count($this->objectbuffer)) {
  18227. $yadj = $iby - $this->y;
  18228. foreach($this->objectbuffer AS $ib=>$val) {
  18229. if ($this->objectbuffer[$ib]['OUTER-Y'] ) $this->objectbuffer[$ib]['OUTER-Y'] -= $yadj;
  18230. if ($this->objectbuffer[$ib]['BORDER-Y']) $this->objectbuffer[$ib]['BORDER-Y'] -= $yadj;
  18231. if ($this->objectbuffer[$ib]['INNER-Y']) $this->objectbuffer[$ib]['INNER-Y'] -= $yadj;
  18232. }
  18233. }
  18234. }
  18235. // Added to correct for OddEven Margins
  18236. if ($this->page != $oldpage) {
  18237. if (($this->page-$oldpage) % 2 == 1) {
  18238. $bak_x += $this->MarginCorrection;
  18239. }
  18240. $oldpage = $this->page;
  18241. $y = $this->tMargin - $paint_ht_corr ;
  18242. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18243. $old_height = 0;
  18244. }
  18245. $this->x = $bak_x;
  18246. /*-- COLUMNS --*/
  18247. // COLS
  18248. // OR COLUMN CHANGE
  18249. if ($this->CurrCol != $oldcolumn) {
  18250. if ($this->directionality == 'rtl') { // *RTL*
  18251. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18252. } // *RTL*
  18253. else { // *RTL*
  18254. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18255. } // *RTL*
  18256. $this->x = $bak_x;
  18257. $oldcolumn = $this->CurrCol;
  18258. $y = $this->y0 - $paint_ht_corr ;
  18259. $this->oldy = $this->y0 - $paint_ht_corr ;
  18260. $old_height = 0;
  18261. }
  18262. /*-- END COLUMNS --*/
  18263. /*-- CSS-IMAGE-FLOAT --*/
  18264. if ($objattr['type'] == 'image' && isset($objattr['float'])) {
  18265. $fy = $this->y;
  18266. // DIV TOP MARGIN/BORDER/PADDING
  18267. if ($this->flowingBlockAttr['newblock'] && ($this->flowingBlockAttr['blockstate']==1 || $this->flowingBlockAttr['blockstate']==3) && $this->flowingBlockAttr['lineCount']== 0) {
  18268. $fy += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  18269. }
  18270. if ($objattr['float']=='R') {
  18271. $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']);
  18272. }
  18273. else if ($objattr['float']=='L') {
  18274. $fx = $this->lMargin + ($this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left']);
  18275. }
  18276. $w = $objattr['width'];
  18277. $h = abs($objattr['height']);
  18278. $widthLeft = $maxWidth - ($this->flowingBlockAttr['contentWidth']/_MPDFK);
  18279. $maxHeight = $this->h - ($this->tMargin + $this->margin_header + $this->bMargin + 10) ;
  18280. // For Images
  18281. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right']);
  18282. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom']);
  18283. if ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg') {
  18284. $file = $objattr['file'];
  18285. $info=$this->formobjects[$file];
  18286. }
  18287. else {
  18288. $file = $objattr['file'];
  18289. $info=$this->images[$file];
  18290. }
  18291. $img_w = $w - $extraWidth ;
  18292. $img_h = $h - $extraHeight ;
  18293. if ($objattr['border_left']['w']) {
  18294. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w'] + $objattr['border_right']['w'])/2) ;
  18295. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w'] + $objattr['border_bottom']['w'])/2) ;
  18296. $objattr['BORDER-X'] = $fx + $objattr['margin_left'] + (($objattr['border_left']['w'])/2) ;
  18297. $objattr['BORDER-Y'] = $fy + $objattr['margin_top'] + (($objattr['border_top']['w'])/2) ;
  18298. }
  18299. $objattr['INNER-WIDTH'] = $img_w;
  18300. $objattr['INNER-HEIGHT'] = $img_h;
  18301. $objattr['INNER-X'] = $fx + $objattr['margin_left'] + ($objattr['border_left']['w']);
  18302. $objattr['INNER-Y'] = $fy + $objattr['margin_top'] + ($objattr['border_top']['w']) ;
  18303. $objattr['ID'] = $info['i'];
  18304. $objattr['OUTER-WIDTH'] = $w;
  18305. $objattr['OUTER-HEIGHT'] = $h;
  18306. $objattr['OUTER-X'] = $fx;
  18307. $objattr['OUTER-Y'] = $fy;
  18308. if ($objattr['float']=='R') {
  18309. // If R float already exists at this level
  18310. $this->floatmargins['R']['skipline'] = false;
  18311. if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  18312. $this->WriteFlowingBlock($vetor[0]);
  18313. }
  18314. // If L float already exists at this level
  18315. else if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  18316. // Final check distance between floats is not now too narrow to fit text
  18317. $mw = 2*$this->GetCharWidth('W',false);
  18318. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['L']['w']) < $mw) {
  18319. $this->WriteFlowingBlock($vetor[0]);
  18320. }
  18321. else {
  18322. $this->floatmargins['R']['x'] = $fx;
  18323. $this->floatmargins['R']['w'] = $w;
  18324. $this->floatmargins['R']['y0'] = $fy;
  18325. $this->floatmargins['R']['y1'] = $fy + $h;
  18326. if ($skipln == 1) {
  18327. $this->floatmargins['R']['skipline'] = true;
  18328. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  18329. $objattr['skipline'] = true;
  18330. }
  18331. $this->floatbuffer[] = $objattr;
  18332. }
  18333. }
  18334. else {
  18335. $this->floatmargins['R']['x'] = $fx;
  18336. $this->floatmargins['R']['w'] = $w;
  18337. $this->floatmargins['R']['y0'] = $fy;
  18338. $this->floatmargins['R']['y1'] = $fy + $h;
  18339. if ($skipln == 1) {
  18340. $this->floatmargins['R']['skipline'] = true;
  18341. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  18342. $objattr['skipline'] = true;
  18343. }
  18344. $this->floatbuffer[] = $objattr;
  18345. }
  18346. }
  18347. else if ($objattr['float']=='L') {
  18348. // If L float already exists at this level
  18349. $this->floatmargins['L']['skipline'] = false;
  18350. if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  18351. $this->floatmargins['L']['skipline'] = false;
  18352. $this->WriteFlowingBlock($vetor[0]);
  18353. }
  18354. // If R float already exists at this level
  18355. else if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  18356. // Final check distance between floats is not now too narrow to fit text
  18357. $mw = 2*$this->GetCharWidth('W',false);
  18358. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['R']['w']) < $mw) {
  18359. $this->WriteFlowingBlock($vetor[0]);
  18360. }
  18361. else {
  18362. $this->floatmargins['L']['x'] = $fx + $w;
  18363. $this->floatmargins['L']['w'] = $w;
  18364. $this->floatmargins['L']['y0'] = $fy;
  18365. $this->floatmargins['L']['y1'] = $fy + $h;
  18366. if ($skipln == 1) {
  18367. $this->floatmargins['L']['skipline'] = true;
  18368. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  18369. $objattr['skipline'] = true;
  18370. }
  18371. $this->floatbuffer[] = $objattr;
  18372. }
  18373. }
  18374. else {
  18375. $this->floatmargins['L']['x'] = $fx + $w;
  18376. $this->floatmargins['L']['w'] = $w;
  18377. $this->floatmargins['L']['y0'] = $fy;
  18378. $this->floatmargins['L']['y1'] = $fy + $h;
  18379. if ($skipln == 1) {
  18380. $this->floatmargins['L']['skipline'] = true;
  18381. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  18382. $objattr['skipline'] = true;
  18383. }
  18384. $this->floatbuffer[] = $objattr;
  18385. }
  18386. }
  18387. }
  18388. else {
  18389. /*-- END CSS-IMAGE-FLOAT --*/
  18390. $this->WriteFlowingBlock($vetor[0]);
  18391. /*-- CSS-IMAGE-FLOAT --*/
  18392. }
  18393. /*-- END CSS-IMAGE-FLOAT --*/
  18394. } // *TABLES*
  18395. } // END If special content
  18396. else { //THE text
  18397. if ($this->tableLevel) { $paint_ht_corr = 0; } // To move the y up when new column/page started if div border needed
  18398. else { $paint_ht_corr = $this->blk[$this->blklvl]['border_top']['w']; }
  18399. if ($vetor[0] == "\n") { //We are reading a <BR> now turned into newline ("\n")
  18400. if ($this->flowingBlockAttr['content']) {
  18401. $this->finishFlowingBlock(false,'br');
  18402. }
  18403. else if ($is_table) {
  18404. $this->y+= $this->_computeLineheight($this->table_lineheight);
  18405. }
  18406. else if (!$is_table) {
  18407. $this->DivLn($this->lineheight);
  18408. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  18409. }
  18410. // Added to correct for OddEven Margins
  18411. if ($this->page != $oldpage) {
  18412. if (($this->page-$oldpage) % 2 == 1) {
  18413. $bak_x += $this->MarginCorrection;
  18414. }
  18415. $oldpage = $this->page;
  18416. $y = $this->tMargin - $paint_ht_corr ;
  18417. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18418. $old_height = 0;
  18419. }
  18420. $this->x = $bak_x;
  18421. /*-- COLUMNS --*/
  18422. // COLS
  18423. // OR COLUMN CHANGE
  18424. if ($this->CurrCol != $oldcolumn) {
  18425. if ($this->directionality == 'rtl') { // *RTL*
  18426. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18427. } // *RTL*
  18428. else { // *RTL*
  18429. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18430. } // *RTL*
  18431. $this->x = $bak_x;
  18432. $oldcolumn = $this->CurrCol;
  18433. $y = $this->y0 - $paint_ht_corr ;
  18434. $this->oldy = $this->y0 - $paint_ht_corr ;
  18435. $old_height = 0;
  18436. }
  18437. /*-- END COLUMNS --*/
  18438. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18439. }
  18440. else {
  18441. $this->WriteFlowingBlock( $vetor[0]);
  18442. // Added to correct for OddEven Margins
  18443. if ($this->page != $oldpage) {
  18444. if (($this->page-$oldpage) % 2 == 1) {
  18445. $bak_x += $this->MarginCorrection;
  18446. $this->x = $bak_x;
  18447. }
  18448. $oldpage = $this->page;
  18449. $y = $this->tMargin - $paint_ht_corr ;
  18450. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18451. $old_height = 0;
  18452. }
  18453. /*-- COLUMNS --*/
  18454. // COLS
  18455. // OR COLUMN CHANGE
  18456. if ($this->CurrCol != $oldcolumn) {
  18457. if ($this->directionality == 'rtl') { // *RTL*
  18458. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18459. } // *RTL*
  18460. else { // *RTL*
  18461. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18462. } // *RTL*
  18463. $this->x = $bak_x;
  18464. $oldcolumn = $this->CurrCol;
  18465. $y = $this->y0 - $paint_ht_corr ;
  18466. $this->oldy = $this->y0 - $paint_ht_corr ;
  18467. $old_height = 0;
  18468. }
  18469. /*-- END COLUMNS --*/
  18470. }
  18471. }
  18472. //Check if it is the last element. If so then finish printing the block
  18473. if ($i == ($array_size-1)) {
  18474. $this->finishFlowingBlock(true); // true = END of flowing block
  18475. // Added to correct for OddEven Margins
  18476. if ($this->page != $oldpage) {
  18477. if (($this->page-$oldpage) % 2 == 1) {
  18478. $bak_x += $this->MarginCorrection;
  18479. $this->x = $bak_x;
  18480. }
  18481. $oldpage = $this->page;
  18482. $y = $this->tMargin - $paint_ht_corr ;
  18483. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18484. $old_height = 0;
  18485. }
  18486. /*-- COLUMNS --*/
  18487. // COLS
  18488. // OR COLUMN CHANGE
  18489. if ($this->CurrCol != $oldcolumn) {
  18490. if ($this->directionality == 'rtl') { // *RTL*
  18491. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18492. } // *RTL*
  18493. else { // *RTL*
  18494. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18495. } // *RTL*
  18496. $this->x = $bak_x;
  18497. $oldcolumn = $this->CurrCol;
  18498. $y = $this->y0 - $paint_ht_corr ;
  18499. $this->oldy = $this->y0 - $paint_ht_corr ;
  18500. $old_height = 0;
  18501. }
  18502. /*-- END COLUMNS --*/
  18503. }
  18504. // RESETTING VALUES
  18505. $this->SetTColor($this->ConvertColor(0));
  18506. $this->SetDColor($this->ConvertColor(0));
  18507. $this->SetFColor($this->ConvertColor(255));
  18508. $this->colorarray = '';
  18509. $this->spanbgcolorarray = '';
  18510. $this->spanbgcolor = false;
  18511. $this->spanborder = false;
  18512. $this->spanborddet = array();
  18513. $this->HREF = '';
  18514. $this->textparam = array();
  18515. $this->SetTextOutline();
  18516. $this->SUP = false;
  18517. $this->SUB = false;
  18518. $this->strike = false;
  18519. $this->textshadow = '';
  18520. $this->currentfontfamily = '';
  18521. $this->currentfontsize = '';
  18522. $this->currentfontstyle = '';
  18523. /*-- TABLES --*/
  18524. if ($this->tableLevel) {
  18525. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  18526. }
  18527. else
  18528. /*-- END TABLES --*/
  18529. /*-- LISTS --*/
  18530. if ($is_list && $this->list_lineheight[$this->listlvl][$this->listOcc]) {
  18531. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->listOcc]); // sets default line height
  18532. }
  18533. else
  18534. /*-- END LISTS --*/
  18535. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  18536. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  18537. }
  18538. $this->ResetStyles();
  18539. $this->toupper = false;
  18540. $this->tolower = false;
  18541. $this->capitalize = false;
  18542. $this->kerning = false;
  18543. $this->lSpacingCSS = '';
  18544. $this->wSpacingCSS = '';
  18545. $this->fixedlSpacing = false;
  18546. $this->minwSpacing = 0;
  18547. $this->SetDash();
  18548. $this->dash_on = false;
  18549. $this->dotted_on = false;
  18550. }//end of for(i=0;i<arraysize;i++)
  18551. // PAINT DIV BORDER // DISABLED IN COLUMNS AS DOESN'T WORK WHEN BROKEN ACROSS COLS??
  18552. if ((isset($this->blk[$this->blklvl]['border']) || isset($this->blk[$this->blklvl]['bgcolor']) || isset($this->blk[$this->blklvl]['box_shadow'])) && $blockstate && ($this->y != $this->oldy)) {
  18553. $bottom_y = $this->y; // Does not include Bottom Margin
  18554. if (isset($this->blk[$this->blklvl]['startpage']) && $this->blk[$this->blklvl]['startpage'] != $this->page && $blockstate != 1) {
  18555. $this->PaintDivBB('pagetop',$blockstate);
  18556. }
  18557. else if ($blockstate != 1) {
  18558. $this->PaintDivBB('',$blockstate);
  18559. }
  18560. $this->y = $bottom_y;
  18561. $this->x = $bak_x;
  18562. }
  18563. // Reset Font
  18564. $this->SetFontSize($this->default_font_size,false);
  18565. }
  18566. function _setDashBorder($style, $div, $cp, $side) {
  18567. if ($style == 'dashed' && (($side=='L' || $side=='R') || ($side=='T' && $div != 'pagetop' && !$cp) || ($side=='B' && $div!='pagebottom') )) {
  18568. $dashsize = 2; // final dash will be this + 1*linewidth
  18569. $dashsizek = 1.5; // ratio of Dash/Blank
  18570. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  18571. }
  18572. else if ($style == 'dotted' || ($side=='T' && ($div == 'pagetop' || $cp)) || ($side=='B' && $div == 'pagebottom')) {
  18573. //Round join and cap
  18574. $this->SetLineJoin(1);
  18575. $this->SetLineCap(1);
  18576. $this->SetDash(0.001,($this->LineWidth*3));
  18577. }
  18578. }
  18579. function _setBorderLine($b, $k=1) {
  18580. $this->SetLineWidth($b['w']/$k);
  18581. $this->SetDColor($b['c']);
  18582. if ($b['c'][0]==5) { // RGBa
  18583. $this->SetAlpha($b['c'][4], 'Normal', false, 'S')."\n";
  18584. }
  18585. else if ($b['c'][0]==6) { // CMYKa
  18586. $this->SetAlpha($b['c'][5], 'Normal', false, 'S')."\n";
  18587. }
  18588. }
  18589. // mPDF 5.6.52
  18590. function PaintDivBB($divider='',$blockstate=0,$blvl=0) {
  18591. // Borders & backgrounds are done elsewhere for columns - messes up the repositioning in printcolumnbuffer
  18592. if ($this->ColActive) { return ; } // *COLUMNS*
  18593. $save_y = $this->y;
  18594. if (!$blvl) { $blvl = $this->blklvl; }
  18595. $x0 = $x1 = $y0 = $y1 = 0;
  18596. // Added mPDF 3.0 Float DIV
  18597. if (isset($this->blk[$blvl]['bb_painted'][$this->page]) && $this->blk[$blvl]['bb_painted'][$this->page]) { return; } // *CSS-FLOAT*
  18598. if (isset($this->blk[$blvl]['x0'])) { $x0 = $this->blk[$blvl]['x0']; } // left
  18599. if (isset($this->blk[$blvl]['y1'])) { $y1 = $this->blk[$blvl]['y1']; } // bottom
  18600. // Added mPDF 3.0 Float DIV - ensures backgrounds/borders are drawn to bottom of page
  18601. if ($y1==0) {
  18602. if ($divider=='pagebottom') { $y1 = $this->h-$this->bMargin; }
  18603. else { $y1 = $this->y; }
  18604. }
  18605. if (isset($this->blk[$blvl]['startpage']) && $this->blk[$blvl]['startpage'] != $this->page) { $continuingpage = true; } else { $continuingpage = false; }
  18606. if (isset($this->blk[$blvl]['y0'])) { $y0 = $this->blk[$blvl]['y0']; }
  18607. $h = $y1 - $y0;
  18608. $w = $this->blk[$blvl]['width'];
  18609. $x1 = $x0 + $w;
  18610. // Set border-widths as used here
  18611. $border_top = $this->blk[$blvl]['border_top']['w'];
  18612. $border_bottom = $this->blk[$blvl]['border_bottom']['w'];
  18613. $border_left = $this->blk[$blvl]['border_left']['w'];
  18614. $border_right = $this->blk[$blvl]['border_right']['w'];
  18615. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) {
  18616. $border_top = 0;
  18617. }
  18618. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') {
  18619. $border_bottom = 0;
  18620. }
  18621. $brTL_H = 0;
  18622. $brTL_V = 0;
  18623. $brTR_H = 0;
  18624. $brTR_V = 0;
  18625. $brBL_H = 0;
  18626. $brBL_V = 0;
  18627. $brBR_H = 0;
  18628. $brBR_V = 0;
  18629. $brset = false;
  18630. /*-- BORDER-RADIUS --*/
  18631. if (isset($this->blk[$blvl]['border_radius_TL_H'])) { $brTL_H = $this->blk[$blvl]['border_radius_TL_H']; $brset = true; }
  18632. if (isset($this->blk[$blvl]['border_radius_TL_V'])) { $brTL_V = $this->blk[$blvl]['border_radius_TL_V']; $brset = true; }
  18633. if (isset($this->blk[$blvl]['border_radius_TR_H'])) { $brTR_H = $this->blk[$blvl]['border_radius_TR_H']; $brset = true; }
  18634. if (isset($this->blk[$blvl]['border_radius_TR_V'])) { $brTR_V = $this->blk[$blvl]['border_radius_TR_V']; $brset = true; }
  18635. if (isset($this->blk[$blvl]['border_radius_BR_H'])) { $brBR_H = $this->blk[$blvl]['border_radius_BR_H']; $brset = true; }
  18636. if (isset($this->blk[$blvl]['border_radius_BR_V'])) { $brBR_V = $this->blk[$blvl]['border_radius_BR_V']; $brset = true; }
  18637. if (isset($this->blk[$blvl]['border_radius_BL_H'])) { $brBL_H = $this->blk[$blvl]['border_radius_BL_H']; $brset = true; }
  18638. if (isset($this->blk[$blvl]['border_radius_BL_V'])) { $brBL_V = $this->blk[$blvl]['border_radius_BL_V']; $brset = true; }
  18639. // mPDF 5.4.17
  18640. //if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage || $this->keep_block_together) {
  18641. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) {
  18642. $brTL_H = 0;
  18643. $brTL_V = 0;
  18644. $brTR_H = 0;
  18645. $brTR_V = 0;
  18646. }
  18647. // mPDF 5.4.17
  18648. //if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom' || $this->keep_block_together) {
  18649. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') {
  18650. $brBL_H = 0;
  18651. $brBL_V = 0;
  18652. $brBR_H = 0;
  18653. $brBR_V = 0;
  18654. }
  18655. // Disallow border-radius if it is smaller than the border width.
  18656. if ($brTL_H < min($border_left, $border_top)) { $brTL_H = $brTL_V = 0; }
  18657. if ($brTL_V < min($border_left, $border_top)) { $brTL_V = $brTL_H = 0; }
  18658. if ($brTR_H < min($border_right, $border_top)) { $brTR_H = $brTR_V = 0; }
  18659. if ($brTR_V < min($border_right, $border_top)) { $brTR_V = $brTR_H = 0; }
  18660. if ($brBL_H < min($border_left, $border_bottom)) { $brBL_H = $brBL_V = 0; }
  18661. if ($brBL_V < min($border_left, $border_bottom)) { $brBL_V = $brBL_H = 0; }
  18662. if ($brBR_H < min($border_right, $border_bottom)) { $brBR_H = $brBR_V = 0; }
  18663. if ($brBR_V < min($border_right, $border_bottom)) { $brBR_V = $brBR_H = 0; }
  18664. // CHECK FOR radii that sum to > width or height of div ********
  18665. $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));
  18666. if ($f < 1) {
  18667. $brTL_H *= $f;
  18668. $brTL_V *= $f;
  18669. $brTR_H *= $f;
  18670. $brTR_V *= $f;
  18671. $brBL_H *= $f;
  18672. $brBL_V *= $f;
  18673. $brBR_H *= $f;
  18674. $brBR_V *= $f;
  18675. }
  18676. /*-- END BORDER-RADIUS --*/
  18677. $tbcol = $this->ConvertColor(255);
  18678. for($l=0; $l <= $blvl; $l++) {
  18679. if ($this->blk[$l]['bgcolor']) {
  18680. $tbcol = $this->blk[$l]['bgcolorarray'];
  18681. }
  18682. }
  18683. // BORDERS
  18684. if (isset($this->blk[$blvl]['y0']) && $this->blk[$blvl]['y0']) { $y0 = $this->blk[$blvl]['y0']; }
  18685. $h = $y1 - $y0;
  18686. $w = $this->blk[$blvl]['width'];
  18687. //if ($this->blk[$blvl]['border_top']) {
  18688. // Reinstate line above for dotted line divider when block border crosses a page
  18689. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  18690. $tbd = $this->blk[$blvl]['border_top'];
  18691. // mPDF 5.4.18
  18692. $legend = '';
  18693. if (isset($this->blk[$blvl]['border_legend']) && $this->blk[$blvl]['border_legend']) {
  18694. $legend = $this->blk[$blvl]['border_legend']; // Same structure array as textbuffer
  18695. $txt = ltrim($legend[0]);
  18696. //Set font, size, style, color
  18697. $this->SetFont($legend[4],$legend[2],$legend[11]);
  18698. if ($legend[3]) {
  18699. $cor = $legend[3];
  18700. $this->SetTColor($cor);
  18701. }
  18702. $stringWidth = $this->GetStringWidth($txt );
  18703. $save_x = $this->x;
  18704. $save_y = $this->y;
  18705. $save_currentfontfamily = $this->FontFamily;
  18706. $save_currentfontsize = $this->FontSizePt;
  18707. $save_currentfontstyle = $this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  18708. $this->y = $y0 - $this->FontSize/2 + $this->blk[$blvl]['border_top']['w']/2;
  18709. $this->x = $x0 + $this->blk[$blvl]['padding_left'] + $this->blk[$blvl]['border_left']['w'];
  18710. // Set the distance from the border line to the text ? make configurable variable
  18711. $gap = 0.2 * $this->FontSize;
  18712. $legbreakL = $this->x - $gap;
  18713. $legbreakR = $this->x + $stringWidth + $gap;
  18714. $this->Cell( $stringWidth, $this->FontSize, $txt , '', 0, 'C', $fill, '', 0, 0,0,'M', $fill);
  18715. // Reset
  18716. $this->x = $save_x;
  18717. $this->y = $save_y;
  18718. $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize);
  18719. $this->SetTColor($this->ConvertColor(0));
  18720. }
  18721. if (isset($tbd['s']) && $tbd['s']) {
  18722. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') {
  18723. $this->_out('q');
  18724. $this->SetLineWidth(0);
  18725. $this->_out(sprintf('%.3F %.3F m ',($x0)*_MPDFK, ($this->h-($y0))*_MPDFK));
  18726. $this->_out(sprintf('%.3F %.3F l ',($x0 + $border_left)*_MPDFK, ($this->h-($y0 + $border_top))*_MPDFK));
  18727. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - $border_right)*_MPDFK, ($this->h-($y0 + $border_top))*_MPDFK));
  18728. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w)*_MPDFK, ($this->h-($y0))*_MPDFK));
  18729. $this->_out(' h W n '); // Ends path no-op & Sets the clipping path
  18730. }
  18731. $this->_setBorderLine($tbd);
  18732. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') {
  18733. $legbreakL -= $border_top/2; // because line cap different
  18734. $legbreakR += $border_top/2;
  18735. $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'T');
  18736. }
  18737. /*-- BORDER-RADIUS --*/
  18738. else if (($brTL_V && $brTL_H) || ($brTR_V && $brTR_H) || $tbd['style']=='solid' || $tbd['style']=='double' ) { // mPDF 5.6.58
  18739. $this->SetLineJoin(0);
  18740. $this->SetLineCap(0);
  18741. }
  18742. $s = '';
  18743. if ($brTR_H && $brTR_V) {
  18744. $s .= ($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_top/2 , $brTR_V - $border_top/2 , 1, 2, true))."\n";
  18745. }
  18746. else
  18747. /*-- END BORDER-RADIUS --*/
  18748. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18749. $s .= (sprintf('%.3F %.3F m ',($x0 + $w)*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18750. }
  18751. else {
  18752. $s .= (sprintf('%.3F %.3F m ',($x0 + $w - ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18753. }
  18754. /*-- BORDER-RADIUS --*/
  18755. if ($brTL_H && $brTL_V ) {
  18756. // mPDF 5.4.18
  18757. if ($legend) {
  18758. if ($legbreakR < ($x0 + $w - $brTR_H)) {
  18759. $s .= (sprintf('%.3F %.3F l ', $legbreakR*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18760. }
  18761. if ($legbreakL > ($x0 + $brTL_H )) {
  18762. $s .= (sprintf('%.3F %.3F m ',$legbreakL*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18763. $s .= (sprintf('%.3F %.3F l ',($x0 + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK)."\n");
  18764. }
  18765. else {
  18766. $s .= (sprintf('%.3F %.3F m ',($x0 + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18767. }
  18768. }
  18769. else {
  18770. $s .= (sprintf('%.3F %.3F l ',($x0 + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18771. }
  18772. $s .= ($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_top/2 , $brTL_V - $border_top/2 , 2, 1))."\n";
  18773. }
  18774. else {
  18775. /*-- END BORDER-RADIUS --*/
  18776. // mPDF 5.4.18
  18777. if ($legend) {
  18778. if ($legbreakR < ($x0 + $w)) {
  18779. $s .= (sprintf('%.3F %.3F l ',$legbreakR*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18780. }
  18781. if ($legbreakL > ($x0)) {
  18782. $s .= (sprintf('%.3F %.3F m ',$legbreakL*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18783. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18784. $s .= (sprintf('%.3F %.3F l ',($x0)*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18785. }
  18786. else {
  18787. $s .= (sprintf('%.3F %.3F l ',($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18788. }
  18789. }
  18790. else if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18791. $s .= (sprintf('%.3F %.3F m ', ($x0)*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18792. }
  18793. else {
  18794. $s .= (sprintf('%.3F %.3F m ', ($x0 + $border_top/2)*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18795. }
  18796. }
  18797. else if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18798. $s .= (sprintf('%.3F %.3F l ',($x0)*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18799. }
  18800. else {
  18801. $s .= (sprintf('%.3F %.3F l ',($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK))."\n";
  18802. }
  18803. /*-- BORDER-RADIUS --*/
  18804. }
  18805. /*-- END BORDER-RADIUS --*/
  18806. $s .= 'S'."\n";
  18807. $this->_out($s);
  18808. if ($tbd['style']=='double') {
  18809. $this->SetLineWidth($tbd['w']/3);
  18810. $this->SetDColor($tbcol);
  18811. $this->_out($s);
  18812. }
  18813. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') { $this->_out('Q'); }
  18814. // Reset Corners and Dash off
  18815. $this->SetLineWidth(0.1); // mPDF 5.6.57
  18816. $this->SetDColor($this->ConvertColor(0));
  18817. $this->SetLineJoin(2);
  18818. $this->SetLineCap(2);
  18819. $this->SetDash();
  18820. }
  18821. }
  18822. //if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1) {
  18823. // Reinstate line above for dotted line divider when block border crosses a page
  18824. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  18825. $tbd = $this->blk[$blvl]['border_bottom'];
  18826. if (isset($tbd['s']) && $tbd['s']) {
  18827. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') {
  18828. $this->_out('q');
  18829. $this->SetLineWidth(0);
  18830. $this->_out(sprintf('%.3F %.3F m ',($x0)*_MPDFK, ($this->h-($y0 + $h))*_MPDFK));
  18831. $this->_out(sprintf('%.3F %.3F l ',($x0 + $border_left)*_MPDFK, ($this->h-($y0 + $h - $border_bottom))*_MPDFK));
  18832. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - $border_right)*_MPDFK, ($this->h-($y0 + $h - $border_bottom))*_MPDFK));
  18833. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w)*_MPDFK, ($this->h-($y0 + $h))*_MPDFK));
  18834. $this->_out(' h W n '); // Ends path no-op & Sets the clipping path
  18835. }
  18836. $this->_setBorderLine($tbd);
  18837. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'B'); }
  18838. /*-- BORDER-RADIUS --*/
  18839. else if (($brBL_V && $brBL_H) || ($brBR_V && $brBR_H) || $tbd['style']=='solid' || $tbd['style']=='double' ) { // mPDF 5.6.58
  18840. $this->SetLineJoin(0);
  18841. $this->SetLineCap(0);
  18842. }
  18843. $s = '';
  18844. if ($brBL_H && $brBL_V) {
  18845. $s .= ($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_bottom/2 , $brBL_V - $border_bottom/2 , 3, 2, true))."\n";
  18846. }
  18847. else
  18848. /*-- END BORDER-RADIUS --*/
  18849. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18850. $s .= (sprintf('%.3F %.3F m ',($x0)*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK))."\n";
  18851. }
  18852. else {
  18853. $s .= (sprintf('%.3F %.3F m ',($x0 + ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK))."\n";
  18854. }
  18855. /*-- BORDER-RADIUS --*/
  18856. if ($brBR_H && $brBR_V ) {
  18857. $s .= (sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2) - $brBR_H )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK))."\n";
  18858. $s .= ($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_bottom/2 , $brBR_V - $border_bottom/2 , 4, 1))."\n";
  18859. }
  18860. else
  18861. /*-- END BORDER-RADIUS --*/
  18862. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18863. $s .= (sprintf('%.3F %.3F l ',($x0 + $w)*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK))."\n";
  18864. }
  18865. else {
  18866. $s .= (sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK))."\n";
  18867. }
  18868. $s .= 'S'."\n";
  18869. $this->_out($s);
  18870. if ($tbd['style']=='double') {
  18871. $this->SetLineWidth($tbd['w']/3);
  18872. $this->SetDColor($tbcol);
  18873. $this->_out($s);
  18874. }
  18875. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') { $this->_out('Q'); }
  18876. // Reset Corners and Dash off
  18877. $this->SetLineWidth(0.1); // mPDF 5.6.57
  18878. $this->SetDColor($this->ConvertColor(0));
  18879. $this->SetLineJoin(2);
  18880. $this->SetLineCap(2);
  18881. $this->SetDash();
  18882. }
  18883. }
  18884. if ($this->blk[$blvl]['border_left']) {
  18885. $tbd = $this->blk[$blvl]['border_left'];
  18886. if (isset($tbd['s']) && $tbd['s']) {
  18887. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') {
  18888. $this->_out('q');
  18889. $this->SetLineWidth(0);
  18890. $this->_out(sprintf('%.3F %.3F m ',($x0)*_MPDFK, ($this->h-($y0))*_MPDFK));
  18891. $this->_out(sprintf('%.3F %.3F l ',($x0 + $border_left)*_MPDFK, ($this->h-($y0+$border_top))*_MPDFK));
  18892. $this->_out(sprintf('%.3F %.3F l ',($x0 + $border_left)*_MPDFK, ($this->h-($y0 + $h - $border_bottom))*_MPDFK));
  18893. $this->_out(sprintf('%.3F %.3F l ',($x0)*_MPDFK, ($this->h-($y0 + $h))*_MPDFK));
  18894. $this->_out(' h W n '); // Ends path no-op & Sets the clipping path
  18895. }
  18896. $this->_setBorderLine($tbd);
  18897. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'L'); }
  18898. /*-- BORDER-RADIUS --*/
  18899. else if (($brTL_V && $brTL_H) || ($brBL_V && $brBL_H) || $tbd['style']=='solid' || $tbd['style']=='double' ) { // mPDF 5.6.58
  18900. $this->SetLineJoin(0);
  18901. $this->SetLineCap(0);
  18902. }
  18903. $s = '';
  18904. if ($brTL_V && $brTL_H) {
  18905. $s .= ($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_left/2 , $brTL_V - $border_left/2, 2, 2, true))."\n";
  18906. }
  18907. else
  18908. /*-- END BORDER-RADIUS --*/
  18909. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18910. $s .= (sprintf('%.3F %.3F m ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0))*_MPDFK))."\n";
  18911. }
  18912. else {
  18913. $s .= (sprintf('%.3F %.3F m ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + ($border_left/2)))*_MPDFK))."\n";
  18914. }
  18915. /*-- BORDER-RADIUS --*/
  18916. if ($brBL_V && $brBL_H ) {
  18917. $s .= (sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)- $brBL_V) )*_MPDFK))."\n";
  18918. $s .= ($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_left/2 , $brBL_V - $border_left/2, 3, 1))."\n";
  18919. }
  18920. else
  18921. /*-- END BORDER-RADIUS --*/
  18922. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18923. $s .= (sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h) )*_MPDFK))."\n";
  18924. }
  18925. else {
  18926. $s .= (sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)) )*_MPDFK))."\n";
  18927. }
  18928. $s .= 'S'."\n";
  18929. $this->_out($s);
  18930. if ($tbd['style']=='double') {
  18931. $this->SetLineWidth($tbd['w']/3);
  18932. $this->SetDColor($tbcol);
  18933. $this->_out($s);
  18934. }
  18935. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') { $this->_out('Q'); }
  18936. // Reset Corners and Dash off
  18937. $this->SetLineWidth(0.1); // mPDF 5.6.57
  18938. $this->SetDColor($this->ConvertColor(0));
  18939. $this->SetLineJoin(2);
  18940. $this->SetLineCap(2);
  18941. $this->SetDash();
  18942. }
  18943. }
  18944. if ($this->blk[$blvl]['border_right']) {
  18945. $tbd = $this->blk[$blvl]['border_right'];
  18946. if (isset($tbd['s']) && $tbd['s']) {
  18947. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') {
  18948. $this->_out('q');
  18949. $this->SetLineWidth(0);
  18950. $this->_out(sprintf('%.3F %.3F m ',($x0 + $w)*_MPDFK, ($this->h-($y0))*_MPDFK));
  18951. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - $border_right)*_MPDFK, ($this->h-($y0+$border_top))*_MPDFK));
  18952. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - $border_right)*_MPDFK, ($this->h-($y0 + $h - $border_bottom))*_MPDFK));
  18953. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w)*_MPDFK, ($this->h-($y0 + $h))*_MPDFK));
  18954. $this->_out(' h W n '); // Ends path no-op & Sets the clipping path
  18955. }
  18956. $this->_setBorderLine($tbd);
  18957. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'R'); }
  18958. /*-- BORDER-RADIUS --*/
  18959. else if (($brTR_V && $brTR_H) || ($brBR_V && $brBR_H) || $tbd['style']=='solid' || $tbd['style']=='double' ) { // mPDF 5.6.58
  18960. $this->SetLineJoin(0);
  18961. $this->SetLineCap(0);
  18962. }
  18963. $s = '';
  18964. if ($brBR_V && $brBR_H) {
  18965. $s .= ($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_right/2 , $brBR_V - $border_right/2, 4, 2, true))."\n";
  18966. }
  18967. else
  18968. /*-- END BORDER-RADIUS --*/
  18969. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18970. $s .= (sprintf('%.3F %.3F m ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h))*_MPDFK))."\n";
  18971. }
  18972. else {
  18973. $s .= (sprintf('%.3F %.3F m ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h - ($border_right/2)))*_MPDFK))."\n";
  18974. }
  18975. /*-- BORDER-RADIUS --*/
  18976. if ($brTR_V && $brTR_H ) {
  18977. $s .= (sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2) + $brTR_V) )*_MPDFK))."\n";
  18978. $s .= ($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_right/2 , $brTR_V - $border_right/2, 1, 1))."\n";
  18979. }
  18980. else
  18981. /*-- END BORDER-RADIUS --*/
  18982. if ($tbd['style']=='solid' || $tbd['style']=='double') {
  18983. $s .= (sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0) )*_MPDFK))."\n";
  18984. }
  18985. else {
  18986. $s .= (sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2)) )*_MPDFK))."\n";
  18987. }
  18988. $s .= 'S'."\n";
  18989. $this->_out($s);
  18990. if ($tbd['style']=='double') {
  18991. $this->SetLineWidth($tbd['w']/3);
  18992. $this->SetDColor($tbcol);
  18993. $this->_out($s);
  18994. }
  18995. if (!$brset && $tbd['style']!='dotted' && $tbd['style']!='dashed') { $this->_out('Q'); }
  18996. // Reset Corners and Dash off
  18997. $this->SetLineWidth(0.1); // mPDF 5.6.57
  18998. $this->SetDColor($this->ConvertColor(0));
  18999. $this->SetLineJoin(2);
  19000. $this->SetLineCap(2);
  19001. $this->SetDash();
  19002. }
  19003. }
  19004. $this->SetDash();
  19005. $this->y = $save_y;
  19006. // BACKGROUNDS are disabled in columns/kbt/headers - messes up the repositioning in printcolumnbuffer
  19007. if ($this->ColActive || $this->kwt || $this->keep_block_together) { return ; }
  19008. $bgx0 = $x0;
  19009. $bgx1 = $x1;
  19010. $bgy0 = $y0;
  19011. $bgy1 = $y1;
  19012. // Defined br values represent the radius of the outer curve - need to take border-width/2 from each radius for drawing the borders
  19013. if (isset($this->blk[$blvl]['background_clip']) && $this->blk[$blvl]['background_clip'] == 'padding-box') {
  19014. $brbgTL_H = max(0, $brTL_H - $this->blk[$blvl]['border_left']['w']);
  19015. $brbgTL_V = max(0, $brTL_V - $this->blk[$blvl]['border_top']['w']);
  19016. $brbgTR_H = max(0, $brTR_H - $this->blk[$blvl]['border_right']['w']);
  19017. $brbgTR_V = max(0, $brTR_V - $this->blk[$blvl]['border_top']['w']);
  19018. $brbgBL_H = max(0, $brBL_H - $this->blk[$blvl]['border_left']['w']);
  19019. $brbgBL_V = max(0, $brBL_V - $this->blk[$blvl]['border_bottom']['w']);
  19020. $brbgBR_H = max(0, $brBR_H - $this->blk[$blvl]['border_right']['w']);
  19021. $brbgBR_V = max(0, $brBR_V - $this->blk[$blvl]['border_bottom']['w']);
  19022. $bgx0 += $this->blk[$blvl]['border_left']['w'];
  19023. $bgx1 -= $this->blk[$blvl]['border_right']['w'];
  19024. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19025. $bgy0 += $this->blk[$blvl]['border_top']['w'];
  19026. }
  19027. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19028. $bgy1 -= $this->blk[$blvl]['border_bottom']['w'];
  19029. }
  19030. }
  19031. // mPDF 5.6.09
  19032. else if (isset($this->blk[$blvl]['background_clip']) && $this->blk[$blvl]['background_clip'] == 'content-box') {
  19033. $brbgTL_H = max(0, $brTL_H - $this->blk[$blvl]['border_left']['w'] - $this->blk[$blvl]['padding_left']);
  19034. $brbgTL_V = max(0, $brTL_V - $this->blk[$blvl]['border_top']['w'] - $this->blk[$blvl]['padding_top']);
  19035. $brbgTR_H = max(0, $brTR_H - $this->blk[$blvl]['border_right']['w'] - $this->blk[$blvl]['padding_right']);
  19036. $brbgTR_V = max(0, $brTR_V - $this->blk[$blvl]['border_top']['w'] - $this->blk[$blvl]['padding_top']);
  19037. $brbgBL_H = max(0, $brBL_H - $this->blk[$blvl]['border_left']['w'] - $this->blk[$blvl]['padding_left']);
  19038. $brbgBL_V = max(0, $brBL_V - $this->blk[$blvl]['border_bottom']['w'] - $this->blk[$blvl]['padding_bottom']);
  19039. $brbgBR_H = max(0, $brBR_H - $this->blk[$blvl]['border_right']['w'] - $this->blk[$blvl]['padding_right']);
  19040. $brbgBR_V = max(0, $brBR_V - $this->blk[$blvl]['border_bottom']['w'] - $this->blk[$blvl]['padding_bottom']);
  19041. $bgx0 += $this->blk[$blvl]['border_left']['w'] + $this->blk[$blvl]['padding_left'];
  19042. $bgx1 -= $this->blk[$blvl]['border_right']['w'] + $this->blk[$blvl]['padding_right'];
  19043. if (($this->blk[$blvl]['border_top']['w'] || $this->blk[$blvl]['padding_top']) && $divider != 'pagetop' && !$continuingpage) {
  19044. $bgy0 += $this->blk[$blvl]['border_top']['w'] + $this->blk[$blvl]['padding_top'];
  19045. }
  19046. if (($this->blk[$blvl]['border_bottom']['w'] || $this->blk[$blvl]['padding_bottom']) && $blockstate != 1 && $divider != 'pagebottom') {
  19047. $bgy1 -= $this->blk[$blvl]['border_bottom']['w'] + $this->blk[$blvl]['padding_bottom'];
  19048. }
  19049. }
  19050. else {
  19051. $brbgTL_H = $brTL_H;
  19052. $brbgTL_V = $brTL_V;
  19053. $brbgTR_H = $brTR_H;
  19054. $brbgTR_V = $brTR_V;
  19055. $brbgBL_H = $brBL_H;
  19056. $brbgBL_V = $brBL_V;
  19057. $brbgBR_H = $brBR_H;
  19058. $brbgBR_V = $brBR_V;
  19059. }
  19060. // Set clipping path
  19061. $s = ' q 0 w '; // Line width=0
  19062. $s .= sprintf('%.3F %.3F m ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // start point TL before the arc
  19063. /*-- BORDER-RADIUS --*/
  19064. if ($brbgTL_H || $brbgTL_V) {
  19065. $s .= $this->_EllipseArc($bgx0+$brbgTL_H, $bgy0+$brbgTL_V, $brbgTL_H , $brbgTL_V , 2); // segment 2 TL
  19066. }
  19067. /*-- END BORDER-RADIUS --*/
  19068. $s .= sprintf('%.3F %.3F l ', ($bgx0)*_MPDFK, ($this->h-($bgy1-$brbgBL_V ))*_MPDFK); // line to BL
  19069. /*-- BORDER-RADIUS --*/
  19070. if ($brbgBL_H || $brbgBL_V) {
  19071. $s .= $this->_EllipseArc($bgx0+$brbgBL_H, $bgy1-$brbgBL_V, $brbgBL_H , $brbgBL_V , 3); // segment 3 BL
  19072. }
  19073. /*-- END BORDER-RADIUS --*/
  19074. $s .= sprintf('%.3F %.3F l ', ($bgx1-$brbgBR_H )*_MPDFK, ($this->h-($bgy1))*_MPDFK); // line to BR
  19075. /*-- BORDER-RADIUS --*/
  19076. if ($brbgBR_H || $brbgBR_V) {
  19077. $s .= $this->_EllipseArc($bgx1-$brbgBR_H, $bgy1-$brbgBR_V, $brbgBR_H , $brbgBR_V , 4); // segment 4 BR
  19078. }
  19079. /*-- END BORDER-RADIUS --*/
  19080. $s .= sprintf('%.3F %.3F l ', ($bgx1)*_MPDFK, ($this->h-($bgy0+$brbgTR_V))*_MPDFK); // line to TR
  19081. /*-- BORDER-RADIUS --*/
  19082. if ($brbgTR_H || $brbgTR_V) {
  19083. $s .= $this->_EllipseArc($bgx1-$brbgTR_H, $bgy0+$brbgTR_V, $brbgTR_H , $brbgTR_V , 1); // segment 1 TR
  19084. }
  19085. /*-- END BORDER-RADIUS --*/
  19086. $s .= sprintf('%.3F %.3F l ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // line to TL
  19087. // Box Shadow
  19088. $shadow = '';
  19089. if (isset($this->blk[$blvl]['box_shadow']) && $this->blk[$blvl]['box_shadow'] && $h > 0) {
  19090. foreach($this->blk[$blvl]['box_shadow'] AS $sh) {
  19091. // Colors
  19092. if ($sh['col']{0}==1) {
  19093. $colspace = 'Gray';
  19094. if ($sh['col']{2}==1) { $col1 = '1'.$sh['col'][1].'1'.$sh['col'][3]; }
  19095. else { $col1 = '1'.$sh['col'][1].'1'.chr(100); }
  19096. $col2 = '1'.$sh['col'][1].'1'.chr(0);
  19097. }
  19098. else if ($sh['col']{0}==4) { // CMYK
  19099. $colspace = 'CMYK';
  19100. $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(100);
  19101. $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0);
  19102. }
  19103. else if ($sh['col']{0}==5) { // RGBa
  19104. $colspace = 'RGB';
  19105. $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4];
  19106. $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0);
  19107. }
  19108. else if ($sh['col']{0}==6) { // CMYKa
  19109. $colspace = 'CMYK';
  19110. $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].$sh['col'][5];
  19111. $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0);
  19112. }
  19113. else {
  19114. $colspace = 'RGB';
  19115. $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(100);
  19116. $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0);
  19117. }
  19118. // Use clipping path as set above (and rectangle around page) to clip area outside box
  19119. $shadow .= $s; // Use the clipping path with W*
  19120. $shadow .= sprintf('0 %.3F m %.3F %.3F l ', $this->h*_MPDFK, $this->w*_MPDFK, $this->h*_MPDFK);
  19121. $shadow .= sprintf('%.3F 0 l 0 0 l 0 %.3F l ', $this->w*_MPDFK, $this->h*_MPDFK);
  19122. $shadow .= 'W n'."\n";
  19123. $sh['blur'] = abs($sh['blur']); // cannot have negative blur value
  19124. // Ensure spread/blur do not make effective shadow width/height < 0
  19125. // Could do more complex things but this just adjusts spread value
  19126. if (-$sh['spread'] + $sh['blur']/2 > min($w/2, $h/2)) {
  19127. $sh['spread'] = $sh['blur']/2 - min($w/2, $h/2) + 0.01;
  19128. }
  19129. // Shadow Offset
  19130. if ($sh['x'] || $sh['y']) $shadow .= sprintf(' q 1 0 0 1 %.4F %.4F cm', $sh['x']*_MPDFK, -$sh['y']*_MPDFK)."\n";
  19131. // Set path for INNER shadow
  19132. $shadow .= ' q 0 w ';
  19133. $shadow .= $this->SetFColor($col1, true)."\n";
  19134. if ($col1{0}==5 && ord($col1{4})<100) { // RGBa
  19135. $shadow .= $this->SetAlpha(ord($col1{4})/100, 'Normal', true, 'F')."\n";
  19136. }
  19137. else if ($col1{0}==6 && ord($col1{5})<100) { // CMYKa
  19138. $shadow .= $this->SetAlpha(ord($col1{5})/100, 'Normal', true, 'F')."\n";
  19139. }
  19140. else if ($col1{0}==1 && $col1{2}==1 && ord($col1{3})<100) { // Gray
  19141. $shadow .= $this->SetAlpha(ord($col1{3})/100, 'Normal', true, 'F')."\n";
  19142. }
  19143. // Blur edges
  19144. $mag = 0.551784; // Bezier Control magic number for 4-part spline for circle/ellipse
  19145. $mag2 = 0.551784; // Bezier Control magic number to fill in edge of blurred rectangle
  19146. $d1 = $sh['spread']+$sh['blur']/2;
  19147. $d2 = $sh['spread']-$sh['blur']/2;
  19148. $bl = $sh['blur'];
  19149. $x00 = $x0 - $d1;
  19150. $y00 = $y0 - $d1;
  19151. $w00 = $w + $d1*2;
  19152. $h00 = $h + $d1*2;
  19153. // If any border-radius is greater width-negative spread(inner edge), ignore radii for shadow or screws up
  19154. $flatten = false;
  19155. if (max($brbgTR_H, $brbgTL_H, $brbgBR_H, $brbgBL_H) >= $w+$d2) { $flatten = true; }
  19156. if (max($brbgTR_V, $brbgTL_V, $brbgBR_V, $brbgBL_V) >= $h+$d2) { $flatten = true; }
  19157. // TOP RIGHT corner
  19158. $p1x = $x00+$w00-$d1-$brbgTR_H; $p1c2x = $p1x +($d2+$brbgTR_H)*$mag;
  19159. $p1y = $y00+$bl;
  19160. $p2x = $x00+$w00-$d1-$brbgTR_H; $p2c2x = $p2x + ($d1+$brbgTR_H)*$mag;
  19161. $p2y = $y00; $p2c1y = $p2y + $bl/2;
  19162. $p3x = $x00+$w00; $p3c2x = $p3x - $bl/2;
  19163. $p3y = $y00+$d1+$brbgTR_V; $p3c1y = $p3y - ($d1+$brbgTR_V)*$mag;
  19164. $p4x = $x00+$w00-$bl;
  19165. $p4y = $y00+$d1+$brbgTR_V; $p4c2y = $p4y - ($d2+$brbgTR_V)*$mag;
  19166. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19167. $p1x = $x00+$w00-$bl; $p1c2x = $p1x;
  19168. $p2x = $x00+$w00-$bl; $p2c2x = $p2x + $bl*$mag2;
  19169. $p3y = $y00+$bl; $p3c1y = $p3y - $bl*$mag2;
  19170. $p4y = $y00+$bl; $p4c2y = $p4y ;
  19171. }
  19172. $shadow .= sprintf('%.3F %.3F m ', ($p1x )*_MPDFK, ($this->h-($p1y ))*_MPDFK);
  19173. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1c2x)*_MPDFK, ($this->h-($p1y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4c2y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19174. $patch_array[0]['f']=0;
  19175. $patch_array[0]['points']=array($p1x,$p1y, $p1x,$p1y,
  19176. $p2x,$p2c1y, $p2x,$p2y, $p2c2x,$p2y,
  19177. $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y,
  19178. $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y,
  19179. $p1c2x,$p1y);
  19180. $patch_array[0]['colors'] = array($col1,$col2,$col2,$col1);
  19181. // RIGHT
  19182. $p1x = $x00+$w00; // control point only matches p3 preceding
  19183. $p1y = $y00+$d1+$brbgTR_V;
  19184. $p2x = $x00+$w00-$bl; // control point only matches p4 preceding
  19185. $p2y = $y00+$d1+$brbgTR_V;
  19186. $p3x = $x00+$w00-$bl;
  19187. $p3y = $y00+$h00-$d1-$brbgBR_V;
  19188. $p4x = $x00+$w00; $p4c1x = $p4x-$bl/2;
  19189. $p4y = $y00+$h00-$d1-$brbgBR_V;
  19190. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19191. $p1y = $y00+$bl;
  19192. $p2y = $y00+$bl;
  19193. }
  19194. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19195. $p3y = $y00+$h00-$bl;
  19196. $p4y = $y00+$h00-$bl;
  19197. }
  19198. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19199. $patch_array[1]['f']=2;
  19200. $patch_array[1]['points']=array($p2x,$p2y,
  19201. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19202. $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y,
  19203. $p1x,$p1y);
  19204. $patch_array[1]['colors'] = array($col1,$col2);
  19205. // BOTTOM RIGHT corner
  19206. $p1x = $x00+$w00-$bl; // control points only matches p3 preceding
  19207. $p1y = $y00+$h00-$d1-$brbgBR_V; $p1c2y = $p1y + ($d2+$brbgBR_V)*$mag;
  19208. $p2x = $x00+$w00; // control point only matches p4 preceding
  19209. $p2y = $y00+$h00-$d1-$brbgBR_V; $p2c2y = $p2y + ($d1+$brbgBR_V)*$mag;
  19210. $p3x = $x00+$w00-$d1-$brbgBR_H; $p3c1x = $p3x + ($d1+$brbgBR_H)*$mag;
  19211. $p3y = $y00+$h00; $p3c2y = $p3y - $bl/2;
  19212. $p4x = $x00+$w00-$d1-$brbgBR_H; $p4c2x = $p4x + ($d2+$brbgBR_H)*$mag;
  19213. $p4y = $y00+$h00-$bl;
  19214. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19215. $p1y = $y00+$h00-$bl; $p1c2y = $p1y;
  19216. $p2y = $y00+$h00-$bl; $p2c2y = $p2y + $bl*$mag2;
  19217. $p3x = $x00+$w00-$bl; $p3c1x = $p3x + $bl*$mag2;
  19218. $p4x = $x00+$w00-$bl; $p4c2x = $p4x;
  19219. }
  19220. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1x)*_MPDFK, ($this->h-($p1c2y))*_MPDFK, ($p4c2x)*_MPDFK, ($this->h-($p4y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19221. $patch_array[2]['f']=2;
  19222. $patch_array[2]['points']=array($p2x,$p2c2y,
  19223. $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y,
  19224. $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y,
  19225. $p1x,$p1c2y);
  19226. $patch_array[2]['colors'] = array($col2,$col1);
  19227. // BOTTOM
  19228. $p1x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p3 preceding
  19229. $p1y = $y00+$h00;
  19230. $p2x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p4 preceding
  19231. $p2y = $y00+$h00-$bl;
  19232. $p3x = $x00+$d1+$brbgBL_H;
  19233. $p3y = $y00+$h00-$bl;
  19234. $p4x = $x00+$d1+$brbgBL_H;
  19235. $p4y = $y00+$h00; $p4c1y = $p4y - $bl/2;
  19236. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19237. $p1x = $x00+$w00-$bl;
  19238. $p2x = $x00+$w00-$bl;
  19239. }
  19240. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19241. $p3x = $x00+$bl;
  19242. $p4x = $x00+$bl;
  19243. }
  19244. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19245. $patch_array[3]['f']=2;
  19246. $patch_array[3]['points']=array($p2x,$p2y,
  19247. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19248. $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y,
  19249. $p1x,$p1y);
  19250. $patch_array[3]['colors'] = array($col1,$col2);
  19251. // BOTTOM LEFT corner
  19252. $p1x = $x00+$d1+$brbgBL_H; $p1c2x = $p1x - ($d2+$brbgBL_H)*$mag; // control points only matches p3 preceding
  19253. $p1y = $y00+$h00-$bl;
  19254. $p2x = $x00+$d1+$brbgBL_H; $p2c2x = $p2x - ($d1+$brbgBL_H)*$mag; // control point only matches p4 preceding
  19255. $p2y = $y00+$h00;
  19256. $p3x = $x00; $p3c2x = $p3x + $bl/2;
  19257. $p3y = $y00+$h00-$d1-$brbgBL_V; $p3c1y = $p3y + ($d1+$brbgBL_V)*$mag;
  19258. $p4x = $x00+$bl;
  19259. $p4y = $y00+$h00-$d1-$brbgBL_V; $p4c2y = $p4y + ($d2+$brbgBL_V)*$mag;
  19260. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19261. $p1x = $x00+$bl; $p1c2x = $p1x;
  19262. $p2x = $x00+$bl; $p2c2x = $p2x - $bl*$mag2;
  19263. $p3y = $y00+$h00-$bl; $p3c1y = $p3y + $bl*$mag2;
  19264. $p4y = $y00+$h00-$bl; $p4c2y = $p4y;
  19265. }
  19266. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1c2x)*_MPDFK, ($this->h-($p1y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4c2y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19267. $patch_array[4]['f']=2;
  19268. $patch_array[4]['points']=array($p2c2x,$p2y,
  19269. $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y,
  19270. $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y,
  19271. $p1c2x,$p1y);
  19272. $patch_array[4]['colors'] = array($col2,$col1);
  19273. // LEFT - joins on the right (C3-C4 of previous): f = 2
  19274. $p1x = $x00; // control point only matches p3 preceding
  19275. $p1y = $y00+$h00-$d1-$brbgBL_V;
  19276. $p2x = $x00+$bl; // control point only matches p4 preceding
  19277. $p2y = $y00+$h00-$d1-$brbgBL_V;
  19278. $p3x = $x00+$bl;
  19279. $p3y = $y00+$d1+$brbgTL_V;
  19280. $p4x = $x00; $p4c1x = $p4x + $bl/2;
  19281. $p4y = $y00+$d1+$brbgTL_V;
  19282. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19283. $p1y = $y00+$h00-$bl;
  19284. $p2y = $y00+$h00-$bl;
  19285. }
  19286. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19287. $p3y = $y00+$bl;
  19288. $p4y = $y00+$bl;
  19289. }
  19290. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19291. $patch_array[5]['f']=2;
  19292. $patch_array[5]['points']=array($p2x,$p2y,
  19293. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19294. $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y,
  19295. $p1x,$p1y);
  19296. $patch_array[5]['colors'] = array($col1,$col2);
  19297. // TOP LEFT corner
  19298. $p1x = $x00+$bl; // control points only matches p3 preceding
  19299. $p1y = $y00+$d1+$brbgTL_V; $p1c2y = $p1y - ($d2+$brbgTL_V)*$mag;
  19300. $p2x = $x00; // control point only matches p4 preceding
  19301. $p2y = $y00+$d1+$brbgTL_V; $p2c2y = $p2y - ($d1+$brbgTL_V)*$mag;
  19302. $p3x = $x00+$d1+$brbgTL_H; $p3c1x = $p3x - ($d1+$brbgTL_H)*$mag;
  19303. $p3y = $y00; $p3c2y = $p3y + $bl/2;
  19304. $p4x = $x00+$d1+$brbgTL_H; $p4c2x = $p4x - ($d2+$brbgTL_H)*$mag;
  19305. $p4y = $y00+$bl;
  19306. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19307. $p1y = $y00+$bl; $p1c2y = $p1y;
  19308. $p2y = $y00+$bl; $p2c2y = $p2y - $bl*$mag2;
  19309. $p3x = $x00+$bl; $p3c1x = $p3x - $bl*$mag2;
  19310. $p4x = $x00+$bl; $p4c2x = $p4x ;
  19311. }
  19312. $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1x)*_MPDFK, ($this->h-($p1c2y))*_MPDFK, ($p4c2x)*_MPDFK, ($this->h-($p4y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK);
  19313. $patch_array[6]['f']=2;
  19314. $patch_array[6]['points']=array($p2x,$p2c2y,
  19315. $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y,
  19316. $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y,
  19317. $p1x,$p1c2y);
  19318. $patch_array[6]['colors'] = array($col2,$col1);
  19319. // TOP - joins on the right (C3-C4 of previous): f = 2
  19320. $p1x = $x00+$d1+$brbgTL_H; // control point only matches p3 preceding
  19321. $p1y = $y00;
  19322. $p2x = $x00+$d1+$brbgTL_H; // control point only matches p4 preceding
  19323. $p2y = $y00+$bl;
  19324. $p3x = $x00+$w00-$d1-$brbgTR_H;
  19325. $p3y = $y00+$bl;
  19326. $p4x = $x00+$w00-$d1-$brbgTR_H;
  19327. $p4y = $y00; $p4c1y = $p4y + $bl/2;
  19328. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19329. $p1x = $x00+$bl;
  19330. $p2x = $x00+$bl;
  19331. }
  19332. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19333. $p3x = $x00+$w00-$bl;
  19334. $p4x = $x00+$w00-$bl;
  19335. }
  19336. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19337. $patch_array[7]['f']=2;
  19338. $patch_array[7]['points']=array($p2x,$p2y,
  19339. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19340. $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y,
  19341. $p1x,$p1y);
  19342. $patch_array[7]['colors'] = array($col1,$col2);
  19343. $shadow .= ' h f Q '."\n"; // Close path and Fill the inner solid shadow
  19344. if ($bl) $shadow .= $this->grad->CoonsPatchMesh($x00,$y00,$w00,$h00,$patch_array,$x00,$x00+$w00,$y00,$y00+$h00, $colspace, true);
  19345. if ($sh['x'] || $sh['y']) $shadow .= ' Q'."\n"; // Shadow Offset
  19346. $shadow .= ' Q'."\n"; // Ends path no-op & Sets the clipping path
  19347. }
  19348. }
  19349. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  19350. if ($this->blk[$blvl]['bgcolor']) {
  19351. $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'col'=>$this->blk[$blvl]['bgcolorarray'], 'clippath'=>$s, 'visibility'=>$this->visibility, 'shadow'=>$shadow, 'z-index'=>$this->current_layer); // mPDF 5.6.01
  19352. }
  19353. else if ($shadow) {
  19354. $this->pageBackgrounds[$blvl][] = array('shadowonly'=>true, 'col'=>'', 'clippath'=>'', 'visibility'=>$this->visibility, 'shadow'=>$shadow, 'z-index'=>$this->current_layer); // mPDF 5.6.01
  19355. }
  19356. /*-- BACKGROUNDS --*/
  19357. if (isset($this->blk[$blvl]['gradient'])) {
  19358. $g = $this->grad->parseBackgroundGradient($this->blk[$blvl]['gradient']);
  19359. if ($g) {
  19360. $gx = $x0;
  19361. $gy = $y0;
  19362. $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, 'visibility'=>$this->visibility, 'z-index'=>$this->current_layer); // mPDF 5.6.01
  19363. }
  19364. }
  19365. if (isset($this->blk[$blvl]['background-image'])) {
  19366. if ($this->blk[$blvl]['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->blk[$blvl]['background-image']['gradient'] )) {
  19367. $g = $this->grad->parseMozGradient( $this->blk[$blvl]['background-image']['gradient'] );
  19368. if ($g) {
  19369. $gx = $x0;
  19370. $gy = $y0;
  19371. // mPDF 5.6.11
  19372. // origin specifies the background-positioning-area (bpa)
  19373. if ($this->blk[$blvl]['background-image']['origin'] == 'padding-box') {
  19374. $gx += $this->blk[$blvl]['border_left']['w'];
  19375. $w -= ($this->blk[$blvl]['border_left']['w'] + $this->blk[$blvl]['border_right']['w']);
  19376. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19377. $gy += $this->blk[$blvl]['border_top']['w'];
  19378. }
  19379. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19380. $gy1 = $y1 - $this->blk[$blvl]['border_bottom']['w'];
  19381. }
  19382. else { $gy1 = $y1; }
  19383. $h = $gy1 - $gy;
  19384. }
  19385. else if ($this->blk[$blvl]['background-image']['origin'] == 'content-box') {
  19386. $gx += $this->blk[$blvl]['border_left']['w'] + $this->blk[$blvl]['padding_left'];
  19387. $w -= ($this->blk[$blvl]['border_left']['w'] + $this->blk[$blvl]['padding_left'] + $this->blk[$blvl]['border_right']['w'] + $this->blk[$blvl]['padding_right']);
  19388. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19389. $gy += $this->blk[$blvl]['border_top']['w'] + $this->blk[$blvl]['padding_top'];
  19390. }
  19391. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19392. $gy1 = $y1 - ($this->blk[$blvl]['border_bottom']['w'] + $this->blk[$blvl]['padding_bottom']);
  19393. }
  19394. else { $gy1 = $y1 - $this->blk[$blvl]['padding_bottom']; }
  19395. $h = $gy1 - $gy;
  19396. }
  19397. if (isset($this->blk[$blvl]['background-image']['size']['w']) && $this->blk[$blvl]['background-image']['size']['w']) {
  19398. $size = $this->blk[$blvl]['background-image']['size'];
  19399. if ($size['w']!='contain' && $size['w']!='cover') {
  19400. if (stristr($size['w'] ,'%')) {
  19401. $size['w'] += 0;
  19402. $size['w'] /= 100;
  19403. $w *= $size['w'];
  19404. }
  19405. else if ($size['w']!='auto') {
  19406. $w = $size['w'];
  19407. }
  19408. if (stristr($size['h'] ,'%')) {
  19409. $size['h'] += 0;
  19410. $size['h'] /= 100;
  19411. $h *= $size['h'];
  19412. }
  19413. else if ($size['h']!='auto') {
  19414. $h = $size['h'];
  19415. }
  19416. }
  19417. }
  19418. $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, 'visibility'=>$this->visibility, 'z-index'=>$this->current_layer); // mPDF 5.6.01
  19419. }
  19420. }
  19421. else {
  19422. $image_id = $this->blk[$blvl]['background-image']['image_id'];
  19423. $orig_w = $this->blk[$blvl]['background-image']['orig_w'];
  19424. $orig_h = $this->blk[$blvl]['background-image']['orig_h'];
  19425. $x_pos = $this->blk[$blvl]['background-image']['x_pos'];
  19426. $y_pos = $this->blk[$blvl]['background-image']['y_pos'];
  19427. $x_repeat = $this->blk[$blvl]['background-image']['x_repeat'];
  19428. $y_repeat = $this->blk[$blvl]['background-image']['y_repeat'];
  19429. $resize = $this->blk[$blvl]['background-image']['resize'];
  19430. $opacity = $this->blk[$blvl]['background-image']['opacity'];
  19431. $itype = $this->blk[$blvl]['background-image']['itype'];
  19432. $size = $this->blk[$blvl]['background-image']['size']; // mPDF 5.6.10
  19433. // mPDF 5.6.10
  19434. // origin specifies the background-positioning-area (bpa)
  19435. $bpa = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h);
  19436. if ($this->blk[$blvl]['background-image']['origin'] == 'padding-box') {
  19437. $bpa['x'] = $x0 + $this->blk[$blvl]['border_left']['w'];
  19438. $bpa['w'] = $w - ($this->blk[$blvl]['border_left']['w'] + $this->blk[$blvl]['border_right']['w']);
  19439. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19440. $bpa['y'] = $y0 + $this->blk[$blvl]['border_top']['w'];
  19441. }
  19442. else { $bpa['y'] = $y0; }
  19443. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19444. $bpay = $y1 - $this->blk[$blvl]['border_bottom']['w'];
  19445. }
  19446. else { $bpay = $y1; }
  19447. $bpa['h'] = $bpay - $bpa['y'];
  19448. }
  19449. // mPDF 5.6.09
  19450. else if ($this->blk[$blvl]['background-image']['origin'] == 'content-box') {
  19451. $bpa['x'] = $x0 + $this->blk[$blvl]['border_left']['w'] + $this->blk[$blvl]['padding_left'];
  19452. $bpa['w'] = $w - ($this->blk[$blvl]['border_left']['w'] + $this->blk[$blvl]['padding_left'] + $this->blk[$blvl]['border_right']['w'] + $this->blk[$blvl]['padding_right']);
  19453. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19454. $bpa['y'] = $y0 + $this->blk[$blvl]['border_top']['w'] + $this->blk[$blvl]['padding_top'];
  19455. }
  19456. else { $bpa['y'] = $y0 + $this->blk[$blvl]['padding_top']; }
  19457. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19458. $bpay = $y1 - ($this->blk[$blvl]['border_bottom']['w'] + $this->blk[$blvl]['padding_bottom']);
  19459. }
  19460. else { $bpay = $y1 - $this->blk[$blvl]['padding_bottom']; }
  19461. $bpa['h'] = $bpay - $bpa['y'];
  19462. }
  19463. $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, 'visibility'=>$this->visibility, 'z-index'=>$this->current_layer, 'size'=>$size, 'bpa'=>$bpa ); // mPDF 5.6.01 5.6.10
  19464. }
  19465. }
  19466. /*-- END BACKGROUNDS --*/
  19467. // Float DIV
  19468. $this->blk[$blvl]['bb_painted'][$this->page] = true;
  19469. }
  19470. /*-- BORDER-RADIUS --*/
  19471. function _EllipseArc($x0, $y0, $rx, $ry, $seg = 1, $part=false, $start=false) { // Anticlockwise segment 1-4 TR-TL-BL-BR (part=1 or 2)
  19472. $s = '';
  19473. if ($rx<0) { $rx = 0; }
  19474. if ($ry<0) { $ry = 0; }
  19475. $rx *= _MPDFK;
  19476. $ry *= _MPDFK;
  19477. $astart = 0;
  19478. if ($seg == 1) { // Top Right
  19479. $afinish = 90;
  19480. $nSeg = 4;
  19481. }
  19482. else if ($seg == 2) { // Top Left
  19483. $afinish = 180;
  19484. $nSeg = 8;
  19485. }
  19486. else if ($seg == 3) { // Bottom Left
  19487. $afinish = 270;
  19488. $nSeg = 12;
  19489. }
  19490. else { // Bottom Right
  19491. $afinish = 360;
  19492. $nSeg = 16;
  19493. }
  19494. $astart = deg2rad((float) $astart);
  19495. $afinish = deg2rad((float) $afinish);
  19496. $totalAngle = $afinish - $astart;
  19497. $dt = $totalAngle / $nSeg; // segment angle
  19498. $dtm = $dt/3;
  19499. $x0 *= _MPDFK;
  19500. $y0 = ($this->h - $y0) * _MPDFK;
  19501. $t1 = $astart;
  19502. $a0 = $x0 + ($rx * cos($t1));
  19503. $b0 = $y0 + ($ry * sin($t1));
  19504. $c0 = -$rx * sin($t1);
  19505. $d0 = $ry * cos($t1);
  19506. $op = false;
  19507. for ($i = 1; $i <= $nSeg; $i++) {
  19508. // Draw this bit of the total curve
  19509. $t1 = ($i * $dt) + $astart;
  19510. $a1 = $x0 + ($rx * cos($t1));
  19511. $b1 = $y0 + ($ry * sin($t1));
  19512. $c1 = -$rx * sin($t1);
  19513. $d1 = $ry * cos($t1);
  19514. if ($i>($nSeg-4) && (!$part || ($part == 1 && $i<=$nSeg-2) || ($part == 2 && $i>$nSeg-2))) {
  19515. if ($start && !$op) {
  19516. $s .= sprintf('%.3F %.3F m ', $a0, $b0);
  19517. }
  19518. $s .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($a0 + ($c0 * $dtm)), ($b0 + ($d0 * $dtm)), ($a1 - ($c1 * $dtm)) , ($b1 - ($d1 * $dtm)), $a1 , $b1 );
  19519. $op = true;
  19520. }
  19521. $a0 = $a1;
  19522. $b0 = $b1;
  19523. $c0 = $c1;
  19524. $d0 = $d1;
  19525. }
  19526. return $s;
  19527. }
  19528. /*-- END BORDER-RADIUS --*/
  19529. function PaintDivLnBorder($state=0,$blvl=0,$h) {
  19530. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  19531. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y + $h;
  19532. $save_y = $this->y;
  19533. $w = $this->blk[$blvl]['width'];
  19534. $x0 = $this->x; // left
  19535. $y0 = $this->y; // top
  19536. $x1 = $this->x + $w; // bottom
  19537. $y1 = $this->y + $h; // bottom
  19538. if ($this->blk[$blvl]['border_top'] && ($state==1 || $state==3)) {
  19539. $tbd = $this->blk[$blvl]['border_top'];
  19540. if (isset($tbd['s']) && $tbd['s']) {
  19541. $this->_setBorderLine($tbd);
  19542. $this->y = $y0 + ($tbd['w']/2);
  19543. // mPDF 5.6.56
  19544. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') {
  19545. $this->_setDashBorder($tbd['style'],'',$continuingpage,'T');
  19546. $this->Line($x0 + ($tbd['w']/2) , $this->y , $x0 + $w - ($tbd['w']/2), $this->y);
  19547. }
  19548. else {
  19549. $this->SetLineJoin(0);
  19550. $this->SetLineCap(0);
  19551. $this->Line($x0, $this->y , $x0 + $w, $this->y);
  19552. }
  19553. $this->y += $tbd['w'];
  19554. // Reset Corners and Dash off
  19555. $this->SetLineJoin(2);
  19556. $this->SetLineCap(2);
  19557. $this->SetDash();
  19558. }
  19559. }
  19560. if ($this->blk[$blvl]['border_left']) {
  19561. $tbd = $this->blk[$blvl]['border_left'];
  19562. if (isset($tbd['s']) && $tbd['s']) {
  19563. $this->_setBorderLine($tbd);
  19564. // mPDF 5.6.56
  19565. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') {
  19566. $this->y = $y0 + ($tbd['w']/2);
  19567. $this->_setDashBorder($tbd['style'],'',$continuingpage,'L');
  19568. $this->Line($x0 + ($tbd['w']/2), $this->y, $x0 + ($tbd['w']/2), $y0 + $h -($tbd['w']/2));
  19569. }
  19570. else {
  19571. $this->y = $y0;
  19572. $this->SetLineJoin(0);
  19573. $this->SetLineCap(0);
  19574. $this->Line($x0 + ($tbd['w']/2), $this->y, $x0 + ($tbd['w']/2), $y0 + $h);
  19575. }
  19576. $this->y += $tbd['w'];
  19577. // Reset Corners and Dash off
  19578. $this->SetLineJoin(2);
  19579. $this->SetLineCap(2);
  19580. $this->SetDash();
  19581. }
  19582. }
  19583. if ($this->blk[$blvl]['border_right']) {
  19584. $tbd = $this->blk[$blvl]['border_right'];
  19585. if (isset($tbd['s']) && $tbd['s']) {
  19586. $this->_setBorderLine($tbd);
  19587. // mPDF 5.6.56
  19588. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') {
  19589. $this->y = $y0 + ($tbd['w']/2);
  19590. $this->_setDashBorder($tbd['style'],'',$continuingpage,'R');
  19591. $this->Line($x0 + $w - ($tbd['w']/2), $this->y, $x0 + $w - ($tbd['w']/2), $y0 + $h - ($tbd['w']/2));
  19592. }
  19593. else {
  19594. $this->y = $y0;
  19595. $this->SetLineJoin(0);
  19596. $this->SetLineCap(0);
  19597. $this->Line($x0 + $w - ($tbd['w']/2), $this->y, $x0 + $w - ($tbd['w']/2), $y0 + $h);
  19598. }
  19599. $this->y += $tbd['w'];
  19600. // Reset Corners and Dash off
  19601. $this->SetLineJoin(2);
  19602. $this->SetLineCap(2);
  19603. $this->SetDash();
  19604. }
  19605. }
  19606. if ($this->blk[$blvl]['border_bottom'] && $state > 1) {
  19607. $tbd = $this->blk[$blvl]['border_bottom'];
  19608. if (isset($tbd['s']) && $tbd['s']) {
  19609. $this->_setBorderLine($tbd);
  19610. $this->y = $y0 + $h - ($tbd['w']/2);
  19611. // mPDF 5.6.56
  19612. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') {
  19613. $this->_setDashBorder($tbd['style'],'',$continuingpage,'B');
  19614. $this->Line($x0 + ($tbd['w']/2) , $this->y, $x0 + $w - ($tbd['w']/2), $this->y);
  19615. }
  19616. else {
  19617. $this->SetLineJoin(0);
  19618. $this->SetLineCap(0);
  19619. $this->Line($x0, $this->y, $x0 + $w, $this->y);
  19620. }
  19621. $this->y += $tbd['w'];
  19622. // Reset Corners and Dash off
  19623. $this->SetLineJoin(2);
  19624. $this->SetLineCap(2);
  19625. $this->SetDash();
  19626. }
  19627. }
  19628. $this->SetDash();
  19629. $this->y = $save_y;
  19630. }
  19631. function PaintImgBorder($objattr,$is_table) {
  19632. // Borders are disabled in columns - messes up the repositioning in printcolumnbuffer
  19633. if ($this->ColActive) { return ; } // *COLUMNS*
  19634. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  19635. $h = (isset($objattr['BORDER-HEIGHT']) ? $objattr['BORDER-HEIGHT'] : 0);
  19636. $w = (isset($objattr['BORDER-WIDTH']) ? $objattr['BORDER-WIDTH'] : 0);
  19637. $x0 = (isset($objattr['BORDER-X']) ? $objattr['BORDER-X'] : 0);
  19638. $y0 = (isset($objattr['BORDER-Y']) ? $objattr['BORDER-Y'] : 0);
  19639. // BORDERS
  19640. if ($objattr['border_top']) {
  19641. $tbd = $objattr['border_top'];
  19642. if (!empty($tbd['s'])) {
  19643. $this->_setBorderLine($tbd,$k);
  19644. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','T'); }
  19645. $this->Line($x0, $y0, $x0 + $w, $y0);
  19646. // Reset Corners and Dash off
  19647. $this->SetLineJoin(2);
  19648. $this->SetLineCap(2);
  19649. $this->SetDash();
  19650. }
  19651. }
  19652. if ($objattr['border_left']) {
  19653. $tbd = $objattr['border_left'];
  19654. if (!empty($tbd['s'])) {
  19655. $this->_setBorderLine($tbd,$k);
  19656. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','L'); }
  19657. $this->Line($x0, $y0, $x0, $y0 + $h);
  19658. // Reset Corners and Dash off
  19659. $this->SetLineJoin(2);
  19660. $this->SetLineCap(2);
  19661. $this->SetDash();
  19662. }
  19663. }
  19664. if ($objattr['border_right']) {
  19665. $tbd = $objattr['border_right'];
  19666. if (!empty($tbd['s'])) {
  19667. $this->_setBorderLine($tbd,$k);
  19668. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','R'); }
  19669. $this->Line($x0 + $w, $y0, $x0 + $w, $y0 + $h);
  19670. // Reset Corners and Dash off
  19671. $this->SetLineJoin(2);
  19672. $this->SetLineCap(2);
  19673. $this->SetDash();
  19674. }
  19675. }
  19676. if ($objattr['border_bottom']) {
  19677. $tbd = $objattr['border_bottom'];
  19678. if (!empty($tbd['s'])) {
  19679. $this->_setBorderLine($tbd,$k);
  19680. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','B'); }
  19681. $this->Line($x0, $y0 + $h, $x0 + $w, $y0 + $h);
  19682. // Reset Corners and Dash off
  19683. $this->SetLineJoin(2);
  19684. $this->SetLineCap(2);
  19685. $this->SetDash();
  19686. }
  19687. }
  19688. $this->SetDash();
  19689. $this->SetAlpha(1);
  19690. }
  19691. /*-- END HTML-CSS --*/
  19692. function Reset() {
  19693. $this->SetTColor($this->ConvertColor(0));
  19694. $this->SetDColor($this->ConvertColor(0));
  19695. $this->SetFColor($this->ConvertColor(255));
  19696. $this->SetAlpha(1);
  19697. $this->colorarray = '';
  19698. $this->spanbgcolorarray = '';
  19699. $this->spanbgcolor = false;
  19700. $this->spanborder = false;
  19701. $this->spanborddet = array();
  19702. $this->ResetStyles();
  19703. $this->HREF = '';
  19704. $this->textparam = array();
  19705. $this->SetTextOutline();
  19706. $this->SUP = false;
  19707. $this->SUB = false;
  19708. $this->strike = false;
  19709. $this->textshadow = '';
  19710. $this->SetFont($this->default_font,'',0,false);
  19711. $this->SetFontSize($this->default_font_size,false);
  19712. $this->currentfontfamily = '';
  19713. $this->currentfontsize = '';
  19714. /*-- TABLES --*/
  19715. if ($this->tableLevel) {
  19716. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  19717. }
  19718. else
  19719. /*-- END TABLES --*/
  19720. /*-- LISTS --*/
  19721. if ($this->listlvl && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) {
  19722. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height
  19723. }
  19724. else
  19725. /*-- END LISTS --*/
  19726. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  19727. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  19728. }
  19729. $this->toupper = false;
  19730. $this->tolower = false;
  19731. $this->kerning = false;
  19732. $this->lSpacingCSS = '';
  19733. $this->wSpacingCSS = '';
  19734. $this->fixedlSpacing = false;
  19735. $this->minwSpacing = 0;
  19736. $this->capitalize = false;
  19737. $this->SetDash(); //restore to no dash
  19738. $this->dash_on = false;
  19739. $this->dotted_on = false;
  19740. $this->divwidth = 0;
  19741. $this->divheight = 0;
  19742. $this->divalign = '';
  19743. $this->divrevert = false;
  19744. $this->oldy = -1;
  19745. $bodystyle = array();
  19746. if (isset($this->cssmgr->CSS['BODY']['FONT-STYLE'])) { $bodystyle['FONT-STYLE'] = $this->cssmgr->CSS['BODY']['FONT-STYLE']; }
  19747. if (isset($this->cssmgr->CSS['BODY']['FONT-WEIGHT'])) { $bodystyle['FONT-WEIGHT'] = $this->cssmgr->CSS['BODY']['FONT-WEIGHT']; }
  19748. if (isset($this->cssmgr->CSS['BODY']['COLOR'])) { $bodystyle['COLOR'] = $this->cssmgr->CSS['BODY']['COLOR']; }
  19749. if (isset($bodystyle)) { $this->setCSS($bodystyle,'BLOCK','BODY'); }
  19750. }
  19751. /*-- HTML-CSS --*/
  19752. function ReadMetaTags($html) {
  19753. // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
  19754. $regexp = '/ (\\w+?)=([^\\s>"]+)/si';
  19755. $html = preg_replace($regexp," \$1=\"\$2\"",$html);
  19756. if (preg_match('/<title>(.*?)<\/title>/si',$html,$m)) {
  19757. $this->SetTitle($m[1]);
  19758. }
  19759. preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|content)="([^>]*?)".*?>/si',$html,$aux);
  19760. $firstattr = $aux[1];
  19761. $secondattr = $aux[3];
  19762. for( $i = 0 ; $i < count($aux[0]) ; $i++) {
  19763. $name = ( strtoupper($firstattr[$i]) == "NAME" )? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]);
  19764. $content = ( strtoupper($firstattr[$i]) == "CONTENT" )? $aux[2][$i] : $aux[4][$i];
  19765. switch($name) {
  19766. case "KEYWORDS": $this->SetKeywords($content); break;
  19767. case "AUTHOR": $this->SetAuthor($content); break;
  19768. case "DESCRIPTION": $this->SetSubject($content); break;
  19769. }
  19770. }
  19771. }
  19772. function ReadCharset($html) {
  19773. // Charset conversion
  19774. if ($this->allow_charset_conversion) {
  19775. if (preg_match('/<head.*charset=([^\'\"\s]*).*<\/head>/si',$html,$m)) {
  19776. if (strtoupper($m[1]) != 'UTF-8') {
  19777. $this->charset_in = strtoupper($m[1]);
  19778. }
  19779. }
  19780. }
  19781. }
  19782. function setCSS($arrayaux,$type='',$tag='') { // type= INLINE | BLOCK | LIST // tag= BODY
  19783. if (!is_array($arrayaux)) return; //Removes PHP Warning
  19784. // Set font size first so that e.g. MARGIN 0.83em works on font size for this element
  19785. if (isset($arrayaux['FONT-SIZE'])) {
  19786. $v = $arrayaux['FONT-SIZE'];
  19787. if(is_numeric($v[0])) {
  19788. if ($type == 'BLOCK' && $this->blklvl>0 && isset($this->blk[$this->blklvl-1]['InlineProperties']) && isset($this->blk[$this->blklvl-1]['InlineProperties']['size'])) {
  19789. $mmsize = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['InlineProperties']['size']);
  19790. }
  19791. else {
  19792. $mmsize = $this->ConvertSize($v,$this->FontSize);
  19793. }
  19794. $this->SetFontSize( $mmsize*(_MPDFK),false ); //Get size in points (pt)
  19795. }
  19796. else{
  19797. $v = strtoupper($v);
  19798. if (isset($this->fontsizes[$v])) {
  19799. $this->SetFontSize( $this->fontsizes[$v]* $this->default_font_size,false);
  19800. }
  19801. }
  19802. if ($tag == 'BODY') { $this->SetDefaultFontSize($this->FontSizePt); }
  19803. }
  19804. if ($this->useLang && !$this->usingCoreFont) {
  19805. if (isset($arrayaux['LANG']) && $arrayaux['LANG'] && $arrayaux['LANG'] != $this->default_lang && ((strlen($arrayaux['LANG']) == 5 && $arrayaux['LANG'] != 'UTF-8') || strlen($arrayaux['LANG']) == 2)) {
  19806. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($arrayaux['LANG'], $this->useAdobeCJK);
  19807. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  19808. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  19809. if ($tag == 'BODY') {
  19810. $this->currentLang = $arrayaux['LANG'];
  19811. $this->default_lang = $arrayaux['LANG'];
  19812. if ($mpdf_pdf_unifonts) { $this->default_available_fonts = $mpdf_pdf_unifonts; }
  19813. }
  19814. }
  19815. else {
  19816. $this->RestrictUnicodeFonts($this->default_available_fonts );
  19817. }
  19818. }
  19819. // FOR INLINE and BLOCK OR 'BODY'
  19820. if (isset($arrayaux['FONT-FAMILY'])) {
  19821. $v = $arrayaux['FONT-FAMILY'];
  19822. //If it is a font list, get all font types
  19823. $aux_fontlist = explode(",",$v);
  19824. $found = 0;
  19825. foreach($aux_fontlist AS $f) {
  19826. $fonttype = trim($f);
  19827. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  19828. $fonttype = preg_replace('/ /','',$fonttype);
  19829. $v = strtolower(trim($fonttype));
  19830. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  19831. if ((!$this->onlyCoreFonts && in_array($v,$this->available_unifonts)) ||
  19832. in_array($v,array('ccourier','ctimes','chelvetica')) ||
  19833. ($this->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
  19834. in_array($v, array('sjis','uhc','big5','gb'))) {
  19835. $fonttype = $v;
  19836. $found = 1;
  19837. break;
  19838. }
  19839. }
  19840. if (!$found) {
  19841. foreach($aux_fontlist AS $f) {
  19842. $fonttype = trim($f);
  19843. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  19844. $fonttype = preg_replace('/ /','',$fonttype);
  19845. $v = strtolower(trim($fonttype));
  19846. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  19847. if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  19848. $fonttype = $v;
  19849. break;
  19850. }
  19851. }
  19852. }
  19853. if ($tag == 'BODY') {
  19854. $this->SetDefaultFont($fonttype);
  19855. }
  19856. $this->SetFont($fonttype,$this->currentfontstyle,0,false);
  19857. }
  19858. else {
  19859. $this->SetFont($this->currentfontfamily,$this->currentfontstyle,0,false);
  19860. }
  19861. foreach($arrayaux as $k => $v) {
  19862. if ($type != 'INLINE' && $tag != 'BODY' && $type != 'LIST') {
  19863. switch($k){
  19864. // BORDERS
  19865. case 'BORDER-TOP':
  19866. $this->blk[$this->blklvl]['border_top'] = $this->border_details($v);
  19867. if ($this->blk[$this->blklvl]['border_top']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  19868. break;
  19869. case 'BORDER-BOTTOM':
  19870. $this->blk[$this->blklvl]['border_bottom'] = $this->border_details($v);
  19871. if ($this->blk[$this->blklvl]['border_bottom']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  19872. break;
  19873. case 'BORDER-LEFT':
  19874. $this->blk[$this->blklvl]['border_left'] = $this->border_details($v);
  19875. if ($this->blk[$this->blklvl]['border_left']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  19876. break;
  19877. case 'BORDER-RIGHT':
  19878. $this->blk[$this->blklvl]['border_right'] = $this->border_details($v);
  19879. if ($this->blk[$this->blklvl]['border_right']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  19880. break;
  19881. // PADDING
  19882. case 'PADDING-TOP':
  19883. $this->blk[$this->blklvl]['padding_top'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19884. break;
  19885. case 'PADDING-BOTTOM':
  19886. $this->blk[$this->blklvl]['padding_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19887. break;
  19888. case 'PADDING-LEFT':
  19889. $this->blk[$this->blklvl]['padding_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19890. break;
  19891. case 'PADDING-RIGHT':
  19892. $this->blk[$this->blklvl]['padding_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19893. break;
  19894. // MARGINS
  19895. case 'MARGIN-TOP':
  19896. $tmp = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19897. if (isset($this->blk[$this->blklvl]['lastbottommargin'])) {
  19898. if ($tmp > $this->blk[$this->blklvl]['lastbottommargin']) {
  19899. $tmp -= $this->blk[$this->blklvl]['lastbottommargin'];
  19900. }
  19901. else {
  19902. $tmp = 0;
  19903. }
  19904. }
  19905. $this->blk[$this->blklvl]['margin_top'] = $tmp;
  19906. break;
  19907. case 'MARGIN-BOTTOM':
  19908. $this->blk[$this->blklvl]['margin_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19909. break;
  19910. case 'MARGIN-LEFT':
  19911. $this->blk[$this->blklvl]['margin_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19912. break;
  19913. case 'MARGIN-RIGHT':
  19914. $this->blk[$this->blklvl]['margin_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19915. break;
  19916. /*-- BORDER-RADIUS --*/
  19917. case 'BORDER-TOP-LEFT-RADIUS-H':
  19918. $this->blk[$this->blklvl]['border_radius_TL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19919. break;
  19920. case 'BORDER-TOP-LEFT-RADIUS-V':
  19921. $this->blk[$this->blklvl]['border_radius_TL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19922. break;
  19923. case 'BORDER-TOP-RIGHT-RADIUS-H':
  19924. $this->blk[$this->blklvl]['border_radius_TR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19925. break;
  19926. case 'BORDER-TOP-RIGHT-RADIUS-V':
  19927. $this->blk[$this->blklvl]['border_radius_TR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19928. break;
  19929. case 'BORDER-BOTTOM-LEFT-RADIUS-H':
  19930. $this->blk[$this->blklvl]['border_radius_BL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19931. break;
  19932. case 'BORDER-BOTTOM-LEFT-RADIUS-V':
  19933. $this->blk[$this->blklvl]['border_radius_BL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19934. break;
  19935. case 'BORDER-BOTTOM-RIGHT-RADIUS-H':
  19936. $this->blk[$this->blklvl]['border_radius_BR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19937. break;
  19938. case 'BORDER-BOTTOM-RIGHT-RADIUS-V':
  19939. $this->blk[$this->blklvl]['border_radius_BR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19940. break;
  19941. /*-- END BORDER-RADIUS --*/
  19942. case 'BOX-SHADOW':
  19943. $bs = $this->cssmgr->setCSSboxshadow($v);
  19944. if ($bs) { $this->blk[$this->blklvl]['box_shadow'] = $bs; }
  19945. break;
  19946. case 'BACKGROUND-CLIP':
  19947. if (strtoupper($v) == 'PADDING-BOX') { $this->blk[$this->blklvl]['background_clip'] = 'padding-box'; }
  19948. else if (strtoupper($v) == 'CONTENT-BOX') { $this->blk[$this->blklvl]['background_clip'] = 'content-box'; } // mPDF 5.6.09
  19949. break;
  19950. case 'PAGE-BREAK-AFTER':
  19951. if (strtoupper($v) == 'AVOID') { $this->blk[$this->blklvl]['page_break_after_avoid'] = true; }
  19952. else if (strtoupper($v) == 'ALWAYS' || strtoupper($v) == 'LEFT' || strtoupper($v) == 'RIGHT') { $this->blk[$this->blklvl]['page_break_after'] = strtoupper($v) ; }
  19953. break;
  19954. case 'WIDTH':
  19955. if (strtoupper($v) != 'AUTO') {
  19956. $this->blk[$this->blklvl]['css_set_width'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  19957. }
  19958. break;
  19959. case 'TEXT-INDENT':
  19960. // Left as raw value (may include 1% or 2em)
  19961. $this->blk[$this->blklvl]['text_indent'] = $v;
  19962. break;
  19963. }//end of switch($k)
  19964. }
  19965. if ($type != 'INLINE' && $type != 'LIST') { // includes BODY tag
  19966. switch($k){
  19967. case 'MARGIN-COLLAPSE': // Custom tag to collapse margins at top and bottom of page
  19968. if (strtoupper($v) == 'COLLAPSE') { $this->blk[$this->blklvl]['margin_collapse'] = true; }
  19969. break;
  19970. case 'LINE-HEIGHT':
  19971. $this->blk[$this->blklvl]['line_height'] = $this->fixLineheight($v);
  19972. if (!$this->blk[$this->blklvl]['line_height'] ) { $this->blk[$this->blklvl]['line_height'] = $this->normalLineheight; }
  19973. break;
  19974. case 'TEXT-ALIGN': //left right center justify
  19975. switch (strtoupper($v)) {
  19976. case 'LEFT':
  19977. $this->blk[$this->blklvl]['align']="L";
  19978. break;
  19979. case 'CENTER':
  19980. $this->blk[$this->blklvl]['align']="C";
  19981. break;
  19982. case 'RIGHT':
  19983. $this->blk[$this->blklvl]['align']="R";
  19984. break;
  19985. case 'JUSTIFY':
  19986. $this->blk[$this->blklvl]['align']="J";
  19987. break;
  19988. }
  19989. break;
  19990. /*-- BACKGROUNDS --*/
  19991. case 'BACKGROUND-GRADIENT':
  19992. if ($type == 'BLOCK') {
  19993. $this->blk[$this->blklvl]['gradient'] = $v;
  19994. }
  19995. break;
  19996. /*-- END BACKGROUNDS --*/
  19997. case 'DIRECTION':
  19998. if ($v) { $this->blk[$this->blklvl]['direction'] = strtolower($v); }
  19999. break;
  20000. }//end of switch($k)
  20001. }
  20002. // FOR INLINE ONLY
  20003. if ($type == 'INLINE' || $type == 'LIST') {
  20004. switch($k){
  20005. case 'DISPLAY': // Custom tag to collapse margins at top and bottom of page
  20006. if (strtoupper($v) == 'NONE') { $this->inlineDisplayOff = true; }
  20007. break;
  20008. case 'DIRECTION':
  20009. break;
  20010. }//end of switch($k)
  20011. }
  20012. // FOR INLINE ONLY
  20013. if ($type == 'INLINE') {
  20014. switch($k){
  20015. // BORDERS
  20016. case 'BORDER-TOP':
  20017. $this->spanborddet['T'] = $this->border_details($v);
  20018. $this->spanborder = true;
  20019. break;
  20020. case 'BORDER-BOTTOM':
  20021. $this->spanborddet['B'] = $this->border_details($v);
  20022. $this->spanborder = true;
  20023. break;
  20024. case 'BORDER-LEFT':
  20025. $this->spanborddet['L'] = $this->border_details($v);
  20026. $this->spanborder = true;
  20027. break;
  20028. case 'BORDER-RIGHT':
  20029. $this->spanborddet['R'] = $this->border_details($v);
  20030. $this->spanborder = true;
  20031. break;
  20032. // mPDF 5.6.26
  20033. case 'VISIBILITY': // block is set in OpenTag
  20034. $v = strtolower($v);
  20035. if ($v == 'visible' || $v == 'hidden' || $v == 'printonly' || $v == 'screenonly') {
  20036. $this->textparam['visibility'] = $v;
  20037. }
  20038. break;
  20039. }//end of switch($k)
  20040. }
  20041. // FOR INLINE and BLOCK
  20042. switch($k){
  20043. case 'TEXT-ALIGN': //left right center justify
  20044. if (strtoupper($v) == 'NOJUSTIFY' && $this->blk[$this->blklvl]['align']=="J") {
  20045. $this->blk[$this->blklvl]['align']="";
  20046. }
  20047. break;
  20048. // bgcolor only - to stay consistent with original html2fpdf
  20049. case 'BACKGROUND':
  20050. case 'BACKGROUND-COLOR':
  20051. $cor = $this->ConvertColor($v);
  20052. if ($cor) {
  20053. if ($tag == 'BODY') {
  20054. $this->bodyBackgroundColor = $cor;
  20055. }
  20056. else if ($type == 'INLINE' || $type == 'LIST') {
  20057. $this->spanbgcolorarray = $cor;
  20058. $this->spanbgcolor = true;
  20059. }
  20060. else {
  20061. $this->blk[$this->blklvl]['bgcolorarray'] = $cor;
  20062. $this->blk[$this->blklvl]['bgcolor'] = true;
  20063. }
  20064. }
  20065. else if ($type != 'INLINE' && $type != 'LIST') {
  20066. if ($this->ColActive || $this->keep_block_together) {
  20067. $this->blk[$this->blklvl]['bgcolorarray'] = $this->blk[$this->blklvl-1]['bgcolorarray'] ;
  20068. $this->blk[$this->blklvl]['bgcolor'] = $this->blk[$this->blklvl-1]['bgcolor'] ;
  20069. }
  20070. }
  20071. break;
  20072. // auto | normal | none
  20073. case 'FONT-KERNING':
  20074. if ((strtoupper($v) == 'NORMAL' || strtoupper($v) == 'AUTO') && $this->useKerning) { $this->kerning = true; }
  20075. else if (strtoupper($v) == 'NONE') { $this->kerning = false; }
  20076. break;
  20077. // normal | <length>
  20078. case 'LETTER-SPACING':
  20079. $this->lSpacingCSS = $v;
  20080. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  20081. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  20082. }
  20083. break;
  20084. // normal | <length>
  20085. case 'WORD-SPACING':
  20086. $this->wSpacingCSS = $v;
  20087. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20088. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  20089. }
  20090. break;
  20091. case 'FONT-STYLE': // italic normal oblique
  20092. switch (strtoupper($v)) {
  20093. case 'ITALIC':
  20094. case 'OBLIQUE':
  20095. $this->SetStyle('I',true);
  20096. break;
  20097. case 'NORMAL':
  20098. $this->SetStyle('I',false);
  20099. break;
  20100. }
  20101. break;
  20102. case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100)
  20103. switch (strtoupper($v)) {
  20104. case 'BOLD':
  20105. $this->SetStyle('B',true);
  20106. break;
  20107. case 'NORMAL':
  20108. $this->SetStyle('B',false);
  20109. break;
  20110. }
  20111. break;
  20112. case 'VERTICAL-ALIGN': //super and sub only dealt with here e.g. <SUB> and <SUP>
  20113. switch (strtoupper($v)) {
  20114. case 'SUPER':
  20115. $this->SUP=true;
  20116. $this->SUB=false; // mPDF 5.6.07
  20117. break;
  20118. case 'SUB':
  20119. $this->SUB=true;
  20120. $this->SUP=false; // mPDF 5.6.07
  20121. break;
  20122. case 'BASELINE': // mPDF 5.6.07
  20123. $this->SUB=false;
  20124. $this->SUP=false;
  20125. break;
  20126. }
  20127. break;
  20128. case 'TEXT-DECORATION': // none underline line-through (strikeout) //Does not support: overline, blink
  20129. if (stristr($v,'LINE-THROUGH')) {
  20130. $this->strike = true;
  20131. }
  20132. else if (stristr($v,'UNDERLINE')) {
  20133. $this->SetStyle('U',true);
  20134. }
  20135. else if (stristr($v,'NONE')) {
  20136. $this->SetStyle('U',false);
  20137. $this->strike = false; // mPDF 5.6.07
  20138. }
  20139. break;
  20140. case 'FONT-VARIANT':
  20141. switch (strtoupper($v)) {
  20142. case 'SMALL-CAPS':
  20143. $this->SetStyle('S',true);
  20144. break;
  20145. case 'NORMAL':
  20146. $this->SetStyle('S',false);
  20147. break;
  20148. }
  20149. break;
  20150. case 'TEXT-TRANSFORM': // none uppercase lowercase //Does support: capitalize
  20151. switch (strtoupper($v)) { //Not working 100%
  20152. case 'CAPITALIZE':
  20153. $this->capitalize=true;
  20154. break;
  20155. case 'UPPERCASE':
  20156. $this->toupper=true;
  20157. break;
  20158. case 'LOWERCASE':
  20159. $this->tolower=true;
  20160. break;
  20161. case 'NONE': break;
  20162. }
  20163. break;
  20164. case 'TEXT-SHADOW':
  20165. $ts = $this->cssmgr->setCSStextshadow($v);
  20166. if ($ts) { $this->textshadow = $ts; }
  20167. break;
  20168. case 'HYPHENS': // mPDF 5.6.08
  20169. if (strtoupper($v)=='NONE') {
  20170. $this->textparam['hyphens'] = 2;
  20171. }
  20172. else if (strtoupper($v)=='AUTO') {
  20173. $this->textparam['hyphens'] = 1;
  20174. }
  20175. else if (strtoupper($v)=='MANUAL') {
  20176. $this->textparam['hyphens'] = 0;
  20177. }
  20178. break;
  20179. case 'TEXT-OUTLINE': // mPDF 5.6.07
  20180. if (strtoupper($v)=='NONE') {
  20181. $this->textparam['outline-s'] = false;
  20182. }
  20183. break;
  20184. case 'TEXT-OUTLINE-WIDTH': // mPDF 5.6.07
  20185. case 'OUTLINE-WIDTH':
  20186. switch(strtoupper($v)) {
  20187. case 'THIN': $v = '0.03em'; break;
  20188. case 'MEDIUM': $v = '0.05em'; break;
  20189. case 'THICK': $v = '0.07em'; break;
  20190. }
  20191. $w = $this->ConvertSize($v,$this->blk[$this->blklvl]['inner_width'],$this->FontSize);
  20192. if ($w) {
  20193. $this->textparam['outline-WIDTH'] = $w;
  20194. $this->textparam['outline-s'] = true;
  20195. }
  20196. else { $this->textparam['outline-s'] = false; }
  20197. break;
  20198. case 'TEXT-OUTLINE-COLOR': // mPDF 5.6.07
  20199. case 'OUTLINE-COLOR':
  20200. if (strtoupper($v) == 'INVERT') {
  20201. if ($this->colorarray) {
  20202. $cor = $this->colorarray;
  20203. $this->textparam['outline-COLOR'] = $this->_invertColor($cor);
  20204. }
  20205. else {
  20206. $this->textparam['outline-COLOR'] = $this->ConvertColor(255);
  20207. }
  20208. }
  20209. else {
  20210. $cor = $this->ConvertColor($v);
  20211. if ($cor) { $this->textparam['outline-COLOR'] = $cor ; }
  20212. }
  20213. break;
  20214. case 'COLOR': // font color
  20215. $cor = $this->ConvertColor($v);
  20216. if ($cor) {
  20217. $this->colorarray = $cor;
  20218. $this->SetTColor($cor);
  20219. }
  20220. break;
  20221. }//end of switch($k)
  20222. }//end of foreach
  20223. }
  20224. /*-- END HTML-CSS --*/
  20225. function SetStyle($tag,$enable) {
  20226. $this->$tag=$enable;
  20227. $style='';
  20228. foreach(array('B','I','U','S') as $s) {
  20229. if($this->$s) {
  20230. $style.=$s;
  20231. }
  20232. }
  20233. if ($this->S && empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); }
  20234. $this->currentfontstyle=$style;
  20235. $this->SetFont('',$style,0,false);
  20236. }
  20237. // Set multiple styles at one $str e.g. "BIS"
  20238. function SetStylesArray($arr) {
  20239. $style='';
  20240. foreach(array('B','I','U','S') as $s) {
  20241. if (isset($arr[$s])) {
  20242. if ($arr[$s]) {
  20243. $this->$s = true;
  20244. $style.=$s;
  20245. }
  20246. else { $this->$s = false; }
  20247. }
  20248. else if ($this->$s) { $style.=$s; }
  20249. }
  20250. $this->currentfontstyle=$style;
  20251. $this->SetFont('',$style,0,false);
  20252. }
  20253. // Set multiple styles at one $str e.g. "BIS"
  20254. function SetStyles($str) {
  20255. $style='';
  20256. foreach(array('B','I','U','S') as $s) {
  20257. if (strpos($str,$s) !== false) {
  20258. $this->$s = true;
  20259. $style.=$s;
  20260. }
  20261. else { $this->$s = false; }
  20262. }
  20263. $this->currentfontstyle=$style;
  20264. $this->SetFont('',$style,0,false);
  20265. }
  20266. function ResetStyles() {
  20267. foreach(array('B','I','U','S') as $s) {
  20268. $this->$s = false;
  20269. }
  20270. $this->currentfontstyle='';
  20271. $this->SetFont('','',0,false);
  20272. }
  20273. function DisableTags($str='')
  20274. {
  20275. if ($str == '') //enable all tags
  20276. {
  20277. //Insert new supported tags in the long string below.
  20278. $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><caption><textcircle><fieldset><legend><article><aside><figure><figcaption><footer><header><hgroup><nav><section><mark><details><summary><meter><progress><time>"; // mPDF 5.5.09
  20279. }
  20280. else
  20281. {
  20282. $str = explode(",",$str);
  20283. foreach($str as $v) $this->enabledtags = str_replace(trim($v),'',$this->enabledtags);
  20284. }
  20285. }
  20286. /*-- TABLES --*/
  20287. function finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight) {
  20288. $af = 0; // Above font
  20289. $bf = 0; // Below font
  20290. $mta = 0; // Maximum top-aligned
  20291. $mba = 0; // Maximum bottom-aligned
  20292. if ($lhxt['BS']) {
  20293. $af = max($af, ($lhxt['BS'] - ($maxfontsize * (0.5 + $this->baselineC))));
  20294. }
  20295. if ($lhxt['M']) {
  20296. $af = max($af, ($lhxt['M'] - $maxfontsize)/2);
  20297. $bf = max($bf, ($lhxt['M'] - $maxfontsize)/2);
  20298. }
  20299. if ($lhxt['TT']) {
  20300. $bf = max($bf, ($lhxt['TT'] - $maxfontsize));
  20301. }
  20302. if ($lhxt['TB']) {
  20303. $af = max($af, ($lhxt['TB'] - $maxfontsize));
  20304. }
  20305. if ($lhxt['T']) {
  20306. $mta = max($mta, $lhxt['T']);
  20307. }
  20308. if ($lhxt['B']) {
  20309. $mba = max($mba, $lhxt['B']);
  20310. }
  20311. if ((!$lhfixed || !$forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  20312. $maxlineHeight = $maxfontsize + $af + $bf;
  20313. }
  20314. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  20315. if ($mta > $maxlineHeight) {
  20316. $bf += ($mta - $maxlineHeight);
  20317. $maxlineHeight = $mta;
  20318. }
  20319. if ($mba > $maxlineHeight) {
  20320. $af += ($mba - $maxlineHeight);
  20321. $maxlineHeight = $mba;
  20322. }
  20323. return $maxlineHeight;
  20324. }
  20325. function TableWordWrap($maxwidth, $forcewrap = 0, $textbuffer = '', $def_fontsize, $returnarray=false) { // NB ** returnarray used in flowchart
  20326. $biggestword=0;
  20327. $toonarrow=false;
  20328. $textbuffer[0][0] = preg_replace('/^[ ]*/','',$textbuffer[0][0]);
  20329. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  20330. $text = '';
  20331. $lhfixed = false;
  20332. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight)) { $lhfixed = true; }
  20333. if ($lhfixed) { $def_lineheight = $this->_computeLineheight($this->table_lineheight, $def_fontsize);}
  20334. else { $def_lineheight = 0; }
  20335. // START OF NEW LINE
  20336. // Initialise lineheight variables
  20337. $maxfontsize = 0;
  20338. $forceExactLineheight = true;
  20339. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20340. $maxlineHeight = $def_lineheight ;
  20341. $ch = 0;
  20342. $width = 0;
  20343. $ln = 1; // Counts line number
  20344. $mxw = $this->GetCharWidth('W',false);
  20345. for($cctr=0;$cctr<count($textbuffer);$cctr++) { // mPDF 5.6.22
  20346. $chunk = $textbuffer[$cctr]; // mPDF 5.6.22
  20347. $line = $chunk[0];
  20348. //IMAGE
  20349. if (substr($line,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  20350. $objattr = $this->_getObjAttr($line);
  20351. if ($objattr['type'] == 'nestedtable') {
  20352. // END OF LINE
  20353. // Finalise & add lineheight
  20354. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20355. $level = $objattr['level'];
  20356. $ih = $this->table[($level+1)][$objattr['nestedcontent']]['h']; // nested table width
  20357. $ch += $ih;
  20358. // START OF NEW LINE
  20359. // Initialise lineheight variables
  20360. $ln++;
  20361. $maxfontsize = 0;
  20362. $forceExactLineheight = true;
  20363. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20364. $maxlineHeight = $def_lineheight ;
  20365. $width = 0;
  20366. $text = "";
  20367. continue;
  20368. }
  20369. list($skipln,$iw,$ih) = $this->inlineObject((isset($specialcontent['type']) ? $specialcontent['type'] : null),0,0, $objattr, $this->lMargin,$width,$maxwidth,$maxlineHeight,false,true);
  20370. if ($objattr['type'] == 'hr') {
  20371. // END OF LINE
  20372. // Finalise & add lineheight
  20373. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20374. // Add HR height
  20375. $ch += $ih;
  20376. // START OF NEW LINE
  20377. // Initialise lineheight variables
  20378. $ln++;
  20379. $maxfontsize = 0;
  20380. $forceExactLineheight = true;
  20381. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20382. $maxlineHeight = $def_lineheight ;
  20383. $width = 0;
  20384. $text = "";
  20385. continue;
  20386. }
  20387. if ($skipln==1 || $skipln==-2) {
  20388. // Finish last line
  20389. // END OF LINE
  20390. // Finalise & add lineheight
  20391. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20392. // START OF NEW LINE
  20393. // Initialise lineheight variables
  20394. $maxfontsize = 0;
  20395. $forceExactLineheight = true;
  20396. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20397. $maxlineHeight = $def_lineheight ;
  20398. $ln++;
  20399. $width = 0;
  20400. $text = "";
  20401. }
  20402. $va = (isset($objattr['vertical-align']) ? $objattr['vertical-align'] : null);
  20403. if ($va) {
  20404. $lhxt[$va] = max($lhxt[$va], $ih);
  20405. }
  20406. if ($lhfixed && $ih > $def_fontsize) { $forceExactLineheight = false; }
  20407. $maxlineHeight = max($maxlineHeight ,$ih);
  20408. $width += $iw;
  20409. continue;
  20410. }
  20411. // SET FONT SIZE/STYLE from $chunk[n]
  20412. // FONTSIZE
  20413. if(isset($chunk[11]) and $chunk[11] != '') {
  20414. if ($this->shrin_k) {
  20415. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  20416. }
  20417. else {
  20418. $this->SetFontSize($chunk[11],false);
  20419. }
  20420. }
  20421. if ($line == "\n") {
  20422. // END OF LINE
  20423. $maxfontsize = max($maxfontsize,$this->FontSize);
  20424. $fh = $this->_computeLineheight($this->table_lineheight);
  20425. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20426. $fh = $this->FontSize;
  20427. $forceExactLineheight = false;
  20428. }
  20429. $maxlineHeight = max($maxlineHeight,$fh);
  20430. // Finalise & add lineheight
  20431. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20432. // START OF NEW LINE
  20433. // Initialise lineheight variables
  20434. $maxfontsize = 0;
  20435. $forceExactLineheight = true;
  20436. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20437. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20438. $ln++;
  20439. $text = "";
  20440. $width = 0;
  20441. if(isset($chunk[11]) and $chunk[11] != '') {
  20442. $this->SetFontSize($this->default_font_size,false);
  20443. }
  20444. continue;
  20445. }
  20446. $lbw = $rbw = 0; // Border widths
  20447. if(isset($chunk[16]) && !empty($chunk[16])) { //Border
  20448. $this->spanborddet = $chunk[16];
  20449. if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w'];
  20450. if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w'];
  20451. }
  20452. if(isset($chunk[15])) { // Word spacing
  20453. $this->wSpacingCSS = $chunk[15];
  20454. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20455. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  20456. }
  20457. }
  20458. if(isset($chunk[14])) { // Letter spacing
  20459. $this->lSpacingCSS = $chunk[14];
  20460. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  20461. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  20462. }
  20463. }
  20464. if(isset($chunk[13])) { // Font Kerning
  20465. $this->kerning = $chunk[13];
  20466. }
  20467. if(isset($chunk[9])) { // Text params - Outline, hyphens // mPDF 5.6.08
  20468. $this->textparam = $chunk[9];
  20469. }
  20470. // FONTFAMILY
  20471. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  20472. // FONT STYLE B I U
  20473. if(isset($chunk[2]) and $chunk[2] != '') {
  20474. $this->SetStyles($chunk[2]);
  20475. }
  20476. $space = $this->GetCharWidth(' ',false);
  20477. if (mb_substr($line,0,1,$this->mb_enc ) == ' ') { // line (chunk) starts with a space
  20478. $width += $space;
  20479. $text .= ' ';
  20480. }
  20481. if (mb_substr($line,(mb_strlen($line,$this->mb_enc )-1),1,$this->mb_enc ) == ' ') { $lsend = true; } // line (chunk) ends with a space
  20482. else { $lsend = false; }
  20483. $line= trim($line);
  20484. if ($line == '') { continue; }
  20485. // mPDF ITERATION
  20486. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  20487. $words = explode(' ', $line);
  20488. foreach ($words as $k=>$word) {
  20489. $word = trim($word);
  20490. $wordwidth = $this->GetStringWidth($word);
  20491. if ($k==0) { $wordwidth += $lbw; }
  20492. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20493. //maxwidth is insufficient for one word
  20494. if ($wordwidth > $maxwidth + 0.0001) {
  20495. $firstchunk=true;
  20496. while($wordwidth > $maxwidth + 0.0001) {
  20497. $chw = 0; // check width
  20498. $oneCJKorphan = false;
  20499. $mlen = mb_strlen($word, $this->mb_enc );
  20500. for ( $i = 0; $i < $mlen; $i++ ) {
  20501. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  20502. if ($k==0) { $chw += $lbw; }
  20503. if ($k==(count($words)-1)) { $chw += $rbw; }
  20504. if ($chw > $maxwidth) {
  20505. if ($i==0 && $firstchunk) {
  20506. // If first letter of line does not fit
  20507. $wordwidth = $maxwidth - 0.0001;
  20508. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for one character!"); }
  20509. break;
  20510. }
  20511. /*-- CJK-FONTS --*/
  20512. // mPDF 5.6.40 mPDF 5.6.44
  20513. if ($this->checkCJK && !$this->usingCoreFont && preg_match("/[".$this->pregCJKchars."]/u", $word)) { // mPDF 5.6.44
  20514. if (!$oneCJKorphan && preg_match('/['.$this->CJKoverflow.']$/u',mb_substr($word,0,$i+1,$this->mb_enc )) && $this->allowCJKorphans) {
  20515. $wordwidth = $maxwidth - 0.0001;
  20516. $oneCJKorphan = true;
  20517. continue;
  20518. }
  20519. $cjkfix = 0;
  20520. // Last character that fits is not allowed to end a line - move lastchar(s) to start of next line
  20521. if ($i>0 && preg_match("/[".$this->CJKleading."$]/u", mb_substr($word,0,$i,$this->mb_enc ))) {
  20522. $cjkfix = 1;
  20523. }
  20524. // Next character is not allowed to start a new line
  20525. else if (preg_match("/[".$this->CJKfollowing."]/u", mb_substr($word,$i,1,$this->mb_enc ))) {
  20526. // try squeezing another character(s) onto this line = Oikomi
  20527. if ($this->allowCJKorphans && !$oneCJKorphan) {
  20528. //if lookahead is not another following char
  20529. if ($i==($mlen-1) || ($i<($mlen-1) && !preg_match("/[".$this->CJKfollowing."]/u", mb_substr($word,$i+1,1,$this->mb_enc )))) {
  20530. $wordwidth = $maxwidth - 0.0001;
  20531. $oneCJKorphan = true;
  20532. continue;
  20533. }
  20534. }
  20535. // or move lastchar(s) to next line
  20536. $cjkfix = 2;
  20537. }
  20538. // mPDF 5.6.42
  20539. // CJK numerals kept together
  20540. else if (preg_match("/([".$this->pregCJKchars."]+[0-9\x{ff10}-\x{ff19}]+$)/u", mb_substr($word,0,$i,$this->mb_enc )) && preg_match("/^([0-9\x{ff10}-\x{ff19}]+[".$this->pregCJKchars."]+)/u", mb_substr($word,$i,16,$this->mb_enc ))) {
  20541. $cjkfix = 3;
  20542. }
  20543. if ($cjkfix) {
  20544. //move lastchar(s) to next line
  20545. $m0 = mb_substr($word,$i-1,1,$this->mb_enc ); // chars to move
  20546. $m1 = mb_substr($word,0,$i-1,$this->mb_enc ); // str after stripped chars to move
  20547. $mi = $i - 1;
  20548. if ($cjkfix == 3) { $match = "0-9\x{ff10}-\x{ff19}"; }
  20549. else { $match = $this->CJKleading; }
  20550. while(preg_match("/[".$match."$]/u", $m1) && mb_strlen($m1, $this->mb_enc)>2) {
  20551. $m0 = mb_substr($m1,$mi-1,1,$this->mb_enc ).$m0; // chars to move
  20552. $m1 = mb_substr($m1,0,$mi-1,$this->mb_enc ); // str after stripped chars to move
  20553. $mi--;
  20554. }
  20555. // Insert $m0 into $word at $i
  20556. $word = mb_substr($word,0,$i,$this->mb_enc ) . $m0 . mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  20557. $mlen = mb_strlen($word, $this->mb_enc ); // increment max for loop counter
  20558. }
  20559. }
  20560. /*-- END CJK-FONTS --*/
  20561. if ($text && $firstchunk) {
  20562. // END OF LINE
  20563. // Finalise & add lineheight
  20564. $maxfontsize = max($maxfontsize,$this->FontSize);
  20565. $fh = $this->_computeLineheight($this->table_lineheight);
  20566. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20567. $fh = $this->FontSize;
  20568. $forceExactLineheight = false;
  20569. }
  20570. $maxlineHeight = max($maxlineHeight,$fh);
  20571. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20572. // START OF NEW LINE
  20573. // Initialise lineheight variables
  20574. $maxfontsize = $this->FontSize;
  20575. $forceExactLineheight = true;
  20576. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20577. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20578. $ln++;
  20579. }
  20580. // END OF LINE
  20581. // Finalise & add lineheight
  20582. $maxfontsize = max($maxfontsize,$this->FontSize);
  20583. $fh = $this->_computeLineheight($this->table_lineheight);
  20584. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20585. $fh = $this->FontSize;
  20586. $forceExactLineheight = false;
  20587. }
  20588. $maxlineHeight = max($maxlineHeight,$fh);
  20589. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20590. // START OF NEW LINE
  20591. // Initialise lineheight variables
  20592. $maxfontsize = $this->FontSize;
  20593. $forceExactLineheight = true;
  20594. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20595. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20596. $ln++;
  20597. $mxw = $maxwidth;
  20598. $text = mb_substr($word,0,$i,$this->mb_enc );
  20599. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  20600. $wordwidth = $this->GetStringWidth($word);
  20601. $width = 0;
  20602. $firstchunk=false;
  20603. break;
  20604. }
  20605. }
  20606. if (mb_strlen($word, $this->mb_enc )<2 && $wordwidth > $maxwidth + 0.0001) {
  20607. $wordwidth = $maxwidth - 0.0001;
  20608. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for single character!"); }
  20609. }
  20610. $firstchunk=false;
  20611. }
  20612. }
  20613. // Word fits on line...
  20614. if ($width + $wordwidth < $maxwidth + 0.0001) {
  20615. $mxw = max($mxw, ($width+$wordwidth));
  20616. $width += $wordwidth + $space;
  20617. $text .= $word.' ';
  20618. }
  20619. // Word does not fit on line...
  20620. else {
  20621. // mPDF 5.6.21 hard hyphens
  20622. if ($this->textparam['hyphens'] != 2 && preg_match('/\-/',$word)) {
  20623. list($hardsuccess,$pre,$post,$prelength) = $this->hardHyphenate($word, ($maxwidth - $width)-$this->GetCharWidth("-", false));
  20624. if ($hardsuccess) {
  20625. $text .= $pre.'-';
  20626. $word = $post;
  20627. $wordwidth = $this->GetStringWidth($word);
  20628. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20629. }
  20630. }
  20631. /*-- HYPHENATION --*/
  20632. // Soft Hyphens chr(173)
  20633. else if ($this->textparam['hyphens'] != 2 && (!$this->usingCoreFont && preg_match("/\xc2\xad/",$word)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$word) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) { // mPDF 5.6.06 5.6.08
  20634. list($success,$pre,$post,$prelength) = $this->softHyphenate($word, ($maxwidth - $width));
  20635. if ($success) {
  20636. $text .= $pre.'-';
  20637. $word = $post;
  20638. $wordwidth = $this->GetStringWidth($word);
  20639. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20640. }
  20641. }
  20642. else if ($this->textparam['hyphens'] == 1) { // mPDF 5.6.06 5.6.08
  20643. list($success,$pre,$post,$prelength) = $this->hyphenateWord($word, ($maxwidth - $width));
  20644. if ($success) {
  20645. $text .= $pre.'-';
  20646. $word = $post;
  20647. $wordwidth = $this->GetStringWidth($word);
  20648. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20649. }
  20650. }
  20651. /*-- END HYPHENATION --*/
  20652. // mPDF 5.6.22
  20653. if ( count($textbuffer)>1 && $cctr > 0 && $k==0
  20654. && (substr($textbuffer[$cctr][0],0,3) != "\xbb\xa4\xac")
  20655. && (substr($textbuffer[$cctr-1][0],0,3) != "\xbb\xa4\xac")
  20656. && substr($textbuffer[$cctr-1][0],-1,1) != ' '
  20657. && substr($textbuffer[$cctr][0],0,1) != ' '
  20658. ) {
  20659. // Go back to find a space in a previous chunk of content
  20660. $found = false;
  20661. for ($ix=$cctr-1;$ix>=0;$ix--) {
  20662. if (preg_match('/[ ]/',$textbuffer[$ix][0])) { $found = $ix; break; }
  20663. }
  20664. if ($found !== false) {
  20665. $charpos = strrpos($textbuffer[$found][0],' ');
  20666. // mPDF 5.6.24
  20667. $a1 = $a2 = $textbuffer[$found];
  20668. $a1[0] = "\n";
  20669. $a2[0] = substr($textbuffer[$found][0], $charpos+1, strlen($textbuffer[$found][0])-$charpos);
  20670. $textbuffer[$found][0] = substr($textbuffer[$found][0], 0, $charpos);
  20671. array_insert($textbuffer, $a1, $found+1);
  20672. array_insert($textbuffer, $a2, $found+2);
  20673. // Initialise all variables
  20674. $biggestword=0;
  20675. $toonarrow=false;
  20676. $lhfixed = false;
  20677. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight)) { $lhfixed = true; }
  20678. if ($lhfixed) { $def_lineheight = $this->_computeLineheight($this->table_lineheight, $def_fontsize);}
  20679. else { $def_lineheight = 0; }
  20680. $maxfontsize = 0;
  20681. $forceExactLineheight = true;
  20682. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20683. $maxlineHeight = $def_lineheight ;
  20684. $ch = 0;
  20685. $width = 0;
  20686. $ln = 1; // Counts line number
  20687. $mxw = $this->GetCharWidth('W',false);
  20688. $text = '';
  20689. $cctr = -1;
  20690. break;
  20691. }
  20692. }
  20693. // END OF LINE
  20694. // Finalise & add lineheight
  20695. $maxfontsize = max($maxfontsize,$this->FontSize);
  20696. $fh = $this->_computeLineheight($this->table_lineheight);
  20697. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20698. $fh = $this->FontSize;
  20699. $forceExactLineheight = false;
  20700. }
  20701. $maxlineHeight = max($maxlineHeight,$fh);
  20702. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20703. $mxw = $maxwidth;
  20704. // START OF NEW LINE
  20705. // Initialise lineheight variables
  20706. $maxfontsize = $this->FontSize;
  20707. $forceExactLineheight = true;
  20708. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20709. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20710. $ln++;
  20711. $width = $wordwidth + $space;
  20712. $text = $word.' ';
  20713. }
  20714. $maxfontsize = max($maxfontsize,$this->FontSize);
  20715. $fh = $this->_computeLineheight($this->table_lineheight);
  20716. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20717. $fh = $this->FontSize;
  20718. $forceExactLineheight = false;
  20719. }
  20720. $maxlineHeight = max($maxlineHeight,$fh);
  20721. }
  20722. // End of textbuffer chunk
  20723. if (!$lsend) {
  20724. $width -= $space;
  20725. $text = rtrim($text);
  20726. }
  20727. // RESET FONT SIZE/STYLE
  20728. // RESETTING VALUES
  20729. //Now we must deactivate what we have used
  20730. if(isset($chunk[2]) and $chunk[2] != '') {
  20731. $this->ResetStyles();
  20732. }
  20733. if(isset($chunk[4]) and $chunk[4] != '') {
  20734. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  20735. }
  20736. if(isset($chunk[11]) and $chunk[11] != '') {
  20737. $this->SetFontSize($this->default_font_size,false);
  20738. }
  20739. $this->spanborddet = array();
  20740. $this->kerning = false;
  20741. $this->lSpacingCSS = '';
  20742. $this->wSpacingCSS = '';
  20743. $this->fixedlSpacing = false;
  20744. $this->minwSpacing = 0;
  20745. }
  20746. // Finalise lineheight if something output on line and add
  20747. if ($width) {
  20748. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20749. }
  20750. if ($returnarray) { return array($ch,$ln,$mxw); }
  20751. else { return $ch; }
  20752. }
  20753. function TableCheckMinWidth($maxwidth, $forcewrap = 0, $textbuffer) {
  20754. $biggestword=0;
  20755. $toonarrow=false;
  20756. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  20757. foreach ($textbuffer as $chunk) {
  20758. $line = $chunk[0];
  20759. // mPDF ITERATION
  20760. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  20761. // IMAGES & FORM ELEMENTS
  20762. if (substr($line,0,3) == "\xbb\xa4\xac") { //inline object - FORM element or IMAGE!
  20763. $objattr = $this->_getObjAttr($line);
  20764. if ($objattr['type']!='hr' && isset($objattr['width']) && ($objattr['width']/$this->shrin_k) > ($maxwidth + 0.0001) ) {
  20765. if (($objattr['width']/$this->shrin_k) > $biggestword) { $biggestword = ($objattr['width']/$this->shrin_k); }
  20766. $toonarrow=true;
  20767. }
  20768. continue;
  20769. }
  20770. if ($line == "\n") {
  20771. continue;
  20772. }
  20773. $line = trim($line );
  20774. // SET FONT SIZE/STYLE from $chunk[n]
  20775. // FONTSIZE
  20776. if(isset($chunk[11]) and $chunk[11] != '') {
  20777. if ($this->shrin_k) {
  20778. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  20779. }
  20780. else {
  20781. $this->SetFontSize($chunk[11],false);
  20782. }
  20783. }
  20784. // FONTFAMILY
  20785. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  20786. // B I U
  20787. if(isset($chunk[2]) and $chunk[2] != '') {
  20788. $this->SetStyles($chunk[2]);
  20789. }
  20790. $lbw = $rbw = 0; // Border widths
  20791. if(isset($chunk[16]) && !empty($chunk[16])) { //Border
  20792. $this->spanborddet = $chunk[16];
  20793. $lbw = $this->spanborddet['L']['w'];
  20794. $rbw = $this->spanborddet['R']['w'];
  20795. }
  20796. if(isset($chunk[15])) { // Word spacing
  20797. $this->wSpacingCSS = $chunk[15];
  20798. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20799. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  20800. }
  20801. }
  20802. if(isset($chunk[14])) { // Letter spacing
  20803. $this->lSpacingCSS = $chunk[14];
  20804. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  20805. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  20806. }
  20807. }
  20808. if(isset($chunk[13])) { // Font Kerning
  20809. $this->kerning = $chunk[13];
  20810. }
  20811. $words = explode(' ', $line);
  20812. foreach ($words as $k=>$word) {
  20813. $word = trim($word);
  20814. $wordwidth = $this->GetStringWidth($word);
  20815. if ($k==0) { $wordwidth += $lbw; }
  20816. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  20817. //Warn user that maxwidth is insufficient
  20818. if ($wordwidth > $maxwidth + 0.0001) {
  20819. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  20820. $toonarrow=true;
  20821. }
  20822. }
  20823. // RESET FONT SIZE/STYLE
  20824. // RESETTING VALUES
  20825. //Now we must deactivate what we have used
  20826. if(isset($chunk[2]) and $chunk[2] != '') {
  20827. $this->ResetStyles();
  20828. }
  20829. if(isset($chunk[4]) and $chunk[4] != '') {
  20830. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  20831. }
  20832. if(isset($chunk[11]) and $chunk[11] != '') {
  20833. $this->SetFontSize($this->default_font_size,false);
  20834. }
  20835. $this->spanborddet = array();
  20836. $this->kerning = false;
  20837. $this->lSpacingCSS = '';
  20838. $this->wSpacingCSS = '';
  20839. $this->fixedlSpacing = false;
  20840. $this->minwSpacing = 0;
  20841. }
  20842. //Return -(wordsize) if word is bigger than maxwidth
  20843. // ADDED
  20844. if (($toonarrow) && ($this->table_error_report)) {
  20845. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  20846. }
  20847. if ($toonarrow) return -$biggestword;
  20848. else return 1;
  20849. }
  20850. function shrinkTable(&$table,$k) {
  20851. $table['border_spacing_H'] /= $k;
  20852. $table['border_spacing_V'] /= $k;
  20853. $table['padding']['T'] /= $k;
  20854. $table['padding']['R'] /= $k;
  20855. $table['padding']['B'] /= $k;
  20856. $table['padding']['L'] /= $k;
  20857. $table['margin']['T'] /= $k;
  20858. $table['margin']['R'] /= $k;
  20859. $table['margin']['B'] /= $k;
  20860. $table['margin']['L'] /= $k;
  20861. $table['border_details']['T']['w'] /= $k;
  20862. $table['border_details']['R']['w'] /= $k;
  20863. $table['border_details']['B']['w'] /= $k;
  20864. $table['border_details']['L']['w'] /= $k;
  20865. if (isset($table['max_cell_border_width']['T'])) $table['max_cell_border_width']['T'] /= $k;
  20866. if (isset($table['max_cell_border_width']['R'])) $table['max_cell_border_width']['R'] /= $k;
  20867. if (isset($table['max_cell_border_width']['B'])) $table['max_cell_border_width']['B'] /= $k;
  20868. if (isset($table['max_cell_border_width']['L'])) $table['max_cell_border_width']['L'] /= $k;
  20869. if ($this->simpleTables){
  20870. $table['simple']['border_details']['T']['w'] /= $k;
  20871. $table['simple']['border_details']['R']['w'] /= $k;
  20872. $table['simple']['border_details']['B']['w'] /= $k;
  20873. $table['simple']['border_details']['L']['w'] /= $k;
  20874. }
  20875. $table['miw'] /= $k;
  20876. $table['maw'] /= $k;
  20877. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  20878. for($j = 0 ; $j < $table['nc'] ; $j++ ) { //columns
  20879. $table['wc'][$j]['miw'] /= $k;
  20880. $table['wc'][$j]['maw'] /= $k;
  20881. // mPDF 5.6.13
  20882. if (isset($table['decimal_align'][$j]['maxs0']) && $table['decimal_align'][$j]['maxs0']) { $table['decimal_align'][$j]['maxs0'] /= $k; }
  20883. if (isset($table['decimal_align'][$j]['maxs1']) && $table['decimal_align'][$j]['maxs1']) { $table['decimal_align'][$j]['maxs1'] /= $k; }
  20884. if (isset($table['wc'][$j]['absmiw']) && $table['wc'][$j]['absmiw'] ) $table['wc'][$j]['absmiw'] /= $k;
  20885. for($i = 0 ; $i < $table['nr']; $i++ ) { //rows
  20886. if ($this->cacheTables) {
  20887. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  20888. }
  20889. else
  20890. $c = &$table['cells'][$i][$j];
  20891. if (isset($c) && $c) {
  20892. if (!$this->simpleTables){
  20893. if ($this->packTableData) {
  20894. $cell = $this->_unpackCellBorder($c['borderbin'] );
  20895. $cell['border_details']['T']['w'] /= $k;
  20896. $cell['border_details']['R']['w'] /= $k;
  20897. $cell['border_details']['B']['w'] /= $k;
  20898. $cell['border_details']['L']['w'] /= $k;
  20899. $cell['border_details']['mbw']['TL'] /= $k;
  20900. $cell['border_details']['mbw']['TR'] /= $k;
  20901. $cell['border_details']['mbw']['BL'] /= $k;
  20902. $cell['border_details']['mbw']['BR'] /= $k;
  20903. $cell['border_details']['mbw']['LT'] /= $k;
  20904. $cell['border_details']['mbw']['LB'] /= $k;
  20905. $cell['border_details']['mbw']['RT'] /= $k;
  20906. $cell['border_details']['mbw']['RB'] /= $k;
  20907. $c['borderbin'] = $this->_packCellBorder($cell);
  20908. }
  20909. else {
  20910. $c['border_details']['T']['w'] /= $k;
  20911. $c['border_details']['R']['w'] /= $k;
  20912. $c['border_details']['B']['w'] /= $k;
  20913. $c['border_details']['L']['w'] /= $k;
  20914. $c['border_details']['mbw']['TL'] /= $k;
  20915. $c['border_details']['mbw']['TR'] /= $k;
  20916. $c['border_details']['mbw']['BL'] /= $k;
  20917. $c['border_details']['mbw']['BR'] /= $k;
  20918. $c['border_details']['mbw']['LT'] /= $k;
  20919. $c['border_details']['mbw']['LB'] /= $k;
  20920. $c['border_details']['mbw']['RT'] /= $k;
  20921. $c['border_details']['mbw']['RB'] /= $k;
  20922. }
  20923. }
  20924. $c['padding']['T'] /= $k;
  20925. $c['padding']['R'] /= $k;
  20926. $c['padding']['B'] /= $k;
  20927. $c['padding']['L'] /= $k;
  20928. $c['maxs'] /= $k;
  20929. if (isset($c['w'])) { $c['w'] /= $k; }
  20930. $c['s'] /= $k;
  20931. $c['maw'] /= $k;
  20932. $c['miw'] /= $k;
  20933. if (isset($c['absmiw'])) $c['absmiw'] /= $k;
  20934. if (isset($c['nestedmaw'])) $c['nestedmaw'] /= $k;
  20935. if (isset($c['nestedmiw'])) $c['nestedmiw'] /= $k;
  20936. if (isset($c['textbuffer'])) {
  20937. foreach($c['textbuffer'] AS $n=>$tb) {
  20938. if (!empty($tb[16])) {
  20939. $c['textbuffer'][$n][16]['T']['w'] /= $k;
  20940. $c['textbuffer'][$n][16]['B']['w'] /= $k;
  20941. $c['textbuffer'][$n][16]['L']['w'] /= $k;
  20942. $c['textbuffer'][$n][16]['R']['w'] /= $k;
  20943. }
  20944. }
  20945. }
  20946. if ($this->cacheTables) {
  20947. $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]);
  20948. }
  20949. unset($c);
  20950. }
  20951. }//rows
  20952. }//columns
  20953. if ($this->cacheTables) { fclose($fh); }
  20954. }
  20955. function _cacheCell($c, $file, $mode="A", $fh=null, $offset=0) { // mode = Append or (over)Write (needs offset and fh)
  20956. // Requires either $file OR $fh (file_handle)
  20957. if (!is_array($c) || !isset($c)) { return ''; }
  20958. if(isset($c['w'])) { $cw = $c['w']; } else { $cw = -1; }
  20959. if(isset($c['w0'])) { $cw0 = $c['w0']; } else { $cw0 = -1; }
  20960. if(isset($c['h0'])) { $ch0 = $c['h0']; } else { $ch0 = -1; }
  20961. $data = pack("n2d19A1A1n2sA32A128",
  20962. $c['colspan'], /* n (16 bit; 2 bytes) [pos 0] */
  20963. $c['rowspan'], /* n (16 bit; 2 bytes) [pos 2] */
  20964. $c['s'], /* d NB machine-dependent size (64 bit; 8 bytes on test winOS) [pos 4] */
  20965. $c['maxs'], /* d NB machine-dependent size [pos 4 + 1*D] */
  20966. $c['nestedmaw'], /* d NB machine-dependent size [pos 4 + 2*D] */
  20967. $c['nestedmiw'], /* d NB machine-dependent size [pos 4 + 3*D] */
  20968. $c['padding']['L'], /* d NB machine-dependent size [pos 4 + 4*D] */
  20969. $c['padding']['R'], /* d NB machine-dependent size [pos 4 + 5*D] */
  20970. $c['padding']['T'], /* d NB machine-dependent size [pos 4 + 6*D] */
  20971. $c['padding']['B'], /* d NB machine-dependent size [pos 4 + 7*D] */
  20972. $c['dfs'], /* d NB machine-dependent size [pos 4 + 8*D] */
  20973. $cw, /* d NB machine-dependent size [pos 4 + 9*D] */
  20974. $c['h'], /* d NB machine-dependent size [pos 4 + 10*D] */
  20975. $c['absmiw'], /* d NB machine-dependent size [pos 4 + 11*D] */
  20976. $c['maw'], /* d NB machine-dependent size [pos 4 + 12*D] */
  20977. $c['miw'], /* d NB machine-dependent size [pos 4 + 13*D] */
  20978. $c['mih'], /* d NB machine-dependent size [pos 4 + 14*D] */
  20979. $c['x0'], /* d NB machine-dependent size [pos 4 + 15*D] */
  20980. $cw0, /* d NB machine-dependent size [pos 4 + 16*D] */
  20981. $c['y0'], /* d NB machine-dependent size [pos 4 + 17*D] */
  20982. $ch0, /* d NB machine-dependent size [pos 4 + 18*D] */
  20983. $c['a'], /* A1 (1 byte) [pos 4 + 19*D] */
  20984. $c['va'], /* A1 (1 byte) [pos 5 + 19*D] */
  20985. $c['nowrap'], /* 1 or blank n (16 bit; 2 bytes) [pos 6 + 19*D] */
  20986. $c['wpercent'], /* 0 - 100 n (16 bit; 2 bytes) [pos 8 + 19*D] */
  20987. $c['R'], /* 90 or -90 s (16 bit; 2 bytes) [pos 10 + 19*D] */
  20988. $c['bgcolor'], /* A32 (32 bytes) [pos 12 + 19*D] */
  20989. $c['gradient'] /* A128 (128 bytes) [pos 44 + 19*D] */
  20990. );
  20991. if ($c['background-image']) {
  20992. $data .= pack("n2d2A6A6n3dA4A128",
  20993. strlen($data), /* offset in main data to start of bgimage data */
  20994. $c['background-image']['image_id'], /* n */
  20995. $c['background-image']['orig_w'], /* d NB machine-dependent size */
  20996. $c['background-image']['orig_h'], /* d NB machine-dependent size */
  20997. $c['background-image']['x_pos'], /* A6 calc size or "50%" */
  20998. $c['background-image']['y_pos'], /* A6 calc size or "50%" */
  20999. $c['background-image']['x_repeat'], /* n true or false*/
  21000. $c['background-image']['y_repeat'], /* n true or false */
  21001. $c['background-image']['resize'], /* n 0 - 6 */
  21002. $c['background-image']['opacity'], /* d 0-1 */
  21003. $c['background-image']['itype'], /* A4 jpg etc */
  21004. $c['background-image']['gradient'] /* A128 CSS string */
  21005. );
  21006. }
  21007. else $data .= pack("n",0);
  21008. $tb_offset = 2 + 186 + 2 + strlen($data);
  21009. $stb = serialize($c['textbuffer']).' '; // buffer to allow updating in reverseTableDir
  21010. $lentb = strlen($stb);
  21011. $data2 = pack("nA".$lentb, $lentb, $stb);
  21012. $tempfh = true;
  21013. if ($mode=="W" && $offset) {
  21014. if (!$fh) { $fh = fopen($file, "r+b"); } // Overwrite (but not truncate)
  21015. else $tempfh = false;
  21016. fseek($fh, $offset);
  21017. }
  21018. else {
  21019. $fh = fopen($file, "ab"); // APPEND
  21020. }
  21021. fwrite($fh, pack("n",$tb_offset)); // Offset to Text buffer 2 bytes
  21022. fwrite($fh, $c['borderbin']); // border details 186 bytes
  21023. fwrite($fh, pack("n",strlen($data))); // Length of Main data
  21024. fwrite($fh, $data); // Main data
  21025. fwrite($fh, $data2); // Text buffer (starts with "n" length of text buffer)
  21026. if ($tempfh) fclose($fh);
  21027. return ($tb_offset + 2 + $lentb);
  21028. }
  21029. function _cacheUpdateTxB($c, $fh, $offset) {
  21030. fseek($fh, $offset);
  21031. $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes
  21032. fseek($fh, ($tb_offset-2), SEEK_CUR);
  21033. $lentb = $this->read_short($fh); // First entry in textbuffer = Length of serialized textbuffer - do not update
  21034. $stb = serialize($c['textbuffer']);
  21035. fwrite($fh, pack("A".$lentb, $stb));
  21036. }
  21037. function _cacheUpdateBorder($c, $fh, $offset) {
  21038. $offset += 2;
  21039. fseek($fh, $offset);
  21040. fwrite($fh, $c['borderbin']);
  21041. }
  21042. function _cacheUpdateMtx($c, $fh, $offset, $var) {
  21043. if ($var=='mih') { $offset += (2 + 186 + 2 + 4 + 14*_DSIZE); }
  21044. else if ($var=='x0') { $offset += (2 + 186 + 2 + 4 + 15*_DSIZE); } // x0 and w0
  21045. else if ($var=='y0') { $offset += (2 + 186 + 2 + 4 + 17*_DSIZE); } // y0 and h0
  21046. fseek($fh, $offset);
  21047. if ($var=='mih') { fwrite($fh, pack("d",$c['mih'])); }
  21048. else if ($var=='x0') { fwrite($fh, pack("d2",$c['x0'],$c['w0'])); }
  21049. else if ($var=='y0') { fwrite($fh, pack("d2",$c['y0'],$c['h0'])); }
  21050. }
  21051. function _uncacheCell($ptr, $file, $fh) {
  21052. // Requires either $file or $fh (file_handle)
  21053. if ($ptr==0) { return null; }
  21054. if (is_array($ptr)) { $this->Error("Probable cause - missing end tag &lt;/td&gt;. You may be able to change the configurable variable: allow_html_optional_endtags "); }
  21055. $tempfh = true;
  21056. if (!$fh) { $fh = fopen($file, "rb"); }
  21057. else $tempfh = false;
  21058. fseek($fh, $ptr);
  21059. $c = array();
  21060. $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes
  21061. $c['borderbin'] = fread($fh,186); // border details 186 bytes
  21062. $maindatalen = $this->read_short($fh); // Length of Main data (2 bytes)
  21063. $str = fread($fh,$maindatalen ); // Main data
  21064. $data = unpack("ncolspan/nrowspan/ds/dmaxs/dnmaw/dnmiw/dpl/dpr/dpt/dpb/ddfs/dw/dh/dabsmiw/dmaw/dmiw/dmih/dx0/dw0/dy0/dh0/A1a/A1va/nnowrap/nwpercent/sR/A32bgcol/A128grad/nbgimage", $str);
  21065. if ($data['colspan']>0) $c['colspan'] = $data['colspan']; /* n */
  21066. if ($data['rowspan']>0) $c['rowspan'] = $data['rowspan']; /* n */
  21067. $c['s'] = $data['s']; /* d NB machine-dependent size */
  21068. $c['maxs'] = $data['maxs']; /* d NB machine-dependent size */
  21069. if ($data['nmaw']>0) $c['nestedmaw'] = $data['nmaw']; /* d NB machine-dependent size */
  21070. if ($data['nmiw']>0) $c['nestedmiw'] = $data['nmiw']; /* d NB machine-dependent size */
  21071. $c['padding']['L'] = $data['pl']; /* d NB machine-dependent size */
  21072. $c['padding']['R'] = $data['pr']; /* d NB machine-dependent size */
  21073. $c['padding']['T'] = $data['pt']; /* d NB machine-dependent size */
  21074. $c['padding']['B'] = $data['pb']; /* d NB machine-dependent size */
  21075. $c['dfs'] = $data['dfs']; /* d NB machine-dependent size */
  21076. if ($data['w']>=0) $c['w'] = $data['w']; /* d NB machine-dependent size */
  21077. if ($data['h']>0) $c['h'] = $data['h']; /* d NB machine-dependent size */
  21078. if ($data['absmiw']>0) $c['absmiw'] = $data['absmiw']; /* d NB machine-dependent size */
  21079. if ($data['maw']>0) $c['maw'] = $data['maw']; /* d NB machine-dependent size */
  21080. if ($data['miw']>0) $c['miw'] = $data['miw']; /* d NB machine-dependent size */
  21081. if ($data['mih']>0) $c['mih'] = $data['mih']; /* d NB machine-dependent size */
  21082. if ($data['w0']>=0) { $c['w0'] = $data['w0']; /* d NB machine-dependent size */
  21083. $c['x0'] = $data['x0']; } /* d NB machine-dependent size */
  21084. if ($data['h0']>=0) { $c['h0'] = $data['h0']; /* d NB machine-dependent size */
  21085. $c['y0'] = $data['y0']; } /* d NB machine-dependent size */
  21086. $c['a'] = trim($data['a']); /* A1 */
  21087. $c['va'] = trim($data['va']); /* A1 */
  21088. if ($data['nowrap']) $c['nowrap'] = $data['nowrap']; /* 1 or blank n */
  21089. else $c['nowrap'] = false;
  21090. if ($data['wpercent']>0) $c['wpercent'] = $data['wpercent']; /* 0 - 100 n */
  21091. if ($data['R']<>0) $c['R'] = $data['R']; /* 90 or -90 s */
  21092. else $c['R'] = false;
  21093. $c['bgcolor'] = trim($data['bgcol']); /* A32 */
  21094. if (trim($data['grad']))
  21095. $c['gradient'] = trim($data['grad']); /* A128 */
  21096. else $c['gradient'] = false;
  21097. if ($data['bgimage']>0) {
  21098. $bgidata = substr($str, ($data['bgimage']+2));
  21099. $c['background-image'] = unpack("nimage_id/dorig_w/dorig_h/A6x_pos/A6y_pos/nx_repeat/ny_repeat/nresize/dopacity/A4itype/A128gradient", $bgidata);
  21100. }
  21101. $tblen = $this->read_short($fh); // Length of Textbuffer
  21102. $tbsp = fread($fh,$tblen); // Textbuffer (serialised and packed)
  21103. $tbs = unpack("A".$tblen."textbuffer",$tbsp); // Textbuffer unpacked
  21104. $c['textbuffer'] = unserialize(trim($tbs['textbuffer'])); // Textbuffer unserialized
  21105. if ($tempfh) { fclose($fh); }
  21106. return ($c);
  21107. }
  21108. function read_short(&$fh) {
  21109. $s = fread($fh,2);
  21110. $a = (ord($s[0])<<8) + ord($s[1]);
  21111. if ($a & (1 << 15) ) {
  21112. $a = ($a - (1 << 16));
  21113. }
  21114. return $a;
  21115. }
  21116. function _backupCacheFiles() {
  21117. foreach($this->table AS $lvl=>$t) {
  21118. foreach($this->table[$lvl] AS $c=>$t2) {
  21119. ///////////////////////////if (!file_exists($t2['cache'])) { echo $lvl; echo $c; print_r($this->table); exit; }
  21120. copy( $t2['cache'], $t2['cache'].'.bak');
  21121. }
  21122. }
  21123. }
  21124. function _restoreCacheFiles() {
  21125. foreach($this->table AS $lvl=>$t) {
  21126. foreach($this->table[$lvl] AS $c=>$t2) {
  21127. copy( $t2['cache'].'.bak', $t2['cache']);
  21128. }
  21129. }
  21130. }
  21131. function _packCellBorder($cell) {
  21132. if (!is_array($cell) || !isset($cell)) { return ''; }
  21133. if (!$this->packTableData) { return $cell; }
  21134. // = 186 bytes
  21135. $bindata = pack("nnda6A10nnda6A10nnda6A10nnda6A10nd9",
  21136. $cell['border'],
  21137. $cell['border_details']['R']['s'],
  21138. $cell['border_details']['R']['w'],
  21139. $cell['border_details']['R']['c'],
  21140. $cell['border_details']['R']['style'],
  21141. $cell['border_details']['R']['dom'],
  21142. $cell['border_details']['L']['s'],
  21143. $cell['border_details']['L']['w'],
  21144. $cell['border_details']['L']['c'],
  21145. $cell['border_details']['L']['style'],
  21146. $cell['border_details']['L']['dom'],
  21147. $cell['border_details']['T']['s'],
  21148. $cell['border_details']['T']['w'],
  21149. $cell['border_details']['T']['c'],
  21150. $cell['border_details']['T']['style'],
  21151. $cell['border_details']['T']['dom'],
  21152. $cell['border_details']['B']['s'],
  21153. $cell['border_details']['B']['w'],
  21154. $cell['border_details']['B']['c'],
  21155. $cell['border_details']['B']['style'],
  21156. $cell['border_details']['B']['dom'],
  21157. $cell['border_details']['mbw']['BL'],
  21158. $cell['border_details']['mbw']['BR'],
  21159. $cell['border_details']['mbw']['RT'],
  21160. $cell['border_details']['mbw']['RB'],
  21161. $cell['border_details']['mbw']['TL'],
  21162. $cell['border_details']['mbw']['TR'],
  21163. $cell['border_details']['mbw']['LT'],
  21164. $cell['border_details']['mbw']['LB'],
  21165. $cell['border_details']['cellposdom']
  21166. );
  21167. return $bindata;
  21168. }
  21169. function _getBorderWidths($bindata) {
  21170. if (!$bindata) { return array(0,0,0,0); }
  21171. 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']); }
  21172. $bd = unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10tst/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata);
  21173. $cell['border_details']['R']['w'] = $bd['rw'];
  21174. $cell['border_details']['L']['w'] = $bd['lw'];
  21175. $cell['border_details']['T']['w'] = $bd['tw'];
  21176. $cell['border_details']['B']['w'] = $bd['bw'];
  21177. return array($bd['tw'], $bd['rw'], $bd['bw'], $bd['lw']);
  21178. }
  21179. function _unpackCellBorder($bindata) {
  21180. if (!$bindata) { return array(); }
  21181. if (!$this->packTableData) { return $bindata; }
  21182. $bd = unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10tst/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata);
  21183. $cell['border'] = $bd['bord'];
  21184. $cell['border_details']['R']['s'] = $bd['rs'];
  21185. $cell['border_details']['R']['w'] = $bd['rw'];
  21186. $cell['border_details']['R']['c'] = $bd['rca'];
  21187. $cell['border_details']['R']['style'] = trim($bd['rst']);
  21188. $cell['border_details']['R']['dom'] = $bd['rd'];
  21189. $cell['border_details']['L']['s'] = $bd['ls'];
  21190. $cell['border_details']['L']['w'] = $bd['lw'];
  21191. $cell['border_details']['L']['c'] = $bd['lca'];
  21192. $cell['border_details']['L']['style'] = trim($bd['lst']);
  21193. $cell['border_details']['L']['dom'] = $bd['ld'];
  21194. $cell['border_details']['T']['s'] = $bd['ts'];
  21195. $cell['border_details']['T']['w'] = $bd['tw'];
  21196. $cell['border_details']['T']['c'] = $bd['tca'];
  21197. $cell['border_details']['T']['style'] = trim($bd['tst']);
  21198. $cell['border_details']['T']['dom'] = $bd['td'];
  21199. $cell['border_details']['B']['s'] = $bd['bs'];
  21200. $cell['border_details']['B']['w'] = $bd['bw'];
  21201. $cell['border_details']['B']['c'] = $bd['bca'];
  21202. $cell['border_details']['B']['style'] = trim($bd['bst']);
  21203. $cell['border_details']['B']['dom'] = $bd['bd'];
  21204. $cell['border_details']['mbw']['BL'] = $bd['mbl'];
  21205. $cell['border_details']['mbw']['BR'] = $bd['mbr'];
  21206. $cell['border_details']['mbw']['RT'] = $bd['mrt'];
  21207. $cell['border_details']['mbw']['RB'] = $bd['mrb'];
  21208. $cell['border_details']['mbw']['TL'] = $bd['mtl'];
  21209. $cell['border_details']['mbw']['TR'] = $bd['mtr'];
  21210. $cell['border_details']['mbw']['LT'] = $bd['mlt'];
  21211. $cell['border_details']['mbw']['LB'] = $bd['mlb'];
  21212. $cell['border_details']['cellposdom'] = $bd['cpd'];
  21213. return($cell);
  21214. }
  21215. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21216. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21217. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21218. //table Array of (w, h, bc, nr, wc, hr, cells)
  21219. //w Width of table
  21220. //h Height of table
  21221. //nc Number column
  21222. //nr Number row
  21223. //hr List of height of each row
  21224. //wc List of width of each column
  21225. //cells List of cells of each rows, cells[i][j] is a cell in the table
  21226. function _tableColumnWidth(&$table,$firstpass=false){
  21227. $cs = &$table['cells'];
  21228. $nc = $table['nc'];
  21229. $nr = $table['nr'];
  21230. $listspan = array();
  21231. if ($table['borders_separate']) {
  21232. $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'];
  21233. }
  21234. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  21235. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  21236. else { $fh = null; }
  21237. // ADDED table['l'][colno]
  21238. // = total length of text approx (using $c['s']) in that column - used to approximately distribute col widths in _tableWidth
  21239. //
  21240. for($j = 0 ; $j < $nc ; $j++ ) { //columns
  21241. $wc = &$table['wc'][$j];
  21242. for($i = 0 ; $i < $nr ; $i++ ) { //rows
  21243. if (isset($cs[$i][$j]) && $cs[$i][$j]) {
  21244. if ($this->cacheTables) {
  21245. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21246. }
  21247. else
  21248. $c = &$cs[$i][$j];
  21249. if ($this->simpleTables){
  21250. if ($table['borders_separate']) { // NB twice border width
  21251. $extrcw = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21252. }
  21253. else {
  21254. $extrcw = $table['simple']['border_details']['L']['w']/2 + $table['simple']['border_details']['R']['w']/2 + $c['padding']['L'] + $c['padding']['R'];
  21255. }
  21256. }
  21257. else {
  21258. if ($this->packTableData) {
  21259. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  21260. }
  21261. else {
  21262. $br = $c['border_details']['R']['w'];
  21263. $bl = $c['border_details']['L']['w'];
  21264. }
  21265. if ($table['borders_separate']) { // NB twice border width
  21266. $extrcw = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21267. }
  21268. else {
  21269. $extrcw = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  21270. }
  21271. }
  21272. //$mw = $this->GetStringWidth('W') + $extrcw ;
  21273. $mw = 0;
  21274. // mPDF 5.6.13 Decimal point alignment
  21275. if(substr($c['a'],0,1) == 'D') {
  21276. $mw = $table['decimal_align'][$j]['maxs0'] + $table['decimal_align'][$j]['maxs1'] + $extrcw ;
  21277. }
  21278. $c['absmiw'] = $mw;
  21279. if (isset($c['R']) && $c['R']) {
  21280. $c['maw'] = $c['miw'] = $this->FontSize + $extrcw ;
  21281. if (isset($c['w'])) { // If cell width is specified
  21282. if ($c['miw'] <$c['w']) { $c['miw'] = $c['w']; }
  21283. }
  21284. if (!isset($c['colspan'])) {
  21285. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; }
  21286. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21287. if ($firstpass) {
  21288. if (isset($table['l'][$j]) ) {
  21289. $table['l'][$j] += $c['miw'] ;
  21290. }
  21291. else {
  21292. $table['l'][$j] = $c['miw'] ;
  21293. }
  21294. }
  21295. }
  21296. if ($c['miw'] > $wc['miw']) { $wc['miw'] = $c['miw']; }
  21297. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; }
  21298. continue;
  21299. }
  21300. if ($firstpass) {
  21301. if (isset($c['s'])) { $c['s'] += $extrcw; }
  21302. if (isset($c['maxs'])) { $c['maxs'] += $extrcw; }
  21303. if (isset($c['nestedmiw'])) { $c['nestedmiw'] += $extrcw; }
  21304. if (isset($c['nestedmaw'])) { $c['nestedmaw'] += $extrcw; }
  21305. }
  21306. // If minimum width has already been set by a nested table or inline object (image/form), use it
  21307. if (isset($c['nestedmiw']) && $this->table[1][1]['overflow']!='visible') { $miw = $c['nestedmiw']; }
  21308. else { $miw = $mw; }
  21309. if (isset($c['maxs']) && $c['maxs'] != '') { $c['s'] = $c['maxs']; }
  21310. // If maximum width has already been set by a nested table, use it
  21311. if (isset($c['nestedmaw'])) { $c['maw'] = $c['nestedmaw']; }
  21312. else $c['maw'] = $c['s'];
  21313. if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) {
  21314. if (($c['maw'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  21315. $c['maw'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw;
  21316. }
  21317. }
  21318. if (isset($c['nowrap']) && $c['nowrap']) { $miw = $c['maw']; }
  21319. if (isset($c['wpercent']) && $firstpass) {
  21320. if (isset($c['colspan'])) { // Not perfect - but % set on colspan is shared equally on cols.
  21321. for($k=0;$k<$c['colspan'];$k++) {
  21322. $table['wc'][($j+$k)]['wpercent'] = $c['wpercent'] / $c['colspan'];
  21323. }
  21324. }
  21325. else {
  21326. if (isset($table['w']) && $table['w']) { $c['w'] = $c['wpercent']/100 * ($table['w'] - $tblbw ); }
  21327. $wc['wpercent'] = $c['wpercent'];
  21328. }
  21329. }
  21330. if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) {
  21331. if (($c['w'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  21332. $c['w'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw;
  21333. }
  21334. }
  21335. if (isset($c['w'])) { // If cell width is specified
  21336. if ($miw<$c['w']) { $c['miw'] = $c['w']; } // Cell min width = that specified
  21337. if ($miw>$c['w']) { $c['miw'] = $c['w'] = $miw; } // If width specified is less than minimum allowed (W) increase it
  21338. if (!isset($wc['w'])) { $wc['w'] = 1; } // If the Col width is not specified = set it to 1
  21339. }
  21340. else { $c['miw'] = $miw; } // If cell width not specified -> set Cell min width it to minimum allowed (W)
  21341. if ($c['maw'] < $c['miw']) { $c['maw'] = $c['miw']; } // If Cell max width < Minwidth - increase it to =
  21342. if (!isset($c['colspan'])) {
  21343. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; } // Update Col Minimum and maximum widths
  21344. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21345. if ((isset($wc['absmiw']) && $wc['absmiw'] < $c['absmiw']) || !isset($wc['absmiw'])) { $wc['absmiw'] = $c['absmiw']; } // Update Col Minimum and maximum widths
  21346. if (isset($table['l'][$j]) ) {
  21347. $table['l'][$j] += $c['s'];
  21348. }
  21349. else {
  21350. $table['l'][$j] = $c['s'];
  21351. }
  21352. }
  21353. else {
  21354. $listspan[] = array($i,$j);
  21355. }
  21356. //Check if minimum width of the whole column is big enough for largest word to fit
  21357. if (isset($c['textbuffer']) && (!isset($table['overflow']) || $table['overflow']!='wrap')) { // mPDF 5.5.11
  21358. $minwidth = $this->TableCheckMinWidth($wc['miw']- $extrcw ,0,$c['textbuffer']);
  21359. }
  21360. else { $minwidth = 0; }
  21361. if ($minwidth < 0) {
  21362. //increase minimum width
  21363. if (!isset($c['colspan'])) {
  21364. $wc['miw'] = max($wc['miw'],((-$minwidth) + $extrcw) );
  21365. }
  21366. else {
  21367. $c['miw'] = max($c['miw'],((-$minwidth) + $extrcw) );
  21368. }
  21369. }
  21370. if (!isset($c['colspan'])) {
  21371. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; } //update maximum width, if needed
  21372. }
  21373. if ($this->cacheTables) {
  21374. $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]);
  21375. }
  21376. }
  21377. unset($c);
  21378. }//rows
  21379. }//columns
  21380. // COLUMN SPANS
  21381. $wc = &$table['wc'];
  21382. foreach ($listspan as $span) {
  21383. list($i,$j) = $span;
  21384. if ($this->cacheTables) {
  21385. $c = $this->_uncacheCell($cs[$i][$j], '', $fh);
  21386. }
  21387. else
  21388. $c = &$cs[$i][$j];
  21389. $lc = $j + $c['colspan'];
  21390. if ($lc > $nc) { $lc = $nc; }
  21391. $wis = $wisa = 0;
  21392. $was = $wasa = 0;
  21393. $list = array();
  21394. for($k=$j;$k<$lc;$k++) {
  21395. if (isset($table['l'][$k]) ) {
  21396. if ($c['R']) { $table['l'][$k] += $c['miw']/$c['colspan'] ; }
  21397. else { $table['l'][$k] += $c['s']/$c['colspan']; }
  21398. }
  21399. else {
  21400. if ($c['R']) { $table['l'][$k] = $c['miw']/$c['colspan'] ; }
  21401. else { $table['l'][$k] = $c['s']/$c['colspan']; }
  21402. }
  21403. $wis += $wc[$k]['miw'];
  21404. $was += $wc[$k]['maw'];
  21405. if (!isset($c['w'])) {
  21406. $list[] = $k;
  21407. $wisa += $wc[$k]['miw'];
  21408. $wasa += $wc[$k]['maw'];
  21409. }
  21410. }
  21411. if ($c['miw'] > $wis) {
  21412. if (!$wis) {
  21413. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] = $c['miw']/$c['colspan']; }
  21414. }
  21415. else if (!count($list)) {
  21416. $wi = $c['miw'] - $wis;
  21417. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wis)*$wi; }
  21418. }
  21419. else {
  21420. $wi = $c['miw'] - $wis;
  21421. foreach ($list as $k) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wisa)*$wi; }
  21422. }
  21423. }
  21424. if ($c['maw'] > $was) {
  21425. if (!$wis) {
  21426. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] = $c['maw']/$c['colspan']; }
  21427. }
  21428. else if (!count($list)) {
  21429. $wi = $c['maw'] - $was;
  21430. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] += ($wc[$k]['maw']/$was)*$wi; }
  21431. }
  21432. else {
  21433. $wi = $c['maw'] - $was;
  21434. foreach ($list as $k) { $wc[$k]['maw'] += ($wc[$k]['maw']/$wasa)*$wi; }
  21435. }
  21436. }
  21437. unset($c);
  21438. }
  21439. if ($this->cacheTables) { fclose($fh); }
  21440. $checkminwidth = 0;
  21441. $checkmaxwidth = 0;
  21442. $totallength = 0;
  21443. for( $i = 0 ; $i < $nc ; $i++ ) {
  21444. $checkminwidth += $table['wc'][$i]['miw'];
  21445. $checkmaxwidth += $table['wc'][$i]['maw'];
  21446. $totallength += $table['l'][$i];
  21447. }
  21448. if (!isset($table['w']) && $firstpass) {
  21449. $sumpc = 0;
  21450. $notset = 0;
  21451. for( $i = 0 ; $i < $nc ; $i++ ) {
  21452. if (isset($table['wc'][$i]['wpercent']) && $table['wc'][$i]['wpercent']) {
  21453. $sumpc += $table['wc'][$i]['wpercent'];
  21454. }
  21455. else { $notset++; }
  21456. }
  21457. // If sum of widths as % >= 100% and not all columns are set
  21458. // Set a nominal width of 1% for unset columns
  21459. if ($sumpc >= 100 && $notset) {
  21460. for( $i = 0 ; $i < $nc ; $i++ ) {
  21461. if ((!isset($table['wc'][$i]['wpercent']) || !$table['wc'][$i]['wpercent']) &&
  21462. (!isset($table['wc'][$i]['w']) || !$table['wc'][$i]['w'])) {
  21463. $table['wc'][$i]['wpercent'] = 1;
  21464. }
  21465. }
  21466. }
  21467. if ($sumpc) { // if any percents are set
  21468. $sumnonpc = (100 - $sumpc);
  21469. $sumpc = max($sumpc,100);
  21470. $miwleft = 0;
  21471. $miwleftcount = 0;
  21472. $miwsurplusnonpc = 0;
  21473. $maxcalcmiw = 0;
  21474. $mawleft = 0;
  21475. $mawleftcount = 0;
  21476. $mawsurplusnonpc = 0;
  21477. $maxcalcmaw = 0;
  21478. for( $i = 0 ; $i < $nc ; $i++ ) {
  21479. if (isset($table['wc'][$i]['wpercent'])) {
  21480. $maxcalcmiw = max($maxcalcmiw, ($table['wc'][$i]['miw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21481. $maxcalcmaw = max($maxcalcmaw, ($table['wc'][$i]['maw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21482. }
  21483. else {
  21484. $miwleft += $table['wc'][$i]['miw'];
  21485. $mawleft += $table['wc'][$i]['maw'];
  21486. if (!isset($table['wc'][$i]['w'])) { $miwleftcount++; $mawleftcount++; }
  21487. }
  21488. }
  21489. if ($miwleft && $sumnonpc > 0) { $miwnon = $miwleft * 100 / $sumnonpc; }
  21490. if ($mawleft && $sumnonpc > 0) { $mawnon = $mawleft * 100 / $sumnonpc; }
  21491. if (($miwnon > $checkminwidth || $maxcalcmiw > $checkminwidth) && $this->keep_table_proportions) {
  21492. if ($miwnon > $maxcalcmiw) {
  21493. $miwsurplusnonpc = round((($miwnon * $sumnonpc / 100) - $miwleft),3);
  21494. $checkminwidth = $miwnon;
  21495. }
  21496. else { $checkminwidth = $maxcalcmiw; }
  21497. for( $i = 0 ; $i < $nc ; $i++ ) {
  21498. if (isset($table['wc'][$i]['wpercent'])) {
  21499. $newmiw = $checkminwidth * $table['wc'][$i]['wpercent']/100;
  21500. if ($table['wc'][$i]['miw'] < $newmiw) {
  21501. $table['wc'][$i]['miw'] = $newmiw;
  21502. }
  21503. $table['wc'][$i]['w'] = 1;
  21504. }
  21505. else if ($miwsurplusnonpc && !$table['wc'][$i]['w']) {
  21506. $table['wc'][$i]['miw'] += $miwsurplusnonpc / $miwleftcount;
  21507. }
  21508. }
  21509. }
  21510. if (($mawnon > $checkmaxwidth || $maxcalcmaw > $checkmaxwidth )) {
  21511. if ($mawnon > $maxcalcmaw) {
  21512. $mawsurplusnonpc = round((($mawnon * $sumnonpc / 100) - $mawleft),3);
  21513. $checkmaxwidth = $mawnon;
  21514. }
  21515. else { $checkmaxwidth = $maxcalcmaw; }
  21516. for( $i = 0 ; $i < $nc ; $i++ ) {
  21517. if (isset($table['wc'][$i]['wpercent'])) {
  21518. $newmaw = $checkmaxwidth * $table['wc'][$i]['wpercent']/100;
  21519. if ($table['wc'][$i]['maw'] < $newmaw) {
  21520. $table['wc'][$i]['maw'] = $newmaw;
  21521. }
  21522. $table['wc'][$i]['w'] = 1;
  21523. }
  21524. else if ($mawsurplusnonpc && !$table['wc'][$i]['w']) {
  21525. $table['wc'][$i]['maw'] += $mawsurplusnonpc / $mawleftcount;
  21526. }
  21527. if ($table['wc'][$i]['maw'] < $table['wc'][$i]['miw']) { $table['wc'][$i]['maw'] = $table['wc'][$i]['miw']; }
  21528. }
  21529. }
  21530. if ($checkminwidth > $checkmaxwidth) { $checkmaxwidth = $checkminwidth; }
  21531. }
  21532. }
  21533. if (isset($table['wpercent']) && $table['wpercent']) {
  21534. $checkminwidth *= (100 / $table['wpercent']);
  21535. $checkmaxwidth *= (100 / $table['wpercent']);
  21536. }
  21537. $checkminwidth += $tblbw ;
  21538. $checkmaxwidth += $tblbw ;
  21539. // Table['miw'] set by percent in first pass may be larger than sum of column miw
  21540. if ((isset($table['miw']) && $checkminwidth > $table['miw']) || !isset($table['miw'])) { $table['miw'] = $checkminwidth; }
  21541. if ((isset($table['maw']) && $checkmaxwidth > $table['maw']) || !isset($table['maw'])) { $table['maw'] = $checkmaxwidth; }
  21542. $table['tl'] = $totallength ;
  21543. if (!$this->tableCJK) {
  21544. if ($this->table_rotate) {
  21545. $mxw = $this->tbrot_maxw;
  21546. }
  21547. else {
  21548. $mxw = $this->blk[$this->blklvl]['inner_width'];
  21549. }
  21550. if(!isset($table['overflow'])) { $table['overflow'] = null; }
  21551. if ($table['overflow']=='visible') {
  21552. return array(0,0);
  21553. }
  21554. else if ($table['overflow']=='hidden' && !$this->table_rotate && !$this->ColActive && $checkminwidth > $mxw) {
  21555. $table['w'] = $table['miw'];
  21556. return array(0,0);
  21557. }
  21558. else if ($table['overflow']=='wrap') { return array(0,0); }
  21559. if (isset($table['w']) && $table['w'] ) {
  21560. if ($table['w'] >= $checkminwidth && $table['w'] <= $mxw) { $table['maw'] = $mxw = $table['w']; }
  21561. else if ($table['w'] >= $checkminwidth && $table['w'] > $mxw && $this->keep_table_proportions) { $checkminwidth = $table['w']; }
  21562. else {
  21563. unset($table['w']);
  21564. }
  21565. }
  21566. $ratio = $checkminwidth/$mxw;
  21567. if ($checkminwidth > $mxw) { return array(($ratio +0.001),$checkminwidth); } // 0.001 to allow for rounded numbers when resizing
  21568. }
  21569. unset($cs);
  21570. return array(0,0);
  21571. }
  21572. function _tableWidth(&$table){
  21573. $widthcols = &$table['wc'];
  21574. $numcols = $table['nc'];
  21575. $tablewidth = 0;
  21576. if ($table['borders_separate']) {
  21577. $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'];
  21578. }
  21579. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  21580. if ($table['level']>1 && isset($table['w'])) {
  21581. if (isset($table['wpercent']) && $table['wpercent']) {
  21582. $table['w'] = $temppgwidth = (($table['w']-$tblbw) * $table['wpercent'] / 100) + $tblbw ;
  21583. }
  21584. else {
  21585. $temppgwidth = $table['w'] ;
  21586. }
  21587. }
  21588. else if ($this->table_rotate) {
  21589. $temppgwidth = $this->tbrot_maxw;
  21590. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  21591. // then allow for this
  21592. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  21593. if ($enddiv/$temppgwidth <0.05) { $temppgwidth -= $enddiv; }
  21594. }
  21595. else {
  21596. if (isset($table['w']) && $table['w']< $this->blk[$this->blklvl]['inner_width']) {
  21597. $notfullwidth = 1;
  21598. $temppgwidth = $table['w'] ;
  21599. }
  21600. else if ($table['overflow']=='visible' && $table['level'] ==1) {
  21601. $temppgwidth = null;
  21602. }
  21603. else if ($table['overflow']=='hidden' && !$this->ColActive && isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width'] && $table['w']==$table['miw']) {
  21604. //$temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  21605. $temppgwidth = $table['w'] ;
  21606. }
  21607. else { $temppgwidth = $this->blk[$this->blklvl]['inner_width']; }
  21608. }
  21609. $totaltextlength = 0; // Added - to sum $table['l'][colno]
  21610. $totalatextlength = 0; // Added - to sum $table['l'][colno] for those columns where width not set
  21611. $percentages_set = 0;
  21612. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  21613. if (isset($widthcols[$i]['wpercent'])) { $tablewidth += $widthcols[$i]['maw']; $percentages_set = 1; }
  21614. else if (isset($widthcols[$i]['w'])) { $tablewidth += $widthcols[$i]['miw']; }
  21615. else { $tablewidth += $widthcols[$i]['maw']; }
  21616. $totaltextlength += $table['l'][$i];
  21617. }
  21618. if (!$totaltextlength) { $totaltextlength =1; }
  21619. $tablewidth += $tblbw; // Outer half of table borders
  21620. if ($tablewidth > $temppgwidth) {
  21621. $table['w'] = $temppgwidth;
  21622. }
  21623. // if any widths set as percentages and max width fits < page width
  21624. else if ($tablewidth < $temppgwidth && !isset($table['w']) && $percentages_set) {
  21625. $table['w'] = $table['maw'];
  21626. }
  21627. // if table width is set and is > allowed width
  21628. if (isset($table['w']) && $table['w'] > $temppgwidth) { $table['w'] = $temppgwidth; }
  21629. // IF the table width is now set - Need to distribute columns widths
  21630. if (isset($table['w'])) {
  21631. $wis = $wisa = 0;
  21632. $list = array();
  21633. $notsetlist = array();
  21634. for( $i = 0 ; $i < $numcols ; $i++ ) {
  21635. $wis += $widthcols[$i]['miw'];
  21636. if (!isset($widthcols[$i]['w']) || ($widthcols[$i]['w'] && $table['w'] > $temppgwidth && !$this->keep_table_proportions && !$notfullwidth )){
  21637. $list[] = $i;
  21638. $wisa += $widthcols[$i]['miw'];
  21639. $totalatextlength += $table['l'][$i];
  21640. }
  21641. }
  21642. if (!$totalatextlength) { $totalatextlength =1; }
  21643. // Allocate spare (more than col's minimum width) across the cols according to their approx total text length
  21644. // Do it by setting minimum width here
  21645. if ($table['w'] > $wis + $tblbw) {
  21646. // First set any cell widths set as percentages
  21647. if ($table['w'] < $temppgwidth || $this->keep_table_proportions) {
  21648. for($k=0;$k<$numcols;$k++) {
  21649. if (isset($widthcols[$k]['wpercent'])) {
  21650. $curr = $widthcols[$k]['miw'];
  21651. $widthcols[$k]['miw'] = ($table['w']-$tblbw) * $widthcols[$k]['wpercent']/100;
  21652. $wis += $widthcols[$k]['miw'] - $curr;
  21653. $wisa += $widthcols[$k]['miw'] - $curr;
  21654. }
  21655. }
  21656. }
  21657. // Now allocate surplus up to maximum width of each column
  21658. $surplus = 0; $ttl = 0; // number of surplus columns
  21659. if (!count($list)) {
  21660. $wi = ($table['w']-($wis + $tblbw)); // i.e. extra space to distribute
  21661. for($k=0;$k<$numcols;$k++) {
  21662. $spareratio = ($table['l'][$k] / $totaltextlength); // gives ratio to divide up free space
  21663. // Don't allocate more than Maximum required width - save rest in surplus
  21664. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  21665. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  21666. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  21667. }
  21668. else {
  21669. $notsetlist[] = $k;
  21670. $ttl += $table['l'][$k];
  21671. $widthcols[$k]['miw'] += ($wi * $spareratio);
  21672. }
  21673. }
  21674. }
  21675. else {
  21676. $wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra space to distribute
  21677. foreach ($list as $k) {
  21678. $spareratio = ($table['l'][$k] / $totalatextlength); // gives ratio to divide up free space
  21679. // Don't allocate more than Maximum required width - save rest in surplus
  21680. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  21681. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  21682. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  21683. }
  21684. else {
  21685. $notsetlist[] = $k;
  21686. $ttl += $table['l'][$k];
  21687. $widthcols[$k]['miw'] += ($wi * $spareratio);
  21688. }
  21689. }
  21690. }
  21691. // If surplus still left over apportion it across columns
  21692. if ($surplus) {
  21693. // if some are set only add to remaining - otherwise add to all of them
  21694. if (count($notsetlist) && count($notsetlist) < $numcols) {
  21695. foreach ($notsetlist AS $i) {
  21696. if ($ttl) $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl ;
  21697. }
  21698. }
  21699. // If some widths are defined, and others have been added up to their maxmum
  21700. else if (count($list) && count($list) < $numcols) {
  21701. foreach ($list AS $i) {
  21702. $widthcols[$i]['miw'] += $surplus / count($list) ;
  21703. }
  21704. }
  21705. else if ($numcols) { // If all columns
  21706. $ttl = array_sum($table['l']);
  21707. for ($i=0;$i<$numcols;$i++) {
  21708. $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl;
  21709. }
  21710. }
  21711. }
  21712. }
  21713. // This sets the columns all to minimum width (which has been increased above if appropriate)
  21714. for ($i=0;$i<$numcols;$i++) {
  21715. $widthcols[$i] = $widthcols[$i]['miw'];
  21716. }
  21717. // TABLE NOT WIDE ENOUGH EVEN FOR MINIMUM CONTENT WIDTH
  21718. // If sum of column widths set are too wide for table
  21719. $checktablewidth = 0;
  21720. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  21721. $checktablewidth += $widthcols[$i];
  21722. }
  21723. if ($checktablewidth > ($temppgwidth + 0.001 - $tblbw)) {
  21724. $usedup = 0; $numleft = 0;
  21725. for ($i=0;$i<$numcols;$i++) {
  21726. if ((isset($widthcols[$i]) && $widthcols[$i] > (($temppgwidth - $tblbw) / $numcols)) && (!isset($widthcols[$i]['w']))) {
  21727. $numleft++;
  21728. unset($widthcols[$i]);
  21729. }
  21730. else { $usedup += $widthcols[$i]; }
  21731. }
  21732. for ($i=0;$i<$numcols;$i++) {
  21733. if (!isset($widthcols[$i]) || !$widthcols[$i]) {
  21734. $widthcols[$i] = ((($temppgwidth - $tblbw) - $usedup)/ ($numleft));
  21735. }
  21736. }
  21737. }
  21738. }
  21739. else { //table has no width defined
  21740. $table['w'] = $tablewidth;
  21741. for ( $i = 0 ; $i < $numcols ; $i++) {
  21742. if (isset($widthcols[$i]['wpercent']) && $this->keep_table_proportions) { $colwidth = $widthcols[$i]['maw']; }
  21743. else if (isset($widthcols[$i]['w'])) { $colwidth = $widthcols[$i]['miw']; }
  21744. else { $colwidth = $widthcols[$i]['maw']; }
  21745. unset($widthcols[$i]);
  21746. $widthcols[$i] = $colwidth;
  21747. }
  21748. }
  21749. if ($table['overflow']=='visible' && $table['level'] ==1) {
  21750. if ($tablewidth > $this->blk[$this->blklvl]['inner_width']) {
  21751. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  21752. else { $fh = null; }
  21753. for ($j = 0 ; $j < $numcols; $j++) { //columns
  21754. for ($i = 0 ; $i < $table['nr']; $i++) { //rows
  21755. if (isset($table['cells'][$i][$j]) && $table['cells'][$i][$j]) {
  21756. if ($this->cacheTables) {
  21757. $cc = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21758. $colspan = $cc['colspan'];
  21759. }
  21760. else
  21761. $colspan = $table['cells'][$i][$j]['colspan'];
  21762. if ($colspan > 1) {
  21763. $w = 0;
  21764. for ($c = $j; $c < ($j + $colspan); $c++) {
  21765. $w += $widthcols[$c];
  21766. }
  21767. if ($w > $this->blk[$this->blklvl]['inner_width']) {
  21768. $diff = $w - ($this->blk[$this->blklvl]['inner_width'] - $tblbw);
  21769. for ($c = $j; $c < ($j + $colspan); $c++) {
  21770. $widthcols[$c] -= $diff * ($widthcols[$c]/$w);
  21771. }
  21772. $table['w'] -= $diff;
  21773. $table['csp'][$j] = $w - $diff;
  21774. }
  21775. }
  21776. }
  21777. }
  21778. }
  21779. if ($this->cacheTables) { fclose($fh); }
  21780. }
  21781. $pgNo = 0;
  21782. $currWc = 0;
  21783. for ($i = 0 ; $i < $numcols; $i++) { //columns
  21784. if (isset($table['csp'][$i])) {
  21785. $w = $table['csp'][$i];
  21786. unset($table['csp'][$i]);
  21787. }
  21788. else { $w = $widthcols[$i]; }
  21789. if (($currWc + $w + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  21790. $pgNo++;
  21791. $currWc = $widthcols[$i] ;
  21792. }
  21793. else { $currWc += $widthcols[$i] ; }
  21794. $table['colPg'][$i] = $pgNo;
  21795. }
  21796. }
  21797. }
  21798. function _tableHeight(&$table){
  21799. $level = $table['level'];
  21800. $levelid = $table['levelid'];
  21801. $cells = &$table['cells'];
  21802. $numcols = $table['nc'];
  21803. $numrows = $table['nr'];
  21804. $listspan = array();
  21805. $checkmaxheight = 0;
  21806. $headerrowheight = 0;
  21807. $checkmaxheightplus = 0;
  21808. $headerrowheightplus = 0;
  21809. $firstrowheight = 0;
  21810. $footerrowheight = 0;
  21811. $footerrowheightplus = 0;
  21812. if ($this->table_rotate) {
  21813. $temppgheight = $this->tbrot_maxh;
  21814. $remainingpage = $this->tbrot_maxh;
  21815. }
  21816. else {
  21817. $temppgheight = ($this->h - $this->bMargin - $this->tMargin) - $this->kwt_height;
  21818. $remainingpage = ($this->h - $this->bMargin - $this->y) - $this->kwt_height;
  21819. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  21820. // then allow for this
  21821. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $table['margin']['B'];
  21822. if ($remainingpage > $enddiv && $enddiv/$remainingpage <0.05) { $remainingpage -= $enddiv; }
  21823. else if ($remainingpage == 0) { $remainingpage = 0.001; }
  21824. if ($temppgheight > $enddiv && $enddiv/$temppgheight <0.05) { $temppgheight -= $enddiv; }
  21825. else if ($temppgheight == 0) { $temppgheight = 0.001; }
  21826. }
  21827. if ($remainingpage < 0) { $remainingpage = 0.001; } // mPDF 5.6.64
  21828. if ($temppgheight < 0) { $temppgheight = 0.001; } // mPDF 5.6.64
  21829. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  21830. else { $fh = null; }
  21831. for( $i = 0 ; $i < $numrows ; $i++ ) { //rows
  21832. $heightrow = &$table['hr'][$i];
  21833. for( $j = 0 ; $j < $numcols ; $j++ ) { //columns
  21834. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  21835. if ($this->cacheTables) {
  21836. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21837. }
  21838. else
  21839. $c = &$cells[$i][$j];
  21840. if ($this->simpleTables){
  21841. if ($table['borders_separate']) { // NB twice border width
  21842. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w']) + ($c['padding']['L']+$c['padding']['R'])+$table['border_spacing_H'];
  21843. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w']) + ($c['padding']['T']+$c['padding']['B'])+$table['border_spacing_V'];
  21844. }
  21845. else {
  21846. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w'])/2 + ($c['padding']['L']+$c['padding']['R']);
  21847. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w'])/2 + ($c['padding']['T']+$c['padding']['B']);
  21848. }
  21849. }
  21850. else {
  21851. if ($this->packTableData) {
  21852. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  21853. }
  21854. else {
  21855. $bt = $c['border_details']['T']['w'];
  21856. $bb = $c['border_details']['B']['w'];
  21857. $br = $c['border_details']['R']['w'];
  21858. $bl = $c['border_details']['L']['w'];
  21859. }
  21860. if ($table['borders_separate']) { // NB twice border width
  21861. $extraWLR = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21862. $extrh = $bt + $bb + $c['padding']['T'] + $c['padding']['B'] + $table['border_spacing_V'];
  21863. }
  21864. else {
  21865. $extraWLR = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  21866. $extrh = $bt/2 + $bb/2 + $c['padding']['T']+$c['padding']['B'];
  21867. }
  21868. }
  21869. if ($table['overflow']=='visible' && $level==1)
  21870. list($x,$cw) = $this->_splitTableGetWidth($table, $i,$j, $fh);
  21871. else
  21872. list($x,$cw) = $this->_tableGetWidth($table, $i,$j, $fh);
  21873. // Get CELL HEIGHT
  21874. // ++ extra parameter forces wrap to break word
  21875. if ($c['R'] && isset($c['textbuffer'])) { // mPDF 5.4.01
  21876. $str = '';
  21877. foreach($c['textbuffer'] AS $t) { $str .= $t[0].' '; }
  21878. $str = trim($str);
  21879. $s_fs = $this->FontSizePt;
  21880. $s_f = $this->FontFamily;
  21881. $s_st = $this->FontStyle;
  21882. $this->SetFont($c['textbuffer'][0][4],$c['textbuffer'][0][2],$c['textbuffer'][0][11] / $this->shrin_k,true,true);
  21883. $tempch = $this->GetStringWidth($str);
  21884. if ($c['R'] >= 45 && $c['R'] < 90) {
  21885. $tempch = ((sin(deg2rad($c['R']))) * $tempch ) + ((sin(deg2rad($c['R']))) * (($c['textbuffer'][0][11]/_MPDFK) / $this->shrin_k));
  21886. }
  21887. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  21888. $ch = ($tempch ) + $extrh ;
  21889. }
  21890. else {
  21891. if (isset($c['textbuffer'])) {
  21892. $tempch = $this->TableWordWrap(($cw-$extraWLR),1,$c['textbuffer'], $c['dfs']);
  21893. }
  21894. else { $tempch = 0; }
  21895. // Added cellpadding top and bottom. (Lineheight already adjusted to table_lineheight)
  21896. $ch = $tempch + $extrh ;
  21897. }
  21898. //If height is defined and it is bigger than calculated $ch then update values
  21899. if (isset($c['h']) && $c['h'] > $ch) {
  21900. $c['mih'] = $ch; //in order to keep valign working
  21901. $ch = $c['h'];
  21902. }
  21903. else $c['mih'] = $ch;
  21904. if ($this->cacheTables) {
  21905. $this->_cacheUpdateMtx($c, $fh, $table['cells'][$i][$j], 'mih');
  21906. }
  21907. if (isset($c['rowspan'])) $listspan[] = array($i,$j);
  21908. elseif ($heightrow < $ch) $heightrow = $ch;
  21909. // this is the extra used in _tableWrite to determine whether to trigger a page change
  21910. if ($table['borders_separate']) {
  21911. if ($i == ($numrows-1) || (isset($c['rowspan']) && ($i+$c['rowspan']) == ($numrows)) ) {
  21912. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  21913. }
  21914. else {
  21915. $extra = $table['border_spacing_V']/2;
  21916. }
  21917. }
  21918. else {
  21919. if (!$this->simpleTables){
  21920. $extra = $bb/2;
  21921. }
  21922. else if ($this->simpleTables){
  21923. $extra = $table['simple']['border_details']['B']['w'] /2;
  21924. }
  21925. }
  21926. if (isset($table['is_thead'][$i]) && $table['is_thead'][$i]) {
  21927. if ($j==0) {
  21928. $headerrowheight += $ch;
  21929. $headerrowheightplus += $ch+$extra;
  21930. }
  21931. }
  21932. else if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) {
  21933. if ($j==0) {
  21934. $footerrowheight += $ch;
  21935. $footerrowheightplus += $ch+$extra;
  21936. }
  21937. }
  21938. else {
  21939. $checkmaxheight = max($checkmaxheight,$ch);
  21940. $checkmaxheightplus = max($checkmaxheightplus,$ch+$extra);
  21941. }
  21942. if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($ch,$firstrowheight); }
  21943. unset($c);
  21944. }
  21945. }//end of columns
  21946. }//end of rows
  21947. $heightrow = &$table['hr'];
  21948. foreach ($listspan as $span) {
  21949. list($i,$j) = $span;
  21950. if ($this->cacheTables) {
  21951. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21952. }
  21953. else
  21954. $c = &$cells[$i][$j];
  21955. $lr = $i + $c['rowspan'];
  21956. if ($lr > $numrows) $lr = $numrows;
  21957. $hs = $hsa = 0;
  21958. $list = array();
  21959. for($k=$i;$k<$lr;$k++) {
  21960. $hs += $heightrow[$k];
  21961. if (!isset($c['h'])) {
  21962. $list[] = $k;
  21963. $hsa += $heightrow[$k];
  21964. }
  21965. }
  21966. if ($table['borders_separate']) {
  21967. if ($i == ($numrows-1) || ($i+$c['rowspan']) == ($numrows) ) {
  21968. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  21969. }
  21970. else {
  21971. $extra = $table['border_spacing_V']/2;
  21972. }
  21973. }
  21974. else {
  21975. if (!$this->simpleTables){
  21976. if ($this->packTableData) {
  21977. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  21978. }
  21979. else {
  21980. $bb = $c['border_details']['B']['w'];
  21981. }
  21982. $extra = $bb/2;
  21983. }
  21984. else if ($this->simpleTables){
  21985. $extra = $table['simple']['border_details']['B']['w'] /2;
  21986. }
  21987. }
  21988. if (!empty($table['is_thead'][$i])) {
  21989. $headerrowheight = max($headerrowheight,$hs);
  21990. $headerrowheightplus = max($headerrowheightplus,$hs+$extra);
  21991. }
  21992. else if (!empty($table['is_tfoot'][$i])) {
  21993. $footerrowheight = max($footerrowheight,$hs);
  21994. $footerrowheightplus = max($footerrowheightplus,$hs+$extra);
  21995. }
  21996. else {
  21997. $checkmaxheight = max($checkmaxheight,$hs);
  21998. $checkmaxheightplus = max($checkmaxheightplus,$hs+$extra);
  21999. }
  22000. if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($hs,$firstrowheight); }
  22001. if ($c['mih'] > $hs) {
  22002. if (!$hs) {
  22003. for($k=$i;$k<$lr;$k++) $heightrow[$k] = $c['mih']/$c['rowspan'];
  22004. }
  22005. elseif (!count($list)) {
  22006. $hi = $c['mih'] - $hs;
  22007. for($k=$i;$k<$lr;$k++) $heightrow[$k] += ($heightrow[$k]/$hs)*$hi;
  22008. }
  22009. else {
  22010. $hi = $c['mih'] - $hsa;
  22011. foreach ($list as $k) $heightrow[$k] += ($heightrow[$k]/$hsa)*$hi;
  22012. }
  22013. }
  22014. unset($c);
  22015. // If rowspans overlap so that one or more rows do not have a height set...
  22016. // i.e. for one or more rows, the only cells (explicit) in that row have rowspan>1
  22017. // so heightrow is still == 0
  22018. if ($heightrow[$i]==0) {
  22019. // Get row extent to analyse above and below
  22020. $top = $i;
  22021. foreach ($listspan as $checkspan) {
  22022. list($cki,$ckj) = $checkspan;
  22023. if ($this->cacheTables) {
  22024. $c = $this->_uncacheCell($table['cells'][$cki][$ckj], '', $fh);
  22025. }
  22026. else
  22027. $c = &$cells[$cki][$ckj];
  22028. if (isset($c['rowspan']) && $c['rowspan']>1) {
  22029. if (($cki + $c['rowspan']-1) >= $i) { $top = min($top, $cki); }
  22030. }
  22031. }
  22032. $bottom = $i + $c['rowspan']-1;
  22033. // Check for overconstrained conditions
  22034. for ($k=$top; $k<=$bottom; $k++) {
  22035. // if ['hr'] for any of the others is also 0, then abort (too complicated)
  22036. if ($k != $i && $heightrow[$k]==0) { break(1); }
  22037. // check again that top and bottom are not crossed by rowspans - or abort (too complicated)
  22038. if ($k==$top) {
  22039. // ???? take account of colspan as well???
  22040. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22041. if (!isset($cells[$k][$m]) || $cells[$k][$m]==0) {
  22042. break(2);
  22043. }
  22044. }
  22045. }
  22046. else if ($k==$bottom) {
  22047. // ???? take account of colspan as well???
  22048. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22049. if ($this->cacheTables) {
  22050. $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh);
  22051. }
  22052. else
  22053. $c = &$cells[$k][$m];
  22054. if (isset($c['rowspan']) && $c['rowspan']>1) {
  22055. break(2);
  22056. }
  22057. }
  22058. }
  22059. }
  22060. // By columns add up col height using ['h'] if set or ['mih'] if not
  22061. // Intentionally do not substract border-spacing
  22062. $colH = array();
  22063. $extH = 0;
  22064. $newhr = array();
  22065. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22066. for ($k=$top; $k<=$bottom; $k++) {
  22067. if (isset($cells[$k][$m]) && $cells[$k][$m]!=0) {
  22068. if ($this->cacheTables) {
  22069. $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh);
  22070. }
  22071. else
  22072. $c = &$cells[$k][$m];
  22073. if (isset($c['h']) && $c['h']) {
  22074. $useh = $c['h'];
  22075. }
  22076. // ???? take account of colspan as well???
  22077. else {
  22078. $useh = $c['mih'];
  22079. }
  22080. $colH[$m] += $useh;
  22081. if (!isset($c['rowspan']) || $c['rowspan']<2) { $newhr[$k] = max($newhr[$k], $useh); }
  22082. }
  22083. }
  22084. $extH = max($tabH, $colH[$m]);
  22085. }
  22086. $newhr[$i] = $extH - array_sum($newhr);
  22087. for ($k=$top; $k<=$bottom; $k++) { $heightrow[$k] = $newhr[$k]; }
  22088. }
  22089. unset($c);
  22090. }
  22091. $table['h'] = array_sum($heightrow);
  22092. unset($heightrow);
  22093. if ($this->cacheTables) { fclose($fh); }
  22094. if ($table['borders_separate']) {
  22095. $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'];
  22096. }
  22097. else {
  22098. $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['max_cell_border_width']['T']/2 + $table['max_cell_border_width']['B']/2;
  22099. }
  22100. $maxrowheight = $checkmaxheightplus + $headerrowheightplus + $footerrowheightplus;
  22101. $maxfirstrowheight = $firstrowheight + $headerrowheightplus + $footerrowheightplus; // includes thead, 1st row and tfoot
  22102. return array($table['h'],$maxrowheight,$temppgheight,$remainingpage,$maxfirstrowheight);
  22103. }
  22104. function _tableGetWidth(&$table, $i,$j, $fh){
  22105. if ($this->cacheTables) {
  22106. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22107. }
  22108. else
  22109. $cell = &$table['cells'][$i][$j];
  22110. if ($cell) {
  22111. if (isset($cell['x0'])) { return array($cell['x0'], $cell['w0']); }
  22112. $x = 0;
  22113. $widthcols = &$table['wc'];
  22114. for( $k = 0 ; $k < $j ; $k++ ) $x += $widthcols[$k];
  22115. $w = $widthcols[$j];
  22116. if (isset($cell['colspan'])) {
  22117. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) $w += $widthcols[$k];
  22118. }
  22119. $cell['x0'] = $x;
  22120. $cell['w0'] = $w;
  22121. if ($this->cacheTables) {
  22122. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0');
  22123. }
  22124. return array($x, $w);
  22125. }
  22126. return array(0,0);
  22127. }
  22128. function _splitTableGetWidth(&$table, $i,$j, $fh){
  22129. if ($this->cacheTables) {
  22130. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22131. }
  22132. else
  22133. $cell = &$table['cells'][$i][$j];
  22134. if ($cell) {
  22135. if (isset($cell['x0'])) return array($cell['x0'], $cell['w0']);
  22136. $x = 0;
  22137. $widthcols = &$table['wc'];
  22138. $pg = $table['colPg'][$j];
  22139. for( $k = 0 ; $k < $j ; $k++ ) {
  22140. if ($table['colPg'][$k]==$pg) $x += $widthcols[$k];
  22141. }
  22142. $w = $widthcols[$j];
  22143. if (isset($cell['colspan'])) {
  22144. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) if ($table['colPg'][$k]==$pg) $w += $widthcols[$k];
  22145. }
  22146. $cell['x0'] = $x;
  22147. $cell['w0'] = $w;
  22148. if ($this->cacheTables) {
  22149. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0');
  22150. }
  22151. return array($x, $w);
  22152. }
  22153. return array(0,0);
  22154. }
  22155. function _tableGetHeight(&$table, $i,$j, $fh){
  22156. if ($this->cacheTables) {
  22157. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22158. }
  22159. else
  22160. $cell = &$table['cells'][$i][$j];
  22161. if ($cell){
  22162. if (isset($cell['y0'])) return array($cell['y0'], $cell['h0']);
  22163. $y = 0;
  22164. $heightrow = &$table['hr'];
  22165. for ($k=0;$k<$i;$k++) $y += $heightrow[$k];
  22166. $h = $heightrow[$i];
  22167. if (isset($cell['rowspan'])){
  22168. for ($k=$i+$cell['rowspan']-1;$k>$i;$k--)
  22169. $h += $heightrow[$k];
  22170. }
  22171. $cell['y0'] = $y;
  22172. $cell['h0'] = $h;
  22173. if ($this->cacheTables) {
  22174. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'y0');
  22175. }
  22176. return array($y, $h);
  22177. }
  22178. return array(0,0);
  22179. }
  22180. function _tableGetMaxRowHeight($table, $row, $fh) {
  22181. if ($row==$table['nc']-1) { return $table['hr'][$row]; }
  22182. $maxrowheight = $table['hr'][$row];
  22183. for ($i=$row+1;$i<$table['nr'];$i++) {
  22184. $cellsset = 0;
  22185. for ($j=0;$j<$table['nc'];$j++) {
  22186. if ($this->cacheTables) {
  22187. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22188. if ($cell) {
  22189. if (isset($cell['colspan'])) { $cellsset += $cell['colspan']; }
  22190. else $cellsset += 1;
  22191. }
  22192. }
  22193. else {
  22194. if ($table['cells'][$i][$j]) {
  22195. if (isset($table['cells'][$i][$j]['colspan'])) { $cellsset += $table['cells'][$i][$j]['colspan']; }
  22196. else $cellsset += 1;
  22197. }
  22198. }
  22199. }
  22200. if ($cellsset == $table['nc']) { return $maxrowheight; }
  22201. else { $maxrowheight += $table['hr'][$i]; }
  22202. }
  22203. return $maxrowheight;
  22204. }
  22205. // CHANGED TO ALLOW TABLE BORDER TO BE SPECIFIED CORRECTLY - added border_details
  22206. function _tableRect($x, $y, $w, $h, $bord=-1, $details=array(), $buffer=false, $bSeparate=false, $cort='cell', $tablecorner='', $bsv=0, $bsh=0) {
  22207. $cellBorderOverlay = array();
  22208. if ($bord==-1) { $this->Rect($x, $y, $w, $h); }
  22209. else if ($this->simpleTables && ($cort=='cell')) {
  22210. $this->SetLineWidth($details['L']['w']);
  22211. if ($details['L']['c']) {
  22212. $this->SetDColor($details['L']['c']);
  22213. }
  22214. else { $this->SetDColor($this->ConvertColor(0)); }
  22215. $this->SetLineJoin(0);
  22216. $this->Rect($x, $y, $w, $h);
  22217. }
  22218. else if ($bord){
  22219. if (!$bSeparate && $buffer) {
  22220. $priority = 'LRTB';
  22221. for($p=0;$p<strlen($priority);$p++) {
  22222. $side = $priority[$p];
  22223. $details['p'] = $side ;
  22224. $dom = 0;
  22225. if (isset($details[$side]['w'])) { $dom += ($details[$side]['w'] * 100000); }
  22226. if (isset($details[$side]['style'])) { $dom += (array_search($details[$side]['style'],$this->borderstyles)*100) ; }
  22227. if (isset($details[$side]['dom'])) { $dom += ($details[$side]['dom']*10); }
  22228. // Precedence to darker colours at joins
  22229. $coldom = 0;
  22230. if (isset($details[$side]['c']) && is_array($details[$side]['c'])) {
  22231. if ($details[$side]['c']{0}==3) { // RGB
  22232. $coldom = 10-(((ord($details[$side]['c']{1})*1.00)+(ord($details[$side]['c']{2})*1.00)+(ord($details[$side]['c']{3})*1.00))/76.5);
  22233. }
  22234. } // 10 black - 0 white
  22235. if ($coldom) { $dom += $coldom; }
  22236. // Lastly precedence to RIGHT and BOTTOM cells at joins
  22237. if (isset($details['cellposdom'])) { $dom += $details['cellposdom']; }
  22238. $save = false;
  22239. if ($side == 'T' && $this->issetBorder($bord, _BORDER_TOP)) { $cbord = _BORDER_TOP; $save = true; }
  22240. else if ($side == 'L' && $this->issetBorder($bord, _BORDER_LEFT)) { $cbord = _BORDER_LEFT; $save = true; }
  22241. else if ($side == 'R' && $this->issetBorder($bord, _BORDER_RIGHT)) { $cbord = _BORDER_RIGHT; $save = true; }
  22242. else if ($side == 'B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { $cbord = _BORDER_BOTTOM; $save = true; }
  22243. if ($save) {
  22244. $this->cellBorderBuffer[] = pack("A16nCnda6A10d14",
  22245. str_pad(sprintf("%08.7f", $dom),16,"0",STR_PAD_LEFT),
  22246. $cbord,
  22247. ord($side),
  22248. $details[$side]['s'],
  22249. $details[$side]['w'],
  22250. $details[$side]['c'],
  22251. $details[$side]['style'],
  22252. $x, $y, $w, $h,
  22253. $details['mbw']['BL'],
  22254. $details['mbw']['BR'],
  22255. $details['mbw']['RT'],
  22256. $details['mbw']['RB'],
  22257. $details['mbw']['TL'],
  22258. $details['mbw']['TR'],
  22259. $details['mbw']['LT'],
  22260. $details['mbw']['LB'],
  22261. $details['cellposdom'],
  22262. 0
  22263. );
  22264. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset' || $details[$side]['style'] == 'double' ) {
  22265. $details[$side]['overlay'] = true;
  22266. $this->cellBorderBuffer[] = pack("A16nCnda6A10d14",
  22267. str_pad(sprintf("%08.7f", ($dom+4)),16,"0",STR_PAD_LEFT),
  22268. $cbord,
  22269. ord($side),
  22270. $details[$side]['s'],
  22271. $details[$side]['w'],
  22272. $details[$side]['c'],
  22273. $details[$side]['style'],
  22274. $x, $y, $w, $h,
  22275. $details['mbw']['BL'],
  22276. $details['mbw']['BR'],
  22277. $details['mbw']['RT'],
  22278. $details['mbw']['RB'],
  22279. $details['mbw']['TL'],
  22280. $details['mbw']['TR'],
  22281. $details['mbw']['LT'],
  22282. $details['mbw']['LB'],
  22283. $details['cellposdom'],
  22284. 1
  22285. );
  22286. }
  22287. }
  22288. }
  22289. return;
  22290. }
  22291. if (isset($details['p']) && strlen($details['p'])>1) { $priority = $details['p']; }
  22292. else { $priority='LTRB'; }
  22293. $Tw = 0;
  22294. $Rw = 0;
  22295. $Bw = 0;
  22296. $Lw = 0;
  22297. if (isset($details['T']['w'])) { $Tw = $details['T']['w']; }
  22298. if (isset($details['R']['w'])) { $Rw = $details['R']['w']; }
  22299. if (isset($details['B']['w'])) { $Bw = $details['B']['w']; }
  22300. if (isset($details['L']['w'])) { $Lw = $details['L']['w']; }
  22301. $x2 = $x + $w; $y2 = $y + $h;
  22302. $oldlinewidth = $this->LineWidth;
  22303. for($p=0;$p<strlen($priority);$p++) {
  22304. $side = $priority[$p];
  22305. $xadj = 0;
  22306. $xadj2 = 0;
  22307. $yadj = 0;
  22308. $yadj2 = 0;
  22309. $print = false;
  22310. if ($Tw && $side=='T' && $this->issetBorder($bord, _BORDER_TOP)) { // TOP
  22311. $ly1 = $y;
  22312. $ly2 = $y;
  22313. $lx1 = $x;
  22314. $lx2 = $x2;
  22315. $this->SetLineWidth($Tw);
  22316. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22317. if ($Tw > $Lw) $xadj = ($Tw - $Lw)/2;
  22318. if ($Tw < $Lw) $xadj = ($Tw + $Lw)/2;
  22319. }
  22320. else { $xadj = $Tw/2 - $bsh/2; }
  22321. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22322. if ($Tw > $Rw) $xadj2 = ($Tw - $Rw)/2;
  22323. if ($Tw < $Rw) $xadj2 = ($Tw + $Rw)/2;
  22324. }
  22325. else { $xadj2 = $Tw/2 - $bsh/2; }
  22326. if (!$bSeparate && $details['mbw']['TL']) {
  22327. $xadj = ($Tw - $details['mbw']['TL'])/2 ;
  22328. }
  22329. if (!$bSeparate && $details['mbw']['TR']) {
  22330. $xadj2 = ($Tw - $details['mbw']['TR'])/2;
  22331. }
  22332. $print = true;
  22333. }
  22334. if ($Lw && $side=='L' && $this->issetBorder($bord, _BORDER_LEFT)) { // LEFT
  22335. $ly1 = $y;
  22336. $ly2 = $y2;
  22337. $lx1 = $x;
  22338. $lx2 = $x;
  22339. $this->SetLineWidth($Lw);
  22340. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22341. if ($Lw > $Tw) $yadj = ($Lw - $Tw)/2;
  22342. if ($Lw < $Tw) $yadj = ($Lw + $Tw)/2;
  22343. }
  22344. else { $yadj = $Lw/2 - $bsv/2; }
  22345. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22346. if ($Lw > $Bw) $yadj2 = ($Lw - $Bw)/2;
  22347. if ($Lw < $Bw) $yadj2 = ($Lw + $Bw)/2;
  22348. }
  22349. else { $yadj2 = $Lw/2 - $bsv/2; }
  22350. if (!$bSeparate && $details['mbw']['LT']) {
  22351. $yadj = ($Lw - $details['mbw']['LT'])/2;
  22352. }
  22353. if (!$bSeparate && $details['mbw']['LB']) {
  22354. $yadj2 = ($Lw - $details['mbw']['LB'])/2;
  22355. }
  22356. $print = true;
  22357. }
  22358. if ($Rw && $side=='R' && $this->issetBorder($bord, _BORDER_RIGHT)) { // RIGHT
  22359. $ly1 = $y;
  22360. $ly2 = $y2;
  22361. $lx1 = $x2;
  22362. $lx2 = $x2;
  22363. $this->SetLineWidth($Rw);
  22364. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22365. if ($Rw < $Tw) $yadj = ($Rw + $Tw)/2;
  22366. if ($Rw > $Tw) $yadj = ($Rw - $Tw)/2;
  22367. }
  22368. else { $yadj = $Rw/2 - $bsv/2; }
  22369. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22370. if ($Rw > $Bw) $yadj2 = ($Rw - $Bw)/2;
  22371. if ($Rw < $Bw) $yadj2 = ($Rw + $Bw)/2;
  22372. }
  22373. else { $yadj2 = $Rw/2 - $bsv/2; }
  22374. if (!$bSeparate && $details['mbw']['RT']) {
  22375. $yadj = ($Rw - $details['mbw']['RT'])/2;
  22376. }
  22377. if (!$bSeparate && $details['mbw']['RB']) {
  22378. $yadj2 = ($Rw - $details['mbw']['RB'])/2;
  22379. }
  22380. $print = true;
  22381. }
  22382. if ($Bw && $side=='B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { // BOTTOM
  22383. $ly1 = $y2;
  22384. $ly2 = $y2;
  22385. $lx1 = $x;
  22386. $lx2 = $x2;
  22387. $this->SetLineWidth($Bw);
  22388. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22389. if ($Bw > $Lw) $xadj = ($Bw - $Lw)/2;
  22390. if ($Bw < $Lw) $xadj = ($Bw + $Lw)/2;
  22391. }
  22392. else { $xadj = $Bw/2 - $bsh/2; }
  22393. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22394. if ($Bw > $Rw) $xadj2 = ($Bw - $Rw)/2;
  22395. if ($Bw < $Rw) $xadj2 = ($Bw + $Rw)/2;
  22396. }
  22397. else { $xadj2 = $Bw/2 - $bsh/2; }
  22398. if (!$bSeparate && $details['mbw']['BL']) {
  22399. $xadj = ($Bw - $details['mbw']['BL'])/2;
  22400. }
  22401. if (!$bSeparate && $details['mbw']['BR']) {
  22402. $xadj2 = ($Bw - $details['mbw']['BR'])/2;
  22403. }
  22404. $print = true;
  22405. }
  22406. // Now draw line
  22407. if ($print) {
  22408. /*-- TABLES-ADVANCED-BORDERS --*/
  22409. if ($details[$side]['style'] == 'double') {
  22410. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22411. if ($details[$side]['c']) {
  22412. $this->SetDColor($details[$side]['c']);
  22413. }
  22414. else { $this->SetDColor($this->ConvertColor(0)); }
  22415. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22416. }
  22417. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22418. if ($bSeparate && $cort=='table') {
  22419. if ($side=='T') {
  22420. $xadj -= $this->LineWidth/2;
  22421. $xadj2 -= $this->LineWidth;
  22422. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22423. $xadj += $this->LineWidth/2;
  22424. }
  22425. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22426. $xadj2 += $this->LineWidth;
  22427. }
  22428. }
  22429. if ($side=='L') {
  22430. $yadj -= $this->LineWidth/2;
  22431. $yadj2 -= $this->LineWidth;
  22432. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22433. $yadj += $this->LineWidth/2;
  22434. }
  22435. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22436. $yadj2 += $this->LineWidth;
  22437. }
  22438. }
  22439. if ($side=='B') {
  22440. $xadj -= $this->LineWidth/2;
  22441. $xadj2 -= $this->LineWidth;
  22442. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22443. $xadj += $this->LineWidth/2;
  22444. }
  22445. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22446. $xadj2 += $this->LineWidth;
  22447. }
  22448. }
  22449. if ($side=='R') {
  22450. $yadj -= $this->LineWidth/2;
  22451. $yadj2 -= $this->LineWidth;
  22452. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22453. $yadj += $this->LineWidth/2;
  22454. }
  22455. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22456. $yadj2 += $this->LineWidth;
  22457. }
  22458. }
  22459. }
  22460. $this->SetLineWidth($this->LineWidth/3);
  22461. $tbcol = $this->ConvertColor(255);
  22462. for($l=0; $l <= $this->blklvl; $l++) {
  22463. if ($this->blk[$l]['bgcolor']) {
  22464. $tbcol = ($this->blk[$l]['bgcolorarray']); // mPDF 5.6.53
  22465. }
  22466. }
  22467. if ($bSeparate) {
  22468. $cellBorderOverlay[] = array(
  22469. 'x' => $lx1 + $xadj,
  22470. 'y' => $ly1 + $yadj,
  22471. 'x2' => $lx2 - $xadj2,
  22472. 'y2' => $ly2 - $yadj2,
  22473. 'col' => $tbcol,
  22474. 'lw' => $this->LineWidth,
  22475. );
  22476. }
  22477. else {
  22478. $this->SetDColor($tbcol);
  22479. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22480. }
  22481. }
  22482. }
  22483. else if (isset($details[$side]['style']) && ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset')) {
  22484. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22485. if ($details[$side]['c']) {
  22486. $this->SetDColor($details[$side]['c']);
  22487. }
  22488. else { $this->SetDColor($this->ConvertColor(0)); }
  22489. if ($details[$side]['style'] == 'outset' || $details[$side]['style'] == 'groove') {
  22490. $nc = $this->_darkenColor($details[$side]['c']);
  22491. $this->SetDColor($nc);
  22492. }
  22493. else if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22494. $nc = $this->_lightenColor($details[$side]['c']);
  22495. $this->SetDColor($nc);
  22496. }
  22497. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22498. }
  22499. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22500. if ($details[$side]['c']) {
  22501. $this->SetDColor($details[$side]['c']);
  22502. }
  22503. else { $this->SetDColor($this->ConvertColor(0)); }
  22504. $doubleadj = ($this->LineWidth)/3;
  22505. $this->SetLineWidth($this->LineWidth/2);
  22506. $xadj3 = $yadj3 = $wadj3 = $hadj3 = 0;
  22507. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22508. $nc = $this->_darkenColor($details[$side]['c']);
  22509. if ($bSeparate && $cort=='table') {
  22510. if ($side=='T') {
  22511. $yadj3 = $this->LineWidth/2;
  22512. $xadj3 = -$this->LineWidth/2;
  22513. $wadj3 = $this->LineWidth;
  22514. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22515. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22516. }
  22517. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22518. $wadj3 -= $this->LineWidth*2;
  22519. }
  22520. }
  22521. if ($side=='L') {
  22522. $xadj3 = $this->LineWidth/2;
  22523. $yadj3 = -$this->LineWidth/2;
  22524. $hadj3 = $this->LineWidth;
  22525. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22526. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22527. }
  22528. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22529. $hadj3 -= $this->LineWidth*2;
  22530. }
  22531. }
  22532. if ($side=='B') {
  22533. $yadj3 = $this->LineWidth/2;
  22534. $xadj3 = -$this->LineWidth/2;
  22535. $wadj3 = $this->LineWidth;
  22536. }
  22537. if ($side=='R') {
  22538. $xadj3 = $this->LineWidth/2;
  22539. $yadj3 = -$this->LineWidth/2;
  22540. $hadj3 = $this->LineWidth;
  22541. }
  22542. }
  22543. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; $wadj3 = -$this->LineWidth*2; }
  22544. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; $hadj3 = -$this->LineWidth*2; }
  22545. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $wadj3 = $this->LineWidth/2; }
  22546. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $hadj3 = $this->LineWidth/2; }
  22547. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22548. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22549. }
  22550. else {
  22551. $nc = $this->_lightenColor($details[$side]['c']);
  22552. if ($bSeparate && $cort=='table') {
  22553. if ($side=='T') {
  22554. $yadj3 = $this->LineWidth/2;
  22555. $xadj3 = -$this->LineWidth/2;
  22556. $wadj3 = $this->LineWidth;
  22557. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22558. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22559. }
  22560. }
  22561. if ($side=='L') {
  22562. $xadj3 = $this->LineWidth/2;
  22563. $yadj3 = -$this->LineWidth/2;
  22564. $hadj3 = $this->LineWidth;
  22565. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22566. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22567. }
  22568. }
  22569. if ($side=='B') {
  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=='R') {
  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. }
  22586. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22587. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22588. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  22589. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  22590. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; }
  22591. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; }
  22592. }
  22593. if ($bSeparate) {
  22594. $cellBorderOverlay[] = array(
  22595. 'x' => $lx1 + $xadj + $xadj3,
  22596. 'y' => $ly1 + $yadj + $yadj3,
  22597. 'x2' => $lx2 - $xadj2 + $xadj3 + $wadj3,
  22598. 'y2' => $ly2 - $yadj2 + $yadj3 + $hadj3,
  22599. 'col' => $nc,
  22600. 'lw' => $this->LineWidth,
  22601. );
  22602. }
  22603. else {
  22604. $this->SetDColor($nc);
  22605. $this->Line($lx1 + $xadj + $xadj3, $ly1 + $yadj + $yadj3, $lx2 - $xadj2 + $xadj3 + $wadj3, $ly2 - $yadj2 + $yadj3 + $hadj3);
  22606. }
  22607. }
  22608. }
  22609. else {
  22610. /*-- END TABLES-ADVANCED-BORDERS --*/
  22611. if ($details[$side]['style'] == 'dashed') {
  22612. $dashsize = 2; // final dash will be this + 1*linewidth
  22613. $dashsizek = 1.5; // ratio of Dash/Blank
  22614. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  22615. }
  22616. else if ($details[$side]['style'] == 'dotted') {
  22617. $this->SetLineJoin(1);
  22618. $this->SetLineCap(1);
  22619. $this->SetDash(0.001,($this->LineWidth*2));
  22620. }
  22621. if ($details[$side]['c']) {
  22622. $this->SetDColor($details[$side]['c']);
  22623. }
  22624. else { $this->SetDColor($this->ConvertColor(0)); }
  22625. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22626. /*-- TABLES-ADVANCED-BORDERS --*/
  22627. }
  22628. /*-- END TABLES-ADVANCED-BORDERS --*/
  22629. // Reset Corners
  22630. $this->SetDash();
  22631. //BUTT style line cap
  22632. $this->SetLineCap(2);
  22633. }
  22634. }
  22635. if ($bSeparate && count($cellBorderOverlay)) {
  22636. foreach($cellBorderOverlay AS $cbo) {
  22637. $this->SetLineWidth($cbo['lw']);
  22638. $this->SetDColor($cbo['col']);
  22639. $this->Line($cbo['x'], $cbo['y'], $cbo['x2'], $cbo['y2']);
  22640. }
  22641. }
  22642. // $this->SetLineWidth($oldlinewidth);
  22643. // $this->SetDColor($this->ConvertColor(0));
  22644. }
  22645. }
  22646. /*-- TABLES --*/
  22647. /*-- TABLES-ADVANCED-BORDERS --*/
  22648. function _lightenColor($c) {
  22649. if (is_array($c)) { die('Color error in _lightencolor'); }
  22650. if ($c{0}==3 || $c{0}==5) { // RGB
  22651. list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255);
  22652. $l += ((1 - $l)*0.8);
  22653. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  22654. $ret = array(3,$r,$g,$b);
  22655. }
  22656. else if ($c{0}==4 || $c{0}==6) { // CMYK
  22657. $ret = array(4, max(0,(ord($c{1})-20)), max(0,(ord($c{2})-20)), max(0,(ord($c{3})-20)), max(0,(ord($c{4})-20)) );
  22658. }
  22659. else if ($c{0}==1) { // Grayscale
  22660. $ret = array(1,min(255,(ord($c{1})+32)));
  22661. }
  22662. $c = array_pad($ret, 6, 0);
  22663. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  22664. return $cstr;
  22665. }
  22666. function _darkenColor($c) {
  22667. if (is_array($c)) { die('Color error in _darkenColor'); }
  22668. if ($c{0}==3 || $c{0}==5) { // RGB
  22669. list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255);
  22670. $s *= 0.25;
  22671. $l *= 0.75;
  22672. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  22673. $ret = array(3,$r,$g,$b);
  22674. }
  22675. else if ($c{0}==4 || $c{0}==6) { // CMYK
  22676. $ret = array(4, min(100,(ord($c{1})+20)), min(100,(ord($c{2})+20)), min(100,(ord($c{3})+20)), min(100,(ord($c{4})+20)) );
  22677. }
  22678. else if ($c{0}==1) { // Grayscale
  22679. $ret = array(1,max(0,(ord($c{1})-32)));
  22680. }
  22681. $c = array_pad($ret, 6, 0);
  22682. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  22683. return $cstr;
  22684. }
  22685. /*-- END TABLES-ADVANCED-BORDERS --*/
  22686. function setBorder(&$var, $flag, $set = true) {
  22687. $flag = intval($flag);
  22688. if ($set) { $set = true; }
  22689. $var = intval($var);
  22690. $var = $set ? ($var | $flag) : ($var & ~$flag);
  22691. }
  22692. function issetBorder($var, $flag) {
  22693. $flag = intval($flag);
  22694. $var = intval($var);
  22695. return (($var & $flag) == $flag);
  22696. }
  22697. function _table2cellBorder(&$tableb, &$cbdb, &$cellb, $bval) {
  22698. if ($tableb && $tableb['w'] > $cbdb['w']) {
  22699. $cbdb = $tableb;
  22700. $this->setBorder($cellb, $bval);
  22701. }
  22702. else if ($tableb && $tableb['w'] == $cbdb['w']
  22703. && array_search($tableb['style'],$this->borderstyles) > array_search($cbdb['style'],$this->borderstyles)) {
  22704. $cbdb = $tableb;
  22705. $this->setBorder($cellb, $bval);
  22706. }
  22707. }
  22708. // FIX BORDERS ********************************************
  22709. function _fixTableBorders(&$table){
  22710. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  22711. else { $fh = null; }
  22712. if (!$table['borders_separate'] && $table['border_details']['L']['w']) {
  22713. $table['max_cell_border_width']['L'] = $table['border_details']['L']['w'];
  22714. }
  22715. if (!$table['borders_separate'] && $table['border_details']['R']['w']) {
  22716. $table['max_cell_border_width']['R'] = $table['border_details']['R']['w'];
  22717. }
  22718. if (!$table['borders_separate'] && $table['border_details']['T']['w']) {
  22719. $table['max_cell_border_width']['T'] = $table['border_details']['T']['w'];
  22720. }
  22721. if (!$table['borders_separate'] && $table['border_details']['B']['w']) {
  22722. $table['max_cell_border_width']['B'] = $table['border_details']['B']['w'];
  22723. }
  22724. if ($this->simpleTables) { return; }
  22725. $cells = &$table['cells'];
  22726. $numcols = $table['nc'];
  22727. $numrows = $table['nr'];
  22728. /*-- TABLES-ADVANCED-BORDERS --*/
  22729. if (isset($table['topntail']) && $table['topntail']) { $tntborddet = $this->border_details($table['topntail']); }
  22730. if (isset($table['thead-underline']) && $table['thead-underline']) { $thuborddet = $this->border_details($table['thead-underline']); }
  22731. /*-- END TABLES-ADVANCED-BORDERS --*/
  22732. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  22733. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  22734. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  22735. if ($this->cacheTables) {
  22736. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22737. }
  22738. else
  22739. $cell = &$cells[$i][$j];
  22740. if ($this->packTableData) { // includes $this->cacheTables
  22741. $cbord = $this->_unpackCellBorder($cell['borderbin']);
  22742. }
  22743. else {
  22744. $cbord = &$cells[$i][$j];
  22745. }
  22746. if (!$cbord['border'] && isset($table['border']) && $table['border'] && $this->table_border_attr_set) {
  22747. $cbord['border'] = $table['border'];
  22748. $cbord['border_details'] = $table['border_details'];
  22749. }
  22750. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  22751. else { $ccolsp = 1; }
  22752. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  22753. else { $crowsp = 1; }
  22754. $cbord['border_details']['cellposdom'] = ((($i+1)/$numrows) / 10000 ) + ((($j+1)/$numcols) / 10 );
  22755. // Inherit Cell border from Table border
  22756. if ($this->table_border_css_set && !$table['borders_separate']) {
  22757. if ($i == 0) {
  22758. $this->_table2cellBorder($table['border_details']['T'], $cbord['border_details']['T'], $cbord['border'], _BORDER_TOP);
  22759. }
  22760. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  22761. $this->_table2cellBorder($table['border_details']['B'], $cbord['border_details']['B'], $cbord['border'], _BORDER_BOTTOM);
  22762. }
  22763. if ($j == 0) {
  22764. $this->_table2cellBorder($table['border_details']['L'], $cbord['border_details']['L'], $cbord['border'], _BORDER_LEFT);
  22765. }
  22766. if ($j == ($numcols-1) || ($j+$ccolsp) == ($numcols) ) {
  22767. $this->_table2cellBorder($table['border_details']['R'], $cbord['border_details']['R'], $cbord['border'], _BORDER_RIGHT);
  22768. }
  22769. }
  22770. /*-- TABLES-ADVANCED-BORDERS --*/
  22771. $fixbottom = true;
  22772. if (isset($table['topntail']) && $table['topntail']) {
  22773. if ($i == 0) {
  22774. $cbord['border_details']['T'] = $tntborddet;
  22775. $this->setBorder($cbord['border'], _BORDER_TOP);
  22776. }
  22777. if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) {
  22778. $cbord['border_details']['B'] = $tntborddet;
  22779. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  22780. $fixbottom = false;
  22781. }
  22782. else if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']) {
  22783. if (!$table['borders_separate']) {
  22784. $cbord['border_details']['T'] = $tntborddet;
  22785. $this->setBorder($cbord['border'], _BORDER_TOP);
  22786. }
  22787. }
  22788. if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows']-1)) {
  22789. if (!$table['borders_separate']) {
  22790. $cbord['border_details']['B'] = $tntborddet;
  22791. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  22792. $fixbottom = false;
  22793. }
  22794. }
  22795. else if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows'])) {
  22796. $cbord['border_details']['T'] = $tntborddet;
  22797. $this->setBorder($cbord['border'], _BORDER_TOP);
  22798. }
  22799. if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  22800. if (!$table['borders_separate']) {
  22801. $cbord['border_details']['T'] = $tntborddet;
  22802. $this->setBorder($cbord['border'], _BORDER_TOP);
  22803. }
  22804. }
  22805. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  22806. $cbord['border_details']['B'] = $tntborddet;
  22807. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  22808. }
  22809. }
  22810. if (isset($table['thead-underline']) && $table['thead-underline']) {
  22811. if ($table['borders_separate']) {
  22812. if ($i == 0) {
  22813. $cbord['border_details']['B'] = $thuborddet;
  22814. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  22815. $fixbottom = false;
  22816. }
  22817. }
  22818. else {
  22819. if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) {
  22820. $cbord['border_details']['T'] = $thuborddet;
  22821. $this->setBorder($cbord['border'], _BORDER_TOP);
  22822. }
  22823. else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  22824. $cbord['border_details']['T'] = $thuborddet;
  22825. $this->setBorder($cbord['border'], _BORDER_TOP);
  22826. }
  22827. }
  22828. }
  22829. // Collapse Border - Algorithm for conflicting borders
  22830. // Hidden >> Width >> double>solid>dashed>dotted... >> style set on cell>table >> top/left>bottom/right
  22831. // Do not turn off border which is overridden
  22832. // Needed for page break for TOP/BOTTOM both to be defined in Collapsed borders
  22833. // Means it is painted twice. (Left/Right can still disable overridden border)
  22834. if (!$table['borders_separate']) {
  22835. if (($i < ($numrows-1) || ($i+$crowsp) < $numrows ) && $fixbottom ) { // Bottom
  22836. for ($cspi = 0; $cspi<$ccolsp; $cspi++) {
  22837. // already defined Top for adjacent cell below
  22838. if (isset($cells[($i+$crowsp)][$j+$cspi])) {
  22839. if ($this->packTableData) {
  22840. if ($this->cacheTables) {
  22841. $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j+$cspi], '', $fh);
  22842. }
  22843. else { $adjc = $cells[($i+$crowsp)][$j+$cspi]; }
  22844. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  22845. }
  22846. else { $celladj =& $cells[($i+$crowsp)][$j+$cspi]; }
  22847. }
  22848. else { $celladj = false; }
  22849. if ($celladj && $celladj['border_details']['T']['s'] == 1) {
  22850. $csadj = $celladj['border_details']['T']['w'];
  22851. $csthis = $cbord['border_details']['B']['w'];
  22852. // Hidden
  22853. if ($cbord['border_details']['B']['style']=='hidden') {
  22854. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22855. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  22856. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  22857. }
  22858. else if ($celladj['border_details']['T']['style']=='hidden') {
  22859. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22860. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  22861. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  22862. }
  22863. // Width
  22864. else if ($csthis > $csadj) {
  22865. 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
  22866. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22867. $this->setBorder($cbord['border'] , _BORDER_BOTTOM);
  22868. }
  22869. }
  22870. else if ($csadj > $csthis) {
  22871. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  22872. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22873. $this->setBorder($celladj['border'] , _BORDER_TOP);
  22874. }
  22875. }
  22876. // double>solid>dashed>dotted...
  22877. else if (array_search($cbord['border_details']['B']['style'],$this->borderstyles) > array_search($celladj['border_details']['T']['style'],$this->borderstyles)) {
  22878. 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
  22879. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22880. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  22881. }
  22882. }
  22883. else if (array_search($celladj['border_details']['T']['style'],$this->borderstyles) > array_search($cbord['border_details']['B']['style'],$this->borderstyles)) {
  22884. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  22885. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22886. $this->setBorder($celladj['border'] , _BORDER_TOP);
  22887. }
  22888. }
  22889. // Style set on cell vs. table
  22890. else if ($celladj['border_details']['T']['dom'] > $cbord['border_details']['B']['dom']) {
  22891. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  22892. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  22893. $this->setBorder($celladj['border'] , _BORDER_TOP);
  22894. }
  22895. }
  22896. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  22897. else {
  22898. 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
  22899. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22900. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  22901. }
  22902. }
  22903. }
  22904. else if ($celladj) {
  22905. 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
  22906. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  22907. }
  22908. }
  22909. if ($celladj && $this->packTableData) {
  22910. $celladj['borderbin'] = $this->_packCellBorder($celladj);
  22911. unset($celladj['border']);
  22912. unset($celladj['border_details']);
  22913. }
  22914. if ($this->cacheTables) {
  22915. $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$crowsp][$j+$cspi]);
  22916. }
  22917. unset($celladj);
  22918. }
  22919. }
  22920. if ($j < ($numcols-1) || ($j+$ccolsp) < $numcols ) { // Right-Left
  22921. for ($cspi = 0; $cspi<$crowsp; $cspi++) {
  22922. // already defined Left for adjacent cell to R
  22923. if (isset($cells[($i+$cspi)][$j+$ccolsp])) {
  22924. if ($this->packTableData) {
  22925. if ($this->cacheTables) {
  22926. $adjc = $this->_uncacheCell($table['cells'][$i+$cspi][$j+$ccolsp], '', $fh);
  22927. }
  22928. else { $adjc = $cells[($i+$cspi)][$j+$ccolsp]; }
  22929. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  22930. }
  22931. else { $celladj =& $cells[$i+$cspi][$j+$ccolsp]; }
  22932. }
  22933. else { $celladj = false; }
  22934. if ($celladj && $celladj['border_details']['L']['s'] == 1) {
  22935. $csadj = $celladj['border_details']['L']['w'];
  22936. $csthis = $cbord['border_details']['R']['w'];
  22937. // Hidden
  22938. if ($cbord['border_details']['R']['style']=='hidden') {
  22939. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22940. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22941. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  22942. }
  22943. else if ($celladj['border_details']['L']['style']=='hidden') {
  22944. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22945. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  22946. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22947. }
  22948. // Width
  22949. else if ($csthis > $csadj) {
  22950. 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
  22951. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22952. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  22953. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22954. }
  22955. }
  22956. else if ($csadj > $csthis) {
  22957. if ($crowsp < 2) { // don't overwrite this cell if it spans
  22958. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22959. $this->setBorder($cbord['border'] , _BORDER_RIGHT, false);
  22960. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  22961. }
  22962. }
  22963. // double>solid>dashed>dotted...
  22964. else if (array_search($cbord['border_details']['R']['style'],$this->borderstyles) > array_search($celladj['border_details']['L']['style'],$this->borderstyles)) {
  22965. 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
  22966. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22967. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  22968. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  22969. }
  22970. }
  22971. else if (array_search($celladj['border_details']['L']['style'],$this->borderstyles) > array_search($cbord['border_details']['R']['style'],$this->borderstyles)) {
  22972. if ($crowsp < 2) { // don't overwrite this cell if it spans
  22973. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22974. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  22975. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  22976. }
  22977. }
  22978. // Style set on cell vs. table
  22979. else if ($celladj['border_details']['L']['dom'] > $cbord['border_details']['R']['dom']) {
  22980. if ($crowsp < 2) { // don't overwrite this cell if it spans
  22981. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  22982. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  22983. }
  22984. }
  22985. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  22986. else {
  22987. 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
  22988. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22989. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  22990. }
  22991. }
  22992. }
  22993. else if ($celladj) {
  22994. // if right-cell border is not set
  22995. 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
  22996. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  22997. }
  22998. }
  22999. if ($celladj && $this->packTableData) {
  23000. $celladj['borderbin'] = $this->_packCellBorder($celladj);
  23001. unset($celladj['border']);
  23002. unset($celladj['border_details']);
  23003. }
  23004. if ($this->cacheTables) {
  23005. $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$cspi][$j+$ccolsp]);
  23006. }
  23007. unset($celladj);
  23008. }
  23009. }
  23010. }
  23011. // Set maximum cell border width meeting at LRTB edges of cell - used for extended cell border
  23012. // ['border_details']['mbw']['LT'] = meeting border width - Left border - Top end
  23013. if (!$table['borders_separate']) {
  23014. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $cbord['border_details']['L']['w']);
  23015. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $cbord['border_details']['R']['w']);
  23016. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $cbord['border_details']['T']['w']);
  23017. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $cbord['border_details']['B']['w']);
  23018. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $cbord['border_details']['L']['w']);
  23019. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $cbord['border_details']['R']['w']);
  23020. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $cbord['border_details']['T']['w']);
  23021. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $cbord['border_details']['B']['w']);
  23022. if (($i+$crowsp) < $numrows && isset($cells[$i+$crowsp][$j])) { // Has Bottom adjoining cell
  23023. if ($this->packTableData) {
  23024. if ($this->cacheTables) {
  23025. $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j], '', $fh);
  23026. }
  23027. else { $adjc = $cells[$i+$crowsp][$j]; }
  23028. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23029. }
  23030. else { $celladj =& $cells[$i+$crowsp][$j]; }
  23031. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['TL']);
  23032. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['TR']);
  23033. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['mbw']['LT']);
  23034. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['mbw']['RT']);
  23035. unset($celladj);
  23036. }
  23037. if (($j+$ccolsp) < $numcols && isset($cells[$i][$j+$ccolsp])) { // Has Right adjoining cell
  23038. if ($this->packTableData) {
  23039. if ($this->cacheTables) {
  23040. $adjc = $this->_uncacheCell($table['cells'][$i][$j+$ccolsp], '', $fh);
  23041. }
  23042. else { $adjc = $cells[$i][$j+$ccolsp]; }
  23043. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23044. }
  23045. else { $celladj =& $cells[$i][$j+$ccolsp]; }
  23046. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['LT']);
  23047. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['LB']);
  23048. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['mbw']['TL']);
  23049. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['mbw']['BL']);
  23050. unset($celladj);
  23051. }
  23052. if ($i > 0 && isset($cells[$i-1][$j]) && (($this->packTableData && $cells[$i-1][$j]['borderbin']) || $cells[$i-1][$j]['border'])) { // Has Top adjoining cell
  23053. if ($this->packTableData) {
  23054. if ($this->cacheTables) {
  23055. $adjc = $this->_uncacheCell($table['cells'][$i-1][$j], '', $fh);
  23056. }
  23057. else { $adjc = $cells[$i-1][$j]; }
  23058. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23059. }
  23060. else { $celladj =& $cells[$i-1][$j]; }
  23061. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['BL']);
  23062. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['BR']);
  23063. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['mbw']['LB']);
  23064. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['mbw']['RB']);
  23065. if ($celladj['border_details']['mbw']['BL']) {
  23066. $celladj['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['BL']);
  23067. }
  23068. if ($celladj['border_details']['mbw']['BR'] ) {
  23069. $celladj['border_details']['mbw']['BR'] = max($celladj['border_details']['mbw']['BR'], $cbord['border_details']['mbw']['TR']);
  23070. }
  23071. if ($this->packTableData) { $cells[$i-1][$j]['borderbin'] = $this->_packCellBorder($celladj); }
  23072. unset($celladj);
  23073. }
  23074. if ($j > 0 && isset($cells[$i][$j-1]) && (($this->packTableData && $cells[$i][$j-1]['borderbin']) || $cells[$i][$j-1]['border'])) { // Has Left adjoining cell
  23075. if ($this->packTableData) {
  23076. if ($this->cacheTables) {
  23077. $adjc = $this->_uncacheCell($table['cells'][$i][$j-1], '', $fh);
  23078. }
  23079. else { $adjc = $cells[$i][$j-1]; }
  23080. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23081. }
  23082. else { $celladj =& $cells[$i][$j-1]; }
  23083. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['RT']);
  23084. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['RB']);
  23085. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['mbw']['BR']);
  23086. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['TR']);
  23087. if ($celladj['border_details']['mbw']['RT']) {
  23088. $celladj['border_details']['mbw']['RT'] = max($celladj['border_details']['mbw']['RT'], $cbord['border_details']['mbw']['LT']);
  23089. }
  23090. if ($celladj['border_details']['mbw']['RB']) {
  23091. $celladj['border_details']['mbw']['RB'] = max($celladj['border_details']['mbw']['RB'], $cbord['border_details']['mbw']['LB']);
  23092. }
  23093. if ($this->packTableData) { $cells[$i][$j-1]['borderbin'] = $this->_packCellBorder($celladj); }
  23094. unset($celladj);
  23095. }
  23096. // Update maximum cell border width at LRTB edges of table - used for overall table width
  23097. if ($j == 0 && $cbord['border_details']['L']['w']) {
  23098. $table['max_cell_border_width']['L'] = max($table['max_cell_border_width']['L'],$cbord['border_details']['L']['w']);
  23099. }
  23100. if (($j == ($numcols-1) || ($j+$ccolsp) == $numcols ) && $cbord['border_details']['R']['w']) {
  23101. $table['max_cell_border_width']['R'] = max($table['max_cell_border_width']['R'],$cbord['border_details']['R']['w']);
  23102. }
  23103. if ($i == 0 && $cbord['border_details']['T']['w']) {
  23104. $table['max_cell_border_width']['T'] = max($table['max_cell_border_width']['T'],$cbord['border_details']['T']['w']);
  23105. }
  23106. if (($i == ($numrows-1) || ($i+$crowsp) == $numrows ) && $cbord['border_details']['B']['w']) {
  23107. $table['max_cell_border_width']['B'] = max($table['max_cell_border_width']['B'],$cbord['border_details']['B']['w']);
  23108. }
  23109. }
  23110. /*-- END TABLES-ADVANCED-BORDERS --*/
  23111. if ($this->packTableData) { $cell['borderbin'] = $this->_packCellBorder($cbord); }
  23112. if ($this->cacheTables) {
  23113. $this->_cacheUpdateBorder($cell, $fh, $table['cells'][$i][$j]);
  23114. }
  23115. unset($cbord );
  23116. unset($cell );
  23117. }
  23118. }
  23119. }
  23120. if ($this->cacheTables) { fclose($fh); }
  23121. unset($cell );
  23122. }
  23123. // END FIX BORDERS ************************************************************************************
  23124. function _reverseTableDir(&$table) {
  23125. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23126. $cells = &$table['cells'];
  23127. $numcols = $table['nc'];
  23128. $numrows = $table['nr'];
  23129. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23130. $row = array();
  23131. for( $j = ($numcols-1) ; $j >= 0 ; $j-- ) { //Columns
  23132. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23133. if ($this->cacheTables) {
  23134. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23135. }
  23136. else
  23137. $cell = &$cells[$i][$j];
  23138. $col = $numcols - $j - 1;
  23139. if (isset($cell['colspan']) && $cell['colspan'] > 1) { $col -= ($cell['colspan']-1); }
  23140. // Nested content
  23141. for ($n=0; $n < count($cell['textbuffer']); $n++) {
  23142. $t = $cell['textbuffer'][$n][0];
  23143. if (substr($t,0,19) == "\xbb\xa4\xactype=nestedtable") {
  23144. $objattr = $this->_getObjAttr($t);
  23145. $objattr['col'] = $col;
  23146. $cell['textbuffer'][$n][0] = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  23147. $this->table[($this->tableLevel+1)][$objattr['nestedcontent']]['nestedpos'][1] = $col;
  23148. if ($this->cacheTables) {
  23149. $this->_cacheUpdateTxB($cell, $fh, $table['cells'][$i][$j]);
  23150. }
  23151. }
  23152. }
  23153. $row[$col] = $cells[$i][$j];
  23154. unset($cell);
  23155. }
  23156. }
  23157. for($f=0; $f < $numcols; $f++) {
  23158. if (!isset($row[$f])) { $row[$f] = 0; }
  23159. }
  23160. $table['cells'][$i] = $row;
  23161. }
  23162. if ($this->cacheTables) { fclose($fh); }
  23163. }
  23164. function _tableWrite(&$table, $split=false, $startrow=0, $startcol=0, $splitpg=0, $rety = 0){
  23165. $level = $table['level'];
  23166. $levelid = $table['levelid'];
  23167. $cells = &$table['cells'];
  23168. $numcols = $table['nc'];
  23169. $numrows = $table['nr'];
  23170. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  23171. if (!$split || ($startrow==0 && $splitpg==0) || $startrow>0){
  23172. // TABLE TOP MARGIN
  23173. if ($table['margin']['T']) {
  23174. if (!$this->table_rotate && $level==1) {
  23175. $this->DivLn($table['margin']['T'],$this->blklvl,true,1); // collapsible
  23176. }
  23177. else {
  23178. $this->y += ($table['margin']['T']);
  23179. }
  23180. }
  23181. // Advance down page by half width of top border
  23182. if ($table['borders_separate']) {
  23183. if ($startrow>0 && (!isset($table['is_thead']) || count($table['is_thead'])==0))
  23184. $adv = $table['border_spacing_V']/2;
  23185. else
  23186. $adv = $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2;
  23187. }
  23188. else {
  23189. $adv = $table['max_cell_border_width']['T']/2;
  23190. }
  23191. if (!$this->table_rotate && $level==1) { $this->DivLn($adv); }
  23192. else { $this->y += $adv; }
  23193. }
  23194. if ($level==1) {
  23195. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'];
  23196. $x0 = $this->x;
  23197. $y0 = $this->y;
  23198. $right = $x0 + $this->blk[$this->blklvl]['inner_width'];
  23199. $outerfilled = $this->y; // Keep track of how far down the outer DIV bgcolor is painted (NB rowspans)
  23200. $this->outerfilled = $this->y;
  23201. $this->colsums = array();
  23202. }
  23203. else {
  23204. $x0 = $this->x;
  23205. $y0 = $this->y;
  23206. $right = $x0 + $table['w'];
  23207. }
  23208. if ($this->table_rotate) {
  23209. $temppgwidth = $this->tbrot_maxw;
  23210. $this->PageBreakTrigger = $pagetrigger = $y0 + ($this->blk[$this->blklvl]['inner_width']);
  23211. if ($level==1) {
  23212. $this->tbrot_y0 = $this->y - $adv - $table['margin']['T'] ;
  23213. $this->tbrot_x0 = $this->x;
  23214. $this->tbrot_w = $table['w'];
  23215. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  23216. else { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['max_cell_border_width']['T']; }
  23217. }
  23218. }
  23219. else {
  23220. $this->PageBreakTrigger = $pagetrigger = ($this->h - $this->bMargin);
  23221. if ($level==1) {
  23222. $temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  23223. if (isset($table['a']) and ($table['w'] < $this->blk[$this->blklvl]['inner_width'])) {
  23224. if ($table['a']=='C') { $x0 += ((($right-$x0) - $table['w'])/2); }
  23225. else if ($table['a']=='R') { $x0 = $right - $table['w']; }
  23226. }
  23227. }
  23228. else {
  23229. $temppgwidth = $table['w'];
  23230. }
  23231. }
  23232. if(!isset($table['overflow'])) { $table['overflow'] = null; }
  23233. if ($table['overflow']=='hidden' && $level==1 && !$this->table_rotate && !$this->ColActive) {
  23234. //Bounding rectangle to clip
  23235. $this->tableClipPath = sprintf('q %.3F %.3F %.3F %.3F re W n',$x0*_MPDFK,$this->h*_MPDFK,$this->blk[$this->blklvl]['inner_width']*_MPDFK,-$this->h*_MPDFK);
  23236. $this->_out($this->tableClipPath);
  23237. }
  23238. else { $this->tableClipPath = ''; }
  23239. if ($table['borders_separate']) { $indent = $table['margin']['L'] + $table['border_details']['L']['w'] + $table['padding']['L'] + $table['border_spacing_H']/2; }
  23240. else { $indent = $table['margin']['L'] + $table['max_cell_border_width']['L']/2; }
  23241. $x0 += $indent;
  23242. $returny = 0;
  23243. $lastCol = 0;
  23244. $tableheader = array();
  23245. $tablefooter = array();
  23246. $tableheaderrowheight = 0;
  23247. $tablefooterrowheight = 0;
  23248. $footery = 0;
  23249. // mPD 3.0 Set the Page & Column where table starts
  23250. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  23251. $tablestartpage = 'EVEN';
  23252. }
  23253. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  23254. $tablestartpage = 'ODD';
  23255. }
  23256. else { $tablestartpage = ''; }
  23257. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; }
  23258. else { $tablestartcolumn = ''; }
  23259. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23260. else { $fh = null; }
  23261. $y = $h = 0;
  23262. for( $i = 0; $i < $numrows ; $i++ ) { //Rows
  23263. if ($this->progressBar) { $this->UpdateProgressBar(7,intval(30 + ($i*40/$numrows)),' '); } // *PROGRESS-BAR*
  23264. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i] && $level==1) {
  23265. $tablefooterrowheight += $table['hr'][$i];
  23266. $tablefooter[$i][0]['trbackground-images'] = $table['trbackground-images'][$i];
  23267. $tablefooter[$i][0]['trgradients'] = $table['trgradients'][$i];
  23268. $tablefooter[$i][0]['trbgcolor'] = $table['bgcolor'][$i];
  23269. for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns
  23270. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23271. if ($this->cacheTables) {
  23272. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23273. }
  23274. else
  23275. $cell = &$cells[$i][$j];
  23276. if ($split) {
  23277. if ($table['colPg'][$j] != $splitpg) { continue; }
  23278. list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh);
  23279. $js = $j - $startcol;
  23280. }
  23281. else {
  23282. list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh);
  23283. $js = $j;
  23284. }
  23285. list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh);
  23286. $x += $x0;
  23287. $y += $y0;
  23288. //Get info of tfoot ==>> table footer
  23289. $tablefooter[$i][$js]['x'] = $x;
  23290. $tablefooter[$i][$js]['y'] = $y;
  23291. $tablefooter[$i][$js]['h'] = $h;
  23292. $tablefooter[$i][$js]['w'] = $w;
  23293. if (isset($cell['textbuffer'])) { $tablefooter[$i][$js]['textbuffer'] = $cell['textbuffer']; }
  23294. else { $tablefooter[$i][$js]['textbuffer'] = ''; }
  23295. $tablefooter[$i][$js]['a'] = $cell['a'];
  23296. $tablefooter[$i][$js]['R'] = $cell['R'];
  23297. $tablefooter[$i][$js]['va'] = $cell['va'];
  23298. $tablefooter[$i][$js]['mih'] = $cell['mih'];
  23299. $tablefooter[$i][$js]['gradient'] = $cell['gradient']; // *BACKGROUNDS*
  23300. $tablefooter[$i][$js]['background-image'] = $cell['background-image']; // *BACKGROUNDS*
  23301. //CELL FILL BGCOLOR
  23302. if (!$this->simpleTables){
  23303. if ($this->packTableData) {
  23304. $c = $this->_unpackCellBorder($cell['borderbin']);
  23305. $tablefooter[$i][$js]['border'] = $c['border'];
  23306. $tablefooter[$i][$js]['border_details'] = $c['border_details'];
  23307. }
  23308. else {
  23309. $tablefooter[$i][$js]['border'] = $cell['border'];
  23310. $tablefooter[$i][$js]['border_details'] = $cell['border_details'];
  23311. }
  23312. }
  23313. else if ($this->simpleTables){
  23314. $tablefooter[$i][$js]['border'] = $table['simple']['border'];
  23315. $tablefooter[$i][$js]['border_details'] = $table['simple']['border_details'];
  23316. }
  23317. $tablefooter[$i][$js]['bgcolor'] = $cell['bgcolor'];
  23318. $tablefooter[$i][$js]['padding'] = $cell['padding'];
  23319. $tablefooter[$i][$js]['rowspan'] = $cell['rowspan'];
  23320. $tablefooter[$i][$js]['colspan'] = $cell['colspan'];
  23321. }
  23322. }
  23323. }
  23324. }
  23325. if ($level==1) { $this->_out('___TABLE___BACKGROUNDS'.date('jY')); }
  23326. $tableheaderadj = 0;
  23327. $tablefooteradj = 0;
  23328. $tablestartpageno = $this->page;
  23329. //Draw Table Contents and Borders
  23330. for( $i = 0; $i < $numrows ; $i++ ) { //Rows
  23331. if ($split && $startrow > 0) {
  23332. $thnr = (isset($table['is_thead']) ? count($table['is_thead']) : 0);
  23333. if ($i >= $thnr && $i < $startrow) { continue; }
  23334. if ($i == $startrow){ $returny = $rety - $tableheaderrowheight; }
  23335. }
  23336. // Get Maximum row/cell height in row - including rowspan>1 + 1 overlapping
  23337. $maxrowheight = $this->_tableGetMaxRowHeight($table, $i, $fh);
  23338. $skippage = false;
  23339. $newpagestarted = false;
  23340. for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns
  23341. if ($split) {
  23342. if ($table['colPg'][$j] > $splitpg) { break; }
  23343. $lastCol = $j;
  23344. }
  23345. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23346. if ($this->cacheTables) {
  23347. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23348. }
  23349. else
  23350. $cell = &$cells[$i][$j];
  23351. if ($split) {
  23352. $lastCol = $j + (isset($cell['colspan']) ? ($cell['colspan']-1) : 0) ;
  23353. list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh);
  23354. }
  23355. else { list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh); }
  23356. list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh);
  23357. $x += $x0;
  23358. $y += $y0;
  23359. $y -= $returny;
  23360. if ($table['borders_separate']) {
  23361. if (!empty($tablefooter) || $i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) {
  23362. $extra = $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23363. //$extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23364. }
  23365. else {
  23366. $extra = $table['border_spacing_V']/2;
  23367. }
  23368. }
  23369. else { $extra = $table['max_cell_border_width']['B']/2; }
  23370. if ($j==$startcol && ((($y + $maxrowheight + $extra ) > ($pagetrigger+0.001)) || (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && ($y + $maxrowheight + $tablefooterrowheight + $extra) > $pagetrigger) && ($this->tableLevel==1 && $i < ($numrows - $table['headernrows']))) && ($y0 >0 || $x0 > 0) && !$this->InFooter && $this->autoPageBreak ) {
  23371. if (!$skippage) {
  23372. $finalSpread = true;
  23373. $firstSpread = true;
  23374. if ($split) {
  23375. for($t=$startcol; $t<$numcols; $t++) {
  23376. // Are there more columns to print on a next page?
  23377. if ($table['colPg'][$t] > $splitpg) {
  23378. $finalSpread = false;
  23379. break;
  23380. }
  23381. }
  23382. if ($startcol>0) { $firstSpread = false; }
  23383. }
  23384. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23385. $this->y = $y;
  23386. $ya = $this->y;
  23387. $this->TableHeaderFooter($tablefooter,$tablestartpage,$tablestartcolumn,'F',$level, $firstSpread, $finalSpread);
  23388. if ($this->table_rotate) {
  23389. $this->tbrot_h += $this->y - $ya ;
  23390. }
  23391. $tablefooteradj = $this->y - $ya ;
  23392. }
  23393. $y -= $y0;
  23394. $returny += $y;
  23395. $oldcolumn = $this->CurrCol;
  23396. if ($this->AcceptPageBreak()) {
  23397. $newpagestarted = true;
  23398. $this->y = $y + $y0;
  23399. // Move down to account for border-spacing or
  23400. // extra half border width in case page breaks in middle
  23401. if($i>0 && !$this->table_rotate && $level==1 && !$this->ColActive) {
  23402. if ($table['borders_separate']) {
  23403. $adv = $table['border_spacing_V']/2;
  23404. // If table footer
  23405. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23406. $adv += ($table['padding']['B'] + $table['border_details']['B']['w']);
  23407. }
  23408. }
  23409. else {
  23410. $maxbwtop = 0;
  23411. $maxbwbottom = 0;
  23412. if (!$this->simpleTables){
  23413. if (!empty($tablefooter)) { $maxbwbottom = $table['max_cell_border_width']['B']; }
  23414. else {
  23415. $brow = $i-1;
  23416. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23417. if (isset($cells[$brow][$ctj]) && $cells[$brow][$ctj]) {
  23418. if ($this->cacheTables) {
  23419. $cadj = $this->_uncacheCell($table['cells'][$brow][$ctj], '', $fh);
  23420. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']);
  23421. }
  23422. else if ($this->packTableData) {
  23423. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$brow][$ctj]['borderbin']);
  23424. }
  23425. else {
  23426. $bb = $cells[$brow][$ctj]['border_details']['B']['w'];
  23427. }
  23428. $maxbwbottom = max($maxbwbottom , $bb);
  23429. }
  23430. }
  23431. }
  23432. if (!empty($tableheader)) { $maxbwtop = $table['max_cell_border_width']['T']; }
  23433. else {
  23434. $trow = $i-1;
  23435. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23436. if (isset($cells[$trow][$ctj]) && $cells[$trow][$ctj]) {
  23437. if ($this->cacheTables) {
  23438. $cadj = $this->_uncacheCell($table['cells'][$trow][$ctj], '', $fh);
  23439. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']);
  23440. }
  23441. else if ($this->packTableData) {
  23442. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$trow][$ctj]['borderbin']);
  23443. }
  23444. else {
  23445. $bt = $cells[$trow][$ctj]['border_details']['T']['w'];
  23446. }
  23447. $maxbwtop = max($maxbwtop , $bt);
  23448. }
  23449. }
  23450. }
  23451. }
  23452. else if ($this->simpleTables){
  23453. $maxbwtop = $table['simple']['border_details']['T']['w'];
  23454. $maxbwbottom = $table['simple']['border_details']['B']['w'];
  23455. }
  23456. $adv = $maxbwbottom /2;
  23457. }
  23458. $this->y += $adv;
  23459. }
  23460. // Rotated table split over pages - needs this->y for borders/backgrounds
  23461. if($i>0 && $this->table_rotate && $level==1) {
  23462. // $this->y = $y0 + $this->tbrot_w;
  23463. }
  23464. if ($this->tableClipPath ) { $this->_out("Q"); }
  23465. $bx = $x0;
  23466. $by = $y0;
  23467. if ($table['borders_separate']) {
  23468. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  23469. if ($tablestartpageno != $this->page) { // IF already broken across a previous pagebreak
  23470. $by += $table['max_cell_border_width']['T']/2;
  23471. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  23472. }
  23473. else {
  23474. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  23475. }
  23476. }
  23477. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  23478. $by -= $tableheaderadj;
  23479. $bh = $this->y - $by + $tablefooteradj;
  23480. if (!$table['borders_separate']) { $bh -= $adv ; }
  23481. if ($split) {
  23482. $bw = 0;
  23483. for($t=$startcol; $t<$numcols; $t++) {
  23484. if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; }
  23485. if ($table['colPg'][$t] > $splitpg) { break; }
  23486. }
  23487. if ($table['borders_separate']) {
  23488. if ($firstSpread) {
  23489. $bw += $table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H'];
  23490. }
  23491. else {
  23492. $bx += ($table['padding']['L'] + $table['border_details']['L']['w']);
  23493. $bw += $table['border_spacing_H'];
  23494. }
  23495. if ($finalSpread) {
  23496. $bw += $table['padding']['R'] + $table['border_details']['R']['w']/2 + $table['border_spacing_H'];
  23497. }
  23498. }
  23499. }
  23500. else {
  23501. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  23502. }
  23503. // mPDF 5.4.16
  23504. if ($this->splitTableBorderWidth && ($this->keepColumns || !$this->ColActive) && empty($tablefooter) && $i > 0 && $table['border_details']['B']['w']) {
  23505. $prevDrawColor = $this->DrawColor;
  23506. $lw = $this->LineWidth;
  23507. $this->SetLineWidth($this->splitTableBorderWidth);
  23508. $this->SetDColor($table['border_details']['B']['c']);
  23509. $this->SetLineJoin(0);
  23510. $this->SetLineCap(0);
  23511. $blx = $bx;
  23512. $blw = $bw;
  23513. if (!$table['borders_separate']) {
  23514. $blx -= ($table['max_cell_border_width']['L']/2);
  23515. $blw += ($table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2);
  23516. }
  23517. $this->Line($blx,$this->y+($this->splitTableBorderWidth/2),$blx+$blw,$this->y+($this->splitTableBorderWidth/2));
  23518. $this->DrawColor = $prevDrawColor;
  23519. $this->_out($this->DrawColor);
  23520. $this->SetLineWidth($lw);
  23521. $this->SetLineJoin(2);
  23522. $this->SetLineCap(2);
  23523. }
  23524. if (!$this->ColActive && ($i > 0 || $j > 0)) {
  23525. if (isset($table['bgcolor'][-1])) {
  23526. $color = $this->ConvertColor($table['bgcolor'][-1]);
  23527. if ($color) {
  23528. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  23529. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  23530. }
  23531. }
  23532. /*-- BACKGROUNDS --*/
  23533. if (isset($table['gradient'])) {
  23534. $g = $this->grad->parseBackgroundGradient($table['gradient']);
  23535. if ($g) {
  23536. $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'=>'');
  23537. }
  23538. }
  23539. if (isset($table['background-image'])) {
  23540. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  23541. $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] );
  23542. if ($g) {
  23543. $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'=>'');
  23544. }
  23545. }
  23546. else {
  23547. $image_id = $table['background-image']['image_id'];
  23548. $orig_w = $table['background-image']['orig_w'];
  23549. $orig_h = $table['background-image']['orig_h'];
  23550. $x_pos = $table['background-image']['x_pos'];
  23551. $y_pos = $table['background-image']['y_pos'];
  23552. $x_repeat = $table['background-image']['x_repeat'];
  23553. $y_repeat = $table['background-image']['y_repeat'];
  23554. $resize = $table['background-image']['resize'];
  23555. $opacity = $table['background-image']['opacity'];
  23556. $itype = $table['background-image']['itype'];
  23557. $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, 'itype'=>$itype);
  23558. }
  23559. }
  23560. /*-- END BACKGROUNDS --*/
  23561. }
  23562. // $this->AcceptPageBreak() has moved tablebuffer to $this->pages content
  23563. if ($this->tableBackgrounds) {
  23564. $s = $this->PrintTableBackgrounds();
  23565. if ($this->bufferoutput) {
  23566. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  23567. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer );
  23568. }
  23569. else {
  23570. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  23571. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]);
  23572. }
  23573. $this->tableBackgrounds = array();
  23574. }
  23575. if ($split) {
  23576. if ($i == 0 && $j == 0) { $y0 = -1; }
  23577. else if ($finalSpread) {
  23578. $splitpg = 0;
  23579. $startcol = 0;
  23580. $startrow = $i;
  23581. }
  23582. else {
  23583. $splitpg++;
  23584. $startcol = $t;
  23585. $returny -= $y;
  23586. }
  23587. return array(false, $startrow, $startcol, $splitpg, $returny, $y0);
  23588. }
  23589. $this->AddPage($this->CurOrientation);
  23590. $this->_out('___TABLE___BACKGROUNDS'.date('jY'));
  23591. if ($this->tableClipPath ) { $this->_out($this->tableClipPath); }
  23592. // Added to correct for OddEven Margins
  23593. $x= $x + $this->MarginCorrection;
  23594. $x0= $x0 + $this->MarginCorrection;
  23595. // mPDF 5.4.16
  23596. if ($this->splitTableBorderWidth && ($this->keepColumns || !$this->ColActive) && empty($tableheader) && $i > 0 && $table['border_details']['T']['w'] ) {
  23597. $prevDrawColor = $this->DrawColor;
  23598. $lw = $this->LineWidth;
  23599. $this->SetLineWidth($this->splitTableBorderWidth);
  23600. $this->SetDColor($table['border_details']['T']['c']);
  23601. $this->SetLineJoin(0);
  23602. $this->SetLineCap(0);
  23603. $blx += $this->MarginCorrection;
  23604. $this->Line($blx,$this->y-($this->splitTableBorderWidth/2),$blx+$blw,$this->y-($this->splitTableBorderWidth/2));
  23605. $this->DrawColor = $prevDrawColor;
  23606. $this->_out($this->DrawColor);
  23607. $this->SetLineWidth($lw);
  23608. $this->SetLineJoin(2);
  23609. $this->SetLineCap(2);
  23610. }
  23611. // Move down to account for half of top border-spacing or
  23612. // extra half border width in case page was broken in middle
  23613. if($i>0 && !$this->table_rotate && $level==1 && $table['headernrows']==0) {
  23614. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; }
  23615. else {
  23616. $maxbwtop = 0;
  23617. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23618. if (isset($cells[$i][$ctj]) && $cells[$i][$ctj]) {
  23619. if (!$this->simpleTables){
  23620. if ($this->cacheTables) {
  23621. $celltj = $this->_uncacheCell($table['cells'][$i][$ctj], '', $fh);
  23622. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($celltj['borderbin']);
  23623. }
  23624. else if ($this->packTableData) {
  23625. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$i][$ctj]['borderbin']);
  23626. }
  23627. else {
  23628. $bt = $cells[$i][$ctj]['border_details']['T']['w'];
  23629. }
  23630. $maxbwtop = max($maxbwtop, $bt);
  23631. }
  23632. else if ($this->simpleTables){
  23633. $maxbwtop = max($maxbwtop, $table['simple']['border_details']['T']['w']);
  23634. }
  23635. }
  23636. }
  23637. $adv = $maxbwtop /2;
  23638. }
  23639. $this->y += $adv;
  23640. }
  23641. if ($this->table_rotate) {
  23642. $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'];
  23643. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  23644. else { $this->tbrot_h = $table['margin']['T'] + $table['max_cell_border_width']['T'] ; }
  23645. $this->tbrot_y0 = $this->y;
  23646. $pagetrigger = $y0 - $tableheaderadj + ($this->blk[$this->blklvl]['inner_width']);
  23647. }
  23648. else {
  23649. $pagetrigger = $this->PageBreakTrigger;
  23650. }
  23651. if ($this->kwt_saved && $level==1) {
  23652. $this->kwt_moved = true;
  23653. }
  23654. // Disable Table header repeat if Keep Block together
  23655. if (!$this->keep_block_together && !empty($tableheader)) {
  23656. $ya = $this->y;
  23657. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level);
  23658. if ($this->table_rotate) {
  23659. $this->tbrot_h = $this->y - $ya ;
  23660. }
  23661. $tableheaderadj = $this->y - $ya ;
  23662. }
  23663. else if ($i==0 && !$this->keep_block_together && !$this->table_rotate && $level==1 && !$this->ColActive) {
  23664. // Advance down page
  23665. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  23666. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  23667. if ($adv) {
  23668. if ($this->table_rotate) {
  23669. $this->y += ($adv);
  23670. }
  23671. else {
  23672. $this->DivLn($adv,$this->blklvl,true);
  23673. }
  23674. }
  23675. }
  23676. $outerfilled = 0;
  23677. $y = $y0 = $this->y;
  23678. }
  23679. /*-- COLUMNS --*/
  23680. // COLS
  23681. // COLUMN CHANGE
  23682. if ($this->CurrCol != $oldcolumn) {
  23683. // Added to correct for Columns
  23684. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  23685. $x0 += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  23686. if ($this->CurrCol == 0) { // just added a page - possibly with tableheader
  23687. $y0 = $this->y; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  23688. }
  23689. else {
  23690. $y0 = $this->y0; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  23691. }
  23692. $y = $y0;
  23693. $outerfilled = 0;
  23694. if ($this->CurrCol != 0 && ($this->keepColumns && $this->ColActive) && !empty($tableheader) && $i > 0 ) {
  23695. $this->x = $x;
  23696. $this->y = $y;
  23697. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level);
  23698. $y0 = $y=$this->y;
  23699. }
  23700. }
  23701. /*-- END COLUMNS --*/
  23702. }
  23703. $skippage = true;
  23704. }
  23705. $this->x = $x;
  23706. $this->y = $y;
  23707. if ($this->kwt_saved && $level==1) {
  23708. $this->printkwtbuffer();
  23709. $x0 = $x = $this->x;
  23710. $y0 = $y = $this->y;
  23711. $this->kwt_moved = false;
  23712. $this->kwt_saved = false;
  23713. }
  23714. // Set the Page & Column where table actually starts
  23715. if ($i==0 && $j==0 && $level==1) {
  23716. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  23717. $tablestartpage = 'EVEN';
  23718. }
  23719. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  23720. $tablestartpage = 'ODD';
  23721. }
  23722. else { $tablestartpage = ''; }
  23723. $tablestartpageno = $this->page;
  23724. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; } // *COLUMNS*
  23725. }
  23726. //ALIGN
  23727. $align = $cell['a'];
  23728. /*-- COLUMNS --*/
  23729. // If outside columns, this is done in PaintDivBB
  23730. if ($this->ColActive) {
  23731. //OUTER FILL BGCOLOR of DIVS
  23732. if ($this->blklvl > 0 && ($j==0) && !$this->table_rotate && $level==1) {
  23733. $firstblockfill = $this->GetFirstBlockFill();
  23734. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  23735. $divh = $maxrowheight;
  23736. // Last row
  23737. if ((!isset($cell['rowspan']) && $i == $numrows-1) || (isset($cell['rowspan']) && (($i == $numrows-1 && $cell['rowspan']<2) || ($cell['rowspan']>1 && ($i + $cell['rowspan']-1) == $numrows-1)))) { // mPDF 5.6.54
  23738. if ($table['borders_separate']) {
  23739. $adv = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23740. }
  23741. else {
  23742. $adv = $table['margin']['B'] + $table['max_cell_border_width']['B']/2;
  23743. }
  23744. $divh += $adv; //last row: fill bottom half of bottom border (y advanced at end)
  23745. }
  23746. if (($this->y + $divh) > $outerfilled ) { // if not already painted by previous rowspan
  23747. $bak_x = $this->x;
  23748. $bak_y = $this->y;
  23749. if ($outerfilled > $this->y) {
  23750. $divh = ($this->y + $divh) - $outerfilled;
  23751. $this->y = $outerfilled;
  23752. }
  23753. $this->DivLn($divh,-3,false);
  23754. $outerfilled = $this->y + $divh;
  23755. // Reset current block fill
  23756. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  23757. if ($bcor ) $this->SetFColor($bcor);
  23758. $this->x = $bak_x;
  23759. $this->y = $bak_y;
  23760. }
  23761. }
  23762. }
  23763. }
  23764. //TABLE BACKGROUND FILL BGCOLOR - for cellSpacing
  23765. if ($this->ColActive) {
  23766. if ($table['borders_separate']) {
  23767. $fill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  23768. if ($fill) {
  23769. $color = $this->ConvertColor($fill);
  23770. if ($color) {
  23771. $xadj = ($table['border_spacing_H']/2);
  23772. $yadj = ($table['border_spacing_V']/2);
  23773. $wadj = $table['border_spacing_H'];
  23774. $hadj = $table['border_spacing_V'];
  23775. if ($i == 0) { // Top
  23776. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  23777. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  23778. }
  23779. if ($j == 0) { // Left
  23780. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  23781. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  23782. }
  23783. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows)) { // Bottom
  23784. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  23785. }
  23786. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right
  23787. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  23788. }
  23789. $this->SetFColor($color);
  23790. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  23791. }
  23792. }
  23793. }
  23794. }
  23795. /*-- END COLUMNS --*/
  23796. if ($table['empty_cells']!='hide' || !empty($cell['textbuffer']) || (isset($cell['nestedcontent']) && $cell['nestedcontent']) || !$table['borders_separate'] ) { $paintcell = true; }
  23797. else { $paintcell = false; }
  23798. //Set Borders
  23799. $bord = 0;
  23800. $bord_det = array();
  23801. if (!$this->simpleTables){
  23802. if ($this->packTableData) {
  23803. if ($cell['borderbin']) {
  23804. $c = $this->_unpackCellBorder($cell['borderbin']);
  23805. $bord = $c['border'];
  23806. $bord_det = $c['border_details'];
  23807. }
  23808. }
  23809. else if ($cell['border']) {
  23810. $bord = $cell['border'];
  23811. $bord_det = $cell['border_details'];
  23812. }
  23813. }
  23814. else if ($this->simpleTables){
  23815. if ($table['simple']['border']) {
  23816. $bord = $table['simple']['border'];
  23817. $bord_det = $table['simple']['border_details'];
  23818. }
  23819. }
  23820. //TABLE ROW OR CELL FILL BGCOLOR
  23821. $fill = 0;
  23822. if (isset($cell['bgcolor']) && $cell['bgcolor'] && $cell['bgcolor']!='transparent') {
  23823. $fill = $cell['bgcolor'];
  23824. $leveladj = 6;
  23825. }
  23826. else if (isset($table['bgcolor'][$i]) && $table['bgcolor'][$i] && $table['bgcolor'][$i]!='transparent') { // Row color
  23827. $fill = $table['bgcolor'][$i];
  23828. $leveladj = 3;
  23829. }
  23830. if ($fill && $paintcell) {
  23831. $color = $this->ConvertColor($fill);
  23832. if ($color) {
  23833. if ($table['borders_separate']) {
  23834. if ($this->ColActive) {
  23835. $this->SetFColor($color);
  23836. $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');
  23837. }
  23838. else {
  23839. $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);
  23840. }
  23841. }
  23842. else {
  23843. if ($this->ColActive) {
  23844. $this->SetFColor($color);
  23845. $this->Rect($x, $y, $w, $h, 'F');
  23846. }
  23847. else {
  23848. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  23849. }
  23850. }
  23851. }
  23852. }
  23853. /*-- BACKGROUNDS --*/
  23854. if (isset($cell['gradient']) && $cell['gradient'] && $paintcell){
  23855. $g = $this->grad->parseBackgroundGradient($cell['gradient']);
  23856. if ($g) {
  23857. if ($table['borders_separate']) {
  23858. $px = $x+ ($table['border_spacing_H']/2);
  23859. $py = $y+ ($table['border_spacing_V']/2);
  23860. $pw = $w- $table['border_spacing_H'];
  23861. $ph = $h- $table['border_spacing_V'];
  23862. }
  23863. else {
  23864. $px = $x;
  23865. $py = $y;
  23866. $pw = $w;
  23867. $ph = $h;
  23868. }
  23869. if ($this->ColActive) {
  23870. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  23871. }
  23872. else {
  23873. $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'=>'');
  23874. }
  23875. }
  23876. }
  23877. if (isset($cell['background-image']) && $paintcell) {
  23878. if ($cell['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $cell['background-image']['gradient'] )) {
  23879. $g = $this->grad->parseMozGradient( $cell['background-image']['gradient'] );
  23880. if ($g) {
  23881. if ($table['borders_separate']) {
  23882. $px = $x+ ($table['border_spacing_H']/2);
  23883. $py = $y+ ($table['border_spacing_V']/2);
  23884. $pw = $w- $table['border_spacing_H'];
  23885. $ph = $h- $table['border_spacing_V'];
  23886. }
  23887. else {
  23888. $px = $x;
  23889. $py = $y;
  23890. $pw = $w;
  23891. $ph = $h;
  23892. }
  23893. if ($this->ColActive) {
  23894. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  23895. }
  23896. else {
  23897. $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'=>'');
  23898. }
  23899. }
  23900. }
  23901. else if ($cell['background-image']['image_id']) { // Background pattern
  23902. $n = count($this->patterns)+1;
  23903. if ($table['borders_separate']) {
  23904. $px = $x+ ($table['border_spacing_H']/2);
  23905. $py = $y+ ($table['border_spacing_V']/2);
  23906. $pw = $w- $table['border_spacing_H'];
  23907. $ph = $h- $table['border_spacing_V'];
  23908. }
  23909. else {
  23910. $px = $x;
  23911. $py = $y;
  23912. $pw = $w;
  23913. $ph = $h;
  23914. }
  23915. if ($this->ColActive) {
  23916. 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']);
  23917. $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);
  23918. if ($cell['background-image']['opacity']>0 && $cell['background-image']['opacity']<1) { $opac = $this->SetAlpha($cell['background-image']['opacity'],'Normal',true); }
  23919. else { $opac = ''; }
  23920. $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $px*_MPDFK, ($this->h-$py)*_MPDFK, $pw*_MPDFK, -$ph*_MPDFK));
  23921. }
  23922. else {
  23923. $image_id = $cell['background-image']['image_id'];
  23924. $orig_w = $cell['background-image']['orig_w'];
  23925. $orig_h = $cell['background-image']['orig_h'];
  23926. $x_pos = $cell['background-image']['x_pos'];
  23927. $y_pos = $cell['background-image']['y_pos'];
  23928. $x_repeat = $cell['background-image']['x_repeat'];
  23929. $y_repeat = $cell['background-image']['y_repeat'];
  23930. $resize = $cell['background-image']['resize'];
  23931. $opacity = $cell['background-image']['opacity'];
  23932. $itype = $cell['background-image']['itype'];
  23933. $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, 'itype'=>$itype);
  23934. }
  23935. }
  23936. }
  23937. /*-- END BACKGROUNDS --*/
  23938. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  23939. else { $ccolsp = 1; }
  23940. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  23941. else { $crowsp = 1; }
  23942. // but still need to do this for repeated headers...
  23943. if (!$table['borders_separate'] && $this->tabletheadjustfinished && !$this->simpleTables){
  23944. if (isset($table['topntail']) && $table['topntail']) {
  23945. $bord_det['T'] = $this->border_details($table['topntail']);
  23946. $bord_det['T']['w'] /= $this->shrin_k;
  23947. $this->setBorder($bord, _BORDER_TOP);
  23948. }
  23949. if (isset($table['thead-underline']) && $table['thead-underline']) {
  23950. $bord_det['T'] = $this->border_details($table['thead-underline']);
  23951. $bord_det['T']['w'] /= $this->shrin_k;
  23952. $this->setBorder($bord, _BORDER_TOP);
  23953. }
  23954. }
  23955. //Get info of first row ==>> table header
  23956. //Use > 1 row if THEAD
  23957. if (isset($table['is_thead'][$i]) && $table['is_thead'][$i] && $level==1) {
  23958. if ($j==0) $tableheaderrowheight += $table['hr'][$i];
  23959. $tableheader[$i][0]['trbackground-images'] = (isset($table['trbackground-images'][$i]) ? $table['trbackground-images'][$i] : null);
  23960. $tableheader[$i][0]['trgradients'] = (isset($table['trgradients'][$i]) ? $table['trgradients'][$i] : null);
  23961. $tableheader[$i][0]['trbgcolor'] = (isset($table['bgcolor'][$i]) ? $table['bgcolor'][$i] : null);
  23962. $tableheader[$i][$j]['x'] = $x;
  23963. $tableheader[$i][$j]['y'] = $y;
  23964. $tableheader[$i][$j]['h'] = $h;
  23965. $tableheader[$i][$j]['w'] = $w;
  23966. if (isset($cell['textbuffer'])) { $tableheader[$i][$j]['textbuffer'] = $cell['textbuffer']; }
  23967. else { $tableheader[$i][$j]['textbuffer'] = ''; }
  23968. $tableheader[$i][$j]['a'] = $cell['a'];
  23969. $tableheader[$i][$j]['R'] = $cell['R'];
  23970. $tableheader[$i][$j]['va'] = $cell['va'];
  23971. $tableheader[$i][$j]['mih'] = $cell['mih'];
  23972. $tableheader[$i][$j]['gradient'] = (isset($cell['gradient']) ? $cell['gradient'] : null); // *BACKGROUNDS*
  23973. $tableheader[$i][$j]['background-image'] = (isset($cell['background-image']) ? $cell['background-image'] : null); // *BACKGROUNDS*
  23974. $tableheader[$i][$j]['rowspan'] = (isset($cell['rowspan']) ? $cell['rowspan'] : null);
  23975. $tableheader[$i][$j]['colspan'] = (isset($cell['colspan']) ? $cell['colspan'] : null);
  23976. $tableheader[$i][$j]['bgcolor'] = $cell['bgcolor'];
  23977. if (!$this->simpleTables){
  23978. $tableheader[$i][$j]['border'] = $bord;
  23979. $tableheader[$i][$j]['border_details'] = $bord_det;
  23980. }
  23981. else if ($this->simpleTables){
  23982. $tableheader[$i][$j]['border'] = $table['simple']['border'];
  23983. $tableheader[$i][$j]['border_details'] = $table['simple']['border_details'];
  23984. }
  23985. $tableheader[$i][$j]['padding'] = $cell['padding'];
  23986. }
  23987. // CELL BORDER
  23988. if ($bord || $bord_det) {
  23989. if ($table['borders_separate'] && $paintcell) {
  23990. $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']);
  23991. }
  23992. else if (!$table['borders_separate']) {
  23993. $this->_tableRect($x, $y, $w, $h, $bord, $bord_det, true, $table['borders_separate']); // true causes buffer
  23994. }
  23995. }
  23996. //VERTICAL ALIGN
  23997. if ($cell['R'] && INTVAL($cell['R']) > 0 && INTVAL($cell['R']) < 90 && isset($cell['va']) && $cell['va']!='B') { $cell['va']='B';}
  23998. if (!isset($cell['va']) || $cell['va']=='M') $this->y += ($h-$cell['mih'])/2;
  23999. elseif (isset($cell['va']) && $cell['va']=='B') $this->y += $h-$cell['mih'];
  24000. // NESTED CONTENT
  24001. // TEXT (and nested tables)
  24002. $this->divalign=$align;
  24003. $this->divwidth=$w;
  24004. if (!empty($cell['textbuffer'])) {
  24005. if ($level==1) {
  24006. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) {
  24007. if (preg_match('/{colsum([0-9]*)[_]*}/', $cell['textbuffer'][0][0], $m)) {
  24008. $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$j]);
  24009. $cell['textbuffer'][0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$cell['textbuffer'][0][0]);
  24010. }
  24011. }
  24012. else if (!isset($table['is_thead'][$i])) { $this->colsums[$j] += floatval(preg_replace('/^[^0-9\.\,]*/','',$cell['textbuffer'][0][0])); } // mPDF 5.6.66
  24013. }
  24014. $opy = $this->y;
  24015. // mPDF ITERATION
  24016. if ($this->iterationCounter) {
  24017. foreach($cell['textbuffer'] AS $k=>$t) {
  24018. if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t[0], $m)) {
  24019. $vname = '__'.$m[1].'_';
  24020. if (!isset($this->$vname)) { $this->$vname = 1; }
  24021. else { $this->$vname++; }
  24022. $cell['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $cell['textbuffer'][$k][0]);
  24023. }
  24024. }
  24025. }
  24026. if ($cell['R']) {
  24027. $cellPtSize = $cell['textbuffer'][0][11] / $this->shrin_k;
  24028. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  24029. $cellFontHeight = ($cellPtSize/_MPDFK);
  24030. $opx = $this->x;
  24031. $angle = INTVAL($cell['R']);
  24032. // Only allow 45 to 89 degrees (when bottom-aligned) or exactly 90 or -90
  24033. if ($angle > 90) { $angle = 90; }
  24034. else if ($angle > 0 && $angle <45) { $angle = 45; }
  24035. else if ($angle < 0) { $angle = -90; }
  24036. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  24037. if (isset($cell['a']) && $cell['a']=='R') {
  24038. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($cell['padding']['R'] + ($table['border_spacing_H']/2));
  24039. }
  24040. else if (!isset($cell['a']) || $cell['a']=='C') {
  24041. $this->x += ($w/2) + ($offset);
  24042. }
  24043. else {
  24044. $this->x += ($offset) + ($cellFontHeight/3)+($cell['padding']['L'] +($table['border_spacing_H']/2));
  24045. }
  24046. $str = '';
  24047. foreach($cell['textbuffer'] AS $t) { $str .= $t[0].' '; }
  24048. $str = trim($str);
  24049. if (!isset($cell['va']) || $cell['va']=='M') {
  24050. $this->y -= ($h-$cell['mih'])/2; //Undo what was added earlier VERTICAL ALIGN
  24051. if ($angle > 0) { $this->y += (($h-$cell['mih'])/2) + $cell['padding']['T'] + ($cell['mih']-($cell['padding']['T'] + $cell['padding']['B'])); }
  24052. else if ($angle < 0) { $this->y += (($h-$cell['mih'])/2)+ ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24053. }
  24054. elseif (isset($cell['va']) && $cell['va']=='B') {
  24055. $this->y -= $h-$cell['mih']; //Undo what was added earlier VERTICAL ALIGN
  24056. if ($angle > 0) { $this->y += $h-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  24057. else if ($angle < 0) { $this->y += $h-$cell['mih'] + ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24058. }
  24059. elseif (isset($cell['va']) && $cell['va']=='T') {
  24060. if ($angle > 0) { $this->y += $cell['mih']-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  24061. else if ($angle < 0) { $this->y += ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24062. }
  24063. $this->Rotate($angle,$this->x,$this->y);
  24064. $s_fs = $this->FontSizePt;
  24065. $s_f = $this->FontFamily;
  24066. $s_st = $this->FontStyle;
  24067. if (!empty($cell['textbuffer'][0][3])) { //Font Color
  24068. $cor = $cell['textbuffer'][0][3];
  24069. $this->SetTColor($cor);
  24070. }
  24071. $s_str = $this->strike;
  24072. $this->strike = $cell['textbuffer'][0][8]; //Strikethrough
  24073. $this->SetFont($cell['textbuffer'][0][4],$cell['textbuffer'][0][2],$cellPtSize,true,true);
  24074. $this->Text($this->x,$this->y,$str);
  24075. $this->Rotate(0);
  24076. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  24077. $this->SetTColor(0);
  24078. $this->strike = $s_str;
  24079. $this->x = $opx;
  24080. }
  24081. else {
  24082. if (!$this->simpleTables){
  24083. if ($bord_det) {
  24084. $btlw = $bord_det['L']['w'];
  24085. $btrw = $bord_det['R']['w'];
  24086. $bttw = $bord_det['T']['w'];
  24087. }
  24088. else {
  24089. $btlw = 0;
  24090. $btrw = 0;
  24091. $bttw = 0;
  24092. }
  24093. if ($table['borders_separate']) {
  24094. $xadj = $btlw + $cell['padding']['L'] +($table['border_spacing_H']/2);
  24095. $wadj = $btlw + $btrw + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  24096. $yadj = $bttw + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  24097. }
  24098. else {
  24099. $xadj = $btlw/2 + $cell['padding']['L'];
  24100. $wadj = ($btlw + $btrw)/2 + $cell['padding']['L'] + $cell['padding']['R'];
  24101. $yadj = $bttw/2 + $cell['padding']['T'];
  24102. }
  24103. }
  24104. else if ($this->simpleTables){
  24105. if ($table['borders_separate']) { // NB twice border width
  24106. $xadj = $table['simple']['border_details']['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2);
  24107. $wadj = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  24108. $yadj = $table['simple']['border_details']['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  24109. }
  24110. else {
  24111. $xadj = $table['simple']['border_details']['L']['w']/2 + $cell['padding']['L'];
  24112. $wadj = ($table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R'];
  24113. $yadj = $table['simple']['border_details']['T']['w']/2 + $cell['padding']['T'];
  24114. }
  24115. }
  24116. // mPDF 5.6.13
  24117. $this->decimal_offset = 0;
  24118. if(substr($cell['a'],0,1) == 'D') {
  24119. if ($cell['colspan'] > 1) { $this->divalign = $c['a'] = substr($cell['a'],2,1); }
  24120. else {
  24121. $smax = $table['decimal_align'][$j]['maxs0'];
  24122. $d_content = $table['decimal_align'][$j]['maxs0'] + $table['decimal_align'][$j]['maxs1'];
  24123. $this->decimal_offset = $smax;
  24124. $extra = ($w - $d_content - $wadj);
  24125. if ($extra > 0) {
  24126. if(substr($cell['a'],2,1) == 'R') { $this->decimal_offset += $extra; }
  24127. else if(substr($cell['a'],2,1) == 'C') { $this->decimal_offset += ($extra)/2; }
  24128. }
  24129. }
  24130. }
  24131. $this->divwidth=$w-$wadj;
  24132. if ($this->divwidth == 0) { $this->divwidth = 0.0001; }
  24133. $this->x += $xadj;
  24134. $this->y += $yadj;
  24135. $this->printbuffer($cell['textbuffer'],'',true);
  24136. }
  24137. $this->y = $opy;
  24138. }
  24139. /*-- BACKGROUNDS --*/
  24140. if (!$this->ColActive) {
  24141. if (isset($table['trgradients'][$i]) && ($j==0 || $table['borders_separate'])) {
  24142. $g = $this->grad->parseBackgroundGradient($table['trgradients'][$i]);
  24143. if ($g) {
  24144. $gx = $x0;
  24145. $gy = $y;
  24146. $gh = $h;
  24147. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24148. if ($table['borders_separate']) {
  24149. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24150. $s = '';
  24151. $clx = $x+ ($table['border_spacing_H']/2);
  24152. $cly = $y+ ($table['border_spacing_V']/2);
  24153. $clw = $w- $table['border_spacing_H'];
  24154. $clh = $h- $table['border_spacing_V'];
  24155. // Set clipping path
  24156. $s = ' q 0 w '; // Line width=0
  24157. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  24158. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24159. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24160. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24161. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24162. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24163. $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);
  24164. }
  24165. else {
  24166. $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'=>'');
  24167. }
  24168. }
  24169. }
  24170. if (isset($table['trbackground-images'][$i]) && ($j==0 || $table['borders_separate'])) {
  24171. if ($table['trbackground-images'][$i]['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['trbackground-images'][$i]['gradient'] )) {
  24172. $g = $this->grad->parseMozGradient( $table['trbackground-images'][$i]['gradient'] );
  24173. if ($g) {
  24174. $gx = $x0;
  24175. $gy = $y;
  24176. $gh = $h;
  24177. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24178. if ($table['borders_separate']) {
  24179. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24180. $s = '';
  24181. $clx = $x+ ($table['border_spacing_H']/2);
  24182. $cly = $y+ ($table['border_spacing_V']/2);
  24183. $clw = $w- $table['border_spacing_H'];
  24184. $clh = $h- $table['border_spacing_V'];
  24185. // Set clipping path
  24186. $s = ' q 0 w '; // Line width=0
  24187. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  24188. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24189. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24190. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24191. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24192. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24193. $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);
  24194. }
  24195. else {
  24196. $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'=>'');
  24197. }
  24198. }
  24199. }
  24200. else {
  24201. $image_id = $table['trbackground-images'][$i]['image_id'];
  24202. $orig_w = $table['trbackground-images'][$i]['orig_w'];
  24203. $orig_h = $table['trbackground-images'][$i]['orig_h'];
  24204. $x_pos = $table['trbackground-images'][$i]['x_pos'];
  24205. $y_pos = $table['trbackground-images'][$i]['y_pos'];
  24206. $x_repeat = $table['trbackground-images'][$i]['x_repeat'];
  24207. $y_repeat = $table['trbackground-images'][$i]['y_repeat'];
  24208. $resize = $table['trbackground-images'][$i]['resize'];
  24209. $opacity = $table['trbackground-images'][$i]['opacity'];
  24210. $itype = $table['trbackground-images'][$i]['itype'];
  24211. $clippath = '';
  24212. $gx = $x0;
  24213. $gy = $y;
  24214. $gh = $h;
  24215. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24216. if ($table['borders_separate']) {
  24217. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24218. $s = '';
  24219. $clx = $x + ($table['border_spacing_H']/2);
  24220. $cly = $y + ($table['border_spacing_V']/2);
  24221. $clw = $w - $table['border_spacing_H'];
  24222. $clh = $h - $table['border_spacing_V'];
  24223. // Set clipping path
  24224. $s = ' q 0 w '; // Line width=0
  24225. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL
  24226. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24227. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24228. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24229. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24230. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24231. $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, 'itype'=>$itype);
  24232. }
  24233. else {
  24234. $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, 'itype'=>$itype);
  24235. }
  24236. }
  24237. }
  24238. }
  24239. /*-- END BACKGROUNDS --*/
  24240. // TABLE BORDER - if separate
  24241. if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) {
  24242. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  24243. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  24244. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  24245. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  24246. $tbx = $x;
  24247. $tby = $y;
  24248. $tbw = $w;
  24249. $tbh = $h;
  24250. $tab_bord = 0;
  24251. $corner = '';
  24252. if ($i == 0) { // Top
  24253. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  24254. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  24255. $this->setBorder($tab_bord , _BORDER_TOP);
  24256. $corner .= 'T';
  24257. }
  24258. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows)) { // Bottom
  24259. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  24260. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  24261. $corner .= 'B';
  24262. }
  24263. if ($j == 0) { // Left
  24264. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  24265. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  24266. $this->setBorder($tab_bord , _BORDER_LEFT);
  24267. $corner .= 'L';
  24268. }
  24269. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols)) { // Right
  24270. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  24271. $this->setBorder($tab_bord , _BORDER_RIGHT);
  24272. $corner .= 'R';
  24273. }
  24274. $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'] );
  24275. }
  24276. unset($cell );
  24277. //Reset values
  24278. $this->Reset();
  24279. }//end of (if isset(cells)...)
  24280. }// end of columns
  24281. $newpagestarted = false;
  24282. $this->tabletheadjustfinished = false;
  24283. if ($this->ColActive && $i < $numrows-1 && $level==1) { $this->breakpoints[$this->CurrCol][] = $y + $h; } // *COLUMNS*
  24284. /*-- COLUMNS --*/
  24285. if ($this->ColActive) {
  24286. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24287. }
  24288. /*-- END COLUMNS --*/
  24289. if ($i == $numrows-1) { $this->y = $y + $h; } //last row jump (update this->y position)
  24290. if ($this->table_rotate && $level==1) {
  24291. $this->tbrot_h += $h;
  24292. }
  24293. }// end of rows
  24294. if ($this->progressBar) { $this->UpdateProgressBar(7,70,' '); } // *PROGRESS-BAR*
  24295. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24296. if ($this->tableClipPath ) { $this->_out("Q"); }
  24297. $this->tableClipPath = '';
  24298. // Advance down page by half width of bottom border
  24299. if ($table['borders_separate']) { $this->y += $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; }
  24300. else { $this->y += $table['max_cell_border_width']['B']/2; }
  24301. 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; }
  24302. else if ($level==1) { $this->tbrot_h += $table['margin']['B'] + $table['max_cell_border_width']['B']/2; }
  24303. $bx = $x0;
  24304. $by = $y0;
  24305. if ($table['borders_separate']) {
  24306. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  24307. if ($tablestartpageno != $this->page) { // IF broken across page
  24308. $by += $table['max_cell_border_width']['T']/2;
  24309. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  24310. }
  24311. else if ($split && $startrow > 0 && empty($tableheader)) {
  24312. $by -= ($table['border_spacing_V']/2);
  24313. }
  24314. else {
  24315. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  24316. }
  24317. }
  24318. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  24319. $by -= $tableheaderadj;
  24320. $bh = $this->y - $by;
  24321. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  24322. if ($split) {
  24323. $bw = 0;
  24324. $finalSpread = true;
  24325. for($t=$startcol; $t<$numcols; $t++) {
  24326. if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; }
  24327. if ($table['colPg'][$t] > $splitpg) { $finalSpread = false; break; }
  24328. }
  24329. if ($startcol==0) { $firstSpread = true; }
  24330. else { $firstSpread = false; }
  24331. if ($table['borders_separate']) {
  24332. $bw += $table['border_spacing_H'];
  24333. if ($firstSpread) {
  24334. $bw += $table['padding']['L'] + $table['border_details']['L']['w'];
  24335. }
  24336. else {
  24337. $bx += ($table['padding']['L'] + $table['border_details']['L']['w']);
  24338. }
  24339. if ($finalSpread) {
  24340. $bw += $table['padding']['R'] + $table['border_details']['R']['w'];
  24341. }
  24342. }
  24343. }
  24344. else {
  24345. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24346. }
  24347. if (!$this->ColActive) {
  24348. if (isset($table['bgcolor'][-1])) {
  24349. $color = $this->ConvertColor($table['bgcolor'][-1]);
  24350. if ($color) {
  24351. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  24352. }
  24353. }
  24354. /*-- BACKGROUNDS --*/
  24355. if (isset($table['gradient'])) {
  24356. $g = $this->grad->parseBackgroundGradient($table['gradient']);
  24357. if ($g) {
  24358. $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'=>'');
  24359. }
  24360. }
  24361. if (isset($table['background-image'])) {
  24362. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  24363. $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] );
  24364. if ($g) {
  24365. $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'=>'');
  24366. }
  24367. }
  24368. else {
  24369. $image_id = $table['background-image']['image_id'];
  24370. $orig_w = $table['background-image']['orig_w'];
  24371. $orig_h = $table['background-image']['orig_h'];
  24372. $x_pos = $table['background-image']['x_pos'];
  24373. $y_pos = $table['background-image']['y_pos'];
  24374. $x_repeat = $table['background-image']['x_repeat'];
  24375. $y_repeat = $table['background-image']['y_repeat'];
  24376. $resize = $table['background-image']['resize'];
  24377. $opacity = $table['background-image']['opacity'];
  24378. $itype = $table['background-image']['itype'];
  24379. $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, 'itype'=>$itype);
  24380. }
  24381. }
  24382. /*-- END BACKGROUNDS --*/
  24383. }
  24384. if ($this->tableBackgrounds && $level == 1) {
  24385. $s = $this->PrintTableBackgrounds();
  24386. if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  24387. $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->tablebuffer);
  24388. if ($level == 1) { $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->tablebuffer); }
  24389. }
  24390. else if ($this->bufferoutput) {
  24391. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  24392. if ($level == 1) { $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer ); }
  24393. }
  24394. else {
  24395. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  24396. if ($level == 1) { $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]); }
  24397. }
  24398. $this->tableBackgrounds = array();
  24399. }
  24400. // TABLE BOTTOM MARGIN
  24401. if ($table['margin']['B']) {
  24402. if (!$this->table_rotate && $level==1) {
  24403. $this->DivLn($table['margin']['B'],$this->blklvl,true); // collapsible
  24404. }
  24405. else {
  24406. $this->y += ($table['margin']['B']);
  24407. }
  24408. }
  24409. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  24410. if ($this->cacheTables) { fclose($fh); }
  24411. if ($split) {
  24412. // Are there more columns to print on a next page?
  24413. if ($lastCol < $numcols-1) {
  24414. $splitpg++;
  24415. $startcol = $lastCol + 1;
  24416. return array(false, $startrow, $startcol, $splitpg, $returny, $y0);
  24417. }
  24418. else {
  24419. if ($this->cacheTables) {
  24420. unlink($table['cache']);
  24421. @unlink($table['cache'].'.bak');
  24422. }
  24423. return array(true,0,0,0);
  24424. }
  24425. }
  24426. if ($this->cacheTables) {
  24427. unlink($table['cache']);
  24428. @unlink($table['cache'].'.bak');
  24429. }
  24430. }//END OF FUNCTION _tableWrite()
  24431. /////////////////////////END OF TABLE CODE//////////////////////////////////
  24432. /*-- END TABLES --*/
  24433. function _putextgstates() {
  24434. for ($i = 1; $i <= count($this->extgstates); $i++) {
  24435. $this->_newobj();
  24436. $this->extgstates[$i]['n'] = $this->n;
  24437. $this->_out('<</Type /ExtGState');
  24438. foreach ($this->extgstates[$i]['parms'] as $k=>$v)
  24439. $this->_out('/'.$k.' '.$v);
  24440. $this->_out('>>');
  24441. $this->_out('endobj');
  24442. }
  24443. }
  24444. function _putocg() {
  24445. if ($this->hasOC) { // mPDF 5.6.01
  24446. $this->_newobj();
  24447. $this->n_ocg_print=$this->n;
  24448. $this->_out('<</Type /OCG /Name '.$this->_textstring('Print only'));
  24449. $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
  24450. $this->_out('endobj');
  24451. $this->_newobj();
  24452. $this->n_ocg_view=$this->n;
  24453. $this->_out('<</Type /OCG /Name '.$this->_textstring('Screen only'));
  24454. $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
  24455. $this->_out('endobj');
  24456. $this->_newobj();
  24457. $this->n_ocg_hidden=$this->n;
  24458. $this->_out('<</Type /OCG /Name '.$this->_textstring('Hidden'));
  24459. $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /OFF>>>>>>');
  24460. $this->_out('endobj');
  24461. }
  24462. // mPDF 5.6.01 Add Layers
  24463. if (count($this->layers)) {
  24464. ksort($this->layers);
  24465. foreach($this->layers as $id=>$layer) {
  24466. $this->_newobj();
  24467. $this->layers[$id]['n'] = $this->n;
  24468. // mPDF 5.6.28
  24469. if (isset($this->layerDetails[$id]['name']) && $this->layerDetails[$id]['name']) {
  24470. $name = $this->layerDetails[$id]['name'];
  24471. }
  24472. else { $name = $layer['name']; }
  24473. $this->_out('<</Type /OCG /Name '.$this->_UTF16BEtextstring($name).'>>');
  24474. $this->_out('endobj');
  24475. }
  24476. }
  24477. }
  24478. /*-- IMPORTS --*/
  24479. // from mPDFI
  24480. function _putimportedobjects() {
  24481. if (is_array($this->parsers) && count($this->parsers) > 0) {
  24482. foreach($this->parsers AS $filename => $p) {
  24483. $this->current_parser =& $this->parsers[$filename];
  24484. if (is_array($this->_obj_stack[$filename])) {
  24485. while($n = key($this->_obj_stack[$filename])) {
  24486. $nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c,$this->_obj_stack[$filename][$n][1]);
  24487. $this->_newobj($this->_obj_stack[$filename][$n][0]);
  24488. if ($nObj[0] == PDF_TYPE_STREAM) {
  24489. $this->pdf_write_value($nObj);
  24490. }
  24491. else {
  24492. $this->pdf_write_value($nObj[1]);
  24493. }
  24494. $this->_out('endobj');
  24495. $this->_obj_stack[$filename][$n] = null; // free memory
  24496. unset($this->_obj_stack[$filename][$n]);
  24497. reset($this->_obj_stack[$filename]);
  24498. }
  24499. }
  24500. }
  24501. }
  24502. }
  24503. function _putformxobjects() {
  24504. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  24505. reset($this->tpls);
  24506. foreach($this->tpls AS $tplidx => $tpl) {
  24507. $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
  24508. $this->_newobj();
  24509. $this->tpls[$tplidx]['n'] = $this->n;
  24510. $this->_out('<<'.$filter.'/Type /XObject');
  24511. $this->_out('/Subtype /Form');
  24512. $this->_out('/FormType 1');
  24513. // Left/Bottom/Right/Top
  24514. $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
  24515. $tpl['box']['x']*_MPDFK,
  24516. $tpl['box']['y']*_MPDFK,
  24517. ($tpl['box']['x'] + $tpl['box']['w'])*_MPDFK,
  24518. ($tpl['box']['y'] + $tpl['box']['h'])*_MPDFK )
  24519. );
  24520. if (isset($tpl['box']))
  24521. $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',-$tpl['box']['x']*_MPDFK, -$tpl['box']['y']*_MPDFK));
  24522. $this->_out('/Resources ');
  24523. if (isset($tpl['resources'])) {
  24524. $this->current_parser =& $tpl['parser'];
  24525. $this->pdf_write_value($tpl['resources']);
  24526. } else {
  24527. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24528. if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
  24529. $this->_out('/Font <<');
  24530. foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
  24531. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24532. $this->_out('>>');
  24533. }
  24534. if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
  24535. isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
  24536. {
  24537. $this->_out('/XObject <<');
  24538. if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
  24539. foreach($this->_res['tpl'][$tplidx]['images'] as $image)
  24540. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  24541. }
  24542. if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
  24543. foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $itpl)
  24544. $this->_out($this->tplprefix.$i.' '.$itpl['n'].' 0 R');
  24545. }
  24546. $this->_out('>>');
  24547. }
  24548. $this->_out('>>');
  24549. }
  24550. $this->_out('/Length '.strlen($p).' >>');
  24551. $this->_putstream($p);
  24552. $this->_out('endobj');
  24553. }
  24554. }
  24555. /*-- END IMPORTS --*/
  24556. function _putpatterns() {
  24557. for ($i = 1; $i <= count($this->patterns); $i++) {
  24558. $x = $this->patterns[$i]['x'];
  24559. $y = $this->patterns[$i]['y'];
  24560. $w = $this->patterns[$i]['w'];
  24561. $h = $this->patterns[$i]['h'];
  24562. $pgh = $this->patterns[$i]['pgh'];
  24563. $orig_w = $this->patterns[$i]['orig_w'];
  24564. $orig_h = $this->patterns[$i]['orig_h'];
  24565. $image_id = $this->patterns[$i]['image_id'];
  24566. $itype = $this->patterns[$i]['itype'];
  24567. $bpa = $this->patterns[$i]['bpa']; // mPDF 5.6.10 background positioning area
  24568. if ($this->patterns[$i]['x_repeat']) { $x_repeat = true; }
  24569. else { $x_repeat = false; }
  24570. if ($this->patterns[$i]['y_repeat']) { $y_repeat = true; }
  24571. else { $y_repeat = false; }
  24572. $x_pos = $this->patterns[$i]['x_pos'];
  24573. if (stristr($x_pos ,'%') ) {
  24574. $x_pos += 0;
  24575. $x_pos /= 100;
  24576. if (isset($bpa['w']) && $bpa['w']) $x_pos = ($bpa['w'] * $x_pos) - ($orig_w/_MPDFK * $x_pos); // mPDF 5.6.10
  24577. else $x_pos = ($w * $x_pos) - ($orig_w/_MPDFK * $x_pos);
  24578. }
  24579. $y_pos = $this->patterns[$i]['y_pos'];
  24580. if (stristr($y_pos ,'%') ) {
  24581. $y_pos += 0;
  24582. $y_pos /= 100;
  24583. if (isset($bpa['h']) && $bpa['h']) $y_pos = ($bpa['h'] * $y_pos) - ($orig_h/_MPDFK * $y_pos); // mPDF 5.6.10
  24584. else $y_pos = ($h * $y_pos) - ($orig_h/_MPDFK * $y_pos);
  24585. }
  24586. if (isset($bpa['x']) && $bpa['x']) $adj_x = ($x_pos + $bpa['x']) *_MPDFK; // mPDF 5.6.10
  24587. else $adj_x = ($x_pos + $x) *_MPDFK;
  24588. if (isset($bpa['y']) && $bpa['y']) $adj_y = (($pgh - $y_pos - $bpa['y'])*_MPDFK) - $orig_h ; // mPDF 5.6.10
  24589. else $adj_y = (($pgh - $y_pos - $y)*_MPDFK) - $orig_h ;
  24590. $img_obj = false;
  24591. if ($itype == 'svg' || $itype == 'wmf') {
  24592. foreach($this->formobjects AS $fo) {
  24593. if ($fo['i'] == $image_id) {
  24594. $img_obj = $fo['n'];
  24595. $fo_w = $fo['w'];
  24596. $fo_h = -$fo['h'];
  24597. $wmf_x = $fo['x'];
  24598. $wmf_y = $fo['y'];
  24599. break;
  24600. }
  24601. }
  24602. }
  24603. else {
  24604. foreach($this->images AS $img) {
  24605. if ($img['i'] == $image_id) { $img_obj = $img['n']; break; }
  24606. }
  24607. }
  24608. if (!$img_obj ) { echo "Problem: Image object not found for background pattern ".$img['i']; exit; }
  24609. $this->_newobj();
  24610. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24611. if ($itype == 'svg' || $itype == 'wmf') {
  24612. $this->_out('/XObject <</FO'.$image_id.' '.$img_obj.' 0 R >>');
  24613. // ******* ADD ANY ExtGStates, Shading AND Fonts needed for the FormObject
  24614. // Set in classes/svg array['fo'] = true
  24615. // Required that _putshaders comes before _putpatterns in _putresources
  24616. // This adds any resources associated with any FormObject to every Formobject - overkill but works!
  24617. if (count($this->extgstates)) {
  24618. $this->_out('/ExtGState <<');
  24619. foreach($this->extgstates as $k=>$extgstate)
  24620. if (isset($extgstate['fo']) && $extgstate['fo']) {
  24621. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  24622. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  24623. }
  24624. $this->_out('>>');
  24625. }
  24626. /*-- BACKGROUNDS --*/
  24627. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  24628. $this->_out('/Shading <<');
  24629. foreach ($this->gradients as $id => $grad) {
  24630. if (isset($grad['fo']) && $grad['fo']) {
  24631. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  24632. }
  24633. }
  24634. $this->_out('>>');
  24635. }
  24636. /*-- END BACKGROUNDS --*/
  24637. $this->_out('/Font <<');
  24638. foreach($this->fonts as $font) {
  24639. if (!$font['used'] && $font['type']=='TTF') { continue; }
  24640. if (isset($font['fo']) && $font['fo']) {
  24641. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) {
  24642. foreach($font['n'] AS $k => $fid) {
  24643. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  24644. }
  24645. }
  24646. else {
  24647. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24648. }
  24649. }
  24650. }
  24651. $this->_out('>>');
  24652. }
  24653. else {
  24654. $this->_out('/XObject <</I'.$image_id.' '.$img_obj.' 0 R >>');
  24655. }
  24656. $this->_out('>>');
  24657. $this->_out('endobj');
  24658. $this->_newobj();
  24659. $this->patterns[$i]['n'] = $this->n;
  24660. $this->_out('<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 2');
  24661. $this->_out('/Resources '. ($this->n-1) .' 0 R');
  24662. $this->_out(sprintf('/BBox [0 0 %.3F %.3F]',$orig_w,$orig_h));
  24663. if ($x_repeat) { $this->_out(sprintf('/XStep %.3F',$orig_w)); }
  24664. else { $this->_out(sprintf('/XStep %d',99999)); }
  24665. if ($y_repeat) { $this->_out(sprintf('/YStep %.3F',$orig_h)); }
  24666. else { $this->_out(sprintf('/YStep %d',99999)); }
  24667. if ($itype == 'svg' || $itype == 'wmf') {
  24668. $this->_out(sprintf('/Matrix [1 0 0 -1 %.3F %.3F]', $adj_x, ($adj_y+$orig_h)));
  24669. $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);
  24670. }
  24671. else {
  24672. $this->_out(sprintf('/Matrix [1 0 0 1 %.3F %.3F]',$adj_x,$adj_y));
  24673. $s = sprintf("q %.3F 0 0 %.3F 0 0 cm /I%d Do Q",$orig_w,$orig_h,$image_id);
  24674. }
  24675. if ($this->compress) {
  24676. $this->_out('/Filter /FlateDecode');
  24677. $s = gzcompress($s);
  24678. }
  24679. $this->_out('/Length '.strlen($s).'>>');
  24680. $this->_putstream($s);
  24681. $this->_out('endobj');
  24682. }
  24683. }
  24684. /*-- BACKGROUNDS --*/
  24685. function _putshaders() {
  24686. $maxid = count($this->gradients); //index for transparency gradients
  24687. foreach ($this->gradients as $id => $grad) {
  24688. if (($grad['type'] == 2 || $grad['type'] == 3) && empty($grad['is_mask'])) {
  24689. $this->_newobj();
  24690. $this->_out('<<');
  24691. $this->_out('/FunctionType 3');
  24692. $this->_out('/Domain [0 1]');
  24693. $fn = array();
  24694. $bd = array();
  24695. $en = array();
  24696. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24697. $fn[] = ($this->n+1+$i).' 0 R';
  24698. $en[] = '0 1';
  24699. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  24700. }
  24701. $this->_out('/Functions ['.implode(' ',$fn).']');
  24702. $this->_out('/Bounds ['.implode(' ',$bd).']');
  24703. $this->_out('/Encode ['.implode(' ',$en).']');
  24704. $this->_out('>>');
  24705. $this->_out('endobj');
  24706. $f1 = $this->n;
  24707. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24708. $this->_newobj();
  24709. $this->_out('<<');
  24710. $this->_out('/FunctionType 2');
  24711. $this->_out('/Domain [0 1]');
  24712. $this->_out('/C0 ['.$grad['stops'][$i]['col'].']');
  24713. $this->_out('/C1 ['.$grad['stops'][$i+1]['col'].']');
  24714. $this->_out('/N 1');
  24715. $this->_out('>>');
  24716. $this->_out('endobj');
  24717. }
  24718. }
  24719. if ($grad['type'] == 2 || $grad['type'] == 3) {
  24720. if (isset($grad['trans']) && $grad['trans']) {
  24721. $this->_newobj();
  24722. $this->_out('<<');
  24723. $this->_out('/FunctionType 3');
  24724. $this->_out('/Domain [0 1]');
  24725. $fn = array();
  24726. $bd = array();
  24727. $en = array();
  24728. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24729. $fn[] = ($this->n+1+$i).' 0 R';
  24730. $en[] = '0 1';
  24731. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  24732. }
  24733. $this->_out('/Functions ['.implode(' ',$fn).']');
  24734. $this->_out('/Bounds ['.implode(' ',$bd).']');
  24735. $this->_out('/Encode ['.implode(' ',$en).']');
  24736. $this->_out('>>');
  24737. $this->_out('endobj');
  24738. $f2 = $this->n;
  24739. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  24740. $this->_newobj();
  24741. $this->_out('<<');
  24742. $this->_out('/FunctionType 2');
  24743. $this->_out('/Domain [0 1]');
  24744. $this->_out(sprintf('/C0 [%.3F]', $grad['stops'][$i]['opacity']));
  24745. $this->_out(sprintf('/C1 [%.3F]', $grad['stops'][$i+1]['opacity']));
  24746. $this->_out('/N 1');
  24747. $this->_out('>>');
  24748. $this->_out('endobj');
  24749. }
  24750. }
  24751. }
  24752. if (empty($grad['is_mask'])) {
  24753. $this->_newobj();
  24754. $this->_out('<<');
  24755. $this->_out('/ShadingType '.$grad['type']);
  24756. if (isset($grad['colorspace'])) {
  24757. $this->_out('/ColorSpace /Device'.$grad['colorspace']); // Can use CMYK if all C0 and C1 above have 4 values
  24758. } else {
  24759. $this->_out('/ColorSpace /DeviceRGB');
  24760. }
  24761. if ($grad['type'] == 2) {
  24762. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  24763. $this->_out('/Function '.$f1.' 0 R');
  24764. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24765. $this->_out('>>');
  24766. }
  24767. else if ($grad['type'] == 3) {
  24768. //x0, y0, r0, x1, y1, r1
  24769. //at this this time radius of inner circle is 0
  24770. $ir = 0;
  24771. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  24772. $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]));
  24773. $this->_out('/Function '.$f1.' 0 R');
  24774. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24775. $this->_out('>>');
  24776. }
  24777. else if ($grad['type']==6) {
  24778. $this->_out('/BitsPerCoordinate 16');
  24779. $this->_out('/BitsPerComponent 8');
  24780. if ($grad['colorspace'] == 'CMYK') { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1 0 1]'); }
  24781. else if ($grad['colorspace'] == 'Gray') { $this->_out('/Decode[0 1 0 1 0 1]'); }
  24782. else { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]'); }
  24783. $this->_out('/BitsPerFlag 8');
  24784. $this->_out('/Length '.strlen($grad['stream']));
  24785. $this->_out('>>');
  24786. $this->_putstream($grad['stream']);
  24787. }
  24788. $this->_out('endobj');
  24789. }
  24790. $this->gradients[$id]['id'] = $this->n;
  24791. // set pattern object
  24792. $this->_newobj();
  24793. $out = '<< /Type /Pattern /PatternType 2';
  24794. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  24795. $out .= ' >>';
  24796. $out .= "\n".'endobj';
  24797. $this->_out($out);
  24798. $this->gradients[$id]['pattern'] = $this->n;
  24799. if (isset($grad['trans']) && $grad['trans']) {
  24800. // luminosity pattern
  24801. $transid = $id + $maxid;
  24802. $this->_newobj();
  24803. $this->_out('<<');
  24804. $this->_out('/ShadingType '.$grad['type']);
  24805. $this->_out('/ColorSpace /DeviceGray');
  24806. if ($grad['type'] == 2) {
  24807. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  24808. $this->_out('/Function '.$f2.' 0 R');
  24809. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24810. $this->_out('>>');
  24811. }
  24812. else if ($grad['type'] == 3) {
  24813. //x0, y0, r0, x1, y1, r1
  24814. //at this this time radius of inner circle is 0
  24815. $ir = 0;
  24816. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  24817. $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]));
  24818. $this->_out('/Function '.$f2.' 0 R');
  24819. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  24820. $this->_out('>>');
  24821. }
  24822. else if ($grad['type']==6) {
  24823. $this->_out('/BitsPerCoordinate 16');
  24824. $this->_out('/BitsPerComponent 8');
  24825. $this->_out('/Decode[0 1 0 1 0 1]');
  24826. $this->_out('/BitsPerFlag 8');
  24827. $this->_out('/Length '.strlen($grad['stream_trans']));
  24828. $this->_out('>>');
  24829. $this->_putstream($grad['stream_trans']);
  24830. }
  24831. $this->_out('endobj');
  24832. $this->gradients[$transid]['id'] = $this->n;
  24833. $this->_newobj();
  24834. $this->_out('<< /Type /Pattern /PatternType 2');
  24835. $this->_out('/Shading '.$this->gradients[$transid]['id'].' 0 R');
  24836. $this->_out('>>');
  24837. $this->_out('endobj');
  24838. $this->gradients[$transid]['pattern'] = $this->n;
  24839. $this->_newobj();
  24840. // Need to extend size of viewing box in case of transformations
  24841. $str = 'q /a0 gs /Pattern cs /p'.$transid.' scn -'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).' re f Q';
  24842. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  24843. $p=($this->compress) ? gzcompress($str) : $str;
  24844. $this->_out('<< /Type /XObject /Subtype /Form /FormType 1 '.$filter);
  24845. $this->_out('/Length '.strlen($p));
  24846. $this->_out('/BBox [-'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).']');
  24847. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >>');
  24848. $this->_out('/Resources <<');
  24849. $this->_out('/ExtGState << /a0 << /ca 1 /CA 1 >> >>');
  24850. $this->_out('/Pattern << /p'.$transid.' '.$this->gradients[$transid]['pattern'].' 0 R >>');
  24851. $this->_out('>>');
  24852. $this->_out('>>');
  24853. $this->_putstream($p);
  24854. $this->_out('endobj');
  24855. $this->_newobj();
  24856. $this->_out('<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj');
  24857. $this->_newobj();
  24858. $this->_out('<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj');
  24859. if ($grad['fo']) { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id, 'fo'=>true); }
  24860. else { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id); }
  24861. }
  24862. }
  24863. }
  24864. /*-- END BACKGROUNDS --*/
  24865. function _putspotcolors() {
  24866. foreach($this->spotColors as $name=>$color) {
  24867. $this->_newobj();
  24868. $this->_out('[/Separation /'.str_replace(' ','#20',$name));
  24869. $this->_out('/DeviceCMYK <<');
  24870. $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  24871. $this->_out(sprintf('/C1 [%.3F %.3F %.3F %.3F] ',$color['c']/100,$color['m']/100,$color['y']/100,$color['k']/100));
  24872. $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  24873. $this->_out('endobj');
  24874. $this->spotColors[$name]['n']=$this->n;
  24875. }
  24876. }
  24877. function _putresources() {
  24878. if ($this->hasOC || count($this->layers)) // mPDF 5.6.01
  24879. $this->_putocg();
  24880. $this->_putextgstates();
  24881. $this->_putspotcolors();
  24882. if ($this->progressBar) { $this->UpdateProgressBar(2,'40','Compiling Fonts'); } // *PROGRESS-BAR*
  24883. $this->_putfonts();
  24884. if ($this->progressBar) { $this->UpdateProgressBar(2,'50','Compiling Images'); } // *PROGRESS-BAR*
  24885. $this->_putimages();
  24886. $this->_putformobjects(); // *IMAGES-CORE*
  24887. /*-- IMPORTS --*/
  24888. if ($this->enableImports) {
  24889. $this->_putformxobjects();
  24890. $this->_putimportedobjects();
  24891. }
  24892. /*-- END IMPORTS --*/
  24893. /*-- BACKGROUNDS --*/
  24894. $this->_putshaders();
  24895. $this->_putpatterns();
  24896. /*-- END BACKGROUNDS --*/
  24897. //Resource dictionary
  24898. $this->offsets[2]=strlen($this->buffer);
  24899. $this->_out('2 0 obj');
  24900. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24901. $this->_out('/Font <<');
  24902. foreach($this->fonts as $font) {
  24903. if (!$font['used'] && $font['type']=='TTF') { continue; }
  24904. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) {
  24905. foreach($font['n'] AS $k => $fid) {
  24906. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  24907. }
  24908. }
  24909. else {
  24910. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24911. }
  24912. }
  24913. $this->_out('>>');
  24914. if (count($this->spotColors)) {
  24915. $this->_out('/ColorSpace <<');
  24916. foreach($this->spotColors as $color)
  24917. $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  24918. $this->_out('>>');
  24919. }
  24920. if (count($this->extgstates)) {
  24921. $this->_out('/ExtGState <<');
  24922. foreach($this->extgstates as $k=>$extgstate)
  24923. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  24924. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  24925. $this->_out('>>');
  24926. }
  24927. /*-- BACKGROUNDS --*/
  24928. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  24929. $this->_out('/Shading <<');
  24930. foreach ($this->gradients as $id => $grad) {
  24931. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  24932. }
  24933. $this->_out('>>');
  24934. /*
  24935. // ??? Not needed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  24936. $this->_out('/Pattern <<');
  24937. foreach ($this->gradients as $id => $grad) {
  24938. $this->_out('/P'.$id.' '.$grad['pattern'].' 0 R');
  24939. }
  24940. $this->_out('>>');
  24941. */
  24942. }
  24943. /*-- END BACKGROUNDS --*/
  24944. if(count($this->images) || count($this->formobjects) || ($this->enableImports && count($this->tpls))) {
  24945. $this->_out('/XObject <<');
  24946. foreach($this->images as $image)
  24947. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  24948. foreach($this->formobjects as $formobject)
  24949. $this->_out('/FO'.$formobject['i'].' '.$formobject['n'].' 0 R');
  24950. /*-- IMPORTS --*/
  24951. if ($this->enableImports && count($this->tpls)) {
  24952. foreach($this->tpls as $tplidx => $tpl) {
  24953. $this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R');
  24954. }
  24955. }
  24956. /*-- END IMPORTS --*/
  24957. $this->_out('>>');
  24958. }
  24959. /*-- BACKGROUNDS --*/
  24960. if (count($this->patterns)) {
  24961. $this->_out('/Pattern <<');
  24962. foreach($this->patterns as $k=>$patterns)
  24963. $this->_out('/P'.$k.' '.$patterns['n'].' 0 R');
  24964. $this->_out('>>');
  24965. }
  24966. /*-- END BACKGROUNDS --*/
  24967. // mPDF 5.6.01
  24968. if ($this->hasOC || count($this->layers)) {
  24969. $this->_out('/Properties <<');
  24970. if ($this->hasOC) {
  24971. $this->_out('/OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R /OC3 '.$this->n_ocg_hidden.' 0 R ');
  24972. }
  24973. if (count($this->layers)) {
  24974. foreach($this->layers as $id=>$layer)
  24975. $this->_out('/ZI'.$id.' '.$layer['n'].' 0 R');
  24976. }
  24977. $this->_out('>>');
  24978. }
  24979. $this->_out('>>');
  24980. $this->_out('endobj'); // end resource dictionary
  24981. $this->_putbookmarks(); // *BOOKMARKS*
  24982. if (isset($this->js) && $this->js) {
  24983. $this->_putjavascript();
  24984. }
  24985. /*-- ENCRYPTION --*/
  24986. if ($this->encrypted) {
  24987. $this->_newobj();
  24988. $this->enc_obj_id = $this->n;
  24989. $this->_out('<<');
  24990. $this->_putencryption();
  24991. $this->_out('>>');
  24992. $this->_out('endobj');
  24993. }
  24994. /*-- END ENCRYPTION --*/
  24995. }
  24996. function _putjavascript() {
  24997. $this->_newobj();
  24998. $this->n_js = $this->n;
  24999. $this->_out('<<');
  25000. $this->_out('/Names [(EmbeddedJS) '.(1 + $this->n).' 0 R ]');
  25001. $this->_out('>>');
  25002. $this->_out('endobj');
  25003. $this->_newobj();
  25004. $this->_out('<<');
  25005. $this->_out('/S /JavaScript');
  25006. $this->_out('/JS '.$this->_textstring($this->js));
  25007. $this->_out('>>');
  25008. $this->_out('endobj');
  25009. }
  25010. /*-- ENCRYPTION --*/
  25011. function _putencryption() {
  25012. $this->_out('/Filter /Standard');
  25013. if ($this->useRC128encryption) {
  25014. $this->_out('/V 2');
  25015. $this->_out('/R 3');
  25016. $this->_out('/Length 128');
  25017. }
  25018. else {
  25019. $this->_out('/V 1');
  25020. $this->_out('/R 2');
  25021. }
  25022. $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  25023. $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  25024. $this->_out('/P '.$this->Pvalue);
  25025. }
  25026. /*-- END ENCRYPTION --*/
  25027. function _puttrailer() {
  25028. $this->_out('/Size '.($this->n+1));
  25029. $this->_out('/Root '.$this->n.' 0 R');
  25030. $this->_out('/Info '.$this->InfoRoot.' 0 R');
  25031. /*-- ENCRYPTION --*/
  25032. if ($this->encrypted) {
  25033. $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  25034. $this->_out('/ID [<'.$this->uniqid.'> <'.$this->uniqid.'>]');
  25035. }
  25036. else {
  25037. /*-- END ENCRYPTION --*/
  25038. $uniqid = md5(time() . $this->buffer);
  25039. $this->_out('/ID [<'.$uniqid.'> <'.$uniqid.'>]');
  25040. /*-- ENCRYPTION --*/
  25041. }
  25042. /*-- END ENCRYPTION --*/
  25043. }
  25044. /*-- ENCRYPTION --*/
  25045. function SetProtection($permissions=array(),$user_pass='',$owner_pass=null, $length=40) {
  25046. $this->encrypted=false;
  25047. if (is_string($permissions) && strlen($permissions)>0) { $permissions = array($permissions); }
  25048. else if (!is_array($permissions)) { return 0; }
  25049. $this->last_rc4_key='';
  25050. $this->padding="\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
  25051. "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  25052. $options = array(
  25053. 'print' => 4, // bit 3
  25054. 'modify' => 8, // bit 4
  25055. 'copy' => 16, // bit 5
  25056. 'annot-forms' => 32, // bit 6
  25057. 'fill-forms' => 256, // bit 9
  25058. 'extract' => 512, // bit 10
  25059. 'assemble' => 1024,// bit 11
  25060. 'print-highres' => 2048 // bit 12
  25061. );
  25062. // bit 31 = 1073741824
  25063. // bit 32 = 2147483648
  25064. // bits 13-31 = 2147479552
  25065. // bits 13-32 = 4294963200 + 192 = 4294963392
  25066. $protection = 4294963392; // bits 7,8,13-32
  25067. foreach ($permissions as $permission) {
  25068. if (!isset($options[$permission]))
  25069. $this->Error('Incorrect permission: '.$permission);
  25070. if ($options[$permission] > 32) { $this->useRC128encryption = true; }
  25071. if (isset($options[$permission])) $protection += $options[$permission];
  25072. }
  25073. if ($length==128) { $this->useRC128encryption = true; }
  25074. if ($owner_pass === null)
  25075. $owner_pass = uniqid(rand());
  25076. $this->encrypted = true;
  25077. $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
  25078. }
  25079. // Compute key depending on object number where the encrypted data is stored
  25080. function _objectkey($n) {
  25081. if ($this->useRC128encryption)
  25082. $len = 16;
  25083. else
  25084. $len = 10;
  25085. return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,$len);
  25086. }
  25087. // RC4 is the standard encryption algorithm used in PDF format
  25088. function _RC4($key, $text) {
  25089. if ($this->last_rc4_key != $key) {
  25090. $k = str_repeat($key, 256/strlen($key)+1);
  25091. $rc4 = range(0,255);
  25092. $j = 0;
  25093. for ($i=0; $i<256; $i++){
  25094. $t = $rc4[$i];
  25095. $j = ($j + $t + ord($k[$i])) % 256;
  25096. $rc4[$i] = $rc4[$j];
  25097. $rc4[$j] = $t;
  25098. }
  25099. $this->last_rc4_key = $key;
  25100. $this->last_rc4_key_c = $rc4;
  25101. } else {
  25102. $rc4 = $this->last_rc4_key_c;
  25103. }
  25104. $len = strlen($text);
  25105. $a = 0;
  25106. $b = 0;
  25107. $out = '';
  25108. for ($i=0; $i<$len; $i++){
  25109. $a = ($a+1)%256;
  25110. $t= $rc4[$a];
  25111. $b = ($b+$t)%256;
  25112. $rc4[$a] = $rc4[$b];
  25113. $rc4[$b] = $t;
  25114. $k = $rc4[($rc4[$a]+$rc4[$b])%256];
  25115. $out.= chr(ord($text[$i]) ^ $k);
  25116. }
  25117. return $out;
  25118. }
  25119. // Get MD5 as binary string
  25120. function _md5_16($string) {
  25121. return pack('H*',md5($string));
  25122. }
  25123. // Compute O value
  25124. function _Ovalue($user_pass, $owner_pass) {
  25125. $tmp = $this->_md5_16($owner_pass);
  25126. if ($this->useRC128encryption) {
  25127. for ($i = 0; $i < 50; ++$i) {
  25128. $tmp = $this->_md5_16($tmp);
  25129. }
  25130. }
  25131. if ($this->useRC128encryption)
  25132. $keybytelen = (128 / 8);
  25133. else
  25134. $keybytelen = (40 / 8);
  25135. $owner_RC4_key = substr($tmp,0,$keybytelen);
  25136. $enc = $this->_RC4($owner_RC4_key, $user_pass);
  25137. if ($this->useRC128encryption) {
  25138. $len = strlen($owner_RC4_key);
  25139. for ($i = 1; $i <= 19; ++$i) {
  25140. $key = '';
  25141. for ($j = 0; $j < $len; ++$j) {
  25142. $key .= chr(ord($owner_RC4_key{$j}) ^ $i);
  25143. }
  25144. $enc = $this->_RC4($key, $enc);
  25145. }
  25146. }
  25147. return $enc;
  25148. }
  25149. // Compute U value
  25150. function _Uvalue() {
  25151. if ($this->useRC128encryption) {
  25152. $tmp = $this->_md5_16($this->padding.$this->_hexToString($this->uniqid));
  25153. $enc = $this->_RC4($this->encryption_key, $tmp);
  25154. $len = strlen($tmp);
  25155. for ($i=1; $i<=19; ++$i) {
  25156. $key = '';
  25157. for ($j=0; $j<$len; ++$j) {
  25158. $key .= chr(ord($this->encryption_key{$j}) ^ $i);
  25159. }
  25160. $enc = $this->_RC4($key, $enc);
  25161. }
  25162. $enc .= str_repeat("\x00", 16);
  25163. return substr($enc, 0, 32);
  25164. }
  25165. else {
  25166. return $this->_RC4($this->encryption_key, $this->padding);
  25167. }
  25168. }
  25169. // Compute encryption key
  25170. function _generateencryptionkey($user_pass, $owner_pass, $protection) {
  25171. // Pad passwords
  25172. $user_pass = substr($user_pass.$this->padding,0,32);
  25173. $owner_pass = substr($owner_pass.$this->padding,0,32);
  25174. $chars = 'ABCDEF1234567890';
  25175. $id = '';
  25176. for ($i=0; $i<32; $i++) { $id .= $chars{rand(0, 15)}; }
  25177. $this->uniqid = md5($id);
  25178. // Compute O value
  25179. $this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
  25180. // Compute encyption key
  25181. if ($this->useRC128encryption)
  25182. $keybytelen = (128/8);
  25183. else
  25184. $keybytelen = (40/8);
  25185. $prot = sprintf('%032b', $protection);
  25186. $perms = chr(bindec(substr($prot,24,8)));
  25187. $perms .= chr(bindec(substr($prot,16,8)));
  25188. $perms .= chr(bindec(substr($prot,8,8)));
  25189. $perms .= chr(bindec(substr($prot,0,8)));
  25190. $tmp = $this->_md5_16($user_pass.$this->Ovalue.$perms.$this->_hexToString($this->uniqid));
  25191. if ($this->useRC128encryption) {
  25192. for ($i=0; $i<50; ++$i) {
  25193. $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
  25194. }
  25195. }
  25196. $this->encryption_key = substr($tmp,0,$keybytelen);
  25197. // Compute U value
  25198. $this->Uvalue = $this->_Uvalue();
  25199. // Compute P value
  25200. $this->Pvalue = $protection;
  25201. }
  25202. function _hexToString($hs) {
  25203. $s = '';
  25204. $len = strlen($hs);
  25205. if (($len % 2) != 0) {
  25206. $hs .= '0';
  25207. ++$len;
  25208. }
  25209. for ($i = 0; $i < $len; $i += 2) {
  25210. $s .= chr(hexdec($hs{$i}.$hs{($i + 1)}));
  25211. }
  25212. return $s;
  25213. }
  25214. /*-- END ENCRYPTION --*/
  25215. //=========================================
  25216. /*-- BOOKMARKS --*/
  25217. // FROM class PDF_Bookmark
  25218. function Bookmark($txt,$level=0,$y=0) {
  25219. $txt = $this->purify_utf8_text($txt);
  25220. if ($this->text_input_as_HTML) {
  25221. $txt = $this->all_entities_to_utf8($txt);
  25222. }
  25223. if($y==-1) {
  25224. if (!$this->ColActive){ $y=$this->y; }
  25225. else { $y = $this->y0; } // If columns are on - mark top of columns
  25226. }
  25227. // else y is used as set, or =0 i.e. top of page
  25228. // DIRECTIONALITY RTL
  25229. $bmo = array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  25230. if ($this->keep_block_together) {
  25231. $this->ktBMoutlines[]= $bmo;
  25232. }
  25233. /*-- TABLES --*/
  25234. else if ($this->table_rotate) {
  25235. $this->tbrot_BMoutlines[]= $bmo;
  25236. }
  25237. else if ($this->kwt) {
  25238. $this->kwt_BMoutlines[]= $bmo;
  25239. }
  25240. /*-- END TABLES --*/
  25241. else if ($this->ColActive) { // *COLUMNS*
  25242. $this->col_BMoutlines[]= $bmo; // *COLUMNS*
  25243. } // *COLUMNS*
  25244. else {
  25245. $this->BMoutlines[]= $bmo;
  25246. }
  25247. }
  25248. function _putbookmarks()
  25249. {
  25250. $nb=count($this->BMoutlines);
  25251. if($nb==0)
  25252. return;
  25253. // mPDF 5.6.36
  25254. $bmo = $this->BMoutlines;
  25255. $this->BMoutlines = array();
  25256. $lastlevel = -1;
  25257. for($i=0;$i<count($bmo);$i++) {
  25258. if ($bmo[$i]['l']>0) {
  25259. while($bmo[$i]['l']-$lastlevel > 1) { // If jump down more than one level, insert a new entry
  25260. $new = $bmo[$i];
  25261. $new['t']="[".$new['t']."]"; // Put [] around text/title to highlight
  25262. $new['l']=$lastlevel+1;
  25263. $lastlevel++;
  25264. $this->BMoutlines[] = $new;
  25265. }
  25266. }
  25267. $this->BMoutlines[] = $bmo[$i];
  25268. $lastlevel = $bmo[$i]['l'];
  25269. }
  25270. $nb=count($this->BMoutlines);
  25271. $lru=array();
  25272. $level=0;
  25273. foreach($this->BMoutlines as $i=>$o) {
  25274. if($o['l']>0) {
  25275. $parent=$lru[$o['l']-1];
  25276. //Set parent and last pointers
  25277. $this->BMoutlines[$i]['parent']=$parent;
  25278. $this->BMoutlines[$parent]['last']=$i;
  25279. if($o['l']>$level) {
  25280. //Level increasing: set first pointer
  25281. $this->BMoutlines[$parent]['first']=$i;
  25282. }
  25283. }
  25284. else {
  25285. $this->BMoutlines[$i]['parent']=$nb;
  25286. }
  25287. if($o['l']<=$level and $i>0) {
  25288. //Set prev and next pointers
  25289. $prev=$lru[$o['l']];
  25290. $this->BMoutlines[$prev]['next']=$i;
  25291. $this->BMoutlines[$i]['prev']=$prev;
  25292. }
  25293. $lru[$o['l']]=$i;
  25294. $level=$o['l'];
  25295. }
  25296. //Outline items
  25297. $n=$this->n+1;
  25298. foreach($this->BMoutlines as $i=>$o) {
  25299. $this->_newobj();
  25300. $this->_out('<</Title '.$this->_UTF16BEtextstring($o['t']));
  25301. $this->_out('/Parent '.($n+$o['parent']).' 0 R');
  25302. if(isset($o['prev']))
  25303. $this->_out('/Prev '.($n+$o['prev']).' 0 R');
  25304. if(isset($o['next']))
  25305. $this->_out('/Next '.($n+$o['next']).' 0 R');
  25306. if(isset($o['first']))
  25307. $this->_out('/First '.($n+$o['first']).' 0 R');
  25308. if(isset($o['last']))
  25309. $this->_out('/Last '.($n+$o['last']).' 0 R');
  25310. if (isset($this->pageDim[$o['p']]['h'])) { $h=$this->pageDim[$o['p']]['h']; }
  25311. else { $h = 0; }
  25312. $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.3F null]',1+2*($o['p']),($h-$o['y'])*_MPDFK));
  25313. if (isset($this->bookmarkStyles) && isset($this->bookmarkStyles[$o['l']])) {
  25314. // font style
  25315. $bms = $this->bookmarkStyles[$o['l']]['style'];
  25316. $style = 0;
  25317. if (strpos($bms,'B') !== false) { $style += 2; }
  25318. if (strpos($bms,'I') !== false) { $style += 1; }
  25319. $this->_out(sprintf('/F %d', $style));
  25320. // Colour
  25321. $col = $this->bookmarkStyles[$o['l']]['color'];
  25322. if (isset($col) && is_array($col) && count($col)==3) {
  25323. $this->_out(sprintf('/C [%.3F %.3F %.3F]', ($col[0]/255), ($col[1]/255), ($col[2]/255)));
  25324. }
  25325. }
  25326. $this->_out('/Count 0>>');
  25327. $this->_out('endobj');
  25328. }
  25329. //Outline root
  25330. $this->_newobj();
  25331. $this->OutlineRoot=$this->n;
  25332. $this->_out('<</Type /BMoutlines /First '.$n.' 0 R');
  25333. $this->_out('/Last '.($n+$lru[0]).' 0 R>>');
  25334. $this->_out('endobj');
  25335. }
  25336. /*-- END BOOKMARKS --*/
  25337. //======================================================
  25338. // DEPRACATED but included for backwards compatability
  25339. function startPageNums() {
  25340. }
  25341. //======================================================
  25342. /*-- TOC --*/
  25343. // ToC TABLE OF CONTENTS
  25344. // Initiate, and Mark a place for the Table of Contents to be inserted
  25345. function TOC($tocfont='', $tocfontsize=0, $tocindent=0, $resetpagenum='', $pagenumstyle='', $suppress='', $toc_orientation='', $TOCusePaging=true, $TOCuseLinking=false, $toc_id=0, $tocoutdent='') { // mPDF 5.6.19
  25346. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25347. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25348. $this->tocontents->TOC($tocfont, $tocfontsize, $tocindent, $resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $TOCusePaging, $TOCuseLinking, $toc_id, $tocoutdent); // mPDF 5.6.19
  25349. }
  25350. function TOCpagebreakByArray($a) {
  25351. if (!is_array($a)) { $a = array(); }
  25352. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25353. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25354. $tocoutdent = (isset($a['tocoutdent']) ? $a['tocoutdent'] : (isset($a['outdent']) ? $a['outdent'] : ''));
  25355. $TOCusePaging = (isset($a['TOCusePaging']) ? $a['TOCusePaging'] : (isset($a['paging']) ? $a['paging'] : true));
  25356. $TOCuseLinking = (isset($a['TOCuseLinking']) ? $a['TOCuseLinking'] : (isset($a['links']) ? $a['links'] : ''));
  25357. $toc_orientation = (isset($a['toc_orientation']) ? $a['toc_orientation'] : (isset($a['toc-orientation']) ? $a['toc-orientation'] : ''));
  25358. $toc_mgl = (isset($a['toc_mgl']) ? $a['toc_mgl'] : (isset($a['toc-margin-left']) ? $a['toc-margin-left'] : ''));
  25359. $toc_mgr = (isset($a['toc_mgr']) ? $a['toc_mgr'] : (isset($a['toc-margin-right']) ? $a['toc-margin-right'] : ''));
  25360. $toc_mgt = (isset($a['toc_mgt']) ? $a['toc_mgt'] : (isset($a['toc-margin-top']) ? $a['toc-margin-top'] : ''));
  25361. $toc_mgb = (isset($a['toc_mgb']) ? $a['toc_mgb'] : (isset($a['toc-margin-bottom']) ? $a['toc-margin-bottom'] : ''));
  25362. $toc_mgh = (isset($a['toc_mgh']) ? $a['toc_mgh'] : (isset($a['toc-margin-header']) ? $a['toc-margin-header'] : ''));
  25363. $toc_mgf = (isset($a['toc_mgf']) ? $a['toc_mgf'] : (isset($a['toc-margin-footer']) ? $a['toc-margin-footer'] : ''));
  25364. $toc_ohname = (isset($a['toc_ohname']) ? $a['toc_ohname'] : (isset($a['toc-odd-header-name']) ? $a['toc-odd-header-name'] : ''));
  25365. $toc_ehname = (isset($a['toc_ehname']) ? $a['toc_ehname'] : (isset($a['toc-even-header-name']) ? $a['toc-even-header-name'] : ''));
  25366. $toc_ofname = (isset($a['toc_ofname']) ? $a['toc_ofname'] : (isset($a['toc-odd-footer-name']) ? $a['toc-odd-footer-name'] : ''));
  25367. $toc_efname = (isset($a['toc_efname']) ? $a['toc_efname'] : (isset($a['toc-even-footer-name']) ? $a['toc-even-footer-name'] : ''));
  25368. $toc_ohvalue = (isset($a['toc_ohvalue']) ? $a['toc_ohvalue'] : (isset($a['toc-odd-header-value']) ? $a['toc-odd-header-value'] : 0));
  25369. $toc_ehvalue = (isset($a['toc_ehvalue']) ? $a['toc_ehvalue'] : (isset($a['toc-even-header-value']) ? $a['toc-even-header-value'] : 0));
  25370. $toc_ofvalue = (isset($a['toc_ofvalue']) ? $a['toc_ofvalue'] : (isset($a['toc-odd-footer-value']) ? $a['toc-odd-footer-value'] : 0));
  25371. $toc_efvalue = (isset($a['toc_efvalue']) ? $a['toc_efvalue'] : (isset($a['toc-even-footer-value']) ? $a['toc-even-footer-value'] : 0));
  25372. $toc_preHTML = (isset($a['toc_preHTML']) ? $a['toc_preHTML'] : (isset($a['toc-preHTML']) ? $a['toc-preHTML'] : ''));
  25373. $toc_postHTML = (isset($a['toc_postHTML']) ? $a['toc_postHTML'] : (isset($a['toc-postHTML']) ? $a['toc-postHTML'] : ''));
  25374. $toc_bookmarkText = (isset($a['toc_bookmarkText']) ? $a['toc_bookmarkText'] : (isset($a['toc-bookmarkText']) ? $a['toc-bookmarkText'] : ''));
  25375. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  25376. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  25377. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  25378. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  25379. $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : ''));
  25380. $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : ''));
  25381. $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : ''));
  25382. $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : ''));
  25383. $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : ''));
  25384. $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : ''));
  25385. $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : ''));
  25386. $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : ''));
  25387. $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : ''));
  25388. $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : ''));
  25389. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0));
  25390. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0));
  25391. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0));
  25392. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0));
  25393. $toc_id = (isset($a['toc_id']) ? $a['toc_id'] : (isset($a['name']) ? $a['name'] : 0));
  25394. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : ''));
  25395. $toc_pagesel = (isset($a['toc_pagesel']) ? $a['toc_pagesel'] : (isset($a['toc-pageselector']) ? $a['toc-pageselector'] : ''));
  25396. $sheetsize = (isset($a['sheetsize']) ? $a['sheetsize'] : (isset($a['sheet-size']) ? $a['sheet-size'] : ''));
  25397. $toc_sheetsize = (isset($a['toc_sheetsize']) ? $a['toc_sheetsize'] : (isset($a['toc-sheet-size']) ? $a['toc-sheet-size'] : ''));
  25398. $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, $tocoutdent); // mPDF 5.6.19
  25399. }
  25400. 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='', $tocoutdent='') { // mPDF 5.6.19) {
  25401. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25402. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25403. //Start a new page
  25404. if($this->state==0) $this->AddPage();
  25405. if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) {
  25406. // Don't add a page
  25407. if ($this->page==1 && count($this->PageNumSubstitutions)==0) {
  25408. if (!$suppress) { $suppress = 'off'; }
  25409. if (!$resetpagenum) { $resetpagenum= 1; }
  25410. //$this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  25411. }
  25412. $this->PageNumSubstitutions[] = array('from'=>$this->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  25413. }
  25414. else {
  25415. $this->AddPage($orientation,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$sheetsize);
  25416. }
  25417. $this->tocontents->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, $tocoutdent); // mPDF 5.6.19
  25418. }
  25419. function TOC_Entry($txt, $level=0, $toc_id=0) {
  25420. $txt = $this->purify_utf8_text($txt);
  25421. if ($this->text_input_as_HTML) {
  25422. $txt = $this->all_entities_to_utf8($txt);
  25423. }
  25424. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  25425. if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  25426. // mPDF 5.6.19 mPDF 5.6.25 mPDF 5.6.37
  25427. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25428. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25429. $linkn = $this->AddLink();
  25430. $uid = '__mpdfinternallink_' . $linkn ;
  25431. if ($this->keep_block_together) { $this->internallink[$uid] = array("Y"=>$ily,"PAGE"=>$this->page, "kt"=>true ); }
  25432. else if ($this->table_rotate) { $this->internallink[$uid] = array("Y"=>$ily,"PAGE"=>$this->page, "tbrot"=>true ); }
  25433. else if ($this->kwt) { $this->internallink[$uid] = array("Y"=>$ily,"PAGE"=>$this->page, "kwt"=>true ); }
  25434. else if ($this->ColActive) { $this->internallink[$uid] = array("Y"=>$ily,"PAGE"=>$this->page, "col"=>$this->CurrCol ); }
  25435. else $this->internallink[$uid] = array("Y"=>$ily,"PAGE"=>$this->page );
  25436. $this->internallink['#'.$uid] = $linkn;
  25437. $this->SetLink($linkn,$ily,$this->page);
  25438. /*-- RTL --*/
  25439. if ($this->biDirectional) {
  25440. $txt = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $txt );
  25441. }
  25442. /*-- END RTL --*/
  25443. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  25444. else if (!$toc_id) { $toc_id = 0; }
  25445. else { $toc_id = strtolower($toc_id); }
  25446. $btoc = array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  25447. if ($this->keep_block_together) {
  25448. $this->_kttoc[]= $btoc;
  25449. }
  25450. /*-- TABLES --*/
  25451. else if ($this->table_rotate) {
  25452. $this->tbrot_toc[]= $btoc;
  25453. }
  25454. else if ($this->kwt) {
  25455. $this->kwt_toc[]= $btoc;
  25456. }
  25457. /*-- END TABLES --*/
  25458. else if ($this->ColActive) { // *COLUMNS*
  25459. $this->col_toc[]= $btoc; // *COLUMNS*
  25460. } // *COLUMNS*
  25461. else {
  25462. $this->tocontents->_toc[]= $btoc;
  25463. }
  25464. }
  25465. /*-- END TOC --*/
  25466. //======================================================
  25467. function MovePages($target_page, $start_page, $end_page=-1) {
  25468. // move a page/pages EARLIER in the document
  25469. if ($end_page<1) { $end_page = $start_page; }
  25470. $n_toc = $end_page - $start_page + 1;
  25471. // Set/Update PageNumSubstitutions changes before moving anything
  25472. if (count($this->PageNumSubstitutions)) {
  25473. $tp_present = false;
  25474. $sp_present = false;
  25475. $ep_present = false;
  25476. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25477. if ($this->PageNumSubstitutions[$k]['from']==$target_page) {
  25478. $tp_present = true;
  25479. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25480. $this->PageNumSubstitutions[$k]['suppress']='off';
  25481. }
  25482. }
  25483. if ($this->PageNumSubstitutions[$k]['from']==$start_page) {
  25484. $sp_present = true;
  25485. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25486. $this->PageNumSubstitutions[$k]['suppress']='off';
  25487. }
  25488. }
  25489. if ($this->PageNumSubstitutions[$k]['from']==($end_page+1)) {
  25490. $ep_present = true;
  25491. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25492. $this->PageNumSubstitutions[$k]['suppress']='off';
  25493. }
  25494. }
  25495. }
  25496. if (!$tp_present) {
  25497. list($tp_type, $tp_suppress, $tp_reset) = $this->docPageSettings($target_page);
  25498. }
  25499. if (!$sp_present) {
  25500. list($sp_type, $sp_suppress, $sp_reset) = $this->docPageSettings($start_page);
  25501. }
  25502. if (!$ep_present) {
  25503. list($ep_type, $ep_suppress, $ep_reset) = $this->docPageSettings($start_page-1);
  25504. }
  25505. }
  25506. $last = array();
  25507. //store pages
  25508. for($i = $start_page;$i <= $end_page ;$i++)
  25509. $last[]=$this->pages[$i];
  25510. //move pages
  25511. for($i=$start_page - 1;$i>=($target_page);$i--) {
  25512. $this->pages[$i+$n_toc]=$this->pages[$i];
  25513. }
  25514. //Put toc pages at insert point
  25515. for($i = 0;$i < $n_toc;$i++) {
  25516. $this->pages[$target_page + $i]=$last[$i];
  25517. }
  25518. /*-- BOOKMARKS --*/
  25519. // Update Bookmarks
  25520. foreach($this->BMoutlines as $i=>$o) {
  25521. if($o['p']>=$target_page) {
  25522. $this->BMoutlines[$i]['p'] += $n_toc;
  25523. }
  25524. }
  25525. /*-- END BOOKMARKS --*/
  25526. // Update Page Links
  25527. if (count($this->PageLinks)) {
  25528. $newarr = array();
  25529. foreach($this->PageLinks as $i=>$o) {
  25530. foreach($this->PageLinks[$i] as $key => $pl) {
  25531. if (strpos($pl[4],'@')===0) {
  25532. $p=substr($pl[4],1);
  25533. if($p>=$start_page && $p<=$end_page) {
  25534. $this->PageLinks[$i][$key][4] = '@'.($p + ($target_page - $start_page));
  25535. }
  25536. else if($p>=$target_page && $p<$start_page) {
  25537. $this->PageLinks[$i][$key][4] = '@'.($p+$n_toc);
  25538. }
  25539. }
  25540. }
  25541. if($i>=$start_page && $i<=$end_page) {
  25542. $newarr[($i + ($target_page - $start_page))] = $this->PageLinks[$i];
  25543. }
  25544. else if($i>=$target_page && $i<$start_page) {
  25545. $newarr[($i + $n_toc)] = $this->PageLinks[$i];
  25546. }
  25547. else {
  25548. $newarr[$i] = $this->PageLinks[$i];
  25549. }
  25550. }
  25551. $this->PageLinks = $newarr;
  25552. }
  25553. // OrientationChanges
  25554. if (count($this->OrientationChanges)) {
  25555. $newarr = array();
  25556. foreach($this->OrientationChanges AS $p=>$v) {
  25557. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->OrientationChanges[$p]; }
  25558. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->OrientationChanges[$p]; }
  25559. else { $newarr[$p] = $this->OrientationChanges[$p]; }
  25560. }
  25561. ksort($newarr);
  25562. $this->OrientationChanges = $newarr;
  25563. }
  25564. // Page Dimensions
  25565. if (count($this->pageDim)) {
  25566. $newarr = array();
  25567. foreach($this->pageDim AS $p=>$v) {
  25568. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->pageDim[$p]; }
  25569. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->pageDim[$p]; }
  25570. else { $newarr[$p] = $this->pageDim[$p]; }
  25571. }
  25572. ksort($newarr);
  25573. $this->pageDim = $newarr;
  25574. }
  25575. // HTML Headers & Footers
  25576. if (count($this->saveHTMLHeader)) {
  25577. $newarr = array();
  25578. foreach($this->saveHTMLHeader AS $p=>$v) {
  25579. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLHeader[$p]; }
  25580. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLHeader[$p]; }
  25581. else { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  25582. }
  25583. ksort($newarr);
  25584. $this->saveHTMLHeader = $newarr;
  25585. }
  25586. if (count($this->saveHTMLFooter)) {
  25587. $newarr = array();
  25588. foreach($this->saveHTMLFooter AS $p=>$v) {
  25589. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLFooter[$p]; }
  25590. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLFooter[$p]; }
  25591. else { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  25592. }
  25593. ksort($newarr);
  25594. $this->saveHTMLFooter = $newarr;
  25595. }
  25596. // Update Internal Links
  25597. if (count($this->internallink)) {
  25598. foreach($this->internallink as $key=>$o) {
  25599. if($o['PAGE']>=$start_page && $o['PAGE']<=$end_page) {
  25600. $this->internallink[$key]['PAGE'] += ($target_page - $start_page);
  25601. }
  25602. else if($o['PAGE']>=$target_page && $o['PAGE']<$start_page) {
  25603. $this->internallink[$key]['PAGE'] += $n_toc;
  25604. }
  25605. }
  25606. }
  25607. // Update Links
  25608. if (count($this->links)) {
  25609. foreach($this->links as $key=>$o) {
  25610. if($o[0]>=$start_page && $o[0]<=$end_page) {
  25611. $this->links[$key][0] += ($target_page - $start_page);
  25612. }
  25613. if($o[0]>=$target_page && $o[0]<$start_page) {
  25614. $this->links[$key][0] += $n_toc;
  25615. }
  25616. }
  25617. }
  25618. // Update Form fields
  25619. if (count($this->form->forms)) {
  25620. foreach($this->form->forms as $key=>$f) {
  25621. if($f['page']>=$start_page && $f['page']<=$end_page) {
  25622. $this->form->forms[$key]['page'] += ($target_page - $start_page);
  25623. }
  25624. if($f['page']>=$target_page && $f['page']<$start_page) {
  25625. $this->form->forms[$key]['page'] += $n_toc;
  25626. }
  25627. }
  25628. }
  25629. /*-- ANNOTATIONS --*/
  25630. // Update Annotations
  25631. if (count($this->PageAnnots)) {
  25632. $newarr = array();
  25633. foreach($this->PageAnnots as $p=>$anno) {
  25634. if($p>=$start_page && $p<=$end_page) {
  25635. $np = $p + ($target_page - $start_page);
  25636. foreach($anno as $o) {
  25637. $newarr[$np][] = $o;
  25638. }
  25639. }
  25640. else if($p>=$target_page && $p<$start_page) {
  25641. $np = $p + $n_toc;
  25642. foreach($anno as $o) {
  25643. $newarr[$np][] = $o;
  25644. }
  25645. }
  25646. else {
  25647. $newarr[$p] = $this->PageAnnots[$p];
  25648. }
  25649. }
  25650. $this->PageAnnots = $newarr;
  25651. unset($newarr);
  25652. }
  25653. /*-- END ANNOTATIONS --*/
  25654. // Update PageNumSubstitutions
  25655. if (count($this->PageNumSubstitutions)) {
  25656. $newarr = array();
  25657. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25658. if($this->PageNumSubstitutions[$k]['from']>=$start_page && $this->PageNumSubstitutions[$k]['from']<=$end_page) {
  25659. $this->PageNumSubstitutions[$k]['from'] += ($target_page - $start_page);
  25660. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25661. }
  25662. else if($this->PageNumSubstitutions[$k]['from']>=$target_page && $this->PageNumSubstitutions[$k]['from']<$start_page) {
  25663. $this->PageNumSubstitutions[$k]['from'] += $n_toc;
  25664. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25665. }
  25666. else {
  25667. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  25668. }
  25669. }
  25670. if (!$sp_present) {
  25671. $newarr[$target_page] = array('from'=>$target_page, 'suppress'=>$sp_suppress, 'reset'=>$sp_reset, 'type'=>$sp_type);
  25672. }
  25673. if (!$tp_present) {
  25674. $newarr[($target_page + $n_toc)] = array('from'=>($target_page+$n_toc), 'suppress'=>$tp_suppress, 'reset'=>$tp_reset, 'type'=>$tp_type);
  25675. }
  25676. if (!$ep_present && $end_page>count($this->pages)) {
  25677. $newarr[($end_page+1)] = array('from'=>($end_page+1), 'suppress'=>$ep_suppress, 'reset'=>$ep_reset, 'type'=>$ep_type);
  25678. }
  25679. ksort($newarr);
  25680. $this->PageNumSubstitutions = array();
  25681. foreach($newarr as $v) {
  25682. $this->PageNumSubstitutions[] = $v;
  25683. }
  25684. }
  25685. }
  25686. //======================================================
  25687. function DeletePages($start_page, $end_page=-1) {
  25688. // move a page/pages EARLIER in the document
  25689. if ($end_page<1) { $end_page = $start_page; }
  25690. $n_tod = $end_page - $start_page + 1;
  25691. $last_page = count($this->pages);
  25692. $n_atend = $last_page - $end_page + 1;
  25693. //move pages
  25694. for($i=0;$i<$n_atend;$i++) {
  25695. $this->pages[$start_page+$i]=$this->pages[$end_page+1+$i];
  25696. }
  25697. //delete pages
  25698. for($i = 0;$i < $n_tod ;$i++)
  25699. unset($this->pages[$last_page-$i]);
  25700. /*-- BOOKMARKS --*/
  25701. // Update Bookmarks
  25702. foreach($this->BMoutlines as $i=>$o) {
  25703. if($o['p']>=$end_page) { $this->BMoutlines[$i]['p'] -= $n_tod; }
  25704. else if($p<$start_page) { unset($this->BMoutlines[$i]); }
  25705. }
  25706. /*-- END BOOKMARKS --*/
  25707. // Update Page Links
  25708. if (count($this->PageLinks)) {
  25709. $newarr = array();
  25710. foreach($this->PageLinks as $i=>$o) {
  25711. foreach($this->PageLinks[$i] as $key => $pl) {
  25712. if (strpos($pl[4],'@')===0) {
  25713. $p=substr($pl[4],1);
  25714. if($p>$end_page) { $this->PageLinks[$i][$key][4] = '@'.($p - $n_tod); }
  25715. else if($p<$start_page) { unset($this->PageLinks[$i][$key]); }
  25716. }
  25717. }
  25718. if($i>$end_page) { $newarr[($i - $n_tod)] = $this->PageLinks[$i]; }
  25719. else if($p<$start_page) { $newarr[$i] = $this->PageLinks[$i]; }
  25720. }
  25721. $this->PageLinks = $newarr;
  25722. }
  25723. // OrientationChanges
  25724. if (count($this->OrientationChanges)) {
  25725. $newarr = array();
  25726. foreach($this->OrientationChanges AS $p=>$v) {
  25727. if($p>$end_page) { $newarr[($p - $t_tod)] = $this->OrientationChanges[$p]; }
  25728. else if($p<$start_page) { $newarr[$p] = $this->OrientationChanges[$p]; }
  25729. }
  25730. ksort($newarr);
  25731. $this->OrientationChanges = $newarr;
  25732. }
  25733. // Page Dimensions
  25734. if (count($this->pageDim)) {
  25735. $newarr = array();
  25736. foreach($this->pageDim AS $p=>$v) {
  25737. if($p>$end_page) { $newarr[($p - $n_tod)] = $this->pageDim[$p]; }
  25738. else if($p<$start_page) { $newarr[$p] = $this->pageDim[$p]; }
  25739. }
  25740. ksort($newarr);
  25741. $this->pageDim = $newarr;
  25742. }
  25743. // HTML Headers & Footers
  25744. if (count($this->saveHTMLHeader)) {
  25745. foreach($this->saveHTMLHeader AS $p=>$v) {
  25746. if($p>end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLHeader[$p]; }
  25747. else if($p<$start_page) { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  25748. }
  25749. ksort($newarr);
  25750. $this->saveHTMLHeader = $newarr;
  25751. }
  25752. if (count($this->saveHTMLFooter)) {
  25753. $newarr = array();
  25754. foreach($this->saveHTMLFooter AS $p=>$v) {
  25755. if($p>$end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLFooter[$p]; }
  25756. else if($p<$start_page) { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  25757. }
  25758. ksort($newarr);
  25759. $this->saveHTMLFooter = $newarr;
  25760. }
  25761. // Update Internal Links
  25762. foreach($this->internallink as $key=>$o) {
  25763. if($o['PAGE']>$end_page) { $this->internallink[$key]['PAGE'] -= $n_tod; }
  25764. else if($o['PAGE']<$start_page) { unset($this->internallink[$key]); }
  25765. }
  25766. // Update Links
  25767. foreach($this->links as $key=>$o) {
  25768. if($o[0]>$end_page) { $this->links[$key][0] -= $n_tod; }
  25769. else if($o[0]<$start_page) { unset($this->links[$key]); }
  25770. }
  25771. // Update Form fields
  25772. foreach($this->form->forms as $key=>$f) {
  25773. if($f['page']>$end_page) { $this->form->forms[$key]['page'] -= $n_tod; }
  25774. else if($f['page']<$start_page) { unset($this->form->forms[$key]); }
  25775. }
  25776. /*-- ANNOTATIONS --*/
  25777. // Update Annotations
  25778. if (count($this->PageAnnots)) {
  25779. $newarr = array();
  25780. foreach($this->PageAnnots as $p=>$anno) {
  25781. if($p>$end_page) { foreach($anno as $o) { $newarr[($p - $n_tod)][] = $o; } }
  25782. else if($p<$start_page) { $newarr[$p] = $this->PageAnnots[$p]; }
  25783. }
  25784. ksort($newarr);
  25785. $this->PageAnnots = $newarr;
  25786. }
  25787. /*-- END ANNOTATIONS --*/
  25788. // Update PageNumSubstitutions
  25789. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25790. if($this->PageNumSubstitutions[$k]['from']>$end_page) { $this->PageNumSubstitutions[$k]['from'] -= $n_tod; }
  25791. else if($this->PageNumSubstitutions[$k]['from']<$start_page) { unset($this->PageNumSubstitutions[$k]); }
  25792. }
  25793. unset($newarr);
  25794. $this->page = count($this->pages);
  25795. }
  25796. //======================================================
  25797. /*-- INDEX --*/
  25798. // FROM class PDF_Ref == INDEX
  25799. function Reference($txt) {
  25800. $this->IndexEntry($txt);
  25801. }
  25802. function IndexEntry($txt, $xref='') {
  25803. if ($xref) {
  25804. $this->IndexEntrySee($txt,$xref);
  25805. return;
  25806. }
  25807. $txt = strip_tags($txt);
  25808. $txt = $this->purify_utf8_text($txt);
  25809. if ($this->text_input_as_HTML) {
  25810. $txt = $this->all_entities_to_utf8($txt);
  25811. }
  25812. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  25813. $Present=0;
  25814. $size=sizeof($this->Reference);
  25815. if ($this->directionality == 'rtl') { // *RTL*
  25816. $txt = str_replace(':',' - ',$txt); // *RTL*
  25817. } // *RTL*
  25818. else { // *RTL*
  25819. $txt = str_replace(':',', ',$txt);
  25820. } // *RTL*
  25821. //Search the reference (AND Ref/PageNo) in the array
  25822. for ($i=0;$i<$size;$i++){
  25823. if ($this->keep_block_together) {
  25824. if (isset($this->ktReference[$i]['t']) && $this->ktReference[$i]['t']==$txt){
  25825. $Present=1;
  25826. if (!in_array($this->page,$this->ktReference[$i]['p'])) {
  25827. $this->ktReference[$i]['op'] = $this->page;
  25828. }
  25829. }
  25830. }
  25831. /*-- TABLES --*/
  25832. else if ($this->table_rotate) {
  25833. if (isset($this->tbrot_Reference[$i]['t']) && $this->tbrot_Reference[$i]['t']==$txt){
  25834. $Present=1;
  25835. if (!in_array($this->page,$this->tbrot_Reference[$i]['p'])) {
  25836. $this->tbrot_Reference[$i]['op'] = $this->page;
  25837. }
  25838. }
  25839. }
  25840. else if ($this->kwt) {
  25841. if (isset($this->kwt_Reference[$i]['t']) && $this->kwt_Reference[$i]['t']==$txt){
  25842. $Present=1;
  25843. if (!in_array($this->page,$this->kwt_Reference[$i]['p'])) {
  25844. $this->kwt_Reference[$i]['op'] = $this->page;
  25845. }
  25846. }
  25847. }
  25848. /*-- END TABLES --*/
  25849. /*-- COLUMNS --*/
  25850. else if ($this->ColActive) {
  25851. if (isset($this->col_Reference[$i]['t']) && $this->col_Reference[$i]['t']==$txt){
  25852. $Present=1;
  25853. if (!in_array($this->page,$this->col_Reference[$i]['p'])) {
  25854. $this->col_Reference[$i]['op'] = $this->page;
  25855. }
  25856. }
  25857. }
  25858. /*-- END COLUMNS --*/
  25859. else {
  25860. if (isset($this->Reference[$i]['t']) && $this->Reference[$i]['t']==$txt){
  25861. $Present=1;
  25862. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  25863. $this->Reference[$i]['p'][] = $this->page;
  25864. }
  25865. }
  25866. }
  25867. }
  25868. //If not found, add it
  25869. if ($Present==0) {
  25870. $opr = array('t'=>$txt, 'op'=>$this->page);
  25871. if ($this->keep_block_together) {
  25872. $this->ktReference[]= $opr;
  25873. }
  25874. /*-- TABLES --*/
  25875. else if ($this->table_rotate) {
  25876. $this->tbrot_Reference[]= $opr;
  25877. }
  25878. else if ($this->kwt) {
  25879. $this->kwt_Reference[]= $opr;
  25880. }
  25881. /*-- END TABLES --*/
  25882. /*-- COLUMNS --*/
  25883. else if ($this->ColActive) {
  25884. $this->col_Reference[]= $opr;
  25885. }
  25886. /*-- END COLUMNS --*/
  25887. else {
  25888. $this->Reference[]=array('t'=>$txt,'p'=>array($this->page));
  25889. }
  25890. }
  25891. }
  25892. // Added function to add a reference "Elephants. See Chickens"
  25893. function ReferenceSee($txta,$txtb) {
  25894. $this->IndexEntrySee($txta,$txtb);
  25895. }
  25896. function IndexEntrySee($txta,$txtb) {
  25897. $txta = strip_tags($txta);
  25898. $txtb = strip_tags($txtb);
  25899. $txta = $this->purify_utf8_text($txta);
  25900. $txtb = $this->purify_utf8_text($txtb);
  25901. if ($this->text_input_as_HTML) {
  25902. $txta = $this->all_entities_to_utf8($txta);
  25903. $txtb = $this->all_entities_to_utf8($txtb);
  25904. }
  25905. if ($this->usingCoreFont) {
  25906. $txta = mb_convert_encoding($txta,$this->mb_enc,'UTF-8');
  25907. $txtb = mb_convert_encoding($txtb,$this->mb_enc,'UTF-8');
  25908. }
  25909. if ($this->directionality == 'rtl') { // *RTL*
  25910. $txta = str_replace(':',' - ',$txta); // *RTL*
  25911. $txtb = str_replace(':',' - ',$txtb); // *RTL*
  25912. } // *RTL*
  25913. else { // *RTL*
  25914. $txta = str_replace(':',', ',$txta);
  25915. $txtb = str_replace(':',', ',$txtb);
  25916. } // *RTL*
  25917. $this->Reference[]=array('t'=>$txta.' - see '.$txtb,'p'=>array());
  25918. }
  25919. function CreateReference($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  25920. $this->CreateIndex($NbCol, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont, $divlettfont, $useLinking);
  25921. }
  25922. function CreateIndex($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  25923. if (!$reffontsize) { $reffontsize = $this->default_font_size; }
  25924. if (!$divlettfontsize) { $divlettfontsize = ($this->default_font_size * 1.8); }
  25925. if (!$reffont) { $reffont = $this->default_font; }
  25926. if (!$divlettfont) { $divlettfont = $reffont; }
  25927. if (!$linespacing) { $linespacing= $this->default_lineheight_correction; }
  25928. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  25929. $size=sizeof($this->Reference);
  25930. if ($size == 0) { return false; }
  25931. if ($NbCol<2) {
  25932. $NbCol = 1;
  25933. $colWidth = $this->pgwidth;
  25934. }
  25935. else {
  25936. $this->SetColumns($NbCol,'',$gap);
  25937. $colWidth = $this->ColWidth;
  25938. }
  25939. if ($this->directionality == 'rtl') { $align = 'R'; }
  25940. else { $align = 'L'; }
  25941. $lett = '';
  25942. if (!function_exists('cmp')) {
  25943. function cmp ($a, $b) {
  25944. return strnatcmp(strtolower($a['t']), strtolower($b['t']));
  25945. }
  25946. }
  25947. //Alphabetic sort of the references
  25948. usort($this->Reference, 'cmp');
  25949. $size=sizeof($this->Reference);
  25950. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  25951. $divlettjuststarted = false;
  25952. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  25953. $last_lett = '';
  25954. for ($i=0;$i<$size;$i++){
  25955. if ($this->Reference[$i]['t']) {
  25956. if ($usedivletters) {
  25957. $lett = mb_strtoupper(mb_substr($this->Reference[$i]['t'],0,1,$this->mb_enc ),$this->mb_enc );
  25958. if ($lett != $last_lett) {
  25959. $save_bp = $this->breakpoints[$this->CurrCol]; // *COLUMNS*
  25960. $divlettjuststarted = true;
  25961. if ($i>0) {
  25962. $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; '));
  25963. }
  25964. else {
  25965. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; '));
  25966. }
  25967. $this->_saveTextBuffer($lett);
  25968. $this->CloseTag('DIV');
  25969. }
  25970. }
  25971. $this->OpenTag('DIV',array('STYLE'=>'text-indent: -'.$offset.'mm; line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  25972. /*-- RTL --*/
  25973. // Change Arabic + Persian. to Presentation Forms
  25974. if ($this->biDirectional) {
  25975. $this->Reference[$i]['t'] = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $this->Reference[$i]['t'] );
  25976. }
  25977. /*-- END RTL --*/
  25978. // Font-specific ligature substitution for Indic fonts
  25979. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($this->Reference[$i]['t']); // *INDIC*
  25980. $this->_saveTextBuffer($this->Reference[$i]['t']);
  25981. $ppp = $this->Reference[$i]['p']; // = array of page numbers to point to
  25982. if (count($ppp)) {
  25983. sort($ppp);
  25984. $newarr = array();
  25985. $range_start = $ppp[0];
  25986. $range_end = 0;
  25987. if (!$this->usingCoreFont) { $spacer = "\xc2\xa0 "; }
  25988. else { $spacer = chr(160).' '; }
  25989. $this->_saveTextBuffer($spacer);
  25990. if ($this->directionality == 'rtl') { $sep = '.'; $joiner = '-'; }
  25991. else { $sep = ', '; $joiner = '-'; }
  25992. for ($zi=1;$zi<count($ppp);$zi++) {
  25993. // RTL - Each number separately
  25994. if ($this->directionality == 'rtl') {
  25995. /*-- RTL --*/
  25996. if ($zi<count($ppp)-1) {
  25997. $txt = $sep . $this->docPageNum($ppp[$zi]);
  25998. if ($useLinking) { $href = '@'.$ppp[$zi]; }
  25999. else { $href = ''; }
  26000. $this->_saveTextBuffer($txt, $href);
  26001. }
  26002. /*-- END RTL --*/
  26003. }
  26004. else if ($ppp[$zi] == ($ppp[($zi-1)]+1)) {
  26005. $range_end = $ppp[$zi];
  26006. }
  26007. else {
  26008. if ($range_end) {
  26009. if ($range_end == $range_start+1) {
  26010. if ($useLinking) { $href = '@'.$range_start; }
  26011. else { $href = ''; }
  26012. $txt = $this->docPageNum($range_start) . $sep;
  26013. $this->_saveTextBuffer($txt, $href);
  26014. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  26015. else { $href = ''; }
  26016. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  26017. $this->_saveTextBuffer($txt, $href);
  26018. }
  26019. else {
  26020. if ($useLinking) { $href = '@'.$range_start; }
  26021. else { $href = ''; }
  26022. }
  26023. }
  26024. else {
  26025. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  26026. else { $href = ''; }
  26027. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  26028. $this->_saveTextBuffer($txt, $href);
  26029. }
  26030. $range_start = $ppp[$zi];
  26031. $range_end = 0;
  26032. }
  26033. }
  26034. if ($range_end) {
  26035. if ($range_end == $range_start+1) {
  26036. if ($useLinking) { $href = '@'.$range_start; }
  26037. else { $href = ''; }
  26038. $txt = $this->docPageNum($range_start) . $sep;
  26039. $this->_saveTextBuffer($txt, $href);
  26040. if ($useLinking) { $href = '@'.$range_end; }
  26041. else { $href = ''; }
  26042. $txt = $this->docPageNum($range_end);
  26043. $this->_saveTextBuffer($txt, $href);
  26044. }
  26045. else {
  26046. if ($useLinking) { $href = '@'.$range_start; }
  26047. else { $href = ''; }
  26048. $txt = $this->docPageNum($range_start) . $joiner;
  26049. $this->_saveTextBuffer($txt, $href);
  26050. if ($useLinking) { $href = '@'.$range_end; }
  26051. else { $href = ''; }
  26052. $txt = $this->docPageNum($range_end);
  26053. $this->_saveTextBuffer($txt, $href);
  26054. }
  26055. }
  26056. else {
  26057. if ($useLinking) { $href = '@'.$ppp[(count($ppp)-1)]; }
  26058. else { $href = ''; }
  26059. $txt = $this->docPageNum($ppp[(count($ppp)-1)]);
  26060. $this->_saveTextBuffer($txt, $href);
  26061. }
  26062. }
  26063. }
  26064. $this->CloseTag('DIV');
  26065. if ($divlettjuststarted) { $this->breakpoints[$this->CurrCol] = $save_bp; } // *COLUMNS*
  26066. $divlettjuststarted = false;
  26067. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26068. $last_lett = $lett;
  26069. }
  26070. $this->CloseTag('DIV');
  26071. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26072. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  26073. }
  26074. /*-- END INDEX --*/
  26075. function AcceptPageBreak() {
  26076. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  26077. /*-- COLUMNS --*/
  26078. if ($this->ColActive==1) {
  26079. if($this->CurrCol<$this->NbCol-1) {
  26080. //Go to the next column
  26081. $this->CurrCol++;
  26082. $this->SetCol($this->CurrCol);
  26083. $this->y=$this->y0;
  26084. $this->ChangeColumn=1; // Number (and direction) of columns changed +1, +2, -2 etc.
  26085. // DIRECTIONALITY RTL
  26086. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26087. //Stay on the page
  26088. return false;
  26089. }
  26090. else {
  26091. //Go back to the first column - NEW PAGE
  26092. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26093. $this->SetCol(0);
  26094. $this->y0 = $this->tMargin;
  26095. $this->ChangeColumn= -($this->NbCol-1);
  26096. // DIRECTIONALITY RTL
  26097. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26098. //Page break
  26099. return true;
  26100. }
  26101. }
  26102. /*-- END COLUMNS --*/
  26103. /*-- TABLES --*/
  26104. else if ($this->table_rotate) {
  26105. if ($this->tablebuffer) { $this->printtablebuffer(); }
  26106. return true;
  26107. }
  26108. /*-- END TABLES --*/
  26109. else { // *COLUMNS*
  26110. $this->ChangeColumn=0;
  26111. return $this->autoPageBreak;
  26112. } // *COLUMNS*
  26113. return $this->autoPageBreak;
  26114. }
  26115. //----------- COLUMNS ---------------------
  26116. /*-- COLUMNS --*/
  26117. function SetColumns($NbCol,$vAlign='',$gap=5) {
  26118. // NbCol = number of columns
  26119. // CurrCol = Number of the current column starting at 0
  26120. // Called externally to set columns on/off and number
  26121. // Integer 2 upwards sets columns on to that number
  26122. // Anything less than 2 turns columns off
  26123. if ($NbCol<2) { // SET COLUMNS OFF
  26124. if ($this->ColActive) {
  26125. $this->ColActive=0;
  26126. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26127. $this->NbCol=1;
  26128. $this->ResetMargins();
  26129. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  26130. $this->divwidth = 0;
  26131. $this->Ln();
  26132. }
  26133. $this->ColActive=0;
  26134. $this->columnbuffer = array();
  26135. $this->ColDetails = array();
  26136. $this->columnLinks = array();
  26137. $this->columnAnnots = array();
  26138. $this->columnForms = array();
  26139. $this->col_Reference = array();
  26140. $this->col_BMoutlines = array();
  26141. $this->col_toc = array();
  26142. $this->breakpoints = array();
  26143. }
  26144. else { // SET COLUMNS ON
  26145. if ($this->ColActive) {
  26146. $this->ColActive=0;
  26147. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26148. $this->ResetMargins();
  26149. }
  26150. if (isset($this->y) && $this->y>$this->tMargin) $this->Ln();
  26151. $this->NbCol=$NbCol;
  26152. $this->ColGap = $gap;
  26153. $this->divwidth = 0;
  26154. $this->ColActive=1;
  26155. $this->ColumnAdjust = true; // enables column height adjustment for the page
  26156. $this->columnbuffer = array();
  26157. $this->ColDetails = array();
  26158. $this->columnLinks = array();
  26159. $this->columnAnnots = array();
  26160. $this->columnForms = array();
  26161. $this->col_Reference = array();
  26162. $this->col_BMoutlines = array();
  26163. $this->col_toc = array();
  26164. $this->breakpoints = array();
  26165. if ((strtoupper($vAlign) == 'J') || (strtoupper($vAlign) == 'JUSTIFY')) { $vAlign = 'J'; }
  26166. else { $vAlign = ''; }
  26167. $this->colvAlign = $vAlign;
  26168. //Save the ordinate
  26169. $absL = $this->DeflMargin-($gap/2);
  26170. $absR = $this->DefrMargin-($gap/2);
  26171. $PageWidth = $this->w-$absL-$absR; // virtual pagewidth for calculation only
  26172. $ColWidth = (($PageWidth - ($gap * ($NbCol)))/$NbCol);
  26173. $this->ColWidth = $ColWidth;
  26174. /*-- RTL --*/
  26175. if ($this->directionality == 'rtl') {
  26176. for ($i=0;$i<$this->NbCol;$i++) {
  26177. $this->ColL[$i] = $absL + ($gap/2) + (($NbCol - ($i+1))*($PageWidth/$NbCol)) ;
  26178. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  26179. }
  26180. }
  26181. else {
  26182. /*-- END RTL --*/
  26183. for ($i=0;$i<$this->NbCol;$i++) {
  26184. $this->ColL[$i] = $absL + ($gap/2) + ($i* ($PageWidth/$NbCol) );
  26185. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  26186. }
  26187. } // *RTL*
  26188. $this->pgwidth = $ColWidth;
  26189. $this->SetCol(0);
  26190. $this->y0=$this->y;
  26191. }
  26192. $this->x = $this->lMargin;
  26193. }
  26194. function SetCol($CurrCol) {
  26195. // Used internally to set column by number: 0 is 1st column
  26196. //Set position on a column
  26197. $this->CurrCol=$CurrCol;
  26198. $x = $this->ColL[$CurrCol];
  26199. $xR = $this->ColR[$CurrCol]; // NB This is not R margin -> R pos
  26200. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  26201. $x += $this->MarginCorrection ;
  26202. $xR += $this->MarginCorrection ;
  26203. }
  26204. $this->SetMargins($x,($this->w - $xR),$this->tMargin);
  26205. }
  26206. function AddColumn() {
  26207. $this->NewColumn();
  26208. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  26209. }
  26210. function NewColumn() {
  26211. if ($this->ColActive==1) {
  26212. if($this->CurrCol<$this->NbCol-1) {
  26213. //Go to the next column
  26214. $this->CurrCol++;
  26215. $this->SetCol($this->CurrCol);
  26216. $this->y = $this->y0;
  26217. $this->ChangeColumn=1;
  26218. // DIRECTIONALITY RTL
  26219. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26220. //Stay on the page
  26221. }
  26222. else {
  26223. //Go back to the first column
  26224. //Page break
  26225. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26226. $this->AddPage($this->CurOrientation);
  26227. $this->SetCol(0);
  26228. $this->y0 = $this->tMargin;
  26229. $this->ChangeColumn= -($this->NbCol-1);
  26230. // DIRECTIONALITY RTL
  26231. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26232. }
  26233. $this->x = $this->lMargin;
  26234. }
  26235. else {
  26236. $this->AddPage($this->CurOrientation);
  26237. }
  26238. }
  26239. function printcolumnbuffer() {
  26240. // Columns ended (but page not ended) -> try to match all columns - unless disabled by using a custom column-break
  26241. if (!$this->ColActive && $this->ColumnAdjust && !$this->keepColumns) {
  26242. // Calculate adjustment to add to each column to calculate rel_y value
  26243. $this->ColDetails[0]['add_y'] = 0;
  26244. $last_col = 0;
  26245. // Recursively add previous column's height
  26246. for($i=1;$i<$this->NbCol;$i++) {
  26247. if (isset($this->ColDetails[$i]['bottom_margin']) && $this->ColDetails[$i]['bottom_margin']) { // If any entries in the column
  26248. $this->ColDetails[$i]['add_y'] = ($this->ColDetails[$i-1]['bottom_margin'] - $this->y0) + $this->ColDetails[$i-1]['add_y'];
  26249. $last_col = $i; // Last column actually printed
  26250. }
  26251. }
  26252. // Calculate value for each position sensitive entry as though for one column
  26253. foreach($this->columnbuffer AS $key=>$s) {
  26254. $t = $s['s'];
  26255. if ($t == 'ACROFORM') {
  26256. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26257. $this->columnbuffer[$key]['s'] = '';
  26258. }
  26259. else if (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) {
  26260. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26261. }
  26262. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) {
  26263. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26264. }
  26265. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) {
  26266. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26267. }
  26268. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) {
  26269. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26270. }
  26271. 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)) {
  26272. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26273. }
  26274. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) {
  26275. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26276. }
  26277. }
  26278. foreach($this->internallink AS $key => $f) {
  26279. if (is_array($f) && isset($f['col'])) {
  26280. $this->internallink[$key]['rel_y'] = $f['Y'] + $this->ColDetails[$f['col']]['add_y'] - $this->y0;
  26281. }
  26282. }
  26283. $breaks = array();
  26284. foreach($this->breakpoints AS $c => $bpa) {
  26285. foreach($bpa AS $rely) {
  26286. $breaks[] = $rely + $this->ColDetails[$c]['add_y'] - $this->y0;
  26287. }
  26288. }
  26289. if (isset($this->ColDetails[$last_col]['bottom_margin'])) { $lcbm = $this->ColDetails[$last_col]['bottom_margin']; }
  26290. else { $lcbm = 0; }
  26291. $sum_h = $this->ColDetails[$last_col]['add_y'] + $lcbm - $this->y0;
  26292. //$sum_h = max($this->ColDetails[$last_col]['add_y'] + $this->ColDetails[$last_col]['bottom_margin'] - $this->y0, end($breaks));
  26293. $target_h = ($sum_h / $this->NbCol);
  26294. $cbr = array();
  26295. for($i=1;$i<$this->NbCol;$i++) {
  26296. $th = ($sum_h * $i / $this->NbCol);
  26297. foreach($breaks AS $bk=>$val) {
  26298. if ($val > $th) {
  26299. if (($val-$th) < ($th-$breaks[$bk-1])) { $cbr[$i-1] = $val; }
  26300. else { $cbr[$i-1] = $breaks[$bk-1]; }
  26301. break;
  26302. }
  26303. }
  26304. }
  26305. $cbr[($this->NbCol-1)] = $sum_h;
  26306. // Now update the columns - divide into columns of approximately equal value
  26307. $last_new_col = 0;
  26308. $yadj = 0; // mm
  26309. $xadj = 0;
  26310. $last_col_bottom = 0;
  26311. $lowest_bottom_y = 0;
  26312. $block_bottom = 0;
  26313. $newcolumn = 0;
  26314. foreach($this->columnbuffer AS $key=>$s) {
  26315. if (isset($s['rel_y'])) { // only process position sensitive data
  26316. if ($s['rel_y'] >= $cbr[$newcolumn]) {
  26317. $newcolumn++;
  26318. }
  26319. else {
  26320. $newcolumn = $last_new_col ;
  26321. }
  26322. $block_bottom = max($block_bottom,($s['rel_y']+$s['h']));
  26323. if ($this->directionality == 'rtl') { // *RTL*
  26324. $xadj = -(($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap)); // *RTL*
  26325. } // *RTL*
  26326. else { // *RTL*
  26327. $xadj = ($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap);
  26328. } // *RTL*
  26329. if ($last_new_col != $newcolumn) { // Added new column
  26330. $last_col_bottom = $this->columnbuffer[$key]['rel_y'];
  26331. $block_bottom = 0;
  26332. }
  26333. $yadj = ($s['rel_y'] - $s['y']) - ($last_col_bottom)+$this->y0;
  26334. // callback function
  26335. $t = $s['s'];
  26336. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->columnAdjustAdd('Td',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26337. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->columnAdjustAdd('re',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4')",$t);
  26338. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->columnAdjustAdd('l',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26339. $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',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5')",$t);
  26340. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->columnAdjustAdd('draw',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26341. $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',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  26342. $this->columnbuffer[$key]['s'] = $t;
  26343. $this->columnbuffer[$key]['newcol'] = $newcolumn;
  26344. $this->columnbuffer[$key]['newy'] = $s['y'] + $yadj;
  26345. $last_new_col = $newcolumn;
  26346. $clb = $s['y'] + $yadj + $s['h'] ; // bottom_margin of current
  26347. 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; }
  26348. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26349. // Adjust LINKS
  26350. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26351. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26352. $this->PageLinks[$this->page][$ref][0] += ($xadj*_MPDFK);
  26353. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK);
  26354. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26355. }
  26356. // Adjust FORM FIELDS
  26357. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26358. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26359. $this->form->forms[$ref]['x'] += ($xadj);
  26360. $this->form->forms[$ref]['y'] += ($yadj);
  26361. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26362. }
  26363. /*-- ANNOTATIONS --*/
  26364. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26365. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26366. if ($this->PageAnnots[$this->page][$ref]['x'] < 0) {
  26367. $this->PageAnnots[$this->page][$ref]['x'] -= ($xadj);
  26368. }
  26369. else {
  26370. $this->PageAnnots[$this->page][$ref]['x'] += ($xadj);
  26371. }
  26372. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); // unlike PageLinks, Page annots has y values from top in mm
  26373. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26374. }
  26375. /*-- END ANNOTATIONS --*/
  26376. }
  26377. }
  26378. /*-- BOOKMARKS --*/
  26379. // Adjust Bookmarks
  26380. foreach($this->col_BMoutlines AS $v) {
  26381. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26382. }
  26383. /*-- END BOOKMARKS --*/
  26384. /*-- INDEX --*/
  26385. // Adjust Reference (index)
  26386. foreach($this->col_Reference AS $v) {
  26387. $Present=0;
  26388. //Search the reference (AND Ref/PageNo) in the array
  26389. for ($i=0;$i<count($this->Reference);$i++){
  26390. if ($this->Reference[$i]['t']==$v['t']){
  26391. $Present=1;
  26392. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26393. $this->Reference[$i]['p'][] = $v['op'];
  26394. }
  26395. }
  26396. }
  26397. if ($Present==0) {
  26398. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26399. }
  26400. }
  26401. /*-- END INDEX --*/
  26402. /*-- TOC --*/
  26403. // Adjust ToC
  26404. foreach($this->col_toc AS $v) {
  26405. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26406. $this->links[$v['link']][1] = $this->y0;
  26407. }
  26408. /*-- END TOC --*/
  26409. // Adjust column length to be equal
  26410. if ($this->colvAlign == 'J') {
  26411. foreach($this->columnbuffer AS $key=>$s) {
  26412. if (isset($s['rel_y'])) { // only process position sensitive data
  26413. // Set ratio to expand y values or heights
  26414. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) {
  26415. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26416. }
  26417. else { $ratio = 1; }
  26418. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26419. $yadj = ($s['newy'] - $this->y0) * ($ratio - 1);
  26420. // Adjust LINKS
  26421. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26422. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26423. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value
  26424. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26425. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26426. }
  26427. // Adjust FORM FIELDS
  26428. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26429. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26430. $this->form->forms[$ref]['x'] += ($xadj);
  26431. $this->form->forms[$ref]['y'] += ($yadj);
  26432. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26433. }
  26434. /*-- ANNOTATIONS --*/
  26435. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26436. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26437. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26438. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26439. }
  26440. /*-- END ANNOTATIONS --*/
  26441. }
  26442. }
  26443. }
  26444. foreach($this->internallink AS $key => $f) {
  26445. if (is_array($f) && isset($f['col'])) {
  26446. $last_col_bottom = 0;
  26447. for ($nbc=0; $nbc<$this->NbCol; $nbc++) {
  26448. if ($f['rel_y'] >= $cbr[$nbc]) { $last_col_bottom = $cbr[$nbc]; }
  26449. }
  26450. $yadj = ($f['rel_y'] - $f['Y']) - $last_col_bottom + $this->y0;
  26451. $f['Y'] += $yadj;
  26452. unset($f['col']);
  26453. unset($f['rel_y']);
  26454. $this->internallink[$key] = $f;
  26455. }
  26456. }
  26457. $last_col = -1;
  26458. $trans_on = false;
  26459. foreach($this->columnbuffer AS $key=>$s) {
  26460. if (isset($s['rel_y'])) { // only process position sensitive data
  26461. // Set ratio to expand y values or heights
  26462. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) {
  26463. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26464. }
  26465. else { $ratio = 1; }
  26466. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26467. //Start Transformation
  26468. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26469. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26470. $trans_on = true;
  26471. }
  26472. }
  26473. // Now output the adjusted values
  26474. $this->pages[$this->page] .= $s['s']."\n";
  26475. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) { // only process position sensitive data
  26476. //Stop Transformation
  26477. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26478. $trans_on = false;
  26479. }
  26480. }
  26481. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; }
  26482. }
  26483. else { // if NOT $this->colvAlign == 'J'
  26484. // Now output the adjusted values
  26485. foreach($this->columnbuffer AS $s) {
  26486. $this->pages[$this->page] .= $s['s']."\n";
  26487. }
  26488. }
  26489. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26490. }
  26491. // Columns not ended but new page -> align columns (can leave the columns alone - just tidy up the height)
  26492. else if ($this->colvAlign == 'J' && $this->ColumnAdjust && !$this->keepColumns) {
  26493. // calculate the lowest bottom margin
  26494. $lowest_bottom_y = 0;
  26495. foreach($this->columnbuffer AS $key=>$s) {
  26496. // Only process output data
  26497. $t = $s['s'];
  26498. if ($t == 'ACROFORM' || (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)) ||
  26499. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  26500. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  26501. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  26502. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  26503. $clb = $s['y'] + $s['h'];
  26504. 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; }
  26505. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26506. $this->columnbuffer[$key]['rel_y'] = $s['y']; // Marks position sensitive data to process later
  26507. if ($t == 'ACROFORM') { $this->columnbuffer[$key]['s'] = ''; }
  26508. }
  26509. }
  26510. // Adjust column length equal
  26511. foreach($this->columnbuffer AS $key=>$s) {
  26512. // Set ratio to expand y values or heights
  26513. if (isset($this->ColDetails[$s['col']]['max_bottom']) && $this->ColDetails[$s['col']]['max_bottom']) {
  26514. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26515. }
  26516. else { $ratio = 1; }
  26517. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26518. $yadj = ($s['y'] - $this->y0) * ($ratio - 1);
  26519. // Adjust LINKS
  26520. if (isset($s['rel_y'])) { // only process position sensitive data
  26521. // otherwise triggers for all entries in column buffer (.e.g. formatting) and makes below adjustments more than once
  26522. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26523. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26524. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value
  26525. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26526. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26527. }
  26528. // Adjust FORM FIELDS
  26529. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26530. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26531. $this->form->forms[$ref]['x'] += ($xadj);
  26532. $this->form->forms[$ref]['y'] += ($yadj);
  26533. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26534. }
  26535. /*-- ANNOTATIONS --*/
  26536. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26537. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26538. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26539. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26540. }
  26541. /*-- END ANNOTATIONS --*/
  26542. }
  26543. }
  26544. }
  26545. /*-- BOOKMARKS --*/
  26546. // Adjust Bookmarks
  26547. foreach($this->col_BMoutlines AS $v) {
  26548. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26549. }
  26550. /*-- END BOOKMARKS --*/
  26551. /*-- INDEX --*/
  26552. // Adjust Reference (index)
  26553. foreach($this->col_Reference AS $v) {
  26554. $Present=0;
  26555. //Search the reference (AND Ref/PageNo) in the array
  26556. for ($i=0;$i<count($this->Reference);$i++){
  26557. if ($this->Reference[$i]['t']==$v['t']){
  26558. $Present=1;
  26559. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26560. $this->Reference[$i]['p'][] = $v['op'];
  26561. }
  26562. }
  26563. }
  26564. if ($Present==0) {
  26565. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26566. }
  26567. }
  26568. /*-- END INDEX --*/
  26569. /*-- TOC --*/
  26570. // Adjust ToC
  26571. foreach($this->col_toc AS $v) {
  26572. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26573. $this->links[$v['link']][1] = $this->y0;
  26574. }
  26575. /*-- END TOC --*/
  26576. $trans_on = false;
  26577. foreach($this->columnbuffer AS $key=>$s) {
  26578. if (isset($s['rel_y'])) { // only process position sensitive data
  26579. // Set ratio to expand y values or heights
  26580. if ($this->ColDetails[$s['col']]['max_bottom']) {
  26581. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26582. }
  26583. else { $ratio = 1; }
  26584. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26585. //Start Transformation
  26586. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26587. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26588. $trans_on = true;
  26589. }
  26590. }
  26591. // Now output the adjusted values
  26592. $this->pages[$this->page] .= $s['s']."\n";
  26593. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26594. //Stop Transformation
  26595. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26596. $trans_on = false; // mPDF 5.1.001
  26597. }
  26598. }
  26599. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; }
  26600. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26601. }
  26602. // Just reproduce the page as it was
  26603. else {
  26604. // If page has not ended but height adjustment was disabled by custom column-break - adjust y
  26605. $lowest_bottom_y = 0;
  26606. if (!$this->ColActive && (!$this->ColumnAdjust || $this->keepColumns)) {
  26607. // calculate the lowest bottom margin
  26608. foreach($this->columnbuffer AS $key=>$s) {
  26609. // Only process output data
  26610. $t = $s['s'];
  26611. if ($t == 'ACROFORM' || (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)) ||
  26612. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  26613. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  26614. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  26615. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  26616. $clb = $s['y'] + $s['h'];
  26617. if ($clb > $this->ColDetails[$s['col']]['max_bottom']) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; }
  26618. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26619. }
  26620. }
  26621. }
  26622. foreach($this->columnbuffer AS $key=>$s) {
  26623. if ($s['s'] != 'ACROFORM')
  26624. $this->pages[$this->page] .= $s['s']."\n";
  26625. }
  26626. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26627. /*-- INDEX --*/
  26628. // Output Reference (index)
  26629. foreach($this->col_Reference AS $v) {
  26630. $Present=0;
  26631. for ($i=0;$i<count($this->Reference);$i++){
  26632. if ($this->Reference[$i]['t']==$v['t']){
  26633. $Present=1;
  26634. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26635. $this->Reference[$i]['p'][] = $v['op'];
  26636. }
  26637. }
  26638. }
  26639. if ($Present==0) {
  26640. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26641. }
  26642. }
  26643. /*-- END INDEX --*/
  26644. /*-- BOOKMARKS --*/
  26645. // Output Bookmarks
  26646. foreach($this->col_BMoutlines AS $v) {
  26647. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26648. }
  26649. /*-- END BOOKMARKS --*/
  26650. /*-- TOC --*/
  26651. // Output ToC
  26652. foreach($this->col_toc AS $v) {
  26653. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26654. }
  26655. /*-- END TOC --*/
  26656. }
  26657. foreach($this->internallink AS $key => $f) {
  26658. if (isset($this->internallink[$key]['col'])) unset($this->internallink[$key]['col']);
  26659. if (isset($this->internallink[$key]['rel_y'])) unset($this->internallink[$key]['rel_y']);
  26660. }
  26661. $this->columnbuffer = array();
  26662. $this->ColDetails = array();
  26663. $this->columnLinks = array();
  26664. $this->columnAnnots = array();
  26665. $this->columnForms = array();
  26666. $this->col_Reference = array();
  26667. $this->col_BMoutlines = array();
  26668. $this->col_toc = array();
  26669. $this->breakpoints = array();
  26670. }
  26671. /*-- END COLUMNS --*/
  26672. //==================================================================
  26673. /*-- TABLES --*/
  26674. function printcellbuffer() {
  26675. if (count($this->cellBorderBuffer )) {
  26676. sort($this->cellBorderBuffer);
  26677. foreach($this->cellBorderBuffer AS $cbb) {
  26678. $cba = unpack("A16dom/nbord/A1side/ns/dbw/a6ca/A10style/dx/dy/dw/dh/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd/dover/", $cbb);
  26679. $side = $cba['side'];
  26680. $details = array();
  26681. $details[$side]['dom'] = (float) $cba['dom'];
  26682. $details[$side]['s'] = $cba['s'];
  26683. $details[$side]['w'] = $cba['bw'];
  26684. $details[$side]['c'] = $cba['ca'];
  26685. $details[$side]['style'] = trim($cba['style']);
  26686. $details['mbw']['BL'] = $cba['mbl'];
  26687. $details['mbw']['BR'] = $cba['mbr'];
  26688. $details['mbw']['RT'] = $cba['mrt'];
  26689. $details['mbw']['RB'] = $cba['mrb'];
  26690. $details['mbw']['TL'] = $cba['mtl'];
  26691. $details['mbw']['TR'] = $cba['mtr'];
  26692. $details['mbw']['LT'] = $cba['mlt'];
  26693. $details['mbw']['LB'] = $cba['mlb'];
  26694. $details['cellposdom'] = $cba['cpd'];
  26695. $details['p'] = $side;
  26696. if ($cba['over']==1) { $details[$side]['overlay'] = true; }
  26697. else { $details[$side]['overlay'] = false; }
  26698. $this->_tableRect($cba['x'],$cba['y'],$cba['w'],$cba['h'],$cba['bord'],$details, false, false);
  26699. }
  26700. $this->cellBorderBuffer = array();
  26701. }
  26702. }
  26703. //==================================================================
  26704. function printtablebuffer() {
  26705. if (!$this->table_rotate) {
  26706. $this->pages[$this->page] .= $this->tablebuffer;
  26707. foreach($this->tbrot_Links AS $p => $l) {
  26708. foreach($l AS $v) {
  26709. $this->PageLinks[$p][] = $v;
  26710. }
  26711. }
  26712. $this->tbrot_Links = array();
  26713. /*-- ANNOTATIONS --*/
  26714. foreach($this->tbrot_Annots AS $p => $l) {
  26715. foreach($l AS $v) {
  26716. $this->PageAnnots[$p][] = $v;
  26717. }
  26718. }
  26719. $this->tbrot_Annots = array();
  26720. /*-- END ANNOTATIONS --*/
  26721. /*-- INDEX --*/
  26722. // Output Reference (index)
  26723. foreach($this->tbrot_Reference AS $v) {
  26724. $Present=0;
  26725. for ($i=0;$i<count($this->Reference);$i++){
  26726. if ($this->Reference[$i]['t']==$v['t']){
  26727. $Present=1;
  26728. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26729. $this->Reference[$i]['p'][] = $v['op'];
  26730. }
  26731. }
  26732. }
  26733. if ($Present==0) {
  26734. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26735. }
  26736. }
  26737. $this->tbrot_Reference = array();
  26738. /*-- END INDEX --*/
  26739. /*-- BOOKMARKS --*/
  26740. // Output Bookmarks
  26741. foreach($this->tbrot_BMoutlines AS $v) {
  26742. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26743. }
  26744. $this->tbrot_BMoutlines = array();
  26745. /*-- END BOOKMARKS --*/
  26746. /*-- TOC --*/
  26747. // Output ToC
  26748. foreach($this->tbrot_toc AS $v) {
  26749. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26750. }
  26751. $this->tbrot_toc = array();
  26752. /*-- END TOC --*/
  26753. return;
  26754. }
  26755. // else if rotated
  26756. $lm = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'];
  26757. $pw = $this->blk[$this->blklvl]['inner_width'];
  26758. //Start Transformation
  26759. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26760. if ($this->table_rotate > 1) { // clockwise
  26761. if ($this->tbrot_align == 'L') {
  26762. $xadj = $this->tbrot_h ; // align L (as is)
  26763. }
  26764. else if ($this->tbrot_align == 'R') {
  26765. $xadj = $lm-$this->tbrot_x0+($pw) ; // align R
  26766. }
  26767. else {
  26768. $xadj = $lm-$this->tbrot_x0+(($pw + $this->tbrot_h)/2) ; // align C
  26769. }
  26770. $yadj = 0;
  26771. }
  26772. else { // anti-clockwise
  26773. if ($this->tbrot_align == 'L') {
  26774. $xadj = 0 ; // align L (as is)
  26775. }
  26776. else if ($this->tbrot_align == 'R') {
  26777. $xadj = $lm-$this->tbrot_x0+($pw - $this->tbrot_h) ; // align R
  26778. }
  26779. else {
  26780. $xadj = $lm-$this->tbrot_x0+(($pw - $this->tbrot_h)/2) ; // align C
  26781. }
  26782. $yadj = $this->tbrot_w;
  26783. }
  26784. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  26785. $this->pages[$this->page] .= $this->transformRotate($this->table_rotate, $this->tbrot_x0 , $this->tbrot_y0 , true)."\n";
  26786. // Now output the adjusted values
  26787. $this->pages[$this->page] .= $this->tablebuffer;
  26788. foreach($this->tbrot_Links AS $p => $l) {
  26789. foreach($l AS $v) {
  26790. $w = $v[2]/_MPDFK;
  26791. $h = $v[3]/_MPDFK;
  26792. $ax = ($v[0]/_MPDFK) - $this->tbrot_x0;
  26793. $ay = (($this->hPt-$v[1])/_MPDFK) - $this->tbrot_y0;
  26794. if ($this->table_rotate > 1) { // clockwise
  26795. $bx = $this->tbrot_x0+$xadj-$ay-$h;
  26796. $by = $this->tbrot_y0+$yadj+$ax;
  26797. }
  26798. else {
  26799. $bx = $this->tbrot_x0+$xadj+$ay;
  26800. $by = $this->tbrot_y0+$yadj-$ax-$w;
  26801. }
  26802. $v[0] = $bx*_MPDFK;
  26803. $v[1] = ($this->h-$by)*_MPDFK;
  26804. $v[2] = $h*_MPDFK; // swap width and height
  26805. $v[3] = $w*_MPDFK;
  26806. $this->PageLinks[$p][] = $v;
  26807. }
  26808. }
  26809. $this->tbrot_Links = array();
  26810. foreach($this->internallink AS $key => $f) {
  26811. if (is_array($f) && isset($f['tbrot'])) {
  26812. $f['Y'] = $this->tbrot_y0;
  26813. $f['PAGE'] = $this->page;
  26814. unset($f['tbrot']);
  26815. $this->internallink[$key] = $f;
  26816. }
  26817. }
  26818. /*-- ANNOTATIONS --*/
  26819. foreach($this->tbrot_Annots AS $p => $l) {
  26820. foreach($l AS $v) {
  26821. $ax = abs($v['x']) - $this->tbrot_x0; // abs because -ve values are internally set and held for reference if annotMargin set
  26822. $ay = $v['y'] - $this->tbrot_y0;
  26823. if ($this->table_rotate > 1) { // clockwise
  26824. $bx = $this->tbrot_x0+$xadj-$ay;
  26825. $by = $this->tbrot_y0+$yadj+$ax;
  26826. }
  26827. else {
  26828. $bx = $this->tbrot_x0+$xadj+$ay;
  26829. $by = $this->tbrot_y0+$yadj-$ax;
  26830. }
  26831. if ($v['x'] < 0) {
  26832. $v['x'] = -$bx;
  26833. }
  26834. else {
  26835. $v['x'] = $bx;
  26836. }
  26837. $v['y'] = ($by);
  26838. $this->PageAnnots[$p][] = $v;
  26839. }
  26840. }
  26841. $this->tbrot_Annots = array();
  26842. /*-- END ANNOTATIONS --*/
  26843. /*-- BOOKMARKS --*/
  26844. // Adjust Bookmarks
  26845. foreach($this->tbrot_BMoutlines AS $v) {
  26846. $v['y'] = $this->tbrot_y0;
  26847. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  26848. }
  26849. /*-- END BOOKMARKS --*/
  26850. /*-- INDEX --*/
  26851. // Adjust Reference (index)
  26852. foreach($this->tbrot_Reference AS $v) {
  26853. $Present=0;
  26854. //Search the reference (AND Ref/PageNo) in the array
  26855. for ($i=0;$i<count($this->Reference);$i++){
  26856. if ($this->Reference[$i]['t']==$v['t']){
  26857. $Present=1;
  26858. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  26859. $this->Reference[$i]['p'][] = $this->page;
  26860. }
  26861. }
  26862. }
  26863. if ($Present==0) {
  26864. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  26865. }
  26866. }
  26867. /*-- END INDEX --*/
  26868. /*-- TOC --*/
  26869. // Adjust ToC - uses document page number
  26870. foreach($this->tbrot_toc AS $v) {
  26871. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26872. $this->links[$v['link']][1] = $this->tbrot_y0;
  26873. }
  26874. /*-- END TOC --*/
  26875. $this->tbrot_Reference = array();
  26876. $this->tbrot_BMoutlines = array();
  26877. $this->tbrot_toc = array();
  26878. //Stop Transformation
  26879. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26880. $this->y = $this->tbrot_y0 + $this->tbrot_w;
  26881. $this->x = $this->lMargin;
  26882. $this->tablebuffer = '';
  26883. }
  26884. //==================================================================
  26885. // Keep-with-table This buffers contents of h1-6 to keep on page with table
  26886. function printkwtbuffer() {
  26887. if (!$this->kwt_moved) {
  26888. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  26889. foreach($this->kwt_Links AS $p => $l) {
  26890. foreach($l AS $v) {
  26891. $this->PageLinks[$p][] = $v;
  26892. }
  26893. }
  26894. $this->kwt_Links = array();
  26895. /*-- ANNOTATIONS --*/
  26896. foreach($this->kwt_Annots AS $p => $l) {
  26897. foreach($l AS $v) {
  26898. $this->PageAnnots[$p][] = $v;
  26899. }
  26900. }
  26901. $this->kwt_Annots = array();
  26902. /*-- END ANNOTATIONS --*/
  26903. /*-- INDEX --*/
  26904. // Output Reference (index)
  26905. foreach($this->kwt_Reference AS $v) {
  26906. $Present=0;
  26907. for ($i=0;$i<count($this->Reference);$i++){
  26908. if ($this->Reference[$i]['t']==$v['t']){
  26909. $Present=1;
  26910. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26911. $this->Reference[$i]['p'][] = $v['op'];
  26912. }
  26913. }
  26914. }
  26915. if ($Present==0) {
  26916. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26917. }
  26918. }
  26919. $this->kwt_Reference = array();
  26920. /*-- END INDEX --*/
  26921. /*-- BOOKMARKS --*/
  26922. // Output Bookmarks
  26923. foreach($this->kwt_BMoutlines AS $v) {
  26924. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  26925. }
  26926. $this->kwt_BMoutlines = array();
  26927. /*-- END BOOKMARKS --*/
  26928. /*-- TOC --*/
  26929. // Output ToC
  26930. foreach($this->kwt_toc AS $v) {
  26931. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26932. }
  26933. $this->kwt_toc = array();
  26934. /*-- END TOC --*/
  26935. return;
  26936. }
  26937. //Start Transformation
  26938. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26939. $xadj = $this->lMargin - $this->kwt_x0 ;
  26940. //$yadj = $this->y - $this->kwt_y0 ;
  26941. $yadj = $this->tMargin - $this->kwt_y0 ;
  26942. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  26943. // Now output the adjusted values
  26944. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  26945. // Adjust hyperLinks
  26946. foreach($this->kwt_Links AS $p => $l) {
  26947. foreach($l AS $v) {
  26948. $bx = $this->kwt_x0+$xadj;
  26949. $by = $this->kwt_y0+$yadj;
  26950. $v[0] = $bx*_MPDFK;
  26951. $v[1] = ($this->h-$by)*_MPDFK;
  26952. $this->PageLinks[$p][] = $v;
  26953. }
  26954. }
  26955. foreach($this->internallink AS $key => $f) {
  26956. if (is_array($f) && isset($f['kwt'])) {
  26957. $f['Y'] += $yadj;
  26958. $f['PAGE'] = $this->page;
  26959. unset($f['kwt']);
  26960. $this->internallink[$key] = $f;
  26961. }
  26962. }
  26963. /*-- ANNOTATIONS --*/
  26964. foreach($this->kwt_Annots AS $p => $l) {
  26965. foreach($l AS $v) {
  26966. $bx = $this->kwt_x0+$xadj;
  26967. $by = $this->kwt_y0+$yadj;
  26968. if ($v['x'] < 0) {
  26969. $v['x'] = -$bx;
  26970. }
  26971. else {
  26972. $v['x'] = $bx;
  26973. }
  26974. $v['y'] = $by;
  26975. $this->PageAnnots[$p][] = $v;
  26976. }
  26977. }
  26978. /*-- END ANNOTATIONS --*/
  26979. /*-- BOOKMARKS --*/
  26980. // Adjust Bookmarks
  26981. foreach($this->kwt_BMoutlines AS $v) {
  26982. if ($v['y'] != 0) { $v['y'] += $yadj; }
  26983. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  26984. }
  26985. /*-- END BOOKMARKS --*/
  26986. /*-- INDEX --*/
  26987. // Adjust Reference (index)
  26988. foreach($this->kwt_Reference AS $v) {
  26989. $Present=0;
  26990. //Search the reference (AND Ref/PageNo) in the array
  26991. for ($i=0;$i<count($this->Reference);$i++){
  26992. if ($this->Reference[$i]['t']==$v['t']){
  26993. $Present=1;
  26994. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  26995. $this->Reference[$i]['p'][] = $this->page;
  26996. }
  26997. }
  26998. }
  26999. if ($Present==0) {
  27000. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  27001. }
  27002. }
  27003. /*-- END INDEX --*/
  27004. /*-- TOC --*/
  27005. // Adjust ToC
  27006. foreach($this->kwt_toc AS $v) {
  27007. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27008. $this->links[$v['link']][0] = $this->page;
  27009. $this->links[$v['link']][1] += $yadj;
  27010. }
  27011. /*-- END TOC --*/
  27012. $this->kwt_Links = array();
  27013. $this->kwt_Annots = array();
  27014. $this->kwt_Reference = array();
  27015. $this->kwt_BMoutlines = array();
  27016. $this->kwt_toc = array();
  27017. //Stop Transformation
  27018. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  27019. $this->kwt_buffer = array();
  27020. $this->y += $this->kwt_height;
  27021. }
  27022. /*-- END TABLES --*/
  27023. //==================================================================
  27024. function printfloatbuffer() {
  27025. if (count($this->floatbuffer)) {
  27026. $this->objectbuffer = $this->floatbuffer;
  27027. $this->printobjectbuffer(false);
  27028. $this->objectbuffer = array();
  27029. $this->floatbuffer = array();
  27030. $this->floatmargins = array();
  27031. }
  27032. }
  27033. //==================================================================
  27034. function printdivbuffer() {
  27035. $p1 = $this->blk[$this->blklvl]['startpage'];
  27036. $p2 = $this->page;
  27037. $bottom[$p1] = $this->ktBlock[$p1]['bottom_margin'];
  27038. $bottom[$p2] = $this->y; // $this->ktBlock[$p2]['bottom_margin'];
  27039. $top[$p1] = $this->kt_y00;
  27040. $top2 = $this->h;
  27041. foreach($this->divbuffer AS $key=>$s) {
  27042. if ($s['page'] == $p2) {
  27043. $top2 = MIN($s['y'], $top2);
  27044. }
  27045. }
  27046. $top[$p2] = $top2;
  27047. $height[$p1] = ($bottom[$p1] - $top[$p1]);
  27048. $height[$p2] = ($bottom[$p2] - $top[$p2]);
  27049. $xadj[$p1] = $this->MarginCorrection;
  27050. $yadj[$p1] = -($top[$p1] - $top[$p2]);
  27051. $xadj[$p2] = 0;
  27052. $yadj[$p2] = $height[$p1];
  27053. // Output without any transformation
  27054. 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) {
  27055. foreach($this->divbuffer AS $s) { $this->pages[$s['page']] .= $s['s']."\n"; }
  27056. foreach($this->ktLinks AS $p => $l) {
  27057. foreach($l AS $v) {
  27058. $this->PageLinks[$p][] = $v;
  27059. }
  27060. }
  27061. foreach($this->ktForms AS $key => $f) {
  27062. $this->form->forms[$f['n']] = $f;
  27063. }
  27064. /*-- ANNOTATIONS --*/
  27065. foreach($this->ktAnnots AS $p => $l) {
  27066. foreach($l AS $v) {
  27067. $this->PageAnnots[$p][] = $v;
  27068. }
  27069. }
  27070. /*-- END ANNOTATIONS --*/
  27071. /*-- INDEX --*/
  27072. // Adjust Reference (index)
  27073. foreach($this->ktReference AS $v) {
  27074. $Present=0;
  27075. //Search the reference (AND Ref/PageNo) in the array
  27076. for ($i=0;$i<count($this->Reference);$i++){
  27077. if ($this->Reference[$i]['t']==$v['t']){
  27078. $Present=1;
  27079. if (!in_array($p2,$this->Reference[$i]['p'])) {
  27080. $this->Reference[$i]['p'][] = $p2;
  27081. }
  27082. }
  27083. }
  27084. //If not found, add it
  27085. if ($Present==0) {
  27086. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  27087. }
  27088. }
  27089. /*-- END INDEX --*/
  27090. /*-- BOOKMARKS --*/
  27091. // Adjust Bookmarks
  27092. foreach($this->ktBMoutlines AS $v) {
  27093. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  27094. }
  27095. /*-- END BOOKMARKS --*/
  27096. /*-- TOC --*/
  27097. // Adjust ToC
  27098. foreach($this->_kttoc AS $v) {
  27099. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27100. }
  27101. /*-- END TOC --*/
  27102. $this->divbuffer = array();
  27103. $this->ktLinks = array();
  27104. $this->ktAnnots = array();
  27105. $this->ktForms = array();
  27106. $this->ktBlock = array();
  27107. $this->ktReference = array();
  27108. $this->ktBMoutlines = array();
  27109. $this->_kttoc = array();
  27110. $this->keep_block_together = 0;
  27111. return;
  27112. }
  27113. else {
  27114. // Output with transformation
  27115. // mPDF 5.6.17
  27116. $np = '';
  27117. $lastpage = -1;
  27118. foreach($this->divbuffer AS $key=>$s) {
  27119. // callback function
  27120. $t = $s['s'];
  27121. $p = $s['page'];
  27122. if ($p != $lastpage) {
  27123. $q = '';
  27124. if ($lastpage != -1) { $q = ' Q'."\n"; }
  27125. $t = $q . $this->StartTransform(true)."\n" . $this->transformTranslate($xadj[$p], $yadj[$p] , true)."\n" . $t;
  27126. $lastpage = $p;
  27127. }
  27128. $np .= $t."\n";
  27129. }
  27130. if ($lastpage != -1) { $np .= ' Q'."\n"; }
  27131. $this->pages[$this->page] .= $np;
  27132. // Adjust hyperLinks
  27133. foreach($this->ktLinks AS $p => $l) {
  27134. foreach($l AS $v) {
  27135. $v[0] += ($xadj[$p]*_MPDFK);
  27136. $v[1] -= ($yadj[$p]*_MPDFK);
  27137. $this->PageLinks[$p2][] = $v;
  27138. }
  27139. }
  27140. foreach($this->ktForms AS $key => $f) {
  27141. $p = $f['page'];
  27142. $f['x'] += ($xadj[$p]);
  27143. $f['y'] += ($yadj[$p]);
  27144. $f['page'] = $p2;
  27145. $this->form->forms[$f['n']] = $f;
  27146. }
  27147. foreach($this->internallink AS $key => $f) {
  27148. if (is_array($f) && isset($f['kt'])) {
  27149. $f['Y'] += ($yadj[$f['PAGE']]);
  27150. $f['PAGE'] = $p2;
  27151. unset($f['kt']);
  27152. $this->internallink[$key] = $f;
  27153. }
  27154. }
  27155. /*-- ANNOTATIONS --*/
  27156. foreach($this->ktAnnots AS $p => $l) {
  27157. foreach($l AS $v) {
  27158. if ($v['x']>0) { $v['x'] += $xadj[$p]; }
  27159. else if ($v['x']<0) { $v['x'] -= $xadj[$p]; }
  27160. $v['y'] += $yadj[$p];
  27161. $this->PageAnnots[$p2][] = $v;
  27162. }
  27163. }
  27164. /*-- END ANNOTATIONS --*/
  27165. /*-- BOOKMARKS --*/
  27166. // Adjust Bookmarks
  27167. foreach($this->ktBMoutlines AS $v) {
  27168. if ($v['y'] != 0) { $v['y'] += ($yadj[$v['p']]); }
  27169. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$p2);
  27170. }
  27171. /*-- END BOOKMARKS --*/
  27172. /*-- INDEX --*/
  27173. // Adjust Reference (index)
  27174. foreach($this->ktReference AS $v) {
  27175. $Present=0;
  27176. //Search the reference (AND Ref/PageNo) in the array
  27177. for ($i=0;$i<count($this->Reference);$i++){
  27178. if ($this->Reference[$i]['t']==$v['t']){
  27179. $Present=1;
  27180. if (!in_array($p2,$this->Reference[$i]['p'])) {
  27181. $this->Reference[$i]['p'][] = $p2;
  27182. }
  27183. }
  27184. }
  27185. //If not found, add it
  27186. if ($Present==0) {
  27187. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  27188. }
  27189. }
  27190. /*-- END INDEX --*/
  27191. /*-- TOC --*/
  27192. // Adjust ToC
  27193. foreach($this->_kttoc AS $v) {
  27194. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$p2,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27195. $this->links[$v['link']][0] = $p2;
  27196. $this->links[$v['link']][1] += $yadj[$v['p']];
  27197. }
  27198. /*-- END TOC --*/
  27199. $this->y = $top[$p2] + $height[$p1] + $height[$p2];
  27200. $this->x = $this->lMargin;
  27201. $this->divbuffer = array();
  27202. $this->ktLinks = array();
  27203. $this->ktAnnots = array();
  27204. $this->ktForms = array();
  27205. $this->ktBlock = array();
  27206. $this->ktReference = array();
  27207. $this->ktBMoutlines = array();
  27208. $this->_kttoc = array();
  27209. $this->keep_block_together = 0;
  27210. }
  27211. }
  27212. //==================================================================
  27213. // Added ELLIPSES and CIRCLES
  27214. function Circle($x,$y,$r,$style='S') {
  27215. $this->Ellipse($x,$y,$r,$r,$style);
  27216. }
  27217. function Ellipse($x,$y,$rx,$ry,$style='S') {
  27218. if($style=='F') { $op='f'; }
  27219. elseif($style=='FD' or $style=='DF') { $op='B'; }
  27220. else { $op='S'; }
  27221. $lx=4/3*(M_SQRT2-1)*$rx;
  27222. $ly=4/3*(M_SQRT2-1)*$ry;
  27223. $h=$this->h;
  27224. $this->_out(sprintf('%.3F %.3F m %.3F %.3F %.3F %.3F %.3F %.3F c', ($x+$rx)*_MPDFK,($h-$y)*_MPDFK, ($x+$rx)*_MPDFK,($h-($y-$ly))*_MPDFK, ($x+$lx)*_MPDFK,($h-($y-$ry))*_MPDFK, $x*_MPDFK,($h-($y-$ry))*_MPDFK));
  27225. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c', ($x-$lx)*_MPDFK,($h-($y-$ry))*_MPDFK, ($x-$rx)*_MPDFK,($h-($y-$ly))*_MPDFK, ($x-$rx)*_MPDFK,($h-$y)*_MPDFK));
  27226. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c', ($x-$rx)*_MPDFK,($h-($y+$ly))*_MPDFK, ($x-$lx)*_MPDFK,($h-($y+$ry))*_MPDFK, $x*_MPDFK,($h-($y+$ry))*_MPDFK));
  27227. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c %s', ($x+$lx)*_MPDFK,($h-($y+$ry))*_MPDFK, ($x+$rx)*_MPDFK,($h-($y+$ly))*_MPDFK, ($x+$rx)*_MPDFK,($h-$y)*_MPDFK, $op));
  27228. }
  27229. /*-- DIRECTW --*/
  27230. // Added adaptation of shaded_box = AUTOSIZE-TEXT
  27231. function AutosizeText($text,$w,$font,$style,$szfont=72) {
  27232. $text = $this->purify_utf8_text($text);
  27233. if ($this->text_input_as_HTML) {
  27234. $text = $this->all_entities_to_utf8($text);
  27235. }
  27236. if ($this->usingCoreFont) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  27237. $text = ' '.$text.' ';
  27238. $width = $this->ConvertSize($w);
  27239. $loop = 0;
  27240. while ( $loop == 0 ) {
  27241. $this->SetFont($font,$style,$szfont);
  27242. $sz = $this->GetStringWidth( $text );
  27243. if ( $sz > $w ) { $szfont --; }
  27244. else { $loop ++; }
  27245. }
  27246. $this->SetFont($font,$style,$szfont);
  27247. $this->Cell($w, 0, $text, 0, 0, "C");
  27248. }
  27249. /*-- END DIRECTW --*/
  27250. // ====================================================
  27251. // ====================================================
  27252. /*-- RTL --*/
  27253. function reverse_letters($str) {
  27254. $str = strtr($str, '{}[]()', '}{][)(');
  27255. return $this->mb_strrev($str, $this->mb_enc);
  27256. }
  27257. function magic_reverse_dir(&$chunk, $join=true, $dir) {
  27258. if ($this->usingCoreFont) { return 0; }
  27259. if ($this->biDirectional) {
  27260. // mPDF 5.4.05 Include PUA for non-indexed Arabic glyphs
  27261. $pregRTLchars = $this->pregRTLchars;
  27262. if ($this->CurrentFont['unAGlyphs']) { $pregRTLchars .= "\x{F500}-\x{F7FF}"; }
  27263. // Change Arabic + Persian. to Presentation Forms
  27264. if ($join) {
  27265. $chunk = preg_replace("/([".$pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $chunk );
  27266. }
  27267. $contains_rtl = false;
  27268. $all_rtl = true;
  27269. $initSpace = false;
  27270. $endSpace = false;
  27271. $nonDirchars = "\x{A0}\"\'\(\)\{\}\[\].,:\\/-="; // mPDF 5.6.32
  27272. // mPDF 5.6.43
  27273. $bdo=array();
  27274. preg_match_all('/([\x{202A}\x{202B}])(.*?)([\x{202C}])/u',$chunk,$m);
  27275. if (count($m[0])) {
  27276. for($i=0;$i<count($m[0]);$i++) {
  27277. if ($m[1][$i]=="\xe2\x80\xab") { // Right-to-Left Embedding [RLE] U+202B &#8235;
  27278. $mark = code2utf(0xf800+$i);
  27279. $bdo[$i] = $this->reverse_letters($m[2][$i]);
  27280. }
  27281. else if ($m[1][$i]=="\xe2\x80\xaa") { // Left-to-Right Embedding [LRE] U+202A &#8234;
  27282. $mark = code2utf(0xf880+$i);
  27283. $bdo[$i] = $m[2][$i];
  27284. }
  27285. $chunk = preg_replace('/'.preg_quote($m[0][$i],'/').'/u',$mark,$chunk);
  27286. }
  27287. $pregRTLchars .= "\x{F800}-\x{F87F}";
  27288. }
  27289. if (preg_match("/[".$pregRTLchars."]/u",$chunk)) { // Chunk contains RTL characters
  27290. if (preg_match("/^[ ]/",$chunk)) { $initSpace = true; $chunk = preg_replace("/^[ ]/",'',$chunk); }
  27291. if (preg_match("/[ ]$/",$chunk)) { $endSpace = true; $chunk = preg_replace("/[ ]$/",'',$chunk); }
  27292. if (preg_match("/[^".$pregRTLchars.$nonDirchars." ]/u",$chunk)) { // Chunk also contains LTR characters
  27293. $all_rtl = false;
  27294. if ($dir == 'rtl') {
  27295. $chunk = preg_replace("/([^".$pregRTLchars.$nonDirchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[^".$pregRTLchars.$nonDirchars."])/u","\\1\x07\\2",$chunk);
  27296. }
  27297. $chunk = preg_replace("/([".$pregRTLchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[".$pregRTLchars."])/u","\\1\x07\\2",$chunk);
  27298. $bits = explode(' ',$chunk);
  27299. foreach($bits AS $bitkey=>$bit) {
  27300. $bit = preg_replace("/\x07/"," ",$bit);
  27301. if (preg_match("/^[".$pregRTLchars.$nonDirchars." ]*$/u",$bit)) {
  27302. $bits[$bitkey] = $this->reverse_letters($bit);
  27303. }
  27304. else if (preg_match("/[".$pregRTLchars."]/u",$bit)) {
  27305. if ($dir == 'rtl') {
  27306. $bit = preg_replace("/([^".$pregRTLchars.$nonDirchars." ])([".$nonDirchars."]*[".$pregRTLchars."])/u","\\1\x07\\2",$bit );
  27307. $bit = preg_replace("/([".$pregRTLchars."][".$nonDirchars."]*)([^".$pregRTLchars.$nonDirchars." ])/u","\\1\x07\\2",$bit );
  27308. }
  27309. else {
  27310. $bit = preg_replace("/([^".$pregRTLchars." ][".$nonDirchars."]*)([".$pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27311. $bit = preg_replace("/([".$pregRTLchars." ])([".$nonDirchars."]*[^".$pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27312. }
  27313. $sbits = explode("\x07",$bit );
  27314. foreach($sbits AS $sbitkey=>$sbit) {
  27315. $sbit = preg_replace("/\x07/","",$sbit);
  27316. if (preg_match("/^[".$pregRTLchars.$nonDirchars." ]*$/u",$sbit)) {
  27317. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27318. }
  27319. else if (preg_match("/[".$pregRTLchars."]/u",$sbit) && $dir=='rtl') {
  27320. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27321. }
  27322. else {
  27323. // Reverse numerals only to RTL
  27324. $sbit = preg_replace("/([\x{0660}-\x{066C}0-9]+[\x{0660}-\x{066C}0-9\.,:\/]*[\x{0660}-\x{066C}0-9]+)/ue", '$this->reverse_letters(\'\\1\')', $sbit ); // mPDF 5.6.32 // mPDF 5.6.46
  27325. $sbits[$sbitkey] = $sbit;
  27326. }
  27327. }
  27328. if ($dir == 'rtl') { $sbits = array_reverse($sbits,false); }
  27329. $bits[$bitkey] = implode('',$sbits);
  27330. }
  27331. else if (preg_match("/[".$pregRTLchars."]/u",$bit) && $dir=='rtl') {
  27332. $bits[$bitkey] = $this->reverse_letters($bit);
  27333. }
  27334. else {
  27335. // Reverse numerals only to RTL
  27336. $bit = preg_replace("/([\x{0660}-\x{066C}0-9]+[\x{0660}-\x{066C}0-9\.,:\/]*[\x{0660}-\x{066C}0-9]+)/ue", '$this->reverse_letters(\'\\1\')', $bit ); // mPDF 5.6.32 // mPDF 5.6.46
  27337. $bits[$bitkey] = $bit;
  27338. }
  27339. }
  27340. if ($dir == 'rtl') { $bits = array_reverse($bits,false); }
  27341. $chunk = implode(' ',$bits);
  27342. }
  27343. else { $chunk = $this->reverse_letters($chunk); }
  27344. $contains_rtl = true;
  27345. // Un-Reverse numerals back to ltr
  27346. $chunk = preg_replace("/([\x{0660}-\x{066C}0-9]+[\x{0660}-\x{066C}0-9\.,:\/]*[\x{0660}-\x{066C}0-9]+)/ue", '$this->reverse_letters(\'\\1\')', $chunk ); // mPDF 5.6.13 // mPDF 5.6.32 // mPDF 5.6.46
  27347. if ($dir == 'rtl') {
  27348. if ($endSpace) { $chunk = ' '.$chunk; }
  27349. if ($initSpace) { $chunk .= ' '; }
  27350. }
  27351. else {
  27352. if ($initSpace) { $chunk = ' '.$chunk; }
  27353. if ($endSpace) { $chunk .= ' '; }
  27354. }
  27355. }
  27356. else { $all_rtl = false; }
  27357. // mPDF 5.6.43
  27358. if (count($bdo)) {
  27359. for($i=0;$i<count($bdo);$i++) {
  27360. $chunk = preg_replace('/[\x{'.dechex(intval(0xf800+$i)).'}\x{'.dechex(intval(0xf880+$i)).'}]/u',$bdo[$i],$chunk);
  27361. }
  27362. }
  27363. if ($all_rtl) { return 2; }
  27364. else if ($contains_rtl) { return 1; }
  27365. else { return 0; }
  27366. }
  27367. return 0;
  27368. }
  27369. /*-- END RTL --*/
  27370. //
  27371. // ****************************
  27372. // ****************************
  27373. function SetSubstitutions() {
  27374. $subsarray = array();
  27375. @include(_MPDF_PATH.'includes/subs_win-1252.php');
  27376. $this->substitute = array();
  27377. foreach($subsarray AS $key => $val) {
  27378. $this->substitute[code2utf($key)] = $val;
  27379. }
  27380. }
  27381. function SubstituteChars($html) {
  27382. // only substitute characters between tags
  27383. if (count($this->substitute)) {
  27384. $a=preg_split('/(<.*?>)/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  27385. $html = '';
  27386. foreach($a as $i => $e) {
  27387. if($i%2==0) {
  27388. $e = strtr($e, $this->substitute);
  27389. }
  27390. $html .= $e;
  27391. }
  27392. }
  27393. return $html;
  27394. }
  27395. function SubstituteCharsSIP(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27396. if (preg_match("/^(.*?)([\x{20000}-\x{2FFFF}]+)(.*)/u", $writehtml_e, $m)) {
  27397. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27398. $font = $this->CurrentFont['sipext'];
  27399. if (!in_array($font, $this->available_unifonts)) { return 0; }
  27400. $writehtml_a[$writehtml_i] = $writehtml_e = $m[1];
  27401. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27402. $this->subPos = $writehtml_i;
  27403. return 4;
  27404. }
  27405. }
  27406. return 0;
  27407. }
  27408. // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font
  27409. function SubstituteCharsNonCore(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27410. if (mb_convert_encoding(mb_convert_encoding($writehtml_e, $this->mb_enc, "UTF-8"), "UTF-8", $this->mb_enc) == $writehtml_e) {
  27411. return 0;
  27412. }
  27413. $cw = &$this->CurrentFont['cw'];
  27414. $unicode = $this->UTF8StringToArray($writehtml_e, false);
  27415. $start = -1;
  27416. $end = 0;
  27417. $flag = 0;
  27418. $ftype = '';
  27419. $u = array();
  27420. if (!$this->subArrMB) {
  27421. include(_MPDF_PATH.'includes/subs_core.php');
  27422. $this->subArrMB['a'] = $aarr;
  27423. $this->subArrMB['s'] = $sarr;
  27424. $this->subArrMB['z'] = $zarr;
  27425. }
  27426. foreach($unicode AS $c => $char) {
  27427. if (($char> 127 || ($flag==1 && $char==32)) && $char != 173 && (!isset($this->subArrMB['a'][$char]) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) {
  27428. if ($flag==0) { $start=$c; }
  27429. $flag=1;
  27430. $u[] = $char;
  27431. }
  27432. else if ($flag>0) { $end=$c-1; break; }
  27433. }
  27434. if ($flag>0 && !$end) { $end=count($unicode)-1; }
  27435. if ($start==-1) { return 0; }
  27436. // TRY IN BACKUP SUBS FONT
  27437. if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); }
  27438. foreach($this->backupSubsFont AS $bsfctr=>$bsf) {
  27439. if ($this->fonttrans[$bsf] == 'chelvetica' || $this->fonttrans[$bsf] == 'ctimes' || $this->fonttrans[$bsf] == 'ccourier') { continue; }
  27440. $font = $bsf;
  27441. unset($cw);
  27442. $cw = '';
  27443. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27444. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27445. else {
  27446. $prevFontFamily = $this->FontFamily;
  27447. $prevFontStyle = $this->currentfontstyle;
  27448. $prevFontSizePt = $this->FontSizePt;
  27449. $this->SetFont($bsf, '', '', false);
  27450. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27451. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27452. }
  27453. if (!$cw) { continue; }
  27454. $l = 0;
  27455. foreach($u AS $char) {
  27456. if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) {
  27457. $l++;
  27458. }
  27459. else {
  27460. if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font
  27461. $cont = mb_substr($writehtml_e, $start+1);
  27462. $writehtml_e = mb_substr($writehtml_e, 0, $start+1, 'UTF-8');
  27463. array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont));
  27464. $this->subPos = $writehtml_i+1;
  27465. return 2;
  27466. }
  27467. else { break; }
  27468. }
  27469. }
  27470. if ($l > 0) {
  27471. $patt = mb_substr($writehtml_e, $start, $l, 'UTF-8');
  27472. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27473. $writehtml_e = $m[1];
  27474. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27475. $this->subPos = $writehtml_i+3;
  27476. return 4;
  27477. }
  27478. }
  27479. }
  27480. unset($cw);
  27481. return 0;
  27482. }
  27483. function SubstituteCharsMB(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27484. $cw = &$this->CurrentFont['cw'];
  27485. $unicode = $this->UTF8StringToArray($writehtml_e, false);
  27486. $start = -1;
  27487. $end = 0;
  27488. $flag = 0;
  27489. $ftype = '';
  27490. $u = array();
  27491. foreach($unicode AS $c => $char) {
  27492. if (($flag == 0 || $flag==2) && (!$this->_charDefined($cw,$char) || ($flag==2 && $char==32)) && $this->checkSIP && $char > 131071) { // Unicode Plane 2 (SIP)
  27493. if (in_array($this->FontFamily ,$this->available_CJK_fonts)) { return 0; }
  27494. if ($flag==0) { $start=$c; }
  27495. $flag=2;
  27496. $u[] = $char;
  27497. }
  27498. //else if (($flag == 0 || $flag==1) && $char != 173 && !$this->_charDefined($cw,$char) && ($char<1423 || ($char>3583 && $char < 11263))) {
  27499. else if (($flag == 0 || $flag==1) && $char != 173 && (!$this->_charDefined($cw,$char) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) {
  27500. if ($flag==0) { $start=$c; }
  27501. $flag=1;
  27502. $u[] = $char;
  27503. }
  27504. else if ($flag>0) { $end=$c-1; break; }
  27505. }
  27506. if ($flag>0 && !$end) { $end=count($unicode)-1; }
  27507. if ($start==-1) { return 0; }
  27508. if ($flag == 2) { // SIP
  27509. // Check if current CJK font has a ext-B related font
  27510. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27511. $font = $this->CurrentFont['sipext'];
  27512. unset($cw);
  27513. $cw = '';
  27514. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27515. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27516. else {
  27517. $prevFontFamily = $this->FontFamily;
  27518. $prevFontStyle = $this->currentfontstyle;
  27519. $prevFontSizePt = $this->FontSizePt;
  27520. $this->SetFont($font, '', '', false);
  27521. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27522. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27523. }
  27524. if (!$cw) { return 0; }
  27525. $l = 0;
  27526. foreach($u AS $char) {
  27527. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27528. $l++;
  27529. }
  27530. else { break; }
  27531. }
  27532. if ($l > 0) {
  27533. $patt = mb_substr($writehtml_e, $start, $l);
  27534. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27535. $writehtml_e = $m[1];
  27536. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27537. $this->subPos = $writehtml_i+3;
  27538. return 4;
  27539. }
  27540. }
  27541. }
  27542. // Check Backup SIP font (defined in config_fonts.php)
  27543. if (isset($this->backupSIPFont) && $this->backupSIPFont) {
  27544. if ($this->currentfontfamily != $this->backupSIPFont) { $font = $this->backupSIPFont; }
  27545. else { unset($cw); return 0; }
  27546. unset($cw);
  27547. $cw = '';
  27548. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27549. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27550. else {
  27551. $prevFontFamily = $this->FontFamily;
  27552. $prevFontStyle = $this->currentfontstyle;
  27553. $prevFontSizePt = $this->FontSizePt;
  27554. $this->SetFont($this->backupSIPFont, '', '', false);
  27555. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27556. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27557. }
  27558. if (!$cw) { return 0; }
  27559. $l = 0;
  27560. foreach($u AS $char) {
  27561. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27562. $l++;
  27563. }
  27564. else { break; }
  27565. }
  27566. if ($l > 0) {
  27567. $patt = mb_substr($writehtml_e, $start, $l);
  27568. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27569. $writehtml_e = $m[1];
  27570. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27571. $this->subPos = $writehtml_i+3;
  27572. return 4;
  27573. }
  27574. }
  27575. }
  27576. return 0;
  27577. }
  27578. // FIRST TRY CORE FONTS
  27579. if (!$this->PDFA && !$this->PDFX) {
  27580. $repl = array();
  27581. if (!$this->subArrMB) {
  27582. include(_MPDF_PATH.'includes/subs_core.php');
  27583. $this->subArrMB['a'] = $aarr;
  27584. $this->subArrMB['s'] = $sarr;
  27585. $this->subArrMB['z'] = $zarr;
  27586. }
  27587. if (isset($this->subArrMB['a'][$u[0]])) {
  27588. $font = 'tta'; $ftype = 'C';
  27589. foreach($u AS $char) {
  27590. if ($this->subArrMB['a'][$char]) { $repl[] = $this->subArrMB['a'][$char]; }
  27591. else { break; }
  27592. }
  27593. }
  27594. else if (isset($this->subArrMB['z'][$u[0]])) {
  27595. $font = 'ttz'; $ftype = 'C';
  27596. foreach($u AS $char) {
  27597. if ($this->subArrMB['z'][$char]) { $repl[] = $this->subArrMB['z'][$char]; }
  27598. else { break; }
  27599. }
  27600. }
  27601. else if (isset($this->subArrMB['s'][$u[0]])) {
  27602. $font = 'tts'; $ftype = 'C';
  27603. foreach($u AS $char) {
  27604. if ($this->subArrMB['s'][$char]) { $repl[] = $this->subArrMB['s'][$char]; }
  27605. else { break; }
  27606. }
  27607. }
  27608. if ($ftype=='C') {
  27609. $patt = mb_substr($writehtml_e, $start, count($repl));
  27610. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27611. $writehtml_e = $m[1];
  27612. array_splice($writehtml_a, $writehtml_i+1, 0, array($font, implode('|', $repl), '/'.$font, $m[3])); // e.g. <tts>
  27613. $this->subPos = $writehtml_i+3;
  27614. return 4;
  27615. }
  27616. return 0;
  27617. }
  27618. }
  27619. // FIND IN DEFAULT FONT - removed mPDF 5.0
  27620. // LASTLY TRY IN BACKUP SUBS FONT
  27621. if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); }
  27622. foreach($this->backupSubsFont AS $bsfctr=>$bsf) {
  27623. if ($this->currentfontfamily != $bsf) { $font = $bsf; }
  27624. else { continue; }
  27625. unset($cw);
  27626. $cw = '';
  27627. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27628. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27629. else {
  27630. $prevFontFamily = $this->FontFamily;
  27631. $prevFontStyle = $this->currentfontstyle;
  27632. $prevFontSizePt = $this->FontSizePt;
  27633. $this->SetFont($bsf, '', '', false);
  27634. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27635. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27636. }
  27637. if (!$cw) { continue; }
  27638. $l = 0;
  27639. foreach($u AS $char) {
  27640. if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) { // Arabic and Indic
  27641. $l++;
  27642. }
  27643. else {
  27644. if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font
  27645. $cont = mb_substr($writehtml_e, $start+1);
  27646. $writehtml_e = mb_substr($writehtml_e, 0, $start+1);
  27647. array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont));
  27648. $this->subPos = $writehtml_i+1;
  27649. return 2;
  27650. }
  27651. else { break; }
  27652. }
  27653. }
  27654. if ($l > 0) {
  27655. $patt = mb_substr($writehtml_e, $start, $l);
  27656. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27657. $writehtml_e = $m[1];
  27658. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27659. $this->subPos = $writehtml_i+3;
  27660. return 4;
  27661. }
  27662. }
  27663. }
  27664. unset($cw);
  27665. return 0;
  27666. }
  27667. function setHiEntitySubstitutions() {
  27668. $entarr = array (
  27669. 'nbsp' => '160', 'iexcl' => '161', 'cent' => '162', 'pound' => '163', 'curren' => '164', 'yen' => '165', 'brvbar' => '166', 'sect' => '167',
  27670. 'uml' => '168', 'copy' => '169', 'ordf' => '170', 'laquo' => '171', 'not' => '172', 'shy' => '173', 'reg' => '174', 'macr' => '175',
  27671. 'deg' => '176', 'plusmn' => '177', 'sup2' => '178', 'sup3' => '179', 'acute' => '180', 'micro' => '181', 'para' => '182', 'middot' => '183',
  27672. 'cedil' => '184', 'sup1' => '185', 'ordm' => '186', 'raquo' => '187', 'frac14' => '188', 'frac12' => '189', 'frac34' => '190',
  27673. 'iquest' => '191', 'Agrave' => '192', 'Aacute' => '193', 'Acirc' => '194', 'Atilde' => '195', 'Auml' => '196', 'Aring' => '197',
  27674. 'AElig' => '198', 'Ccedil' => '199', 'Egrave' => '200', 'Eacute' => '201', 'Ecirc' => '202', 'Euml' => '203', 'Igrave' => '204',
  27675. 'Iacute' => '205', 'Icirc' => '206', 'Iuml' => '207', 'ETH' => '208', 'Ntilde' => '209', 'Ograve' => '210', 'Oacute' => '211',
  27676. 'Ocirc' => '212', 'Otilde' => '213', 'Ouml' => '214', 'times' => '215', 'Oslash' => '216', 'Ugrave' => '217', 'Uacute' => '218',
  27677. 'Ucirc' => '219', 'Uuml' => '220', 'Yacute' => '221', 'THORN' => '222', 'szlig' => '223', 'agrave' => '224', 'aacute' => '225',
  27678. 'acirc' => '226', 'atilde' => '227', 'auml' => '228', 'aring' => '229', 'aelig' => '230', 'ccedil' => '231', 'egrave' => '232',
  27679. 'eacute' => '233', 'ecirc' => '234', 'euml' => '235', 'igrave' => '236', 'iacute' => '237', 'icirc' => '238', 'iuml' => '239',
  27680. 'eth' => '240', 'ntilde' => '241', 'ograve' => '242', 'oacute' => '243', 'ocirc' => '244', 'otilde' => '245', 'ouml' => '246',
  27681. 'divide' => '247', 'oslash' => '248', 'ugrave' => '249', 'uacute' => '250', 'ucirc' => '251', 'uuml' => '252', 'yacute' => '253',
  27682. 'thorn' => '254', 'yuml' => '255', 'OElig' => '338', 'oelig' => '339', 'Scaron' => '352', 'scaron' => '353', 'Yuml' => '376',
  27683. 'fnof' => '402', 'circ' => '710', 'tilde' => '732', 'Alpha' => '913', 'Beta' => '914', 'Gamma' => '915', 'Delta' => '916',
  27684. 'Epsilon' => '917', 'Zeta' => '918', 'Eta' => '919', 'Theta' => '920', 'Iota' => '921', 'Kappa' => '922', 'Lambda' => '923',
  27685. 'Mu' => '924', 'Nu' => '925', 'Xi' => '926', 'Omicron' => '927', 'Pi' => '928', 'Rho' => '929', 'Sigma' => '931', 'Tau' => '932',
  27686. 'Upsilon' => '933', 'Phi' => '934', 'Chi' => '935', 'Psi' => '936', 'Omega' => '937', 'alpha' => '945', 'beta' => '946', 'gamma' => '947',
  27687. 'delta' => '948', 'epsilon' => '949', 'zeta' => '950', 'eta' => '951', 'theta' => '952', 'iota' => '953', 'kappa' => '954',
  27688. 'lambda' => '955', 'mu' => '956', 'nu' => '957', 'xi' => '958', 'omicron' => '959', 'pi' => '960', 'rho' => '961', 'sigmaf' => '962',
  27689. 'sigma' => '963', 'tau' => '964', 'upsilon' => '965', 'phi' => '966', 'chi' => '967', 'psi' => '968', 'omega' => '969',
  27690. 'thetasym' => '977', 'upsih' => '978', 'piv' => '982', 'ensp' => '8194', 'emsp' => '8195', 'thinsp' => '8201', 'zwnj' => '8204',
  27691. 'zwj' => '8205', 'lrm' => '8206', 'rlm' => '8207', 'ndash' => '8211', 'mdash' => '8212', 'lsquo' => '8216', 'rsquo' => '8217',
  27692. 'sbquo' => '8218', 'ldquo' => '8220', 'rdquo' => '8221', 'bdquo' => '8222', 'dagger' => '8224', 'Dagger' => '8225', 'bull' => '8226',
  27693. 'hellip' => '8230', 'permil' => '8240', 'prime' => '8242', 'Prime' => '8243', 'lsaquo' => '8249', 'rsaquo' => '8250', 'oline' => '8254',
  27694. 'frasl' => '8260', 'euro' => '8364', 'image' => '8465', 'weierp' => '8472', 'real' => '8476', 'trade' => '8482', 'alefsym' => '8501',
  27695. 'larr' => '8592', 'uarr' => '8593', 'rarr' => '8594', 'darr' => '8595', 'harr' => '8596', 'crarr' => '8629', 'lArr' => '8656',
  27696. 'uArr' => '8657', 'rArr' => '8658', 'dArr' => '8659', 'hArr' => '8660', 'forall' => '8704', 'part' => '8706', 'exist' => '8707',
  27697. 'empty' => '8709', 'nabla' => '8711', 'isin' => '8712', 'notin' => '8713', 'ni' => '8715', 'prod' => '8719', 'sum' => '8721',
  27698. 'minus' => '8722', 'lowast' => '8727', 'radic' => '8730', 'prop' => '8733', 'infin' => '8734', 'ang' => '8736', 'and' => '8743',
  27699. 'or' => '8744', 'cap' => '8745', 'cup' => '8746', 'int' => '8747', 'there4' => '8756', 'sim' => '8764', 'cong' => '8773',
  27700. 'asymp' => '8776', 'ne' => '8800', 'equiv' => '8801', 'le' => '8804', 'ge' => '8805', 'sub' => '8834', 'sup' => '8835', 'nsub' => '8836',
  27701. 'sube' => '8838', 'supe' => '8839', 'oplus' => '8853', 'otimes' => '8855', 'perp' => '8869', 'sdot' => '8901', 'lceil' => '8968',
  27702. 'rceil' => '8969', 'lfloor' => '8970', 'rfloor' => '8971', 'lang' => '9001', 'rang' => '9002', 'loz' => '9674', 'spades' => '9824',
  27703. 'clubs' => '9827', 'hearts' => '9829', 'diams' => '9830',
  27704. );
  27705. foreach($entarr AS $key => $val) {
  27706. $this->entsearch[] = '&'.$key.';';
  27707. $this->entsubstitute[] = code2utf($val);
  27708. }
  27709. }
  27710. function SubstituteHiEntities($html) {
  27711. // converts html_entities > ASCII 127 to unicode
  27712. // Leaves in particular &lt; to distinguish from tag marker
  27713. if (count($this->entsearch)) {
  27714. $html = str_replace($this->entsearch,$this->entsubstitute,$html);
  27715. }
  27716. return $html;
  27717. }
  27718. // Edited v1.2 Pass by reference; option to continue if invalid UTF-8 chars
  27719. function is_utf8(&$string) {
  27720. if ($string === mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
  27721. return true;
  27722. }
  27723. else {
  27724. if ($this->ignore_invalid_utf8) {
  27725. $string = mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") ;
  27726. return true;
  27727. }
  27728. else {
  27729. return false;
  27730. }
  27731. }
  27732. }
  27733. function purify_utf8($html,$lo=true) {
  27734. // For HTML
  27735. // Checks string is valid UTF-8 encoded
  27736. // converts html_entities > ASCII 127 to UTF-8
  27737. // Only exception - leaves low ASCII entities e.g. &lt; &amp; etc.
  27738. // Leaves in particular &lt; to distinguish from tag marker
  27739. if (!$this->is_utf8($html)) {
  27740. echo "<p><b>HTML contains invalid UTF-8 character(s)</b></p>";
  27741. while (mb_convert_encoding(mb_convert_encoding($html, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") != $html) {
  27742. $a = iconv('UTF-8', 'UTF-8', $html);
  27743. echo ($a);
  27744. $pos = $start = strlen($a);
  27745. $err = '';
  27746. while ( ord(substr($html,$pos,1)) > 128 ) {
  27747. $err .= '[[#'.ord(substr($html,$pos,1)).']]';
  27748. $pos++;
  27749. }
  27750. echo '<span style="color:red; font-weight:bold">'.$err.'</span>';
  27751. $html = substr($html, $pos);
  27752. }
  27753. echo $html;
  27754. $this->Error("");
  27755. }
  27756. $html = preg_replace("/\r/", "", $html );
  27757. // converts html_entities > ASCII 127 to UTF-8
  27758. // Leaves in particular &lt; to distinguish from tag marker
  27759. $html = $this->SubstituteHiEntities($html);
  27760. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  27761. // If $lo==true then includes ASCII < 128
  27762. $html = strcode2utf($html,$lo);
  27763. return ($html);
  27764. }
  27765. function purify_utf8_text($txt) {
  27766. // For TEXT
  27767. // Make sure UTF-8 string of characters
  27768. if (!$this->is_utf8($txt)) { $this->Error("Text contains invalid UTF-8 character(s)"); }
  27769. $txt = preg_replace("/\r/", "", $txt );
  27770. return ($txt);
  27771. }
  27772. function all_entities_to_utf8($txt) {
  27773. // converts txt_entities > ASCII 127 to UTF-8
  27774. // Leaves in particular &lt; to distinguish from tag marker
  27775. $txt = $this->SubstituteHiEntities($txt);
  27776. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  27777. $txt = strcode2utf($txt);
  27778. $txt = $this->lesser_entity_decode($txt);
  27779. return ($txt);
  27780. }
  27781. // ====================================================
  27782. /*-- BARCODES --*/
  27783. // UPC/EAN barcode
  27784. // EAN13, EAN8, UPCA, UPCE, ISBN, ISSN
  27785. // Accepts 12 or 13 digits with or without - hyphens
  27786. 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) {
  27787. if (empty($code)) {
  27788. return;
  27789. }
  27790. $codestr = $code;
  27791. $code = preg_replace('/\-/','',$code);
  27792. if (!class_exists('PDFBarcode', false)) {
  27793. include(_MPDF_PATH.'classes/barcode.php');
  27794. }
  27795. $this->barcode = new PDFBarcode();
  27796. if ($btype == 'ISSN' || $btype == 'ISBN') {
  27797. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  27798. }
  27799. else { $arrcode = $this->barcode->getBarcodeArray($code, $btype); }
  27800. if ($arrcode === false) { $this->Error('Error in barcode string: '.$codestr); }
  27801. if((($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') && strlen($code) == 12) || ($btype=='UPCA' && strlen($code) == 11)
  27802. || ($btype=='UPCE' && strlen($code) == 11) || ($btype=='EAN8' && strlen($code) == 7)) {
  27803. $code .= $arrcode['checkdigit'];
  27804. if (stristr($codestr,'-')) { $codestr .= '-' . $arrcode['checkdigit']; }
  27805. else { $codestr .= $arrcode['checkdigit']; }
  27806. }
  27807. if ($btype == 'ISBN') { $codestr = 'ISBN '.$codestr; }
  27808. if ($btype == 'ISSN') { $codestr = 'ISSN '.$codestr; }
  27809. if (empty($x)) {
  27810. $x = $this->x;
  27811. }
  27812. if (empty($y)) {
  27813. $y = $this->y;
  27814. }
  27815. // set foreground color
  27816. $prevDrawColor = $this->DrawColor;
  27817. $prevTextColor = $this->TextColor;
  27818. $prevFillColor = $this->FillColor;
  27819. $lw = $this->LineWidth;
  27820. $this->SetLineWidth(0.01);
  27821. $size /= $k; // in case resized in a table
  27822. $xres = $arrcode['nom-X'] * $size;
  27823. $llm = $arrcode['lightmL'] * $arrcode['nom-X'] * $size; // Left Light margin
  27824. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  27825. $bcw = ($arrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  27826. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  27827. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  27828. $fbwi = $fbw - 2; // Full barcode width incl. light margins - 2mm - for isbn string
  27829. // cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf
  27830. $num_height = 3 * $size; // Height of numerals
  27831. $fbh = $arrcode['nom-H'] * $size * $height; // Full barcode height incl. numerals
  27832. $bch = $fbh - (1.5 * $size); // Barcode height of bars (3mm for numerals)
  27833. if (($btype=='EAN13' && $showtext) || $btype == 'ISSN' || $btype == 'ISBN') { // Add height for ISBN string + margin from top of bars
  27834. $tisbnm = 1.5 * $size; // Top margin between isbn (if shown) & bars
  27835. $codestr_fontsize = 2.1 * $size;
  27836. $paddingT += $codestr_fontsize + $tisbnm ;
  27837. }
  27838. $oh = $fbh + $paddingT + $paddingB; // Full overall height incl. user-defined padding
  27839. // PRINT border background color
  27840. $xpos = $x;
  27841. $ypos = $y;
  27842. if ($col) {
  27843. $this->SetDColor($col);
  27844. $this->SetTColor($col);
  27845. }
  27846. else {
  27847. $this->SetDColor($this->ConvertColor(0));
  27848. $this->SetTColor($this->ConvertColor(0));
  27849. }
  27850. if ($bgcol) {
  27851. $this->SetFColor($bgcol);
  27852. }
  27853. else { $this->SetFColor($this->ConvertColor(255)); }
  27854. if (!$bgcol && !$col) { // fn. called directly - not via HTML
  27855. if ($border) { $fillb = 'DF'; } else { $fillb = 'F'; }
  27856. $this->Rect($xpos, $ypos, $ow, $oh, $fillb);
  27857. }
  27858. // PRINT BARS
  27859. $xpos = $x + $paddingL + $llm ;
  27860. $ypos = $y + $paddingT;
  27861. if ($col) { $this->SetFColor($col); }
  27862. else { $this->SetFColor($this->ConvertColor(0)); }
  27863. if ($arrcode !== false) {
  27864. foreach ($arrcode["bcode"] AS $v) {
  27865. $bw = ($v["w"] * $xres);
  27866. if ($v["t"]) {
  27867. // draw a vertical bar
  27868. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  27869. }
  27870. $xpos += $bw;
  27871. }
  27872. }
  27873. // print text
  27874. $prevFontFamily = $this->FontFamily;
  27875. $prevFontStyle = $this->FontStyle;
  27876. $prevFontSizePt = $this->FontSizePt;
  27877. // ISBN string
  27878. if (($btype=='EAN13' && $showtext) || $btype=='ISBN' || $btype=='ISSN') {
  27879. if ($this->onlyCoreFonts) {
  27880. $this->SetFont('chelvetica');
  27881. }
  27882. else {
  27883. $this->SetFont('sans');
  27884. }
  27885. if ($bgcol) { $this->SetFColor($bgcol); }
  27886. else { $this->SetFColor($this->ConvertColor(255)); }
  27887. $this->x = $x + $paddingL + 1; // 1mm left margin (cf. $fbwi above)
  27888. // max width is $fbwi
  27889. $loop = 0;
  27890. while ( $loop == 0 ) {
  27891. $this->SetFontSize($codestr_fontsize*1.4*_MPDFK, false); // don't write
  27892. $sz = $this->GetStringWidth( $codestr );
  27893. if ($sz > $fbwi)
  27894. $codestr_fontsize -= 0.1;
  27895. else
  27896. $loop ++;
  27897. }
  27898. $this->SetFont('','',$codestr_fontsize*1.4*_MPDFK, true, true); // * 1.4 because font height is only 7/10 of given mm
  27899. // WORD SPACING
  27900. if ($fbwi > $sz) {
  27901. $xtra = $fbwi - $sz;
  27902. $charspacing = $xtra / (strlen($codestr)-1);
  27903. if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); }
  27904. }
  27905. $this->y = $y + $paddingT - ($codestr_fontsize ) - $tisbnm ;
  27906. $this->Cell($fbw , $codestr_fontsize, $codestr);
  27907. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  27908. }
  27909. // Bottom NUMERALS
  27910. if ($this->onlyCoreFonts) {
  27911. $this->SetFont('mono');
  27912. }
  27913. else {
  27914. if (in_array('ocrb',$this->available_unifonts)) { $this->SetFont('ocrb'); }
  27915. else { $this->SetFont('mono'); }
  27916. }
  27917. if (isset($this->CurrentFont['desc']['CapHeight'])) { $fh = (1000/$this->CurrentFont['desc']['CapHeight']); }
  27918. else if (isset($this->CurrentFont['desc']['Ascent'])) { $fh = (1000/$this->CurrentFont['desc']['Ascent']); }
  27919. else { $fh = 1.2; }
  27920. $charRO = '';
  27921. if ($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') {
  27922. $outerfontsize = 3; // Inner fontsize = 3
  27923. $outerp = $xres * 4;
  27924. $innerp = $xres * 2.5;
  27925. $textw = ($bcw*0.5) - $outerp - $innerp;
  27926. $chars = 6; // number of numerals in each half
  27927. $charLO = substr($code,0,1); // Left Outer
  27928. $charLI = substr($code,1,6); // Left Inner
  27929. $charRI = substr($code,7,6); // Right Inner
  27930. if (!$supplement) $charRO = '>'; // Right Outer
  27931. }
  27932. else if ($btype=='UPCA') {
  27933. $outerfontsize = 2.3; // Inner fontsize = 3
  27934. $outerp = $xres * 10;
  27935. $innerp = $xres * 2.5;
  27936. $textw = ($bcw*0.5) - $outerp - $innerp;
  27937. $chars = 5;
  27938. $charLO = substr($code,0,1); // Left Outer
  27939. $charLI = substr($code,1,5); // Left Inner
  27940. $charRI = substr($code,6,5); // Right Inner
  27941. $charRO = substr($code,11,1); // Right Outer
  27942. }
  27943. else if ($btype=='UPCE') {
  27944. $outerfontsize = 2.3; // Inner fontsize = 3
  27945. $outerp = $xres * 4;
  27946. $innerp = 0;
  27947. $textw = ($bcw*0.5) - $outerp - $innerp;
  27948. $chars = 3;
  27949. $upce_code = $arrcode['code'];
  27950. $charLO = substr($code,0,1); // Left Outer
  27951. $charLI = substr($upce_code,0,3); // Left Inner
  27952. $charRI = substr($upce_code,3,3); // Right Inner
  27953. $charRO = substr($code,11,1); // Right Outer
  27954. }
  27955. else if ($btype=='EAN8') {
  27956. $outerfontsize = 3; // Inner fontsize = 3
  27957. $outerp = $xres * 4;
  27958. $innerp = $xres * 2.5;
  27959. $textw = ($bcw*0.5) - $outerp - $innerp;
  27960. $chars = 4;
  27961. $charLO = '<'; // Left Outer
  27962. $charLI = substr($code,0,4); // Left Inner
  27963. $charRI = substr($code,4,4); // Right Inner
  27964. if (!$supplement) $charRO = '>'; // Right Outer
  27965. }
  27966. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27967. if (!$this->usingCoreFont) { $cw = $this->_getCharWidth($this->CurrentFont['cw'],32)*3*$fh*$size/1000; } // character width at 3mm
  27968. else { $cw = $this->_getCharWidth($this->CurrentFont['cw'],48)*3*$fh*$size/1000; } // 48 == char "0"
  27969. // Outer left character
  27970. $y_text = $y + $paddingT + $bch - ($num_height/2);
  27971. $y_text_outer = $y + $paddingT + $bch - ($num_height*($outerfontsize/3)/2);
  27972. $this->x = $x + $paddingL - ($cw*($outerfontsize/3)*0.1); // 0.1 is correction as char does not fill full width;
  27973. $this->y = $y_text_outer;
  27974. $this->Cell($cw, $num_height, $charLO );
  27975. // WORD SPACING for inner chars
  27976. $xtra = $textw - ($cw*$chars);
  27977. $charspacing = $xtra / ($chars-1);
  27978. if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); }
  27979. if ($bgcol) { $this->SetFColor($bgcol); }
  27980. else { $this->SetFColor($this->ConvertColor(255)); }
  27981. $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27982. // Inner left half characters
  27983. $this->x = $x + $paddingL + $llm + $outerp;
  27984. $this->y = $y_text;
  27985. $this->Cell($textw, $num_height, $charLI , 0, 0, '', 1);
  27986. // Inner right half characters
  27987. $this->x = $x + $paddingL + $llm + ($bcw*0.5) + $innerp;
  27988. $this->y = $y_text;
  27989. $this->Cell($textw, $num_height, $charRI , 0, 0, '', 1);
  27990. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  27991. // Outer Right character
  27992. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  27993. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*($outerfontsize/3)*0.9); // 0.9 is correction as char does not fill full width
  27994. $this->y = $y_text_outer;
  27995. $this->Cell($cw*($outerfontsize/3), $num_height, $charRO , 0, 0, 'R');
  27996. if ($supplement) { // EAN-2 or -5 Supplement
  27997. // PRINT BARS
  27998. $supparrcode = $this->barcode->getBarcodeArray($supplement_code, 'EAN'.$supplement);
  27999. if ($supparrcode === false) { $this->Error('Error in barcode string (supplement): '.$codestr.' '.$supplement_code); }
  28000. if(strlen($supplement_code) != $supplement) {
  28001. $this->Error('Barcode supplement incorrect: '.$supplement_code);
  28002. }
  28003. $llm = $fbw - (($arrcode['lightmR'] - $supparrcode['sepM']) * $arrcode['nom-X'] * $size); // Left Light margin
  28004. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  28005. $bcw = ($supparrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  28006. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28007. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  28008. $bch = $fbh - (1.5 * $size) - ($num_height + 0.5); // Barcode height of bars (3mm for numerals)
  28009. $xpos = $x + $paddingL + $llm ;
  28010. $ypos = $y + $paddingT + $num_height + 0.5;
  28011. if ($col) { $this->SetFColor($col); }
  28012. else { $this->SetFColor($this->ConvertColor(0)); }
  28013. if ($supparrcode !== false) {
  28014. foreach ($supparrcode["bcode"] AS $v) {
  28015. $bw = ($v["w"] * $xres);
  28016. if ($v["t"]) {
  28017. // draw a vertical bar
  28018. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  28019. }
  28020. $xpos += $bw;
  28021. }
  28022. }
  28023. // Characters
  28024. if ($bgcol) { $this->SetFColor($bgcol); }
  28025. else { $this->SetFColor($this->ConvertColor(255)); }
  28026. $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28027. $this->x = $x + $paddingL + $llm;
  28028. $this->y = $y + $paddingT;
  28029. $this->Cell($bcw, $num_height, $supplement_code, 0, 0, 'C');
  28030. // Outer Right character (light margin)
  28031. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28032. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*0.9); // 0.9 is correction as char does not fill full width
  28033. $this->y = $y + $paddingT;
  28034. $this->Cell($cw*($outerfontsize/3), $num_height, '>', 0, 0, 'R');
  28035. }
  28036. // Restore **************
  28037. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  28038. $this->DrawColor = $prevDrawColor;
  28039. $this->TextColor = $prevTextColor;
  28040. $this->FillColor = $prevFillColor;
  28041. $this->SetLineWidth($lw);
  28042. $this->SetY($y);
  28043. }
  28044. // ====================================================
  28045. // POSTAL and OTHER barcodes
  28046. function WriteBarcode2($code, $x='', $y='', $size=1, $height=1, $bgcol=false, $col=false, $btype='IMB', $print_ratio='', $k=1) {
  28047. if (empty($code)) { return; }
  28048. if (!class_exists('PDFBarcode', false)) {
  28049. include(_MPDF_PATH.'classes/barcode.php');
  28050. }
  28051. $this->barcode = new PDFBarcode();
  28052. $arrcode = $this->barcode->getBarcodeArray($code, $btype, $print_ratio);
  28053. if ($arrcode === false) { $this->Error('Error in barcode string: '.$code); }
  28054. if (empty($x)) { $x = $this->x; }
  28055. if (empty($y)) { $y = $this->y; }
  28056. $prevDrawColor = $this->DrawColor;
  28057. $prevTextColor = $this->TextColor;
  28058. $prevFillColor = $this->FillColor;
  28059. $lw = $this->LineWidth;
  28060. $this->SetLineWidth(0.01);
  28061. $size /= $k; // in case resized in a table
  28062. $xres = $arrcode['nom-X'] * $size;
  28063. if ($btype == 'IMB' || $btype == 'RM4SCC' || $btype == 'KIX' || $btype == 'POSTNET' || $btype == 'PLANET') {
  28064. $llm = $arrcode['quietL'] / $k; // Left Quiet margin
  28065. $rlm = $arrcode['quietR'] / $k; // Right Quiet margin
  28066. $tlm = $blm = $arrcode['quietTB'] / $k;
  28067. $height=1; // Overrides
  28068. }
  28069. 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'))) {
  28070. $llm = $arrcode['lightmL'] * $xres; // Left Quiet margin
  28071. $rlm = $arrcode['lightmR'] * $xres; // Right Quiet margin
  28072. $tlm = $blm = $arrcode['lightTB'] * $xres * $height;
  28073. }
  28074. $bcw = ($arrcode["maxw"] * $xres);
  28075. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28076. $bch = ($arrcode["nom-H"] * $size * $height);
  28077. $fbh = $bch + $tlm + $blm; // Full barcode height
  28078. // PRINT border background color
  28079. $xpos = $x;
  28080. $ypos = $y;
  28081. if ($col) {
  28082. $this->SetDColor($col);
  28083. $this->SetTColor($col);
  28084. }
  28085. else {
  28086. $this->SetDColor($this->ConvertColor(0));
  28087. $this->SetTColor($this->ConvertColor(0));
  28088. }
  28089. if ($bgcol) {
  28090. $this->SetFColor($bgcol);
  28091. }
  28092. else { $this->SetFColor($this->ConvertColor(255)); }
  28093. // PRINT BARS
  28094. if ($col) { $this->SetFColor($col); }
  28095. else { $this->SetFColor($this->ConvertColor(0)); }
  28096. $xpos = $x + $llm ;
  28097. if ($arrcode !== false) {
  28098. foreach ($arrcode["bcode"] AS $v) {
  28099. $bw = ($v["w"] * $xres);
  28100. if ($v["t"]) {
  28101. $ypos = $y + $tlm + ($bch * $v['p'] / $arrcode['maxh']);
  28102. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $bch / $arrcode['maxh']), 'F');
  28103. }
  28104. $xpos += $bw;
  28105. }
  28106. }
  28107. // PRINT BEARER BARS
  28108. if ($btype == 'I25B' || $btype == 'I25B+') {
  28109. $this->Rect($x, $y, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  28110. $this->Rect($x, $y+$tlm+$bch, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  28111. }
  28112. // Restore **************
  28113. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  28114. $this->DrawColor = $prevDrawColor;
  28115. $this->TextColor = $prevTextColor;
  28116. $this->FillColor = $prevFillColor;
  28117. $this->SetLineWidth($lw);
  28118. $this->SetY($y);
  28119. }
  28120. /*-- END BARCODES --*/
  28121. // ====================================================
  28122. // ====================================================
  28123. function StartTransform($returnstring=false) {
  28124. if ($returnstring) { return('q'); }
  28125. else { $this->_out('q'); }
  28126. }
  28127. function StopTransform($returnstring=false) {
  28128. if ($returnstring) { return('Q'); }
  28129. else { $this->_out('Q'); }
  28130. }
  28131. function transformScale($s_x, $s_y, $x='', $y='', $returnstring=false) {
  28132. if ($x === '') {
  28133. $x=$this->x;
  28134. }
  28135. if ($y === '') {
  28136. $y=$this->y;
  28137. }
  28138. if (($s_x == 0) OR ($s_y == 0)) {
  28139. $this->Error('Please do not use values equal to zero for scaling');
  28140. }
  28141. $y = ($this->h - $y) * _MPDFK;
  28142. $x *= _MPDFK;
  28143. //calculate elements of transformation matrix
  28144. $s_x /= 100;
  28145. $s_y /= 100;
  28146. $tm[0] = $s_x;
  28147. $tm[1] = 0;
  28148. $tm[2] = 0;
  28149. $tm[3] = $s_y;
  28150. $tm[4] = $x * (1 - $s_x);
  28151. $tm[5] = $y * (1 - $s_y);
  28152. //scale the coordinate system
  28153. if ($returnstring) { return($this->_transform($tm, true)); }
  28154. else { $this->_transform($tm); }
  28155. }
  28156. function transformTranslate($t_x, $t_y, $returnstring=false) {
  28157. //calculate elements of transformation matrix
  28158. $tm[0] = 1;
  28159. $tm[1] = 0;
  28160. $tm[2] = 0;
  28161. $tm[3] = 1;
  28162. $tm[4] = $t_x * _MPDFK;
  28163. $tm[5] = -$t_y * _MPDFK;
  28164. //translate the coordinate system
  28165. if ($returnstring) { return($this->_transform($tm, true)); }
  28166. else { $this->_transform($tm); }
  28167. }
  28168. function transformRotate($angle, $x='', $y='', $returnstring=false) {
  28169. if ($x === '') {
  28170. $x=$this->x;
  28171. }
  28172. if ($y === '') {
  28173. $y=$this->y;
  28174. }
  28175. $angle = -$angle;
  28176. $y = ($this->h - $y) * _MPDFK;
  28177. $x *= _MPDFK;
  28178. //calculate elements of transformation matrix
  28179. $tm[0] = cos(deg2rad($angle));
  28180. $tm[1] = sin(deg2rad($angle));
  28181. $tm[2] = -$tm[1];
  28182. $tm[3] = $tm[0];
  28183. $tm[4] = $x + $tm[1] * $y - $tm[0] * $x;
  28184. $tm[5] = $y - $tm[0] * $y - $tm[1] * $x;
  28185. //rotate the coordinate system around ($x,$y)
  28186. if ($returnstring) { return($this->_transform($tm, true)); }
  28187. else { $this->_transform($tm); }
  28188. }
  28189. function _transform($tm, $returnstring=false) {
  28190. if ($returnstring) { return(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  28191. else { $this->_out(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  28192. }
  28193. /*-- INDIC --*/
  28194. // INDIC ============================
  28195. // This conversion can only be done when font is set
  28196. function ConvertIndic(&$str) {
  28197. if (preg_match('/^ind_([a-z]{2})_/',$this->currentfontfamily, $m)) {
  28198. if (!class_exists('indic', false)) { include(_MPDF_PATH.'classes/indic.php'); }
  28199. if (empty($this->indic)) { $this->indic = new indic($this); }
  28200. $earr = $this->UTF8StringToArray($str, false);
  28201. $str = $this->indic->substituteIndic($earr, $m[1], $this->currentfontfamily);
  28202. }
  28203. }
  28204. /*-- END INDIC --*/
  28205. // AUTOFONT =========================
  28206. function AutoFont($html) {
  28207. if ($this->onlyCoreFonts) { return $html; }
  28208. $this->useLang = true;
  28209. if ($this->autoFontGroupSize == 1) { $extra = $this->pregASCIIchars1; }
  28210. else if ($this->autoFontGroupSize == 3) { $extra = $this->pregASCIIchars3; }
  28211. else { $extra = $this->pregASCIIchars2; }
  28212. $n = '';
  28213. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  28214. foreach($a as $i => $e) {
  28215. if($i%2==0) {
  28216. $e = strcode2utf($e);
  28217. $e = $this->lesser_entity_decode($e);
  28218. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28219. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28220. /*-- CJK-FONTS --*/
  28221. if ($this->autoFontGroups & AUTOFONT_CJK) {
  28222. $e = preg_replace("/([".$this->pregCJKchars.$extra."]*[".$this->pregCJKchars."][".$this->pregCJKchars.$extra."]*)/ue", '$this->replaceCJK(stripslashes(\'\\1\'))', $e);
  28223. }
  28224. /*-- END CJK-FONTS --*/
  28225. /*-- RTL --*/
  28226. if ($this->autoFontGroups & AUTOFONT_RTL) {
  28227. // HEBREW
  28228. $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);
  28229. // All Arabic
  28230. $e = preg_replace("/([".$this->pregARABICchars .$extra."]*[".$this->pregARABICchars ."][".$this->pregARABICchars .$extra."]*)/ue", '$this->replaceArabic(stripslashes(\'\\1\'))', $e);
  28231. }
  28232. /*-- END RTL --*/
  28233. /*-- INDIC --*/
  28234. // INDIC
  28235. if ($this->autoFontGroups & AUTOFONT_INDIC) {
  28236. // Bengali
  28237. $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);
  28238. // Devanagari (= script for Hindi, Nepali + Sindhi)
  28239. $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);
  28240. // Gujarati
  28241. $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);
  28242. // Malayalam
  28243. $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);
  28244. // Kannada
  28245. $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);
  28246. // Oriya
  28247. $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);
  28248. // Punjabi ?= Gurmuhki
  28249. $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);
  28250. // Tamil
  28251. $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);
  28252. // Telugu
  28253. $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);
  28254. }
  28255. /*-- END INDIC --*/
  28256. if ($this->autoFontGroups & AUTOFONT_THAIVIET) {
  28257. // THAI
  28258. $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);
  28259. // Vietnamese
  28260. $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);
  28261. }
  28262. $e = preg_replace('/[&]/','&amp;',$e);
  28263. $e = preg_replace('/[<]/','&lt;',$e);
  28264. $e = preg_replace('/[>]/','&gt;',$e);
  28265. $e = preg_replace("/(\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1)\s+/",' \\1',$e);
  28266. $e = preg_replace("/[ ]+(\xef\xbf\xb0\/span\xef\xbf\xb1)/",'\\1 ',$e);
  28267. $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);
  28268. $e = preg_replace("/\xef\xbf\xb0/",'<',$e);
  28269. $e = preg_replace("/\xef\xbf\xb1/",'>',$e);
  28270. $a[$i] = $e;
  28271. }
  28272. else {
  28273. $a[$i] = '<'.$e.'>';
  28274. }
  28275. }
  28276. $n = implode('',$a);
  28277. return $n;
  28278. }
  28279. /*-- CJK-FONTS --*/
  28280. function replaceCJK($str) {
  28281. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28282. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28283. if (preg_match("/[".$this->pregUHCchars."]/u", $str)) {
  28284. return "\xef\xbf\xb0span lang=\"ko\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28285. }
  28286. else if (preg_match("/[".$this->pregSJISchars."]/u", $str)) {
  28287. return "\xef\xbf\xb0span lang=\"ja\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28288. }
  28289. // if in Unicode Plane 2, probably HKCS (incl in BIG5) if not Japanese
  28290. else if (preg_match("/[\x{20000}-\x{2FFFF}]/u", $str)) {
  28291. return "\xef\xbf\xb0span lang=\"zh-HK\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28292. }
  28293. else{
  28294. return "\xef\xbf\xb0span lang=\"zh-CN\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28295. }
  28296. return $str;
  28297. }
  28298. /*-- END CJK-FONTS --*/
  28299. /*-- RTL --*/
  28300. function replaceArabic($str) {
  28301. // PASHTO, SINDHI, URDU, ARABIC, PERSIAN
  28302. $persian = "\x{067E}\x{0686}\x{0698}\x{06AF}";
  28303. $urdu = "\x{0679}\x{0688}\x{0691}\x{06BA}\x{06BE}\x{06C1}\x{06D2}";
  28304. $pashto = "\x{067C}\x{0681}\x{0685}\x{0689}\x{0693}\x{0696}\x{069A}\x{06BC}\x{06D0}"; // ? and U+06AB, U+06CD
  28305. $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}";
  28306. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28307. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28308. if (preg_match("/[".$this->pregNonARABICchars ."]/u", $str) ) {
  28309. if (preg_match("/[".$sindhi ."]/u", $str) ) {
  28310. return "\xef\xbf\xb0span lang=\"sd\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28311. }
  28312. else if (preg_match("/[".$urdu ."]/u", $str) ) {
  28313. return "\xef\xbf\xb0span lang=\"ur\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28314. }
  28315. else if (preg_match("/[".$pashto ."]/u", $str) ) {
  28316. return "\xef\xbf\xb0span lang=\"ps\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28317. }
  28318. else if (preg_match("/[".$persian ."]/u", $str) ) {
  28319. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28320. }
  28321. else {
  28322. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28323. }
  28324. }
  28325. if (preg_match("/[".$persian ."]/u", $str) ) {
  28326. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28327. }
  28328. else {
  28329. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28330. }
  28331. return $str;
  28332. }
  28333. // ARABIC ===========================
  28334. // mPDF 5.4.08
  28335. function InitArabic() {
  28336. // JOIN TO FOLLOWING LETTER IN LOGICAL ORDER (i.e. AS INITIAL)
  28337. $this->arabPrevLink = "";
  28338. // U+060c; U+061b; U+061f; U+0626; U+0628;
  28339. $this->arabPrevLink .= "\xd8\x8c\xd8\x9b\xd8\x9f\xd8\xa6\xd8\xa8";
  28340. // U+062a; U+062b; U+062c; U+062d; U+062e;
  28341. $this->arabPrevLink .= "\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae";
  28342. // U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; U+0639; U+063a;
  28343. $this->arabPrevLink .= "\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba";
  28344. // U+0640; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; U+0647; U+0649; U+064a;
  28345. $this->arabPrevLink .= "\xd9\x80\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x89\xd9\x8a";
  28346. // U+0678; U+0679; U+067a; U+067b; U+067c; U+067d; U+067e; U+067f;
  28347. $this->arabPrevLink .= "\xd9\xb8\xd9\xb9\xd9\xba\xd9\xbb\xd9\xbc\xd9\xbd\xd9\xbe\xd9\xbf";
  28348. // U+0680; U+0681; U+0682; U+0683; U+0684; U+0685; U+0686; U+0687;
  28349. $this->arabPrevLink .= "\xda\x80\xda\x81\xda\x82\xda\x83\xda\x84\xda\x85\xda\x86\xda\x87";
  28350. // U+069a; U+069b; U+069c; U+069d; U+069e; U+069f;
  28351. $this->arabPrevLink .= "\xda\x9a\xda\x9b\xda\x9c\xda\x9d\xda\x9e\xda\x9f";
  28352. // U+06a0; U+06a1; U+06a2; U+06a3; U+06a4; U+06a5; U+06a6; U+06A7; U+06A8;
  28353. $this->arabPrevLink .= "\xda\xa0\xda\xa1\xda\xa2\xda\xa3\xda\xa4\xda\xa5\xda\xa6\xda\xa7\xda\xa8";
  28354. // U+06a9; U+06aa; U+06ab; U+06ac; U+06ad; U+06ae; U+06af;
  28355. $this->arabPrevLink .= "\xda\xa9\xda\xaa\xda\xab\xda\xac\xda\xad\xda\xae\xda\xaf";
  28356. // U+06b0; U+06b1; U+06b2; U+06b3; U+06b4; U+06b5; U+06b6; U+06b7; U+06b8; U+06b9;
  28357. $this->arabPrevLink .= "\xda\xb0\xda\xb1\xda\xb2\xda\xb3\xda\xb4\xda\xb5\xda\xb6\xda\xb7\xda\xb8\xda\xb9";
  28358. // U+06ba; U+06bb; U+06bc; U+06be; U+06bf;
  28359. $this->arabPrevLink .= "\xda\xba\xda\xbb\xda\xbc\xda\xbe\xda\xbf";
  28360. // U+06c1; U+06cc; U+06ce; U+06d0; U+06d1;
  28361. $this->arabPrevLink .= "\xdb\x81\xdb\x8c\xdb\x8e\xdb\x90\xdb\x91";
  28362. // JOIN TO PREVIOUS LETTER IN LOGICAL ORDER (i.e. AS FINAL FORM)
  28363. $this->arabNextLink = "";
  28364. // U+0622; U+0623; U+0624; U+0625; U+0626; U+0627; U+0628; U+0629;
  28365. $this->arabNextLink .= "\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa6\xd8\xa7\xd8\xa8\xd8\xa9";
  28366. // U+062A; U+062B; U+062C; U+062D; U+062E; U+062F;
  28367. $this->arabNextLink .= "\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf";
  28368. // U+0630; U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; U+0639; U+063A;
  28369. $this->arabNextLink .= "\xd8\xb0\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba";
  28370. // U+0640; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; U+0647; U+0648; U+0649; U+064A;
  28371. $this->arabNextLink .= "\xd9\x80\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x88\xd9\x89\xd9\x8a";
  28372. // U+0671; U+0672; U+0675; U+0676; U+0677; U+0678; U+0679;
  28373. $this->arabNextLink .= "\xd9\xb1\xd9\xb2\xd9\xb5\xd9\xb6\xd9\xb7\xd9\xb8\xd9\xb9";
  28374. // U+067A; U+067B; U+067C; U+067D; U+067E; U+067F;
  28375. $this->arabNextLink .= "\xd9\xba\xd9\xbb\xd9\xbc\xd9\xbd\xd9\xbe\xd9\xbf";
  28376. // U+0680; U+0681; U+0682; U+0683; U+0684; U+0685; U+0686; U+0687; U+0688; U+0689;
  28377. $this->arabNextLink .= "\xda\x80\xda\x81\xda\x82\xda\x83\xda\x84\xda\x85\xda\x86\xda\x87\xda\x88\xda\x89";
  28378. // U+068A; U+068B; U+068C; U+068D; U+068F;U+068F;
  28379. $this->arabNextLink .= "\xda\x8a\xda\x8b\xda\x8c\xda\x8d\xda\x8e\xda\x8f";
  28380. // U+0690; U+0691; U+0692; U+0693; U+0694; U+0695; U+0696; U+0697; U+0698; U+0699;
  28381. $this->arabNextLink .= "\xda\x90\xda\x91\xda\x92\xda\x93\xda\x94\xda\x95\xda\x96\xda\x97\xda\x98\xda\x99";
  28382. // U+069A; U+069B; U+069C; U+069D; U+069E; U+069F;
  28383. $this->arabNextLink .= "\xda\x9a\xda\x9b\xda\x9c\xda\x9d\xda\x9e\xda\x9f";
  28384. // U+06A0; U+06A1; U+06A2; U+06A3; U+06A4; U+06A5; U+06A6; U+06A7; U+06A8; U+06A9;
  28385. $this->arabNextLink .= "\xda\xa0\xda\xa1\xda\xa2\xda\xa3\xda\xa4\xda\xa5\xda\xa6\xda\xa7\xda\xa8\xda\xa9";
  28386. // U+06AA; U+06AB; U+06AC; U+06AD; U+06AE; U+06AF;
  28387. $this->arabNextLink .= "\xda\xaa\xda\xab\xda\xac\xda\xad\xda\xae\xda\xaf";
  28388. // U+06B0; U+06B1; U+06B2; U+06B3; U+06B4; U+06B5; U+06B6; U+06B7; U+06B8; U+06B9;
  28389. $this->arabNextLink .= "\xda\xb0\xda\xb1\xda\xb2\xda\xb3\xda\xb4\xda\xb5\xda\xb6\xda\xb7\xda\xb8\xda\xb9";
  28390. // U+06BA; U+06BB; U+06BC; U+06BE; U+06BF;
  28391. $this->arabNextLink .= "\xda\xba\xda\xbb\xda\xbc\xda\xbe\xda\xbf";
  28392. // U+06C0; U+06C1; U+06C2; U+06C3; U+06C4; U+06C5; U+06C6; U+06C7; U+06C8; U+06C9;
  28393. $this->arabNextLink .= "\xdb\x80\xdb\x81\xdb\x82\xdb\x83\xdb\x84\xdb\x85\xdb\x86\xdb\x87\xdb\x88\xdb\x89";
  28394. // U+06CA; U+06CB; U+06CC; U+06CD; U+06CE; U+06CF;
  28395. $this->arabNextLink .= "\xdb\x8a\xdb\x8b\xdb\x8c\xdb\x8d\xdb\x8e\xdb\x8f";
  28396. // U+06D0; U+06d1; U+06D2; U+06D3;
  28397. $this->arabNextLink .= "\xdb\x90\xdb\x91\xdb\x92\xdb\x93";
  28398. // VOWELS ++
  28399. // U+064b U+064c; U+064d; U+064e; U+064f; U+0650; U+0651; U+0652;
  28400. $this->arabVowels = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  28401. // Added chars that may not be vowels but should not interrupt joining
  28402. // U+0670; U+0653;
  28403. $this->arabVowels .= "\xd9\xb0\xd9\x93";
  28404. // ? should also add - U+615, 616, 617-61A, 653-65E, 6D6-6DC, 6DF-6E4, 6E7, 6E8, 6EA-6ED
  28405. // ISOLATED FORM :: FINAL :: INITIAL :: MEDIAL
  28406. // FB** - FE** = Arabic presentation Forms
  28407. // F5** F6** F7** = Private use area used by unAGlyphs in mPDF
  28408. $this->arabGlyphs = array(
  28409. "\xd8\x8c"=>array("\xd8\x8c", "\xd8\x8c", "\xd8\x8c", "\xd8\x8c"), /* 060C, 060C, 060C, 060C */
  28410. "\xd8\x9b"=>array("\xd8\x9b", "\xd8\x9b", "\xd8\x9b", "\xd8\x9b"), /* 061B, 061B, 061B, 061B */
  28411. "\xd8\x9f"=>array("\xd8\x9f", "\xd8\x9f", "\xd8\x9f", "\xd8\x9f"), /* 061F, 061F, 061F, 061F */
  28412. "\xd8\xa1"=>array("\xd8\xa1", "\xd8\xa1", "\xd8\xa1", "\xd8\xa1"), /* 0621, 0621, 0621, 0621 */
  28413. "\xd8\xa2"=>array("\xd8\xa2", "\xef\xba\x82", "\xd8\xa2", "\xef\xba\x82"), /* 0622, FE82, 0622, FE82 */
  28414. "\xd8\xa3"=>array("\xd8\xa3", "\xef\xba\x84", "\xd8\xa3", "\xef\xba\x84"), /* 0623, FE84, 0623, FE84 */
  28415. "\xd8\xa4"=>array("\xd8\xa4", "\xef\xba\x86", "\xd8\xa4", "\xef\xba\x86"), /* 0624, FE86, 0624, FE86 */
  28416. "\xd8\xa5"=>array("\xd8\xa5", "\xef\xba\x88", "\xd8\xa5", "\xef\xba\x88"), /* 0625, FE88, 0625, FE88 */
  28417. "\xd8\xa6"=>array("\xd8\xa6", "\xef\xba\x8a", "\xef\xba\x8b", "\xef\xba\x8c"), /* 0626, FE8A, FE8B, FE8C */
  28418. "\xd8\xa7"=>array("\xd8\xa7", "\xef\xba\x8e", "\xd8\xa7", "\xef\xba\x8e"), /* 0627, FE8E, 0627, FE8E */
  28419. "\xd8\xa8"=>array("\xd8\xa8", "\xef\xba\x90", "\xef\xba\x91", "\xef\xba\x92"), /* 0628, FE90, FE91, FE92 */
  28420. "\xd8\xa9"=>array("\xd8\xa9", "\xef\xba\x94", "\xd8\xa9", "\xef\xba\x94"), /* 0629, FE94, 0629, FE94 */
  28421. "\xd8\xaa"=>array("\xd8\xaa", "\xef\xba\x96", "\xef\xba\x97", "\xef\xba\x98"), /* 062A, FE96, FE97, FE98 */
  28422. "\xd8\xab"=>array("\xd8\xab", "\xef\xba\x9a", "\xef\xba\x9b", "\xef\xba\x9c"), /* 062B, FE9A, FE9B, FE9C */
  28423. "\xd8\xac"=>array("\xd8\xac", "\xef\xba\x9e", "\xef\xba\x9f", "\xef\xba\xa0"), /* 062C, FE9E, FE9F, FEA0 */
  28424. "\xd8\xad"=>array("\xd8\xad", "\xef\xba\xa2", "\xef\xba\xa3", "\xef\xba\xa4"), /* 062D, FEA2, FEA3, FEA4 */
  28425. "\xd8\xae"=>array("\xd8\xae", "\xef\xba\xa6", "\xef\xba\xa7", "\xef\xba\xa8"), /* 062E, FEA6, FEA7, FEA8 */
  28426. "\xd8\xaf"=>array("\xd8\xaf", "\xef\xba\xaa", "\xd8\xaf", "\xef\xba\xaa"), /* 062F, FEAA, 062F, FEAA */
  28427. "\xd8\xb0"=>array("\xd8\xb0", "\xef\xba\xac", "\xd8\xb0", "\xef\xba\xac"), /* 0630, FEAC, 0630, FEAC */
  28428. "\xd8\xb1"=>array("\xd8\xb1", "\xef\xba\xae", "\xd8\xb1", "\xef\xba\xae"), /* 0631, FEAE, 0631, FEAE */
  28429. "\xd8\xb2"=>array("\xd8\xb2", "\xef\xba\xb0", "\xd8\xb2", "\xef\xba\xb0"), /* 0632, FEB0, 0632, FEB0 */
  28430. "\xd8\xb3"=>array("\xd8\xb3", "\xef\xba\xb2", "\xef\xba\xb3", "\xef\xba\xb4"), /* 0633, FEB2, FEB3, FEB4 */
  28431. "\xd8\xb4"=>array("\xd8\xb4", "\xef\xba\xb6", "\xef\xba\xb7", "\xef\xba\xb8"), /* 0634, FEB6, FEB7, FEB8 */
  28432. "\xd8\xb5"=>array("\xd8\xb5", "\xef\xba\xba", "\xef\xba\xbb", "\xef\xba\xbc"), /* 0635, FEBA, FEBB, FEBC */
  28433. "\xd8\xb6"=>array("\xd8\xb6", "\xef\xba\xbe", "\xef\xba\xbf", "\xef\xbb\x80"), /* 0636, FEBE, FEBF, FEC0 */
  28434. "\xd8\xb7"=>array("\xd8\xb7", "\xef\xbb\x82", "\xef\xbb\x83", "\xef\xbb\x84"), /* 0637, FEC2, FEC3, FEC4 */
  28435. "\xd8\xb8"=>array("\xd8\xb8", "\xef\xbb\x86", "\xef\xbb\x87", "\xef\xbb\x88"), /* 0638, FEC6, FEC7, FEC8 */
  28436. "\xd8\xb9"=>array("\xd8\xb9", "\xef\xbb\x8a", "\xef\xbb\x8b", "\xef\xbb\x8c"), /* 0639, FECA, FECB, FECC */
  28437. "\xd8\xba"=>array("\xd8\xba", "\xef\xbb\x8e", "\xef\xbb\x8f", "\xef\xbb\x90"), /* 063A, FECE, FECF, FED0 */
  28438. "\xd9\x80"=>array("\xd9\x80", "\xd9\x80", "\xd9\x80", "\xd9\x80"), /* 0640, 0640, 0640, 0640 */
  28439. "\xd9\x81"=>array("\xd9\x81", "\xef\xbb\x92", "\xef\xbb\x93", "\xef\xbb\x94"), /* 0641, FED2, FED3, FED4 */
  28440. "\xd9\x82"=>array("\xd9\x82", "\xef\xbb\x96", "\xef\xbb\x97", "\xef\xbb\x98"), /* 0642, FED6, FED7, FED8 */
  28441. "\xd9\x83"=>array("\xd9\x83", "\xef\xbb\x9a", "\xef\xbb\x9b", "\xef\xbb\x9c"), /* 0643, FEDA, FEDB, FEDC */
  28442. "\xd9\x84"=>array("\xd9\x84", "\xef\xbb\x9e", "\xef\xbb\x9f", "\xef\xbb\xa0"), /* 0644, FEDE, FEDF, FEE0 */
  28443. "\xd9\x85"=>array("\xd9\x85", "\xef\xbb\xa2", "\xef\xbb\xa3", "\xef\xbb\xa4"), /* 0645, FEE2, FEE3, FEE4 */
  28444. "\xd9\x86"=>array("\xd9\x86", "\xef\xbb\xa6", "\xef\xbb\xa7", "\xef\xbb\xa8"), /* 0646, FEE6, FEE7, FEE8 */
  28445. "\xd9\x87"=>array("\xd9\x87", "\xef\xbb\xaa", "\xef\xbb\xab", "\xef\xbb\xac"), /* 0647, FEEA, FEEB, FEEC */
  28446. "\xd9\x88"=>array("\xd9\x88", "\xef\xbb\xae", "\xd9\x88", "\xef\xbb\xae"), /* 0648, FEEE, 0648, FEEE */
  28447. /* 0649 Alef Maksura should only appear at end of word (in Arabic) So Initial and medial are shown as isolated/final */
  28448. "\xd9\x89"=>array("\xd9\x89", "\xef\xbb\xb0", "\xd9\x89", "\xef\xbb\xb0"), /* 0649, FEF0, 0649, FEF0 */
  28449. /* 0649 Alef Maksura Initial and Medial forms as given in Unicode FBE8 and FBE9 for Uighur Kazakh (not in some fonts) */
  28450. "\xd9\x89"=>array("\xd9\x89", "\xef\xbb\xb0", "\xef\xaf\xa8", "\xef\xaf\xa9"), /* 0649, FEF0, FBE8, FBE9 not in most fonts */
  28451. "\xd9\x8a"=>array("\xd9\x8a", "\xef\xbb\xb2", "\xef\xbb\xb3", "\xef\xbb\xb4"), /* 064A, FEF2, FEF3, FEF4 */
  28452. "\xd9\x8b"=>array("\xd9\x8b", "\xd9\x8b", "\xd9\x8b", "\xd9\x8b"), /* 064B, 064B, 064B, 064B */
  28453. "\xd9\x8c"=>array("\xd9\x8c", "\xd9\x8c", "\xd9\x8c", "\xd9\x8c"), /* 064C, 064C, 064C, 064C */
  28454. "\xd9\x8d"=>array("\xd9\x8d", "\xd9\x8d", "\xd9\x8d", "\xd9\x8d"), /* 064D, 064D, 064D, 064D */
  28455. "\xd9\x8e"=>array("\xd9\x8e", "\xd9\x8e", "\xd9\x8e", "\xd9\x8e"), /* 064E, 064E, 064E, 064E */
  28456. "\xd9\x8f"=>array("\xd9\x8f", "\xd9\x8f", "\xd9\x8f", "\xd9\x8f"), /* 064F, 064F, 064F, 064F */
  28457. "\xd9\x90"=>array("\xd9\x90", "\xd9\x90", "\xd9\x90", "\xd9\x90"), /* 0650, 0650, 0650, 0650 */
  28458. "\xd9\x91"=>array("\xd9\x91", "\xd9\x91", "\xd9\x91", "\xd9\x91"), /* 0651, 0651, 0651, 0651 */
  28459. "\xd9\x92"=>array("\xd9\x92", "\xd9\x92", "\xd9\x92", "\xd9\x92"), /* 0652, 0652, 0652, 0652 */
  28460. "\xd9\xb1"=>array("\xd9\xb1", "\xef\xad\x91", "\xd9\xb1", "\xef\xad\x91"), /* 0671, FB51, 0671, FB51 */
  28461. "\xd9\xb2"=>array("\xd9\xb2", "\xef\x95\xb2", "\xd9\xb2", "\xef\x95\xb2"), /* 0672, F572, 0672, F572 */
  28462. "\xd9\xb5"=>array("\xd9\xb5", "\xef\x95\xb5", "\xd9\xb5", "\xef\x95\xb5"), /* 0675, F575, 0675, F575 */
  28463. "\xd9\xb8"=>array("\xd9\xb8", "\xef\x95\xb8", "\xef\xba\x8b", "\xef\xba\x8c"), /* 0678, F578, FE8B, FE8C ( as 0626 ) */
  28464. "\xd9\xb9"=>array("\xd9\xb9", "\xef\xad\xa7", "\xef\xad\xa8", "\xef\xad\xa9"), /* 0679, FB67, FB68, FB69 */
  28465. "\xd9\xba"=>array("\xd9\xba", "\xef\xad\x9f", "\xef\xad\xa0", "\xef\xad\xa1"), /* 067A, FB5F, FB60, FB61 */
  28466. "\xd9\xbb"=>array("\xd9\xbb", "\xef\xad\x93", "\xef\xad\x94", "\xef\xad\x95"), /* 067B, FB53, FB54, FB55 */
  28467. "\xd9\xbc"=>array("\xd9\xbc", "\xef\x95\xbc", "\xef\x99\xbc", "\xef\x9d\xbc"), /* 067C, F57C, F67C, F77C */
  28468. "\xd9\xbd"=>array("\xd9\xbd", "\xef\x95\xbd", "\xef\x99\xbd", "\xef\x9d\xbd"), /* 067D, F57D, F67D, F77D */
  28469. "\xd9\xbe"=>array("\xd9\xbe", "\xef\xad\x97", "\xef\xad\x98", "\xef\xad\x99"), /* 067E, FB57, FB58, FB59 */
  28470. "\xd9\xbf"=>array("\xd9\xbf", "\xef\xad\xa3", "\xef\xad\xa4", "\xef\xad\xa5"), /* 067F, FB63, FB64, FB65 */
  28471. "\xda\x80"=>array("\xda\x80", "\xef\xad\x9b", "\xef\xad\x9c", "\xef\xad\x9d"), /* 0680, FB5B, FB5C, FB5D */
  28472. "\xda\x81"=>array("\xda\x81", "\xef\x96\x81", "\xef\x9a\x81", "\xef\x9e\x81"), /* 0681, F581, F681, F781 */
  28473. "\xda\x82"=>array("\xda\x82", "\xef\x96\x82", "\xef\x9a\x82", "\xef\x9e\x82"), /* 0682, F582, F682, F782 */
  28474. "\xda\x83"=>array("\xda\x83", "\xef\xad\xb7", "\xef\xad\xb8", "\xef\xad\xb9"), /* 0683, FB77, FB78, FB79 */
  28475. "\xda\x84"=>array("\xda\x84", "\xef\xad\xb3", "\xef\xad\xb4", "\xef\xad\xb5"), /* 0684, FB73, FB74, FB75 */
  28476. "\xda\x85"=>array("\xda\x85", "\xef\x96\x85", "\xef\x9a\x85", "\xef\x9e\x85"), /* 0685, F585, F685, F785 */
  28477. "\xda\x86"=>array("\xda\x86", "\xef\xad\xbb", "\xef\xad\xbc", "\xef\xad\xbd"), /* 0686, FB7B, FB7C, FB7D */
  28478. "\xda\x87"=>array("\xda\x87", "\xef\xad\xbf", "\xef\xae\x80", "\xef\xae\x81"), /* 0687, FB7F, FB80, FB81 */
  28479. "\xda\x88"=>array("\xda\x88", "\xef\xae\x89", "\xda\x88", "\xda\x88"), /* 0688, FB89, 0688, 0688 */
  28480. "\xda\x89"=>array("\xda\x89", "\xef\x96\x89", "\xda\x89", "\xda\x89"), /* 0689, F589, 0689, 0689 */
  28481. "\xda\x91"=>array("\xda\x91", "\xef\xae\x8d", "\xda\x91", "\xef\xae\x8d"), /* 0691, FB8D, 0691, FB8D */
  28482. "\xda\x93"=>array("\xda\x93", "\xef\x96\x93", "\xda\x93", "\xda\x93"), /* 0693, F593, 0693, 0693 */
  28483. "\xda\x96"=>array("\xda\x96", "\xef\x96\x96", "\xda\x96", "\xda\x96"), /* 0696, F596, 0696, 0696 */
  28484. "\xda\x98"=>array("\xda\x98", "\xef\xae\x8b", "\xda\x98", "\xef\xae\x8b"), /* 0698, FB8B, 0698, FB8B */
  28485. "\xda\x9a"=>array("\xda\x9a", "\xef\x96\x9a", "\xef\x9a\x9a", "\xef\x9e\x9a"), /* 069A, F59A, F69A, F79A */
  28486. "\xda\x9b"=>array("\xda\x9b", "\xef\x96\x9b", "\xef\x9a\x9b", "\xef\x9e\x9b"), /* 069B, F59B, F69B, F79B */
  28487. "\xda\x9c"=>array("\xda\x9c", "\xef\x96\x9c", "\xef\x9a\x9c", "\xef\x9e\x9c"), /* 069C, F59C, F69C, F79C */
  28488. "\xda\x9d"=>array("\xda\x9d", "\xef\x96\x9d", "\xef\x9a\x9d", "\xef\x9e\x9d"), /* 069D, F59D, F69D, F79D */
  28489. "\xda\x9e"=>array("\xda\x9e", "\xef\x96\x9e", "\xef\x9a\x9e", "\xef\x9e\x9e"), /* 069E, F59E, F69E, F79E */
  28490. "\xda\xa0"=>array("\xda\xa0", "\xef\x96\xa0", "\xef\x9a\xa0", "\xef\x9e\xa0"), /* 06A0, F5A0, F6A0, F7A0 */
  28491. "\xda\xa1"=>array("\xda\xa1", "\xef\x96\xa1", "\xef\x9a\xa1", "\xef\x9e\xa1"), /* 06A1, F5A1, F6A1, F7A1 */
  28492. "\xda\xa2"=>array("\xda\xa2", "\xef\x96\xa2", "\xef\x9a\xa2", "\xef\x9e\xa2"), /* 06A2, F5A2, F6A2, F7A2 */
  28493. "\xda\xa3"=>array("\xda\xa3", "\xef\x96\xa3", "\xef\x9a\xa3", "\xef\x9e\xa3"), /* 06A3, F5A3, F6A3, F7A3 */
  28494. "\xda\xa4"=>array("\xda\xa4", "\xef\xad\xab", "\xef\xad\xac", "\xef\xad\xad"), /* 06A4, FB6B, FB6C, FB6D */
  28495. "\xda\xa5"=>array("\xda\xa5", "\xef\x96\xa5", "\xef\x9a\xa5", "\xef\x9e\xa5"), /* 06A5, F5A5, F6A5, F7A5 */
  28496. "\xda\xa6"=>array("\xda\xa6", "\xef\xad\xaf", "\xef\xad\xb0", "\xef\xad\xb1"), /* 06A6, FB6F, FB70, FB71 */
  28497. "\xda\xa9"=>array("\xda\xa9", "\xef\xae\x8f", "\xef\xae\x90", "\xef\xae\x91"), /* 06A9, FB8F, FB90, FB91 */
  28498. "\xda\xaa"=>array("\xda\xaa", "\xef\x96\xaa", "\xef\x9a\xaa", "\xef\x9e\xaa"), /* 06AA, F5AA, F6AA, F7AA */
  28499. "\xda\xab"=>array("\xda\xab", "\xef\x96\xab", "\xef\x9a\xab", "\xef\x9e\xab"), /* 06AB, F5AB, F6AB, F7AB */
  28500. "\xda\xac"=>array("\xda\xac", "\xef\x96\xac", "\xef\x9a\xac", "\xef\x9e\xac"), /* 06AC, F5AC, F6AC, F7AC */
  28501. "\xda\xad"=>array("\xda\xad", "\xef\xaf\x94", "\xef\xaf\x95", "\xef\xaf\x96"), /* 06AD, FBD4, FBD5, FBD6 */
  28502. "\xda\xae"=>array("\xda\xae", "\xef\x96\xae", "\xef\x9a\xae", "\xef\x9e\xae"), /* 06AE, F5AE, F6AE, F7AE */
  28503. "\xda\xaf"=>array("\xda\xaf", "\xef\xae\x93", "\xef\xae\x94", "\xef\xae\x95"), /* 06Af, FB93, FB94, FB95 */
  28504. "\xda\xb0"=>array("\xda\xb0", "\xef\x96\xb0", "\xef\x9a\xb0", "\xef\x9e\xb0"), /* 06B0, F5B0, F6B0, F7B0 */
  28505. "\xda\xb1"=>array("\xda\xb1", "\xef\xae\x9b", "\xef\xae\x9c", "\xef\xae\x9d"), /* 06B1, FB9B, FB9C, FB9D */
  28506. "\xda\xb2"=>array("\xda\xb2", "\xef\x96\xb2", "\xef\x9a\xb2", "\xef\x9e\xb2"), /* 06B2, F5B2, F6B2, F7B2 */
  28507. "\xda\xb3"=>array("\xda\xb3", "\xef\xae\x97", "\xef\xae\x98", "\xef\xae\x99"), /* 06B3, FB97, FB98, FB99 */
  28508. "\xda\xb4"=>array("\xda\xb4", "\xef\x96\xb4", "\xef\x9a\xb4", "\xef\x9e\xb4"), /* 06B4, F5B4, F6B4, F7B4 */
  28509. "\xda\xb5"=>array("\xda\xb5", "\xef\x96\xb5", "\xef\x9a\xb5", "\xef\x9e\xb5"), /* 06B5, F5B5, F6B5, F7B5 */
  28510. "\xda\xb6"=>array("\xda\xb6", "\xef\x96\xb6", "\xef\x9a\xb6", "\xef\x9e\xb6"), /* 06B6, F5B6, F6B6, F7B6 */
  28511. "\xda\xb7"=>array("\xda\xb7", "\xef\x96\xb7", "\xef\x9a\xb7", "\xef\x9e\xb7"), /* 06B7, F5B7, F6B7, F7B7 */
  28512. "\xda\xb8"=>array("\xda\xb8", "\xef\x96\xb8", "\xef\x9a\xb8", "\xef\x9e\xb8"), /* 06B8, F5B8, F6B8, F7B8 */
  28513. "\xda\xb9"=>array("\xda\xb9", "\xef\x96\xb9", "\xef\x9a\xb9", "\xef\x9e\xb9"), /* 06B9, F5B9, F6B9, F7B9 */
  28514. "\xda\xba"=>array("\xda\xba", "\xef\xae\x9f", "\xda\xba", "\xda\xba"), /* 06BA, FB9F, 06BA, 06BA */
  28515. "\xda\xbb"=>array("\xda\xbb", "\xef\xae\xa1", "\xef\xae\xa2", "\xef\xae\xa3"), /* 06BB, FBA1, FBA2, FBA3 */
  28516. "\xda\xbc"=>array("\xda\xbc", "\xef\x96\xbc", "\xef\x9a\xbc", "\xef\x9e\xbc"), /* 06BC, F5BC, F6BC, F7BC */
  28517. "\xda\xbe"=>array("\xda\xbe", "\xef\xae\xab", "\xef\xae\xac", "\xef\xae\xad"), /* 06BE, FBAB, FBAC, FBAD */
  28518. "\xda\xbf"=>array("\xda\xbf", "\xef\x96\xbf", "\xef\x9a\xbf", "\xef\x9e\xbf"), /* 06BF, F5BF, F6BF, F7BF */
  28519. "\xdb\x80"=>array("\xdb\x80", "\xef\xae\xa5", "\xdb\x80", "\xef\xae\xa5"), /* 06C0, FBA5, 06C0, FBA5 */
  28520. "\xdb\x81"=>array("\xdb\x81", "\xef\xae\xa7", "\xef\xae\xa8", "\xef\xae\xa9"), /* 06C1, FBA7, FBA8, FBA9 */
  28521. "\xdb\x8c"=>array("\xdb\x8c", "\xef\xaf\xbd", "\xef\xaf\xbe", "\xef\xaf\xbf"), /* 06CC, FBFD, FBFE, FBFF */
  28522. "\xdb\x8d"=>array("\xdb\x8d", "\xef\x97\x8d", "\xdb\x8d", "\xef\x97\x8d"), /* 06CD, F5CD, 06CD, F5CD */
  28523. "\xdb\x8e"=>array("\xdb\x8e", "\xef\x97\x8e", "\xef\x9b\x8e", "\xef\x9f\x8e"), /* 06CE, F5CE, F6CE, F7CE */
  28524. "\xdb\x90"=>array("\xdb\x90", "\xef\xaf\xa5", "\xef\xaf\xa6", "\xef\xaf\xa7"), /* 06D0, FBE5, FBE6, FBE7 */
  28525. "\xdb\x91"=>array("\xdb\x91", "\xef\x97\x91", "\xef\xad\x98", "\xef\xad\x99"), /* 06D1, F5D1, FB58, FB59 Fudge borrows from 067E */
  28526. "\xdb\x92"=>array("\xdb\x92", "\xef\xae\xaf", "\xdb\x92", "\xef\xae\xaf"), /* 06D2, FBAF, 06D2, FBAF */
  28527. "\xdb\x93"=>array("\xdb\x93", "\xef\xae\xb1", "\xdb\x93", "\xef\xae\xb1"), /* 06D3, FBB1, 06D3, FBB1 */
  28528. );
  28529. // LAM with ALEF ligatures (Mandatory ligatures)
  28530. // U+0644; U+0622; U+0644; U+0623; U+0644; U+0625; U+0644; U+0627;
  28531. $this->arabLigGlyphs = "\xd9\x84\xd8\xa2\xd9\x84\xd8\xa3\xd9\x84\xd8\xa5\xd9\x84\xd8\xa7";
  28532. $this->arabLigHex = 'FEF5FEF6FEF5FEF6FEF7FEF8FEF7FEF8FEF9FEFAFEF9FEFAFEFBFEFCFEFBFEFC';
  28533. }
  28534. // mPDF 5.4.08
  28535. function ArabJoin($str) {
  28536. if (!$this->arabGlyphs) { $this->InitArabic(); }
  28537. $crntChar = null;
  28538. $prevChar = null;
  28539. $nextChar = null;
  28540. $output = array();
  28541. $chars = preg_split('//u', $str);
  28542. $max = count($chars);
  28543. for ($i = $max - 1; $i >= 0; $i--) {
  28544. $crntChar = $chars[$i];
  28545. if ($i > 0){ $prevChar = $chars[$i - 1]; }
  28546. else{ $prevChar = NULL; }
  28547. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28548. $prevChar = $chars[$i - 2];
  28549. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28550. $prevChar = $chars[$i - 3];
  28551. }
  28552. }
  28553. if ($crntChar && mb_strpos($this->arabVowels, $crntChar, 0, 'utf-8') !== false) {
  28554. // If next_char = nextLink && prev_char = prevLink:
  28555. // Added && $prevchar (defined) else error on mb_strpos()
  28556. 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)) {
  28557. $output[] = $this->get_arab_glyphs($crntChar, 1); // <final> form
  28558. }
  28559. else {
  28560. $output[] = $this->get_arab_glyphs($crntChar, 0); // <isolated> form
  28561. }
  28562. continue;
  28563. }
  28564. // NB = &#x622 &#x623; &#x625; &#x627; &#x644;
  28565. if (isset($chars[$i + 1]) && in_array($chars[$i + 1], array("\xd8\xa2","\xd8\xa3","\xd8\xa5","\xd8\xa7")) && $crntChar == "\xd9\x84"){
  28566. continue;
  28567. }
  28568. if (ord($crntChar) < 128) {
  28569. $output[] = $crntChar;
  28570. $nextChar = $crntChar;
  28571. continue;
  28572. }
  28573. $form = 0;
  28574. if ($prevChar == "\xd9\x84" && ($crntChar == "\xd8\xa2" || $crntChar == "\xd8\xa3" || $crntChar == "\xd8\xa5" || $crntChar == "\xd8\xa7")) {
  28575. if ($chars[$i - 2] && mb_strpos($this->arabPrevLink, $chars[$i - 2], 0, 'utf-8') !== false) {
  28576. $form++; // <final> form
  28577. }
  28578. $pos = mb_strpos($this->arabLigGlyphs, ($prevChar . $crntChar), 0, 'utf-8');
  28579. $pos = $pos*8 + $form*4;
  28580. $pres = (mb_substr($this->arabLigHex, $pos, 4, 'utf-8'));
  28581. // If presentation forms for mandatory ligatures with diacritics not present (even if remapped from e.g. uni0644uni0625)
  28582. // try replacing with mandatory ligature Alef/lam isolated/final FEFB/FEFC + diacritic glyph
  28583. if (!$this->_charDefined($this->CurrentFont['cw'], hexdec($pres)) && $this->_charDefined($this->CurrentFont['cw'], hexdec('FEFB'))) {
  28584. if ($pres=='FEF5') { $output[] = strcode2utf('&#xFEFB;&#x0653;'); }
  28585. else if ($pres=='FEF6') { $output[] = strcode2utf('&#xFEFC;&#x0653;'); }
  28586. else if ($pres=='FEF7') { $output[] = strcode2utf('&#xFEFB;&#x0654;'); }
  28587. else if ($pres=='FEF8') { $output[] = strcode2utf('&#xFEFC;&#x0654;'); }
  28588. else if ($pres=='FEF9') { $output[] = strcode2utf('&#xFEFB;&#x0655;'); }
  28589. else if ($pres=='FEFA') { $output[] = strcode2utf('&#xFEFC;&#x0655;'); }
  28590. }
  28591. else {
  28592. $output[] = strcode2utf('&#x' . $pres . ';');
  28593. }
  28594. $nextChar = $prevChar;
  28595. continue;
  28596. }
  28597. if ($prevChar && mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false) {
  28598. $form++;
  28599. }
  28600. if ($nextChar && mb_strpos($this->arabNextLink, $nextChar, 0, 'utf-8') !== false) {
  28601. $form += 2;
  28602. }
  28603. $output[] = $this->get_arab_glyphs($crntChar, $form) ;
  28604. $nextChar = $crntChar;
  28605. }
  28606. $ra = array_reverse($output);
  28607. $s = implode($ra);
  28608. return $s;
  28609. }
  28610. // mPDF 5.4.08
  28611. function get_arab_glyphs($char, $type) {
  28612. if ($type>0 && isset($this->arabGlyphs[$char])) {
  28613. // If presentation form specified FB** - FE** = Arabic presentation Forms
  28614. if (preg_match("/[\x{FB50}-\x{FEFF}]/u",$this->arabGlyphs[$char][$type])) {
  28615. $unicode = $this->UTF8StringToArray($this->arabGlyphs[$char][$type], false);
  28616. if ($this->_charDefined($this->CurrentFont['cw'],$unicode[0])) { return $this->arabGlyphs[$char][$type]; }
  28617. else if (isset($this->CurrentFont['unAGlyphs'])) {
  28618. $uni = $this->UTF8StringToArray($char, false);
  28619. $pua = $uni[0] - 1536 + 62464 + 256*$type ;
  28620. if ($this->_charDefined($this->CurrentFont['cw'], $pua)) { return strcode2utf('&#x' . dechex($pua) . ';'); }
  28621. else return $char;
  28622. }
  28623. else return $char;
  28624. }
  28625. // If PUA form specified and unAGlphs font set F5** F6** F7** = Private use area used by unAGlyphs in mPDF
  28626. if (preg_match("/[\x{F500}-\x{F7FF}]/u",$this->arabGlyphs[$char][$type]) && isset($this->CurrentFont['unAGlyphs'])) {
  28627. $unicode = $this->UTF8StringToArray($this->arabGlyphs[$char][$type], false);
  28628. if ($this->_charDefined($this->CurrentFont['cw'],$unicode[0])) { return $this->arabGlyphs[$char][$type]; }
  28629. else return $char;
  28630. }
  28631. return $this->arabGlyphs[$char][$type];
  28632. }
  28633. else return $char;
  28634. }
  28635. /*-- END RTL --*/
  28636. //===========================
  28637. // Functions originally in htmltoolkit - moved mPDF 4.0
  28638. // Call-back function Used for usort in fn _tableWrite
  28639. function _cmpdom($a, $b) {
  28640. return ($a["dom"] < $b["dom"]) ? -1 : 1;
  28641. }
  28642. function mb_strrev($str, $enc = 'utf-8'){
  28643. $ch = array();
  28644. $ch = preg_split('//u',$str);
  28645. $revch = array_reverse($ch);
  28646. return implode('',$revch);
  28647. }
  28648. /*-- COLUMNS --*/
  28649. // Callback function from function printcolumnbuffer in mpdf
  28650. function columnAdjustAdd($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  28651. if ($type == 'Td') { // xpos,ypos
  28652. $a += ($xadj * $k);
  28653. $b -= ($yadj * $k);
  28654. return 'BT '.sprintf('%.3F %.3F',$a,$b).' Td';
  28655. }
  28656. else if ($type == 're') { // xpos,ypos,width,height
  28657. $a += ($xadj * $k);
  28658. $b -= ($yadj * $k);
  28659. return sprintf('%.3F %.3F %.3F %.3F',$a,$b,$c,$d).' re';
  28660. }
  28661. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  28662. $a += ($xadj * $k);
  28663. $b -= ($yadj * $k);
  28664. return sprintf('%.3F %.3F l',$a,$b);
  28665. }
  28666. else if ($type == 'img') { // width,height,xpos,ypos
  28667. $c += ($xadj * $k);
  28668. $d -= ($yadj * $k);
  28669. return sprintf('q %.3F 0 0 %.3F %.3F %.3F',$a,$b,$c,$d).' cm /'.$e;
  28670. }
  28671. else if ($type == 'draw') { // xpos,ypos
  28672. $a += ($xadj * $k);
  28673. $b -= ($yadj * $k);
  28674. return sprintf('%.3F %.3F m',$a,$b);
  28675. }
  28676. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  28677. $a += ($xadj * $k);
  28678. $b -= ($yadj * $k);
  28679. $c += ($xadj * $k);
  28680. $d -= ($yadj * $k);
  28681. $e += ($xadj * $k);
  28682. $f -= ($yadj * $k);
  28683. return sprintf('%.3F %.3F %.3F %.3F %.3F %.3F',$a,$b,$c,$d,$e,$f).' c';
  28684. }
  28685. }
  28686. /*-- END COLUMNS --*/
  28687. function ConvertColor($color="#000000"){
  28688. $color = trim(strtolower($color));
  28689. $c = false;
  28690. if ($color=='transparent') { return false; }
  28691. else if ($color=='inherit') { return false; }
  28692. else if (isset($this->SVGcolors[$color])) $color = $this->SVGcolors[$color];
  28693. if (preg_match('/^[\d]+$/',$color)) { $c = (array(1,$color)); } // i.e. integer only
  28694. else if ($color[0] == '#') { //case of #nnnnnn or #nnn
  28695. $cor = preg_replace('/\s+.*/','',$color); // in case of Background: #CCC url() x-repeat etc.
  28696. if (strlen($cor) == 4) { // Turn #RGB into #RRGGBB
  28697. $cor = "#" . $cor[1] . $cor[1] . $cor[2] . $cor[2] . $cor[3] . $cor[3];
  28698. }
  28699. $r = hexdec(substr($cor, 1, 2));
  28700. $g = hexdec(substr($cor, 3, 2));
  28701. $b = hexdec(substr($cor, 5, 2));
  28702. $c = array(3,$r,$g,$b);
  28703. }
  28704. else if (preg_match('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\((.*?)\)/',$color,$m)) { // mPDF 5.6.05
  28705. $type= $m[1];
  28706. $cores = explode(",", $m[2]);
  28707. $ncores = count($cores);
  28708. if (stristr($cores[0],'%') ) {
  28709. $cores[0] += 0;
  28710. if ($type=='rgb' || $type=='rgba') { $cores[0] = intval($cores[0]*255/100); }
  28711. }
  28712. if ($ncores>1 && stristr($cores[1],'%') ) {
  28713. $cores[1] += 0;
  28714. if ($type=='rgb' || $type=='rgba') { $cores[1] = intval($cores[1]*255/100); }
  28715. if ($type=='hsl' || $type=='hsla') { $cores[1] = $cores[1]/100; }
  28716. }
  28717. if ($ncores>2 && stristr($cores[2],'%') ) {
  28718. $cores[2] += 0;
  28719. if ($type=='rgb' || $type=='rgba') { $cores[2] = intval($cores[2]*255/100); }
  28720. if ($type=='hsl' || $type=='hsla') { $cores[2] = $cores[2]/100; }
  28721. }
  28722. if ($ncores>3 && stristr($cores[3],'%') ) {
  28723. $cores[3] += 0;
  28724. }
  28725. if ($type=='rgb') { $c = array(3,$cores[0],$cores[1],$cores[2]); }
  28726. else if ($type=='rgba') { $c = array(5,$cores[0],$cores[1],$cores[2],$cores[3]*100); }
  28727. else if ($type=='cmyk' || $type=='device-cmyk') { $c = array(4,$cores[0],$cores[1],$cores[2],$cores[3]); } // mPDF 5.6.05
  28728. else if ($type=='cmyka' || $type=='device-cmyka') { $c = array(6,$cores[0],$cores[1],$cores[2],$cores[3],$cores[4]*100); } // mPDF 5.6.05
  28729. else if ($type=='hsl' || $type=='hsla') {
  28730. $conv = $this->hsl2rgb($cores[0]/360,$cores[1],$cores[2]);
  28731. if ($type=='hsl') { $c = array(3,$conv[0],$conv[1],$conv[2]); }
  28732. else if ($type=='hsla') { $c = array(5,$conv[0],$conv[1],$conv[2],$cores[3]*100); }
  28733. }
  28734. else if ($type=='spot') {
  28735. $name = strtoupper(trim($cores[0]));
  28736. // mPDF 5.6.59
  28737. if(!isset($this->spotColors[$name])) {
  28738. if (isset($cores[5])) { $this->AddSpotColor($cores[0],$cores[2],$cores[3],$cores[4],$cores[5]); }
  28739. else { $this->Error('Undefined spot color: '.$name); }
  28740. }
  28741. $c = array(2,$this->spotColors[$name]['i'],$cores[1]);
  28742. }
  28743. }
  28744. // $this->restrictColorSpace
  28745. // 1 - allow GRAYSCALE only [convert CMYK/RGB->gray]
  28746. // 2 - allow RGB / SPOT COLOR / Grayscale [convert CMYK->RGB]
  28747. // 3 - allow CMYK / SPOT COLOR / Grayscale [convert RGB->CMYK]
  28748. if ($this->PDFA || $this->PDFX || $this->restrictColorSpace) {
  28749. if ($c[0]==1) { // GRAYSCALE
  28750. }
  28751. else if ($c[0]==2) { // SPOT COLOR
  28752. if (!isset($this->spotColorIDs[$c[1]])) { die('Error: Spot colour has not been defined - '.$this->spotColorIDs[$c[1]]); }
  28753. if ($this->PDFA) {
  28754. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "Spot color specified '".$this->spotColorIDs[$c[1]]."' (converted to process color)"; }
  28755. if ($this->restrictColorSpace!=3) {
  28756. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  28757. $c = $this->cmyk2rgb(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  28758. }
  28759. }
  28760. else if ($this->restrictColorSpace==1) {
  28761. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  28762. $c = $this->cmyk2gray(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  28763. }
  28764. }
  28765. else if ($c[0]==3) { // RGB
  28766. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28767. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color specified '".$color."' (converted to CMYK)"; }
  28768. $c = $this->rgb2cmyk($c);
  28769. }
  28770. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  28771. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  28772. }
  28773. else if ($c[0]==4) { // CMYK
  28774. if ($this->PDFA && $this->restrictColorSpace!=3) {
  28775. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "CMYK color specified '".$color."' (converted to RGB)"; }
  28776. $c = $this->cmyk2rgb($c);
  28777. }
  28778. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  28779. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  28780. }
  28781. else if ($c[0]==5) { // RGBa
  28782. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28783. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  28784. $c = $this->rgb2cmyk($c);
  28785. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  28786. }
  28787. else if ($this->PDFA && $this->restrictColorSpace!=3) {
  28788. if (!$this->PDFAauto) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  28789. $c = $this->rgb2cmyk($c);
  28790. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  28791. }
  28792. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  28793. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  28794. }
  28795. else if ($c[0]==6) { // CMYKa
  28796. if ($this->PDFA && $this->restrictColorSpace!=3) {
  28797. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  28798. $c = $this->cmyk2rgb($c);
  28799. $c = array(3, $c[1], $c[2], $c[3]);
  28800. }
  28801. else if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  28802. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  28803. $c = $this->cmyk2rgb($c);
  28804. $c = array(3, $c[1], $c[2], $c[3]);
  28805. }
  28806. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  28807. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  28808. }
  28809. }
  28810. if (is_array($c)) {
  28811. $c = array_pad($c, 6, 0);
  28812. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  28813. }
  28814. return $cstr;
  28815. }
  28816. function rgb2gray($c) {
  28817. if (isset($c[4])) { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07)), ord(1), $c[4]); }
  28818. else { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07))); }
  28819. }
  28820. function cmyk2gray($c) {
  28821. $rgb = $this->cmyk2rgb($c);
  28822. return $this->rgb2gray($rgb);
  28823. }
  28824. function rgb2cmyk($c) {
  28825. $cyan = 1 - ($c[1] / 255);
  28826. $magenta = 1 - ($c[2] / 255);
  28827. $yellow = 1 - ($c[3] / 255);
  28828. $min = min($cyan, $magenta, $yellow);
  28829. if ($min == 1) {
  28830. if ($c[0]==5) { return array (6,100,100,100,100, $c[4]); }
  28831. else { return array (4,100,100,100,100); }
  28832. // For K-Black
  28833. //if ($c[0]==5) { return array (6,0,0,0,100, $c[4]); }
  28834. //else { return array (4,0,0,0,100); }
  28835. }
  28836. $K = $min;
  28837. $black = 1 - $K;
  28838. if ($c[0]==5) { return array (6,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100, $c[4]); }
  28839. else { return array (4,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100); }
  28840. }
  28841. function cmyk2rgb($c) {
  28842. $rgb = array();
  28843. $colors = 255 - ($c[4]*2.55);
  28844. $rgb[0] = intval($colors * (255 - ($c[1]*2.55))/255);
  28845. $rgb[1] = intval($colors * (255 - ($c[2]*2.55))/255);
  28846. $rgb[2] = intval($colors * (255 - ($c[3]*2.55))/255);
  28847. if ($c[0]==6) { return array (5,$rgb[0],$rgb[1],$rgb[2], $c[5]); }
  28848. else { return array (3,$rgb[0],$rgb[1],$rgb[2]); }
  28849. }
  28850. function rgb2hsl($var_r, $var_g, $var_b) {
  28851. $var_min = min($var_r,$var_g,$var_b);
  28852. $var_max = max($var_r,$var_g,$var_b);
  28853. $del_max = $var_max - $var_min;
  28854. $l = ($var_max + $var_min) / 2;
  28855. if ($del_max == 0) {
  28856. $h = 0;
  28857. $s = 0;
  28858. }
  28859. else {
  28860. if ($l < 0.5) { $s = $del_max / ($var_max + $var_min); }
  28861. else { $s = $del_max / (2 - $var_max - $var_min); }
  28862. $del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max;
  28863. $del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max;
  28864. $del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max;
  28865. if ($var_r == $var_max) { $h = $del_b - $del_g; }
  28866. elseif ($var_g == $var_max) { $h = (1 / 3) + $del_r - $del_b; }
  28867. elseif ($var_b == $var_max) { $h = (2 / 3) + $del_g - $del_r; };
  28868. if ($h < 0) { $h += 1; }
  28869. if ($h > 1) { $h -= 1; }
  28870. }
  28871. return array($h,$s,$l);
  28872. }
  28873. function hsl2rgb($h2,$s2,$l2) {
  28874. // Input is HSL value of complementary colour, held in $h2, $s, $l as fractions of 1
  28875. // Output is RGB in normal 255 255 255 format, held in $r, $g, $b
  28876. // Hue is converted using function hue_2_rgb, shown at the end of this code
  28877. if ($s2 == 0) {
  28878. $r = $l2 * 255;
  28879. $g = $l2 * 255;
  28880. $b = $l2 * 255;
  28881. }
  28882. else {
  28883. if ($l2 < 0.5) { $var_2 = $l2 * (1 + $s2); }
  28884. else { $var_2 = ($l2 + $s2) - ($s2 * $l2); }
  28885. $var_1 = 2 * $l2 - $var_2;
  28886. $r = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 + (1 / 3)));
  28887. $g = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2));
  28888. $b = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 - (1 / 3)));
  28889. }
  28890. return array($r,$g,$b);
  28891. }
  28892. function hue_2_rgb($v1,$v2,$vh) {
  28893. // Function to convert hue to RGB, called from above
  28894. if ($vh < 0) { $vh += 1; };
  28895. if ($vh > 1) { $vh -= 1; };
  28896. if ((6 * $vh) < 1) { return ($v1 + ($v2 - $v1) * 6 * $vh); };
  28897. if ((2 * $vh) < 1) { return ($v2); };
  28898. if ((3 * $vh) < 2) { return ($v1 + ($v2 - $v1) * ((2 / 3 - $vh) * 6)); };
  28899. return ($v1);
  28900. }
  28901. function _invertColor($cor) {
  28902. if ($cor[0]==3 || $cor[0]==5) { // RGB
  28903. return array(3, (255-$cor[1]), (255-$cor[2]), (255-$cor[3]));
  28904. }
  28905. else if ($cor[0]==4 || $cor[0]==6) { // CMYK
  28906. return array(4, (100-$cor[1]), (100-$cor[2]), (100-$cor[3]), (100-$cor[4]));
  28907. }
  28908. else if ($cor[0]==1) { // Grayscale
  28909. return array(1, (255-$cor[1]));
  28910. }
  28911. // Cannot cope with non-RGB colors at present
  28912. die('Error in _invertColor - trying to invert non-RGB color');
  28913. }
  28914. function _colAtoString($cor) {
  28915. $s = '';
  28916. if ($cor{0}==1) $s = 'rgb('.ord($cor{1}).','.ord($cor{1}).','.ord($cor{1}).')';
  28917. else if ($cor{0}==2) $s = 'spot('.ord($cor{1}).','.ord($cor{2}).')'; // SPOT COLOR
  28918. else if ($cor{0}==3) $s = 'rgb('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).')';
  28919. else if ($cor{0}==4) $s = 'cmyk('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.ord($cor{4}).')';
  28920. else if ($cor{0}==5) $s = 'rgba('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.sprintf('%0.2F',ord($cor{4})/100).')';
  28921. else if ($cor{0}==6) $s = 'cmyka('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.ord($cor{4}).','.sprintf('%0.2F',ord($cor{5})/100).')';
  28922. return $s;
  28923. }
  28924. function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){
  28925. // usefontsize - setfalse for e.g. margins - will ignore fontsize for % values
  28926. // Depends of maxsize value to make % work properly. Usually maxsize == pagewidth
  28927. // For text $maxsize = Fontsize
  28928. // Setting e.g. margin % will use maxsize (pagewidth) and em will use fontsize
  28929. //Identify size (remember: we are using 'mm' units here)
  28930. $size = trim(strtolower($size));
  28931. if ( $size == 'thin' ) $size = 1*(25.4/$this->dpi); //1 pixel width for table borders
  28932. elseif ( stristr($size,'px') ) $size *= (25.4/$this->dpi); //pixels
  28933. elseif ( stristr($size,'cm') ) $size *= 10; //centimeters
  28934. elseif ( stristr($size,'mm') ) $size += 0; //millimeters
  28935. elseif ( stristr($size,'pt') ) $size *= 25.4/72; //72 pts/inch
  28936. elseif ( stristr($size,'rem') ) { // mPDF 5.6.12
  28937. $size += 0; //make "0.83rem" become simply "0.83"
  28938. $size *= ($this->default_font_size / _MPDFK);
  28939. }
  28940. elseif ( stristr($size,'em') ) {
  28941. $size += 0; //make "0.83em" become simply "0.83"
  28942. if ($fontsize) { $size *= $fontsize; }
  28943. else { $size *= $maxsize; }
  28944. }
  28945. elseif ( stristr($size,'%') ) {
  28946. $size += 0; //make "90%" become simply "90"
  28947. if ($fontsize && $usefontsize) { $size *= $fontsize/100; }
  28948. else { $size *= $maxsize/100; }
  28949. }
  28950. elseif ( stristr($size,'in') ) $size *= 25.4; //inches
  28951. elseif ( stristr($size,'pc') ) $size *= 38.1/9; //PostScript picas
  28952. elseif ( stristr($size,'ex') ) { // Approximates "ex" as half of font height
  28953. $size += 0; //make "3.5ex" become simply "3.5"
  28954. if ($fontsize) { $size *= $fontsize/2; }
  28955. else { $size *= $maxsize/2; }
  28956. }
  28957. elseif ( $size == 'medium' ) $size = 3*(25.4/$this->dpi); //3 pixel width for table borders
  28958. elseif ( $size == 'thick' ) $size = 5*(25.4/$this->dpi); //5 pixel width for table borders
  28959. elseif ($size == 'xx-small') {
  28960. if ($fontsize) { $size *= $fontsize*0.7; }
  28961. else { $size *= $maxsize*0.7; }
  28962. }
  28963. elseif ($size == 'x-small') {
  28964. if ($fontsize) { $size *= $fontsize*0.77; }
  28965. else { $size *= $maxsize*0.77; }
  28966. }
  28967. elseif ($size == 'small') {
  28968. if ($fontsize) { $size *= $fontsize*0.86; }
  28969. else { $size *= $maxsize*0.86; }
  28970. }
  28971. elseif ($size == 'medium') {
  28972. if ($fontsize) { $size *= $fontsize; }
  28973. else { $size *= $maxsize; }
  28974. }
  28975. elseif ($size == 'large') {
  28976. if ($fontsize) { $size *= $fontsize*1.2; }
  28977. else { $size *= $maxsize*1.2; }
  28978. }
  28979. elseif ($size == 'x-large') {
  28980. if ($fontsize) { $size *= $fontsize*1.5; }
  28981. else { $size *= $maxsize*1.5; }
  28982. }
  28983. elseif ($size == 'xx-large') {
  28984. if ($fontsize) { $size *= $fontsize*2; }
  28985. else { $size *= $maxsize*2; }
  28986. }
  28987. else $size *= (25.4/$this->dpi); //nothing == px
  28988. return $size;
  28989. }
  28990. function lesser_entity_decode($html) {
  28991. //supports the most used entity codes (only does ascii safe characters)
  28992. //$html = str_replace("&nbsp;"," ",$html); // mPDF 5.3.59
  28993. $html = str_replace("&lt;","<",$html);
  28994. $html = str_replace("&gt;",">",$html);
  28995. $html = str_replace("&apos;","'",$html);
  28996. $html = str_replace("&quot;",'"',$html);
  28997. $html = str_replace("&amp;","&",$html);
  28998. return $html;
  28999. }
  29000. function AdjustHTML($html, $tabSpaces=8) {
  29001. //Try to make the html text more manageable (turning it into XHTML)
  29002. if (PHP_VERSION_ID < 50307) {
  29003. if (strlen($html) > 100000) {
  29004. if (PHP_VERSION_ID < 50200) $this->Error("The HTML code is more than 100,000 characters. You should use WriteHTML() with smaller string lengths.");
  29005. else ini_set("pcre.backtrack_limit","1000000");
  29006. }
  29007. }
  29008. /*-- ANNOTATIONS --*/
  29009. preg_match_all("/(<annotation.*?>)/si", $html, $m);
  29010. if (count($m[1])) {
  29011. for($i=0;$i<count($m[1]);$i++) {
  29012. $sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]);
  29013. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  29014. }
  29015. }
  29016. /*-- END ANNOTATIONS --*/
  29017. preg_match_all("/(<svg.*?<\/svg>)/si", $html, $svgi);
  29018. if (count($svgi[0])) {
  29019. for($i=0;$i<count($svgi[0]);$i++) {
  29020. $file = _MPDF_TEMP_PATH.'_tempSVG'.RAND(1,10000).'_'.$i.'.svg';
  29021. //Save to local file
  29022. file_put_contents($file, $svgi[0][$i]);
  29023. $html = str_replace($svgi[0][$i], '<img src="'.$file.'" />', $html); // mPDF 5.5.18
  29024. }
  29025. }
  29026. //Remove javascript code from HTML (should not appear in the PDF file)
  29027. $html = preg_replace('/<script.*?<\/script>/is','',$html);
  29028. //Remove special comments
  29029. $html = preg_replace('/<!--mpdf/i','',$html);
  29030. $html = preg_replace('/mpdf-->/i','',$html);
  29031. //Remove comments from HTML (should not appear in the PDF file)
  29032. $html = preg_replace('/<!--.*?-->/s','',$html);
  29033. $html = preg_replace('/\f/','',$html); //replace formfeed by nothing
  29034. $html = preg_replace('/\r/','',$html); //replace carriage return by nothing
  29035. // Well formed XHTML end tags
  29036. $html = preg_replace('/<(br|hr)\/>/i',"<\\1 />",$html);
  29037. // Get rid of empty <thead></thead>
  29038. $html = preg_replace('/<thead>\s*<\/thead>/i','',$html);
  29039. $html = preg_replace('/<tfoot>\s*<\/tfoot>/i','',$html);
  29040. $html = preg_replace('/<table[^>]*>\s*<\/table>/i','',$html);
  29041. $html = preg_replace('/<tr>\s*<\/tr>/i','',$html);
  29042. // Remove spaces at end of table cells
  29043. $html = preg_replace("/[ \n\r]+<\/t(d|h)/",'</t\\1',$html); // mPDF 5.5.09
  29044. $html = preg_replace("/[ ]*<dottab\s*[\/]*>[ ]*/",'<dottab />',$html);
  29045. // Concatenates any Substitute characters from symbols/dingbats
  29046. $html = str_replace('</tts><tts>','|',$html);
  29047. $html = str_replace('</ttz><ttz>','|',$html);
  29048. $html = str_replace('</tta><tta>','|',$html);
  29049. $html = preg_replace('/<br \/>\s*/is',"<br />",$html);
  29050. $html = preg_replace('/<wbr[ \/]*>\s*/is',"&#173;",$html); // mPDF 5.6.04
  29051. // Preserve '\n's in content between the tags <pre> and </pre>
  29052. if (preg_match('/<pre/',$html)) {
  29053. $html_a = preg_split('/(\<\/?pre[^\>]*\>)/', $html, -1, 2);
  29054. $h = array();
  29055. $c=0;
  29056. foreach($html_a AS $s) {
  29057. if ($c>1 && preg_match('/^<\/pre/i',$s)) { $c--; $s=preg_replace('/<\/pre/i','</innerpre',$s); }
  29058. else if ($c>0 && preg_match('/^<pre/i',$s)) { $c++; $s=preg_replace('/<pre/i','<innerpre',$s); }
  29059. else if (preg_match('/^<pre/i',$s)) { $c++; }
  29060. else if (preg_match('/^<\/pre/i',$s)) { $c--; }
  29061. array_push($h, $s);
  29062. }
  29063. $html = implode("", $h);
  29064. }
  29065. $thereispre = preg_match_all('#<pre(.*?)>(.*?)</pre>#si',$html,$temp);
  29066. // Preserve '\n's in content between the tags <textarea> and </textarea>
  29067. $thereistextarea = preg_match_all('#<textarea(.*?)>(.*?)</textarea>#si',$html,$temp2);
  29068. $html = preg_replace('/[\n]/',' ',$html); //replace linefeed by spaces
  29069. $html = preg_replace('/[\t]/',' ',$html); //replace tabs by spaces
  29070. // Converts < to &lt; when not a tag
  29071. $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
  29072. $html = preg_replace("/[ ]+/",' ',$html);
  29073. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  29074. $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html);
  29075. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  29076. $html = preg_replace('/\/li>\s+<li/i','/li><li',$html);
  29077. $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
  29078. $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html);
  29079. $iterator = 0;
  29080. while($thereispre) //Recover <pre attributes>content</pre>
  29081. {
  29082. $temp[2][$iterator] = preg_replace("/^([^\n\t]*?)\t/me", "stripslashes('\\1') . str_repeat(' ', ( $tabSpaces - (mb_strlen(stripslashes('\\1')) % $tabSpaces)) )",$temp[2][$iterator]);
  29083. $temp[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp[2][$iterator]);
  29084. $temp[2][$iterator] = preg_replace('/\n/',"<br />",$temp[2][$iterator]);
  29085. $temp[2][$iterator] = str_replace('\\',"\\\\",$temp[2][$iterator]);
  29086. $html = preg_replace('#<pre(.*?)>(.*?)</pre>#si','<erp'.$temp[1][$iterator].'>'.$temp[2][$iterator].'</erp>',$html,1);
  29087. $thereispre--;
  29088. $iterator++;
  29089. }
  29090. $iterator = 0;
  29091. while($thereistextarea) //Recover <textarea attributes>content</textarea>
  29092. {
  29093. $temp2[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp2[2][$iterator]);
  29094. $temp2[2][$iterator] = str_replace('\\',"\\\\",$temp2[2][$iterator]); // mPDF 5.3.88
  29095. $html = preg_replace('#<textarea(.*?)>(.*?)</textarea>#si','<aeratxet'.$temp2[1][$iterator].'>'.trim($temp2[2][$iterator]) .'</aeratxet>',$html,1);
  29096. $thereistextarea--;
  29097. $iterator++;
  29098. }
  29099. //Restore original tag names
  29100. $html = str_replace("<erp","<pre",$html);
  29101. $html = str_replace("</erp>","</pre>",$html);
  29102. $html = str_replace("<aeratxet","<textarea",$html);
  29103. $html = str_replace("</aeratxet>","</textarea>",$html);
  29104. $html = str_replace("</innerpre","</pre",$html);
  29105. $html = str_replace("<innerpre","<pre",$html);
  29106. $html = preg_replace('/<textarea([^>]*)><\/textarea>/si','<textarea\\1> </textarea>',$html);
  29107. $html = preg_replace('/(<table[^>]*>)\s*(<caption)(.*?<\/caption>)(.*?<\/table>)/si','\\2 position="top"\\3\\1\\4\\2 position="bottom"\\3',$html); // *TABLES*
  29108. $html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html); // *TABLES*
  29109. $html = preg_replace("/\xbb\xa4\xac/", "\n", $html);
  29110. return $html;
  29111. }
  29112. /*-- LISTS --*/
  29113. function dec2other($num, $cp) {
  29114. $nstr = (string) $num;
  29115. $rnum = '';
  29116. for ($i=0;$i<strlen($nstr);$i++) {
  29117. if ($this->_charDefined($this->CurrentFont['cw'],$cp+intval($nstr[$i]))) { // contains arabic-indic numbers
  29118. $rnum .= code2utf($cp+intval($nstr[$i]));
  29119. }
  29120. else { $rnum .= $nstr[$i]; }
  29121. }
  29122. return $rnum;
  29123. }
  29124. function dec2alpha($valor,$toupper="true"){
  29125. // returns a string from A-Z to AA-ZZ to AAA-ZZZ
  29126. // OBS: A = 65 ASCII TABLE VALUE
  29127. if (($valor < 1) || ($valor > 18278)) return "?"; //supports 'only' up to 18278
  29128. $c1 = $c2 = $c3 = '';
  29129. if ($valor > 702) // 3 letters (up to 18278)
  29130. {
  29131. $c1 = 65 + floor(($valor-703)/676);
  29132. $c2 = 65 + floor((($valor-703)%676)/26);
  29133. $c3 = 65 + floor((($valor-703)%676)%26);
  29134. }
  29135. elseif ($valor > 26) // 2 letters (up to 702)
  29136. {
  29137. $c1 = (64 + (int)(($valor-1) / 26));
  29138. $c2 = (64 + (int)($valor % 26));
  29139. if ($c2 == 64) $c2 += 26;
  29140. }
  29141. else // 1 letter (up to 26)
  29142. {
  29143. $c1 = (64 + $valor);
  29144. }
  29145. $alpha = chr($c1);
  29146. if ($c2 != '') $alpha .= chr($c2);
  29147. if ($c3 != '') $alpha .= chr($c3);
  29148. if (!$toupper) $alpha = strtolower($alpha);
  29149. return $alpha;
  29150. }
  29151. function dec2roman($valor,$toupper=true){
  29152. //returns a string as a roman numeral
  29153. $r1=$r2=$r3=$r4='';
  29154. if (($valor >= 5000) || ($valor < 1)) return "?"; //supports 'only' up to 4999
  29155. $aux = (int)($valor/1000);
  29156. if ($aux!==0)
  29157. {
  29158. $valor %= 1000;
  29159. while($aux!==0)
  29160. {
  29161. $r1 .= "M";
  29162. $aux--;
  29163. }
  29164. }
  29165. $aux = (int)($valor/100);
  29166. if ($aux!==0)
  29167. {
  29168. $valor %= 100;
  29169. switch($aux){
  29170. case 3: $r2="C";
  29171. case 2: $r2.="C";
  29172. case 1: $r2.="C"; break;
  29173. case 9: $r2="CM"; break;
  29174. case 8: $r2="C";
  29175. case 7: $r2.="C";
  29176. case 6: $r2.="C";
  29177. case 5: $r2="D".$r2; break;
  29178. case 4: $r2="CD"; break;
  29179. default: break;
  29180. }
  29181. }
  29182. $aux = (int)($valor/10);
  29183. if ($aux!==0)
  29184. {
  29185. $valor %= 10;
  29186. switch($aux){
  29187. case 3: $r3="X";
  29188. case 2: $r3.="X";
  29189. case 1: $r3.="X"; break;
  29190. case 9: $r3="XC"; break;
  29191. case 8: $r3="X";
  29192. case 7: $r3.="X";
  29193. case 6: $r3.="X";
  29194. case 5: $r3="L".$r3; break;
  29195. case 4: $r3="XL"; break;
  29196. default: break;
  29197. }
  29198. }
  29199. switch($valor){
  29200. case 3: $r4="I";
  29201. case 2: $r4.="I";
  29202. case 1: $r4.="I"; break;
  29203. case 9: $r4="IX"; break;
  29204. case 8: $r4="I";
  29205. case 7: $r4.="I";
  29206. case 6: $r4.="I";
  29207. case 5: $r4="V".$r4; break;
  29208. case 4: $r4="IV"; break;
  29209. default: break;
  29210. }
  29211. $roman = $r1.$r2.$r3.$r4;
  29212. if (!$toupper) $roman = strtolower($roman);
  29213. return $roman;
  29214. }
  29215. /*-- END LISTS --*/
  29216. //===========================
  29217. /*-- IMPORTS --*/
  29218. function SetImportUse() {
  29219. $this->enableImports = true;
  29220. ini_set('auto_detect_line_endings',1);
  29221. require_once(_MPDF_PATH."mpdfi/pdf_context.php");
  29222. require_once(_MPDF_PATH."mpdfi/pdf_parser.php");
  29223. require_once(_MPDF_PATH."mpdfi/fpdi_pdf_parser.php");
  29224. }
  29225. // from mPDFI
  29226. function hex2str($hex) {
  29227. return pack("H*", str_replace(array("\r","\n"," "),"", $hex));
  29228. }
  29229. function str2hex($str) {
  29230. return current(unpack("H*",$str));
  29231. }
  29232. function pdf_write_value(&$value) {
  29233. switch ($value[0]) {
  29234. case PDF_TYPE_NUMERIC :
  29235. case PDF_TYPE_TOKEN :
  29236. // A numeric value or a token.
  29237. // Simply output them
  29238. $this->_out($value[1]." ", false);
  29239. break;
  29240. case PDF_TYPE_ARRAY :
  29241. // An array. Output the proper
  29242. // structure and move on.
  29243. $this->_out("[",false);
  29244. for ($i = 0; $i < count($value[1]); $i++) {
  29245. $this->pdf_write_value($value[1][$i]);
  29246. }
  29247. $this->_out("]");
  29248. break;
  29249. case PDF_TYPE_DICTIONARY :
  29250. // A dictionary.
  29251. $this->_out("<<",false);
  29252. reset ($value[1]);
  29253. while (list($k, $v) = each($value[1])) {
  29254. $this->_out($k . " ",false);
  29255. $this->pdf_write_value($v);
  29256. }
  29257. $this->_out(">>");
  29258. break;
  29259. case PDF_TYPE_OBJREF :
  29260. // An indirect object reference
  29261. // Fill the object stack if needed
  29262. $cpfn =& $this->current_parser->filename;
  29263. if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
  29264. $this->_newobj(false,true);
  29265. $this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  29266. $this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  29267. }
  29268. $objid = $this->_don_obj_stack[$cpfn][$value[1]][0];
  29269. $this->_out("{$objid} 0 R"); //{$value[2]}
  29270. break;
  29271. case PDF_TYPE_STRING :
  29272. if ($this->encrypted) {
  29273. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  29274. $value[1] = $this->_escape($value[1]);
  29275. }
  29276. // A string.
  29277. $this->_out('('.$value[1].')');
  29278. break;
  29279. case PDF_TYPE_STREAM :
  29280. // A stream. First, output the
  29281. // stream dictionary, then the
  29282. // stream data itself.
  29283. $this->pdf_write_value($value[1]);
  29284. if ($this->encrypted) {
  29285. $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
  29286. }
  29287. $this->_out("stream");
  29288. $this->_out($value[2][1]);
  29289. $this->_out("endstream");
  29290. break;
  29291. case PDF_TYPE_HEX :
  29292. if ($this->encrypted) {
  29293. $value[1] = $this->hex2str($value[1]);
  29294. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  29295. // remake hexstring of encrypted string
  29296. $value[1] = $this->str2hex($value[1]);
  29297. }
  29298. $this->_out("<".$value[1].">");
  29299. break;
  29300. case PDF_TYPE_NULL :
  29301. // The null object.
  29302. $this->_out("null");
  29303. break;
  29304. }
  29305. }
  29306. // ========== OVERWRITE SEARCH STRING IN A PDF FILE ================
  29307. function OverWrite($file_in, $search, $replacement, $dest="D", $file_out="mpdf" ) {
  29308. $pdf = file_get_contents($file_in);
  29309. if (!is_array($search)) {
  29310. $x = $search;
  29311. $search = array($x);
  29312. }
  29313. if (!is_array($replacement)) {
  29314. $x = $replacement;
  29315. $search = array($x);
  29316. }
  29317. if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  29318. foreach($search AS $k=>$val) {
  29319. $search[$k] = $this->UTF8ToUTF16BE($search[$k] , false);
  29320. $search[$k] = $this->_escape($search[$k]);
  29321. $replacement[$k] = $this->UTF8ToUTF16BE($replacement[$k], false);
  29322. $replacement[$k] = $this->_escape($replacement[$k]);
  29323. }
  29324. }
  29325. else {
  29326. foreach($replacement AS $k=>$val) {
  29327. $replacement[$k] = mb_convert_encoding($replacement[$k],$this->mb_enc,'utf-8');
  29328. $replacement[$k] = $this->_escape($replacement[$k]);
  29329. }
  29330. }
  29331. // Get xref into array
  29332. $xref = array();
  29333. preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s",$pdf,$m);
  29334. $xref_objid = $m[1];
  29335. preg_match_all('/(\d{10}) (\d{5}) (f|n)/',$m[2],$x);
  29336. for($i=0; $i<count($x[0]); $i++) {
  29337. $xref[] = array(intval($x[1][$i]), $x[2][$i], $x[3][$i]);
  29338. }
  29339. $changes = array();
  29340. preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s",$pdf,$m);
  29341. preg_match_all("/(\d+) 0 R /s",$m[1],$o);
  29342. $objlist = $o[1];
  29343. foreach($objlist AS $obj) {
  29344. if ($this->compress) {
  29345. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  29346. }
  29347. else {
  29348. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  29349. }
  29350. $s = $m[2];
  29351. if (!$s) { continue; }
  29352. $oldlen = $m[1];
  29353. if ($this->encrypted) {
  29354. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  29355. }
  29356. if ($this->compress) {
  29357. $s = gzuncompress($s);
  29358. }
  29359. foreach($search AS $k=>$val) {
  29360. $s = str_replace($search[$k],$replacement[$k],$s);
  29361. }
  29362. if ($this->compress) {
  29363. $s = gzcompress($s);
  29364. }
  29365. if ($this->encrypted) {
  29366. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  29367. }
  29368. $newlen = strlen($s);
  29369. $changes[($xref[$obj+1][0])] = ($newlen - $oldlen) + (strlen($newlen) - strlen($oldlen ));
  29370. if ($this->compress) {
  29371. $newstr = ($obj+1) . " 0 obj\n<</Filter /FlateDecode /Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  29372. }
  29373. else {
  29374. $newstr = ($obj+1) . " 0 obj\n<</Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  29375. }
  29376. $pdf = str_replace($m[0],$newstr,$pdf);
  29377. }
  29378. // Update xref in PDF
  29379. krsort($changes);
  29380. $newxref = "xref\n0 ".$xref_objid."\n";
  29381. foreach($xref AS $v) {
  29382. foreach($changes AS $ck => $cv) {
  29383. if ($v[0] > $ck) { $v[0] += $cv; }
  29384. }
  29385. $newxref .= sprintf('%010d',$v[0]) . ' ' . $v[1] . ' ' .$v[2] . " \n";
  29386. }
  29387. $newxref .= "trailer";
  29388. $pdf = preg_replace("/xref\n0 \d+\n.*?\ntrailer/s",$newxref,$pdf);
  29389. // Update startxref in PDF
  29390. preg_match("/startxref\n(\d+)\n%%EOF/s", $pdf, $m);
  29391. $startxref = $m[1];
  29392. $startxref += array_sum($changes);
  29393. $pdf = preg_replace("/startxref\n(\d+)\n%%EOF/s","startxref\n".$startxref."\n%%EOF",$pdf);
  29394. // OUTPUT
  29395. switch($dest) {
  29396. case 'I':
  29397. //Send to standard output
  29398. if(isset($_SERVER['SERVER_NAME']))
  29399. {
  29400. //We send to a browser
  29401. Header('Content-Type: application/pdf');
  29402. Header('Content-Length: '.strlen($pdf));
  29403. Header('Content-disposition: inline; filename='.$file_out);
  29404. }
  29405. echo $pdf;
  29406. break;
  29407. case 'F':
  29408. //Save to local file
  29409. if (!$file_out) { $file_out = 'mpdf.pdf'; }
  29410. $f=fopen($file_out,'wb');
  29411. if(!$f) die('Unable to create output file: '.$file_out);
  29412. fwrite($f,$pdf,strlen($pdf));
  29413. fclose($f);
  29414. break;
  29415. case 'S':
  29416. //Return as a string
  29417. return $pdf;
  29418. case 'D':
  29419. default:
  29420. //Download file
  29421. if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  29422. Header('Content-Type: application/force-download');
  29423. else
  29424. Header('Content-Type: application/octet-stream');
  29425. Header('Content-Length: '.strlen($pdf));
  29426. Header('Content-disposition: attachment; filename='.$file_out);
  29427. echo $pdf;
  29428. break;
  29429. }
  29430. }
  29431. function GetTemplateSize($tplidx, $_w=0, $_h=0) {
  29432. if (!$this->tpls[$tplidx])
  29433. return false;
  29434. $w = $this->tpls[$tplidx]['box']['w'];
  29435. $h = $this->tpls[$tplidx]['box']['h'];
  29436. if ($_w == 0 and $_h == 0) {
  29437. $_w = $w;
  29438. $_h = $h;
  29439. }
  29440. if($_w==0)
  29441. $_w=$_h*$w/$h;
  29442. if($_h==0)
  29443. $_h=$_w*$h/$w;
  29444. return array("w" => $_w, "h" => $_h);
  29445. }
  29446. // Thumbnails
  29447. function Thumbnail($file, $npr=3, $spacing=10) { //$npr = number per row
  29448. $w = (($this->pgwidth + $spacing)/$npr) - $spacing;
  29449. $oldlinewidth = $this->LineWidth;
  29450. $this->SetLineWidth(0.02);
  29451. $this->SetDColor($this->ConvertColor(0));
  29452. $h = 0;
  29453. $maxh = 0;
  29454. $x = $_x = $this->lMargin;
  29455. $_y = $this->tMargin;
  29456. if ($this->y==0) { $y = $_y; } else { $y = $this->y; }
  29457. $pagecount = $this->SetSourceFile($file);
  29458. for ($n = 1; $n <= $pagecount; $n++) {
  29459. $tplidx = $this->ImportPage($n);
  29460. $size = $this->useTemplate($tplidx, $x, $y, $w);
  29461. $this->Rect($x, $y, $size['w'], $size['h']);
  29462. $h = max($h, $size['h']);
  29463. $maxh = max($h, $maxh);
  29464. if ($n % $npr == 0) {
  29465. if (($y + $h + $spacing + $maxh)>$this->PageBreakTrigger && $n != $pagecount) {
  29466. $this->AddPage();
  29467. $x = $_x;
  29468. $y = $_y;
  29469. }
  29470. else {
  29471. $y += $h+$spacing ;
  29472. $x = $_x;
  29473. $h = 0;
  29474. }
  29475. }
  29476. else {
  29477. $x += $w+$spacing ;
  29478. }
  29479. }
  29480. $this->SetLineWidth($oldlinewidth);
  29481. }
  29482. function SetSourceFile($filename) {
  29483. $this->current_filename = $filename;
  29484. $fn =& $this->current_filename;
  29485. if (!isset($this->parsers[$fn]))
  29486. // $this->parsers[$fn] =& new fpdi_pdf_parser($fn,$this);
  29487. $this->parsers[$fn] = new fpdi_pdf_parser($fn,$this);
  29488. if (!$this->parsers[$fn]->success) {
  29489. $this->Error($this->parsers[$fn]->errormsg); // Delete this line to return false on fail
  29490. return false;
  29491. }
  29492. $this->current_parser =& $this->parsers[$fn];
  29493. return $this->parsers[$fn]->getPageCount();
  29494. }
  29495. function ImportPage($pageno=1, $crop_x=null, $crop_y=null, $crop_w=0, $crop_h=0, $boxName='/CropBox') {
  29496. $fn =& $this->current_filename;
  29497. $parser =& $this->parsers[$fn];
  29498. $parser->setPageno($pageno);
  29499. $this->tpl++;
  29500. $this->tpls[$this->tpl] = array();
  29501. $tpl =& $this->tpls[$this->tpl];
  29502. $tpl['parser'] =& $parser;
  29503. $tpl['resources'] = $parser->getPageResources();
  29504. $tpl['buffer'] = $parser->getContent();
  29505. if (!in_array($boxName, $parser->availableBoxes))
  29506. return $this->Error(sprintf("Unknown box: %s", $boxName));
  29507. $pageboxes = $parser->getPageBoxes($pageno);
  29508. /**
  29509. * MediaBox
  29510. * CropBox: Default -> MediaBox
  29511. * BleedBox: Default -> CropBox
  29512. * TrimBox: Default -> CropBox
  29513. * ArtBox: Default -> CropBox
  29514. */
  29515. if (!isset($pageboxes[$boxName]) && ($boxName == "/BleedBox" || $boxName == "/TrimBox" || $boxName == "/ArtBox"))
  29516. $boxName = "/CropBox";
  29517. if (!isset($pageboxes[$boxName]) && $boxName == "/CropBox")
  29518. $boxName = "/MediaBox";
  29519. if (!isset($pageboxes[$boxName]))
  29520. return false;
  29521. $box = $pageboxes[$boxName];
  29522. $tpl['box'] = $box;
  29523. // To build an array that can be used by useTemplate()
  29524. $this->tpls[$this->tpl] = array_merge($this->tpls[$this->tpl],$box);
  29525. // An imported page will start at 0,0 everytime. Translation will be set in _putformxobjects()
  29526. $tpl['x'] = 0;
  29527. $tpl['y'] = 0;
  29528. $tpl['w'] = $tpl['box']['w'] ;
  29529. $tpl['h'] = $tpl['box']['h'] ;
  29530. if ($crop_w) { $tpl['box']['w'] = $crop_w; }
  29531. if ($crop_h) { $tpl['box']['h'] = $crop_h; }
  29532. if (isset($crop_x)) { $tpl['box']['x'] = $crop_x; }
  29533. if (isset($crop_y)) {$tpl['box']['y'] = $tpl['h'] - $crop_y - $crop_h ; }
  29534. $page =& $parser->pages[$parser->pageno];
  29535. // fix for rotated pages
  29536. $rotation = $parser->getPageRotation($pageno);
  29537. if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0 && $tpl['box']['w'] == $tpl['w']) {
  29538. $steps = $angle / 90;
  29539. $_w = $tpl['w'];
  29540. $_h = $tpl['h'];
  29541. $tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
  29542. $tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
  29543. if ($steps % 2 != 0) {
  29544. $x = $y = ($steps == 1 || $steps == -3) ? $tpl['h'] : $tpl['w'];
  29545. } else {
  29546. $x = $tpl['w'];
  29547. $y = $tpl['h'];
  29548. }
  29549. $cx=($x/2+$tpl['box']['x'])*_MPDFK;
  29550. $cy=($y/2+$tpl['box']['y'])*_MPDFK;
  29551. $angle*=-1;
  29552. $angle*=M_PI/180;
  29553. $c=cos($angle);
  29554. $s=sin($angle);
  29555. $tpl['box']['w'] = $tpl['w'] ;
  29556. $tpl['box']['h'] = $tpl['h'] ;
  29557. $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']);
  29558. }
  29559. return $this->tpl;
  29560. }
  29561. function UseTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
  29562. if (!isset($this->tpls[$tplidx]))
  29563. $this->Error("Template does not exist!");
  29564. if($this->state==0) { $this->AddPage(); }
  29565. $out = 'q 0 J 1 w 0 j 0 G'."\n"; // reset standard values
  29566. $x = $this->tpls[$tplidx]['x'];
  29567. $y = $this->tpls[$tplidx]['y'];
  29568. $w = $this->tpls[$tplidx]['w'];
  29569. $h = $this->tpls[$tplidx]['h'];
  29570. if ($_x == null) { $_x = $x; }
  29571. if ($_y == null) { $_y = $y; }
  29572. if ($_x === -1) { $_x = $this->x; }
  29573. if ($_y === -1) { $_y = $this->y; }
  29574. $wh = $this->getTemplateSize($tplidx,$_w,$_h);
  29575. $_w = $wh['w'];
  29576. $_h = $wh['h'];
  29577. $out .= sprintf("q %.4F 0 0 %.4F %.2F %.2F cm", ($_w/$this->tpls[$tplidx]['box']['w']), ($_h/$this->tpls[$tplidx]['box']['h']), $_x*_MPDFK, ($this->h-($_y+$_h))*_MPDFK)."\n";
  29578. $out .= $this->tplprefix.$tplidx." Do Q\n";
  29579. $s = array("w" => $_w, "h" => $_h);
  29580. $out .= "Q\n";
  29581. $this->pages[$this->page] = $out . $this->pages[$this->page];
  29582. return $s;
  29583. }
  29584. function SetPageTemplate($tplidx='') {
  29585. if (!isset($this->tpls[$tplidx])) {
  29586. $this->pageTemplate = '';
  29587. return false;
  29588. }
  29589. $this->pageTemplate = $tplidx;
  29590. }
  29591. function SetDocTemplate($file='', $continue=0) {
  29592. $this->docTemplate = $file;
  29593. $this->docTemplateContinue = $continue;
  29594. }
  29595. /*-- END IMPORTS --*/
  29596. /* ---------------------------------------------- */
  29597. /* ---------------------------------------------- */
  29598. /* ---------------------------------------------- */
  29599. /* ---------------------------------------------- */
  29600. /* ---------------------------------------------- */
  29601. // JAVASCRIPT
  29602. function _set_object_javascript ($string) {
  29603. $this->_newobj();
  29604. $this->_out('<<');
  29605. $this->_out('/S /JavaScript ');
  29606. $this->_out('/JS '.$this->_textstring($string));
  29607. $this->_out('>>');
  29608. $this->_out('endobj');
  29609. }
  29610. function SetJS($script) {
  29611. $this->js = $script;
  29612. }
  29613. }//end of Class
  29614. ?>