/application/helpers/mpdf/mpdf.php

https://bitbucket.org/Korrigan33/fusioninvoice · PHP · 33146 lines · 29393 code · 1961 blank · 1792 comment · 7221 complexity · 6c9dc135cb0588ed57876750254b172b MD5 · raw file

  1. <?php
  2. // ******************************************************************************
  3. // Software: mPDF, Unicode-HTML Free PDF generator *
  4. // Version: 5.6 based on *
  5. // FPDF by Olivier PLATHEY *
  6. // HTML2FPDF by Renato Coelho *
  7. // Date: 2013-01-20 *
  8. // Author: Ian Back <ianb@bpm1.com> *
  9. // License: GPL *
  10. // *
  11. // Changes: See changelog.txt *
  12. // ******************************************************************************
  13. define('mPDF_VERSION','5.6');
  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 $margBuffer; // mPDF 5.4.04
  57. var $splitTableBorderWidth; // mPDF 5.4.16
  58. var $cacheTables;
  59. var $bookmarkStyles;
  60. var $useActiveForms;
  61. var $repackageTTF;
  62. var $allowCJKorphans;
  63. var $allowCJKoverflow;
  64. var $useKerning;
  65. var $restrictColorSpace;
  66. var $bleedMargin;
  67. var $crossMarkMargin;
  68. var $cropMarkMargin;
  69. var $cropMarkLength;
  70. var $nonPrintMargin;
  71. var $PDFX;
  72. var $PDFXauto;
  73. var $PDFA;
  74. var $PDFAauto;
  75. var $ICCProfile;
  76. var $printers_info;
  77. var $iterationCounter;
  78. var $smCapsScale;
  79. var $smCapsStretch;
  80. var $backupSubsFont;
  81. var $backupSIPFont;
  82. var $debugfonts;
  83. var $useAdobeCJK;
  84. var $percentSubset;
  85. var $maxTTFFilesize;
  86. var $BMPonly;
  87. var $tableMinSizePriority;
  88. var $dpi;
  89. var $watermarkImgAlphaBlend;
  90. var $watermarkImgBehind;
  91. var $justifyB4br;
  92. var $packTableData;
  93. var $pgsIns;
  94. var $simpleTables;
  95. var $enableImports;
  96. var $debug;
  97. var $showStats;
  98. var $setAutoTopMargin;
  99. var $setAutoBottomMargin;
  100. var $autoMarginPadding;
  101. var $collapseBlockMargins;
  102. var $falseBoldWeight;
  103. var $normalLineheight;
  104. var $progressBar;
  105. var $incrementFPR1;
  106. var $incrementFPR2;
  107. var $incrementFPR3;
  108. var $incrementFPR4;
  109. var $hyphenate;
  110. var $hyphenateTables;
  111. var $SHYlang;
  112. var $SHYleftmin;
  113. var $SHYrightmin;
  114. var $SHYcharmin;
  115. var $SHYcharmax;
  116. var $SHYlanguages;
  117. // PageNumber Conditional Text
  118. var $pagenumPrefix;
  119. var $pagenumSuffix;
  120. var $nbpgPrefix;
  121. var $nbpgSuffix;
  122. var $showImageErrors;
  123. var $allow_output_buffering;
  124. var $autoPadding;
  125. var $useGraphs;
  126. var $autoFontGroupSize;
  127. var $tabSpaces;
  128. var $useLang;
  129. var $restoreBlockPagebreaks;
  130. var $watermarkTextAlpha;
  131. var $watermarkImageAlpha;
  132. var $watermark_size;
  133. var $watermark_pos;
  134. var $annotSize;
  135. var $annotMargin;
  136. var $annotOpacity;
  137. var $title2annots;
  138. var $keepColumns;
  139. var $keep_table_proportions;
  140. var $ignore_table_widths;
  141. var $ignore_table_percents;
  142. var $list_align_style;
  143. var $list_number_suffix;
  144. var $useSubstitutions;
  145. var $CSSselectMedia;
  146. var $forcePortraitHeaders;
  147. var $forcePortraitMargins;
  148. var $displayDefaultOrientation;
  149. var $ignore_invalid_utf8;
  150. var $allowedCSStags;
  151. var $onlyCoreFonts;
  152. var $allow_charset_conversion;
  153. var $jSWord;
  154. var $jSmaxChar;
  155. var $jSmaxCharLast;
  156. var $jSmaxWordLast;
  157. var $orphansAllowed;
  158. var $max_colH_correction;
  159. var $table_error_report;
  160. var $table_error_report_param;
  161. var $biDirectional;
  162. var $text_input_as_HTML;
  163. var $anchor2Bookmark;
  164. var $list_indent_first_level;
  165. var $shrink_tables_to_fit;
  166. var $allow_html_optional_endtags;
  167. var $img_dpi;
  168. var $defaultheaderfontsize;
  169. var $defaultheaderfontstyle;
  170. var $defaultheaderline;
  171. var $defaultfooterfontsize;
  172. var $defaultfooterfontstyle;
  173. var $defaultfooterline;
  174. var $header_line_spacing;
  175. var $footer_line_spacing;
  176. var $pregUHCchars;
  177. var $pregSJISchars;
  178. var $pregCJKchars;
  179. var $pregASCIIchars1;
  180. var $pregASCIIchars2;
  181. var $pregASCIIchars3;
  182. var $pregVIETchars;
  183. var $pregVIETPluschars;
  184. var $pregRTLchars;
  185. var $pregHEBchars;
  186. var $pregARABICchars;
  187. var $pregNonARABICchars;
  188. // INDIC
  189. var $pregHIchars;
  190. var $pregBNchars;
  191. var $pregPAchars;
  192. var $pregGUchars;
  193. var $pregORchars;
  194. var $pregTAchars;
  195. var $pregTEchars;
  196. var $pregKNchars;
  197. var $pregMLchars;
  198. var $pregSHchars;
  199. var $pregINDextra;
  200. var $mirrorMargins;
  201. var $default_lineheight_correction;
  202. var $watermarkText;
  203. var $watermarkImage;
  204. var $showWatermarkText;
  205. var $showWatermarkImage;
  206. var $fontsizes;
  207. // Aliases for backward compatability
  208. var $UnvalidatedText; // alias = $watermarkText
  209. var $TopicIsUnvalidated; // alias = $showWatermarkText
  210. var $useOddEven; // alias = $mirrorMargins
  211. var $useSubstitutionsMB; // alias = $useSubstitutions
  212. //////////////////////
  213. // CLASS OBJECTS
  214. //////////////////////
  215. var $grad;
  216. var $bmp;
  217. var $wmf;
  218. var $tocontents;
  219. var $form;
  220. var $directw;
  221. //////////////////////
  222. // INTERNAL VARIABLES
  223. //////////////////////
  224. var $inMeter; // mPDF 5.5.09
  225. var $CJKleading;
  226. var $CJKfollowing;
  227. var $CJKoverflow;
  228. var $textshadow;
  229. var $colsums;
  230. var $spanborder;
  231. var $spanborddet;
  232. var $visibility;
  233. var $useRC128encryption;
  234. var $uniqid;
  235. var $kerning;
  236. var $fixedlSpacing;
  237. var $minwSpacing;
  238. var $lSpacingCSS;
  239. var $wSpacingCSS;
  240. var $listDir;
  241. var $spotColorIDs;
  242. var $SVGcolors;
  243. var $spotColors;
  244. var $defTextColor;
  245. var $defDrawColor;
  246. var $defFillColor;
  247. var $tableBackgrounds;
  248. var $inlineDisplayOff;
  249. var $kt_y00;
  250. var $kt_p00;
  251. var $upperCase;
  252. var $checkSIP;
  253. var $checkSMP;
  254. var $checkCJK;
  255. var $tableCJK;
  256. var $watermarkImgAlpha;
  257. var $PDFAXwarnings;
  258. var $MetadataRoot;
  259. var $OutputIntentRoot;
  260. var $InfoRoot;
  261. var $current_filename;
  262. var $parsers;
  263. var $current_parser;
  264. var $_obj_stack;
  265. var $_don_obj_stack;
  266. var $_current_obj_id;
  267. var $tpls;
  268. var $tpl;
  269. var $tplprefix;
  270. var $_res;
  271. var $pdf_version;
  272. var $noImageFile;
  273. var $lastblockbottommargin;
  274. var $baselineC;
  275. var $subPos;
  276. var $subArrMB;
  277. var $ReqFontStyle;
  278. var $tableClipPath ;
  279. var $forceExactLineheight;
  280. var $listOcc;
  281. var $fullImageHeight;
  282. var $inFixedPosBlock; // Internal flag for position:fixed block
  283. var $fixedPosBlock; // Buffer string for position:fixed block
  284. var $fixedPosBlockDepth;
  285. var $fixedPosBlockBBox;
  286. var $fixedPosBlockSave;
  287. var $maxPosL;
  288. var $maxPosR;
  289. var $loaded;
  290. var $extraFontSubsets;
  291. var $docTemplateStart; // Internal flag for page (page no. -1) that docTemplate starts on
  292. var $time0;
  293. // Classes
  294. var $indic;
  295. var $barcode;
  296. var $SHYpatterns;
  297. var $loadedSHYpatterns;
  298. var $loadedSHYdictionary;
  299. var $SHYdictionary;
  300. var $SHYdictionaryWords;
  301. var $spanbgcolorarray;
  302. var $default_font;
  303. var $list_lineheight;
  304. var $headerbuffer;
  305. var $lastblocklevelchange;
  306. var $nestedtablejustfinished;
  307. var $linebreakjustfinished;
  308. var $cell_border_dominance_L;
  309. var $cell_border_dominance_R;
  310. var $cell_border_dominance_T;
  311. var $cell_border_dominance_B;
  312. var $tbCSSlvl;
  313. var $listCSSlvl;
  314. var $table_keep_together;
  315. var $plainCell_properties;
  316. var $inherit_lineheight;
  317. var $listitemtype;
  318. var $shrin_k1;
  319. var $outerfilled;
  320. var $blockContext;
  321. var $floatDivs;
  322. var $tablecascadeCSS;
  323. var $listcascadeCSS;
  324. var $patterns;
  325. var $pageBackgrounds;
  326. var $bodyBackgroundGradient;
  327. var $bodyBackgroundImage;
  328. var $bodyBackgroundColor;
  329. var $writingHTMLheader; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  330. var $writingHTMLfooter;
  331. var $autoFontGroups;
  332. var $angle;
  333. var $gradients;
  334. var $kwt_Reference;
  335. var $kwt_BMoutlines;
  336. var $kwt_toc;
  337. var $tbrot_Reference;
  338. var $tbrot_BMoutlines;
  339. var $tbrot_toc;
  340. var $col_Reference;
  341. var $col_BMoutlines;
  342. var $col_toc;
  343. var $currentGraphId;
  344. var $graphs;
  345. var $floatbuffer;
  346. var $floatmargins;
  347. var $bullet;
  348. var $bulletarray;
  349. var $rtlAsArabicFarsi; // DEPRACATED
  350. var $currentLang;
  351. var $default_lang;
  352. var $default_available_fonts;
  353. var $pageTemplate;
  354. var $docTemplate;
  355. var $docTemplateContinue;
  356. var $arabGlyphs;
  357. var $arabHex;
  358. var $persianGlyphs;
  359. var $persianHex;
  360. var $arabVowels;
  361. var $arabPrevLink;
  362. var $arabNextLink;
  363. var $formobjects; // array of Form Objects for WMF
  364. var $InlineProperties;
  365. var $InlineAnnots;
  366. var $ktAnnots;
  367. var $tbrot_Annots;
  368. var $kwt_Annots;
  369. var $columnAnnots;
  370. var $columnForms;
  371. var $PageAnnots;
  372. var $pageDim; // Keep track of page wxh for orientation changes - set in _beginpage, used in _putannots
  373. var $breakpoints;
  374. var $tableLevel;
  375. var $tbctr;
  376. var $innermostTableLevel;
  377. var $saveTableCounter;
  378. var $cellBorderBuffer;
  379. var $saveHTMLFooter_height;
  380. var $saveHTMLFooterE_height;
  381. var $firstPageBoxHeader;
  382. var $firstPageBoxHeaderEven;
  383. var $firstPageBoxFooter;
  384. var $firstPageBoxFooterEven;
  385. var $page_box;
  386. var $show_marks; // crop or cross marks
  387. var $basepathIsLocal;
  388. var $use_kwt;
  389. var $kwt;
  390. var $kwt_height;
  391. var $kwt_y0;
  392. var $kwt_x0;
  393. var $kwt_buffer;
  394. var $kwt_Links;
  395. var $kwt_moved;
  396. var $kwt_saved;
  397. var $PageNumSubstitutions;
  398. var $table_borders_separate;
  399. var $base_table_properties;
  400. var $borderstyles;
  401. var $listjustfinished;
  402. var $blockjustfinished;
  403. var $orig_bMargin;
  404. var $orig_tMargin;
  405. var $orig_lMargin;
  406. var $orig_rMargin;
  407. var $orig_hMargin;
  408. var $orig_fMargin;
  409. var $pageheaders;
  410. var $pagefooters;
  411. var $pageHTMLheaders;
  412. var $pageHTMLfooters;
  413. var $saveHTMLHeader;
  414. var $saveHTMLFooter;
  415. var $HTMLheaderPageLinks;
  416. var $HTMLheaderPageAnnots;
  417. var $HTMLheaderPageForms;
  418. // See config_fonts.php for these next 5 values
  419. var $available_unifonts;
  420. var $sans_fonts;
  421. var $serif_fonts;
  422. var $mono_fonts;
  423. var $defaultSubsFont;
  424. // List of ALL available CJK fonts (incl. styles) (Adobe add-ons) hw removed
  425. var $available_CJK_fonts;
  426. var $cascadeCSS;
  427. var $HTMLHeader;
  428. var $HTMLFooter;
  429. var $HTMLHeaderE;
  430. var $HTMLFooterE;
  431. var $bufferoutput;
  432. var $showdefaultpagenos; // DEPRACATED -left for backward compatability
  433. // CJK fonts
  434. var $Big5_widths;
  435. var $GB_widths;
  436. var $SJIS_widths;
  437. var $UHC_widths;
  438. // SetProtection
  439. var $encrypted; //whether document is protected
  440. var $Uvalue; //U entry in pdf document
  441. var $Ovalue; //O entry in pdf document
  442. var $Pvalue; //P entry in pdf document
  443. var $enc_obj_id; //encryption object id
  444. var $last_rc4_key; //last RC4 key encrypted (cached for optimisation)
  445. var $last_rc4_key_c; //last RC4 computed key
  446. var $encryption_key;
  447. var $padding; //used for encryption
  448. // Bookmark
  449. var $BMoutlines;
  450. var $OutlineRoot;
  451. // INDEX
  452. var $ColActive;
  453. var $Reference;
  454. var $CurrCol;
  455. var $NbCol;
  456. var $y0; //Top ordinate of columns
  457. var $ColL;
  458. var $ColWidth;
  459. var $ColGap;
  460. // COLUMNS
  461. var $ColR;
  462. var $ChangeColumn;
  463. var $columnbuffer;
  464. var $ColDetails;
  465. var $columnLinks;
  466. var $colvAlign;
  467. // Substitutions
  468. var $substitute; // Array of substitution strings e.g. <ttz>112</ttz>
  469. var $entsearch; // Array of HTML entities (>ASCII 127) to substitute
  470. var $entsubstitute; // Array of substitution decimal unicode for the Hi entities
  471. // Default values if no style sheet offered (cf. http://www.w3.org/TR/CSS21/sample.html)
  472. var $defaultCSS;
  473. var $linemaxfontsize;
  474. var $lineheight_correction;
  475. var $lastoptionaltag; // Save current block item which HTML specifies optionsl endtag
  476. var $pageoutput;
  477. var $charset_in;
  478. var $blk;
  479. var $blklvl;
  480. var $ColumnAdjust;
  481. var $ws; // Word spacing
  482. var $HREF;
  483. var $pgwidth;
  484. var $fontlist;
  485. var $oldx;
  486. var $oldy;
  487. var $B;
  488. var $U; //underlining flag
  489. var $S; // SmallCaps flag
  490. var $I;
  491. var $tdbegin;
  492. var $table;
  493. var $cell;
  494. var $col;
  495. var $row;
  496. var $divbegin;
  497. var $divalign;
  498. var $divwidth;
  499. var $divheight;
  500. var $divrevert;
  501. var $spanbgcolor;
  502. var $spanlvl;
  503. var $listlvl;
  504. var $listnum;
  505. var $listtype;
  506. var $listoccur;
  507. var $listlist;
  508. var $listitem;
  509. var $pjustfinished;
  510. var $ignorefollowingspaces;
  511. var $SUP;
  512. var $SUB;
  513. var $SMALL;
  514. var $BIG;
  515. var $toupper;
  516. var $tolower;
  517. var $capitalize;
  518. var $dash_on;
  519. var $dotted_on;
  520. var $strike;
  521. var $CSS;
  522. var $textbuffer;
  523. var $currentfontstyle;
  524. var $currentfontfamily;
  525. var $currentfontsize;
  526. var $colorarray;
  527. var $bgcolorarray;
  528. var $internallink;
  529. var $enabledtags;
  530. var $lineheight;
  531. var $basepath;
  532. var $outlineparam;
  533. var $outline_on;
  534. var $specialcontent;
  535. var $selectoption;
  536. var $objectbuffer;
  537. // Table Rotation
  538. var $table_rotate;
  539. var $tbrot_maxw;
  540. var $tbrot_maxh;
  541. var $tablebuffer;
  542. var $tbrot_align;
  543. var $tbrot_Links;
  544. var $divbuffer; // Buffer used when keeping DIV on one page
  545. var $keep_block_together; // Keep a Block from page-break-inside: avoid
  546. var $ktLinks; // Keep-together Block links array
  547. var $ktBlock; // Keep-together Block array
  548. var $ktForms;
  549. var $ktReference;
  550. var $ktBMoutlines;
  551. var $_kttoc;
  552. var $tbrot_y0;
  553. var $tbrot_x0;
  554. var $tbrot_w;
  555. var $tbrot_h;
  556. var $mb_enc;
  557. var $directionality;
  558. var $extgstates; // Used for alpha channel - Transparency (Watermark)
  559. var $mgl;
  560. var $mgt;
  561. var $mgr;
  562. var $mgb;
  563. var $tts;
  564. var $ttz;
  565. var $tta;
  566. var $headerDetails;
  567. var $footerDetails;
  568. // Best to alter the below variables using default stylesheet above
  569. var $page_break_after_avoid;
  570. var $margin_bottom_collapse;
  571. var $list_indent;
  572. var $list_align;
  573. var $list_margin_bottom;
  574. var $default_font_size; // in pts
  575. var $original_default_font_size; // used to save default sizes when using table default
  576. var $original_default_font;
  577. var $watermark_font;
  578. var $defaultAlign;
  579. // TABLE
  580. var $defaultTableAlign;
  581. var $tablethead;
  582. var $thead_font_weight;
  583. var $thead_font_style;
  584. var $thead_font_smCaps;
  585. var $thead_valign_default;
  586. var $thead_textalign_default;
  587. var $tabletfoot;
  588. var $tfoot_font_weight;
  589. var $tfoot_font_style;
  590. var $tfoot_font_smCaps;
  591. var $tfoot_valign_default;
  592. var $tfoot_textalign_default;
  593. var $trow_text_rotate;
  594. var $cellPaddingL;
  595. var $cellPaddingR;
  596. var $cellPaddingT;
  597. var $cellPaddingB;
  598. var $table_lineheight;
  599. var $table_border_attr_set;
  600. var $table_border_css_set;
  601. var $shrin_k; // factor with which to shrink tables - used internally - do not change
  602. var $shrink_this_table_to_fit; // 0 or false to disable; value (if set) gives maximum factor to reduce fontsize
  603. var $MarginCorrection; // corrects for OddEven Margins
  604. var $margin_footer;
  605. var $margin_header;
  606. var $tabletheadjustfinished;
  607. var $usingCoreFont;
  608. var $charspacing;
  609. //Private properties FROM FPDF
  610. var $DisplayPreferences;
  611. var $outlines;
  612. var $flowingBlockAttr;
  613. var $page; //current page number
  614. var $n; //current object number
  615. var $offsets; //array of object offsets
  616. var $buffer; //buffer holding in-memory PDF
  617. var $pages; //array containing pages
  618. var $state; //current document state
  619. var $compress; //compression flag
  620. var $DefOrientation; //default orientation
  621. var $CurOrientation; //current orientation
  622. var $OrientationChanges; //array indicating orientation changes
  623. var $k; //scale factor (number of points in user unit)
  624. var $fwPt;
  625. var $fhPt; //dimensions of page format in points
  626. var $fw;
  627. var $fh; //dimensions of page format in user unit
  628. var $wPt;
  629. var $hPt; //current dimensions of page in points
  630. var $w;
  631. var $h; //current dimensions of page in user unit
  632. var $lMargin; //left margin
  633. var $tMargin; //top margin
  634. var $rMargin; //right margin
  635. var $bMargin; //page break margin
  636. var $cMarginL; //cell margin Left
  637. var $cMarginR; //cell margin Right
  638. var $cMarginT; //cell margin Left
  639. var $cMarginB; //cell margin Right
  640. var $DeflMargin; //Default left margin
  641. var $DefrMargin; //Default right margin
  642. var $x;
  643. var $y; //current position in user unit for cell positioning
  644. var $lasth; //height of last cell printed
  645. var $LineWidth; //line width in user unit
  646. var $CoreFonts; //array of standard font names
  647. var $fonts; //array of used fonts
  648. var $FontFiles; //array of font files
  649. var $images; //array of used images
  650. var $PageLinks; //array of links in pages
  651. var $links; //array of internal links
  652. var $FontFamily; //current font family
  653. var $FontStyle; //current font style
  654. var $CurrentFont; //current font info
  655. var $FontSizePt; //current font size in points
  656. var $FontSize; //current font size in user unit
  657. var $DrawColor; //commands for drawing color
  658. var $FillColor; //commands for filling color
  659. var $TextColor; //commands for text color
  660. var $ColorFlag; //indicates whether fill and text colors are different
  661. var $autoPageBreak; //automatic page breaking
  662. var $PageBreakTrigger; //threshold used to trigger page breaks
  663. var $InFooter; //flag set when processing footer
  664. var $InHTMLFooter;
  665. var $processingFooter; //flag set when processing footer - added for columns
  666. var $processingHeader; //flag set when processing header - added for columns
  667. var $ZoomMode; //zoom display mode
  668. var $LayoutMode; //layout display mode
  669. var $title; //title
  670. var $subject; //subject
  671. var $author; //author
  672. var $keywords; //keywords
  673. var $creator; //creator
  674. var $aliasNbPg; //alias for total number of pages
  675. var $aliasNbPgGp; //alias for total number of pages in page group
  676. var $aliasNbPgHex;
  677. var $aliasNbPgGpHex;
  678. var $ispre;
  679. var $outerblocktags;
  680. var $innerblocktags;
  681. // **********************************
  682. // **********************************
  683. // **********************************
  684. // **********************************
  685. // **********************************
  686. // **********************************
  687. // **********************************
  688. // **********************************
  689. // **********************************
  690. 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') {
  691. /*-- BACKGROUNDS --*/
  692. if (!class_exists('grad', false)) { include(_MPDF_PATH.'classes/grad.php'); }
  693. if (empty($this->grad)) { $this->grad = new grad($this); }
  694. /*-- END BACKGROUNDS --*/
  695. /*-- FORMS --*/
  696. if (!class_exists('form', false)) { include(_MPDF_PATH.'classes/form.php'); }
  697. if (empty($this->form)) { $this->form = new form($this); }
  698. /*-- END FORMS --*/
  699. $this->time0 = microtime(true);
  700. //Some checks
  701. $this->_dochecks();
  702. // Set up Aliases for backwards compatability
  703. $this->UnvalidatedText =& $this->watermarkText;
  704. $this->TopicIsUnvalidated =& $this->showWatermarkText;
  705. $this->AliasNbPg =& $this->aliasNbPg;
  706. $this->AliasNbPgGp =& $this->aliasNbPgGp;
  707. $this->BiDirectional =& $this->biDirectional;
  708. $this->Anchor2Bookmark =& $this->anchor2Bookmark;
  709. $this->KeepColumns =& $this->keepColumns;
  710. $this->useOddEven =& $this->mirrorMargins;
  711. $this->useSubstitutionsMB =& $this->useSubstitutions;
  712. $this->visibility='visible';
  713. //Initialization of properties
  714. $this->spotColors=array();
  715. $this->spotColorIDs = array();
  716. $this->tableBackgrounds = array();
  717. $this->kt_y00 = '';
  718. $this->kt_p00 = '';
  719. $this->iterationCounter = false;
  720. $this->BMPonly = array();
  721. $this->page=0;
  722. $this->n=2;
  723. $this->buffer='';
  724. $this->objectbuffer = array();
  725. $this->pages=array();
  726. $this->OrientationChanges=array();
  727. $this->state=0;
  728. $this->fonts=array();
  729. $this->FontFiles=array();
  730. $this->images=array();
  731. $this->links=array();
  732. $this->InFooter=false;
  733. $this->processingFooter=false;
  734. $this->processingHeader=false;
  735. $this->lasth=0;
  736. $this->FontFamily='';
  737. $this->FontStyle='';
  738. $this->FontSizePt=9;
  739. $this->U=false;
  740. // Small Caps
  741. $this->upperCase = array();
  742. $this->S = false;
  743. $this->smCapsScale = 1;
  744. $this->smCapsStretch = 100;
  745. $this->margBuffer = 0; // mPDF 5.4.04
  746. $this->inMeter = false; // mPDF 5.5.09
  747. $this->defTextColor = $this->TextColor = $this->SetTColor($this->ConvertColor(0),true);
  748. $this->defDrawColor = $this->DrawColor = $this->SetDColor($this->ConvertColor(0),true);
  749. $this->defFillColor = $this->FillColor = $this->SetFColor($this->ConvertColor(255),true);
  750. //SVG color names array
  751. //http://www.w3schools.com/css/css_colornames.asp
  752. $this->SVGcolors = array('antiquewhite'=>'#FAEBD7','aqua'=>'#00FFFF','aquamarine'=>'#7FFFD4','beige'=>'#F5F5DC','black'=>'#000000',
  753. 'blue'=>'#0000FF','brown'=>'#A52A2A','cadetblue'=>'#5F9EA0','chocolate'=>'#D2691E','cornflowerblue'=>'#6495ED','crimson'=>'#DC143C',
  754. 'darkblue'=>'#00008B','darkgoldenrod'=>'#B8860B','darkgreen'=>'#006400','darkmagenta'=>'#8B008B','darkorange'=>'#FF8C00',
  755. 'darkred'=>'#8B0000','darkseagreen'=>'#8FBC8F','darkslategray'=>'#2F4F4F','darkviolet'=>'#9400D3','deepskyblue'=>'#00BFFF',
  756. 'dodgerblue'=>'#1E90FF','firebrick'=>'#B22222','forestgreen'=>'#228B22','fuchsia'=>'#FF00FF','gainsboro'=>'#DCDCDC','gold'=>'#FFD700',
  757. 'gray'=>'#808080','green'=>'#008000','greenyellow'=>'#ADFF2F','hotpink'=>'#FF69B4','indigo'=>'#4B0082','khaki'=>'#F0E68C',
  758. 'lavenderblush'=>'#FFF0F5','lemonchiffon'=>'#FFFACD','lightcoral'=>'#F08080','lightgoldenrodyellow'=>'#FAFAD2','lightgreen'=>'#90EE90',
  759. 'lightsalmon'=>'#FFA07A','lightskyblue'=>'#87CEFA','lightslategray'=>'#778899','lightyellow'=>'#FFFFE0','lime'=>'#00FF00','limegreen'=>'#32CD32',
  760. 'magenta'=>'#FF00FF','maroon'=>'#800000','mediumaquamarine'=>'#66CDAA','mediumorchid'=>'#BA55D3','mediumseagreen'=>'#3CB371',
  761. 'mediumspringgreen'=>'#00FA9A','mediumvioletred'=>'#C71585','midnightblue'=>'#191970','mintcream'=>'#F5FFFA','moccasin'=>'#FFE4B5','navy'=>'#000080',
  762. 'olive'=>'#808000','orange'=>'#FFA500','orchid'=>'#DA70D6','palegreen'=>'#98FB98',
  763. 'palevioletred'=>'#D87093','peachpuff'=>'#FFDAB9','pink'=>'#FFC0CB','powderblue'=>'#B0E0E6','purple'=>'#800080',
  764. 'red'=>'#FF0000','royalblue'=>'#4169E1','salmon'=>'#FA8072','seagreen'=>'#2E8B57','sienna'=>'#A0522D','silver'=>'#C0C0C0','skyblue'=>'#87CEEB',
  765. 'slategray'=>'#708090','springgreen'=>'#00FF7F','steelblue'=>'#4682B4','tan'=>'#D2B48C','teal'=>'#008080','thistle'=>'#D8BFD8','turquoise'=>'#40E0D0',
  766. 'violetred'=>'#D02090','white'=>'#FFFFFF','yellow'=>'#FFFF00',
  767. 'aliceblue'=>'#f0f8ff', 'azure'=>'#f0ffff', 'bisque'=>'#ffe4c4', 'blanchedalmond'=>'#ffebcd', 'blueviolet'=>'#8a2be2', 'burlywood'=>'#deb887',
  768. 'chartreuse'=>'#7fff00', 'coral'=>'#ff7f50', 'cornsilk'=>'#fff8dc', 'cyan'=>'#00ffff', 'darkcyan'=>'#008b8b', 'darkgray'=>'#a9a9a9',
  769. 'darkgrey'=>'#a9a9a9', 'darkkhaki'=>'#bdb76b', 'darkolivegreen'=>'#556b2f', 'darkorchid'=>'#9932cc', 'darksalmon'=>'#e9967a',
  770. 'darkslateblue'=>'#483d8b', 'darkslategrey'=>'#2f4f4f', 'darkturquoise'=>'#00ced1', 'deeppink'=>'#ff1493', 'dimgray'=>'#696969',
  771. 'dimgrey'=>'#696969', 'floralwhite'=>'#fffaf0', 'ghostwhite'=>'#f8f8ff', 'goldenrod'=>'#daa520', 'grey'=>'#808080', 'honeydew'=>'#f0fff0',
  772. 'indianred'=>'#cd5c5c', 'ivory'=>'#fffff0', 'lavender'=>'#e6e6fa', 'lawngreen'=>'#7cfc00', 'lightblue'=>'#add8e6', 'lightcyan'=>'#e0ffff',
  773. 'lightgray'=>'#d3d3d3', 'lightgrey'=>'#d3d3d3', 'lightpink'=>'#ffb6c1', 'lightseagreen'=>'#20b2aa', 'lightslategrey'=>'#778899',
  774. 'lightsteelblue'=>'#b0c4de', 'linen'=>'#faf0e6', 'mediumblue'=>'#0000cd', 'mediumpurple'=>'#9370db', 'mediumslateblue'=>'#7b68ee',
  775. 'mediumturquoise'=>'#48d1cc', 'mistyrose'=>'#ffe4e1', 'navajowhite'=>'#ffdead', 'oldlace'=>'#fdf5e6', 'olivedrab'=>'#6b8e23', 'orangered'=>'#ff4500',
  776. 'palegoldenrod'=>'#eee8aa', 'paleturquoise'=>'#afeeee', 'papayawhip'=>'#ffefd5', 'peru'=>'#cd853f', 'plum'=>'#dda0dd', 'rosybrown'=>'#bc8f8f',
  777. 'saddlebrown'=>'#8b4513', 'sandybrown'=>'#f4a460', 'seashell'=>'#fff5ee', 'slateblue'=>'#6a5acd', 'slategrey'=>'#708090', 'snow'=>'#fffafa',
  778. 'tomato'=>'#ff6347', 'violet'=>'#ee82ee', 'wheat'=>'#f5deb3', 'whitesmoke'=>'#f5f5f5', 'yellowgreen'=>'#9acd32');
  779. $this->ColorFlag=false;
  780. $this->extgstates = array();
  781. $this->mb_enc='windows-1252';
  782. $this->directionality='ltr';
  783. $this->defaultAlign = 'L';
  784. $this->defaultTableAlign = 'L';
  785. $this->fixedPosBlockSave = array();
  786. $this->extraFontSubsets = 0;
  787. $this->SHYpatterns = array();
  788. $this->loadedSHYdictionary = false;
  789. $this->SHYdictionary = array();
  790. $this->SHYdictionaryWords = array();
  791. $this->blockContext = 1;
  792. $this->floatDivs = array();
  793. $this->DisplayPreferences='';
  794. $this->tablecascadeCSS = array();
  795. $this->listcascadeCSS = array();
  796. $this->patterns = array(); // Tiling patterns used for backgrounds
  797. $this->pageBackgrounds = array();
  798. $this->writingHTMLheader = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  799. $this->writingHTMLfooter = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  800. $this->gradients = array();
  801. $this->kwt_Reference = array();
  802. $this->kwt_BMoutlines = array();
  803. $this->kwt_toc = array();
  804. $this->tbrot_Reference = array();
  805. $this->tbrot_BMoutlines = array();
  806. $this->tbrot_toc = array();
  807. $this->col_Reference = array();
  808. $this->col_BMoutlines = array();
  809. $this->col_toc = array();
  810. $this->graphs = array();
  811. $this->pgsIns = array();
  812. $this->PDFAXwarnings = array();
  813. $this->inlineDisplayOff = false;
  814. $this->kerning = false;
  815. $this->lSpacingCSS = '';
  816. $this->wSpacingCSS = '';
  817. $this->fixedlSpacing = false;
  818. $this->minwSpacing = 0;
  819. $this->baselineC = 0.35; // Baseline for text
  820. $this->noImageFile = str_replace("\\","/",dirname(__FILE__)) . '/includes/no_image.jpg';
  821. $this->subPos = 0;
  822. $this->forceExactLineheight = false;
  823. $this->listOcc = 0;
  824. $this->normalLineheight = 1.3;
  825. // These are intended as configuration variables, and should be set in config.php - which will override these values;
  826. // set here as failsafe as will cause an error if not defined
  827. $this->incrementFPR1 = 10;
  828. $this->incrementFPR2 = 10;
  829. $this->incrementFPR3 = 10;
  830. $this->incrementFPR4 = 10;
  831. $this->fullImageHeight = false;
  832. $this->floatbuffer = array();
  833. $this->floatmargins = array();
  834. $this->autoFontGroups = 0;
  835. $this->formobjects=array(); // array of Form Objects for WMF
  836. $this->InlineProperties=array();
  837. $this->InlineAnnots=array();
  838. $this->ktAnnots=array();
  839. $this->tbrot_Annots=array();
  840. $this->kwt_Annots=array();
  841. $this->columnAnnots=array();
  842. $this->pageDim=array();
  843. $this->breakpoints = array(); // used in columnbuffer
  844. $this->tableLevel=0;
  845. $this->tbctr=array(); // counter for nested tables at each level
  846. $this->page_box = array();
  847. $this->show_marks = ''; // crop or cross marks
  848. $this->kwt = false;
  849. $this->kwt_height = 0;
  850. $this->kwt_y0 = 0;
  851. $this->kwt_x0 = 0;
  852. $this->kwt_buffer = array();
  853. $this->kwt_Links = array();
  854. $this->kwt_moved = false;
  855. $this->kwt_saved = false;
  856. $this->PageNumSubstitutions = array();
  857. $this->base_table_properties=array();
  858. $this->borderstyles = array('inset','groove','outset','ridge','dotted','dashed','solid','double');
  859. $this->tbrot_align = 'C';
  860. $this->pageheaders=array();
  861. $this->pagefooters=array();
  862. $this->pageHTMLheaders=array();
  863. $this->pageHTMLfooters=array();
  864. $this->HTMLheaderPageLinks = array();
  865. $this->HTMLheaderPageAnnots = array();
  866. $this->ktForms = array();
  867. $this->HTMLheaderPageForms = array();
  868. $this->columnForms = array();
  869. $this->tbrotForms = array();
  870. $this->useRC128encryption = false;
  871. $this->uniqid = '';
  872. $this->cascadeCSS = array();
  873. $this->bufferoutput = false;
  874. $this->encrypted=false; //whether document is protected
  875. $this->BMoutlines=array();
  876. $this->ColActive=0; //Flag indicating that columns are on (the index is being processed)
  877. $this->Reference=array(); //Array containing the references
  878. $this->CurrCol=0; //Current column number
  879. $this->ColL = array(0); // Array of Left pos of columns - absolute - needs Margin correction for Odd-Even
  880. $this->ColR = array(0); // Array of Right pos of columns - absolute pos - needs Margin correction for Odd-Even
  881. $this->ChangeColumn = 0;
  882. $this->columnbuffer = array();
  883. $this->ColDetails = array(); // Keeps track of some column details
  884. $this->columnLinks = array(); // Cross references PageLinks
  885. $this->substitute = array(); // Array of substitution strings e.g. <ttz>112</ttz>
  886. $this->entsearch = array(); // Array of HTML entities (>ASCII 127) to substitute
  887. $this->entsubstitute = array(); // Array of substitution decimal unicode for the Hi entities
  888. $this->lastoptionaltag = '';
  889. $this->charset_in = '';
  890. $this->blk = array();
  891. $this->blklvl = 0;
  892. $this->tts = false;
  893. $this->ttz = false;
  894. $this->tta = false;
  895. $this->ispre=false;
  896. $this->checkSIP = false;
  897. $this->checkSMP = false;
  898. $this->checkCJK = false;
  899. $this->tableCJK = false;
  900. $this->headerDetails=array();
  901. $this->footerDetails=array();
  902. $this->page_break_after_avoid = false;
  903. $this->margin_bottom_collapse = false;
  904. $this->tablethead = 0;
  905. $this->tabletfoot = 0;
  906. $this->table_border_attr_set = 0;
  907. $this->table_border_css_set = 0;
  908. $this->shrin_k = 1.0;
  909. $this->shrink_this_table_to_fit = 0;
  910. $this->MarginCorrection = 0;
  911. $this->tabletheadjustfinished = false;
  912. $this->usingCoreFont = false;
  913. $this->charspacing=0;
  914. $this->outlines=array();
  915. $this->autoPageBreak = true;
  916. require(_MPDF_PATH.'config.php'); // config data
  917. $this->_setPageSize($format, $orientation);
  918. $this->DefOrientation=$orientation;
  919. $this->margin_header=$mgh;
  920. $this->margin_footer=$mgf;
  921. $bmargin=$mgb;
  922. $this->DeflMargin = $mgl;
  923. $this->DefrMargin = $mgr;
  924. $this->orig_tMargin = $mgt;
  925. $this->orig_bMargin = $bmargin;
  926. $this->orig_lMargin = $this->DeflMargin;
  927. $this->orig_rMargin = $this->DefrMargin;
  928. $this->orig_hMargin = $this->margin_header;
  929. $this->orig_fMargin = $this->margin_footer;
  930. if ($this->setAutoTopMargin=='pad') { $mgt += $this->margin_header; }
  931. if ($this->setAutoBottomMargin=='pad') { $mgb += $this->margin_footer; }
  932. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$mgt); // sets l r t margin
  933. //Automatic page break
  934. $this->SetAutoPageBreak($this->autoPageBreak,$bmargin); // sets $this->bMargin & PageBreakTrigger
  935. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  936. //Interior cell margin (1 mm) ? not used
  937. $this->cMarginL = 1;
  938. $this->cMarginR = 1;
  939. //Line width (0.2 mm)
  940. $this->LineWidth=.567/_MPDFK;
  941. //To make the function Footer() work - replaces {nb} with page number
  942. $this->AliasNbPages();
  943. $this->AliasNbPageGroups();
  944. $this->aliasNbPgHex = '{nbHEXmarker}';
  945. $this->aliasNbPgGpHex = '{nbpgHEXmarker}';
  946. //Enable all tags as default
  947. $this->DisableTags();
  948. //Full width display mode
  949. $this->SetDisplayMode(100); // fullwidth? 'fullpage'
  950. //Compression
  951. $this->SetCompression(true);
  952. //Set default display preferences
  953. $this->SetDisplayPreferences('');
  954. // Font data
  955. require(_MPDF_PATH.'config_fonts.php');
  956. // Available fonts
  957. $this->available_unifonts = array();
  958. foreach ($this->fontdata AS $f => $fs) {
  959. if (isset($fs['R']) && $fs['R']) { $this->available_unifonts[] = $f; }
  960. if (isset($fs['B']) && $fs['B']) { $this->available_unifonts[] = $f.'B'; }
  961. if (isset($fs['I']) && $fs['I']) { $this->available_unifonts[] = $f.'I'; }
  962. if (isset($fs['BI']) && $fs['BI']) { $this->available_unifonts[] = $f.'BI'; }
  963. }
  964. $this->default_available_fonts = $this->available_unifonts;
  965. $optcore = false;
  966. $onlyCoreFonts = false;
  967. if (preg_match('/([\-+])aCJK/i',$mode, $m)) {
  968. preg_replace('/([\-+])aCJK/i','',$mode);
  969. if ($m[1]=='+') { $this->useAdobeCJK = true; }
  970. else { $this->useAdobeCJK = false; }
  971. }
  972. if (strlen($mode)==1) {
  973. if ($mode=='s') { $this->percentSubset = 100; $mode = ''; }
  974. else if ($mode=='c') { $onlyCoreFonts = true; $mode = ''; }
  975. }
  976. else if (substr($mode,-2)=='-s') {
  977. $this->percentSubset = 100;
  978. $mode = substr($mode,0,strlen($mode)-2);
  979. }
  980. else if (substr($mode,-2)=='-c') {
  981. $onlyCoreFonts = true;
  982. $mode = substr($mode,0,strlen($mode)-2);
  983. }
  984. else if (substr($mode,-2)=='-x') {
  985. $optcore = true;
  986. $mode = substr($mode,0,strlen($mode)-2);
  987. }
  988. // Autodetect if mode is a language_country string (en-GB or en_GB or en)
  989. if ((strlen($mode) == 5 && $mode != 'UTF-8') || strlen($mode) == 2) {
  990. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($mode, $this->useAdobeCJK);
  991. if ($coreSuitable && $optcore) { $onlyCoreFonts = true; }
  992. if ($mpdf_pdf_unifonts) {
  993. $this->RestrictUnicodeFonts($mpdf_pdf_unifonts);
  994. $this->default_available_fonts = $mpdf_pdf_unifonts;
  995. }
  996. $this->currentLang = $mode;
  997. $this->default_lang = $mode;
  998. }
  999. $this->onlyCoreFonts = $onlyCoreFonts;
  1000. if ($this->onlyCoreFonts) {
  1001. $this->setMBencoding('windows-1252'); // sets $this->mb_enc
  1002. }
  1003. else {
  1004. $this->setMBencoding('UTF-8'); // sets $this->mb_enc
  1005. }
  1006. @mb_regex_encoding('UTF-8'); // required only for mb_ereg... and mb_split functions
  1007. // Adobe CJK fonts
  1008. $this->available_CJK_fonts = array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  1009. 'gbBI','big5BI','sjisBI','uhcBI');
  1010. //Standard fonts
  1011. $this->CoreFonts=array('ccourier'=>'Courier','ccourierB'=>'Courier-Bold','ccourierI'=>'Courier-Oblique','ccourierBI'=>'Courier-BoldOblique',
  1012. 'chelvetica'=>'Helvetica','chelveticaB'=>'Helvetica-Bold','chelveticaI'=>'Helvetica-Oblique','chelveticaBI'=>'Helvetica-BoldOblique',
  1013. 'ctimes'=>'Times-Roman','ctimesB'=>'Times-Bold','ctimesI'=>'Times-Italic','ctimesBI'=>'Times-BoldItalic',
  1014. 'csymbol'=>'Symbol','czapfdingbats'=>'ZapfDingbats');
  1015. $this->fontlist=array("ctimes","ccourier","chelvetica","csymbol","czapfdingbats");
  1016. // Substitutions
  1017. $this->setHiEntitySubstitutions();
  1018. if ($this->onlyCoreFonts) {
  1019. $this->useSubstitutions = true;
  1020. $this->SetSubstitutions();
  1021. }
  1022. else { $this->useSubstitutions = false; }
  1023. /*-- HTML-CSS --*/
  1024. if (file_exists(_MPDF_PATH.'mpdf.css')) {
  1025. $css = file_get_contents(_MPDF_PATH.'mpdf.css');
  1026. $css2 = $this->ReadDefaultCSS($css);
  1027. $this->defaultCSS = $this->array_merge_recursive_unique($this->defaultCSS,$css2);
  1028. }
  1029. /*-- END HTML-CSS --*/
  1030. if ($default_font=='') {
  1031. if ($this->onlyCoreFonts) {
  1032. if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->mono_fonts)) { $default_font = 'ccourier'; }
  1033. else if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->sans_fonts)) { $default_font = 'chelvetica'; }
  1034. else { $default_font = 'ctimes'; }
  1035. }
  1036. else { $default_font = $this->defaultCSS['BODY']['FONT-FAMILY']; }
  1037. }
  1038. if (!$default_font_size) {
  1039. $mmsize = $this->ConvertSize($this->defaultCSS['BODY']['FONT-SIZE']);
  1040. $default_font_size = $mmsize*(_MPDFK);
  1041. }
  1042. if ($default_font) { $this->SetDefaultFont($default_font); }
  1043. if ($default_font_size) { $this->SetDefaultFontSize($default_font_size); }
  1044. $this->SetLineHeight(); // lineheight is in mm
  1045. $this->SetFColor($this->ConvertColor(255));
  1046. $this->HREF='';
  1047. $this->oldy=-1;
  1048. $this->B=0;
  1049. $this->U=false;
  1050. $this->S=false;
  1051. $this->I=0;
  1052. $this->listlvl=0;
  1053. $this->listnum=0;
  1054. $this->listtype='';
  1055. $this->listoccur=array();
  1056. $this->listlist=array();
  1057. $this->listitem=array();
  1058. $this->tdbegin=false;
  1059. $this->table=array();
  1060. $this->cell=array();
  1061. $this->col=-1;
  1062. $this->row=-1;
  1063. $this->cellBorderBuffer = array();
  1064. $this->divbegin=false;
  1065. $this->divalign='';
  1066. $this->divwidth=0;
  1067. $this->divheight=0;
  1068. $this->spanbgcolor=false;
  1069. $this->divrevert=false;
  1070. $this->spanborder=false;
  1071. $this->spanborddet=array();
  1072. $this->blockjustfinished=false;
  1073. $this->listjustfinished=false;
  1074. $this->ignorefollowingspaces = true; //in order to eliminate exceeding left-side spaces
  1075. $this->toupper=false;
  1076. $this->tolower=false;
  1077. $this->capitalize=false;
  1078. $this->dash_on=false;
  1079. $this->dotted_on=false;
  1080. $this->SUP=false;
  1081. $this->SUB=false;
  1082. $this->strike=false;
  1083. $this->textshadow='';
  1084. $this->currentfontfamily='';
  1085. $this->currentfontsize='';
  1086. $this->currentfontstyle='';
  1087. $this->colorarray=array();
  1088. $this->spanbgcolorarray=array();
  1089. $this->textbuffer=array();
  1090. $this->CSS=array();
  1091. $this->internallink=array();
  1092. $this->basepath = "";
  1093. $this->SetBasePath('');
  1094. $this->outlineparam = array();
  1095. $this->outline_on = false;
  1096. $this->specialcontent = '';
  1097. $this->selectoption = array();
  1098. /*-- IMPORTS --*/
  1099. $this->tpls = array();
  1100. $this->tpl = 0;
  1101. $this->tplprefix = "/TPL";
  1102. $this->res = array();
  1103. if ($this->enableImports) {
  1104. $this->SetImportUse();
  1105. }
  1106. /*-- END IMPORTS --*/
  1107. if ($this->progressBar) { $this->StartProgressBarOutput($this->progressBar) ; } // *PROGRESS-BAR*
  1108. }
  1109. function _setPageSize($format, &$orientation) {
  1110. //Page format
  1111. if(is_string($format))
  1112. {
  1113. if ($format=='') { $format = 'A4'; }
  1114. $pfo = 'P';
  1115. if(preg_match('/([0-9a-zA-Z]*)-L/i',$format,$m)) { // e.g. A4-L = A4 landscape
  1116. $format=$m[1];
  1117. $pfo='L';
  1118. }
  1119. $format = $this->_getPageFormat($format);
  1120. if (!$format) { $this->Error('Unknown page format: '.$format); }
  1121. else { $orientation = $pfo; }
  1122. $this->fwPt=$format[0];
  1123. $this->fhPt=$format[1];
  1124. }
  1125. else
  1126. {
  1127. if (!$format[0] || !$format[1]) { $this->Error('Invalid page format: '.$format[0].' '.$format[1]); }
  1128. $this->fwPt=$format[0]*_MPDFK;
  1129. $this->fhPt=$format[1]*_MPDFK;
  1130. }
  1131. $this->fw=$this->fwPt/_MPDFK;
  1132. $this->fh=$this->fhPt/_MPDFK;
  1133. //Page orientation
  1134. $orientation=strtolower($orientation);
  1135. if($orientation=='p' or $orientation=='portrait')
  1136. {
  1137. $orientation='P';
  1138. $this->wPt=$this->fwPt;
  1139. $this->hPt=$this->fhPt;
  1140. }
  1141. elseif($orientation=='l' or $orientation=='landscape')
  1142. {
  1143. $orientation='L';
  1144. $this->wPt=$this->fhPt;
  1145. $this->hPt=$this->fwPt;
  1146. }
  1147. else $this->Error('Incorrect orientation: '.$orientation);
  1148. $this->CurOrientation=$orientation;
  1149. $this->w=$this->wPt/_MPDFK;
  1150. $this->h=$this->hPt/_MPDFK;
  1151. }
  1152. function _getPageFormat($format) {
  1153. switch (strtoupper($format)) {
  1154. case '4A0': {$format = array(4767.87,6740.79); break;}
  1155. case '2A0': {$format = array(3370.39,4767.87); break;}
  1156. case 'A0': {$format = array(2383.94,3370.39); break;}
  1157. case 'A1': {$format = array(1683.78,2383.94); break;}
  1158. case 'A2': {$format = array(1190.55,1683.78); break;}
  1159. case 'A3': {$format = array(841.89,1190.55); break;}
  1160. case 'A4': default: {$format = array(595.28,841.89); break;}
  1161. case 'A5': {$format = array(419.53,595.28); break;}
  1162. case 'A6': {$format = array(297.64,419.53); break;}
  1163. case 'A7': {$format = array(209.76,297.64); break;}
  1164. case 'A8': {$format = array(147.40,209.76); break;}
  1165. case 'A9': {$format = array(104.88,147.40); break;}
  1166. case 'A10': {$format = array(73.70,104.88); break;}
  1167. case 'B0': {$format = array(2834.65,4008.19); break;}
  1168. case 'B1': {$format = array(2004.09,2834.65); break;}
  1169. case 'B2': {$format = array(1417.32,2004.09); break;}
  1170. case 'B3': {$format = array(1000.63,1417.32); break;}
  1171. case 'B4': {$format = array(708.66,1000.63); break;}
  1172. case 'B5': {$format = array(498.90,708.66); break;}
  1173. case 'B6': {$format = array(354.33,498.90); break;}
  1174. case 'B7': {$format = array(249.45,354.33); break;}
  1175. case 'B8': {$format = array(175.75,249.45); break;}
  1176. case 'B9': {$format = array(124.72,175.75); break;}
  1177. case 'B10': {$format = array(87.87,124.72); break;}
  1178. case 'C0': {$format = array(2599.37,3676.54); break;}
  1179. case 'C1': {$format = array(1836.85,2599.37); break;}
  1180. case 'C2': {$format = array(1298.27,1836.85); break;}
  1181. case 'C3': {$format = array(918.43,1298.27); break;}
  1182. case 'C4': {$format = array(649.13,918.43); break;}
  1183. case 'C5': {$format = array(459.21,649.13); break;}
  1184. case 'C6': {$format = array(323.15,459.21); break;}
  1185. case 'C7': {$format = array(229.61,323.15); break;}
  1186. case 'C8': {$format = array(161.57,229.61); break;}
  1187. case 'C9': {$format = array(113.39,161.57); break;}
  1188. case 'C10': {$format = array(79.37,113.39); break;}
  1189. case 'RA0': {$format = array(2437.80,3458.27); break;}
  1190. case 'RA1': {$format = array(1729.13,2437.80); break;}
  1191. case 'RA2': {$format = array(1218.90,1729.13); break;}
  1192. case 'RA3': {$format = array(864.57,1218.90); break;}
  1193. case 'RA4': {$format = array(609.45,864.57); break;}
  1194. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  1195. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  1196. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  1197. case 'SRA3': {$format = array(907.09,1275.59); break;}
  1198. case 'SRA4': {$format = array(637.80,907.09); break;}
  1199. case 'LETTER': {$format = array(612.00,792.00); break;}
  1200. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  1201. case 'LEDGER': {$format = array(279.00,432.00); break;}
  1202. case 'TABLOID': {$format = array(279.00,432.00); break;}
  1203. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  1204. case 'FOLIO': {$format = array(612.00,936.00); break;}
  1205. case 'B': {$format=array(362.83,561.26 ); break;} // 'B' format paperback size 128x198mm
  1206. case 'A': {$format=array(314.65,504.57 ); break;} // 'A' format paperback size 111x178mm
  1207. case 'DEMY': {$format=array(382.68,612.28 ); break;} // 'Demy' format paperback size 135x216mm
  1208. case 'ROYAL': {$format=array(433.70,663.30 ); break;} // 'Royal' format paperback size 153x234mm
  1209. default: $format = false;
  1210. }
  1211. return $format;
  1212. }
  1213. /*-- PROGRESS-BAR --*/
  1214. function StartProgressBarOutput($mode=1) {
  1215. // must be relative path, or URI (not a file system path)
  1216. if (!defined('_MPDF_URI')) {
  1217. $this->progressBar = false;
  1218. if ($this->debug) { $this->Error("You need to define _MPDF_URI to use the progress bar!"); }
  1219. else return false;
  1220. }
  1221. $this->progressBar = $mode;
  1222. if ($this->progbar_altHTML) {
  1223. echo $this->progbar_altHTML;
  1224. }
  1225. else {
  1226. echo '<html>
  1227. <head>
  1228. <title>mPDF File Progress</title>
  1229. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1230. <link rel="stylesheet" type="text/css" href="'._MPDF_URI.'progbar.css" />
  1231. </head>
  1232. <body>
  1233. <div class="main">
  1234. <div class="heading">'.$this->progbar_heading.'</div>
  1235. <div class="demo">
  1236. ';
  1237. if ($this->progressBar==2) { echo ' <table width="100%"><tr><td style="width: 50%;">
  1238. <span class="barheading">Writing HTML code</span> <br/>
  1239. <div class="progressBar">
  1240. <div id="element1" class="innerBar">&nbsp;</div>
  1241. </div>
  1242. <span class="code" id="box1"></span>
  1243. </td><td style="width: 50%;">
  1244. <span class="barheading">Autosizing elements</span> <br/>
  1245. <div class="progressBar">
  1246. <div id="element4" class="innerBar">&nbsp;</div>
  1247. </div>
  1248. <span class="code" id="box4"></span>
  1249. <br/><br/>
  1250. <span class="barheading">Writing Tables</span> <br/>
  1251. <div class="progressBar">
  1252. <div id="element7" class="innerBar">&nbsp;</div>
  1253. </div>
  1254. <span class="code" id="box7"></span>
  1255. </td></tr>
  1256. <tr><td><br /><br /></td><td></td></tr>
  1257. <tr><td style="width: 50%;">
  1258. '; }
  1259. echo ' <span class="barheading">Writing PDF file</span> <br/>
  1260. <div class="progressBar">
  1261. <div id="element2" class="innerBar">&nbsp;</div>
  1262. </div>
  1263. <span class="code" id="box2"></span>
  1264. ';
  1265. if ($this->progressBar==2) { echo '
  1266. </td><td style="width: 50%;">
  1267. <span class="barheading">Memory usage</span> <br/>
  1268. <div class="progressBar">
  1269. <div id="element5" class="innerBar">&nbsp;</div>
  1270. </div>
  1271. <span id="box5">0</span> '.ini_get("memory_limit").'<br />
  1272. <br/><br/>
  1273. <span class="barheading">Memory usage (peak)</span> <br/>
  1274. <div class="progressBar">
  1275. <div id="element6" class="innerBar">&nbsp;</div>
  1276. </div>
  1277. <span id="box6">0</span> '.ini_get("memory_limit").'<br />
  1278. </td></tr>
  1279. </table>
  1280. '; }
  1281. echo ' <br/><br/>
  1282. <span id="box3"></span>
  1283. </div>
  1284. ';
  1285. }
  1286. ob_flush();
  1287. flush();
  1288. }
  1289. function UpdateProgressBar($el,$val,$txt='') {
  1290. // $val should be a string - 5 = actual value, +15 = increment
  1291. if ($this->progressBar<2) {
  1292. if ($el>3) { return; }
  1293. else if ($el ==1) { $el = 2; }
  1294. }
  1295. echo '<script type="text/javascript">';
  1296. if ($val) { echo ' document.getElementById(\'element'.$el.'\').style.width=\''.$val.'%\'; '; }
  1297. if ($txt) { echo ' document.getElementById(\'box'.$el.'\').innerHTML=\''.$txt.'\'; '; }
  1298. if ($this->progressBar==2) {
  1299. $m = round(memory_get_usage(true)/1048576);
  1300. $m2 = round(memory_get_peak_usage(true)/1048576);
  1301. $mem = $m * 100 / (ini_get("memory_limit")+0);
  1302. $mem2 = $m2 * 100 / (ini_get("memory_limit")+0);
  1303. echo ' document.getElementById(\'element5\').style.width=\''.$mem.'%\'; ';
  1304. echo ' document.getElementById(\'element6\').style.width=\''.$mem2.'%\'; ';
  1305. echo ' document.getElementById(\'box5\').innerHTML=\''.$m.'MB / \'; ';
  1306. echo ' document.getElementById(\'box6\').innerHTML=\''.$m2.'MB / \'; ';
  1307. }
  1308. echo '</script>'."\n";
  1309. ob_flush();
  1310. flush();
  1311. }
  1312. /*-- END PROGRESS-BAR --*/
  1313. function RestrictUnicodeFonts($res) {
  1314. // $res = array of (Unicode) fonts to restrict to: e.g. norasi|norasiB - language specific
  1315. if (count($res)) { // Leave full list of available fonts if passed blank array
  1316. $this->available_unifonts = $res;
  1317. }
  1318. else { $this->available_unifonts = $this->default_available_fonts; }
  1319. if (count($this->available_unifonts) == 0) { $this->available_unifonts[] = $this->default_available_fonts[0]; }
  1320. $this->available_unifonts = array_values($this->available_unifonts);
  1321. }
  1322. function setMBencoding($enc) {
  1323. if ($this->mb_enc != $enc) {
  1324. $this->mb_enc = $enc;
  1325. mb_internal_encoding($this->mb_enc);
  1326. }
  1327. }
  1328. function SetMargins($left,$right,$top) {
  1329. //Set left, top and right margins
  1330. $this->lMargin=$left;
  1331. $this->rMargin=$right;
  1332. $this->tMargin=$top;
  1333. }
  1334. function ResetMargins() {
  1335. //ReSet left, top margins
  1336. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P' && $this->CurOrientation=='L') {
  1337. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1338. $this->tMargin=$this->orig_rMargin;
  1339. $this->bMargin=$this->orig_lMargin;
  1340. }
  1341. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1342. $this->tMargin=$this->orig_lMargin;
  1343. $this->bMargin=$this->orig_rMargin;
  1344. }
  1345. $this->lMargin=$this->DeflMargin;
  1346. $this->rMargin=$this->DefrMargin;
  1347. $this->MarginCorrection = 0;
  1348. $this->PageBreakTrigger=$this->h-$this->bMargin;
  1349. }
  1350. else if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1351. $this->lMargin=$this->DefrMargin;
  1352. $this->rMargin=$this->DeflMargin;
  1353. $this->MarginCorrection = $this->DefrMargin-$this->DeflMargin;
  1354. }
  1355. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1356. $this->lMargin=$this->DeflMargin;
  1357. $this->rMargin=$this->DefrMargin;
  1358. if ($this->mirrorMargins) { $this->MarginCorrection = $this->DeflMargin-$this->DefrMargin; }
  1359. }
  1360. $this->x=$this->lMargin;
  1361. }
  1362. function SetLeftMargin($margin) {
  1363. //Set left margin
  1364. $this->lMargin=$margin;
  1365. if($this->page>0 and $this->x<$margin) $this->x=$margin;
  1366. }
  1367. function SetTopMargin($margin) {
  1368. //Set top margin
  1369. $this->tMargin=$margin;
  1370. }
  1371. function SetRightMargin($margin) {
  1372. //Set right margin
  1373. $this->rMargin=$margin;
  1374. }
  1375. function SetAutoPageBreak($auto,$margin=0) {
  1376. //Set auto page break mode and triggering margin
  1377. $this->autoPageBreak=$auto;
  1378. $this->bMargin=$margin;
  1379. $this->PageBreakTrigger=$this->h-$margin;
  1380. }
  1381. function SetDisplayMode($zoom,$layout='continuous') {
  1382. //Set display mode in viewer
  1383. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
  1384. $this->ZoomMode=$zoom;
  1385. else
  1386. $this->Error('Incorrect zoom display mode: '.$zoom);
  1387. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='twoleft' or $layout=='tworight' or $layout=='default')
  1388. $this->LayoutMode=$layout;
  1389. else
  1390. $this->Error('Incorrect layout display mode: '.$layout);
  1391. }
  1392. function SetCompression($compress) {
  1393. //Set page compression
  1394. if(function_exists('gzcompress')) $this->compress=$compress;
  1395. else $this->compress=false;
  1396. }
  1397. function SetTitle($title) {
  1398. //Title of document // Arrives as UTF-8
  1399. $this->title = $title;
  1400. }
  1401. function SetSubject($subject) {
  1402. //Subject of document
  1403. $this->subject= $subject;
  1404. }
  1405. function SetAuthor($author) {
  1406. //Author of document
  1407. $this->author= $author;
  1408. }
  1409. function SetKeywords($keywords) {
  1410. //Keywords of document
  1411. $this->keywords= $keywords;
  1412. }
  1413. function SetCreator($creator) {
  1414. //Creator of document
  1415. $this->creator= $creator;
  1416. }
  1417. function SetAnchor2Bookmark($x) {
  1418. $this->anchor2Bookmark = $x;
  1419. }
  1420. function AliasNbPages($alias='{nb}') {
  1421. //Define an alias for total number of pages
  1422. $this->aliasNbPg=$alias;
  1423. }
  1424. function AliasNbPageGroups($alias='{nbpg}') {
  1425. //Define an alias for total number of pages in a group
  1426. $this->aliasNbPgGp=$alias;
  1427. }
  1428. function SetAlpha($alpha, $bm='Normal', $return=false, $mode='B') {
  1429. // alpha: real value from 0 (transparent) to 1 (opaque)
  1430. // bm: blend mode, one of the following:
  1431. // Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
  1432. // HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  1433. // set alpha for stroking (CA) and non-stroking (ca) operations
  1434. // mode determines F (fill) S (stroke) B (both)
  1435. if (($this->PDFA || $this->PDFX) && $alpha!=1) {
  1436. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Image opacity must be 100% (Opacity changed to 100%)"; }
  1437. $alpha = 1;
  1438. }
  1439. $a = array('BM'=>'/'.$bm);
  1440. if ($mode=='F' || $mode='B') $a['ca'] = $alpha;
  1441. if ($mode=='S' || $mode='B') $a['CA'] = $alpha;
  1442. $gs = $this->AddExtGState($a);
  1443. if ($return) { return sprintf('/GS%d gs', $gs); }
  1444. else { $this->_out(sprintf('/GS%d gs', $gs)); }
  1445. }
  1446. function AddExtGState($parms) {
  1447. $n = count($this->extgstates);
  1448. // check if graphics state already exists
  1449. for ($i=1; $i<=$n; $i++) {
  1450. if (count($this->extgstates[$i]['parms']) == count($parms)) {
  1451. $same = true;
  1452. foreach($this->extgstates[$i]['parms'] AS $k=>$v) {
  1453. if (!isset($parms[$k]) || $parms[$k] != $v) { $same = false; break; }
  1454. }
  1455. if ($same) { return $i; }
  1456. }
  1457. }
  1458. $n++;
  1459. $this->extgstates[$n]['parms'] = $parms;
  1460. return $n;
  1461. }
  1462. function SetVisibility($v) {
  1463. if (($this->PDFA || $this->PDFX) && $this->visibility!='visible') { $this->PDFAXwarnings[] = "Cannot set visibility to anything other than full when using PDFA or PDFX"; return ''; }
  1464. else if (!$this->PDFA && !$this->PDFX)
  1465. $this->pdf_version='1.5';
  1466. if($this->visibility!='visible') {
  1467. $this->_out('EMC');
  1468. $this->hasOC = true;
  1469. }
  1470. if($v=='printonly')
  1471. $this->_out('/OC /OC1 BDC');
  1472. elseif($v=='screenonly')
  1473. $this->_out('/OC /OC2 BDC');
  1474. elseif($v=='hidden')
  1475. $this->_out('/OC /OC3 BDC');
  1476. elseif($v!='visible')
  1477. $this->Error('Incorrect visibility: '.$v);
  1478. $this->visibility=$v;
  1479. }
  1480. function Error($msg) {
  1481. //Fatal error
  1482. header('Content-Type: text/html; charset=utf-8');
  1483. die('<B>mPDF error: </B>'.$msg);
  1484. }
  1485. function Open() {
  1486. //Begin document
  1487. if($this->state==0) $this->_begindoc();
  1488. }
  1489. function Close() {
  1490. if ($this->progressBar) { $this->UpdateProgressBar(2,'2','Closing last page'); } // *PROGRESS-BAR*
  1491. //Terminate document
  1492. if($this->state==3) return;
  1493. if($this->page==0) $this->AddPage($this->CurOrientation);
  1494. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  1495. if ($this->tablebuffer) { $this->printtablebuffer(); } // *TABLES*
  1496. /*-- COLUMNS --*/
  1497. if ($this->ColActive) {
  1498. $this->SetColumns(0);
  1499. $this->ColActive = 0;
  1500. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  1501. }
  1502. /*-- END COLUMNS --*/
  1503. if (count($this->divbuffer)) { $this->printdivbuffer(); }
  1504. // BODY Backgrounds
  1505. $s = '';
  1506. $s .= $this->PrintBodyBackgrounds();
  1507. $s .= $this->PrintPageBackgrounds();
  1508. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1509. $this->pageBackgrounds = array();
  1510. if($this->visibility!='visible')
  1511. $this->SetVisibility('visible');
  1512. if (!$this->tocontents || !$this->tocontents->TOCmark) { //Page footer
  1513. $this->InFooter=true;
  1514. $this->Footer();
  1515. $this->InFooter=false;
  1516. }
  1517. if ($this->tocontents && ($this->tocontents->TOCmark || count($this->tocontents->m_TOC))) { $this->tocontents->insertTOC(); } // *TOC*
  1518. //Close page
  1519. $this->_endpage();
  1520. //Close document
  1521. $this->_enddoc();
  1522. }
  1523. /*-- BACKGROUNDS --*/
  1524. function _resizeBackgroundImage($imw, $imh, $cw, $ch, $resize=0, $repx, $repy) {
  1525. $cw = $cw*_MPDFK;
  1526. $ch = $ch*_MPDFK;
  1527. if (!$resize) { return array($imw, $imh, $repx, $repy); }
  1528. if ($resize==1 && $imw > $cw) {
  1529. $h = $imh * $cw/$imw;
  1530. $repx = false;
  1531. return array($cw, $h, $repx, $repy);
  1532. }
  1533. else if ($resize==2 && $imh > $ch) {
  1534. $w = $imw * $ch/$imh;
  1535. $repy = false;
  1536. return array($w, $ch, $repx, $repy);
  1537. }
  1538. else if ($resize==3) {
  1539. $w = $imw;
  1540. $h = $imh;
  1541. $saverepx = $repx;
  1542. if ($w > $cw) {
  1543. $h = $h * $cw/$w;
  1544. $w = $cw;
  1545. $repx = false;
  1546. }
  1547. if ($h > $ch) {
  1548. $w = $w * $ch/$h;
  1549. $h = $ch;
  1550. $repy = false;
  1551. $repx = $saverepx;
  1552. }
  1553. return array($w, $h, $repx, $repy);
  1554. }
  1555. else if ($resize==4) {
  1556. $h = $imh * $cw/$imw;
  1557. $repx = false;
  1558. return array($cw, $h, $repx, $repy);
  1559. }
  1560. else if ($resize==5) {
  1561. $w = $imw * $ch/$imh;
  1562. $repy = false;
  1563. return array($w, $ch, $repx, $repy);
  1564. }
  1565. else if ($resize==6) {
  1566. $repx = false;
  1567. $repy = false;
  1568. return array($cw, $ch, $repx, $repy);
  1569. }
  1570. return array($imw, $imh, $repx, $repy);
  1571. }
  1572. function SetBackground(&$properties, &$maxwidth) {
  1573. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['BACKGROUND-IMAGE'])) {
  1574. return array('gradient'=>$properties['BACKGROUND-IMAGE']);
  1575. }
  1576. else {
  1577. $file = $properties['BACKGROUND-IMAGE'];
  1578. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, true);
  1579. if (isset($sizesarray['IMAGE_ID'])) {
  1580. $image_id = $sizesarray['IMAGE_ID'];
  1581. $orig_w = $sizesarray['WIDTH']*_MPDFK; // in user units i.e. mm
  1582. $orig_h = $sizesarray['HEIGHT']*_MPDFK; // (using $this->img_dpi)
  1583. if (isset($properties['BACKGROUND-IMAGE-RESOLUTION'])) {
  1584. if (preg_match('/from-image/i', $properties['BACKGROUND-IMAGE-RESOLUTION']) && isset($sizesarray['set-dpi']) && $sizesarray['set-dpi']>0) {
  1585. $orig_w *= $this->img_dpi / $sizesarray['set-dpi'];
  1586. $orig_h *= $this->img_dpi / $sizesarray['set-dpi'];
  1587. }
  1588. else if (preg_match('/(\d+)dpi/i', $properties['BACKGROUND-IMAGE-RESOLUTION'], $m)) {
  1589. $dpi = $m[1];
  1590. if ($dpi > 0) {
  1591. $orig_w *= $this->img_dpi / $dpi;
  1592. $orig_h *= $this->img_dpi / $dpi;
  1593. }
  1594. }
  1595. }
  1596. $x_repeat = true;
  1597. $y_repeat = true;
  1598. if (isset($properties['BACKGROUND-REPEAT'])) {
  1599. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  1600. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  1601. }
  1602. $x_pos = 0;
  1603. $y_pos = 0;
  1604. if (isset($properties['BACKGROUND-POSITION'])) {
  1605. $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']);
  1606. $x_pos = $ppos[0];
  1607. $y_pos = $ppos[1];
  1608. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$maxwidth,$this->FontSize); }
  1609. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$maxwidth,$this->FontSize); }
  1610. }
  1611. if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; }
  1612. else { $resize = 0; }
  1613. if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; }
  1614. else { $opacity = 1; }
  1615. 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']);
  1616. }
  1617. }
  1618. return false;
  1619. }
  1620. /*-- END BACKGROUNDS --*/
  1621. function PrintBodyBackgrounds() {
  1622. $s = '';
  1623. $clx = 0;
  1624. $cly = 0;
  1625. $clw = $this->w;
  1626. $clh = $this->h;
  1627. // If using bleed and trim margins in paged media
  1628. if ($this->pageDim[$this->page]['outer_width_LR'] || $this->pageDim[$this->page]['outer_width_TB']) {
  1629. $clx = $this->pageDim[$this->page]['outer_width_LR'] - $this->pageDim[$this->page]['bleedMargin'];
  1630. $cly = $this->pageDim[$this->page]['outer_width_TB'] - $this->pageDim[$this->page]['bleedMargin'];
  1631. $clw = $this->w - 2*$clx;
  1632. $clh = $this->h - 2*$cly;
  1633. }
  1634. if ($this->bodyBackgroundColor) {
  1635. $s .= 'q ' .$this->SetFColor($this->bodyBackgroundColor, true)."\n";
  1636. if ($this->bodyBackgroundColor{0}==5) { // RGBa
  1637. $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{4})/100, 'Normal', true, 'F')."\n";
  1638. }
  1639. else if ($this->bodyBackgroundColor{0}==6) { // CMYKa
  1640. $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{5})/100, 'Normal', true, 'F')."\n";
  1641. }
  1642. $s .= sprintf('%.3F %.3F %.3F %.3F re f Q', ($clx*_MPDFK), ($cly*_MPDFK),$clw*_MPDFK,$clh*_MPDFK)."\n";
  1643. }
  1644. /*-- BACKGROUNDS --*/
  1645. if ($this->bodyBackgroundGradient) {
  1646. $g = $this->grad->parseBackgroundGradient($this->bodyBackgroundGradient);
  1647. if ($g) {
  1648. $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, (isset($g['gradtype']) ? $g['gradtype'] : null), $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
  1649. }
  1650. }
  1651. if ($this->bodyBackgroundImage) {
  1652. if ( $this->bodyBackgroundImage['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->bodyBackgroundImage['gradient'])) {
  1653. $g = $this->grad->parseMozGradient( $this->bodyBackgroundImage['gradient']);
  1654. if ($g) {
  1655. $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
  1656. }
  1657. }
  1658. else if ($this->bodyBackgroundImage['image_id']) { // Background pattern
  1659. $n = count($this->patterns)+1;
  1660. // If using resize, uses TrimBox (not including the bleed)
  1661. 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']);
  1662. $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']);
  1663. if (($this->bodyBackgroundImage['opacity']>0 || $this->bodyBackgroundImage['opacity']==='0') && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); }
  1664. else { $opac = ''; }
  1665. $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";
  1666. }
  1667. }
  1668. /*-- END BACKGROUNDS --*/
  1669. return $s;
  1670. }
  1671. function PrintPageBackgrounds($adjustmenty=0) {
  1672. $s = '';
  1673. ksort($this->pageBackgrounds);
  1674. foreach($this->pageBackgrounds AS $bl=>$pbs) {
  1675. foreach ($pbs AS $pb) {
  1676. if ((!isset($pb['image_id']) && !isset($pb['gradient'])) || isset($pb['shadowonly'])) { // Background colour or boxshadow
  1677. if($pb['visibility']!='visible') {
  1678. if($pb['visibility']=='printonly')
  1679. $s .= '/OC /OC1 BDC'."\n";
  1680. else if($pb['visibility']=='screenonly')
  1681. $s .= '/OC /OC2 BDC'."\n";
  1682. else if($pb['visibility']=='hidden')
  1683. $s .= '/OC /OC3 BDC'."\n";
  1684. }
  1685. // Box shadow
  1686. if (isset($pb['shadow']) && $pb['shadow']) { $s .= $pb['shadow']."\n"; }
  1687. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1688. $s .= 'q '.$this->SetFColor($pb['col'], true)."\n";
  1689. if ($pb['col']{0}==5) { // RGBa
  1690. $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n";
  1691. }
  1692. else if ($pb['col']{0}==6) { // CMYKa
  1693. $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n";
  1694. }
  1695. $s .= sprintf('%.3F %.3F %.3F %.3F re f Q',$pb['x']*_MPDFK,($this->h-$pb['y'])*_MPDFK,$pb['w']*_MPDFK,-$pb['h']*_MPDFK)."\n";
  1696. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1697. if($pb['visibility']!='visible')
  1698. $s .= 'EMC'."\n";
  1699. }
  1700. }
  1701. /*-- BACKGROUNDS --*/
  1702. foreach ($pbs AS $pb) {
  1703. if($pb['visibility']!='visible') {
  1704. if($pb['visibility']=='printonly')
  1705. $s .= '/OC /OC1 BDC'."\n";
  1706. else if($pb['visibility']=='screenonly')
  1707. $s .= '/OC /OC2 BDC'."\n";
  1708. else if($pb['visibility']=='hidden')
  1709. $s .= '/OC /OC3 BDC'."\n";
  1710. }
  1711. if (isset($pb['gradient']) && $pb['gradient']) {
  1712. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1713. $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1714. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1715. }
  1716. else if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1717. $pb['y'] -= $adjustmenty;
  1718. $pb['h'] += $adjustmenty;
  1719. $n = count($this->patterns)+1;
  1720. 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']);
  1721. $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']);
  1722. $x = $pb['x']*_MPDFK;
  1723. $y = ($this->h - $pb['y'])*_MPDFK;
  1724. $w = $pb['w']*_MPDFK;
  1725. $h = -$pb['h']*_MPDFK;
  1726. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1727. if ($this->writingHTMLfooter || $this->writingHTMLheader) {
  1728. $iw = $pb['orig_w']/_MPDFK;
  1729. $ih = $pb['orig_h']/_MPDFK;
  1730. $w = $pb['w'];
  1731. $h = $pb['h'];
  1732. $x0 = $pb['x'];
  1733. $y0 = $pb['y'];
  1734. // Number to repeat
  1735. if ($pb['x_repeat']) { $nx = ceil($w/$iw); }
  1736. else { $nx = 1; }
  1737. if ($pb['y_repeat']) { $ny = ceil($h/$ih); }
  1738. else { $ny = 1; }
  1739. $x_pos = $pb['x_pos'];
  1740. if (stristr($x_pos ,'%') ) {
  1741. $x_pos += 0;
  1742. $x_pos /= 100;
  1743. $x_pos = ($w * $x_pos) - ($iw * $x_pos);
  1744. }
  1745. $y_pos = $pb['y_pos'];
  1746. if (stristr($y_pos ,'%') ) {
  1747. $y_pos += 0;
  1748. $y_pos /= 100;
  1749. $y_pos = ($h * $y_pos) - ($ih * $y_pos);
  1750. }
  1751. if ($nx>1) {
  1752. while($x_pos>0) { $x_pos -= $iw; }
  1753. }
  1754. if ($ny>1) {
  1755. while($y_pos>0) { $y_pos -= $ih; }
  1756. }
  1757. for($xi=0;$xi<$nx;$xi++) {
  1758. for($yi=0;$yi<$ny;$yi++) {
  1759. $x = $x0 + $x_pos + ($iw*$xi);
  1760. $y = $y0 + $y_pos + ($ih*$yi);
  1761. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1762. else { $opac = ''; }
  1763. $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";
  1764. }
  1765. }
  1766. }
  1767. else {
  1768. if (($pb['opacity']>0 || $pb['opacity']==='0') && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1769. else { $opac = ''; }
  1770. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1771. }
  1772. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1773. }
  1774. if($pb['visibility']!='visible')
  1775. $s .= 'EMC'."\n";
  1776. }
  1777. /*-- END BACKGROUNDS --*/
  1778. }
  1779. return $s;
  1780. }
  1781. function PrintTableBackgrounds($adjustmenty=0) {
  1782. $s = '';
  1783. /*-- BACKGROUNDS --*/
  1784. ksort($this->tableBackgrounds);
  1785. foreach($this->tableBackgrounds AS $bl=>$pbs) {
  1786. foreach ($pbs AS $pb) {
  1787. if ((!isset($pb['gradient']) || !$pb['gradient']) && (!isset($pb['image_id']) || !$pb['image_id'])) {
  1788. $s .= 'q '.$this->SetFColor($pb['col'], true)."\n";
  1789. if ($pb['col']{0}==5) { // RGBa
  1790. $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n";
  1791. }
  1792. else if ($pb['col']{0}==6) { // CMYKa
  1793. $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n";
  1794. }
  1795. $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";
  1796. }
  1797. if (isset($pb['gradient']) && $pb['gradient']) {
  1798. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1799. $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true);
  1800. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1801. }
  1802. if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1803. $pb['y'] -= $adjustmenty;
  1804. $pb['h'] += $adjustmenty;
  1805. $n = count($this->patterns)+1;
  1806. 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']);
  1807. $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']);
  1808. $x = $pb['x']*_MPDFK;
  1809. $y = ($this->h - $pb['y'])*_MPDFK;
  1810. $w = $pb['w']*_MPDFK;
  1811. $h = -$pb['h']*_MPDFK;
  1812. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1813. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1814. else { $opac = ''; }
  1815. $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1816. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1817. }
  1818. }
  1819. }
  1820. /*-- END BACKGROUNDS --*/
  1821. return $s;
  1822. }
  1823. // Depracated - can use AddPage for all
  1824. 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='')
  1825. {
  1826. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  1827. }
  1828. function AddPageByArray($a) {
  1829. if (!is_array($a)) { $a = array(); }
  1830. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  1831. $condition = (isset($a['condition']) ? $a['condition'] : (isset($a['type']) ? $a['type'] : ''));
  1832. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  1833. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  1834. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  1835. $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : ''));
  1836. $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : ''));
  1837. $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : ''));
  1838. $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : ''));
  1839. $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : ''));
  1840. $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : ''));
  1841. $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : ''));
  1842. $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : ''));
  1843. $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : ''));
  1844. $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : ''));
  1845. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0));
  1846. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0));
  1847. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0));
  1848. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0));
  1849. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : ''));
  1850. $newformat = (isset($a['newformat']) ? $a['newformat'] : (isset($a['sheet-size']) ? $a['sheet-size'] : ''));
  1851. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat);
  1852. }
  1853. 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='')
  1854. {
  1855. /*-- CSS-FLOAT --*/
  1856. // Float DIV
  1857. // Cannot do with columns on, or if any change in page orientation/margins etc.
  1858. // If next page already exists - i.e background /headers and footers already written
  1859. if ($this->state > 0 && $this->page < count($this->pages)) {
  1860. $bak_cml = $this->cMarginL;
  1861. $bak_cmr = $this->cMarginR;
  1862. $bak_dw = $this->divwidth;
  1863. // Paint Div Border if necessary
  1864. if ($this->blklvl > 0) {
  1865. $save_tr = $this->table_rotate; // *TABLES*
  1866. $this->table_rotate = 0; // *TABLES*
  1867. if ($this->y == $this->blk[$this->blklvl]['y0']) { $this->blk[$this->blklvl]['startpage']++; }
  1868. if (($this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  1869. else { $toplvl = $this->blklvl-1; }
  1870. $sy = $this->y;
  1871. for ($bl=1;$bl<=$toplvl;$bl++) {
  1872. $this->PaintDivBB('pagebottom',0,$bl);
  1873. }
  1874. $this->y = $sy;
  1875. $this->table_rotate = $save_tr; // *TABLES*
  1876. }
  1877. $s = $this->PrintPageBackgrounds();
  1878. // Writes after the marker so not overwritten later by page background etc.
  1879. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  1880. $this->pageBackgrounds = array();
  1881. $family=$this->FontFamily;
  1882. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  1883. $size=$this->FontSizePt;
  1884. $lw=$this->LineWidth;
  1885. $dc=$this->DrawColor;
  1886. $fc=$this->FillColor;
  1887. $tc=$this->TextColor;
  1888. $cf=$this->ColorFlag;
  1889. $this->printfloatbuffer();
  1890. //Move to next page
  1891. $this->page++;
  1892. $this->ResetMargins();
  1893. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  1894. $this->x=$this->lMargin;
  1895. $this->y=$this->tMargin;
  1896. $this->FontFamily='';
  1897. $this->_out('2 J');
  1898. $this->LineWidth=$lw;
  1899. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  1900. if($family) $this->SetFont($family,$style,$size,true,true);
  1901. $this->DrawColor=$dc;
  1902. if($dc!=$this->defDrawColor) $this->_out($dc);
  1903. $this->FillColor=$fc;
  1904. if($fc!=$this->defFillColor) $this->_out($fc);
  1905. $this->TextColor=$tc;
  1906. $this->ColorFlag=$cf;
  1907. for($bl=1;$bl<=$this->blklvl;$bl++) {
  1908. $this->blk[$bl]['y0'] = $this->y;
  1909. // Don't correct more than once for background DIV containing a Float
  1910. if (!isset($this->blk[$bl]['marginCorrected'][$this->page])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  1911. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  1912. }
  1913. $this->cMarginL = $bak_cml;
  1914. $this->cMarginR = $bak_cmr;
  1915. $this->divwidth = $bak_dw;
  1916. return '';
  1917. }
  1918. /*-- END CSS-FLOAT --*/
  1919. //Start a new page
  1920. if($this->state==0) $this->Open();
  1921. $bak_cml = $this->cMarginL;
  1922. $bak_cmr = $this->cMarginR;
  1923. $bak_dw = $this->divwidth;
  1924. $bak_lh = $this->lineheight;
  1925. $orientation = substr(strtoupper($orientation),0,1);
  1926. $condition = strtoupper($condition);
  1927. if ($condition == 'NEXT-EVEN') { // always adds at least one new page to create an Even page
  1928. if (!$this->mirrorMargins) { $condition = ''; }
  1929. else {
  1930. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1931. else { $pbch = false; } // *CSS-PAGE*
  1932. $this->AddPage($this->CurOrientation,'O');
  1933. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1934. $condition = '';
  1935. }
  1936. }
  1937. if ($condition == 'NEXT-ODD') { // always adds at least one new page to create an Odd page
  1938. if (!$this->mirrorMargins) { $condition = ''; }
  1939. else {
  1940. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1941. else { $pbch = false; } // *CSS-PAGE*
  1942. $this->AddPage($this->CurOrientation,'E');
  1943. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1944. $condition = '';
  1945. }
  1946. }
  1947. if ($condition == 'E') { // only adds new page if needed to create an Even page
  1948. if (!$this->mirrorMargins || ($this->page)%2==0) { return false; }
  1949. }
  1950. if ($condition == 'O') { // only adds new page if needed to create an Odd page
  1951. if (!$this->mirrorMargins || ($this->page)%2==1) { return false; }
  1952. }
  1953. if ($resetpagenum || $pagenumstyle || $suppress) {
  1954. $this->PageNumSubstitutions[] = array('from'=>($this->page+1), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  1955. }
  1956. $save_tr = $this->table_rotate; // *TABLES*
  1957. $this->table_rotate = 0; // *TABLES*
  1958. $save_kwt = $this->kwt;
  1959. $this->kwt = 0;
  1960. // Paint Div Border if necessary
  1961. //PAINTS BACKGROUND COLOUR OR BORDERS for DIV - DISABLED FOR COLUMNS (cf. AcceptPageBreak) AT PRESENT in ->PaintDivBB
  1962. if (!$this->ColActive && $this->blklvl > 0) {
  1963. if (isset($this->blk[$this->blklvl]['y0']) && $this->y == $this->blk[$this->blklvl]['y0']) {
  1964. if (isset($this->blk[$this->blklvl]['startpage'])) { $this->blk[$this->blklvl]['startpage']++; }
  1965. else { $this->blk[$this->blklvl]['startpage'] = 1; }
  1966. }
  1967. if ((isset($this->blk[$this->blklvl]['y0']) && $this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  1968. else { $toplvl = $this->blklvl-1; }
  1969. $sy = $this->y;
  1970. for ($bl=1;$bl<=$toplvl;$bl++) {
  1971. $this->PaintDivBB('pagebottom',0,$bl);
  1972. }
  1973. $this->y = $sy;
  1974. // RESET block y0 and x0 - see below
  1975. }
  1976. // BODY Backgrounds
  1977. if ($this->page > 0) {
  1978. $s = '';
  1979. $s .= $this->PrintBodyBackgrounds();
  1980. $s .= $this->PrintPageBackgrounds();
  1981. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1982. $this->pageBackgrounds = array();
  1983. }
  1984. $save_kt = $this->keep_block_together;
  1985. $this->keep_block_together = 0;
  1986. $save_cols = false;
  1987. /*-- COLUMNS --*/
  1988. if ($this->ColActive) {
  1989. $save_cols = true;
  1990. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  1991. $this->SetColumns(0);
  1992. }
  1993. /*-- END COLUMNS --*/
  1994. $save_vis = $this->visibility;
  1995. if($this->visibility!='visible')
  1996. $this->SetVisibility('visible');
  1997. $family=$this->FontFamily;
  1998. $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  1999. $size=$this->FontSizePt;
  2000. $this->ColumnAdjust = true; // enables column height adjustment for the page
  2001. $lw=$this->LineWidth;
  2002. $dc=$this->DrawColor;
  2003. $fc=$this->FillColor;
  2004. $tc=$this->TextColor;
  2005. $cf=$this->ColorFlag;
  2006. if($this->page>0)
  2007. {
  2008. //Page footer
  2009. $this->InFooter=true;
  2010. $this->Reset();
  2011. $this->pageoutput[$this->page] = array();
  2012. $this->Footer();
  2013. //Close page
  2014. $this->_endpage();
  2015. }
  2016. //Start new page
  2017. $this->_beginpage($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat);
  2018. if ($this->docTemplate) {
  2019. $pagecount = $this->SetSourceFile($this->docTemplate);
  2020. if (($this->page - $this->docTemplateStart) > $pagecount) {
  2021. if ($this->docTemplateContinue) {
  2022. $tplIdx = $this->ImportPage($pagecount);
  2023. $this->UseTemplate($tplIdx);
  2024. }
  2025. }
  2026. else {
  2027. $tplIdx = $this->ImportPage(($this->page - $this->docTemplateStart));
  2028. $this->UseTemplate($tplIdx);
  2029. }
  2030. }
  2031. if ($this->pageTemplate) {
  2032. $this->UseTemplate($this->pageTemplate);
  2033. }
  2034. // Tiling Patterns
  2035. $this->_out('___PAGE___START'.date('jY'));
  2036. $this->_out('___BACKGROUND___PATTERNS'.date('jY'));
  2037. $this->_out('___HEADER___MARKER'.date('jY'));
  2038. $this->pageBackgrounds = array();
  2039. //Set line cap style to square
  2040. $this->SetLineCap(2);
  2041. //Set line width
  2042. $this->LineWidth=$lw;
  2043. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  2044. //Set font
  2045. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2046. //Set colors
  2047. $this->DrawColor=$dc;
  2048. if($dc!=$this->defDrawColor) $this->_out($dc);
  2049. $this->FillColor=$fc;
  2050. if($fc!=$this->defFillColor) $this->_out($fc);
  2051. $this->TextColor=$tc;
  2052. $this->ColorFlag=$cf;
  2053. //Page header
  2054. $this->Header();
  2055. //Restore line width
  2056. if($this->LineWidth!=$lw)
  2057. {
  2058. $this->LineWidth=$lw;
  2059. $this->_out(sprintf('%.3F w',$lw*_MPDFK));
  2060. }
  2061. //Restore font
  2062. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  2063. //Restore colors
  2064. if($this->DrawColor!=$dc)
  2065. {
  2066. $this->DrawColor=$dc;
  2067. $this->_out($dc);
  2068. }
  2069. if($this->FillColor!=$fc)
  2070. {
  2071. $this->FillColor=$fc;
  2072. $this->_out($fc);
  2073. }
  2074. $this->TextColor=$tc;
  2075. $this->ColorFlag=$cf;
  2076. $this->InFooter=false;
  2077. if($save_vis!='visible')
  2078. $this->SetVisibility($save_vis);
  2079. /*-- COLUMNS --*/
  2080. if ($save_cols) {
  2081. // Restore columns
  2082. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  2083. }
  2084. if ($this->ColActive) { $this->SetCol(0); }
  2085. /*-- END COLUMNS --*/
  2086. //RESET BLOCK BORDER TOP
  2087. if (!$this->ColActive) {
  2088. for($bl=1;$bl<=$this->blklvl;$bl++) {
  2089. $this->blk[$bl]['y0'] = $this->y;
  2090. if (isset($this->blk[$bl]['x0'])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  2091. else { $this->blk[$bl]['x0'] = $this->MarginCorrection; }
  2092. // Added mPDF 3.0 Float DIV
  2093. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  2094. }
  2095. }
  2096. $this->table_rotate = $save_tr; // *TABLES*
  2097. $this->kwt = $save_kwt;
  2098. $this->keep_block_together = $save_kt ;
  2099. $this->cMarginL = $bak_cml;
  2100. $this->cMarginR = $bak_cmr;
  2101. $this->divwidth = $bak_dw;
  2102. $this->lineheight = $bak_lh;
  2103. }
  2104. function PageNo() {
  2105. //Get current page number
  2106. return $this->page;
  2107. }
  2108. function AddSpotColorsFromFile($file) {
  2109. $colors = @file($file) or die("Cannot load spot colors file - ".$file);
  2110. foreach($colors AS $sc) {
  2111. list($name, $c, $m, $y, $k) = preg_split("/\t/",$sc);
  2112. $c = intval($c);
  2113. $m = intval($m);
  2114. $y = intval($y);
  2115. $k = intval($k);
  2116. $this->AddSpotColor($name, $c, $m, $y, $k);
  2117. }
  2118. }
  2119. function AddSpotColor($name, $c, $m, $y, $k) {
  2120. $name = strtoupper(trim($name));
  2121. if(!isset($this->spotColors[$name])) {
  2122. $i=count($this->spotColors)+1;
  2123. $this->spotColors[$name]=array('i'=>$i,'c'=>$c,'m'=>$m,'y'=>$y,'k'=>$k);
  2124. $this->spotColorIDs[$i]=$name;
  2125. }
  2126. }
  2127. function SetColor($col, $type='') {
  2128. $out = '';
  2129. if ($col{0}==3 || $col{0}==5) { // RGB / RGBa
  2130. $out = sprintf('%.3F %.3F %.3F rg',ord($col{1})/255,ord($col{2})/255,ord($col{3})/255);
  2131. }
  2132. else if ($col{0}==1) { // GRAYSCALE
  2133. $out = sprintf('%.3F g',ord($col{1})/255);
  2134. }
  2135. else if ($col{0}==2) { // SPOT COLOR
  2136. $out = sprintf('/CS%d cs %.3F scn',ord($col{1}),ord($col{2})/100);
  2137. }
  2138. else if ($col{0}==4 || $col{0}==6) { // CMYK / CMYKa
  2139. $out = sprintf('%.3F %.3F %.3F %.3F k', ord($col{1})/100, ord($col{2})/100, ord($col{3})/100, ord($col{4})/100);
  2140. }
  2141. if ($type=='Draw') { $out = strtoupper($out); } // e.g. rg => RG
  2142. else if ($type=='CodeOnly') { $out = preg_replace('/\s(rg|g|k)/','',$out); }
  2143. return $out;
  2144. }
  2145. function SetDColor($col, $return=false) {
  2146. $out = $this->SetColor($col, 'Draw');
  2147. if ($return) { return $out; }
  2148. if ($out=='') { return ''; }
  2149. $this->DrawColor = $out;
  2150. 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); }
  2151. $this->pageoutput[$this->page]['DrawColor'] = $this->DrawColor;
  2152. }
  2153. function SetFColor($col, $return=false) {
  2154. $out = $this->SetColor($col, 'Fill');
  2155. if ($return) { return $out; }
  2156. if ($out=='') { return ''; }
  2157. $this->FillColor = $out;
  2158. $this->ColorFlag = ($out != $this->TextColor);
  2159. 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); }
  2160. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  2161. }
  2162. function SetTColor($col, $return=false) {
  2163. $out = $this->SetColor($col, 'Text');
  2164. if ($return) { return $out; }
  2165. if ($out=='') { return ''; }
  2166. $this->TextColor = $out;
  2167. $this->ColorFlag = ($this->FillColor != $out);
  2168. }
  2169. function SetDrawColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2170. //Set color for all stroking operations
  2171. $col = array();
  2172. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2173. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2174. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2175. $out = $this->SetDColor($col, $return);
  2176. return $out;
  2177. }
  2178. function SetFillColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2179. //Set color for all filling operations
  2180. $col = array();
  2181. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2182. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2183. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2184. $out = $this->SetFColor($col, $return);
  2185. return $out;
  2186. }
  2187. function SetTextColor($r,$g=-1,$b=-1,$col4=-1, $return=false) {
  2188. //Set color for text
  2189. $col = array();
  2190. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); }
  2191. else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); }
  2192. else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); }
  2193. $out = $this->SetTColor($col, $return);
  2194. return $out;
  2195. }
  2196. function _getCharWidth(&$cw, $u, $isdef=true) {
  2197. if ($u==0) { $w = false; }
  2198. else { $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); }
  2199. if ($w == 65535) { return 0; }
  2200. else if ($w) { return $w; }
  2201. else if ($isdef) { return false; }
  2202. else { return 0; }
  2203. }
  2204. function _charDefined(&$cw, $u) {
  2205. if ($u==0) { return false; }
  2206. $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]);
  2207. if ($w) { return true; }
  2208. else { return false; }
  2209. }
  2210. function GetCharWidthCore($c) {
  2211. //Get width of a single character in the current Core font
  2212. $c = (string)$c;
  2213. $w = 0;
  2214. // Soft Hyphens chr(173)
  2215. if ($c == chr(173) && $this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  2216. return 0;
  2217. }
  2218. else if ($this->S && isset($this->upperCase[ord($c)])) {
  2219. $charw = $this->CurrentFont['cw'][chr($this->upperCase[ord($c)])];
  2220. if ($charw!==false) {
  2221. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2222. $w+=$charw;
  2223. }
  2224. }
  2225. else if (isset($this->CurrentFont['cw'][$c])) {
  2226. $w += $this->CurrentFont['cw'][$c];
  2227. }
  2228. else if (isset($this->CurrentFont['cw'][ord($c)])) {
  2229. $w += $this->CurrentFont['cw'][ord($c)];
  2230. }
  2231. $w *= ($this->FontSize/ 1000);
  2232. if ($this->minwSpacing || $this->fixedlSpacing) {
  2233. if ($c==' ') $nb_spaces = 1;
  2234. else $nb_spaces = 0;
  2235. $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing);
  2236. }
  2237. return ($w);
  2238. }
  2239. function GetCharWidthNonCore($c, $addSubset=true) {
  2240. //Get width of a single character in the current Non-Core font
  2241. $c = (string)$c;
  2242. $w = 0;
  2243. $unicode = $this->UTF8StringToArray($c, $addSubset);
  2244. $char = $unicode[0];
  2245. /*-- CJK-FONTS --*/
  2246. if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts
  2247. if ($char == 173) { return 0; } // Soft Hyphens
  2248. elseif (isset($this->CurrentFont['cw'][$char])) { $w+=$this->CurrentFont['cw'][$char]; }
  2249. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2250. else { $w += 500; }
  2251. }
  2252. else {
  2253. /*-- END CJK-FONTS --*/
  2254. if ($char == 173) { return 0; } // Soft Hyphens
  2255. else if ($this->S && isset($this->upperCase[$char])) {
  2256. $charw = $this->_getCharWidth($this->CurrentFont['cw'],$this->upperCase[$char]);
  2257. if ($charw!==false) {
  2258. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2259. $w+=$charw;
  2260. }
  2261. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2262. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2263. else { $w += 500; }
  2264. }
  2265. else {
  2266. $charw = $this->_getCharWidth($this->CurrentFont['cw'],$char);
  2267. if ($charw!==false) { $w+=$charw; }
  2268. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2269. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2270. else { $w += 500; }
  2271. }
  2272. } // *CJK-FONTS*
  2273. $w *= ($this->FontSize/ 1000);
  2274. if ($this->minwSpacing || $this->fixedlSpacing) {
  2275. if ($c==' ') $nb_spaces = 1;
  2276. else $nb_spaces = 0;
  2277. $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing);
  2278. }
  2279. return ($w);
  2280. }
  2281. function GetCharWidth($c, $addSubset=true) {
  2282. if (!$this->usingCoreFont) {
  2283. return $this->GetCharWidthNonCore($c, $addSubset);
  2284. }
  2285. else {
  2286. return $this->GetCharWidthCore($c);
  2287. }
  2288. }
  2289. function GetStringWidth($s, $addSubset=true) {
  2290. //Get width of a string in the current font
  2291. $s = (string)$s;
  2292. $cw = &$this->CurrentFont['cw'];
  2293. $w = 0;
  2294. $kerning = 0;
  2295. $lastchar = 0;
  2296. $nb_carac = 0;
  2297. $nb_spaces = 0;
  2298. // mPDF ITERATION
  2299. if ($this->iterationCounter) $s = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/', '\\1', $s);
  2300. if (!$this->usingCoreFont) {
  2301. $s = str_replace("\xc2\xad",'',$s );
  2302. $unicode = $this->UTF8StringToArray($s, $addSubset);
  2303. if ($this->minwSpacing || $this->fixedlSpacing) {
  2304. $nb_carac = count($unicode);
  2305. $nb_spaces = mb_substr_count($s,' ', $this->mb_enc);
  2306. }
  2307. /*-- CJK-FONTS --*/
  2308. if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts
  2309. foreach($unicode as $char) {
  2310. if (isset($cw[$char])) { $w+=$cw[$char]; }
  2311. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2312. else { $w += 500; }
  2313. }
  2314. }
  2315. else {
  2316. /*-- END CJK-FONTS --*/
  2317. foreach($unicode as $char) {
  2318. if ($this->S && isset($this->upperCase[$char])) {
  2319. $charw = $this->_getCharWidth($cw,$this->upperCase[$char]);
  2320. if ($charw!==false) {
  2321. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2322. $w+=$charw;
  2323. }
  2324. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2325. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2326. else { $w += 500; }
  2327. }
  2328. else {
  2329. $charw = $this->_getCharWidth($cw,$char);
  2330. if ($charw!==false) { $w+=$charw; }
  2331. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2332. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2333. else { $w += 500; }
  2334. if ($this->kerning && $this->useKerning && $lastchar) {
  2335. if (isset($this->CurrentFont['kerninfo'][$lastchar][$char])) {
  2336. $kerning += $this->CurrentFont['kerninfo'][$lastchar][$char];
  2337. }
  2338. }
  2339. $lastchar = $char;
  2340. }
  2341. }
  2342. } // *CJK-FONTS*
  2343. }
  2344. else {
  2345. if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  2346. $s = str_replace(chr(173),'',$s );
  2347. }
  2348. $nb_carac = $l = strlen($s);
  2349. if ($this->minwSpacing || $this->fixedlSpacing) {
  2350. $nb_spaces = substr_count($s,' ');
  2351. }
  2352. for($i=0; $i<$l; $i++) {
  2353. if ($this->S && isset($this->upperCase[ord($s[$i])])) {
  2354. $charw = $cw[chr($this->upperCase[ord($s[$i])])];
  2355. if ($charw!==false) {
  2356. $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100;
  2357. $w+=$charw;
  2358. }
  2359. }
  2360. else if (isset($cw[$s[$i]])) {
  2361. $w += $cw[$s[$i]];
  2362. }
  2363. else if (isset($cw[ord($s[$i])])) {
  2364. $w += $cw[ord($s[$i])];
  2365. }
  2366. if ($this->kerning && $this->useKerning && $i>0) {
  2367. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]])) {
  2368. $kerning += $this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]];
  2369. }
  2370. }
  2371. }
  2372. }
  2373. unset($cw);
  2374. if ($this->kerning && $this->useKerning) { $w += $kerning; }
  2375. $w *= ($this->FontSize/ 1000);
  2376. $w += (($nb_carac + $nb_spaces) * $this->fixedlSpacing) + ($nb_spaces * $this->minwSpacing);
  2377. return ($w);
  2378. }
  2379. function SetLineWidth($width) {
  2380. //Set line width
  2381. $this->LineWidth=$width;
  2382. $lwout = (sprintf('%.3F w',$width*_MPDFK));
  2383. 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)) {
  2384. $this->_out($lwout);
  2385. }
  2386. $this->pageoutput[$this->page]['LineWidth'] = $lwout;
  2387. }
  2388. function Line($x1,$y1,$x2,$y2) {
  2389. //Draw a line
  2390. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x2*_MPDFK,($this->h-$y2)*_MPDFK));
  2391. }
  2392. function Arrow($x1,$y1,$x2,$y2,$headsize=3,$fill='B',$angle=25) {
  2393. //F == fill //S == stroke //B == stroke and fill
  2394. // angle = splay of arrowhead - 1 - 89 degrees
  2395. if($fill=='F') $fill='f';
  2396. elseif($fill=='FD' or $fill=='DF' or $fill=='B') $fill='B';
  2397. else $fill='S';
  2398. $a = atan2(($y2-$y1),($x2-$x1));
  2399. $b = $a + deg2rad($angle);
  2400. $c = $a - deg2rad($angle);
  2401. $x3 = $x2 - ($headsize* cos($b));
  2402. $y3 = $this->h-($y2 - ($headsize* sin($b)));
  2403. $x4 = $x2 - ($headsize* cos($c));
  2404. $y4 = $this->h-($y2 - ($headsize* sin($c)));
  2405. $x5 = $x3-($x3-$x4)/2; // mid point of base of arrowhead - to join arrow line to
  2406. $y5 = $y3-($y3-$y4)/2;
  2407. $s = '';
  2408. $s.=sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x5*_MPDFK,$y5*_MPDFK);
  2409. $this->_out($s);
  2410. $s = '';
  2411. $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);
  2412. $s.=$fill;
  2413. $this->_out($s);
  2414. }
  2415. function Rect($x,$y,$w,$h,$style='') {
  2416. //Draw a rectangle
  2417. if($style=='F') $op='f';
  2418. elseif($style=='FD' or $style=='DF') $op='B';
  2419. else $op='S';
  2420. $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$h*_MPDFK,$op));
  2421. }
  2422. function AddFont($family,$style='') {
  2423. if(empty($family)) { return; }
  2424. $family = strtolower($family);
  2425. $style=strtoupper($style);
  2426. $style=str_replace('U','',$style);
  2427. if($style=='IB') $style='BI';
  2428. $fontkey = $family.$style;
  2429. // check if the font has been already added
  2430. if(isset($this->fonts[$fontkey])) {
  2431. return;
  2432. }
  2433. /*-- CJK-FONTS --*/
  2434. if (in_array($family,$this->available_CJK_fonts)) {
  2435. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2436. $this->AddCJKFont($family); // don't need to add style
  2437. return;
  2438. }
  2439. /*-- END CJK-FONTS --*/
  2440. if ($this->usingCoreFont) { die("mPDF Error - problem with Font management"); }
  2441. $stylekey = $style;
  2442. if (!$style) { $stylekey = 'R'; }
  2443. if (!isset($this->fontdata[$family][$stylekey]) || !$this->fontdata[$family][$stylekey]) {
  2444. die('mPDF Error - Font is not supported - '.$family.' '.$style);
  2445. }
  2446. $name = '';
  2447. $originalsize = 0;
  2448. $sip = false;
  2449. $smp = false;
  2450. $unAGlyphs = false; // mPDF 5.4.05
  2451. $haskerninfo = false;
  2452. $BMPselected = false;
  2453. @include(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php');
  2454. $ttffile = '';
  2455. if (defined('_MPDF_SYSTEM_TTFONTS')) {
  2456. $ttffile = _MPDF_SYSTEM_TTFONTS.$this->fontdata[$family][$stylekey];
  2457. if (!file_exists($ttffile)) { $ttffile = ''; }
  2458. }
  2459. if (!$ttffile) {
  2460. $ttffile = _MPDF_TTFONTPATH.$this->fontdata[$family][$stylekey];
  2461. if (!file_exists($ttffile)) { die("mPDF Error - cannot find TTF TrueType font file - ".$ttffile); }
  2462. }
  2463. $ttfstat = stat($ttffile);
  2464. if (isset($this->fontdata[$family]['TTCfontID'][$stylekey])) { $TTCfontID = $this->fontdata[$family]['TTCfontID'][$stylekey]; }
  2465. else { $TTCfontID = 0; }
  2466. $BMPonly = false;
  2467. if (in_array($family,$this->BMPonly)) { $BMPonly = true; }
  2468. $regenerate = false;
  2469. if ($BMPonly && !$BMPselected) { $regenerate = true; }
  2470. else if (!$BMPonly && $BMPselected) { $regenerate = true; }
  2471. if ($this->useKerning && !$haskerninfo) { $regenerate = true; }
  2472. // mPDF 5.4.05
  2473. if (isset($this->fontdata[$family]['unAGlyphs']) && $this->fontdata[$family]['unAGlyphs'] && !$unAGlyphs) {
  2474. $regenerate = true;
  2475. $unAGlyphs = true;
  2476. }
  2477. else if ((!isset($this->fontdata[$family]['unAGlyphs']) || !$this->fontdata[$family]['unAGlyphs']) && $unAGlyphs) {
  2478. $regenerate = true;
  2479. $unAGlyphs = false;
  2480. }
  2481. if (!isset($name) || $originalsize != $ttfstat['size'] || $regenerate) {
  2482. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  2483. $ttf = new TTFontFile();
  2484. $ttf->getMetrics($ttffile, $TTCfontID, $this->debugfonts, $BMPonly, $this->useKerning, $unAGlyphs); // mPDF 5.4.05
  2485. $cw = $ttf->charWidths;
  2486. $kerninfo = $ttf->kerninfo;
  2487. $haskerninfo = true;
  2488. $name = preg_replace('/[ ()]/','',$ttf->fullName);
  2489. $sip = $ttf->sipset;
  2490. $smp = $ttf->smpset;
  2491. $desc= array('Ascent'=>round($ttf->ascent),
  2492. 'Descent'=>round($ttf->descent),
  2493. 'CapHeight'=>round($ttf->capHeight),
  2494. 'Flags'=>$ttf->flags,
  2495. 'FontBBox'=>'['.round($ttf->bbox[0])." ".round($ttf->bbox[1])." ".round($ttf->bbox[2])." ".round($ttf->bbox[3]).']',
  2496. 'ItalicAngle'=>$ttf->italicAngle,
  2497. 'StemV'=>round($ttf->stemV),
  2498. 'MissingWidth'=>round($ttf->defaultWidth));
  2499. $panose = '';
  2500. // mPDF 5.5.19
  2501. if (count($ttf->panose)) {
  2502. $panoseArray = array_merge(array($ttf->sFamilyClass, $ttf->sFamilySubClass), $ttf->panose);
  2503. foreach($panoseArray as $value)
  2504. $panose .= ' '.dechex($value);
  2505. }
  2506. $up = round($ttf->underlinePosition);
  2507. $ut = round($ttf->underlineThickness);
  2508. $originalsize = $ttfstat['size']+0;
  2509. $type = 'TTF';
  2510. //Generate metrics .php file
  2511. $s='<?php'."\n";
  2512. $s.='$name=\''.$name."';\n";
  2513. $s.='$type=\''.$type."';\n";
  2514. $s.='$desc='.var_export($desc,true).";\n";
  2515. $s.='$up='.$up.";\n";
  2516. $s.='$ut='.$ut.";\n";
  2517. $s.='$ttffile=\''.$ttffile."';\n";
  2518. $s.='$TTCfontID=\''.$TTCfontID."';\n";
  2519. $s.='$originalsize='.$originalsize.";\n";
  2520. if ($sip) $s.='$sip=true;'."\n";
  2521. else $s.='$sip=false;'."\n";
  2522. if ($smp) $s.='$smp=true;'."\n";
  2523. else $s.='$smp=false;'."\n";
  2524. if ($BMPonly) $s.='$BMPselected=true;'."\n";
  2525. else $s.='$BMPselected=false;'."\n";
  2526. $s.='$fontkey=\''.$fontkey."';\n";
  2527. $s.='$panose=\''.$panose."';\n";
  2528. if ($this->useKerning) {
  2529. $s.='$kerninfo='.var_export($kerninfo,true).";\n";
  2530. $s.='$haskerninfo=true;'."\n";
  2531. }
  2532. else $s.='$haskerninfo=false;'."\n";
  2533. // mPDF 5.4.05
  2534. if ($this->fontdata[$family]['unAGlyphs']) {
  2535. $s.='$unAGlyphs=true;'."\n";
  2536. }
  2537. else $s.='$unAGlyphs=false;'."\n";
  2538. $s.="?>";
  2539. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  2540. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php',"w");
  2541. fwrite($fh,$s,strlen($s));
  2542. fclose($fh);
  2543. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat',"wb");
  2544. fwrite($fh,$cw,strlen($cw));
  2545. fclose($fh);
  2546. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cgm');
  2547. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.z');
  2548. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw127.php');
  2549. @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw');
  2550. }
  2551. else if ($this->debugfonts) { $this->Error('Cannot write to the font caching directory - '._MPDF_TTFONTDATAPATH); }
  2552. unset($ttf);
  2553. }
  2554. else {
  2555. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat');
  2556. }
  2557. if (isset($this->fontdata[$family]['indic']) && $this->fontdata[$family]['indic']) { $indic = true; }
  2558. else { $indic = false; }
  2559. if (isset($this->fontdata[$family]['sip-ext']) && $this->fontdata[$family]['sip-ext']) { $sipext = $this->fontdata[$family]['sip-ext']; }
  2560. else { $sipext = ''; }
  2561. $i = count($this->fonts)+$this->extraFontSubsets+1;
  2562. if ($sip || $smp) {
  2563. $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
  2564. }
  2565. else {
  2566. $ss = array();
  2567. for ($s=32; $s<128; $s++) { $ss[$s] = $s; }
  2568. $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
  2569. }
  2570. if ($this->useKerning && $haskerninfo) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; }
  2571. $this->FontFiles[$fontkey]=array('length1'=>$originalsize, 'type'=>"TTF", 'ttffile'=>$ttffile, 'sip'=>$sip, 'smp'=>$smp);
  2572. unset($cw);
  2573. }
  2574. function SetFont($family,$style='',$size=0, $write=true, $forcewrite=false) {
  2575. $family=strtolower($family);
  2576. if (!$this->onlyCoreFonts) {
  2577. if ($family == 'sans' || $family == 'sans-serif') { $family = $this->sans_fonts[0]; }
  2578. if ($family == 'serif') { $family = $this->serif_fonts[0]; }
  2579. if ($family == 'mono' || $family == 'monospace') { $family = $this->mono_fonts[0]; }
  2580. }
  2581. if (isset($this->fonttrans[$family]) && $this->fonttrans[$family]) { $family = $this->fonttrans[$family]; }
  2582. if($family=='') {
  2583. if ($this->FontFamily) { $family=$this->FontFamily; }
  2584. else if ($this->default_font) { $family=$this->default_font; }
  2585. else { $this->Error("No font or default font set!"); }
  2586. }
  2587. $this->ReqFontStyle = $style; // required or requested style - used later for artificial bold/italic
  2588. if (($family == 'csymbol') || ($family == 'czapfdingbats') || ($family == 'ctimes') || ($family == 'ccourier') || ($family == 'chelvetica')) {
  2589. if ($this->PDFA || $this->PDFX) {
  2590. if ($family == 'csymbol' || $family == 'czapfdingbats') {
  2591. $this->Error("Symbol and Zapfdingbats cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a).");
  2592. }
  2593. if ($family == 'ctimes' || $family == 'ccourier' || $family == 'chelvetica') {
  2594. 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.)"; }
  2595. if ($family == 'chelvetica') { $family = 'sans'; }
  2596. if ($family == 'ctimes') { $family = 'serif'; }
  2597. if ($family == 'ccourier') { $family = 'mono'; }
  2598. }
  2599. $this->usingCoreFont = false;
  2600. }
  2601. else { $this->usingCoreFont = true; }
  2602. if($family=='csymbol' || $family=='czapfdingbats') { $style=''; }
  2603. }
  2604. else { $this->usingCoreFont = false; }
  2605. $this->U=false;
  2606. $this->S=false;
  2607. if ($style) {
  2608. $style=strtoupper($style);
  2609. if(strpos($style,'U')!==false) {
  2610. $this->U=true;
  2611. $style=str_replace('U','',$style);
  2612. }
  2613. if(strpos($style,'S')!==false) {
  2614. $this->S=true;
  2615. // Small Caps
  2616. if (empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); }
  2617. $style=str_replace('S','',$style);
  2618. }
  2619. if ($style=='IB') $style='BI';
  2620. }
  2621. if ($size==0) $size=$this->FontSizePt;
  2622. $fontkey=$family.$style;
  2623. $stylekey = $style;
  2624. if (!$stylekey) { $stylekey = "R"; }
  2625. if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  2626. if(!isset($this->fonts[$fontkey]) || count($this->default_available_fonts) != count($this->available_unifonts) ) { // not already added
  2627. /*-- CJK-FONTS --*/
  2628. // CJK fonts
  2629. if (in_array($fontkey,$this->available_CJK_fonts)) {
  2630. if(!isset($this->fonts[$fontkey])) { // already added
  2631. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2632. $this->AddCJKFont($family); // don't need to add style
  2633. }
  2634. }
  2635. // Test to see if requested font/style is available - or substitute
  2636. else
  2637. /*-- END CJK-FONTS --*/
  2638. if (!in_array($fontkey,$this->available_unifonts)) {
  2639. // If font[nostyle] exists - set it
  2640. if (in_array($family,$this->available_unifonts)) {
  2641. $style = '';
  2642. }
  2643. // Else if only one font available - set it (assumes if only one font available it will not have a style)
  2644. else if (count($this->available_unifonts) == 1) {
  2645. $family = $this->available_unifonts[0];
  2646. $style = '';
  2647. }
  2648. else {
  2649. $found = 0;
  2650. // else substitute font of similar type
  2651. if (in_array($family,$this->sans_fonts)) {
  2652. $i = array_intersect($this->sans_fonts,$this->available_unifonts);
  2653. if (count($i)) {
  2654. $i = array_values($i);
  2655. // with requested style if possible
  2656. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2657. $style = '';
  2658. }
  2659. $family = $i[0];
  2660. $found = 1;
  2661. }
  2662. }
  2663. else if (in_array($family,$this->serif_fonts)) {
  2664. $i = array_intersect($this->serif_fonts,$this->available_unifonts);
  2665. if (count($i)) {
  2666. $i = array_values($i);
  2667. // with requested style if possible
  2668. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2669. $style = '';
  2670. }
  2671. $family = $i[0];
  2672. $found = 1;
  2673. }
  2674. }
  2675. else if (in_array($family,$this->mono_fonts)) {
  2676. $i = array_intersect($this->mono_fonts,$this->available_unifonts);
  2677. if (count($i)) {
  2678. $i = array_values($i);
  2679. // with requested style if possible
  2680. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2681. $style = '';
  2682. }
  2683. $family = $i[0];
  2684. $found = 1;
  2685. }
  2686. }
  2687. if (!$found) {
  2688. // set first available font
  2689. $fs = $this->available_unifonts[0];
  2690. preg_match('/^([a-z_0-9\-]+)([BI]{0,2})$/',$fs,$fas); // Allow "-"
  2691. // with requested style if possible
  2692. $ws = $fas[1].$style;
  2693. if (in_array($ws,$this->available_unifonts)) {
  2694. $family = $fas[1]; // leave $style as is
  2695. }
  2696. else if (in_array($fas[1],$this->available_unifonts)) {
  2697. // or without style
  2698. $family = $fas[1];
  2699. $style = '';
  2700. }
  2701. else {
  2702. // or with the style specified
  2703. $family = $fas[1];
  2704. $style = $fas[2];
  2705. }
  2706. }
  2707. }
  2708. $fontkey = $family.$style;
  2709. }
  2710. }
  2711. // try to add font (if not already added)
  2712. $this->AddFont($family, $style);
  2713. //Test if font is already selected
  2714. if($this->FontFamily == $family && $this->FontFamily == $this->currentfontfamily && $this->FontStyle == $style && $this->FontStyle == $this->currentfontstyle && $this->FontSizePt == $size && $this->FontSizePt == $this->currentfontsize && !$forcewrite) {
  2715. return $family;
  2716. }
  2717. $fontkey = $family.$style;
  2718. //Select it
  2719. $this->FontFamily = $family;
  2720. $this->FontStyle = $style;
  2721. $this->FontSizePt = $size;
  2722. $this->FontSize = $size / _MPDFK;
  2723. $this->CurrentFont = &$this->fonts[$fontkey];
  2724. if ($write) {
  2725. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2726. 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); }
  2727. $this->pageoutput[$this->page]['Font'] = $fontout;
  2728. }
  2729. // Added - currentfont (lowercase) used in HTML2PDF
  2730. $this->currentfontfamily=$family;
  2731. $this->currentfontsize=$size;
  2732. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2733. $this->setMBencoding('UTF-8');
  2734. }
  2735. else { // if using core fonts
  2736. if ($this->PDFA || $this->PDFX) {
  2737. $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.');
  2738. }
  2739. $this->setMBencoding('windows-1252');
  2740. //Test if font is already selected
  2741. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2742. return $family;
  2743. }
  2744. if (!isset($this->CoreFonts[$fontkey])) {
  2745. if (in_array($family,$this->serif_fonts)) { $family = 'ctimes'; }
  2746. else if (in_array($family,$this->mono_fonts)) { $family = 'ccourier'; }
  2747. else { $family = 'chelvetica'; }
  2748. $this->usingCoreFont = true;
  2749. $fontkey = $family.$style;
  2750. }
  2751. if(!isset($this->fonts[$fontkey])) {
  2752. // STANDARD CORE FONTS
  2753. if (isset($this->CoreFonts[$fontkey])) {
  2754. //Load metric file
  2755. $file=$family;
  2756. if($family=='ctimes' || $family=='chelvetica' || $family=='ccourier') { $file.=strtolower($style); }
  2757. $file.='.php';
  2758. include(_MPDF_PATH.'font/'.$file);
  2759. if(!isset($cw)) { $this->Error('Could not include font metric file'); }
  2760. $i=count($this->fonts)+$this->extraFontSubsets+1;
  2761. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw);
  2762. if ($this->useKerning) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; }
  2763. }
  2764. else {
  2765. die('mPDF error - Font not defined');
  2766. }
  2767. }
  2768. //Test if font is already selected
  2769. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2770. return $family;
  2771. }
  2772. //Select it
  2773. $this->FontFamily=$family;
  2774. $this->FontStyle=$style;
  2775. $this->FontSizePt=$size;
  2776. $this->FontSize=$size/_MPDFK;
  2777. $this->CurrentFont=&$this->fonts[$fontkey];
  2778. if ($write) {
  2779. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2780. 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); }
  2781. $this->pageoutput[$this->page]['Font'] = $fontout;
  2782. }
  2783. // Added - currentfont (lowercase) used in HTML2PDF
  2784. $this->currentfontfamily=$family;
  2785. $this->currentfontsize=$size;
  2786. $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : '');
  2787. }
  2788. return $family;
  2789. }
  2790. function SetFontSize($size,$write=true) {
  2791. //Set font size in points
  2792. if($this->FontSizePt==$size) return;
  2793. $this->FontSizePt=$size;
  2794. $this->FontSize=$size/_MPDFK;
  2795. $this->currentfontsize=$size;
  2796. if ($write) {
  2797. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2798. // Edited mPDF 3.0
  2799. 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); }
  2800. $this->pageoutput[$this->page]['Font'] = $fontout;
  2801. }
  2802. }
  2803. function AddLink() {
  2804. //Create a new internal link
  2805. $n=count($this->links)+1;
  2806. $this->links[$n]=array(0,0);
  2807. return $n;
  2808. }
  2809. function SetLink($link,$y=0,$page=-1) {
  2810. //Set destination of internal link
  2811. if($y==-1) $y=$this->y;
  2812. if($page==-1) $page=$this->page;
  2813. $this->links[$link]=array($page,$y);
  2814. }
  2815. function Link($x,$y,$w,$h,$link) {
  2816. $l = array($x*_MPDFK,$this->hPt-$y*_MPDFK,$w*_MPDFK,$h*_MPDFK,$link);
  2817. if ($this->keep_block_together) { // Save to array - don't write yet
  2818. $this->ktLinks[$this->page][]= $l;
  2819. return;
  2820. }
  2821. else if ($this->table_rotate) { // *TABLES*
  2822. $this->tbrot_Links[$this->page][]= $l; // *TABLES*
  2823. return; // *TABLES*
  2824. } // *TABLES*
  2825. else if ($this->kwt) {
  2826. $this->kwt_Links[$this->page][]= $l;
  2827. return;
  2828. }
  2829. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  2830. $this->HTMLheaderPageLinks[]= $l;
  2831. return;
  2832. }
  2833. //Put a link on the page
  2834. $this->PageLinks[$this->page][]= $l;
  2835. // Save cross-reference to Column buffer
  2836. $ref = count($this->PageLinks[$this->page])-1; // *COLUMNS*
  2837. $this->columnLinks[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref; // *COLUMNS*
  2838. }
  2839. function Text($x,$y,$txt) {
  2840. // Output a string
  2841. // Called (internally) by Watermark and _tableWrite [rotated cells]
  2842. // Expects input to be mb_encoded if necessary and RTL reversed
  2843. // ARTIFICIAL BOLD AND ITALIC
  2844. $s = 'q ';
  2845. if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false) {
  2846. $s .= '2 Tr 1 J 1 j ';
  2847. $s .= sprintf('%.3F w ',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight);
  2848. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2849. if($this->FillColor!=$tc) { $s .= $tc.' '; } // stroke (outline) = same colour as text(fill)
  2850. }
  2851. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) {
  2852. $aix = '1 0 0.261799 1 %.3F %.3F Tm';
  2853. }
  2854. else { $aix = '%.3F %.3F Td'; }
  2855. if($this->ColorFlag) $s.=$this->TextColor.' ';
  2856. $this->CurrentFont['used']= true;
  2857. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) {
  2858. $txt2 = str_replace(chr(194).chr(160),chr(32),$txt);
  2859. $txt2 = $this->UTF8toSubset($txt2);
  2860. $s.=sprintf('BT '.$aix.' %s Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$txt2);
  2861. }
  2862. else if (!$this->usingCoreFont) {
  2863. $txt2 = str_replace(chr(194).chr(160),chr(32),$txt);
  2864. $this->UTF8StringToArray($txt2); // this is just to add chars to subset list
  2865. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); }
  2866. else {
  2867. //Convert string to UTF-16BE without BOM
  2868. $txt2= $this->UTF8ToUTF16BE($txt2, false);
  2869. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2));
  2870. }
  2871. }
  2872. else {
  2873. $txt2 = str_replace(chr(160),chr(32),$txt);
  2874. if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); }
  2875. else {
  2876. $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2));
  2877. }
  2878. }
  2879. if($this->U && $txt!='') {
  2880. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2881. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  2882. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  2883. else { $up = -100; }
  2884. $adjusty = (-$up/1000* $this->FontSize);
  2885. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  2886. else { $ut = 60/1000* $this->FontSize; }
  2887. $olw = $this->LineWidth;
  2888. $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK));
  2889. $s.=' '.$this->_dounderline($x,$y + $adjusty,$txt);
  2890. $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK));
  2891. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  2892. }
  2893. // STRIKETHROUGH
  2894. if($this->strike && $txt!='') {
  2895. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2896. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  2897. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  2898. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  2899. else { $ch = 700; }
  2900. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  2901. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  2902. else { $ut = 60/1000* $this->FontSize; }
  2903. $olw = $this->LineWidth;
  2904. $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK));
  2905. $s.=' '.$this->_dounderline($x,$y+$adjusty,$txt);
  2906. $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK));
  2907. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  2908. }
  2909. $s .= 'Q';
  2910. $this->_out($s);
  2911. }
  2912. /*-- DIRECTW --*/
  2913. function WriteText($x,$y,$txt) {
  2914. // Output a string using Text() but does encoding and text reversing of RTL
  2915. $txt = $this->purify_utf8_text($txt);
  2916. if ($this->text_input_as_HTML) {
  2917. $txt = $this->all_entities_to_utf8($txt);
  2918. }
  2919. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2920. // DIRECTIONALITY
  2921. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  2922. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  2923. // Font-specific ligature substitution for Indic fonts
  2924. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  2925. $this->Text($x,$y,$txt);
  2926. }
  2927. function WriteCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0) {
  2928. //Output a cell using Cell() but does encoding and text reversing of RTL
  2929. $txt = $this->purify_utf8_text($txt);
  2930. if ($this->text_input_as_HTML) {
  2931. $txt = $this->all_entities_to_utf8($txt);
  2932. }
  2933. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2934. // DIRECTIONALITY
  2935. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  2936. $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL*
  2937. // Font-specific ligature substitution for Indic fonts
  2938. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC*
  2939. $this->Cell($w,$h,$txt,$border,$ln,$align,$fill,$link, $currentx);
  2940. }
  2941. /*-- END DIRECTW --*/
  2942. function ResetSpacing() {
  2943. if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2944. $this->ws=0;
  2945. if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2946. $this->charspacing=0;
  2947. }
  2948. function SetSpacing($cs,$ws) {
  2949. if (intval($cs*1000)==0) { $cs = 0; }
  2950. if ($cs) { $this->_out(sprintf('BT %.3F Tc ET',$cs)); }
  2951. else if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2952. $this->charspacing=$cs;
  2953. if (intval($ws*1000)==0) { $ws = 0; }
  2954. if ($ws) { $this->_out(sprintf('BT %.3F Tw ET',$ws)); }
  2955. else if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2956. $this->ws=$ws;
  2957. }
  2958. // WORD SPACING
  2959. function GetJspacing($nc,$ns,$w,$inclCursive) {
  2960. $ws = 0;
  2961. $charspacing = 0;
  2962. $ww = $this->jSWord;
  2963. $ncx = $nc-1;
  2964. if ($nc == 0) { return array(0,0); }
  2965. else if ($nc==1) { $charspacing = $w; }
  2966. // Only word spacing allowed / possible
  2967. else if ($this->fixedlSpacing !== false || $inclCursive) {
  2968. if ($ns) { $ws = $w / $ns; }
  2969. }
  2970. else if (!$ns) {
  2971. $charspacing = $w / ($ncx );
  2972. if (($this->jSmaxChar > 0) && ($charspacing > $this->jSmaxChar)) {
  2973. $charspacing = $this->jSmaxChar;
  2974. }
  2975. }
  2976. else if ($ns == ($ncx )) {
  2977. $charspacing = $w / $ns;
  2978. }
  2979. else {
  2980. if ($this->usingCoreFont) {
  2981. $cs = ($w * (1 - $this->jSWord)) / ($ncx );
  2982. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  2983. $cs = $this->jSmaxChar;
  2984. $ww = 1 - (($cs * ($ncx ))/$w);
  2985. }
  2986. $charspacing = $cs;
  2987. $ws = ($w * ($ww) ) / $ns;
  2988. }
  2989. else {
  2990. $cs = ($w * (1 - $this->jSWord)) / ($ncx -$ns);
  2991. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  2992. $cs = $this->jSmaxChar;
  2993. $ww = 1 - (($cs * ($ncx -$ns))/$w);
  2994. }
  2995. $charspacing = $cs;
  2996. $ws = (($w * ($ww) ) / $ns) - $charspacing;
  2997. }
  2998. }
  2999. return array($charspacing,$ws);
  3000. }
  3001. 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) {
  3002. //Output a cell
  3003. // Expects input to be mb_encoded if necessary and RTL reversed
  3004. // NON_BREAKING SPACE
  3005. if ($this->usingCoreFont) {
  3006. $txt = str_replace(chr(160),chr(32),$txt);
  3007. }
  3008. else {
  3009. $txt = str_replace(chr(194).chr(160),chr(32),$txt);
  3010. }
  3011. $oldcolumn = $this->CurrCol;
  3012. // Automatic page break
  3013. // Allows PAGE-BREAK-AFTER = avoid to work
  3014. if (!$this->tableLevel && (($this->y+$this->divheight>$this->PageBreakTrigger) || ($this->y+$h>$this->PageBreakTrigger) ||
  3015. ($this->y+($h*2)>$this->PageBreakTrigger && $this->blk[$this->blklvl]['page_break_after_avoid'])) and !$this->InFooter and $this->AcceptPageBreak()) {
  3016. $x=$this->x;//Current X position
  3017. // WORD SPACING
  3018. $ws=$this->ws;//Word Spacing
  3019. $charspacing=$this->charspacing;//Character Spacing
  3020. $this->ResetSpacing();
  3021. $this->AddPage($this->CurOrientation);
  3022. // Added to correct for OddEven Margins
  3023. $x += $this->MarginCorrection;
  3024. if ($currentx) {
  3025. $currentx += $this->MarginCorrection;
  3026. }
  3027. $this->x=$x;
  3028. // WORD SPACING
  3029. $this->SetSpacing($charspacing,$ws);
  3030. }
  3031. // Test: to put line through centre of cell: $this->Line($this->x,$this->y+($h/2),$this->x+50,$this->y+($h/2));
  3032. /*-- COLUMNS --*/
  3033. // COLS
  3034. // COLUMN CHANGE
  3035. if ($this->CurrCol != $oldcolumn) {
  3036. if ($currentx) {
  3037. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3038. }
  3039. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3040. }
  3041. // COLUMNS Update/overwrite the lowest bottom of printing y value for a column
  3042. if ($this->ColActive) {
  3043. if ($h) { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h; }
  3044. else { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$this->divheight; }
  3045. }
  3046. /*-- END COLUMNS --*/
  3047. // KEEP BLOCK TOGETHER Update/overwrite the lowest bottom of printing y value on first page
  3048. if ($this->keep_block_together) {
  3049. if ($h) { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h; }
  3050. // else { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$this->divheight; }
  3051. }
  3052. if($w==0) $w = $this->w-$this->rMargin-$this->x;
  3053. $s='';
  3054. if($fill==1 && $this->FillColor) {
  3055. 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.' '; }
  3056. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  3057. }
  3058. $boxtop = $this->y;
  3059. $boxheight = $h;
  3060. $boxbottom = $this->y+$h;
  3061. if($txt!='') {
  3062. // FONT SIZE - this determines the baseline caculation
  3063. if ($this->linemaxfontsize && !$this->processingHeader) { $bfs = $this->linemaxfontsize; }
  3064. else { $bfs = $this->FontSize; }
  3065. //Calculate baseline Superscript and Subscript Y coordinate adjustment
  3066. $bfx = $this->baselineC;
  3067. $baseline = $bfx*$bfs;
  3068. if($this->SUP) { $baseline += ($bfx-1.05)*$this->FontSize; }
  3069. else if($this->SUB) { $baseline += ($bfx + 0.04)*$this->FontSize; }
  3070. else if($this->bullet) { $baseline += ($bfx-0.7)*$this->FontSize; }
  3071. // Vertical align (for Images)
  3072. if ($abovefont || $belowfont) { // from flowing block - valign always M
  3073. $va = $abovefont + (0.5*$bfs);
  3074. }
  3075. else if ($this->lineheight_correction) {
  3076. if ($valign == 'T') { $va = (0.5 * $bfs * $this->lineheight_correction); }
  3077. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->lineheight_correction); }
  3078. else { $va = 0.5*$h; } // Middle
  3079. }
  3080. else {
  3081. if ($valign == 'T') { $va = (0.5 * $bfs * $this->default_lineheight_correction); }
  3082. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->default_lineheight_correction); }
  3083. else { $va = 0.5*$h; } // Middle
  3084. }
  3085. // ONLY SET THESE IF WANT TO CONFINE BORDER +/- FILL TO FIT FONTSIZE - NOT FULL CELL AS IS ORIGINAL FUNCTION
  3086. // spanfill or spanborder are set in FlowingBlock functions
  3087. if ($spanfill || !empty($this->spanborddet) || $link!='') {
  3088. $exth = 0.2; // Add to fontsize to increase height of background / link / border
  3089. $boxtop = $this->y+$baseline+$va-($this->FontSize*(1+$exth/2)*(0.5+$bfx));
  3090. $boxheight = $this->FontSize * (1+$exth);
  3091. $boxbottom = $boxtop + $boxheight;
  3092. }
  3093. }
  3094. $bbw = $tbw = $lbw = $rbw = 0; // Border widths
  3095. if (!empty($this->spanborddet)) {
  3096. if (!isset($this->spanborddet['B'])) { $this->spanborddet['B'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3097. if (!isset($this->spanborddet['T'])) { $this->spanborddet['T'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3098. if (!isset($this->spanborddet['L'])) { $this->spanborddet['L'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3099. if (!isset($this->spanborddet['R'])) { $this->spanborddet['R'] = array('s' => 0, 'style' => '', 'w' => 0); }
  3100. $bbw = $this->spanborddet['B']['w'];
  3101. $tbw = $this->spanborddet['T']['w'];
  3102. $lbw = $this->spanborddet['L']['w'];
  3103. $rbw = $this->spanborddet['R']['w'];
  3104. }
  3105. if($fill==1 || $border==1 || !empty($this->spanborddet)) {
  3106. if (!empty($this->spanborddet)) {
  3107. if ($fill==1) {
  3108. $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);
  3109. }
  3110. $s.= ' q ';
  3111. $dashon = 3;
  3112. $dashoff = 3.5;
  3113. $dot = 2.5;
  3114. if($tbw) {
  3115. $short = 0;
  3116. if ($this->spanborddet['T']['style'] == 'dashed') {
  3117. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$tbw*$dashon*_MPDFK,$tbw*$dashoff*_MPDFK);
  3118. }
  3119. else if ($this->spanborddet['T']['style'] == 'dotted') {
  3120. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$tbw*$dot*_MPDFK,-$tbw/2*_MPDFK);
  3121. $short = $tbw/2;
  3122. }
  3123. else {
  3124. $s.=' 0 j 0 J [] 0 d ';
  3125. }
  3126. $c = $this->SetDColor($this->spanborddet['T']['c'],true);
  3127. if ($this->spanborddet['T']['style'] == 'double') {
  3128. $s.=sprintf(' %s %.3F w ',$c,$tbw/3*_MPDFK);
  3129. $xadj = $xadj2 = 0;
  3130. if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; }
  3131. if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; }
  3132. $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);
  3133. $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);
  3134. }
  3135. else {
  3136. $s.=sprintf(' %s %.3F w ',$c,$tbw*_MPDFK);
  3137. $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);
  3138. }
  3139. }
  3140. if($bbw) {
  3141. $short = 0;
  3142. if ($this->spanborddet['B']['style'] == 'dashed') {
  3143. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$bbw*$dashon*_MPDFK,$bbw*$dashoff*_MPDFK);
  3144. }
  3145. else if ($this->spanborddet['B']['style'] == 'dotted') {
  3146. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$bbw*$dot*_MPDFK,-$bbw/2*_MPDFK);
  3147. $short = $bbw/2;
  3148. }
  3149. else {
  3150. $s.=' 0 j 0 J [] 0 d ';
  3151. }
  3152. $c = $this->SetDColor($this->spanborddet['B']['c'],true);
  3153. if ($this->spanborddet['B']['style'] == 'double') {
  3154. $s.=sprintf(' %s %.3F w ',$c,$bbw/3*_MPDFK);
  3155. $xadj = $xadj2 = 0;
  3156. if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; }
  3157. if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; }
  3158. $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);
  3159. $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);
  3160. }
  3161. else {
  3162. $s.=sprintf(' %s %.3F w ',$c,$bbw*_MPDFK);
  3163. $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);
  3164. }
  3165. }
  3166. if($lbw) {
  3167. $short = 0;
  3168. if ($this->spanborddet['L']['style'] == 'dashed') {
  3169. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$lbw*$dashon*_MPDFK,$lbw*$dashoff*_MPDFK);
  3170. }
  3171. else if ($this->spanborddet['L']['style'] == 'dotted') {
  3172. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$lbw*$dot*_MPDFK,-$lbw/2*_MPDFK);
  3173. $short = $lbw/2;
  3174. }
  3175. else {
  3176. $s.=' 0 j 0 J [] 0 d ';
  3177. }
  3178. $c = $this->SetDColor($this->spanborddet['L']['c'],true);
  3179. if ($this->spanborddet['L']['style'] == 'double') {
  3180. $s.=sprintf(' %s %.3F w ',$c,$lbw/3*_MPDFK);
  3181. $yadj = $yadj2 = 0;
  3182. if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; }
  3183. if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; }
  3184. $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);
  3185. $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);
  3186. }
  3187. else {
  3188. $s.=sprintf(' %s %.3F w ',$c,$lbw*_MPDFK);
  3189. $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);
  3190. }
  3191. }
  3192. if($rbw) {
  3193. $short = 0;
  3194. if ($this->spanborddet['R']['style'] == 'dashed') {
  3195. $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$rbw*$dashon*_MPDFK,$rbw*$dashoff*_MPDFK);
  3196. }
  3197. else if ($this->spanborddet['R']['style'] == 'dotted') {
  3198. $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$rbw*$dot*_MPDFK,-$rbw/2*_MPDFK);
  3199. $short = $rbw/2;
  3200. }
  3201. else {
  3202. $s.=' 0 j 0 J [] 0 d ';
  3203. }
  3204. $c = $this->SetDColor($this->spanborddet['R']['c'],true);
  3205. if ($this->spanborddet['R']['style'] == 'double') {
  3206. $s.=sprintf(' %s %.3F w ',$c,$rbw/3*_MPDFK);
  3207. $yadj = $yadj2 = 0;
  3208. if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; }
  3209. if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; }
  3210. $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);
  3211. $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);
  3212. }
  3213. else {
  3214. $s.=sprintf(' %s %.3F w ',$c,$rbw*_MPDFK);
  3215. $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);
  3216. }
  3217. }
  3218. $s.= ' Q ';
  3219. }
  3220. else {
  3221. if ($fill==1) $op=($border==1) ? 'B' : 'f';
  3222. else $op='S';
  3223. $s.=sprintf('%.3F %.3F %.3F %.3F re %s ',$this->x*_MPDFK,($this->h-$boxtop)*_MPDFK,$w*_MPDFK,-$boxheight*_MPDFK,$op);
  3224. }
  3225. }
  3226. if(is_string($border)) {
  3227. $x=$this->x;
  3228. $y=$this->y;
  3229. if(is_int(strpos($border,'L')))
  3230. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,$x*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3231. if(is_int(strpos($border,'T')))
  3232. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK);
  3233. if(is_int(strpos($border,'R')))
  3234. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3235. if(is_int(strpos($border,'B')))
  3236. $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-($boxbottom))*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK);
  3237. }
  3238. if($txt!='') {
  3239. if ($exactWidth)
  3240. $stringWidth = $w;
  3241. else
  3242. $stringWidth = $this->GetStringWidth($txt) + ( $this->charspacing * mb_strlen( $txt, $this->mb_enc ) / _MPDFK )
  3243. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ) / _MPDFK );
  3244. // Set x OFFSET FOR PRINTING
  3245. if($align=='R') {
  3246. $dx=$w-$this->cMarginR - $stringWidth - $lcpaddingR;
  3247. }
  3248. elseif($align=='C') {
  3249. $dx=(($w - $stringWidth )/2);
  3250. }
  3251. elseif($align=='L' or $align=='J') $dx=$this->cMarginL + $lcpaddingL;
  3252. else $dx = 0;
  3253. if($this->ColorFlag) $s .='q '.$this->TextColor.' ';
  3254. // OUTLINE
  3255. if($this->outline_on && !$this->S) {
  3256. $s .=' '.sprintf('%.3F w',$this->LineWidth*_MPDFK).' ';
  3257. $s .=" $this->DrawColor ";
  3258. $s .=" 2 Tr ";
  3259. }
  3260. 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
  3261. $s .= ' 2 Tr 1 J 1 j ';
  3262. $s .= ' '.sprintf('%.3F w',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight).' ';
  3263. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3264. if($this->FillColor!=$tc) { $s .= ' '.$tc.' '; } // stroke (outline) = same colour as text(fill)
  3265. }
  3266. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) { // Artificial italic
  3267. $aix = '1 0 0.261799 1 %.3F %.3F Tm ';
  3268. }
  3269. else { $aix = '%.3F %.3F Td '; }
  3270. // THE TEXT
  3271. $sub = '';
  3272. $this->CurrentFont['used']= true;
  3273. // WORD SPACING
  3274. // IF multibyte - Tw has no effect - need to use alternative method - do word spacing using an adjustment before each space
  3275. if ($this->ws && !$this->usingCoreFont && !$this->CurrentFont['sip'] && !$this->CurrentFont['smp'] && !$this->S) {
  3276. $sub .= ' BT 0 Tw ET ';
  3277. if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt, 'MBTw', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); }
  3278. else {
  3279. $space = " ";
  3280. //Convert string to UTF-16BE without BOM
  3281. $space= $this->UTF8ToUTF16BE($space , false);
  3282. $space=$this->_escape($space );
  3283. $sub .=sprintf('BT '.$aix,($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK);
  3284. $t = explode(' ',$txt);
  3285. $sub .=sprintf(' %.3F Tc [',$this->charspacing);
  3286. $numt = count($t);
  3287. for($i=0;$i<$numt;$i++) {
  3288. $tx = $t[$i];
  3289. //Convert string to UTF-16BE without BOM
  3290. $tx = $this->UTF8ToUTF16BE($tx , false);
  3291. $tx = $this->_escape($tx);
  3292. $sub .=sprintf('(%s) ',$tx);
  3293. if (($i+1)<$numt) {
  3294. $adj = -($this->ws)*1000/$this->FontSizePt;
  3295. $sub .=sprintf('%d(%s) ',$adj,$space);
  3296. }
  3297. }
  3298. $sub .='] TJ ';
  3299. $sub .=' ET';
  3300. }
  3301. }
  3302. else {
  3303. $txt2= $txt;
  3304. if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) {
  3305. if ($this->S) { $sub .= $this->_smallCaps($txt2, 'SIPSMP', $aix, $dx, _MPDFK, $baseline, $va); }
  3306. else {
  3307. $txt2 = $this->UTF8toSubset($txt2);
  3308. $sub .=sprintf('BT '.$aix.' %s Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2);
  3309. }
  3310. }
  3311. else {
  3312. if ($this->S) { $sub .= $this->_smallCaps($txt2, '', $aix, $dx, _MPDFK, $baseline, $va); }
  3313. else if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt2, '', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); }
  3314. else {
  3315. if (!$this->usingCoreFont) {
  3316. $txt2 = $this->UTF8ToUTF16BE($txt2, false);
  3317. }
  3318. $txt2=$this->_escape($txt2);
  3319. $sub .=sprintf('BT '.$aix.' (%s) Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2);
  3320. }
  3321. }
  3322. }
  3323. // UNDERLINE
  3324. if($this->U) {
  3325. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3326. if($this->FillColor!=$c) { $sub .= ' '.$c.' '; }
  3327. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  3328. else { $up = -100; }
  3329. $adjusty = (-$up/1000* $this->FontSize);
  3330. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3331. else { $ut = 60/1000* $this->FontSize; }
  3332. $olw = $this->LineWidth;
  3333. $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK));
  3334. $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3335. $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK));
  3336. if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; }
  3337. }
  3338. // STRIKETHROUGH
  3339. if($this->strike) {
  3340. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  3341. if($this->FillColor!=$c) { $sub .= ' '.$c.' '; }
  3342. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  3343. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  3344. else { $ch = 700; }
  3345. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  3346. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  3347. else { $ut = 60/1000* $this->FontSize; }
  3348. $olw = $this->LineWidth;
  3349. $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK));
  3350. $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  3351. $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK));
  3352. if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; }
  3353. }
  3354. // TEXT SHADOW
  3355. if ($this->textshadow) { // First to process is last in CSS comma separated shadows
  3356. foreach($this->textshadow AS $ts) {
  3357. $s .= ' q ';
  3358. $s .= $this->SetTColor($ts['col'], true)."\n";
  3359. if ($ts['col']{0}==5 && ord($ts['col']{4})<100) { // RGBa
  3360. $s .= $this->SetAlpha(ord($ts['col']{4})/100, 'Normal', true, 'F')."\n";
  3361. }
  3362. else if ($ts['col']{0}==6 && ord($ts['col']{5})<100) { // CMYKa
  3363. $s .= $this->SetAlpha(ord($ts['col']{5})/100, 'Normal', true, 'F')."\n";
  3364. }
  3365. else if ($ts['col']{0}==1 && $ts['col']{2}==1 && ord($ts['col']{3})<100) { // Gray
  3366. $s .= $this->SetAlpha(ord($ts['col']{3})/100, 'Normal', true, 'F')."\n";
  3367. }
  3368. $s .= sprintf(' 1 0 0 1 %.4F %.4F cm', $ts['x']*_MPDFK, -$ts['y']*_MPDFK)."\n";
  3369. $s .= $sub;
  3370. $s .= ' Q ';
  3371. }
  3372. }
  3373. $s .= $sub;
  3374. // COLOR
  3375. if($this->ColorFlag) $s .=' Q';
  3376. // LINK
  3377. if($link!='') {
  3378. $this->Link($this->x,$boxtop,$w,$boxheight,$link);
  3379. }
  3380. }
  3381. if($s) $this->_out($s);
  3382. // WORD SPACING
  3383. if ($this->ws && !$this->usingCoreFont) {
  3384. $this->_out(sprintf('BT %.3F Tc ET',$this->charspacing));
  3385. }
  3386. $this->lasth=$h;
  3387. if( strpos($txt,"\n") !== false) $ln=1; // cell recognizes \n from <BR> tag
  3388. if($ln>0)
  3389. {
  3390. //Go to next line
  3391. $this->y += $h;
  3392. if($ln==1) {
  3393. //Move to next line
  3394. if ($currentx != 0) { $this->x=$currentx; }
  3395. else { $this->x=$this->lMargin; }
  3396. }
  3397. }
  3398. else $this->x+=$w;
  3399. }
  3400. function _kern($txt, $mode, $aix, $x, $y) {
  3401. if ($mode == 'MBTw') { // Multibyte requiring word spacing
  3402. $space = ' ';
  3403. //Convert string to UTF-16BE without BOM
  3404. $space= $this->UTF8ToUTF16BE($space , false);
  3405. $space=$this->_escape($space );
  3406. $s = sprintf(' BT '.$aix,$x*_MPDFK,($this->h-$y)*_MPDFK);
  3407. $t = explode(' ',$txt);
  3408. for($i=0;$i<count($t);$i++) {
  3409. $tx = $t[$i];
  3410. $tj = '(';
  3411. $unicode = $this->UTF8StringToArray($tx);
  3412. for($ti=0;$ti<count($unicode);$ti++) {
  3413. if ($ti > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]])) {
  3414. $kern = -$this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]];
  3415. $tj .= sprintf(')%d(',$kern);
  3416. }
  3417. $tc = code2utf($unicode[$ti]);
  3418. $tc = $this->UTF8ToUTF16BE($tc, false);
  3419. $tj .= $this->_escape($tc);
  3420. }
  3421. $tj .= ')';
  3422. $s.=sprintf(' %.3F Tc [%s] TJ',$this->charspacing,$tj);
  3423. if (($i+1)<count($t)) {
  3424. $s.=sprintf(' %.3F Tc (%s) Tj',$this->ws+$this->charspacing,$space);
  3425. }
  3426. }
  3427. $s.=' ET ';
  3428. }
  3429. else if (!$this->usingCoreFont) {
  3430. $s = '';
  3431. $tj = '(';
  3432. $unicode = $this->UTF8StringToArray($txt);
  3433. for($i=0;$i<count($unicode);$i++) {
  3434. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]])) {
  3435. $kern = -$this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]];
  3436. $tj .= sprintf(')%d(',$kern);
  3437. }
  3438. $tx = code2utf($unicode[$i]);
  3439. $tx = $this->UTF8ToUTF16BE($tx, false);
  3440. $tj .= $this->_escape($tx);
  3441. }
  3442. $tj .= ')';
  3443. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj);
  3444. }
  3445. else { // CORE Font
  3446. $s = '';
  3447. $tj = '(';
  3448. $l = strlen($txt);
  3449. for($i=0;$i<$l;$i++) {
  3450. if ($i > 0 && isset($this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]])) {
  3451. $kern = -$this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]];
  3452. $tj .= sprintf(')%d(',$kern);
  3453. }
  3454. $tj .= $this->_escape($txt[$i]);
  3455. }
  3456. $tj .= ')';
  3457. $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj);
  3458. }
  3459. return $s;
  3460. }
  3461. function _smallCaps($txt, $mode, $aix, $dx, $k, $baseline, $va) {
  3462. $upp = false;
  3463. $str = array();
  3464. $bits = array();
  3465. if (!$this->usingCoreFont) {
  3466. $unicode = $this->UTF8StringToArray($txt);
  3467. foreach($unicode as $char) {
  3468. if ($this->ws && $char == 32) { // space
  3469. if (count($str)) { $bits[] = array($upp, $str, false); }
  3470. $bits[] = array(false, array(32), true);
  3471. $str = array();
  3472. $upp = false;
  3473. }
  3474. else if (isset($this->upperCase[$char])) {
  3475. if (!$upp) {
  3476. if (count($str)) { $bits[] = array($upp, $str, false); }
  3477. $str = array();
  3478. }
  3479. $str[] = $this->upperCase[$char];
  3480. if ((!isset($this->CurrentFont['sip']) || !$this->CurrentFont['sip']) && (!isset($this->CurrentFont['smp']) || !$this->CurrentFont['smp'])) {
  3481. $this->CurrentFont['subset'][$this->upperCase[$char]] = $this->upperCase[$char];
  3482. }
  3483. $upp = true;
  3484. }
  3485. else {
  3486. if ($upp) {
  3487. if (count($str)) { $bits[] = array($upp, $str, false); }
  3488. $str = array();
  3489. }
  3490. $str[] = $char;
  3491. $upp = false;
  3492. }
  3493. }
  3494. }
  3495. else {
  3496. for($i=0;$i<strlen($txt);$i++) {
  3497. if (isset($this->upperCase[ord($txt[$i])]) && $this->upperCase[ord($txt[$i])] < 256) {
  3498. if (!$upp) {
  3499. if (count($str)) { $bits[] = array($upp, $str, false); }
  3500. $str = array();
  3501. }
  3502. $str[] = $this->upperCase[ord($txt[$i])];
  3503. $upp = true;
  3504. }
  3505. else {
  3506. if ($upp) {
  3507. if (count($str)) { $bits[] = array($upp, $str, false); }
  3508. $str = array();
  3509. }
  3510. $str[] = ord($txt[$i]);
  3511. $upp = false;
  3512. }
  3513. }
  3514. }
  3515. if (count($str)) { $bits[] = array($upp, $str, false); }
  3516. $fid = $this->CurrentFont['i'];
  3517. $s=sprintf(' BT '.$aix,($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k);
  3518. foreach($bits AS $b) {
  3519. if ($b[0]) { $upp = true; }
  3520. else { $upp = false; }
  3521. $size = count ($b[1]);
  3522. $txt = '';
  3523. for ($i = 0; $i < $size; $i++) {
  3524. $txt .= code2utf($b[1][$i]);
  3525. }
  3526. if ($this->usingCoreFont) {
  3527. $txt = utf8_decode($txt);
  3528. }
  3529. if ($mode == 'SIPSMP') {
  3530. $txt = $this->UTF8toSubset($txt);
  3531. }
  3532. else {
  3533. if (!$this->usingCoreFont) {
  3534. $txt = $this->UTF8ToUTF16BE($txt, false);
  3535. }
  3536. $txt=$this->_escape($txt);
  3537. $txt = '('.$txt.')';
  3538. }
  3539. if ($b[2]) { // space
  3540. $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100);
  3541. $s.=sprintf(' %.3F Tc', ($this->charspacing+$this->ws));
  3542. $s.=sprintf(' %s Tj', $txt);
  3543. }
  3544. else if ($upp) {
  3545. $s.=sprintf(' /F%d %.3F Tf', $fid, $this->FontSizePt*$this->smCapsScale);
  3546. $s.=sprintf(' %d Tz', $this->smCapsStretch);
  3547. $s.=sprintf(' %.3F Tc', ($this->charspacing*100/$this->smCapsStretch));
  3548. $s.=sprintf(' %s Tj', $txt);
  3549. }
  3550. else {
  3551. $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100);
  3552. $s.=sprintf(' %.3F Tc', ($this->charspacing));
  3553. $s.=sprintf(' %s Tj', $txt);
  3554. }
  3555. }
  3556. $s.=' ET ';
  3557. return $s;
  3558. }
  3559. function MultiCell($w,$h,$txt,$border=0,$align='',$fill=0,$link='',$directionality='ltr',$encoded=false)
  3560. {
  3561. // Parameter (pre-)encoded - When called internally from ToC or textarea: mb_encoding already done - but not reverse RTL/Indic
  3562. if (!$encoded) {
  3563. $txt = $this->purify_utf8_text($txt);
  3564. if ($this->text_input_as_HTML) {
  3565. $txt = $this->all_entities_to_utf8($txt);
  3566. }
  3567. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  3568. // Font-specific ligature substitution for Indic fonts
  3569. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { // *INDIC*
  3570. $this->ConvertIndic($tmp); // *INDIC*
  3571. } // *INDIC*
  3572. if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL*
  3573. }
  3574. if (!$align) { $align = $this->defaultAlign; }
  3575. //Output text with automatic or explicit line breaks
  3576. $cw=&$this->CurrentFont['cw'];
  3577. if($w==0) $w=$this->w-$this->rMargin-$this->x;
  3578. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3579. if ($this->usingCoreFont) {
  3580. $s=str_replace("\r",'',$txt);
  3581. $nb=strlen($s);
  3582. while($nb>0 and $s[$nb-1]=="\n") $nb--;
  3583. }
  3584. else {
  3585. $s=str_replace("\r",'',$txt);
  3586. $nb=mb_strlen($s, $this->mb_enc );
  3587. while($nb>0 and mb_substr($s,$nb-1,1,$this->mb_enc )=="\n") $nb--;
  3588. }
  3589. $b=0;
  3590. if($border) {
  3591. if($border==1) {
  3592. $border='LTRB';
  3593. $b='LRT';
  3594. $b2='LR';
  3595. }
  3596. else {
  3597. $b2='';
  3598. if(is_int(strpos($border,'L'))) $b2.='L';
  3599. if(is_int(strpos($border,'R'))) $b2.='R';
  3600. $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
  3601. }
  3602. }
  3603. $sep=-1;
  3604. $i=0;
  3605. $j=0;
  3606. $l=0;
  3607. $ns=0;
  3608. $nl=1;
  3609. if (!$this->usingCoreFont) {
  3610. $checkCursive=false;
  3611. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  3612. else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  3613. while($i<$nb) {
  3614. //Get next character
  3615. $c = mb_substr($s,$i,1,$this->mb_enc );
  3616. if($c == "\n") {
  3617. //Explicit line break
  3618. // WORD SPACING
  3619. $this->ResetSpacing();
  3620. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3621. // DIRECTIONALITY
  3622. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3623. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3624. $i++;
  3625. $sep=-1;
  3626. $j=$i;
  3627. $l=0;
  3628. $ns=0;
  3629. $nl++;
  3630. if($border and $nl==2) $b=$b2;
  3631. continue;
  3632. }
  3633. if($c == " ") {
  3634. $sep=$i;
  3635. $ls=$l;
  3636. $ns++;
  3637. }
  3638. $l += $this->GetCharWidthNonCore($c);
  3639. if($l>$wmax) {
  3640. //Automatic line break
  3641. if($sep==-1) { // Only one word
  3642. if($i==$j) $i++;
  3643. // WORD SPACING
  3644. $this->ResetSpacing();
  3645. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3646. // DIRECTIONALITY
  3647. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3648. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3649. }
  3650. else {
  3651. $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc));
  3652. if($align=='J') {
  3653. //////////////////////////////////////////
  3654. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3655. // WORD SPACING UNICODE
  3656. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3657. $tmp = str_replace(chr(194).chr(160),chr(32),$tmp );
  3658. $len_ligne = $this->GetStringWidth($tmp );
  3659. $nb_carac = mb_strlen( $tmp , $this->mb_enc ) ;
  3660. $nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3661. $inclCursive=false;
  3662. if ($checkCursive) {
  3663. if (preg_match("/([".$this->pregRTLchars."])/u", $tmp)) { $inclCursive = true; } // *RTL*
  3664. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $tmp)) { $inclCursive = true; } // *INDIC*
  3665. }
  3666. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),$inclCursive);
  3667. $this->SetSpacing($charspacing,$ws);
  3668. //////////////////////////////////////////
  3669. }
  3670. // DIRECTIONALITY
  3671. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3672. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3673. $i=$sep+1;
  3674. }
  3675. $sep=-1;
  3676. $j=$i;
  3677. $l=0;
  3678. $ns=0;
  3679. $nl++;
  3680. if($border and $nl==2) $b=$b2;
  3681. }
  3682. else $i++;
  3683. }
  3684. //Last chunk
  3685. // WORD SPACING
  3686. $this->ResetSpacing();
  3687. }
  3688. else {
  3689. while($i<$nb) {
  3690. //Get next character
  3691. $c=$s[$i];
  3692. if($c == "\n") {
  3693. //Explicit line break
  3694. // WORD SPACING
  3695. $this->ResetSpacing();
  3696. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3697. $i++;
  3698. $sep=-1;
  3699. $j=$i;
  3700. $l=0;
  3701. $ns=0;
  3702. $nl++;
  3703. if($border and $nl==2) $b=$b2;
  3704. continue;
  3705. }
  3706. if($c == " ") {
  3707. $sep=$i;
  3708. $ls=$l;
  3709. $ns++;
  3710. }
  3711. $l += $this->GetCharWidthCore($c);
  3712. if($l>$wmax) {
  3713. //Automatic line break
  3714. if($sep==-1) {
  3715. if($i==$j) $i++;
  3716. // WORD SPACING
  3717. $this->ResetSpacing();
  3718. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3719. }
  3720. else {
  3721. if($align=='J') {
  3722. $tmp = rtrim(substr($s,$j,$sep-$j));
  3723. //////////////////////////////////////////
  3724. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3725. // WORD SPACING NON_UNICDOE/CJK
  3726. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3727. $tmp = str_replace(chr(160),chr(32),$tmp);
  3728. $len_ligne = $this->GetStringWidth($tmp );
  3729. $nb_carac = strlen( $tmp ) ;
  3730. $nb_spaces = substr_count( $tmp ,' ' ) ;
  3731. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),false);
  3732. $this->SetSpacing($charspacing,$ws);
  3733. //////////////////////////////////////////
  3734. }
  3735. $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link);
  3736. $i=$sep+1;
  3737. }
  3738. $sep=-1;
  3739. $j=$i;
  3740. $l=0;
  3741. $ns=0;
  3742. $nl++;
  3743. if($border and $nl==2) $b=$b2;
  3744. }
  3745. else $i++;
  3746. }
  3747. //Last chunk
  3748. // WORD SPACING
  3749. $this->ResetSpacing();
  3750. }
  3751. //Last chunk
  3752. if($border and is_int(strpos($border,'B'))) $b.='B';
  3753. if (!$this->usingCoreFont) {
  3754. $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc));
  3755. // DIRECTIONALITY
  3756. $this->magic_reverse_dir($tmp, true, $directionality); // *RTL*
  3757. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3758. }
  3759. else { $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); }
  3760. $this->x=$this->lMargin;
  3761. }
  3762. /*-- DIRECTW --*/
  3763. function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
  3764. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  3765. if (empty($this->directw)) { $this->directw = new directw($this); }
  3766. $this->directw->Write($h,$txt,$currentx,$link,$directionality,$align);
  3767. }
  3768. /*-- END DIRECTW --*/
  3769. /*-- HTML-CSS --*/
  3770. function saveInlineProperties() {
  3771. $saved = array();
  3772. $saved[ 'family' ] = $this->FontFamily;
  3773. $saved[ 'style' ] = $this->FontStyle;
  3774. $saved[ 'sizePt' ] = $this->FontSizePt;
  3775. $saved[ 'size' ] = $this->FontSize;
  3776. $saved[ 'HREF' ] = $this->HREF;
  3777. $saved[ 'underline' ] = $this->U;
  3778. $saved[ 'smCaps' ] = $this->S;
  3779. $saved[ 'strike' ] = $this->strike;
  3780. $saved[ 'textshadow' ] = $this->textshadow;
  3781. $saved[ 'SUP' ] = $this->SUP;
  3782. $saved[ 'SUB' ] = $this->SUB;
  3783. $saved[ 'linewidth' ] = $this->LineWidth;
  3784. $saved[ 'drawcolor' ] = $this->DrawColor;
  3785. $saved[ 'is_outline' ] = $this->outline_on;
  3786. $saved[ 'outlineparam' ] = $this->outlineparam;
  3787. $saved[ 'toupper' ] = $this->toupper;
  3788. $saved[ 'tolower' ] = $this->tolower;
  3789. $saved[ 'capitalize' ] = $this->capitalize;
  3790. $saved[ 'fontkerning' ] = $this->kerning;
  3791. $saved[ 'lSpacingCSS' ] = $this->lSpacingCSS;
  3792. $saved[ 'wSpacingCSS' ] = $this->wSpacingCSS;
  3793. $saved[ 'I' ] = $this->I;
  3794. $saved[ 'B' ] = $this->B;
  3795. $saved[ 'colorarray' ] = $this->colorarray;
  3796. $saved[ 'bgcolorarray' ] = $this->spanbgcolorarray;
  3797. $saved[ 'border' ] = $this->spanborddet;
  3798. $saved[ 'color' ] = $this->TextColor;
  3799. $saved[ 'bgcolor' ] = $this->FillColor;
  3800. $saved['lang'] = $this->currentLang;
  3801. $saved['display_off'] = $this->inlineDisplayOff;
  3802. return $saved;
  3803. }
  3804. function restoreInlineProperties( &$saved) {
  3805. $FontFamily = $saved[ 'family' ];
  3806. $this->FontStyle = $saved[ 'style' ];
  3807. $this->FontSizePt = $saved[ 'sizePt' ];
  3808. $this->FontSize = $saved[ 'size' ];
  3809. $this->currentLang = $saved['lang'];
  3810. if ($this->useLang && !$this->usingCoreFont) {
  3811. if ($this->currentLang != $this->default_lang && ((strlen($this->currentLang) == 5 && $this->currentLang != 'UTF-8') || strlen($this->currentLang ) == 2)) {
  3812. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($this->currentLang, $this->useAdobeCJK);
  3813. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  3814. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  3815. }
  3816. else {
  3817. $this->RestrictUnicodeFonts($this->default_available_fonts );
  3818. }
  3819. }
  3820. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3821. $this->HREF = $saved[ 'HREF' ];
  3822. $this->U = $saved[ 'underline' ];
  3823. $this->S = $saved[ 'smCaps' ];
  3824. $this->strike = $saved[ 'strike' ];
  3825. $this->textshadow = $saved[ 'textshadow' ];
  3826. $this->SUP = $saved[ 'SUP' ];
  3827. $this->SUB = $saved[ 'SUB' ];
  3828. $this->LineWidth = $saved[ 'linewidth' ];
  3829. $this->DrawColor = $saved[ 'drawcolor' ];
  3830. $this->outline_on = $saved[ 'is_outline' ];
  3831. $this->outlineparam = $saved[ 'outlineparam' ];
  3832. $this->inlineDisplayOff = $saved['display_off'];
  3833. $this->toupper = $saved[ 'toupper' ];
  3834. $this->tolower = $saved[ 'tolower' ];
  3835. $this->capitalize = $saved[ 'capitalize' ];
  3836. $this->kerning = $saved[ 'fontkerning' ];
  3837. $this->lSpacingCSS = $saved[ 'lSpacingCSS' ];
  3838. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  3839. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  3840. }
  3841. else { $this->fixedlSpacing = false; }
  3842. $this->wSpacingCSS = $saved[ 'wSpacingCSS' ];
  3843. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  3844. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  3845. }
  3846. else { $this->minwSpacing = 0; }
  3847. $this->SetFont($FontFamily, $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],false);
  3848. $this->currentfontstyle = $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : '');
  3849. $this->currentfontsize = $saved[ 'sizePt' ];
  3850. $this->SetStylesArray(array('S'=>$this->S, 'U'=>$this->U, 'B'=>$saved[ 'B' ], 'I'=>$saved[ 'I' ]));
  3851. $this->TextColor = $saved[ 'color' ];
  3852. $this->FillColor = $saved[ 'bgcolor' ];
  3853. $this->colorarray = $saved[ 'colorarray' ];
  3854. $cor = $saved[ 'colorarray' ];
  3855. if ($cor) $this->SetTColor($cor);
  3856. $this->spanbgcolorarray = $saved[ 'bgcolorarray' ];
  3857. $cor = $saved[ 'bgcolorarray' ];
  3858. if ($cor) $this->SetFColor($cor);
  3859. $this->spanborddet = $saved[ 'border' ];
  3860. }
  3861. // Used when ColActive for tables - updated to return first block with background fill OR borders
  3862. function GetFirstBlockFill() {
  3863. // Returns the first blocklevel that uses a bgcolor fill
  3864. $startfill = 0;
  3865. for ($i=1;$i<=$this->blklvl;$i++) {
  3866. 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'] ) {
  3867. $startfill = $i;
  3868. break;
  3869. }
  3870. }
  3871. return $startfill;
  3872. }
  3873. function SetBlockFill($blvl) {
  3874. if ($this->blk[$blvl]['bgcolor']) {
  3875. $this->SetFColor($this->blk[$blvl]['bgcolorarray']);
  3876. return 1;
  3877. }
  3878. else {
  3879. $this->SetFColor($this->ConvertColor(255));
  3880. return 0;
  3881. }
  3882. }
  3883. //-------------------------FLOWING BLOCK------------------------------------//
  3884. //The following functions were originally written by Damon Kohler //
  3885. //--------------------------------------------------------------------------//
  3886. function saveFont() {
  3887. $saved = array();
  3888. $saved[ 'family' ] = $this->FontFamily;
  3889. $saved[ 'style' ] = $this->FontStyle;
  3890. $saved[ 'sizePt' ] = $this->FontSizePt;
  3891. $saved[ 'size' ] = $this->FontSize;
  3892. $saved[ 'curr' ] = &$this->CurrentFont;
  3893. $saved[ 'color' ] = $this->TextColor;
  3894. $saved[ 'spanbgcolor' ] = $this->spanbgcolor;
  3895. $saved[ 'spanbgcolorarray' ] = $this->spanbgcolorarray;
  3896. $saved[ 'bord' ] = $this->spanborder;
  3897. $saved[ 'border' ] = $this->spanborddet;
  3898. $saved[ 'HREF' ] = $this->HREF;
  3899. $saved[ 'underline' ] = $this->U;
  3900. $saved[ 'smCaps' ] = $this->S;
  3901. $saved[ 'strike' ] = $this->strike;
  3902. $saved[ 'textshadow' ] = $this->textshadow;
  3903. $saved[ 'SUP' ] = $this->SUP;
  3904. $saved[ 'SUB' ] = $this->SUB;
  3905. $saved[ 'linewidth' ] = $this->LineWidth;
  3906. $saved[ 'drawcolor' ] = $this->DrawColor;
  3907. $saved[ 'is_outline' ] = $this->outline_on;
  3908. $saved[ 'outlineparam' ] = $this->outlineparam;
  3909. $saved[ 'ReqFontStyle' ] = $this->ReqFontStyle;
  3910. $saved[ 'fontkerning' ] = $this->kerning;
  3911. $saved[ 'fixedlSpacing' ] = $this->fixedlSpacing;
  3912. $saved[ 'minwSpacing' ] = $this->minwSpacing;
  3913. return $saved;
  3914. }
  3915. function restoreFont( &$saved, $write=true) {
  3916. if (!isset($saved) || empty($saved)) return;
  3917. $this->FontFamily = $saved[ 'family' ];
  3918. $this->FontStyle = $saved[ 'style' ];
  3919. $this->FontSizePt = $saved[ 'sizePt' ];
  3920. $this->FontSize = $saved[ 'size' ];
  3921. $this->CurrentFont = &$saved[ 'curr' ];
  3922. $this->TextColor = $saved[ 'color' ];
  3923. $this->spanbgcolor = $saved[ 'spanbgcolor' ];
  3924. $this->spanbgcolorarray = $saved[ 'spanbgcolorarray' ];
  3925. $this->spanborder = $saved[ 'bord' ];
  3926. $this->spanborddet = $saved[ 'border' ];
  3927. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3928. $this->HREF = $saved[ 'HREF' ];
  3929. $this->U = $saved[ 'underline' ];
  3930. $this->S = $saved[ 'smCaps' ];
  3931. $this->kerning = $saved[ 'fontkerning' ];
  3932. $this->fixedlSpacing = $saved[ 'fixedlSpacing' ];
  3933. $this->minwSpacing = $saved[ 'minwSpacing' ];
  3934. $this->strike = $saved[ 'strike' ];
  3935. $this->textshadow = $saved[ 'textshadow' ];
  3936. $this->SUP = $saved[ 'SUP' ];
  3937. $this->SUB = $saved[ 'SUB' ];
  3938. $this->LineWidth = $saved[ 'linewidth' ];
  3939. $this->DrawColor = $saved[ 'drawcolor' ];
  3940. $this->outline_on = $saved[ 'is_outline' ];
  3941. $this->outlineparam = $saved[ 'outlineparam' ];
  3942. if ($write) {
  3943. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],true,true); // force output
  3944. $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  3945. 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); }
  3946. $this->pageoutput[$this->page]['Font'] = $fontout;
  3947. }
  3948. else
  3949. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ]);
  3950. $this->ReqFontStyle = $saved[ 'ReqFontStyle' ];
  3951. }
  3952. function newFlowingBlock( $w, $h, $a = '', $is_table = false, $is_list = false, $blockstate = 0, $newblock=true, $blockdir='ltr')
  3953. {
  3954. if (!$a) {
  3955. if ($blockdir=='rtl') { $a = 'R'; }
  3956. else { $a = 'L'; }
  3957. }
  3958. $this->flowingBlockAttr[ 'width' ] = ($w * _MPDFK);
  3959. // line height in user units
  3960. $this->flowingBlockAttr[ 'is_table' ] = $is_table;
  3961. $this->flowingBlockAttr[ 'is_list' ] = $is_list;
  3962. $this->flowingBlockAttr[ 'height' ] = $h;
  3963. $this->flowingBlockAttr[ 'lineCount' ] = 0;
  3964. $this->flowingBlockAttr[ 'align' ] = $a;
  3965. $this->flowingBlockAttr[ 'font' ] = array();
  3966. $this->flowingBlockAttr[ 'content' ] = array();
  3967. $this->flowingBlockAttr[ 'contentB' ] = array();
  3968. $this->flowingBlockAttr[ 'contentWidth' ] = 0;
  3969. $this->flowingBlockAttr[ 'blockstate' ] = $blockstate;
  3970. $this->flowingBlockAttr[ 'newblock' ] = $newblock;
  3971. $this->flowingBlockAttr[ 'valign' ] = 'M';
  3972. $this->flowingBlockAttr['blockdir'] = $blockdir;
  3973. }
  3974. function finishFlowingBlock($endofblock=false, $next='') {
  3975. $currentx = $this->x;
  3976. //prints out the last chunk
  3977. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  3978. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  3979. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  3980. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  3981. $align =& $this->flowingBlockAttr[ 'align' ];
  3982. $content =& $this->flowingBlockAttr[ 'content' ];
  3983. $contentB =& $this->flowingBlockAttr[ 'contentB' ];
  3984. $font =& $this->flowingBlockAttr[ 'font' ];
  3985. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  3986. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  3987. $valign =& $this->flowingBlockAttr[ 'valign' ];
  3988. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  3989. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  3990. $blockdir = $this->flowingBlockAttr['blockdir'];
  3991. // *********** BLOCK BACKGROUND COLOR *****************//
  3992. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  3993. $fill = 0;
  3994. }
  3995. else {
  3996. $this->SetFColor($this->ConvertColor(255));
  3997. $fill = 0;
  3998. }
  3999. // Always right trim!
  4000. // Right trim content and adjust width if need to justify (later)
  4001. if (isset($content[count($content)-1]) && preg_match('/[ ]+$/',$content[count($content)-1], $m)) {
  4002. $strip = strlen($m[0]);
  4003. $content[count($content)-1] = substr($content[count($content)-1],0,(strlen($content[count($content)-1])-$strip));
  4004. $this->restoreFont( $font[ count($content)-1 ],false );
  4005. $contentWidth -= $this->GetStringWidth($m[0]) * _MPDFK;
  4006. }
  4007. // the amount of space taken up so far in user units
  4008. $usedWidth = 0;
  4009. // COLS
  4010. $oldcolumn = $this->CurrCol;
  4011. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4012. // Print out each chunk
  4013. /*-- TABLES --*/
  4014. if ($is_table) {
  4015. $ipaddingL = 0;
  4016. $ipaddingR = 0;
  4017. $paddingL = 0;
  4018. $paddingR = 0;
  4019. }
  4020. else {
  4021. /*-- END TABLES --*/
  4022. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4023. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4024. $paddingL = ($ipaddingL * _MPDFK);
  4025. $paddingR = ($ipaddingR * _MPDFK);
  4026. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4027. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4028. // Added mPDF 3.0 Float DIV
  4029. $fpaddingR = 0;
  4030. $fpaddingL = 0;
  4031. /*-- CSS-FLOAT --*/
  4032. if (count($this->floatDivs)) {
  4033. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4034. if ($r_exists) { $fpaddingR = $r_width; }
  4035. if ($l_exists) { $fpaddingL = $l_width; }
  4036. }
  4037. /*-- END CSS-FLOAT --*/
  4038. $usey = $this->y + 0.002;
  4039. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4040. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4041. }
  4042. /*-- CSS-IMAGE-FLOAT --*/
  4043. // If float exists at this level
  4044. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4045. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4046. /*-- END CSS-IMAGE-FLOAT --*/
  4047. } // *TABLES*
  4048. // Set Current lineheight (correction factor)
  4049. $lhfixed = false;
  4050. /*-- LISTS --*/
  4051. if ($is_list) {
  4052. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  4053. $lhfixed = true;
  4054. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  4055. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4056. }
  4057. else {
  4058. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  4059. }
  4060. }
  4061. else
  4062. /*-- END LISTS --*/
  4063. /*-- TABLES --*/
  4064. if ($is_table) {
  4065. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  4066. $lhfixed = true;
  4067. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  4068. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  4069. }
  4070. else {
  4071. $this->lineheight_correction = $this->table_lineheight;
  4072. }
  4073. }
  4074. else
  4075. /*-- END TABLES --*/
  4076. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  4077. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  4078. $lhfixed = true;
  4079. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  4080. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4081. }
  4082. else {
  4083. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  4084. }
  4085. }
  4086. else {
  4087. $this->lineheight_correction = $this->normalLineheight;
  4088. }
  4089. // correct lineheight to maximum fontsize
  4090. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  4091. else { $maxlineHeight = 0; }
  4092. $this->forceExactLineheight = true;
  4093. $maxfontsize = 0;
  4094. // While we're at it, check if contains cursive text
  4095. $checkCursive=false;
  4096. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  4097. foreach ( $content as $k => $chunk )
  4098. {
  4099. $this->restoreFont( $font[ $k ],false );
  4100. if (!isset($this->objectbuffer[$k])) {
  4101. // Soft Hyphens chr(173)
  4102. if (!$this->usingCoreFont) {
  4103. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  4104. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  4105. }
  4106. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  4107. $content[$k] = $chunk = str_replace(chr(173),'',$chunk );
  4108. }
  4109. // Special case of sub/sup carried over on its own to last line
  4110. if (($this->SUB || $this->SUP) && count($content)==1) { $actfs = $this->FontSize*100/55; } // 55% is font change for sub/sup
  4111. else { $actfs = $this->FontSize; }
  4112. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4113. if ($lhfixed && ($actfs > $def_fontsize || ($actfs > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  4114. $this->forceExactLineheight = false;
  4115. }
  4116. $maxfontsize = max($maxfontsize,$actfs);
  4117. }
  4118. }
  4119. if(isset($font[count($font)-1])) {
  4120. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  4121. $lastfontstyle = $font[count($font)-1]['style'];
  4122. }
  4123. else {
  4124. $lastfontreqstyle=null;
  4125. $lastfontstyle=null;
  4126. }
  4127. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  4128. $lastitalic = $this->FontSize*0.15*_MPDFK;
  4129. }
  4130. else { $lastitalic = 0; }
  4131. /*-- LISTS --*/
  4132. if ($is_list && is_array($this->bulletarray) && count($this->bulletarray)) {
  4133. $actfs = $this->bulletarray['fontsize'];
  4134. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  4135. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  4136. $maxfontsize = max($maxfontsize,$actfs);
  4137. }
  4138. /*-- END LISTS --*/
  4139. // when every text item checked i.e. $maxfontsize is set properly
  4140. $af = 0; // Above font
  4141. $bf = 0; // Below font
  4142. $mta = 0; // Maximum top-aligned
  4143. $mba = 0; // Maximum bottom-aligned
  4144. foreach ( $content as $k => $chunk )
  4145. {
  4146. if (isset($this->objectbuffer[$k])) {
  4147. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  4148. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  4149. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  4150. if ($va == 'BS') { // (BASELINE default)
  4151. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  4152. }
  4153. else if ($va == 'M') {
  4154. $af = max($af, ($oh - $maxfontsize)/2);
  4155. $bf = max($bf, ($oh - $maxfontsize)/2);
  4156. }
  4157. else if ($va == 'TT') {
  4158. $bf = max($bf, ($oh - $maxfontsize));
  4159. }
  4160. else if ($va == 'TB') {
  4161. $af = max($af, ($oh - $maxfontsize));
  4162. }
  4163. else if ($va == 'T') {
  4164. $mta = max($mta, $oh);
  4165. }
  4166. else if ($va == 'B') {
  4167. $mba = max($mba, $oh);
  4168. }
  4169. }
  4170. }
  4171. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  4172. $maxlineHeight = $maxfontsize + $af + $bf;
  4173. }
  4174. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  4175. if ($mta > $maxlineHeight) {
  4176. $bf += ($mta - $maxlineHeight);
  4177. $maxlineHeight = $mta;
  4178. }
  4179. if ($mba > $maxlineHeight) {
  4180. $af += ($mba - $maxlineHeight);
  4181. $maxlineHeight = $mba;
  4182. }
  4183. $lineHeight = $maxlineHeight;
  4184. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  4185. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  4186. $this->linemaxfontsize = $def_fontsize;
  4187. }
  4188. else { $this->linemaxfontsize = $maxfontsize; }
  4189. // Get PAGEBREAK TO TEST for height including the bottom border/padding
  4190. $check_h = max($this->divheight,$lineHeight);
  4191. // This fixes a proven bug...
  4192. if ($endofblock && $newblock && $blockstate==0 && !$content) { $check_h = 0; }
  4193. // but ? needs to fix potentially more widespread...
  4194. // if (!$content) { $check_h = 0; }
  4195. if ($this->blklvl > 0 && !$is_table) {
  4196. if ($endofblock && $blockstate > 1) {
  4197. if ($this->blk[$this->blklvl]['page_break_after_avoid']) { $check_h += $lineHeight; }
  4198. $check_h += ($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4199. }
  4200. // mPDF 5.4.03
  4201. if (($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0) || ($endofblock && $blockstate ==3 && $lineCount == 0)) {
  4202. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  4203. }
  4204. }
  4205. // Force PAGE break if column height cannot take check-height
  4206. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  4207. $this->SetCol($this->NbCol-1);
  4208. }
  4209. // mPDF 5.4.04
  4210. // Avoid just border/background-color moved on to next page
  4211. if ($endofblock && $blockstate > 1 && !$content) { $buff = $this->margBuffer; }
  4212. else { $buff = 0; }
  4213. // PAGEBREAK
  4214. // mPDF 5.4.04
  4215. if(!$is_table && ($this->y+$check_h) > ($this->PageBreakTrigger + $buff) and !$this->InFooter and $this->AcceptPageBreak()) {
  4216. $bak_x=$this->x;//Current X position
  4217. // WORD SPACING
  4218. $ws=$this->ws;//Word Spacing
  4219. $charspacing=$this->charspacing;//Character Spacing
  4220. $this->ResetSpacing();
  4221. $this->AddPage($this->CurOrientation);
  4222. $this->x=$bak_x;
  4223. // Added to correct for OddEven Margins
  4224. $currentx += $this->MarginCorrection;
  4225. $this->x += $this->MarginCorrection;
  4226. // WORD SPACING
  4227. $this->SetSpacing($charspacing,$ws);
  4228. }
  4229. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  4230. $this->printdivbuffer();
  4231. $this->keep_block_together = 0;
  4232. }
  4233. /*-- COLUMNS --*/
  4234. // COLS
  4235. // COLUMN CHANGE
  4236. if ($this->CurrCol != $oldcolumn) {
  4237. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4238. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  4239. $oldcolumn = $this->CurrCol;
  4240. }
  4241. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; }
  4242. /*-- END COLUMNS --*/
  4243. // TOP MARGIN
  4244. if ($newblock && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && $lineCount == 0 && !$is_table && !$is_list) {
  4245. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4246. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4247. }
  4248. if ($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0 && !$is_table && !$is_list) {
  4249. $this->blk[$this->blklvl]['y0'] = $this->y;
  4250. $this->blk[$this->blklvl]['startpage'] = $this->page;
  4251. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4252. }
  4253. // ADDED for Paragraph_indent
  4254. $WidthCorrection = 0;
  4255. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  4256. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4257. $WidthCorrection = ($ti*_MPDFK);
  4258. }
  4259. // PADDING and BORDER spacing/fill
  4260. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 0) && (!$is_table) && (!$is_list)) {
  4261. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4262. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  4263. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4264. $this->x = $currentx;
  4265. }
  4266. // Added mPDF 3.0 Float DIV
  4267. $fpaddingR = 0;
  4268. $fpaddingL = 0;
  4269. /*-- CSS-FLOAT --*/
  4270. if (count($this->floatDivs)) {
  4271. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4272. if ($r_exists) { $fpaddingR = $r_width; }
  4273. if ($l_exists) { $fpaddingL = $l_width; }
  4274. }
  4275. /*-- END CSS-FLOAT --*/
  4276. $usey = $this->y + 0.002;
  4277. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4278. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4279. }
  4280. /*-- CSS-IMAGE-FLOAT --*/
  4281. // If float exists at this level
  4282. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4283. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4284. /*-- END CSS-IMAGE-FLOAT --*/
  4285. if ($content) {
  4286. // In FinishFlowing Block no lines are justified as it is always last line
  4287. // but if orphansAllowed have allowed content width to go over max width, use J charspacing to compress line
  4288. // JUSTIFICATION J - NOT!
  4289. $nb_carac = 0;
  4290. $nb_spaces = 0;
  4291. $jcharspacing = 0;
  4292. $jws = 0;
  4293. $inclCursive=false;
  4294. foreach ( $content as $k => $chunk ) {
  4295. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  4296. if ($this->usingCoreFont) {
  4297. $chunk = str_replace(chr(160),chr(32),$chunk );
  4298. }
  4299. else {
  4300. $chunk = str_replace(chr(194).chr(160),chr(32),$chunk );
  4301. }
  4302. $nb_carac += mb_strlen( $chunk, $this->mb_enc );
  4303. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc );
  4304. if ($checkCursive) {
  4305. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  4306. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  4307. }
  4308. }
  4309. }
  4310. // 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)
  4311. // If "orphans" in fact is just a final space - ignore this
  4312. if (((($contentWidth + $lastitalic) > $maxWidth) && ($content[count($content)-1] != ' ') ) ||
  4313. (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br)))
  4314. ) {
  4315. // WORD SPACING
  4316. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$contentWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive);
  4317. }
  4318. // Check if will fit at word/char spacing of previous line - if so continue it
  4319. // but only allow a maximum of $this->jSmaxWordLast and $this->jSmaxCharLast
  4320. else if ($contentWidth < ($maxWidth - $lastitalic-$WidthCorrection - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK))) && !$this->fixedlSpacing) {
  4321. if ($this->ws > $this->jSmaxWordLast) {
  4322. $jws = $this->jSmaxWordLast;
  4323. }
  4324. if ($this->charspacing > $this->jSmaxCharLast) {
  4325. $jcharspacing = $this->jSmaxCharLast;
  4326. }
  4327. $check = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) - ( $jcharspacing * $nb_carac) - ( $jws * $nb_spaces);
  4328. if ($check <= 0) {
  4329. $jcharspacing = 0;
  4330. $jws = 0;
  4331. }
  4332. }
  4333. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  4334. $empty -= ($jcharspacing * $nb_carac);
  4335. $empty -= ($jws * $nb_spaces);
  4336. $empty /= _MPDFK;
  4337. if (!$is_table) {
  4338. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin'] - $empty));
  4339. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $empty));
  4340. }
  4341. $arraysize = count($content);
  4342. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  4343. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  4344. // DIRECTIONALITY RTL
  4345. $all_rtl = false;
  4346. $contains_rtl = false;
  4347. /*-- RTL --*/
  4348. if ($blockdir == 'rtl' || $this->biDirectional) {
  4349. $all_rtl = true;
  4350. foreach ( $content as $k => $chunk ) {
  4351. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir);
  4352. if ($reversed > 0) { $contains_rtl = true; }
  4353. if ($reversed < 2) { $all_rtl = false; }
  4354. $content[$k] = $chunk;
  4355. }
  4356. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) {
  4357. $content = array_reverse($content,false);
  4358. $contentB = array_reverse($contentB,false);
  4359. }
  4360. }
  4361. /*-- END RTL --*/
  4362. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL;
  4363. if ($align == 'R') { $this->x += $empty; }
  4364. else if ($align == 'J' && $blockdir == 'rtl') { $this->x += $empty; }
  4365. else if ($align == 'C') { $this->x += ($empty / 2); }
  4366. // Paragraph INDENT
  4367. $WidthCorrection = 0;
  4368. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align !='C')) {
  4369. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4370. $this->x += $ti;
  4371. }
  4372. foreach ( $content as $k => $chunk )
  4373. {
  4374. // FOR IMAGES
  4375. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $dirk = $arraysize-1 - $k; } else { $dirk = $k; }
  4376. $va = 'M'; // default for text
  4377. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  4378. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'];
  4379. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  4380. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  4381. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  4382. $va = $this->objectbuffer[$dirk]['vertical-align'];
  4383. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  4384. if ($va == 'BS') {
  4385. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4386. }
  4387. else if ($va == 'M' || $va == '') {
  4388. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  4389. }
  4390. else if ($va == 'TB') {
  4391. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4392. }
  4393. else if ($va == 'TT') {
  4394. $yadj += $af;
  4395. }
  4396. else if ($va == 'B') {
  4397. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4398. }
  4399. else if ($va == 'T') {
  4400. $yadj += 0;
  4401. }
  4402. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  4403. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  4404. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  4405. }
  4406. // DIRECTIONALITY RTL
  4407. if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $this->restoreFont( $font[ $arraysize-1 - $k ] ); }
  4408. else { $this->restoreFont( $font[ $k ] ); }
  4409. $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws);
  4410. $this->fixedlSpacing = false;
  4411. $this->minwSpacing = 0;
  4412. // *********** SPAN BACKGROUND COLOR ***************** //
  4413. if (isset($this->spanbgcolor) && $this->spanbgcolor) {
  4414. $cor = $this->spanbgcolorarray;
  4415. $this->SetFColor($cor);
  4416. $save_fill = $fill; $spanfill = 1; $fill = 1;
  4417. }
  4418. if (!empty($this->spanborddet)) {
  4419. if (strpos($contentB[$k],'L')!==false && isset($this->spanborddet['L'])) $this->x += $this->spanborddet['L']['w'];
  4420. if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0;
  4421. if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0;
  4422. }
  4423. // WORD SPACING
  4424. $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK )
  4425. + ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK );
  4426. if (isset($this->objectbuffer[$dirk])) {
  4427. if ($this->objectbuffer[$dirk]['type']=='dottab') {
  4428. $this->objectbuffer[$dirk]['OUTER-WIDTH'] +=$empty;
  4429. }
  4430. $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH'];
  4431. }
  4432. if ($stringWidth==0) { $stringWidth = 0.000001; }
  4433. if ($k == $arraysize-1) $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)
  4434. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part
  4435. if (!empty($this->spanborddet)) {
  4436. if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w'];
  4437. }
  4438. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  4439. if (isset($spanfill) && $spanfill) {
  4440. $fill = $save_fill; $spanfill = 0;
  4441. if ($fill) { $this->SetFColor($bcor); }
  4442. }
  4443. }
  4444. $this->printobjectbuffer($is_table, $blockdir);
  4445. $this->objectbuffer = array();
  4446. $this->ResetSpacing();
  4447. /*-- LISTS --*/
  4448. // LIST BULLETS/NUMBERS
  4449. if ($is_list && is_array($this->bulletarray) && ($lineCount == 0) ) {
  4450. $savedFont = $this->saveFont();
  4451. $bull = $this->bulletarray;
  4452. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  4453. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  4454. }
  4455. 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']]); }
  4456. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4457. $this->bullet = true;
  4458. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  4459. }
  4460. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  4461. //Output bullet
  4462. $this->x = $currentx;
  4463. if (isset($bull['x'])) { $this->x += $bull['x']; }
  4464. $this->y -= $lineHeight;
  4465. if (is_array($bull['col'])) { $this->SetTColor($bull['col']); }
  4466. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  4467. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  4468. $this->bullet = false;
  4469. }
  4470. $this->x = $currentx; // Reset
  4471. $this->y += $lineHeight;
  4472. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4473. $this->restoreFont( $savedFont );
  4474. // $font = array( $savedFont );
  4475. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  4476. }
  4477. /*-- END LISTS --*/
  4478. } // END IF CONTENT
  4479. /*-- CSS-IMAGE-FLOAT --*/
  4480. // Update values if set to skipline
  4481. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  4482. if ($endofblock && $blockstate>1) {
  4483. // If float exists at this level
  4484. if (isset($this->floatmargins['R']['y1'])) { $fry1 = $this->floatmargins['R']['y1']; }
  4485. else { $fry1 = 0; }
  4486. if (isset($this->floatmargins['L']['y1'])) { $fly1 = $this->floatmargins['L']['y1']; }
  4487. else { $fly1 = 0; }
  4488. if ($this->y < $fry1 || $this->y < $fly1) {
  4489. $drop = max($fry1,$fly1) - $this->y;
  4490. $this->DivLn($drop);
  4491. $this->x = $currentx;
  4492. }
  4493. }
  4494. /*-- END CSS-IMAGE-FLOAT --*/
  4495. // PADDING and BORDER spacing/fill
  4496. 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)) {
  4497. // If CSS height set, extend bottom - if on same page as block started, and CSS HEIGHT > actual height,
  4498. // and does not force pagebreak
  4499. $extra = 0;
  4500. if ($this->blk[$this->blklvl]['css_set_height'] && $this->blk[$this->blklvl]['startpage']==$this->page) {
  4501. // predicted height
  4502. $h1 = ($this->y-$this->blk[$this->blklvl]['y0']) + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  4503. 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; }
  4504. if($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra > $this->PageBreakTrigger) {
  4505. $extra = $this->PageBreakTrigger - ($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4506. }
  4507. }
  4508. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4509. $this->DivLn($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra,-3,true,false,2);
  4510. $this->x = $currentx;
  4511. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4512. }
  4513. // SET Bottom y1 of block (used for painting borders)
  4514. if (($endofblock) && ($blockstate > 1) && (!$is_table) && (!$is_list)) {
  4515. $this->blk[$this->blklvl]['y1'] = $this->y;
  4516. }
  4517. // BOTTOM MARGIN
  4518. if (($endofblock) && ($blockstate > 1) && ($this->blk[$this->blklvl]['margin_bottom']) && (!$is_table) && (!$is_list)) {
  4519. if($this->y+$this->blk[$this->blklvl]['margin_bottom'] < $this->PageBreakTrigger and !$this->InFooter) {
  4520. $this->DivLn($this->blk[$this->blklvl]['margin_bottom'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4521. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4522. }
  4523. }
  4524. // Reset lineheight
  4525. $lineHeight = $this->divheight;
  4526. }
  4527. function printobjectbuffer($is_table=false, $blockdir=false) {
  4528. if (!$blockdir) { $blockdir = $this->directionality; }
  4529. if ($is_table && $this->shrin_k > 1) { $k = $this->shrin_k; }
  4530. else { $k = 1; }
  4531. $save_y = $this->y;
  4532. $save_x = $this->x;
  4533. $save_currentfontfamily = $this->FontFamily;
  4534. $save_currentfontsize = $this->FontSizePt;
  4535. $save_currentfontstyle = $this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  4536. if ($blockdir == 'rtl') { $rtlalign = 'R'; } else { $rtlalign = 'L'; }
  4537. foreach ($this->objectbuffer AS $ib => $objattr) {
  4538. if ($objattr['type'] == 'bookmark' || $objattr['type'] == 'indexentry' || $objattr['type'] == 'toc') {
  4539. $x = $objattr['OUTER-X'];
  4540. $y = $objattr['OUTER-Y'];
  4541. $this->y = $y - $this->FontSize/2;
  4542. $this->x = $x;
  4543. if ($objattr['type'] == 'bookmark' ) { $this->Bookmark($objattr['CONTENT'],$objattr['bklevel'] ,$y - $this->FontSize); } // *BOOKMARKS*
  4544. if ($objattr['type'] == 'indexentry') { $this->IndexEntry($objattr['CONTENT']); } // *INDEX*
  4545. if ($objattr['type'] == 'toc') { $this->TOC_Entry($objattr['CONTENT'], $objattr['toclevel'], $objattr['toc_id']); } // *TOC*
  4546. }
  4547. /*-- ANNOTATIONS --*/
  4548. else if ($objattr['type'] == 'annot') {
  4549. if ($objattr['POS-X']) { $x = $objattr['POS-X']; }
  4550. else if ($this->annotMargin<>0) { $x = -$objattr['OUTER-X']; }
  4551. else { $x = $objattr['OUTER-X']; }
  4552. if ($objattr['POS-Y']) { $y = $objattr['POS-Y']; }
  4553. else { $y = $objattr['OUTER-Y'] - $this->FontSize/2; }
  4554. // Create a dummy entry in the _out/columnBuffer with position sensitive data,
  4555. // linking $y-1 in the Columnbuffer with entry in $this->columnAnnots
  4556. // and when columns are split in length will not break annotation from current line
  4557. $this->y = $y-1;
  4558. $this->x = $x-1;
  4559. $this->Line($x-1,$y-1,$x-1,$y-1);
  4560. $this->Annotation($objattr['CONTENT'], $x , $y , $objattr['ICON'], $objattr['AUTHOR'], $objattr['SUBJECT'], $objattr['OPACITY'], $objattr['COLOR'], $objattr['POPUP'], $objattr['FILE']);
  4561. }
  4562. /*-- END ANNOTATIONS --*/
  4563. else {
  4564. $y = $objattr['OUTER-Y'];
  4565. $x = $objattr['OUTER-X'];
  4566. $w = $objattr['OUTER-WIDTH'];
  4567. $h = $objattr['OUTER-HEIGHT'];
  4568. if (isset($objattr['text'])) { $texto = $objattr['text']; }
  4569. $this->y = $y;
  4570. $this->x = $x;
  4571. if (isset($objattr['fontfamily'])) { $this->SetFont($objattr['fontfamily'],'',$objattr['fontsize'] ); }
  4572. }
  4573. // HR
  4574. if ($objattr['type'] == 'hr') {
  4575. $this->SetDColor($objattr['color']);
  4576. switch($objattr['align']) {
  4577. case 'C':
  4578. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4579. $empty /= 2;
  4580. $x += $empty;
  4581. break;
  4582. case 'R':
  4583. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4584. $x += $empty;
  4585. break;
  4586. }
  4587. $oldlinewidth = $this->LineWidth;
  4588. $this->SetLineWidth($objattr['linewidth']/$k );
  4589. $this->y += ($objattr['linewidth']/2) + $objattr['margin_top']/$k;
  4590. $this->Line($x,$this->y,$x+$objattr['INNER-WIDTH'],$this->y);
  4591. $this->SetLineWidth($oldlinewidth);
  4592. $this->SetDColor($this->ConvertColor(0));
  4593. }
  4594. // IMAGE
  4595. if ($objattr['type'] == 'image') {
  4596. if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) {
  4597. $this->SetVisibility($objattr['visibility']);
  4598. }
  4599. if (isset($objattr['opacity'])) { $this->SetAlpha($objattr['opacity']); }
  4600. $rotate = 0;
  4601. $obiw = $objattr['INNER-WIDTH'];
  4602. $obih = $objattr['INNER-HEIGHT'];
  4603. $sx = $objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w'];
  4604. $sy = abs($objattr['INNER-HEIGHT'])*_MPDFK / abs($objattr['orig_h']);
  4605. $sx = ($objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w']);
  4606. $sy = ($objattr['INNER-HEIGHT']*_MPDFK / $objattr['orig_h']);
  4607. if (isset($objattr['ROTATE'])) { $rotate = $objattr['ROTATE']; }
  4608. if ($rotate==90) {
  4609. // Clockwise
  4610. $obiw = $objattr['INNER-HEIGHT'];
  4611. $obih = $objattr['INNER-WIDTH'];
  4612. $tr = $this->transformTranslate(0, -$objattr['INNER-WIDTH'], true) ;
  4613. $tr .= ' '. $this->transformRotate(90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4614. $sx = $obiw*_MPDFK / $objattr['orig_h'];
  4615. $sy = $obih*_MPDFK / $objattr['orig_w'];
  4616. }
  4617. else if ($rotate==-90 || $rotate==270) {
  4618. // AntiClockwise
  4619. $obiw = $objattr['INNER-HEIGHT'];
  4620. $obih = $objattr['INNER-WIDTH'];
  4621. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], ($objattr['INNER-HEIGHT']-$objattr['INNER-WIDTH']), true) ;
  4622. $tr .= ' '. $this->transformRotate(-90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4623. $sx = $obiw*_MPDFK / $objattr['orig_h'];
  4624. $sy = $obih*_MPDFK / $objattr['orig_w'];
  4625. }
  4626. else if ($rotate==180) {
  4627. // Mirror
  4628. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], -$objattr['INNER-HEIGHT'], true) ;
  4629. $tr .= ' '. $this->transformRotate(180, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ),true) ;
  4630. }
  4631. else { $tr = ''; }
  4632. $tr = trim($tr);
  4633. if ($tr) { $tr .= ' '; }
  4634. $gradmask = '';
  4635. /*-- BACKGROUNDS --*/
  4636. if (isset($objattr['GRADIENT-MASK'])) {
  4637. $g = $this->grad->parseMozGradient( $objattr['GRADIENT-MASK'] );
  4638. if ($g) {
  4639. $dummy = $this->grad->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true, true);
  4640. $gradmask = '/TGS'.count($this->gradients).' gs ';
  4641. // $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");
  4642. }
  4643. }
  4644. /*-- END BACKGROUNDS --*/
  4645. /*-- IMAGES-WMF --*/
  4646. if (isset($objattr['itype']) && $objattr['itype']=='wmf') {
  4647. $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']);
  4648. }
  4649. else
  4650. /*-- END IMAGES-WMF --*/
  4651. if (isset($objattr['itype']) && $objattr['itype']=='svg') {
  4652. $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']);
  4653. }
  4654. else {
  4655. $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'] );
  4656. }
  4657. $this->_out($outstring);
  4658. // LINK
  4659. if (isset($objattr['link'])) $this->Link($objattr['INNER-X'],$objattr['INNER-Y'],$objattr['INNER-WIDTH'],$objattr['INNER-HEIGHT'],$objattr['link']);
  4660. if (isset($objattr['opacity'])) { $this->SetAlpha(1); }
  4661. 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); }
  4662. if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) {
  4663. $this->SetVisibility('visible');
  4664. }
  4665. }
  4666. /*-- BARCODES --*/
  4667. // BARCODE
  4668. if ($objattr['type'] == 'barcode') {
  4669. $bgcol = $this->ConvertColor(255);
  4670. if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
  4671. $bgcol = $objattr['bgcolor'];
  4672. }
  4673. $col = $this->ConvertColor(0);
  4674. if (isset($objattr['color']) && $objattr['color']) {
  4675. $col = $objattr['color'];
  4676. }
  4677. $this->SetFColor($bgcol);
  4678. $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
  4679. $this->SetFColor($this->ConvertColor(255));
  4680. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4681. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  4682. $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);
  4683. }
  4684. // QR-code
  4685. else if ($objattr['btype']=='QR') {
  4686. if (!class_exists('QRcode', false)) {
  4687. include(_MPDF_PATH.'qrcode/qrcode.class.php');
  4688. }
  4689. $this->qrcode = new QRcode($objattr['code'], $objattr['errorlevel']);
  4690. $this->qrcode->displayFPDF($this, $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize']*25, array(255,255,255), array(0,0,0));
  4691. }
  4692. else {
  4693. $this->WriteBarcode2($objattr['code'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k);
  4694. }
  4695. }
  4696. /*-- END BARCODES --*/
  4697. // TEXT CIRCLE
  4698. if ($objattr['type'] == 'textcircle') {
  4699. $bgcol = ''; // mPDF 5.5.14
  4700. if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
  4701. $bgcol = $objattr['bgcolor'];
  4702. }
  4703. $col = $this->ConvertColor(0);
  4704. if (isset($objattr['color']) && $objattr['color']) {
  4705. $col = $objattr['color'];
  4706. }
  4707. $this->SetTColor($col);
  4708. $this->SetFColor($bgcol);
  4709. if ($bgcol) $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F'); // mPDF 5.5.14
  4710. $this->SetFColor($this->ConvertColor(255));
  4711. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4712. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  4713. if (empty($this->directw)) { $this->directw = new directw($this); }
  4714. $save_lmfs = $this->linemaxfontsize;
  4715. $this->linemaxfontsize = 0;
  4716. if (isset($objattr['top-text'])) {
  4717. $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
  4718. }
  4719. if (isset($objattr['bottom-text'])) {
  4720. $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
  4721. }
  4722. $this->linemaxfontsize = $save_lmfs;
  4723. }
  4724. $this->ResetSpacing();
  4725. // DOT-TAB
  4726. if ($objattr['type'] == 'dottab') {
  4727. $sp = $this->GetStringWidth(' ');
  4728. $nb=floor(($w-2*$sp)/$this->GetStringWidth('.'));
  4729. if ($nb>0) { $dots=' '.str_repeat('.',$nb).' '; }
  4730. else { $dots=' '; }
  4731. $col = $this->ConvertColor(0);
  4732. if (isset($objattr['colorarray']) && is_array($objattr['colorarray'])) {
  4733. $col = $objattr['colorarray'];
  4734. }
  4735. $this->SetTColor($col);
  4736. $save_sbd = $this->spanborddet;
  4737. $save_u = $this->U;
  4738. $save_s = $this->strike;
  4739. $this->spanborddet = '';
  4740. $this->U = false;
  4741. $this->strike = false;
  4742. $this->Cell($w,$h,$dots,0,0,'C');
  4743. $this->spanborddet = $save_sbd;
  4744. $this->U = $save_u;
  4745. $this->strike = $save_s;
  4746. // mPDF 5.0
  4747. $this->SetTColor($this->ConvertColor(0));
  4748. }
  4749. /*-- FORMS --*/
  4750. // TEXT/PASSWORD INPUT
  4751. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD')) {
  4752. $this->form->print_ob_text($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4753. }
  4754. // TEXTAREA
  4755. if ($objattr['type'] == 'textarea') {
  4756. $this->form->print_ob_textarea($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4757. }
  4758. // SELECT
  4759. if ($objattr['type'] == 'select') {
  4760. $this->form->print_ob_select($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4761. }
  4762. // INPUT/BUTTON as IMAGE
  4763. if ($objattr['type'] == 'input' && $objattr['subtype'] == 'IMAGE') {
  4764. $this->form->print_ob_imageinput($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4765. }
  4766. // BUTTON
  4767. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'SUBMIT' || $objattr['subtype'] == 'RESET' || $objattr['subtype'] == 'BUTTON')) {
  4768. $this->form->print_ob_button($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir);
  4769. }
  4770. // CHECKBOX
  4771. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'CHECKBOX')) {
  4772. $this->form->print_ob_checkbox($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y);
  4773. }
  4774. // RADIO
  4775. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'RADIO')) {
  4776. $this->form->print_ob_radio($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y);
  4777. }
  4778. /*-- END FORMS --*/
  4779. }
  4780. $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize);
  4781. $this->y = $save_y;
  4782. $this->x = $save_x;
  4783. unset($content);
  4784. }
  4785. function WriteFlowingBlock( $s)
  4786. {
  4787. $currentx = $this->x;
  4788. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  4789. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  4790. // width of all the content so far in points
  4791. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  4792. // cell width in points
  4793. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  4794. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  4795. // line height in user units
  4796. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  4797. $align =& $this->flowingBlockAttr[ 'align' ];
  4798. $content =& $this->flowingBlockAttr[ 'content' ];
  4799. $contentB =& $this->flowingBlockAttr[ 'contentB' ];
  4800. $font =& $this->flowingBlockAttr[ 'font' ];
  4801. $valign =& $this->flowingBlockAttr[ 'valign' ];
  4802. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  4803. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  4804. $blockdir = $this->flowingBlockAttr['blockdir'];
  4805. // *********** BLOCK BACKGROUND COLOR ***************** //
  4806. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  4807. $fill = 0;
  4808. }
  4809. else {
  4810. $this->SetFColor($this->ConvertColor(255));
  4811. $fill = 0;
  4812. }
  4813. $font[] = $this->saveFont();
  4814. $content[] = '';
  4815. $contentB[] = '';
  4816. $currContent =& $content[ count( $content ) - 1 ];
  4817. // where the line should be cutoff if it is to be justified
  4818. $cutoffWidth = $contentWidth;
  4819. $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  4820. $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  4821. // mPDF 5.5.07
  4822. $raquote = mb_convert_encoding("\xc2\xbb",$this->mb_enc,'UTF-8'); //&#187; &raquo;
  4823. // mPDF 5.5.20
  4824. $rsquo = mb_convert_encoding("\xe2\x80\x99",$this->mb_enc,'UTF-8'); //&#8217; &rsquo;
  4825. $sbquo = mb_convert_encoding("\xe2\x80\x9a",$this->mb_enc,'UTF-8'); //&#8218; &sbquo;
  4826. $bdquo = mb_convert_encoding("\xe2\x80\xba",$this->mb_enc,'UTF-8'); //&#8222; &bdquo;
  4827. $CJKoverflow = false;
  4828. // COLS
  4829. $oldcolumn = $this->CurrCol;
  4830. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4831. /*-- TABLES --*/
  4832. if ($is_table) {
  4833. $ipaddingL = 0;
  4834. $ipaddingR = 0;
  4835. $paddingL = 0;
  4836. $paddingR = 0;
  4837. $cpaddingadjustL = 0;
  4838. $cpaddingadjustR = 0;
  4839. // Added mPDF 3.0
  4840. $fpaddingR = 0;
  4841. $fpaddingL = 0;
  4842. }
  4843. else {
  4844. /*-- END TABLES --*/
  4845. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4846. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4847. $paddingL = ($ipaddingL * _MPDFK);
  4848. $paddingR = ($ipaddingR * _MPDFK);
  4849. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4850. $cpaddingadjustL = -$this->cMarginL;
  4851. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4852. $cpaddingadjustR = -$this->cMarginR;
  4853. // Added mPDF 3.0 Float DIV
  4854. $fpaddingR = 0;
  4855. $fpaddingL = 0;
  4856. /*-- CSS-FLOAT --*/
  4857. if (count($this->floatDivs)) {
  4858. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4859. if ($r_exists) { $fpaddingR = $r_width; }
  4860. if ($l_exists) { $fpaddingL = $l_width; }
  4861. }
  4862. /*-- END CSS-FLOAT --*/
  4863. $usey = $this->y + 0.002;
  4864. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4865. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4866. }
  4867. /*-- CSS-IMAGE-FLOAT --*/
  4868. // If float exists at this level
  4869. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4870. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4871. /*-- END CSS-IMAGE-FLOAT --*/
  4872. } // *TABLES*
  4873. //OBJECTS - IMAGES & FORM Elements (NB has already skipped line/page if required - in printbuffer)
  4874. if (substr($s,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  4875. $objattr = $this->_getObjAttr($s);
  4876. $h_corr = 0;
  4877. if ($is_table) { // *TABLES*
  4878. $maximumW = ($maxWidth/_MPDFK) - ($this->cellPaddingL + $this->cMarginL + $this->cellPaddingR + $this->cMarginR); // *TABLES*
  4879. } // *TABLES*
  4880. else { // *TABLES*
  4881. 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']; }
  4882. $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 );
  4883. } // *TABLES*
  4884. $objattr = $this->inlineObject($objattr['type'],$this->lMargin + $fpaddingL + ($contentWidth/_MPDFK),($this->y + $h_corr), $objattr, $this->lMargin,($contentWidth/_MPDFK),$maximumW,$lineHeight,true,$is_table);
  4885. // SET LINEHEIGHT for this line ================ RESET AT END
  4886. $lineHeight = MAX($lineHeight,$objattr['OUTER-HEIGHT']);
  4887. $this->objectbuffer[count($content)-1] = $objattr;
  4888. // if (isset($objattr['vertical-align'])) { $valign = $objattr['vertical-align']; }
  4889. // else { $valign = ''; }
  4890. $contentWidth += ($objattr['OUTER-WIDTH'] * _MPDFK);
  4891. return;
  4892. }
  4893. $lbw = $rbw = 0; // Border widths
  4894. if (!empty($this->spanborddet)) {
  4895. if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w'];
  4896. if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w'];
  4897. }
  4898. if ($this->usingCoreFont) {
  4899. $tmp = strlen( $s );
  4900. }
  4901. else {
  4902. $tmp = mb_strlen( $s, $this->mb_enc );
  4903. }
  4904. $orphs = 0;
  4905. $check = 0;
  4906. // for every character in the string
  4907. for ( $i = 0; $i < $tmp; $i++ ) {
  4908. // extract the current character
  4909. // get the width of the character in points
  4910. if ($this->usingCoreFont) {
  4911. $c = $s[$i];
  4912. // Soft Hyphens chr(173)
  4913. $cw = ($this->GetCharWidthCore($c) * _MPDFK);
  4914. if ($this->kerning && $this->useKerning && $i > 0) {
  4915. if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$c])) {
  4916. $cw += ($this->CurrentFont['kerninfo'][$s[($i-1)]][$c] * $this->FontSizePt / 1000 );
  4917. }
  4918. }
  4919. }
  4920. else {
  4921. $c = mb_substr($s,$i,1,$this->mb_enc );
  4922. $cw = ($this->GetCharWidthNonCore($c, false) * _MPDFK);
  4923. if ($this->kerning && $this->useKerning && $i > 0) {
  4924. $lastc = mb_substr($s,($i-1),1,$this->mb_enc );
  4925. $ulastc = $this->UTF8StringToArray($lastc, false);
  4926. $uc = $this->UTF8StringToArray($c, false);
  4927. if (isset($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]])) {
  4928. $cw += ($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]] * $this->FontSizePt / 1000 );
  4929. }
  4930. }
  4931. }
  4932. if ($i==0) {
  4933. $cw += $lbw*_MPDFK;
  4934. $contentB[(count($contentB)-1)] .= 'L';
  4935. }
  4936. if ($i==($tmp-1)) {
  4937. $cw += $rbw*_MPDFK;
  4938. $contentB[(count($contentB)-1)] .= 'R';
  4939. }
  4940. if ($c==' ') { $check = 1; }
  4941. // CHECK for ORPHANS
  4942. else if ($c=='.' || $c==',' || $c==')' || $c==']' || $c==';' || $c==':' || $c=='!' || $c=='?'|| $c=='"' || $c==$curlyquote || $c==$curlylowquote || $c==$raquote || $c==$rsquo || $c==$sbquo || $c==$bdquo ) {$check++; } // mPDF 5.5.07 mPDF 5.5.20
  4943. /*-- CJK-FONTS --*/
  4944. else if ($this->checkCJK) {
  4945. if ((!$is_table && $this->CJKfollowing && preg_match("/[".$this->CJKfollowing."]/u", $c)) || ($is_table && preg_match("/[".$this->CJKoverflow ."]/u", $c))) { $check++; }
  4946. else { $check = 0; }
  4947. }
  4948. /*-- END CJK-FONTS --*/
  4949. else { $check = 0; }
  4950. // There's an orphan '. ' or ', ' or <sup>32</sup> about to be cut off at the end of line
  4951. if($check==1) {
  4952. $currContent .= $c;
  4953. $cutoffWidth = $contentWidth;
  4954. $contentWidth += $cw;
  4955. continue;
  4956. }
  4957. if(($this->SUP || $this->SUB) && ($orphs < $this->orphansAllowed)) { // ? disable orphans in table if borders used
  4958. $currContent .= $c;
  4959. $cutoffWidth = $contentWidth;
  4960. $contentWidth += $cw;
  4961. $orphs++;
  4962. continue;
  4963. }
  4964. else { $orphs = 0; }
  4965. // ADDED for Paragraph_indent
  4966. $WidthCorrection = 0;
  4967. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  4968. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4969. $WidthCorrection = ($ti*_MPDFK);
  4970. }
  4971. // Added mPDF 3.0 Float DIV
  4972. $fpaddingR = 0;
  4973. $fpaddingL = 0;
  4974. /*-- CSS-FLOAT --*/
  4975. if (count($this->floatDivs)) {
  4976. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4977. if ($r_exists) { $fpaddingR = $r_width; }
  4978. if ($l_exists) { $fpaddingL = $l_width; }
  4979. }
  4980. /*-- END CSS-FLOAT --*/
  4981. $usey = $this->y + 0.002;
  4982. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4983. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4984. }
  4985. /*-- CSS-IMAGE-FLOAT --*/
  4986. // If float exists at this level
  4987. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4988. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4989. /*-- END CSS-IMAGE-FLOAT --*/
  4990. // try adding another char
  4991. 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
  4992. // it won't fit, output what we already have
  4993. $lineCount++;
  4994. // contains any content that didn't make it into this print
  4995. $savedContent = '';
  4996. $savedContentB = '';
  4997. $savedFont = array();
  4998. $savedObj = array();
  4999. // cut off and save any partial words at the end of the string
  5000. $words = explode( ' ', $currContent );
  5001. ///////////////////
  5002. // HYPHENATION
  5003. $currWord = $words[count($words)-1] ;
  5004. $success = false;
  5005. /*-- HYPHENATION --*/
  5006. // Soft Hyphens chr(173)
  5007. if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$currWord)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$currWord) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) {
  5008. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5009. list($success,$pre,$post,$prelength) = $this->softHyphenate($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidthNonCore(" ", false)) );
  5010. }
  5011. if (!$success && ($this->hyphenate || ($this->hyphenateTables && $is_table))) {
  5012. // Look ahead to get current word
  5013. for($ac = $i; $ac<(mb_strlen($s)-1); $ac++) {
  5014. $addc = mb_substr($s,$ac,1,$this->mb_enc );
  5015. if ($addc == ' ') { break; }
  5016. $currWord .= $addc;
  5017. }
  5018. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5019. list($success,$pre,$post,$prelength) = $this->hyphenateWord($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidth(" ", false)) );
  5020. }
  5021. if ($success) {
  5022. $already = array_pop( $words );
  5023. $forward = mb_substr($already,$prelength,mb_strlen($already, $this->mb_enc), $this->mb_enc);
  5024. $words[] = $pre.'-';
  5025. $words[] = $forward;
  5026. $currContent = mb_substr($currContent,0,mb_strlen($currContent, $this->mb_enc)+1-mb_strlen($post, $this->mb_enc), $this->mb_enc) . '-';
  5027. }
  5028. /*-- END HYPHENATION --*/
  5029. /*-- CJK-FONTS --*/
  5030. // mPDF 5.5.10
  5031. // if current overflow character is CJK
  5032. if ($this->checkCJK && preg_match("/[".$this->pregCJKchars."]/u", $c)) {
  5033. $lastchar = mb_substr($words[(count($words)-1)],mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  5034. if ($this->checkCJK) {
  5035. // Last character that fits is not allowed to end a line - move lastchar(s) to start of next line
  5036. if (!$is_table && preg_match("/[".$this->CJKleading."]/u", $lastchar)) {
  5037. //move lastchar(s) to next line
  5038. $m0 = $lastchar;
  5039. $m1 = $c;
  5040. while(preg_match("/[".$this->CJKleading."]/u", $m0) && mb_strlen($words[(count($words)-1)], $this->mb_enc)>2) {
  5041. // trim last letter off word[0]
  5042. $words[(count($words)-1)] = mb_substr($words[(count($words)-1)],0,mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, $this->mb_enc);
  5043. // and add it to savedContent for next line
  5044. $savedContent = $m0.$savedContent;
  5045. $m1 = $lastchar;
  5046. $lastchar = mb_substr($words[(count($words)-1)],mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  5047. $m0 = $lastchar;
  5048. }
  5049. }
  5050. // Next character is not allowed to start a new line - move lastchar(s) to next line
  5051. else if (!$is_table && preg_match("/[".$this->CJKfollowing."]/u", $c)) {
  5052. // try squeezing another character(s) onto this line = Oikomi
  5053. if ($this->allowCJKorphans) {
  5054. $lookahead = mb_substr($s,$i+1,1,$this->mb_enc );
  5055. //if lookahead is not another following char
  5056. if ($lookahead && !preg_match("/[".$this->CJKfollowing."]/u", $lookahead)) {
  5057. $currContent .= $c;
  5058. $cutoffWidth = $contentWidth;
  5059. $contentWidth += $cw;
  5060. if ($this->allowCJKoverflow && !$is_table && preg_match("/[".$this->CJKoverflow."]/u", $c)) { $CJKoverflow = true; }
  5061. continue;
  5062. }
  5063. }
  5064. // or move lastchar(s) to next line to keep $c company = Oidashi
  5065. $m0 = $lastchar;
  5066. $m1 = $c;
  5067. while(preg_match("/[".$this->CJKfollowing."]/u", $m1) && mb_strlen($words[(count($words)-1)], $this->mb_enc)>2) {
  5068. // trim last letter off word[0]
  5069. $words[(count($words)-1)] = mb_substr($words[(count($words)-1)],0,mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, $this->mb_enc);
  5070. // and add it to savedContent for next line
  5071. $savedContent = $m0.$savedContent;
  5072. $m1 = $lastchar;
  5073. $lastchar = mb_substr($words[(count($words)-1)],mb_strlen($words[(count($words)-1)], $this->mb_enc)-1, 1, $this->mb_enc);
  5074. $m0 = $lastchar;
  5075. }
  5076. }
  5077. }
  5078. $lastContent = '';
  5079. for ( $w = 0; $w < count( $words ) ; $w++) { $lastContent .= $words[ $w ]." "; }
  5080. $savedFont = $this->saveFont();
  5081. // replace the current content with the cropped version
  5082. $currContent = rtrim( $lastContent );
  5083. }
  5084. else
  5085. /*-- END CJK-FONTS --*/
  5086. // if it looks like we didn't finish any words for this chunk
  5087. if ( count( $words ) == 1 ) {
  5088. // TO correct for error when word too wide for page - but only when one long word from left to right margin
  5089. if (count($content) == 1 && $currContent != ' ') {
  5090. // mPDF 5.5.10
  5091. $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc);
  5092. $lastContent = $words[0];
  5093. $savedFont = $this->saveFont();
  5094. // replace the current content with the cropped version
  5095. $currContent = rtrim( $lastContent );
  5096. }
  5097. else {
  5098. // save and crop off the content currently on the stack
  5099. $savedContent = array_pop( $content );
  5100. $savedContentB = $contentB[(count($contentB)-1)];
  5101. $savedFont = array_pop( $font );
  5102. // trim any trailing spaces off the last bit of content
  5103. $currContent =& $content[ count( $content ) - 1 ];
  5104. $currContent = rtrim( $currContent );
  5105. }
  5106. }
  5107. else { // otherwise, we need to find which bit to cut off
  5108. $lastContent = '';
  5109. for ( $w = 0; $w < count( $words ) - 1; $w++) { $lastContent .= $words[ $w ]." "; }
  5110. $savedContent = $words[ count( $words ) - 1 ];
  5111. $savedFont = $this->saveFont();
  5112. // replace the current content with the cropped version
  5113. $currContent = rtrim( $lastContent );
  5114. }
  5115. // CJK - strip CJK space at end of line
  5116. // &#x3000; = \xe3\x80\x80 = CJK space
  5117. if ($this->checkCJK) { $currContent = preg_replace("/\xe3\x80\x80$/",'',$currContent) ; } // *CJK-FONTS*
  5118. if (isset($this->objectbuffer[(count($content)-1)]) && $this->objectbuffer[(count($content)-1)]['type']=='dottab') {
  5119. $savedObj = array_pop( $this->objectbuffer );
  5120. $contentWidth -= ($this->objectbuffer[(count($content)-1)]['OUTER-WIDTH'] * _MPDFK);
  5121. }
  5122. // Set Current lineheight (correction factor)
  5123. $lhfixed = false;
  5124. /*-- LISTS --*/
  5125. if ($is_list) {
  5126. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  5127. $lhfixed = true;
  5128. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  5129. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5130. }
  5131. else {
  5132. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  5133. }
  5134. }
  5135. else
  5136. /*-- END LISTS --*/
  5137. /*-- TABLES --*/
  5138. if ($is_table) {
  5139. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  5140. $lhfixed = true;
  5141. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  5142. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  5143. }
  5144. else {
  5145. $this->lineheight_correction = $this->table_lineheight;
  5146. }
  5147. }
  5148. else
  5149. /*-- END TABLES --*/
  5150. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  5151. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  5152. $lhfixed = true;
  5153. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  5154. $this->lineheight_correction = $am[1] / $def_fontsize ;
  5155. }
  5156. else {
  5157. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  5158. }
  5159. }
  5160. else {
  5161. $this->lineheight_correction = $this->normalLineheight;
  5162. }
  5163. // update $contentWidth and $cutoffWidth since they changed with cropping
  5164. // Also correct lineheight to maximum fontsize (not for tables)
  5165. $contentWidth = 0;
  5166. // correct lineheight to maximum fontsize
  5167. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  5168. else { $maxlineHeight = 0; }
  5169. $this->forceExactLineheight = true;
  5170. $maxfontsize = 0;
  5171. // While we're at it, check for cursive text
  5172. $checkCursive=false;
  5173. if ($this->biDirectional) { $checkCursive=true; } // *RTL*
  5174. foreach ( $content as $k => $chunk )
  5175. {
  5176. $this->restoreFont( $font[ $k ]);
  5177. if (!isset($this->objectbuffer[$k])) {
  5178. if (!$this->usingCoreFont) {
  5179. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  5180. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC*
  5181. }
  5182. // Soft Hyphens chr(173)
  5183. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  5184. $content[$k] = $chunk = str_replace(chr(173),'',$chunk );
  5185. }
  5186. $contentWidth += $this->GetStringWidth( $chunk ) * _MPDFK;
  5187. if (!empty($this->spanborddet)) {
  5188. if (strpos($contentB[$k],'L')!==false) $contentWidth += $this->spanborddet['L']['w'] * _MPDFK;
  5189. if (strpos($contentB[$k],'R')!==false) $contentWidth += $this->spanborddet['R']['w'] * _MPDFK;
  5190. }
  5191. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$this->FontSize * $this->lineheight_correction ); }
  5192. if ($lhfixed && ($this->FontSize > $def_fontsize || ($this->FontSize > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  5193. $this->forceExactLineheight = false;
  5194. }
  5195. $maxfontsize = max($maxfontsize,$this->FontSize);
  5196. }
  5197. }
  5198. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  5199. $lastfontstyle = $font[count($font)-1]['style'];
  5200. if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  5201. $lastitalic = $this->FontSize*0.15*_MPDFK;
  5202. }
  5203. else { $lastitalic = 0; }
  5204. /*-- LISTS --*/
  5205. if ($is_list && is_array($this->bulletarray) && $this->bulletarray) {
  5206. $actfs = $this->bulletarray['fontsize'];
  5207. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  5208. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  5209. $maxfontsize = max($maxfontsize,$actfs);
  5210. }
  5211. /*-- END LISTS --*/
  5212. // when every text item checked i.e. $maxfontsize is set properly
  5213. $af = 0; // Above font
  5214. $bf = 0; // Below font
  5215. $mta = 0; // Maximum top-aligned
  5216. $mba = 0; // Maximum bottom-aligned
  5217. foreach ( $content as $k => $chunk ) {
  5218. if (isset($this->objectbuffer[$k]) && $this->objectbuffer[$k]) {
  5219. $contentWidth += $this->objectbuffer[$k]['OUTER-WIDTH'] * _MPDFK;
  5220. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  5221. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  5222. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  5223. if ($va == 'BS') { // (BASELINE default)
  5224. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  5225. }
  5226. else if ($va == 'M') {
  5227. $af = max($af, ($oh - $maxfontsize)/2);
  5228. $bf = max($bf, ($oh - $maxfontsize)/2);
  5229. }
  5230. else if ($va == 'TT') {
  5231. $bf = max($bf, ($oh - $maxfontsize));
  5232. }
  5233. else if ($va == 'TB') {
  5234. $af = max($af, ($oh - $maxfontsize));
  5235. }
  5236. else if ($va == 'T') {
  5237. $mta = max($mta, $oh);
  5238. }
  5239. else if ($va == 'B') {
  5240. $mba = max($mba, $oh);
  5241. }
  5242. }
  5243. }
  5244. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  5245. $maxlineHeight = $maxfontsize + $af + $bf;
  5246. }
  5247. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  5248. if ($mta > $maxlineHeight) {
  5249. $bf += ($mta - $maxlineHeight);
  5250. $maxlineHeight = $mta;
  5251. }
  5252. if ($mba > $maxlineHeight) {
  5253. $af += ($mba - $maxlineHeight);
  5254. $maxlineHeight = $mba;
  5255. }
  5256. $lineHeight = $maxlineHeight;
  5257. $cutoffWidth = $contentWidth;
  5258. // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  5259. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  5260. $this->linemaxfontsize = $def_fontsize;
  5261. }
  5262. else { $this->linemaxfontsize = $maxfontsize; }
  5263. $inclCursive=false;
  5264. foreach ( $content as $k => $chunk ) {
  5265. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5266. if ($this->usingCoreFont) {
  5267. $content[$k] = str_replace(chr(160),chr(32),$chunk );
  5268. }
  5269. else {
  5270. $content[$k] = str_replace(chr(194).chr(160),chr(32),$chunk );
  5271. if ($checkCursive) {
  5272. if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL*
  5273. if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC*
  5274. }
  5275. }
  5276. }
  5277. }
  5278. // JUSTIFICATION J
  5279. $jcharspacing = 0;
  5280. $jws = 0;
  5281. $nb_carac = 0;
  5282. $nb_spaces = 0;
  5283. // 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)
  5284. if(( $align == 'J' ) || (($cutoffWidth + $lastitalic > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) + 0.001) && !$CJKoverflow)) { // 0.001 is to correct for deviations converting mm=>pts
  5285. // JUSTIFY J (Use character spacing)
  5286. // WORD SPACING
  5287. foreach ( $content as $k => $chunk ) {
  5288. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5289. $nb_carac += mb_strlen( $chunk, $this->mb_enc ) ;
  5290. $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc ) ;
  5291. }
  5292. }
  5293. list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$cutoffWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive);
  5294. }
  5295. // WORD SPACING
  5296. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) );
  5297. $empty -= ($jcharspacing * $nb_carac);
  5298. $empty -= ($jws * $nb_spaces);
  5299. $empty /= _MPDFK;
  5300. $b = ''; //do not use borders
  5301. // Get PAGEBREAK TO TEST for height including the top border/padding
  5302. $check_h = max($this->divheight,$lineHeight);
  5303. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blklvl > 0) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5304. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  5305. }
  5306. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) {
  5307. $this->SetCol($this->NbCol-1);
  5308. }
  5309. // PAGEBREAK
  5310. // 'If' below used in order to fix "first-line of other page with justify on" bug
  5311. if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5312. $bak_x=$this->x;//Current X position
  5313. // WORD SPACING
  5314. $ws=$this->ws;//Word Spacing
  5315. $charspacing=$this->charspacing;//Character Spacing
  5316. $this->ResetSpacing();
  5317. $this->AddPage($this->CurOrientation);
  5318. $this->x = $bak_x;
  5319. // Added to correct for OddEven Margins
  5320. $currentx += $this->MarginCorrection;
  5321. $this->x += $this->MarginCorrection;
  5322. // WORD SPACING
  5323. $this->SetSpacing($charspacing,$ws);
  5324. }
  5325. if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) {
  5326. $this->printdivbuffer();
  5327. $this->keep_block_together = 0;
  5328. }
  5329. /*-- COLUMNS --*/
  5330. // COLS
  5331. // COLUMN CHANGE
  5332. if ($this->CurrCol != $oldcolumn) {
  5333. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5334. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5335. $oldcolumn = $this->CurrCol;
  5336. }
  5337. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5338. /*-- END COLUMNS --*/
  5339. // TOP MARGIN
  5340. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5341. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  5342. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5343. }
  5344. // Update y0 for top of block (used to paint border)
  5345. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5346. $this->blk[$this->blklvl]['y0'] = $this->y;
  5347. $this->blk[$this->blklvl]['startpage'] = $this->page;
  5348. }
  5349. // TOP PADDING and BORDER spacing/fill
  5350. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5351. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  5352. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  5353. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5354. }
  5355. $arraysize = count($content);
  5356. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  5357. // PAINT BACKGROUND FOR THIS LINE
  5358. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  5359. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL ;
  5360. if ($align == 'R') { $this->x += $empty; }
  5361. else if ($align == 'C') { $this->x += ($empty / 2); }
  5362. // Paragraph INDENT
  5363. if (isset($this->blk[$this->blklvl]['text_indent']) && ($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && ($blockdir !='rtl') && ($align !='C')) {
  5364. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5365. $this->x += $ti;
  5366. }
  5367. // DIRECTIONALITY RTL
  5368. $all_rtl = false;
  5369. $contains_rtl = false;
  5370. /*-- RTL --*/
  5371. if ($blockdir == 'rtl' || $this->biDirectional) {
  5372. $all_rtl = true;
  5373. foreach ( $content as $k => $chunk ) {
  5374. $reversed = $this->magic_reverse_dir($chunk, false, $blockdir);
  5375. if ($reversed > 0) { $contains_rtl = true; }
  5376. if ($reversed < 2) { $all_rtl = false; }
  5377. $content[$k] = $chunk;
  5378. }
  5379. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) {
  5380. $content = array_reverse($content,false);
  5381. $contentB = array_reverse($contentB,false);
  5382. }
  5383. }
  5384. /*-- END RTL --*/
  5385. foreach ( $content as $k => $chunk ) {
  5386. // FOR IMAGES - UPDATE POSITION
  5387. if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $dirk = $arraysize-1 - $k ; } else { $dirk = $k; }
  5388. $va = 'M'; // default for text
  5389. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  5390. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'] ;
  5391. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  5392. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  5393. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  5394. $va = $this->objectbuffer[$dirk]['vertical-align'];
  5395. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  5396. if ($va == 'BS') {
  5397. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5398. }
  5399. else if ($va == 'M' || $va == '') {
  5400. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  5401. }
  5402. else if ($va == 'TB') {
  5403. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5404. }
  5405. else if ($va == 'TT') {
  5406. $yadj += $af;
  5407. }
  5408. else if ($va == 'B') {
  5409. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5410. }
  5411. else if ($va == 'T') {
  5412. $yadj += 0;
  5413. }
  5414. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  5415. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  5416. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  5417. }
  5418. // DIRECTIONALITY RTL
  5419. if ((($blockdir == 'rtl') && ($contains_rtl )) || ($all_rtl )) { $this->restoreFont($font[$arraysize-1 - $k]); }
  5420. else { $this->restoreFont( $font[ $k ] ); }
  5421. $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws);
  5422. // Now unset these values so they don't influence GetStringwidth below or in fn. Cell
  5423. $this->fixedlSpacing = false;
  5424. $this->minwSpacing = 0;
  5425. // *********** SPAN BACKGROUND COLOR ***************** //
  5426. if ($this->spanbgcolor) {
  5427. $cor = $this->spanbgcolorarray;
  5428. $this->SetFColor($cor);
  5429. $save_fill = $fill; $spanfill = 1; $fill = 1;
  5430. }
  5431. if (!empty($this->spanborddet)) {
  5432. if (strpos($contentB[$k],'L')!==false) $this->x += $this->spanborddet['L']['w'];
  5433. if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0;
  5434. if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0;
  5435. }
  5436. // WORD SPACING
  5437. $stringWidth = $this->GetStringWidth($chunk );
  5438. $stringWidth += ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK );
  5439. $stringWidth += ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK );
  5440. if (isset($this->objectbuffer[$dirk])) { $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH']; }
  5441. if ($stringWidth==0) { $stringWidth = 0.000001; }
  5442. if ($k == $arraysize-1) {
  5443. $stringWidth -= ( $this->charspacing / _MPDFK );
  5444. $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)
  5445. }
  5446. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part
  5447. if (!empty($this->spanborddet)) {
  5448. if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w'];
  5449. }
  5450. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  5451. if (isset($spanfill) && $spanfill) {
  5452. $fill = $save_fill; $spanfill = 0;
  5453. if ($fill) { $this->SetFColor($bcor); }
  5454. }
  5455. }
  5456. if (!$is_table) {
  5457. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin']));
  5458. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']));
  5459. }
  5460. // move on to the next line, reset variables, tack on saved content and current char
  5461. $this->printobjectbuffer($is_table, $blockdir);
  5462. $this->objectbuffer = array();
  5463. /*-- LISTS --*/
  5464. // LIST BULLETS/NUMBERS
  5465. if ($is_list && is_array($this->bulletarray) && ($lineCount == 1) ) {
  5466. $this->ResetSpacing();
  5467. $bull = $this->bulletarray;
  5468. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  5469. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  5470. }
  5471. 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']]); }
  5472. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5473. $this->bullet = true;
  5474. $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5);
  5475. }
  5476. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  5477. //Output bullet
  5478. $this->x = $currentx;
  5479. if (isset($bull['x'])) { $this->x += $bull['x']; }
  5480. $this->y -= $lineHeight;
  5481. if (is_array($bull['col'])) { $this->SetTColor($bull['col']); }
  5482. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  5483. if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') {
  5484. $this->bullet = false;
  5485. }
  5486. $this->x = $currentx; // Reset
  5487. $this->y += $lineHeight;
  5488. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5489. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  5490. }
  5491. /*-- END LISTS --*/
  5492. /*-- CSS-IMAGE-FLOAT --*/
  5493. // Update values if set to skipline
  5494. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  5495. /*-- END CSS-IMAGE-FLOAT --*/
  5496. // Reset lineheight
  5497. $lineHeight = $this->divheight;
  5498. $valign = 'M';
  5499. $this->restoreFont( $savedFont );
  5500. $lbw = $rbw = 0; // Border widths
  5501. if (!empty($this->spanborddet)) {
  5502. $lbw = $this->spanborddet['L']['w'];
  5503. $rbw = $this->spanborddet['R']['w'];
  5504. }
  5505. $font = array();
  5506. $content = array();
  5507. $contentB = array();
  5508. $contentWidth = 0;
  5509. if (!empty($savedObj)) {
  5510. $this->objectbuffer[] = $savedObj;
  5511. $font[] = $savedFont;
  5512. $content[] = '';
  5513. $contentB[] = '';
  5514. $contentWidth += $savedObj['OUTER-WIDTH'] * _MPDFK;
  5515. }
  5516. $font[] = $savedFont;
  5517. $content[] = $savedContent . $c;
  5518. $contentB[] = $savedContentB ;
  5519. $currContent =& $content[ (count($content)-1) ];
  5520. // CJK - strip CJK space at end of line
  5521. // &#x3000; = \xe3\x80\x80 = CJK space
  5522. if ($this->checkCJK && $currContent == "\xe3\x80\x80") { $currContent = '' ; } // *CJK-FONTS*
  5523. $contentWidth += $this->GetStringWidth( $currContent ) * _MPDFK;
  5524. if (strpos($savedContentB,'L')!==false) $contentWidth += $lbw;
  5525. $cutoffWidth = $contentWidth;
  5526. $CJKoverflow = false;
  5527. }
  5528. // another character will fit, so add it on
  5529. else {
  5530. $contentWidth += $cw;
  5531. $currContent .= $c;
  5532. }
  5533. }
  5534. unset($content);
  5535. unset($contentB);
  5536. }
  5537. //----------------------END OF FLOWING BLOCK------------------------------------//
  5538. /*-- CSS-IMAGE-FLOAT --*/
  5539. // Update values if set to skipline
  5540. function _advanceFloatMargins() {
  5541. // Update floatmargins - L
  5542. if (isset($this->floatmargins['L']) && $this->floatmargins['L']['skipline'] && $this->floatmargins['L']['y0'] != $this->y) {
  5543. $yadj = $this->y - $this->floatmargins['L']['y0'];
  5544. $this->floatmargins['L']['y0'] = $this->y;
  5545. $this->floatmargins['L']['y1'] += $yadj;
  5546. // Update objattr in floatbuffer
  5547. if ($this->floatbuffer[$this->floatmargins['L']['id']]['border_left']['w']) {
  5548. $this->floatbuffer[$this->floatmargins['L']['id']]['BORDER-Y'] += $yadj;
  5549. }
  5550. $this->floatbuffer[$this->floatmargins['L']['id']]['INNER-Y'] += $yadj;
  5551. $this->floatbuffer[$this->floatmargins['L']['id']]['OUTER-Y'] += $yadj;
  5552. // Unset values
  5553. $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false;
  5554. $this->floatmargins['L']['skipline'] = false;
  5555. $this->floatmargins['L']['id'] = '';
  5556. }
  5557. // Update floatmargins - R
  5558. if (isset($this->floatmargins['R']) && $this->floatmargins['R']['skipline'] && $this->floatmargins['R']['y0'] != $this->y) {
  5559. $yadj = $this->y - $this->floatmargins['R']['y0'];
  5560. $this->floatmargins['R']['y0'] = $this->y;
  5561. $this->floatmargins['R']['y1'] += $yadj;
  5562. // Update objattr in floatbuffer
  5563. if ($this->floatbuffer[$this->floatmargins['R']['id']]['border_left']['w']) {
  5564. $this->floatbuffer[$this->floatmargins['R']['id']]['BORDER-Y'] += $yadj;
  5565. }
  5566. $this->floatbuffer[$this->floatmargins['R']['id']]['INNER-Y'] += $yadj;
  5567. $this->floatbuffer[$this->floatmargins['R']['id']]['OUTER-Y'] += $yadj;
  5568. // Unset values
  5569. $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false;
  5570. $this->floatmargins['R']['skipline'] = false;
  5571. $this->floatmargins['R']['id'] = '';
  5572. }
  5573. }
  5574. /*-- END CSS-IMAGE-FLOAT --*/
  5575. ////////////////////////////////////////////////////////////////////////////////
  5576. // ADDED forcewrap - to call from inline OBJECT functions to breakwords if necessary in cell
  5577. ////////////////////////////////////////////////////////////////////////////////
  5578. function WordWrap(&$text, $maxwidth, $forcewrap = 0) {
  5579. $biggestword=0;
  5580. $toonarrow=false;
  5581. $text = trim($text);
  5582. if ($text==='') return 0;
  5583. $space = $this->GetCharWidth(' ',false);
  5584. $lines = explode("\n", $text);
  5585. $text = '';
  5586. $count = 0;
  5587. foreach ($lines as $line) {
  5588. $words = explode(' ', $line);
  5589. $width = 0;
  5590. foreach ($words as $word) {
  5591. $word = trim($word);
  5592. $wordwidth = $this->GetStringWidth($word);
  5593. //Warn user that maxwidth is insufficient
  5594. if ($wordwidth > $maxwidth + 0.0001) {
  5595. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  5596. $toonarrow=true;
  5597. // ADDED
  5598. if ($forcewrap) {
  5599. while($wordwidth > $maxwidth) {
  5600. $chw = 0; // check width
  5601. for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) {
  5602. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  5603. if ($chw > $maxwidth ) {
  5604. if ($text) {
  5605. $text = rtrim($text)."\n".mb_substr($word,0,$i,$this->mb_enc );
  5606. $count++;
  5607. }
  5608. else {
  5609. $text = mb_substr($word,0,$i,$this->mb_enc );
  5610. }
  5611. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  5612. $wordwidth = $this->GetStringWidth($word);
  5613. $width = $maxwidth;
  5614. break;
  5615. }
  5616. }
  5617. }
  5618. }
  5619. }
  5620. if ($width + $wordwidth < $maxwidth - 0.0001) {
  5621. $width += $wordwidth + $space;
  5622. $text .= $word.' ';
  5623. }
  5624. else {
  5625. $width = $wordwidth + $space;
  5626. $text = rtrim($text)."\n".$word.' ';
  5627. $count++;
  5628. }
  5629. }
  5630. $text .= "\n";
  5631. $count++;
  5632. }
  5633. $text = rtrim($text);
  5634. //Return -(wordsize) if word is bigger than maxwidth
  5635. // ADDED
  5636. if ($forcewrap) { return $count; }
  5637. if (($toonarrow) && ($this->table_error_report)) {
  5638. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  5639. }
  5640. if ($toonarrow) return -$biggestword;
  5641. else return $count;
  5642. }
  5643. /*-- END HTML-CSS --*/
  5644. function _SetTextRendering($mode) {
  5645. if (!(($mode == 0) || ($mode == 1) || ($mode == 2)))
  5646. $this->Error("Text rendering mode should be 0, 1 or 2 (value : $mode)");
  5647. $tr = ($mode.' Tr');
  5648. 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); }
  5649. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5650. }
  5651. function SetTextOutline($width, $col=0) {
  5652. if ($width == false) //Now resets all values
  5653. {
  5654. $this->outline_on = false;
  5655. $this->SetLineWidth(0.2);
  5656. $this->SetDColor($this->ConvertColor(0));
  5657. $this->_SetTextRendering(0);
  5658. $tr = ('0 Tr');
  5659. 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); }
  5660. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5661. }
  5662. else
  5663. {
  5664. $this->SetLineWidth($width);
  5665. $this->SetDColor($col);
  5666. $tr = ('2 Tr');
  5667. 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); }
  5668. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5669. }
  5670. }
  5671. function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$paint=true, $constrain=true, $watermark=false, $shownoimg=true, $allowvector=true) {
  5672. $orig_srcpath = $file;
  5673. $this->GetFullPath($file);
  5674. $info=$this->_getImage($file, true, $allowvector, $orig_srcpath );
  5675. if(!$info && $paint) {
  5676. $info = $this->_getImage($this->noImageFile);
  5677. if ($info) {
  5678. $file = $this->noImageFile;
  5679. $w = ($info['w'] * (25.4/$this->dpi)); // 14 x 16px
  5680. $h = ($info['h'] * (25.4/$this->dpi)); // 14 x 16px
  5681. }
  5682. }
  5683. if(!$info) return false;
  5684. //Automatic width and height calculation if needed
  5685. if($w==0 and $h==0) {
  5686. /*-- IMAGES-WMF --*/
  5687. if ($info['type']=='wmf') {
  5688. // WMF units are twips (1/20pt)
  5689. // divide by 20 to get points
  5690. // divide by k to get user units
  5691. $w = abs($info['w'])/(20*_MPDFK);
  5692. $h = abs($info['h']) / (20*_MPDFK);
  5693. }
  5694. else
  5695. /*-- END IMAGES-WMF --*/
  5696. if ($info['type']=='svg') {
  5697. // returned SVG units are pts
  5698. // divide by k to get user units (mm)
  5699. $w = abs($info['w'])/_MPDFK;
  5700. $h = abs($info['h']) /_MPDFK;
  5701. }
  5702. else {
  5703. //Put image at default image dpi
  5704. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  5705. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  5706. }
  5707. }
  5708. if($w==0) $w=abs($h*$info['w']/$info['h']);
  5709. if($h==0) $h=abs($w*$info['h']/$info['w']);
  5710. /*-- WATERMARK --*/
  5711. if ($watermark) {
  5712. $maxw = $this->w;
  5713. $maxh = $this->h;
  5714. // Size = D PF or array
  5715. if (is_array($this->watermark_size)) {
  5716. $w = $this->watermark_size[0];
  5717. $h = $this->watermark_size[1];
  5718. }
  5719. else if (!is_string($this->watermark_size)) {
  5720. $maxw -= $this->watermark_size*2;
  5721. $maxh -= $this->watermark_size*2;
  5722. $w = $maxw;
  5723. $h=abs($w*$info['h']/$info['w']);
  5724. if ($h > $maxh ) {
  5725. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5726. }
  5727. }
  5728. else if ($this->watermark_size == 'F') {
  5729. if ($this->ColActive) { $maxw = $this->w - ($this->DeflMargin + $this->DefrMargin); }
  5730. else { $maxw = $this->pgwidth; }
  5731. $maxh = $this->h - ($this->tMargin + $this->bMargin);
  5732. $w = $maxw;
  5733. $h=abs($w*$info['h']/$info['w']);
  5734. if ($h > $maxh ) {
  5735. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5736. }
  5737. }
  5738. else if ($this->watermark_size == 'P') { // Default P
  5739. $w = $maxw;
  5740. $h=abs($w*$info['h']/$info['w']);
  5741. if ($h > $maxh ) {
  5742. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5743. }
  5744. }
  5745. // Automatically resize to maximum dimensions of page if too large
  5746. if ($w > $maxw) {
  5747. $w = $maxw;
  5748. $h=abs($w*$info['h']/$info['w']);
  5749. }
  5750. if ($h > $maxh ) {
  5751. $h = $maxh ;
  5752. $w=abs($h*$info['w']/$info['h']);
  5753. }
  5754. // Position
  5755. if (is_array($this->watermark_pos)) {
  5756. $x = $this->watermark_pos[0];
  5757. $y = $this->watermark_pos[1];
  5758. }
  5759. else if ($this->watermark_pos == 'F') { // centred on printable area
  5760. if ($this->ColActive) { // *COLUMNS*
  5761. if (($this->mirrorMargins) && (($this->page)%2==0)) { $xadj = $this->DeflMargin-$this->DefrMargin; } // *COLUMNS*
  5762. else { $xadj = 0; } // *COLUMNS*
  5763. $x = ($this->DeflMargin - $xadj + ($this->w - ($this->DeflMargin + $this->DefrMargin))/2) - ($w/2); // *COLUMNS*
  5764. } // *COLUMNS*
  5765. else { // *COLUMNS*
  5766. $x = ($this->lMargin + ($this->pgwidth)/2) - ($w/2);
  5767. } // *COLUMNS*
  5768. $y = ($this->tMargin + ($this->h - ($this->tMargin + $this->bMargin))/2) - ($h/2);
  5769. }
  5770. else { // default P - centred on whole page
  5771. $x = ($this->w/2) - ($w/2);
  5772. $y = ($this->h/2) - ($h/2);
  5773. }
  5774. /*-- IMAGES-WMF --*/
  5775. if ($info['type']=='wmf') {
  5776. $sx = $w*_MPDFK / $info['w'];
  5777. $sy = -$h*_MPDFK / $info['h'];
  5778. $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']);
  5779. }
  5780. else
  5781. /*-- END IMAGES-WMF --*/
  5782. if ($info['type']=='svg') {
  5783. $sx = $w*_MPDFK / $info['w'];
  5784. $sy = -$h*_MPDFK / $info['h'];
  5785. $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']);
  5786. }
  5787. else {
  5788. $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']);
  5789. }
  5790. if ($this->watermarkImgBehind) {
  5791. $outstring = $this->watermarkImgAlpha . "\n" . $outstring . "\n" . $this->SetAlpha(1, 'Normal', true) . "\n";
  5792. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$outstring."\n".'\\1', $this->pages[$this->page]);
  5793. }
  5794. else { $this->_out($outstring); }
  5795. return 0;
  5796. } // end of IF watermark
  5797. /*-- END WATERMARK --*/
  5798. if ($constrain) {
  5799. // Automatically resize to maximum dimensions of page if too large
  5800. if (isset($this->blk[$this->blklvl]['inner_width']) && $this->blk[$this->blklvl]['inner_width']) { $maxw = $this->blk[$this->blklvl]['inner_width']; }
  5801. else { $maxw = $this->pgwidth; }
  5802. if ($w > $maxw) {
  5803. $w = $maxw;
  5804. $h=abs($w*$info['h']/$info['w']);
  5805. }
  5806. if ($h > $this->h - ($this->tMargin + $this->bMargin + 1)) { // see below - +10 to avoid drawing too close to border of page
  5807. $h = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  5808. if ($this->fullImageHeight) { $h = $this->fullImageHeight; }
  5809. $w=abs($h*$info['w']/$info['h']);
  5810. }
  5811. //Avoid drawing out of the paper(exceeding width limits).
  5812. //if ( ($x + $w) > $this->fw ) {
  5813. if ( ($x + $w) > $this->w ) {
  5814. $x = $this->lMargin;
  5815. $y += 5;
  5816. }
  5817. $changedpage = false;
  5818. $oldcolumn = $this->CurrCol;
  5819. //Avoid drawing out of the page.
  5820. if($y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5821. $this->AddPage($this->CurOrientation);
  5822. // Added to correct for OddEven Margins
  5823. $x=$x +$this->MarginCorrection;
  5824. $y = $tMargin + $this->margin_header;
  5825. $changedpage = true;
  5826. }
  5827. /*-- COLUMNS --*/
  5828. // COLS
  5829. // COLUMN CHANGE
  5830. if ($this->CurrCol != $oldcolumn) {
  5831. $y = $this->y0;
  5832. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5833. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5834. }
  5835. /*-- END COLUMNS --*/
  5836. } // end of IF constrain
  5837. /*-- IMAGES-WMF --*/
  5838. if ($info['type']=='wmf') {
  5839. $sx = $w*_MPDFK / $info['w'];
  5840. $sy = -$h*_MPDFK / $info['h'];
  5841. $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']);
  5842. }
  5843. else
  5844. /*-- END IMAGES-WMF --*/
  5845. if ($info['type']=='svg') {
  5846. $sx = $w*_MPDFK / $info['w'];
  5847. $sy = -$h*_MPDFK / $info['h'];
  5848. $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']);
  5849. }
  5850. else {
  5851. $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']);
  5852. }
  5853. if($paint) {
  5854. $this->_out($outstring);
  5855. if($link) $this->Link($x,$y,$w,$h,$link);
  5856. // Avoid writing text on top of the image. // THIS WAS OUTSIDE THE if ($paint) bit!!!!!!!!!!!!!!!!
  5857. $this->y = $y + $h;
  5858. }
  5859. //Return width-height array
  5860. $sizesarray['WIDTH'] = $w;
  5861. $sizesarray['HEIGHT'] = $h;
  5862. $sizesarray['X'] = $x; //Position before painting image
  5863. $sizesarray['Y'] = $y; //Position before painting image
  5864. $sizesarray['OUTPUT'] = $outstring;
  5865. $sizesarray['IMAGE_ID'] = $info['i'];
  5866. $sizesarray['itype'] = $info['type'];
  5867. $sizesarray['set-dpi'] = $info['set-dpi'];
  5868. return $sizesarray;
  5869. }
  5870. //=============================================================
  5871. //=============================================================
  5872. //=============================================================
  5873. //=============================================================
  5874. //=============================================================
  5875. /*-- HTML-CSS --*/
  5876. function _getObjAttr($t) {
  5877. $c = explode("\xbb\xa4\xac",$t,2);
  5878. $c = explode(",",$c[1],2);
  5879. foreach($c as $v) {
  5880. $v = explode("=",$v,2);
  5881. $sp[$v[0]] = $v[1];
  5882. }
  5883. return (unserialize($sp['objattr']));
  5884. }
  5885. function inlineObject($type,$x,$y,$objattr,$Lmargin,$widthUsed,$maxWidth,$lineHeight,$paint=false,$is_table=false)
  5886. {
  5887. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  5888. // NB $x is only used when paint=true
  5889. // Lmargin not used
  5890. $w = 0;
  5891. if (isset($objattr['width'])) { $w = $objattr['width']/$k; }
  5892. $h = 0;
  5893. if (isset($objattr['height'])) { $h = abs($objattr['height']/$k); }
  5894. $widthLeft = $maxWidth - $widthUsed;
  5895. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  5896. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  5897. // For Images
  5898. if (isset($objattr['border_left'])) {
  5899. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right'])/$k;
  5900. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom'])/$k;
  5901. if ($type == 'image' || $type == 'barcode' || $type == 'textcircle') {
  5902. $extraWidth += ($objattr['padding_left'] + $objattr['padding_right'])/$k;
  5903. $extraHeight += ($objattr['padding_top'] + $objattr['padding_bottom'])/$k;
  5904. }
  5905. }
  5906. if (!isset($objattr['vertical-align'])) { $objattr['vertical-align'] = 'M'; }
  5907. if ($type == 'image' || (isset($objattr['subtype']) && $objattr['subtype'] == 'IMAGE')) {
  5908. if (isset($objattr['itype']) && ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg')) {
  5909. $file = $objattr['file'];
  5910. $info=$this->formobjects[$file];
  5911. }
  5912. else if (isset($objattr['file'])) {
  5913. $file = $objattr['file'];
  5914. $info=$this->images[$file];
  5915. }
  5916. }
  5917. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  5918. $w = 0.00001;
  5919. $h = 0.00001;
  5920. }
  5921. // TEST whether need to skipline
  5922. if (!$paint) {
  5923. if ($type == 'hr') { // always force new line
  5924. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-2, $w ,$h ); } // New page + new line
  5925. else { return array(1, $w ,$h ); } // new line
  5926. }
  5927. else {
  5928. if ($widthUsed > 0 && $w > $widthLeft && (!$is_table || $type != 'image')) { // New line needed
  5929. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter) { return array(-2,$w ,$h ); } // New page + new line
  5930. return array(1,$w ,$h ); // new line
  5931. }
  5932. else if ($widthUsed > 0 && $w > $widthLeft && $is_table) { // New line needed in TABLE
  5933. return array(1,$w ,$h ); // new line
  5934. }
  5935. // Will fit on line but NEW PAGE REQUIRED
  5936. else if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-1,$w ,$h ); }
  5937. else { return array(0,$w ,$h ); }
  5938. }
  5939. }
  5940. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  5941. $w = 0.00001;
  5942. $h = 0.00001;
  5943. $objattr['BORDER-WIDTH'] = 0;
  5944. $objattr['BORDER-HEIGHT'] = 0;
  5945. $objattr['BORDER-X'] = $x;
  5946. $objattr['BORDER-Y'] = $y;
  5947. $objattr['INNER-WIDTH'] = 0;
  5948. $objattr['INNER-HEIGHT'] = 0;
  5949. $objattr['INNER-X'] = $x;
  5950. $objattr['INNER-Y'] = $y;
  5951. }
  5952. if ($type == 'image') {
  5953. // Automatically resize to width remaining
  5954. if ($w > $widthLeft && !$is_table) {
  5955. $w = $widthLeft ;
  5956. $h=abs($w*$info['h']/$info['w']);
  5957. }
  5958. $img_w = $w - $extraWidth ;
  5959. $img_h = $h - $extraHeight ;
  5960. $objattr['BORDER-WIDTH'] = $img_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  5961. $objattr['BORDER-HEIGHT'] = $img_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  5962. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  5963. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  5964. $objattr['INNER-WIDTH'] = $img_w;
  5965. $objattr['INNER-HEIGHT'] = $img_h;
  5966. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  5967. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  5968. $objattr['ID'] = $info['i'];
  5969. }
  5970. if ($type == 'input' && $objattr['subtype'] == 'IMAGE') {
  5971. $img_w = $w - $extraWidth ;
  5972. $img_h = $h - $extraHeight ;
  5973. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  5974. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  5975. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  5976. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  5977. $objattr['INNER-WIDTH'] = $img_w;
  5978. $objattr['INNER-HEIGHT'] = $img_h;
  5979. $objattr['INNER-X'] = $x + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  5980. $objattr['INNER-Y'] = $y + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  5981. $objattr['ID'] = $info['i'];
  5982. }
  5983. if ($type == 'barcode' || $type == 'textcircle') {
  5984. $b_w = $w - $extraWidth ;
  5985. $b_h = $h - $extraHeight ;
  5986. $objattr['BORDER-WIDTH'] = $b_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  5987. $objattr['BORDER-HEIGHT'] = $b_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  5988. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  5989. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  5990. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  5991. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  5992. $objattr['INNER-WIDTH'] = $b_w;
  5993. $objattr['INNER-HEIGHT'] = $b_h;
  5994. }
  5995. if ($type == 'textarea') {
  5996. // Automatically resize to width remaining
  5997. if ($w > $widthLeft && !$is_table) {
  5998. $w = $widthLeft ;
  5999. }
  6000. if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter) {
  6001. $h=$this->h - $y - $this->bMargin;
  6002. }
  6003. }
  6004. if ($type == 'hr') {
  6005. if ($is_table) {
  6006. $objattr['INNER-WIDTH'] = $maxWidth * $objattr['W-PERCENT']/100;
  6007. $objattr['width'] = $objattr['INNER-WIDTH'];
  6008. $w = $maxWidth;
  6009. }
  6010. else {
  6011. if ($w>$maxWidth) { $w = $maxWidth; }
  6012. $objattr['INNER-WIDTH'] = $w;
  6013. $w = $maxWidth;
  6014. }
  6015. }
  6016. if (($type == 'select') || ($type == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD'))) {
  6017. // Automatically resize to width remaining
  6018. if ($w > $widthLeft && !$is_table) {
  6019. $w = $widthLeft;
  6020. }
  6021. }
  6022. if ($type == 'textarea' || $type == 'select' || $type == 'input') {
  6023. if (isset($objattr['fontsize'])) $objattr['fontsize'] /= $k;
  6024. if (isset($objattr['linewidth'])) $objattr['linewidth'] /= $k;
  6025. }
  6026. if (!isset($objattr['BORDER-Y'])) { $objattr['BORDER-Y'] = 0; }
  6027. if (!isset($objattr['BORDER-X'])) { $objattr['BORDER-X'] = 0; }
  6028. if (!isset($objattr['INNER-Y'])) { $objattr['INNER-Y'] = 0; }
  6029. if (!isset($objattr['INNER-X'])) { $objattr['INNER-X'] = 0; }
  6030. //Return width-height array
  6031. $objattr['OUTER-WIDTH'] = $w;
  6032. $objattr['OUTER-HEIGHT'] = $h;
  6033. $objattr['OUTER-X'] = $x;
  6034. $objattr['OUTER-Y'] = $y;
  6035. return $objattr;
  6036. }
  6037. /*-- END HTML-CSS --*/
  6038. //=============================================================
  6039. //=============================================================
  6040. //=============================================================
  6041. //=============================================================
  6042. //=============================================================
  6043. function SetLineJoin($mode=0)
  6044. {
  6045. $s=sprintf('%d j',$mode);
  6046. 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); }
  6047. $this->pageoutput[$this->page]['LineJoin'] = $s;
  6048. }
  6049. function SetLineCap($mode=2) {
  6050. $s=sprintf('%d J',$mode);
  6051. 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); }
  6052. $this->pageoutput[$this->page]['LineCap'] = $s;
  6053. }
  6054. function SetDash($black=false,$white=false)
  6055. {
  6056. if($black and $white) $s=sprintf('[%.3F %.3F] 0 d',$black*_MPDFK,$white*_MPDFK);
  6057. else $s='[] 0 d';
  6058. 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); }
  6059. $this->pageoutput[$this->page]['Dash'] = $s;
  6060. }
  6061. function SetDisplayPreferences($preferences) {
  6062. // String containing any or none of /HideMenubar/HideToolbar/HideWindowUI/DisplayDocTitle/CenterWindow/FitWindow
  6063. $this->DisplayPreferences .= $preferences;
  6064. }
  6065. function Ln($h='',$collapsible=0)
  6066. {
  6067. // Added collapsible to allow collapsible top-margin on new page
  6068. //Line feed; default value is last cell height
  6069. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  6070. if ($collapsible && ($this->y==$this->tMargin) && (!$this->ColActive)) { $h = 0; }
  6071. if(is_string($h)) $this->y+=$this->lasth;
  6072. else $this->y+=$h;
  6073. }
  6074. /*-- HTML-CSS --*/
  6075. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6076. function DivLn($h,$level=-3,$move_y=true,$collapsible=false,$state=0) {
  6077. // this->x is returned as it was
  6078. // adds lines (y) where DIV bgcolors are filled in
  6079. // allows .00001 as nominal height used for bookmarks/annotations etc.
  6080. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)) && (!$this->ColActive)) { return; }
  6081. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->y0)) && ($this->ColActive) && $this->CurrCol == 0) { return; } // *COLUMNS*
  6082. // Still use this method if columns or page-break-inside: avoid, as it allows repositioning later
  6083. // otherwise, now uses PaintDivBB()
  6084. if (!$this->ColActive && !$this->keep_block_together && !$this->kwt) {
  6085. if ($move_y && !$this->ColActive) { $this->y += $h; }
  6086. return;
  6087. }
  6088. if ($level == -3) { $level = $this->blklvl; }
  6089. $firstblockfill = $this->GetFirstBlockFill();
  6090. if ($firstblockfill && $this->blklvl > 0 && $this->blklvl >= $firstblockfill) {
  6091. $last_x = 0;
  6092. $last_w = 0;
  6093. $last_fc = $this->FillColor;
  6094. $bak_x = $this->x;
  6095. $bak_h = $this->divheight;
  6096. $this->divheight = 0; // Temporarily turn off divheight - as Cell() uses it to check for PageBreak
  6097. for ($blvl=$firstblockfill;$blvl<=$level;$blvl++) {
  6098. $this->SetBlockFill($blvl);
  6099. $this->x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6100. if ($last_x != $this->lMargin + $this->blk[$blvl]['outer_left_margin'] || $last_w != $this->blk[$blvl]['width'] || $last_fc != $this->FillColor) {
  6101. $x = $this->x;
  6102. $this->Cell( ($this->blk[$blvl]['width']), $h, '', '', 0, '', 1);
  6103. if (!$this->keep_block_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  6104. $this->x = $x;
  6105. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  6106. if ($blvl == $this->blklvl) { $this->PaintDivLnBorder($state,$blvl,$h); }
  6107. else { $this->PaintDivLnBorder(0,$blvl,$h); }
  6108. }
  6109. }
  6110. $last_x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  6111. $last_w = $this->blk[$blvl]['width'];
  6112. $last_fc = $this->FillColor;
  6113. }
  6114. // Reset current block fill
  6115. if (isset($this->blk[$this->blklvl]['bgcolorarray'])) {
  6116. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  6117. $this->SetFColor($bcor);
  6118. }
  6119. $this->x = $bak_x;
  6120. $this->divheight = $bak_h;
  6121. }
  6122. if ($move_y) { $this->y += $h; }
  6123. }
  6124. /*-- END HTML-CSS --*/
  6125. function SetX($x)
  6126. {
  6127. //Set x position
  6128. if($x >= 0) $this->x=$x;
  6129. else $this->x = $this->w + $x;
  6130. }
  6131. function SetY($y)
  6132. {
  6133. //Set y position and reset x
  6134. $this->x=$this->lMargin;
  6135. if($y>=0)
  6136. $this->y=$y;
  6137. else
  6138. $this->y=$this->h+$y;
  6139. }
  6140. function SetXY($x,$y)
  6141. {
  6142. //Set x and y positions
  6143. $this->SetY($y);
  6144. $this->SetX($x);
  6145. }
  6146. function Output($name='',$dest='')
  6147. {
  6148. //Output PDF to some destination
  6149. if ($this->showStats) {
  6150. echo '<div>Generated in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds</div>';
  6151. }
  6152. //Finish document if necessary
  6153. if ($this->progressBar) { $this->UpdateProgressBar(1,'100','Finished'); } // *PROGRESS-BAR*
  6154. if($this->state < 3) $this->Close();
  6155. if ($this->progressBar) { $this->UpdateProgressBar(2,'100','Finished'); } // *PROGRESS-BAR*
  6156. // fn. error_get_last is only in PHP>=5.2
  6157. if ($this->debug && function_exists('error_get_last') && error_get_last()) {
  6158. $e = error_get_last();
  6159. if (($e['type'] < 2048 && $e['type'] != 8) || (intval($e['type']) & intval(ini_get("error_reporting")))) {
  6160. echo "<p>Error message detected - PDF file generation aborted.</p>";
  6161. echo $e['message'].'<br />';
  6162. echo 'File: '.$e['file'].'<br />';
  6163. echo 'Line: '.$e['line'].'<br />';
  6164. exit;
  6165. }
  6166. }
  6167. if (($this->PDFA || $this->PDFX) && $this->encrypted) { $this->Error("PDFA1-b or PDFX/1-a does not permit encryption of documents."); }
  6168. if (count($this->PDFAXwarnings) && (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto))) {
  6169. if ($this->PDFA) {
  6170. echo '<div>WARNING - This file could not be generated as it stands as a PDFA1-b compliant file.</div>';
  6171. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFAauto=true;</i></div>';
  6172. echo '<div>Action that mPDF will take to automatically force PDFA1-b compliance are shown in brackets.</div>';
  6173. }
  6174. else {
  6175. echo '<div>WARNING - This file could not be generated as it stands as a PDFX/1-a compliant file.</div>';
  6176. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFXauto=true;</i></div>';
  6177. echo '<div>Action that mPDF will take to automatically force PDFX/1-a compliance are shown in brackets.</div>';
  6178. }
  6179. echo '<div>Warning(s) generated:</div><ul>';
  6180. $this->PDFAXwarnings = array_unique($this->PDFAXwarnings);
  6181. foreach($this->PDFAXwarnings AS $w) {
  6182. echo '<li>'.$w.'</li>';
  6183. }
  6184. echo '</ul>';
  6185. exit;
  6186. }
  6187. if ($this->showStats) {
  6188. echo '<div>Compiled in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds (total)</div>';
  6189. echo '<div>Peak Memory usage '.number_format((memory_get_peak_usage(true)/(1024*1024)),2).' MB</div>';
  6190. echo '<div>PDF file size '.number_format((strlen($this->buffer)/1024)).' kB</div>';
  6191. echo '<div>Number of fonts '.count($this->fonts).'</div>';
  6192. exit;
  6193. }
  6194. if(is_bool($dest)) $dest=$dest ? 'D' : 'F';
  6195. $dest=strtoupper($dest);
  6196. if($dest=='') {
  6197. if($name=='') {
  6198. $name='mpdf.pdf';
  6199. $dest='I';
  6200. }
  6201. else { $dest='F'; }
  6202. }
  6203. /*-- PROGRESS-BAR --*/
  6204. if ($this->progressBar && ($dest=='D' || $dest=='I')) {
  6205. if($name=='') { $name='mpdf.pdf'; }
  6206. $tempfile = '_tempPDF'.RAND(1,10000);
  6207. //Save to local file
  6208. $f=fopen(_MPDF_TEMP_PATH.$tempfile.'.pdf','wb');
  6209. if(!$f) $this->Error('Unable to create temporary output file: '.$tempfile.'.pdf');
  6210. fwrite($f,$this->buffer,strlen($this->buffer));
  6211. fclose($f);
  6212. $this->UpdateProgressBar(3,'','Finished');
  6213. echo '<script type="text/javascript">
  6214. var form = document.createElement("form");
  6215. form.setAttribute("method", "post");
  6216. form.setAttribute("action", "'._MPDF_URI.'includes/out.php");
  6217. var hiddenField = document.createElement("input");
  6218. hiddenField.setAttribute("type", "hidden");
  6219. hiddenField.setAttribute("name", "filename");
  6220. hiddenField.setAttribute("value", "'.$tempfile.'");
  6221. form.appendChild(hiddenField);
  6222. var hiddenField = document.createElement("input");
  6223. hiddenField.setAttribute("type", "hidden");
  6224. hiddenField.setAttribute("name", "dest");
  6225. hiddenField.setAttribute("value", "'.$dest.'");
  6226. form.appendChild(hiddenField);
  6227. var hiddenField = document.createElement("input");
  6228. hiddenField.setAttribute("type", "hidden");
  6229. hiddenField.setAttribute("name", "opname");
  6230. hiddenField.setAttribute("value", "'.$name.'");
  6231. form.appendChild(hiddenField);
  6232. var hiddenField = document.createElement("input");
  6233. hiddenField.setAttribute("type", "hidden");
  6234. hiddenField.setAttribute("name", "path");
  6235. hiddenField.setAttribute("value", "'.urlencode(_MPDF_TEMP_PATH).'");
  6236. form.appendChild(hiddenField);
  6237. document.body.appendChild(form);
  6238. form.submit();
  6239. </script>
  6240. </div>
  6241. </body>
  6242. </html>';
  6243. exit;
  6244. }
  6245. else {
  6246. if ($this->progressBar) { $this->UpdateProgressBar(3,'','Finished'); }
  6247. /*-- END PROGRESS-BAR --*/
  6248. switch($dest) {
  6249. case 'I':
  6250. 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; }
  6251. //Send to standard output
  6252. if(PHP_SAPI!='cli') {
  6253. //We send to a browser
  6254. header('Content-Type: application/pdf');
  6255. if(headers_sent())
  6256. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6257. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  6258. // don't use length if server using compression
  6259. header('Content-Length: '.strlen($this->buffer));
  6260. }
  6261. header('Content-disposition: inline; filename="'.$name.'"');
  6262. header('Cache-Control: public, must-revalidate, max-age=0');
  6263. header('Pragma: public');
  6264. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6265. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6266. }
  6267. echo $this->buffer;
  6268. break;
  6269. case 'D':
  6270. //Download file
  6271. header('Content-Description: File Transfer');
  6272. if (headers_sent())
  6273. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6274. header('Content-Transfer-Encoding: binary');
  6275. header('Cache-Control: public, must-revalidate, max-age=0');
  6276. header('Pragma: public');
  6277. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
  6278. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  6279. header('Content-Type: application/force-download');
  6280. header('Content-Type: application/octet-stream', false);
  6281. header('Content-Type: application/download', false);
  6282. header('Content-Type: application/pdf', false);
  6283. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  6284. // don't use length if server using compression
  6285. header('Content-Length: '.strlen($this->buffer));
  6286. }
  6287. header('Content-disposition: attachment; filename="'.$name.'"');
  6288. echo $this->buffer;
  6289. break;
  6290. case 'F':
  6291. //Save to local file
  6292. $f=fopen($name,'wb');
  6293. if(!$f) $this->Error('Unable to create output file: '.$name);
  6294. fwrite($f,$this->buffer,strlen($this->buffer));
  6295. fclose($f);
  6296. break;
  6297. case 'S':
  6298. //Return as a string
  6299. return $this->buffer;
  6300. default:
  6301. $this->Error('Incorrect output destination: '.$dest);
  6302. }
  6303. } // *PROGRESS-BAR*
  6304. //======================================================================================================
  6305. // DELETE OLD TMP FILES - Housekeeping
  6306. // Delete any files in tmp/ directory that are >1 hrs old
  6307. $interval = 3600;
  6308. if ($handle = opendir(preg_replace('/\/$/','',_MPDF_TEMP_PATH))) {
  6309. while (false !== ($file = readdir($handle))) {
  6310. if (!is_dir($file) && ((filemtime(_MPDF_TEMP_PATH.$file)+$interval) < time()) && ($file != "..") && ($file != ".")) { // mPDF 5.4.19
  6311. unlink(_MPDF_TEMP_PATH.$file);
  6312. }
  6313. }
  6314. closedir($handle);
  6315. }
  6316. //==============================================================================================================
  6317. return '';
  6318. }
  6319. // *****************************************************************************
  6320. // *
  6321. // Protected methods *
  6322. // *
  6323. // *****************************************************************************
  6324. function _dochecks()
  6325. {
  6326. //Check for locale-related bug
  6327. if(1.1==1)
  6328. $this->Error('Don\'t alter the locale before including mPDF');
  6329. //Check for decimal separator
  6330. if(sprintf('%.1f',1.0)!='1.0')
  6331. setlocale(LC_NUMERIC,'C');
  6332. // mPDF 5.4.11
  6333. $mqr=ini_get("magic_quotes_runtime");
  6334. if ($mqr) { $this->Error('mPDF requires magic_quotes_runtime to be turned off e.g. by using ini_set("magic_quotes_runtime", 0);'); }
  6335. }
  6336. function _begindoc()
  6337. {
  6338. //Start document
  6339. $this->state=1;
  6340. $this->_out('%PDF-'.$this->pdf_version);
  6341. $this->_out('%'.chr(226).chr(227).chr(207).chr(211)); // 4 chars > 128 to show binary file
  6342. }
  6343. /*-- HTMLHEADERS-FOOTERS --*/
  6344. function _puthtmlheaders() {
  6345. $this->state=2;
  6346. $nb=$this->page;
  6347. for($n=1;$n<=$nb;$n++) {
  6348. if ($this->mirrorMargins && $n%2==0) { $OE = 'E'; } // EVEN
  6349. else { $OE = 'O'; }
  6350. $this->page = $n;
  6351. if (isset($this->saveHTMLHeader[$n][$OE])) {
  6352. $html = $this->saveHTMLHeader[$n][$OE]['html'];
  6353. $this->lMargin = $this->saveHTMLHeader[$n][$OE]['ml'];
  6354. $this->rMargin = $this->saveHTMLHeader[$n][$OE]['mr'];
  6355. $this->tMargin = $this->saveHTMLHeader[$n][$OE]['mh'];
  6356. $this->bMargin = $this->saveHTMLHeader[$n][$OE]['mf'];
  6357. $this->margin_header = $this->saveHTMLHeader[$n][$OE]['mh'];
  6358. $this->margin_footer = $this->saveHTMLHeader[$n][$OE]['mf'];
  6359. $this->w = $this->saveHTMLHeader[$n][$OE]['pw'];
  6360. $this->h = $this->saveHTMLHeader[$n][$OE]['ph'];
  6361. $rotate = (isset($this->saveHTMLHeader[$n][$OE]['rotate']) ? $this->saveHTMLHeader[$n][$OE]['rotate'] : null);
  6362. $this->Reset();
  6363. $this->pageoutput[$n] = array();
  6364. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6365. $this->x = $this->lMargin;
  6366. $this->y = $this->margin_header;
  6367. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6368. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6369. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6370. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6371. $this->HTMLheaderPageLinks = array();
  6372. $this->HTMLheaderPageAnnots = array();
  6373. $this->HTMLheaderPageForms = array();
  6374. $this->pageBackgrounds = array();
  6375. $this->writingHTMLheader = true;
  6376. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6377. $this->writingHTMLheader = false;
  6378. $this->Reset();
  6379. $this->pageoutput[$n] = array();
  6380. $s = $this->PrintPageBackgrounds();
  6381. $this->headerbuffer = $s . $this->headerbuffer;
  6382. $os = '';
  6383. if ($rotate) {
  6384. $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK));
  6385. }
  6386. $os .= $this->headerbuffer ;
  6387. if ($rotate) {
  6388. $os .= ' Q' . "\n";
  6389. }
  6390. // Writes over the page background but behind any other output on page
  6391. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6392. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6393. $lks = $this->HTMLheaderPageLinks;
  6394. foreach($lks AS $lk) {
  6395. if ($rotate) {
  6396. $lw = $lk[2];
  6397. $lh = $lk[3];
  6398. $lk[2] = $lh;
  6399. $lk[3] = $lw; // swap width and height
  6400. $ax = $lk[0]/_MPDFK;
  6401. $ay = $lk[1]/_MPDFK;
  6402. $bx = $ay-($lh/_MPDFK);
  6403. $by = $this->w-$ax;
  6404. $lk[0] = $bx*_MPDFK;
  6405. $lk[1] = ($this->h-$by)*_MPDFK - $lw;
  6406. }
  6407. $this->PageLinks[$n][]=$lk;
  6408. }
  6409. /*-- FORMS --*/
  6410. foreach($this->HTMLheaderPageForms AS $f) {
  6411. $this->form->forms[$f['n']] = $f;
  6412. }
  6413. /*-- END FORMS --*/
  6414. }
  6415. if (isset($this->saveHTMLFooter[$n][$OE])) {
  6416. $html = $this->saveHTMLFooter[$this->page][$OE]['html'];
  6417. $this->lMargin = $this->saveHTMLFooter[$n][$OE]['ml'];
  6418. $this->rMargin = $this->saveHTMLFooter[$n][$OE]['mr'];
  6419. $this->tMargin = $this->saveHTMLFooter[$n][$OE]['mh'];
  6420. $this->bMargin = $this->saveHTMLFooter[$n][$OE]['mf'];
  6421. $this->margin_header = $this->saveHTMLFooter[$n][$OE]['mh'];
  6422. $this->margin_footer = $this->saveHTMLFooter[$n][$OE]['mf'];
  6423. $this->w = $this->saveHTMLFooter[$n][$OE]['pw'];
  6424. $this->h = $this->saveHTMLFooter[$n][$OE]['ph'];
  6425. $rotate = (isset($this->saveHTMLFooter[$n][$OE]['rotate']) ? $this->saveHTMLFooter[$n][$OE]['rotate'] : null);
  6426. $this->Reset();
  6427. $this->pageoutput[$n] = array();
  6428. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6429. $this->x = $this->lMargin;
  6430. $top_y = $this->y = $this->h - $this->margin_footer;
  6431. // if bottom-margin==0, corrects to avoid division by zero
  6432. if ($this->y == $this->h) { $top_y = $this->y = ($this->h - 0.1); }
  6433. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6434. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6435. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6436. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6437. $this->HTMLheaderPageLinks = array();
  6438. $this->HTMLheaderPageAnnots = array();
  6439. $this->HTMLheaderPageForms = array();
  6440. $this->pageBackgrounds = array();
  6441. $this->writingHTMLfooter = true;
  6442. $this->InFooter = true;
  6443. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6444. $this->writingHTMLfooter = false;
  6445. $this->InFooter = false;
  6446. $this->Reset();
  6447. $this->pageoutput[$n] = array();
  6448. $fheight = $this->y - $top_y;
  6449. $adj = -$fheight;
  6450. $s = $this->PrintPageBackgrounds(-$adj);
  6451. $this->headerbuffer = $s . $this->headerbuffer;
  6452. $os = '';
  6453. $os .= $this->StartTransform(true)."\n";
  6454. if ($rotate) {
  6455. $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK));
  6456. }
  6457. $os .= $this->transformTranslate(0, $adj, true)."\n";
  6458. $os .= $this->headerbuffer ;
  6459. if ($rotate) {
  6460. $os .= ' Q' . "\n";
  6461. }
  6462. $os .= $this->StopTransform(true)."\n";
  6463. // Writes over the page background but behind any other output on page
  6464. $os = preg_replace('/\\\\/','\\\\\\\\',$os);
  6465. $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6466. $lks = $this->HTMLheaderPageLinks;
  6467. foreach($lks AS $lk) {
  6468. $lk[1] -= $adj*_MPDFK;
  6469. if ($rotate) {
  6470. $lw = $lk[2];
  6471. $lh = $lk[3];
  6472. $lk[2] = $lh;
  6473. $lk[3] = $lw; // swap width and height
  6474. $ax = $lk[0]/_MPDFK;
  6475. $ay = $lk[1]/_MPDFK;
  6476. $bx = $ay-($lh/_MPDFK);
  6477. $by = $this->w-$ax;
  6478. $lk[0] = $bx*_MPDFK;
  6479. $lk[1] = ($this->h-$by)*_MPDFK - $lw;
  6480. }
  6481. $this->PageLinks[$n][]=$lk;
  6482. }
  6483. /*-- FORMS --*/
  6484. foreach($this->HTMLheaderPageForms AS $f) {
  6485. $f['y'] += $adj;
  6486. $this->form->forms[$f['n']] = $f;
  6487. }
  6488. /*-- END FORMS --*/
  6489. }
  6490. }
  6491. $this->page=$nb;
  6492. $this->state=1;
  6493. }
  6494. /*-- END HTMLHEADERS-FOOTERS --*/
  6495. function _putpages()
  6496. {
  6497. $nb=$this->page;
  6498. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  6499. if($this->DefOrientation=='P') {
  6500. $defwPt=$this->fwPt;
  6501. $defhPt=$this->fhPt;
  6502. }
  6503. else {
  6504. $defwPt=$this->fhPt;
  6505. $defhPt=$this->fwPt;
  6506. }
  6507. $annotid=(3+2*$nb);
  6508. // Active Forms
  6509. $totaladdnum = 0;
  6510. for($n=1;$n<=$nb;$n++) {
  6511. if (isset($this->PageLinks[$n])) { $totaladdnum += count($this->PageLinks[$n]); }
  6512. /*-- ANNOTATIONS --*/
  6513. if (isset($this->PageAnnots[$n])) {
  6514. foreach ($this->PageAnnots[$n] as $k => $pl) {
  6515. if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $totaladdnum += 2 ; }
  6516. else { $totaladdnum++; }
  6517. }
  6518. }
  6519. /*-- END ANNOTATIONS --*/
  6520. /*-- FORMS --*/
  6521. if ( count($this->form->forms) > 0 ) {
  6522. $this->form->countPageForms($n, $totaladdnum);
  6523. }
  6524. /*-- END FORMS --*/
  6525. }
  6526. /*-- FORMS --*/
  6527. // Make a note in the radio button group of the obj_id it will have
  6528. $ctr = 0;
  6529. if (count($this->form->form_radio_groups)) {
  6530. foreach($this->form->form_radio_groups AS $name=>$frg) {
  6531. $this->form->form_radio_groups[$name]['obj_id'] = $annotid + $totaladdnum + $ctr;
  6532. $ctr++;
  6533. }
  6534. }
  6535. /*-- END FORMS --*/
  6536. // Select unused fonts (usually default font)
  6537. $unused = array();
  6538. foreach($this->fonts as $fk=>$font) {
  6539. if (!$font['used'] && ($font['type']=='TTF')) {
  6540. $unused[] = $fk;
  6541. }
  6542. }
  6543. for($n=1;$n<=$nb;$n++)
  6544. {
  6545. $thispage = $this->pages[$n];
  6546. unset($this->pages[$n]);
  6547. if(isset($this->OrientationChanges[$n])) {
  6548. $hPt=$this->pageDim[$n]['w']*_MPDFK;
  6549. $wPt=$this->pageDim[$n]['h']*_MPDFK;
  6550. $owidthPt_LR = $this->pageDim[$n]['outer_width_TB']*_MPDFK;
  6551. $owidthPt_TB = $this->pageDim[$n]['outer_width_LR']*_MPDFK;
  6552. }
  6553. else {
  6554. $wPt=$this->pageDim[$n]['w']*_MPDFK;
  6555. $hPt=$this->pageDim[$n]['h']*_MPDFK;
  6556. $owidthPt_LR = $this->pageDim[$n]['outer_width_LR']*_MPDFK;
  6557. $owidthPt_TB = $this->pageDim[$n]['outer_width_TB']*_MPDFK;
  6558. }
  6559. // Remove references to unused fonts (usually default font)
  6560. foreach($unused as $fk) {
  6561. if ($this->fonts[$fk]['sip'] || $this->fonts[$fk]['smp']) {
  6562. foreach($this->fonts[$fk]['subsetfontids'] AS $k => $fid) {
  6563. $thispage = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$thispage);
  6564. }
  6565. }
  6566. else {
  6567. $thispage = preg_replace('/\s\/F'.$this->fonts[$fk]['i'].' \d[\d.]* Tf\s/is',' ',$thispage);
  6568. }
  6569. }
  6570. //Replace number of pages
  6571. if(!empty($this->aliasNbPg)) {
  6572. if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPg, false); }
  6573. $s2 = $this->aliasNbPg;
  6574. if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nb, false); }
  6575. $r2 = $nb;
  6576. if (preg_match_all('/{mpdfheadernbpg (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) {
  6577. for($hi=0;$hi<count($m[0]);$hi++) {
  6578. $pos = $m[1][$hi];
  6579. $hff = $m[2][$hi];
  6580. $hfst = $m[3][$hi];
  6581. $hfsz = $m[4][$hi];
  6582. $this->SetFont($hff,$hfst,$hfsz, false);
  6583. $x1 = $this->GetStringWidth($this->aliasNbPg);
  6584. $x2 = $this->GetStringWidth($nb);
  6585. $xadj = $x1 - $x2;
  6586. if ($pos=='C') { $xadj /= 2; }
  6587. $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK);
  6588. $thispage = str_replace($m[0][$hi], $rep, $thispage);
  6589. }
  6590. }
  6591. if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); }
  6592. $thispage=str_replace($s2,$r2,$thispage);
  6593. // And now for any SMP/SIP fonts subset using <HH> format
  6594. $r = '';
  6595. $nstr = "$nb";
  6596. for($i=0;$i<strlen($nstr);$i++) {
  6597. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  6598. }
  6599. $thispage=str_replace($this->aliasNbPgHex,$r,$thispage);
  6600. }
  6601. //Replace number of pages in group
  6602. if(!empty($this->aliasNbPgGp)) {
  6603. if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPgGp, false); }
  6604. $s2 = $this->aliasNbPgGp;
  6605. $nbt = $this->docPageNumTotal($n);
  6606. if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nbt, false); }
  6607. $r2 = $nbt;
  6608. if (preg_match_all('/{mpdfheadernbpggp (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) {
  6609. for($hi=0;$hi<count($m[0]);$hi++) {
  6610. $pos = $m[1][$hi];
  6611. $hff = $m[2][$hi];
  6612. $hfst = $m[3][$hi];
  6613. $hfsz = $m[4][$hi];
  6614. $this->SetFont($hff,$hfst,$hfsz, false);
  6615. $x1 = $this->GetStringWidth($this->aliasNbPgGp);
  6616. $x2 = $this->GetStringWidth($nbt);
  6617. $xadj = $x1 - $x2;
  6618. if ($pos=='C') { $xadj /= 2; }
  6619. $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK);
  6620. $thispage = str_replace($m[0][$hi], $rep, $thispage);
  6621. }
  6622. }
  6623. if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); }
  6624. $thispage=str_replace($s2,$r2,$thispage);
  6625. // And now for any SMP/SIP fonts subset using <HH> format
  6626. $r = '';
  6627. $nstr = "$nbt";
  6628. for($i=0;$i<strlen($nstr);$i++) {
  6629. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48)));
  6630. }
  6631. $thispage=str_replace($this->aliasNbPgGpHex,$r,$thispage);
  6632. }
  6633. $thispage = preg_replace('/(\s*___BACKGROUND___PATTERNS'.date('jY').'\s*)/', " ", $thispage);
  6634. $thispage = preg_replace('/(\s*___HEADER___MARKER'.date('jY').'\s*)/', " ", $thispage);
  6635. $thispage = preg_replace('/(\s*___PAGE___START'.date('jY').'\s*)/', " ", $thispage);
  6636. $thispage = preg_replace('/(\s*___TABLE___BACKGROUNDS'.date('jY').'\s*)/', " ", $thispage);
  6637. //Page
  6638. $this->_newobj();
  6639. $this->_out('<</Type /Page');
  6640. $this->_out('/Parent 1 0 R');
  6641. if(isset($this->OrientationChanges[$n])) {
  6642. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$hPt,$wPt));
  6643. //If BleedBox is defined, it must be larger than the TrimBox, but smaller than the MediaBox
  6644. $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK;
  6645. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  6646. $x0 = $owidthPt_TB-$bleedMargin;
  6647. $y0 = $owidthPt_LR-$bleedMargin;
  6648. $x1 = $hPt-$owidthPt_TB+$bleedMargin;
  6649. $y1 = $wPt-$owidthPt_LR+$bleedMargin;
  6650. $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1));
  6651. }
  6652. $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_TB, $owidthPt_LR, ($hPt-$owidthPt_TB), ($wPt-$owidthPt_LR)));
  6653. if (isset($this->OrientationChanges[$n]) && $this->displayDefaultOrientation) {
  6654. if ($this->DefOrientation=='P') { $this->_out('/Rotate 270'); }
  6655. else { $this->_out('/Rotate 90'); }
  6656. }
  6657. }
  6658. //else if($wPt != $defwPt || $hPt != $defhPt) {
  6659. else {
  6660. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$wPt,$hPt));
  6661. $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK;
  6662. if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
  6663. $x0 = $owidthPt_LR-$bleedMargin;
  6664. $y0 = $owidthPt_TB-$bleedMargin;
  6665. $x1 = $wPt-$owidthPt_LR+$bleedMargin;
  6666. $y1 = $hPt-$owidthPt_TB+$bleedMargin;
  6667. $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1));
  6668. }
  6669. $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_LR, $owidthPt_TB, ($wPt-$owidthPt_LR), ($hPt-$owidthPt_TB)));
  6670. }
  6671. $this->_out('/Resources 2 0 R');
  6672. // Important to keep in RGB colorSpace when using transparency
  6673. if (!$this->PDFA && !$this->PDFX) {
  6674. if ($this->restrictColorSpace == 3)
  6675. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceCMYK >> ');
  6676. else if ($this->restrictColorSpace == 1)
  6677. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >> ');
  6678. else
  6679. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceRGB >> ');
  6680. }
  6681. $annotsnum = 0;
  6682. if (isset($this->PageLinks[$n])) { $annotsnum += count($this->PageLinks[$n]); }
  6683. /*-- ANNOTATIONS --*/
  6684. if (isset($this->PageAnnots[$n])) {
  6685. foreach ($this->PageAnnots[$n] as $k => $pl) {
  6686. if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $annotsnum += 2 ; }
  6687. else { $annotsnum++; }
  6688. $this->PageAnnots[$n][$k]['pageobj'] = $this->n;
  6689. }
  6690. }
  6691. /*-- END ANNOTATIONS --*/
  6692. /*-- FORMS --*/
  6693. // Active Forms
  6694. $formsnum = 0;
  6695. if ( count($this->form->forms) > 0 ) {
  6696. foreach( $this->form->forms as $val ) {
  6697. if ( $val['page'] == $n )
  6698. $formsnum++;
  6699. }
  6700. }
  6701. /*-- END FORMS --*/
  6702. if ($annotsnum || $formsnum) {
  6703. $s = '/Annots [ ';
  6704. for($i=0;$i<$annotsnum;$i++) {
  6705. $s .= ($annotid + $i) . ' 0 R ';
  6706. }
  6707. $annotid += $annotsnum;
  6708. /*-- FORMS --*/
  6709. if ( count($this->form->forms) > 0 ) {
  6710. $this->form->addFormIds($n, $s, $annotid);
  6711. }
  6712. /*-- END FORMS --*/
  6713. $s .= '] ';
  6714. $this->_out($s);
  6715. }
  6716. $this->_out('/Contents '.($this->n+1).' 0 R>>');
  6717. $this->_out('endobj');
  6718. //Page content
  6719. $this->_newobj();
  6720. $p=($this->compress) ? gzcompress($thispage) : $thispage;
  6721. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  6722. $this->_putstream($p);
  6723. $this->_out('endobj');
  6724. }
  6725. $this->_putannots($n);
  6726. //Pages root
  6727. $this->offsets[1]=strlen($this->buffer);
  6728. $this->_out('1 0 obj');
  6729. $this->_out('<</Type /Pages');
  6730. $kids='/Kids [';
  6731. for($i=0;$i<$nb;$i++)
  6732. $kids.=(3+2*$i).' 0 R ';
  6733. $this->_out($kids.']');
  6734. $this->_out('/Count '.$nb);
  6735. $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$defwPt,$defhPt));
  6736. $this->_out('>>');
  6737. $this->_out('endobj');
  6738. }
  6739. function _putannots($n) {
  6740. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  6741. $nb=$this->page;
  6742. for($n=1;$n<=$nb;$n++)
  6743. {
  6744. $annotobjs = array();
  6745. if(isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n]) || count($this->form->forms) > 0 ) {
  6746. $wPt=$this->pageDim[$n]['w']*_MPDFK;
  6747. $hPt=$this->pageDim[$n]['h']*_MPDFK;
  6748. //Links
  6749. if(isset($this->PageLinks[$n])) {
  6750. foreach($this->PageLinks[$n] as $key => $pl) {
  6751. $this->_newobj();
  6752. $annot='';
  6753. $rect=sprintf('%.3F %.3F %.3F %.3F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  6754. $annot .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.']';
  6755. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl[4]);
  6756. $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, $key));
  6757. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6758. $annot .= ' /Border [0 0 0]';
  6759. // Use this (instead of /Border) to specify border around link
  6760. // $annot .= ' /BS <</W 1'; // Width on points; 0 = no line
  6761. // $annot .= ' /S /D'; // style - [S]olid, [D]ashed, [B]eveled, [I]nset, [U]nderline
  6762. // $annot .= ' /D [3 2]'; // Dash array - if dashed
  6763. // $annot .= ' >>';
  6764. // $annot .= ' /C [1 0 0]'; // Color RGB
  6765. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  6766. if (strpos($pl[4],'@')===0) {
  6767. $p=substr($pl[4],1);
  6768. // $h=isset($this->OrientationChanges[$p]) ? $wPt : $hPt;
  6769. $htarg=$this->pageDim[$p]['h']*_MPDFK;
  6770. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$p,$htarg);
  6771. }
  6772. else if(is_string($pl[4])) {
  6773. $annot .= ' /A <</S /URI /URI '.$this->_textstring($pl[4]).'>> >>';
  6774. }
  6775. else {
  6776. $l=$this->links[$pl[4]];
  6777. // may not be set if #link points to non-existent target
  6778. if (isset($this->pageDim[$l[0]]['h'])) { $htarg=$this->pageDim[$l[0]]['h']*_MPDFK; }
  6779. else { $htarg=$this->h*_MPDFK; } // doesn't really matter
  6780. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$l[0],$htarg-$l[1]*_MPDFK);
  6781. }
  6782. $this->_out($annot);
  6783. $this->_out('endobj');
  6784. }
  6785. }
  6786. /*-- ANNOTATIONS --*/
  6787. if(isset($this->PageAnnots[$n])) {
  6788. foreach ($this->PageAnnots[$n] as $key => $pl) {
  6789. if ($pl['opt']['file']) { $FileAttachment=true; }
  6790. else { $FileAttachment=false; }
  6791. $this->_newobj();
  6792. $annot='';
  6793. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  6794. $x = $pl['x'];
  6795. if ($this->annotMargin <> 0 || $x==0 || $x<0) { // Odd page
  6796. $x = ($wPt/_MPDFK) - $this->annotMargin;
  6797. }
  6798. $w = $h = 0;
  6799. $a = $x * _MPDFK;
  6800. $b = $hPt - ($pl['y'] * _MPDFK);
  6801. $annot .= '<</Type /Annot ';
  6802. if ($FileAttachment) {
  6803. $annot .= '/Subtype /FileAttachment';
  6804. // Need to set a size for FileAttachment icons
  6805. if ($pl['opt']['icon']=='Paperclip') { $w=8.235; $h=20; } // 7,17
  6806. else if ($pl['opt']['icon']=='Tag') { $w=20; $h=16; }
  6807. else if ($pl['opt']['icon']=='Graph') { $w=20; $h=20; }
  6808. else { $w=14; $h=20; } // PushPin
  6809. $f = $pl['opt']['file'];
  6810. $f = preg_replace('/^.*\//', '', $f);
  6811. $f = preg_replace('/[^a-zA-Z0-9._]/', '', $f);
  6812. $annot .= '/FS <</Type /Filespec /F ('.$f.')';
  6813. $annot .= '/EF <</F '.($this->n+1).' 0 R>>';
  6814. $annot .= '>>';
  6815. }
  6816. else {
  6817. $annot .= '/Subtype /Text';
  6818. }
  6819. $rect = sprintf('%.3F %.3F %.3F %.3F', $a, $b-$h, $a+$w, $b);
  6820. $annot .= '/Rect ['.$rect.']';
  6821. // contents = description of file in free text
  6822. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl['txt']);
  6823. $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, (2000 + $key)));
  6824. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6825. $annot .= ' /CreationDate '.$this->_textstring('D:'.date('YmdHis'));
  6826. $annot .= ' /Border [0 0 0]';
  6827. if ($this->PDFA || $this->PDFX) {
  6828. $annot .= ' /F 28';
  6829. $annot .= ' /CA 1';
  6830. }
  6831. else if ($pl['opt']['ca']>0) { $annot .= ' /CA '.$pl['opt']['ca']; }
  6832. $annotcolor = ' /C [';
  6833. if (isset($pl['opt']['c']) AND $pl['opt']['c']) {
  6834. $col = $pl['opt']['c'];
  6835. if ($col{0}==3 || $col{0}==5) { $annotcolor .= sprintf("%.3F %.3F %.3F", ord($col{1})/255,ord($col{2})/255,ord($col{3})/255); }
  6836. else if ($col{0}==1) { $annotcolor .= sprintf("%.3F", ord($col{1})/255); }
  6837. 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); }
  6838. else { $annotcolor .= '1 1 0'; }
  6839. }
  6840. else { $annotcolor .= '1 1 0'; }
  6841. $annotcolor .= ']';
  6842. $annot .= $annotcolor;
  6843. // Usually Author
  6844. // Use as Title for fileattachment
  6845. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  6846. $annot .= ' /T '.$this->_UTF16BEtextstring($pl['opt']['t']);
  6847. }
  6848. if ($FileAttachment) {
  6849. $iconsapp = array('Paperclip', 'Graph', 'PushPin', 'Tag');
  6850. }
  6851. else { $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); }
  6852. if (isset($pl['opt']['icon']) AND in_array($pl['opt']['icon'], $iconsapp)) {
  6853. $annot .= ' /Name /'.$pl['opt']['icon'];
  6854. }
  6855. else if ($FileAttachment) { $annot .= ' /Name /PushPin'; }
  6856. else { $annot .= ' /Name /Note'; }
  6857. if (!$FileAttachment) {
  6858. // /Subj is PDF 1.5 spec.
  6859. if (isset($pl['opt']['subj']) && !$this->PDFA && !$this->PDFX) {
  6860. $annot .= ' /Subj '.$this->_UTF16BEtextstring($pl['opt']['subj']);
  6861. }
  6862. if (!empty($pl['opt']['popup'])) {
  6863. $annot .= ' /Open true';
  6864. $annot .= ' /Popup '.($this->n+1).' 0 R';
  6865. }
  6866. else { $annot .= ' /Open false'; }
  6867. }
  6868. $annot .= ' /P '.$pl['pageobj'].' 0 R';
  6869. $annot .= '>>';
  6870. $this->_out($annot);
  6871. $this->_out('endobj');
  6872. if ($FileAttachment) {
  6873. $file = @file_get_contents($pl['opt']['file']) or die('mPDF Error: Cannot access file attachment - '.$pl['opt']['file']);
  6874. $filestream = gzcompress($file);
  6875. $this->_newobj();
  6876. $this->_out('<</Type /EmbeddedFile');
  6877. $this->_out('/Length '.strlen($filestream));
  6878. $this->_out('/Filter /FlateDecode');
  6879. $this->_out('>>');
  6880. $this->_putstream($filestream);
  6881. $this->_out('endobj');
  6882. }
  6883. else if (!empty($pl['opt']['popup'])) {
  6884. $this->_newobj();
  6885. $annot='';
  6886. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][0])) { $x = $pl['opt']['popup'][0] * _MPDFK; }
  6887. else { $x = $pl['x'] * _MPDFK; }
  6888. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][1])) { $y = $hPt - ($pl['opt']['popup'][1] * _MPDFK); }
  6889. else { $y = $hPt - ($pl['y'] * _MPDFK); }
  6890. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][2])) { $w = $pl['opt']['popup'][2] * _MPDFK; }
  6891. else { $w = 180; }
  6892. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][3])) { $h = $pl['opt']['popup'][3] * _MPDFK; }
  6893. else { $h = 120; }
  6894. $rect = sprintf('%.3F %.3F %.3F %.3F', $x, $y-$h, $x+$w, $y);
  6895. $annot .= '<</Type /Annot /Subtype /Popup /Rect ['.$rect.']';
  6896. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6897. if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; }
  6898. $annot .= ' /Parent '.($this->n-1).' 0 R';
  6899. $annot .= '>>';
  6900. $this->_out($annot);
  6901. $this->_out('endobj');
  6902. }
  6903. }
  6904. }
  6905. /*-- END ANNOTATIONS --*/
  6906. /*-- FORMS --*/
  6907. // Active Forms
  6908. if ( count($this->form->forms) > 0 ) {
  6909. $this->form->_putFormItems($n, $hPt);
  6910. }
  6911. /*-- END FORMS --*/
  6912. }
  6913. }
  6914. /*-- FORMS --*/
  6915. // Active Forms - Radio Button Group entries
  6916. // Output Radio Button Group form entries (radio_on_obj_id already determined)
  6917. if (count($this->form->form_radio_groups)) {
  6918. $this->form->_putRadioItems($n);
  6919. }
  6920. /*-- END FORMS --*/
  6921. }
  6922. /*-- ANNOTATIONS --*/
  6923. function Annotation($text, $x=0, $y=0, $icon='Note', $author='', $subject='', $opacity=0, $colarray=false, $popup='', $file='') {
  6924. if (is_array($colarray) && count($colarray)==3) { $colarray = $this->ConvertColor('rgb('.$colarray[0].','.$colarray[1].','.$colarray[2].')'); }
  6925. if ($colarray === false) { $colarray = $this->ConvertColor('yellow'); }
  6926. if ($x==0) { $x = $this->x; }
  6927. if ($y==0) { $y = $this->y; }
  6928. $page = $this->page;
  6929. if ($page < 1) { // Document has not been started - assume it's for first page
  6930. $page = 1;
  6931. if ($x==0) { $x = $this->lMargin; }
  6932. if ($y==0) { $y = $this->tMargin; }
  6933. }
  6934. if ($this->PDFA || $this->PDFX) {
  6935. 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)"; }
  6936. $x = ($this->w) - $this->rMargin*0.66;
  6937. }
  6938. if (!$this->annotMargin) { $y -= $this->FontSize / 2; }
  6939. if (!$opacity && $this->annotMargin) { $opacity = 1; }
  6940. else if (!$opacity) { $opacity = $this->annotOpacity; }
  6941. $an = array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file));
  6942. if ($this->keep_block_together) { // Save to array - don't write yet
  6943. $this->ktAnnots[$this->page][]= $an;
  6944. return;
  6945. }
  6946. else if ($this->table_rotate) {
  6947. $this->tbrot_Annots[$this->page][]= $an;
  6948. return;
  6949. }
  6950. else if ($this->kwt) {
  6951. $this->kwt_Annots[$this->page][]= $an;
  6952. return;
  6953. }
  6954. // mPDF 5.0
  6955. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  6956. $this->HTMLheaderPageAnnots[]= $an;
  6957. return;
  6958. }
  6959. //Put an Annotation on the page
  6960. $this->PageAnnots[$page][] = $an;
  6961. /*-- COLUMNS --*/
  6962. // Save cross-reference to Column buffer
  6963. $ref = count($this->PageAnnots[$this->page])-1;
  6964. $this->columnAnnots[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref;
  6965. /*-- END COLUMNS --*/
  6966. }
  6967. /*-- END ANNOTATIONS --*/
  6968. function _putfonts() {
  6969. $nf=$this->n;
  6970. foreach($this->FontFiles as $fontkey=>$info) {
  6971. // TrueType embedded
  6972. if (isset($info['type']) && $info['type']=='TTF' && !$info['sip'] && !$info['smp']) {
  6973. $used = true;
  6974. $asSubset = false;
  6975. foreach($this->fonts AS $k=>$f) {
  6976. if ($f['fontkey'] == $fontkey && $f['type']=='TTF') {
  6977. $used = $f['used'];
  6978. if ($used) {
  6979. $nChars = (ord($f['cw'][0]) << 8) + ord($f['cw'][1]);
  6980. $usage = intval(count($f['subset'])*100 / $nChars);
  6981. $fsize = $info['length1'];
  6982. // Always subset the very large TTF files
  6983. if ($fsize > ($this->maxTTFFilesize *1024)) { $asSubset = true; }
  6984. else if ($usage < $this->percentSubset) { $asSubset = true; }
  6985. }
  6986. if ($f['unAGlyphs']) $aaSubset = true; // mPDF 5.4.05
  6987. if ($this->PDFA || $this->PDFX) $asSubset = false;
  6988. $this->fonts[$k]['asSubset'] = $asSubset;
  6989. break;
  6990. }
  6991. }
  6992. if ($used && !$asSubset) {
  6993. //Font file embedding
  6994. $this->_newobj();
  6995. $this->FontFiles[$fontkey]['n']=$this->n;
  6996. $font='';
  6997. $originalsize = $info['length1'];
  6998. if ($this->repackageTTF || $this->fonts[$fontkey]['TTCfontID']>0) {
  6999. // First see if there is a cached compressed file
  7000. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z')) {
  7001. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z','rb');
  7002. if(!$f) { $this->Error('Font file .ps.z not found'); }
  7003. while(!feof($f)) { $font .= fread($f, 2048); }
  7004. fclose($f);
  7005. include(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php'); // sets $originalsize (of repackaged font)
  7006. }
  7007. else {
  7008. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7009. $ttf = new TTFontFile();
  7010. $font = $ttf->repackageTTF($this->FontFiles[$fontkey]['ttffile'], $this->fonts[$fontkey]['TTCfontID'], $this->debugfonts, $this->fonts[$fontkey]['unAGlyphs']); // mPDF 5.4.05
  7011. $originalsize = strlen($font);
  7012. $font = gzcompress($font);
  7013. unset($ttf);
  7014. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7015. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z',"wb");
  7016. fwrite($fh,$font,strlen($font));
  7017. fclose($fh);
  7018. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php',"wb");
  7019. $len = "<?php \n";
  7020. $len.='$originalsize='.$originalsize.";\n";
  7021. $len.="?>";
  7022. fwrite($fh,$len,strlen($len));
  7023. fclose($fh);
  7024. }
  7025. }
  7026. }
  7027. else {
  7028. // First see if there is a cached compressed file
  7029. if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.z')) {
  7030. $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z','rb');
  7031. if(!$f) { $this->Error('Font file not found'); }
  7032. while(!feof($f)) { $font .= fread($f, 2048); }
  7033. fclose($f);
  7034. }
  7035. else {
  7036. $f=fopen($this->FontFiles[$fontkey]['ttffile'],'rb');
  7037. if(!$f) { $this->Error('Font file not found'); }
  7038. while(!feof($f)) { $font .= fread($f, 2048); }
  7039. fclose($f);
  7040. $font = gzcompress($font);
  7041. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7042. $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z',"wb");
  7043. fwrite($fh,$font,strlen($font));
  7044. fclose($fh);
  7045. }
  7046. }
  7047. }
  7048. $this->_out('<</Length '.strlen($font));
  7049. $this->_out('/Filter /FlateDecode');
  7050. $this->_out('/Length1 '.$originalsize);
  7051. $this->_out('>>');
  7052. $this->_putstream($font);
  7053. $this->_out('endobj');
  7054. }
  7055. }
  7056. }
  7057. $nfonts = count($this->fonts);
  7058. $fctr = 1;
  7059. foreach($this->fonts as $k=>$font) {
  7060. //Font objects
  7061. $type=$font['type'];
  7062. $name=$font['name'];
  7063. if ((!isset($font['used']) || !$font['used']) && $type=='TTF') { continue; }
  7064. if ($this->progressBar) { $this->UpdateProgressBar(2,intval($fctr*100/$nfonts),'Writing Fonts'); $fctr++; } // *PROGRESS-BAR*
  7065. if (isset($font['asSubset'])) { $asSubset = $font['asSubset']; }
  7066. else { $asSubset = ''; }
  7067. /*-- CJK-FONTS --*/
  7068. if($type=='Type0') { // = Adobe CJK Fonts
  7069. $this->fonts[$k]['n']=$this->n+1;
  7070. $this->_newobj();
  7071. $this->_out('<</Type /Font');
  7072. $this->_putType0($font);
  7073. }
  7074. else
  7075. /*-- END CJK-FONTS --*/
  7076. if($type=='core') {
  7077. //Standard font
  7078. $this->fonts[$k]['n']=$this->n+1;
  7079. 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.)'); }
  7080. $this->_newobj();
  7081. $this->_out('<</Type /Font');
  7082. $this->_out('/BaseFont /'.$name);
  7083. $this->_out('/Subtype /Type1');
  7084. if($name!='Symbol' && $name!='ZapfDingbats') {
  7085. $this->_out('/Encoding /WinAnsiEncoding');
  7086. }
  7087. $this->_out('>>');
  7088. $this->_out('endobj');
  7089. }
  7090. // TrueType embedded SUBSETS for SIP (CJK extB containing Supplementary Ideographic Plane 2)
  7091. // Or Unicode Plane 1 - Supplementary Multilingual Plane
  7092. else if ($type=='TTF' && ($font['sip'] || $font['smp'])) {
  7093. if (!$font['used']) { continue; }
  7094. $ssfaid="AA";
  7095. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7096. $ttf = new TTFontFile();
  7097. for($sfid=0;$sfid<count($font['subsetfontids']);$sfid++) {
  7098. $this->fonts[$k]['n'][$sfid]=$this->n+1; // NB an array for subset
  7099. $subsetname = 'MPDF'.$ssfaid.'+'.$font['name'];
  7100. $ssfaid++;
  7101. $subset = $font['subsets'][$sfid];
  7102. unset($subset[0]);
  7103. $ttfontstream = $ttf->makeSubsetSIP($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts);
  7104. $ttfontsize = strlen($ttfontstream);
  7105. $fontstream = gzcompress($ttfontstream);
  7106. $widthstring = '';
  7107. $toUnistring = '';
  7108. foreach($font['subsets'][$sfid] AS $cp=>$u) {
  7109. $w = $this->_getCharWidth($font['cw'], $u);
  7110. if ($w !== false) {
  7111. $widthstring .= $w.' ';
  7112. }
  7113. else {
  7114. $widthstring .= round($ttf->defaultWidth).' ';
  7115. }
  7116. if ($u > 65535) {
  7117. $utf8 = chr(($u>>18)+240).chr((($u>>12)&63)+128).chr((($u>>6)&63)+128) .chr(($u&63)+128);
  7118. $utf16 = mb_convert_encoding($utf8, 'UTF-16BE', 'UTF-8');
  7119. $l1 = ord($utf16[0]);
  7120. $h1 = ord($utf16[1]);
  7121. $l2 = ord($utf16[2]);
  7122. $h2 = ord($utf16[3]);
  7123. $toUnistring .= sprintf("<%02s> <%02s%02s%02s%02s>\n", strtoupper(dechex($cp)), strtoupper(dechex($l1)), strtoupper(dechex($h1)), strtoupper(dechex($l2)), strtoupper(dechex($h2)));
  7124. }
  7125. else {
  7126. $toUnistring .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), strtoupper(dechex($u)));
  7127. }
  7128. }
  7129. //Additional Type1 or TrueType font
  7130. $this->_newobj();
  7131. $this->_out('<</Type /Font');
  7132. $this->_out('/BaseFont /'.$subsetname);
  7133. $this->_out('/Subtype /TrueType');
  7134. $this->_out('/FirstChar 0 /LastChar '.(count($font['subsets'][$sfid])-1));
  7135. $this->_out('/Widths '.($this->n+1).' 0 R');
  7136. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  7137. $this->_out('/ToUnicode '.($this->n + 3).' 0 R');
  7138. $this->_out('>>');
  7139. $this->_out('endobj');
  7140. //Widths
  7141. $this->_newobj();
  7142. $this->_out('['.$widthstring.']');
  7143. $this->_out('endobj');
  7144. //Descriptor
  7145. $this->_newobj();
  7146. $s='<</Type /FontDescriptor /FontName /'.$subsetname."\n";
  7147. foreach($font['desc'] as $kd=>$v) {
  7148. if ($kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7149. $s.=' /'.$kd.' '.$v."\n";
  7150. }
  7151. $s.='/FontFile2 '.($this->n + 2).' 0 R';
  7152. $this->_out($s.'>>');
  7153. $this->_out('endobj');
  7154. // ToUnicode
  7155. $this->_newobj();
  7156. $toUni = "/CIDInit /ProcSet findresource begin\n";
  7157. $toUni .= "12 dict begin\n";
  7158. $toUni .= "begincmap\n";
  7159. $toUni .= "/CIDSystemInfo\n";
  7160. $toUni .= "<</Registry (Adobe)\n";
  7161. $toUni .= "/Ordering (UCS)\n";
  7162. $toUni .= "/Supplement 0\n";
  7163. $toUni .= ">> def\n";
  7164. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  7165. $toUni .= "/CMapType 2 def\n";
  7166. $toUni .= "1 begincodespacerange\n";
  7167. $toUni .= "<00> <FF>\n";
  7168. $toUni .= "endcodespacerange\n";
  7169. $toUni .= count($font['subsets'][$sfid])." beginbfchar\n";
  7170. $toUni .= $toUnistring;
  7171. $toUni .= "endbfchar\n";
  7172. $toUni .= "endcmap\n";
  7173. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  7174. $toUni .= "end\n";
  7175. $toUni .= "end\n";
  7176. $this->_out('<</Length '.(strlen($toUni)).'>>');
  7177. $this->_putstream($toUni);
  7178. $this->_out('endobj');
  7179. //Font file
  7180. $this->_newobj();
  7181. $this->_out('<</Length '.strlen($fontstream));
  7182. $this->_out('/Filter /FlateDecode');
  7183. $this->_out('/Length1 '.$ttfontsize);
  7184. $this->_out('>>');
  7185. $this->_putstream($fontstream);
  7186. $this->_out('endobj');
  7187. } // foreach subset
  7188. unset($ttf);
  7189. }
  7190. // TrueType embedded SUBSETS or FULL
  7191. else if ($type=='TTF') {
  7192. $this->fonts[$k]['n']=$this->n+1;
  7193. if ($asSubset ) {
  7194. $ssfaid="A";
  7195. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7196. $ttf = new TTFontFile();
  7197. $fontname = 'MPDFA'.$ssfaid.'+'.$font['name'];
  7198. $subset = $font['subset'];
  7199. unset($subset[0]);
  7200. $ttfontstream = $ttf->makeSubset($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts, $font['unAGlyphs']); // mPDF 5.4.05
  7201. $ttfontsize = strlen($ttfontstream);
  7202. $fontstream = gzcompress($ttfontstream);
  7203. $codeToGlyph = $ttf->codeToGlyph;
  7204. unset($codeToGlyph[0]);
  7205. }
  7206. else { $fontname = $font['name']; }
  7207. // Type0 Font
  7208. // A composite font - a font composed of other fonts, organized hierarchically
  7209. $this->_newobj();
  7210. $this->_out('<</Type /Font');
  7211. $this->_out('/Subtype /Type0');
  7212. $this->_out('/BaseFont /'.$fontname.'');
  7213. $this->_out('/Encoding /Identity-H');
  7214. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  7215. $this->_out('/ToUnicode '.($this->n + 2).' 0 R');
  7216. $this->_out('>>');
  7217. $this->_out('endobj');
  7218. // CIDFontType2
  7219. // A CIDFont whose glyph descriptions are based on TrueType font technology
  7220. $this->_newobj();
  7221. $this->_out('<</Type /Font');
  7222. $this->_out('/Subtype /CIDFontType2');
  7223. $this->_out('/BaseFont /'.$fontname.'');
  7224. $this->_out('/CIDSystemInfo '.($this->n + 2).' 0 R');
  7225. $this->_out('/FontDescriptor '.($this->n + 3).' 0 R');
  7226. if (isset($font['desc']['MissingWidth'])){
  7227. $this->_out('/DW '.$font['desc']['MissingWidth'].'');
  7228. }
  7229. if (!$asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw')) {
  7230. $w = '';
  7231. $w=file_get_contents(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw');
  7232. $this->_out($w);
  7233. }
  7234. else {
  7235. $this->_putTTfontwidths($font, $asSubset, $ttf->maxUni);
  7236. }
  7237. $this->_out('/CIDToGIDMap '.($this->n + 4).' 0 R');
  7238. $this->_out('>>');
  7239. $this->_out('endobj');
  7240. // ToUnicode
  7241. $this->_newobj();
  7242. $toUni = "/CIDInit /ProcSet findresource begin\n";
  7243. $toUni .= "12 dict begin\n";
  7244. $toUni .= "begincmap\n";
  7245. $toUni .= "/CIDSystemInfo\n";
  7246. $toUni .= "<</Registry (Adobe)\n";
  7247. $toUni .= "/Ordering (UCS)\n";
  7248. $toUni .= "/Supplement 0\n";
  7249. $toUni .= ">> def\n";
  7250. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  7251. $toUni .= "/CMapType 2 def\n";
  7252. $toUni .= "1 begincodespacerange\n";
  7253. $toUni .= "<0000> <FFFF>\n";
  7254. $toUni .= "endcodespacerange\n";
  7255. $toUni .= "1 beginbfrange\n";
  7256. $toUni .= "<0000> <FFFF> <0000>\n";
  7257. $toUni .= "endbfrange\n";
  7258. $toUni .= "endcmap\n";
  7259. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  7260. $toUni .= "end\n";
  7261. $toUni .= "end\n";
  7262. $this->_out('<</Length '.(strlen($toUni)).'>>');
  7263. $this->_putstream($toUni);
  7264. $this->_out('endobj');
  7265. // CIDSystemInfo dictionary
  7266. $this->_newobj();
  7267. $this->_out('<</Registry (Adobe)');
  7268. $this->_out('/Ordering (UCS)');
  7269. $this->_out('/Supplement 0');
  7270. $this->_out('>>');
  7271. $this->_out('endobj');
  7272. // Font descriptor
  7273. $this->_newobj();
  7274. $this->_out('<</Type /FontDescriptor');
  7275. $this->_out('/FontName /'.$fontname);
  7276. foreach($font['desc'] as $kd=>$v) {
  7277. if ($asSubset && $kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag
  7278. $this->_out(' /'.$kd.' '.$v);
  7279. }
  7280. if ($font['panose']) {
  7281. $this->_out(' /Style << /Panose <'.$font['panose'].'> >>');
  7282. }
  7283. if ($asSubset ) {
  7284. $this->_out('/FontFile2 '.($this->n + 2).' 0 R');
  7285. }
  7286. else if ($font['fontkey']) {
  7287. // obj ID of a stream containing a TrueType font program
  7288. $this->_out('/FontFile2 '.$this->FontFiles[$font['fontkey']]['n'].' 0 R');
  7289. }
  7290. $this->_out('>>');
  7291. $this->_out('endobj');
  7292. // Embed CIDToGIDMap
  7293. // A specification of the mapping from CIDs to glyph indices
  7294. if ($asSubset ) {
  7295. $cidtogidmap = '';
  7296. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7297. foreach($codeToGlyph as $cc=>$glyph) {
  7298. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7299. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7300. }
  7301. $cidtogidmap = gzcompress($cidtogidmap);
  7302. }
  7303. else {
  7304. // First see if there is a cached CIDToGIDMapfile
  7305. $cidtogidmap = '';
  7306. if (file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm')) {
  7307. $f=fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm','rb');
  7308. while(!feof($f)) { $cidtogidmap .= fread($f, 2048); }
  7309. fclose($f);
  7310. }
  7311. else {
  7312. if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
  7313. $ttf = new TTFontFile();
  7314. $charToGlyph = $ttf->getCTG($font['ttffile'], $font['TTCfontID'], $this->debugfonts, $font['unAGlyphs']); // mPDF 5.4.05
  7315. $cidtogidmap = str_pad('', 256*256*2, "\x00");
  7316. foreach($charToGlyph as $cc=>$glyph) {
  7317. $cidtogidmap[$cc*2] = chr($glyph >> 8);
  7318. $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
  7319. }
  7320. unset($ttf);
  7321. $cidtogidmap = gzcompress($cidtogidmap);
  7322. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7323. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm',"wb");
  7324. fwrite($fh,$cidtogidmap,strlen($cidtogidmap));
  7325. fclose($fh);
  7326. }
  7327. }
  7328. }
  7329. $this->_newobj();
  7330. $this->_out('<</Length '.strlen($cidtogidmap).'');
  7331. $this->_out('/Filter /FlateDecode');
  7332. $this->_out('>>');
  7333. $this->_putstream($cidtogidmap);
  7334. $this->_out('endobj');
  7335. //Font file
  7336. if ($asSubset ) {
  7337. $this->_newobj();
  7338. $this->_out('<</Length '.strlen($fontstream));
  7339. $this->_out('/Filter /FlateDecode');
  7340. $this->_out('/Length1 '.$ttfontsize);
  7341. $this->_out('>>');
  7342. $this->_putstream($fontstream);
  7343. $this->_out('endobj');
  7344. unset($ttf);
  7345. }
  7346. }
  7347. else { $this->Error('Unsupported font type: '.$type.' ('.$name.')'); }
  7348. }
  7349. }
  7350. function _putTTfontwidths(&$font, $asSubset, $maxUni) {
  7351. if ($asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php')) {
  7352. include(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php') ;
  7353. $startcid = 128;
  7354. }
  7355. else {
  7356. $rangeid = 0;
  7357. $range = array();
  7358. $prevcid = -2;
  7359. $prevwidth = -1;
  7360. $interval = false;
  7361. $startcid = 1;
  7362. }
  7363. if ($asSubset) { $cwlen = $maxUni + 1; }
  7364. else { $cwlen = (strlen($font['cw'])/2); }
  7365. // for each character
  7366. for ($cid=$startcid; $cid<$cwlen; $cid++) {
  7367. if ($cid==128 && $asSubset && (!file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php'))) {
  7368. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7369. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php',"wb");
  7370. $cw127='<?php'."\n";
  7371. $cw127.='$rangeid='.$rangeid.";\n";
  7372. $cw127.='$prevcid='.$prevcid.";\n";
  7373. $cw127.='$prevwidth='.$prevwidth.";\n";
  7374. if ($interval) { $cw127.='$interval=true'.";\n"; }
  7375. else { $cw127.='$interval=false'.";\n"; }
  7376. $cw127.='$range='.var_export($range,true).";\n";
  7377. $cw127.="?>";
  7378. fwrite($fh,$cw127,strlen($cw127));
  7379. fclose($fh);
  7380. }
  7381. }
  7382. if ($font['cw'][$cid*2] == "\00" && $font['cw'][$cid*2+1] == "\00") { continue; }
  7383. $width = (ord($font['cw'][$cid*2]) << 8) + ord($font['cw'][$cid*2+1]);
  7384. if ($width == 65535) { $width = 0; }
  7385. if ($asSubset && $cid > 255 && (!isset($font['subset'][$cid]) || !$font['subset'][$cid])) {
  7386. continue;
  7387. }
  7388. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7389. if ($cid == ($prevcid + 1)) {
  7390. // consecutive CID
  7391. if ($width == $prevwidth) {
  7392. if ($width == $range[$rangeid][0]) {
  7393. $range[$rangeid][] = $width;
  7394. } else {
  7395. array_pop($range[$rangeid]);
  7396. // new range
  7397. $rangeid = $prevcid;
  7398. $range[$rangeid] = array();
  7399. $range[$rangeid][] = $prevwidth;
  7400. $range[$rangeid][] = $width;
  7401. }
  7402. $interval = true;
  7403. $range[$rangeid]['interval'] = true;
  7404. } else {
  7405. if ($interval) {
  7406. // new range
  7407. $rangeid = $cid;
  7408. $range[$rangeid] = array();
  7409. $range[$rangeid][] = $width;
  7410. } else {
  7411. $range[$rangeid][] = $width;
  7412. }
  7413. $interval = false;
  7414. }
  7415. } else {
  7416. // new range
  7417. $rangeid = $cid;
  7418. $range[$rangeid] = array();
  7419. $range[$rangeid][] = $width;
  7420. $interval = false;
  7421. }
  7422. $prevcid = $cid;
  7423. $prevwidth = $width;
  7424. }
  7425. }
  7426. $w = $this->_putfontranges($range);
  7427. $this->_out($w);
  7428. if (!$asSubset) {
  7429. if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
  7430. $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw',"wb");
  7431. fwrite($fh,$w,strlen($w));
  7432. fclose($fh);
  7433. }
  7434. }
  7435. }
  7436. function _putfontranges(&$range) {
  7437. // optimize ranges
  7438. $prevk = -1;
  7439. $nextk = -1;
  7440. $prevint = false;
  7441. foreach ($range as $k => $ws) {
  7442. $cws = count($ws);
  7443. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  7444. if (isset($range[$k]['interval'])) {
  7445. unset($range[$k]['interval']);
  7446. }
  7447. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  7448. unset($range[$k]);
  7449. } else {
  7450. $prevk = $k;
  7451. }
  7452. $nextk = $k + $cws;
  7453. if (isset($ws['interval'])) {
  7454. if ($cws > 3) {
  7455. $prevint = true;
  7456. } else {
  7457. $prevint = false;
  7458. }
  7459. unset($range[$k]['interval']);
  7460. --$nextk;
  7461. } else {
  7462. $prevint = false;
  7463. }
  7464. }
  7465. // output data
  7466. $w = '';
  7467. foreach ($range as $k => $ws) {
  7468. if (count(array_count_values($ws)) == 1) {
  7469. // interval mode is more compact
  7470. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  7471. } else {
  7472. // range mode
  7473. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]' . "\n";
  7474. }
  7475. }
  7476. return '/W ['.$w.' ]';
  7477. }
  7478. function _putfontwidths(&$font, $cidoffset=0) {
  7479. ksort($font['cw']);
  7480. unset($font['cw'][65535]);
  7481. $rangeid = 0;
  7482. $range = array();
  7483. $prevcid = -2;
  7484. $prevwidth = -1;
  7485. $interval = false;
  7486. // for each character
  7487. foreach ($font['cw'] as $cid => $width) {
  7488. $cid -= $cidoffset;
  7489. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7490. if ($cid == ($prevcid + 1)) {
  7491. // consecutive CID
  7492. if ($width == $prevwidth) {
  7493. if ($width == $range[$rangeid][0]) {
  7494. $range[$rangeid][] = $width;
  7495. } else {
  7496. array_pop($range[$rangeid]);
  7497. // new range
  7498. $rangeid = $prevcid;
  7499. $range[$rangeid] = array();
  7500. $range[$rangeid][] = $prevwidth;
  7501. $range[$rangeid][] = $width;
  7502. }
  7503. $interval = true;
  7504. $range[$rangeid]['interval'] = true;
  7505. } else {
  7506. if ($interval) {
  7507. // new range
  7508. $rangeid = $cid;
  7509. $range[$rangeid] = array();
  7510. $range[$rangeid][] = $width;
  7511. } else {
  7512. $range[$rangeid][] = $width;
  7513. }
  7514. $interval = false;
  7515. }
  7516. } else {
  7517. // new range
  7518. $rangeid = $cid;
  7519. $range[$rangeid] = array();
  7520. $range[$rangeid][] = $width;
  7521. $interval = false;
  7522. }
  7523. $prevcid = $cid;
  7524. $prevwidth = $width;
  7525. }
  7526. }
  7527. $this->_out($this->_putfontranges($range));
  7528. }
  7529. /*-- CJK-FONTS --*/
  7530. // from class PDF_Chinese CJK EXTENSIONS
  7531. function _putType0(&$font)
  7532. {
  7533. //Type0
  7534. $this->_out('/Subtype /Type0');
  7535. $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']);
  7536. $this->_out('/Encoding /'.$font['CMap']);
  7537. $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]');
  7538. $this->_out('>>');
  7539. $this->_out('endobj');
  7540. //CIDFont
  7541. $this->_newobj();
  7542. $this->_out('<</Type /Font');
  7543. $this->_out('/Subtype /CIDFontType0');
  7544. $this->_out('/BaseFont /'.$font['name']);
  7545. $cidinfo = '/Registry '.$this->_textstring('Adobe');
  7546. $cidinfo .= ' /Ordering '.$this->_textstring($font['registry']['ordering']);
  7547. $cidinfo .= ' /Supplement '.$font['registry']['supplement'];
  7548. $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  7549. $this->_out('/FontDescriptor '.($this->n+1).' 0 R');
  7550. if (isset($font['MissingWidth'])){
  7551. $this->_out('/DW '.$font['MissingWidth'].'');
  7552. }
  7553. $this->_putfontwidths($font, 31);
  7554. $this->_out('>>');
  7555. $this->_out('endobj');
  7556. //Font descriptor
  7557. $this->_newobj();
  7558. $s = '<</Type /FontDescriptor /FontName /'.$font['name'];
  7559. foreach ($font['desc'] as $k => $v) {
  7560. if ($k != 'Style') {
  7561. $s .= ' /'.$k.' '.$v.'';
  7562. }
  7563. }
  7564. $this->_out($s.'>>');
  7565. $this->_out('endobj');
  7566. }
  7567. /*-- END CJK-FONTS --*/
  7568. function _putimages()
  7569. {
  7570. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  7571. reset($this->images);
  7572. while(list($file,$info)=each($this->images)) {
  7573. $this->_newobj();
  7574. $this->images[$file]['n']=$this->n;
  7575. $this->_out('<</Type /XObject');
  7576. $this->_out('/Subtype /Image');
  7577. $this->_out('/Width '.$info['w']);
  7578. $this->_out('/Height '.$info['h']);
  7579. if (isset($info['masked'])) {
  7580. $this->_out('/SMask '.($this->n - 1).' 0 R');
  7581. }
  7582. if($info['cs']=='Indexed') {
  7583. 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.")."); }
  7584. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  7585. }
  7586. else {
  7587. $this->_out('/ColorSpace /'.$info['cs']);
  7588. if($info['cs']=='DeviceCMYK') {
  7589. if ($this->PDFA && $this->restrictColorSpace!=3) { $this->Error("PDFA1-b does not permit Images using mixed colour space (".$file.")."); }
  7590. if($info['type']=='jpg') { $this->_out('/Decode [1 0 1 0 1 0 1 0]'); }
  7591. }
  7592. 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.")."); }
  7593. }
  7594. $this->_out('/BitsPerComponent '.$info['bpc']);
  7595. if (isset($info['f']) && $info['f']) { $this->_out('/Filter /'.$info['f']); }
  7596. if(isset($info['parms'])) { $this->_out($info['parms']); }
  7597. if(isset($info['trns']) and is_array($info['trns'])) {
  7598. $trns='';
  7599. for($i=0;$i<count($info['trns']);$i++)
  7600. $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  7601. $this->_out('/Mask ['.$trns.']');
  7602. }
  7603. $this->_out('/Length '.strlen($info['data']).'>>');
  7604. $this->_putstream($info['data']);
  7605. unset($this->images[$file]['data']);
  7606. $this->_out('endobj');
  7607. //Palette
  7608. if($info['cs']=='Indexed') {
  7609. $this->_newobj();
  7610. $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  7611. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  7612. $this->_putstream($pal);
  7613. $this->_out('endobj');
  7614. }
  7615. }
  7616. }
  7617. function _putinfo()
  7618. {
  7619. $this->_out('/Producer '.$this->_UTF16BEtextstring('mPDF '.mPDF_VERSION));
  7620. if(!empty($this->title))
  7621. $this->_out('/Title '.$this->_UTF16BEtextstring($this->title));
  7622. if(!empty($this->subject))
  7623. $this->_out('/Subject '.$this->_UTF16BEtextstring($this->subject));
  7624. if(!empty($this->author))
  7625. $this->_out('/Author '.$this->_UTF16BEtextstring($this->author));
  7626. if(!empty($this->keywords))
  7627. $this->_out('/Keywords '.$this->_UTF16BEtextstring($this->keywords));
  7628. if(!empty($this->creator))
  7629. $this->_out('/Creator '.$this->_UTF16BEtextstring($this->creator));
  7630. $z = date('O'); // +0200
  7631. $offset = substr($z,0,3)."'".substr($z,3,2)."'";
  7632. $this->_out('/CreationDate '.$this->_textstring(date('YmdHis').$offset));
  7633. $this->_out('/ModDate '.$this->_textstring(date('YmdHis').$offset));
  7634. if ($this->PDFX) {
  7635. $this->_out('/Trapped/False');
  7636. $this->_out('/GTS_PDFXVersion(PDF/X-1a:2003)');
  7637. }
  7638. }
  7639. function _putmetadata() {
  7640. $this->_newobj();
  7641. $this->MetadataRoot = $this->n;
  7642. $Producer = 'mPDF '.mPDF_VERSION;
  7643. $z = date('O'); // +0200
  7644. $offset = substr($z,0,3).':'.substr($z,3,2);
  7645. $CreationDate = date('Y-m-d\TH:i:s').$offset; // 2006-03-10T10:47:26-05:00 2006-06-19T09:05:17Z
  7646. $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  7647. mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
  7648. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) );
  7649. $m = '<?xpacket begin="'.chr(239).chr(187).chr(191).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; // begin = FEFF BOM
  7650. $m .= ' <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701">'."\n";
  7651. $m .= ' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  7652. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  7653. $m .= ' <pdf:Producer>'.$Producer.'</pdf:Producer>'."\n";
  7654. if(!empty($this->keywords)) { $m .= ' <pdf:Keywords>'.$this->keywords.'</pdf:Keywords>'."\n"; }
  7655. $m .= ' </rdf:Description>'."\n";
  7656. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  7657. $m .= ' <xmp:CreateDate>'.$CreationDate.'</xmp:CreateDate>'."\n";
  7658. $m .= ' <xmp:ModifyDate>'.$CreationDate.'</xmp:ModifyDate>'."\n";
  7659. $m .= ' <xmp:MetadataDate>'.$CreationDate.'</xmp:MetadataDate>'."\n";
  7660. if(!empty($this->creator)) { $m .= ' <xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n"; }
  7661. $m .= ' </rdf:Description>'."\n";
  7662. // DC elements
  7663. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  7664. $m .= ' <dc:format>application/pdf</dc:format>'."\n";
  7665. if(!empty($this->title)) {
  7666. $m .= ' <dc:title>
  7667. <rdf:Alt>
  7668. <rdf:li xml:lang="x-default">'.$this->title.'</rdf:li>
  7669. </rdf:Alt>
  7670. </dc:title>'."\n";
  7671. }
  7672. if(!empty($this->keywords)) {
  7673. $m .= ' <dc:subject>
  7674. <rdf:Bag>
  7675. <rdf:li>'.$this->keywords.'</rdf:li>
  7676. </rdf:Bag>
  7677. </dc:subject>'."\n";
  7678. }
  7679. if(!empty($this->subject)) {
  7680. $m .= ' <dc:description>
  7681. <rdf:Alt>
  7682. <rdf:li xml:lang="x-default">'.$this->subject.'</rdf:li>
  7683. </rdf:Alt>
  7684. </dc:description>'."\n";
  7685. }
  7686. if(!empty($this->author)) {
  7687. $m .= ' <dc:creator>
  7688. <rdf:Seq>
  7689. <rdf:li>'.$this->author.'</rdf:li>
  7690. </rdf:Seq>
  7691. </dc:creator>'."\n";
  7692. }
  7693. $m .= ' </rdf:Description>'."\n";
  7694. // This bit is specific to PDFX-1a
  7695. if ($this->PDFX) {
  7696. $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";
  7697. }
  7698. // This bit is specific to PDFA-1b
  7699. else if ($this->PDFA) {
  7700. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" >'."\n";
  7701. $m .= ' <pdfaid:part>1</pdfaid:part>'."\n";
  7702. $m .= ' <pdfaid:conformance>B</pdfaid:conformance>'."\n";
  7703. $m .= ' <pdfaid:amd>2005</pdfaid:amd>'."\n";
  7704. $m .= ' </rdf:Description>'."\n";
  7705. }
  7706. $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  7707. $m .= ' <xmpMM:DocumentID>uuid:'.$uuid.'</xmpMM:DocumentID>'."\n";
  7708. $m .= ' </rdf:Description>'."\n";
  7709. $m .= ' </rdf:RDF>'."\n";
  7710. $m .= ' </x:xmpmeta>'."\n";
  7711. $m .= str_repeat(str_repeat(' ',100)."\n",20); // 2-4kB whitespace padding required
  7712. $m .= '<?xpacket end="w"?>'; // "r" read only
  7713. $this->_out('<</Type/Metadata/Subtype/XML/Length '.strlen($m).'>>');
  7714. $this->_putstream($m);
  7715. $this->_out('endobj');
  7716. }
  7717. function _putoutputintent() {
  7718. $this->_newobj();
  7719. $this->OutputIntentRoot = $this->n;
  7720. $this->_out('<</Type /OutputIntent');
  7721. if ($this->PDFA) {
  7722. $this->_out('/S /GTS_PDFA1');
  7723. if ($this->ICCProfile) {
  7724. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  7725. $this->_out('/OutputConditionIdentifier (Custom)');
  7726. $this->_out('/OutputCondition ()');
  7727. }
  7728. else {
  7729. $this->_out('/Info (sRGB IEC61966-2.1)');
  7730. $this->_out('/OutputConditionIdentifier (sRGB IEC61966-2.1)');
  7731. $this->_out('/OutputCondition ()');
  7732. }
  7733. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  7734. }
  7735. else if ($this->PDFX) { // always a CMYK profile
  7736. $this->_out('/S /GTS_PDFX');
  7737. if ($this->ICCProfile) {
  7738. $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')');
  7739. $this->_out('/OutputConditionIdentifier (Custom)');
  7740. $this->_out('/OutputCondition ()');
  7741. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R');
  7742. }
  7743. else {
  7744. $this->_out('/Info (CGATS TR 001)');
  7745. $this->_out('/OutputConditionIdentifier (CGATS TR 001)');
  7746. $this->_out('/OutputCondition (CGATS TR 001 (SWOP))');
  7747. $this->_out('/RegistryName (http://www.color.org)');
  7748. }
  7749. }
  7750. $this->_out('>>');
  7751. $this->_out('endobj');
  7752. if ($this->PDFX && !$this->ICCProfile) { return; } // no ICCProfile embedded
  7753. $this->_newobj();
  7754. if ($this->ICCProfile)
  7755. $s = file_get_contents(_MPDF_PATH.'iccprofiles/'.$this->ICCProfile.'.icc');
  7756. else
  7757. $s = file_get_contents(_MPDF_PATH.'iccprofiles/sRGB_IEC61966-2-1.icc');
  7758. if ($this->compress) { $s = gzcompress($s); }
  7759. $this->_out('<<');
  7760. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace == 3)) { $this->_out('/N 4'); }
  7761. else { $this->_out('/N 3'); }
  7762. if ($this->compress)
  7763. $this->_out('/Filter /FlateDecode ');
  7764. $this->_out('/Length '.strlen($s).'>>');
  7765. $this->_putstream($s);
  7766. $this->_out('endobj');
  7767. }
  7768. function _putcatalog() {
  7769. $this->_out('/Type /Catalog');
  7770. $this->_out('/Pages 1 0 R');
  7771. if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]');
  7772. elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]');
  7773. elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  7774. elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  7775. else $this->_out('/OpenAction [3 0 R /XYZ null null null]');
  7776. if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage');
  7777. elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn');
  7778. elseif($this->LayoutMode=='twoleft') $this->_out('/PageLayout /TwoColumnLeft');
  7779. elseif($this->LayoutMode=='tworight') $this->_out('/PageLayout /TwoColumnRight');
  7780. elseif($this->LayoutMode=='two') {
  7781. if ($this->mirrorMargins) { $this->_out('/PageLayout /TwoColumnRight'); }
  7782. else { $this->_out('/PageLayout /TwoColumnLeft'); }
  7783. }
  7784. /*-- BOOKMARKS --*/
  7785. if(count($this->BMoutlines)>0) {
  7786. $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  7787. $this->_out('/PageMode /UseOutlines');
  7788. }
  7789. /*-- END BOOKMARKS --*/
  7790. if(is_int(strpos($this->DisplayPreferences,'FullScreen'))) $this->_out('/PageMode /FullScreen');
  7791. // Metadata
  7792. if ($this->PDFA || $this->PDFX) {
  7793. $this->_out('/Metadata '.$this->MetadataRoot.' 0 R');
  7794. }
  7795. // OutputIntents
  7796. if ($this->PDFA || $this->PDFX || $this->ICCProfile) {
  7797. $this->_out('/OutputIntents ['.$this->OutputIntentRoot.' 0 R]');
  7798. }
  7799. /*-- FORMS --*/
  7800. if (count($this->form->forms)>0) {
  7801. $this->form->_putFormsCatalog();
  7802. }
  7803. /*-- END FORMS --*/
  7804. if ( isset($this->js) ) {
  7805. $this->_out('/Names << /JavaScript '.($this->n_js).' 0 R >> ');
  7806. }
  7807. if($this->DisplayPreferences || $this->directionality == 'rtl' || $this->mirrorMargins) {
  7808. $this->_out('/ViewerPreferences<<');
  7809. if(is_int(strpos($this->DisplayPreferences,'HideMenubar'))) $this->_out('/HideMenubar true');
  7810. if(is_int(strpos($this->DisplayPreferences,'HideToolbar'))) $this->_out('/HideToolbar true');
  7811. if(is_int(strpos($this->DisplayPreferences,'HideWindowUI'))) $this->_out('/HideWindowUI true');
  7812. if(is_int(strpos($this->DisplayPreferences,'DisplayDocTitle'))) $this->_out('/DisplayDocTitle true');
  7813. if(is_int(strpos($this->DisplayPreferences,'CenterWindow'))) $this->_out('/CenterWindow true');
  7814. if(is_int(strpos($this->DisplayPreferences,'FitWindow'))) $this->_out('/FitWindow true');
  7815. // /PrintScaling is PDF 1.6 spec.
  7816. if(is_int(strpos($this->DisplayPreferences,'NoPrintScaling')) && !$this->PDFA && !$this->PDFX)
  7817. $this->_out('/PrintScaling /None');
  7818. if($this->directionality == 'rtl') $this->_out('/Direction /R2L');
  7819. // /Duplex is PDF 1.7 spec.
  7820. if($this->mirrorMargins && !$this->PDFA && !$this->PDFX) {
  7821. // if ($this->DefOrientation=='P') $this->_out('/Duplex /DuplexFlipShortEdge');
  7822. $this->_out('/Duplex /DuplexFlipLongEdge'); // PDF v1.7+
  7823. }
  7824. $this->_out('>>');
  7825. }
  7826. if ($this->hasOC) {
  7827. $p=$this->n_ocg_print.' 0 R';
  7828. $v=$this->n_ocg_view.' 0 R';
  7829. $h=$this->n_ocg_hidden.' 0 R';
  7830. $as="<</Event /Print /OCGs [$p $v $h] /Category [/Print]>> <</Event /View /OCGs [$p $v $h] /Category [/View]>>";
  7831. $this->_out("/OCProperties <</OCGs [$p $v $h] /D <</ON [$p] /OFF [$v] /OFF [$h] /AS [$as]>>>>");
  7832. }
  7833. }
  7834. // Inactive function left for backwards compatability
  7835. function SetUserRights($enable=true, $annots="", $form="", $signature="") {
  7836. // Does nothing
  7837. }
  7838. function _enddoc() {
  7839. if ($this->progressBar) { $this->UpdateProgressBar(2,'10','Writing Headers & Footers'); } // *PROGRESS-BAR*
  7840. $this->_puthtmlheaders(); // *HTMLHEADERS-FOOTERS*
  7841. if ($this->progressBar) { $this->UpdateProgressBar(2,'20','Writing Pages'); } // *PROGRESS-BAR*
  7842. // Remove references to unused fonts (usually default font)
  7843. foreach($this->fonts as $fk=>$font) {
  7844. if (!$font['used'] && ($font['type']=='TTF')) {
  7845. if ($font['sip'] || $font['smp']) {
  7846. foreach($font['subsetfontids'] AS $k => $fid) {
  7847. foreach($this->pages AS $pn=>$page) {
  7848. $this->pages[$pn] = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7849. }
  7850. }
  7851. }
  7852. else {
  7853. foreach($this->pages AS $pn=>$page) {
  7854. $this->pages[$pn] = preg_replace('/\s\/F'.$font['i'].' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7855. }
  7856. }
  7857. }
  7858. }
  7859. $this->_putpages();
  7860. if ($this->progressBar) { $this->UpdateProgressBar(2,'30','Writing document resources'); } // *PROGRESS-BAR*
  7861. $this->_putresources();
  7862. //Info
  7863. $this->_newobj();
  7864. $this->InfoRoot = $this->n;
  7865. $this->_out('<<');
  7866. if ($this->progressBar) { $this->UpdateProgressBar(2,'80','Writing document info'); } // *PROGRESS-BAR*
  7867. $this->_putinfo();
  7868. $this->_out('>>');
  7869. $this->_out('endobj');
  7870. // METADATA
  7871. if ($this->PDFA || $this->PDFX) { $this->_putmetadata(); }
  7872. // OUTPUTINTENT
  7873. if ($this->PDFA || $this->PDFX || $this->ICCProfile) { $this->_putoutputintent(); }
  7874. //Catalog
  7875. $this->_newobj();
  7876. $this->_out('<<');
  7877. if ($this->progressBar) { $this->UpdateProgressBar(2,'90','Writing document catalog'); } // *PROGRESS-BAR*
  7878. $this->_putcatalog();
  7879. $this->_out('>>');
  7880. $this->_out('endobj');
  7881. //Cross-ref
  7882. $o=strlen($this->buffer);
  7883. $this->_out('xref');
  7884. $this->_out('0 '.($this->n+1));
  7885. $this->_out('0000000000 65535 f ');
  7886. for($i=1; $i <= $this->n ; $i++)
  7887. $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  7888. //Trailer
  7889. $this->_out('trailer');
  7890. $this->_out('<<');
  7891. $this->_puttrailer();
  7892. $this->_out('>>');
  7893. $this->_out('startxref');
  7894. $this->_out($o);
  7895. $this->buffer .= '%%EOF';
  7896. $this->state=3;
  7897. /*-- IMPORTS --*/
  7898. if ($this->enableImports && count($this->parsers) > 0) {
  7899. foreach ($this->parsers as $k => $_){
  7900. $this->parsers[$k]->closeFile();
  7901. $this->parsers[$k] = null;
  7902. unset($this->parsers[$k]);
  7903. }
  7904. }
  7905. /*-- END IMPORTS --*/
  7906. }
  7907. function _beginpage($orientation,$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') {
  7908. if (!($pagesel && $this->page==1 && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)))) {
  7909. $this->page++;
  7910. $this->pages[$this->page]='';
  7911. }
  7912. $this->state=2;
  7913. $resetHTMLHeadersrequired = false;
  7914. if ($newformat) { $this->_setPageSize($newformat, $orientation); }
  7915. /*-- CSS-PAGE --*/
  7916. // Paged media (page-box)
  7917. if ($pagesel || (isset($this->page_box['using']) && $this->page_box['using'])) {
  7918. if ($pagesel || $this->page==1) { $first = true; }
  7919. else { $first = false; }
  7920. if ($this->mirrorMargins && ($this->page % 2==0)) { $oddEven = 'E'; }
  7921. else { $oddEven = 'O'; }
  7922. if ($pagesel) { $psel = $pagesel; }
  7923. else if ($this->page_box['current']) { $psel = $this->page_box['current']; }
  7924. else { $psel = ''; }
  7925. list($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS($psel, $first, $oddEven);
  7926. if ($this->mirrorMargins && ($this->page % 2==0)) {
  7927. if ($hname) { $ehvalue = 1; $ehname = $hname; } else { $ehvalue = -1; }
  7928. if ($fname) { $efvalue = 1; $efname = $fname; } else { $efvalue = -1; }
  7929. }
  7930. else {
  7931. if ($hname) { $ohvalue = 1; $ohname = $hname; } else { $ohvalue = -1; }
  7932. if ($fname) { $ofvalue = 1; $ofname = $fname; } else { $ofvalue = -1; }
  7933. }
  7934. if ($resetpagenum || $pagenumstyle || $suppress) {
  7935. $this->PageNumSubstitutions[] = array('from'=>($this->page), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  7936. }
  7937. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  7938. $this->show_marks = $marks;
  7939. // Background color
  7940. if (isset($bg['BACKGROUND-COLOR'])) {
  7941. $cor = $this->ConvertColor($bg['BACKGROUND-COLOR']);
  7942. if ($cor) {
  7943. $this->bodyBackgroundColor = $cor;
  7944. }
  7945. }
  7946. else { $this->bodyBackgroundColor = false; }
  7947. /*-- BACKGROUNDS --*/
  7948. if (isset($bg['BACKGROUND-GRADIENT'])) {
  7949. $this->bodyBackgroundGradient = $bg['BACKGROUND-GRADIENT'];
  7950. }
  7951. else { $this->bodyBackgroundGradient = false; }
  7952. // Tiling Patterns
  7953. if (isset($bg['BACKGROUND-IMAGE']) && $bg['BACKGROUND-IMAGE']) {
  7954. $ret = $this->SetBackground($bg, $this->pgwidth);
  7955. if ($ret) { $this->bodyBackgroundImage = $ret; }
  7956. }
  7957. else { $this->bodyBackgroundImage = false; }
  7958. /*-- END BACKGROUNDS --*/
  7959. $this->page_box['current'] = $psel;
  7960. $this->page_box['using'] = true;
  7961. }
  7962. /*-- END CSS-PAGE --*/
  7963. //Page orientation
  7964. if(!$orientation)
  7965. $orientation=$this->DefOrientation;
  7966. else {
  7967. $orientation=strtoupper(substr($orientation,0,1));
  7968. if($orientation!=$this->DefOrientation)
  7969. $this->OrientationChanges[$this->page]=true;
  7970. }
  7971. if($orientation!=$this->CurOrientation || $newformat) {
  7972. //Change orientation
  7973. if($orientation=='P') {
  7974. $this->wPt=$this->fwPt;
  7975. $this->hPt=$this->fhPt;
  7976. $this->w=$this->fw;
  7977. $this->h=$this->fh;
  7978. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  7979. $this->tMargin = $this->orig_tMargin;
  7980. $this->bMargin = $this->orig_bMargin;
  7981. $this->DeflMargin = $this->orig_lMargin;
  7982. $this->DefrMargin = $this->orig_rMargin;
  7983. $this->margin_header = $this->orig_hMargin;
  7984. $this->margin_footer = $this->orig_fMargin;
  7985. }
  7986. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  7987. }
  7988. else {
  7989. $this->wPt=$this->fhPt;
  7990. $this->hPt=$this->fwPt;
  7991. $this->w=$this->fh;
  7992. $this->h=$this->fw;
  7993. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  7994. $this->tMargin = $this->orig_lMargin;
  7995. $this->bMargin = $this->orig_rMargin;
  7996. $this->DeflMargin = $this->orig_bMargin;
  7997. $this->DefrMargin = $this->orig_tMargin;
  7998. $this->margin_header = $this->orig_hMargin;
  7999. $this->margin_footer = $this->orig_fMargin;
  8000. }
  8001. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  8002. }
  8003. $this->CurOrientation=$orientation;
  8004. $this->ResetMargins();
  8005. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8006. $this->PageBreakTrigger=$this->h-$this->bMargin;
  8007. }
  8008. $this->pageDim[$this->page]['w']=$this->w ;
  8009. $this->pageDim[$this->page]['h']=$this->h ;
  8010. $this->pageDim[$this->page]['outer_width_LR'] = isset($this->page_box['outer_width_LR']) ? $this->page_box['outer_width_LR'] : 0;
  8011. $this->pageDim[$this->page]['outer_width_TB'] = isset($this->page_box['outer_width_TB']) ? $this->page_box['outer_width_TB'] : 0;
  8012. if (!isset($this->page_box['outer_width_LR']) && !isset($this->page_box['outer_width_TB'])) {
  8013. $this->pageDim[$this->page]['bleedMargin'] = 0;
  8014. }
  8015. else if ($this->bleedMargin <= $this->page_box['outer_width_LR'] && $this->bleedMargin <= $this->page_box['outer_width_TB']) {
  8016. $this->pageDim[$this->page]['bleedMargin'] = $this->bleedMargin;
  8017. }
  8018. else {
  8019. $this->pageDim[$this->page]['bleedMargin'] = min($this->page_box['outer_width_LR'], $this->page_box['outer_width_TB'])-0.01;
  8020. }
  8021. // If Page Margins are re-defined
  8022. // strlen()>0 is used to pick up (integer) 0, (string) '0', or set value
  8023. 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)) {
  8024. if (strlen($mgl)>0) $this->DeflMargin = $mgl;
  8025. if (strlen($mgr)>0) $this->DefrMargin = $mgr;
  8026. if (strlen($mgt)>0) $this->tMargin = $mgt;
  8027. if (strlen($mgb)>0) $this->bMargin = $mgb;
  8028. if (strlen($mgh)>0) $this->margin_header=$mgh;
  8029. if (strlen($mgf)>0) $this->margin_footer=$mgf;
  8030. $this->ResetMargins();
  8031. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8032. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8033. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8034. }
  8035. $this->ResetMargins();
  8036. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  8037. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  8038. // Reset column top margin
  8039. $this->y0 = $this->tMargin;
  8040. $this->x=$this->lMargin;
  8041. $this->y=$this->tMargin;
  8042. $this->FontFamily='';
  8043. // HEADERS AND FOOTERS
  8044. if ($ohvalue<0 || strtoupper($ohvalue)=='OFF') {
  8045. $this->HTMLHeader = '';
  8046. $this->headerDetails['odd'] = array();
  8047. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8048. }
  8049. else if ($ohname && $ohvalue>0) {
  8050. /*-- HTMLHEADERS-FOOTERS --*/
  8051. if (preg_match('/^html_(.*)$/i',$ohname,$n)) {
  8052. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeader = $this->pageHTMLheaders[$n[1]]; }
  8053. else { $this->HTMLHeader = ''; }
  8054. $this->headerDetails['odd'] = array();
  8055. $resetHTMLHeadersrequired = true;
  8056. }
  8057. else {
  8058. /*-- END HTMLHEADERS-FOOTERS --*/
  8059. if (isset($this->pageheaders[$ohname])) { $this->headerDetails['odd'] = $this->pageheaders[$ohname]; }
  8060. else if ($ohname!='_default') { $this->headerDetails['odd'] = array(); }
  8061. $this->HTMLHeader = '';
  8062. /*-- HTMLHEADERS-FOOTERS --*/
  8063. $resetHTMLHeadersrequired = false;
  8064. }
  8065. /*-- END HTMLHEADERS-FOOTERS --*/
  8066. }
  8067. if ($ehvalue<0 || strtoupper($ehvalue)=='OFF') {
  8068. $this->HTMLHeaderE = '';
  8069. $this->headerDetails['even'] = array();
  8070. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8071. }
  8072. else if ($ehname && $ehvalue>0) {
  8073. /*-- HTMLHEADERS-FOOTERS --*/
  8074. if (preg_match('/^html_(.*)$/i',$ehname,$n)) {
  8075. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeaderE = $this->pageHTMLheaders[$n[1]]; }
  8076. else { $this->HTMLHeaderE = ''; }
  8077. $this->headerDetails['even'] = array();
  8078. $resetHTMLHeadersrequired = true;
  8079. }
  8080. else {
  8081. /*-- END HTMLHEADERS-FOOTERS --*/
  8082. if (isset($this->pageheaders[$ehname])) { $this->headerDetails['even'] = $this->pageheaders[$ehname]; }
  8083. else if ($ehname!='_default') { $this->headerDetails['even'] = array(); }
  8084. $this->HTMLHeaderE = '';
  8085. /*-- HTMLHEADERS-FOOTERS --*/
  8086. $resetHTMLHeadersrequired = false;
  8087. }
  8088. /*-- END HTMLHEADERS-FOOTERS --*/
  8089. }
  8090. if ($ofvalue<0 || strtoupper($ofvalue)=='OFF') {
  8091. $this->HTMLFooter = '';
  8092. $this->footerDetails['odd'] = array();
  8093. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8094. }
  8095. else if ($ofname && $ofvalue>0) {
  8096. /*-- HTMLHEADERS-FOOTERS --*/
  8097. if (preg_match('/^html_(.*)$/i',$ofname,$n)) {
  8098. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooter = $this->pageHTMLfooters[$n[1]]; }
  8099. else { $this->HTMLFooter = ''; }
  8100. $this->footerDetails['odd'] = array();
  8101. $resetHTMLHeadersrequired = true;
  8102. }
  8103. else {
  8104. /*-- END HTMLHEADERS-FOOTERS --*/
  8105. if (isset($this->pagefooters[$ofname])) { $this->footerDetails['odd'] = $this->pagefooters[$ofname]; }
  8106. else if ($ofname!='_default') { $this->footerDetails['odd'] = array(); }
  8107. $this->HTMLFooter = '';
  8108. /*-- HTMLHEADERS-FOOTERS --*/
  8109. $resetHTMLHeadersrequired = true;
  8110. }
  8111. /*-- END HTMLHEADERS-FOOTERS --*/
  8112. }
  8113. if ($efvalue<0 || strtoupper($efvalue)=='OFF') {
  8114. $this->HTMLFooterE = '';
  8115. $this->footerDetails['even'] = array();
  8116. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  8117. }
  8118. else if ($efname && $efvalue>0) {
  8119. /*-- HTMLHEADERS-FOOTERS --*/
  8120. if (preg_match('/^html_(.*)$/i',$efname,$n)) {
  8121. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooterE = $this->pageHTMLfooters[$n[1]]; }
  8122. else { $this->HTMLFooterE = ''; }
  8123. $this->footerDetails['even'] = array();
  8124. $resetHTMLHeadersrequired = true;
  8125. }
  8126. else {
  8127. /*-- END HTMLHEADERS-FOOTERS --*/
  8128. if (isset($this->pagefooters[$efname])) { $this->footerDetails['even'] = $this->pagefooters[$efname]; }
  8129. else if ($efname!='_default') { $this->footerDetails['even'] = array(); }
  8130. $this->HTMLFooterE = '';
  8131. /*-- HTMLHEADERS-FOOTERS --*/
  8132. $resetHTMLHeadersrequired = true;
  8133. }
  8134. /*-- END HTMLHEADERS-FOOTERS --*/
  8135. }
  8136. /*-- HTMLHEADERS-FOOTERS --*/
  8137. if ($resetHTMLHeadersrequired) {
  8138. $this->SetHTMLHeader($this->HTMLHeader );
  8139. $this->SetHTMLHeader($this->HTMLHeaderE ,'E');
  8140. $this->SetHTMLFooter($this->HTMLFooter );
  8141. $this->SetHTMLFooter($this->HTMLFooterE ,'E');
  8142. }
  8143. /*-- END HTMLHEADERS-FOOTERS --*/
  8144. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  8145. $this->_setAutoHeaderHeight($this->headerDetails['even'], $this->HTMLHeaderE);
  8146. $this->_setAutoFooterHeight($this->footerDetails['even'], $this->HTMLFooterE);
  8147. }
  8148. else { // ODD or DEFAULT
  8149. $this->_setAutoHeaderHeight($this->headerDetails['odd'], $this->HTMLHeader);
  8150. $this->_setAutoFooterHeight($this->footerDetails['odd'], $this->HTMLFooter);
  8151. }
  8152. // Reset column top margin
  8153. $this->y0 = $this->tMargin;
  8154. $this->x=$this->lMargin;
  8155. $this->y=$this->tMargin;
  8156. }
  8157. function _setAutoHeaderHeight(&$det, &$htmlh) {
  8158. if ($this->setAutoTopMargin=='pad') {
  8159. if ($htmlh['h']) { $h = $htmlh['h']; }
  8160. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8161. else { $h = 0; }
  8162. $this->tMargin = $this->margin_header + $h + $this->orig_tMargin;
  8163. }
  8164. else if ($this->setAutoTopMargin=='stretch') {
  8165. if ($htmlh['h']) { $h = $htmlh['h']; }
  8166. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  8167. else { $h = 0; }
  8168. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $h + $this->autoMarginPadding);
  8169. }
  8170. }
  8171. function _setAutoFooterHeight(&$det, &$htmlf) {
  8172. if ($this->setAutoBottomMargin=='pad') {
  8173. if ($htmlf['h']) { $h = $htmlf['h']; }
  8174. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8175. else { $h = 0; }
  8176. $this->bMargin = $this->margin_footer + $h + $this->orig_bMargin;
  8177. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8178. }
  8179. else if ($this->setAutoBottomMargin=='stretch') {
  8180. if ($htmlf['h']) { $h = $htmlf['h']; }
  8181. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  8182. else { $h = 0; }
  8183. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $h + $this->autoMarginPadding);
  8184. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  8185. }
  8186. }
  8187. function _getHFHeight(&$det,$end) {
  8188. $h = 0;
  8189. if(count($det)) {
  8190. foreach(array('L','C','R') AS $pos) {
  8191. if (isset($det[$pos]['content']) && $det[$pos]['content']) {
  8192. if (isset($det[$pos]['font-size']) && $det[$pos]['font-size']) { $hfsz = $det[$pos]['font-size']; }
  8193. else { $hfsz = $this->default_font_size; }
  8194. $h = max($h,$hfsz/_MPDFK);
  8195. }
  8196. }
  8197. if ($det['line'] && $end=='H') { $h += $h/_MPDFK*$this->header_line_spacing; }
  8198. else if ($det['line'] && $end=='F') { $h += $h/_MPDFK*$this->footer_line_spacing; }
  8199. }
  8200. return $h;
  8201. }
  8202. function _endpage() {
  8203. /*-- CSS-IMAGE-FLOAT --*/
  8204. $this->printfloatbuffer();
  8205. /*-- END CSS-IMAGE-FLOAT --*/
  8206. if($this->visibility!='visible')
  8207. $this->SetVisibility('visible');
  8208. //End of page contents
  8209. $this->state=1;
  8210. }
  8211. function _newobj($obj_id=false,$onlynewobj=false) {
  8212. if (!$obj_id) {
  8213. $obj_id = ++$this->n;
  8214. }
  8215. //Begin a new object
  8216. if (!$onlynewobj) {
  8217. $this->offsets[$obj_id] = strlen($this->buffer);
  8218. $this->_out($obj_id.' 0 obj');
  8219. $this->_current_obj_id = $obj_id; // for later use with encryption
  8220. }
  8221. }
  8222. function _dounderline($x,$y,$txt) {
  8223. // Now print line exactly where $y secifies - called from Text() and Cell() - adjust position there
  8224. // WORD SPACING
  8225. $w =($this->GetStringWidth($txt)*_MPDFK) + ($this->charspacing * mb_strlen( $txt, $this->mb_enc ))
  8226. + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ));
  8227. //Draw a line
  8228. return sprintf('%.3F %.3F m %.3F %.3F l S',$x*_MPDFK,($this->h-$y)*_MPDFK,($x*_MPDFK)+$w,($this->h-$y)*_MPDFK);
  8229. }
  8230. function _imageError($file, $firsttime, $msg) {
  8231. // Save re-trying image URL's which have already failed
  8232. $this->failedimages[$file] = true;
  8233. if ($firsttime && ($this->showImageErrors || $this->debug)) {
  8234. $this->Error("IMAGE Error (".$file."): ".$msg);
  8235. }
  8236. return false;
  8237. }
  8238. function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false) {
  8239. // firsttime i.e. whether to add to this->images - use false when calling iteratively
  8240. // Image Data passed directly as var:varname
  8241. if (preg_match('/var:\s*(.*)/',$file, $v)) {
  8242. $data = $this->$v[1];
  8243. $file = md5($data);
  8244. }
  8245. // mPDF 5.5.13
  8246. if (preg_match('/data:image\/(gif|jpeg|png);base64,(.*)/',$file, $v)) {
  8247. $type = $v[1];
  8248. $data = base64_decode($v[2]);
  8249. $file = md5($data);
  8250. }
  8251. $file = urldecode_pathonly($file); // mPDF 5.5.03 // mPDF 5.5.12
  8252. if ($orig_srcpath && substr($orig_srcpath,0,5)!='data:') { $orig_srcpath = urldecode_pathonly($orig_srcpath); } // mPDF 5.5.03 5.4.21
  8253. $ppUx = 0;
  8254. if ($firsttime && preg_match('/(.*\/)([^\/]*)/',$file,$fm)) {
  8255. if (strlen($fm[2])) { $file = $fm[1].preg_replace('/ /','%20',$fm[2]); }
  8256. }
  8257. if ($orig_srcpath && isset($this->images[$orig_srcpath])) { $file=$orig_srcpath; return $this->images[$orig_srcpath]; }
  8258. if (isset($this->images[$file])) { return $this->images[$file]; }
  8259. else if ($orig_srcpath && isset($this->formobjects[$orig_srcpath])) { $file=$orig_srcpath; return $this->formobjects[$file]; }
  8260. else if (isset($this->formobjects[$file])) { return $this->formobjects[$file]; }
  8261. // Save re-trying image URL's which have already failed
  8262. else if ($firsttime && isset($this->failedimages[$file])) { return $this->_imageError($file, $firsttime, ''); }
  8263. if (empty($data)) {
  8264. $type = '';
  8265. $data = '';
  8266. if ($orig_srcpath && $this->basepathIsLocal && $check = @fopen($orig_srcpath,"rb")) {
  8267. fclose($check);
  8268. $file=$orig_srcpath;
  8269. $data = file_get_contents($file);
  8270. $type = $this->_imageTypeFromString($data);
  8271. }
  8272. if (!$data && $check = @fopen($file,"rb")) {
  8273. fclose($check);
  8274. $data = file_get_contents($file);
  8275. $type = $this->_imageTypeFromString($data);
  8276. }
  8277. if ((!$data || !$type) && !ini_get('allow_url_fopen')) { // only worth trying if remote file and !ini_get('allow_url_fopen')
  8278. $this->file_get_contents_by_socket($file, $data); // needs full url?? even on local (never needed for local)
  8279. if ($data) { $type = $this->_imageTypeFromString($data); }
  8280. }
  8281. if ((!$data || !$type) && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  8282. $this->file_get_contents_by_curl($file, $data); // needs full url?? even on local (never needed for local)
  8283. if ($data) { $type = $this->_imageTypeFromString($data); }
  8284. }
  8285. }
  8286. if (!$data) { return $this->_imageError($file, $firsttime, 'Could not find image file'); }
  8287. if (empty($type)) { $type = $this->_imageTypeFromString($data); }
  8288. if (($type == 'wmf' || $type == 'svg') && !$allowvector) { return $this->_imageError($file, $firsttime, 'WMF or SVG image file not supported in this context'); }
  8289. // SVG
  8290. if ($type == 'svg') {
  8291. if (!class_exists('SVG', false)) { include(_MPDF_PATH .'classes/svg.php'); }
  8292. $svg = new SVG($this);
  8293. $family=$this->FontFamily;
  8294. $style=$this->FontStyle;
  8295. $size=$this->FontSizePt;
  8296. $info = $svg->ImageSVG($data);
  8297. //Restore font
  8298. if($family) $this->SetFont($family,$style,$size,false);
  8299. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing SVG file'); }
  8300. $info['type']='svg';
  8301. $info['i']=count($this->formobjects)+1;
  8302. $this->formobjects[$file]=$info;
  8303. return $info;
  8304. }
  8305. // JPEG
  8306. if ($type == 'jpeg' || $type == 'jpg') {
  8307. $hdr = $this->_jpgHeaderFromString($data);
  8308. if (!$hdr) { return $this->_imageError($file, $firsttime, 'Error parsing JPG header'); }
  8309. $a = $this->_jpgDataFromHeader($hdr);
  8310. $j = strpos($data,'JFIF');
  8311. if ($j) {
  8312. //Read resolution
  8313. $unitSp=ord(substr($data,($j+7),1));
  8314. if ($unitSp > 0) {
  8315. $ppUx=$this->_twobytes2int(substr($data,($j+8),2)); // horizontal pixels per meter, usually set to zero
  8316. if ($unitSp == 2) { // = dots per cm (if == 1 set as dpi)
  8317. $ppUx=round($ppUx/10 *25.4);
  8318. }
  8319. }
  8320. }
  8321. if ($a[2] == 'DeviceCMYK' && (($this->PDFA && $this->restrictColorSpace!=3) || $this->restrictColorSpace==2)) {
  8322. // convert to RGB image
  8323. if (!function_exists("gd_info")) { $this->Error("JPG image may not use CMYK color space (".$file.")."); }
  8324. 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.)"; }
  8325. $im = @imagecreatefromstring($data);
  8326. if ($im) {
  8327. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8328. imageinterlace($im, false);
  8329. $check = @imagepng($im, $tempfile);
  8330. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse JPG(CMYK) image'); }
  8331. $info = $this->_getImage($tempfile, false);
  8332. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse JPG(CMYK) image'); }
  8333. imagedestroy($im);
  8334. unlink($tempfile);
  8335. $info['type']='jpg';
  8336. if ($firsttime) {
  8337. $info['i']=count($this->images)+1;
  8338. $this->images[$file]=$info;
  8339. }
  8340. return $info;
  8341. }
  8342. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from JPG(CMYK) image'); }
  8343. }
  8344. else if ($a[2] == 'DeviceRGB' && ($this->PDFX || $this->restrictColorSpace==3)) {
  8345. // Convert to CMYK image stream - nominally returned as type='png'
  8346. $info = $this->_convImage($data, $a[2], 'DeviceCMYK', $a[0], $a[1], $ppUx, false);
  8347. 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.)"; }
  8348. }
  8349. else if (($a[2] == 'DeviceRGB' || $a[2] == 'DeviceCMYK') && $this->restrictColorSpace==1) {
  8350. // Convert to Grayscale image stream - nominally returned as type='png'
  8351. $info = $this->_convImage($data, $a[2], 'DeviceGray', $a[0], $a[1], $ppUx, false);
  8352. }
  8353. else {
  8354. $info = array('w'=>$a[0],'h'=>$a[1],'cs'=>$a[2],'bpc'=>$a[3],'f'=>'DCTDecode','data'=>$data, 'type'=>'jpg');
  8355. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8356. }
  8357. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting JPG image'); }
  8358. if ($firsttime) {
  8359. $info['i']=count($this->images)+1;
  8360. $this->images[$file]=$info;
  8361. }
  8362. return $info;
  8363. }
  8364. // PNG
  8365. else if ($type == 'png') {
  8366. //Check signature
  8367. if(substr($data,0,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  8368. return $this->_imageError($file, $firsttime, 'Error parsing PNG identifier');
  8369. }
  8370. //Read header chunk
  8371. if(substr($data,12,4)!='IHDR') {
  8372. return $this->_imageError($file, $firsttime, 'Incorrect PNG file (no IHDR block found)');
  8373. }
  8374. $w=$this->_fourbytes2int(substr($data,16,4));
  8375. $h=$this->_fourbytes2int(substr($data,20,4));
  8376. $bpc=ord(substr($data,24,1));
  8377. $errpng = false;
  8378. $pngalpha = false;
  8379. if($bpc>8) { $errpng = 'not 8-bit depth'; }
  8380. $ct=ord(substr($data,25,1));
  8381. if($ct==0) { $colspace='DeviceGray'; }
  8382. elseif($ct==2) { $colspace='DeviceRGB'; }
  8383. elseif($ct==3) { $colspace='Indexed'; }
  8384. elseif($ct==4) { $colspace='DeviceGray'; $errpng = 'alpha channel'; $pngalpha = true; }
  8385. else { $colspace='DeviceRGB'; $errpng = 'alpha channel'; $pngalpha = true; }
  8386. if(ord(substr($data,26,1))!=0) { $errpng = 'compression method'; }
  8387. if(ord(substr($data,27,1))!=0) { $errpng = 'filter method'; }
  8388. if(ord(substr($data,28,1))!=0) { $errpng = 'interlaced file'; }
  8389. $j = strpos($data,'pHYs');
  8390. if ($j) {
  8391. //Read resolution
  8392. $unitSp=ord(substr($data,($j+12),1));
  8393. if ($unitSp == 1) {
  8394. $ppUx=$this->_fourbytes2int(substr($data,($j+4),4)); // horizontal pixels per meter, usually set to zero
  8395. $ppUx=round($ppUx/1000 *25.4);
  8396. }
  8397. }
  8398. if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && ($this->PDFX || $this->restrictColorSpace==3)) {
  8399. // Convert to CMYK image stream - nominally returned as type='png'
  8400. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8401. 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.)"; }
  8402. }
  8403. else if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && $this->restrictColorSpace==1) {
  8404. // Convert to Grayscale image stream - nominally returned as type='png'
  8405. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8406. }
  8407. else if (($this->PDFA || $this->PDFX) && $pngalpha) {
  8408. // Remove alpha channel
  8409. if ($this->restrictColorSpace==1) { // Grayscale
  8410. $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha);
  8411. }
  8412. else if ($this->restrictColorSpace==3) { // CMYK
  8413. $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha);
  8414. }
  8415. else if ($this->PDFA ) { // RGB
  8416. $info = $this->_convImage($data, $colspace, 'DeviceRGB', $w, $h, $ppUx, $pngalpha);
  8417. }
  8418. 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.)"; }
  8419. }
  8420. else if ($errpng || $pngalpha) {
  8421. if (function_exists('gd_info')) { $gd = gd_info(); }
  8422. else {$gd = array(); }
  8423. if (!isset($gd['PNG Support'])) { return $this->_imageError($file, $firsttime, 'GD library required for PNG image ('.$errpng.')'); }
  8424. $im = imagecreatefromstring($data);
  8425. if (!$im) { return $this->_imageError($file, $firsttime, 'Error creating GD image from PNG file ('.$errpng.')'); }
  8426. $w = imagesx($im);
  8427. $h = imagesy($im);
  8428. if ($im) {
  8429. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8430. // Alpha channel set
  8431. if ($pngalpha) {
  8432. if ($this->PDFA) { $this->Error("PDFA1-b does not permit images with alpha channel transparency (".$file.")."); }
  8433. $imgalpha = imagecreate($w, $h);
  8434. // generate gray scale pallete
  8435. for ($c = 0; $c < 256; ++$c) { ImageColorAllocate($imgalpha, $c, $c, $c); }
  8436. // extract alpha channel
  8437. $gammacorr = 2.2; // gamma correction
  8438. for ($xpx = 0; $xpx < $w; ++$xpx) {
  8439. for ($ypx = 0; $ypx < $h; ++$ypx) {
  8440. //$colorindex = imagecolorat($im, $xpx, $ypx);
  8441. //$col = imagecolorsforindex($im, $colorindex);
  8442. //$gamma2 = (pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255);
  8443. $alpha = (imagecolorat($im, $xpx, $ypx) & 0x7F000000) >> 24;
  8444. if ($alpha < 127) {
  8445. if ($alpha==0) { $gamma = 255; }
  8446. else
  8447. $gamma = (pow((((127 - $alpha) * 255 / 127) / 255), $gammacorr) * 255);
  8448. imagesetpixel($imgalpha, $xpx, $ypx, $gamma);
  8449. }
  8450. }
  8451. }
  8452. // create temp alpha file
  8453. $tempfile_alpha = _MPDF_TEMP_PATH.'_tempMskPNG'.RAND(1,10000).'.png';
  8454. if (!is_writable($tempfile_alpha)) {
  8455. ob_start();
  8456. $check = @imagepng($imgalpha);
  8457. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8458. imagedestroy($imgalpha);
  8459. $this->_tempimg = ob_get_contents();
  8460. $this->_tempimglnk = 'var:_tempimg';
  8461. ob_end_clean();
  8462. // extract image without alpha channel
  8463. $imgplain = imagecreatetruecolor($w, $h);
  8464. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8465. // create temp image file
  8466. $minfo = $this->_getImage($this->_tempimglnk, false);
  8467. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8468. ob_start();
  8469. $check = @imagepng($imgplain);
  8470. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8471. $this->_tempimg = ob_get_contents();
  8472. $this->_tempimglnk = 'var:_tempimg';
  8473. ob_end_clean();
  8474. $info = $this->_getImage($this->_tempimglnk, false);
  8475. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8476. imagedestroy($imgplain);
  8477. $imgmask = count($this->images)+1;
  8478. $minfo['cs'] = 'DeviceGray';
  8479. $minfo['i']=$imgmask ;
  8480. $this->images[$tempfile_alpha] = $minfo;
  8481. }
  8482. else {
  8483. $check = @imagepng($imgalpha, $tempfile_alpha);
  8484. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile_alpha.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8485. imagedestroy($imgalpha);
  8486. // extract image without alpha channel
  8487. $imgplain = imagecreatetruecolor($w, $h);
  8488. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  8489. // create temp image file
  8490. $check = @imagepng($imgplain, $tempfile);
  8491. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image with alpha channel ('.$errpng.')'); }
  8492. imagedestroy($imgplain);
  8493. // embed mask image
  8494. $minfo = $this->_getImage($tempfile_alpha, false);
  8495. unlink($tempfile_alpha);
  8496. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile_alpha.') created with GD library to parse PNG image'); }
  8497. $imgmask = count($this->images)+1;
  8498. $minfo['cs'] = 'DeviceGray';
  8499. $minfo['i']=$imgmask ;
  8500. $this->images[$tempfile_alpha] = $minfo;
  8501. // embed image, masked with previously embedded mask
  8502. $info = $this->_getImage($tempfile, false);
  8503. unlink($tempfile);
  8504. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8505. }
  8506. $info['masked'] = $imgmask;
  8507. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8508. $info['type']='png';
  8509. if ($firsttime) {
  8510. $info['i']=count($this->images)+1;
  8511. $this->images[$file]=$info;
  8512. }
  8513. return $info;
  8514. }
  8515. else { // No alpha/transparency set
  8516. imagealphablending($im, false);
  8517. imagesavealpha($im, false);
  8518. imageinterlace($im, false);
  8519. if (!is_writable($tempfile)) {
  8520. ob_start();
  8521. $check = @imagepng($im);
  8522. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); }
  8523. $this->_tempimg = ob_get_contents();
  8524. $this->_tempimglnk = 'var:_tempimg';
  8525. ob_end_clean();
  8526. $info = $this->_getImage($this->_tempimglnk, false);
  8527. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); }
  8528. imagedestroy($im);
  8529. }
  8530. else {
  8531. $check = @imagepng($im, $tempfile );
  8532. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image ('.$errpng.')'); }
  8533. imagedestroy($im);
  8534. $info = $this->_getImage($tempfile, false) ;
  8535. unlink($tempfile );
  8536. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8537. }
  8538. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8539. $info['type']='png';
  8540. if ($firsttime) {
  8541. $info['i']=count($this->images)+1;
  8542. $this->images[$file]=$info;
  8543. }
  8544. return $info;
  8545. }
  8546. }
  8547. }
  8548. else {
  8549. $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  8550. //Scan chunks looking for palette, transparency and image data
  8551. $pal='';
  8552. $trns='';
  8553. $pngdata='';
  8554. $p = 33;
  8555. do {
  8556. $n=$this->_fourbytes2int(substr($data,$p,4)); $p += 4;
  8557. $type=substr($data,$p,4); $p += 4;
  8558. if($type=='PLTE') {
  8559. //Read palette
  8560. $pal=substr($data,$p,$n); $p += $n;
  8561. $p += 4;
  8562. }
  8563. elseif($type=='tRNS') {
  8564. //Read transparency info
  8565. $t=substr($data,$p,$n); $p += $n;
  8566. if($ct==0) $trns=array(ord(substr($t,1,1)));
  8567. elseif($ct==2) $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  8568. else
  8569. {
  8570. $pos=strpos($t,chr(0));
  8571. if(is_int($pos)) $trns=array($pos);
  8572. }
  8573. $p += 4;
  8574. }
  8575. elseif($type=='IDAT') {
  8576. $pngdata.=substr($data,$p,$n); $p += $n;
  8577. $p += 4;
  8578. }
  8579. elseif($type=='IEND') { break; }
  8580. else if (preg_match('/[a-zA-Z]{4}/',$type)) { $p += $n+4; }
  8581. else { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data'); }
  8582. }
  8583. while($n);
  8584. if (!$pngdata) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - no IDAT data found'); }
  8585. if($colspace=='Indexed' and empty($pal)) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - missing colour palette'); }
  8586. $info = array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$pngdata);
  8587. $info['type']='png';
  8588. if ($ppUx) { $info['set-dpi'] = $ppUx; }
  8589. }
  8590. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting PNG image'); }
  8591. if ($firsttime) {
  8592. $info['i']=count($this->images)+1;
  8593. $this->images[$file]=$info;
  8594. }
  8595. return $info;
  8596. }
  8597. // GIF
  8598. else if ($type == 'gif') {
  8599. if (function_exists('gd_info')) { $gd = gd_info(); }
  8600. else {$gd = array(); }
  8601. if (isset($gd['GIF Read Support']) && $gd['GIF Read Support']) {
  8602. $im = @imagecreatefromstring($data);
  8603. if ($im) {
  8604. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8605. imagealphablending($im, false);
  8606. imagesavealpha($im, false);
  8607. imageinterlace($im, false);
  8608. if (!is_writable($tempfile)) {
  8609. ob_start();
  8610. $check = @imagepng($im);
  8611. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse GIF image'); }
  8612. $this->_tempimg = ob_get_contents();
  8613. $this->_tempimglnk = 'var:_tempimg';
  8614. ob_end_clean();
  8615. $info = $this->_getImage($this->_tempimglnk, false);
  8616. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse GIF image'); }
  8617. imagedestroy($im);
  8618. }
  8619. else {
  8620. $check = @imagepng($im, $tempfile);
  8621. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse GIF image'); }
  8622. $info = $this->_getImage($tempfile, false);
  8623. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse GIF image'); }
  8624. imagedestroy($im);
  8625. unlink($tempfile);
  8626. }
  8627. $info['type']='gif';
  8628. if ($firsttime) {
  8629. $info['i']=count($this->images)+1;
  8630. $this->images[$file]=$info;
  8631. }
  8632. return $info;
  8633. }
  8634. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from GIF image'); }
  8635. }
  8636. if (!class_exists('gif', false)) {
  8637. include_once(_MPDF_PATH.'classes/gif.php');
  8638. }
  8639. $gif=new CGIF();
  8640. $h=0;
  8641. $w=0;
  8642. $gif->loadFile($data, 0);
  8643. if(isset($gif->m_img->m_gih->m_bLocalClr) && $gif->m_img->m_gih->m_bLocalClr) {
  8644. $nColors = $gif->m_img->m_gih->m_nTableSize;
  8645. $pal = $gif->m_img->m_gih->m_colorTable->toString();
  8646. if($bgColor != -1) {
  8647. $bgColor = $gif->m_img->m_gih->m_colorTable->colorIndex($bgColor);
  8648. }
  8649. $colspace='Indexed';
  8650. } elseif(isset($gif->m_gfh->m_bGlobalClr) && $gif->m_gfh->m_bGlobalClr) {
  8651. $nColors = $gif->m_gfh->m_nTableSize;
  8652. $pal = $gif->m_gfh->m_colorTable->toString();
  8653. if((isset($bgColor)) and $bgColor != -1) {
  8654. $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor);
  8655. }
  8656. $colspace='Indexed';
  8657. } else {
  8658. $nColors = 0;
  8659. $bgColor = -1;
  8660. $colspace='DeviceGray';
  8661. $pal='';
  8662. }
  8663. $trns='';
  8664. if(isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans && ($nColors > 0)) {
  8665. $trns=array($gif->m_img->m_nTrans);
  8666. }
  8667. $gifdata=$gif->m_img->m_data;
  8668. $w=$gif->m_gfh->m_nWidth;
  8669. $h=$gif->m_gfh->m_nHeight;
  8670. $gif->ClearData();
  8671. if($colspace=='Indexed' and empty($pal)) {
  8672. return $this->_imageError($file, $firsttime, 'Error parsing GIF image - missing colour palette');
  8673. }
  8674. if ($this->compress) {
  8675. $gifdata=gzcompress($gifdata);
  8676. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8677. }
  8678. else {
  8679. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8680. }
  8681. $info['type']='gif';
  8682. if ($firsttime) {
  8683. $info['i']=count($this->images)+1;
  8684. $this->images[$file]=$info;
  8685. }
  8686. return $info;
  8687. }
  8688. /*-- IMAGES-BMP --*/
  8689. // BMP (Windows Bitmap)
  8690. else if ($type == 'bmp') {
  8691. if (!class_exists('bmp', false)) { include(_MPDF_PATH.'classes/bmp.php'); }
  8692. if (empty($this->bmp)) { $this->bmp = new bmp($this); }
  8693. $info = $this->bmp->_getBMPimage($data, $file);
  8694. if (isset($info['error'])) {
  8695. return $this->_imageError($file, $firsttime, $info['error']);
  8696. }
  8697. if ($firsttime) {
  8698. $info['i']=count($this->images)+1;
  8699. $this->images[$file]=$info;
  8700. }
  8701. return $info;
  8702. }
  8703. /*-- END IMAGES-BMP --*/
  8704. /*-- IMAGES-WMF --*/
  8705. // WMF
  8706. else if ($type == 'wmf') {
  8707. if (!class_exists('wmf', false)) { include(_MPDF_PATH.'classes/wmf.php'); }
  8708. if (empty($this->wmf)) { $this->wmf = new wmf($this); }
  8709. $wmfres = $this->wmf->_getWMFimage($data);
  8710. if ($wmfres[0]==0) {
  8711. if ($wmfres[1]) { return $this->_imageError($file, $firsttime, $wmfres[1]); }
  8712. return $this->_imageError($file, $firsttime, 'Error parsing WMF image');
  8713. }
  8714. $info = array('x'=>$wmfres[2][0],'y'=>$wmfres[2][1],'w'=>$wmfres[3][0],'h'=>$wmfres[3][1],'data'=>$wmfres[1]);
  8715. $info['i']=count($this->formobjects)+1;
  8716. $info['type']='wmf';
  8717. $this->formobjects[$file]=$info;
  8718. return $info;
  8719. }
  8720. /*-- END IMAGES-WMF --*/
  8721. // UNKNOWN TYPE - try GD imagecreatefromstring
  8722. else {
  8723. if (function_exists('gd_info')) { $gd = gd_info(); }
  8724. else {$gd = array(); }
  8725. if (isset($gd['PNG Support']) && $gd['PNG Support']) {
  8726. $im = @imagecreatefromstring($data);
  8727. if (!$im) { return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised, and not supported by GD imagecreate'); }
  8728. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png';
  8729. imagealphablending($im, false);
  8730. imagesavealpha($im, false);
  8731. imageinterlace($im, false);
  8732. $check = @imagepng($im, $tempfile);
  8733. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse unknown image type'); }
  8734. $info = $this->_getImage($tempfile, false);
  8735. imagedestroy($im);
  8736. unlink($tempfile);
  8737. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse unknown image type'); }
  8738. $info['type']='png';
  8739. if ($firsttime) {
  8740. $info['i']=count($this->images)+1;
  8741. $this->images[$file]=$info;
  8742. }
  8743. return $info;
  8744. }
  8745. }
  8746. return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised');
  8747. }
  8748. //==============================================================
  8749. function _convImage(&$data, $colspace, $targetcs, $w, $h, $dpi, $mask) {
  8750. if ($this->PDFA || $this->PDFX) { $mask=false; }
  8751. $im = @imagecreatefromstring($data);
  8752. $info = array();
  8753. if ($im) {
  8754. $imgdata = '';
  8755. $mimgdata = '';
  8756. $minfo = array();
  8757. //Read transparency info
  8758. $trns=array();
  8759. $trnsrgb = false;
  8760. if (!$this->PDFA && !$this->PDFX) {
  8761. $p = strpos($data,'tRNS');
  8762. if ($p) {
  8763. $n=$this->_fourbytes2int(substr($data,($p-4),4));
  8764. $t = substr($data,($p+4),$n);
  8765. if ($colspace=='DeviceGray') {
  8766. $trns=array(ord(substr($t,1,1)));
  8767. $trnsrgb = array($trns[0],$trns[0],$trns[0]);
  8768. }
  8769. else if ($colspace=='DeviceRGB') {
  8770. $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  8771. $trnsrgb = $trns;
  8772. if ($targetcs=='DeviceCMYK') {
  8773. $col = $this->rgb2cmyk(array(3,$trns[0],$trns[1],$trns[2]));
  8774. $c1 = intval($col[1]*2.55);
  8775. $c2 = intval($col[2]*2.55);
  8776. $c3 = intval($col[3]*2.55);
  8777. $c4 = intval($col[4]*2.55);
  8778. $trns = array($c1,$c2,$c3,$c4);
  8779. }
  8780. else if ($targetcs=='DeviceGray') {
  8781. $c = intval(($trns[0] * .21) + ($trns[1] * .71) + ($trns[2] * .07));
  8782. $trns = array($c);
  8783. }
  8784. }
  8785. else { // Indexed
  8786. $pos = strpos($t,chr(0));
  8787. if (is_int($pos)) {
  8788. $pal = imagecolorsforindex($im, $pos);
  8789. $r = $pal['red'];
  8790. $g = $pal['green'];
  8791. $b = $pal['blue'];
  8792. $trns=array($r,$g,$b); // ****
  8793. $trnsrgb = $trns;
  8794. if ($targetcs=='DeviceCMYK') {
  8795. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  8796. $c1 = intval($col[1]*2.55);
  8797. $c2 = intval($col[2]*2.55);
  8798. $c3 = intval($col[3]*2.55);
  8799. $c4 = intval($col[4]*2.55);
  8800. $trns = array($c1,$c2,$c3,$c4);
  8801. }
  8802. else if ($targetcs=='DeviceGray') {
  8803. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  8804. $trns = array($c);
  8805. }
  8806. }
  8807. }
  8808. }
  8809. }
  8810. for ($i = 0; $i < $h; $i++) {
  8811. for ($j = 0; $j < $w; $j++) {
  8812. $rgb = imagecolorat($im, $j, $i);
  8813. $r = ($rgb >> 16) & 0xFF;
  8814. $g = ($rgb >> 8) & 0xFF;
  8815. $b = $rgb & 0xFF;
  8816. if ($colspace=='Indexed') {
  8817. $pal = imagecolorsforindex($im, $rgb);
  8818. $r = $pal['red'];
  8819. $g = $pal['green'];
  8820. $b = $pal['blue'];
  8821. }
  8822. if ($targetcs=='DeviceCMYK') {
  8823. $col = $this->rgb2cmyk(array(3,$r,$g,$b));
  8824. $c1 = intval($col[1]*2.55);
  8825. $c2 = intval($col[2]*2.55);
  8826. $c3 = intval($col[3]*2.55);
  8827. $c4 = intval($col[4]*2.55);
  8828. if ($trnsrgb) {
  8829. // original pixel was not set as transparent but processed color does match
  8830. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c1,$c2,$c3,$c4)) {
  8831. if ($c4==0) { $c4=1; } else { $c4--; }
  8832. }
  8833. }
  8834. $imgdata .= chr($c1).chr($c2).chr($c3).chr($c4);
  8835. }
  8836. else if ($targetcs=='DeviceGray') {
  8837. $c = intval(($r * .21) + ($g * .71) + ($b * .07));
  8838. if ($trnsrgb) {
  8839. // original pixel was not set as transparent but processed color does match
  8840. if ($trnsrgb!=array($r,$g,$b) && $trns==array($c)) {
  8841. if ($c==0) { $c=1; } else { $c--; }
  8842. }
  8843. }
  8844. $imgdata .= chr($c);
  8845. }
  8846. else if ($targetcs=='DeviceRGB') {
  8847. $imgdata .= chr($r).chr($g).chr($b);
  8848. }
  8849. if ($mask) {
  8850. $col = imagecolorsforindex($im, $rgb);
  8851. $gammacorr = 2.2; // gamma correction
  8852. $gamma = intval((pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255));
  8853. $mimgdata .= chr($gamma);
  8854. }
  8855. }
  8856. }
  8857. if ($targetcs=='DeviceGray') { $ncols = 1; }
  8858. else if ($targetcs=='DeviceRGB') { $ncols = 3; }
  8859. else if ($targetcs=='DeviceCMYK') { $ncols = 4; }
  8860. $imgdata = gzcompress($imgdata);
  8861. $info = array('w'=>$w,'h'=>$h,'cs'=>$targetcs,'bpc'=>8,'f'=>'FlateDecode','data'=>$imgdata, 'type'=>'png',
  8862. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  8863. if ($dpi) { $info['set-dpi'] = $dpi; }
  8864. if ($mask) {
  8865. $mimgdata = gzcompress($mimgdata);
  8866. $minfo = array('w'=>$w,'h'=>$h,'cs'=>'DeviceGray','bpc'=>8,'f'=>'FlateDecode','data'=>$mimgdata, 'type'=>'png',
  8867. 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
  8868. if ($dpi) { $minfo['set-dpi'] = $dpi; }
  8869. $tempfile = '_tempImgPNG'.RAND(1,10000).'.png';
  8870. $imgmask = count($this->images)+1;
  8871. $minfo['i']=$imgmask ;
  8872. $this->images[$tempfile] = $minfo;
  8873. $info['masked'] = $imgmask;
  8874. }
  8875. else if ($trns) { $info['trns'] = $trns; }
  8876. imagedestroy($im);
  8877. }
  8878. return $info;
  8879. }
  8880. function _fourbytes2int($s) {
  8881. //Read a 4-byte integer from string
  8882. return (ord($s[0])<<24) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]);
  8883. }
  8884. function _twobytes2int($s) {
  8885. //Read a 2-byte integer from string
  8886. return (ord(substr($s, 0, 1))<<8) + ord(substr($s, 1, 1));
  8887. }
  8888. function _jpgHeaderFromString(&$data) {
  8889. $p = 4;
  8890. $p += $this->_twobytes2int(substr($data, $p, 2)); // Length of initial marker block
  8891. $marker = substr($data, $p, 2);
  8892. while($marker != chr(255).chr(192) && $marker != chr(255).chr(194) && $p<strlen($data)) {
  8893. // Start of frame marker (FFC0) or (FFC2) mPDF 4.4.004
  8894. $p += ($this->_twobytes2int(substr($data, $p+2, 2))) + 2; // Length of marker block
  8895. $marker = substr($data, $p, 2);
  8896. }
  8897. if ($marker != chr(255).chr(192) && $marker != chr(255).chr(194)) { return false; }
  8898. return substr($data, $p+2, 10);
  8899. }
  8900. function _jpgDataFromHeader($hdr) {
  8901. $bpc = ord(substr($hdr, 2, 1));
  8902. if (!$bpc) { $bpc = 8; }
  8903. $h = $this->_twobytes2int(substr($hdr, 3, 2));
  8904. $w = $this->_twobytes2int(substr($hdr, 5, 2));
  8905. $channels = ord(substr($hdr, 7, 1));
  8906. if ($channels==3) { $colspace='DeviceRGB'; }
  8907. elseif($channels==4) { $colspace='DeviceCMYK'; }
  8908. else { $colspace='DeviceGray'; }
  8909. return array($w, $h, $colspace, $bpc);
  8910. }
  8911. function file_get_contents_by_curl($url, &$data) {
  8912. $timeout = 5;
  8913. $ch = curl_init($url);
  8914. curl_setopt($ch, CURLOPT_HEADER, 0);
  8915. curl_setopt($ch, CURLOPT_NOBODY, 0);
  8916. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  8917. curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , $timeout );
  8918. $data = curl_exec($ch);
  8919. curl_close($ch);
  8920. }
  8921. function file_get_contents_by_socket($url, &$data) {
  8922. $timeout = 1;
  8923. $p = parse_url($url);
  8924. $file = $p['path'];
  8925. if ($p['query']) { $file .= '?'.$p['query']; }
  8926. if(!($fh = @fsockopen($p['host'], 80, $errno, $errstr, $timeout))) { return false; }
  8927. $getstring =
  8928. "GET ".$file." HTTP/1.0 \r\n" .
  8929. "Host: ".$p['host']." \r\n" .
  8930. "Connection: close\r\n\r\n";
  8931. fwrite($fh, $getstring);
  8932. // Get rid of HTTP header
  8933. $s = fgets($fh, 1024);
  8934. if (!$s) { return false; }
  8935. $httpheader .= $s;
  8936. while (!feof($fh)) {
  8937. $s = fgets($fh, 1024);
  8938. if ( $s == "\r\n" ) { break; }
  8939. }
  8940. $data = '';
  8941. while (!feof($fh)) {
  8942. $data .= fgets($fh, 1024);
  8943. }
  8944. fclose($fh);
  8945. }
  8946. //==============================================================
  8947. function _imageTypeFromString(&$data) {
  8948. $type = '';
  8949. if (substr($data, 6, 4)== 'JFIF' || substr($data, 6, 4)== 'Exif') {
  8950. $type = 'jpeg';
  8951. }
  8952. else if (substr($data, 0, 6)== "GIF87a" || substr($data, 0, 6)== "GIF89a") {
  8953. $type = 'gif';
  8954. }
  8955. else if (substr($data, 0, 8)== chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  8956. $type = 'png';
  8957. }
  8958. /*-- IMAGES-WMF --*/
  8959. else if (substr($data, 0, 4)== chr(215).chr(205).chr(198).chr(154)) {
  8960. $type = 'wmf';
  8961. }
  8962. /*-- END IMAGES-WMF --*/
  8963. else if (preg_match('/<svg.*<\/svg>/is',$data)) {
  8964. $type = 'svg';
  8965. }
  8966. // BMP images
  8967. else if (substr($data, 0, 2)== "BM") {
  8968. $type = 'bmp';
  8969. }
  8970. return $type;
  8971. }
  8972. //==============================================================
  8973. // Moved outside WMF as also needed for SVG
  8974. function _putformobjects() {
  8975. reset($this->formobjects);
  8976. while(list($file,$info)=each($this->formobjects)) {
  8977. $this->_newobj();
  8978. $this->formobjects[$file]['n']=$this->n;
  8979. $this->_out('<</Type /XObject');
  8980. $this->_out('/Subtype /Form');
  8981. $this->_out('/Group '.($this->n+1).' 0 R');
  8982. $this->_out('/BBox ['.$info['x'].' '.$info['y'].' '.($info['w']+$info['x']).' '.($info['h']+$info['y']).']');
  8983. if ($this->compress)
  8984. $this->_out('/Filter /FlateDecode');
  8985. $data=($this->compress) ? gzcompress($info['data']) : $info['data'];
  8986. $this->_out('/Length '.strlen($data).'>>');
  8987. $this->_putstream($data);
  8988. unset($this->formobjects[$file]['data']);
  8989. $this->_out('endobj');
  8990. // Required for SVG transparency (opacity) to work
  8991. $this->_newobj();
  8992. $this->_out('<</Type /Group');
  8993. $this->_out('/S /Transparency');
  8994. $this->_out('>>');
  8995. $this->_out('endobj');
  8996. }
  8997. }
  8998. function _freadint($f)
  8999. {
  9000. //Read a 4-byte integer from file
  9001. $i=ord(fread($f,1))<<24;
  9002. $i+=ord(fread($f,1))<<16;
  9003. $i+=ord(fread($f,1))<<8;
  9004. $i+=ord(fread($f,1));
  9005. return $i;
  9006. }
  9007. function _UTF16BEtextstring($s) {
  9008. $s = $this->UTF8ToUTF16BE($s, true);
  9009. /*-- ENCRYPTION --*/
  9010. if ($this->encrypted) {
  9011. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9012. }
  9013. /*-- END ENCRYPTION --*/
  9014. return '('. $this->_escape($s).')';
  9015. }
  9016. function _textstring($s) {
  9017. /*-- ENCRYPTION --*/
  9018. if ($this->encrypted) {
  9019. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9020. }
  9021. /*-- END ENCRYPTION --*/
  9022. return '('. $this->_escape($s).')';
  9023. }
  9024. function _escape($s)
  9025. {
  9026. // the chr(13) substitution fixes the Bugs item #1421290.
  9027. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  9028. }
  9029. function _putstream($s) {
  9030. /*-- ENCRYPTION --*/
  9031. if ($this->encrypted) {
  9032. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
  9033. }
  9034. /*-- END ENCRYPTION --*/
  9035. $this->_out('stream');
  9036. $this->_out($s);
  9037. $this->_out('endstream');
  9038. }
  9039. function _out($s,$ln=true) {
  9040. if($this->state==2) {
  9041. if ($this->bufferoutput) {
  9042. $this->headerbuffer.= $s."\n";
  9043. }
  9044. /*-- COLUMNS --*/
  9045. else if (($this->ColActive) && !$this->processingHeader && !$this->processingFooter) {
  9046. // Captures everything in buffer for columns; Almost everything is sent from fn. Cell() except:
  9047. // Images sent from Image() or
  9048. // later sent as _out($textto) in printbuffer
  9049. // Line()
  9050. 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
  9051. $h = ($m[1]/_MPDFK);
  9052. // Update/overwrite the lowest bottom of printing y value for a column
  9053. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h;
  9054. }
  9055. /*-- TABLES --*/
  9056. 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
  9057. $h = ($m[1]/_MPDFK);
  9058. // Update/overwrite the lowest bottom of printing y value for a column
  9059. $this->ColDetails[$this->CurrCol]['bottom_margin'] = max($this->ColDetails[$this->CurrCol]['bottom_margin'],($this->y+$h));
  9060. }
  9061. /*-- END TABLES --*/
  9062. else { // Td Text Set in Cell()
  9063. if (isset($this->ColDetails[$this->CurrCol]['bottom_margin'])) { $h = $this->ColDetails[$this->CurrCol]['bottom_margin'] - $this->y; }
  9064. else { $h = 0; }
  9065. }
  9066. if ($h < 0) { $h = -$h; }
  9067. $this->columnbuffer[] = array(
  9068. 's' => $s, // Text string to output
  9069. 'col' => $this->CurrCol, // Column when printed
  9070. 'x' => $this->x, // x when printed
  9071. 'y' => $this->y, // this->y when printed (after column break)
  9072. 'h' => $h // actual y at bottom when printed = y+h
  9073. );
  9074. }
  9075. /*-- END COLUMNS --*/
  9076. /*-- TABLES --*/
  9077. else if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  9078. // Captures eveything in buffer for rotated tables;
  9079. $this->tablebuffer .= $s . "\n";
  9080. }
  9081. /*-- END TABLES --*/
  9082. else if ($this->kwt && !$this->processingHeader && !$this->processingFooter) {
  9083. // Captures eveything in buffer for keep-with-table (h1-6);
  9084. $this->kwt_buffer[] = array(
  9085. 's' => $s, // Text string to output
  9086. 'x' => $this->x, // x when printed
  9087. 'y' => $this->y, // y when printed
  9088. );
  9089. }
  9090. else if (($this->keep_block_together) && !$this->processingHeader && !$this->processingFooter) {
  9091. if (!isset($this->ktBlock[$this->page]['bottom_margin'])) {
  9092. $this->ktBlock[$this->page]['bottom_margin'] = $this->y;
  9093. }
  9094. // Captures eveything in buffer;
  9095. 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
  9096. $h = ($m[1]/_MPDFK);
  9097. // Update/overwrite the lowest bottom of printing y value for Keep together block
  9098. $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h;
  9099. }
  9100. else { // Td Text Set in Cell()
  9101. if (isset($this->ktBlock[$this->page]['bottom_margin'])) { $h = $this->ktBlock[$this->page]['bottom_margin'] - $this->y; }
  9102. else { $h = 0; }
  9103. }
  9104. if ($h < 0) { $h = -$h; }
  9105. $this->divbuffer[] = array(
  9106. 'page' => $this->page,
  9107. 's' => $s, // Text string to output
  9108. 'x' => $this->x, // x when printed
  9109. 'y' => $this->y, // y when printed (after column break)
  9110. 'h' => $h // actual y at bottom when printed = y+h
  9111. );
  9112. }
  9113. else {
  9114. $this->pages[$this->page] .= $s.($ln == true ? "\n" : '');
  9115. }
  9116. }
  9117. else {
  9118. $this->buffer .= $s.($ln == true ? "\n" : '');
  9119. }
  9120. }
  9121. /*-- WATERMARK --*/
  9122. // add a watermark
  9123. function watermark( $texte, $angle=45, $fontsize=96, $alpha=0.2 ) {
  9124. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9125. if (!$this->watermark_font) { $this->watermark_font = $this->default_font; }
  9126. $this->SetFont( $this->watermark_font, "B", $fontsize, false ); // Don't output
  9127. $texte= $this->purify_utf8_text($texte);
  9128. if ($this->text_input_as_HTML) {
  9129. $texte= $this->all_entities_to_utf8($texte);
  9130. }
  9131. if ($this->usingCoreFont) { $texte = mb_convert_encoding($texte,$this->mb_enc,'UTF-8'); }
  9132. // DIRECTIONALITY
  9133. $this->magic_reverse_dir($texte, true, $this->directionality); // *RTL*
  9134. // Font-specific ligature substitution for Indic fonts
  9135. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($texte); // *INDIC*
  9136. $this->SetAlpha($alpha);
  9137. $this->SetTColor($this->ConvertColor(0));
  9138. $szfont = $fontsize;
  9139. $loop = 0;
  9140. $maxlen = (min($this->w,$this->h) ); // sets max length of text as 7/8 width/height of page
  9141. while ( $loop == 0 )
  9142. {
  9143. $this->SetFont( $this->watermark_font, "B", $szfont, false ); // Don't output
  9144. $offset = ((sin(deg2rad($angle))) * ($szfont/_MPDFK));
  9145. $strlen = $this->GetStringWidth($texte);
  9146. if ( $strlen > $maxlen - $offset )
  9147. $szfont --;
  9148. else
  9149. $loop ++;
  9150. }
  9151. $this->SetFont( $this->watermark_font, "B", $szfont-0.1, true, true); // Output The -0.1 is because SetFont above is not written to PDF
  9152. // Repeating it will not output anything as mPDF thinks it is set
  9153. $adj = ((cos(deg2rad($angle))) * ($strlen/2));
  9154. $opp = ((sin(deg2rad($angle))) * ($strlen/2));
  9155. $wx = ($this->w/2) - $adj + $offset/3;
  9156. $wy = ($this->h/2) + $opp;
  9157. $this->Rotate($angle,$wx,$wy);
  9158. $this->Text($wx,$wy,$texte);
  9159. $this->Rotate(0);
  9160. $this->SetTColor($this->ConvertColor(0));
  9161. $this->SetAlpha(1);
  9162. }
  9163. function watermarkImg( $src, $alpha=0.2 ) {
  9164. if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); }
  9165. if ($this->watermarkImgBehind) { $this->watermarkImgAlpha = $this->SetAlpha($alpha, 'Normal', true); }
  9166. else { $this->SetAlpha($alpha, $this->watermarkImgAlphaBlend); }
  9167. $this->Image($src,0,0,0,0,'','', true, true, true);
  9168. if (!$this->watermarkImgBehind) { $this->SetAlpha(1); }
  9169. }
  9170. /*-- END WATERMARK --*/
  9171. function Rotate($angle,$x=-1,$y=-1)
  9172. {
  9173. if($x==-1)
  9174. $x=$this->x;
  9175. if($y==-1)
  9176. $y=$this->y;
  9177. if($this->angle!=0)
  9178. $this->_out('Q');
  9179. $this->angle=$angle;
  9180. if($angle!=0)
  9181. {
  9182. $angle*=M_PI/180;
  9183. $c=cos($angle);
  9184. $s=sin($angle);
  9185. $cx=$x*_MPDFK;
  9186. $cy=($this->h-$y)*_MPDFK;
  9187. $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));
  9188. }
  9189. }
  9190. function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsize=0, $fontstyle='', $kerning=120, $fontwidth=100, $divider) { // mPDF 5.5.23
  9191. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  9192. if (empty($this->directw)) { $this->directw = new directw($this); }
  9193. $this->directw->CircularText($x, $y, $r, $text, $align, $fontfamily, $fontsize, $fontstyle, $kerning, $fontwidth, $divider); // mPDF 5.5.23
  9194. }
  9195. // From Invoice
  9196. function RoundedRect($x, $y, $w, $h, $r, $style = '')
  9197. {
  9198. $hp = $this->h;
  9199. if($style=='F')
  9200. $op='f';
  9201. elseif($style=='FD' or $style=='DF')
  9202. $op='B';
  9203. else
  9204. $op='S';
  9205. $MyArc = 4/3 * (sqrt(2) - 1);
  9206. $this->_out(sprintf('%.3F %.3F m',($x+$r)*_MPDFK,($hp-$y)*_MPDFK ));
  9207. $xc = $x+$w-$r ;
  9208. $yc = $y+$r;
  9209. $this->_out(sprintf('%.3F %.3F l', $xc*_MPDFK,($hp-$y)*_MPDFK ));
  9210. $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
  9211. $xc = $x+$w-$r ;
  9212. $yc = $y+$h-$r;
  9213. $this->_out(sprintf('%.3F %.3F l',($x+$w)*_MPDFK,($hp-$yc)*_MPDFK));
  9214. $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
  9215. $xc = $x+$r ;
  9216. $yc = $y+$h-$r;
  9217. $this->_out(sprintf('%.3F %.3F l',$xc*_MPDFK,($hp-($y+$h))*_MPDFK));
  9218. $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
  9219. $xc = $x+$r ;
  9220. $yc = $y+$r;
  9221. $this->_out(sprintf('%.3F %.3F l',($x)*_MPDFK,($hp-$yc)*_MPDFK ));
  9222. $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
  9223. $this->_out($op);
  9224. }
  9225. function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
  9226. {
  9227. $h = $this->h;
  9228. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', $x1*_MPDFK, ($h-$y1)*_MPDFK,
  9229. $x2*_MPDFK, ($h-$y2)*_MPDFK, $x3*_MPDFK, ($h-$y3)*_MPDFK));
  9230. }
  9231. //====================================================
  9232. /*-- DIRECTW --*/
  9233. function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 ) {
  9234. // F (shading - no line),S (line, no shading),DF (both)
  9235. if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); }
  9236. if (empty($this->directw)) { $this->directw = new directw($this); }
  9237. $this->directw->Shaded_box( $text,$font,$fontstyle,$szfont,$width,$style,$radius,$fill,$color,$pad);
  9238. }
  9239. /*-- END DIRECTW --*/
  9240. function UTF8StringToArray($str, $addSubset=true) {
  9241. $out = array();
  9242. $len = strlen($str);
  9243. for ($i = 0; $i < $len; $i++) {
  9244. $uni = -1;
  9245. $h = ord($str[$i]);
  9246. if ( $h <= 0x7F )
  9247. $uni = $h;
  9248. elseif ( $h >= 0xC2 ) {
  9249. if ( ($h <= 0xDF) && ($i < $len -1) )
  9250. $uni = ($h & 0x1F) << 6 | (ord($str[++$i]) & 0x3F);
  9251. elseif ( ($h <= 0xEF) && ($i < $len -2) )
  9252. $uni = ($h & 0x0F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  9253. elseif ( ($h <= 0xF4) && ($i < $len -3) )
  9254. $uni = ($h & 0x0F) << 18 | (ord($str[++$i]) & 0x3F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F);
  9255. }
  9256. if ($uni >= 0) {
  9257. $out[] = $uni;
  9258. if ($addSubset && isset($this->CurrentFont['subset'])) {
  9259. $this->CurrentFont['subset'][$uni] = $uni;
  9260. }
  9261. }
  9262. }
  9263. return $out;
  9264. }
  9265. //Convert utf-8 string to <HHHHHH> for Font Subsets
  9266. function UTF8toSubset($str) {
  9267. $ret = '<';
  9268. $str = preg_replace('/'.preg_quote($this->aliasNbPg,'/').'/', chr(7), $str );
  9269. $str = preg_replace('/'.preg_quote($this->aliasNbPgGp,'/').'/', chr(8), $str );
  9270. $unicode = $this->UTF8StringToArray($str);
  9271. $orig_fid = $this->CurrentFont['subsetfontids'][0];
  9272. $last_fid = $this->CurrentFont['subsetfontids'][0];
  9273. foreach($unicode as $c) {
  9274. if ($c == 7 || $c == 8) {
  9275. if ($orig_fid != $last_fid) {
  9276. $ret .= '> Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <';
  9277. $last_fid = $orig_fid;
  9278. }
  9279. if ($c == 7) { $ret .= $this->aliasNbPgHex; }
  9280. else { $ret .= $this->aliasNbPgGpHex; }
  9281. continue;
  9282. }
  9283. for ($i=0; $i<99; $i++) {
  9284. // return c as decimal char
  9285. $init = array_search($c, $this->CurrentFont['subsets'][$i]);
  9286. if ($init!==false) {
  9287. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9288. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9289. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9290. }
  9291. $ret .= sprintf("%02s", strtoupper(dechex($init)));
  9292. break;
  9293. }
  9294. // TrueType embedded SUBSETS
  9295. else if (count($this->CurrentFont['subsets'][$i]) < 255) {
  9296. $n = count($this->CurrentFont['subsets'][$i]);
  9297. $this->CurrentFont['subsets'][$i][$n] = $c;
  9298. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9299. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9300. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9301. }
  9302. $ret .= sprintf("%02s", strtoupper(dechex($n)));
  9303. break;
  9304. }
  9305. else if (!isset($this->CurrentFont['subsets'][($i+1)])) {
  9306. // TrueType embedded SUBSETS
  9307. $this->CurrentFont['subsets'][($i+1)] = array(0=>0);
  9308. $new_fid = count($this->fonts)+$this->extraFontSubsets+1;
  9309. $this->CurrentFont['subsetfontids'][($i+1)] = $new_fid;
  9310. $this->extraFontSubsets++;
  9311. }
  9312. }
  9313. }
  9314. $ret .= '>';
  9315. if ($last_fid != $orig_fid) {
  9316. $ret .= ' Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <> ';
  9317. }
  9318. return $ret;
  9319. }
  9320. // Converts UTF-8 strings to UTF16-BE.
  9321. function UTF8ToUTF16BE($str, $setbom=true) {
  9322. if ($this->checkSIP && preg_match("/([\x{20000}-\x{2FFFF}])/u", $str)) {
  9323. if (!in_array($this->currentfontfamily, array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI',
  9324. 'gbBI','big5BI','sjisBI','uhcBI'))) {
  9325. $str = preg_replace("/[\x{20000}-\x{2FFFF}]/u", chr(0), $str);
  9326. }
  9327. }
  9328. if ($this->checkSMP && preg_match("/([\x{10000}-\x{1FFFF}])/u", $str )) {
  9329. $str = preg_replace("/[\x{10000}-\x{1FFFF}]/u", chr(0), $str );
  9330. }
  9331. $outstr = ""; // string to be returned
  9332. if ($setbom) {
  9333. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  9334. }
  9335. $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8');
  9336. return $outstr;
  9337. }
  9338. // ====================================================
  9339. // ====================================================
  9340. /*-- CJK-FONTS --*/
  9341. // from class PDF_Chinese CJK EXTENSIONS
  9342. function AddCIDFont($family,$style,$name,&$cw,$CMap,$registry,$desc)
  9343. {
  9344. $fontkey=strtolower($family).strtoupper($style);
  9345. if(isset($this->fonts[$fontkey]))
  9346. $this->Error("Font already added: $family $style");
  9347. $i=count($this->fonts)+$this->extraFontSubsets+1;
  9348. $name=str_replace(' ','',$name);
  9349. if ($family == 'sjis') { $up = -120; } else { $up = -130; }
  9350. // ? 'up' and 'ut' do not seem to be referenced anywhere
  9351. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>$up,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry,'MissingWidth'=>1000,'desc'=>$desc);
  9352. }
  9353. function AddCJKFont($family) {
  9354. if ($this->PDFA || $this->PDFX) {
  9355. $this->Error("Adobe CJK fonts cannot be embedded in mPDF (required for PDFA1-b and PDFX/1-a).");
  9356. }
  9357. if ($family == 'big5') { $this->AddBig5Font(); }
  9358. else if ($family == 'gb') { $this->AddGBFont(); }
  9359. else if ($family == 'sjis') { $this->AddSJISFont(); }
  9360. else if ($family == 'uhc') { $this->AddUHCFont(); }
  9361. }
  9362. function AddBig5Font()
  9363. {
  9364. //Add Big5 font with proportional Latin
  9365. $family='big5';
  9366. $name='MSungStd-Light-Acro';
  9367. $cw=$this->Big5_widths;
  9368. $CMap='UniCNS-UTF16-H';
  9369. $registry=array('ordering'=>'CNS1','supplement'=>4);
  9370. $desc = array(
  9371. 'Ascent' => 880,
  9372. 'Descent' => -120,
  9373. 'CapHeight' => 880,
  9374. 'Flags' => 6,
  9375. 'FontBBox' => '[-160 -249 1015 1071]',
  9376. 'ItalicAngle' => 0,
  9377. 'StemV' => 93,
  9378. );
  9379. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9380. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9381. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9382. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9383. }
  9384. function AddGBFont()
  9385. {
  9386. //Add GB font with proportional Latin
  9387. $family='gb';
  9388. $name='STSongStd-Light-Acro';
  9389. $cw=$this->GB_widths;
  9390. $CMap='UniGB-UTF16-H';
  9391. $registry=array('ordering'=>'GB1','supplement'=>4);
  9392. $desc = array(
  9393. 'Ascent' => 752,
  9394. 'Descent' => -271,
  9395. 'CapHeight' => 737,
  9396. 'Flags' => 6,
  9397. 'FontBBox' => '[-25 -254 1000 880]',
  9398. 'ItalicAngle' => 0,
  9399. 'StemV' => 58,
  9400. 'Style' => '<< /Panose <000000000400000000000000> >>',
  9401. );
  9402. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9403. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9404. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9405. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9406. }
  9407. function AddSJISFont()
  9408. {
  9409. //Add SJIS font with proportional Latin
  9410. $family='sjis';
  9411. $name='KozMinPro-Regular-Acro';
  9412. $cw=$this->SJIS_widths;
  9413. $CMap='UniJIS-UTF16-H';
  9414. $registry=array('ordering'=>'Japan1','supplement'=>5);
  9415. $desc = array(
  9416. 'Ascent' => 880,
  9417. 'Descent' => -120,
  9418. 'CapHeight' => 740,
  9419. 'Flags' => 6,
  9420. 'FontBBox' => '[-195 -272 1110 1075]',
  9421. 'ItalicAngle' => 0,
  9422. 'StemV' => 86,
  9423. 'XHeight' => 502,
  9424. );
  9425. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9426. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9427. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9428. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9429. }
  9430. function AddUHCFont()
  9431. {
  9432. //Add UHC font with proportional Latin
  9433. $family='uhc';
  9434. $name='HYSMyeongJoStd-Medium-Acro';
  9435. $cw=$this->UHC_widths;
  9436. $CMap='UniKS-UTF16-H';
  9437. $registry=array('ordering'=>'Korea1','supplement'=>2);
  9438. $desc = array(
  9439. 'Ascent' => 880,
  9440. 'Descent' => -120,
  9441. 'CapHeight' => 720,
  9442. 'Flags' => 6,
  9443. 'FontBBox' => '[-28 -148 1001 880]',
  9444. 'ItalicAngle' => 0,
  9445. 'StemV' => 60,
  9446. 'Style' => '<< /Panose <000000000600000000000000> >>',
  9447. );
  9448. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9449. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9450. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9451. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9452. }
  9453. /*-- END CJK-FONTS --*/
  9454. //////////////////////////////////////////////////////////////////////////////
  9455. //////////////////////////////////////////////////////////////////////////////
  9456. //////////////////////////////////////////////////////////////////////////////
  9457. //////////////////////////////////////////////////////////////////////////////
  9458. //////////////////////////////////////////////////////////////////////////////
  9459. //////////////////////////////////////////////////////////////////////////////
  9460. //////////////////////////////////////////////////////////////////////////////
  9461. function SetAutoFont($af = AUTOFONT_ALL) {
  9462. if ($this->onlyCoreFonts) { return false; }
  9463. if (!$af && $af !== 0) { $af = AUTOFONT_ALL; }
  9464. $this->autoFontGroups = $af;
  9465. if ($this->autoFontGroups ) {
  9466. $this->useLang = true;
  9467. }
  9468. }
  9469. function SetDefaultFont($font) {
  9470. // Disallow embedded fonts to be used as defaults in PDFA
  9471. if ($this->PDFA || $this->PDFX) {
  9472. if (strtolower($font) == 'ctimes') { $font = 'serif'; }
  9473. if (strtolower($font) == 'ccourier') { $font = 'monospace'; }
  9474. if (strtolower($font) == 'chelvetica') { $font = 'sans-serif'; }
  9475. }
  9476. $font = $this->SetFont($font); // returns substituted font if necessary
  9477. $this->default_font = $font;
  9478. $this->original_default_font = $font;
  9479. if (!$this->watermark_font ) { $this->watermark_font = $font; } // *WATERMARK*
  9480. $this->defaultCSS['BODY']['FONT-FAMILY'] = $font;
  9481. $this->CSS['BODY']['FONT-FAMILY'] = $font;
  9482. }
  9483. function SetDefaultFontSize($fontsize) {
  9484. $this->default_font_size = $fontsize;
  9485. $this->original_default_font_size = $fontsize;
  9486. $this->SetFontSize($fontsize);
  9487. $this->defaultCSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  9488. $this->CSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  9489. }
  9490. function SetDefaultBodyCSS($prop, $val) {
  9491. if ($prop) {
  9492. $this->defaultCSS['BODY'][strtoupper($prop)] = $val;
  9493. $this->CSS['BODY'][strtoupper($prop)] = $val;
  9494. }
  9495. }
  9496. function SetDirectionality($dir='ltr') {
  9497. /*-- RTL --*/
  9498. if (strtolower($dir) == 'rtl') {
  9499. if ($this->directionality != 'rtl') {
  9500. // Swop L/R Margins so page 1 RTL is an 'even' page
  9501. $tmp = $this->DeflMargin;
  9502. $this->DeflMargin = $this->DefrMargin;
  9503. $this->DefrMargin = $tmp;
  9504. $this->orig_lMargin = $this->DeflMargin;
  9505. $this->orig_rMargin = $this->DefrMargin;
  9506. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$this->tMargin);
  9507. }
  9508. $this->directionality = 'rtl';
  9509. $this->defaultAlign = 'R';
  9510. $this->defaultTableAlign = 'R';
  9511. }
  9512. else {
  9513. /*-- END RTL --*/
  9514. $this->directionality = 'ltr';
  9515. $this->defaultAlign = 'L';
  9516. $this->defaultTableAlign = 'L';
  9517. } // *RTL*
  9518. $this->CSS['BODY']['DIRECTION'] = $this->directionality;
  9519. }
  9520. // Added to set line-height-correction
  9521. function SetLineHeightCorrection($val) {
  9522. if ($val > 0) { $this->default_lineheight_correction = $val; }
  9523. else { $this->default_lineheight_correction = 1.2; }
  9524. }
  9525. // Set a (fixed) lineheight to an actual value - either to named fontsize(pts) or default
  9526. function SetLineHeight($FontPt='',$spacing = '') {
  9527. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9528. else { $k = 1; }
  9529. if ($spacing > 0) {
  9530. if (preg_match('/mm/',$spacing)) {
  9531. $this->lineheight = ($spacing + 0.0) / $k; // convert to number
  9532. }
  9533. else {
  9534. if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$spacing); }
  9535. else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$spacing); }
  9536. }
  9537. }
  9538. else {
  9539. if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$this->normalLineheight); }
  9540. else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$this->normalLineheight); }
  9541. }
  9542. }
  9543. function _computeLineheight($lh, $fs='') {
  9544. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9545. else { $k = 1; }
  9546. if (!$fs) { $fs = $this->FontSize; }
  9547. if (preg_match('/mm/',$lh)) {
  9548. return (($lh + 0.0) / $k); // convert to number
  9549. }
  9550. else if ($lh > 0) {
  9551. return ($fs * $lh);
  9552. }
  9553. else if (isset($this->normalLineheight)) { return ($fs * $this->normalLineheight); }
  9554. else return ($fs * $this->default_lineheight_correction);
  9555. }
  9556. function SetBasePath($str='') {
  9557. if ( isset($_SERVER['HTTP_HOST']) ) { $host = $_SERVER['HTTP_HOST']; }
  9558. else if ( isset($_SERVER['SERVER_NAME']) ) { $host = $_SERVER['SERVER_NAME']; }
  9559. else { $host = ''; }
  9560. if (!$str) {
  9561. if ($_SERVER['SCRIPT_NAME']) { $currentPath = dirname($_SERVER['SCRIPT_NAME']); }
  9562. else { $currentPath = dirname($_SERVER['PHP_SELF']); }
  9563. $currentPath = str_replace("\\","/",$currentPath);
  9564. if ($currentPath == '/') { $currentPath = ''; }
  9565. if ($host) { $currpath = 'http://' . $host . $currentPath .'/'; }
  9566. else { $currpath = ''; }
  9567. $this->basepath = $currpath;
  9568. $this->basepathIsLocal = true;
  9569. return;
  9570. }
  9571. $str = preg_replace('/\?.*/','',$str);
  9572. if (!preg_match('/(http|https|ftp):\/\/.*\//i',$str)) { $str .= '/'; }
  9573. $str .= 'xxx'; // in case $str ends in / e.g. http://www.bbc.co.uk/
  9574. $this->basepath = dirname($str) . "/"; // returns e.g. e.g. http://www.google.com/dir1/dir2/dir3/
  9575. $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
  9576. $tr = parse_url($this->basepath);
  9577. if (isset($tr['host']) && ($tr['host'] == $host)) { $this->basepathIsLocal = true; }
  9578. else { $this->basepathIsLocal = false; }
  9579. }
  9580. function GetFullPath(&$path,$basepath='') {
  9581. // When parsing CSS need to pass temporary basepath - so links are relative to current stylesheet
  9582. if (!$basepath) { $basepath = $this->basepath; }
  9583. //Fix path value
  9584. $path = str_replace("\\","/",$path); //If on Windows
  9585. //Get link info and obtain its absolute path
  9586. $regexp = '|^./|'; // Inadvertently corrects "./path/etc" and "//www.domain.com/etc"
  9587. $path = preg_replace($regexp,'',$path);
  9588. if(substr($path,0,1) == '#') { return; }
  9589. if (stristr($path,"mailto:") !== false) { return; }
  9590. if (strpos($path,"../") !== false ) { //It is a Relative Link
  9591. $backtrackamount = substr_count($path,"../");
  9592. $maxbacktrack = substr_count($basepath,"/") - 1;
  9593. $filepath = str_replace("../",'',$path);
  9594. $path = $basepath;
  9595. //If it is an invalid relative link, then make it go to directory root
  9596. if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
  9597. //Backtrack some directories
  9598. for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
  9599. $path = $path . "/" . $filepath; //Make it an absolute path
  9600. }
  9601. else if( strpos($path,":/") === false || strpos($path,":/") > 10) { //It is a Local Link
  9602. if (substr($path,0,1) == "/") {
  9603. $tr = parse_url($basepath);
  9604. $root = $tr['scheme'].'://'.$tr['host'];
  9605. $path = $root . $path;
  9606. }
  9607. else { $path = $basepath . $path; }
  9608. }
  9609. //Do nothing if it is an Absolute Link
  9610. }
  9611. // Used for external CSS files
  9612. function _get_file($path) {
  9613. // If local file try using local path (? quicker, but also allowed even if allow_url_fopen false)
  9614. $contents = '';
  9615. $contents = @file_get_contents($path);
  9616. if ($contents) { return $contents; }
  9617. if ($this->basepathIsLocal) {
  9618. $tr = parse_url($path);
  9619. $lp=getenv("SCRIPT_NAME");
  9620. $ap=realpath($lp);
  9621. $ap=str_replace("\\","/",$ap);
  9622. $docroot=substr($ap,0,strpos($ap,$lp));
  9623. // WriteHTML parses all paths to full URLs; may be local file name
  9624. if ($tr['scheme'] && $tr['host'] && $_SERVER["DOCUMENT_ROOT"] ) {
  9625. $localpath = $_SERVER["DOCUMENT_ROOT"] . $tr['path'];
  9626. }
  9627. // DOCUMENT_ROOT is not returned on IIS
  9628. else if ($docroot) {
  9629. $localpath = $docroot . $tr['path'];
  9630. }
  9631. else { $localpath = $path; }
  9632. $contents = @file_get_contents($localpath);
  9633. }
  9634. // if not use full URL
  9635. else if (!$contents && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  9636. $ch = curl_init($path);
  9637. curl_setopt($ch, CURLOPT_HEADER, 0);
  9638. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  9639. $contents = curl_exec($ch);
  9640. curl_close($ch);
  9641. }
  9642. return $contents;
  9643. }
  9644. function docPageNum($num = 0, $extras = false) {
  9645. if ($num < 1) { $num = $this->page; }
  9646. $type = '1'; // set default decimal
  9647. $ppgno = $num;
  9648. $suppress = 0;
  9649. $offset = 0;
  9650. $lastreset = 0;
  9651. foreach($this->PageNumSubstitutions AS $psarr) {
  9652. if ($num >= $psarr['from']) {
  9653. if ($psarr['reset']) {
  9654. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9655. $ppgno = $num - $psarr['from'] + 1 + $offset;
  9656. $lastreset = $psarr['from'];
  9657. }
  9658. if ($psarr['type']) { $type = $psarr['type']; }
  9659. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9660. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9661. }
  9662. }
  9663. if ($suppress) { return ''; }
  9664. foreach($this->pgsIns AS $k=>$v) {
  9665. if ($k>$lastreset && $k<$num) {
  9666. $ppgno -= $v;
  9667. }
  9668. }
  9669. if ($type=='A') { $ppgno = $this->dec2alpha($ppgno,true); }
  9670. else if ($type=='a') { $ppgno = $this->dec2alpha($ppgno,false);}
  9671. else if ($type=='I') { $ppgno = $this->dec2roman($ppgno,true); }
  9672. else if ($type=='i') { $ppgno = $this->dec2roman($ppgno,false); }
  9673. if ($extras) { $ppgno = $this->pagenumPrefix . $ppgno . $this->pagenumSuffix; }
  9674. return $ppgno;
  9675. }
  9676. function docPageSettings($num = 0) {
  9677. // Returns current type (numberstyle), suppression state for this page number;
  9678. // reset is only returned if set for this page number
  9679. if ($num < 1) { $num = $this->page; }
  9680. $type = '1'; // set default decimal
  9681. $ppgno = $num;
  9682. $suppress = 0;
  9683. $offset = 0;
  9684. $reset = '';
  9685. foreach($this->PageNumSubstitutions AS $psarr) {
  9686. if ($num >= $psarr['from']) {
  9687. if ($psarr['reset']) {
  9688. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9689. $ppgno = $num - $psarr['from'] + 1 + $offset;
  9690. }
  9691. if ($psarr['type']) { $type = $psarr['type']; }
  9692. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9693. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9694. }
  9695. if ($num == $psarr['from']) { $reset = $psarr['reset']; }
  9696. }
  9697. if ($suppress) { $suppress = 'on'; }
  9698. else { $suppress = 'off'; }
  9699. return array($type, $suppress, $reset);
  9700. }
  9701. function docPageNumTotal($num = 0, $extras = false) {
  9702. if ($num < 1) { $num = $this->page; }
  9703. $type = '1'; // set default decimal
  9704. $ppgstart = 1;
  9705. $ppgend = count($this->pages)+1;
  9706. $suppress = 0;
  9707. $offset = 0;
  9708. foreach($this->PageNumSubstitutions AS $psarr) {
  9709. if ($num >= $psarr['from']) {
  9710. if ($psarr['reset']) {
  9711. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9712. $ppgstart = $psarr['from'] + $offset;
  9713. $ppgend = count($this->pages)+1 + $offset;
  9714. }
  9715. if ($psarr['type']) { $type = $psarr['type']; }
  9716. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9717. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9718. }
  9719. if ($num < $psarr['from']) {
  9720. if ($psarr['reset']) {
  9721. $ppgend = $psarr['from'] + $offset;
  9722. break;
  9723. }
  9724. }
  9725. }
  9726. if ($suppress) { return ''; }
  9727. $ppgno = $ppgend-$ppgstart+$offset;
  9728. if ($extras) { $ppgno = $this->nbpgPrefix . $ppgno . $this->nbpgSuffix; }
  9729. return $ppgno;
  9730. }
  9731. function RestartDocTemplate() {
  9732. $this->docTemplateStart = $this->page;
  9733. }
  9734. //Page header
  9735. function Header($content='') {
  9736. $this->cMarginL = 0;
  9737. $this->cMarginR = 0;
  9738. /*-- HTMLHEADERS-FOOTERS --*/
  9739. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLHeaderE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLHeader) || (!$this->mirrorMargins && $this->HTMLHeader)) {
  9740. $this->writeHTMLHeaders();
  9741. return;
  9742. }
  9743. /*-- END HTMLHEADERS-FOOTERS --*/
  9744. $this->processingHeader=true;
  9745. $h = $this->headerDetails;
  9746. if(count($h)) {
  9747. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  9748. $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK)));
  9749. $yadj = $this->w - $this->h;
  9750. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  9751. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  9752. $headerlmargin = $this->orig_rMargin;
  9753. }
  9754. else {
  9755. $headerlmargin = $this->orig_lMargin;
  9756. }
  9757. }
  9758. else {
  9759. $yadj = 0;
  9760. $headerpgwidth = $this->pgwidth;
  9761. $headerlmargin = $this->lMargin;
  9762. }
  9763. $this->y = $this->margin_header - $yadj ;
  9764. $this->SetTColor($this->ConvertColor(0));
  9765. $this->SUP = false;
  9766. $this->SUB = false;
  9767. $this->bullet = false;
  9768. // only show pagenumber if numbering on
  9769. $pgno = $this->docPageNum($this->page, true);
  9770. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  9771. $side = 'even';
  9772. }
  9773. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  9774. $side = 'odd';
  9775. }
  9776. $maxfontheight = 0;
  9777. foreach(array('L','C','R') AS $pos) {
  9778. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  9779. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  9780. else { $hfsz = $this->default_font_size; }
  9781. $maxfontheight = max($maxfontheight,$hfsz);
  9782. }
  9783. }
  9784. // LEFT-CENTER-RIGHT
  9785. foreach(array('L','C','R') AS $pos) {
  9786. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  9787. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  9788. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  9789. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  9790. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  9791. else { $hff = $this->original_default_font; }
  9792. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  9793. else { $hfsz = $this->original_default_font_size; } // pts
  9794. $maxfontheight = max($maxfontheight,$hfsz);
  9795. $hfst = '';
  9796. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) {
  9797. $hfst = $h[$side][$pos]['font-style'];
  9798. }
  9799. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  9800. $hfcol = $h[$side][$pos]['color'];
  9801. $cor = $this->ConvertColor($hfcol);
  9802. if ($cor) { $this->SetTColor($cor); }
  9803. }
  9804. else { $hfcol = ''; }
  9805. $this->SetFont($hff,$hfst,$hfsz,true,true);
  9806. $this->x = $headerlmargin ;
  9807. $this->y = $this->margin_header - $yadj ;
  9808. $hd = $this->purify_utf8_text($hd);
  9809. if ($this->text_input_as_HTML) {
  9810. $hd = $this->all_entities_to_utf8($hd);
  9811. }
  9812. // CONVERT CODEPAGE
  9813. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  9814. // DIRECTIONALITY RTL
  9815. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  9816. // Font-specific ligature substitution for Indic fonts
  9817. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  9818. $align = $pos;
  9819. /*-- RTL --*/
  9820. if ($this->directionality == 'rtl') {
  9821. if ($pos == 'L') { $align = 'R'; }
  9822. else if ($pos == 'R') { $align = 'L'; }
  9823. }
  9824. /*-- END RTL --*/
  9825. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  9826. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  9827. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  9828. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  9829. $this->_out('Q');
  9830. }
  9831. else {
  9832. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  9833. }
  9834. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); }
  9835. }
  9836. }
  9837. //Return Font to normal
  9838. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  9839. // LINE
  9840. if (isset($h[$side]['line']) && $h[$side]['line']) {
  9841. $this->SetLineWidth(0.1);
  9842. $this->SetDColor($this->ConvertColor(0));
  9843. $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 );
  9844. }
  9845. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  9846. $this->_out('Q');
  9847. }
  9848. }
  9849. $this->SetY($this->tMargin);
  9850. if ($this->ColActive) { $this->pgwidth = $this->ColWidth; } // *COLUMNS*
  9851. $this->processingHeader=false;
  9852. }
  9853. /*-- TABLES --*/
  9854. function TableHeaderFooter($content='',$tablestartpage='',$tablestartcolumn ='',$horf = 'H',$level, $firstSpread=true, $finalSpread=true) {
  9855. if(($horf=='H' || $horf=='F') && !empty($content)) {
  9856. $table = &$this->table[1][1];
  9857. // Advance down page by half width of top border
  9858. if ($horf=='H') { // Only if header
  9859. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  9860. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  9861. if ($adv) {
  9862. if ($this->table_rotate) {
  9863. $this->y += ($adv);
  9864. }
  9865. else {
  9866. $this->DivLn($adv,$this->blklvl,true);
  9867. }
  9868. }
  9869. }
  9870. if ($horf=='F') { // Table Footer
  9871. $firstrow = count($table['cells']) - $table['footernrows'];
  9872. $lastrow = count($table['cells']) - 1;
  9873. }
  9874. else { // Table Header
  9875. $firstrow = 0;
  9876. $lastrow = $table['headernrows'] - 1;
  9877. }
  9878. $topy = $content[$firstrow][0]['y']-$this->y;
  9879. for ($i=$firstrow ; $i<=$lastrow; $i++) {
  9880. $y = $this->y;
  9881. /*-- COLUMNS --*/
  9882. // If outside columns, this is done in PaintDivBB
  9883. if ($this->ColActive) {
  9884. //OUTER FILL BGCOLOR of DIVS
  9885. if ($this->blklvl > 0) {
  9886. $firstblockfill = $this->GetFirstBlockFill();
  9887. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  9888. $divh = $content[$i][0]['h'];
  9889. $bak_x = $this->x;
  9890. $this->DivLn($divh,-3,false);
  9891. // Reset current block fill
  9892. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  9893. $this->SetFColor($bcor);
  9894. $this->x = $bak_x;
  9895. }
  9896. }
  9897. }
  9898. /*-- END COLUMNS --*/
  9899. $colctr = 0;
  9900. foreach($content[$i] as $tablehf) {
  9901. $colctr++;
  9902. $y = $tablehf['y'] - $topy;
  9903. $this->y = $y;
  9904. //Set some cell values
  9905. $x = $tablehf['x'];
  9906. if (($this->mirrorMargins) && ($tablestartpage == 'ODD') && (($this->page)%2==0)) { // EVEN
  9907. $x = $x +$this->MarginCorrection;
  9908. }
  9909. else if (($this->mirrorMargins) && ($tablestartpage == 'EVEN') && (($this->page)%2==1)) { // ODD
  9910. $x = $x +$this->MarginCorrection;
  9911. }
  9912. /*-- COLUMNS --*/
  9913. // Added to correct for Columns
  9914. if ($this->ColActive) {
  9915. if ($this->directionality == 'rtl') { // *RTL*
  9916. $x -= ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  9917. } // *RTL*
  9918. else { // *RTL*
  9919. $x += ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap);
  9920. } // *RTL*
  9921. }
  9922. /*-- END COLUMNS --*/
  9923. if ($colctr==1) { $x0 = $x; }
  9924. // mPDF ITERATION
  9925. if ($this->iterationCounter) {
  9926. foreach($tablehf['textbuffer'] AS $k=>$t) {
  9927. if (!is_array($t[0]) && preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t[0], $m)) { // mPDF 5.5.06
  9928. $vname = '__'.$m[1].'_';
  9929. if (!isset($this->$vname)) { $this->$vname = 1; }
  9930. else { $this->$vname++; }
  9931. $tablehf['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $tablehf['textbuffer'][$k][0]);
  9932. }
  9933. }
  9934. }
  9935. $w = $tablehf['w'];
  9936. $h = $tablehf['h'];
  9937. $va = $tablehf['va'];
  9938. $R = $tablehf['R'];
  9939. $mih = $tablehf['mih'];
  9940. $border = $tablehf['border'];
  9941. $border_details = $tablehf['border_details'];
  9942. $padding = $tablehf['padding'];
  9943. $this->tabletheadjustfinished = true;
  9944. $textbuffer = $tablehf['textbuffer'];
  9945. $align = $tablehf['a'];
  9946. //Align
  9947. $this->divalign=$align;
  9948. $this->x = $x;
  9949. if ($this->ColActive) {
  9950. if ($table['borders_separate']) {
  9951. $tablefill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  9952. if ($tablefill) {
  9953. $color = $this->ConvertColor($tablefill);
  9954. if ($color) {
  9955. $xadj = ($table['border_spacing_H']/2);
  9956. $yadj = ($table['border_spacing_V']/2);
  9957. $wadj = $table['border_spacing_H'];
  9958. $hadj = $table['border_spacing_V'];
  9959. if ($i == $firstrow && $horf=='H') { // Top
  9960. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  9961. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  9962. }
  9963. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom
  9964. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  9965. }
  9966. if ($colctr == 1) { // Left
  9967. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  9968. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  9969. }
  9970. if ($colctr == count($content[$i]) ) { // Right
  9971. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  9972. }
  9973. $this->SetFColor($color);
  9974. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  9975. }
  9976. }
  9977. }
  9978. }
  9979. if ($table['empty_cells']!='hide' || !empty($textbuffer) || !$table['borders_separate']) { $paintcell = true; }
  9980. else { $paintcell = false; }
  9981. //Vertical align
  9982. if ($R && INTVAL($R) > 0 && isset($va) && $va!='B') { $va='B';}
  9983. if (!isset($va) || empty($va) || $va=='M') $this->y += ($h-$mih)/2;
  9984. elseif (isset($va) && $va=='B') $this->y += $h-$mih;
  9985. //TABLE ROW OR CELL FILL BGCOLOR
  9986. $fill = 0;
  9987. if (isset($tablehf['bgcolor']) && $tablehf['bgcolor'] && $tablehf['bgcolor']!='transparent') {
  9988. $fill = $tablehf['bgcolor'];
  9989. $leveladj = 6;
  9990. }
  9991. else if (isset($content[$i][0]['trbgcolor']) && $content[$i][0]['trbgcolor'] && $content[$i][0]['trbgcolor']!='transparent') { // Row color
  9992. $fill = $content[$i][0]['trbgcolor'];
  9993. $leveladj = 3;
  9994. }
  9995. if ($fill && $paintcell) {
  9996. $color = $this->ConvertColor($fill);
  9997. if ($color) {
  9998. if ($table['borders_separate']) {
  9999. if ($this->ColActive) {
  10000. $this->SetFColor($color);
  10001. $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');
  10002. }
  10003. else {
  10004. $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);
  10005. }
  10006. }
  10007. else {
  10008. if ($this->ColActive) {
  10009. $this->SetFColor($color);
  10010. $this->Rect($x, $y, $w, $h, 'F');
  10011. }
  10012. else {
  10013. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  10014. }
  10015. }
  10016. }
  10017. }
  10018. /*-- BACKGROUNDS --*/
  10019. if (isset($tablehf['gradient']) && $tablehf['gradient'] && $paintcell){
  10020. $g = $this->grad->parseBackgroundGradient($tablehf['gradient']);
  10021. if ($g) {
  10022. if ($table['borders_separate']) {
  10023. $px = $x+ ($table['border_spacing_H']/2);
  10024. $py = $y+ ($table['border_spacing_V']/2);
  10025. $pw = $w- $table['border_spacing_H'];
  10026. $ph = $h- $table['border_spacing_V'];
  10027. }
  10028. else {
  10029. $px = $x;
  10030. $py = $y;
  10031. $pw = $w;
  10032. $ph = $h;
  10033. }
  10034. if ($this->ColActive) {
  10035. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10036. }
  10037. else {
  10038. $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'=>'');
  10039. }
  10040. }
  10041. }
  10042. if (isset($tablehf['background-image']) && $paintcell){
  10043. if ($tablehf['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $tablehf['background-image']['gradient'] )) {
  10044. $g = $this->grad->parseMozGradient( $tablehf['background-image']['gradient'] );
  10045. if ($g) {
  10046. if ($table['borders_separate']) {
  10047. $px = $x+ ($table['border_spacing_H']/2);
  10048. $py = $y+ ($table['border_spacing_V']/2);
  10049. $pw = $w- $table['border_spacing_H'];
  10050. $ph = $h- $table['border_spacing_V'];
  10051. }
  10052. else {
  10053. $px = $x;
  10054. $py = $y;
  10055. $pw = $w;
  10056. $ph = $h;
  10057. }
  10058. if ($this->ColActive) {
  10059. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  10060. }
  10061. else {
  10062. $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'=>'');
  10063. }
  10064. }
  10065. }
  10066. else if ($tablehf['background-image']['image_id']) { // Background pattern
  10067. $n = count($this->patterns)+1;
  10068. if ($table['borders_separate']) {
  10069. $px = $x+ ($table['border_spacing_H']/2);
  10070. $py = $y+ ($table['border_spacing_V']/2);
  10071. $pw = $w- $table['border_spacing_H'];
  10072. $ph = $h- $table['border_spacing_V'];
  10073. }
  10074. else {
  10075. $px = $x;
  10076. $py = $y;
  10077. $pw = $w;
  10078. $ph = $h;
  10079. }
  10080. if ($this->ColActive) {
  10081. 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']);
  10082. $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']);
  10083. if ($tablehf['background-image']['opacity']>0 && $tablehf['background-image']['opacity']<1) { $opac = $this->SetAlpha($tablehf['background-image']['opacity'],'Normal',true); }
  10084. else { $opac = ''; }
  10085. $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));
  10086. }
  10087. else {
  10088. $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']);
  10089. }
  10090. }
  10091. }
  10092. /*-- END BACKGROUNDS --*/
  10093. //Cell Border
  10094. if ($table['borders_separate'] && $paintcell && $border) {
  10095. $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']);
  10096. }
  10097. else if ($paintcell && $border) {
  10098. $this->_tableRect($x, $y, $w, $h, $border, $border_details, true, $table['borders_separate']); // true causes buffer
  10099. }
  10100. //Print cell content
  10101. //$this->divheight = $this->table_lineheight*$this->lineheight;
  10102. if (!empty($textbuffer)) {
  10103. if ($horf=='F' && preg_match('/{colsum([0-9]*)[_]*}/', $textbuffer[0][0], $m)) {
  10104. $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$colctr-1]);
  10105. $textbuffer[0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$textbuffer[0][0]);
  10106. }
  10107. if ($R) {
  10108. $cellPtSize = $textbuffer[0][11] / $this->shrin_k;
  10109. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  10110. $cellFontHeight = ($cellPtSize/_MPDFK);
  10111. $opx = $this->x;
  10112. $opy = $this->y;
  10113. $angle = INTVAL($R);
  10114. // Only allow 45 - 90 degrees (when bottom-aligned) or -90
  10115. if ($angle > 90) { $angle = 90; }
  10116. else if ($angle > 0 && (isset($va) && $va!='B')) { $angle = 90; }
  10117. else if ($angle > 0 && $angle <45) { $angle = 45; }
  10118. else if ($angle < 0) { $angle = -90; }
  10119. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  10120. if (isset($align) && $align =='R') {
  10121. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($padding['R'] + $border_details['R']['w']);
  10122. }
  10123. else if (!isset($align ) || $align =='C') {
  10124. $this->x += ($w/2) + ($offset);
  10125. }
  10126. else {
  10127. $this->x += ($offset) + ($cellFontHeight/3)+($padding['L'] + $border_details['L']['w']);
  10128. }
  10129. $str = '';
  10130. foreach($tablehf['textbuffer'] AS $t) { $str .= $t[0].' '; }
  10131. $str = trim($str);
  10132. if (!isset($va) || $va=='M') {
  10133. $this->y -= ($h-$mih)/2; //Undo what was added earlier VERTICAL ALIGN
  10134. 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'])); }
  10135. else if ($angle < 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']); }
  10136. }
  10137. else if (isset($va) && $va=='B') {
  10138. $this->y -= $h-$mih; //Undo what was added earlier VERTICAL ALIGN
  10139. if ($angle > 0) { $this->y += $h-($border_details['B']['w']+$padding['B']); }
  10140. else if ($angle < 0) { $this->y += $h-$mih+($padding['T'] + $border_details['T']['w']); }
  10141. }
  10142. else if (isset($va) && $va=='T') {
  10143. if ($angle > 0) { $this->y += $mih-($border_details['B']['w']+$padding['B']); }
  10144. else if ($angle < 0) { $this->y += ($padding['T'] + $border_details['T']['w']); }
  10145. }
  10146. $this->Rotate($angle,$this->x,$this->y);
  10147. $s_fs = $this->FontSizePt;
  10148. $s_f = $this->FontFamily;
  10149. $s_st = $this->FontStyle;
  10150. if (!empty($textbuffer[0][3])) { //Font Color
  10151. $cor = $textbuffer[0][3];
  10152. $this->SetTColor($cor);
  10153. }
  10154. $s_str = $this->strike;
  10155. $this->strike = $textbuffer[0][8]; //Strikethrough
  10156. $this->SetFont($textbuffer[0][4],$textbuffer[0][2],$cellPtSize,true,true);
  10157. $this->Text($this->x,$this->y,$str);
  10158. $this->Rotate(0);
  10159. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  10160. $this->SetTColor(0);
  10161. $this->strike = $s_str;
  10162. $this->x = $opx;
  10163. $this->y = $opy;
  10164. }
  10165. else {
  10166. if ($table['borders_separate']) { // NB twice border width
  10167. $xadj = $border_details['L']['w'] + $padding['L'] +($table['border_spacing_H']/2);
  10168. $wadj = $border_details['L']['w'] + $border_details['R']['w'] + $padding['L'] +$padding['R'] + $table['border_spacing_H'];
  10169. $yadj = $border_details['T']['w'] + $padding['T'] + ($table['border_spacing_H']/2);
  10170. }
  10171. else {
  10172. $xadj = $border_details['L']['w']/2 + $padding['L'];
  10173. $wadj = ($border_details['L']['w'] + $border_details['R']['w'])/2 + $padding['L'] + $padding['R'];
  10174. $yadj = $border_details['T']['w']/2 + $padding['T'];
  10175. }
  10176. $this->divwidth=$w-($wadj);
  10177. $this->x += $xadj;
  10178. $this->y += $yadj;
  10179. $this->printbuffer($textbuffer,'',true);
  10180. }
  10181. }
  10182. $textbuffer = array();
  10183. /*-- BACKGROUNDS --*/
  10184. if (!$this->ColActive) {
  10185. if (isset($content[$i][0]['trgradients']) && ($colctr==1 || $table['borders_separate'])) {
  10186. $g = $this->grad->parseBackgroundGradient($content[$i][0]['trgradients']);
  10187. if ($g) {
  10188. $gx = $x0;
  10189. $gy = $y;
  10190. $gh = $h;
  10191. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10192. if ($table['borders_separate']) {
  10193. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10194. $s = '';
  10195. $clx = $x+ ($table['border_spacing_H']/2);
  10196. $cly = $y+ ($table['border_spacing_V']/2);
  10197. $clw = $w- $table['border_spacing_H'];
  10198. $clh = $h- $table['border_spacing_V'];
  10199. // Set clipping path
  10200. $s = ' q 0 w '; // Line width=0
  10201. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10202. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10203. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10204. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10205. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10206. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10207. $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);
  10208. }
  10209. else {
  10210. $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'=>'');
  10211. }
  10212. }
  10213. }
  10214. if (isset($content[$i][0]['trbackground-images']) && ($colctr==1 || $table['borders_separate'])) {
  10215. if ($content[$i][0]['trbackground-images']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $content[$i][0]['trbackground-images']['gradient'] )) {
  10216. $g = $this->grad->parseMozGradient( $content[$i][0]['trbackground-images']['gradient'] );
  10217. if ($g) {
  10218. $gx = $x0;
  10219. $gy = $y;
  10220. $gh = $h;
  10221. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10222. if ($table['borders_separate']) {
  10223. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10224. $s = '';
  10225. $clx = $x+ ($table['border_spacing_H']/2);
  10226. $cly = $y+ ($table['border_spacing_V']/2);
  10227. $clw = $w- $table['border_spacing_H'];
  10228. $clh = $h- $table['border_spacing_V'];
  10229. // Set clipping path
  10230. $s = ' q 0 w '; // Line width=0
  10231. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10232. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10233. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10234. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10235. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10236. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10237. $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);
  10238. }
  10239. else {
  10240. $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'=>'');
  10241. }
  10242. }
  10243. }
  10244. else {
  10245. $image_id = $content[$i][0]['trbackground-images']['image_id'];
  10246. $orig_w = $content[$i][0]['trbackground-images']['orig_w'];
  10247. $orig_h = $content[$i][0]['trbackground-images']['orig_h'];
  10248. $x_pos = $content[$i][0]['trbackground-images']['x_pos'];
  10249. $y_pos = $content[$i][0]['trbackground-images']['y_pos'];
  10250. $x_repeat = $content[$i][0]['trbackground-images']['x_repeat'];
  10251. $y_repeat = $content[$i][0]['trbackground-images']['y_repeat'];
  10252. $resize = $content[$i][0]['trbackground-images']['resize'];
  10253. $opacity = $content[$i][0]['trbackground-images']['opacity'];
  10254. $itype = $content[$i][0]['trbackground-images']['itype'];
  10255. $clippath = '';
  10256. $gx = $x0;
  10257. $gy = $y;
  10258. $gh = $h;
  10259. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  10260. if ($table['borders_separate']) {
  10261. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  10262. $s = '';
  10263. $clx = $x+ ($table['border_spacing_H']/2);
  10264. $cly = $y+ ($table['border_spacing_V']/2);
  10265. $clw = $w- $table['border_spacing_H'];
  10266. $clh = $h- $table['border_spacing_V'];
  10267. // Set clipping path
  10268. $s = ' q 0 w '; // Line width=0
  10269. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  10270. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  10271. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  10272. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  10273. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  10274. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  10275. $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);
  10276. }
  10277. else {
  10278. $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);
  10279. }
  10280. }
  10281. }
  10282. }
  10283. /*-- END BACKGROUNDS --*/
  10284. // TABLE BORDER - if separate OR collapsed and only table border
  10285. if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) {
  10286. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  10287. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  10288. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  10289. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  10290. $tbx = $x;
  10291. $tby = $y;
  10292. $tbw = $w;
  10293. $tbh = $h;
  10294. $tab_bord = 0;
  10295. $corner = '';
  10296. if ($i == $firstrow && $horf=='H') { // Top
  10297. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  10298. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  10299. $this->setBorder($tab_bord , _BORDER_TOP);
  10300. $corner .= 'T';
  10301. }
  10302. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1))) && $horf=='F') { // Bottom
  10303. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  10304. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  10305. $corner .= 'B';
  10306. }
  10307. if ($colctr == 1 && $firstSpread) { // Left
  10308. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  10309. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  10310. $this->setBorder($tab_bord , _BORDER_LEFT);
  10311. $corner .= 'L';
  10312. }
  10313. if ($colctr == count($content[$i]) && $finalSpread) { // Right
  10314. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  10315. $this->setBorder($tab_bord , _BORDER_RIGHT);
  10316. $corner .= 'R';
  10317. }
  10318. $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'] );
  10319. }
  10320. }// end column $content
  10321. $this->y = $y + $h; //Update y coordinate
  10322. }// end row $i
  10323. unset($table );
  10324. $this->colsums = array();
  10325. }
  10326. }
  10327. /*-- END TABLES --*/
  10328. /*-- HTMLHEADERS-FOOTERS --*/
  10329. function SetHTMLHeader($header='',$OE='',$write=false) {
  10330. $height = 0;
  10331. if (is_array($header) && isset($header['html']) && $header['html']) {
  10332. $Hhtml = $header['html'];
  10333. if ($this->setAutoTopMargin) {
  10334. if (isset($header['h'])) { $height = $header['h']; }
  10335. else { $height = $this->_gethtmlheight($Hhtml); }
  10336. }
  10337. }
  10338. else if (!is_array($header) && $header) {
  10339. $Hhtml = $header;
  10340. if ($this->setAutoTopMargin) { $height = $this->_gethtmlheight($Hhtml); }
  10341. }
  10342. else { $Hhtml = ''; }
  10343. if ($OE != 'E') { $OE = 'O'; }
  10344. if ($OE == 'E') {
  10345. if ($Hhtml) {
  10346. $this->HTMLHeaderE['html'] = $Hhtml;
  10347. $this->HTMLHeaderE['h'] = $height;
  10348. }
  10349. else { $this->HTMLHeaderE = ''; }
  10350. }
  10351. else {
  10352. if ($Hhtml) {
  10353. $this->HTMLHeader['html'] = $Hhtml;
  10354. $this->HTMLHeader['h'] = $height;
  10355. }
  10356. else { $this->HTMLHeader = ''; }
  10357. }
  10358. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10359. if ($Hhtml=='') { return; }
  10360. if ($OE == 'E') {
  10361. $this->headerDetails['even'] = array(); // override and clear any other non-HTML header/footer
  10362. }
  10363. else {
  10364. $this->headerDetails['odd'] = array(); // override and clear any non-HTML other header/footer
  10365. }
  10366. if ($this->setAutoTopMargin=='pad') {
  10367. $this->tMargin = $this->margin_header + $height + $this->orig_tMargin;
  10368. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10369. }
  10370. else if ($this->setAutoTopMargin=='stretch') {
  10371. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $height + $this->autoMarginPadding);
  10372. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10373. }
  10374. 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(); }
  10375. }
  10376. function SetHTMLFooter($footer='',$OE='') {
  10377. $height = 0;
  10378. if (is_array($footer) && isset($footer['html']) && $footer['html']) {
  10379. $Fhtml = $footer['html'];
  10380. if ($this->setAutoBottomMargin) {
  10381. if (isset($footer['h'])) { $height = $footer['h']; }
  10382. else { $height = $this->_gethtmlheight($Fhtml); }
  10383. }
  10384. }
  10385. else if (!is_array($footer) && $footer) {
  10386. $Fhtml = $footer;
  10387. if ($this->setAutoBottomMargin) { $height = $this->_gethtmlheight($Fhtml); }
  10388. }
  10389. else { $Fhtml = ''; }
  10390. if ($OE != 'E') { $OE = 'O'; }
  10391. if ($OE == 'E') {
  10392. if ($Fhtml) {
  10393. $this->HTMLFooterE['html'] = $Fhtml;
  10394. $this->HTMLFooterE['h'] = $height;
  10395. }
  10396. else { $this->HTMLFooterE = ''; }
  10397. }
  10398. else {
  10399. if ($Fhtml) {
  10400. $this->HTMLFooter['html'] = $Fhtml;
  10401. $this->HTMLFooter['h'] = $height;
  10402. }
  10403. else { $this->HTMLFooter = ''; }
  10404. }
  10405. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10406. if ($Fhtml=='') { return false; }
  10407. if ($OE == 'E') {
  10408. $this->footerDetails['even'] = array(); // override and clear any other header/footer
  10409. }
  10410. else {
  10411. $this->footerDetails['odd'] = array(); // override and clear any other header/footer
  10412. }
  10413. if ($this->setAutoBottomMargin=='pad') {
  10414. $this->bMargin = $this->margin_footer + $height + $this->orig_bMargin;
  10415. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10416. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10417. }
  10418. else if ($this->setAutoBottomMargin=='stretch') {
  10419. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $height + $this->autoMarginPadding);
  10420. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10421. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10422. }
  10423. }
  10424. function _getHtmlHeight($html) {
  10425. $save_state = $this->state;
  10426. if($this->state==0) {
  10427. $this->AddPage($this->CurOrientation);
  10428. }
  10429. $this->state = 2;
  10430. $this->Reset();
  10431. $this->pageoutput[$this->page] = array();
  10432. $save_x = $this->x;
  10433. $save_y = $this->y;
  10434. $this->x = $this->lMargin;
  10435. $this->y = $this->margin_header;
  10436. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($this->page).$this->pagenumSuffix,$html);
  10437. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($this->page).$this->nbpgSuffix,$html );
  10438. $html = str_replace($this->aliasNbPg,$this->page,$html );
  10439. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  10440. $this->HTMLheaderPageLinks = array();
  10441. $this->HTMLheaderPageAnnots = array();
  10442. $this->HTMLheaderPageForms = array();
  10443. $savepb = $this->pageBackgrounds;
  10444. $this->writingHTMLheader = true;
  10445. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  10446. $this->writingHTMLheader = false;
  10447. $h = ($this->y - $this->margin_header);
  10448. $this->Reset();
  10449. $this->pageoutput[$this->page] = array();
  10450. $this->headerbuffer = '';
  10451. $this->pageBackgrounds = $savepb;
  10452. $this->x = $save_x;
  10453. $this->y = $save_y;
  10454. $this->state = $save_state;
  10455. if($save_state==0) {
  10456. unset($this->pages[1]);
  10457. $this->page = 0;
  10458. }
  10459. return $h;
  10460. }
  10461. // Called internally from Header
  10462. function writeHTMLHeaders() {
  10463. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10464. else { $OE = 'O'; }
  10465. if ($OE == 'E') {
  10466. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeaderE['html'] ;
  10467. }
  10468. else {
  10469. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeader['html'] ;
  10470. }
  10471. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10472. $this->saveHTMLHeader[$this->page][$OE]['rotate'] = true;
  10473. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->tMargin;
  10474. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->bMargin;
  10475. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10476. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10477. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->h;
  10478. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->w;
  10479. }
  10480. else {
  10481. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->lMargin;
  10482. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->rMargin;
  10483. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10484. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10485. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->w;
  10486. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->h;
  10487. }
  10488. }
  10489. function writeHTMLFooters() {
  10490. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10491. else { $OE = 'O'; }
  10492. if ($OE == 'E') {
  10493. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooterE['html'] ;
  10494. }
  10495. else {
  10496. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooter['html'] ;
  10497. }
  10498. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10499. $this->saveHTMLFooter[$this->page][$OE]['rotate'] = true;
  10500. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->tMargin;
  10501. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->bMargin;
  10502. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->rMargin;
  10503. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->lMargin;
  10504. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10505. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10506. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->h;
  10507. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->w;
  10508. }
  10509. else {
  10510. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->lMargin;
  10511. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->rMargin;
  10512. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->tMargin;
  10513. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->bMargin;
  10514. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10515. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10516. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->w;
  10517. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->h;
  10518. }
  10519. }
  10520. /*-- END HTMLHEADERS-FOOTERS --*/
  10521. function DefHeaderByName($name,$arr) {
  10522. if (!$name) { $name = '_default'; }
  10523. $this->pageheaders[$name] = $arr;
  10524. }
  10525. function DefFooterByName($name,$arr) {
  10526. if (!$name) { $name = '_default'; }
  10527. $this->pagefooters[$name] = $arr;
  10528. }
  10529. function SetHeaderByName($name,$side='O',$write=false) {
  10530. if (!$name) { $name = '_default'; }
  10531. if ($side=='E') { $this->headerDetails['even'] = $this->pageheaders[$name]; }
  10532. else { $this->headerDetails['odd'] = $this->pageheaders[$name]; }
  10533. if ($write) { $this->Header(); }
  10534. }
  10535. function SetFooterByName($name,$side='O') {
  10536. if (!$name) { $name = '_default'; }
  10537. if ($side=='E') { $this->footerDetails['even'] = $this->pagefooters[$name]; }
  10538. else { $this->footerDetails['odd'] = $this->pagefooters[$name]; }
  10539. }
  10540. /*-- HTMLHEADERS-FOOTERS --*/
  10541. function DefHTMLHeaderByName($name,$html) {
  10542. if (!$name) { $name = '_default'; }
  10543. $this->pageHTMLheaders[$name]['html'] = $html;
  10544. $this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html);
  10545. }
  10546. function DefHTMLFooterByName($name,$html) {
  10547. if (!$name) { $name = '_default'; }
  10548. $this->pageHTMLfooters[$name]['html'] = $html;
  10549. $this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html);
  10550. }
  10551. function SetHTMLHeaderByName($name,$side='O',$write=false) {
  10552. if (!$name) { $name = '_default'; }
  10553. $this->SetHTMLHeader($this->pageHTMLheaders[$name],$side,$write);
  10554. }
  10555. function SetHTMLFooterByName($name,$side='O') {
  10556. if (!$name) { $name = '_default'; }
  10557. $this->SetHTMLFooter($this->pageHTMLfooters[$name],$side,$write);
  10558. }
  10559. /*-- END HTMLHEADERS-FOOTERS --*/
  10560. function SetHeader($Harray=array(),$side='',$write=false) {
  10561. if (is_string($Harray)) {
  10562. if (strlen($Harray)==0) {
  10563. if ($side=='O') { $this->headerDetails['odd'] = array(); }
  10564. else if ($side=='E') { $this->headerDetails['even'] = array(); }
  10565. else { $this->headerDetails = array(); }
  10566. }
  10567. else if (strpos($Harray,'|') || strpos($Harray,'|')===0) {
  10568. $hdet = explode('|',$Harray);
  10569. $this->headerDetails = array (
  10570. 'odd' => array (
  10571. 'L' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10572. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10573. 'R' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10574. 'line' => $this->defaultheaderline,
  10575. ),
  10576. 'even' => array (
  10577. 'R' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10578. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10579. 'L' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10580. 'line' => $this->defaultheaderline,
  10581. )
  10582. );
  10583. }
  10584. else {
  10585. $this->headerDetails = array (
  10586. 'odd' => array (
  10587. 'R' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10588. 'line' => $this->defaultheaderline,
  10589. ),
  10590. 'even' => array (
  10591. 'L' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10592. 'line' => $this->defaultheaderline,
  10593. )
  10594. );
  10595. }
  10596. }
  10597. else if (is_array($Harray)) {
  10598. if ($side=='O') { $this->headerDetails['odd'] = $Harray; }
  10599. else if ($side=='E') { $this->headerDetails['even'] = $Harray; }
  10600. else { $this->headerDetails = $Harray; }
  10601. }
  10602. /*-- HTMLHEADERS-FOOTERS --*/
  10603. // Overwrite any HTML Header previously set
  10604. if ($side=='E') { $this->SetHTMLHeader('','E'); }
  10605. else if ($side=='O') { $this->SetHTMLHeader(''); }
  10606. else {
  10607. $this->SetHTMLHeader('');
  10608. $this->SetHTMLHeader('','E');
  10609. }
  10610. /*-- END HTMLHEADERS-FOOTERS --*/
  10611. if ($write) {
  10612. $save_y = $this->y;
  10613. $this->Header();
  10614. $this->SetY($save_y) ;
  10615. }
  10616. }
  10617. function SetFooter($Farray=array(),$side='') {
  10618. if (is_string($Farray)) {
  10619. if (strlen($Farray)==0) {
  10620. if ($side=='O') { $this->footerDetails['odd'] = array(); }
  10621. else if ($side=='E') { $this->footerDetails['even'] = array(); }
  10622. else { $this->footerDetails = array(); }
  10623. }
  10624. else if (strpos($Farray,'|') || strpos($Farray,'|')===0) {
  10625. $fdet = explode('|',$Farray);
  10626. $this->footerDetails = array (
  10627. 'odd' => array (
  10628. 'L' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10629. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10630. 'R' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10631. 'line' => $this->defaultfooterline,
  10632. ),
  10633. 'even' => array (
  10634. 'R' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10635. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10636. 'L' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10637. 'line' => $this->defaultfooterline,
  10638. )
  10639. );
  10640. }
  10641. else {
  10642. $this->footerDetails = array (
  10643. 'odd' => array (
  10644. 'R' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10645. 'line' => $this->defaultfooterline,
  10646. ),
  10647. 'even' => array (
  10648. 'L' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10649. 'line' => $this->defaultfooterline,
  10650. )
  10651. );
  10652. }
  10653. }
  10654. else if (is_array($Farray)) {
  10655. if ($side=='O') { $this->footerDetails['odd'] = $Farray; }
  10656. else if ($side=='E') { $this->footerDetails['even'] = $Farray; }
  10657. else { $this->footerDetails = $Farray; }
  10658. }
  10659. /*-- HTMLHEADERS-FOOTERS --*/
  10660. // Overwrite any HTML Footer previously set
  10661. if ($side=='E') { $this->SetHTMLFooter('','E'); }
  10662. else if ($side=='O') { $this->SetHTMLFooter(''); }
  10663. else {
  10664. $this->SetHTMLFooter('');
  10665. $this->SetHTMLFooter('','E');
  10666. }
  10667. /*-- END HTMLHEADERS-FOOTERS --*/
  10668. }
  10669. /*-- WATERMARK --*/
  10670. function setUnvalidatedText($txt='', $alpha=-1) {
  10671. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  10672. $this->watermarkText = $txt;
  10673. }
  10674. function SetWatermarkText($txt='', $alpha=-1) {
  10675. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  10676. $this->watermarkText = $txt;
  10677. }
  10678. function SetWatermarkImage($src, $alpha=-1, $size='D', $pos='F') {
  10679. if ($alpha>=0) $this->watermarkImageAlpha = $alpha;
  10680. $this->watermarkImage = $src;
  10681. $this->watermark_size = $size;
  10682. $this->watermark_pos = $pos;
  10683. }
  10684. /*-- END WATERMARK --*/
  10685. //Page footer
  10686. function Footer() {
  10687. /*-- CSS-PAGE --*/
  10688. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  10689. if ($this->show_marks == 'CROP' || $this->show_marks == 'CROPCROSS') {
  10690. // Show TICK MARKS
  10691. $this->SetLineWidth(0.1); // = 0.1 mm
  10692. $this->SetDColor($this->ConvertColor(0));
  10693. $l = $this->cropMarkLength;
  10694. $m = $this->cropMarkMargin; // Distance of crop mark from margin
  10695. $b = $this->nonPrintMargin; // Non-printable border at edge of paper sheet
  10696. $ax1 = $b;
  10697. $bx = $this->page_box['outer_width_LR'] - $m;
  10698. $ax = max($ax1, $bx-$l);
  10699. $cx1 = $this->w - $b;
  10700. $dx = $this->w - $this->page_box['outer_width_LR'] + $m;
  10701. $cx = min($cx1, $dx+$l);
  10702. $ay1 = $b;
  10703. $by = $this->page_box['outer_width_TB'] - $m;
  10704. $ay = max($ay1, $by-$l);
  10705. $cy1 = $this->h - $b;
  10706. $dy = $this->h - $this->page_box['outer_width_TB'] + $m;
  10707. $cy = min($cy1, $dy+$l);
  10708. $this->Line($ax, $this->page_box['outer_width_TB'], $bx, $this->page_box['outer_width_TB']);
  10709. $this->Line($cx, $this->page_box['outer_width_TB'], $dx, $this->page_box['outer_width_TB']);
  10710. $this->Line($ax, $this->h - $this->page_box['outer_width_TB'], $bx, $this->h - $this->page_box['outer_width_TB']);
  10711. $this->Line($cx, $this->h - $this->page_box['outer_width_TB'], $dx, $this->h - $this->page_box['outer_width_TB']);
  10712. $this->Line($this->page_box['outer_width_LR'], $ay, $this->page_box['outer_width_LR'], $by);
  10713. $this->Line($this->page_box['outer_width_LR'], $cy, $this->page_box['outer_width_LR'], $dy);
  10714. $this->Line($this->w - $this->page_box['outer_width_LR'], $ay, $this->w - $this->page_box['outer_width_LR'], $by);
  10715. $this->Line($this->w - $this->page_box['outer_width_LR'], $cy, $this->w - $this->page_box['outer_width_LR'], $dy);
  10716. if ($this->printers_info) {
  10717. $hd = date('Y-m-d H:i').' Page '.$this->page.' of {nb}';
  10718. $this->SetTColor($this->ConvertColor(0));
  10719. $this->SetFont('arial','',7.5,true,true);
  10720. $this->x = $this->page_box['outer_width_LR'] + 1.5;
  10721. $this->y = 1;
  10722. $this->Cell($headerpgwidth ,$this->FontSize,$hd,0,0,'L',0,'',0,0,0,'M');
  10723. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  10724. }
  10725. }
  10726. if ($this->show_marks == 'CROSS' || $this->show_marks == 'CROPCROSS') {
  10727. $this->SetLineWidth(0.1); // = 0.1 mm
  10728. $this->SetDColor($this->ConvertColor(0));
  10729. $l = 14 /2; // longer length of the cross line (half)
  10730. $w = 6 /2; // shorter width of the cross line (half)
  10731. $r = 1.2; // radius of circle
  10732. $m = $this->crossMarkMargin; // Distance of cross mark from margin
  10733. $x1 = $this->page_box['outer_width_LR'] - $m;
  10734. $x2 = $this->w - $this->page_box['outer_width_LR'] + $m;
  10735. $y1 = $this->page_box['outer_width_TB'] - $m;
  10736. $y2 = $this->h - $this->page_box['outer_width_TB'] + $m;
  10737. // Left
  10738. $this->Circle($x1, $this->h/2, $r, 'S') ;
  10739. $this->Line($x1-$w, $this->h/2, $x1+$w, $this->h/2);
  10740. $this->Line($x1, $this->h/2-$l, $x1, $this->h/2+$l);
  10741. // Right
  10742. $this->Circle($x2, $this->h/2, $r, 'S') ;
  10743. $this->Line($x2-$w, $this->h/2, $x2+$w, $this->h/2);
  10744. $this->Line($x2, $this->h/2-$l, $x2, $this->h/2+$l);
  10745. // Top
  10746. $this->Circle($this->w/2, $y1, $r, 'S') ;
  10747. $this->Line($this->w/2, $y1-$w, $this->w/2, $y1+$w);
  10748. $this->Line($this->w/2-$l, $y1, $this->w/2+$l, $y1);
  10749. // Bottom
  10750. $this->Circle($this->w/2, $y2, $r, 'S') ;
  10751. $this->Line($this->w/2, $y2-$w, $this->w/2, $y2+$w);
  10752. $this->Line($this->w/2-$l, $y2, $this->w/2+$l, $y2);
  10753. }
  10754. // If @page set non-HTML headers/footers named, they were not read until later in the HTML code - so now set them
  10755. if ($this->page==1) {
  10756. if ($this->firstPageBoxHeader) {
  10757. $this->headerDetails['odd'] = $this->pageheaders[$this->firstPageBoxHeader];
  10758. $this->Header();
  10759. }
  10760. if ($this->firstPageBoxFooter) {
  10761. $this->footerDetails['odd'] = $this->pagefooters[$this->firstPageBoxFooter];
  10762. }
  10763. $this->firstPageBoxHeader='';
  10764. $this->firstPageBoxFooter='';
  10765. }
  10766. /*-- END CSS-PAGE --*/
  10767. /*-- HTMLHEADERS-FOOTERS --*/
  10768. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLFooterE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLFooter) || (!$this->mirrorMargins && $this->HTMLFooter)) {
  10769. $this->writeHTMLFooters();
  10770. /*-- WATERMARK --*/
  10771. if (($this->watermarkText) && ($this->showWatermarkText)) {
  10772. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  10773. }
  10774. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  10775. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  10776. }
  10777. /*-- END WATERMARK --*/
  10778. return;
  10779. }
  10780. /*-- END HTMLHEADERS-FOOTERS --*/
  10781. $this->processingHeader=true;
  10782. $this->ResetMargins(); // necessary after columns
  10783. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  10784. /*-- WATERMARK --*/
  10785. if (($this->watermarkText) && ($this->showWatermarkText)) {
  10786. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  10787. }
  10788. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  10789. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  10790. }
  10791. /*-- END WATERMARK --*/
  10792. $h = $this->footerDetails;
  10793. if(count($h)) {
  10794. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10795. $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK)));
  10796. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  10797. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10798. $headerlmargin = $this->orig_rMargin;
  10799. }
  10800. else {
  10801. $headerlmargin = $this->orig_lMargin;
  10802. }
  10803. }
  10804. else {
  10805. $yadj = 0;
  10806. $headerpgwidth = $this->pgwidth;
  10807. $headerlmargin = $this->lMargin;
  10808. }
  10809. $this->SetY(-$this->margin_footer);
  10810. $this->SetTColor($this->ConvertColor(0));
  10811. $this->SUP = false;
  10812. $this->SUB = false;
  10813. $this->bullet = false;
  10814. // only show pagenumber if numbering on
  10815. $pgno = $this->docPageNum($this->page, true);
  10816. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10817. $side = 'even';
  10818. }
  10819. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  10820. $side = 'odd';
  10821. }
  10822. $maxfontheight = 0;
  10823. foreach(array('L','C','R') AS $pos) {
  10824. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10825. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10826. else { $hfsz = $this->default_font_size; }
  10827. $maxfontheight = max($maxfontheight,$hfsz);
  10828. }
  10829. }
  10830. // LEFT-CENTER-RIGHT
  10831. foreach(array('L','C','R') AS $pos) {
  10832. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10833. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  10834. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd);
  10835. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  10836. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  10837. else { $hff = $this->original_default_font; }
  10838. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10839. else { $hfsz = $this->original_default_font_size; }
  10840. $maxfontheight = max($maxfontheight,$hfsz);
  10841. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) { $hfst = $h[$side][$pos]['font-style']; }
  10842. else { $hfst = ''; }
  10843. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  10844. $hfcol = $h[$side][$pos]['color'];
  10845. $cor = $this->ConvertColor($hfcol);
  10846. if ($cor) { $this->SetTColor($cor); }
  10847. }
  10848. else { $hfcol = ''; }
  10849. $this->SetFont($hff,$hfst,$hfsz,true,true);
  10850. $this->x = $headerlmargin ;
  10851. $this->y = $this->h - $this->margin_footer - ($maxfontheight/_MPDFK);
  10852. $hd = $this->purify_utf8_text($hd);
  10853. if ($this->text_input_as_HTML) {
  10854. $hd = $this->all_entities_to_utf8($hd);
  10855. }
  10856. // CONVERT CODEPAGE
  10857. if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  10858. // DIRECTIONALITY RTL
  10859. $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL*
  10860. // Font-specific ligature substitution for Indic fonts
  10861. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC*
  10862. $align = $pos;
  10863. if ($this->directionality == 'rtl') {
  10864. if ($pos == 'L') { $align = 'R'; }
  10865. else if ($pos == 'R') { $align = 'L'; }
  10866. }
  10867. if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) {
  10868. if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  10869. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  10870. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  10871. $this->_out('Q');
  10872. }
  10873. else {
  10874. $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M');
  10875. }
  10876. if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); }
  10877. }
  10878. }
  10879. // Return Font to normal
  10880. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  10881. // LINE
  10882. if (isset($h[$side]['line']) && $h[$side]['line']) {
  10883. $this->SetLineWidth(0.1);
  10884. $this->SetDColor($this->ConvertColor(0));
  10885. $this->Line($headerlmargin , $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK), $headerlmargin +$headerpgwidth, $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK));
  10886. }
  10887. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10888. $this->_out('Q');
  10889. }
  10890. }
  10891. $this->processingHeader=false;
  10892. }
  10893. /*-- HYPHENATION --*/
  10894. ///////////////////
  10895. ///////////////////
  10896. // HYPHENATION
  10897. ///////////////////
  10898. // Soft hyphs
  10899. function softHyphenate($word, $maxWidth) {
  10900. // Don't hyphenate web addresses
  10901. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  10902. // Get dictionary
  10903. $poss = array();
  10904. $softhyphens = array();
  10905. $offset = 0;
  10906. $p = true;
  10907. if ($this->usingCoreFont) {
  10908. $wl = strlen($word);
  10909. }
  10910. else {
  10911. $wl = mb_strlen($word,'UTF-8');
  10912. }
  10913. while($offset < $wl) {
  10914. // Soft Hyphens chr(173)
  10915. if (!$this->usingCoreFont) {
  10916. $p = mb_strpos($word, "\xc2\xad", $offset, 'UTF-8');
  10917. }
  10918. else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') {
  10919. $p = strpos($word, chr(173), $offset);
  10920. }
  10921. if ($p !== false) { $poss[] = $p - count($poss); }
  10922. else { break; }
  10923. $offset = $p+1;
  10924. }
  10925. $success = false;
  10926. foreach($poss AS $i) {
  10927. if ($this->usingCoreFont) {
  10928. $a = substr($word,0,$i);
  10929. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  10930. $pre = $a;
  10931. $post = substr($word,$i,strlen($word));
  10932. $prelength = strlen($pre);
  10933. }
  10934. else {
  10935. $a = mb_substr($word,0,$i,'UTF-8');
  10936. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  10937. $pre = $a;
  10938. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8');
  10939. $prelength = mb_strlen($pre, 'UTF-8');
  10940. }
  10941. $success = true;
  10942. }
  10943. return array($success,$pre,$post,$prelength);
  10944. }
  10945. ///////////////////
  10946. // Word hyphenation
  10947. function hyphenateWord($word, $maxWidth) {
  10948. // Do everything inside this function in utf-8
  10949. // Don't hyphenate web addresses
  10950. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  10951. // Get dictionary
  10952. if (!$this->loadedSHYdictionary) {
  10953. if (file_exists(_MPDF_PATH.'patterns/dictionary.txt')) {
  10954. $this->SHYdictionary = file(_MPDF_PATH.'patterns/dictionary.txt',FILE_SKIP_EMPTY_LINES);
  10955. foreach($this->SHYdictionary as $entry) {
  10956. $entry = trim($entry);
  10957. $poss = array();
  10958. $offset = 0;
  10959. $p = true;
  10960. $wl = mb_strlen($entry ,'UTF-8');
  10961. while($offset < $wl) {
  10962. $p = mb_strpos($entry, '/', $offset, 'UTF-8');
  10963. if ($p !== false) { $poss[] = $p - count($poss); }
  10964. else { break; }
  10965. $offset = $p+1;
  10966. }
  10967. if (count($poss)) { $this->SHYdictionaryWords[str_replace('/', '', mb_strtolower($entry))] = $poss; }
  10968. }
  10969. }
  10970. $this->loadedSHYdictionary = true;
  10971. }
  10972. if (!in_array($this->SHYlang,$this->SHYlanguages)) { return array(false,'','',''); }
  10973. // If no pattern loaded or not the best one
  10974. if (count($this->SHYpatterns) < 1 || ($this->loadedSHYpatterns && $this->loadedSHYpatterns != $this->SHYlang)) {
  10975. include(_MPDF_PATH."patterns/" . $this->SHYlang . ".php");
  10976. $patterns = explode(' ', $patterns);
  10977. $new_patterns = array();
  10978. for($i = 0; $i < count($patterns); $i++) {
  10979. $value = $patterns[$i];
  10980. $new_patterns[preg_replace('/[0-9]/', '', $value)] = $value;
  10981. }
  10982. $this->SHYpatterns = $new_patterns;
  10983. $this->loadedSHYpatterns = $this->SHYlang;
  10984. }
  10985. if ($this->usingCoreFont) { $word = mb_convert_encoding($word,'UTF-8',$this->mb_enc); }
  10986. $prepre = '';
  10987. $postpost = '';
  10988. $startpunctuation = "\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f";
  10989. $endpunctuation = "\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb";
  10990. $pre = '';
  10991. $post = '';
  10992. if (preg_match('/^(["\''.$startpunctuation .'])+(.{'.$this->SHYcharmin.',})$/u',$word,$m)) {
  10993. $prepre = $m[1];
  10994. $word = $m[2];
  10995. }
  10996. if (preg_match('/^(.{'.$this->SHYcharmin.',})([\'\.,;:!?"'.$endpunctuation .']+)$/u',$word,$m)) {
  10997. $word = $m[1];
  10998. $postpost = $m[2];
  10999. }
  11000. if(mb_strlen($word,'UTF-8') < $this->SHYcharmin) {
  11001. return array(false,'','','');
  11002. }
  11003. $success = false;
  11004. if(isset($this->SHYdictionaryWords[mb_strtolower($word)])) {
  11005. foreach($this->SHYdictionaryWords[mb_strtolower($word)] AS $i) {
  11006. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11007. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11008. else { $testa = $a; }
  11009. if ($this->GetStringWidth($testa.'-') > $maxWidth) { break ; }
  11010. $pre = $a;
  11011. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11012. $success = true;
  11013. }
  11014. }
  11015. if (!$success) {
  11016. $text_word = '_' . $word . '_';
  11017. $word_length = mb_strlen($text_word,'UTF-8');
  11018. $single_character = preg_split('//u', $text_word);
  11019. $text_word = mb_strtolower($text_word,'UTF-8');
  11020. $hyphenated_word = array();
  11021. $numb3rs = array('0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true);
  11022. for($position = 0; $position <= ($word_length - $this->SHYcharmin); $position++) {
  11023. $maxwins = min(($word_length - $position), $this->SHYcharmax);
  11024. for($win = $this->SHYcharmin; $win <= $maxwins; $win++) {
  11025. if(isset($this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')])) {
  11026. $pattern = $this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')];
  11027. $digits = 1;
  11028. $pattern_length = mb_strlen($pattern,'UTF-8');
  11029. for($i = 0; $i < $pattern_length; $i++) {
  11030. $char = $pattern[$i];
  11031. if(isset($numb3rs[$char])) {
  11032. $zero = ($i == 0) ? $position - 1 : $position + $i - $digits;
  11033. if(!isset($hyphenated_word[$zero]) || $hyphenated_word[$zero] != $char) $hyphenated_word[$zero] = $char;
  11034. $digits++;
  11035. }
  11036. }
  11037. }
  11038. }
  11039. }
  11040. for($i = $this->SHYleftmin; $i <= (mb_strlen($word,'UTF-8') - $this->SHYrightmin); $i++) {
  11041. if(isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 != 0) {
  11042. $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  11043. if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  11044. else { $testa = $a; }
  11045. if ($this->GetStringWidth($testa.'-') > $maxWidth + 0.0001) { break ; }
  11046. $pre = $a;
  11047. $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost;
  11048. $success = true;
  11049. }
  11050. }
  11051. }
  11052. if ($this->usingCoreFont) {
  11053. $pre = mb_convert_encoding($pre,$this->mb_enc,'UTF-8');
  11054. $post = mb_convert_encoding($post,$this->mb_enc,'UTF-8');
  11055. $prelength = strlen($pre);
  11056. }
  11057. else {
  11058. $prelength = mb_strlen($pre);
  11059. }
  11060. return array($success,$pre,$post,$prelength);
  11061. }
  11062. /*-- END HYPHENATION --*/
  11063. /*-- HTML-CSS --*/
  11064. ///////////////////
  11065. /// HTML parser ///
  11066. ///////////////////
  11067. function WriteHTML($html,$sub=0,$init=true,$close=true) {
  11068. // $sub ADDED - 0 = default; 1=headerCSS only; 2=HTML body (parts) only; 3 - HTML parses only
  11069. // 4 - writes HTML headers
  11070. // $close Leaves buffers etc. in current state, so that it can continue a block etc.
  11071. // $init - Clears and sets buffers to Top level block etc.
  11072. if (empty($html)) { $html = ''; }
  11073. if ($this->progressBar) { $this->UpdateProgressBar(1,0,'Parsing CSS & Headers'); } // *PROGRESS-BAR*
  11074. if ($init) {
  11075. $this->headerbuffer='';
  11076. $this->textbuffer = array();
  11077. $this->fixedPosBlockSave = array();
  11078. }
  11079. if ($sub == 1) { $html = '<style> '.$html.' </style>'; } // stylesheet only
  11080. if ($this->allow_charset_conversion) {
  11081. if ($sub < 1) {
  11082. $this->ReadCharset($html);
  11083. }
  11084. if ($this->charset_in && $sub!=4) { // mPDF 5.4.14
  11085. $success = iconv($this->charset_in,'UTF-8//TRANSLIT',$html);
  11086. if ($success) { $html = $success; }
  11087. }
  11088. }
  11089. $html = $this->purify_utf8($html,false);
  11090. if ($init) {
  11091. $this->blklvl = 0;
  11092. $this->lastblocklevelchange = 0;
  11093. $this->blk = array();
  11094. $this->initialiseBlock($this->blk[0]);
  11095. $this->blk[0]['width'] =& $this->pgwidth;
  11096. $this->blk[0]['inner_width'] =& $this->pgwidth;
  11097. $this->blk[0]['blockContext'] = $this->blockContext;
  11098. }
  11099. $zproperties = array();
  11100. if ($sub < 2) {
  11101. $this->ReadMetaTags($html);
  11102. // NB default stylesheet now in mPDF.css - read on initialising class
  11103. $html = $this->ReadCSS($html);
  11104. if ($this->useLang && !$this->usingCoreFont && preg_match('/<html [^>]*lang=[\'\"](.*?)[\'\"]/ism',$html,$m)) {
  11105. $html_lang = $m[1];
  11106. }
  11107. if (preg_match('/<html [^>]*dir=[\'\"]\s*rtl\s*[\'\"]/ism',$html)) {
  11108. $zproperties['DIRECTION'] = 'rtl';
  11109. }
  11110. // allow in-line CSS for body tag to be parsed // Get <body> tag inline CSS
  11111. if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism',$html,$m) || preg_match('/<body([^>]*)>(.*)$/ism',$html,$m)) {
  11112. $html = $m[2];
  11113. // Changed to allow style="background: url('bg.jpg')"
  11114. if (preg_match('/style=[\"](.*?)[\"]/ism',$m[1],$mm) || preg_match('/style=[\'](.*?)[\']/ism',$m[1],$mm)) {
  11115. $zproperties = $this->readInlineCSS($mm[1]);
  11116. }
  11117. if (preg_match('/dir=[\'\"]\s*rtl\s*[\'\"]/ism',$m[1])) {
  11118. $zproperties['DIRECTION'] = 'rtl';
  11119. }
  11120. if (isset($html_lang) && $html_lang) { $zproperties['LANG'] = $html_lang; }
  11121. if ($this->useLang && !$this->onlyCoreFonts && preg_match('/lang=[\'\"](.*?)[\'\"]/ism',$m[1],$mm)) {
  11122. $zproperties['LANG'] = $mm[1];
  11123. }
  11124. }
  11125. }
  11126. $properties = $this->MergeCSS('BLOCK','BODY','');
  11127. if ($zproperties) { $properties = $this->array_merge_recursive_unique($properties,$zproperties); }
  11128. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) {
  11129. $this->CSS['BODY']['DIRECTION'] = $properties['DIRECTION'];
  11130. }
  11131. if (!isset($this->CSS['BODY']['DIRECTION'])) {
  11132. $this->CSS['BODY']['DIRECTION'] = $this->directionality;
  11133. }
  11134. else { $this->SetDirectionality($this->CSS['BODY']['DIRECTION']); }
  11135. $this->setCSS($properties,'','BODY');
  11136. $this->blk[0]['InlineProperties'] = $this->saveInlineProperties();
  11137. if ($sub == 1) { return ''; }
  11138. if (!isset($this->CSS['BODY'])) { $this->CSS['BODY'] = array(); }
  11139. /*-- BACKGROUNDS --*/
  11140. if (isset($properties['BACKGROUND-GRADIENT'])) {
  11141. $this->bodyBackgroundGradient = $properties['BACKGROUND-GRADIENT'];
  11142. }
  11143. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE']) {
  11144. $ret = $this->SetBackground($properties, $this->pgwidth);
  11145. if ($ret) { $this->bodyBackgroundImage = $ret; }
  11146. }
  11147. /*-- END BACKGROUNDS --*/
  11148. /*-- CSS-PAGE --*/
  11149. // If page-box is set
  11150. if ($this->state==0 && isset($this->CSS['@PAGE']) && $this->CSS['@PAGE'] ) {
  11151. $this->page_box['current'] = '';
  11152. $this->page_box['using'] = true;
  11153. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', false, 'O');
  11154. $this->DefOrientation = $this->CurOrientation = $pborientation;
  11155. $this->orig_lMargin = $this->DeflMargin = $pbmgl;
  11156. $this->orig_rMargin = $this->DefrMargin = $pbmgr;
  11157. $this->orig_tMargin = $this->tMargin = $pbmgt;
  11158. $this->orig_bMargin = $this->bMargin = $pbmgb;
  11159. $this->orig_hMargin = $this->margin_header = $pbmgh;
  11160. $this->orig_fMargin = $this->margin_footer = $pbmgf;
  11161. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', true, 'O'); // first page
  11162. $this->show_marks = $marks;
  11163. if ($hname && !preg_match('/^html_(.*)$/i',$hname)) $this->firstPageBoxHeader = $hname;
  11164. if ($fname && !preg_match('/^html_(.*)$/i',$fname)) $this->firstPageBoxFooter = $fname;
  11165. }
  11166. /*-- END CSS-PAGE --*/
  11167. $parseonly = false;
  11168. $this->bufferoutput = false;
  11169. if ($sub == 3) {
  11170. $parseonly = true;
  11171. // Close any open block tags
  11172. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11173. // Output any text left in buffer
  11174. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  11175. $this->textbuffer=array();
  11176. }
  11177. else if ($sub == 4) {
  11178. // Close any open block tags
  11179. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11180. // Output any text left in buffer
  11181. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  11182. $this->bufferoutput = true;
  11183. $this->textbuffer=array();
  11184. $this->headerbuffer='';
  11185. $properties = $this->MergeCSS('BLOCK','BODY','');
  11186. $this->setCSS($properties,'','BODY');
  11187. }
  11188. mb_internal_encoding('UTF-8');
  11189. $html = $this->AdjustHTML($html, $this->tabSpaces); //Try to make HTML look more like XHTML
  11190. if ($this->autoFontGroups) { $html = $this->AutoFont($html); }
  11191. /*-- HTMLHEADERS-FOOTERS --*/
  11192. preg_match_all('/<htmlpageheader([^>]*)>(.*?)<\/htmlpageheader>/si',$html,$h);
  11193. for($i=0;$i<count($h[1]);$i++) {
  11194. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$h[1][$i],$n)) {
  11195. $this->pageHTMLheaders[$n[1]]['html'] = $h[2][$i];
  11196. $this->pageHTMLheaders[$n[1]]['h'] = $this->_gethtmlheight($h[2][$i]);
  11197. }
  11198. }
  11199. preg_match_all('/<htmlpagefooter([^>]*)>(.*?)<\/htmlpagefooter>/si',$html,$f);
  11200. for($i=0;$i<count($f[1]);$i++) {
  11201. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$f[1][$i],$n)) {
  11202. $this->pageHTMLfooters[$n[1]]['html'] = $f[2][$i];
  11203. $this->pageHTMLfooters[$n[1]]['h'] = $this->_gethtmlheight($f[2][$i]);
  11204. }
  11205. }
  11206. /*-- END HTMLHEADERS-FOOTERS --*/
  11207. $html = preg_replace('/<htmlpageheader.*?<\/htmlpageheader>/si','',$html);
  11208. $html = preg_replace('/<htmlpagefooter.*?<\/htmlpagefooter>/si','',$html);
  11209. if($this->state==0 && $sub!=1 && $sub!=3 && $sub!=4) {
  11210. $this->AddPage($this->CurOrientation);
  11211. }
  11212. /*-- HTMLHEADERS-FOOTERS --*/
  11213. if (isset($hname) && preg_match('/^html_(.*)$/i',$hname,$n)) $this->SetHTMLHeader($this->pageHTMLheaders[$n[1]],'O',true);
  11214. if (isset($fname) && preg_match('/^html_(.*)$/i',$fname,$n)) $this->SetHTMLFooter($this->pageHTMLfooters[$n[1]],'O');
  11215. /*-- END HTMLHEADERS-FOOTERS --*/
  11216. $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word
  11217. $this->checkSIP = false;
  11218. $this->checkSMP = false;
  11219. $this->checkCJK = false;
  11220. if ($this->onlyCoreFonts) { $html = $this->SubstituteChars($html); }
  11221. else {
  11222. if (preg_match("/([".$this->pregRTLchars."])/u", $html)) { $this->biDirectional = true; } // *RTL*
  11223. if (preg_match("/([\x{20000}-\x{2FFFF}])/u", $html)) { $this->checkSIP = true; }
  11224. if (preg_match("/([\x{10000}-\x{1FFFF}])/u", $html)) { $this->checkSMP = true; }
  11225. /*-- CJK-FONTS --*/
  11226. if (preg_match("/([".$this->pregCJKchars."])/u", $html)) { $this->checkCJK = true; }
  11227. /*-- END CJK-FONTS --*/
  11228. }
  11229. // Don't allow non-breaking spaces that are converted to substituted chars or will break anyway and mess up table width calc.
  11230. $html = str_replace('<tta>160</tta>',chr(32),$html);
  11231. $html = str_replace('</tta><tta>','|',$html);
  11232. $html = str_replace('</tts><tts>','|',$html);
  11233. $html = str_replace('</ttz><ttz>','|',$html);
  11234. //Add new supported tags in the DisableTags function
  11235. $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string
  11236. //Explode the string in order to parse the HTML code
  11237. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  11238. // ? more accurate regexp that allows e.g. <a name="Silly <name>">
  11239. // if changing - also change in fn.SubstituteChars()
  11240. // $a = preg_split ('/<((?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+)>/ms', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
  11241. if ($this->mb_enc) {
  11242. mb_internal_encoding($this->mb_enc);
  11243. }
  11244. $pbc = 0;
  11245. if ($this->progressBar) { $this->UpdateProgressBar(1,0); } // *PROGRESS-BAR*
  11246. $this->subPos = -1;
  11247. $cnt = count($a);
  11248. for($i=0;$i<$cnt; $i++) {
  11249. $e = $a[$i];
  11250. if($i%2==0) {
  11251. //TEXT
  11252. if ($this->blk[$this->blklvl]['hide']) { continue; }
  11253. if ($this->inlineDisplayOff) { continue; }
  11254. if ($this->inMeter) { continue; } // mPDF 5.5.09
  11255. if ($this->inFixedPosBlock) { $this->fixedPosBlock .= $e; continue; } // *CSS-POSITION*
  11256. if (strlen($e) == 0) { continue; }
  11257. $e = strcode2utf($e);
  11258. $e = $this->lesser_entity_decode($e);
  11259. if ($this->usingCoreFont) {
  11260. // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font
  11261. if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->subPos<$i && !$this->specialcontent) {
  11262. $cnt += $this->SubstituteCharsNonCore($a, $i, $e);
  11263. }
  11264. // CONVERT ENCODING
  11265. $e = mb_convert_encoding($e,$this->mb_enc,'UTF-8');
  11266. if ($this->toupper) { $e = strtoupper($e); }
  11267. if ($this->tolower) { $e = strtolower($e); }
  11268. if ($this->capitalize) { $e = ucwords($e); }
  11269. }
  11270. else {
  11271. if ($this->checkSIP && $this->CurrentFont['sipext'] && $this->subPos<$i && !$this->specialcontent) {
  11272. $cnt += $this->SubstituteCharsSIP($a, $i, $e);
  11273. }
  11274. if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->CurrentFont['type']!='Type0' && $this->subPos<$i && !$this->specialcontent) {
  11275. $cnt += $this->SubstituteCharsMB($a, $i, $e);
  11276. }
  11277. if ($this->biDirectional) { // *RTL*
  11278. $e = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $e); // *RTL*
  11279. // mPDF 5.4.05 removes U+200E/U+200F LTR and RTL mark
  11280. // mPDF 5.4.06 removes U+200C/U+200D Zero-width Joiner and Non-joiner
  11281. $e = preg_replace("/[\xe2\x80\x8c\xe2\x80\x8d\xe2\x80\x8e\xe2\x80\x8f]/u",'',$e);
  11282. } // *RTL*
  11283. // Font-specific ligature substitution for Indic fonts
  11284. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($e); // *INDIC*
  11285. if ($this->toupper) { $e = mb_strtoupper($e,$this->mb_enc); }
  11286. if ($this->tolower) { $e = mb_strtolower($e,$this->mb_enc); }
  11287. if ($this->capitalize) { $e = mb_convert_case($e, MB_CASE_TITLE, "UTF-8"); }
  11288. }
  11289. if (($this->tts) || ($this->ttz) || ($this->tta)) {
  11290. $es = explode('|',$e);
  11291. $e = '';
  11292. foreach($es AS $val) {
  11293. $e .= chr($val);
  11294. }
  11295. }
  11296. //Adjust lineheight
  11297. // FORM ELEMENTS
  11298. if ($this->specialcontent) {
  11299. /*-- FORMS --*/
  11300. //SELECT tag (form element)
  11301. if ($this->specialcontent == "type=select") {
  11302. $e = ltrim($e);
  11303. $stringwidth = $this->GetStringWidth($e);
  11304. if (!isset($this->selectoption['MAXWIDTH']) || $stringwidth > $this->selectoption['MAXWIDTH']) { $this->selectoption['MAXWIDTH'] = $stringwidth; }
  11305. if (!isset($this->selectoption['SELECTED']) || $this->selectoption['SELECTED'] == '') { $this->selectoption['SELECTED'] = $e; }
  11306. // mPDD 1.4 Active Forms
  11307. if (isset($this->selectoption['ACTIVE']) && $this->selectoption['ACTIVE']) {
  11308. $this->selectoption['ITEMS'][]=array('exportValue'=>$this->selectoption['currentVAL'], 'content'=>$e, 'selected'=>$this->selectoption['currentSEL']);
  11309. }
  11310. }
  11311. // TEXTAREA
  11312. else {
  11313. $objattr = unserialize($this->specialcontent);
  11314. $objattr['text'] = $e;
  11315. $te = "\xbb\xa4\xactype=textarea,objattr=".serialize($objattr)."\xbb\xa4\xac";
  11316. if ($this->tdbegin) {
  11317. $this->_saveCellTextBuffer($te, $this->HREF);
  11318. }
  11319. else {
  11320. $this->_saveTextBuffer($te, $this->HREF);
  11321. }
  11322. }
  11323. /*-- END FORMS --*/
  11324. }
  11325. // TABLE
  11326. else if ($this->tableLevel) {
  11327. /*-- TABLES --*/
  11328. if ($this->tdbegin) {
  11329. if (($this->ignorefollowingspaces) && !$this->ispre) { $e = ltrim($e); }
  11330. if ($e || $e==='0') {
  11331. if (($this->blockjustfinished || $this->listjustfinished) && $this->cell[$this->row][$this->col]['s']>0) {
  11332. $this->_saveCellTextBuffer("\n");
  11333. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  11334. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11335. }
  11336. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  11337. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11338. }
  11339. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  11340. }
  11341. $this->blockjustfinished=false;
  11342. $this->listjustfinished=false;
  11343. $this->_saveCellTextBuffer($e, $this->HREF);
  11344. if (!isset($this->cell[$this->row][$this->col]['R']) || !$this->cell[$this->row][$this->col]['R']) {
  11345. if (isset($this->cell[$this->row][$this->col]['s'])) {
  11346. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e, false);
  11347. }
  11348. else { $this->cell[$this->row][$this->col]['s'] = $this->GetStringWidth($e, false); }
  11349. if (!empty($this->spanborddet)) {
  11350. $this->cell[$this->row][$this->col]['s'] += $this->spanborddet['L']['w'] + $this->spanborddet['R']['w'];
  11351. }
  11352. }
  11353. if ($this->checkCJK && preg_match("/([".$this->pregCJKchars."])/u", $e)) { $this->tableCJK = true; } // *CJK-FONTS*
  11354. if ($this->tableLevel==1 && $this->useGraphs) {
  11355. $this->graphs[$this->currentGraphId]['data'][$this->row][$this->col] = $e;
  11356. }
  11357. $this->nestedtablejustfinished = false;
  11358. $this->linebreakjustfinished=false;
  11359. }
  11360. }
  11361. /*-- END TABLES --*/
  11362. }
  11363. // ALL ELSE
  11364. else {
  11365. if ($this->ignorefollowingspaces and !$this->ispre) { $e = ltrim($e); }
  11366. if ($e || $e==='0') $this->_saveTextBuffer($e, $this->HREF);
  11367. }
  11368. }
  11369. else { // TAG **
  11370. if($e[0]=='/') {
  11371. /*-- PROGRESS-BAR --*/
  11372. if ($this->progressBar) { // 10% increments
  11373. if (intval($i*10/$cnt) != $pbc) { $pbc = intval($i*10/$cnt); $this->UpdateProgressBar(1,$pbc*10,$tag); }
  11374. }
  11375. /*-- END PROGRESS-BAR --*/
  11376. // Check for tags where HTML specifies optional end tags,
  11377. // and/or does not allow nesting e.g. P inside P, or
  11378. $endtag = trim(strtoupper(substr($e,1))); // mPDF 5.4.20
  11379. if($this->blk[$this->blklvl]['hide']) {
  11380. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) {
  11381. unset($this->blk[$this->blklvl]);
  11382. $this->blklvl--;
  11383. }
  11384. continue;
  11385. }
  11386. /*-- CSS-POSITION --*/
  11387. if ($this->inFixedPosBlock) {
  11388. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) { $this->fixedPosBlockDepth--; }
  11389. if ($this->fixedPosBlockDepth == 0) {
  11390. $this->fixedPosBlockSave[] = array($this->fixedPosBlock, $this->fixedPosBlockBBox, $this->page);
  11391. $this->fixedPosBlock = '';
  11392. $this->inFixedPosBlock = false;
  11393. continue;
  11394. }
  11395. $this->fixedPosBlock .= '<'.$e.'>';
  11396. continue;
  11397. }
  11398. /*-- END CSS-POSITION --*/
  11399. if ($this->allow_html_optional_endtags && !$parseonly) {
  11400. if (($endtag == 'DIV' || $endtag =='FORM' || $endtag =='CENTER') && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); }
  11401. if ($this->lastoptionaltag == 'LI' && $endtag == 'OL') { $this->CloseTag($this->lastoptionaltag ); }
  11402. if ($this->lastoptionaltag == 'LI' && $endtag == 'UL') { $this->CloseTag($this->lastoptionaltag ); }
  11403. if ($this->lastoptionaltag == 'DD' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11404. if ($this->lastoptionaltag == 'DT' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11405. if ($this->lastoptionaltag == 'OPTION' && $endtag == 'SELECT') { $this->CloseTag($this->lastoptionaltag ); }
  11406. /*-- TABLES --*/
  11407. if ($endtag == 'TABLE') {
  11408. if ($this->lastoptionaltag == 'THEAD' || $this->lastoptionaltag == 'TBODY' || $this->lastoptionaltag == 'TFOOT') {
  11409. $this->CloseTag($this->lastoptionaltag);
  11410. }
  11411. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11412. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11413. }
  11414. if ($endtag == 'THEAD' || $endtag == 'TBODY' || $endtag == 'TFOOT') {
  11415. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11416. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11417. }
  11418. if ($endtag == 'TR') {
  11419. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); }
  11420. }
  11421. /*-- END TABLES --*/
  11422. }
  11423. $this->CloseTag($endtag);
  11424. }
  11425. else { // OPENING TAG
  11426. if($this->blk[$this->blklvl]['hide']) {
  11427. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11428. else { $te = strtoupper($e); }
  11429. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) {
  11430. $this->blklvl++;
  11431. $this->blk[$this->blklvl]['hide']=true;
  11432. }
  11433. continue;
  11434. }
  11435. /*-- CSS-POSITION --*/
  11436. if ($this->inFixedPosBlock) {
  11437. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11438. else { $te = strtoupper($e); }
  11439. $this->fixedPosBlock .= '<'.$e.'>';
  11440. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) { $this->fixedPosBlockDepth++; }
  11441. continue;
  11442. }
  11443. /*-- END CSS-POSITION --*/
  11444. $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any
  11445. $e = preg_replace($regexp,"=\"\$1\"",$e);
  11446. // changes anykey=anyvalue to anykey="anyvalue" (only do this inside tags)
  11447. if (substr($e,0,10)!='pageheader' && substr($e,0,10)!='pagefooter') {
  11448. $regexp = '| (\\w+?)=([^\\s>"]+)|si';
  11449. $e = preg_replace($regexp," \$1=\"\$2\"",$e);
  11450. }
  11451. $e = preg_replace('/ (\\S+?)\s*=\s*"/i', " \\1=\"", $e);
  11452. //Fix path values, if needed
  11453. $orig_srcpath = '';
  11454. if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) ) {
  11455. $regexp = '/ (href|src)\s*=\s*"(.*?)"/i';
  11456. preg_match($regexp,$e,$auxiliararray);
  11457. if (isset($auxiliararray[2])) { $path = $auxiliararray[2]; }
  11458. else { $path = ''; }
  11459. if (trim($path) != '' && !(stristr($e,"src=") !== false && substr($path,0,4)=='var:')) {
  11460. $orig_srcpath = $path;
  11461. $this->GetFullPath($path);
  11462. $regexp = '/ (href|src)="(.*?)"/i';
  11463. $e = preg_replace($regexp,' \\1="'.$path.'"',$e);
  11464. }
  11465. }//END of Fix path values
  11466. //Extract attributes
  11467. $contents=array();
  11468. $contents1=array(); // mPDF 5.5.17
  11469. $contents2=array();
  11470. // Changed to allow style="background: url('bg.jpg')"
  11471. // mPDF 5.5.17 Changed to improve performance; maximum length of \S (attribute) = 16
  11472. preg_match_all('/\\S{1,16}=["][^"]*["]/',$e,$contents1);
  11473. preg_match_all('/\\S{1,16}=[\'][^\']*[\']/i',$e,$contents2);
  11474. $contents = array_merge($contents1, $contents2);
  11475. preg_match('/\\S+/',$e,$a2);
  11476. $tag=strtoupper($a2[0]);
  11477. $attr=array();
  11478. if ($orig_srcpath) { $attr['ORIG_SRC'] = $orig_srcpath; }
  11479. if (!empty($contents)) {
  11480. foreach($contents[0] as $v) {
  11481. // Changed to allow style="background: url('bg.jpg')"
  11482. if(preg_match('/^([^=]*)=["]?([^"]*)["]?$/',$v,$a3) || preg_match('/^([^=]*)=[\']?([^\']*)[\']?$/',$v,$a3)) {
  11483. if (strtoupper($a3[1])=='ID' || strtoupper($a3[1])=='CLASS') { // 4.2.013 Omits STYLE
  11484. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  11485. }
  11486. // includes header-style-right etc. used for <pageheader>
  11487. else if (preg_match('/^(HEADER|FOOTER)-STYLE/i',$a3[1])) {
  11488. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  11489. }
  11490. else {
  11491. $attr[strtoupper($a3[1])]=trim($a3[2]);
  11492. }
  11493. }
  11494. }
  11495. }
  11496. $this->OpenTag($tag,$attr);
  11497. /*-- CSS-POSITION --*/
  11498. if ($this->inFixedPosBlock) {
  11499. $this->fixedPosBlockBBox = array($tag,$attr, $this->x, $this->y);
  11500. $this->fixedPosBlock = '';
  11501. $this->fixedPosBlockDepth = 1;
  11502. }
  11503. /*-- END CSS-POSITION --*/
  11504. // mPDF 5.5.09
  11505. if (preg_match('/\/$/',$e)) { $this->closeTag($tag); }
  11506. }
  11507. } // end TAG
  11508. } //end of foreach($a as $i=>$e)
  11509. if ($close) {
  11510. // Close any open block tags
  11511. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11512. // Output any text left in buffer
  11513. if (count($this->textbuffer) && !$parseonly) { $this->printbuffer($this->textbuffer); }
  11514. if (!$parseonly) $this->textbuffer=array();
  11515. /*-- CSS-FLOAT --*/
  11516. // If ended with a float, need to move to end page
  11517. $currpos = $this->page*1000 + $this->y;
  11518. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  11519. $old_page = $this->page;
  11520. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  11521. if ($old_page != $new_page) {
  11522. $s = $this->PrintPageBackgrounds();
  11523. // Writes after the marker so not overwritten later by page background etc.
  11524. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  11525. $this->pageBackgrounds = array();
  11526. $this->page = $new_page;
  11527. $this->ResetMargins();
  11528. $this->Reset();
  11529. $this->pageoutput[$this->page] = array();
  11530. }
  11531. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  11532. }
  11533. /*-- END CSS-FLOAT --*/
  11534. /*-- CSS-IMAGE-FLOAT --*/
  11535. $this->printfloatbuffer();
  11536. /*-- END CSS-IMAGE-FLOAT --*/
  11537. //Create Internal Links, if needed
  11538. if (!empty($this->internallink) ) {
  11539. foreach($this->internallink as $k=>$v) {
  11540. if (strpos($k,"#") !== false ) { continue; } //ignore
  11541. $ypos = $v['Y'];
  11542. $pagenum = $v['PAGE'];
  11543. $sharp = "#";
  11544. while (array_key_exists($sharp.$k,$this->internallink)) {
  11545. $internallink = $this->internallink[$sharp.$k];
  11546. $this->SetLink($internallink,$ypos,$pagenum);
  11547. $sharp .= "#";
  11548. }
  11549. }
  11550. }
  11551. $this->linemaxfontsize = '';
  11552. $this->lineheight_correction = $this->default_lineheight_correction;
  11553. $this->bufferoutput = false;
  11554. /*-- CSS-POSITION --*/
  11555. if (count($this->fixedPosBlockSave) && $sub != 4) {
  11556. foreach($this->fixedPosBlockSave AS $fpbs) {
  11557. $old_page = $this->page;
  11558. $this->page = $fpbs[2];
  11559. $this->WriteFixedPosHTML($fpbs[0], 0, 0, 100, 100,'auto', $fpbs[1]); // 0,0,10,10 are overwritten by bbox
  11560. $this->page = $old_page;
  11561. }
  11562. }
  11563. /*-- END CSS-POSITION --*/
  11564. }
  11565. }
  11566. /*-- CSS-POSITION --*/
  11567. function WriteFixedPosHTML($html='',$x, $y, $w, $h, $overflow='visible', $bounding=array()) {
  11568. // $overflow can be 'hidden', 'visible' or 'auto' - 'auto' causes autofit to size
  11569. // Annotations disabled - enabled in mPDF 5.0
  11570. // Links do work
  11571. // Will always go on current page (or start Page 1 if required)
  11572. // Probably INCOMPATIBLE WITH keep with table, columns etc.
  11573. // Called externally or interally via <div style="position: [fixed|absolute]">
  11574. // When used internally, $x $y $w $h and $overflow are all overridden by $bounding
  11575. $overflow = strtolower($overflow);
  11576. if($this->state==0) {
  11577. $this->AddPage($this->CurOrientation);
  11578. }
  11579. $save_y = $this->y;
  11580. $save_x = $this->x;
  11581. $this->fullImageHeight = $this->h;
  11582. $save_cols = false;
  11583. /*-- COLUMNS --*/
  11584. if ($this->ColActive) {
  11585. $save_cols = true;
  11586. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  11587. $this->SetColumns(0);
  11588. }
  11589. /*-- END COLUMNS --*/
  11590. $save_annots = $this->title2annots; // *ANNOTATIONS*
  11591. $this->writingHTMLheader = true; // a FIX to stop pagebreaks etc.
  11592. $this->writingHTMLfooter = true;
  11593. $this->InFooter = true; // suppresses autopagebreaks
  11594. $save_bgs = $this->pageBackgrounds;
  11595. $checkinnerhtml = preg_replace('/\s/','',$html);
  11596. if ($w > $this->w) { $x = 0; $w = $this->w; }
  11597. if ($h > $this->h) { $y = 0; $h = $this->h; }
  11598. if ($x > $this->w) { $x = $this->w - $w; }
  11599. if ($y > $this->h) { $y = $this->h - $h; }
  11600. if (!empty($bounding)) {
  11601. // $cont_ containing block = full physical page (position: absolute) or page inside margins (position: fixed)
  11602. // $bbox_ Bounding box is the <div> which is positioned absolutely/fixed
  11603. // top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken from bounding
  11604. // font*[family/size/style/weight]/line-height/text*[align/decoration/transform/indent]/color are transferred to $inner
  11605. // as an enclosing <div> (after having checked ID/CLASS)
  11606. // $x, $y, $w, $h are inside of $bbox_ = containing box for $inner_
  11607. // $inner_ InnerHTML is the contents of that block to be output
  11608. $tag = $bounding[0];
  11609. $attr = $bounding[1];
  11610. $orig_x0 = $bounding[2];
  11611. $orig_y0 = $bounding[3];
  11612. // As in WriteHTML() initialising
  11613. $this->blklvl = 0;
  11614. $this->lastblocklevelchange = 0;
  11615. $this->blk = array();
  11616. $this->initialiseBlock($this->blk[0]);
  11617. $this->blk[0]['width'] =& $this->pgwidth;
  11618. $this->blk[0]['inner_width'] =& $this->pgwidth;
  11619. $this->blk[0]['blockContext'] = $this->blockContext;
  11620. $properties = $this->MergeCSS('BLOCK','BODY','');
  11621. $this->setCSS($properties,'','BODY');
  11622. $this->blklvl = 1;
  11623. $this->initialiseBlock($this->blk[1]);
  11624. $this->blk[1]['tag'] = $tag;
  11625. $this->blk[1]['attr'] = $attr;
  11626. $this->Reset();
  11627. $p = $this->MergeCSS('BLOCK',$tag,$attr);
  11628. if (isset($p['ROTATE']) && ($p['ROTATE']==90 || $p['ROTATE']==-90)) { $rotate = $p['ROTATE']; }
  11629. else { $rotate = 0; }
  11630. if (isset($p['OVERFLOW'])) { $overflow = strtolower($p['OVERFLOW']); }
  11631. if (strtolower($p['POSITION']) == 'fixed') {
  11632. $cont_w = $this->pgwidth; // $this->blk[0]['inner_width'];
  11633. $cont_h = $this->h - $this->tMargin - $this->bMargin;
  11634. $cont_x = $this->lMargin;
  11635. $cont_y = $this->tMargin;
  11636. }
  11637. else {
  11638. $cont_w = $this->w; // ABSOLUTE;
  11639. $cont_h = $this->h;
  11640. $cont_x = 0;
  11641. $cont_y = 0;
  11642. }
  11643. // Pass on in-line properties to the innerhtml
  11644. $css = '';
  11645. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; }
  11646. if (isset($p['TEXT-TRANSFORM'])) { $css .= 'text-transform: '.strtolower($p['TEXT-TRANSFORM']).'; '; }
  11647. if (isset($p['TEXT-INDENT'])) { $css .= 'text-indent: '.strtolower($p['TEXT-INDENT']).'; '; }
  11648. if (isset($p['TEXT-DECORATION'])) { $css .= 'text-decoration: '.strtolower($p['TEXT-DECORATION']).'; '; }
  11649. if (isset($p['FONT-FAMILY'])) { $css .= 'font-family: '.strtolower($p['FONT-FAMILY']).'; '; }
  11650. if (isset($p['FONT-STYLE'])) { $css .= 'font-style: '.strtolower($p['FONT-STYLE']).'; '; }
  11651. if (isset($p['FONT-WEIGHT'])) { $css .= 'font-weight: '.strtolower($p['FONT-WEIGHT']).'; '; }
  11652. if (isset($p['FONT-SIZE'])) { $css .= 'font-size: '.strtolower($p['FONT-SIZE']).'; '; }
  11653. if (isset($p['LINE-HEIGHT'])) { $css .= 'line-height: '.strtolower($p['LINE-HEIGHT']).'; '; }
  11654. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; }
  11655. if (isset($p['TEXT-SHADOW'])) { $css .= 'text-shadow: '.strtolower($p['TEXT-SHADOW']).'; '; }
  11656. if (isset($p['LETTER-SPACING'])) { $css .= 'letter-spacing: '.strtolower($p['LETTER-SPACING']).'; '; }
  11657. if (isset($p['FONT-VARIANT'])) { $css .= 'font-variant: '.strtolower($p['FONT-VARIANT']).'; '; }
  11658. if (isset($p['COLOR'])) { $css .= 'color: '.strtolower($p['COLOR']).'; '; }
  11659. if ($css) {
  11660. $html = '<div style="'.$css.'">'.$html.'</div>';
  11661. }
  11662. // Copy over (only) the properties to set for border and background
  11663. $pb = array();
  11664. $pb['MARGIN-TOP'] = $p['MARGIN-TOP'];
  11665. $pb['MARGIN-RIGHT'] = $p['MARGIN-RIGHT'];
  11666. $pb['MARGIN-BOTTOM'] = $p['MARGIN-BOTTOM'];
  11667. $pb['MARGIN-LEFT'] = $p['MARGIN-LEFT'];
  11668. $pb['PADDING-TOP'] = $p['PADDING-TOP'];
  11669. $pb['PADDING-RIGHT'] = $p['PADDING-RIGHT'];
  11670. $pb['PADDING-BOTTOM'] = $p['PADDING-BOTTOM'];
  11671. $pb['PADDING-LEFT'] = $p['PADDING-LEFT'];
  11672. $pb['BORDER-TOP'] = $p['BORDER-TOP'];
  11673. $pb['BORDER-RIGHT'] = $p['BORDER-RIGHT'];
  11674. $pb['BORDER-BOTTOM'] = $p['BORDER-BOTTOM'];
  11675. $pb['BORDER-LEFT'] = $p['BORDER-LEFT'];
  11676. $pb['BORDER-TOP-LEFT-RADIUS-H'] = $p['BORDER-TOP-LEFT-RADIUS-H'];
  11677. $pb['BORDER-TOP-LEFT-RADIUS-V'] = $p['BORDER-TOP-LEFT-RADIUS-V'];
  11678. $pb['BORDER-TOP-RIGHT-RADIUS-H'] = $p['BORDER-TOP-RIGHT-RADIUS-H'];
  11679. $pb['BORDER-TOP-RIGHT-RADIUS-V'] = $p['BORDER-TOP-RIGHT-RADIUS-V'];
  11680. $pb['BORDER-BOTTOM-LEFT-RADIUS-H'] = $p['BORDER-BOTTOM-LEFT-RADIUS-H'];
  11681. $pb['BORDER-BOTTOM-LEFT-RADIUS-V'] = $p['BORDER-BOTTOM-LEFT-RADIUS-V'];
  11682. $pb['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-H'];
  11683. $pb['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-V'];
  11684. if (isset($p['BACKGROUND-COLOR'])) { $pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  11685. if (isset($p['BOX-SHADOW'])) { $pb['BOX-SHADOW'] = $p['BOX-SHADOW']; }
  11686. /*-- BACKGROUNDS --*/
  11687. if (isset($p['BACKGROUND-IMAGE'])) { $pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  11688. if (isset($p['BACKGROUND-IMAGE-RESIZE'])) { $pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  11689. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; }
  11690. if (isset($p['BACKGROUND-REPEAT'])) { $pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  11691. if (isset($p['BACKGROUND-POSITION'])) { $pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  11692. if (isset($p['BACKGROUND-GRADIENT'])) { $pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  11693. /*-- END BACKGROUNDS --*/
  11694. $this->setCSS($pb,'BLOCK',$tag);
  11695. //================================================================
  11696. $bbox_br = $this->blk[1]['border_right']['w'];
  11697. $bbox_bl = $this->blk[1]['border_left']['w'];
  11698. $bbox_bt = $this->blk[1]['border_top']['w'];
  11699. $bbox_bb = $this->blk[1]['border_bottom']['w'];
  11700. $bbox_pr = $this->blk[1]['padding_right'];
  11701. $bbox_pl = $this->blk[1]['padding_left'];
  11702. $bbox_pt = $this->blk[1]['padding_top'];
  11703. $bbox_pb = $this->blk[1]['padding_bottom'];
  11704. $bbox_mr = $this->blk[1]['margin_right'];
  11705. if (strtolower($p['MARGIN-RIGHT'])=='auto') { $bbox_mr = 'auto'; }
  11706. $bbox_ml = $this->blk[1]['margin_left'];
  11707. if (strtolower($p['MARGIN-LEFT'])=='auto') { $bbox_ml = 'auto'; }
  11708. $bbox_mt = $this->blk[1]['margin_top'];
  11709. if (strtolower($p['MARGIN-TOP'])=='auto') { $bbox_mt = 'auto'; }
  11710. $bbox_mb = $this->blk[1]['margin_bottom'];
  11711. if (strtolower($p['MARGIN-BOTTOM'])=='auto') { $bbox_mb = 'auto'; }
  11712. if (isset($p['LEFT']) && strtolower($p['LEFT'])!='auto') { $bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this->FontSize,false); }
  11713. else { $bbox_left = 'auto'; }
  11714. if (isset($p['TOP']) && strtolower($p['TOP'])!='auto') { $bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this->FontSize,false); }
  11715. else { $bbox_top = 'auto'; }
  11716. if (isset($p['RIGHT']) && strtolower($p['RIGHT'])!='auto') { $bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w, $this->FontSize,false); }
  11717. else { $bbox_right = 'auto'; }
  11718. if (isset($p['BOTTOM']) && strtolower($p['BOTTOM'])!='auto') { $bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h, $this->FontSize,false); }
  11719. else { $bbox_bottom = 'auto'; }
  11720. if (isset($p['WIDTH']) && strtolower($p['WIDTH'])!='auto') { $inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this->FontSize,false); }
  11721. else { $inner_w = 'auto'; }
  11722. if (isset($p['HEIGHT']) && strtolower($p['HEIGHT'])!='auto') { $inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this->FontSize,false); }
  11723. else { $inner_h = 'auto'; }
  11724. // If bottom or right pos are set and not left / top - save this to adjust rotated block later
  11725. if ($rotate) {
  11726. if ($bbox_left === 'auto' && $bbox_right !== 'auto') { $rot_rpos = $bbox_right; }
  11727. else { $rot_rpos = false; }
  11728. if ($bbox_top === 'auto' && $bbox_bottom !== 'auto') { $rot_bpos = $bbox_bottom; }
  11729. else { $rot_bpos = false; }
  11730. }
  11731. //================================================================
  11732. if ($checkinnerhtml=='' && $inner_h==='auto') { $inner_h = 0.0001; }
  11733. if ($checkinnerhtml=='' && $inner_w==='auto') { $inner_w = 2*$this->GetCharWidth('W',false); }
  11734. //================================================================
  11735. // Algorithm from CSS2.1 See http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height
  11736. // mPD 5.3.14
  11737. // Special case (not CSS) if all not specified, centre vertically on page
  11738. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto' && $bbox_mt==='auto' && $bbox_mb==='auto') {
  11739. $bbox_top_orig = $bbox_top;
  11740. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11741. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11742. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  11743. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11744. }
  11745. // mPD 5.3.14
  11746. else if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto') {
  11747. $bbox_top_orig = $bbox_top = $orig_y0 - $cont_y;
  11748. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11749. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11750. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11751. }
  11752. else if ($bbox_top!=='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  11753. if ($bbox_mt==='auto' && $bbox_mb==='auto') {
  11754. $x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  11755. $bbox_mt = $bbox_mb = ($x/2);
  11756. }
  11757. else if ($bbox_mt==='auto') {
  11758. $bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11759. }
  11760. else if ($bbox_mb==='auto') {
  11761. $bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  11762. }
  11763. else {
  11764. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11765. }
  11766. }
  11767. else {
  11768. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11769. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11770. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom!=='auto') {
  11771. // solve for $bbox_top when content_h known - $inner_h=='auto' && $bbox_top =='auto'
  11772. }
  11773. else if ($bbox_top==='auto' && $bbox_bottom==='auto' && $inner_h!=='auto') {
  11774. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  11775. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11776. }
  11777. else if ($inner_h==='auto' && $bbox_bottom==='auto' && $bbox_top!=='auto') {
  11778. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11779. }
  11780. else if ($bbox_top==='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  11781. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  11782. }
  11783. else if ($inner_h==='auto' && $bbox_top!=='auto' && $bbox_bottom!=='auto') {
  11784. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  11785. }
  11786. else if ($bbox_bottom==='auto' && $bbox_top!=='auto' && $inner_h!=='auto') {
  11787. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11788. }
  11789. }
  11790. // THEN DO SAME FOR WIDTH
  11791. // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width
  11792. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right==='auto') {
  11793. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  11794. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  11795. // IF containing element RTL, should set $bbox_right
  11796. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  11797. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  11798. }
  11799. else if ($bbox_left!=='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  11800. if ($bbox_ml==='auto' && $bbox_mr==='auto') {
  11801. $x = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  11802. $bbox_ml = $bbox_mr = ($x/2);
  11803. }
  11804. else if ($bbox_ml==='auto') {
  11805. $bbox_ml = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  11806. }
  11807. else if ($bbox_mr==='auto') {
  11808. $bbox_mr = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  11809. }
  11810. else {
  11811. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11812. }
  11813. }
  11814. else {
  11815. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  11816. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  11817. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right!=='auto') {
  11818. // solve for $bbox_left when content_w known - $inner_w=='auto' && $bbox_left =='auto'
  11819. }
  11820. else if ($bbox_left==='auto' && $bbox_right==='auto' && $inner_w!=='auto') {
  11821. // IF containing element RTL, should set $bbox_right
  11822. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  11823. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11824. }
  11825. else if ($inner_w==='auto' && $bbox_right==='auto' && $bbox_left!=='auto') {
  11826. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  11827. }
  11828. else if ($bbox_left==='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  11829. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11830. }
  11831. else if ($inner_w==='auto' && $bbox_left!=='auto' && $bbox_right!=='auto') {
  11832. $inner_w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11833. }
  11834. else if ($bbox_right==='auto' && $bbox_left!=='auto' && $inner_w!=='auto') {
  11835. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11836. }
  11837. }
  11838. //================================================================
  11839. //================================================================
  11840. /*-- BACKGROUNDS --*/
  11841. if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) {
  11842. $ret = $this->SetBackground($pb, $this->blk[1]['inner_width']);
  11843. if ($ret) { $this->blk[1]['background-image'] = $ret; }
  11844. }
  11845. /*-- END BACKGROUNDS --*/
  11846. //================================================================
  11847. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  11848. $h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11849. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  11850. $w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  11851. // Set (temporary) values for x y w h to do first paint, if values are auto
  11852. if ($inner_h==='auto' && $bbox_top==='auto') {
  11853. $y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt;
  11854. $h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  11855. }
  11856. else if ($inner_h==='auto' && $bbox_bottom==='auto') {
  11857. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  11858. $h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  11859. }
  11860. if ($inner_w==='auto' && $bbox_left==='auto') {
  11861. $x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl;
  11862. $w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  11863. }
  11864. else if ($inner_w==='auto' && $bbox_right==='auto') {
  11865. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  11866. $w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  11867. }
  11868. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11869. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11870. $saved_block1 = $this->blk[1];
  11871. unset($p);
  11872. unset($pb);
  11873. //================================================================
  11874. if ($inner_w==='auto') { // do a first write
  11875. $this->lMargin=$x;
  11876. $this->rMargin=$this->w - $w - $x;
  11877. // SET POSITION & FONT VALUES
  11878. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11879. $this->pageoutput[$this->page]=array();
  11880. $this->x = $x;
  11881. $this->y = $y;
  11882. $this->HTMLheaderPageLinks = array();
  11883. $this->HTMLheaderPageAnnots = array();
  11884. $this->HTMLheaderPageForms = array();
  11885. $this->pageBackgrounds = array();
  11886. $this->maxPosR = 0;
  11887. $this->maxPosL = $this->w; // For RTL
  11888. $this->WriteHTML($html , 4);
  11889. $inner_w = $this->maxPosR - $this->lMargin;
  11890. if ($bbox_right==='auto') {
  11891. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11892. }
  11893. else if ($bbox_left==='auto') {
  11894. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11895. $bbox_x = $cont_x + $bbox_left + $bbox_ml ;
  11896. $inner_x = $bbox_x + $bbox_bl + $bbox_pl;
  11897. $x = $inner_x;
  11898. }
  11899. $w = $inner_w;
  11900. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11901. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11902. }
  11903. if ($inner_h==='auto') { // do a first write
  11904. $this->lMargin=$x;
  11905. $this->rMargin=$this->w - $w - $x;
  11906. // SET POSITION & FONT VALUES
  11907. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11908. $this->pageoutput[$this->page]=array();
  11909. $this->x = $x;
  11910. $this->y = $y;
  11911. $this->HTMLheaderPageLinks = array();
  11912. $this->HTMLheaderPageAnnots = array();
  11913. $this->HTMLheaderPageForms = array();
  11914. $this->pageBackgrounds = array();
  11915. $this->WriteHTML($html , 4);
  11916. $inner_h = $this->y - $y;
  11917. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11918. if (($this->y + $bbox_pb + $bbox_bb) > ($cont_y + $cont_h)) {
  11919. $adj = ($this->y + $bbox_pb + $bbox_bb) - ($cont_y + $cont_h);
  11920. $inner_h -= $adj;
  11921. }
  11922. }
  11923. if ($bbox_bottom==='auto' && $bbox_top_orig==='auto') {
  11924. $bbox_bottom = $bbox_top = ($cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb)/2;
  11925. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11926. if ($bbox_top < 0) {
  11927. $bbox_top = 0;
  11928. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11929. }
  11930. }
  11931. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11932. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  11933. $y = $inner_y;
  11934. }
  11935. else if ($bbox_bottom==='auto') {
  11936. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb;
  11937. }
  11938. else if ($bbox_top==='auto') {
  11939. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11940. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11941. if ($bbox_top < 0) {
  11942. $bbox_top = 0;
  11943. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11944. }
  11945. }
  11946. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11947. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  11948. $y = $inner_y;
  11949. }
  11950. $h = $inner_h;
  11951. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11952. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11953. }
  11954. $inner_w = $w;
  11955. $inner_h = $h;
  11956. }
  11957. $this->lMargin=$x;
  11958. $this->rMargin=$this->w - $w - $x;
  11959. // SET POSITION & FONT VALUES
  11960. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11961. $this->pageoutput[$this->page]=array();
  11962. $this->x = $x;
  11963. $this->y = $y;
  11964. $this->HTMLheaderPageLinks = array();
  11965. $this->HTMLheaderPageAnnots = array();
  11966. $this->HTMLheaderPageForms = array();
  11967. $this->pageBackgrounds = array();
  11968. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  11969. $actual_h = $this->y - $y;
  11970. $use_w = $w;
  11971. $use_h = $h;
  11972. $ratio = $actual_h / $use_w;
  11973. if ($overflow!='hidden' && $overflow!='visible') {
  11974. $target = $h/$w;
  11975. if (($ratio / $target ) > 1) {
  11976. $nl = CEIL($actual_h / $this->lineheight);
  11977. $l = $use_w * $nl;
  11978. $est_w = sqrt(($l * $this->lineheight) / $target) * 0.8;
  11979. $use_w += ($est_w - $use_w) - ($w/100);
  11980. }
  11981. $bpcstart = ($ratio / $target);
  11982. $bpcctr = 1;
  11983. while(($ratio / $target ) > 1) {
  11984. if ($this->progressBar) { $this->UpdateProgressBar(4,intval(100/($ratio/$target)),('Auto-sizing fixed-position block: '.$bpcctr++)); } // *PROGRESS-BAR*
  11985. $this->x = $x;
  11986. $this->y = $y;
  11987. if (($ratio / $target) > 1.5 || ($ratio / $target) < 0.6) {
  11988. $use_w += ($w/$this->incrementFPR1);
  11989. }
  11990. else if (($ratio / $target) > 1.2 || ($ratio / $target) < 0.85) {
  11991. $use_w += ($w/$this->incrementFPR2);
  11992. }
  11993. else if (($ratio / $target) > 1.1 || ($ratio / $target) < 0.91) {
  11994. $use_w += ($w/$this->incrementFPR3);
  11995. }
  11996. else {
  11997. $use_w += ($w/$this->incrementFPR4);
  11998. }
  11999. $use_h = $use_w * $target ;
  12000. $this->rMargin=$this->w - $use_w - $x;
  12001. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12002. $this->HTMLheaderPageLinks = array();
  12003. $this->HTMLheaderPageAnnots = array();
  12004. $this->HTMLheaderPageForms = array();
  12005. $this->pageBackgrounds = array();
  12006. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  12007. $actual_h = $this->y - $y;
  12008. $ratio = $actual_h / $use_w;
  12009. }
  12010. if ($this->progressBar) { $this->UpdateProgressBar(4,'100',' '); } // *PROGRESS-BAR*
  12011. }
  12012. $shrink_f = $w/$use_w;
  12013. //================================================================
  12014. $this->pages[$this->page] .= '___BEFORE_BORDERS___';
  12015. $block_s = $this->PrintPageBackgrounds(); // Save to print later inside clipping path
  12016. $this->pageBackgrounds = array();
  12017. //================================================================
  12018. if ($rotate) {
  12019. $prerotw = $bbox_bl + $bbox_pl + $inner_w + $bbox_pr + $bbox_br;
  12020. $preroth = $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb;
  12021. $rot_start = " q\n";
  12022. if ($rotate == 90) {
  12023. if ($rot_rpos !== false) { $adjw = $prerotw; } // width before rotation
  12024. else { $adjw = $preroth; } // height before rotation
  12025. if ($rot_bpos !== false) { $adjh = -$prerotw + $preroth; }
  12026. else { $adjh = 0; }
  12027. }
  12028. else {
  12029. if ($rot_rpos !== false) { $adjw = $prerotw - $preroth; }
  12030. else { $adjw = 0; }
  12031. if ($rot_bpos !== false) { $adjh = $preroth; } // height before rotation
  12032. else { $adjh = $prerotw; } // width before rotation
  12033. }
  12034. $rot_start .= $this->transformTranslate($adjw, $adjh, true)."\n";
  12035. $rot_start .= $this->transformRotate($rotate, $bbox_x, $bbox_y, true)."\n";
  12036. $rot_end = " Q\n";
  12037. }
  12038. else {
  12039. $rot_start = '';
  12040. $rot_end = '';
  12041. }
  12042. //================================================================
  12043. if (!empty($bounding)) {
  12044. // WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the bottom
  12045. // Re-instate saved $this->blk[1]
  12046. $this->blk[1] = $saved_block1;
  12047. // These are only needed when painting border/background
  12048. $this->blk[1]['width'] = $bbox_w = $cont_w - $bbox_left - $bbox_ml - $bbox_mr - $bbox_right;
  12049. $this->blk[1]['x0'] = $bbox_x;
  12050. $this->blk[1]['y0'] = $bbox_y;
  12051. $this->blk[1]['startpage'] = $this->page;
  12052. $this->blk[1]['y1'] = $bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ;
  12053. $this->_out($rot_start); // mPDF 5.0
  12054. $this->PaintDivBB('',0,1); // Prints borders and sets backgrounds in $this->pageBackgrounds
  12055. $this->_out($rot_end);
  12056. }
  12057. $s = $this->PrintPageBackgrounds();
  12058. $s = $rot_start.$s.$rot_end;
  12059. $this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n".$s."\n", $this->pages[$this->page]);
  12060. $this->pageBackgrounds = array();
  12061. $this->_out($rot_start);
  12062. // Clipping Output
  12063. if ($overflow=='hidden') {
  12064. //Bounding rectangle to clip
  12065. $clip_y1 = $this->y;
  12066. if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) > ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) {
  12067. $clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb);
  12068. }
  12069. //$op = 'W* n'; // Clipping
  12070. $op = 'W n'; // Clipping alternative mode
  12071. $this->_out("q");
  12072. $ch = $clip_y1 - $y;
  12073. $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op));
  12074. if (!empty($block_s)) {
  12075. $tmp = "q\n".sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op);
  12076. $tmp .= "\n".$block_s."\nQ";
  12077. $block_s = $tmp ;
  12078. }
  12079. }
  12080. if (!empty($block_s)) {
  12081. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12082. $tmp = "q\n".$this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y, true);
  12083. $tmp .= "\n".$block_s."\nQ";
  12084. $block_s = $tmp ;
  12085. }
  12086. $this->_out($block_s);
  12087. }
  12088. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12089. $this->StartTransform();
  12090. $this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y);
  12091. }
  12092. $this->_out($this->headerbuffer);
  12093. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12094. $this->StopTransform();
  12095. }
  12096. if ($overflow=='hidden') {
  12097. //End clipping
  12098. $this->_out("Q");
  12099. }
  12100. $this->_out($rot_end);
  12101. // Page Links
  12102. foreach($this->HTMLheaderPageLinks AS $lk) {
  12103. if ($rotate) {
  12104. $tmp = $lk[2]; // Switch h - w
  12105. $lk[2] = $lk[3];
  12106. $lk[3] = $tmp;
  12107. $lx1 = (($lk[0]/_MPDFK));
  12108. $ly1 = (($this->h-($lk[1]/_MPDFK)));
  12109. if ($rotate == 90) {
  12110. $adjx = -($lx1-$bbox_x) + ($preroth - ($ly1-$bbox_y));
  12111. $adjy = -($ly1-$bbox_y) + ($lx1-$bbox_x);
  12112. $lk[2] = -$lk[2];
  12113. }
  12114. else if ($rotate == -90) {
  12115. $adjx = -($lx1-$bbox_x) + ($ly1-$bbox_y);
  12116. $adjy = -($ly1-$bbox_y) - ($lx1-$bbox_x) + $prerotw;
  12117. $lk[3] = -$lk[3];
  12118. }
  12119. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12120. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12121. $lx1 += $adjx;
  12122. $ly1 += $adjy;
  12123. $lk[0] = $lx1*_MPDFK;
  12124. $lk[1] = ($this->h-$ly1)*_MPDFK;
  12125. }
  12126. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12127. $lx1 = (($lk[0]/_MPDFK)-$x);
  12128. $lx2 = $x + ($lx1 * $shrink_f);
  12129. $lk[0] = $lx2*_MPDFK;
  12130. $ly1 = (($this->h-($lk[1]/_MPDFK))-$y);
  12131. $ly2 = $y + ($ly1 * $shrink_f);
  12132. $lk[1] = ($this->h-$ly2)*_MPDFK;
  12133. $lk[2] *= $shrink_f; // width
  12134. $lk[3] *= $shrink_f; // height
  12135. }
  12136. $this->PageLinks[$this->page][]=$lk;
  12137. }
  12138. foreach($this->HTMLheaderPageForms AS $n=>$f) {
  12139. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12140. $f['x'] = $x + (($f['x'] -$x) * $shrink_f);
  12141. $f['y'] = $y + (($f['y'] -$y) * $shrink_f);
  12142. $f['w'] *= $shrink_f;
  12143. $f['h'] *= $shrink_f;
  12144. $f['style']['fontsize'] *= $shrink_f;
  12145. }
  12146. $this->form->forms[$f['n']] = $f;
  12147. }
  12148. // Page Annotations
  12149. foreach($this->HTMLheaderPageAnnots AS $lk) {
  12150. if ($rotate) {
  12151. if ($rotate == 90) {
  12152. $adjx = -($lk['x']-$bbox_x) + ($preroth - ($lk['y']-$bbox_y));
  12153. $adjy = -($lk['y']-$bbox_y) + ($lk['x']-$bbox_x);
  12154. }
  12155. else if ($rotate == -90) {
  12156. $adjx = -($lk['x']-$bbox_x) + ($lk['y']-$bbox_y);
  12157. $adjy = -($lk['y']-$bbox_y) - ($lk['x']-$bbox_x) + $prerotw;
  12158. }
  12159. if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; }
  12160. if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; }
  12161. $lk['x'] += $adjx;
  12162. $lk['y'] += $adjy;
  12163. }
  12164. if ($shrink_f != 1) { // i.e. autofit has resized the box
  12165. $lk['x'] = $x + (($lk['x']-$x) * $shrink_f);
  12166. $lk['y'] = $y + (($lk['y']-$y) * $shrink_f);
  12167. }
  12168. $this->PageAnnots[$this->page][]=$lk;
  12169. }
  12170. // Restore
  12171. $this->headerbuffer = '';
  12172. $this->HTMLheaderPageLinks = array();
  12173. $this->HTMLheaderPageAnnots = array();
  12174. $this->HTMLheaderPageForms = array();
  12175. $this->pageBackgrounds = $save_bgs;
  12176. $this->writingHTMLheader = false;
  12177. $this->writingHTMLfooter = false;
  12178. $this->fullImageHeight = false;
  12179. $this->ResetMargins();
  12180. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  12181. $this->SetXY($save_x,$save_y) ;
  12182. $this->title2annots = $save_annots; // *ANNOTATIONS*
  12183. $this->InFooter = false; // turns back on autopagebreaks
  12184. $this->pageoutput[$this->page]=array();
  12185. $this->pageoutput[$this->page]['Font']='';
  12186. /*-- COLUMNS --*/
  12187. if ($save_cols) {
  12188. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  12189. }
  12190. /*-- END COLUMNS --*/
  12191. }
  12192. /*-- END CSS-POSITION --*/
  12193. function initialiseBlock(&$blk) {
  12194. $blk['margin_top'] = 0;
  12195. $blk['margin_left'] = 0;
  12196. $blk['margin_bottom'] = 0;
  12197. $blk['margin_right'] = 0;
  12198. $blk['padding_top'] = 0;
  12199. $blk['padding_left'] = 0;
  12200. $blk['padding_bottom'] = 0;
  12201. $blk['padding_right'] = 0;
  12202. $blk['border_top']['w'] = 0;
  12203. $blk['border_left']['w'] = 0;
  12204. $blk['border_bottom']['w'] = 0;
  12205. $blk['border_right']['w'] = 0;
  12206. $blk['hide'] = false;
  12207. $blk['outer_left_margin'] = 0;
  12208. $blk['outer_right_margin'] = 0;
  12209. $blk['cascadeCSS'] = array();
  12210. $blk['block-align'] = false;
  12211. $blk['bgcolor'] = false;
  12212. $blk['page_break_after_avoid'] = false;
  12213. $blk['keep_block_together'] = false;
  12214. $blk['float'] = false;
  12215. $blk['line_height'] = '';
  12216. $blk['margin_collapse'] = false;
  12217. }
  12218. function border_details($bd) {
  12219. $prop = preg_split('/\s+/',trim($bd));
  12220. if (isset($this->blk[$this->blklvl]['inner_width'])) { $refw = $this->blk[$this->blklvl]['inner_width']; }
  12221. else if (isset($this->blk[$this->blklvl-1]['inner_width'])) { $refw = $this->blk[$this->blklvl-1]['inner_width']; }
  12222. else { $refw = $this->w; }
  12223. if ( count($prop) == 1 ) {
  12224. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  12225. if ($bsize > 0) {
  12226. return array('s' => 1, 'w' => $bsize, 'c' => $this->ConvertColor(0), 'style'=>'solid');
  12227. }
  12228. else { return array('w' => 0, 's' => 0); }
  12229. }
  12230. else if (count($prop) == 2 ) {
  12231. // 1px solid
  12232. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $prop[2] = ''; }
  12233. // solid #000000
  12234. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $prop[0] = ''; $prop[1] = $prop[0]; $prop[2] = $prop[1]; }
  12235. // 1px #000000
  12236. else { $prop[1] = ''; $prop[2] = $prop[1]; }
  12237. }
  12238. else if ( count($prop) == 3 ) {
  12239. // Change #000000 1px solid to 1px solid #000000 (proper)
  12240. if (substr($prop[0],0,1) == '#') { $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $prop[2]; $prop[2] = $tmp; }
  12241. // Change solid #000000 1px to 1px solid #000000 (proper)
  12242. else if (substr($prop[0],1,1) == '#') { $tmp = $prop[1]; $prop[0] = $prop[2]; $prop[1] = $prop[0]; $prop[2] = $tmp; }
  12243. // Change solid 1px #000000 to 1px solid #000000 (proper)
  12244. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  12245. $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $tmp;
  12246. }
  12247. }
  12248. else { return array(); }
  12249. // Size
  12250. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  12251. //color
  12252. $coul = $this->ConvertColor($prop[2]); // returns array
  12253. // Style
  12254. $prop[1] = strtolower($prop[1]);
  12255. if (in_array($prop[1],$this->borderstyles) && $bsize > 0) { $on = 1; }
  12256. else if ($prop[1] == 'hidden') { $on = 1; $bsize = 0; $coul = ''; }
  12257. else if ($prop[1] == 'none') { $on = 0; $bsize = 0; $coul = ''; }
  12258. else { $on = 0; $bsize = 0; $coul = ''; $prop[1] = ''; }
  12259. return array('s' => $on, 'w' => $bsize, 'c' => $coul, 'style'=> $prop[1] );
  12260. }
  12261. function _fix_borderStr($bd) {
  12262. // mPDF 5.5.04
  12263. preg_match_all("/\((.*?)\)/", $bd, $m);
  12264. if (count($m[1])) {
  12265. for($i=0;$i<count($m[1]);$i++) {
  12266. $sub = preg_replace("/ /", "", $m[1][$i]);
  12267. $bd = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $bd);
  12268. }
  12269. }
  12270. $prop = preg_split('/\s+/',trim($bd));
  12271. $w = 'medium';
  12272. $c = '#000000';
  12273. $s = 'none';
  12274. if ( count($prop) == 1 ) {
  12275. // solid
  12276. if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; }
  12277. // #000000
  12278. else if (is_array($this->ConvertColor($prop[0]))) { $c = $prop[0]; }
  12279. // 1px
  12280. else { $w = $prop[0]; }
  12281. }
  12282. else if (count($prop) == 2 ) {
  12283. // 1px solid
  12284. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; }
  12285. // solid #000000
  12286. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; }
  12287. // 1px #000000
  12288. else { $w = $prop[0]; $c = $prop[1]; }
  12289. }
  12290. else if ( count($prop) == 3 ) {
  12291. // Change #000000 1px solid to 1px solid #000000 (proper)
  12292. if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; }
  12293. // Change solid #000000 1px to 1px solid #000000 (proper)
  12294. else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; }
  12295. // Change solid 1px #000000 to 1px solid #000000 (proper)
  12296. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  12297. $s = $prop[0]; $w = $prop[1]; $c = $prop[2];
  12298. }
  12299. else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; }
  12300. }
  12301. else { return ''; }
  12302. $s = strtolower($s);
  12303. return $w.' '.$s.' '.$c;
  12304. }
  12305. // NEW FUNCTION FOR CSS MARGIN or PADDING called from SetCSS
  12306. function fixCSS($prop) {
  12307. if (!is_array($prop) || (count($prop)==0)) return array();
  12308. $newprop = array();
  12309. foreach($prop AS $k => $v) {
  12310. if ($k != 'BACKGROUND-IMAGE' && $k != 'BACKGROUND' && $k != 'ODD-HEADER-NAME' && $k != 'EVEN-HEADER-NAME' && $k != 'ODD-FOOTER-NAME' && $k != 'EVEN-FOOTER-NAME' && $k != 'HEADER' && $k != 'FOOTER') {
  12311. $v = strtolower($v);
  12312. }
  12313. if ($k == 'FONT') {
  12314. $s = trim($v);
  12315. preg_match_all('/\"(.*?)\"/',$s,$ff);
  12316. if (count($ff[1])) {
  12317. foreach($ff[1] AS $ffp) {
  12318. $w = preg_split('/\s+/',$ffp);
  12319. $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s);
  12320. }
  12321. }
  12322. preg_match_all('/\'(.*?)\'/',$s,$ff);
  12323. if (count($ff[1])) {
  12324. foreach($ff[1] AS $ffp) {
  12325. $w = preg_split('/\s+/',$ffp);
  12326. $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s);
  12327. }
  12328. }
  12329. $s = preg_replace('/\s*,\s*/',',',$s);
  12330. $bits = preg_split('/\s+/',$s);
  12331. if (count($bits)>1) {
  12332. $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)];
  12333. $fs = $bits[(count($bits)-2)];
  12334. if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) {
  12335. $newprop['FONT-SIZE'] = $fsp[1];
  12336. $newprop['LINE-HEIGHT'] = $fsp[2];
  12337. }
  12338. else { $newprop['FONT-SIZE'] = $fs; }
  12339. if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; }
  12340. else { $newprop['FONT-STYLE'] = 'normal'; }
  12341. if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; }
  12342. else { $newprop['FONT-WEIGHT'] = 'normal'; }
  12343. if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; }
  12344. }
  12345. }
  12346. if ($k == 'FONT-FAMILY') {
  12347. $aux_fontlist = explode(",",$v);
  12348. $found = 0;
  12349. foreach($aux_fontlist AS $f) {
  12350. $fonttype = trim($f);
  12351. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  12352. $fonttype = preg_replace('/ /','',$fonttype);
  12353. $v = strtolower(trim($fonttype));
  12354. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  12355. if ((!$this->onlyCoreFonts && in_array($v,$this->available_unifonts)) ||
  12356. in_array($v,array('ccourier','ctimes','chelvetica')) ||
  12357. ($this->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
  12358. in_array($v, array('sjis','uhc','big5','gb'))) {
  12359. $newprop[$k] = $v;
  12360. $found = 1;
  12361. break;
  12362. }
  12363. }
  12364. if (!$found) {
  12365. foreach($aux_fontlist AS $f) {
  12366. $fonttype = trim($f);
  12367. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  12368. $fonttype = preg_replace('/ /','',$fonttype);
  12369. $v = strtolower(trim($fonttype));
  12370. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  12371. if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  12372. $newprop[$k] = $v;
  12373. break;
  12374. }
  12375. }
  12376. }
  12377. }
  12378. else if ($k == 'MARGIN') {
  12379. $tmp = $this->expand24($v);
  12380. $newprop['MARGIN-TOP'] = $tmp['T'];
  12381. $newprop['MARGIN-RIGHT'] = $tmp['R'];
  12382. $newprop['MARGIN-BOTTOM'] = $tmp['B'];
  12383. $newprop['MARGIN-LEFT'] = $tmp['L'];
  12384. }
  12385. /*-- BORDER-RADIUS --*/
  12386. else if ($k == 'BORDER-RADIUS' || $k == 'BORDER-TOP-LEFT-RADIUS' || $k == 'BORDER-TOP-RIGHT-RADIUS' || $k == 'BORDER-BOTTOM-LEFT-RADIUS' || $k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  12387. $tmp = $this->border_radius_expand($v,$k);
  12388. if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
  12389. if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
  12390. if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
  12391. if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
  12392. if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
  12393. if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
  12394. if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
  12395. if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
  12396. }
  12397. /*-- END BORDER-RADIUS --*/
  12398. else if ($k == 'PADDING') {
  12399. $tmp = $this->expand24($v);
  12400. $newprop['PADDING-TOP'] = $tmp['T'];
  12401. $newprop['PADDING-RIGHT'] = $tmp['R'];
  12402. $newprop['PADDING-BOTTOM'] = $tmp['B'];
  12403. $newprop['PADDING-LEFT'] = $tmp['L'];
  12404. }
  12405. else if ($k == 'BORDER') {
  12406. if ($v == '1') { $v = '1px solid #000000'; }
  12407. else { $v = $this->_fix_borderStr($v); }
  12408. $newprop['BORDER-TOP'] = $v;
  12409. $newprop['BORDER-RIGHT'] = $v;
  12410. $newprop['BORDER-BOTTOM'] = $v;
  12411. $newprop['BORDER-LEFT'] = $v;
  12412. }
  12413. else if ($k == 'BORDER-TOP') {
  12414. $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
  12415. }
  12416. else if ($k == 'BORDER-RIGHT') {
  12417. $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
  12418. }
  12419. else if ($k == 'BORDER-BOTTOM') {
  12420. $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
  12421. }
  12422. else if ($k == 'BORDER-LEFT') {
  12423. $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
  12424. }
  12425. else if ($k == 'BORDER-STYLE') {
  12426. $e = $this->expand24($v);
  12427. $newprop['BORDER-TOP-STYLE'] = $e['T'];
  12428. $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
  12429. $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
  12430. $newprop['BORDER-LEFT-STYLE'] = $e['L'];
  12431. }
  12432. else if ($k == 'BORDER-WIDTH') {
  12433. $e = $this->expand24($v);
  12434. $newprop['BORDER-TOP-WIDTH'] = $e['T'];
  12435. $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
  12436. $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
  12437. $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
  12438. }
  12439. else if ($k == 'BORDER-COLOR') {
  12440. $e = $this->expand24($v);
  12441. $newprop['BORDER-TOP-COLOR'] = $e['T'];
  12442. $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
  12443. $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
  12444. $newprop['BORDER-LEFT-COLOR'] = $e['L'];
  12445. }
  12446. else if ($k == 'BORDER-SPACING') {
  12447. $prop = preg_split('/\s+/',trim($v));
  12448. if (count($prop) == 1 ) {
  12449. $newprop['BORDER-SPACING-H'] = $prop[0];
  12450. $newprop['BORDER-SPACING-V'] = $prop[0];
  12451. }
  12452. else if (count($prop) == 2 ) {
  12453. $newprop['BORDER-SPACING-H'] = $prop[0];
  12454. $newprop['BORDER-SPACING-V'] = $prop[1];
  12455. }
  12456. }
  12457. else if ($k == 'SIZE') {
  12458. $prop = preg_split('/\s+/',trim($v));
  12459. if (preg_match('/(auto|portrait|landscape)/',$prop[0])) {
  12460. $newprop['SIZE'] = strtoupper($prop[0]);
  12461. }
  12462. else if (count($prop) == 1 ) {
  12463. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  12464. $newprop['SIZE']['H'] = $this->ConvertSize($prop[0]);
  12465. }
  12466. else if (count($prop) == 2 ) {
  12467. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  12468. $newprop['SIZE']['H'] = $this->ConvertSize($prop[1]);
  12469. }
  12470. }
  12471. else if ($k == 'SHEET-SIZE') {
  12472. $prop = preg_split('/\s+/',trim($v));
  12473. if (count($prop) == 2 ) {
  12474. $newprop['SHEET-SIZE'] = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  12475. }
  12476. else {
  12477. if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape
  12478. $ft = $this->_getPageFormat($m[1]);
  12479. $format = array($ft[1],$ft[0]);
  12480. }
  12481. else { $format = $this->_getPageFormat($v); }
  12482. if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/_MPDFK, $format[1]/_MPDFK); }
  12483. }
  12484. }
  12485. else if ($k == 'BACKGROUND') {
  12486. $bg = $this->parseCSSbackground($v);
  12487. if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; }
  12488. else { $newprop['BACKGROUND-COLOR'] = 'transparent'; }
  12489. /*-- BACKGROUNDS --*/
  12490. if ($bg['i']) {
  12491. $newprop['BACKGROUND-IMAGE'] = $bg['i'];
  12492. if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; }
  12493. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  12494. }
  12495. else { $newprop['BACKGROUND-IMAGE'] = ''; }
  12496. /*-- END BACKGROUNDS --*/
  12497. }
  12498. /*-- BACKGROUNDS --*/
  12499. else if ($k == 'BACKGROUND-IMAGE') {
  12500. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$v,$m)) {
  12501. $newprop['BACKGROUND-IMAGE'] = $m[0];
  12502. continue;
  12503. }
  12504. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
  12505. $newprop['BACKGROUND-IMAGE'] = $m[1];
  12506. }
  12507. else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; }
  12508. }
  12509. else if ($k == 'BACKGROUND-REPEAT') {
  12510. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) {
  12511. $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
  12512. }
  12513. }
  12514. else if ($k == 'BACKGROUND-POSITION') {
  12515. $s = $v;
  12516. $bits = preg_split('/\s+/',trim($s));
  12517. // These should be Position x1 or x2
  12518. if (count($bits)==1) {
  12519. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  12520. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  12521. else { $bg['p'] = $bits[0] . ' 50%'; }
  12522. }
  12523. else if (count($bits)==2) {
  12524. // Can be either right center or center right
  12525. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  12526. $bg['p'] = $bits[1] . ' '.$bits[0];
  12527. }
  12528. else {
  12529. $bg['p'] = $bits[0] . ' '.$bits[1];
  12530. }
  12531. }
  12532. if ($bg['p']) {
  12533. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  12534. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  12535. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  12536. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
  12537. $bg['p'] = false;
  12538. }
  12539. }
  12540. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  12541. }
  12542. /*-- END BACKGROUNDS --*/
  12543. else if ($k == 'IMAGE-ORIENTATION') {
  12544. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$v,$m)) {
  12545. $angle = $m[1] + 0;
  12546. if (strtolower($m[2])=='deg') { $angle = $angle; }
  12547. else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
  12548. else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
  12549. while($angle < 0) { $angle += 360; }
  12550. $angle = ($angle % 360);
  12551. $angle /= 90;
  12552. $angle = round($angle) * 90;
  12553. $newprop['IMAGE-ORIENTATION'] = $angle;
  12554. }
  12555. }
  12556. else {
  12557. $newprop[$k] = $v;
  12558. }
  12559. }
  12560. return $newprop;
  12561. }
  12562. function setCSSboxshadow($v) {
  12563. $sh = array();
  12564. $c = preg_match_all('/(rgba|rgb|cmyka|cmyk|hsla|hsl)\(.*?\)/',$v,$x);
  12565. for($i=0; $i<$c; $i++) {
  12566. $col = preg_replace('/,/','*',$x[0][$i]);
  12567. $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
  12568. }
  12569. $ss = explode(',',$v);
  12570. foreach ($ss AS $s) {
  12571. $new = array('inset'=>false, 'blur'=>0, 'spread'=>0);
  12572. if (preg_match('/inset/i',$s)) { $new['inset'] = true; $s = preg_replace('/\s*inset\s*/','',$s); }
  12573. $p = explode(' ',trim($s));
  12574. if (isset($p[0])) { $new['x'] = $this->ConvertSize(trim($p[0]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12575. if (isset($p[1])) { $new['y'] = $this->ConvertSize(trim($p[1]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12576. if (isset($p[2])) {
  12577. if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
  12578. $new['blur'] = $this->ConvertSize(trim($p[2]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  12579. }
  12580. else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[2])); }
  12581. if (isset($p[3])) {
  12582. if (preg_match('/^\s*[\.\-0-9]/',$p[3])) {
  12583. $new['spread'] = $this->ConvertSize(trim($p[3]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  12584. }
  12585. else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[3])); }
  12586. if (isset($p[4])) {
  12587. $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[4]));
  12588. }
  12589. }
  12590. }
  12591. if (!$new['col']) { $new['col'] = $this->ConvertColor('#888888'); }
  12592. if (isset($new['y'])) { array_unshift($sh, $new); }
  12593. }
  12594. return $sh;
  12595. }
  12596. function setCSStextshadow($v) {
  12597. $sh = array();
  12598. $c = preg_match_all('/(rgba|rgb|cmyka|cmyk|hsla|hsl)\(.*?\)/',$v,$x);
  12599. for($i=0; $i<$c; $i++) {
  12600. $col = preg_replace('/,/','*',$x[0][$i]);
  12601. $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
  12602. }
  12603. $ss = explode(',',$v);
  12604. foreach ($ss AS $s) {
  12605. $new = array('blur'=>0);
  12606. $p = explode(' ',trim($s));
  12607. if (isset($p[0])) { $new['x'] = $this->ConvertSize(trim($p[0]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12608. if (isset($p[1])) { $new['y'] = $this->ConvertSize(trim($p[1]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); }
  12609. if (isset($p[2])) {
  12610. if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
  12611. $new['blur'] = $this->ConvertSize(trim($p[2]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  12612. }
  12613. else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[2])); }
  12614. if (isset($p[3])) {
  12615. $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[3]));
  12616. }
  12617. }
  12618. if (!$new['col']) { $new['col'] = $this->ConvertColor('#888888'); }
  12619. if (isset($new['y'])) { array_unshift($sh, $new); }
  12620. }
  12621. return $sh;
  12622. }
  12623. function parseCSSbackground($s) {
  12624. $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, );
  12625. /*-- BACKGROUNDS --*/
  12626. if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$s,$m)) {
  12627. $bg['i'] = $m[0];
  12628. }
  12629. else
  12630. /*-- END BACKGROUNDS --*/
  12631. if (preg_match('/url\(/i',$s)) {
  12632. // If color, set and strip it off
  12633. if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i',$s,$m)) {
  12634. $bg['c'] = strtolower($m[1]);
  12635. $s = $m[3];
  12636. }
  12637. /*-- BACKGROUNDS --*/
  12638. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) {
  12639. $bg['i'] = $m[1];
  12640. $s = strtolower($m[2]);
  12641. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) {
  12642. $bg['r'] = $m[1];
  12643. }
  12644. // Remove repeat, attachment (discarded) and also any inherit
  12645. $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s);
  12646. $bits = preg_split('/\s+/',trim($s));
  12647. // These should be Position x1 or x2
  12648. if (count($bits)==1) {
  12649. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  12650. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  12651. else { $bg['p'] = $bits[0] . ' 50%'; }
  12652. }
  12653. else if (count($bits)==2) {
  12654. // Can be either right center or center right
  12655. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  12656. $bg['p'] = $bits[1] . ' '.$bits[0];
  12657. }
  12658. else {
  12659. $bg['p'] = $bits[0] . ' '.$bits[1];
  12660. }
  12661. }
  12662. if ($bg['p']) {
  12663. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  12664. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  12665. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  12666. if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
  12667. $bg['p'] = false;
  12668. }
  12669. }
  12670. }
  12671. /*-- END BACKGROUNDS --*/
  12672. }
  12673. else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})/i',$s,$m)) { $bg['c'] = strtolower($m[1]); }
  12674. return ($bg);
  12675. }
  12676. function expand24($mp) {
  12677. $prop = preg_split('/\s+/',trim($mp));
  12678. if (count($prop) == 1 ) {
  12679. return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]);
  12680. }
  12681. if (count($prop) == 2 ) {
  12682. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]);
  12683. }
  12684. if (count($prop) == 3 ) {
  12685. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]);
  12686. }
  12687. if (count($prop) == 4 ) {
  12688. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]);
  12689. }
  12690. return array();
  12691. }
  12692. /*-- BORDER-RADIUS --*/
  12693. function border_radius_expand($val,$k) {
  12694. $b = array();
  12695. if ($k == 'BORDER-RADIUS') {
  12696. $hv = explode('/',trim($val));
  12697. $prop = preg_split('/\s+/',trim($hv[0]));
  12698. if (count($prop)==1) {
  12699. $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
  12700. }
  12701. else if (count($prop)==2) {
  12702. $b['TL-H'] = $b['BR-H'] = $prop[0];
  12703. $b['TR-H'] = $b['BL-H'] = $prop[1];
  12704. }
  12705. else if (count($prop)==3) {
  12706. $b['TL-H'] = $prop[0];
  12707. $b['TR-H'] = $b['BL-H'] = $prop[1];
  12708. $b['BR-H'] = $prop[2];
  12709. }
  12710. else if (count($prop)==4) {
  12711. $b['TL-H'] = $prop[0];
  12712. $b['TR-H'] = $prop[1];
  12713. $b['BR-H'] = $prop[2];
  12714. $b['BL-H'] = $prop[3];
  12715. }
  12716. if (count($hv)==2) {
  12717. $prop = preg_split('/\s+/',trim($hv[1]));
  12718. if (count($prop)==1) {
  12719. $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
  12720. }
  12721. else if (count($prop)==2) {
  12722. $b['TL-V'] = $b['BR-V'] = $prop[0];
  12723. $b['TR-V'] = $b['BL-V'] = $prop[1];
  12724. }
  12725. else if (count($prop)==3) {
  12726. $b['TL-V'] = $prop[0];
  12727. $b['TR-V'] = $b['BL-V'] = $prop[1];
  12728. $b['BR-V'] = $prop[2];
  12729. }
  12730. else if (count($prop)==4) {
  12731. $b['TL-V'] = $prop[0];
  12732. $b['TR-V'] = $prop[1];
  12733. $b['BR-V'] = $prop[2];
  12734. $b['BL-V'] = $prop[3];
  12735. }
  12736. }
  12737. else {
  12738. $b['TL-V'] = $b['TL-H'];
  12739. $b['TR-V'] = $b['TR-H'];
  12740. $b['BL-V'] = $b['BL-H'];
  12741. $b['BR-V'] = $b['BR-H'];
  12742. }
  12743. return $b;
  12744. }
  12745. // Parse 2
  12746. $h = 0;
  12747. $v = 0;
  12748. $prop = preg_split('/\s+/',trim($val));
  12749. if (count($prop)==1) { $h = $v = $val; }
  12750. else { $h = $prop[0]; $v = $prop[1]; }
  12751. if ($h==0 || $v==0) { $h = $v = 0; }
  12752. if ($k == 'BORDER-TOP-LEFT-RADIUS') {
  12753. $b['TL-H'] = $h;
  12754. $b['TL-V'] = $v;
  12755. }
  12756. else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
  12757. $b['TR-H'] = $h;
  12758. $b['TR-V'] = $v;
  12759. }
  12760. else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
  12761. $b['BL-H'] = $h;
  12762. $b['BL-V'] = $v;
  12763. }
  12764. else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  12765. $b['BR-H'] = $h;
  12766. $b['BR-V'] = $v;
  12767. }
  12768. return $b;
  12769. }
  12770. /*-- END BORDER-RADIUS --*/
  12771. /*-- END HTML-CSS --*/
  12772. // Return either a number (factor) - based on current set fontsize (if % or em) - or exact lineheight (with 'mm' after it)
  12773. function fixLineheight($v) {
  12774. $lh = false;
  12775. if (preg_match('/^[0-9\.,]*$/',$v) && $v >= 0) { return ($v + 0); }
  12776. else if (strtoupper($v) == 'NORMAL') {
  12777. return $this->normalLineheight;
  12778. }
  12779. else {
  12780. $tlh = $this->ConvertSize($v,$this->FontSize,$this->FontSize,true);
  12781. if ($tlh) { return ($tlh.'mm'); }
  12782. }
  12783. return $this->normalLineheight;
  12784. }
  12785. /*-- BORDER-RADIUS --*/
  12786. function _borderPadding($a, $b, &$px, &$py) {
  12787. // $px and py are padding long axis (x) and short axis (y)
  12788. $added = 0; // extra padding
  12789. $x = $a-$px;
  12790. $y = $b-$py;
  12791. // Check if Falls within ellipse of border radius
  12792. if ( ( (($x+$added)*($x+$added))/($a*$a) + (($y+$added)*($y+$added))/($b*$b) ) <=1 ) { return false; }
  12793. $t = atan2($y,$x);
  12794. $newx = $b / sqrt((($b*$b)/($a*$a)) + ( tan($t) * tan($t) ) );
  12795. $newy = $a / sqrt((($a*$a)/($b*$b)) + ( (1/tan($t)) * (1/tan($t)) ) );
  12796. $px = max($px, $a - $newx + $added);
  12797. $py = max($py, $b - $newy + $added);
  12798. }
  12799. /*-- END BORDER-RADIUS --*/
  12800. /*-- TABLES --*/
  12801. function setBorderDominance($prop, $val) {
  12802. if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; }
  12803. if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; }
  12804. if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; }
  12805. if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; }
  12806. }
  12807. /*-- END TABLES --*/
  12808. /*-- HTML-CSS --*/
  12809. function _mergeCSS($p, &$t) {
  12810. // Save Cascading CSS e.g. "div.topic p" at this block level
  12811. if (isset($p) && $p) {
  12812. if ($t) {
  12813. $t = $this->array_merge_recursive_unique($t, $p);
  12814. }
  12815. else { $t = $p; }
  12816. }
  12817. }
  12818. // for CSS handling
  12819. function array_merge_recursive_unique($array1, $array2) {
  12820. $arrays = func_get_args();
  12821. $narrays = count($arrays);
  12822. $ret = $arrays[0];
  12823. for ($i = 1; $i < $narrays; $i ++) {
  12824. foreach ($arrays[$i] as $key => $value) {
  12825. if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
  12826. $ret[] = $value;
  12827. }
  12828. else { // string key - merge
  12829. if (is_array($value) && isset($ret[$key])) {
  12830. $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
  12831. }
  12832. else {
  12833. $ret[$key] = $value;
  12834. }
  12835. }
  12836. }
  12837. }
  12838. return $ret;
  12839. }
  12840. function _mergeFullCSS($p, &$t, $tag, $classes, $id) {
  12841. $this->_mergeCSS($p[$tag], $t);
  12842. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  12843. foreach($classes AS $class) {
  12844. $this->_mergeCSS($p['CLASS>>'.$class], $t);
  12845. }
  12846. // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
  12847. if ($tag=='TR' && isset($p) && $p) {
  12848. foreach($p AS $k=>$val) {
  12849. if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
  12850. $select = false;
  12851. if ($tag=='TR') {
  12852. $row = $this->row;
  12853. $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0);
  12854. $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0);
  12855. if ($this->tabletfoot) { $row -= $thnr; }
  12856. else if (!$this->tablethead) { $row -= ($thnr + $tfnr); }
  12857. if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; }
  12858. else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; }
  12859. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  12860. if ((($row + 1) % $a[1]) == $a[2]) { $select = true; }
  12861. }
  12862. }
  12863. else if ($tag=='TD' || $tag=='TH') {
  12864. if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; }
  12865. else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; }
  12866. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  12867. if ((($this->col + 1) % $a[1]) == $a[2]) { $select = true; }
  12868. }
  12869. }
  12870. if ($select) {
  12871. $this->_mergeCSS($p[$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $t);
  12872. }
  12873. }
  12874. }
  12875. }
  12876. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  12877. if (isset($id) && $id) {
  12878. $this->_mergeCSS($p['ID>>'.$id], $t);
  12879. }
  12880. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  12881. foreach($classes AS $class) {
  12882. $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t);
  12883. }
  12884. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  12885. if (isset($id)) {
  12886. $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t);
  12887. }
  12888. }
  12889. function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) {
  12890. if (isset($m)) {
  12891. if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth'
  12892. if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES*
  12893. if (is_array($m)) {
  12894. $p = array_merge($p,$m);
  12895. $this->_mergeBorders($p,$m);
  12896. }
  12897. }
  12898. }
  12899. }
  12900. function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
  12901. foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) {
  12902. foreach(array('STYLE','WIDTH','COLOR') AS $el) {
  12903. if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE']
  12904. $s = trim($a['BORDER-'.$side.'-'.$el]);
  12905. if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP']
  12906. $p = trim($b['BORDER-'.$side]);
  12907. }
  12908. else { $p = ''; }
  12909. if ($el=='STYLE') {
  12910. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); }
  12911. else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; }
  12912. }
  12913. else if ($el=='WIDTH') {
  12914. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); }
  12915. else { $b['BORDER-'.$side] = $s.' none #000000'; }
  12916. }
  12917. else if ($el=='COLOR') {
  12918. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); }
  12919. else { $b['BORDER-'.$side] = '0px none '.$s; }
  12920. }
  12921. }
  12922. }
  12923. }
  12924. }
  12925. function MergeCSS($inherit,$tag,$attr) {
  12926. $p = array();
  12927. $zp = array();
  12928. $classes = array();
  12929. if (isset($attr['CLASS'])) {
  12930. $classes = preg_split('/\s+/',$attr['CLASS']);
  12931. }
  12932. if (!isset($attr['ID'])) { $attr['ID']=''; }
  12933. //===============================================
  12934. /*-- TABLES --*/
  12935. // Set Inherited properties
  12936. if ($inherit == 'TOPTABLE') { // $tag = TABLE
  12937. //===============================================
  12938. // Save Cascading CSS e.g. "div.topic p" at this block level
  12939. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  12940. $this->tablecascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  12941. }
  12942. else {
  12943. $this->tablecascadeCSS[0] = $this->cascadeCSS;
  12944. }
  12945. }
  12946. //===============================================
  12947. // Set Inherited properties
  12948. if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
  12949. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  12950. if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) {
  12951. foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) {
  12952. $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
  12953. }
  12954. }
  12955. $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  12956. //===============================================
  12957. // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
  12958. //===============================================
  12959. // STYLESHEET TAG e.g. table
  12960. $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  12961. //===============================================
  12962. }
  12963. /*-- END TABLES --*/
  12964. //===============================================
  12965. /*-- LISTS --*/
  12966. // Set Inherited properties
  12967. if ($inherit == 'TOPLIST') { // $tag = UL,OL
  12968. //===============================================
  12969. // Save Cascading CSS e.g. "div.topic p" at this block level
  12970. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  12971. $this->listcascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  12972. }
  12973. else {
  12974. $this->listcascadeCSS[0] = $this->cascadeCSS;
  12975. }
  12976. }
  12977. //===============================================
  12978. // Set Inherited properties
  12979. if ($inherit == 'TOPLIST' || $inherit == 'LIST') {
  12980. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  12981. if (isset($this->listcascadeCSS[$this->listCSSlvl-1]) && is_array($this->listcascadeCSS[$this->listCSSlvl-1])) {
  12982. foreach($this->listcascadeCSS[$this->listCSSlvl-1] AS $k=>$v) {
  12983. $this->listcascadeCSS[$this->listCSSlvl][$k] = $v;
  12984. }
  12985. }
  12986. $this->_mergeFullCSS($this->cascadeCSS, $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  12987. //===============================================
  12988. // Cascading forward CSS e.g. "table.topic td" for this list in $this->listcascadeCSS
  12989. //===============================================
  12990. // STYLESHEET TAG e.g. table
  12991. $this->_mergeFullCSS($this->listcascadeCSS[$this->listCSSlvl-1], $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  12992. //===============================================
  12993. }
  12994. /*-- END LISTS --*/
  12995. //===============================================
  12996. // Set Inherited properties
  12997. if ($inherit == 'BLOCK') {
  12998. if (isset($this->blk[$this->blklvl-1]['cascadeCSS']) && is_array($this->blk[$this->blklvl-1]['cascadeCSS'])) {
  12999. foreach($this->blk[$this->blklvl-1]['cascadeCSS'] AS $k=>$v) {
  13000. $this->blk[$this->blklvl]['cascadeCSS'][$k] = $v;
  13001. }
  13002. }
  13003. //===============================================
  13004. // Save Cascading CSS e.g. "div.topic p" at this block level
  13005. $this->_mergeFullCSS($this->cascadeCSS, $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  13006. //===============================================
  13007. // Cascading forward CSS
  13008. //===============================================
  13009. $this->_mergeFullCSS($this->blk[$this->blklvl-1]['cascadeCSS'], $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  13010. //===============================================
  13011. // Block properties
  13012. if (isset($this->blk[$this->blklvl-1]['margin_collapse']) && $this->blk[$this->blklvl-1]['margin_collapse']) { $p['MARGIN-COLLAPSE'] = 'COLLAPSE'; } // custom tag, but follows CSS principle that border-collapse is inherited
  13013. if (isset($this->blk[$this->blklvl-1]['line_height']) && $this->blk[$this->blklvl-1]['line_height']) { $p['LINE-HEIGHT'] = $this->blk[$this->blklvl-1]['line_height']; }
  13014. if (isset($this->blk[$this->blklvl-1]['direction']) && $this->blk[$this->blklvl-1]['direction']) { $p['DIRECTION'] = $this->blk[$this->blklvl-1]['direction']; }
  13015. if (isset($this->blk[$this->blklvl-1]['align']) && $this->blk[$this->blklvl-1]['align']) {
  13016. if ($this->blk[$this->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; }
  13017. else if ($this->blk[$this->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; }
  13018. else if ($this->blk[$this->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; }
  13019. else if ($this->blk[$this->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; }
  13020. }
  13021. if ($this->ColActive || $this->keep_block_together) {
  13022. if (isset($this->blk[$this->blklvl-1]['bgcolor']) && $this->blk[$this->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
  13023. $cor = $this->blk[$this->blklvl-1]['bgcolorarray' ];
  13024. $p['BACKGROUND-COLOR'] = $this->_colAtoString($cor);
  13025. }
  13026. }
  13027. if (isset($this->blk[$this->blklvl-1]['text_indent']) && ($this->blk[$this->blklvl-1]['text_indent'] || $this->blk[$this->blklvl-1]['text_indent']===0)) { $p['TEXT-INDENT'] = $this->blk[$this->blklvl-1]['text_indent']; }
  13028. if (isset($this->blk[$this->blklvl-1]['InlineProperties'])) {
  13029. $biilp = $this->blk[$this->blklvl-1]['InlineProperties'];
  13030. }
  13031. else { $biilp = null; }
  13032. if (isset($biilp[ 'family' ]) && $biilp[ 'family' ]) { $p['FONT-FAMILY'] = $biilp[ 'family' ]; }
  13033. if (isset($biilp[ 'I' ]) && $biilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  13034. if (isset($biilp[ 'sizePt' ]) && $biilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $biilp[ 'sizePt' ] . 'pt'; }
  13035. if (isset($biilp[ 'B' ]) && $biilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  13036. if (isset($biilp[ 'colorarray' ]) && $biilp[ 'colorarray' ]) {
  13037. $cor = $biilp[ 'colorarray' ];
  13038. $p['COLOR'] = $this->_colAtoString($cor);
  13039. }
  13040. if (isset($biilp[ 'fontkerning' ])) {
  13041. if ($biilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; }
  13042. else { $p['FONT-KERNING'] = 'none'; }
  13043. }
  13044. if (isset($biilp[ 'lSpacingCSS' ]) && $biilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $biilp[ 'lSpacingCSS' ]; }
  13045. if (isset($biilp[ 'wSpacingCSS' ]) && $biilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $biilp[ 'wSpacingCSS' ]; }
  13046. if (isset($biilp[ 'toupper' ]) && $biilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  13047. else if (isset($biilp[ 'tolower' ]) && $biilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  13048. else if (isset($biilp[ 'capitalize' ]) && $biilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; }
  13049. // CSS says text-decoration is not inherited, but IE7 does??
  13050. if (isset($biilp[ 'underline' ]) && $biilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  13051. if (isset($biilp[ 'smCaps' ]) && $biilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; }
  13052. }
  13053. //===============================================
  13054. //===============================================
  13055. /*-- LISTS --*/
  13056. // Set Inherited properties
  13057. if ($inherit == 'TOPLIST') {
  13058. if ($this->listCSSlvl == 1) {
  13059. $bilp = $this->blk[$this->blklvl]['InlineProperties'];
  13060. if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; }
  13061. if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  13062. if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; }
  13063. if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  13064. if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) {
  13065. $cor = $bilp[ 'colorarray' ];
  13066. $p['COLOR'] = $this->_colAtoString($cor);
  13067. }
  13068. if (isset($bilp[ 'toupper' ]) && $bilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  13069. else if (isset($bilp[ 'tolower' ]) && $bilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  13070. else if (isset($bilp[ 'capitalize' ]) && $bilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; }
  13071. if (isset($bilp[ 'fontkerning' ])) {
  13072. if ($bilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; }
  13073. else { $p['FONT-KERNING'] = 'none'; }
  13074. }
  13075. if (isset($bilp[ 'lSpacingCSS' ]) && $bilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $bilp[ 'lSpacingCSS' ]; }
  13076. if (isset($bilp[ 'wSpacingCSS' ]) && $bilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $bilp[ 'wSpacingCSS' ]; }
  13077. // CSS says text-decoration is not inherited, but IE7 does??
  13078. if (isset($bilp[ 'underline' ]) && $bilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  13079. if (isset($bilp[ 'smCaps' ]) && $bilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; }
  13080. if ($tag=='LI') {
  13081. // Note to self - this should never work, as TOPLIST is not called when LI (see code removed in v5.3)
  13082. $this->Error("If you see this message, please report this as a bug to the mPDF Forum.");
  13083. }
  13084. }
  13085. }
  13086. /*-- END LISTS --*/
  13087. //===============================================
  13088. //===============================================
  13089. // DEFAULT for this TAG set in DefaultCSS
  13090. if (isset($this->defaultCSS[$tag])) {
  13091. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  13092. if (is_array($zp)) { // Default overwrites Inherited
  13093. $p = array_merge($p,$zp); // !! Note other way round !!
  13094. $this->_mergeBorders($p,$zp);
  13095. }
  13096. }
  13097. //===============================================
  13098. /*-- TABLES --*/
  13099. // cellPadding overwrites TD/TH default but not specific CSS set on cell
  13100. if (($tag=='TD' || $tag=='TH') && isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']) && ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'] || $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']===0)) {
  13101. $p['PADDING-LEFT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13102. $p['PADDING-RIGHT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13103. $p['PADDING-TOP'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13104. $p['PADDING-BOTTOM'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  13105. }
  13106. /*-- END TABLES --*/
  13107. //===============================================
  13108. // STYLESHEET TAG e.g. h1 p div table
  13109. if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
  13110. $zp = $this->CSS[$tag];
  13111. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13112. if (is_array($zp)) {
  13113. $p = array_merge($p,$zp);
  13114. $this->_mergeBorders($p,$zp);
  13115. }
  13116. }
  13117. //===============================================
  13118. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13119. foreach($classes AS $class) {
  13120. $zp = array();
  13121. if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; }
  13122. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13123. if (is_array($zp)) {
  13124. $p = array_merge($p,$zp);
  13125. $this->_mergeBorders($p,$zp);
  13126. }
  13127. }
  13128. //===============================================
  13129. /*-- TABLES --*/
  13130. // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
  13131. if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
  13132. foreach($this->CSS AS $k=>$val) {
  13133. if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
  13134. $select = false;
  13135. if ($tag=='TR') {
  13136. $row = $this->row;
  13137. $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0);
  13138. $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0);
  13139. if ($this->tabletfoot) { $row -= $thnr; }
  13140. else if (!$this->tablethead) { $row -= ($thnr + $tfnr); }
  13141. if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; }
  13142. else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; }
  13143. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13144. if ((($row + 1) % $a[1]) == $a[2]) { $select = true; }
  13145. }
  13146. }
  13147. else if ($tag=='TD' || $tag=='TH') {
  13148. if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; }
  13149. else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; }
  13150. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13151. if ((($this->col+1) % $a[1]) == $a[2]) { $select = true; }
  13152. }
  13153. }
  13154. if ($select) {
  13155. $zp = $this->CSS[$tag.'>>SELECTORNTHCHILD>>'.$m[1]];
  13156. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); }
  13157. if (is_array($zp)) {
  13158. $p = array_merge($p,$zp);
  13159. $this->_mergeBorders($p,$zp);
  13160. }
  13161. }
  13162. }
  13163. }
  13164. }
  13165. /*-- END TABLES --*/
  13166. //===============================================
  13167. // STYLESHEET ID e.g. #smallone{} #redletter{}
  13168. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) {
  13169. $zp = $this->CSS['ID>>'.$attr['ID']];
  13170. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13171. if (is_array($zp)) {
  13172. $p = array_merge($p,$zp);
  13173. $this->_mergeBorders($p,$zp);
  13174. }
  13175. }
  13176. //===============================================
  13177. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  13178. foreach($classes AS $class) {
  13179. $zp = array();
  13180. if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  13181. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13182. if (is_array($zp)) {
  13183. $p = array_merge($p,$zp);
  13184. $this->_mergeBorders($p,$zp);
  13185. }
  13186. }
  13187. //===============================================
  13188. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  13189. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) {
  13190. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  13191. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13192. if (is_array($zp)) {
  13193. $p = array_merge($p,$zp);
  13194. $this->_mergeBorders($p,$zp);
  13195. }
  13196. }
  13197. //===============================================
  13198. // Cascaded e.g. div.class p only works for block level
  13199. if ($inherit == 'BLOCK') {
  13200. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag], $p);
  13201. foreach($classes AS $class) {
  13202. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p);
  13203. }
  13204. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  13205. foreach($classes AS $class) {
  13206. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  13207. }
  13208. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  13209. }
  13210. else if ($inherit == 'INLINE') {
  13211. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag], $p);
  13212. foreach($classes AS $class) {
  13213. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['CLASS>>'.$class], $p);
  13214. }
  13215. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  13216. foreach($classes AS $class) {
  13217. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  13218. }
  13219. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  13220. }
  13221. /*-- TABLES --*/
  13222. else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
  13223. // false, 9 = don't check for 'depth' and do set border dominance
  13224. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9);
  13225. foreach($classes AS $class) {
  13226. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9);
  13227. }
  13228. // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
  13229. if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
  13230. foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$val) {
  13231. if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
  13232. $select = false;
  13233. if ($tag=='TR') {
  13234. $row = $this->row;
  13235. $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0);
  13236. $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0);
  13237. if ($this->tabletfoot) { $row -= $thnr; }
  13238. else if (!$this->tablethead) { $row -= ($thnr + $tfnr); }
  13239. if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; }
  13240. else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; }
  13241. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13242. if ((($row + 1) % $a[1]) == $a[2]) { $select = true; }
  13243. }
  13244. }
  13245. else if ($tag=='TD' || $tag=='TH') {
  13246. if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; }
  13247. else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; }
  13248. else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) {
  13249. if ((($this->col + 1) % $a[1]) == $a[2]) { $select = true; }
  13250. }
  13251. }
  13252. if ($select) {
  13253. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $p, false, 9);
  13254. }
  13255. }
  13256. }
  13257. }
  13258. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9);
  13259. foreach($classes AS $class) {
  13260. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9);
  13261. }
  13262. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9);
  13263. }
  13264. /*-- END TABLES --*/
  13265. //===============================================
  13266. /*-- LISTS --*/
  13267. else if ($inherit == 'TOPLIST' || $inherit == 'LIST') { // NB looks at $this->listcascadeCSS-1 for cascading CSS
  13268. // false = don't check for 'depth'
  13269. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag], $p, false);
  13270. foreach($classes AS $class) {
  13271. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['CLASS>>'.$class], $p, false);
  13272. }
  13273. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['ID>>'.$attr['ID']], $p, false);
  13274. foreach($classes AS $class) {
  13275. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false);
  13276. }
  13277. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false);
  13278. }
  13279. /*-- END LISTS --*/
  13280. //===============================================
  13281. //===============================================
  13282. // INLINE STYLE e.g. style="CSS:property"
  13283. if (isset($attr['STYLE'])) {
  13284. $zp = $this->readInlineCSS($attr['STYLE']);
  13285. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  13286. if (is_array($zp)) {
  13287. $p = array_merge($p,$zp);
  13288. $this->_mergeBorders($p,$zp);
  13289. }
  13290. }
  13291. //===============================================
  13292. //===============================================
  13293. // INLINE ATTRIBUTES e.g. .. ALIGN="CENTER">
  13294. if (isset($attr['LANG']) and $attr['LANG']!='') {
  13295. $p['LANG'] = $attr['LANG'];
  13296. }
  13297. if (isset($attr['COLOR']) and $attr['COLOR']!='') {
  13298. $p['COLOR'] = $attr['COLOR'];
  13299. }
  13300. if ($tag != 'INPUT') {
  13301. if (isset($attr['WIDTH']) and $attr['WIDTH']!='') {
  13302. $p['WIDTH'] = $attr['WIDTH'];
  13303. }
  13304. if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') {
  13305. $p['HEIGHT'] = $attr['HEIGHT'];
  13306. }
  13307. }
  13308. if ($tag == 'FONT') {
  13309. if (isset($attr['FACE'])) {
  13310. $p['FONT-FAMILY'] = $attr['FACE'];
  13311. }
  13312. if (isset($attr['SIZE']) and $attr['SIZE']!='') {
  13313. $s = '';
  13314. if ($attr['SIZE'] === '+1') { $s = '120%'; }
  13315. else if ($attr['SIZE'] === '-1') { $s = '86%'; }
  13316. else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; }
  13317. else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; }
  13318. else if ($attr['SIZE'] == '3') { $s = 'SMALL'; }
  13319. else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; }
  13320. else if ($attr['SIZE'] == '5') { $s = 'LARGE'; }
  13321. else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; }
  13322. else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; }
  13323. if ($s) $p['FONT-SIZE'] = $s;
  13324. }
  13325. }
  13326. if (isset($attr['VALIGN']) and $attr['VALIGN']!='') {
  13327. $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
  13328. }
  13329. if (isset($attr['VSPACE']) and $attr['VSPACE']!='') {
  13330. $p['MARGIN-TOP'] = $attr['VSPACE'];
  13331. $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
  13332. }
  13333. if (isset($attr['HSPACE']) and $attr['HSPACE']!='') {
  13334. $p['MARGIN-LEFT'] = $attr['HSPACE'];
  13335. $p['MARGIN-RIGHT'] = $attr['HSPACE'];
  13336. }
  13337. //===============================================
  13338. return $p;
  13339. }
  13340. /*-- CSS-PAGE --*/
  13341. function SetPagedMediaCSS($name='', $first, $oddEven) {
  13342. if ($oddEven == 'E') {
  13343. if ($this->directionality=='rtl') { $side = 'R'; }
  13344. else { $side = 'L'; }
  13345. }
  13346. else {
  13347. if ($this->directionality=='rtl') { $side = 'L'; }
  13348. else { $side = 'R'; }
  13349. }
  13350. $name = strtoupper($name);
  13351. $p = array();
  13352. $p['SIZE'] = 'AUTO';
  13353. // Uses mPDF original margins as default
  13354. $p['MARGIN-RIGHT'] = strval($this->orig_rMargin).'mm';
  13355. $p['MARGIN-LEFT'] = strval($this->orig_lMargin).'mm';
  13356. $p['MARGIN-TOP'] = strval($this->orig_tMargin).'mm';
  13357. $p['MARGIN-BOTTOM'] = strval($this->orig_bMargin).'mm';
  13358. $p['MARGIN-HEADER'] = strval($this->orig_hMargin).'mm';
  13359. $p['MARGIN-FOOTER'] = strval($this->orig_fMargin).'mm';
  13360. // Basic page + selector
  13361. if (isset($this->CSS['@PAGE'])) { $zp = $this->CSS['@PAGE']; }
  13362. else { $zp = array(); }
  13363. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13364. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  13365. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  13366. }
  13367. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  13368. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  13369. }
  13370. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  13371. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  13372. }
  13373. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  13374. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  13375. }
  13376. // If right/Odd page
  13377. if (isset($this->CSS['@PAGE>>PSEUDO>>RIGHT']) && $side=='R') {
  13378. $zp = $this->CSS['@PAGE>>PSEUDO>>RIGHT'];
  13379. }
  13380. else { $zp = array(); }
  13381. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13382. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13383. // Disallow margin-left or -right on :LEFT or :RIGHT
  13384. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13385. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13386. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13387. // If left/Even page
  13388. if (isset($this->CSS['@PAGE>>PSEUDO>>LEFT']) && $side=='L') {
  13389. $zp = $this->CSS['@PAGE>>PSEUDO>>LEFT'];
  13390. }
  13391. else { $zp = array(); }
  13392. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13393. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13394. // Disallow margin-left or -right on :LEFT or :RIGHT
  13395. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13396. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13397. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13398. // If first page
  13399. if (isset($this->CSS['@PAGE>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>PSEUDO>>FIRST']; }
  13400. else { $zp = array(); }
  13401. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13402. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13403. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13404. // If named page
  13405. if ($name) {
  13406. if (isset($this->CSS['@PAGE>>NAMED>>'.$name])) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name]; }
  13407. else { $zp = array(); }
  13408. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13409. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  13410. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  13411. }
  13412. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  13413. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  13414. }
  13415. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  13416. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  13417. }
  13418. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  13419. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  13420. }
  13421. // If named right/Odd page
  13422. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']) && $side=='R') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']; }
  13423. else { $zp = array(); }
  13424. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13425. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13426. // Disallow margin-left or -right on :LEFT or :RIGHT
  13427. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13428. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13429. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13430. // If named left/Even page
  13431. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']) && $side=='L') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']; }
  13432. else { $zp = array(); }
  13433. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13434. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13435. // Disallow margin-left or -right on :LEFT or :RIGHT
  13436. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13437. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13438. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13439. // If named first page
  13440. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']; }
  13441. else { $zp = array(); }
  13442. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13443. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); }
  13444. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13445. }
  13446. $orientation = $mgl = $mgr = $mgt = $mgb = $mgh = $mgf = '';
  13447. $header = $footer = '';
  13448. $resetpagenum = $pagenumstyle = $suppress = '';
  13449. $marks = '';
  13450. $bg = array();
  13451. $newformat = '';
  13452. if (isset($p['SHEET-SIZE']) && is_array($p['SHEET-SIZE'])) {
  13453. $newformat = $p['SHEET-SIZE'];
  13454. if ($newformat[0] > $newformat[1]) { // landscape
  13455. $newformat = array_reverse($newformat);
  13456. $p['ORIENTATION'] = 'L';
  13457. }
  13458. else { $p['ORIENTATION'] = 'P'; }
  13459. $this->_setPageSize($newformat, $p['ORIENTATION']);
  13460. }
  13461. if (isset($p['SIZE']) && is_array($p['SIZE']) && !$newformat) {
  13462. if ($p['SIZE']['W'] > $p['SIZE']['H']) { $p['ORIENTATION'] = 'L'; }
  13463. else { $p['ORIENTATION'] = 'P'; }
  13464. }
  13465. if (is_array($p['SIZE'])) {
  13466. if ($p['SIZE']['W'] > $this->fw) { $p['SIZE']['W'] = $this->fw; } // mPD 4.2 use fw not fPt
  13467. if ($p['SIZE']['H'] > $this->fh) { $p['SIZE']['H'] = $this->fh; }
  13468. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  13469. $outer_width_LR = ($this->fw - $p['SIZE']['W'])/2;
  13470. $outer_width_TB = ($this->fh - $p['SIZE']['H'])/2;
  13471. }
  13472. else {
  13473. $outer_width_LR = ($this->fh - $p['SIZE']['W'])/2;
  13474. $outer_width_TB = ($this->fw - $p['SIZE']['H'])/2;
  13475. }
  13476. $pgw = $p['SIZE']['W'];
  13477. $pgh = $p['SIZE']['H'];
  13478. }
  13479. else { // AUTO LANDSCAPE PORTRAIT
  13480. $outer_width_LR = 0;
  13481. $outer_width_TB = 0;
  13482. if (!$newformat) {
  13483. if (strtoupper($p['SIZE']) == 'AUTO') { $p['ORIENTATION']=$this->DefOrientation; }
  13484. else if (strtoupper($p['SIZE']) == 'LANDSCAPE') { $p['ORIENTATION']='L'; }
  13485. else { $p['ORIENTATION']='P'; }
  13486. }
  13487. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) {
  13488. $pgw = $this->fw;
  13489. $pgh = $this->fh;
  13490. }
  13491. else {
  13492. $pgw = $this->fh;
  13493. $pgh = $this->fw;
  13494. }
  13495. }
  13496. if (isset($p['HEADER']) && $p['HEADER']) { $header = $p['HEADER']; }
  13497. if (isset($p['FOOTER']) && $p['FOOTER']) { $footer = $p['FOOTER']; }
  13498. if (isset($p['RESETPAGENUM']) && $p['RESETPAGENUM']) { $resetpagenum = $p['RESETPAGENUM']; }
  13499. if (isset($p['PAGENUMSTYLE']) && $p['PAGENUMSTYLE']) { $pagenumstyle = $p['PAGENUMSTYLE']; }
  13500. if (isset($p['SUPPRESS']) && $p['SUPPRESS']) { $suppress = $p['SUPPRESS']; }
  13501. if (preg_match('/cross/i', $p['MARKS']) && preg_match('/crop/i', $p['MARKS'])) { $marks = 'CROPCROSS'; }
  13502. else if (strtoupper($p['MARKS']) == 'CROP') { $marks = 'CROP'; }
  13503. else if (strtoupper($p['MARKS']) == 'CROSS') { $marks = 'CROSS'; }
  13504. if (isset($p['BACKGROUND-COLOR']) && $p['BACKGROUND-COLOR']) { $bg['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  13505. /*-- BACKGROUNDS --*/
  13506. if (isset($p['BACKGROUND-GRADIENT']) && $p['BACKGROUND-GRADIENT']) { $bg['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; }
  13507. if (isset($p['BACKGROUND-IMAGE']) && $p['BACKGROUND-IMAGE']) { $bg['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; }
  13508. if (isset($p['BACKGROUND-REPEAT']) && $p['BACKGROUND-REPEAT']) { $bg['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; }
  13509. if (isset($p['BACKGROUND-POSITION']) && $p['BACKGROUND-POSITION']) { $bg['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; }
  13510. if (isset($p['BACKGROUND-IMAGE-RESIZE']) && $p['BACKGROUND-IMAGE-RESIZE']) { $bg['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; }
  13511. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $bg['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; }
  13512. /*-- END BACKGROUNDS --*/
  13513. if (isset($p['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($p['MARGIN-LEFT'],$pgw) + $outer_width_LR; }
  13514. if (isset($p['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($p['MARGIN-RIGHT'],$pgw) + $outer_width_LR; }
  13515. if (isset($p['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($p['MARGIN-BOTTOM'],$pgh) + $outer_width_TB; }
  13516. if (isset($p['MARGIN-TOP'])) { $mgt = $this->ConvertSize($p['MARGIN-TOP'],$pgh) + $outer_width_TB; }
  13517. if (isset($p['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($p['MARGIN-HEADER'],$pgh) + $outer_width_TB; }
  13518. if (isset($p['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($p['MARGIN-FOOTER'],$pgh) + $outer_width_TB; }
  13519. if (isset($p['ORIENTATION']) && $p['ORIENTATION']) { $orientation = $p['ORIENTATION']; }
  13520. $this->page_box['outer_width_LR'] = $outer_width_LR; // Used in MARKS:crop etc.
  13521. $this->page_box['outer_width_TB'] = $outer_width_TB;
  13522. return array($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$header,$footer,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat);
  13523. }
  13524. /*-- END CSS-PAGE --*/
  13525. function PreviewBlockCSS($tag,$attr) {
  13526. // Looks ahead from current block level to a new level
  13527. $p = array();
  13528. $zp = array();
  13529. $oldcascadeCSS = $this->blk[$this->blklvl]['cascadeCSS'];
  13530. $classes = array();
  13531. if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); }
  13532. //===============================================
  13533. // DEFAULT for this TAG set in DefaultCSS
  13534. if (isset($this->defaultCSS[$tag])) {
  13535. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  13536. if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default
  13537. }
  13538. // STYLESHEET TAG e.g. h1 p div table
  13539. if (isset($this->CSS[$tag])) {
  13540. $zp = $this->CSS[$tag];
  13541. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13542. }
  13543. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13544. foreach($classes AS $class) {
  13545. $zp = array();
  13546. if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; }
  13547. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13548. }
  13549. // STYLESHEET ID e.g. #smallone{} #redletter{}
  13550. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) {
  13551. $zp = $this->CSS['ID>>'.$attr['ID']];
  13552. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13553. }
  13554. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  13555. foreach($classes AS $class) {
  13556. $zp = array();
  13557. if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  13558. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13559. }
  13560. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  13561. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) {
  13562. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  13563. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13564. }
  13565. //===============================================
  13566. // STYLESHEET TAG e.g. div h1 div p
  13567. $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
  13568. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13569. foreach($classes AS $class) {
  13570. $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p);
  13571. }
  13572. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  13573. if (isset($attr['ID'])) {
  13574. $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p);
  13575. }
  13576. // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
  13577. foreach($classes AS $class) {
  13578. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p);
  13579. }
  13580. // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
  13581. if (isset($attr['ID'])) {
  13582. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p);
  13583. }
  13584. //===============================================
  13585. // INLINE STYLE e.g. style="CSS:property"
  13586. if (isset($attr['STYLE'])) {
  13587. $zp = $this->readInlineCSS($attr['STYLE']);
  13588. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13589. }
  13590. //===============================================
  13591. return $p;
  13592. }
  13593. /*-- CSS-FLOAT --*/
  13594. // Added mPDF 3.0 Float DIV - CLEAR
  13595. function ClearFloats($clear, $blklvl=0) {
  13596. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($blklvl,true);
  13597. $end = $currpos = ($this->page*1000 + $this->y);
  13598. if ($clear == 'BOTH' && ($l_exists || $r_exists)) {
  13599. $this->pageoutput[$this->page] = array();
  13600. $end = max($l_max, $r_max, $currpos);
  13601. }
  13602. else if ($clear == 'RIGHT' && $r_exists) {
  13603. $this->pageoutput[$this->page] = array();
  13604. $end = max($r_max, $currpos);
  13605. }
  13606. else if ($clear == 'LEFT' && $l_exists ) {
  13607. $this->pageoutput[$this->page] = array();
  13608. $end = max($l_max, $currpos);
  13609. }
  13610. else { return; }
  13611. $old_page = $this->page;
  13612. $new_page = intval($end/1000);
  13613. if ($old_page != $new_page) {
  13614. $s = $this->PrintPageBackgrounds();
  13615. // Writes after the marker so not overwritten later by page background etc.
  13616. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  13617. $this->pageBackgrounds = array();
  13618. $this->page = $new_page;
  13619. }
  13620. $this->ResetMargins();
  13621. $this->pageoutput[$this->page] = array();
  13622. $this->y = (($end*1000) % 1000000)/1000; // mod changes operands to integers before processing
  13623. }
  13624. // Added mPDF 3.0 Float DIV
  13625. function GetFloatDivInfo($blklvl=0,$clear=false) {
  13626. // If blklvl specified, only returns floats at that level - for ClearFloats
  13627. $l_exists = false;
  13628. $r_exists = false;
  13629. $l_max = 0;
  13630. $r_max = 0;
  13631. $l_width = 0;
  13632. $r_width = 0;
  13633. if (count($this->floatDivs)) {
  13634. $currpos = ($this->page*1000 + $this->y);
  13635. foreach($this->floatDivs AS $f) {
  13636. 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'])) {
  13637. if ($f['side']=='L') {
  13638. $l_exists= true;
  13639. $l_max = max($l_max, $f['endpos']);
  13640. $l_width = max($l_width , $f['w']);
  13641. }
  13642. if ($f['side']=='R') {
  13643. $r_exists= true;
  13644. $r_max = max($r_max, $f['endpos']);
  13645. $r_width = max($r_width , $f['w']);
  13646. }
  13647. }
  13648. }
  13649. }
  13650. return array($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width);
  13651. }
  13652. /*-- END CSS-FLOAT --*/
  13653. function OpenTag($tag,$attr)
  13654. {
  13655. // What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here>
  13656. // Correct tags where HTML specifies optional end tags,
  13657. // and/or does not allow nesting e.g. P inside P, or
  13658. if ($this->allow_html_optional_endtags) {
  13659. 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 ); }
  13660. if ($tag == 'DD' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13661. if ($tag == 'DD' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13662. if ($tag == 'DT' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13663. if ($tag == 'DT' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13664. if ($tag == 'LI' && $this->lastoptionaltag == 'LI') { $this->CloseTag($this->lastoptionaltag ); }
  13665. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13666. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13667. if ($tag == 'TR' && $this->lastoptionaltag == 'TR') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13668. if ($tag == 'TR' && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13669. if ($tag == 'TR' && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13670. if ($tag == 'OPTION' && $this->lastoptionaltag == 'OPTION') { $this->CloseTag($this->lastoptionaltag ); }
  13671. }
  13672. $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','text-top'=>'TT','middle'=>'M','baseline'=>'BS','bottom'=>'B','text-bottom'=>'TB','justify'=>'J');
  13673. $this->ignorefollowingspaces=false;
  13674. //Opening tag
  13675. switch($tag){
  13676. case 'DOTTAB':
  13677. $objattr = array();
  13678. $objattr['type'] = 'dottab';
  13679. $dots=str_repeat('.', 3)." "; // minimum number of dots
  13680. $objattr['width'] = $this->GetStringWidth($dots);
  13681. $objattr['margin_top'] = 0;
  13682. $objattr['margin_bottom'] = 0;
  13683. $objattr['margin_left'] = 0;
  13684. $objattr['margin_right'] = 0;
  13685. $objattr['height'] = 0;
  13686. $objattr['colorarray'] = $this->colorarray;
  13687. $objattr['border_top']['w'] = 0;
  13688. $objattr['border_bottom']['w'] = 0;
  13689. $objattr['border_left']['w'] = 0;
  13690. $objattr['border_right']['w'] = 0;
  13691. $e = "\xbb\xa4\xactype=dottab,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13692. /*-- TABLES --*/
  13693. // Output it to buffers
  13694. if ($this->tableLevel) {
  13695. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  13696. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13697. }
  13698. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  13699. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13700. }
  13701. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  13702. $this->_saveCellTextBuffer($e);
  13703. }
  13704. else {
  13705. /*-- END TABLES --*/
  13706. $this->_saveTextBuffer($e);
  13707. } // *TABLES*
  13708. break;
  13709. case 'PAGEHEADER':
  13710. case 'PAGEFOOTER':
  13711. $this->ignorefollowingspaces = true;
  13712. if ($attr['NAME']) { $pname = $attr['NAME']; }
  13713. else { $pname = '_default'; }
  13714. if ($tag=='PAGEHEADER') { $p = &$this->pageheaders[$pname]; }
  13715. else { $p = &$this->pagefooters[$pname]; }
  13716. $p['L']=array();
  13717. $p['C']=array();
  13718. $p['R']=array();
  13719. $p['L']['font-style'] = '';
  13720. $p['C']['font-style'] = '';
  13721. $p['R']['font-style'] = '';
  13722. if (isset($attr['CONTENT-LEFT'])) {
  13723. $p['L']['content'] = $attr['CONTENT-LEFT'];
  13724. }
  13725. if (isset($attr['CONTENT-CENTER'])) {
  13726. $p['C']['content'] = $attr['CONTENT-CENTER'];
  13727. }
  13728. if (isset($attr['CONTENT-RIGHT'])) {
  13729. $p['R']['content'] = $attr['CONTENT-RIGHT'];
  13730. }
  13731. if (isset($attr['HEADER-STYLE']) || isset($attr['FOOTER-STYLE'])) { // font-family,size,weight,style,color
  13732. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE']); }
  13733. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE']); }
  13734. if (isset($properties['FONT-FAMILY'])) {
  13735. $p['L']['font-family'] = $properties['FONT-FAMILY'];
  13736. $p['C']['font-family'] = $properties['FONT-FAMILY'];
  13737. $p['R']['font-family'] = $properties['FONT-FAMILY'];
  13738. }
  13739. if (isset($properties['FONT-SIZE'])) {
  13740. $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13741. $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13742. $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK;
  13743. }
  13744. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') {
  13745. $p['L']['font-style'] = 'B';
  13746. $p['C']['font-style'] = 'B';
  13747. $p['R']['font-style'] = 'B';
  13748. }
  13749. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') {
  13750. $p['L']['font-style'] .= 'I';
  13751. $p['C']['font-style'] .= 'I';
  13752. $p['R']['font-style'] .= 'I';
  13753. }
  13754. if (isset($properties['COLOR'])) {
  13755. $p['L']['color'] = $properties['COLOR'];
  13756. $p['C']['color'] = $properties['COLOR'];
  13757. $p['R']['color'] = $properties['COLOR'];
  13758. }
  13759. }
  13760. if (isset($attr['HEADER-STYLE-LEFT']) || isset($attr['FOOTER-STYLE-LEFT'])) {
  13761. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-LEFT']); }
  13762. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-LEFT']); }
  13763. if (isset($properties['FONT-FAMILY'])) { $p['L']['font-family'] = $properties['FONT-FAMILY']; }
  13764. if (isset($properties['FONT-SIZE'])) { $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13765. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['L']['font-style'] ='B'; }
  13766. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['L']['font-style'] .='I'; }
  13767. if (isset($properties['COLOR'])) { $p['L']['color'] = $properties['COLOR']; }
  13768. }
  13769. if (isset($attr['HEADER-STYLE-CENTER']) || isset($attr['FOOTER-STYLE-CENTER'])) {
  13770. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-CENTER']); }
  13771. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-CENTER']); }
  13772. if (isset($properties['FONT-FAMILY'])) { $p['C']['font-family'] = $properties['FONT-FAMILY']; }
  13773. if (isset($properties['FONT-SIZE'])) { $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13774. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['C']['font-style'] = 'B'; }
  13775. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['C']['font-style'] .= 'I'; }
  13776. if (isset($properties['COLOR'])) { $p['C']['color'] = $properties['COLOR']; }
  13777. }
  13778. if (isset($attr['HEADER-STYLE-RIGHT']) || isset($attr['FOOTER-STYLE-RIGHT'])) {
  13779. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-RIGHT']); }
  13780. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-RIGHT']); }
  13781. if (isset($properties['FONT-FAMILY'])) { $p['R']['font-family'] = $properties['FONT-FAMILY']; }
  13782. if (isset($properties['FONT-SIZE'])) { $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; }
  13783. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['R']['font-style'] = 'B'; }
  13784. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['R']['font-style'] .= 'I'; }
  13785. if (isset($properties['COLOR'])) { $p['R']['color'] = $properties['COLOR']; }
  13786. }
  13787. if (isset($attr['LINE']) && $attr['LINE']) { // 0|1|on|off
  13788. if ($attr['LINE']=='1' || strtoupper($attr['LINE'])=='ON') { $lineset=1; }
  13789. else { $lineset=0; }
  13790. $p['line'] = $lineset;
  13791. }
  13792. break;
  13793. /*-- HTMLHEADERS-FOOTERS --*/
  13794. case 'SETHTMLPAGEHEADER':
  13795. case 'SETHTMLPAGEFOOTER':
  13796. $this->ignorefollowingspaces = true;
  13797. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13798. else { $pname = '_default'; }
  13799. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13800. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13801. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13802. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13803. else { $side='odd'; }
  13804. }
  13805. else { $side='odd'; }
  13806. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13807. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13808. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13809. else { $set=1; }
  13810. }
  13811. else { $set=1; }
  13812. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETHTMLPAGEHEADER') { $write = 1; }
  13813. else { $write = 0; }
  13814. if ($side=='odd' || $side=='both') {
  13815. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'O',$write); }
  13816. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'O'); }
  13817. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','O'); }
  13818. else { $this->SetHTMLFooter('','O'); }
  13819. }
  13820. if ($side=='even' || $side=='both') {
  13821. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'E',$write); }
  13822. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'E'); }
  13823. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','E'); }
  13824. else { $this->SetHTMLFooter('','E'); }
  13825. }
  13826. break;
  13827. /*-- END HTMLHEADERS-FOOTERS --*/
  13828. case 'SETPAGEHEADER':
  13829. case 'SETPAGEFOOTER':
  13830. $this->ignorefollowingspaces = true;
  13831. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13832. else { $pname = '_default'; }
  13833. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13834. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13835. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13836. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13837. else { $side='odd'; }
  13838. }
  13839. else { $side='odd'; }
  13840. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13841. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13842. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13843. else { $set=1; }
  13844. }
  13845. else { $set=1; }
  13846. if ($side=='odd' || $side=='both') {
  13847. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = $this->pageheaders[$pname]; }
  13848. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['odd'] = $this->pagefooters[$pname]; }
  13849. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = array(); }
  13850. else { $this->footerDetails['odd'] = array(); }
  13851. if (!$this->mirrorMargins || ($this->page)%2!=0) { // ODD
  13852. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['odd'],$this->HTMLHeader); }
  13853. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['odd'],$this->HTMLFooter); }
  13854. }
  13855. }
  13856. if ($side=='even' || $side=='both') {
  13857. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['even'] = $this->pageheaders[$pname]; }
  13858. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['even'] = $this->pagefooters[$pname]; }
  13859. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['even'] = array(); }
  13860. else { $this->footerDetails['even'] = array(); }
  13861. if ($this->mirrorMargins && ($this->page)%2==0) { // EVEN
  13862. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['even'],$this->HTMLHeaderE); }
  13863. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['even'],$this->HTMLFooterE); }
  13864. }
  13865. }
  13866. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETPAGEHEADER') {
  13867. $this->Header();
  13868. }
  13869. break;
  13870. /*-- TOC --*/
  13871. case 'TOC': //added custom-tag - set Marker for insertion later of ToC
  13872. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  13873. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  13874. $this->tocontents->openTagTOC($attr);
  13875. break;
  13876. case 'TOCPAGEBREAK': // custom-tag - set Marker for insertion later of ToC AND adds PAGEBREAK
  13877. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  13878. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  13879. list($isbreak,$toc_id) = $this->tocontents->openTagTOCPAGEBREAK($attr);
  13880. if ($isbreak) break;
  13881. // No break - continues as PAGEBREAK...
  13882. /*-- END TOC --*/
  13883. case 'PAGE_BREAK': //custom-tag
  13884. case 'PAGEBREAK': //custom-tag
  13885. case 'NEWPAGE': //custom-tag
  13886. case 'FORMFEED': //custom-tag
  13887. $save_blklvl = $this->blklvl;
  13888. $save_blk = $this->blk;
  13889. $save_silp = $this->saveInlineProperties();
  13890. $save_spanlvl = $this->spanlvl;
  13891. $save_ilp = $this->InlineProperties;
  13892. // Close any open block tags
  13893. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  13894. if(!empty($this->textbuffer)) { //Output previously buffered content
  13895. $this->printbuffer($this->textbuffer);
  13896. $this->textbuffer=array();
  13897. }
  13898. $this->ignorefollowingspaces = true;
  13899. $save_cols = false;
  13900. /*-- COLUMNS --*/
  13901. if ($this->ColActive) {
  13902. $save_cols = true;
  13903. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  13904. $this->SetColumns(0);
  13905. }
  13906. /*-- END COLUMNS --*/
  13907. if (isset($attr['SHEET-SIZE']) && $tag != 'FORMFEED' && !$this->restoreBlockPageBreaks) {
  13908. // Convert to same types as accepted in initial mPDF() A4, A4-L, or array(w,h)
  13909. $prop = preg_split('/\s+/',trim($attr['SHEET-SIZE']));
  13910. if (count($prop) == 2 ) {
  13911. $newformat = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  13912. }
  13913. else { $newformat = $attr['SHEET-SIZE']; }
  13914. }
  13915. else { $newformat = ''; }
  13916. $mgr = $mgl = $mgt = $mgb = $mgh = $mgf = '';
  13917. if (isset($attr['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($attr['MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  13918. if (isset($attr['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($attr['MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  13919. if (isset($attr['MARGIN-TOP'])) { $mgt = $this->ConvertSize($attr['MARGIN-TOP'],$this->w,$this->FontSize,false); }
  13920. if (isset($attr['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($attr['MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  13921. if (isset($attr['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($attr['MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  13922. if (isset($attr['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($attr['MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  13923. $ohname = $ehname = $ofname = $efname = '';
  13924. if (isset($attr['ODD-HEADER-NAME'])) { $ohname = $attr['ODD-HEADER-NAME']; }
  13925. if (isset($attr['EVEN-HEADER-NAME'])) { $ehname = $attr['EVEN-HEADER-NAME']; }
  13926. if (isset($attr['ODD-FOOTER-NAME'])) { $ofname = $attr['ODD-FOOTER-NAME']; }
  13927. if (isset($attr['EVEN-FOOTER-NAME'])) { $efname = $attr['EVEN-FOOTER-NAME']; }
  13928. $ohvalue = $ehvalue = $ofvalue = $efvalue = 0;
  13929. if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='1' || strtoupper($attr['ODD-HEADER-VALUE'])=='ON')) { $ohvalue = 1; }
  13930. else if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='-1' || strtoupper($attr['ODD-HEADER-VALUE'])=='OFF')) { $ohvalue = -1; }
  13931. if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='ON')) { $ehvalue = 1; }
  13932. else if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='OFF')) { $ehvalue = -1; }
  13933. if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='ON')) { $ofvalue = 1; }
  13934. else if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='OFF')) { $ofvalue = -1; }
  13935. if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='ON')) { $efvalue = 1; }
  13936. else if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='OFF')) { $efvalue = -1; }
  13937. if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='L' || strtoupper($attr['ORIENTATION'])=='LANDSCAPE')) { $orient = 'L'; }
  13938. else if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='P' || strtoupper($attr['ORIENTATION'])=='PORTRAIT')) { $orient = 'P'; }
  13939. else { $orient = $this->CurOrientation; }
  13940. if (isset($attr['PAGE-SELECTOR']) && $attr['PAGE-SELECTOR']) { $pagesel = $attr['PAGE-SELECTOR']; }
  13941. else { $pagesel = ''; }
  13942. $resetpagenum = '';
  13943. $pagenumstyle = '';
  13944. $suppress = '';
  13945. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  13946. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  13947. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  13948. if ($tag == 'TOCPAGEBREAK') { $type = 'NEXT-ODD'; }
  13949. else if(isset($attr['TYPE'])) { $type = strtoupper($attr['TYPE']); }
  13950. else { $type = ''; }
  13951. 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); }
  13952. 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); }
  13953. 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); }
  13954. 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); }
  13955. else { $this->AddPage($orient,'', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13956. /*-- TOC --*/
  13957. if ($tag == 'TOCPAGEBREAK') {
  13958. if ($toc_id) { $this->tocontents->m_TOC[$toc_id]['TOCmark'] = $this->page; }
  13959. else { $this->tocontents->TOCmark = $this->page; }
  13960. }
  13961. /*-- END TOC --*/
  13962. /*-- COLUMNS --*/
  13963. if ($save_cols) {
  13964. // Restore columns
  13965. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  13966. }
  13967. /*-- END COLUMNS --*/
  13968. if (($tag == 'FORMFEED' || $this->restoreBlockPagebreaks) && !$this->tableLevel && !$this->listlvl) {
  13969. $this->blk = $save_blk;
  13970. // Re-open block tags
  13971. $t = $this->blk[0]['tag'];
  13972. $a = $this->blk[0]['attr'];
  13973. $this->blklvl = 0;
  13974. for ($b=0; $b<=$save_blklvl;$b++) {
  13975. $tc = $t;
  13976. $ac = $a;
  13977. $t = $this->blk[$b+1]['tag'];
  13978. $a = $this->blk[$b+1]['attr'];
  13979. unset($this->blk[$b+1]);
  13980. $this->OpenTag($tc,$ac);
  13981. }
  13982. $this->spanlvl = $save_spanlvl;
  13983. $this->InlineProperties = $save_ilp;
  13984. $this->restoreInlineProperties($save_silp);
  13985. }
  13986. break;
  13987. /*-- TOC --*/
  13988. case 'TOCENTRY':
  13989. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  13990. $objattr = array();
  13991. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13992. $objattr['type'] = 'toc';
  13993. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['toclevel'] = $attr['LEVEL']; } else { $objattr['toclevel'] = 0; }
  13994. if (isset($attr['NAME']) && $attr['NAME']) { $objattr['toc_id'] = $attr['NAME']; } else { $objattr['toc_id'] = 0; }
  13995. $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13996. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13997. else { // *TABLES*
  13998. $this->textbuffer[] = array($e);
  13999. } // *TABLES*
  14000. }
  14001. break;
  14002. /*-- END TOC --*/
  14003. /*-- INDEX --*/
  14004. case 'INDEXENTRY':
  14005. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  14006. if (isset($attr['XREF']) && $attr['XREF']) {
  14007. $this->IndexEntry(htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES),$attr['XREF']);
  14008. break;
  14009. }
  14010. $objattr = array();
  14011. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  14012. $objattr['type'] = 'indexentry';
  14013. $e = "\xbb\xa4\xactype=indexentry,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14014. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  14015. else { // *TABLES*
  14016. $this->textbuffer[] = array($e);
  14017. } // *TABLES*
  14018. }
  14019. break;
  14020. case 'INDEXINSERT':
  14021. if (isset($attr['FONT-SIZE'])) { $reffontsize = $attr['FONT-SIZE']; } else { $reffontsize = ''; }
  14022. if (isset($attr['LINE-SPACING']) && $attr['LINE-SPACING']) { $linespacing = $attr['LINE-SPACING']; } else { $linespacing = ''; }
  14023. if (isset($attr['DIV-FONT-SIZE']) && $attr['DIV-FONT-SIZE']) { $divlettfontsize = $attr['DIV-FONT-SIZE']; } else { $divlettfontsize = ''; }
  14024. if (isset($attr['FONT']) && $attr['FONT']) { $reffont = $attr['FONT']; } else { $reffont = ''; }
  14025. if (isset($attr['DIV-FONT']) && $attr['DIV-FONT']) { $divlettfont = $attr['DIV-FONT']; } else { $divlettfont = ''; }
  14026. if (isset($attr['COLS']) && $attr['COLS']) { $cols = $attr['COLS']; } else { $cols = 1; }
  14027. if (isset($attr['OFFSET']) && $attr['OFFSET']) { $offset = $attr['OFFSET']; } else { $offset = 3; }
  14028. if (isset($attr['GAP']) && $attr['GAP']) { $gap = $attr['GAP']; } else { $gap = 5; }
  14029. if (isset($attr['USEDIVLETTERS']) && (strtoupper($attr['USEDIVLETTERS'])=='OFF' || $attr['USEDIVLETTERS']==-1 || $attr['USEDIVLETTERS']==='0')) { $usedivletters = 0; }
  14030. else { $usedivletters = 1; }
  14031. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  14032. else { $links = false; }
  14033. $this->CreateIndex($cols, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont,$divlettfont, $links);
  14034. break;
  14035. /*-- END INDEX --*/
  14036. /*-- WATERMARK --*/
  14037. case 'WATERMARKTEXT':
  14038. if (isset($attr['CONTENT']) && $attr['CONTENT']) { $txt = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); } else { $txt = ''; }
  14039. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  14040. $this->SetWatermarkText($txt, $alpha);
  14041. break;
  14042. case 'WATERMARKIMAGE':
  14043. if (isset($attr['SRC'])) { $src = $attr['SRC']; } else { $src = ''; }
  14044. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  14045. if (isset($attr['SIZE']) && $attr['SIZE']) {
  14046. $size = $attr['SIZE'];
  14047. if (strpos($size,',')) { $size = explode(',',$size); }
  14048. }
  14049. else { $size = 'D'; }
  14050. if (isset($attr['POS']) && $attr['POS']) {
  14051. $pos = $attr['POS'];
  14052. if (strpos($pos,',')) { $pos = explode(',',$pos); }
  14053. }
  14054. else { $pos = 'P'; }
  14055. $this->SetWatermarkImage($src, $alpha, $size, $pos);
  14056. break;
  14057. /*-- END WATERMARK --*/
  14058. /*-- BOOKMARKS --*/
  14059. case 'BOOKMARK':
  14060. if (isset($attr['CONTENT'])) {
  14061. $objattr = array();
  14062. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  14063. $objattr['type'] = 'bookmark';
  14064. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  14065. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14066. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  14067. else { // *TABLES*
  14068. $this->textbuffer[] = array($e);
  14069. } // *TABLES*
  14070. }
  14071. break;
  14072. /*-- END BOOKMARKS --*/
  14073. /*-- ANNOTATIONS --*/
  14074. case 'ANNOTATION':
  14075. //if (isset($attr['CONTENT']) && !$this->writingHTMLheader && !$this->writingHTMLfooter) { // Stops annotations in FixedPos
  14076. if (isset($attr['CONTENT'])) {
  14077. $objattr = array();
  14078. $objattr['margin_top'] = 0;
  14079. $objattr['margin_bottom'] = 0;
  14080. $objattr['margin_left'] = 0;
  14081. $objattr['margin_right'] = 0;
  14082. $objattr['width'] = 0;
  14083. $objattr['height'] = 0;
  14084. $objattr['border_top']['w'] = 0;
  14085. $objattr['border_bottom']['w'] = 0;
  14086. $objattr['border_left']['w'] = 0;
  14087. $objattr['border_right']['w'] = 0;
  14088. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  14089. $objattr['type'] = 'annot';
  14090. $objattr['POPUP'] = '';
  14091. }
  14092. else { break; }
  14093. if (isset($attr['POS-X'])) { $objattr['POS-X'] = $attr['POS-X']; } else { $objattr['POS-X'] = 0; }
  14094. if (isset($attr['POS-Y'])) { $objattr['POS-Y'] = $attr['POS-Y']; } else { $objattr['POS-Y'] = 0; }
  14095. if (isset($attr['ICON'])) { $objattr['ICON'] = $attr['ICON']; } else { $objattr['ICON'] = 'Note'; }
  14096. if (isset($attr['AUTHOR'])) { $objattr['AUTHOR'] = $attr['AUTHOR']; }
  14097. else if (isset($attr['TITLE'])) { $objattr['AUTHOR'] = $attr['TITLE']; } else { $objattr['AUTHOR'] = ''; }
  14098. if (isset($attr['FILE'])) { $objattr['FILE'] = $attr['FILE']; } else { $objattr['FILE'] = ''; }
  14099. if (isset($attr['SUBJECT'])) { $objattr['SUBJECT'] = $attr['SUBJECT']; } else { $objattr['SUBJECT'] = ''; }
  14100. if (isset($attr['OPACITY']) && $attr['OPACITY']>0 && $attr['OPACITY']<=1) { $objattr['OPACITY'] = $attr['OPACITY']; }
  14101. else if ($this->annotMargin) { $objattr['OPACITY'] = 1; }
  14102. else { $objattr['OPACITY'] = $this->annotOpacity; }
  14103. if (isset($attr['COLOR'])) {
  14104. $cor = $this->ConvertColor($attr['COLOR']);
  14105. if ($cor) { $objattr['COLOR'] = $cor; }
  14106. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); }
  14107. }
  14108. else { $objattr['COLOR'] = $this->ConvertColor('yellow'); }
  14109. if (isset($attr['POPUP']) && !empty($attr['POPUP'])) {
  14110. $pop = preg_split('/\s+/',trim($attr['POPUP']));
  14111. if (count($pop)>1) { $objattr['POPUP'] = $pop; }
  14112. else { $objattr['POPUP'] = true; }
  14113. }
  14114. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14115. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  14116. else { // *TABLES*
  14117. $this->textbuffer[] = array($e);
  14118. } // *TABLES*
  14119. break;
  14120. /*-- END ANNOTATIONS --*/
  14121. /*-- COLUMNS --*/
  14122. case 'COLUMNS': //added custom-tag
  14123. if (isset($attr['COLUMN-COUNT']) && ($attr['COLUMN-COUNT'] || $attr['COLUMN-COUNT']==='0')) {
  14124. // Close any open block tags
  14125. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  14126. if(!empty($this->textbuffer)) { //Output previously buffered content
  14127. $this->printbuffer($this->textbuffer);
  14128. $this->textbuffer=array();
  14129. }
  14130. if (isset($attr['VALIGN']) && $attr['VALIGN']) {
  14131. if ($attr['VALIGN'] == 'J') { $valign = 'J'; }
  14132. else { $valign = $align[$attr['VALIGN']]; }
  14133. }
  14134. else { $valign = ''; }
  14135. if (isset($attr['COLUMN-GAP']) && $attr['COLUMN-GAP']) { $this->SetColumns($attr['COLUMN-COUNT'],$valign,$attr['COLUMN-GAP']); }
  14136. else { $this->SetColumns($attr['COLUMN-COUNT'],$valign); }
  14137. }
  14138. $this->ignorefollowingspaces = true;
  14139. break;
  14140. case 'COLUMN_BREAK': //custom-tag
  14141. case 'COLUMNBREAK': //custom-tag
  14142. case 'NEWCOLUMN': //custom-tag
  14143. $this->ignorefollowingspaces = true;
  14144. $this->NewColumn();
  14145. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  14146. break;
  14147. /*-- END COLUMNS --*/
  14148. case 'BDO':
  14149. // $this->biDirectional = true;
  14150. break;
  14151. case 'TTZ':
  14152. $this->ttz = true;
  14153. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14154. $this->setCSS(array('FONT-FAMILY'=>'czapfdingbats','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  14155. break;
  14156. case 'TTS':
  14157. $this->tts = true;
  14158. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14159. $this->setCSS(array('FONT-FAMILY'=>'csymbol','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  14160. break;
  14161. case 'TTA':
  14162. $this->tta = true;
  14163. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14164. if (in_array($this->FontFamily,$this->mono_fonts)) {
  14165. $this->setCSS(array('FONT-FAMILY'=>'ccourier'),'INLINE');
  14166. }
  14167. else if (in_array($this->FontFamily,$this->serif_fonts)) {
  14168. $this->setCSS(array('FONT-FAMILY'=>'ctimes'),'INLINE');
  14169. }
  14170. else {
  14171. $this->setCSS(array('FONT-FAMILY'=>'chelvetica'),'INLINE');
  14172. }
  14173. break;
  14174. // INLINE PHRASES OR STYLES
  14175. case 'SUB':
  14176. case 'SUP':
  14177. case 'ACRONYM':
  14178. case 'BIG':
  14179. case 'SMALL':
  14180. case 'INS':
  14181. case 'S':
  14182. case 'STRIKE':
  14183. case 'DEL':
  14184. case 'STRONG':
  14185. case 'CITE':
  14186. case 'Q':
  14187. case 'EM':
  14188. case 'B':
  14189. case 'I':
  14190. case 'U':
  14191. case 'SAMP':
  14192. case 'CODE':
  14193. case 'KBD':
  14194. case 'TT':
  14195. case 'VAR':
  14196. case 'FONT':
  14197. case 'MARK': // mPDF 5.5.09
  14198. case 'TIME':
  14199. case 'SPAN':
  14200. /*-- ANNOTATIONS --*/
  14201. if ($this->title2annots && isset($attr['TITLE'])) {
  14202. $objattr = array();
  14203. $objattr['margin_top'] = 0;
  14204. $objattr['margin_bottom'] = 0;
  14205. $objattr['margin_left'] = 0;
  14206. $objattr['margin_right'] = 0;
  14207. $objattr['width'] = 0;
  14208. $objattr['height'] = 0;
  14209. $objattr['border_top']['w'] = 0;
  14210. $objattr['border_bottom']['w'] = 0;
  14211. $objattr['border_left']['w'] = 0;
  14212. $objattr['border_right']['w'] = 0;
  14213. $objattr['CONTENT'] = $attr['TITLE'];
  14214. $objattr['type'] = 'annot';
  14215. $objattr['POS-X'] = 0;
  14216. $objattr['POS-Y'] = 0;
  14217. $objattr['ICON'] = 'Comment';
  14218. $objattr['AUTHOR'] = '';
  14219. $objattr['SUBJECT'] = '';
  14220. $objattr['OPACITY'] = $this->annotOpacity;
  14221. $objattr['COLOR'] = $this->ConvertColor('yellow');
  14222. $annot = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14223. }
  14224. /*-- END ANNOTATIONS --*/
  14225. if ($tag == 'SPAN') {
  14226. $this->spanlvl++;
  14227. $this->InlineProperties['SPAN'][$this->spanlvl] = $this->saveInlineProperties();
  14228. if (isset($annot)) { $this->InlineAnnots[$tag][$this->spanlvl] = $annot; } // *ANNOTATIONS*
  14229. }
  14230. else {
  14231. if (!isset($this->InlineProperties[$tag])) $this->InlineProperties[$tag] = $this->saveInlineProperties(); // mPDF 5.4.13
  14232. if (isset($annot)) { $this->InlineAnnots[$tag] = $annot; } // *ANNOTATIONS*
  14233. }
  14234. $properties = $this->MergeCSS('INLINE',$tag,$attr);
  14235. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14236. break;
  14237. case 'A':
  14238. if (isset($attr['NAME']) and $attr['NAME'] != '') {
  14239. $e = '';
  14240. /*-- BOOKMARKS --*/
  14241. if ($this->anchor2Bookmark) {
  14242. $objattr = array();
  14243. $objattr['CONTENT'] = htmlspecialchars_decode($attr['NAME'],ENT_QUOTES);
  14244. $objattr['type'] = 'bookmark';
  14245. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  14246. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14247. }
  14248. /*-- END BOOKMARKS --*/
  14249. if($this->tableLevel) { // *TABLES*
  14250. $this->_saveCellTextBuffer($e, '', $attr['NAME']); // *TABLES*
  14251. } // *TABLES*
  14252. else { // *TABLES*
  14253. $this->_saveTextBuffer($e, '', $attr['NAME']); //an internal link (adds a space for recognition)
  14254. } // *TABLES*
  14255. }
  14256. if (isset($attr['HREF'])) {
  14257. $this->InlineProperties['A'] = $this->saveInlineProperties();
  14258. $properties = $this->MergeCSS('',$tag,$attr);
  14259. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14260. $this->HREF=htmlspecialchars_decode(urldecode($attr['HREF']));
  14261. }
  14262. break;
  14263. case 'LEGEND': // mPDF 5.4.18
  14264. $this->InlineProperties['LEGEND'] = $this->saveInlineProperties();
  14265. $properties = $this->MergeCSS('',$tag,$attr);
  14266. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14267. break;
  14268. case 'PROGRESS': // mPDF 5.5.09
  14269. case 'METER': // mPDF 5.5.09
  14270. $this->inMeter = true; // mPDF 5.5.09
  14271. if (isset($attr['MAX']) && $attr['MAX']) { $max = $attr['MAX']; }
  14272. else { $max = 1; }
  14273. if (isset($attr['MIN']) && $attr['MIN'] && $tag=='METER') { $min = $attr['MIN']; }
  14274. else { $min = 0; }
  14275. if ($max < $min) { $max = $min; }
  14276. if (isset($attr['VALUE']) && ($attr['VALUE'] || $attr['VALUE']==='0')) {
  14277. $value = $attr['VALUE'];
  14278. if ($value < $min) { $value = $min; }
  14279. else if ($value > $max) { $value = $max; }
  14280. }
  14281. else { $value = ''; }
  14282. if (isset($attr['LOW']) && $attr['LOW']) { $low = $attr['LOW']; }
  14283. else { $low = $min; }
  14284. if ($low < $min) { $low = $min; }
  14285. else if ($low > $max) { $low = $max; }
  14286. if (isset($attr['HIGH']) && $attr['HIGH']) { $high = $attr['HIGH']; }
  14287. else { $high = $max; }
  14288. if ($high < $low) { $high = $low; }
  14289. else if ($high > $max) { $high = $max; }
  14290. if (isset($attr['OPTIMUM']) && $attr['OPTIMUM']) { $optimum = $attr['OPTIMUM']; }
  14291. else { $optimum = $min + (($max-$min)/2); }
  14292. if ($optimum < $min) { $optimum = $min; }
  14293. else if ($optimum > $max) { $optimum = $max; }
  14294. if (isset($attr['TYPE']) && $attr['TYPE']) { $type = $attr['TYPE']; }
  14295. else { $type = ''; }
  14296. $objattr = array();
  14297. $objattr['margin_top'] = 0;
  14298. $objattr['margin_bottom'] = 0;
  14299. $objattr['margin_left'] = 0;
  14300. $objattr['margin_right'] = 0;
  14301. $objattr['padding_top'] = 0;
  14302. $objattr['padding_bottom'] = 0;
  14303. $objattr['padding_left'] = 0;
  14304. $objattr['padding_right'] = 0;
  14305. $objattr['width'] = 0;
  14306. $objattr['height'] = 0;
  14307. $objattr['border_top']['w'] = 0;
  14308. $objattr['border_bottom']['w'] = 0;
  14309. $objattr['border_left']['w'] = 0;
  14310. $objattr['border_right']['w'] = 0;
  14311. $properties = $this->MergeCSS('',$tag,$attr);
  14312. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  14313. return;
  14314. }
  14315. $objattr['visibility'] = 'visible';
  14316. if (isset($properties['VISIBILITY'])) {
  14317. $v = strtolower($properties['VISIBILITY']);
  14318. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  14319. $objattr['visibility'] = $v;
  14320. }
  14321. }
  14322. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14323. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14324. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14325. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14326. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14327. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14328. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14329. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14330. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  14331. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  14332. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  14333. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  14334. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14335. $w = 0;
  14336. $h = 0;
  14337. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14338. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14339. if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14340. if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14341. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  14342. if ($this->HREF) {
  14343. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  14344. $href = $this->HREF;
  14345. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  14346. $this->internallink[$href] = $this->AddLink();
  14347. $objattr['link'] = $this->internallink[$href];
  14348. }
  14349. else { $objattr['link'] = $this->HREF; }
  14350. }
  14351. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  14352. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  14353. // Image file
  14354. if (!class_exists('meter', false)) {
  14355. include(_MPDF_PATH.'classes/meter.php');
  14356. }
  14357. $this->meter = new meter();
  14358. $svg = $this->meter->makeSVG(strtolower($tag), $type, $value, $max, $min, $optimum, $low, $high);
  14359. //Save to local file
  14360. $srcpath= _MPDF_TEMP_PATH.'_tempSVG'.RAND(1,10000).'_'.strtolower($tag).'.svg';
  14361. file_put_contents($srcpath, $svg);
  14362. $orig_srcpath = $srcpath;
  14363. $this->GetFullPath($srcpath);
  14364. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  14365. if(!$info) {
  14366. $info = $this->_getImage($this->noImageFile);
  14367. if ($info) {
  14368. $srcpath = $this->noImageFile;
  14369. $w = ($info['w'] * (25.4/$this->dpi));
  14370. $h = ($info['h'] * (25.4/$this->dpi));
  14371. }
  14372. }
  14373. if(!$info) break;
  14374. $objattr['file'] = $srcpath;
  14375. //Default width and height calculation if needed
  14376. if($w==0 and $h==0) {
  14377. // SVG units are pixels
  14378. $w = $this->FontSize/(10/_MPDFK) * abs($info['w'])/_MPDFK; // mPDF 5.5.21
  14379. $h = $this->FontSize/(10/_MPDFK) * abs($info['h'])/_MPDFK;
  14380. }
  14381. // IF WIDTH OR HEIGHT SPECIFIED
  14382. if($w==0) $w=abs($h*$info['w']/$info['h']);
  14383. if($h==0) $h=abs($w*$info['h']/$info['w']);
  14384. // Resize to maximum dimensions of page
  14385. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  14386. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  14387. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  14388. if ($w + $extrawidth > $maxWidth ) {
  14389. $w = $maxWidth - $extrawidth;
  14390. $h=abs($w*$info['h']/$info['w']);
  14391. }
  14392. if ($h + $extraheight > $maxHeight ) {
  14393. $h = $maxHeight - $extraheight;
  14394. $w=abs($h*$info['w']/$info['h']);
  14395. }
  14396. $objattr['type'] = 'image';
  14397. $objattr['itype'] = $info['type'];
  14398. $objattr['orig_h'] = $info['h'];
  14399. $objattr['orig_w'] = $info['w'];
  14400. $objattr['wmf_x'] = $info['x'];
  14401. $objattr['wmf_y'] = $info['y'];
  14402. $objattr['height'] = $h + $extraheight;
  14403. $objattr['width'] = $w + $extrawidth;
  14404. $objattr['image_height'] = $h;
  14405. $objattr['image_width'] = $w;
  14406. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14407. $properties = array();
  14408. if ($this->tableLevel) {
  14409. $this->_saveCellTextBuffer($e, $this->HREF);
  14410. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  14411. }
  14412. else {
  14413. $this->_saveTextBuffer($e, $this->HREF);
  14414. }
  14415. break;
  14416. case 'BR':
  14417. // Added mPDF 3.0 Float DIV - CLEAR
  14418. if (isset($attr['STYLE'])) {
  14419. $properties = $this->readInlineCSS($attr['STYLE']);
  14420. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  14421. }
  14422. /*-- TABLES --*/
  14423. if($this->tableLevel) {
  14424. if ($this->blockjustfinished || $this->listjustfinished) {
  14425. $this->_saveCellTextBuffer("\n");
  14426. }
  14427. $this->_saveCellTextBuffer("\n");
  14428. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14429. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14430. }
  14431. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14432. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14433. }
  14434. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14435. }
  14436. else {
  14437. /*-- END TABLES --*/
  14438. if (count($this->textbuffer)) {
  14439. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/ $/','',$this->textbuffer[count($this->textbuffer)-1][0]);
  14440. }
  14441. $this->_saveTextBuffer("\n");
  14442. } // *TABLES*
  14443. $this->ignorefollowingspaces = true;
  14444. $this->blockjustfinished=false;
  14445. $this->listjustfinished=false;
  14446. $this->linebreakjustfinished=true;
  14447. break;
  14448. // *********** BLOCKS ********************
  14449. case 'PRE':
  14450. $this->ispre=true; // ADDED - Prevents left trim of textbuffer in printbuffer()
  14451. case 'DIV':
  14452. case 'FORM':
  14453. case 'CENTER':
  14454. case 'BLOCKQUOTE':
  14455. case 'ADDRESS':
  14456. case 'CAPTION':
  14457. case 'P':
  14458. case 'H1':
  14459. case 'H2':
  14460. case 'H3':
  14461. case 'H4':
  14462. case 'H5':
  14463. case 'H6':
  14464. case 'DL':
  14465. case 'DT':
  14466. case 'DD':
  14467. case 'FIELDSET':
  14468. // mPDF 5.5.22
  14469. case 'DETAILS':
  14470. case 'SUMMARY':
  14471. // mPDF 5.5.09
  14472. case 'ARTICLE':
  14473. case 'ASIDE':
  14474. case 'FIGURE':
  14475. case 'FIGCAPTION':
  14476. case 'FOOTER':
  14477. case 'HEADER':
  14478. case 'HGROUP':
  14479. case 'NAV':
  14480. case 'SECTION':
  14481. $p = $this->PreviewBlockCSS($tag,$attr);
  14482. if(isset($p['DISPLAY']) && strtolower($p['DISPLAY'])=='none') {
  14483. $this->blklvl++;
  14484. $this->blk[$this->blklvl]['hide'] = true;
  14485. return;
  14486. }
  14487. if($tag == 'CAPTION') {
  14488. // position is written in AdjstHTML
  14489. if (isset($attr['POSITION']) && strtolower($attr['POSITION'])=='bottom') { $divpos = 'B'; }
  14490. else { $divpos = 'T'; }
  14491. if (isset($attr['ALIGN']) && strtolower($attr['ALIGN'])=='bottom') { $cappos = 'B'; }
  14492. else if (isset($p['CAPTION-SIDE']) && strtolower($p['CAPTION-SIDE'])=='bottom') { $cappos = 'B'; }
  14493. else { $cappos = 'T'; }
  14494. if (isset($attr['ALIGN'])) { unset($attr['ALIGN']); }
  14495. if ($cappos != $divpos) {
  14496. $this->blklvl++;
  14497. $this->blk[$this->blklvl]['hide'] = true;
  14498. return;
  14499. }
  14500. }
  14501. /*-- FORMS --*/
  14502. if($tag == 'FORM') {
  14503. if (isset($attr['METHOD']) && strtolower($attr['METHOD'])=='get') { $this->form->formMethod = 'GET'; }
  14504. else { $this->form->formMethod = 'POST'; }
  14505. if (isset($attr['ACTION'])) { $this->form->formAction = $attr['ACTION']; }
  14506. else { $this->form->formAction = ''; }
  14507. }
  14508. /*-- END FORMS --*/
  14509. /*-- CSS-POSITION --*/
  14510. if ((isset($p['POSITION']) && (strtolower($p['POSITION'])=='fixed' || strtolower($p['POSITION'])=='absolute')) && $this->blklvl==0) {
  14511. if ($this->inFixedPosBlock) {
  14512. $this->Error("Cannot nest block with position:fixed or position:absolute");
  14513. }
  14514. $this->inFixedPosBlock = true;
  14515. return;
  14516. }
  14517. /*-- END CSS-POSITION --*/
  14518. // Start Block
  14519. $this->ignorefollowingspaces = true;
  14520. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  14521. else { $lastbottommargin = 0; }
  14522. $this->lastblockbottommargin = 0;
  14523. $this->blockjustfinished=false;
  14524. /*-- LISTS --*/
  14525. if ($this->listlvl>0) { return; }
  14526. /*-- END LISTS --*/
  14527. $this->InlineProperties = array();
  14528. $this->spanlvl = 0;
  14529. $this->listjustfinished=false;
  14530. $this->divbegin=true;
  14531. $this->linebreakjustfinished=false;
  14532. /*-- TABLES --*/
  14533. if ($this->tableLevel) {
  14534. // If already something on the line
  14535. if ($this->cell[$this->row][$this->col]['s'] > 0 && !$this->nestedtablejustfinished ) {
  14536. $this->_saveCellTextBuffer("\n");
  14537. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14538. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14539. }
  14540. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14541. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14542. }
  14543. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14544. }
  14545. // Cannot set block properties inside table - use Bold to indicate h1-h6
  14546. if ($tag == 'CENTER' && $this->tdbegin) { $this->cell[$this->row][$this->col]['a'] = $align['center']; }
  14547. $this->InlineProperties['BLOCKINTABLE'] = $this->saveInlineProperties();
  14548. $properties = $this->MergeCSS('',$tag,$attr);
  14549. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14550. break;
  14551. }
  14552. /*-- END TABLES --*/
  14553. if ($tag == 'P' || $tag == 'DT' || $tag == 'DD') { $this->lastoptionaltag = $tag; } // Save current HTML specified optional endtag
  14554. else { $this->lastoptionaltag = ''; }
  14555. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  14556. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  14557. $this->printbuffer($this->textbuffer,$blockstate);
  14558. $this->textbuffer=array();
  14559. $save_blklvl = $this->blklvl;
  14560. $save_blk = $this->blk;
  14561. $save_silp = $this->saveInlineProperties();
  14562. $save_spanlvl = $this->spanlvl;
  14563. $save_ilp = $this->InlineProperties;
  14564. $this->blklvl++;
  14565. $currblk =& $this->blk[$this->blklvl];
  14566. $this->initialiseBlock($currblk);
  14567. $prevblk =& $this->blk[$this->blklvl-1];
  14568. $currblk['tag'] = $tag;
  14569. $currblk['attr'] = $attr;
  14570. $this->Reset();
  14571. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  14572. $pagesel = '';
  14573. /*-- CSS-PAGE --*/
  14574. if (isset($properties['PAGE'])) { $pagesel = $properties['PAGE']; }
  14575. /*-- END CSS-PAGE --*/
  14576. // If page-box has changed AND/OR PAGE-BREAK-BEFORE
  14577. $save_cols = false;
  14578. if (($pagesel && $pagesel != $this->page_box['current']) || (isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  14579. if ($this->blklvl>1) {
  14580. // Close any open block tags
  14581. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  14582. // Output any text left in buffer
  14583. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  14584. }
  14585. /*-- COLUMNS --*/
  14586. if ($this->ColActive) {
  14587. $save_cols = true;
  14588. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  14589. $this->SetColumns(0);
  14590. }
  14591. /*-- END COLUMNS --*/
  14592. // Must Add new page if changed page properties
  14593. if (isset($properties['PAGE-BREAK-BEFORE'])) {
  14594. if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14595. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14596. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'ALWAYS') { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14597. else if ($this->page_box['current'] != $pagesel) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } // *CSS-PAGE*
  14598. }
  14599. /*-- CSS-PAGE --*/
  14600. else if ($pagesel != $this->page_box['current']) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14601. /*-- END CSS-PAGE --*/
  14602. // if using htmlheaders, the headers need to be rewritten when new page
  14603. // done by calling WriteHTML() within resethtmlheaders
  14604. // so block is reset to 0 - now we need to resurrect it
  14605. // As in WriteHTML() initialising
  14606. if (!($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  14607. $this->blklvl = 0;
  14608. $this->lastblocklevelchange = 0;
  14609. $this->blk = array();
  14610. $this->initialiseBlock($this->blk[0]);
  14611. $this->blk[0]['width'] =& $this->pgwidth;
  14612. $this->blk[0]['inner_width'] =& $this->pgwidth;
  14613. $this->blk[0]['blockContext'] = $this->blockContext;
  14614. $properties = $this->MergeCSS('BLOCK','BODY','');
  14615. $this->setCSS($properties,'','BODY');
  14616. $this->blklvl++;
  14617. $currblk =& $this->blk[$this->blklvl];
  14618. $prevblk =& $this->blk[$this->blklvl-1];
  14619. $this->initialiseBlock($currblk);
  14620. $currblk['tag'] = $tag;
  14621. $currblk['attr'] = $attr;
  14622. $this->Reset();
  14623. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  14624. }
  14625. /*-- COLUMNS --*/
  14626. if ($save_cols) {
  14627. // Restore columns
  14628. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  14629. }
  14630. /*-- END COLUMNS --*/
  14631. if ($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE']) {
  14632. $this->blk = $save_blk;
  14633. // Re-open block tags
  14634. $t = $this->blk[0]['tag'];
  14635. $a = $this->blk[0]['attr'];
  14636. $this->blklvl = 0;
  14637. for ($b=0; $b<=$save_blklvl;$b++) {
  14638. $tc = $t;
  14639. $ac = $a;
  14640. $t = $this->blk[$b+1]['tag'];
  14641. $a = $this->blk[$b+1]['attr'];
  14642. unset($this->blk[$b+1]);
  14643. $this->OpenTag($tc,$ac);
  14644. }
  14645. $this->spanlvl = $save_spanlvl;
  14646. $this->InlineProperties = $save_ilp;
  14647. $this->restoreInlineProperties($save_silp);
  14648. }
  14649. }
  14650. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE']) == 'AVOID' && !$this->ColActive && !$this->keep_block_together) {
  14651. $currblk['keep_block_together'] = 1;
  14652. $this->kt_y00 = $this->y;
  14653. $this->kt_p00 = $this->page;
  14654. $this->keep_block_together = 1;
  14655. $this->divbuffer = array();
  14656. $this->ktLinks = array();
  14657. $this->ktAnnots = array();
  14658. $this->ktForms = array();
  14659. $this->ktBlock = array();
  14660. $this->ktReference = array();
  14661. $this->ktBMoutlines = array();
  14662. $this->_kttoc = array();
  14663. }
  14664. if ($lastbottommargin && isset($properties['MARGIN-TOP']) && $properties['MARGIN-TOP'] && empty($properties['FLOAT'])) { $currblk['lastbottommargin'] = $lastbottommargin; }
  14665. $this->setCSS($properties,'BLOCK',$tag); //name(id/class/style) found in the CSS array!
  14666. $currblk['InlineProperties'] = $this->saveInlineProperties();
  14667. if (isset($properties['VISIBILITY'])) {
  14668. $v = strtolower($properties['VISIBILITY']);
  14669. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible' && !$this->tableLevel) {
  14670. $currblk['visibility'] = $v;
  14671. $this->SetVisibility($v);
  14672. }
  14673. }
  14674. if(isset($attr['DIR']) && $attr['DIR']) { $currblk['direction'] = strtolower($attr['DIR']); }
  14675. if(isset($attr['ALIGN']) && $attr['ALIGN']) { $currblk['block-align'] = $align[strtolower($attr['ALIGN'])]; }
  14676. if (isset($properties['HEIGHT'])) {
  14677. $currblk['css_set_height'] = $this->ConvertSize($properties['HEIGHT'],($this->h - $this->tMargin - $this->bMargin),$this->FontSize,false);
  14678. 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); }
  14679. }
  14680. else { $currblk['css_set_height'] = false; }
  14681. // Added mPDF 3.0 Float DIV
  14682. if (isset($prevblk['blockContext'])) { $currblk['blockContext'] = $prevblk['blockContext'] ; } // *CSS-FLOAT*
  14683. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']), $this->blklvl-1); } // *CSS-FLOAT*
  14684. $container_w = $prevblk['inner_width'];
  14685. $bdr = $currblk['border_right']['w'];
  14686. $bdl = $currblk['border_left']['w'];
  14687. $pdr = $currblk['padding_right'];
  14688. $pdl = $currblk['padding_left'];
  14689. if (isset($currblk['css_set_width'])) { $setwidth = $currblk['css_set_width']; }
  14690. else { $setwidth = 0; }
  14691. /*-- CSS-FLOAT --*/
  14692. if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'RIGHT' && !$this->ColActive) {
  14693. // Cancel Keep-Block-together
  14694. $currblk['keep_block_together'] = false;
  14695. $this->kt_y00 = '';
  14696. $this->keep_block_together = 0;
  14697. $this->blockContext++;
  14698. $currblk['blockContext'] = $this->blockContext;
  14699. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14700. // DIV is too narrow for text to fit!
  14701. $maxw = $container_w - $l_width - $r_width;
  14702. if (($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) {
  14703. // Too narrow to fit - try to move down past L or R float
  14704. 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))) {
  14705. $this->ClearFloats('LEFT', $this->blklvl-1);
  14706. }
  14707. 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))) {
  14708. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14709. }
  14710. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14711. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14712. }
  14713. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14714. $currblk['float'] = 'R';
  14715. $currblk['float_start_y'] = $this->y;
  14716. if ($currblk['css_set_width']) {
  14717. $currblk['margin_left'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14718. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14719. }
  14720. else {
  14721. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14722. // and do borders and backgrounds - For now - just set to maximum width left
  14723. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14724. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14725. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14726. }
  14727. }
  14728. else if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'LEFT' && !$this->ColActive) {
  14729. // Cancel Keep-Block-together
  14730. $currblk['keep_block_together'] = false;
  14731. $this->kt_y00 = '';
  14732. $this->keep_block_together = 0;
  14733. $this->blockContext++;
  14734. $currblk['blockContext'] = $this->blockContext;
  14735. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14736. // DIV is too narrow for text to fit!
  14737. $maxw = $container_w - $l_width - $r_width;
  14738. if (($setwidth + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) {
  14739. // Too narrow to fit - try to move down past L or R float
  14740. 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))) {
  14741. $this->ClearFloats('LEFT', $this->blklvl-1);
  14742. }
  14743. 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))) {
  14744. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14745. }
  14746. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14747. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14748. }
  14749. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14750. $currblk['float'] = 'L';
  14751. $currblk['float_start_y'] = $this->y;
  14752. if ($setwidth) {
  14753. $currblk['margin_right'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14754. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14755. }
  14756. else {
  14757. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14758. // and do borders and backgrounds - For now - just set to maximum width left
  14759. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14760. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14761. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14762. }
  14763. }
  14764. else {
  14765. // Don't allow overlap - if floats present - adjust padding to avoid overlap with Floats
  14766. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14767. $maxw = $container_w - $l_width - $r_width;
  14768. 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))) {
  14769. // Too narrow to fit - try to move down past L or R float
  14770. 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))) {
  14771. $this->ClearFloats('LEFT', $this->blklvl-1);
  14772. }
  14773. 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))) {
  14774. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14775. }
  14776. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14777. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14778. }
  14779. if ($r_exists) { $currblk['padding_right'] = max(($r_width-$currblk['margin_right']-$bdr), $pdr); }
  14780. if ($l_exists) { $currblk['padding_left'] = max(($l_width-$currblk['margin_left']-$bdl), $pdl); }
  14781. }
  14782. /*-- END CSS-FLOAT --*/
  14783. /*-- BORDER-RADIUS --*/
  14784. // Automatically increase padding if required for border-radius
  14785. if ($this->autoPadding && !$this->ColActive && !$this->keep_block_together) {
  14786. if ($currblk['border_radius_TL_H']>$currblk['padding_left'] && $currblk['border_radius_TL_V']>$currblk['padding_top']) {
  14787. if ($currblk['border_radius_TL_H']>$currblk['border_radius_TL_V']) {
  14788. $this->_borderPadding($currblk['border_radius_TL_H'],$currblk['border_radius_TL_V'], $currblk['padding_left'], $currblk['padding_top']);
  14789. }
  14790. else {
  14791. $this->_borderPadding($currblk['border_radius_TL_V'],$currblk['border_radius_TL_H'], $currblk['padding_top'], $currblk['padding_left']);
  14792. }
  14793. }
  14794. if ($currblk['border_radius_TR_H']>$currblk['padding_right'] && $currblk['border_radius_TR_V']>$currblk['padding_top']) {
  14795. if ($currblk['border_radius_TR_H']>$currblk['border_radius_TR_V']) {
  14796. $this->_borderPadding($currblk['border_radius_TR_H'],$currblk['border_radius_TR_V'], $currblk['padding_right'], $currblk['padding_top']);
  14797. }
  14798. else {
  14799. $this->_borderPadding($currblk['border_radius_TR_V'],$currblk['border_radius_TR_H'], $currblk['padding_top'], $currblk['padding_right']);
  14800. }
  14801. }
  14802. if ($currblk['border_radius_BL_H']>$currblk['padding_left'] && $currblk['border_radius_BL_V']>$currblk['padding_bottom']) {
  14803. if ($currblk['border_radius_BL_H']>$currblk['border_radius_BL_V']) {
  14804. $this->_borderPadding($currblk['border_radius_BL_H'],$currblk['border_radius_BL_V'], $currblk['padding_left'], $currblk['padding_bottom']);
  14805. }
  14806. else {
  14807. $this->_borderPadding($currblk['border_radius_BL_V'],$currblk['border_radius_BL_H'], $currblk['padding_bottom'], $currblk['padding_left']);
  14808. }
  14809. }
  14810. if ($currblk['border_radius_BR_H']>$currblk['padding_right'] && $currblk['border_radius_BR_V']>$currblk['padding_bottom']) {
  14811. if ($currblk['border_radius_BR_H']>$currblk['border_radius_BR_V']) {
  14812. $this->_borderPadding($currblk['border_radius_BR_H'],$currblk['border_radius_BR_V'], $currblk['padding_right'], $currblk['padding_bottom']);
  14813. }
  14814. else {
  14815. $this->_borderPadding($currblk['border_radius_BR_V'],$currblk['border_radius_BR_H'], $currblk['padding_bottom'], $currblk['padding_right']);
  14816. }
  14817. }
  14818. }
  14819. /*-- END BORDER-RADIUS --*/
  14820. // Hanging indent - if negative indent: ensure padding is >= indent
  14821. if(!isset($currblk['text_indent'])) { $currblk['text_indent'] = null; }
  14822. if(!isset($currblk['inner_width'])) { $currblk['inner_width'] = null; }
  14823. $cbti = $this->ConvertSize($currblk['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14824. if ($cbti < 0) {
  14825. $hangind = -($cbti);
  14826. if ($currblk['direction'] == 'rtl') { // *RTL*
  14827. $currblk['padding_right'] = max($currblk['padding_right'],$hangind); // *RTL*
  14828. } // *RTL*
  14829. else { // *RTL*
  14830. $currblk['padding_left'] = max($currblk['padding_left'],$hangind);
  14831. } // *RTL*
  14832. }
  14833. if (isset($currblk['css_set_width'])) {
  14834. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14835. // Try to reduce margins to accomodate - if still too wide, set margin-right/left=0 (reduces width)
  14836. $anyextra = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14837. if ($anyextra>0) {
  14838. $currblk['margin_left'] = $currblk['margin_right'] = $anyextra /2;
  14839. }
  14840. else {
  14841. $currblk['margin_left'] = $currblk['margin_right'] = 0;
  14842. }
  14843. }
  14844. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14845. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14846. $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']);
  14847. if ($currblk['margin_left'] < 0) {
  14848. $currblk['margin_left'] = 0;
  14849. }
  14850. }
  14851. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14852. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14853. $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']);
  14854. if ($currblk['margin_right'] < 0) {
  14855. $currblk['margin_right'] = 0;
  14856. }
  14857. }
  14858. else {
  14859. if ($currblk['direction'] == 'rtl') { // *RTL*
  14860. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14861. $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*
  14862. if ($currblk['margin_left'] < 0) { // *RTL*
  14863. $currblk['margin_left'] = 0; // *RTL*
  14864. } // *RTL*
  14865. } // *RTL*
  14866. else { // *RTL*
  14867. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14868. $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']);
  14869. if ($currblk['margin_right'] < 0) {
  14870. $currblk['margin_right'] = 0;
  14871. }
  14872. } // *RTL*
  14873. }
  14874. }
  14875. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14876. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14877. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14878. $currblk['inner_width'] = $currblk['width'] - ($currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14879. // Check DIV is not now too narrow to fit text
  14880. $mw = 2*$this->GetCharWidth('W',false);
  14881. if ($currblk['inner_width'] < $mw) {
  14882. $currblk['padding_left'] = 0;
  14883. $currblk['padding_right'] = 0;
  14884. $currblk['border_left']['w'] = 0.2;
  14885. $currblk['border_right']['w'] = 0.2;
  14886. $currblk['margin_left'] = 0;
  14887. $currblk['margin_right'] = 0;
  14888. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14889. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14890. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14891. $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']);
  14892. // if ($currblk['inner_width'] < $mw) { $this->Error("DIV is too narrow for text to fit!"); }
  14893. }
  14894. $this->x = $this->lMargin + $currblk['outer_left_margin'];
  14895. /*-- BACKGROUNDS --*/
  14896. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive && !$this->keep_block_together) {
  14897. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  14898. if ($ret) { $currblk['background-image'] = $ret; }
  14899. }
  14900. /*-- END BACKGROUNDS --*/
  14901. /*-- TABLES --*/
  14902. if ($this->use_kwt && isset($attr['KEEP-WITH-TABLE']) && !$this->ColActive && !$this->keep_block_together) {
  14903. $this->kwt = true;
  14904. $this->kwt_y0 = $this->y;
  14905. $this->kwt_x0 = $this->x;
  14906. $this->kwt_height = 0;
  14907. $this->kwt_buffer = array();
  14908. $this->kwt_Links = array();
  14909. $this->kwt_Annots = array();
  14910. $this->kwt_moved = false;
  14911. $this->kwt_saved = false;
  14912. $this->kwt_Reference = array();
  14913. $this->kwt_BMoutlines = array();
  14914. $this->kwt_toc = array();
  14915. }
  14916. else {
  14917. /*-- END TABLES --*/
  14918. $this->kwt = false;
  14919. } // *TABLES*
  14920. //Save x,y coords in case we need to print borders...
  14921. $currblk['y0'] = $this->y;
  14922. $currblk['x0'] = $this->x;
  14923. $currblk['startpage'] = $this->page;
  14924. $this->oldy = $this->y;
  14925. $this->lastblocklevelchange = 1 ;
  14926. break;
  14927. case 'HR':
  14928. // Added mPDF 3.0 Float DIV - CLEAR
  14929. if (isset($attr['STYLE'])) {
  14930. $properties = $this->readInlineCSS($attr['STYLE']);
  14931. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  14932. }
  14933. $this->ignorefollowingspaces = true;
  14934. $objattr = array();
  14935. $objattr['margin_top'] = 0;
  14936. $objattr['margin_bottom'] = 0;
  14937. $objattr['margin_left'] = 0;
  14938. $objattr['margin_right'] = 0;
  14939. $objattr['width'] = 0;
  14940. $objattr['height'] = 0;
  14941. $objattr['border_top']['w'] = 0;
  14942. $objattr['border_bottom']['w'] = 0;
  14943. $objattr['border_left']['w'] = 0;
  14944. $objattr['border_right']['w'] = 0;
  14945. $properties = $this->MergeCSS('',$tag,$attr);
  14946. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14947. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14948. if (isset($properties['WIDTH'])) { $objattr['width'] = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); }
  14949. if (isset($properties['TEXT-ALIGN'])) { $objattr['align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  14950. if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14951. $objattr['align'] = 'R';
  14952. }
  14953. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14954. $objattr['align'] = 'L';
  14955. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto' && isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14956. $objattr['align'] = 'C';
  14957. }
  14958. }
  14959. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14960. if (isset($properties['HEIGHT'])) { $objattr['linewidth'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14961. if(isset($attr['WIDTH']) && $attr['WIDTH'] != '') $objattr['width'] = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14962. if(isset($attr['ALIGN']) && $attr['ALIGN'] != '') $objattr['align'] = $align[strtolower($attr['ALIGN'])];
  14963. if(isset($attr['COLOR']) && $attr['COLOR'] != '') $objattr['color'] = $this->ConvertColor($attr['COLOR']);
  14964. /*-- TABLES --*/
  14965. if ($this->tableLevel) {
  14966. $objattr['W-PERCENT'] = 100;
  14967. if (isset($properties['WIDTH']) && stristr($properties['WIDTH'],'%')) {
  14968. $properties['WIDTH'] += 0; //make "90%" become simply "90"
  14969. $objattr['W-PERCENT'] = $properties['WIDTH'];
  14970. }
  14971. if (isset($attr['WIDTH']) && stristr($attr['WIDTH'],'%')) {
  14972. $attr['WIDTH'] += 0; //make "90%" become simply "90"
  14973. $objattr['W-PERCENT'] = $attr['WIDTH'];
  14974. }
  14975. }
  14976. /*-- END TABLES --*/
  14977. $objattr['type'] = 'hr';
  14978. $objattr['height'] = $objattr['linewidth'] + $objattr['margin_top'] + $objattr['margin_bottom'];
  14979. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14980. // Clear properties - tidy up
  14981. $properties = array();
  14982. /*-- TABLES --*/
  14983. // Output it to buffers
  14984. if ($this->tableLevel) {
  14985. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14986. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14987. }
  14988. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14989. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14990. }
  14991. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14992. $this->_saveCellTextBuffer($e, $this->HREF);
  14993. }
  14994. else {
  14995. /*-- END TABLES --*/
  14996. $this->_saveTextBuffer($e, $this->HREF);
  14997. } // *TABLES*
  14998. break;
  14999. /*-- BARCODES --*/
  15000. case 'BARCODE':
  15001. if(isset($attr['CODE']) && $attr['CODE']) {
  15002. $objattr = array();
  15003. $objattr['margin_top'] = 0;
  15004. $objattr['margin_bottom'] = 0;
  15005. $objattr['margin_left'] = 0;
  15006. $objattr['margin_right'] = 0;
  15007. $objattr['padding_top'] = 0;
  15008. $objattr['padding_bottom'] = 0;
  15009. $objattr['padding_left'] = 0;
  15010. $objattr['padding_right'] = 0;
  15011. $objattr['width'] = 0;
  15012. $objattr['height'] = 0;
  15013. $objattr['border_top']['w'] = 0;
  15014. $objattr['border_bottom']['w'] = 0;
  15015. $objattr['border_left']['w'] = 0;
  15016. $objattr['border_right']['w'] = 0;
  15017. $objattr['code'] = $attr['CODE'];
  15018. if(isset($attr['TYPE'])) {
  15019. $objattr['btype'] = trim(strtoupper($attr['TYPE']));
  15020. }
  15021. else { $objattr['btype'] = 'EAN13'; } // default
  15022. if (preg_match('/^(EAN13|ISBN|ISSN|EAN8|UPCA|UPCE)P([25])$/',$objattr['btype'],$m)) {
  15023. $objattr['btype'] = $m[1];
  15024. $objattr['bsupp'] = $m[2];
  15025. if (preg_match('/^(\S+)\s+(.*)$/',$objattr['code'],$mm)) {
  15026. $objattr['code'] = $mm[1];
  15027. $objattr['bsupp_code'] = $mm[2];
  15028. }
  15029. }
  15030. else { $objattr['bsupp'] = 0; }
  15031. if(isset($attr['TEXT']) && $attr['TEXT']==1) { $objattr['showtext'] = 1; }
  15032. else { $objattr['showtext'] = 0; }
  15033. if(isset($attr['SIZE']) && $attr['SIZE']>0) { $objattr['bsize'] = $attr['SIZE']; }
  15034. else { $objattr['bsize'] = 1; }
  15035. if(isset($attr['HEIGHT']) && $attr['HEIGHT']>0) { $objattr['bheight'] = $attr['HEIGHT']; }
  15036. else { $objattr['bheight'] = 1; }
  15037. if(isset($attr['PR']) && $attr['PR']>0) { $objattr['pr_ratio'] = $attr['PR']; }
  15038. else { $objattr['pr_ratio'] = ''; }
  15039. $properties = $this->MergeCSS('',$tag,$attr);
  15040. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15041. return;
  15042. }
  15043. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15044. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15045. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15046. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15047. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15048. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15049. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15050. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15051. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15052. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15053. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15054. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15055. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15056. if (isset($properties['COLOR']) && $properties['COLOR'] != '') { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15057. else { $objattr['color'] = false; }
  15058. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15059. else { $objattr['bgcolor'] = false; }
  15060. if (!class_exists('PDFBarcode', false)) {
  15061. include(_MPDF_PATH.'classes/barcode.php');
  15062. }
  15063. $this->barcode = new PDFBarcode();
  15064. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  15065. $code = preg_replace('/\-/','',$objattr['code']);
  15066. if ($objattr['btype'] == 'ISSN' || $objattr['btype'] == 'ISBN') {
  15067. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  15068. }
  15069. else { $arrcode = $this->barcode->getBarcodeArray($code, $objattr['btype'] ); }
  15070. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  15071. if ($objattr['bsupp'] == 2 || $objattr['bsupp'] == 5) { // EAN-2 or -5 Supplement
  15072. $supparrcode = $this->barcode->getBarcodeArray($objattr['bsupp_code'], 'EAN'.$objattr['bsupp'] );
  15073. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR'] + $supparrcode["maxw"] + $supparrcode['sepM']) * $arrcode['nom-X'] * $objattr['bsize'];
  15074. }
  15075. else {
  15076. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  15077. }
  15078. $h = $arrcode['nom-H'] * $objattr['bsize'] * $objattr['bheight'];
  15079. // Add height for ISBN string + margin from top of bars
  15080. if (($objattr['showtext'] && $objattr['btype'] == 'EAN13') || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN') {
  15081. $tisbnm = 1.5 * $objattr['bsize']; // Top margin between TOP TEXT (isbn - if shown) & bars
  15082. $isbn_fontsize = 2.1 * $objattr['bsize'];
  15083. $h += $isbn_fontsize + $tisbnm ;
  15084. }
  15085. }
  15086. // QR-code
  15087. else if ($objattr['btype'] == 'QR') {
  15088. $w = $h = $objattr['bsize']*25; // Factor of 25mm (default)
  15089. $objattr['errorlevel'] = 'L';
  15090. if (isset($attr['ERROR'])) { $objattr['errorlevel'] = $attr['ERROR']; }
  15091. }
  15092. else if ($objattr['btype'] == 'IMB' || $objattr['btype'] == 'RM4SCC' || $objattr['btype'] == 'KIX' || $objattr['btype'] == 'POSTNET' || $objattr['btype'] == 'PLANET') {
  15093. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'] );
  15094. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  15095. $w = ($arrcode["maxw"] * $arrcode['nom-X'] * $objattr['bsize']) + $arrcode['quietL'] + $arrcode['quietR'];
  15096. $h = ($arrcode['nom-H'] * $objattr['bsize']) + (2*$arrcode['quietTB']);
  15097. }
  15098. 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'))) {
  15099. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'], $objattr['pr_ratio'] );
  15100. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  15101. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  15102. $h = ((2*$arrcode['lightTB'] * $arrcode['nom-X']) + $arrcode['nom-H']) * $objattr['bsize'] * $objattr['bheight'];
  15103. }
  15104. else { break; }
  15105. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15106. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15107. $objattr['type'] = 'barcode';
  15108. $objattr['height'] = $h + $extraheight;
  15109. $objattr['width'] = $w + $extrawidth;
  15110. $objattr['barcode_height'] = $h;
  15111. $objattr['barcode_width'] = $w;
  15112. /*-- CSS-IMAGE-FLOAT --*/
  15113. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  15114. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  15115. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  15116. }
  15117. }
  15118. /*-- END CSS-IMAGE-FLOAT --*/
  15119. $e = "\xbb\xa4\xactype=barcode,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15120. // Clear properties - tidy up
  15121. $properties = array();
  15122. /*-- TABLES --*/
  15123. // Output it to buffers
  15124. if ($this->tableLevel) {
  15125. $this->_saveCellTextBuffer($e, $this->HREF);
  15126. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15127. }
  15128. else {
  15129. /*-- END TABLES --*/
  15130. $this->_saveTextBuffer($e, $this->HREF);
  15131. } // *TABLES*
  15132. }
  15133. break;
  15134. /*-- END BARCODES --*/
  15135. // *********** FORM ELEMENTS ********************
  15136. /*-- FORMS --*/
  15137. case 'SELECT':
  15138. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  15139. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15140. $properties = $this->MergeCSS('',$tag,$attr);
  15141. if (isset($properties['FONT-FAMILY'])) {
  15142. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15143. }
  15144. if (isset($properties['FONT-SIZE'])) {
  15145. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  15146. $this->SetFontSize($mmsize*_MPDFK,false);
  15147. }
  15148. if (isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') {
  15149. $this->selectoption['SPELLCHECK'] = true;
  15150. }
  15151. if (isset($properties['COLOR'])) { $this->selectoption['COLOR'] = $this->ConvertColor($properties['COLOR']); }
  15152. $this->specialcontent = "type=select";
  15153. if(isset($attr['DISABLED'])) { $this->selectoption['DISABLED'] = $attr['DISABLED']; }
  15154. if(isset($attr['READONLY'])) { $this->selectoption['READONLY'] = $attr['READONLY']; }
  15155. if(isset($attr['REQUIRED'])) { $this->selectoption['REQUIRED'] = $attr['REQUIRED']; }
  15156. if(isset($attr['EDITABLE'])) { $this->selectoption['EDITABLE'] = $attr['EDITABLE']; }
  15157. if(isset($attr['TITLE'])) { $this->selectoption['TITLE'] = $attr['TITLE']; }
  15158. if(isset($attr['MULTIPLE'])) { $this->selectoption['MULTIPLE'] = $attr['MULTIPLE']; }
  15159. if(isset($attr['SIZE']) && $attr['SIZE']>1) { $this->selectoption['SIZE'] = $attr['SIZE']; }
  15160. if ($this->useActiveForms) {
  15161. if(isset($attr['NAME'])) { $this->selectoption['NAME'] = $attr['NAME']; }
  15162. if (isset($attr['ONCHANGE'])) { $this->selectoption['ONCHANGE'] = $attr['ONCHANGE']; }
  15163. }
  15164. $properties = array();
  15165. break;
  15166. case 'OPTION':
  15167. $this->lastoptionaltag = 'OPTION'; // Save current HTML specified optional endtag
  15168. $this->selectoption['ACTIVE'] = true;
  15169. $this->selectoption['currentSEL'] = false;
  15170. if (empty($this->selectoption)) {
  15171. $this->selectoption['MAXWIDTH'] = '';
  15172. $this->selectoption['SELECTED'] = '';
  15173. }
  15174. if (isset($attr['SELECTED'])) {
  15175. $this->selectoption['SELECTED'] = '';
  15176. $this->selectoption['currentSEL'] = true;
  15177. }
  15178. if(isset($attr['VALUE'])) {
  15179. $attr['VALUE'] = strcode2utf($attr['VALUE']);
  15180. $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']);
  15181. if ($this->onlyCoreFonts)
  15182. $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8');
  15183. }
  15184. $this->selectoption['currentVAL'] = $attr['VALUE'];
  15185. break;
  15186. case 'TEXTAREA':
  15187. $objattr = array();
  15188. $objattr['margin_top'] = 0;
  15189. $objattr['margin_bottom'] = 0;
  15190. $objattr['margin_left'] = 0;
  15191. $objattr['margin_right'] = 0;
  15192. $objattr['width'] = 0;
  15193. $objattr['height'] = 0;
  15194. $objattr['border_top']['w'] = 0;
  15195. $objattr['border_bottom']['w'] = 0;
  15196. $objattr['border_left']['w'] = 0;
  15197. $objattr['border_right']['w'] = 0;
  15198. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  15199. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  15200. if(isset($attr['REQUIRED'])) { $objattr['required'] = true; }
  15201. if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; }
  15202. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  15203. if ($this->onlyCoreFonts)
  15204. $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8');
  15205. if ($this->useActiveForms) {
  15206. if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; }
  15207. $this->form->form_element_spacing['textarea']['outer']['v'] = 0;
  15208. $this->form->form_element_spacing['textarea']['inner']['v'] = 0;
  15209. if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; }
  15210. else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; }
  15211. if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; }
  15212. if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; }
  15213. if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; }
  15214. }
  15215. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15216. $properties = $this->MergeCSS('',$tag,$attr);
  15217. if (isset($properties['FONT-FAMILY'])) {
  15218. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  15219. }
  15220. if (isset($properties['FONT-SIZE'])) {
  15221. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  15222. $this->SetFontSize($mmsize*_MPDFK,false);
  15223. }
  15224. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15225. $objattr['fontfamily'] = $this->FontFamily;
  15226. $objattr['fontsize'] = $this->FontSizePt;
  15227. if ($this->useActiveForms) {
  15228. if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; }
  15229. else if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15230. if (isset($properties['OVERFLOW']) && strtolower($properties['OVERFLOW'])=='hidden') { $objattr['donotscroll'] = true; }
  15231. if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); }
  15232. if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15233. }
  15234. $this->SetLineHeight('',$this->form->textarea_lineheight);
  15235. $formLineHeight = $this->lineheight;
  15236. $w = 0;
  15237. $h = 0;
  15238. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15239. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15240. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15241. $colsize = 20; //HTML default value
  15242. $rowsize = 2; //HTML default value
  15243. if (isset($attr['COLS'])) $colsize = intval($attr['COLS']);
  15244. if (isset($attr['ROWS'])) $rowsize = intval($attr['ROWS']);
  15245. $charsize = $this->GetCharWidth('w',false);
  15246. if ($w) { $colsize = round(($w-($this->form->form_element_spacing['textarea']['outer']['h']*2)-($this->form->form_element_spacing['textarea']['inner']['h']*2))/$charsize); }
  15247. if ($h) { $rowsize = round(($h-($this->form->form_element_spacing['textarea']['outer']['v']*2)-($this->form->form_element_spacing['textarea']['inner']['v']*2))/$formLineHeight); }
  15248. $objattr['type'] = 'textarea';
  15249. $objattr['width'] = ($colsize * $charsize) + ($this->form->form_element_spacing['textarea']['outer']['h']*2)+($this->form->form_element_spacing['textarea']['inner']['h']*2);
  15250. $objattr['height'] = ($rowsize * $formLineHeight) + ($this->form->form_element_spacing['textarea']['outer']['v']*2)+($this->form->form_element_spacing['textarea']['inner']['v']*2);
  15251. $objattr['rows'] = $rowsize;
  15252. $objattr['cols'] = $colsize;
  15253. $this->specialcontent = serialize($objattr);
  15254. if ($this->tableLevel) { // *TABLES*
  15255. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  15256. } // *TABLES*
  15257. // Clear properties - tidy up
  15258. $properties = array();
  15259. break;
  15260. // *********** FORM - INPUT ********************
  15261. case 'INPUT':
  15262. if (!isset($attr['TYPE'])) $attr['TYPE'] == 'TEXT';
  15263. $objattr = array();
  15264. $objattr['margin_top'] = 0;
  15265. $objattr['margin_bottom'] = 0;
  15266. $objattr['margin_left'] = 0;
  15267. $objattr['margin_right'] = 0;
  15268. $objattr['width'] = 0;
  15269. $objattr['height'] = 0;
  15270. $objattr['border_top']['w'] = 0;
  15271. $objattr['border_bottom']['w'] = 0;
  15272. $objattr['border_left']['w'] = 0;
  15273. $objattr['border_right']['w'] = 0;
  15274. $objattr['type'] = 'input';
  15275. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  15276. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  15277. if(isset($attr['REQUIRED'])) { $objattr['required'] = true; }
  15278. if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; }
  15279. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  15280. else if(isset($attr['ALT'])) { $objattr['title'] = $attr['ALT']; }
  15281. else $objattr['title'] = '';
  15282. $objattr['title'] = strcode2utf($objattr['title']);
  15283. $objattr['title'] = $this->lesser_entity_decode($objattr['title']);
  15284. if ($this->onlyCoreFonts)
  15285. $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8');
  15286. if ($this->useActiveForms) {
  15287. if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; }
  15288. }
  15289. if(isset($attr['VALUE'])) {
  15290. $attr['VALUE'] = strcode2utf($attr['VALUE']);
  15291. $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']);
  15292. if ($this->onlyCoreFonts)
  15293. $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8');
  15294. $objattr['value'] = $attr['VALUE'];
  15295. }
  15296. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15297. $properties = $this->MergeCSS('',$tag,$attr);
  15298. $objattr['vertical-align'] = '';
  15299. if (isset($properties['FONT-FAMILY'])) {
  15300. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15301. }
  15302. if (isset($properties['FONT-SIZE'])) {
  15303. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK));
  15304. $this->SetFontSize($mmsize*_MPDFK,false);
  15305. }
  15306. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15307. $objattr['fontfamily'] = $this->FontFamily;
  15308. $objattr['fontsize'] = $this->FontSizePt;
  15309. if ($this->useActiveForms) {
  15310. if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; }
  15311. else if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15312. if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); }
  15313. if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15314. }
  15315. $type = '';
  15316. $texto='';
  15317. $height = $this->FontSize;
  15318. $width = 0;
  15319. $spacesize = $this->GetCharWidth(' ',false);
  15320. $w = 0;
  15321. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  15322. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15323. switch(strtoupper($attr['TYPE'])){
  15324. case 'HIDDEN':
  15325. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  15326. if ($this->useActiveForms) {
  15327. $this->form->SetFormText( 0, 0, $objattr['fieldname'], $objattr['value'], $objattr['value'], '', 0, '', true );
  15328. }
  15329. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  15330. unset($this->InlineProperties[$tag]);
  15331. break 2;
  15332. case 'CHECKBOX': //Draw Checkbox
  15333. $type = 'CHECKBOX';
  15334. if (isset($attr['CHECKED'])) { $objattr['checked'] = true; }
  15335. else { $objattr['checked'] = false; }
  15336. $width = $this->FontSize;
  15337. $height = $this->FontSize;
  15338. break;
  15339. case 'RADIO': //Draw Radio button
  15340. $type = 'RADIO';
  15341. if (isset($attr['CHECKED'])) $objattr['checked'] = true;
  15342. $width = $this->FontSize;
  15343. $height = $this->FontSize;
  15344. break;
  15345. /*-- IMAGES-CORE --*/
  15346. case 'IMAGE': // Draw an Image button
  15347. if(isset($attr['SRC'])) {
  15348. $type = 'IMAGE';
  15349. $srcpath = $attr['SRC'];
  15350. $orig_srcpath = $attr['ORIG_SRC'];
  15351. // VSPACE and HSPACE converted to margins in MergeCSS
  15352. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15353. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15354. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15355. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15356. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15357. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15358. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15359. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15360. $objattr['padding_top'] = 0;
  15361. $objattr['padding_bottom'] = 0;
  15362. $objattr['padding_left'] = 0;
  15363. $objattr['padding_right'] = 0;
  15364. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15365. $w = 0;
  15366. $h = 0;
  15367. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  15368. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width']);
  15369. $extraheight = $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15370. $extrawidth = $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15371. // Image file
  15372. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  15373. if(!$info) {
  15374. $info = $this->_getImage($this->noImageFile);
  15375. if ($info) {
  15376. $srcpath = $this->noImageFile;
  15377. $w = ($info['w'] * (25.4/$this->dpi));
  15378. $h = ($info['h'] * (25.4/$this->dpi));
  15379. }
  15380. }
  15381. if(!$info) break;
  15382. if ($info['cs']=='Indexed') { $objattr['Indexed'] = true; }
  15383. $objattr['file'] = $srcpath;
  15384. //Default width and height calculation if needed
  15385. if($w==0 and $h==0) {
  15386. /*-- IMAGES-WMF --*/
  15387. if ($info['type']=='wmf') {
  15388. // WMF units are twips (1/20pt)
  15389. // divide by 20 to get points
  15390. // divide by k to get user units
  15391. $w = abs($info['w'])/(20*_MPDFK);
  15392. $h = abs($info['h']) / (20*_MPDFK);
  15393. }
  15394. else
  15395. /*-- END IMAGES-WMF --*/
  15396. if ($info['type']=='svg') {
  15397. // SVG units are pixels
  15398. $w = abs($info['w'])/_MPDFK;
  15399. $h = abs($info['h'])/_MPDFK;
  15400. }
  15401. else {
  15402. //Put image at default image dpi
  15403. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  15404. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  15405. }
  15406. if (isset($properties['IMAGE-RESOLUTION'])) {
  15407. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  15408. $w *= $this->img_dpi / $info['set-dpi'];
  15409. $h *= $this->img_dpi / $info['set-dpi'];
  15410. }
  15411. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  15412. $dpi = $m[1];
  15413. if ($dpi > 0) {
  15414. $w *= $this->img_dpi / $dpi;
  15415. $h *= $this->img_dpi / $dpi;
  15416. }
  15417. }
  15418. }
  15419. }
  15420. // IF WIDTH OR HEIGHT SPECIFIED
  15421. if($w==0) $w=$h*$info['w']/$info['h'];
  15422. if($h==0) $h=$w*$info['h']/$info['w'];
  15423. // Resize to maximum dimensions of page
  15424. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  15425. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ;
  15426. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  15427. if ($w + $extrawidth > $maxWidth ) {
  15428. $w = $maxWidth - $extrawidth;
  15429. $h=$w*$info['h']/$info['w'];
  15430. }
  15431. if ($h + $extraheight > $maxHeight ) {
  15432. $h = $maxHeight - $extraheight;
  15433. $w=$h*$info['w']/$info['h'];
  15434. }
  15435. $height = $h + $extraheight;
  15436. $width = $w + $extrawidth;
  15437. $objattr['type'] = 'image';
  15438. $objattr['itype'] = $info['type'];
  15439. $objattr['orig_h'] = $info['h'];
  15440. $objattr['orig_w'] = $info['w'];
  15441. /*-- IMAGES-WMF --*/
  15442. if ($info['type']=='wmf') {
  15443. $objattr['wmf_x'] = $info['x'];
  15444. $objattr['wmf_y'] = $info['y'];
  15445. }
  15446. else
  15447. /*-- END IMAGES-WMF --*/
  15448. if ($info['type']=='svg') {
  15449. $objattr['wmf_x'] = $info['x'];
  15450. $objattr['wmf_y'] = $info['y'];
  15451. }
  15452. $objattr['height'] = $h + $extraheight;
  15453. $objattr['width'] = $w + $extrawidth;
  15454. $objattr['image_height'] = $h;
  15455. $objattr['image_width'] = $w;
  15456. $objattr['ID'] = $info['i'];
  15457. $texto = 'X';
  15458. if ($this->useActiveForms) {
  15459. if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; }
  15460. $objattr['type'] = 'input';
  15461. $type = 'IMAGE';
  15462. }
  15463. break;
  15464. }
  15465. /*-- END IMAGES-CORE --*/
  15466. case 'BUTTON': // Draw a button
  15467. case 'SUBMIT':
  15468. case 'RESET':
  15469. $type = strtoupper($attr['TYPE']);
  15470. if ($type=='IMAGE') { $type = 'BUTTON'; } // src path not found
  15471. if(isset($attr['NOPRINT'])) { $objattr['noprint'] = true; }
  15472. if (!isset($attr['VALUE'])) {
  15473. $objattr['value'] = ucfirst(strtolower($type));
  15474. }
  15475. $texto = " " . $objattr['value'] . " ";
  15476. $width = $this->GetStringWidth($texto) + ($this->form->form_element_spacing['button']['outer']['h']*2)+($this->form->form_element_spacing['button']['inner']['h']*2);
  15477. $height = $this->FontSize + ($this->form->form_element_spacing['button']['outer']['v']*2)+($this->form->form_element_spacing['button']['inner']['v']*2);
  15478. if ($this->useActiveForms) {
  15479. if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; }
  15480. }
  15481. break;
  15482. case 'PASSWORD':
  15483. case 'TEXT':
  15484. default:
  15485. if ($type == '') { $type = 'TEXT'; }
  15486. if(strtoupper($attr['TYPE'])=='PASSWORD') { $type = 'PASSWORD'; }
  15487. if (isset($attr['VALUE'])) {
  15488. if ($type == 'PASSWORD') {
  15489. $num_stars = mb_strlen($attr['VALUE'],$this->mb_enc );
  15490. $texto = str_repeat('*',$num_stars);
  15491. }
  15492. else { $texto = $attr['VALUE']; }
  15493. }
  15494. $xw = ($this->form->form_element_spacing['input']['outer']['h']*2)+($this->form->form_element_spacing['input']['inner']['h']*2);
  15495. $xh = ($this->form->form_element_spacing['input']['outer']['v']*2)+($this->form->form_element_spacing['input']['inner']['v']*2);
  15496. if ($w) { $width = $w + $xw; }
  15497. else { $width = (20 * $spacesize) + $xw; } // Default width in chars
  15498. if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $width = ($attr['SIZE'] * $spacesize) + $xw;
  15499. $height = $this->FontSize + $xh;
  15500. if (isset($attr['MAXLENGTH']) and ctype_digit($attr['MAXLENGTH']) ) $objattr['maxlength'] = $attr['MAXLENGTH'];
  15501. if ($this->useActiveForms) {
  15502. if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; }
  15503. else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; }
  15504. if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; }
  15505. if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; }
  15506. if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; }
  15507. }
  15508. break;
  15509. }
  15510. $objattr['subtype'] = $type;
  15511. $objattr['text'] = $texto;
  15512. $objattr['width'] = $width;
  15513. $objattr['height'] = $height;
  15514. $e = "\xbb\xa4\xactype=input,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15515. // Clear properties - tidy up
  15516. $properties = array();
  15517. /*-- TABLES --*/
  15518. // Output it to buffers
  15519. if ($this->tableLevel) {
  15520. $this->_saveCellTextBuffer($e, $this->HREF);
  15521. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15522. }
  15523. else {
  15524. /*-- END TABLES --*/
  15525. $this->_saveTextBuffer($e, $this->HREF);
  15526. } // *TABLES*
  15527. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  15528. unset($this->InlineProperties[$tag]);
  15529. break; // END of INPUT
  15530. /*-- END FORMS --*/
  15531. // *********** GRAPH ********************
  15532. case 'JPGRAPH':
  15533. if (!$this->useGraphs) { break; }
  15534. if ($attr['TABLE']) { $gid = strtoupper($attr['TABLE']); }
  15535. else { $gid = '0'; }
  15536. if (!is_array($this->graphs[$gid]) || count($this->graphs[$gid])==0 ) { break; }
  15537. include_once(_MPDF_PATH.'graph.php');
  15538. $this->graphs[$gid]['attr'] = $attr;
  15539. if (isset($this->graphs[$gid]['attr']['WIDTH']) && $this->graphs[$gid]['attr']['WIDTH']) {
  15540. $this->graphs[$gid]['attr']['cWIDTH']=$this->ConvertSize($this->graphs[$gid]['attr']['WIDTH'],$pgwidth);
  15541. } // mm
  15542. if (isset($this->graphs[$gid]['attr']['HEIGHT']) && $this->graphs[$gid]['attr']['HEIGHT']) {
  15543. $this->graphs[$gid]['attr']['cHEIGHT']=$this->ConvertSize($this->graphs[$gid]['attr']['HEIGHT'],$pgwidth);
  15544. }
  15545. $graph_img = print_graph($this->graphs[$gid],$this->blk[$this->blklvl]['inner_width']);
  15546. if ($graph_img) {
  15547. if(isset($attr['ROTATE'])) {
  15548. if ($attr['ROTATE']==90 || $attr['ROTATE']==-90) {
  15549. $tmpw = $graph_img['w'];
  15550. $graph_img['w']= $graph_img['h'];
  15551. $graph_img['h']= $tmpw;
  15552. }
  15553. }
  15554. $attr['SRC'] = $graph_img['file'];
  15555. $attr['WIDTH'] = $graph_img['w'];
  15556. $attr['HEIGHT'] = $graph_img['h'];
  15557. }
  15558. else { break; }
  15559. // *********** IMAGE ********************
  15560. /*-- IMAGES-CORE --*/
  15561. case 'IMG':
  15562. if ($this->progressBar) { $this->UpdateProgressBar(1,'','IMG'); } // *PROGRESS-BAR*
  15563. $objattr = array();
  15564. $objattr['margin_top'] = 0;
  15565. $objattr['margin_bottom'] = 0;
  15566. $objattr['margin_left'] = 0;
  15567. $objattr['margin_right'] = 0;
  15568. $objattr['padding_top'] = 0;
  15569. $objattr['padding_bottom'] = 0;
  15570. $objattr['padding_left'] = 0;
  15571. $objattr['padding_right'] = 0;
  15572. $objattr['width'] = 0;
  15573. $objattr['height'] = 0;
  15574. $objattr['border_top']['w'] = 0;
  15575. $objattr['border_bottom']['w'] = 0;
  15576. $objattr['border_left']['w'] = 0;
  15577. $objattr['border_right']['w'] = 0;
  15578. if(isset($attr['SRC'])) {
  15579. $srcpath = $attr['SRC'];
  15580. $orig_srcpath = $attr['ORIG_SRC'];
  15581. $properties = $this->MergeCSS('',$tag,$attr);
  15582. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15583. return;
  15584. }
  15585. $objattr['visibility'] = 'visible';
  15586. if (isset($properties['VISIBILITY'])) {
  15587. $v = strtolower($properties['VISIBILITY']);
  15588. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  15589. $objattr['visibility'] = $v;
  15590. }
  15591. }
  15592. // VSPACE and HSPACE converted to margins in MergeCSS
  15593. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15594. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15595. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15596. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15597. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15598. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15599. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15600. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15601. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15602. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15603. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15604. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15605. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15606. $w = 0;
  15607. $h = 0;
  15608. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15609. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15610. // mPDF 5.5.15
  15611. $maxw=$maxh=$minw=$minh=false;
  15612. if(isset($properties['MAX-WIDTH'])) $maxw = $this->ConvertSize($properties['MAX-WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15613. if(isset($properties['MAX-HEIGHT'])) $maxh = $this->ConvertSize($properties['MAX-HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15614. if(isset($properties['MIN-WIDTH'])) $minw = $this->ConvertSize($properties['MIN-WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15615. if(isset($properties['MIN-HEIGHT'])) $minh = $this->ConvertSize($properties['MIN-HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15616. if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15617. if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15618. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  15619. if ($this->HREF) {
  15620. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  15621. $href = $this->HREF;
  15622. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  15623. $this->internallink[$href] = $this->AddLink();
  15624. $objattr['link'] = $this->internallink[$href];
  15625. }
  15626. else { $objattr['link'] = $this->HREF; }
  15627. }
  15628. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15629. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15630. /*-- BACKGROUNDS --*/
  15631. if(isset($properties['GRADIENT-MASK']) && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['GRADIENT-MASK'])) {
  15632. $objattr['GRADIENT-MASK'] = $properties['GRADIENT-MASK'];
  15633. }
  15634. /*-- END BACKGROUNDS --*/
  15635. // Image file
  15636. $info=$this->_getImage($srcpath, true, true, $orig_srcpath);
  15637. if(!$info) {
  15638. $info = $this->_getImage($this->noImageFile);
  15639. if ($info) {
  15640. $srcpath = $this->noImageFile;
  15641. $w = ($info['w'] * (25.4/$this->dpi));
  15642. $h = ($info['h'] * (25.4/$this->dpi));
  15643. }
  15644. }
  15645. if(!$info) break;
  15646. if(isset($attr['ROTATE'])) { $image_orientation = $attr['ROTATE']; }
  15647. else if(isset($properties['IMAGE-ORIENTATION'])) { $image_orientation = $properties['IMAGE-ORIENTATION']; }
  15648. else { $image_orientation = 0; }
  15649. if($image_orientation) {
  15650. if ($image_orientation==90 || $image_orientation==-90 || $image_orientation==270) {
  15651. $tmpw = $info['w'];
  15652. $info['w'] = $info['h'];
  15653. $info['h'] = $tmpw;
  15654. }
  15655. $objattr['ROTATE'] = $image_orientation;
  15656. }
  15657. $objattr['file'] = $srcpath;
  15658. //Default width and height calculation if needed
  15659. if($w==0 and $h==0) {
  15660. /*-- IMAGES-WMF --*/
  15661. if ($info['type']=='wmf') {
  15662. // WMF units are twips (1/20pt)
  15663. // divide by 20 to get points
  15664. // divide by k to get user units
  15665. $w = abs($info['w'])/(20*_MPDFK);
  15666. $h = abs($info['h']) / (20*_MPDFK);
  15667. }
  15668. else
  15669. /*-- END IMAGES-WMF --*/
  15670. if ($info['type']=='svg') {
  15671. // SVG units are pixels
  15672. $w = abs($info['w'])/_MPDFK;
  15673. $h = abs($info['h'])/_MPDFK;
  15674. }
  15675. else {
  15676. //Put image at default image dpi
  15677. $w=($info['w']/_MPDFK) * (72/$this->img_dpi);
  15678. $h=($info['h']/_MPDFK) * (72/$this->img_dpi);
  15679. }
  15680. if (isset($properties['IMAGE-RESOLUTION'])) {
  15681. if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) {
  15682. $w *= $this->img_dpi / $info['set-dpi'];
  15683. $h *= $this->img_dpi / $info['set-dpi'];
  15684. }
  15685. else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) {
  15686. $dpi = $m[1];
  15687. if ($dpi > 0) {
  15688. $w *= $this->img_dpi / $dpi;
  15689. $h *= $this->img_dpi / $dpi;
  15690. }
  15691. }
  15692. }
  15693. }
  15694. // IF WIDTH OR HEIGHT SPECIFIED
  15695. if($w==0) $w=abs($h*$info['w']/$info['h']);
  15696. if($h==0) $h=abs($w*$info['h']/$info['w']);
  15697. // mPDF 5.5.15
  15698. if ($minw && $w<$minw) { $w = $minw; $h=abs($w*$info['h']/$info['w']); }
  15699. if ($maxw && $w>$maxw) { $w = $maxw; $h=abs($w*$info['h']/$info['w']); }
  15700. if ($minh && $h<$minh) { $h = $minh; $w=abs($h*$info['w']/$info['h']); }
  15701. if ($maxh && $h>$maxh) { $h = $maxh; $w=abs($h*$info['w']/$info['h']); }
  15702. // Resize to maximum dimensions of page
  15703. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  15704. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 1) ;
  15705. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; }
  15706. if ($w + $extrawidth > $maxWidth ) {
  15707. $w = $maxWidth - $extrawidth;
  15708. $h=abs($w*$info['h']/$info['w']);
  15709. }
  15710. if ($h + $extraheight > $maxHeight ) {
  15711. $h = $maxHeight - $extraheight;
  15712. $w=abs($h*$info['w']/$info['h']);
  15713. }
  15714. $objattr['type'] = 'image';
  15715. $objattr['itype'] = $info['type'];
  15716. $objattr['orig_h'] = $info['h'];
  15717. $objattr['orig_w'] = $info['w'];
  15718. /*-- IMAGES-WMF --*/
  15719. if ($info['type']=='wmf') {
  15720. $objattr['wmf_x'] = $info['x'];
  15721. $objattr['wmf_y'] = $info['y'];
  15722. }
  15723. else
  15724. /*-- END IMAGES-WMF --*/
  15725. if ($info['type']=='svg') {
  15726. $objattr['wmf_x'] = $info['x'];
  15727. $objattr['wmf_y'] = $info['y'];
  15728. }
  15729. $objattr['height'] = $h + $extraheight;
  15730. $objattr['width'] = $w + $extrawidth;
  15731. $objattr['image_height'] = $h;
  15732. $objattr['image_width'] = $w;
  15733. /*-- CSS-IMAGE-FLOAT --*/
  15734. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  15735. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  15736. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  15737. }
  15738. }
  15739. /*-- END CSS-IMAGE-FLOAT --*/
  15740. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15741. // Clear properties - tidy up
  15742. $properties = array();
  15743. /*-- TABLES --*/
  15744. // Output it to buffers
  15745. if ($this->tableLevel) {
  15746. $this->_saveCellTextBuffer($e, $this->HREF);
  15747. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15748. }
  15749. else {
  15750. /*-- END TABLES --*/
  15751. $this->_saveTextBuffer($e, $this->HREF);
  15752. } // *TABLES*
  15753. /*-- ANNOTATIONS --*/
  15754. if ($this->title2annots && isset($attr['TITLE'])) {
  15755. $objattr = array();
  15756. $objattr['margin_top'] = 0;
  15757. $objattr['margin_bottom'] = 0;
  15758. $objattr['margin_left'] = 0;
  15759. $objattr['margin_right'] = 0;
  15760. $objattr['width'] = 0;
  15761. $objattr['height'] = 0;
  15762. $objattr['border_top']['w'] = 0;
  15763. $objattr['border_bottom']['w'] = 0;
  15764. $objattr['border_left']['w'] = 0;
  15765. $objattr['border_right']['w'] = 0;
  15766. $objattr['CONTENT'] = $attr['TITLE'];
  15767. $objattr['type'] = 'annot';
  15768. $objattr['POS-X'] = 0;
  15769. $objattr['POS-Y'] = 0;
  15770. $objattr['ICON'] = 'Comment';
  15771. $objattr['AUTHOR'] = '';
  15772. $objattr['SUBJECT'] = '';
  15773. $objattr['OPACITY'] = $this->annotOpacity;
  15774. $objattr['COLOR'] = $this->ConvertColor('yellow');
  15775. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15776. if($this->tableLevel) { // *TABLES*
  15777. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); // *TABLES*
  15778. } // *TABLES*
  15779. else { // *TABLES*
  15780. $this->textbuffer[] = array($e);
  15781. } // *TABLES*
  15782. }
  15783. /*-- END ANNOTATIONS --*/
  15784. }
  15785. break;
  15786. /*-- END IMAGES-CORE --*/
  15787. // *********** CIRCULAR TEXT = TEXTCIRCLE ********************
  15788. case 'TEXTCIRCLE':
  15789. $objattr = array();
  15790. $objattr['margin_top'] = 0;
  15791. $objattr['margin_bottom'] = 0;
  15792. $objattr['margin_left'] = 0;
  15793. $objattr['margin_right'] = 0;
  15794. $objattr['padding_top'] = 0;
  15795. $objattr['padding_bottom'] = 0;
  15796. $objattr['padding_left'] = 0;
  15797. $objattr['padding_right'] = 0;
  15798. $objattr['width'] = 0;
  15799. $objattr['height'] = 0;
  15800. $objattr['border_top']['w'] = 0;
  15801. $objattr['border_bottom']['w'] = 0;
  15802. $objattr['border_left']['w'] = 0;
  15803. $objattr['border_right']['w'] = 0;
  15804. $objattr['top-text'] = '';
  15805. $objattr['bottom-text'] = '';
  15806. $objattr['r'] = 20; // radius (default value here for safety)
  15807. $objattr['space-width'] = 120;
  15808. $objattr['char-width'] = 100;
  15809. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  15810. $properties = $this->MergeCSS('INLINE',$tag,$attr);
  15811. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15812. return;
  15813. }
  15814. if (isset($attr['R'])) { $objattr['r']=$this->ConvertSize($attr['R'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15815. if(isset($attr['TOP-TEXT'])) {
  15816. $objattr['top-text'] = strcode2utf($attr['TOP-TEXT']);
  15817. $objattr['top-text'] = $this->lesser_entity_decode($objattr['top-text']);
  15818. if ($this->onlyCoreFonts)
  15819. $objattr['top-text'] = mb_convert_encoding($objattr['top-text'], $this->mb_enc,'UTF-8');
  15820. }
  15821. if(isset($attr['BOTTOM-TEXT'])) {
  15822. $objattr['bottom-text'] = strcode2utf($attr['BOTTOM-TEXT']);
  15823. $objattr['bottom-text'] = $this->lesser_entity_decode($objattr['bottom-text']);
  15824. if ($this->onlyCoreFonts)
  15825. $objattr['bottom-text'] = mb_convert_encoding($objattr['bottom-text'], $this->mb_enc,'UTF-8');
  15826. }
  15827. if(isset($attr['SPACE-WIDTH']) && $attr['SPACE-WIDTH']) { $objattr['space-width'] = $attr['SPACE-WIDTH']; }
  15828. if(isset($attr['CHAR-WIDTH']) && $attr['CHAR-WIDTH']) { $objattr['char-width'] = $attr['CHAR-WIDTH']; }
  15829. // VISIBILITY
  15830. $objattr['visibility'] = 'visible';
  15831. if (isset($properties['VISIBILITY'])) {
  15832. $v = strtolower($properties['VISIBILITY']);
  15833. if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') {
  15834. $objattr['visibility'] = $v;
  15835. }
  15836. }
  15837. // mPDF 5.5.23
  15838. if (isset($properties['FONT-SIZE'])) {
  15839. if (strtolower($properties['FONT-SIZE'])=='auto') {
  15840. if ($objattr['top-text'] && $objattr['bottom-text']) {
  15841. $objattr['fontsize'] = -2;
  15842. }
  15843. else {
  15844. $objattr['fontsize'] = -1;
  15845. }
  15846. }
  15847. else {
  15848. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK));
  15849. $this->SetFontSize($mmsize*_MPDFK,false);
  15850. $objattr['fontsize'] = $this->FontSizePt;
  15851. }
  15852. }
  15853. // mPDF 5.5.23
  15854. if(isset($attr['DIVIDER'])) {
  15855. $objattr['divider'] = strcode2utf($attr['DIVIDER']);
  15856. $objattr['divider'] = $this->lesser_entity_decode($objattr['divider']);
  15857. if ($this->onlyCoreFonts)
  15858. $objattr['divider'] = mb_convert_encoding($objattr['divider'], $this->mb_enc,'UTF-8');
  15859. }
  15860. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  15861. $objattr['fontstyle'] = '';
  15862. if (isset($properties['FONT-WEIGHT'])) {
  15863. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $objattr['fontstyle'] .= 'B'; }
  15864. }
  15865. if (isset($properties['FONT-STYLE'])) {
  15866. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $objattr['fontstyle'] .= 'I'; }
  15867. }
  15868. if (isset($properties['FONT-FAMILY'])) {
  15869. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  15870. }
  15871. $objattr['fontfamily'] = $this->FontFamily;
  15872. // VSPACE and HSPACE converted to margins in MergeCSS
  15873. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15874. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15875. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15876. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15877. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15878. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15879. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15880. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15881. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15882. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15883. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15884. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15885. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  15886. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  15887. else { $objattr['bgcolor'] = false; }
  15888. if ($this->HREF) {
  15889. if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) {
  15890. $href = $this->HREF;
  15891. while(array_key_exists($href,$this->internallink)) $href="#".$href;
  15892. $this->internallink[$href] = $this->AddLink();
  15893. $objattr['link'] = $this->internallink[$href];
  15894. }
  15895. else { $objattr['link'] = $this->HREF; }
  15896. }
  15897. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15898. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15899. $w = $objattr['r']*2;
  15900. $h = $w;
  15901. $objattr['height'] = $h + $extraheight;
  15902. $objattr['width'] = $w + $extrawidth;
  15903. $objattr['type'] = 'textcircle';
  15904. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15905. // Clear properties - tidy up
  15906. $properties = array();
  15907. /*-- TABLES --*/
  15908. // Output it to buffers
  15909. if ($this->tableLevel) {
  15910. $this->_saveCellTextBuffer($e, $this->HREF);
  15911. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15912. }
  15913. else {
  15914. /*-- END TABLES --*/
  15915. $this->_saveTextBuffer($e, $this->HREF);
  15916. } // *TABLES*
  15917. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  15918. unset($this->InlineProperties[$tag]);
  15919. break;
  15920. /*-- TABLES --*/
  15921. case 'TABLE': // TABLE-BEGIN
  15922. $this->tdbegin = false;
  15923. $this->lastoptionaltag = '';
  15924. // Disable vertical justification in columns
  15925. if ($this->ColActive) { $this->colvAlign = ''; } // *COLUMNS*
  15926. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  15927. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  15928. // called from block after new div e.g. <div> ... <table> ... Outputs block top margin/border and padding
  15929. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  15930. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']);
  15931. $this->finishFlowingBlock(true); // true = END of flowing block
  15932. }
  15933. else if (!$this->tableLevel && count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  15934. $this->textbuffer=array();
  15935. $this->lastblocklevelchange = -1;
  15936. if ($this->tableLevel) { // i.e. now a nested table coming...
  15937. // Save current level table
  15938. // mPDF 5.4.10
  15939. $this->cell['PARENTCELL'] = $this->saveInlineProperties();
  15940. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties']= $this->base_table_properties;
  15941. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  15942. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'] = $this->row;
  15943. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'] = $this->col;
  15944. }
  15945. $this->tableLevel++;
  15946. $this->tbCSSlvl++;
  15947. if ($this->tableLevel>1) { // inherit table properties from cell in which nested
  15948. $this->base_table_properties['FONT-KERNING'] = $this->kerning ;
  15949. $this->base_table_properties['LETTER-SPACING'] = $this->lSpacingCSS ;
  15950. $this->base_table_properties['WORD-SPACING'] = $this->wSpacingCSS ;
  15951. }
  15952. if (isset($this->tbctr[$this->tableLevel])) { $this->tbctr[$this->tableLevel]++; }
  15953. else { $this->tbctr[$this->tableLevel] = 1; }
  15954. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['level'] = $this->tableLevel;
  15955. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['levelid'] = $this->tbctr[$this->tableLevel];
  15956. if ($this->tableLevel > $this->innermostTableLevel) { $this->innermostTableLevel = $this->tableLevel; }
  15957. if ($this->tableLevel > 1) {
  15958. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nestedpos'] = array($this->row,$this->col,$this->tbctr[($this->tableLevel-1)]);
  15959. }
  15960. //++++++++++++++++++++++++++++
  15961. $this->cell = array();
  15962. $this->col=-1; //int
  15963. $this->row=-1; //int
  15964. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  15965. // New table - any level
  15966. if ($this->cacheTables) {
  15967. $this->packTableData = true; // required for cacheTables
  15968. $this->simpleTables = false; // Cannot co-exist with cacheTables
  15969. $table['cache'] = _MPDF_TEMP_PATH.'_tempTblCache'.RAND(1,1000000).'.dat';
  15970. $fh = fopen($table['cache'] , "wb") or $this->Error("When using cacheTables, you must have read/write access to cache files (".$table['cache'] .")");
  15971. fwrite($fh, "\x00");
  15972. fclose($fh);
  15973. $table['ptr'] = 1 ; // Must not be 0
  15974. }
  15975. $table['direction'] = $this->directionality;
  15976. $table['bgcolor'] = false;
  15977. $table['va'] = false;
  15978. $table['txta'] = false;
  15979. $table['topntail'] = false;
  15980. $table['thead-underline'] = false;
  15981. $table['border'] = false;
  15982. $table['border_details']['R']['w'] = 0;
  15983. $table['border_details']['L']['w'] = 0;
  15984. $table['border_details']['T']['w'] = 0;
  15985. $table['border_details']['B']['w'] = 0;
  15986. $table['border_details']['R']['style'] = '';
  15987. $table['border_details']['L']['style'] = '';
  15988. $table['border_details']['T']['style'] = '';
  15989. $table['border_details']['B']['style'] = '';
  15990. $table['max_cell_border_width']['R'] = 0;
  15991. $table['max_cell_border_width']['L'] = 0;
  15992. $table['max_cell_border_width']['T'] = 0;
  15993. $table['max_cell_border_width']['B'] = 0;
  15994. $table['padding']['L'] = false;
  15995. $table['padding']['R'] = false;
  15996. $table['padding']['T'] = false;
  15997. $table['padding']['B'] = false;
  15998. $table['margin']['L'] = false;
  15999. $table['margin']['R'] = false;
  16000. $table['margin']['T'] = false;
  16001. $table['margin']['B'] = false;
  16002. $table['a'] = false;
  16003. $table['border_spacing_H'] = false;
  16004. $table['border_spacing_V'] = false;
  16005. $this->Reset();
  16006. $this->InlineProperties = array();
  16007. $this->spanlvl = 0;
  16008. $table['nc'] = $table['nr'] = 0;
  16009. $this->tablethead = 0;
  16010. $this->tabletfoot = 0;
  16011. $this->tabletheadjustfinished = false;
  16012. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins && $this->tableLevel==1) { $lastbottommargin = $this->lastblockbottommargin; }
  16013. else { $lastbottommargin = 0; }
  16014. $this->lastblockbottommargin = 0;
  16015. $this->blockjustfinished=false;
  16016. if ($this->tableLevel==1) {
  16017. $this->tableCJK = false;
  16018. $this->table_lineheight = $this->normalLineheight;
  16019. $table['headernrows'] = 0;
  16020. $table['footernrows'] = 0;
  16021. $this->base_table_properties = array();
  16022. }
  16023. // ADDED CSS FUNCIONS FOR TABLE
  16024. if ($this->tbCSSlvl==1) {
  16025. $properties = $this->MergeCSS('TOPTABLE',$tag,$attr);
  16026. }
  16027. else {
  16028. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16029. }
  16030. $w = '';
  16031. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  16032. if(isset($properties['DIRECTION']) && $properties['DIRECTION']) { $table['direction'] = strtolower($properties['DIRECTION']); }
  16033. if(isset($attr['DIR']) && $attr['DIR']) { $table['direction'] = strtolower($attr['DIR']); }
  16034. else if (!isset($table['direction'])){ $table['direction'] = $this->blk[$this->blklvl]['direction']; }
  16035. if (isset($properties['BACKGROUND-COLOR'])) { $table['bgcolor'][-1] = $properties['BACKGROUND-COLOR']; }
  16036. else if (isset($properties['BACKGROUND'])) { $table['bgcolor'][-1] = $properties['BACKGROUND']; }
  16037. if (isset($properties['VERTICAL-ALIGN'])) { $table['va'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16038. if (isset($properties['TEXT-ALIGN'])) { $table['txta'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  16039. if (isset($properties['AUTOSIZE']) && $properties['AUTOSIZE'] && $this->tableLevel ==1) {
  16040. $this->shrink_this_table_to_fit = $properties['AUTOSIZE'];
  16041. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 0; }
  16042. }
  16043. if (isset($properties['ROTATE']) && $properties['ROTATE'] && $this->tableLevel ==1) {
  16044. $this->table_rotate = $properties['ROTATE'];
  16045. }
  16046. if (isset($properties['TOPNTAIL'])) { $table['topntail'] = $properties['TOPNTAIL']; }
  16047. if (isset($properties['THEAD-UNDERLINE'])) { $table['thead-underline'] = $properties['THEAD-UNDERLINE']; }
  16048. if (isset($properties['BORDER'])) {
  16049. $bord = $this->border_details($properties['BORDER']);
  16050. if ($bord['s']) {
  16051. $table['border'] = _BORDER_ALL;
  16052. $table['border_details']['R'] = $bord;
  16053. $table['border_details']['L'] = $bord;
  16054. $table['border_details']['T'] = $bord;
  16055. $table['border_details']['B'] = $bord;
  16056. }
  16057. }
  16058. if (isset($properties['BORDER-RIGHT'])) {
  16059. if ($table['direction'] == 'rtl') { // *RTL*
  16060. $table['border_details']['R'] = $this->border_details($properties['BORDER-LEFT']); // *RTL*
  16061. } // *RTL*
  16062. else { // *RTL*
  16063. $table['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  16064. } // *RTL*
  16065. $this->setBorder($table['border'], _BORDER_RIGHT, $table['border_details']['R']['s']);
  16066. }
  16067. if (isset($properties['BORDER-LEFT'])) {
  16068. if ($table['direction'] == 'rtl') { // *RTL*
  16069. $table['border_details']['L'] = $this->border_details($properties['BORDER-RIGHT']); // *RTL*
  16070. } // *RTL*
  16071. else { // *RTL*
  16072. $table['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  16073. } // *RTL*
  16074. $this->setBorder($table['border'], _BORDER_LEFT, $table['border_details']['L']['s']);
  16075. }
  16076. if (isset($properties['BORDER-BOTTOM'])) {
  16077. $table['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  16078. $this->setBorder($table['border'], _BORDER_BOTTOM, $table['border_details']['B']['s']);
  16079. }
  16080. if (isset($properties['BORDER-TOP'])) {
  16081. $table['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  16082. $this->setBorder($table['border'], _BORDER_TOP, $table['border_details']['T']['s']);
  16083. }
  16084. if ($table['border']){
  16085. $this->table_border_css_set = 1;
  16086. }
  16087. else {
  16088. $this->table_border_css_set = 0;
  16089. }
  16090. if (isset($properties['FONT-FAMILY'])) {
  16091. $this->default_font = $properties['FONT-FAMILY'];
  16092. $this->SetFont($this->default_font,'',0,false);
  16093. }
  16094. $this->base_table_properties['FONT-FAMILY'] = $this->FontFamily; // mPDF 5.4.10
  16095. if (isset($properties['FONT-SIZE'])) {
  16096. // mPDF 5.4.10
  16097. if ($this->tableLevel>1) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'], $this->base_table_properties['FONT-SIZE']); }
  16098. else { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK); }
  16099. if ($mmsize) {
  16100. $this->default_font_size = $mmsize*(_MPDFK);
  16101. $this->SetFontSize($this->default_font_size,false);
  16102. }
  16103. }
  16104. $this->base_table_properties['FONT-SIZE'] = $this->FontSize.'mm'; // mPDF 5.4.10
  16105. if (isset($properties['FONT-WEIGHT'])) {
  16106. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->base_table_properties['FONT-WEIGHT'] = 'BOLD'; }
  16107. }
  16108. if (isset($properties['FONT-STYLE'])) {
  16109. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->base_table_properties['FONT-STYLE'] = 'ITALIC'; }
  16110. }
  16111. if (isset($properties['COLOR'])) {
  16112. $this->base_table_properties['COLOR'] = $properties['COLOR'];
  16113. }
  16114. if (isset($properties['FONT-KERNING'])) {
  16115. $this->base_table_properties['FONT-KERNING'] = $properties['FONT-KERNING'];
  16116. }
  16117. if (isset($properties['LETTER-SPACING'])) {
  16118. $this->base_table_properties['LETTER-SPACING'] = $properties['LETTER-SPACING'];
  16119. }
  16120. if (isset($properties['WORD-SPACING'])) {
  16121. $this->base_table_properties['WORD-SPACING'] = $properties['WORD-SPACING'];
  16122. }
  16123. if (isset($properties['PADDING-LEFT'])) {
  16124. $table['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16125. }
  16126. if (isset($properties['PADDING-RIGHT'])) {
  16127. $table['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16128. }
  16129. if (isset($properties['PADDING-TOP'])) {
  16130. $table['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16131. }
  16132. if (isset($properties['PADDING-BOTTOM'])) {
  16133. $table['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16134. }
  16135. if (isset($properties['MARGIN-TOP'])) {
  16136. if ($lastbottommargin) {
  16137. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16138. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  16139. else { $properties['MARGIN-TOP'] = 0; }
  16140. }
  16141. $table['margin']['T'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16142. }
  16143. if (isset($properties['MARGIN-BOTTOM'])) {
  16144. $table['margin']['B'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16145. }
  16146. if (isset($properties['MARGIN-LEFT'])) {
  16147. $table['margin']['L'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16148. }
  16149. if (isset($properties['MARGIN-RIGHT'])) {
  16150. $table['margin']['R'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16151. }
  16152. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  16153. $table['a'] = 'C';
  16154. }
  16155. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  16156. $table['a'] = 'R';
  16157. }
  16158. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  16159. $table['a'] = 'L';
  16160. }
  16161. if (isset($properties['LINE-HEIGHT']) && $this->tableLevel==1) {
  16162. $this->table_lineheight = $this->fixLineheight($properties['LINE-HEIGHT']);
  16163. if (!$this->table_lineheight) { $this->table_lineheight = $this->normalLineheight; }
  16164. }
  16165. if (isset($properties['BORDER-COLLAPSE']) && strtoupper($properties['BORDER-COLLAPSE'])=='SEPARATE') {
  16166. $table['borders_separate'] = true;
  16167. }
  16168. else {
  16169. $table['borders_separate'] = false;
  16170. }
  16171. if (isset($properties['BORDER-SPACING-H'])) {
  16172. $table['border_spacing_H'] = $this->ConvertSize($properties['BORDER-SPACING-H'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16173. }
  16174. if (isset($properties['BORDER-SPACING-V'])) {
  16175. $table['border_spacing_V'] = $this->ConvertSize($properties['BORDER-SPACING-V'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16176. }
  16177. if (isset($properties['EMPTY-CELLS'])) {
  16178. $table['empty_cells'] = strtolower($properties['EMPTY-CELLS']); // 'hide' or 'show'
  16179. }
  16180. else { $table['empty_cells'] = ''; }
  16181. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE'])=='AVOID' && $this->tableLevel==1 && !$this->writingHTMLfooter) {
  16182. $this->table_keep_together = true;
  16183. }
  16184. else if ($this->tableLevel==1) {
  16185. $this->table_keep_together = false;
  16186. }
  16187. if (isset($properties['PAGE-BREAK-AFTER']) && $this->tableLevel==1) {
  16188. $table['page_break_after'] = strtoupper($properties['PAGE-BREAK-AFTER']);
  16189. }
  16190. /*-- BACKGROUNDS --*/
  16191. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $table['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  16192. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  16193. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  16194. if ($ret) { $table['background-image'] = $ret; }
  16195. }
  16196. /*-- END BACKGROUNDS --*/
  16197. if (isset($properties['OVERFLOW'])) {
  16198. $table['overflow'] = strtolower($properties['OVERFLOW']); // 'hidden' 'wrap' or 'visible' or 'auto'
  16199. if (($this->ColActive || $this->tableLevel>1) && $table['overflow']=='visible') { unset($table['overflow']); }
  16200. }
  16201. $properties = array();
  16202. if (!$table['borders_separate']) { $table['border_spacing_H'] = $table['border_spacing_V'] = 0; }
  16203. else if (isset($attr['CELLSPACING'])) {
  16204. $table['border_spacing_H'] = $table['border_spacing_V'] = $this->ConvertSize($attr['CELLSPACING'],$this->blk[$this->blklvl]['inner_width']);
  16205. }
  16206. if (isset($attr['CELLPADDING'])) {
  16207. $table['cell_padding'] = $attr['CELLPADDING'];
  16208. }
  16209. else {
  16210. $table['cell_padding'] = false;
  16211. }
  16212. if (isset($attr['BORDER']) && $attr['BORDER']=='1') { // mPDF 5.5.08
  16213. $this->table_border_attr_set = 1; // mPDF 5.5.08
  16214. $bord = $this->border_details('#000000 1px solid');
  16215. if ($bord['s']) {
  16216. $table['border'] = _BORDER_ALL;
  16217. $table['border_details']['R'] = $bord;
  16218. $table['border_details']['L'] = $bord;
  16219. $table['border_details']['T'] = $bord;
  16220. $table['border_details']['B'] = $bord;
  16221. }
  16222. }
  16223. else {
  16224. $this->table_border_attr_set = 0;
  16225. }
  16226. if (isset($attr['ALIGN'])) { $table['a'] = $align[strtolower($attr['ALIGN'])]; }
  16227. if (!$table['a']) {
  16228. if ($table['direction'] == 'rtl' ) { $table['a'] = 'R'; }
  16229. else { $table['a'] = 'L'; }
  16230. }
  16231. if (isset($attr['BGCOLOR'])) { $table['bgcolor'][-1] = $attr['BGCOLOR']; }
  16232. if (isset($attr['WIDTH']) && $attr['WIDTH']) { $w = $attr['WIDTH']; }
  16233. if ($w) { // set here or earlier in $properties
  16234. $maxwidth = $this->blk[$this->blklvl]['inner_width'];
  16235. if ($table['borders_separate']) {
  16236. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['border_details']['L']['w']/2 + $table['border_details']['R']['w']/2;
  16237. }
  16238. else {
  16239. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2;
  16240. }
  16241. if (strpos($w,'%') && $this->tableLevel == 1 && !$this->ignore_table_percents ) {
  16242. // % needs to be of inner box without table margins etc.
  16243. $maxwidth -= $tblblw ;
  16244. $wmm = $this->ConvertSize($w,$maxwidth,$this->FontSize,false);
  16245. $table['w'] = $wmm + $tblblw ;
  16246. }
  16247. if (strpos($w,'%') && $this->tableLevel > 1 && !$this->ignore_table_percents && $this->keep_table_proportions) {
  16248. $table['wpercent'] = $w + 0; // makes 80% -> 80
  16249. }
  16250. if (!strpos($w,'%') && !$this->ignore_table_widths ) {
  16251. $wmm = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16252. $table['w'] = $wmm + $tblblw ;
  16253. }
  16254. if (!$this->keep_table_proportions) {
  16255. if (isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width']) { $table['w'] = $this->blk[$this->blklvl]['inner_width']; }
  16256. }
  16257. }
  16258. if (isset($attr['AUTOSIZE']) && $this->tableLevel==1) {
  16259. $this->shrink_this_table_to_fit = $attr['AUTOSIZE'];
  16260. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 1; }
  16261. }
  16262. if (isset($attr['ROTATE']) && $this->tableLevel==1) {
  16263. $this->table_rotate = $attr['ROTATE'];
  16264. }
  16265. //++++++++++++++++++++++++++++
  16266. // keeping block together on one page
  16267. // Autosize is now forced therefore keep block together disabled
  16268. if ($this->keep_block_together) {
  16269. $this->keep_block_together = 0;
  16270. $this->printdivbuffer();
  16271. $this->blk[$this->blklvl]['keep_block_together'] = 0;
  16272. }
  16273. if ($this->table_rotate) {
  16274. $this->tbrot_Links = array();
  16275. $this->tbrot_Annots = array();
  16276. $this->tbrotForms = array();
  16277. $this->tbrot_Reference = array();
  16278. $this->tbrot_BMoutlines = array();
  16279. $this->tbrot_toc = array();
  16280. }
  16281. if ($this->kwt) {
  16282. if ($this->table_rotate) { $this->table_keep_together = true; }
  16283. $this->kwt = false;
  16284. $this->kwt_saved = true;
  16285. }
  16286. if ($this->tableLevel==1 && $this->useGraphs) {
  16287. if (isset($attr['ID']) && $attr['ID']) { $this->currentGraphId = strtoupper($attr['ID']); }
  16288. else { $this->currentGraphId = '0'; }
  16289. $this->graphs[$this->currentGraphId] = array();
  16290. }
  16291. //++++++++++++++++++++++++++++
  16292. $this->plainCell_properties = array();
  16293. unset($table);
  16294. break;
  16295. case 'THEAD':
  16296. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16297. $this->tbCSSlvl++;
  16298. $this->tablethead = 1;
  16299. $this->tabletfoot = 0;
  16300. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16301. if (isset($properties['FONT-WEIGHT'])) {
  16302. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->thead_font_weight = 'B'; }
  16303. else { $this->thead_font_weight = ''; }
  16304. }
  16305. if (isset($properties['FONT-STYLE'])) {
  16306. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->thead_font_style = 'I'; }
  16307. else { $this->thead_font_style = ''; }
  16308. }
  16309. if (isset($properties['FONT-VARIANT'])) {
  16310. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->thead_font_smCaps = 'S'; }
  16311. else { $this->thead_font_smCaps = ''; }
  16312. }
  16313. if (isset($properties['VERTICAL-ALIGN'])) {
  16314. $this->thead_valign_default = $properties['VERTICAL-ALIGN'];
  16315. }
  16316. if (isset($properties['TEXT-ALIGN'])) {
  16317. $this->thead_textalign_default = $properties['TEXT-ALIGN'];
  16318. }
  16319. $properties = array();
  16320. break;
  16321. case 'TFOOT':
  16322. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16323. $this->tbCSSlvl++;
  16324. $this->tabletfoot = 1;
  16325. $this->tablethead = 0;
  16326. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16327. if (isset($properties['FONT-WEIGHT'])) {
  16328. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->tfoot_font_weight = 'B'; }
  16329. else { $this->tfoot_font_weight = ''; }
  16330. }
  16331. if (isset($properties['FONT-STYLE'])) {
  16332. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->tfoot_font_style = 'I'; }
  16333. else { $this->tfoot_font_style = ''; }
  16334. }
  16335. if (isset($properties['FONT-VARIANT'])) {
  16336. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->tfoot_font_smCaps = 'S'; }
  16337. else { $this->tfoot_font_smCaps = ''; }
  16338. }
  16339. if (isset($properties['VERTICAL-ALIGN'])) {
  16340. $this->tfoot_valign_default = $properties['VERTICAL-ALIGN'];
  16341. }
  16342. if (isset($properties['TEXT-ALIGN'])) {
  16343. $this->tfoot_textalign_default = $properties['TEXT-ALIGN'];
  16344. }
  16345. $properties = array();
  16346. break;
  16347. case 'TBODY':
  16348. $this->tablethead = 0;
  16349. $this->tabletfoot = 0;
  16350. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16351. $this->tbCSSlvl++;
  16352. $this->MergeCSS('TABLE',$tag,$attr);
  16353. break;
  16354. case 'TR':
  16355. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16356. $this->tbCSSlvl++;
  16357. $this->row++;
  16358. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']++;
  16359. $this->col = -1;
  16360. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16361. if (!$this->simpleTables && (!isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate']) || !$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate'])) {
  16362. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row] = $properties['BORDER-LEFT']; }
  16363. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row] = $properties['BORDER-RIGHT']; }
  16364. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-top'][$this->row] = $properties['BORDER-TOP']; }
  16365. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-bottom'][$this->row] = $properties['BORDER-BOTTOM']; }
  16366. }
  16367. if (isset($properties['BACKGROUND-COLOR'])) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $properties['BACKGROUND-COLOR']; }
  16368. /*-- BACKGROUNDS --*/
  16369. if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$this->row] = $properties['BACKGROUND-GRADIENT']; }
  16370. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) {
  16371. $ret = $this->SetBackground($properties, $currblk['inner_width']);
  16372. if ($ret) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$this->row] = $ret; }
  16373. }
  16374. /*-- END BACKGROUNDS --*/
  16375. if (isset($properties['TEXT-ROTATE'])) {
  16376. $this->trow_text_rotate = $properties['TEXT-ROTATE'];
  16377. }
  16378. if (isset($attr['TEXT-ROTATE'])) $this->trow_text_rotate = $attr['TEXT-ROTATE'];
  16379. if (isset($attr['BGCOLOR'])) $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $attr['BGCOLOR'];
  16380. if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; }
  16381. if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; }
  16382. $properties = array();
  16383. break;
  16384. case 'TH':
  16385. case 'TD':
  16386. $this->ignorefollowingspaces = true;
  16387. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16388. $this->tbCSSlvl++;
  16389. $this->InlineProperties = array();
  16390. $this->spanlvl = 0;
  16391. $this->tdbegin = true;
  16392. $this->col++;
  16393. while (isset($this->cell[$this->row][$this->col])) { $this->col++; }
  16394. //Update number column
  16395. 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; }
  16396. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  16397. $c = array('a' => false,
  16398. 'R' => false,
  16399. 'nowrap' => false,
  16400. 'bgcolor' => false,
  16401. 'padding' => array('L' => false,
  16402. 'R' => false,
  16403. 'T' => false,
  16404. 'B' => false
  16405. )
  16406. );
  16407. if ($this->simpleTables && $this->row==0 && $this->col==0){
  16408. $table['simple']['border'] = false;
  16409. $table['simple']['border_details']['R']['w'] = 0;
  16410. $table['simple']['border_details']['L']['w'] = 0;
  16411. $table['simple']['border_details']['T']['w'] = 0;
  16412. $table['simple']['border_details']['B']['w'] = 0;
  16413. $table['simple']['border_details']['R']['style'] = '';
  16414. $table['simple']['border_details']['L']['style'] = '';
  16415. $table['simple']['border_details']['T']['style'] = '';
  16416. $table['simple']['border_details']['B']['style'] = '';
  16417. }
  16418. else if (!$this->simpleTables) {
  16419. $c['border'] = false;
  16420. $c['border_details']['R']['w'] = 0;
  16421. $c['border_details']['L']['w'] = 0;
  16422. $c['border_details']['T']['w'] = 0;
  16423. $c['border_details']['B']['w'] = 0;
  16424. $c['border_details']['mbw']['BL'] = 0;
  16425. $c['border_details']['mbw']['BR'] = 0;
  16426. $c['border_details']['mbw']['RT'] = 0;
  16427. $c['border_details']['mbw']['RB'] = 0;
  16428. $c['border_details']['mbw']['TL'] = 0;
  16429. $c['border_details']['mbw']['TR'] = 0;
  16430. $c['border_details']['mbw']['LT'] = 0;
  16431. $c['border_details']['mbw']['LB'] = 0;
  16432. $c['border_details']['R']['style'] = '';
  16433. $c['border_details']['L']['style'] = '';
  16434. $c['border_details']['T']['style'] = '';
  16435. $c['border_details']['B']['style'] = '';
  16436. $c['border_details']['R']['s'] = 0;
  16437. $c['border_details']['L']['s'] = 0;
  16438. $c['border_details']['T']['s'] = 0;
  16439. $c['border_details']['B']['s'] = 0;
  16440. $c['border_details']['R']['c'] = $this->ConvertColor(0);
  16441. $c['border_details']['L']['c'] = $this->ConvertColor(0);
  16442. $c['border_details']['T']['c'] = $this->ConvertColor(0);
  16443. $c['border_details']['B']['c'] = $this->ConvertColor(0);
  16444. $c['border_details']['R']['dom'] = 0;
  16445. $c['border_details']['L']['dom'] = 0;
  16446. $c['border_details']['T']['dom'] = 0;
  16447. $c['border_details']['B']['dom'] = 0;
  16448. }
  16449. if ($table['va']) { $c['va'] = $table['va']; }
  16450. if ($table['txta']) { $c['a'] = $table['txta']; }
  16451. if ($this->table_border_attr_set) {
  16452. if ($table['border_details']) {
  16453. if (!$this->simpleTables){
  16454. $c['border_details']['R'] = $table['border_details']['R'];
  16455. $c['border_details']['L'] = $table['border_details']['L'];
  16456. $c['border_details']['T'] = $table['border_details']['T'];
  16457. $c['border_details']['B'] = $table['border_details']['B'];
  16458. $c['border'] = $table['border'];
  16459. $c['border_details']['L']['dom'] = 1;
  16460. $c['border_details']['R']['dom'] = 1;
  16461. $c['border_details']['T']['dom'] = 1;
  16462. $c['border_details']['B']['dom'] = 1;
  16463. }
  16464. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16465. $table['simple']['border_details']['R'] = $table['border_details']['R'];
  16466. $table['simple']['border_details']['L'] = $table['border_details']['L'];
  16467. $table['simple']['border_details']['T'] = $table['border_details']['T'];
  16468. $table['simple']['border_details']['B'] = $table['border_details']['B'];
  16469. $table['simple']['border'] = $table['border'];
  16470. }
  16471. }
  16472. }
  16473. // INHERITED THEAD CSS Properties
  16474. if ($this->tablethead) {
  16475. if ($this->thead_valign_default) $c['va'] = $align[strtolower($this->thead_valign_default)];
  16476. if ($this->thead_textalign_default) $c['a'] = $align[strtolower($this->thead_textalign_default)];
  16477. if ($this->thead_font_weight == 'B') { $this->SetStyle('B',true); }
  16478. if ($this->thead_font_style == 'I') { $this->SetStyle('I',true); }
  16479. if ($this->thead_font_smCaps == 'S') { $this->SetStyle('S',true); }
  16480. }
  16481. // INHERITED TFOOT CSS Properties
  16482. if ($this->tabletfoot) {
  16483. if ($this->tfoot_valign_default) $c['va'] = $align[strtolower($this->tfoot_valign_default)];
  16484. if ($this->tfoot_textalign_default) $c['a'] = $align[strtolower($this->tfoot_textalign_default)];
  16485. if ($this->tfoot_font_weight == 'B') { $this->SetStyle('B',true); }
  16486. if ($this->tfoot_font_style == 'I') { $this->SetStyle('I',true); }
  16487. if ($this->tfoot_font_style == 'S') { $this->SetStyle('S',true); }
  16488. }
  16489. if ($this->trow_text_rotate){
  16490. $c['R'] = $this->trow_text_rotate;
  16491. }
  16492. $this->cell_border_dominance_L = 0;
  16493. $this->cell_border_dominance_R = 0;
  16494. $this->cell_border_dominance_T = 0;
  16495. $this->cell_border_dominance_B = 0;
  16496. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  16497. $properties = $this->array_merge_recursive_unique($this->base_table_properties, $properties);
  16498. if (isset($properties['FONT-KERNING']) && (strtoupper($properties['FONT-KERNING'])=='NORMAL' || strtoupper($properties['FONT-KERNING'])=='AUTO')) {
  16499. $this->kerning = true;
  16500. }
  16501. else { $this->kerning = false; }
  16502. if (isset($properties['LETTER-SPACING']) && ($properties['LETTER-SPACING'] || $properties['LETTER-SPACING']==='0') && strtoupper($properties['LETTER-SPACING']) != 'NORMAL') {
  16503. $this->lSpacingCSS = strtoupper($properties['LETTER-SPACING']);
  16504. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  16505. }
  16506. else {
  16507. $this->lSpacingCSS = '';
  16508. $this->fixedlSpacing = false;
  16509. }
  16510. if (isset($properties['WORD-SPACING']) && strtoupper($properties['WORD-SPACING']) != 'NORMAL') {
  16511. $this->wSpacingCSS = strtoupper($properties['WORD-SPACING']);
  16512. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  16513. }
  16514. else {
  16515. $this->minwSpacing = 0;
  16516. $this->wSpacingCSS = '';
  16517. }
  16518. if (isset($properties['BACKGROUND-COLOR'])) { $c['bgcolor'] = $properties['BACKGROUND-COLOR']; }
  16519. else if (isset($properties['BACKGROUND'])) { $c['bgcolor'] = $properties['BACKGROUND']; }
  16520. /*-- BACKGROUNDS --*/
  16521. if (isset($properties['BACKGROUND-GRADIENT'])) { $c['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  16522. else { $c['gradient'] = false; }
  16523. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->keep_block_together) {
  16524. $ret = $this->SetBackground($properties, $this->blk[$this->blklvl]['inner_width']);
  16525. if ($ret) { $c['background-image'] = $ret; }
  16526. }
  16527. /*-- END BACKGROUNDS --*/
  16528. if (isset($properties['VERTICAL-ALIGN'])) { $c['va']=$align[strtolower($properties['VERTICAL-ALIGN'])]; }
  16529. if (isset($properties['TEXT-ALIGN'])) { $c['a'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  16530. if (isset($properties['TEXT-ROTATE']) && ($properties['TEXT-ROTATE'] || $properties['TEXT-ROTATE']==="0")){
  16531. $c['R'] = $properties['TEXT-ROTATE'];
  16532. }
  16533. if (isset($properties['BORDER'])) {
  16534. $bord = $this->border_details($properties['BORDER']);
  16535. if ($bord['s']) {
  16536. if (!$this->simpleTables){
  16537. $c['border'] = _BORDER_ALL;
  16538. $c['border_details']['R'] = $bord;
  16539. $c['border_details']['L'] = $bord;
  16540. $c['border_details']['T'] = $bord;
  16541. $c['border_details']['B'] = $bord;
  16542. $c['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  16543. $c['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  16544. $c['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  16545. $c['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  16546. }
  16547. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16548. $table['simple']['border'] = _BORDER_ALL;
  16549. $table['simple']['border_details']['R'] = $bord;
  16550. $table['simple']['border_details']['L'] = $bord;
  16551. $table['simple']['border_details']['T'] = $bord;
  16552. $table['simple']['border_details']['B'] = $bord;
  16553. }
  16554. }
  16555. }
  16556. if (!$this->simpleTables){
  16557. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) {
  16558. $c['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  16559. $this->setBorder($c['border'], _BORDER_RIGHT, $c['border_details']['R']['s']);
  16560. $c['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  16561. }
  16562. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  16563. $c['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  16564. $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']);
  16565. $c['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  16566. }
  16567. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) {
  16568. $c['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  16569. $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']);
  16570. $c['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  16571. }
  16572. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) {
  16573. $c['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  16574. $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']);
  16575. $c['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  16576. }
  16577. }
  16578. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  16579. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  16580. $bord = $this->border_details($properties['BORDER-LEFT']);
  16581. if ($bord['s']) { $table['simple']['border'] = _BORDER_ALL; }
  16582. else { $table['simple']['border'] = 0; }
  16583. $table['simple']['border_details']['R'] = $bord;
  16584. $table['simple']['border_details']['L'] = $bord;
  16585. $table['simple']['border_details']['T'] = $bord;
  16586. $table['simple']['border_details']['B'] = $bord;
  16587. }
  16588. }
  16589. if ($this->simpleTables && $this->row==0 && $this->col==0 && !$table['borders_separate'] && $table['simple']['border'] ){
  16590. $table['border_details'] = $table['simple']['border_details'];
  16591. $table['border'] = $table['simple']['border'];
  16592. }
  16593. // Border set on TR (if collapsed only)
  16594. if (!$table['borders_separate'] && !$this->simpleTables && isset($table['trborder-left'][$this->row])) {
  16595. if ($this->col==0) {
  16596. $left = $this->border_details($table['trborder-left'][$this->row]);
  16597. $c['border_details']['L'] = $left;
  16598. $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']);
  16599. }
  16600. $c['border_details']['B'] = $this->border_details($table['trborder-bottom'][$this->row]);
  16601. $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']);
  16602. $c['border_details']['T'] = $this->border_details($table['trborder-top'][$this->row]);
  16603. $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']);
  16604. }
  16605. if ($this->packTableData && !$this->simpleTables) {
  16606. $c['borderbin'] = $this->_packCellBorder($c);
  16607. unset($c['border']);
  16608. unset($c['border_details']);
  16609. }
  16610. if (isset($properties['PADDING-LEFT'])) {
  16611. $c['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16612. }
  16613. if (isset($properties['PADDING-RIGHT'])) {
  16614. $c['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16615. }
  16616. if (isset($properties['PADDING-BOTTOM'])) {
  16617. $c['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16618. }
  16619. if (isset($properties['PADDING-TOP'])) {
  16620. $c['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16621. }
  16622. $w = '';
  16623. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  16624. if (isset($attr['WIDTH'])) { $w = $attr['WIDTH']; }
  16625. if ($w) {
  16626. if (strpos($w,'%') && !$this->ignore_table_percents ) { $c['wpercent'] = $w + 0; } // makes 80% -> 80
  16627. else if (!strpos($w,'%') && !$this->ignore_table_widths ) { $c['w'] = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16628. }
  16629. if (isset($properties['HEIGHT']) && !strpos($properties['HEIGHT'],'%')) { $c['h'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  16630. if (isset($properties['COLOR'])) {
  16631. $cor = $this->ConvertColor($properties['COLOR']);
  16632. if ($cor) {
  16633. $this->colorarray = $cor;
  16634. $this->SetTColor($cor);
  16635. }
  16636. }
  16637. if (isset($properties['FONT-FAMILY'])) {
  16638. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  16639. }
  16640. if (isset($properties['FONT-SIZE'])) {
  16641. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK);
  16642. if ($mmsize) {
  16643. $this->SetFontSize($mmsize*(_MPDFK),false);
  16644. }
  16645. }
  16646. $c['dfs'] = $this->FontSize; // Default Font size
  16647. if (isset($properties['FONT-WEIGHT'])) {
  16648. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->SetStyle('B',true); }
  16649. }
  16650. if (isset($properties['FONT-STYLE'])) {
  16651. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->SetStyle('I',true); }
  16652. }
  16653. if (isset($properties['FONT-VARIANT'])) {
  16654. if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->SetStyle('S',true); }
  16655. }
  16656. if (isset($properties['TEXT-DECORATION'])) {
  16657. if (strtoupper($properties['TEXT-DECORATION']) == 'LINE-THROUGH') { $this->strike = true; }
  16658. else if (strtoupper($properties['TEXT-DECORATION']) == 'UNDERLINE') { $this->SetStyle('U',true); }
  16659. }
  16660. if (isset($properties['TEXT-SHADOW'])) {
  16661. $ts = $this->setCSStextshadow($properties['TEXT-SHADOW']);
  16662. if ($ts) { $this->textshadow = $ts; }
  16663. }
  16664. if (isset($properties['TEXT-TRANSFORM'])) {
  16665. if (strtoupper($properties['TEXT-TRANSFORM']) == 'CAPITALIZE') { $this->capitalize = true; }
  16666. else if (strtoupper($properties['TEXT-TRANSFORM']) == 'UPPERCASE') { $this->toupper = true; }
  16667. else if (strtoupper($properties['TEXT-TRANSFORM']) == 'LOWERCASE') { $this->tolower = true; }
  16668. }
  16669. if (isset($properties['WHITE-SPACE'])) {
  16670. if (strtoupper($properties['WHITE-SPACE']) == 'NOWRAP') { $c['nowrap']= 1; }
  16671. }
  16672. $properties = array();
  16673. if (isset($attr['HEIGHT']) && !strpos($attr['HEIGHT'],'%')) $c['h'] = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16674. if (isset($attr['ALIGN'])) $c['a'] = $align[strtolower($attr['ALIGN'])];
  16675. if (!$c['a']) {
  16676. if (isset($table['direction']) && $table['direction'] == 'rtl' ) { $c['a'] = 'R'; }
  16677. else { $c['a'] = 'L'; }
  16678. }
  16679. if (isset($attr['VALIGN'])) $c['va'] = $align[strtolower($attr['VALIGN'])];
  16680. if (isset($attr['BGCOLOR'])) $c['bgcolor'] = $attr['BGCOLOR'];
  16681. if (isset($attr['TEXT-ROTATE'])) {
  16682. $c['R'] = $attr['TEXT-ROTATE'];
  16683. }
  16684. if (isset($attr['NOWRAP']) && $attr['NOWRAP']) $c['nowrap']= 1;
  16685. $this->cell[$this->row][$this->col] = $c;
  16686. unset($c);
  16687. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16688. $cs = $rs = 1;
  16689. if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $this->cell[$this->row][$this->col]['colspan'] = $attr['COLSPAN'];
  16690. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+$cs) {
  16691. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+$cs;
  16692. } // following code moved outside if...
  16693. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  16694. if ($l-$this->col) $this->cell[$this->row][$l] = 0;
  16695. }
  16696. if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $this->cell[$this->row][$this->col]['rowspan'] = $attr['ROWSPAN'];
  16697. for ($k=$this->row ; $k < $this->row+$rs ;$k++) {
  16698. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  16699. if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0;
  16700. }
  16701. }
  16702. unset($table);
  16703. break;
  16704. /*-- END TABLES --*/
  16705. /*-- LISTS --*/
  16706. // *********** LISTS ********************
  16707. case 'OL':
  16708. case 'UL':
  16709. $this->listjustfinished = false;
  16710. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  16711. else { $lastbottommargin = 0; }
  16712. $this->lastblockbottommargin = 0;
  16713. $this->blockjustfinished=false;
  16714. $this->linebreakjustfinished=false;
  16715. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  16716. $this->listCSSlvl++;
  16717. if((!$this->tableLevel) && ($this->listlvl == 0)) {
  16718. $blockstate = 0;
  16719. //if ($this->lastblocklevelchange == 1) { $blockstate = -1; } // Top margins/padding only
  16720. //else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  16721. // called from block after new div e.g. <div> ... <ol> ... Outputs block top margin/border and padding
  16722. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  16723. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']);
  16724. $this->finishFlowingBlock(true); // true = END of flowing block
  16725. }
  16726. else if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  16727. $this->textbuffer=array();
  16728. $this->lastblocklevelchange = -1;
  16729. }
  16730. // ol and ul types are mixed here
  16731. if ($this->listlvl == 0) {
  16732. $this->list_indent = array();
  16733. $this->list_align = array();
  16734. $this->list_lineheight = array();
  16735. $this->InlineProperties['LIST'] = array();
  16736. $this->InlineProperties['LISTITEM'] = array();
  16737. }
  16738. /*-- TABLES --*/
  16739. // A simple list for inside a table
  16740. if($this->tableLevel) {
  16741. $this->list_indent[$this->listlvl] = 0; // mm default indent for each level
  16742. if ($tag == 'OL') $this->listtype = '1';
  16743. else if ($tag == 'UL') $this->listtype = 'disc';
  16744. if ($this->listlvl > 0) {
  16745. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16746. }
  16747. $this->listlvl++;
  16748. $this->listnum = 0; // reset
  16749. $this->listlist[$this->listlvl] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16750. break;
  16751. }
  16752. /*-- END TABLES --*/
  16753. if (($this->PDFA || $this->PDFX) && $tag == 'UL') {
  16754. 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 '-')"; }
  16755. }
  16756. if ($this->listCSSlvl==1) {
  16757. $properties = $this->MergeCSS('TOPLIST',$tag,$attr);
  16758. }
  16759. else {
  16760. $properties = $this->MergeCSS('LIST',$tag,$attr);
  16761. }
  16762. if (!empty($properties)) $this->setCSS($properties,'LIST');
  16763. // List-type
  16764. $this->listtype = '';
  16765. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listtype = $attr['TYPE']; }
  16766. else if (isset($properties['LIST-STYLE-TYPE'])) {
  16767. $this->listtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  16768. }
  16769. else if (isset($properties['LIST-STYLE'])) {
  16770. $this->listtype = $this->_getListStyle($properties['LIST-STYLE']);
  16771. }
  16772. if (!$this->listtype) {
  16773. if ($tag == 'OL') $this->listtype = '1';
  16774. if ($tag == 'UL') {
  16775. if ($this->listlvl % 3 == 0) $this->listtype = 'disc';
  16776. elseif ($this->listlvl % 3 == 1) $this->listtype = 'circle';
  16777. else $this->listtype = 'square';
  16778. }
  16779. }
  16780. if ($this->listlvl == 0) {
  16781. $this->inherit_lineheight = 0;
  16782. $this->listlvl++; // first depth level
  16783. $this->listnum = 0; // reset
  16784. $this->listDir = (isset($this->blk[$this->blklvl]['direction']) ? $this->blk[$this->blklvl]['direction'] : null);
  16785. $occur = $this->listoccur[$this->listlvl] = 1;
  16786. $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16787. }
  16788. else {
  16789. if (!empty($this->textbuffer))
  16790. {
  16791. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16792. $this->listnum++;
  16793. }
  16794. // Save current lineheight to inherit
  16795. $this->textbuffer = array();
  16796. $occur = $this->listoccur[$this->listlvl];
  16797. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16798. $this->listlvl++;
  16799. $this->listnum = 0; // reset
  16800. if (!isset($this->listoccur[$this->listlvl]) || $this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
  16801. else $this->listoccur[$this->listlvl]++;
  16802. $occur = $this->listoccur[$this->listlvl];
  16803. $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16804. }
  16805. // TOP LEVEL ONLY
  16806. if ($this->listlvl == 1) {
  16807. if (isset($properties['MARGIN-TOP'])) {
  16808. if ($lastbottommargin) {
  16809. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16810. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  16811. else { $properties['MARGIN-TOP'] = 0; }
  16812. }
  16813. $this->DivLn($this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false),$this->blklvl,true,1); // collapsible
  16814. }
  16815. if (isset($properties['MARGIN-BOTTOM'])) {
  16816. $this->list_margin_bottom = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16817. }
  16818. if (isset($this->blk[$this->blklvl]['line_height'])) {
  16819. $this->list_lineheight[$this->listlvl][$occur] = $this->blk[$this->blklvl]['line_height'];
  16820. }
  16821. if (isset($properties['DIRECTION']) && $properties['DIRECTION']) { $this->listDir = strtolower($properties['DIRECTION']); }
  16822. if (isset($attr['DIR']) && $attr['DIR']) { $this->listDir = strtolower($attr['DIR']); }
  16823. }
  16824. $this->list_indent[$this->listlvl][$occur] = 5; // mm default indent for each level
  16825. 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); }
  16826. if (isset($properties['TEXT-ALIGN'])) {
  16827. $this->list_align[$this->listlvl][$occur] = $align[strtolower($properties['TEXT-ALIGN'])];
  16828. }
  16829. if (isset($properties['LINE-HEIGHT'])) {
  16830. $this->list_lineheight[$this->listlvl][$occur] = $this->fixLineheight($properties['LINE-HEIGHT']);
  16831. }
  16832. else if ($this->listlvl>1 && isset($this->list_lineheight[($this->listlvl - 1)][1])) {
  16833. $this->list_lineheight[$this->listlvl][$occur] = end($this->list_lineheight[($this->listlvl - 1)]);
  16834. }
  16835. if (!isset($this->list_lineheight[$this->listlvl][$occur]) || !$this->list_lineheight[$this->listlvl][$occur]) {
  16836. $this->list_lineheight[$this->listlvl][$occur] = $this->normalLineheight;
  16837. }
  16838. $this->InlineProperties['LIST'][$this->listlvl][$occur] = $this->saveInlineProperties();
  16839. $properties = array();
  16840. break;
  16841. case 'LI':
  16842. // Start Block
  16843. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16844. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16845. /*-- TABLES --*/
  16846. // A simple list for inside a table
  16847. if($this->tableLevel) {
  16848. $this->blockjustfinished=false;
  16849. // If already something in the Cell
  16850. 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 ) {
  16851. $this->_saveCellTextBuffer("\n");
  16852. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  16853. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16854. }
  16855. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  16856. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16857. }
  16858. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16859. }
  16860. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16861. $this->listlvl++; // first depth level
  16862. $this->listnum = 0; // reset
  16863. $this->listlist[$this->listlvl] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16864. }
  16865. $this->listnum++;
  16866. switch($this->listlist[$this->listlvl]['TYPE']) {
  16867. case 'A':
  16868. $blt = $this->dec2alpha($this->listnum,true).$this->list_number_suffix;
  16869. break;
  16870. case 'a':
  16871. $blt = $this->dec2alpha($this->listnum,false).$this->list_number_suffix;
  16872. break;
  16873. case 'I':
  16874. $blt = $this->dec2roman($this->listnum,true).$this->list_number_suffix;
  16875. break;
  16876. case 'i':
  16877. $blt = $this->dec2roman($this->listnum,false).$this->list_number_suffix;
  16878. break;
  16879. case '1':
  16880. $blt = $this->listnum.$this->list_number_suffix;
  16881. break;
  16882. default:
  16883. if ($this->listlvl % 3 == 1 && $this->_charDefined($this->CurrentFont['cw'],8226)) { $blt = "\xe2\x80\xa2"; } // &#8226;
  16884. else if ($this->listlvl % 3 == 2 && $this->_charDefined($this->CurrentFont['cw'],9900)) { $blt = "\xe2\x9a\xac"; } // &#9900;
  16885. else if ($this->listlvl % 3 == 0 && $this->_charDefined($this->CurrentFont['cw'],9642)) { $blt = "\xe2\x96\xaa"; } // &#9642;
  16886. else { $blt = '-'; }
  16887. break;
  16888. }
  16889. // change to &nbsp; spaces
  16890. if ($this->usingCoreFont) {
  16891. $ls = str_repeat(chr(160).chr(160),($this->listlvl-1)*2) . $blt . ' ';
  16892. }
  16893. else {
  16894. $ls = str_repeat("\xc2\xa0\xc2\xa0",($this->listlvl-1)*2) . $blt . ' ';
  16895. }
  16896. $this->_saveCellTextBuffer($ls, $this->HREF);
  16897. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($ls);
  16898. break;
  16899. }
  16900. /*-- END TABLES --*/
  16901. //Observation: </LI> is ignored
  16902. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16903. //First of all, skip a line
  16904. $this->listlvl++; // first depth level
  16905. $this->listnum = 0; // reset
  16906. $this->listoccur[$this->listlvl] = 1;
  16907. $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16908. }
  16909. if ($this->listnum == 0) {
  16910. $this->listnum++;
  16911. $this->textbuffer = array();
  16912. }
  16913. else {
  16914. if (!empty($this->textbuffer)) {
  16915. if (!$this->listjustfinished) {
  16916. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16917. $this->listnum++;
  16918. }
  16919. else {
  16920. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype, true);
  16921. }
  16922. }
  16923. $this->textbuffer = array();
  16924. }
  16925. $this->listjustfinished = false;
  16926. $this->listCSSlvl++;
  16927. $properties = $this->MergeCSS('LIST',$tag,$attr);
  16928. if (!empty($properties)) $this->setCSS($properties,'LIST');
  16929. $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listoccur[$this->listlvl]][$this->listnum] = $this->saveInlineProperties();
  16930. // List-type
  16931. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listitemtype = $attr['TYPE']; }
  16932. else if (isset($properties['LIST-STYLE-TYPE'])) {
  16933. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  16934. }
  16935. else if (isset($properties['LIST-STYLE'])) {
  16936. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE']);
  16937. }
  16938. else $this->listitemtype = '';
  16939. break;
  16940. /*-- END LISTS --*/
  16941. }//end of switch
  16942. }
  16943. /*-- LISTS --*/
  16944. function _getListStyle($ls) {
  16945. if (stristr($ls,'decimal')) { return '1'; }
  16946. /* CSS3 list-styles numeric (selected) + I added tamil
  16947. arabic-indic | bengali | devanagari | gujarati | gurmukhi | kannada | malayalam | oriya | persian | telugu | thai | urdu
  16948. */
  16949. else if (preg_match('/(disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu)/i',$ls,$m)) {
  16950. return strtolower(trim($m[1]));
  16951. }
  16952. else if (stristr($ls,'lower-roman')) { return 'i'; }
  16953. else if (stristr($ls,'upper-roman')) { return 'I'; }
  16954. else if (stristr($ls,'lower-latin')|| stristr($ls,'lower-alpha')) { return 'a'; }
  16955. else if (stristr($ls,'upper-latin') || stristr($ls,'upper-alpha')) { return 'A'; }
  16956. else if (stristr($ls,'none')) { return 'none'; }
  16957. else if (preg_match('/U\+([a-fA-F0-9]+)/i',$ls)) { return $ls; }
  16958. else { return ''; }
  16959. }
  16960. /*-- END LISTS --*/
  16961. function CloseTag($tag)
  16962. {
  16963. $this->ignorefollowingspaces = false; //Eliminate exceeding left-side spaces
  16964. //Closing tag
  16965. if($tag=='OPTION') { $this->selectoption['ACTIVE'] = false; $this->lastoptionaltag = ''; }
  16966. if($tag=='TTS' or $tag=='TTA' or $tag=='TTZ') {
  16967. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16968. unset($this->InlineProperties[$tag]);
  16969. $ltag = strtolower($tag);
  16970. $this->$ltag = false;
  16971. }
  16972. if($tag=='FONT' || $tag=='SPAN' || $tag=='CODE' || $tag=='KBD' || $tag=='SAMP' || $tag=='TT' || $tag=='VAR'
  16973. || $tag=='INS' || $tag=='STRONG' || $tag=='CITE' || $tag=='SUB' || $tag=='SUP' || $tag=='S' || $tag=='STRIKE' || $tag=='DEL'
  16974. || $tag=='Q' || $tag=='EM' || $tag=='B' || $tag=='I' || $tag=='U' | $tag=='SMALL' || $tag=='BIG' || $tag=='ACRONYM'
  16975. || $tag=='MARK' || $tag=='TIME' || $tag=='PROGRESS' || $tag=='METER'
  16976. ) { // mPDF 5.5.09
  16977. if ($tag == 'SPAN') {
  16978. if (isset($this->InlineProperties['SPAN'][$this->spanlvl]) && $this->InlineProperties['SPAN'][$this->spanlvl]) { $this->restoreInlineProperties($this->InlineProperties['SPAN'][$this->spanlvl]); }
  16979. unset($this->InlineProperties['SPAN'][$this->spanlvl]);
  16980. if (isset($this->InlineAnnots['SPAN'][$this->spanlvl]) && $this->InlineAnnots['SPAN'][$this->spanlvl]) { $annot = $this->InlineAnnots['SPAN'][$this->spanlvl]; } // *ANNOTATIONS*
  16981. unset($this->InlineAnnots['SPAN'][$this->spanlvl]); // *ANNOTATIONS*
  16982. $this->spanlvl--;
  16983. }
  16984. else {
  16985. if (isset($this->InlineProperties[$tag]) && $this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16986. unset($this->InlineProperties[$tag]);
  16987. if (isset($this->InlineAnnots[$tag]) && $this->InlineAnnots[$tag]) { $annot = $this->InlineAnnots[$tag]; } // *ANNOTATIONS*
  16988. unset($this->InlineAnnots[$tag]); // *ANNOTATIONS*
  16989. }
  16990. /*-- ANNOTATIONS --*/
  16991. if (isset($annot)) {
  16992. if($this->tableLevel) { // *TABLES*
  16993. $this->cell[$this->row][$this->col]['textbuffer'][] = array($annot); // *TABLES*
  16994. } // *TABLES*
  16995. else { // *TABLES*
  16996. $this->textbuffer[] = array($annot);
  16997. } // *TABLES*
  16998. }
  16999. /*-- END ANNOTATIONS --*/
  17000. }
  17001. if($tag=='METER' || $tag=='PROGRESS') {
  17002. $this->inMeter = false; // mPDF 5.5.09
  17003. }
  17004. if($tag=='A') {
  17005. $this->HREF='';
  17006. if (isset($this->InlineProperties['A'])) { $this->restoreInlineProperties($this->InlineProperties['A']); }
  17007. unset($this->InlineProperties['A']);
  17008. }
  17009. if($tag=='LEGEND') { // mPDF 5.4.18
  17010. if (count($this->textbuffer) && !$this->tableLevel) {
  17011. $leg = $this->textbuffer[(count($this->textbuffer)-1)];
  17012. unset($this->textbuffer[(count($this->textbuffer)-1)]);
  17013. $this->textbuffer = array_values($this->textbuffer);
  17014. $this->blk[$this->blklvl]['border_legend'] = $leg;
  17015. $this->blk[$this->blklvl]['margin_top'] += ($leg[11]/2)/_MPDFK;
  17016. $this->blk[$this->blklvl]['padding_top'] += ($leg[11]/2)/_MPDFK;
  17017. }
  17018. if (isset($this->InlineProperties['LEGEND'])) { $this->restoreInlineProperties($this->InlineProperties['LEGEND']); }
  17019. unset($this->InlineProperties['LEGEND']);
  17020. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17021. }
  17022. /*-- FORMS --*/
  17023. // *********** FORM ELEMENTS ********************
  17024. if($tag=='TEXTAREA') {
  17025. $this->specialcontent = '';
  17026. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  17027. unset($this->InlineProperties[$tag]);
  17028. }
  17029. if($tag=='SELECT') {
  17030. $this->lastoptionaltag = '';
  17031. $texto = '';
  17032. if (isset($this->selectoption['SELECTED'])) { $texto = $this->selectoption['SELECTED']; }
  17033. if ($this->useActiveForms) { $w = $this->selectoption['MAXWIDTH']; }
  17034. else { $w = $this->GetStringWidth($texto); }
  17035. if ($w == 0) { $w = 5; }
  17036. $objattr['type'] = 'select';
  17037. $objattr['text'] = $texto;
  17038. if (isset($this->selectoption['NAME'])) { $objattr['fieldname'] = $this->selectoption['NAME']; }
  17039. if (isset($this->selectoption['READONLY'])) { $objattr['readonly'] = true; }
  17040. if (isset($this->selectoption['REQUIRED'])) { $objattr['required'] = true; }
  17041. if (isset($this->selectoption['SPELLCHECK'])) { $objattr['spellcheck'] = true; }
  17042. if (isset($this->selectoption['EDITABLE'])) { $objattr['editable'] = true; }
  17043. if (isset($this->selectoption['ONCHANGE'])) { $objattr['onChange'] = $this->selectoption['ONCHANGE']; }
  17044. if (isset($this->selectoption['ITEMS'])) { $objattr['items'] = $this->selectoption['ITEMS']; }
  17045. if (isset($this->selectoption['MULTIPLE'])) { $objattr['multiple'] = $this->selectoption['MULTIPLE']; }
  17046. if (isset($this->selectoption['DISABLED'])) { $objattr['disabled'] = $this->selectoption['DISABLED']; }
  17047. if (isset($this->selectoption['TITLE'])) { $objattr['title'] = $this->selectoption['TITLE']; }
  17048. if (isset($this->selectoption['COLOR'])) { $objattr['color'] = $this->selectoption['COLOR']; }
  17049. if (isset($this->selectoption['SIZE'])) { $objattr['size'] = $this->selectoption['SIZE']; }
  17050. if (isset($objattr['size']) && $objattr['size']>1) { $rows=$objattr['size']; } else { $rows = 1; }
  17051. $objattr['fontfamily'] = $this->FontFamily;
  17052. $objattr['fontsize'] = $this->FontSizePt;
  17053. $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);
  17054. $objattr['height'] = ($this->FontSize*$rows) + ($this->form->form_element_spacing['select']['outer']['v']*2)+($this->form->form_element_spacing['select']['inner']['v']*2);
  17055. $e = "\xbb\xa4\xactype=select,objattr=".serialize($objattr)."\xbb\xa4\xac";
  17056. // Clear properties - tidy up
  17057. $properties = array();
  17058. // Output it to buffers
  17059. if ($this->tableLevel) { // *TABLES*
  17060. $this->_saveCellTextBuffer($e, $this->HREF);
  17061. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  17062. } // *TABLES*
  17063. else { // *TABLES*
  17064. $this->_saveTextBuffer($e, $this->HREF);
  17065. } // *TABLES*
  17066. $this->selectoption = array();
  17067. $this->specialcontent = '';
  17068. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  17069. unset($this->InlineProperties[$tag]);
  17070. }
  17071. /*-- END FORMS --*/
  17072. // *********** BLOCKS ********************
  17073. // mPDF 5.4.18
  17074. if($tag=='P' || $tag=='DIV' || $tag=='H1' || $tag=='H2' || $tag=='H3' || $tag=='H4' || $tag=='H5' || $tag=='H6' || $tag=='PRE'
  17075. || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DT' || $tag=='DD' || $tag=='DL'
  17076. || $tag=='CAPTION' || $tag=='FIELDSET'
  17077. || $tag=='ARTICLE' || $tag=='ASIDE' || $tag=='FIGURE' || $tag=='FIGCAPTION' || $tag=='FOOTER' || $tag=='HEADER' || $tag=='HGROUP'
  17078. || $tag=='NAV' || $tag=='SECTION' || $tag=='DETAILS' || $tag=='SUMMARY'
  17079. ) { // mPDF 5.5.09 // mPDF 5.5.22
  17080. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17081. $this->blockjustfinished=true;
  17082. $this->lastblockbottommargin = $this->blk[$this->blklvl]['margin_bottom'];
  17083. /*-- LISTS --*/
  17084. if ($this->listlvl>0) { return; }
  17085. /*-- END LISTS --*/
  17086. /*-- TABLES --*/
  17087. if($this->tableLevel) {
  17088. if ($this->linebreakjustfinished) { $this->blockjustfinished=false; }
  17089. if (isset($this->InlineProperties['BLOCKINTABLE'])) {
  17090. if ($this->InlineProperties['BLOCKINTABLE']) { $this->restoreInlineProperties($this->InlineProperties['BLOCKINTABLE']); }
  17091. unset($this->InlineProperties['BLOCKINTABLE']);
  17092. }
  17093. if($tag=='PRE') { $this->ispre=false; }
  17094. return;
  17095. }
  17096. /*-- END TABLES --*/
  17097. $this->lastoptionaltag = '';
  17098. $this->divbegin=false;
  17099. $this->linebreakjustfinished=false;
  17100. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17101. /*-- CSS-FLOAT --*/
  17102. // If float contained in a float, need to extend bottom to allow for it
  17103. $currpos = $this->page*1000 + $this->y;
  17104. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  17105. $old_page = $this->page;
  17106. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  17107. if ($old_page != $new_page) {
  17108. $s = $this->PrintPageBackgrounds();
  17109. // Writes after the marker so not overwritten later by page background etc.
  17110. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  17111. $this->pageBackgrounds = array();
  17112. $this->page = $new_page;
  17113. $this->ResetMargins();
  17114. $this->Reset();
  17115. $this->pageoutput[$this->page] = array();
  17116. }
  17117. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  17118. }
  17119. /*-- END CSS-FLOAT --*/
  17120. //Print content
  17121. if ($this->lastblocklevelchange == 1) { $blockstate = 3; } // Top & bottom margins/padding
  17122. else if ($this->lastblocklevelchange == -1) { $blockstate = 2; } // Bottom margins/padding only
  17123. else { $blockstate = 0; }
  17124. // called from after e.g. </table> </div> </div> ... Outputs block margin/border and padding
  17125. if (count($this->textbuffer) && $this->textbuffer[count($this->textbuffer)-1]) {
  17126. if (substr($this->textbuffer[count($this->textbuffer)-1][0],0,3) != "\xbb\xa4\xac") { // not special content
  17127. if ($this->usingCoreFont) {
  17128. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/', '', $this->textbuffer[count($this->textbuffer)-1][0]);
  17129. }
  17130. else {
  17131. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/u', '', $this->textbuffer[count($this->textbuffer)-1][0]); }
  17132. }
  17133. }
  17134. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange != 0) {
  17135. //$this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,2,true, $this->blk[$this->blklvl]['direction']);
  17136. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,$blockstate,true, $this->blk[$this->blklvl]['direction']);
  17137. $this->finishFlowingBlock(true); // true = END of flowing block
  17138. $this->PaintDivBB('',$blockstate);
  17139. }
  17140. else {
  17141. $this->printbuffer($this->textbuffer,$blockstate);
  17142. }
  17143. $this->textbuffer=array();
  17144. if ($this->blk[$this->blklvl]['keep_block_together']) {
  17145. $this->printdivbuffer();
  17146. }
  17147. if ($this->kwt) {
  17148. $this->kwt_height = $this->y - $this->kwt_y0;
  17149. }
  17150. /*-- CSS-IMAGE-FLOAT --*/
  17151. $this->printfloatbuffer();
  17152. /*-- END CSS-IMAGE-FLOAT --*/
  17153. if($tag=='PRE') { $this->ispre=false; }
  17154. /*-- CSS-FLOAT --*/
  17155. if ($this->blk[$this->blklvl]['float'] == 'R') {
  17156. // If width not set, here would need to adjust and output buffer
  17157. $s = $this->PrintPageBackgrounds();
  17158. // Writes after the marker so not overwritten later by page background etc.
  17159. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  17160. $this->pageBackgrounds = array();
  17161. $this->Reset();
  17162. $this->pageoutput[$this->page] = array();
  17163. for($i=($this->blklvl-1); $i >= 0; $i--) {
  17164. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  17165. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  17166. }
  17167. $this->floatDivs[] = array(
  17168. 'side'=>'R',
  17169. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  17170. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  17171. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  17172. 'endpage'=>$this->page ,
  17173. 'y1'=>$this->y ,
  17174. 'endpos'=> ($this->page*1000 + $this->y),
  17175. 'w'=> $this->blk[$this->blklvl]['float_width'],
  17176. 'blklvl'=>$this->blklvl,
  17177. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  17178. );
  17179. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  17180. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  17181. $this->ResetMargins();
  17182. $this->pageoutput[$this->page] = array();
  17183. }
  17184. if ($this->blk[$this->blklvl]['float'] == 'L') {
  17185. // If width not set, here would need to adjust and output buffer
  17186. $s = $this->PrintPageBackgrounds();
  17187. // Writes after the marker so not overwritten later by page background etc.
  17188. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  17189. $this->pageBackgrounds = array();
  17190. $this->Reset();
  17191. $this->pageoutput[$this->page] = array();
  17192. for($i=($this->blklvl-1); $i >= 0; $i--) {
  17193. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  17194. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  17195. }
  17196. $this->floatDivs[] = array(
  17197. 'side'=>'L',
  17198. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  17199. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  17200. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  17201. 'endpage'=>$this->page ,
  17202. 'y1'=>$this->y ,
  17203. 'endpos'=> ($this->page*1000 + $this->y),
  17204. 'w'=> $this->blk[$this->blklvl]['float_width'],
  17205. 'blklvl'=>$this->blklvl,
  17206. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  17207. );
  17208. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  17209. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  17210. $this->ResetMargins();
  17211. $this->pageoutput[$this->page] = array();
  17212. }
  17213. /*-- END CSS-FLOAT --*/
  17214. if (isset($this->blk[$this->blklvl]['visibility']) && $this->blk[$this->blklvl]['visibility']!='visible') {
  17215. $this->SetVisibility('visible');
  17216. }
  17217. if (isset($this->blk[$this->blklvl]['page_break_after'])) { $page_break_after = $this->blk[$this->blklvl]['page_break_after']; }
  17218. else { $page_break_after = ''; }
  17219. //Reset values
  17220. $this->Reset();
  17221. if ($this->blklvl > 0) { // ==0 SHOULDN'T HAPPEN - NOT XHTML
  17222. if ($this->blk[$this->blklvl]['tag'] == $tag) {
  17223. unset($this->blk[$this->blklvl]);
  17224. $this->blklvl--;
  17225. }
  17226. //else { echo $tag; exit; } // debug - forces error if incorrectly nested html tags
  17227. }
  17228. $this->lastblocklevelchange = -1 ;
  17229. // Reset Inline-type properties
  17230. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']); }
  17231. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17232. if ($page_break_after) {
  17233. $save_blklvl = $this->blklvl;
  17234. $save_blk = $this->blk;
  17235. $save_silp = $this->saveInlineProperties();
  17236. $save_spanlvl = $this->spanlvl;
  17237. $save_ilp = $this->InlineProperties;
  17238. if ($this->blklvl>1) {
  17239. // Close any open block tags
  17240. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  17241. // Output any text left in buffer
  17242. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  17243. }
  17244. /*-- COLUMNS --*/
  17245. $save_cols = false;
  17246. if ($this->ColActive) {
  17247. $save_cols = true;
  17248. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  17249. $this->SetColumns(0);
  17250. }
  17251. /*-- END COLUMNS --*/
  17252. if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17253. else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17254. else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17255. if (!$this->restoreBlockPagebreaks) {
  17256. $this->blklvl = 0;
  17257. $this->lastblocklevelchange = 0;
  17258. $this->blk = array();
  17259. $this->initialiseBlock($this->blk[0]);
  17260. $this->blk[0]['width'] =& $this->pgwidth;
  17261. $this->blk[0]['inner_width'] =& $this->pgwidth;
  17262. $this->blk[0]['blockContext'] = $this->blockContext;
  17263. $properties = $this->MergeCSS('BLOCK','BODY','');
  17264. $this->setCSS($properties,'','BODY');
  17265. $this->blklvl++;
  17266. $currblk =& $this->blk[$this->blklvl];
  17267. $prevblk =& $this->blk[$this->blklvl-1];
  17268. $this->initialiseBlock($currblk);
  17269. $currblk['tag'] = $tag;
  17270. $currblk['attr'] = $attr;
  17271. $this->Reset();
  17272. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  17273. }
  17274. /*-- COLUMNS --*/
  17275. if ($save_cols) {
  17276. // Restore columns
  17277. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  17278. }
  17279. /*-- END COLUMNS --*/
  17280. if ($this->restoreBlockPagebreaks && !$this->tableLevel && !$this->listlvl) {
  17281. $this->blk = $save_blk;
  17282. // Re-open block tags
  17283. $t = $this->blk[0]['tag'];
  17284. $a = $this->blk[0]['attr'];
  17285. $this->blklvl = 0;
  17286. for ($b=0; $b<=$save_blklvl;$b++) {
  17287. $tc = $t;
  17288. $ac = $a;
  17289. $t = $this->blk[$b+1]['tag'];
  17290. $a = $this->blk[$b+1]['attr'];
  17291. unset($this->blk[$b+1]);
  17292. $this->OpenTag($tc,$ac);
  17293. }
  17294. $this->spanlvl = $save_spanlvl;
  17295. $this->InlineProperties = $save_ilp;
  17296. $this->restoreInlineProperties($save_silp);
  17297. }
  17298. }
  17299. }
  17300. /*-- TABLES --*/
  17301. if($tag=='TH') $this->SetStyle('B',false);
  17302. if(($tag=='TH' or $tag=='TD') && $this->tableLevel) {
  17303. $this->lastoptionaltag = 'TR';
  17304. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17305. $this->tbCSSlvl--;
  17306. if (!$this->tdbegin) { return; }
  17307. $this->tdbegin = false;
  17308. // Added for correct calculation of cell column width - otherwise misses the last line if not end </p> etc.
  17309. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17310. 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;"); }
  17311. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17312. }
  17313. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17314. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17315. }
  17316. // Remove last <br> if at end of cell
  17317. if (isset($this->cell[$this->row][$this->col]['textbuffer'])) { $ntb = count($this->cell[$this->row][$this->col]['textbuffer']); }
  17318. else { $ntb = 0; }
  17319. if ($ntb>1 && $this->cell[$this->row][$this->col]['textbuffer'][$ntb-1][0] == "\n") {
  17320. unset($this->cell[$this->row][$this->col]['textbuffer'][$ntb-1]);
  17321. }
  17322. if ($this->cacheTables) {
  17323. $clen = $this->_cacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache']);
  17324. $this->cell[$this->row][$this->col] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr'];
  17325. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr'] += $clen;
  17326. }
  17327. if ($this->tablethead) {
  17328. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true;
  17329. 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)); }
  17330. }
  17331. if ($this->tabletfoot) {
  17332. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true;
  17333. 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'] )); }
  17334. }
  17335. $this->Reset();
  17336. }
  17337. if($tag=='TR' && $this->tableLevel) {
  17338. // If Border set on TR - Update right border
  17339. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row])) {
  17340. if ($this->cacheTables) {
  17341. $c = $this->_uncacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], null);
  17342. }
  17343. else { $c =& $this->cell[$this->row][$this->col]; }
  17344. if ($c) {
  17345. if ($this->packTableData) {
  17346. $cell = $this->_unpackCellBorder($c['borderbin'] );
  17347. }
  17348. else { $cell = $c; }
  17349. $cell['border_details']['R'] = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row]);
  17350. $this->setBorder($cell['border'], _BORDER_RIGHT, $cell['border_details']['R']['s']);
  17351. if ($this->packTableData) {
  17352. $c['borderbin'] = $this->_packCellBorder($cell);
  17353. unset($c['border']);
  17354. unset($c['border_details']);
  17355. }
  17356. else { $c = $cell; }
  17357. }
  17358. if ($this->cacheTables) {
  17359. $fh = fopen($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], "r+b");
  17360. $this->_cacheUpdateBorder($c, $fh, $this->cell[$this->row][$this->col]);
  17361. fclose($fh);
  17362. }
  17363. }
  17364. $this->lastoptionaltag = '';
  17365. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17366. $this->tbCSSlvl--;
  17367. $this->trow_text_rotate = '';
  17368. $this->tabletheadjustfinished = false;
  17369. }
  17370. if($tag=='TBODY') {
  17371. $this->lastoptionaltag = '';
  17372. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17373. $this->tbCSSlvl--;
  17374. }
  17375. if($tag=='THEAD') {
  17376. $this->lastoptionaltag = '';
  17377. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17378. $this->tbCSSlvl--;
  17379. $this->tablethead = 0;
  17380. $this->tabletheadjustfinished = true;
  17381. $this->ResetStyles();
  17382. $this->thead_font_weight = '';
  17383. $this->thead_font_style = '';
  17384. $this->thead_font_smCaps = '';
  17385. $this->thead_valign_default = '';
  17386. $this->thead_textalign_default = '';
  17387. }
  17388. if($tag=='TFOOT') {
  17389. $this->lastoptionaltag = '';
  17390. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17391. $this->tbCSSlvl--;
  17392. $this->tabletfoot = 0;
  17393. $this->ResetStyles();
  17394. $this->tfoot_font_weight = '';
  17395. $this->tfoot_font_style = '';
  17396. $this->tfoot_font_smCaps = '';
  17397. $this->tfoot_valign_default = '';
  17398. $this->tfoot_textalign_default = '';
  17399. }
  17400. if($tag=='TABLE') { // TABLE-END (
  17401. if ($this->progressBar) { $this->UpdateProgressBar(1,'','TABLE'); } // *PROGRESS-BAR*
  17402. if ($this->progressBar) { $this->UpdateProgressBar(7,0,''); } // *PROGRESS-BAR*
  17403. $this->lastoptionaltag = '';
  17404. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  17405. $this->tbCSSlvl--;
  17406. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  17407. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  17408. $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));
  17409. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['hr'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr'],0);
  17410. // Move table footer <tfoot> row to end of table
  17411. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) && count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'])) {
  17412. $tfrows = array();
  17413. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] AS $r=>$val) {
  17414. if ($val) { $tfrows[] = $r; }
  17415. }
  17416. $temp = array();
  17417. $temptf = array();
  17418. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] AS $k=>$row) {
  17419. if (in_array($k,$tfrows)) {
  17420. $temptf[] = $row;
  17421. }
  17422. else {
  17423. $temp[] = $row;
  17424. }
  17425. }
  17426. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] = array();
  17427. for($i=count($temp) ; $i<(count($temp)+count($temptf)); $i++) {
  17428. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$i] = true;
  17429. }
  17430. // Update nestedpos row references
  17431. if (count($this->table[($this->tableLevel+1)])) {
  17432. foreach($this->table[($this->tableLevel+1)] AS $nid=>$nested) {
  17433. $this->table[($this->tableLevel+1)][$nid]['nestedpos'][0] -= count($temptf);
  17434. }
  17435. }
  17436. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = array_merge($temp, $temptf);
  17437. // Update other arays set on row number
  17438. // [trbackground-images] [trgradients]
  17439. $temptrbgi = array();
  17440. $temptrbgg = array();
  17441. $temptrbgc = array();
  17442. $temptrbgc[-1] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][-1];
  17443. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  17444. if (!in_array($k,$tfrows)) {
  17445. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  17446. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  17447. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k];
  17448. }
  17449. }
  17450. for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) {
  17451. if (in_array($k,$tfrows)) {
  17452. $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k];
  17453. $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k];
  17454. $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k];
  17455. }
  17456. }
  17457. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'] = $temptrbgi;
  17458. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'] = $temptrbgg;
  17459. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'] = $temptrbgc ;
  17460. // Should Update all other arays set on row number, but cell properties have been set so not needed
  17461. // [bgcolor] [trborder-left] [trborder-right] [trborder-top] [trborder-bottom]
  17462. }
  17463. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']=='rtl') {
  17464. $this->_reverseTableDir($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  17465. }
  17466. // Fix Borders *********************************************
  17467. $this->_fixTableBorders($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  17468. if ($this->progressBar) { $this->UpdateProgressBar(7,10,' '); } // *PROGRESS-BAR*
  17469. if ($this->ColActive) { $this->table_rotate = 0; } // *COLUMNS*
  17470. if ($this->table_rotate <> 0) {
  17471. $this->tablebuffer = '';
  17472. // Max width for rotated table
  17473. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 1);
  17474. $this->tbrot_maxh = $this->blk[$this->blklvl]['inner_width'] ; // Max width for rotated table
  17475. $this->tbrot_align = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['a'] ;
  17476. }
  17477. $this->shrin_k = 1;
  17478. if ($this->shrink_tables_to_fit < 1) { $this->shrink_tables_to_fit = 1; }
  17479. if (!$this->shrink_this_table_to_fit) { $this->shrink_this_table_to_fit = $this->shrink_tables_to_fit; }
  17480. if ($this->tableLevel>1) {
  17481. // deal with nested table
  17482. $this->_tableColumnWidth($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]],true);
  17483. $tmiw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['miw'];
  17484. $tmaw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['maw'];
  17485. $tl = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tl'];
  17486. // Go down to lower table level
  17487. $this->tableLevel--;
  17488. // Reset lower level table
  17489. $this->base_table_properties = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties'];
  17490. $this->cell = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'];
  17491. // mPDF 5.4.10
  17492. if (isset($this->cell['PARENTCELL'])) {
  17493. if ($this->cell['PARENTCELL']) { $this->restoreInlineProperties($this->cell['PARENTCELL']); }
  17494. unset($this->cell['PARENTCELL']);
  17495. }
  17496. $this->row = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'];
  17497. $this->col = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'];
  17498. $objattr = array();
  17499. $objattr['type'] = 'nestedtable';
  17500. $objattr['nestedcontent'] = $this->tbctr[($this->tableLevel+1)];
  17501. $objattr['table'] = $this->tbctr[$this->tableLevel];
  17502. $objattr['row'] = $this->row;
  17503. $objattr['col'] = $this->col;
  17504. $objattr['level'] = $this->tableLevel;
  17505. $e = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  17506. $this->_saveCellTextBuffer($e);
  17507. $this->cell[$this->row][$this->col]['s'] += $tl ;
  17508. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  17509. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17510. }
  17511. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  17512. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  17513. }
  17514. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  17515. 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 ; }
  17516. 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 ; }
  17517. $this->tdbegin = true;
  17518. $this->nestedtablejustfinished = true;
  17519. $this->ignorefollowingspaces = true;
  17520. return;
  17521. }
  17522. $this->cMarginL = 0;
  17523. $this->cMarginR = 0;
  17524. $this->cMarginT = 0;
  17525. $this->cMarginB = 0;
  17526. $this->cellPaddingL = 0;
  17527. $this->cellPaddingR = 0;
  17528. $this->cellPaddingT = 0;
  17529. $this->cellPaddingB = 0;
  17530. if (isset($this->table[1][1]['overflow']) && $this->table[1][1]['overflow']=='visible') {
  17531. if ($this->kwt || $this->table_rotate || $this->table_keep_together || $this->ColActive) {
  17532. $this->kwt = false;
  17533. $this->table_rotate = 0;
  17534. $this->table_keep_together = false;
  17535. //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");
  17536. }
  17537. $this->_tableColumnWidth($this->table[1][1],true);
  17538. $this->_tableWidth($this->table[1][1]);
  17539. }
  17540. else {
  17541. if (!$this->kwt_saved) { $this->kwt_height = 0; }
  17542. list($check,$tablemiw) = $this->_tableColumnWidth($this->table[1][1],true);
  17543. $save_table = $this->table;
  17544. if ($this->cacheTables) { $this->_backupCacheFiles(); }
  17545. $reset_to_minimum_width = false;
  17546. $added_page = false;
  17547. if ($check > 1) {
  17548. if ($check > $this->shrink_this_table_to_fit && $this->table_rotate) {
  17549. if ($this->y != $this->tMargin) {
  17550. $this->AddPage($this->CurOrientation);
  17551. $this->kwt_moved = true;
  17552. }
  17553. $added_page = true;
  17554. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17555. //$check = $tablemiw/$this->tbrot_maxw; // undo any shrink
  17556. $check = 1; // undo any shrink
  17557. }
  17558. $reset_to_minimum_width = true;
  17559. }
  17560. if ($reset_to_minimum_width) {
  17561. $this->shrin_k = $check;
  17562. $this->default_font_size /= $this->shrin_k;
  17563. $this->SetFontSize($this->default_font_size, false );
  17564. $this->shrinkTable($this->table[1][1],$this->shrin_k);
  17565. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  17566. // Starting at $this->innermostTableLevel
  17567. // Shrink table values - and redo columnWidth
  17568. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17569. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17570. $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k);
  17571. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  17572. }
  17573. }
  17574. }
  17575. // Set table cell widths for top level table
  17576. // Use $shrin_k to resize but don't change again
  17577. $this->SetLineHeight('',$this->table_lineheight);
  17578. // Top level table
  17579. $this->_tableWidth($this->table[1][1]);
  17580. }
  17581. // Now work through any nested tables setting child table[w'] = parent cell['w']
  17582. // Now do nested tables _tableWidth
  17583. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17584. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17585. // HERE set child table width = cell width
  17586. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  17587. if ($this->cacheTables) {
  17588. $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null);
  17589. }
  17590. else
  17591. $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol];
  17592. if (isset($c['colspan']) && $c['colspan']> 1) {
  17593. $parentwidth = 0;
  17594. for($cs=0;$cs<$c['colspan'] ; $cs++) {
  17595. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  17596. }
  17597. }
  17598. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  17599. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  17600. if (!$this->simpleTables){
  17601. if ($this->packTableData) {
  17602. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  17603. }
  17604. else {
  17605. $br = $c['border_details']['R']['w'];
  17606. $bl = $c['border_details']['L']['w'];
  17607. }
  17608. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17609. $parentwidth -= $br + $bl
  17610. + $c['padding']['L']
  17611. + $c['padding']['R']
  17612. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17613. }
  17614. else {
  17615. $parentwidth -= $br/2 + $bl/2
  17616. + $c['padding']['L']
  17617. + $c['padding']['R'];
  17618. }
  17619. }
  17620. else if ($this->simpleTables){
  17621. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17622. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17623. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  17624. + $c['padding']['L']
  17625. + $c['padding']['R']
  17626. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17627. }
  17628. else {
  17629. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']/2
  17630. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']/2
  17631. + $c['padding']['L']
  17632. + $c['padding']['R'];
  17633. }
  17634. }
  17635. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  17636. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17637. }
  17638. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  17639. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'];
  17640. }
  17641. else {
  17642. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17643. }
  17644. unset($c);
  17645. $this->_tableWidth($this->table[$lvl][$nid]);
  17646. }
  17647. }
  17648. // Starting at $this->innermostTableLevel
  17649. // Cascade back up nested tables: setting heights back up the tree
  17650. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  17651. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17652. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  17653. }
  17654. if ($this->progressBar) { $this->UpdateProgressBar(7,20,' '); } // *PROGRESS-BAR*
  17655. if ($this->table[1][1]['overflow']=='visible') {
  17656. if ($maxrowheight > $fullpage) { die("mPDF Warning: A Table row is greater than available height. You cannot use CSS overflow:visible"); }
  17657. if ($maxfirstrowheight > $remainingpage) { $this->AddPage($this->CurOrientation); }
  17658. $r = 0; $c = 0; $p = 0; $y = 0;
  17659. while (!$finished) {
  17660. list($finished,$r,$c,$p,$y,$y0) = $this->_tableWrite($this->table[1][1],true,$r,$c,$p,$y);
  17661. if (!$finished) {
  17662. $this->AddPage($this->CurOrientation);
  17663. // If printed something on first spread, set same y
  17664. if ($r==0 && $y0 > -1) { $this->y = $y0; }
  17665. }
  17666. }
  17667. }
  17668. else {
  17669. $recalculate = 1;
  17670. $forcerecalc = false;
  17671. // RESIZING ALGORITHM
  17672. if ($maxrowheight > $fullpage) {
  17673. $recalculate = $this->tbsqrt($maxrowheight / $fullpage, 1);
  17674. $forcerecalc = true;
  17675. }
  17676. else if ($this->table_rotate) { // NB $remainingpage == $fullpage == the width of the page
  17677. if ($tableheight > $remainingpage) {
  17678. // If can fit on remainder of page whilst respecting autsize value..
  17679. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  17680. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  17681. }
  17682. else if (!$added_page) {
  17683. if ($this->y != $this->tMargin) {
  17684. $this->AddPage($this->CurOrientation);
  17685. $this->kwt_moved = true;
  17686. }
  17687. $added_page = true;
  17688. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17689. // 0.001 to force it to recalculate
  17690. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17691. }
  17692. }
  17693. else { $recalculate = 1; }
  17694. }
  17695. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) {
  17696. if ($tableheight > $fullpage) {
  17697. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, 1)) <= $this->shrink_this_table_to_fit) {
  17698. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  17699. }
  17700. else if ($this->tableMinSizePriority) {
  17701. $this->table_keep_together = false;
  17702. $recalculate = 1.001;
  17703. }
  17704. else {
  17705. if ($this->y != $this->tMargin) { // mPDF 5.1
  17706. $this->AddPage($this->CurOrientation);
  17707. $this->kwt_moved = true;
  17708. }
  17709. $added_page = true;
  17710. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17711. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  17712. }
  17713. }
  17714. else if ($tableheight > $remainingpage) {
  17715. // If can fit on remainder of page whilst respecting autsize value..
  17716. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  17717. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  17718. }
  17719. else {
  17720. if ($this->y != $this->tMargin) {
  17721. $this->AddPage($this->CurOrientation);
  17722. $this->kwt_moved = true;
  17723. }
  17724. $added_page = true;
  17725. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17726. $recalculate = 1.001;
  17727. }
  17728. }
  17729. else { $recalculate = 1; }
  17730. }
  17731. else { $recalculate = 1; }
  17732. if ($recalculate > $this->shrink_this_table_to_fit && !$forcerecalc) { $recalculate = $this->shrink_this_table_to_fit; }
  17733. $iteration = 1;
  17734. // RECALCULATE
  17735. while($recalculate <> 1) {
  17736. $this->shrin_k1 = $recalculate ;
  17737. $this->shrin_k *= $recalculate ;
  17738. $this->default_font_size /= ($this->shrin_k1) ;
  17739. $this->SetFontSize($this->default_font_size, false );
  17740. $this->SetLineHeight('',$this->table_lineheight);
  17741. $this->table = $save_table;
  17742. if ($this->cacheTables) { $this->_restoreCacheFiles(); }
  17743. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[1][1],$this->shrin_k); }
  17744. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  17745. // Starting at $this->innermostTableLevel
  17746. // Shrink table values - and redo columnWidth
  17747. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17748. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17749. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k); }
  17750. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  17751. }
  17752. }
  17753. // Set table cell widths for top level table
  17754. // Top level table
  17755. $this->_tableWidth($this->table[1][1]);
  17756. // Now work through any nested tables setting child table[w'] = parent cell['w']
  17757. // Now do nested tables _tableWidth
  17758. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  17759. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17760. // HERE set child table width = cell width
  17761. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  17762. if ($this->cacheTables) {
  17763. $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null);
  17764. }
  17765. else
  17766. $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol];
  17767. if (isset($c['colspan']) && $c['colspan']> 1) {
  17768. $parentwidth = 0;
  17769. for($cs=0;$cs<$c['colspan'] ; $cs++) {
  17770. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  17771. }
  17772. }
  17773. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  17774. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  17775. if (!$this->simpleTables){
  17776. if ($this->packTableData) {
  17777. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  17778. }
  17779. else {
  17780. $br = $c['border_details']['R']['w'];
  17781. $bl = $c['border_details']['L']['w'];
  17782. }
  17783. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17784. $parentwidth -= $br + $bl
  17785. + $c['padding']['L']
  17786. + $c['padding']['R']
  17787. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17788. }
  17789. else {
  17790. $parentwidth -= $br/2 + $bl/2
  17791. + $c['padding']['L']
  17792. + $c['padding']['R'];
  17793. }
  17794. }
  17795. else if ($this->simpleTables){
  17796. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  17797. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17798. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  17799. + $c['padding']['L']
  17800. + $c['padding']['R']
  17801. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  17802. }
  17803. else {
  17804. $parentwidth -= ($this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  17805. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']) /2
  17806. + $c['padding']['L']
  17807. + $c['padding']['R'];
  17808. }
  17809. }
  17810. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  17811. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17812. }
  17813. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  17814. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'] ;
  17815. }
  17816. else {
  17817. $this->table[$lvl][$nid]['w'] = $parentwidth;
  17818. }
  17819. unset($c);
  17820. $this->_tableWidth($this->table[$lvl][$nid]);
  17821. }
  17822. }
  17823. // Starting at $this->innermostTableLevel
  17824. // Cascade back up nested tables: setting heights back up the tree
  17825. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  17826. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  17827. list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); }
  17828. }
  17829. // RESIZING ALGORITHM
  17830. if ($maxrowheight > $fullpage) { $recalculate = $this->tbsqrt($maxrowheight / $fullpage, $iteration); $iteration++; }
  17831. else if ($this->table_rotate && $tableheight > $remainingpage && !$added_page) {
  17832. // If can fit on remainder of page whilst respecting autosize value..
  17833. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17834. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  17835. }
  17836. else {
  17837. if (!$added_page) {
  17838. $this->AddPage($this->CurOrientation);
  17839. $added_page = true;
  17840. $this->kwt_moved = true;
  17841. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17842. }
  17843. // 0.001 to force it to recalculate
  17844. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17845. }
  17846. }
  17847. else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) {
  17848. if ($tableheight > $fullpage) {
  17849. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17850. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17851. }
  17852. else if ($this->tableMinSizePriority) {
  17853. $this->table_keep_together = false;
  17854. $recalculate = (1 / $this->shrin_k) + 0.001;
  17855. }
  17856. else {
  17857. if (!$added_page && $this->y != $this->tMargin) {
  17858. $this->AddPage($this->CurOrientation);
  17859. $added_page = true;
  17860. $this->kwt_moved = true;
  17861. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17862. }
  17863. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17864. }
  17865. }
  17866. else if ($tableheight > $remainingpage) {
  17867. // If can fit on remainder of page whilst respecting autosize value..
  17868. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  17869. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  17870. }
  17871. else {
  17872. if (!$added_page) {
  17873. $this->AddPage($this->CurOrientation);
  17874. $added_page = true;
  17875. $this->kwt_moved = true;
  17876. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  17877. }
  17878. //$recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  17879. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  17880. }
  17881. }
  17882. else { $recalculate = 1; }
  17883. }
  17884. else { $recalculate = 1; }
  17885. }
  17886. if ($maxfirstrowheight > $remainingpage && !$added_page && !$this->table_rotate && !$this->ColActive && !$this->table_keep_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  17887. $this->AddPage($this->CurOrientation);
  17888. $this->kwt_moved = true;
  17889. }
  17890. // keep-with-table: if page has advanced, print out buffer now, else done in fn. _Tablewrite()
  17891. if ($this->kwt_saved && $this->kwt_moved) {
  17892. $this->printkwtbuffer();
  17893. $this->kwt_moved = false;
  17894. $this->kwt_saved = false;
  17895. }
  17896. if ($this->progressBar) { $this->UpdateProgressBar(7,30,' '); } // *PROGRESS-BAR*
  17897. // Recursively writes all tables starting at top level
  17898. $this->_tableWrite($this->table[1][1]);
  17899. if ($this->table_rotate && $this->tablebuffer) {
  17900. $this->PageBreakTrigger=$this->h-$this->bMargin;
  17901. $save_tr = $this->table_rotate;
  17902. $save_y = $this->y;
  17903. $this->table_rotate = 0;
  17904. $this->y = $this->tbrot_y0;
  17905. $h = $this->tbrot_w;
  17906. $this->DivLn($h,$this->blklvl,true);
  17907. $this->table_rotate = $save_tr;
  17908. $this->y = $save_y;
  17909. $this->printtablebuffer();
  17910. }
  17911. $this->table_rotate = 0;
  17912. }
  17913. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17914. $this->maxPosR = max($this->maxPosR , ($this->x + $this->table[1][1]['w']));
  17915. $this->blockjustfinished=true;
  17916. $this->lastblockbottommargin = $this->table[1][1]['margin']['B'];
  17917. //Reset values
  17918. if (isset($this->table[1][1]['page_break_after'])) { $page_break_after = $this->table[1][1]['page_break_after']; }
  17919. else { $page_break_after = ''; }
  17920. // Keep-with-table
  17921. $this->kwt = false;
  17922. $this->kwt_y0 = 0;
  17923. $this->kwt_x0 = 0;
  17924. $this->kwt_height = 0;
  17925. $this->kwt_buffer = array();
  17926. $this->kwt_Links = array();
  17927. $this->kwt_Annots = array();
  17928. $this->kwt_moved = false;
  17929. $this->kwt_saved = false;
  17930. $this->kwt_Reference = array();
  17931. $this->kwt_BMoutlines = array();
  17932. $this->kwt_toc = array();
  17933. $this->shrin_k = 1;
  17934. $this->shrink_this_table_to_fit = 0;
  17935. unset($this->table);
  17936. $this->table=array(); //array
  17937. $this->tableLevel=0;
  17938. $this->tbctr=array();
  17939. $this->innermostTableLevel=0;
  17940. $this->tbCSSlvl = 0;
  17941. $this->tablecascadeCSS = array();
  17942. unset($this->cell);
  17943. $this->cell=array(); //array
  17944. $this->col=-1; //int
  17945. $this->row=-1; //int
  17946. $this->Reset();
  17947. $this->cellPaddingL = 0;
  17948. $this->cellPaddingT = 0;
  17949. $this->cellPaddingR = 0;
  17950. $this->cellPaddingB = 0;
  17951. $this->cMarginL = 0;
  17952. $this->cMarginT = 0;
  17953. $this->cMarginR = 0;
  17954. $this->cMarginB = 0;
  17955. $this->default_font_size = $this->original_default_font_size;
  17956. $this->default_font = $this->original_default_font;
  17957. $this->SetFontSize($this->default_font_size, false);
  17958. $this->SetFont($this->default_font,'',0,false);
  17959. $this->SetLineHeight();
  17960. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  17961. if ($this->progressBar) { $this->UpdateProgressBar(7,100,' '); } // *PROGRESS-BAR*
  17962. if ($page_break_after) {
  17963. $save_blklvl = $this->blklvl;
  17964. $save_blk = $this->blk;
  17965. $save_silp = $this->saveInlineProperties();
  17966. $save_spanlvl = $this->spanlvl;
  17967. $save_ilp = $this->InlineProperties;
  17968. if ($this->blklvl>1) {
  17969. // Close any open block tags
  17970. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  17971. // Output any text left in buffer
  17972. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  17973. }
  17974. /*-- COLUMNS --*/
  17975. $save_cols = false;
  17976. if ($this->ColActive) {
  17977. $save_cols = true;
  17978. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  17979. $this->SetColumns(0);
  17980. }
  17981. /*-- END COLUMNS --*/
  17982. if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17983. else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17984. else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  17985. if (!$this->restoreBlockPagebreaks) {
  17986. $this->blklvl = 0;
  17987. $this->lastblocklevelchange = 0;
  17988. $this->blk = array();
  17989. $this->initialiseBlock($this->blk[0]);
  17990. $this->blk[0]['width'] =& $this->pgwidth;
  17991. $this->blk[0]['inner_width'] =& $this->pgwidth;
  17992. $this->blk[0]['blockContext'] = $this->blockContext;
  17993. $properties = $this->MergeCSS('BLOCK','BODY','');
  17994. $this->setCSS($properties,'','BODY');
  17995. }
  17996. /*-- COLUMNS --*/
  17997. if ($save_cols) {
  17998. // Restore columns
  17999. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  18000. }
  18001. /*-- END COLUMNS --*/
  18002. if ($this->restoreBlockPagebreaks) {
  18003. $this->blk = $save_blk;
  18004. // Re-open block tags
  18005. $t = $this->blk[0]['tag'];
  18006. $a = $this->blk[0]['attr'];
  18007. $this->blklvl = 0;
  18008. for ($b=0; $b<=$save_blklvl;$b++) {
  18009. $tc = $t;
  18010. $ac = $a;
  18011. $t = $this->blk[$b+1]['tag'];
  18012. $a = $this->blk[$b+1]['attr'];
  18013. unset($this->blk[$b+1]);
  18014. $this->OpenTag($tc,$ac);
  18015. }
  18016. $this->spanlvl = $save_spanlvl;
  18017. $this->InlineProperties = $save_ilp;
  18018. $this->restoreInlineProperties($save_silp);
  18019. }
  18020. }
  18021. }
  18022. /*-- END TABLES --*/
  18023. /*-- LISTS --*/
  18024. // *********** LISTS ********************
  18025. if($tag=='LI') {
  18026. $this->lastoptionaltag = '';
  18027. unset($this->listcascadeCSS[$this->listCSSlvl]);
  18028. $this->listCSSlvl--;
  18029. 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]]); }
  18030. }
  18031. if(($tag=='UL') or ($tag=='OL')) {
  18032. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  18033. unset($this->listcascadeCSS[$this->listCSSlvl]);
  18034. $this->listCSSlvl--;
  18035. $this->lastoptionaltag = '';
  18036. /*-- TABLES --*/
  18037. // A simple list for inside a table
  18038. if($this->tableLevel) {
  18039. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  18040. unset($this->listlist[$this->listlvl]);
  18041. $this->listlvl--;
  18042. if (isset($this->listlist[$this->listlvl]['MAXNUM'])) { $this->listnum = $this->listlist[$this->listlvl]['MAXNUM']; } // restore previous levels
  18043. if ($this->listlvl == 0) { $this->listjustfinished = true; }
  18044. return;
  18045. }
  18046. /*-- END TABLES --*/
  18047. if ($this->listlvl > 1) { // returning one level
  18048. $this->listjustfinished=true;
  18049. if (!empty($this->textbuffer)) {
  18050. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  18051. }
  18052. else {
  18053. $this->listnum--;
  18054. }
  18055. $this->textbuffer = array();
  18056. $occur = $this->listoccur[$this->listlvl];
  18057. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  18058. $this->listlvl--;
  18059. $occur = $this->listoccur[$this->listlvl];
  18060. $this->listnum = $this->listlist[$this->listlvl][$occur]['MAXNUM']; // recover previous level's number
  18061. $this->listtype = $this->listlist[$this->listlvl][$occur]['TYPE']; // recover previous level's type
  18062. if ($this->InlineProperties['LIST'][$this->listlvl][$occur]) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$occur]); }
  18063. }
  18064. else { // We are closing the last OL/UL tag
  18065. if (!empty($this->textbuffer)) {
  18066. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  18067. }
  18068. else {
  18069. $this->listnum--;
  18070. }
  18071. $occur = $this->listoccur[$this->listlvl];
  18072. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum;
  18073. $this->textbuffer = array();
  18074. $this->listlvl--;
  18075. $this->printlistbuffer();
  18076. unset($this->InlineProperties['LIST']);
  18077. // SPACING AFTER LIST (Top level only)
  18078. $this->Ln(0);
  18079. if ($this->list_margin_bottom) {
  18080. $this->DivLn($this->list_margin_bottom,$this->blklvl,true,1); // collapsible
  18081. }
  18082. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  18083. $this->listjustfinished = true;
  18084. $this->listCSSlvl = 0;
  18085. $this->listcascadeCSS = array();
  18086. $this->blockjustfinished=true;
  18087. $this->lastblockbottommargin = $this->list_margin_bottom;
  18088. }
  18089. }
  18090. /*-- END LISTS --*/
  18091. }
  18092. /*-- TABLES --*/
  18093. // This function determines the shrink factor when resizing tables
  18094. // val is the table_height / page_height_available
  18095. // returns a scaling factor used as $shrin_k to resize the table
  18096. // Overcompensating will be quicker but may unnecessarily shrink table too much
  18097. // Undercompensating means it will reiterate more times (taking more processing time)
  18098. function tbsqrt($val, $iteration=3) {
  18099. $k = 4; // Alters number of iterations until it returns $val itself - Must be > 2
  18100. // Probably best guess and most accurate
  18101. if ($iteration==1) return sqrt($val);
  18102. // Faster than using sqrt (because it won't undercompensate), and gives reasonable results
  18103. //return 1+(($val-1)/2);
  18104. $x = 2-(($iteration-2)/($k-2));
  18105. if ($x == 0) { $ret = $val+0.00001; }
  18106. else if ($x < 0) { $ret = 1 + ( pow(2, ($iteration-2-$k))/1000 ); }
  18107. else { $ret = 1+(($val-1)/$x); }
  18108. return $ret;
  18109. }
  18110. /*-- END TABLES --*/
  18111. /*-- LISTS --*/
  18112. function printlistbuffer() {
  18113. //Save x coordinate
  18114. $x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  18115. $this->cMarginL = 0;
  18116. $this->cMarginR = 0;
  18117. $currIndentLvl = -1;
  18118. $lastIndent = array();
  18119. $bak_page = $this->page;
  18120. $indent = 0;
  18121. foreach($this->listitem as $item)
  18122. {
  18123. // COLS
  18124. $oldcolumn = $this->CurrCol;
  18125. $this->bulletarray = array();
  18126. //Get list's buffered data
  18127. $this->listlvl = $lvl = $item[0];
  18128. $num = $item[1];
  18129. $this->textbuffer = $item[2];
  18130. $occur = $item[3];
  18131. if ($item[4]) { $type = $item[4]; } // listitemtype
  18132. else { $type = $this->listlist[$lvl][$occur]['TYPE']; }
  18133. $maxnum = $this->listlist[$lvl][$occur]['MAXNUM'];
  18134. $this->restoreInlineProperties($this->InlineProperties['LIST'][$lvl][$occur]);
  18135. $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); // force to write
  18136. $clh = $this->FontSize;
  18137. $this->SetLineHeight($this->FontSizePt,$this->list_lineheight[$lvl][$occur]);
  18138. $this->listOcc = $occur;
  18139. $this->listnum = $num;
  18140. if (isset($this->list_align[$this->listlvl][$occur])) { $this->divalign = $this->list_align[$this->listlvl][$occur]; }
  18141. else {
  18142. if (isset($this->blk[$this->blklvl]['direction']) && $this->blk[$this->blklvl]['direction']=='rtl') { $this->divalign = 'R'; }
  18143. else { $this->divalign = 'L'; }
  18144. }
  18145. // Set the bullet fontsize
  18146. $bullfs = $this->InlineProperties['LISTITEM'][$lvl][$occur][$num]['size'];
  18147. $space_width = $this->GetCharWidth(' ',false) * 1.5;
  18148. //Set default width & height values
  18149. $this->divwidth = $this->blk[$this->blklvl]['inner_width'];
  18150. $this->divheight = $this->lineheight;
  18151. $typefont = $this->FontFamily;
  18152. if (preg_match('/U\+([a-fA-F0-9]+)/i',$type,$m)) {
  18153. if ($this->_charDefined($this->CurrentFont['cw'],hexdec($m[1]))) { $list_item_marker = codeHex2utf($m[1]); }
  18154. else { $list_item_marker = '-'; }
  18155. $blt_width = $this->GetStringWidth($list_item_marker);
  18156. $typefont = '';
  18157. if (preg_match('/rgb\(.*?\)/',$type,$m)) {
  18158. $list_item_color = $this->ConvertColor($m[0]);
  18159. }
  18160. }
  18161. else {
  18162. $list_item_color = false;
  18163. switch($type) //Format type
  18164. {
  18165. case '1':
  18166. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  18167. else { $list_item_marker = $num . $this->list_number_suffix; }
  18168. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  18169. break;
  18170. case 'none':
  18171. $list_item_marker = '';
  18172. $blt_width = 0;
  18173. break;
  18174. case 'A':
  18175. $anum = $this->dec2alpha($num,true);
  18176. $maxnum = $this->dec2alpha($maxnum,true);
  18177. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18178. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18179. $blt_width = $this->GetStringWidth(str_repeat('W',strlen($maxnum)).$this->list_number_suffix);
  18180. break;
  18181. case 'a':
  18182. $anum = $this->dec2alpha($num,false);
  18183. $maxnum = $this->dec2alpha($maxnum,false);
  18184. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18185. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18186. $blt_width = $this->GetStringWidth(str_repeat('m',strlen($maxnum)).$this->list_number_suffix);
  18187. break;
  18188. case 'I':
  18189. $anum = $this->dec2roman($num,true);
  18190. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18191. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18192. if ($maxnum>87) { $bbit = 87; }
  18193. else if ($maxnum>86) { $bbit = 86; }
  18194. else if ($maxnum>37) { $bbit = 38; }
  18195. else if ($maxnum>36) { $bbit = 37; }
  18196. else if ($maxnum>27) { $bbit = 28; }
  18197. else if ($maxnum>26) { $bbit = 27; }
  18198. else if ($maxnum>17) { $bbit = 18; }
  18199. else if ($maxnum>16) { $bbit = 17; }
  18200. else if ($maxnum>7) { $bbit = 8; }
  18201. else if ($maxnum>6) { $bbit = 7; }
  18202. else if ($maxnum>3) { $bbit = 4; }
  18203. else { $bbit = $maxnum; }
  18204. $maxlnum = $this->dec2roman($bbit,true);
  18205. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  18206. break;
  18207. case 'i':
  18208. $anum = $this->dec2roman($num,false);
  18209. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; }
  18210. else { $list_item_marker = $anum . $this->list_number_suffix; }
  18211. if ($maxnum>87) { $bbit = 87; }
  18212. else if ($maxnum>86) { $bbit = 86; }
  18213. else if ($maxnum>37) { $bbit = 38; }
  18214. else if ($maxnum>36) { $bbit = 37; }
  18215. else if ($maxnum>27) { $bbit = 28; }
  18216. else if ($maxnum>26) { $bbit = 27; }
  18217. else if ($maxnum>17) { $bbit = 18; }
  18218. else if ($maxnum>16) { $bbit = 17; }
  18219. else if ($maxnum>7) { $bbit = 8; }
  18220. else if ($maxnum>6) { $bbit = 7; }
  18221. else if ($maxnum>3) { $bbit = 4; }
  18222. else { $bbit = $maxnum; }
  18223. $maxlnum = $this->dec2roman($bbit,false);
  18224. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  18225. break;
  18226. case 'disc':
  18227. if ($this->PDFA || $this->PDFX) {
  18228. if ($this->_charDefined($this->CurrentFont['cw'],8226)) { $list_item_marker = "\xe2\x80\xa2"; } // &#8226;
  18229. else { $list_item_marker = '-'; }
  18230. $blt_width = $this->GetCharWidth($list_item_marker);
  18231. break;
  18232. }
  18233. $list_item_marker = chr(108); // bullet disc in Zapfdingbats 'l'
  18234. $typefont = 'czapfdingbats';
  18235. $blt_width = (0.791 * $this->FontSize/2.5);
  18236. break;
  18237. case 'circle':
  18238. if ($this->PDFA || $this->PDFX) {
  18239. if ($this->_charDefined($this->CurrentFont['cw'],9900)) { $list_item_marker = "\xe2\x9a\xac"; } // &#9900;
  18240. else { $list_item_marker = '-'; }
  18241. $blt_width = $this->GetCharWidth($list_item_marker);
  18242. break;
  18243. }
  18244. $list_item_marker = chr(109); // circle in Zapfdingbats 'm'
  18245. $typefont = 'czapfdingbats';
  18246. $blt_width = (0.873 * $this->FontSize/2.5);
  18247. break;
  18248. case 'square':
  18249. if ($this->PDFA || $this->PDFX) {
  18250. if ($this->_charDefined($this->CurrentFont['cw'],9642)) { $list_item_marker = "\xe2\x96\xaa"; } // &#9642;
  18251. else { $list_item_marker = '-'; }
  18252. $blt_width = $this->GetCharWidth($list_item_marker);
  18253. break;
  18254. }
  18255. $list_item_marker = chr(110); //black square in Zapfdingbats font 'n'
  18256. $typefont = 'czapfdingbats';
  18257. $blt_width = (0.761 * $this->FontSize/2.5);
  18258. break;
  18259. /* CSS3 list-styles numeric + I added tamil
  18260. arabic-indic | bengali | cambodian | devanagari | gujarati | gurmukhi | kannada | khmer | lao | malayalam | mongolian | myanmar | oriya | persian | telugu | tibetan | thai | urdu
  18261. */
  18262. case 'arabic-indic':
  18263. $cp = 0x0660;
  18264. $rnum = $this->dec2other($num, $cp);
  18265. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  18266. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18267. break;
  18268. case 'persian':
  18269. case 'urdu':
  18270. $cp = 0x06F0;
  18271. $rnum = $this->dec2other($num, $cp);
  18272. $list_item_marker = $this->list_number_suffix . $rnum; // RTL
  18273. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18274. break;
  18275. case 'bengali':
  18276. $cp = 0x09E6;
  18277. $rnum = $this->dec2other($num, $cp);
  18278. $list_item_marker = $rnum . $this->list_number_suffix;
  18279. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18280. break;
  18281. case 'devanagari':
  18282. $cp = 0x0966;
  18283. $rnum = $this->dec2other($num, $cp);
  18284. $list_item_marker = $rnum . $this->list_number_suffix;
  18285. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18286. break;
  18287. case 'gujarati':
  18288. $cp = 0x0AE6;
  18289. $rnum = $this->dec2other($num, $cp);
  18290. $list_item_marker = $rnum . $this->list_number_suffix;
  18291. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18292. break;
  18293. case 'gurmukhi':
  18294. $cp = 0x0A66;
  18295. $rnum = $this->dec2other($num, $cp);
  18296. $list_item_marker = $rnum . $this->list_number_suffix;
  18297. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18298. break;
  18299. case 'kannada':
  18300. $cp = 0x0CE6;
  18301. $rnum = $this->dec2other($num, $cp);
  18302. $list_item_marker = $rnum . $this->list_number_suffix;
  18303. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18304. break;
  18305. case 'malayalam':
  18306. $cp = 0x0D66;
  18307. $rnum = $this->dec2other($num, $cp);
  18308. $list_item_marker = $rnum . $this->list_number_suffix;
  18309. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(6, $cp),strlen($maxnum)).$this->list_number_suffix);
  18310. break;
  18311. case 'oriya':
  18312. $cp = 0x0B66;
  18313. $rnum = $this->dec2other($num, $cp);
  18314. $list_item_marker = $rnum . $this->list_number_suffix;
  18315. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18316. break;
  18317. case 'telugu':
  18318. $cp = 0x0C66;
  18319. $rnum = $this->dec2other($num, $cp);
  18320. $list_item_marker = $rnum . $this->list_number_suffix;
  18321. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix);
  18322. break;
  18323. case 'tamil':
  18324. $cp = 0x0BE6;
  18325. $rnum = $this->dec2other($num, $cp);
  18326. $list_item_marker = $rnum . $this->list_number_suffix;
  18327. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(9, $cp),strlen($maxnum)).$this->list_number_suffix);
  18328. break;
  18329. case 'thai':
  18330. $cp = 0x0E50;
  18331. $rnum = $this->dec2other($num, $cp);
  18332. $list_item_marker = $rnum . $this->list_number_suffix;
  18333. $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(5, $cp),strlen($maxnum)).$this->list_number_suffix);
  18334. break;
  18335. default:
  18336. if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; }
  18337. else { $list_item_marker = $num . $this->list_number_suffix; }
  18338. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  18339. break;
  18340. }
  18341. }
  18342. if (isset($item[5]) && $item[5]) { $list_item_marker = ''; }
  18343. if ($currIndentLvl < $lvl) {
  18344. if ($lvl > 1 || $this->list_indent_first_level) {
  18345. $indent += $this->list_indent[$lvl][$occur];
  18346. $lastIndent[$lvl] = $this->list_indent[$lvl][$occur];
  18347. }
  18348. }
  18349. else if ($currIndentLvl > $lvl) {
  18350. while ($currIndentLvl > $lvl) {
  18351. $indent -= $lastIndent[$currIndentLvl];
  18352. $currIndentLvl--;
  18353. }
  18354. }
  18355. $currIndentLvl = $lvl;
  18356. /*-- RTL --*/
  18357. if ($this->listDir == 'rtl') {
  18358. // list_align_style Determines alignment of numbers in numbered lists
  18359. if ($this->list_align_style == 'L') { $lalign = 'R'; }
  18360. else { $lalign = 'L'; }
  18361. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  18362. $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)
  18363. //Output bullet
  18364. $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 );
  18365. $this->x = $x;
  18366. }
  18367. else {
  18368. /*-- END RTL --*/
  18369. if ($this->list_align_style == 'L') { $lalign = 'L'; }
  18370. else { $lalign = 'R'; }
  18371. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  18372. $xb = $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] - $blt_width - $space_width;
  18373. //Output bullet
  18374. $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 );
  18375. $this->x = $x + $indent + $blt_width + $space_width;
  18376. } // *RTL*
  18377. //Print content
  18378. $this->printbuffer($this->textbuffer,'',false,true);
  18379. $this->textbuffer=array();
  18380. // Added to correct for OddEven Margins
  18381. if ($this->page != $bak_page) {
  18382. if (($this->page-$bak_page) % 2 == 1) {
  18383. $x += $this->MarginCorrection;
  18384. }
  18385. $bak_page = $this->page;
  18386. }
  18387. /*-- COLUMNS --*/
  18388. // OR COLUMN CHANGE
  18389. if ($this->CurrCol != $oldcolumn) {
  18390. if ($this->directionality == 'rtl') { // *RTL*
  18391. $x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18392. } // *RTL*
  18393. else { // *RTL*
  18394. $x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18395. } // *RTL*
  18396. $oldcolumn = $this->CurrCol;
  18397. }
  18398. /*-- END COLUMNS --*/
  18399. }
  18400. //Reset all used values
  18401. $this->listoccur = array();
  18402. $this->listitem = array();
  18403. $this->listlist = array();
  18404. $this->listlvl = 0;
  18405. $this->listnum = 0;
  18406. $this->listtype = '';
  18407. $this->textbuffer = array();
  18408. $this->divwidth = 0;
  18409. $this->divheight = 0;
  18410. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  18411. }
  18412. /*-- END LISTS --*/
  18413. function _saveTextBuffer($t, $link = '', $intlink = '') {
  18414. $this->textbuffer[] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow);
  18415. }
  18416. function _saveCellTextBuffer($t, $link = '', $intlink = '') {
  18417. $this->cell[$this->row][$this->col]['textbuffer'][] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow);
  18418. }
  18419. function printbuffer($arrayaux,$blockstate=0,$is_table=false,$is_list=false)
  18420. {
  18421. // $blockstate = 0; // NO margins/padding
  18422. // $blockstate = 1; // Top margins/padding only
  18423. // $blockstate = 2; // Bottom margins/padding only
  18424. // $blockstate = 3; // Top & bottom margins/padding
  18425. $this->spanbgcolorarray = '';
  18426. $this->spanbgcolor = false;
  18427. $this->spanborder = false;
  18428. $this->spanborddet = array();
  18429. $paint_ht_corr = 0;
  18430. /*-- CSS-FLOAT --*/
  18431. if (count($this->floatDivs)) {
  18432. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  18433. if (($this->blk[$this->blklvl]['inner_width']-$l_width-$r_width) < (2*$this->GetCharWidth('W',false))) {
  18434. // Too narrow to fit - try to move down past L or R float
  18435. if ($l_max < $r_max && ($this->blk[$this->blklvl]['inner_width']-$r_width) > (2*$this->GetCharWidth('W',false))) {
  18436. $this->ClearFloats('LEFT', $this->blklvl);
  18437. }
  18438. else if ($r_max < $l_max && ($this->blk[$this->blklvl]['inner_width']-$l_width) > (2*$this->GetCharWidth('W',false))) {
  18439. $this->ClearFloats('RIGHT', $this->blklvl);
  18440. }
  18441. else { $this->ClearFloats('BOTH', $this->blklvl); }
  18442. }
  18443. }
  18444. /*-- END CSS-FLOAT --*/
  18445. $bak_y = $this->y;
  18446. $bak_x = $this->x;
  18447. $align = '';
  18448. if (!$is_table && !$is_list) {
  18449. if (isset($this->blk[$this->blklvl]['align']) && $this->blk[$this->blklvl]['align']) { $align = $this->blk[$this->blklvl]['align']; }
  18450. // Block-align is set by e.g. <.. align="center"> Takes priority for this block but not inherited
  18451. if (isset($this->blk[$this->blklvl]['block-align']) && $this->blk[$this->blklvl]['block-align']) { $align = $this->blk[$this->blklvl]['block-align']; }
  18452. if (isset($this->blk[$this->blklvl]['direction'])) $blockdir = $this->blk[$this->blklvl]['direction'];
  18453. else $blockdir = "";
  18454. $this->divwidth = $this->blk[$this->blklvl]['width'];
  18455. }
  18456. else {
  18457. $align = $this->divalign;
  18458. if ($is_table) { $blockdir = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']; }
  18459. else { $blockdir = $this->listDir; }
  18460. }
  18461. $oldpage = $this->page;
  18462. // ADDED for Out of Block now done as Flowing Block
  18463. if ($this->divwidth == 0) {
  18464. $this->divwidth = $this->pgwidth;
  18465. }
  18466. if (!$is_table && !$is_list) { $this->SetLineHeight($this->FontSizePt,$this->blk[$this->blklvl]['line_height']); }
  18467. $this->divheight = $this->lineheight;
  18468. $old_height = $this->divheight;
  18469. // As a failsafe - if font has been set but not output to page
  18470. $this->SetFont($this->default_font,'',$this->default_font_size,true,true); // force output to page
  18471. $array_size = count($arrayaux);
  18472. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,true,$blockdir);
  18473. // Added - Otherwise <div><div><p> did not output top margins/padding for 1st/2nd div
  18474. if ($array_size == 0) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18475. for($i=0;$i < $array_size; $i++)
  18476. {
  18477. // COLS
  18478. $oldcolumn = $this->CurrCol;
  18479. $vetor = $arrayaux[$i];
  18480. if ($i == 0 and $vetor[0] != "\n" and !$this->ispre) {
  18481. $vetor[0] = ltrim($vetor[0]);
  18482. }
  18483. // FIXED TO ALLOW IT TO SHOW '0'
  18484. if (empty($vetor[0]) && !($vetor[0]==='0') && empty($vetor[7])) { //Ignore empty text and not carrying an internal link
  18485. //Check if it is the last element. If so then finish printing the block
  18486. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18487. continue;
  18488. }
  18489. //Activating buffer properties
  18490. if(isset($vetor[11]) and $vetor[11] != '') { // Font Size
  18491. if ($is_table && $this->shrin_k) {
  18492. $this->SetFontSize($vetor[11]/$this->shrin_k,false);
  18493. }
  18494. else {
  18495. $this->SetFontSize($vetor[11],false);
  18496. }
  18497. }
  18498. if(isset($vetor[17]) && !empty($vetor[17])) { //TextShadow
  18499. $this->textshadow = $vetor[17];
  18500. }
  18501. if(isset($vetor[16]) && !empty($vetor[16])) { //Border
  18502. $this->spanborddet = $vetor[16];
  18503. $this->spanborder = true;
  18504. }
  18505. if(isset($vetor[15])) { // Word spacing
  18506. $this->wSpacingCSS = $vetor[15];
  18507. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  18508. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  18509. }
  18510. }
  18511. if(isset($vetor[14])) { // Letter spacing
  18512. $this->lSpacingCSS = $vetor[14];
  18513. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  18514. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  18515. }
  18516. }
  18517. if(isset($vetor[13])) { // Font Kerning
  18518. $this->kerning = $vetor[13];
  18519. }
  18520. if(isset($vetor[10]) and !empty($vetor[10])) //Background color
  18521. {
  18522. $this->spanbgcolorarray = $vetor[10];
  18523. $this->spanbgcolor = true;
  18524. }
  18525. if(isset($vetor[9]) and !empty($vetor[9])) // Outline parameters
  18526. {
  18527. $cor = $vetor[9]['COLOR'];
  18528. $outlinewidth = $vetor[9]['WIDTH'];
  18529. $this->SetTextOutline($outlinewidth,$cor);
  18530. $this->outline_on = true;
  18531. }
  18532. if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text
  18533. {
  18534. $this->strike = true;
  18535. }
  18536. if(isset($vetor[7]) and $vetor[7] != '') // internal link: <a name="anyvalue">
  18537. {
  18538. $ily = $this->y;
  18539. if ($this->keep_block_together) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kt"=>true ); }
  18540. else if ($this->table_rotate) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "tbrot"=>true ); }
  18541. else if ($this->kwt) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kwt"=>true ); }
  18542. else if ($this->ColActive) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "col"=>$this->CurrCol ); }
  18543. else
  18544. $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page );
  18545. if (empty($vetor[0])) { //Ignore empty text
  18546. //Check if it is the last element. If so then finish printing the block
  18547. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  18548. continue;
  18549. }
  18550. }
  18551. if(isset($vetor[6]) and $vetor[6] === true) // Subscript
  18552. {
  18553. $this->SUB = true;
  18554. }
  18555. if(isset($vetor[5]) and $vetor[5] === true) // Superscript
  18556. {
  18557. $this->SUP = true;
  18558. }
  18559. if(isset($vetor[4]) and $vetor[4] != '') { // Font Family
  18560. $font = $this->SetFont($vetor[4],$this->FontStyle,0,false);
  18561. }
  18562. if (!empty($vetor[3])) //Font Color
  18563. {
  18564. $cor = $vetor[3];
  18565. $this->SetTColor($cor);
  18566. }
  18567. if(isset($vetor[2]) and $vetor[2] != '') //Bold,Italic,Underline styles
  18568. {
  18569. $this->SetStyles($vetor[2]);
  18570. }
  18571. if(isset($vetor[12]) and $vetor[12] != '') { //Requested Bold,Italic,Underline
  18572. $this->ReqFontStyle = $vetor[12];
  18573. }
  18574. if(isset($vetor[1]) and $vetor[1] != '') //LINK
  18575. {
  18576. 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.)
  18577. {
  18578. //Repeated reference to same anchor?
  18579. while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
  18580. $this->internallink[$vetor[1]] = $this->AddLink();
  18581. $vetor[1] = $this->internallink[$vetor[1]];
  18582. }
  18583. $this->HREF = $vetor[1]; // HREF link style set here ******
  18584. }
  18585. // SPECIAL CONTENT - IMAGES & FORM OBJECTS
  18586. //Print-out special content
  18587. if (substr($vetor[0],0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  18588. $objattr = $this->_getObjAttr($vetor[0]);
  18589. /*-- TABLES --*/
  18590. if ($objattr['type'] == 'nestedtable') {
  18591. if ($objattr['nestedcontent']) {
  18592. $level = $objattr['level'];
  18593. $table = &$this->table[$level][$objattr['table']];
  18594. if ($this->cacheTables) {
  18595. $fh = fopen($table['cache'], "r+b");
  18596. $cell = $this->_uncacheCell($table['cells'][$objattr['row']][$objattr['col']], '', $fh);
  18597. }
  18598. else {
  18599. $fh = null;
  18600. $cell = &$table['cells'][$objattr['row']][$objattr['col']];
  18601. }
  18602. $this->finishFlowingBlock(false,'nestedtable');
  18603. $save_dw = $this->divwidth ;
  18604. $save_buffer = $this->cellBorderBuffer;
  18605. $this->cellBorderBuffer = array();
  18606. $ncx = $this->x;
  18607. list($dummyx,$w) = $this->_tableGetWidth($table, $objattr['row'], $objattr['col'], $fh);
  18608. $ntw = $this->table[($level+1)][$objattr['nestedcontent']]['w']; // nested table width
  18609. if (!$this->simpleTables){
  18610. if ($this->packTableData) {
  18611. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cell['borderbin']);
  18612. }
  18613. else {
  18614. $br = $cell['border_details']['R']['w'];
  18615. $bl = $cell['border_details']['L']['w'];
  18616. }
  18617. if ($table['borders_separate']) {
  18618. $innerw = $w - $bl - $br - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18619. }
  18620. else {
  18621. $innerw = $w - $bl/2 - $br/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18622. }
  18623. }
  18624. else if ($this->simpleTables){
  18625. if ($table['borders_separate']) {
  18626. $innerw = $w - $table['simple']['border_details']['L']['w'] - $table['simple']['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  18627. }
  18628. else {
  18629. $innerw = $w - $table['simple']['border_details']['L']['w']/2 - $table['simple']['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R'];
  18630. }
  18631. }
  18632. if ($cell['a']=='C' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='C') {
  18633. $ncx += ($innerw-$ntw)/2;
  18634. }
  18635. elseif ($cell['a']=='R' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='R') {
  18636. $ncx += $innerw- $ntw;
  18637. }
  18638. $this->x = $ncx ;
  18639. if ($this->cacheTables) { fclose($fh); }
  18640. $this->_tableWrite($this->table[($level+1)][$objattr['nestedcontent']]);
  18641. $this->cellBorderBuffer = $save_buffer;
  18642. $this->x = $bak_x ;
  18643. $this->divwidth = $save_dw;
  18644. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18645. }
  18646. }
  18647. else {
  18648. /*-- END TABLES --*/
  18649. if ($is_table) { // *TABLES*
  18650. $maxWidth = $this->divwidth; // *TABLES*
  18651. } // *TABLES*
  18652. else { // *TABLES*
  18653. $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']);
  18654. } // *TABLES*
  18655. /*-- CSS-IMAGE-FLOAT --*/
  18656. // If float (already) exists at this level
  18657. if (isset($this->floatmargins['R']) && $this->y <= $this->floatmargins['R']['y1'] && $this->y >= $this->floatmargins['R']['y0']) { $maxWidth -= $this->floatmargins['R']['w']; }
  18658. if (isset($this->floatmargins['L']) && $this->y <= $this->floatmargins['L']['y1'] && $this->y >= $this->floatmargins['L']['y0']) { $maxWidth -= $this->floatmargins['L']['w']; }
  18659. /*-- END CSS-IMAGE-FLOAT --*/
  18660. list($skipln) = $this->inlineObject($objattr['type'], '', $this->y, $objattr,$this->lMargin, ($this->flowingBlockAttr['contentWidth']/_MPDFK), $maxWidth, $this->flowingBlockAttr['height'], false, $is_table);
  18661. // 1 -> New line needed because of width
  18662. // -1 -> Will fit width on line but NEW PAGE REQUIRED because of height
  18663. // -2 -> Will not fit on line therefore needs new line but thus NEW PAGE REQUIRED
  18664. $iby = $this->y;
  18665. $oldpage = $this->page;
  18666. $oldcol = $this->CurrCol;
  18667. if (($skipln == 1 || $skipln == -2) && !isset($objattr['float'])) {
  18668. $this->finishFlowingBlock(false,$objattr['type']);
  18669. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18670. }
  18671. $thispage = $this->page;
  18672. if ($this->CurrCol!=$oldcol) { $changedcol = true; }
  18673. else { $changedcol=false; }
  18674. // the previous lines can already have triggered page break or column change
  18675. if (!$changedcol && $skipln <0 && $this->AcceptPageBreak() && $thispage==$oldpage) {
  18676. $this->AddPage($this->CurOrientation);
  18677. // Added to correct Images already set on line before page advanced
  18678. // i.e. if second inline image on line is higher than first and forces new page
  18679. if (count($this->objectbuffer)) {
  18680. $yadj = $iby - $this->y;
  18681. foreach($this->objectbuffer AS $ib=>$val) {
  18682. if ($this->objectbuffer[$ib]['OUTER-Y'] ) $this->objectbuffer[$ib]['OUTER-Y'] -= $yadj;
  18683. if ($this->objectbuffer[$ib]['BORDER-Y']) $this->objectbuffer[$ib]['BORDER-Y'] -= $yadj;
  18684. if ($this->objectbuffer[$ib]['INNER-Y']) $this->objectbuffer[$ib]['INNER-Y'] -= $yadj;
  18685. }
  18686. }
  18687. }
  18688. // Added to correct for OddEven Margins
  18689. if ($this->page != $oldpage) {
  18690. if (($this->page-$oldpage) % 2 == 1) {
  18691. $bak_x += $this->MarginCorrection;
  18692. }
  18693. $oldpage = $this->page;
  18694. $y = $this->tMargin - $paint_ht_corr ;
  18695. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18696. $old_height = 0;
  18697. }
  18698. $this->x = $bak_x;
  18699. /*-- COLUMNS --*/
  18700. // COLS
  18701. // OR COLUMN CHANGE
  18702. if ($this->CurrCol != $oldcolumn) {
  18703. if ($this->directionality == 'rtl') { // *RTL*
  18704. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18705. } // *RTL*
  18706. else { // *RTL*
  18707. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18708. } // *RTL*
  18709. $this->x = $bak_x;
  18710. $oldcolumn = $this->CurrCol;
  18711. $y = $this->y0 - $paint_ht_corr ;
  18712. $this->oldy = $this->y0 - $paint_ht_corr ;
  18713. $old_height = 0;
  18714. }
  18715. /*-- END COLUMNS --*/
  18716. /*-- CSS-IMAGE-FLOAT --*/
  18717. if ($objattr['type'] == 'image' && isset($objattr['float'])) {
  18718. $fy = $this->y;
  18719. // DIV TOP MARGIN/BORDER/PADDING
  18720. if ($this->flowingBlockAttr['newblock'] && ($this->flowingBlockAttr['blockstate']==1 || $this->flowingBlockAttr['blockstate']==3) && $this->flowingBlockAttr['lineCount']== 0) {
  18721. $fy += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  18722. }
  18723. if ($objattr['float']=='R') {
  18724. $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']);
  18725. }
  18726. else if ($objattr['float']=='L') {
  18727. $fx = $this->lMargin + ($this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left']);
  18728. }
  18729. $w = $objattr['width'];
  18730. $h = abs($objattr['height']);
  18731. $widthLeft = $maxWidth - ($this->flowingBlockAttr['contentWidth']/_MPDFK);
  18732. $maxHeight = $this->h - ($this->tMargin + $this->margin_header + $this->bMargin + 10) ;
  18733. // For Images
  18734. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right']);
  18735. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom']);
  18736. if ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg') {
  18737. $file = $objattr['file'];
  18738. $info=$this->formobjects[$file];
  18739. }
  18740. else {
  18741. $file = $objattr['file'];
  18742. $info=$this->images[$file];
  18743. }
  18744. $img_w = $w - $extraWidth ;
  18745. $img_h = $h - $extraHeight ;
  18746. if ($objattr['border_left']['w']) {
  18747. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w'] + $objattr['border_right']['w'])/2) ;
  18748. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w'] + $objattr['border_bottom']['w'])/2) ;
  18749. $objattr['BORDER-X'] = $fx + $objattr['margin_left'] + (($objattr['border_left']['w'])/2) ;
  18750. $objattr['BORDER-Y'] = $fy + $objattr['margin_top'] + (($objattr['border_top']['w'])/2) ;
  18751. }
  18752. $objattr['INNER-WIDTH'] = $img_w;
  18753. $objattr['INNER-HEIGHT'] = $img_h;
  18754. $objattr['INNER-X'] = $fx + $objattr['margin_left'] + ($objattr['border_left']['w']);
  18755. $objattr['INNER-Y'] = $fy + $objattr['margin_top'] + ($objattr['border_top']['w']) ;
  18756. $objattr['ID'] = $info['i'];
  18757. $objattr['OUTER-WIDTH'] = $w;
  18758. $objattr['OUTER-HEIGHT'] = $h;
  18759. $objattr['OUTER-X'] = $fx;
  18760. $objattr['OUTER-Y'] = $fy;
  18761. if ($objattr['float']=='R') {
  18762. // If R float already exists at this level
  18763. $this->floatmargins['R']['skipline'] = false;
  18764. if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  18765. $this->WriteFlowingBlock($vetor[0]);
  18766. }
  18767. // If L float already exists at this level
  18768. else if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  18769. // Final check distance between floats is not now too narrow to fit text
  18770. $mw = 2*$this->GetCharWidth('W',false);
  18771. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['L']['w']) < $mw) {
  18772. $this->WriteFlowingBlock($vetor[0]);
  18773. }
  18774. else {
  18775. $this->floatmargins['R']['x'] = $fx;
  18776. $this->floatmargins['R']['w'] = $w;
  18777. $this->floatmargins['R']['y0'] = $fy;
  18778. $this->floatmargins['R']['y1'] = $fy + $h;
  18779. if ($skipln == 1) {
  18780. $this->floatmargins['R']['skipline'] = true;
  18781. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  18782. $objattr['skipline'] = true;
  18783. }
  18784. $this->floatbuffer[] = $objattr;
  18785. }
  18786. }
  18787. else {
  18788. $this->floatmargins['R']['x'] = $fx;
  18789. $this->floatmargins['R']['w'] = $w;
  18790. $this->floatmargins['R']['y0'] = $fy;
  18791. $this->floatmargins['R']['y1'] = $fy + $h;
  18792. if ($skipln == 1) {
  18793. $this->floatmargins['R']['skipline'] = true;
  18794. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  18795. $objattr['skipline'] = true;
  18796. }
  18797. $this->floatbuffer[] = $objattr;
  18798. }
  18799. }
  18800. else if ($objattr['float']=='L') {
  18801. // If L float already exists at this level
  18802. $this->floatmargins['L']['skipline'] = false;
  18803. if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  18804. $this->floatmargins['L']['skipline'] = false;
  18805. $this->WriteFlowingBlock($vetor[0]);
  18806. }
  18807. // If R float already exists at this level
  18808. else if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  18809. // Final check distance between floats is not now too narrow to fit text
  18810. $mw = 2*$this->GetCharWidth('W',false);
  18811. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['R']['w']) < $mw) {
  18812. $this->WriteFlowingBlock($vetor[0]);
  18813. }
  18814. else {
  18815. $this->floatmargins['L']['x'] = $fx + $w;
  18816. $this->floatmargins['L']['w'] = $w;
  18817. $this->floatmargins['L']['y0'] = $fy;
  18818. $this->floatmargins['L']['y1'] = $fy + $h;
  18819. if ($skipln == 1) {
  18820. $this->floatmargins['L']['skipline'] = true;
  18821. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  18822. $objattr['skipline'] = true;
  18823. }
  18824. $this->floatbuffer[] = $objattr;
  18825. }
  18826. }
  18827. else {
  18828. $this->floatmargins['L']['x'] = $fx + $w;
  18829. $this->floatmargins['L']['w'] = $w;
  18830. $this->floatmargins['L']['y0'] = $fy;
  18831. $this->floatmargins['L']['y1'] = $fy + $h;
  18832. if ($skipln == 1) {
  18833. $this->floatmargins['L']['skipline'] = true;
  18834. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  18835. $objattr['skipline'] = true;
  18836. }
  18837. $this->floatbuffer[] = $objattr;
  18838. }
  18839. }
  18840. }
  18841. else {
  18842. /*-- END CSS-IMAGE-FLOAT --*/
  18843. $this->WriteFlowingBlock($vetor[0]);
  18844. /*-- CSS-IMAGE-FLOAT --*/
  18845. }
  18846. /*-- END CSS-IMAGE-FLOAT --*/
  18847. } // *TABLES*
  18848. } // END If special content
  18849. else { //THE text
  18850. if ($this->tableLevel) { $paint_ht_corr = 0; } // To move the y up when new column/page started if div border needed
  18851. else { $paint_ht_corr = $this->blk[$this->blklvl]['border_top']['w']; }
  18852. if ($vetor[0] == "\n") { //We are reading a <BR> now turned into newline ("\n")
  18853. if ($this->flowingBlockAttr['content']) {
  18854. $this->finishFlowingBlock(false,'br');
  18855. }
  18856. else if ($is_table) {
  18857. $this->y+= $this->_computeLineheight($this->table_lineheight);
  18858. }
  18859. else if (!$is_table) {
  18860. $this->DivLn($this->lineheight);
  18861. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  18862. }
  18863. // Added to correct for OddEven Margins
  18864. if ($this->page != $oldpage) {
  18865. if (($this->page-$oldpage) % 2 == 1) {
  18866. $bak_x += $this->MarginCorrection;
  18867. }
  18868. $oldpage = $this->page;
  18869. $y = $this->tMargin - $paint_ht_corr ;
  18870. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18871. $old_height = 0;
  18872. }
  18873. $this->x = $bak_x;
  18874. /*-- COLUMNS --*/
  18875. // COLS
  18876. // OR COLUMN CHANGE
  18877. if ($this->CurrCol != $oldcolumn) {
  18878. if ($this->directionality == 'rtl') { // *RTL*
  18879. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18880. } // *RTL*
  18881. else { // *RTL*
  18882. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18883. } // *RTL*
  18884. $this->x = $bak_x;
  18885. $oldcolumn = $this->CurrCol;
  18886. $y = $this->y0 - $paint_ht_corr ;
  18887. $this->oldy = $this->y0 - $paint_ht_corr ;
  18888. $old_height = 0;
  18889. }
  18890. /*-- END COLUMNS --*/
  18891. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir);
  18892. }
  18893. else {
  18894. $this->WriteFlowingBlock( $vetor[0]);
  18895. // Added to correct for OddEven Margins
  18896. if ($this->page != $oldpage) {
  18897. if (($this->page-$oldpage) % 2 == 1) {
  18898. $bak_x += $this->MarginCorrection;
  18899. $this->x = $bak_x;
  18900. }
  18901. $oldpage = $this->page;
  18902. $y = $this->tMargin - $paint_ht_corr ;
  18903. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18904. $old_height = 0;
  18905. }
  18906. /*-- COLUMNS --*/
  18907. // COLS
  18908. // OR COLUMN CHANGE
  18909. if ($this->CurrCol != $oldcolumn) {
  18910. if ($this->directionality == 'rtl') { // *RTL*
  18911. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18912. } // *RTL*
  18913. else { // *RTL*
  18914. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18915. } // *RTL*
  18916. $this->x = $bak_x;
  18917. $oldcolumn = $this->CurrCol;
  18918. $y = $this->y0 - $paint_ht_corr ;
  18919. $this->oldy = $this->y0 - $paint_ht_corr ;
  18920. $old_height = 0;
  18921. }
  18922. /*-- END COLUMNS --*/
  18923. }
  18924. }
  18925. //Check if it is the last element. If so then finish printing the block
  18926. if ($i == ($array_size-1)) {
  18927. $this->finishFlowingBlock(true); // true = END of flowing block
  18928. // Added to correct for OddEven Margins
  18929. if ($this->page != $oldpage) {
  18930. if (($this->page-$oldpage) % 2 == 1) {
  18931. $bak_x += $this->MarginCorrection;
  18932. $this->x = $bak_x;
  18933. }
  18934. $oldpage = $this->page;
  18935. $y = $this->tMargin - $paint_ht_corr ;
  18936. $this->oldy = $this->tMargin - $paint_ht_corr ;
  18937. $old_height = 0;
  18938. }
  18939. /*-- COLUMNS --*/
  18940. // COLS
  18941. // OR COLUMN CHANGE
  18942. if ($this->CurrCol != $oldcolumn) {
  18943. if ($this->directionality == 'rtl') { // *RTL*
  18944. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  18945. } // *RTL*
  18946. else { // *RTL*
  18947. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  18948. } // *RTL*
  18949. $this->x = $bak_x;
  18950. $oldcolumn = $this->CurrCol;
  18951. $y = $this->y0 - $paint_ht_corr ;
  18952. $this->oldy = $this->y0 - $paint_ht_corr ;
  18953. $old_height = 0;
  18954. }
  18955. /*-- END COLUMNS --*/
  18956. }
  18957. // RESETTING VALUES
  18958. $this->SetTColor($this->ConvertColor(0));
  18959. $this->SetDColor($this->ConvertColor(0));
  18960. $this->SetFColor($this->ConvertColor(255));
  18961. $this->colorarray = '';
  18962. $this->spanbgcolorarray = '';
  18963. $this->spanbgcolor = false;
  18964. $this->spanborder = false;
  18965. $this->spanborddet = array();
  18966. $this->HREF = '';
  18967. $this->outlineparam = array();
  18968. $this->SetTextOutline(false);
  18969. $this->outline_on = false;
  18970. $this->SUP = false;
  18971. $this->SUB = false;
  18972. $this->strike = false;
  18973. $this->textshadow = '';
  18974. $this->currentfontfamily = '';
  18975. $this->currentfontsize = '';
  18976. $this->currentfontstyle = '';
  18977. /*-- TABLES --*/
  18978. if ($this->tableLevel) {
  18979. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  18980. }
  18981. else
  18982. /*-- END TABLES --*/
  18983. /*-- LISTS --*/
  18984. if ($is_list && $this->list_lineheight[$this->listlvl][$this->listOcc]) {
  18985. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->listOcc]); // sets default line height
  18986. }
  18987. else
  18988. /*-- END LISTS --*/
  18989. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  18990. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  18991. }
  18992. $this->ResetStyles();
  18993. $this->toupper = false;
  18994. $this->tolower = false;
  18995. $this->capitalize = false;
  18996. $this->kerning = false;
  18997. $this->lSpacingCSS = '';
  18998. $this->wSpacingCSS = '';
  18999. $this->fixedlSpacing = false;
  19000. $this->minwSpacing = 0;
  19001. $this->SetDash();
  19002. $this->dash_on = false;
  19003. $this->dotted_on = false;
  19004. }//end of for(i=0;i<arraysize;i++)
  19005. // PAINT DIV BORDER // DISABLED IN COLUMNS AS DOESN'T WORK WHEN BROKEN ACROSS COLS??
  19006. 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)) {
  19007. $bottom_y = $this->y; // Does not include Bottom Margin
  19008. if (isset($this->blk[$this->blklvl]['startpage']) && $this->blk[$this->blklvl]['startpage'] != $this->page && $blockstate != 1) {
  19009. $this->PaintDivBB('pagetop',$blockstate);
  19010. }
  19011. else if ($blockstate != 1) {
  19012. $this->PaintDivBB('',$blockstate);
  19013. }
  19014. $this->y = $bottom_y;
  19015. $this->x = $bak_x;
  19016. }
  19017. // Reset Font
  19018. $this->SetFontSize($this->default_font_size,false);
  19019. }
  19020. function _setDashBorder($style, $div, $cp, $side) {
  19021. if ($style == 'dashed' && (($side=='L' || $side=='R') || ($side=='T' && $div != 'pagetop' && !$cp) || ($side=='B' && $div!='pagebottom') )) {
  19022. $dashsize = 2; // final dash will be this + 1*linewidth
  19023. $dashsizek = 1.5; // ratio of Dash/Blank
  19024. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  19025. }
  19026. else if ($style == 'dotted' || ($side=='T' && ($div == 'pagetop' || $cp)) || ($side=='B' && $div == 'pagebottom')) {
  19027. //Round join and cap
  19028. $this->SetLineJoin(1);
  19029. $this->SetLineCap(1);
  19030. $this->SetDash(0.001,($this->LineWidth*3));
  19031. }
  19032. }
  19033. function _setBorderLine($b, $k=1) {
  19034. $this->SetLineWidth($b['w']/$k);
  19035. $this->SetDColor($b['c']);
  19036. if ($b['c'][0]==5) { // RGBa
  19037. $this->SetAlpha($b['c'][4], 'Normal', false, 'S')."\n";
  19038. }
  19039. else if ($b['c'][0]==6) { // CMYKa
  19040. $this->SetAlpha($b['c'][5], 'Normal', false, 'S')."\n";
  19041. }
  19042. }
  19043. function PaintDivBB($divider='',$blockstate=0,$blvl=0) {
  19044. // Borders & backgrounds are done elsewhere for columns - messes up the repositioning in printcolumnbuffer
  19045. if ($this->ColActive) { return ; } // *COLUMNS*
  19046. $save_y = $this->y;
  19047. if (!$blvl) { $blvl = $this->blklvl; }
  19048. $x0 = $x1 = $y0 = $y1 = 0;
  19049. // Added mPDF 3.0 Float DIV
  19050. if (isset($this->blk[$blvl]['bb_painted'][$this->page]) && $this->blk[$blvl]['bb_painted'][$this->page]) { return; } // *CSS-FLOAT*
  19051. if (isset($this->blk[$blvl]['x0'])) { $x0 = $this->blk[$blvl]['x0']; } // left
  19052. if (isset($this->blk[$blvl]['y1'])) { $y1 = $this->blk[$blvl]['y1']; } // bottom
  19053. // Added mPDF 3.0 Float DIV - ensures backgrounds/borders are drawn to bottom of page
  19054. if ($y1==0) {
  19055. if ($divider=='pagebottom') { $y1 = $this->h-$this->bMargin; }
  19056. else { $y1 = $this->y; }
  19057. }
  19058. if (isset($this->blk[$blvl]['startpage']) && $this->blk[$blvl]['startpage'] != $this->page) { $continuingpage = true; } else { $continuingpage = false; }
  19059. if (isset($this->blk[$blvl]['y0'])) { $y0 = $this->blk[$blvl]['y0']; }
  19060. $h = $y1 - $y0;
  19061. $w = $this->blk[$blvl]['width'];
  19062. $x1 = $x0 + $w;
  19063. // Set border-widths as used here
  19064. $border_top = $this->blk[$blvl]['border_top']['w'];
  19065. $border_bottom = $this->blk[$blvl]['border_bottom']['w'];
  19066. $border_left = $this->blk[$blvl]['border_left']['w'];
  19067. $border_right = $this->blk[$blvl]['border_right']['w'];
  19068. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) {
  19069. $border_top = 0;
  19070. }
  19071. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') {
  19072. $border_bottom = 0;
  19073. }
  19074. $brTL_H = 0;
  19075. $brTL_V = 0;
  19076. $brTR_H = 0;
  19077. $brTR_V = 0;
  19078. $brBL_H = 0;
  19079. $brBL_V = 0;
  19080. $brBR_H = 0;
  19081. $brBR_V = 0;
  19082. $brset = false;
  19083. /*-- BORDER-RADIUS --*/
  19084. if (isset($this->blk[$blvl]['border_radius_TL_H'])) { $brTL_H = $this->blk[$blvl]['border_radius_TL_H']; $brset = true; }
  19085. if (isset($this->blk[$blvl]['border_radius_TL_V'])) { $brTL_V = $this->blk[$blvl]['border_radius_TL_V']; $brset = true; }
  19086. if (isset($this->blk[$blvl]['border_radius_TR_H'])) { $brTR_H = $this->blk[$blvl]['border_radius_TR_H']; $brset = true; }
  19087. if (isset($this->blk[$blvl]['border_radius_TR_V'])) { $brTR_V = $this->blk[$blvl]['border_radius_TR_V']; $brset = true; }
  19088. if (isset($this->blk[$blvl]['border_radius_BR_H'])) { $brBR_H = $this->blk[$blvl]['border_radius_BR_H']; $brset = true; }
  19089. if (isset($this->blk[$blvl]['border_radius_BR_V'])) { $brBR_V = $this->blk[$blvl]['border_radius_BR_V']; $brset = true; }
  19090. if (isset($this->blk[$blvl]['border_radius_BL_H'])) { $brBL_H = $this->blk[$blvl]['border_radius_BL_H']; $brset = true; }
  19091. if (isset($this->blk[$blvl]['border_radius_BL_V'])) { $brBL_V = $this->blk[$blvl]['border_radius_BL_V']; $brset = true; }
  19092. // mPDF 5.4.17
  19093. //if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage || $this->keep_block_together) {
  19094. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) {
  19095. $brTL_H = 0;
  19096. $brTL_V = 0;
  19097. $brTR_H = 0;
  19098. $brTR_V = 0;
  19099. }
  19100. // mPDF 5.4.17
  19101. //if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom' || $this->keep_block_together) {
  19102. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') {
  19103. $brBL_H = 0;
  19104. $brBL_V = 0;
  19105. $brBR_H = 0;
  19106. $brBR_V = 0;
  19107. }
  19108. // Disallow border-radius if it is smaller than the border width.
  19109. if ($brTL_H < min($border_left, $border_top)) { $brTL_H = $brTL_V = 0; }
  19110. if ($brTL_V < min($border_left, $border_top)) { $brTL_V = $brTL_H = 0; }
  19111. if ($brTR_H < min($border_right, $border_top)) { $brTR_H = $brTR_V = 0; }
  19112. if ($brTR_V < min($border_right, $border_top)) { $brTR_V = $brTR_H = 0; }
  19113. if ($brBL_H < min($border_left, $border_bottom)) { $brBL_H = $brBL_V = 0; }
  19114. if ($brBL_V < min($border_left, $border_bottom)) { $brBL_V = $brBL_H = 0; }
  19115. if ($brBR_H < min($border_right, $border_bottom)) { $brBR_H = $brBR_V = 0; }
  19116. if ($brBR_V < min($border_right, $border_bottom)) { $brBR_V = $brBR_H = 0; }
  19117. // CHECK FOR radii that sum to > width or height of div ********
  19118. $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));
  19119. if ($f < 1) {
  19120. $brTL_H *= $f;
  19121. $brTL_V *= $f;
  19122. $brTR_H *= $f;
  19123. $brTR_V *= $f;
  19124. $brBL_H *= $f;
  19125. $brBL_V *= $f;
  19126. $brBR_H *= $f;
  19127. $brBR_V *= $f;
  19128. }
  19129. /*-- END BORDER-RADIUS --*/
  19130. // BORDERS
  19131. if (isset($this->blk[$blvl]['y0']) && $this->blk[$blvl]['y0']) { $y0 = $this->blk[$blvl]['y0']; }
  19132. $h = $y1 - $y0;
  19133. $w = $this->blk[$blvl]['width'];
  19134. //if ($this->blk[$blvl]['border_top']) {
  19135. // Reinstate line above for dotted line divider when block border crosses a page
  19136. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19137. $tbd = $this->blk[$blvl]['border_top'];
  19138. // mPDF 5.4.18
  19139. $legend = '';
  19140. if (isset($this->blk[$blvl]['border_legend']) && $this->blk[$blvl]['border_legend']) {
  19141. $legend = $this->blk[$blvl]['border_legend']; // Same structure array as textbuffer
  19142. $txt = ltrim($legend[0]);
  19143. //Set font, size, style, color
  19144. $this->SetFont($legend[4],$legend[2],$legend[11]);
  19145. if ($legend[3]) {
  19146. $cor = $legend[3];
  19147. $this->SetTColor($cor);
  19148. }
  19149. $stringWidth = $this->GetStringWidth($txt );
  19150. $save_x = $this->x;
  19151. $save_y = $this->y;
  19152. $save_currentfontfamily = $this->FontFamily;
  19153. $save_currentfontsize = $this->FontSizePt;
  19154. $save_currentfontstyle = $this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : '');
  19155. $this->y = $y0 - $this->FontSize/2 + $this->blk[$blvl]['border_top']['w']/2;
  19156. $this->x = $x0 + $this->blk[$blvl]['padding_left'] + $this->blk[$blvl]['border_left']['w'];
  19157. // Set the distance from the border line to the text ? make configurable variable
  19158. $gap = 0.2 * $this->FontSize;
  19159. $legbreakL = $this->x - $gap;
  19160. $legbreakR = $this->x + $stringWidth + $gap;
  19161. $this->Cell( $stringWidth, $this->FontSize, $txt , '', 0, 'C', $fill, '', 0, 0,0,'M', $fill);
  19162. // Reset
  19163. $this->x = $save_x;
  19164. $this->y = $save_y;
  19165. $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize);
  19166. $this->SetTColor($this->ConvertColor(0));
  19167. }
  19168. if (isset($tbd['s']) && $tbd['s']) {
  19169. $this->_setBorderLine($tbd);
  19170. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'T'); }
  19171. /*-- BORDER-RADIUS --*/
  19172. else if (($brTL_V && $brTL_H) || ($brTR_V && $brTR_H)) {
  19173. $this->SetLineJoin(0);
  19174. $this->SetLineCap(0);
  19175. }
  19176. if ($brTR_H && $brTR_V) {
  19177. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_top/2 , $brTR_V - $border_top/2 , 1, 2, true));
  19178. }
  19179. else {
  19180. /*-- END BORDER-RADIUS --*/
  19181. $this->_out(sprintf('%.3F %.3F m ',($x0 + $w - ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19182. /*-- BORDER-RADIUS --*/
  19183. }
  19184. if ($brTL_H && $brTL_V ) {
  19185. // mPDF 5.4.18
  19186. if ($legend) {
  19187. if ($legbreakR < ($x0 + $w - $brTR_H)) {
  19188. $this->_out(sprintf('%.3F %.3F l ', $legbreakR*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19189. }
  19190. if ($legbreakL > ($x0 + $border_top/2 + $brTL_H )) {
  19191. $this->_out(sprintf('%.3F %.3F m ',$legbreakL*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19192. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2) + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19193. }
  19194. else {
  19195. $this->_out(sprintf('%.3F %.3F m ',($x0 + ($border_top/2) + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19196. }
  19197. }
  19198. else {
  19199. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2) + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19200. }
  19201. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_top/2 , $brTL_V - $border_top/2 , 2, 1));
  19202. }
  19203. else {
  19204. /*-- END BORDER-RADIUS --*/
  19205. // mPDF 5.4.18
  19206. if ($legend) {
  19207. $legbreakL -= $border_top/2; // because line cap different if not radius
  19208. $legbreakR += $border_top/2;
  19209. if ($legbreakR < ($x0 + $w - ($border_top/2))) {
  19210. $this->_out(sprintf('%.3F %.3F l ',$legbreakR*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19211. }
  19212. if ($legbreakL > ($x0 + $border_top/2)) {
  19213. $this->_out(sprintf('%.3F %.3F m ',$legbreakL*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19214. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19215. }
  19216. else {
  19217. $this->_out(sprintf('%.3F %.3F m ', ($x0 + $border_top/2)*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19218. }
  19219. }
  19220. else {
  19221. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK));
  19222. }
  19223. /*-- BORDER-RADIUS --*/
  19224. }
  19225. /*-- END BORDER-RADIUS --*/
  19226. $this->_out('S');
  19227. // Reset Corners and Dash off
  19228. $this->SetLineJoin(2);
  19229. $this->SetLineCap(2);
  19230. $this->SetDash();
  19231. }
  19232. }
  19233. //if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1) {
  19234. // Reinstate line above for dotted line divider when block border crosses a page
  19235. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19236. $tbd = $this->blk[$blvl]['border_bottom'];
  19237. if (isset($tbd['s']) && $tbd['s']) {
  19238. $this->_setBorderLine($tbd);
  19239. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'B'); }
  19240. /*-- BORDER-RADIUS --*/
  19241. else if (($brBL_V && $brBL_H) || ($brBR_V && $brBR_H)) {
  19242. $this->SetLineJoin(0);
  19243. $this->SetLineCap(0);
  19244. }
  19245. if ($brBL_H && $brBL_V) {
  19246. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_bottom/2 , $brBL_V - $border_bottom/2 , 3, 2, true));
  19247. }
  19248. else {
  19249. /*-- END BORDER-RADIUS --*/
  19250. $this->_out(sprintf('%.3F %.3F m ',($x0 + ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK));
  19251. /*-- BORDER-RADIUS --*/
  19252. }
  19253. if ($brBR_H && $brBR_V ) {
  19254. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2) - $brBR_H )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK));
  19255. $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_bottom/2 , $brBR_V - $border_bottom/2 , 4, 1));
  19256. }
  19257. else {
  19258. /*-- END BORDER-RADIUS --*/
  19259. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2) )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK));
  19260. /*-- BORDER-RADIUS --*/
  19261. }
  19262. /*-- END BORDER-RADIUS --*/
  19263. $this->_out('S');
  19264. // Reset Corners and Dash off
  19265. $this->SetLineJoin(2);
  19266. $this->SetLineCap(2);
  19267. $this->SetDash();
  19268. }
  19269. }
  19270. if ($this->blk[$blvl]['border_left']) {
  19271. $tbd = $this->blk[$blvl]['border_left'];
  19272. if (isset($tbd['s']) && $tbd['s']) {
  19273. $this->_setBorderLine($tbd);
  19274. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'L'); }
  19275. /*-- BORDER-RADIUS --*/
  19276. else if (($brTL_V && $brTL_H) || ($brBL_V && $brBL_H)) {
  19277. $this->SetLineJoin(0);
  19278. $this->SetLineCap(0);
  19279. }
  19280. if ($brTL_V && $brTL_H) {
  19281. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_left/2 , $brTL_V - $border_left/2, 2, 2, true));
  19282. }
  19283. else {
  19284. /*-- END BORDER-RADIUS --*/
  19285. $this->_out(sprintf('%.3F %.3F m ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + ($border_left/2)))*_MPDFK));
  19286. /*-- BORDER-RADIUS --*/
  19287. }
  19288. if ($brBL_V && $brBL_H ) {
  19289. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)- $brBL_V) )*_MPDFK));
  19290. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_left/2 , $brBL_V - $border_left/2, 3, 1));
  19291. }
  19292. else {
  19293. /*-- END BORDER-RADIUS --*/
  19294. $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)) )*_MPDFK));
  19295. /*-- BORDER-RADIUS --*/
  19296. }
  19297. /*-- END BORDER-RADIUS --*/
  19298. $this->_out('S');
  19299. // Reset Corners and Dash off
  19300. $this->SetLineJoin(2);
  19301. $this->SetLineCap(2);
  19302. $this->SetDash();
  19303. }
  19304. }
  19305. if ($this->blk[$blvl]['border_right']) {
  19306. $tbd = $this->blk[$blvl]['border_right'];
  19307. if (isset($tbd['s']) && $tbd['s']) {
  19308. $this->_setBorderLine($tbd);
  19309. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'R'); }
  19310. /*-- BORDER-RADIUS --*/
  19311. else if (($brTR_V && $brTR_H) || ($brBR_V && $brBR_H)) {
  19312. $this->SetLineJoin(0);
  19313. $this->SetLineCap(0);
  19314. }
  19315. if ($brBR_V && $brBR_H) {
  19316. $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_right/2 , $brBR_V - $border_right/2, 4, 2, true));
  19317. }
  19318. else {
  19319. /*-- END BORDER-RADIUS --*/
  19320. $this->_out(sprintf('%.3F %.3F m ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h - ($border_right/2)))*_MPDFK));
  19321. /*-- BORDER-RADIUS --*/
  19322. }
  19323. if ($brTR_V && $brTR_H ) {
  19324. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2) + $brTR_V) )*_MPDFK));
  19325. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_right/2 , $brTR_V - $border_right/2, 1, 1));
  19326. }
  19327. else {
  19328. /*-- END BORDER-RADIUS --*/
  19329. $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2)) )*_MPDFK));
  19330. /*-- BORDER-RADIUS --*/
  19331. }
  19332. /*-- END BORDER-RADIUS --*/
  19333. $this->_out('S');
  19334. // Reset Corners and Dash off
  19335. $this->SetLineJoin(2);
  19336. $this->SetLineCap(2);
  19337. $this->SetDash();
  19338. }
  19339. }
  19340. if (!$brset) { // not if border-radius used
  19341. $tbcol = $this->ConvertColor(255);
  19342. for($l=0; $l <= $blvl; $l++) {
  19343. if ($this->blk[$l]['bgcolor']) {
  19344. $tbcol = $this->blk[$l]['bgcolorarray'];
  19345. }
  19346. }
  19347. }
  19348. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19349. $tbd = $this->blk[$blvl]['border_top'];
  19350. if (isset($tbd['s']) && $tbd['s']) {
  19351. if (!$brset && $tbd['style']=='double') {
  19352. $this->SetLineWidth($tbd['w']/3);
  19353. $this->SetDColor($tbcol);
  19354. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + $w - ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK, ($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK ));
  19355. }
  19356. }
  19357. }
  19358. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19359. $tbd = $this->blk[$blvl]['border_bottom'];
  19360. if (isset($tbd['s']) && $tbd['s']) {
  19361. if (!$brset && $tbd['style']=='double') {
  19362. $this->SetLineWidth($tbd['w']/3);
  19363. $this->SetDColor($tbcol);
  19364. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK, ($x0 + $w - ($border_bottom/2) )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK ));
  19365. }
  19366. }
  19367. }
  19368. if ($this->blk[$blvl]['border_left']) {
  19369. $tbd = $this->blk[$blvl]['border_left'];
  19370. if (isset($tbd['s']) && $tbd['s']) {
  19371. if (!$brset && $tbd['style']=='double') {
  19372. $this->SetLineWidth($tbd['w']/3);
  19373. $this->SetDColor($tbcol);
  19374. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + ($border_left/2)))*_MPDFK, ($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)) )*_MPDFK));
  19375. }
  19376. }
  19377. }
  19378. if ($this->blk[$blvl]['border_right']) {
  19379. $tbd = $this->blk[$blvl]['border_right'];
  19380. if (isset($tbd['s']) && $tbd['s']) {
  19381. if (!$brset && $tbd['style']=='double') {
  19382. $this->SetLineWidth($tbd['w']/3);
  19383. $this->SetDColor($tbcol);
  19384. $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h - ($border_right/2)))*_MPDFK, ($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2)) )*_MPDFK));
  19385. }
  19386. }
  19387. }
  19388. $this->SetDash();
  19389. $this->y = $save_y;
  19390. // BACKGROUNDS are disabled in columns/kbt/headers - messes up the repositioning in printcolumnbuffer
  19391. if ($this->ColActive || $this->kwt || $this->keep_block_together) { return ; }
  19392. $bgx0 = $x0;
  19393. $bgx1 = $x1;
  19394. $bgy0 = $y0;
  19395. $bgy1 = $y1;
  19396. /*-- BORDER-RADIUS --*/
  19397. // Defined br values represent the radius of the outer curve - need to take border-width/2 from each radius for drawing the borders
  19398. if (isset($this->blk[$blvl]['background_clip']) && $this->blk[$blvl]['background_clip'] == 'padding-box') {
  19399. $brbgTL_H = max(0, $brTL_H - $this->blk[$blvl]['border_left']['w']);
  19400. $brbgTL_V = max(0, $brTL_V - $this->blk[$blvl]['border_top']['w']);
  19401. $brbgTR_H = max(0, $brTR_H - $this->blk[$blvl]['border_right']['w']);
  19402. $brbgTR_V = max(0, $brTR_V - $this->blk[$blvl]['border_top']['w']);
  19403. $brbgBL_H = max(0, $brBL_H - $this->blk[$blvl]['border_left']['w']);
  19404. $brbgBL_V = max(0, $brBL_V - $this->blk[$blvl]['border_bottom']['w']);
  19405. $brbgBR_H = max(0, $brBR_H - $this->blk[$blvl]['border_right']['w']);
  19406. $brbgBR_V = max(0, $brBR_V - $this->blk[$blvl]['border_bottom']['w']);
  19407. $bgx0 += $this->blk[$blvl]['border_left']['w'];
  19408. $bgx1 -= $this->blk[$blvl]['border_right']['w'];
  19409. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  19410. $bgy0 += $this->blk[$blvl]['border_top']['w'];
  19411. }
  19412. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  19413. $bgy1 -= $this->blk[$blvl]['border_bottom']['w'];
  19414. }
  19415. }
  19416. else {
  19417. /*-- END BORDER-RADIUS --*/
  19418. $brbgTL_H = $brTL_H;
  19419. $brbgTL_V = $brTL_V;
  19420. $brbgTR_H = $brTR_H;
  19421. $brbgTR_V = $brTR_V;
  19422. $brbgBL_H = $brBL_H;
  19423. $brbgBL_V = $brBL_V;
  19424. $brbgBR_H = $brBR_H;
  19425. $brbgBR_V = $brBR_V;
  19426. /*-- BORDER-RADIUS --*/
  19427. }
  19428. /*-- END BORDER-RADIUS --*/
  19429. // Set clipping path
  19430. $s = ' q 0 w '; // Line width=0
  19431. $s .= sprintf('%.3F %.3F m ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // start point TL before the arc
  19432. /*-- BORDER-RADIUS --*/
  19433. if ($brbgTL_H || $brbgTL_V) {
  19434. $s .= $this->_EllipseArc($bgx0+$brbgTL_H, $bgy0+$brbgTL_V, $brbgTL_H , $brbgTL_V , 2); // segment 2 TL
  19435. }
  19436. /*-- END BORDER-RADIUS --*/
  19437. $s .= sprintf('%.3F %.3F l ', ($bgx0)*_MPDFK, ($this->h-($bgy1-$brbgBL_V ))*_MPDFK); // line to BL
  19438. /*-- BORDER-RADIUS --*/
  19439. if ($brbgBL_H || $brbgBL_V) {
  19440. $s .= $this->_EllipseArc($bgx0+$brbgBL_H, $bgy1-$brbgBL_V, $brbgBL_H , $brbgBL_V , 3); // segment 3 BL
  19441. }
  19442. /*-- END BORDER-RADIUS --*/
  19443. $s .= sprintf('%.3F %.3F l ', ($bgx1-$brbgBR_H )*_MPDFK, ($this->h-($bgy1))*_MPDFK); // line to BR
  19444. /*-- BORDER-RADIUS --*/
  19445. if ($brbgBR_H || $brbgBR_V) {
  19446. $s .= $this->_EllipseArc($bgx1-$brbgBR_H, $bgy1-$brbgBR_V, $brbgBR_H , $brbgBR_V , 4); // segment 4 BR
  19447. }
  19448. /*-- END BORDER-RADIUS --*/
  19449. $s .= sprintf('%.3F %.3F l ', ($bgx1)*_MPDFK, ($this->h-($bgy0+$brbgTR_V))*_MPDFK); // line to TR
  19450. /*-- BORDER-RADIUS --*/
  19451. if ($brbgTR_H || $brbgTR_V) {
  19452. $s .= $this->_EllipseArc($bgx1-$brbgTR_H, $bgy0+$brbgTR_V, $brbgTR_H , $brbgTR_V , 1); // segment 1 TR
  19453. }
  19454. /*-- END BORDER-RADIUS --*/
  19455. $s .= sprintf('%.3F %.3F l ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // line to TL
  19456. // Box Shadow
  19457. $shadow = '';
  19458. if (isset($this->blk[$blvl]['box_shadow']) && $this->blk[$blvl]['box_shadow'] && $h > 0) {
  19459. foreach($this->blk[$blvl]['box_shadow'] AS $sh) {
  19460. // Colors
  19461. if ($sh['col']{0}==1) {
  19462. $colspace = 'Gray';
  19463. if ($sh['col']{2}==1) { $col1 = '1'.$sh['col'][1].'1'.$sh['col'][3]; }
  19464. else { $col1 = '1'.$sh['col'][1].'1'.chr(100); }
  19465. $col2 = '1'.$sh['col'][1].'1'.chr(0);
  19466. }
  19467. else if ($sh['col']{0}==4) { // CMYK
  19468. $colspace = 'CMYK';
  19469. $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(100);
  19470. $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0);
  19471. }
  19472. else if ($sh['col']{0}==5) { // RGBa
  19473. $colspace = 'RGB';
  19474. $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4];
  19475. $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0);
  19476. }
  19477. else if ($sh['col']{0}==6) { // CMYKa
  19478. $colspace = 'CMYK';
  19479. $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].$sh['col'][5];
  19480. $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0);
  19481. }
  19482. else {
  19483. $colspace = 'RGB';
  19484. $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(100);
  19485. $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0);
  19486. }
  19487. // Use clipping path as set above (and rectangle around page) to clip area outside box
  19488. $shadow .= $s; // Use the clipping path with W*
  19489. $shadow .= sprintf('0 %.3F m %.3F %.3F l ', $this->h*_MPDFK, $this->w*_MPDFK, $this->h*_MPDFK);
  19490. $shadow .= sprintf('%.3F 0 l 0 0 l 0 %.3F l ', $this->w*_MPDFK, $this->h*_MPDFK);
  19491. $shadow .= 'W n'."\n";
  19492. $sh['blur'] = abs($sh['blur']); // cannot have negative blur value
  19493. // Ensure spread/blur do not make effective shadow width/height < 0
  19494. // Could do more complex things but this just adjusts spread value
  19495. if (-$sh['spread'] + $sh['blur']/2 > min($w/2, $h/2)) {
  19496. $sh['spread'] = $sh['blur']/2 - min($w/2, $h/2) + 0.01;
  19497. }
  19498. // Shadow Offset
  19499. if ($sh['x'] || $sh['y']) $shadow .= sprintf(' q 1 0 0 1 %.4F %.4F cm', $sh['x']*_MPDFK, -$sh['y']*_MPDFK)."\n";
  19500. // Set path for INNER shadow
  19501. $shadow .= ' q 0 w ';
  19502. $shadow .= $this->SetFColor($col1, true)."\n";
  19503. if ($col1{0}==5 && ord($col1{4})<100) { // RGBa
  19504. $shadow .= $this->SetAlpha(ord($col1{4})/100, 'Normal', true, 'F')."\n";
  19505. }
  19506. else if ($col1{0}==6 && ord($col1{5})<100) { // CMYKa
  19507. $shadow .= $this->SetAlpha(ord($col1{5})/100, 'Normal', true, 'F')."\n";
  19508. }
  19509. else if ($col1{0}==1 && $col1{2}==1 && ord($col1{3})<100) { // Gray
  19510. $shadow .= $this->SetAlpha(ord($col1{3})/100, 'Normal', true, 'F')."\n";
  19511. }
  19512. // Blur edges
  19513. $mag = 0.551784; // Bezier Control magic number for 4-part spline for circle/ellipse
  19514. $mag2 = 0.551784; // Bezier Control magic number to fill in edge of blurred rectangle
  19515. $d1 = $sh['spread']+$sh['blur']/2;
  19516. $d2 = $sh['spread']-$sh['blur']/2;
  19517. $bl = $sh['blur'];
  19518. $x00 = $x0 - $d1;
  19519. $y00 = $y0 - $d1;
  19520. $w00 = $w + $d1*2;
  19521. $h00 = $h + $d1*2;
  19522. // If any border-radius is greater width-negative spread(inner edge), ignore radii for shadow or screws up
  19523. $flatten = false;
  19524. if (max($brbgTR_H, $brbgTL_H, $brbgBR_H, $brbgBL_H) >= $w+$d2) { $flatten = true; }
  19525. if (max($brbgTR_V, $brbgTL_V, $brbgBR_V, $brbgBL_V) >= $h+$d2) { $flatten = true; }
  19526. // TOP RIGHT corner
  19527. $p1x = $x00+$w00-$d1-$brbgTR_H; $p1c2x = $p1x +($d2+$brbgTR_H)*$mag;
  19528. $p1y = $y00+$bl;
  19529. $p2x = $x00+$w00-$d1-$brbgTR_H; $p2c2x = $p2x + ($d1+$brbgTR_H)*$mag;
  19530. $p2y = $y00; $p2c1y = $p2y + $bl/2;
  19531. $p3x = $x00+$w00; $p3c2x = $p3x - $bl/2;
  19532. $p3y = $y00+$d1+$brbgTR_V; $p3c1y = $p3y - ($d1+$brbgTR_V)*$mag;
  19533. $p4x = $x00+$w00-$bl;
  19534. $p4y = $y00+$d1+$brbgTR_V; $p4c2y = $p4y - ($d2+$brbgTR_V)*$mag;
  19535. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19536. $p1x = $x00+$w00-$bl; $p1c2x = $p1x;
  19537. $p2x = $x00+$w00-$bl; $p2c2x = $p2x + $bl*$mag2;
  19538. $p3y = $y00+$bl; $p3c1y = $p3y - $bl*$mag2;
  19539. $p4y = $y00+$bl; $p4c2y = $p4y ;
  19540. }
  19541. $shadow .= sprintf('%.3F %.3F m ', ($p1x )*_MPDFK, ($this->h-($p1y ))*_MPDFK);
  19542. $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);
  19543. $patch_array[0]['f']=0;
  19544. $patch_array[0]['points']=array($p1x,$p1y, $p1x,$p1y,
  19545. $p2x,$p2c1y, $p2x,$p2y, $p2c2x,$p2y,
  19546. $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y,
  19547. $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y,
  19548. $p1c2x,$p1y);
  19549. $patch_array[0]['colors'] = array($col1,$col2,$col2,$col1);
  19550. // RIGHT
  19551. $p1x = $x00+$w00; // control point only matches p3 preceding
  19552. $p1y = $y00+$d1+$brbgTR_V;
  19553. $p2x = $x00+$w00-$bl; // control point only matches p4 preceding
  19554. $p2y = $y00+$d1+$brbgTR_V;
  19555. $p3x = $x00+$w00-$bl;
  19556. $p3y = $y00+$h00-$d1-$brbgBR_V;
  19557. $p4x = $x00+$w00; $p4c1x = $p4x-$bl/2;
  19558. $p4y = $y00+$h00-$d1-$brbgBR_V;
  19559. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19560. $p1y = $y00+$bl;
  19561. $p2y = $y00+$bl;
  19562. }
  19563. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19564. $p3y = $y00+$h00-$bl;
  19565. $p4y = $y00+$h00-$bl;
  19566. }
  19567. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19568. $patch_array[1]['f']=2;
  19569. $patch_array[1]['points']=array($p2x,$p2y,
  19570. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19571. $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y,
  19572. $p1x,$p1y);
  19573. $patch_array[1]['colors'] = array($col1,$col2);
  19574. // BOTTOM RIGHT corner
  19575. $p1x = $x00+$w00-$bl; // control points only matches p3 preceding
  19576. $p1y = $y00+$h00-$d1-$brbgBR_V; $p1c2y = $p1y + ($d2+$brbgBR_V)*$mag;
  19577. $p2x = $x00+$w00; // control point only matches p4 preceding
  19578. $p2y = $y00+$h00-$d1-$brbgBR_V; $p2c2y = $p2y + ($d1+$brbgBR_V)*$mag;
  19579. $p3x = $x00+$w00-$d1-$brbgBR_H; $p3c1x = $p3x + ($d1+$brbgBR_H)*$mag;
  19580. $p3y = $y00+$h00; $p3c2y = $p3y - $bl/2;
  19581. $p4x = $x00+$w00-$d1-$brbgBR_H; $p4c2x = $p4x + ($d2+$brbgBR_H)*$mag;
  19582. $p4y = $y00+$h00-$bl;
  19583. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19584. $p1y = $y00+$h00-$bl; $p1c2y = $p1y;
  19585. $p2y = $y00+$h00-$bl; $p2c2y = $p2y + $bl*$mag2;
  19586. $p3x = $x00+$w00-$bl; $p3c1x = $p3x + $bl*$mag2;
  19587. $p4x = $x00+$w00-$bl; $p4c2x = $p4x;
  19588. }
  19589. $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);
  19590. $patch_array[2]['f']=2;
  19591. $patch_array[2]['points']=array($p2x,$p2c2y,
  19592. $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y,
  19593. $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y,
  19594. $p1x,$p1c2y);
  19595. $patch_array[2]['colors'] = array($col2,$col1);
  19596. // BOTTOM
  19597. $p1x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p3 preceding
  19598. $p1y = $y00+$h00;
  19599. $p2x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p4 preceding
  19600. $p2y = $y00+$h00-$bl;
  19601. $p3x = $x00+$d1+$brbgBL_H;
  19602. $p3y = $y00+$h00-$bl;
  19603. $p4x = $x00+$d1+$brbgBL_H;
  19604. $p4y = $y00+$h00; $p4c1y = $p4y - $bl/2;
  19605. if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
  19606. $p1x = $x00+$w00-$bl;
  19607. $p2x = $x00+$w00-$bl;
  19608. }
  19609. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19610. $p3x = $x00+$bl;
  19611. $p4x = $x00+$bl;
  19612. }
  19613. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19614. $patch_array[3]['f']=2;
  19615. $patch_array[3]['points']=array($p2x,$p2y,
  19616. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19617. $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y,
  19618. $p1x,$p1y);
  19619. $patch_array[3]['colors'] = array($col1,$col2);
  19620. // BOTTOM LEFT corner
  19621. $p1x = $x00+$d1+$brbgBL_H; $p1c2x = $p1x - ($d2+$brbgBL_H)*$mag; // control points only matches p3 preceding
  19622. $p1y = $y00+$h00-$bl;
  19623. $p2x = $x00+$d1+$brbgBL_H; $p2c2x = $p2x - ($d1+$brbgBL_H)*$mag; // control point only matches p4 preceding
  19624. $p2y = $y00+$h00;
  19625. $p3x = $x00; $p3c2x = $p3x + $bl/2;
  19626. $p3y = $y00+$h00-$d1-$brbgBL_V; $p3c1y = $p3y + ($d1+$brbgBL_V)*$mag;
  19627. $p4x = $x00+$bl;
  19628. $p4y = $y00+$h00-$d1-$brbgBL_V; $p4c2y = $p4y + ($d2+$brbgBL_V)*$mag;
  19629. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19630. $p1x = $x00+$bl; $p1c2x = $p1x;
  19631. $p2x = $x00+$bl; $p2c2x = $p2x - $bl*$mag2;
  19632. $p3y = $y00+$h00-$bl; $p3c1y = $p3y + $bl*$mag2;
  19633. $p4y = $y00+$h00-$bl; $p4c2y = $p4y;
  19634. }
  19635. $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);
  19636. $patch_array[4]['f']=2;
  19637. $patch_array[4]['points']=array($p2c2x,$p2y,
  19638. $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y,
  19639. $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y,
  19640. $p1c2x,$p1y);
  19641. $patch_array[4]['colors'] = array($col2,$col1);
  19642. // LEFT - joins on the right (C3-C4 of previous): f = 2
  19643. $p1x = $x00; // control point only matches p3 preceding
  19644. $p1y = $y00+$h00-$d1-$brbgBL_V;
  19645. $p2x = $x00+$bl; // control point only matches p4 preceding
  19646. $p2y = $y00+$h00-$d1-$brbgBL_V;
  19647. $p3x = $x00+$bl;
  19648. $p3y = $y00+$d1+$brbgTL_V;
  19649. $p4x = $x00; $p4c1x = $p4x + $bl/2;
  19650. $p4y = $y00+$d1+$brbgTL_V;
  19651. if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) {
  19652. $p1y = $y00+$h00-$bl;
  19653. $p2y = $y00+$h00-$bl;
  19654. }
  19655. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19656. $p3y = $y00+$bl;
  19657. $p4y = $y00+$bl;
  19658. }
  19659. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19660. $patch_array[5]['f']=2;
  19661. $patch_array[5]['points']=array($p2x,$p2y,
  19662. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19663. $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y,
  19664. $p1x,$p1y);
  19665. $patch_array[5]['colors'] = array($col1,$col2);
  19666. // TOP LEFT corner
  19667. $p1x = $x00+$bl; // control points only matches p3 preceding
  19668. $p1y = $y00+$d1+$brbgTL_V; $p1c2y = $p1y - ($d2+$brbgTL_V)*$mag;
  19669. $p2x = $x00; // control point only matches p4 preceding
  19670. $p2y = $y00+$d1+$brbgTL_V; $p2c2y = $p2y - ($d1+$brbgTL_V)*$mag;
  19671. $p3x = $x00+$d1+$brbgTL_H; $p3c1x = $p3x - ($d1+$brbgTL_H)*$mag;
  19672. $p3y = $y00; $p3c2y = $p3y + $bl/2;
  19673. $p4x = $x00+$d1+$brbgTL_H; $p4c2x = $p4x - ($d2+$brbgTL_H)*$mag;
  19674. $p4y = $y00+$bl;
  19675. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19676. $p1y = $y00+$bl; $p1c2y = $p1y;
  19677. $p2y = $y00+$bl; $p2c2y = $p2y - $bl*$mag2;
  19678. $p3x = $x00+$bl; $p3c1x = $p3x - $bl*$mag2;
  19679. $p4x = $x00+$bl; $p4c2x = $p4x ;
  19680. }
  19681. $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);
  19682. $patch_array[6]['f']=2;
  19683. $patch_array[6]['points']=array($p2x,$p2c2y,
  19684. $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y,
  19685. $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y,
  19686. $p1x,$p1c2y);
  19687. $patch_array[6]['colors'] = array($col2,$col1);
  19688. // TOP - joins on the right (C3-C4 of previous): f = 2
  19689. $p1x = $x00+$d1+$brbgTL_H; // control point only matches p3 preceding
  19690. $p1y = $y00;
  19691. $p2x = $x00+$d1+$brbgTL_H; // control point only matches p4 preceding
  19692. $p2y = $y00+$bl;
  19693. $p3x = $x00+$w00-$d1-$brbgTR_H;
  19694. $p3y = $y00+$bl;
  19695. $p4x = $x00+$w00-$d1-$brbgTR_H;
  19696. $p4y = $y00; $p4c1y = $p4y + $bl/2;
  19697. if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) {
  19698. $p1x = $x00+$bl;
  19699. $p2x = $x00+$bl;
  19700. }
  19701. if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
  19702. $p3x = $x00+$w00-$bl;
  19703. $p4x = $x00+$w00-$bl;
  19704. }
  19705. $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK);
  19706. $patch_array[7]['f']=2;
  19707. $patch_array[7]['points']=array($p2x,$p2y,
  19708. $p3x,$p3y, $p3x,$p3y, $p3x,$p3y,
  19709. $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y,
  19710. $p1x,$p1y);
  19711. $patch_array[7]['colors'] = array($col1,$col2);
  19712. $shadow .= ' h f Q '."\n"; // Close path and Fill the inner solid shadow
  19713. if ($bl) $shadow .= $this->grad->CoonsPatchMesh($x00,$y00,$w00,$h00,$patch_array,$x00,$x00+$w00,$y00,$y00+$h00, $colspace, true);
  19714. if ($sh['x'] || $sh['y']) $shadow .= ' Q'."\n"; // Shadow Offset
  19715. $shadow .= ' Q'."\n"; // Ends path no-op & Sets the clipping path
  19716. }
  19717. }
  19718. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  19719. if ($this->blk[$blvl]['bgcolor']) {
  19720. $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'col'=>$this->blk[$blvl]['bgcolorarray'], 'clippath'=>$s, 'visibility'=>$this->visibility, 'shadow'=>$shadow);
  19721. }
  19722. else if ($shadow) {
  19723. $this->pageBackgrounds[$blvl][] = array('shadowonly'=>true, 'col'=>'', 'clippath'=>'', 'visibility'=>$this->visibility, 'shadow'=>$shadow);
  19724. }
  19725. /*-- BACKGROUNDS --*/
  19726. if (isset($this->blk[$blvl]['gradient'])) {
  19727. $g = $this->grad->parseBackgroundGradient($this->blk[$blvl]['gradient']);
  19728. if ($g) {
  19729. $gx = $x0;
  19730. $gy = $y0;
  19731. $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);
  19732. }
  19733. }
  19734. if (isset($this->blk[$blvl]['background-image'])) {
  19735. if ($this->blk[$blvl]['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->blk[$blvl]['background-image']['gradient'] )) {
  19736. $g = $this->grad->parseMozGradient( $this->blk[$blvl]['background-image']['gradient'] );
  19737. if ($g) {
  19738. $gx = $x0;
  19739. $gy = $y0;
  19740. $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);
  19741. }
  19742. }
  19743. else {
  19744. $image_id = $this->blk[$blvl]['background-image']['image_id'];
  19745. $orig_w = $this->blk[$blvl]['background-image']['orig_w'];
  19746. $orig_h = $this->blk[$blvl]['background-image']['orig_h'];
  19747. $x_pos = $this->blk[$blvl]['background-image']['x_pos'];
  19748. $y_pos = $this->blk[$blvl]['background-image']['y_pos'];
  19749. $x_repeat = $this->blk[$blvl]['background-image']['x_repeat'];
  19750. $y_repeat = $this->blk[$blvl]['background-image']['y_repeat'];
  19751. $resize = $this->blk[$blvl]['background-image']['resize'];
  19752. $opacity = $this->blk[$blvl]['background-image']['opacity'];
  19753. $itype = $this->blk[$blvl]['background-image']['itype'];
  19754. $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);
  19755. }
  19756. }
  19757. /*-- END BACKGROUNDS --*/
  19758. // Float DIV
  19759. $this->blk[$blvl]['bb_painted'][$this->page] = true;
  19760. }
  19761. /*-- BORDER-RADIUS --*/
  19762. function _EllipseArc($x0, $y0, $rx, $ry, $seg = 1, $part=false, $start=false) { // Anticlockwise segment 1-4 TR-TL-BL-BR (part=1 or 2)
  19763. $s = '';
  19764. if ($rx<0) { $rx = 0; }
  19765. if ($ry<0) { $ry = 0; }
  19766. $rx *= _MPDFK;
  19767. $ry *= _MPDFK;
  19768. $astart = 0;
  19769. if ($seg == 1) { // Top Right
  19770. $afinish = 90;
  19771. $nSeg = 4;
  19772. }
  19773. else if ($seg == 2) { // Top Left
  19774. $afinish = 180;
  19775. $nSeg = 8;
  19776. }
  19777. else if ($seg == 3) { // Bottom Left
  19778. $afinish = 270;
  19779. $nSeg = 12;
  19780. }
  19781. else { // Bottom Right
  19782. $afinish = 360;
  19783. $nSeg = 16;
  19784. }
  19785. $astart = deg2rad((float) $astart);
  19786. $afinish = deg2rad((float) $afinish);
  19787. $totalAngle = $afinish - $astart;
  19788. $dt = $totalAngle / $nSeg; // segment angle
  19789. $dtm = $dt/3;
  19790. $x0 *= _MPDFK;
  19791. $y0 = ($this->h - $y0) * _MPDFK;
  19792. $t1 = $astart;
  19793. $a0 = $x0 + ($rx * cos($t1));
  19794. $b0 = $y0 + ($ry * sin($t1));
  19795. $c0 = -$rx * sin($t1);
  19796. $d0 = $ry * cos($t1);
  19797. $op = false;
  19798. for ($i = 1; $i <= $nSeg; $i++) {
  19799. // Draw this bit of the total curve
  19800. $t1 = ($i * $dt) + $astart;
  19801. $a1 = $x0 + ($rx * cos($t1));
  19802. $b1 = $y0 + ($ry * sin($t1));
  19803. $c1 = -$rx * sin($t1);
  19804. $d1 = $ry * cos($t1);
  19805. if ($i>($nSeg-4) && (!$part || ($part == 1 && $i<=$nSeg-2) || ($part == 2 && $i>$nSeg-2))) {
  19806. if ($start && !$op) {
  19807. $s .= sprintf('%.3F %.3F m ', $a0, $b0);
  19808. }
  19809. $s .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($a0 + ($c0 * $dtm)), ($b0 + ($d0 * $dtm)), ($a1 - ($c1 * $dtm)) , ($b1 - ($d1 * $dtm)), $a1 , $b1 );
  19810. $op = true;
  19811. }
  19812. $a0 = $a1;
  19813. $b0 = $b1;
  19814. $c0 = $c1;
  19815. $d0 = $d1;
  19816. }
  19817. return $s;
  19818. }
  19819. /*-- END BORDER-RADIUS --*/
  19820. function PaintDivLnBorder($state=0,$blvl=0,$h) {
  19821. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  19822. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y + $h;
  19823. $save_y = $this->y;
  19824. $w = $this->blk[$blvl]['width'];
  19825. $x0 = $this->x; // left
  19826. $y0 = $this->y; // top
  19827. $x1 = $this->x + $w; // bottom
  19828. $y1 = $this->y + $h; // bottom
  19829. if ($this->blk[$blvl]['border_top'] && ($state==1 || $state==3)) {
  19830. $tbd = $this->blk[$blvl]['border_top'];
  19831. if (isset($tbd['s']) && $tbd['s']) {
  19832. $this->_setBorderLine($tbd);
  19833. $this->y = $y0 + ($tbd['w']/2);
  19834. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'T'); }
  19835. $this->Line($x0 + ($tbd['w']/2) , $this->y , $x0 + $w - ($tbd['w']/2), $this->y);
  19836. $this->y += $tbd['w'];
  19837. // Reset Corners and Dash off
  19838. $this->SetLineJoin(2);
  19839. $this->SetLineCap(2);
  19840. $this->SetDash();
  19841. }
  19842. }
  19843. if ($this->blk[$blvl]['border_left']) {
  19844. $tbd = $this->blk[$blvl]['border_left'];
  19845. if (isset($tbd['s']) && $tbd['s']) {
  19846. $this->_setBorderLine($tbd);
  19847. $this->y = $y0 + ($tbd['w']/2);
  19848. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'L'); }
  19849. $this->Line($x0 + ($tbd['w']/2), $this->y, $x0 + ($tbd['w']/2), $y0 + $h -($tbd['w']/2));
  19850. $this->y += $tbd['w'];
  19851. // Reset Corners and Dash off
  19852. $this->SetLineJoin(2);
  19853. $this->SetLineCap(2);
  19854. $this->SetDash();
  19855. }
  19856. }
  19857. if ($this->blk[$blvl]['border_right']) {
  19858. $tbd = $this->blk[$blvl]['border_right'];
  19859. if (isset($tbd['s']) && $tbd['s']) {
  19860. $this->_setBorderLine($tbd);
  19861. $this->y = $y0 + ($tbd['w']/2);
  19862. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'R'); }
  19863. $this->Line($x0 + $w - ($tbd['w']/2), $this->y, $x0 + $w - ($tbd['w']/2), $y0 + $h - ($tbd['w']/2));
  19864. $this->y += $tbd['w'];
  19865. // Reset Corners and Dash off
  19866. $this->SetLineJoin(2);
  19867. $this->SetLineCap(2);
  19868. $this->SetDash();
  19869. }
  19870. }
  19871. if ($this->blk[$blvl]['border_bottom'] && $state > 1) {
  19872. $tbd = $this->blk[$blvl]['border_bottom'];
  19873. if (isset($tbd['s']) && $tbd['s']) {
  19874. $this->_setBorderLine($tbd);
  19875. $this->y = $y0 + $h - ($tbd['w']/2);
  19876. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'B'); }
  19877. $this->Line($x0 + ($tbd['w']/2) , $this->y, $x0 + $w - ($tbd['w']/2), $this->y);
  19878. $this->y += $tbd['w'];
  19879. // Reset Corners and Dash off
  19880. $this->SetLineJoin(2);
  19881. $this->SetLineCap(2);
  19882. $this->SetDash();
  19883. }
  19884. }
  19885. $this->SetDash();
  19886. $this->y = $save_y;
  19887. }
  19888. function PaintImgBorder($objattr,$is_table) {
  19889. // Borders are disabled in columns - messes up the repositioning in printcolumnbuffer
  19890. if ($this->ColActive) { return ; } // *COLUMNS*
  19891. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  19892. $h = (isset($objattr['BORDER-HEIGHT']) ? $objattr['BORDER-HEIGHT'] : 0);
  19893. $w = (isset($objattr['BORDER-WIDTH']) ? $objattr['BORDER-WIDTH'] : 0);
  19894. $x0 = (isset($objattr['BORDER-X']) ? $objattr['BORDER-X'] : 0);
  19895. $y0 = (isset($objattr['BORDER-Y']) ? $objattr['BORDER-Y'] : 0);
  19896. // BORDERS
  19897. if ($objattr['border_top']) {
  19898. $tbd = $objattr['border_top'];
  19899. if (!empty($tbd['s'])) {
  19900. $this->_setBorderLine($tbd,$k);
  19901. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','T'); }
  19902. $this->Line($x0, $y0, $x0 + $w, $y0);
  19903. // Reset Corners and Dash off
  19904. $this->SetLineJoin(2);
  19905. $this->SetLineCap(2);
  19906. $this->SetDash();
  19907. }
  19908. }
  19909. if ($objattr['border_left']) {
  19910. $tbd = $objattr['border_left'];
  19911. if (!empty($tbd['s'])) {
  19912. $this->_setBorderLine($tbd,$k);
  19913. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','L'); }
  19914. $this->Line($x0, $y0, $x0, $y0 + $h);
  19915. // Reset Corners and Dash off
  19916. $this->SetLineJoin(2);
  19917. $this->SetLineCap(2);
  19918. $this->SetDash();
  19919. }
  19920. }
  19921. if ($objattr['border_right']) {
  19922. $tbd = $objattr['border_right'];
  19923. if (!empty($tbd['s'])) {
  19924. $this->_setBorderLine($tbd,$k);
  19925. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','R'); }
  19926. $this->Line($x0 + $w, $y0, $x0 + $w, $y0 + $h);
  19927. // Reset Corners and Dash off
  19928. $this->SetLineJoin(2);
  19929. $this->SetLineCap(2);
  19930. $this->SetDash();
  19931. }
  19932. }
  19933. if ($objattr['border_bottom']) {
  19934. $tbd = $objattr['border_bottom'];
  19935. if (!empty($tbd['s'])) {
  19936. $this->_setBorderLine($tbd,$k);
  19937. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','B'); }
  19938. $this->Line($x0, $y0 + $h, $x0 + $w, $y0 + $h);
  19939. // Reset Corners and Dash off
  19940. $this->SetLineJoin(2);
  19941. $this->SetLineCap(2);
  19942. $this->SetDash();
  19943. }
  19944. }
  19945. $this->SetDash();
  19946. $this->SetAlpha(1);
  19947. }
  19948. /*-- END HTML-CSS --*/
  19949. function Reset() {
  19950. $this->SetTColor($this->ConvertColor(0));
  19951. $this->SetDColor($this->ConvertColor(0));
  19952. $this->SetFColor($this->ConvertColor(255));
  19953. $this->SetAlpha(1);
  19954. $this->colorarray = '';
  19955. $this->spanbgcolorarray = '';
  19956. $this->spanbgcolor = false;
  19957. $this->spanborder = false;
  19958. $this->spanborddet = array();
  19959. $this->ResetStyles();
  19960. $this->HREF = '';
  19961. $this->outlineparam = array();
  19962. $this->outline_on = false;
  19963. $this->SetTextOutline(false);
  19964. $this->SUP = false;
  19965. $this->SUB = false;
  19966. $this->strike = false;
  19967. $this->textshadow = '';
  19968. $this->SetFont($this->default_font,'',0,false);
  19969. $this->SetFontSize($this->default_font_size,false);
  19970. $this->currentfontfamily = '';
  19971. $this->currentfontsize = '';
  19972. /*-- TABLES --*/
  19973. if ($this->tableLevel) {
  19974. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  19975. }
  19976. else
  19977. /*-- END TABLES --*/
  19978. /*-- LISTS --*/
  19979. if ($this->listlvl && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) {
  19980. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height
  19981. }
  19982. else
  19983. /*-- END LISTS --*/
  19984. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  19985. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  19986. }
  19987. $this->toupper = false;
  19988. $this->tolower = false;
  19989. $this->kerning = false;
  19990. $this->lSpacingCSS = '';
  19991. $this->wSpacingCSS = '';
  19992. $this->fixedlSpacing = false;
  19993. $this->minwSpacing = 0;
  19994. $this->capitalize = false;
  19995. $this->SetDash(); //restore to no dash
  19996. $this->dash_on = false;
  19997. $this->dotted_on = false;
  19998. $this->divwidth = 0;
  19999. $this->divheight = 0;
  20000. $this->divalign = '';
  20001. $this->divrevert = false;
  20002. $this->oldy = -1;
  20003. $bodystyle = array();
  20004. if (isset($this->CSS['BODY']['FONT-STYLE'])) { $bodystyle['FONT-STYLE'] = $this->CSS['BODY']['FONT-STYLE']; }
  20005. if (isset($this->CSS['BODY']['FONT-WEIGHT'])) { $bodystyle['FONT-WEIGHT'] = $this->CSS['BODY']['FONT-WEIGHT']; }
  20006. if (isset($this->CSS['BODY']['COLOR'])) { $bodystyle['COLOR'] = $this->CSS['BODY']['COLOR']; }
  20007. if (isset($bodystyle)) { $this->setCSS($bodystyle,'BLOCK','BODY'); }
  20008. }
  20009. /*-- HTML-CSS --*/
  20010. function ReadMetaTags($html) {
  20011. // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
  20012. $regexp = '/ (\\w+?)=([^\\s>"]+)/si';
  20013. $html = preg_replace($regexp," \$1=\"\$2\"",$html);
  20014. if (preg_match('/<title>(.*?)<\/title>/si',$html,$m)) {
  20015. $this->SetTitle($m[1]);
  20016. }
  20017. preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|content)="([^>]*?)".*?>/si',$html,$aux);
  20018. $firstattr = $aux[1];
  20019. $secondattr = $aux[3];
  20020. for( $i = 0 ; $i < count($aux[0]) ; $i++) {
  20021. $name = ( strtoupper($firstattr[$i]) == "NAME" )? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]);
  20022. $content = ( strtoupper($firstattr[$i]) == "CONTENT" )? $aux[2][$i] : $aux[4][$i];
  20023. switch($name) {
  20024. case "KEYWORDS": $this->SetKeywords($content); break;
  20025. case "AUTHOR": $this->SetAuthor($content); break;
  20026. case "DESCRIPTION": $this->SetSubject($content); break;
  20027. }
  20028. }
  20029. }
  20030. function ReadCharset($html) {
  20031. // Charset conversion
  20032. if ($this->allow_charset_conversion) {
  20033. if (preg_match('/<head.*charset=([^\'\"\s]*).*<\/head>/si',$html,$m)) {
  20034. if (strtoupper($m[1]) != 'UTF-8') {
  20035. $this->charset_in = strtoupper($m[1]);
  20036. }
  20037. }
  20038. }
  20039. }
  20040. /*-- END HTML-CSS --*/
  20041. //////////////////
  20042. /// CSS parser ///
  20043. //////////////////
  20044. //////////////////
  20045. /// CSS parser ///
  20046. //////////////////
  20047. //////////////////
  20048. /// CSS parser ///
  20049. //////////////////
  20050. /*-- HTML-CSS --*/
  20051. function ReadDefaultCSS($CSSstr) {
  20052. $CSS = array();
  20053. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  20054. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  20055. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  20056. if ($CSSstr ) {
  20057. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  20058. for($i=0; $i < count($styles[1]) ; $i++) {
  20059. $stylestr= trim($styles[2][$i]);
  20060. $stylearr = explode(';',$stylestr);
  20061. foreach($stylearr AS $sta) {
  20062. if (trim($sta)) {
  20063. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  20064. list($property,$value) = explode(':',$sta,2);
  20065. $property = trim($property);
  20066. $value = preg_replace('/\s*!important/i','',$value);
  20067. $value = trim($value);
  20068. if ($property && ($value || $value==='0')) {
  20069. $classproperties[strtoupper($property)] = $value;
  20070. }
  20071. }
  20072. }
  20073. $classproperties = $this->fixCSS($classproperties);
  20074. $tagstr = strtoupper(trim($styles[1][$i]));
  20075. $tagarr = explode(',',$tagstr);
  20076. foreach($tagarr AS $tg) {
  20077. $tags = preg_split('/\s+/',trim($tg));
  20078. $level = count($tags);
  20079. if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  20080. $t = trim($tags[0]);
  20081. if ($t) {
  20082. $tag = '';
  20083. if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20084. if ($this->CSS[$tag] && $tag) { $CSS[$tag] = $this->array_merge_recursive_unique($CSS[$tag], $classproperties); }
  20085. else if ($tag) { $CSS[$tag] = $classproperties; }
  20086. }
  20087. }
  20088. }
  20089. $properties = array();
  20090. $values = array();
  20091. $classproperties = array();
  20092. }
  20093. } // end of if
  20094. return $CSS;
  20095. }
  20096. function ReadCSS($html) {
  20097. preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m);
  20098. for($i=0; $i<count($m[0]); $i++) {
  20099. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  20100. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  20101. }
  20102. }
  20103. preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m);
  20104. for($i=0; $i<count($m[0]); $i++) {
  20105. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  20106. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  20107. }
  20108. }
  20109. // mPDF 5.5.02
  20110. // Remove Comment tags <!-- ... --> inside CSS as <style> in HTML document
  20111. // Remove Comment tags /* ... */ inside CSS as <style> in HTML document
  20112. // But first, we replace upper and mixed case closing style tag with lower
  20113. // case so we can use str_replace later.
  20114. preg_replace('/<\/style>/i', '</style>', $html);
  20115. preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
  20116. if (count($m[1])) {
  20117. for($i=0;$i<count($m[1]);$i++) {
  20118. // Remove comment tags
  20119. $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
  20120. $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).'</style>';
  20121. $html = str_replace('>'.$m[1][$i].'</style>', $sub, $html);
  20122. }
  20123. }
  20124. $html = preg_replace('/<!--mpdf/i','',$html);
  20125. $html = preg_replace('/mpdf-->/i','',$html);
  20126. $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html);
  20127. $match = 0; // no match for instance
  20128. $regexp = ''; // This helps debugging: showing what is the REAL string being processed
  20129. $CSSext = array();
  20130. //CSS inside external files
  20131. $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
  20132. $x = preg_match_all($regexp,$html,$cxt);
  20133. if ($x) {
  20134. $match += $x;
  20135. $CSSext = $cxt[1];
  20136. }
  20137. $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
  20138. $x = preg_match_all($regexp,$html,$cxt);
  20139. if ($x) {
  20140. $match += $x;
  20141. $CSSext = array_merge($CSSext,$cxt[1]);
  20142. }
  20143. // look for @import stylesheets
  20144. //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
  20145. $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
  20146. $x = preg_match_all($regexp,$html,$cxt);
  20147. if ($x) {
  20148. $match += $x;
  20149. $CSSext = array_merge($CSSext,$cxt[1]);
  20150. }
  20151. // look for @import without the url()
  20152. //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
  20153. $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si';
  20154. $x = preg_match_all($regexp,$html,$cxt);
  20155. if ($x) {
  20156. $match += $x;
  20157. $CSSext = array_merge($CSSext,$cxt[1]);
  20158. }
  20159. $ind = 0;
  20160. $CSSstr = '';
  20161. if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array();
  20162. while($match){
  20163. $path = $CSSext[$ind];
  20164. $this->GetFullPath($path);
  20165. $CSSextblock = $this->_get_file($path);
  20166. if ($CSSextblock) {
  20167. // look for embedded @import stylesheets in other stylesheets
  20168. // and fix url paths (including background-images) relative to stylesheet
  20169. //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
  20170. $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
  20171. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  20172. $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/';
  20173. if ($xem) {
  20174. foreach($cxtem[1] AS $cxtembedded) {
  20175. // path is relative to original stlyesheet!!
  20176. $this->GetFullPath($cxtembedded, $cssBasePath );
  20177. $match++;
  20178. $CSSext[] = $cxtembedded;
  20179. }
  20180. }
  20181. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  20182. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  20183. if ($xem) {
  20184. for ($i=0;$i<count($cxtem[0]);$i++) {
  20185. // path is relative to original stlyesheet!!
  20186. $embedded = $cxtem[2][$i];
  20187. if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
  20188. $this->GetFullPath($embedded, $cssBasePath );
  20189. $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock);
  20190. }
  20191. }
  20192. }
  20193. $CSSstr .= ' '.$CSSextblock;
  20194. }
  20195. $match--;
  20196. $ind++;
  20197. } //end of match
  20198. $match = 0; // reset value, if needed
  20199. // CSS as <style> in HTML document
  20200. $regexp = '/<style.*?>(.*?)<\/style>/si';
  20201. $match = preg_match_all($regexp,$html,$CSSblock);
  20202. if ($match) {
  20203. $tmpCSSstr = implode(' ',$CSSblock[1]);
  20204. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  20205. $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem);
  20206. if ($xem) {
  20207. for ($i=0;$i<count($cxtem[0]);$i++) {
  20208. $embedded = $cxtem[2][$i];
  20209. if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
  20210. $this->GetFullPath($embedded);
  20211. $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr );
  20212. }
  20213. }
  20214. }
  20215. $CSSstr .= ' '.$tmpCSSstr;
  20216. }
  20217. // Remove comments
  20218. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  20219. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  20220. if (preg_match('/@media/',$CSSstr)) {
  20221. preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
  20222. for($i=0; $i<count($m[0]); $i++) {
  20223. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  20224. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
  20225. }
  20226. else {
  20227. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
  20228. }
  20229. }
  20230. }
  20231. // mPDF 5.5.13
  20232. // Replace any background: url(data:image... with temporary image file reference
  20233. preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*)\))/si", $CSSstr, $idata);
  20234. if (count($idata[0])) {
  20235. for($i=0;$i<count($idata[0]);$i++) {
  20236. $file = _MPDF_TEMP_PATH.'_tempCSSidata'.RAND(1,10000).'_'.$i.'.'.$idata[2][$i];
  20237. //Save to local file
  20238. file_put_contents($file, base64_decode($idata[3][$i]));
  20239. $this->GetFullPath($file); // ? is this needed
  20240. $CSSstr = str_replace($idata[0][$i], 'url("'.$file.'")', $CSSstr); // mPDF 5.5.17
  20241. }
  20242. }
  20243. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  20244. if ($CSSstr ) {
  20245. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  20246. for($i=0; $i < count($styles[1]) ; $i++) {
  20247. // SET array e.g. $classproperties['COLOR'] = '#ffffff';
  20248. $stylestr= trim($styles[2][$i]);
  20249. $stylearr = explode(';',$stylestr);
  20250. foreach($stylearr AS $sta) {
  20251. if (trim($sta)) {
  20252. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  20253. list($property,$value) = explode(':',$sta,2);
  20254. $property = trim($property);
  20255. $value = preg_replace('/\s*!important/i','',$value);
  20256. $value = trim($value);
  20257. if ($property && ($value || $value==='0')) {
  20258. // Ignores -webkit-gradient so doesn't override -moz-
  20259. if ((strtoupper($property)=='BACKGROUND-IMAGE' || strtoupper($property)=='BACKGROUND') && preg_match('/-webkit-gradient/i',$value)) {
  20260. continue;
  20261. }
  20262. $classproperties[strtoupper($property)] = $value;
  20263. }
  20264. }
  20265. }
  20266. $classproperties = $this->fixCSS($classproperties);
  20267. $tagstr = strtoupper(trim($styles[1][$i]));
  20268. $tagarr = explode(',',$tagstr);
  20269. $pageselectors = false; // used to turn on $this->mirrorMargins
  20270. foreach($tagarr AS $tg) {
  20271. $tags = preg_split('/\s+/',trim($tg));
  20272. $level = count($tags);
  20273. $t = '';
  20274. $t2 = '';
  20275. $t3 = '';
  20276. if (trim($tags[0])=='@PAGE') {
  20277. if (isset($tags[0])) { $t = trim($tags[0]); }
  20278. if (isset($tags[1])) { $t2 = trim($tags[1]); }
  20279. if (isset($tags[2])) { $t3 = trim($tags[2]); }
  20280. $tag = '';
  20281. if ($level==1) { $tag = $t; }
  20282. else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) {
  20283. $tag = $t.'>>PSEUDO>>'.$m[1];
  20284. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  20285. }
  20286. else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; }
  20287. else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) {
  20288. $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1];
  20289. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  20290. }
  20291. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  20292. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  20293. }
  20294. else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  20295. if (isset($tags[0])) { $t = trim($tags[0]); }
  20296. if ($t) {
  20297. $tag = '';
  20298. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  20299. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  20300. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  20301. else if (preg_match('/^('.$this->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
  20302. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  20303. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20304. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  20305. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  20306. }
  20307. }
  20308. else {
  20309. $tmp = array();
  20310. for($n=0;$n<$level;$n++) {
  20311. if (isset($tags[$n])) { $t = trim($tags[$n]); }
  20312. else { $t = ''; }
  20313. if ($t) {
  20314. $tag = '';
  20315. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  20316. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  20317. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  20318. else if (preg_match('/^('.$this->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
  20319. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  20320. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  20321. if ($tag) $tmp[] = $tag;
  20322. else { break; }
  20323. }
  20324. }
  20325. if ($tag) {
  20326. $x = &$this->cascadeCSS;
  20327. foreach($tmp AS $tp) { $x = &$x[$tp]; }
  20328. $x = $this->array_merge_recursive_unique($x, $classproperties);
  20329. $x['depth'] = $level;
  20330. }
  20331. }
  20332. }
  20333. if ($pageselectors) { $this->mirrorMargins = true; }
  20334. $properties = array();
  20335. $values = array();
  20336. $classproperties = array();
  20337. }
  20338. } // end of if
  20339. //Remove CSS (tags and content), if any
  20340. $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
  20341. $html = preg_replace($regexp,'',$html);
  20342. //print_r($this->CSS); exit;
  20343. //print_r($this->cascadeCSS); exit;
  20344. return $html;
  20345. }
  20346. function readInlineCSS($html) {
  20347. //Fix incomplete CSS code
  20348. $size = strlen($html)-1;
  20349. if (substr($html,$size,1) != ';') $html .= ';';
  20350. //Make CSS[Name-of-the-class] = array(key => value)
  20351. $regexp = '|\\s*?(\\S+?):(.+?);|i';
  20352. preg_match_all( $regexp, $html, $styleinfo);
  20353. $properties = $styleinfo[1];
  20354. $values = $styleinfo[2];
  20355. //Array-properties and Array-values must have the SAME SIZE!
  20356. $classproperties = array();
  20357. for($i = 0; $i < count($properties) ; $i++) {
  20358. // Ignores -webkit-gradient so doesn't override -moz-
  20359. if ((strtoupper($properties[$i])=='BACKGROUND-IMAGE' || strtoupper($properties[$i])=='BACKGROUND') && preg_match('/-webkit-gradient/i',$values[$i])) {
  20360. continue;
  20361. }
  20362. $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
  20363. }
  20364. return $this->fixCSS($classproperties);
  20365. }
  20366. function setCSS($arrayaux,$type='',$tag='') { // type= INLINE | BLOCK | LIST // tag= BODY
  20367. if (!is_array($arrayaux)) return; //Removes PHP Warning
  20368. // Set font size first so that e.g. MARGIN 0.83em works on font size for this element
  20369. if (isset($arrayaux['FONT-SIZE'])) {
  20370. $v = $arrayaux['FONT-SIZE'];
  20371. if(is_numeric($v[0])) {
  20372. if ($type == 'BLOCK' && $this->blklvl>0 && isset($this->blk[$this->blklvl-1]['InlineProperties']) && isset($this->blk[$this->blklvl-1]['InlineProperties']['size'])) {
  20373. $mmsize = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['InlineProperties']['size']);
  20374. }
  20375. else {
  20376. $mmsize = $this->ConvertSize($v,$this->FontSize);
  20377. }
  20378. $this->SetFontSize( $mmsize*(_MPDFK),false ); //Get size in points (pt)
  20379. }
  20380. else{
  20381. $v = strtoupper($v);
  20382. if (isset($this->fontsizes[$v])) {
  20383. $this->SetFontSize( $this->fontsizes[$v]* $this->default_font_size,false);
  20384. }
  20385. }
  20386. if ($tag == 'BODY') { $this->SetDefaultFontSize($this->FontSizePt); }
  20387. }
  20388. if ($this->useLang && !$this->usingCoreFont) {
  20389. if (isset($arrayaux['LANG']) && $arrayaux['LANG'] && $arrayaux['LANG'] != $this->default_lang && ((strlen($arrayaux['LANG']) == 5 && $arrayaux['LANG'] != 'UTF-8') || strlen($arrayaux['LANG']) == 2)) {
  20390. list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($arrayaux['LANG'], $this->useAdobeCJK);
  20391. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  20392. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  20393. if ($tag == 'BODY') {
  20394. $this->currentLang = $arrayaux['LANG'];
  20395. $this->default_lang = $arrayaux['LANG'];
  20396. if ($mpdf_pdf_unifonts) { $this->default_available_fonts = $mpdf_pdf_unifonts; }
  20397. }
  20398. }
  20399. else {
  20400. $this->RestrictUnicodeFonts($this->default_available_fonts );
  20401. }
  20402. }
  20403. // FOR INLINE and BLOCK OR 'BODY'
  20404. if (isset($arrayaux['FONT-FAMILY'])) {
  20405. $v = $arrayaux['FONT-FAMILY'];
  20406. //If it is a font list, get all font types
  20407. $aux_fontlist = explode(",",$v);
  20408. $found = 0;
  20409. foreach($aux_fontlist AS $f) {
  20410. $fonttype = trim($f);
  20411. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  20412. $fonttype = preg_replace('/ /','',$fonttype);
  20413. $v = strtolower(trim($fonttype));
  20414. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  20415. if ((!$this->onlyCoreFonts && in_array($v,$this->available_unifonts)) ||
  20416. in_array($v,array('ccourier','ctimes','chelvetica')) ||
  20417. ($this->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
  20418. in_array($v, array('sjis','uhc','big5','gb'))) {
  20419. $fonttype = $v;
  20420. $found = 1;
  20421. break;
  20422. }
  20423. }
  20424. if (!$found) {
  20425. foreach($aux_fontlist AS $f) {
  20426. $fonttype = trim($f);
  20427. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  20428. $fonttype = preg_replace('/ /','',$fonttype);
  20429. $v = strtolower(trim($fonttype));
  20430. if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; }
  20431. if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  20432. $fonttype = $v;
  20433. break;
  20434. }
  20435. }
  20436. }
  20437. if ($tag == 'BODY') {
  20438. $this->SetDefaultFont($fonttype);
  20439. }
  20440. $this->SetFont($fonttype,$this->currentfontstyle,0,false);
  20441. }
  20442. else {
  20443. $this->SetFont($this->currentfontfamily,$this->currentfontstyle,0,false);
  20444. }
  20445. foreach($arrayaux as $k => $v) {
  20446. if ($type != 'INLINE' && $tag != 'BODY' && $type != 'LIST') {
  20447. switch($k){
  20448. // BORDERS
  20449. case 'BORDER-TOP':
  20450. $this->blk[$this->blklvl]['border_top'] = $this->border_details($v);
  20451. if ($this->blk[$this->blklvl]['border_top']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20452. break;
  20453. case 'BORDER-BOTTOM':
  20454. $this->blk[$this->blklvl]['border_bottom'] = $this->border_details($v);
  20455. if ($this->blk[$this->blklvl]['border_bottom']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20456. break;
  20457. case 'BORDER-LEFT':
  20458. $this->blk[$this->blklvl]['border_left'] = $this->border_details($v);
  20459. if ($this->blk[$this->blklvl]['border_left']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20460. break;
  20461. case 'BORDER-RIGHT':
  20462. $this->blk[$this->blklvl]['border_right'] = $this->border_details($v);
  20463. if ($this->blk[$this->blklvl]['border_right']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  20464. break;
  20465. // PADDING
  20466. case 'PADDING-TOP':
  20467. $this->blk[$this->blklvl]['padding_top'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20468. break;
  20469. case 'PADDING-BOTTOM':
  20470. $this->blk[$this->blklvl]['padding_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20471. break;
  20472. case 'PADDING-LEFT':
  20473. $this->blk[$this->blklvl]['padding_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20474. break;
  20475. case 'PADDING-RIGHT':
  20476. $this->blk[$this->blklvl]['padding_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20477. break;
  20478. // MARGINS
  20479. case 'MARGIN-TOP':
  20480. $tmp = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20481. if (isset($this->blk[$this->blklvl]['lastbottommargin'])) {
  20482. if ($tmp > $this->blk[$this->blklvl]['lastbottommargin']) {
  20483. $tmp -= $this->blk[$this->blklvl]['lastbottommargin'];
  20484. }
  20485. else {
  20486. $tmp = 0;
  20487. }
  20488. }
  20489. $this->blk[$this->blklvl]['margin_top'] = $tmp;
  20490. break;
  20491. case 'MARGIN-BOTTOM':
  20492. $this->blk[$this->blklvl]['margin_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20493. break;
  20494. case 'MARGIN-LEFT':
  20495. $this->blk[$this->blklvl]['margin_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20496. break;
  20497. case 'MARGIN-RIGHT':
  20498. $this->blk[$this->blklvl]['margin_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20499. break;
  20500. /*-- BORDER-RADIUS --*/
  20501. case 'BORDER-TOP-LEFT-RADIUS-H':
  20502. $this->blk[$this->blklvl]['border_radius_TL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20503. break;
  20504. case 'BORDER-TOP-LEFT-RADIUS-V':
  20505. $this->blk[$this->blklvl]['border_radius_TL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20506. break;
  20507. case 'BORDER-TOP-RIGHT-RADIUS-H':
  20508. $this->blk[$this->blklvl]['border_radius_TR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20509. break;
  20510. case 'BORDER-TOP-RIGHT-RADIUS-V':
  20511. $this->blk[$this->blklvl]['border_radius_TR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20512. break;
  20513. case 'BORDER-BOTTOM-LEFT-RADIUS-H':
  20514. $this->blk[$this->blklvl]['border_radius_BL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20515. break;
  20516. case 'BORDER-BOTTOM-LEFT-RADIUS-V':
  20517. $this->blk[$this->blklvl]['border_radius_BL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20518. break;
  20519. case 'BORDER-BOTTOM-RIGHT-RADIUS-H':
  20520. $this->blk[$this->blklvl]['border_radius_BR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20521. break;
  20522. case 'BORDER-BOTTOM-RIGHT-RADIUS-V':
  20523. $this->blk[$this->blklvl]['border_radius_BR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20524. break;
  20525. /*-- END BORDER-RADIUS --*/
  20526. case 'BOX-SHADOW':
  20527. $bs = $this->setCSSboxshadow($v);
  20528. if ($bs) { $this->blk[$this->blklvl]['box_shadow'] = $bs; }
  20529. break;
  20530. case 'BACKGROUND-CLIP':
  20531. if (strtoupper($v) == 'PADDING-BOX') { $this->blk[$this->blklvl]['background_clip'] = 'padding-box'; }
  20532. break;
  20533. case 'PAGE-BREAK-AFTER':
  20534. if (strtoupper($v) == 'AVOID') { $this->blk[$this->blklvl]['page_break_after_avoid'] = true; }
  20535. else if (strtoupper($v) == 'ALWAYS' || strtoupper($v) == 'LEFT' || strtoupper($v) == 'RIGHT') { $this->blk[$this->blklvl]['page_break_after'] = strtoupper($v) ; }
  20536. break;
  20537. case 'WIDTH':
  20538. if (strtoupper($v) != 'AUTO') {
  20539. $this->blk[$this->blklvl]['css_set_width'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  20540. }
  20541. break;
  20542. case 'TEXT-INDENT':
  20543. // Left as raw value (may include 1% or 2em)
  20544. $this->blk[$this->blklvl]['text_indent'] = $v;
  20545. break;
  20546. }//end of switch($k)
  20547. }
  20548. if ($type != 'INLINE' && $type != 'LIST') { // includes BODY tag
  20549. switch($k){
  20550. case 'MARGIN-COLLAPSE': // Custom tag to collapse margins at top and bottom of page
  20551. if (strtoupper($v) == 'COLLAPSE') { $this->blk[$this->blklvl]['margin_collapse'] = true; }
  20552. break;
  20553. case 'LINE-HEIGHT':
  20554. $this->blk[$this->blklvl]['line_height'] = $this->fixLineheight($v);
  20555. if (!$this->blk[$this->blklvl]['line_height'] ) { $this->blk[$this->blklvl]['line_height'] = $this->normalLineheight; }
  20556. break;
  20557. case 'TEXT-ALIGN': //left right center justify
  20558. switch (strtoupper($v)) {
  20559. case 'LEFT':
  20560. $this->blk[$this->blklvl]['align']="L";
  20561. break;
  20562. case 'CENTER':
  20563. $this->blk[$this->blklvl]['align']="C";
  20564. break;
  20565. case 'RIGHT':
  20566. $this->blk[$this->blklvl]['align']="R";
  20567. break;
  20568. case 'JUSTIFY':
  20569. $this->blk[$this->blklvl]['align']="J";
  20570. break;
  20571. }
  20572. break;
  20573. /*-- BACKGROUNDS --*/
  20574. case 'BACKGROUND-GRADIENT':
  20575. if ($type == 'BLOCK') {
  20576. $this->blk[$this->blklvl]['gradient'] = $v;
  20577. }
  20578. break;
  20579. /*-- END BACKGROUNDS --*/
  20580. case 'DIRECTION':
  20581. if ($v) { $this->blk[$this->blklvl]['direction'] = strtolower($v); }
  20582. break;
  20583. }//end of switch($k)
  20584. }
  20585. // FOR INLINE ONLY
  20586. if ($type == 'INLINE' || $type == 'LIST') {
  20587. switch($k){
  20588. case 'DISPLAY': // Custom tag to collapse margins at top and bottom of page
  20589. if (strtoupper($v) == 'NONE') { $this->inlineDisplayOff = true; }
  20590. break;
  20591. case 'DIRECTION':
  20592. break;
  20593. }//end of switch($k)
  20594. }
  20595. // FOR INLINE ONLY
  20596. if ($type == 'INLINE') {
  20597. switch($k){
  20598. // BORDERS
  20599. case 'BORDER-TOP':
  20600. $this->spanborddet['T'] = $this->border_details($v);
  20601. $this->spanborder = true;
  20602. break;
  20603. case 'BORDER-BOTTOM':
  20604. $this->spanborddet['B'] = $this->border_details($v);
  20605. $this->spanborder = true;
  20606. break;
  20607. case 'BORDER-LEFT':
  20608. $this->spanborddet['L'] = $this->border_details($v);
  20609. $this->spanborder = true;
  20610. break;
  20611. case 'BORDER-RIGHT':
  20612. $this->spanborddet['R'] = $this->border_details($v);
  20613. $this->spanborder = true;
  20614. break;
  20615. }//end of switch($k)
  20616. }
  20617. // FOR INLINE and BLOCK
  20618. switch($k){
  20619. case 'TEXT-ALIGN': //left right center justify
  20620. if (strtoupper($v) == 'NOJUSTIFY' && $this->blk[$this->blklvl]['align']=="J") {
  20621. $this->blk[$this->blklvl]['align']="";
  20622. }
  20623. break;
  20624. // bgcolor only - to stay consistent with original html2fpdf
  20625. case 'BACKGROUND':
  20626. case 'BACKGROUND-COLOR':
  20627. $cor = $this->ConvertColor($v);
  20628. if ($cor) {
  20629. if ($tag == 'BODY') {
  20630. $this->bodyBackgroundColor = $cor;
  20631. }
  20632. else if ($type == 'INLINE' || $type == 'LIST') {
  20633. $this->spanbgcolorarray = $cor;
  20634. $this->spanbgcolor = true;
  20635. }
  20636. else {
  20637. $this->blk[$this->blklvl]['bgcolorarray'] = $cor;
  20638. $this->blk[$this->blklvl]['bgcolor'] = true;
  20639. }
  20640. }
  20641. else if ($type != 'INLINE' && $type != 'LIST') {
  20642. if ($this->ColActive || $this->keep_block_together) {
  20643. $this->blk[$this->blklvl]['bgcolorarray'] = $this->blk[$this->blklvl-1]['bgcolorarray'] ;
  20644. $this->blk[$this->blklvl]['bgcolor'] = $this->blk[$this->blklvl-1]['bgcolor'] ;
  20645. }
  20646. }
  20647. break;
  20648. // auto | normal | none
  20649. case 'FONT-KERNING':
  20650. if ((strtoupper($v) == 'NORMAL' || strtoupper($v) == 'AUTO') && $this->useKerning) { $this->kerning = true; }
  20651. else if (strtoupper($v) == 'NONE') { $this->kerning = false; }
  20652. break;
  20653. // normal | <length>
  20654. case 'LETTER-SPACING':
  20655. $this->lSpacingCSS = $v;
  20656. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  20657. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  20658. }
  20659. break;
  20660. // normal | <length>
  20661. case 'WORD-SPACING':
  20662. $this->wSpacingCSS = $v;
  20663. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  20664. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  20665. }
  20666. break;
  20667. case 'FONT-STYLE': // italic normal oblique
  20668. switch (strtoupper($v)) {
  20669. case 'ITALIC':
  20670. case 'OBLIQUE':
  20671. $this->SetStyle('I',true);
  20672. break;
  20673. case 'NORMAL':
  20674. $this->SetStyle('I',false);
  20675. break;
  20676. }
  20677. break;
  20678. case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100)
  20679. switch (strtoupper($v)) {
  20680. case 'BOLD':
  20681. $this->SetStyle('B',true);
  20682. break;
  20683. case 'NORMAL':
  20684. $this->SetStyle('B',false);
  20685. break;
  20686. }
  20687. break;
  20688. case 'VERTICAL-ALIGN': //super and sub only dealt with here e.g. <SUB> and <SUP>
  20689. switch (strtoupper($v)) {
  20690. case 'SUPER':
  20691. $this->SUP=true;
  20692. break;
  20693. case 'SUB':
  20694. $this->SUB=true;
  20695. break;
  20696. }
  20697. break;
  20698. case 'TEXT-DECORATION': // none underline line-through (strikeout) //Does not support: overline, blink
  20699. if (stristr($v,'LINE-THROUGH')) {
  20700. $this->strike = true;
  20701. }
  20702. if (stristr($v,'UNDERLINE')) {
  20703. $this->SetStyle('U',true);
  20704. }
  20705. break;
  20706. case 'FONT-VARIANT':
  20707. switch (strtoupper($v)) {
  20708. case 'SMALL-CAPS':
  20709. $this->SetStyle('S',true);
  20710. break;
  20711. case 'NORMAL':
  20712. $this->SetStyle('S',false);
  20713. break;
  20714. }
  20715. break;
  20716. case 'TEXT-TRANSFORM': // none uppercase lowercase //Does support: capitalize
  20717. switch (strtoupper($v)) { //Not working 100%
  20718. case 'CAPITALIZE':
  20719. $this->capitalize=true;
  20720. break;
  20721. case 'UPPERCASE':
  20722. $this->toupper=true;
  20723. break;
  20724. case 'LOWERCASE':
  20725. $this->tolower=true;
  20726. break;
  20727. case 'NONE': break;
  20728. }
  20729. break;
  20730. case 'TEXT-SHADOW':
  20731. $ts = $this->setCSStextshadow($v);
  20732. if ($ts) { $this->textshadow = $ts; }
  20733. break;
  20734. case 'OUTLINE-WIDTH':
  20735. switch(strtoupper($v)) {
  20736. case 'THIN': $v = '0.03em'; break;
  20737. case 'MEDIUM': $v = '0.05em'; break;
  20738. case 'THICK': $v = '0.07em'; break;
  20739. }
  20740. $this->outlineparam['WIDTH'] = $this->ConvertSize($v,$this->blk[$this->blklvl]['inner_width'],$this->FontSize);
  20741. break;
  20742. case 'OUTLINE-COLOR':
  20743. if (strtoupper($v) == 'INVERT') {
  20744. if ($this->colorarray) {
  20745. $cor = $this->colorarray;
  20746. $this->outlineparam['COLOR'] = $this->_invertColor($cor);
  20747. }
  20748. else {
  20749. $this->outlineparam['COLOR'] = $this->ConvertColor(255);
  20750. }
  20751. }
  20752. else {
  20753. $cor = $this->ConvertColor($v);
  20754. if ($cor) { $this->outlineparam['COLOR'] = $cor ; }
  20755. }
  20756. break;
  20757. case 'COLOR': // font color
  20758. $cor = $this->ConvertColor($v);
  20759. if ($cor) {
  20760. $this->colorarray = $cor;
  20761. $this->SetTColor($cor);
  20762. }
  20763. break;
  20764. }//end of switch($k)
  20765. }//end of foreach
  20766. }
  20767. /*-- END HTML-CSS --*/
  20768. function SetStyle($tag,$enable) {
  20769. $this->$tag=$enable;
  20770. $style='';
  20771. foreach(array('B','I','U','S') as $s) {
  20772. if($this->$s) {
  20773. $style.=$s;
  20774. }
  20775. }
  20776. if ($this->S && empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); }
  20777. $this->currentfontstyle=$style;
  20778. $this->SetFont('',$style,0,false);
  20779. }
  20780. // Set multiple styles at one $str e.g. "BIS"
  20781. function SetStylesArray($arr) {
  20782. $style='';
  20783. foreach(array('B','I','U','S') as $s) {
  20784. if (isset($arr[$s])) {
  20785. if ($arr[$s]) {
  20786. $this->$s = true;
  20787. $style.=$s;
  20788. }
  20789. else { $this->$s = false; }
  20790. }
  20791. else if ($this->$s) { $style.=$s; }
  20792. }
  20793. $this->currentfontstyle=$style;
  20794. $this->SetFont('',$style,0,false);
  20795. }
  20796. // Set multiple styles at one $str e.g. "BIS"
  20797. function SetStyles($str) {
  20798. $style='';
  20799. foreach(array('B','I','U','S') as $s) {
  20800. if (strpos($str,$s) !== false) {
  20801. $this->$s = true;
  20802. $style.=$s;
  20803. }
  20804. else { $this->$s = false; }
  20805. }
  20806. $this->currentfontstyle=$style;
  20807. $this->SetFont('',$style,0,false);
  20808. }
  20809. function ResetStyles() {
  20810. foreach(array('B','I','U','S') as $s) {
  20811. $this->$s = false;
  20812. }
  20813. $this->currentfontstyle='';
  20814. $this->SetFont('','',0,false);
  20815. }
  20816. function DisableTags($str='')
  20817. {
  20818. if ($str == '') //enable all tags
  20819. {
  20820. //Insert new supported tags in the long string below.
  20821. $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
  20822. }
  20823. else
  20824. {
  20825. $str = explode(",",$str);
  20826. foreach($str as $v) $this->enabledtags = str_replace(trim($v),'',$this->enabledtags);
  20827. }
  20828. }
  20829. /*-- TABLES --*/
  20830. function finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight) {
  20831. $af = 0; // Above font
  20832. $bf = 0; // Below font
  20833. $mta = 0; // Maximum top-aligned
  20834. $mba = 0; // Maximum bottom-aligned
  20835. if ($lhxt['BS']) {
  20836. $af = max($af, ($lhxt['BS'] - ($maxfontsize * (0.5 + $this->baselineC))));
  20837. }
  20838. if ($lhxt['M']) {
  20839. $af = max($af, ($lhxt['M'] - $maxfontsize)/2);
  20840. $bf = max($bf, ($lhxt['M'] - $maxfontsize)/2);
  20841. }
  20842. if ($lhxt['TT']) {
  20843. $bf = max($bf, ($lhxt['TT'] - $maxfontsize));
  20844. }
  20845. if ($lhxt['TB']) {
  20846. $af = max($af, ($lhxt['TB'] - $maxfontsize));
  20847. }
  20848. if ($lhxt['T']) {
  20849. $mta = max($mta, $lhxt['T']);
  20850. }
  20851. if ($lhxt['B']) {
  20852. $mba = max($mba, $lhxt['B']);
  20853. }
  20854. if ((!$lhfixed || !$forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  20855. $maxlineHeight = $maxfontsize + $af + $bf;
  20856. }
  20857. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  20858. if ($mta > $maxlineHeight) {
  20859. $bf += ($mta - $maxlineHeight);
  20860. $maxlineHeight = $mta;
  20861. }
  20862. if ($mba > $maxlineHeight) {
  20863. $af += ($mba - $maxlineHeight);
  20864. $maxlineHeight = $mba;
  20865. }
  20866. return $maxlineHeight;
  20867. }
  20868. function TableWordWrap($maxwidth, $forcewrap = 0, $textbuffer = '', $def_fontsize, $returnarray=false) { // NB ** returnarray used in flowchart
  20869. $biggestword=0;
  20870. $toonarrow=false;
  20871. $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  20872. $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  20873. // mPDF 5.5.07
  20874. $raquote = mb_convert_encoding("\xc2\xbb",$this->mb_enc,'UTF-8');
  20875. // mPDF 5.5.20
  20876. $rsquo = mb_convert_encoding("\xe2\x80\x99",$this->mb_enc,'UTF-8'); //&#8217; &rsquo;
  20877. $sbquo = mb_convert_encoding("\xe2\x80\x9a",$this->mb_enc,'UTF-8'); //&#8218; &sbquo;
  20878. $bdquo = mb_convert_encoding("\xe2\x80\xba",$this->mb_enc,'UTF-8'); //&#8222; &bdquo;
  20879. $textbuffer[0][0] = preg_replace('/^[ ]*/','',$textbuffer[0][0]);
  20880. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  20881. $text = '';
  20882. $lhfixed = false;
  20883. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight)) { $lhfixed = true; }
  20884. if ($lhfixed) { $def_lineheight = $this->_computeLineheight($this->table_lineheight, $def_fontsize);}
  20885. else { $def_lineheight = 0; }
  20886. // START OF NEW LINE
  20887. // Initialise lineheight variables
  20888. $maxfontsize = 0;
  20889. $forceExactLineheight = true;
  20890. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20891. $maxlineHeight = $def_lineheight ;
  20892. $ch = 0;
  20893. $width = 0;
  20894. $ln = 1; // Counts line number
  20895. $mxw = $this->GetCharWidth('W',false);
  20896. foreach ($textbuffer as $cctr=>$chunk) {
  20897. $line = $chunk[0];
  20898. //IMAGE
  20899. if (substr($line,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  20900. $objattr = $this->_getObjAttr($line);
  20901. if ($objattr['type'] == 'nestedtable') {
  20902. // END OF LINE
  20903. // Finalise & add lineheight
  20904. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20905. $level = $objattr['level'];
  20906. $ih = $this->table[($level+1)][$objattr['nestedcontent']]['h']; // nested table width
  20907. $ch += $ih;
  20908. // START OF NEW LINE
  20909. // Initialise lineheight variables
  20910. $ln++;
  20911. $maxfontsize = 0;
  20912. $forceExactLineheight = true;
  20913. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20914. $maxlineHeight = $def_lineheight ;
  20915. $width = 0;
  20916. $text = "";
  20917. continue;
  20918. }
  20919. list($skipln,$iw,$ih) = $this->inlineObject((isset($specialcontent['type']) ? $specialcontent['type'] : null),0,0, $objattr, $this->lMargin,$width,$maxwidth,$maxlineHeight,false,true);
  20920. if ($objattr['type'] == 'hr') {
  20921. // END OF LINE
  20922. // Finalise & add lineheight
  20923. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20924. // Add HR height
  20925. $ch += $ih;
  20926. // START OF NEW LINE
  20927. // Initialise lineheight variables
  20928. $ln++;
  20929. $maxfontsize = 0;
  20930. $forceExactLineheight = true;
  20931. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20932. $maxlineHeight = $def_lineheight ;
  20933. $width = 0;
  20934. $text = "";
  20935. continue;
  20936. }
  20937. if ($skipln==1 || $skipln==-2) {
  20938. // Finish last line
  20939. // END OF LINE
  20940. // Finalise & add lineheight
  20941. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20942. // START OF NEW LINE
  20943. // Initialise lineheight variables
  20944. $maxfontsize = 0;
  20945. $forceExactLineheight = true;
  20946. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20947. $maxlineHeight = $def_lineheight ;
  20948. $ln++;
  20949. $width = 0;
  20950. $text = "";
  20951. }
  20952. $va = (isset($objattr['vertical-align']) ? $objattr['vertical-align'] : null);
  20953. if ($va) {
  20954. $lhxt[$va] = max($lhxt[$va], $ih);
  20955. }
  20956. if ($lhfixed && $ih > $def_fontsize) { $forceExactLineheight = false; }
  20957. $maxlineHeight = max($maxlineHeight ,$ih);
  20958. $width += $iw;
  20959. continue;
  20960. }
  20961. // SET FONT SIZE/STYLE from $chunk[n]
  20962. // FONTSIZE
  20963. if(isset($chunk[11]) and $chunk[11] != '') {
  20964. if ($this->shrin_k) {
  20965. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  20966. }
  20967. else {
  20968. $this->SetFontSize($chunk[11],false);
  20969. }
  20970. }
  20971. if ($line == "\n") {
  20972. // END OF LINE
  20973. $maxfontsize = max($maxfontsize,$this->FontSize);
  20974. $fh = $this->_computeLineheight($this->table_lineheight);
  20975. if ($lhfixed && $this->FontSize > $def_fontsize) {
  20976. $fh = $this->FontSize;
  20977. $forceExactLineheight = false;
  20978. }
  20979. $maxlineHeight = max($maxlineHeight,$fh);
  20980. // Finalise & add lineheight
  20981. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  20982. // START OF NEW LINE
  20983. // Initialise lineheight variables
  20984. $maxfontsize = 0;
  20985. $forceExactLineheight = true;
  20986. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  20987. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  20988. $ln++;
  20989. $text = "";
  20990. $width = 0;
  20991. if(isset($chunk[11]) and $chunk[11] != '') {
  20992. $this->SetFontSize($this->default_font_size,false);
  20993. }
  20994. continue;
  20995. }
  20996. $lbw = $rbw = 0; // Border widths
  20997. if(isset($chunk[16]) && !empty($chunk[16])) { //Border
  20998. $this->spanborddet = $chunk[16];
  20999. if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w'];
  21000. if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w'];
  21001. }
  21002. if(isset($chunk[15])) { // Word spacing
  21003. $this->wSpacingCSS = $chunk[15];
  21004. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  21005. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  21006. }
  21007. }
  21008. if(isset($chunk[14])) { // Letter spacing
  21009. $this->lSpacingCSS = $chunk[14];
  21010. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  21011. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  21012. }
  21013. }
  21014. if(isset($chunk[13])) { // Font Kerning
  21015. $this->kerning = $chunk[13];
  21016. }
  21017. // FONTFAMILY
  21018. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  21019. // FONT STYLE B I U
  21020. if(isset($chunk[2]) and $chunk[2] != '') {
  21021. $this->SetStyles($chunk[2]);
  21022. }
  21023. $space = $this->GetCharWidth(' ',false);
  21024. if (mb_substr($line,0,1,$this->mb_enc ) == ' ') { // line (chunk) starts with a space
  21025. $width += $space;
  21026. $text .= ' ';
  21027. }
  21028. if (mb_substr($line,(mb_strlen($line,$this->mb_enc )-1),1,$this->mb_enc ) == ' ') { $lsend = true; } // line (chunk) ends with a space
  21029. else { $lsend = false; }
  21030. $line= trim($line);
  21031. if ($line == '') { continue; }
  21032. // mPDF ITERATION
  21033. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  21034. if (!$this->usingCoreFont) { $matchsuff="u"; } else { $matchsuff=""; } // mPDF.5.5.05
  21035. $words = explode(' ', $line);
  21036. foreach ($words as $k=>$word) {
  21037. $word = trim($word);
  21038. $wordwidth = $this->GetStringWidth($word);
  21039. if ($k==0) { $wordwidth += $lbw; }
  21040. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  21041. //maxwidth is insufficient for one word
  21042. if ($wordwidth > $maxwidth + 0.0001) {
  21043. $firstchunk=true;
  21044. while($wordwidth > $maxwidth + 0.0001) {
  21045. $chw = 0; // check width
  21046. $oneCJKorphan = false;
  21047. $mlen = mb_strlen($word, $this->mb_enc );
  21048. for ( $i = 0; $i < $mlen; $i++ ) {
  21049. $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  21050. if ($k==0) { $chw += $lbw; }
  21051. if ($k==(count($words)-1)) { $chw += $rbw; }
  21052. if ($chw > $maxwidth) {
  21053. if ($i==0 && $firstchunk) {
  21054. // If first letter of line does not fit
  21055. $wordwidth = $maxwidth - 0.0001;
  21056. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for one character!"); }
  21057. break;
  21058. }
  21059. if (!$oneCJKorphan && (preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote . $raquote.$rsquo.$sbquo.$bdquo.']$/'.$matchsuff,mb_substr($word,0,$i+1,$this->mb_enc )) || (!$this->usingCoreFont && preg_match('/['.$this->CJKoverflow.']$/u',mb_substr($word,0,$i+1,$this->mb_enc ))))) { // mPDF.5.5.01 mPDF.5.5.05 mPDF 5.5.07 // mPDF 5.5.20
  21060. $wordwidth = $maxwidth - 0.0001;
  21061. $oneCJKorphan = true;
  21062. continue;
  21063. }
  21064. if ($text && $firstchunk) {
  21065. // END OF LINE
  21066. // Finalise & add lineheight
  21067. $maxfontsize = max($maxfontsize,$this->FontSize);
  21068. $fh = $this->_computeLineheight($this->table_lineheight);
  21069. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21070. $fh = $this->FontSize;
  21071. $forceExactLineheight = false;
  21072. }
  21073. $maxlineHeight = max($maxlineHeight,$fh);
  21074. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21075. // START OF NEW LINE
  21076. // Initialise lineheight variables
  21077. $maxfontsize = $this->FontSize;
  21078. $forceExactLineheight = true;
  21079. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  21080. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  21081. $ln++;
  21082. }
  21083. // END OF LINE
  21084. // Finalise & add lineheight
  21085. $maxfontsize = max($maxfontsize,$this->FontSize);
  21086. $fh = $this->_computeLineheight($this->table_lineheight);
  21087. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21088. $fh = $this->FontSize;
  21089. $forceExactLineheight = false;
  21090. }
  21091. $maxlineHeight = max($maxlineHeight,$fh);
  21092. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21093. // START OF NEW LINE
  21094. // Initialise lineheight variables
  21095. $maxfontsize = $this->FontSize;
  21096. $forceExactLineheight = true;
  21097. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  21098. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  21099. $ln++;
  21100. $mxw = $maxwidth;
  21101. $text = mb_substr($word,0,$i,$this->mb_enc );
  21102. $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  21103. $wordwidth = $this->GetStringWidth($word);
  21104. $width = 0;
  21105. $firstchunk=false;
  21106. break;
  21107. }
  21108. }
  21109. if (mb_strlen($word, $this->mb_enc )<2 && $wordwidth > $maxwidth + 0.0001) {
  21110. $wordwidth = $maxwidth - 0.0001;
  21111. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for single character!"); }
  21112. }
  21113. $firstchunk=false;
  21114. }
  21115. }
  21116. // Word fits on line...
  21117. if ($width + $wordwidth < $maxwidth + 0.0001) {
  21118. $mxw = max($mxw, ($width+$wordwidth));
  21119. $width += $wordwidth + $space;
  21120. $text .= $word.' ';
  21121. }
  21122. // Word does not fit on line...
  21123. else {
  21124. $alloworphans = false;
  21125. // In case of orphan punctuation or SUB/SUP
  21126. // Strip end punctuation
  21127. $tmp = preg_replace('/[\.\]),;:!?"'.$curlyquote . $curlylowquote . $raquote.$rsquo.$sbquo.$bdquo.']{1}$/'.$matchsuff,'',$word); // mPDF.5.5.01 mPDF.5.5.05 mPDF 5.5.07 // mPDF 5.5.20
  21128. if (!$this->usingCoreFont) { $tmp = preg_replace('/['.$this->CJKoverflow.']{1}$/u','',$tmp); } // *CJK-FONTS*
  21129. if ($tmp !== $word && (($this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote . $raquote.$rsquo.$sbquo.$bdquo.']$/',$tmp)) || (!$this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote . $raquote.$rsquo.$sbquo.$bdquo .$this->CJKoverflow.']$/u',$tmp)))) { // mPDF 5.5.07 // mPDF 5.5.20
  21130. $tmpwidth = $this->GetStringWidth($tmp);
  21131. if ($k==0) { $tmpwidth += $lbw; }
  21132. if ($k==(count($words)-1)) { $tmpwidth += $rbw; }
  21133. if ($width + $tmpwidth < $maxwidth + 0.0001) { $alloworphans = true; }
  21134. }
  21135. // If line = SUB/SUP to max of orphansallowed ( $this->SUP || $this->SUB )
  21136. if(( (isset($chunk[5]) and $chunk[5]) || (isset($chunk[6]) and $chunk[6])) && strlen($word) <= $this->orphansAllowed) {
  21137. $alloworphans = true;
  21138. if ($k==1) { echo $word; exit; }
  21139. }
  21140. // if [stripped] word fits
  21141. if ($alloworphans) {
  21142. $mxw = $maxwidth;
  21143. $width += $wordwidth + $space;
  21144. $text .= $word.' ';
  21145. }
  21146. else {
  21147. /*-- HYPHENATION --*/
  21148. // Soft Hyphens chr(173)
  21149. if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$word)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$word) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) {
  21150. list($success,$pre,$post,$prelength) = $this->softHyphenate($word, ($maxwidth - $width));
  21151. if ($success) {
  21152. $text .= $pre.'-';
  21153. $word = $post;
  21154. $wordwidth = $this->GetStringWidth($word);
  21155. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  21156. }
  21157. }
  21158. else if ($this->hyphenate || ($this->hyphenateTables)) {
  21159. list($success,$pre,$post,$prelength) = $this->hyphenateWord($word, ($maxwidth - $width));
  21160. if ($success) {
  21161. $text .= $pre.'-';
  21162. $word = $post;
  21163. $wordwidth = $this->GetStringWidth($word);
  21164. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  21165. }
  21166. }
  21167. /*-- END HYPHENATION --*/
  21168. // END OF LINE
  21169. // Finalise & add lineheight
  21170. $maxfontsize = max($maxfontsize,$this->FontSize);
  21171. $fh = $this->_computeLineheight($this->table_lineheight);
  21172. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21173. $fh = $this->FontSize;
  21174. $forceExactLineheight = false;
  21175. }
  21176. $maxlineHeight = max($maxlineHeight,$fh);
  21177. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21178. $mxw = $maxwidth;
  21179. // START OF NEW LINE
  21180. // Initialise lineheight variables
  21181. $maxfontsize = $this->FontSize;
  21182. $forceExactLineheight = true;
  21183. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  21184. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  21185. $ln++;
  21186. $width = $wordwidth + $space;
  21187. $text = $word.' ';
  21188. }
  21189. }
  21190. $maxfontsize = max($maxfontsize,$this->FontSize);
  21191. $fh = $this->_computeLineheight($this->table_lineheight);
  21192. if ($lhfixed && $this->FontSize > $def_fontsize) {
  21193. $fh = $this->FontSize;
  21194. $forceExactLineheight = false;
  21195. }
  21196. $maxlineHeight = max($maxlineHeight,$fh);
  21197. }
  21198. // End of textbuffer chunk
  21199. if (!$lsend) {
  21200. $width -= $space;
  21201. $text = rtrim($text);
  21202. }
  21203. // RESET FONT SIZE/STYLE
  21204. // RESETTING VALUES
  21205. //Now we must deactivate what we have used
  21206. if(isset($chunk[2]) and $chunk[2] != '') {
  21207. $this->ResetStyles();
  21208. }
  21209. if(isset($chunk[4]) and $chunk[4] != '') {
  21210. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  21211. }
  21212. if(isset($chunk[11]) and $chunk[11] != '') {
  21213. $this->SetFontSize($this->default_font_size,false);
  21214. }
  21215. $this->spanborddet = array();
  21216. $this->kerning = false;
  21217. $this->lSpacingCSS = '';
  21218. $this->wSpacingCSS = '';
  21219. $this->fixedlSpacing = false;
  21220. $this->minwSpacing = 0;
  21221. }
  21222. // Finalise lineheight if something output on line and add
  21223. if ($width) {
  21224. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  21225. }
  21226. if ($returnarray) { return array($ch,$ln,$mxw); }
  21227. else { return $ch; }
  21228. }
  21229. function TableCheckMinWidth($maxwidth, $forcewrap = 0, $textbuffer) {
  21230. $biggestword=0;
  21231. $toonarrow=false;
  21232. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  21233. foreach ($textbuffer as $chunk) {
  21234. $line = $chunk[0];
  21235. // mPDF ITERATION
  21236. if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line);
  21237. // IMAGES & FORM ELEMENTS
  21238. if (substr($line,0,3) == "\xbb\xa4\xac") { //inline object - FORM element or IMAGE!
  21239. $objattr = $this->_getObjAttr($line);
  21240. if ($objattr['type']!='hr' && isset($objattr['width']) && ($objattr['width']/$this->shrin_k) > ($maxwidth + 0.0001) ) {
  21241. if (($objattr['width']/$this->shrin_k) > $biggestword) { $biggestword = ($objattr['width']/$this->shrin_k); }
  21242. $toonarrow=true;
  21243. }
  21244. continue;
  21245. }
  21246. if ($line == "\n") {
  21247. continue;
  21248. }
  21249. $line = trim($line );
  21250. // SET FONT SIZE/STYLE from $chunk[n]
  21251. // FONTSIZE
  21252. if(isset($chunk[11]) and $chunk[11] != '') {
  21253. if ($this->shrin_k) {
  21254. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  21255. }
  21256. else {
  21257. $this->SetFontSize($chunk[11],false);
  21258. }
  21259. }
  21260. // FONTFAMILY
  21261. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  21262. // B I U
  21263. if(isset($chunk[2]) and $chunk[2] != '') {
  21264. $this->SetStyles($chunk[2]);
  21265. }
  21266. $lbw = $rbw = 0; // Border widths
  21267. if(isset($chunk[16]) && !empty($chunk[16])) { //Border
  21268. $this->spanborddet = $chunk[16];
  21269. $lbw = $this->spanborddet['L']['w'];
  21270. $rbw = $this->spanborddet['R']['w'];
  21271. }
  21272. if(isset($chunk[15])) { // Word spacing
  21273. $this->wSpacingCSS = $chunk[15];
  21274. if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
  21275. $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize);
  21276. }
  21277. }
  21278. if(isset($chunk[14])) { // Letter spacing
  21279. $this->lSpacingCSS = $chunk[14];
  21280. if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
  21281. $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize);
  21282. }
  21283. }
  21284. if(isset($chunk[13])) { // Font Kerning
  21285. $this->kerning = $chunk[13];
  21286. }
  21287. $words = explode(' ', $line);
  21288. foreach ($words as $k=>$word) {
  21289. $word = trim($word);
  21290. $wordwidth = $this->GetStringWidth($word);
  21291. if ($k==0) { $wordwidth += $lbw; }
  21292. if ($k==(count($words)-1)) { $wordwidth += $rbw; }
  21293. //Warn user that maxwidth is insufficient
  21294. if ($wordwidth > $maxwidth + 0.0001) {
  21295. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  21296. $toonarrow=true;
  21297. }
  21298. }
  21299. // RESET FONT SIZE/STYLE
  21300. // RESETTING VALUES
  21301. //Now we must deactivate what we have used
  21302. if(isset($chunk[2]) and $chunk[2] != '') {
  21303. $this->ResetStyles();
  21304. }
  21305. if(isset($chunk[4]) and $chunk[4] != '') {
  21306. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  21307. }
  21308. if(isset($chunk[11]) and $chunk[11] != '') {
  21309. $this->SetFontSize($this->default_font_size,false);
  21310. }
  21311. $this->spanborddet = array();
  21312. $this->kerning = false;
  21313. $this->lSpacingCSS = '';
  21314. $this->wSpacingCSS = '';
  21315. $this->fixedlSpacing = false;
  21316. $this->minwSpacing = 0;
  21317. }
  21318. //Return -(wordsize) if word is bigger than maxwidth
  21319. // ADDED
  21320. if (($toonarrow) && ($this->table_error_report)) {
  21321. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  21322. }
  21323. if ($toonarrow) return -$biggestword;
  21324. else return 1;
  21325. }
  21326. function shrinkTable(&$table,$k) {
  21327. $table['border_spacing_H'] /= $k;
  21328. $table['border_spacing_V'] /= $k;
  21329. $table['padding']['T'] /= $k;
  21330. $table['padding']['R'] /= $k;
  21331. $table['padding']['B'] /= $k;
  21332. $table['padding']['L'] /= $k;
  21333. $table['margin']['T'] /= $k;
  21334. $table['margin']['R'] /= $k;
  21335. $table['margin']['B'] /= $k;
  21336. $table['margin']['L'] /= $k;
  21337. $table['border_details']['T']['w'] /= $k;
  21338. $table['border_details']['R']['w'] /= $k;
  21339. $table['border_details']['B']['w'] /= $k;
  21340. $table['border_details']['L']['w'] /= $k;
  21341. if (isset($table['max_cell_border_width']['T'])) $table['max_cell_border_width']['T'] /= $k;
  21342. if (isset($table['max_cell_border_width']['R'])) $table['max_cell_border_width']['R'] /= $k;
  21343. if (isset($table['max_cell_border_width']['B'])) $table['max_cell_border_width']['B'] /= $k;
  21344. if (isset($table['max_cell_border_width']['L'])) $table['max_cell_border_width']['L'] /= $k;
  21345. if ($this->simpleTables){
  21346. $table['simple']['border_details']['T']['w'] /= $k;
  21347. $table['simple']['border_details']['R']['w'] /= $k;
  21348. $table['simple']['border_details']['B']['w'] /= $k;
  21349. $table['simple']['border_details']['L']['w'] /= $k;
  21350. }
  21351. $table['miw'] /= $k;
  21352. $table['maw'] /= $k;
  21353. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  21354. for($j = 0 ; $j < $table['nc'] ; $j++ ) { //columns
  21355. $table['wc'][$j]['miw'] /= $k;
  21356. $table['wc'][$j]['maw'] /= $k;
  21357. if (isset($table['wc'][$j]['absmiw']) && $table['wc'][$j]['absmiw'] ) $table['wc'][$j]['absmiw'] /= $k;
  21358. for($i = 0 ; $i < $table['nr']; $i++ ) { //rows
  21359. if ($this->cacheTables) {
  21360. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21361. }
  21362. else
  21363. $c = &$table['cells'][$i][$j];
  21364. if (isset($c) && $c) {
  21365. if (!$this->simpleTables){
  21366. if ($this->packTableData) {
  21367. $cell = $this->_unpackCellBorder($c['borderbin'] );
  21368. $cell['border_details']['T']['w'] /= $k;
  21369. $cell['border_details']['R']['w'] /= $k;
  21370. $cell['border_details']['B']['w'] /= $k;
  21371. $cell['border_details']['L']['w'] /= $k;
  21372. $cell['border_details']['mbw']['TL'] /= $k;
  21373. $cell['border_details']['mbw']['TR'] /= $k;
  21374. $cell['border_details']['mbw']['BL'] /= $k;
  21375. $cell['border_details']['mbw']['BR'] /= $k;
  21376. $cell['border_details']['mbw']['LT'] /= $k;
  21377. $cell['border_details']['mbw']['LB'] /= $k;
  21378. $cell['border_details']['mbw']['RT'] /= $k;
  21379. $cell['border_details']['mbw']['RB'] /= $k;
  21380. $c['borderbin'] = $this->_packCellBorder($cell);
  21381. }
  21382. else {
  21383. $c['border_details']['T']['w'] /= $k;
  21384. $c['border_details']['R']['w'] /= $k;
  21385. $c['border_details']['B']['w'] /= $k;
  21386. $c['border_details']['L']['w'] /= $k;
  21387. $c['border_details']['mbw']['TL'] /= $k;
  21388. $c['border_details']['mbw']['TR'] /= $k;
  21389. $c['border_details']['mbw']['BL'] /= $k;
  21390. $c['border_details']['mbw']['BR'] /= $k;
  21391. $c['border_details']['mbw']['LT'] /= $k;
  21392. $c['border_details']['mbw']['LB'] /= $k;
  21393. $c['border_details']['mbw']['RT'] /= $k;
  21394. $c['border_details']['mbw']['RB'] /= $k;
  21395. }
  21396. }
  21397. $c['padding']['T'] /= $k;
  21398. $c['padding']['R'] /= $k;
  21399. $c['padding']['B'] /= $k;
  21400. $c['padding']['L'] /= $k;
  21401. $c['maxs'] /= $k;
  21402. if (isset($c['w'])) { $c['w'] /= $k; }
  21403. $c['s'] /= $k;
  21404. $c['maw'] /= $k;
  21405. $c['miw'] /= $k;
  21406. if (isset($c['absmiw'])) $c['absmiw'] /= $k;
  21407. if (isset($c['nestedmaw'])) $c['nestedmaw'] /= $k;
  21408. if (isset($c['nestedmiw'])) $c['nestedmiw'] /= $k;
  21409. if (isset($c['textbuffer'])) {
  21410. foreach($c['textbuffer'] AS $n=>$tb) {
  21411. if (!empty($tb[16])) {
  21412. $c['textbuffer'][$n][16]['T']['w'] /= $k;
  21413. $c['textbuffer'][$n][16]['B']['w'] /= $k;
  21414. $c['textbuffer'][$n][16]['L']['w'] /= $k;
  21415. $c['textbuffer'][$n][16]['R']['w'] /= $k;
  21416. }
  21417. }
  21418. }
  21419. if ($this->cacheTables) {
  21420. $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]);
  21421. }
  21422. unset($c);
  21423. }
  21424. }//rows
  21425. }//columns
  21426. if ($this->cacheTables) { fclose($fh); }
  21427. }
  21428. function _cacheCell($c, $file, $mode="A", $fh=null, $offset=0) { // mode = Append or (over)Write (needs offset and fh)
  21429. // Requires either $file OR $fh (file_handle)
  21430. if (!is_array($c) || !isset($c)) { return ''; }
  21431. if(isset($c['w'])) { $cw = $c['w']; } else { $cw = -1; }
  21432. if(isset($c['w0'])) { $cw0 = $c['w0']; } else { $cw0 = -1; }
  21433. if(isset($c['h0'])) { $ch0 = $c['h0']; } else { $ch0 = -1; }
  21434. $data = pack("n2d19A1A1n2sA32A128",
  21435. $c['colspan'], /* n (16 bit; 2 bytes) [pos 0] */
  21436. $c['rowspan'], /* n (16 bit; 2 bytes) [pos 2] */
  21437. $c['s'], /* d NB machine-dependent size (64 bit; 8 bytes on test winOS) [pos 4] */
  21438. $c['maxs'], /* d NB machine-dependent size [pos 4 + 1*D] */
  21439. $c['nestedmaw'], /* d NB machine-dependent size [pos 4 + 2*D] */
  21440. $c['nestedmiw'], /* d NB machine-dependent size [pos 4 + 3*D] */
  21441. $c['padding']['L'], /* d NB machine-dependent size [pos 4 + 4*D] */
  21442. $c['padding']['R'], /* d NB machine-dependent size [pos 4 + 5*D] */
  21443. $c['padding']['T'], /* d NB machine-dependent size [pos 4 + 6*D] */
  21444. $c['padding']['B'], /* d NB machine-dependent size [pos 4 + 7*D] */
  21445. $c['dfs'], /* d NB machine-dependent size [pos 4 + 8*D] */
  21446. $cw, /* d NB machine-dependent size [pos 4 + 9*D] */
  21447. $c['h'], /* d NB machine-dependent size [pos 4 + 10*D] */
  21448. $c['absmiw'], /* d NB machine-dependent size [pos 4 + 11*D] */
  21449. $c['maw'], /* d NB machine-dependent size [pos 4 + 12*D] */
  21450. $c['miw'], /* d NB machine-dependent size [pos 4 + 13*D] */
  21451. $c['mih'], /* d NB machine-dependent size [pos 4 + 14*D] */
  21452. $c['x0'], /* d NB machine-dependent size [pos 4 + 15*D] */
  21453. $cw0, /* d NB machine-dependent size [pos 4 + 16*D] */
  21454. $c['y0'], /* d NB machine-dependent size [pos 4 + 17*D] */
  21455. $ch0, /* d NB machine-dependent size [pos 4 + 18*D] */
  21456. $c['a'], /* A1 (1 byte) [pos 4 + 19*D] */
  21457. $c['va'], /* A1 (1 byte) [pos 5 + 19*D] */
  21458. $c['nowrap'], /* 1 or blank n (16 bit; 2 bytes) [pos 6 + 19*D] */
  21459. $c['wpercent'], /* 0 - 100 n (16 bit; 2 bytes) [pos 8 + 19*D] */
  21460. $c['R'], /* 90 or -90 s (16 bit; 2 bytes) [pos 10 + 19*D] */
  21461. $c['bgcolor'], /* A32 (32 bytes) [pos 12 + 19*D] */
  21462. $c['gradient'] /* A128 (128 bytes) [pos 44 + 19*D] */
  21463. );
  21464. if ($c['background-image']) {
  21465. $data .= pack("n2d2A6A6n3dA4A128",
  21466. strlen($data), /* offset in main data to start of bgimage data */
  21467. $c['background-image']['image_id'], /* n */
  21468. $c['background-image']['orig_w'], /* d NB machine-dependent size */
  21469. $c['background-image']['orig_h'], /* d NB machine-dependent size */
  21470. $c['background-image']['x_pos'], /* A6 calc size or "50%" */
  21471. $c['background-image']['y_pos'], /* A6 calc size or "50%" */
  21472. $c['background-image']['x_repeat'], /* n true or false*/
  21473. $c['background-image']['y_repeat'], /* n true or false */
  21474. $c['background-image']['resize'], /* n 0 - 6 */
  21475. $c['background-image']['opacity'], /* d 0-1 */
  21476. $c['background-image']['itype'], /* A4 jpg etc */
  21477. $c['background-image']['gradient'] /* A128 CSS string */
  21478. );
  21479. }
  21480. else $data .= pack("n",0);
  21481. $tb_offset = 2 + 186 + 2 + strlen($data);
  21482. $stb = serialize($c['textbuffer']).' '; // buffer to allow updating in reverseTableDir
  21483. $lentb = strlen($stb);
  21484. $data2 = pack("nA".$lentb, $lentb, $stb);
  21485. $tempfh = true;
  21486. if ($mode=="W" && $offset) {
  21487. if (!$fh) { $fh = fopen($file, "r+b"); } // Overwrite (but not truncate)
  21488. else $tempfh = false;
  21489. fseek($fh, $offset);
  21490. }
  21491. else {
  21492. $fh = fopen($file, "ab"); // APPEND
  21493. }
  21494. fwrite($fh, pack("n",$tb_offset)); // Offset to Text buffer 2 bytes
  21495. fwrite($fh, $c['borderbin']); // border details 186 bytes
  21496. fwrite($fh, pack("n",strlen($data))); // Length of Main data
  21497. fwrite($fh, $data); // Main data
  21498. fwrite($fh, $data2); // Text buffer (starts with "n" length of text buffer)
  21499. if ($tempfh) fclose($fh);
  21500. return ($tb_offset + 2 + $lentb);
  21501. }
  21502. function _cacheUpdateTxB($c, $fh, $offset) {
  21503. fseek($fh, $offset);
  21504. $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes
  21505. fseek($fh, ($tb_offset-2), SEEK_CUR);
  21506. $lentb = $this->read_short($fh); // First entry in textbuffer = Length of serialized textbuffer - do not update
  21507. $stb = serialize($c['textbuffer']);
  21508. fwrite($fh, pack("A".$lentb, $stb));
  21509. }
  21510. function _cacheUpdateBorder($c, $fh, $offset) {
  21511. $offset += 2;
  21512. fseek($fh, $offset);
  21513. fwrite($fh, $c['borderbin']);
  21514. }
  21515. function _cacheUpdateMtx($c, $fh, $offset, $var) {
  21516. if ($var=='mih') { $offset += (2 + 186 + 2 + 4 + 14*_DSIZE); }
  21517. else if ($var=='x0') { $offset += (2 + 186 + 2 + 4 + 15*_DSIZE); } // x0 and w0
  21518. else if ($var=='y0') { $offset += (2 + 186 + 2 + 4 + 17*_DSIZE); } // y0 and h0
  21519. fseek($fh, $offset);
  21520. if ($var=='mih') { fwrite($fh, pack("d",$c['mih'])); }
  21521. else if ($var=='x0') { fwrite($fh, pack("d2",$c['x0'],$c['w0'])); }
  21522. else if ($var=='y0') { fwrite($fh, pack("d2",$c['y0'],$c['h0'])); }
  21523. }
  21524. function _uncacheCell($ptr, $file, $fh) {
  21525. // Requires either $file or $fh (file_handle)
  21526. if ($ptr==0) { return null; }
  21527. 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 "); }
  21528. $tempfh = true;
  21529. if (!$fh) { $fh = fopen($file, "rb"); }
  21530. else $tempfh = false;
  21531. fseek($fh, $ptr);
  21532. $c = array();
  21533. $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes
  21534. $c['borderbin'] = fread($fh,186); // border details 186 bytes
  21535. $maindatalen = $this->read_short($fh); // Length of Main data (2 bytes)
  21536. $str = fread($fh,$maindatalen ); // Main data
  21537. $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);
  21538. if ($data['colspan']>0) $c['colspan'] = $data['colspan']; /* n */
  21539. if ($data['rowspan']>0) $c['rowspan'] = $data['rowspan']; /* n */
  21540. $c['s'] = $data['s']; /* d NB machine-dependent size */
  21541. $c['maxs'] = $data['maxs']; /* d NB machine-dependent size */
  21542. if ($data['nmaw']>0) $c['nestedmaw'] = $data['nmaw']; /* d NB machine-dependent size */
  21543. if ($data['nmiw']>0) $c['nestedmiw'] = $data['nmiw']; /* d NB machine-dependent size */
  21544. $c['padding']['L'] = $data['pl']; /* d NB machine-dependent size */
  21545. $c['padding']['R'] = $data['pr']; /* d NB machine-dependent size */
  21546. $c['padding']['T'] = $data['pt']; /* d NB machine-dependent size */
  21547. $c['padding']['B'] = $data['pb']; /* d NB machine-dependent size */
  21548. $c['dfs'] = $data['dfs']; /* d NB machine-dependent size */
  21549. if ($data['w']>=0) $c['w'] = $data['w']; /* d NB machine-dependent size */
  21550. if ($data['h']>0) $c['h'] = $data['h']; /* d NB machine-dependent size */
  21551. if ($data['absmiw']>0) $c['absmiw'] = $data['absmiw']; /* d NB machine-dependent size */
  21552. if ($data['maw']>0) $c['maw'] = $data['maw']; /* d NB machine-dependent size */
  21553. if ($data['miw']>0) $c['miw'] = $data['miw']; /* d NB machine-dependent size */
  21554. if ($data['mih']>0) $c['mih'] = $data['mih']; /* d NB machine-dependent size */
  21555. if ($data['w0']>=0) { $c['w0'] = $data['w0']; /* d NB machine-dependent size */
  21556. $c['x0'] = $data['x0']; } /* d NB machine-dependent size */
  21557. if ($data['h0']>=0) { $c['h0'] = $data['h0']; /* d NB machine-dependent size */
  21558. $c['y0'] = $data['y0']; } /* d NB machine-dependent size */
  21559. $c['a'] = trim($data['a']); /* A1 */
  21560. $c['va'] = trim($data['va']); /* A1 */
  21561. if ($data['nowrap']) $c['nowrap'] = $data['nowrap']; /* 1 or blank n */
  21562. else $c['nowrap'] = false;
  21563. if ($data['wpercent']>0) $c['wpercent'] = $data['wpercent']; /* 0 - 100 n */
  21564. if ($data['R']<>0) $c['R'] = $data['R']; /* 90 or -90 s */
  21565. else $c['R'] = false;
  21566. $c['bgcolor'] = trim($data['bgcol']); /* A32 */
  21567. if (trim($data['grad']))
  21568. $c['gradient'] = trim($data['grad']); /* A128 */
  21569. else $c['gradient'] = false;
  21570. if ($data['bgimage']>0) {
  21571. $bgidata = substr($str, ($data['bgimage']+2));
  21572. $c['background-image'] = unpack("nimage_id/dorig_w/dorig_h/A6x_pos/A6y_pos/nx_repeat/ny_repeat/nresize/dopacity/A4itype/A128gradient", $bgidata);
  21573. }
  21574. $tblen = $this->read_short($fh); // Length of Textbuffer
  21575. $tbsp = fread($fh,$tblen); // Textbuffer (serialised and packed)
  21576. $tbs = unpack("A".$tblen."textbuffer",$tbsp); // Textbuffer unpacked
  21577. $c['textbuffer'] = unserialize(trim($tbs['textbuffer'])); // Textbuffer unserialized
  21578. if ($tempfh) { fclose($fh); }
  21579. return ($c);
  21580. }
  21581. function read_short(&$fh) {
  21582. $s = fread($fh,2);
  21583. $a = (ord($s[0])<<8) + ord($s[1]);
  21584. if ($a & (1 << 15) ) {
  21585. $a = ($a - (1 << 16));
  21586. }
  21587. return $a;
  21588. }
  21589. function _backupCacheFiles() {
  21590. foreach($this->table AS $lvl=>$t) {
  21591. foreach($this->table[$lvl] AS $c=>$t2) {
  21592. ///////////////////////////if (!file_exists($t2['cache'])) { echo $lvl; echo $c; print_r($this->table); exit; }
  21593. copy( $t2['cache'], $t2['cache'].'.bak');
  21594. }
  21595. }
  21596. }
  21597. function _restoreCacheFiles() {
  21598. foreach($this->table AS $lvl=>$t) {
  21599. foreach($this->table[$lvl] AS $c=>$t2) {
  21600. copy( $t2['cache'].'.bak', $t2['cache']);
  21601. }
  21602. }
  21603. }
  21604. function _packCellBorder($cell) {
  21605. if (!is_array($cell) || !isset($cell)) { return ''; }
  21606. if (!$this->packTableData) { return $cell; }
  21607. // = 186 bytes
  21608. $bindata = pack("nnda6A10nnda6A10nnda6A10nnda6A10nd9",
  21609. $cell['border'],
  21610. $cell['border_details']['R']['s'],
  21611. $cell['border_details']['R']['w'],
  21612. $cell['border_details']['R']['c'],
  21613. $cell['border_details']['R']['style'],
  21614. $cell['border_details']['R']['dom'],
  21615. $cell['border_details']['L']['s'],
  21616. $cell['border_details']['L']['w'],
  21617. $cell['border_details']['L']['c'],
  21618. $cell['border_details']['L']['style'],
  21619. $cell['border_details']['L']['dom'],
  21620. $cell['border_details']['T']['s'],
  21621. $cell['border_details']['T']['w'],
  21622. $cell['border_details']['T']['c'],
  21623. $cell['border_details']['T']['style'],
  21624. $cell['border_details']['T']['dom'],
  21625. $cell['border_details']['B']['s'],
  21626. $cell['border_details']['B']['w'],
  21627. $cell['border_details']['B']['c'],
  21628. $cell['border_details']['B']['style'],
  21629. $cell['border_details']['B']['dom'],
  21630. $cell['border_details']['mbw']['BL'],
  21631. $cell['border_details']['mbw']['BR'],
  21632. $cell['border_details']['mbw']['RT'],
  21633. $cell['border_details']['mbw']['RB'],
  21634. $cell['border_details']['mbw']['TL'],
  21635. $cell['border_details']['mbw']['TR'],
  21636. $cell['border_details']['mbw']['LT'],
  21637. $cell['border_details']['mbw']['LB'],
  21638. $cell['border_details']['cellposdom']
  21639. );
  21640. return $bindata;
  21641. }
  21642. function _getBorderWidths($bindata) {
  21643. if (!$bindata) { return array(0,0,0,0); }
  21644. 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']); }
  21645. $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);
  21646. $cell['border_details']['R']['w'] = $bd['rw'];
  21647. $cell['border_details']['L']['w'] = $bd['lw'];
  21648. $cell['border_details']['T']['w'] = $bd['tw'];
  21649. $cell['border_details']['B']['w'] = $bd['bw'];
  21650. return array($bd['tw'], $bd['rw'], $bd['bw'], $bd['lw']);
  21651. }
  21652. function _unpackCellBorder($bindata) {
  21653. if (!$bindata) { return array(); }
  21654. if (!$this->packTableData) { return $bindata; }
  21655. $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);
  21656. $cell['border'] = $bd['bord'];
  21657. $cell['border_details']['R']['s'] = $bd['rs'];
  21658. $cell['border_details']['R']['w'] = $bd['rw'];
  21659. $cell['border_details']['R']['c'] = $bd['rca'];
  21660. $cell['border_details']['R']['style'] = trim($bd['rst']);
  21661. $cell['border_details']['R']['dom'] = $bd['rd'];
  21662. $cell['border_details']['L']['s'] = $bd['ls'];
  21663. $cell['border_details']['L']['w'] = $bd['lw'];
  21664. $cell['border_details']['L']['c'] = $bd['lca'];
  21665. $cell['border_details']['L']['style'] = trim($bd['lst']);
  21666. $cell['border_details']['L']['dom'] = $bd['ld'];
  21667. $cell['border_details']['T']['s'] = $bd['ts'];
  21668. $cell['border_details']['T']['w'] = $bd['tw'];
  21669. $cell['border_details']['T']['c'] = $bd['tca'];
  21670. $cell['border_details']['T']['style'] = trim($bd['tst']);
  21671. $cell['border_details']['T']['dom'] = $bd['td'];
  21672. $cell['border_details']['B']['s'] = $bd['bs'];
  21673. $cell['border_details']['B']['w'] = $bd['bw'];
  21674. $cell['border_details']['B']['c'] = $bd['bca'];
  21675. $cell['border_details']['B']['style'] = trim($bd['bst']);
  21676. $cell['border_details']['B']['dom'] = $bd['bd'];
  21677. $cell['border_details']['mbw']['BL'] = $bd['mbl'];
  21678. $cell['border_details']['mbw']['BR'] = $bd['mbr'];
  21679. $cell['border_details']['mbw']['RT'] = $bd['mrt'];
  21680. $cell['border_details']['mbw']['RB'] = $bd['mrb'];
  21681. $cell['border_details']['mbw']['TL'] = $bd['mtl'];
  21682. $cell['border_details']['mbw']['TR'] = $bd['mtr'];
  21683. $cell['border_details']['mbw']['LT'] = $bd['mlt'];
  21684. $cell['border_details']['mbw']['LB'] = $bd['mlb'];
  21685. $cell['border_details']['cellposdom'] = $bd['cpd'];
  21686. return($cell);
  21687. }
  21688. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21689. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21690. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  21691. //table Array of (w, h, bc, nr, wc, hr, cells)
  21692. //w Width of table
  21693. //h Height of table
  21694. //nc Number column
  21695. //nr Number row
  21696. //hr List of height of each row
  21697. //wc List of width of each column
  21698. //cells List of cells of each rows, cells[i][j] is a cell in the table
  21699. function _tableColumnWidth(&$table,$firstpass=false){
  21700. $cs = &$table['cells'];
  21701. $nc = $table['nc'];
  21702. $nr = $table['nr'];
  21703. $listspan = array();
  21704. if ($table['borders_separate']) {
  21705. $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'];
  21706. }
  21707. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  21708. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  21709. else { $fh = null; }
  21710. // ADDED table['l'][colno]
  21711. // = total length of text approx (using $c['s']) in that column - used to approximately distribute col widths in _tableWidth
  21712. //
  21713. for($j = 0 ; $j < $nc ; $j++ ) { //columns
  21714. $wc = &$table['wc'][$j];
  21715. for($i = 0 ; $i < $nr ; $i++ ) { //rows
  21716. if (isset($cs[$i][$j]) && $cs[$i][$j]) {
  21717. if ($this->cacheTables) {
  21718. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  21719. }
  21720. else
  21721. $c = &$cs[$i][$j];
  21722. if ($this->simpleTables){
  21723. if ($table['borders_separate']) { // NB twice border width
  21724. $extrcw = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21725. }
  21726. else {
  21727. $extrcw = $table['simple']['border_details']['L']['w']/2 + $table['simple']['border_details']['R']['w']/2 + $c['padding']['L'] + $c['padding']['R'];
  21728. }
  21729. }
  21730. else {
  21731. if ($this->packTableData) {
  21732. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  21733. }
  21734. else {
  21735. $br = $c['border_details']['R']['w'];
  21736. $bl = $c['border_details']['L']['w'];
  21737. }
  21738. if ($table['borders_separate']) { // NB twice border width
  21739. $extrcw = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  21740. }
  21741. else {
  21742. $extrcw = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  21743. }
  21744. }
  21745. //$mw = $this->GetStringWidth('W') + $extrcw ;
  21746. $mw = 0;
  21747. $c['absmiw'] = $mw;
  21748. if (isset($c['R']) && $c['R']) {
  21749. $c['maw'] = $c['miw'] = $this->FontSize + $extrcw ;
  21750. if (isset($c['w'])) { // If cell width is specified
  21751. if ($c['miw'] <$c['w']) { $c['miw'] = $c['w']; }
  21752. }
  21753. if (!isset($c['colspan'])) {
  21754. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; }
  21755. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21756. if ($firstpass) {
  21757. if (isset($table['l'][$j]) ) {
  21758. $table['l'][$j] += $c['miw'] ;
  21759. }
  21760. else {
  21761. $table['l'][$j] = $c['miw'] ;
  21762. }
  21763. }
  21764. }
  21765. if ($c['miw'] > $wc['miw']) { $wc['miw'] = $c['miw']; }
  21766. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; }
  21767. continue;
  21768. }
  21769. if ($firstpass) {
  21770. if (isset($c['s'])) { $c['s'] += $extrcw; }
  21771. if (isset($c['maxs'])) { $c['maxs'] += $extrcw; }
  21772. if (isset($c['nestedmiw'])) { $c['nestedmiw'] += $extrcw; }
  21773. if (isset($c['nestedmaw'])) { $c['nestedmaw'] += $extrcw; }
  21774. }
  21775. // If minimum width has already been set by a nested table or inline object (image/form), use it
  21776. if (isset($c['nestedmiw']) && $this->table[1][1]['overflow']!='visible') { $miw = $c['nestedmiw']; }
  21777. else { $miw = $mw; }
  21778. if (isset($c['maxs']) && $c['maxs'] != '') { $c['s'] = $c['maxs']; }
  21779. // If maximum width has already been set by a nested table, use it
  21780. if (isset($c['nestedmaw'])) { $c['maw'] = $c['nestedmaw']; }
  21781. else $c['maw'] = $c['s'];
  21782. if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) {
  21783. if (($c['maw'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  21784. $c['maw'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw;
  21785. }
  21786. }
  21787. if (isset($c['nowrap']) && $c['nowrap']) { $miw = $c['maw']; }
  21788. if (isset($c['wpercent']) && $firstpass) {
  21789. if (isset($c['colspan'])) { // Not perfect - but % set on colspan is shared equally on cols.
  21790. for($k=0;$k<$c['colspan'];$k++) {
  21791. $table['wc'][($j+$k)]['wpercent'] = $c['wpercent'] / $c['colspan'];
  21792. }
  21793. }
  21794. else {
  21795. if (isset($table['w']) && $table['w']) { $c['w'] = $c['wpercent']/100 * ($table['w'] - $tblbw ); }
  21796. $wc['wpercent'] = $c['wpercent'];
  21797. }
  21798. }
  21799. if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) {
  21800. if (($c['w'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  21801. $c['w'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw;
  21802. }
  21803. }
  21804. if (isset($c['w'])) { // If cell width is specified
  21805. if ($miw<$c['w']) { $c['miw'] = $c['w']; } // Cell min width = that specified
  21806. if ($miw>$c['w']) { $c['miw'] = $c['w'] = $miw; } // If width specified is less than minimum allowed (W) increase it
  21807. if (!isset($wc['w'])) { $wc['w'] = 1; } // If the Col width is not specified = set it to 1
  21808. }
  21809. else { $c['miw'] = $miw; } // If cell width not specified -> set Cell min width it to minimum allowed (W)
  21810. if ($c['maw'] < $c['miw']) { $c['maw'] = $c['miw']; } // If Cell max width < Minwidth - increase it to =
  21811. if (!isset($c['colspan'])) {
  21812. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; } // Update Col Minimum and maximum widths
  21813. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  21814. if ((isset($wc['absmiw']) && $wc['absmiw'] < $c['absmiw']) || !isset($wc['absmiw'])) { $wc['absmiw'] = $c['absmiw']; } // Update Col Minimum and maximum widths
  21815. if (isset($table['l'][$j]) ) {
  21816. $table['l'][$j] += $c['s'];
  21817. }
  21818. else {
  21819. $table['l'][$j] = $c['s'];
  21820. }
  21821. }
  21822. else {
  21823. $listspan[] = array($i,$j);
  21824. }
  21825. //Check if minimum width of the whole column is big enough for largest word to fit
  21826. if (isset($c['textbuffer']) && (!isset($table['overflow']) || $table['overflow']!='wrap')) { // mPDF 5.5.11
  21827. $minwidth = $this->TableCheckMinWidth($wc['miw']- $extrcw ,0,$c['textbuffer']);
  21828. }
  21829. else { $minwidth = 0; }
  21830. if ($minwidth < 0) {
  21831. //increase minimum width
  21832. if (!isset($c['colspan'])) {
  21833. $wc['miw'] = max($wc['miw'],((-$minwidth) + $extrcw) );
  21834. }
  21835. else {
  21836. $c['miw'] = max($c['miw'],((-$minwidth) + $extrcw) );
  21837. }
  21838. }
  21839. if (!isset($c['colspan'])) {
  21840. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; } //update maximum width, if needed
  21841. }
  21842. if ($this->cacheTables) {
  21843. $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]);
  21844. }
  21845. }
  21846. unset($c);
  21847. }//rows
  21848. }//columns
  21849. // COLUMN SPANS
  21850. $wc = &$table['wc'];
  21851. foreach ($listspan as $span) {
  21852. list($i,$j) = $span;
  21853. if ($this->cacheTables) {
  21854. $c = $this->_uncacheCell($cs[$i][$j], '', $fh);
  21855. }
  21856. else
  21857. $c = &$cs[$i][$j];
  21858. $lc = $j + $c['colspan'];
  21859. if ($lc > $nc) { $lc = $nc; }
  21860. $wis = $wisa = 0;
  21861. $was = $wasa = 0;
  21862. $list = array();
  21863. for($k=$j;$k<$lc;$k++) {
  21864. if (isset($table['l'][$k]) ) {
  21865. if ($c['R']) { $table['l'][$k] += $c['miw']/$c['colspan'] ; }
  21866. else { $table['l'][$k] += $c['s']/$c['colspan']; }
  21867. }
  21868. else {
  21869. if ($c['R']) { $table['l'][$k] = $c['miw']/$c['colspan'] ; }
  21870. else { $table['l'][$k] = $c['s']/$c['colspan']; }
  21871. }
  21872. $wis += $wc[$k]['miw'];
  21873. $was += $wc[$k]['maw'];
  21874. if (!isset($c['w'])) {
  21875. $list[] = $k;
  21876. $wisa += $wc[$k]['miw'];
  21877. $wasa += $wc[$k]['maw'];
  21878. }
  21879. }
  21880. if ($c['miw'] > $wis) {
  21881. if (!$wis) {
  21882. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] = $c['miw']/$c['colspan']; }
  21883. }
  21884. else if (!count($list)) {
  21885. $wi = $c['miw'] - $wis;
  21886. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wis)*$wi; }
  21887. }
  21888. else {
  21889. $wi = $c['miw'] - $wis;
  21890. foreach ($list as $k) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wisa)*$wi; }
  21891. }
  21892. }
  21893. if ($c['maw'] > $was) {
  21894. if (!$wis) {
  21895. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] = $c['maw']/$c['colspan']; }
  21896. }
  21897. else if (!count($list)) {
  21898. $wi = $c['maw'] - $was;
  21899. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] += ($wc[$k]['maw']/$was)*$wi; }
  21900. }
  21901. else {
  21902. $wi = $c['maw'] - $was;
  21903. foreach ($list as $k) { $wc[$k]['maw'] += ($wc[$k]['maw']/$wasa)*$wi; }
  21904. }
  21905. }
  21906. unset($c);
  21907. }
  21908. if ($this->cacheTables) { fclose($fh); }
  21909. $checkminwidth = 0;
  21910. $checkmaxwidth = 0;
  21911. $totallength = 0;
  21912. for( $i = 0 ; $i < $nc ; $i++ ) {
  21913. $checkminwidth += $table['wc'][$i]['miw'];
  21914. $checkmaxwidth += $table['wc'][$i]['maw'];
  21915. $totallength += $table['l'][$i];
  21916. }
  21917. if (!isset($table['w']) && $firstpass) {
  21918. $sumpc = 0;
  21919. $notset = 0;
  21920. for( $i = 0 ; $i < $nc ; $i++ ) {
  21921. if (isset($table['wc'][$i]['wpercent']) && $table['wc'][$i]['wpercent']) {
  21922. $sumpc += $table['wc'][$i]['wpercent'];
  21923. }
  21924. else { $notset++; }
  21925. }
  21926. // If sum of widths as % >= 100% and not all columns are set
  21927. // Set a nominal width of 1% for unset columns
  21928. if ($sumpc >= 100 && $notset) {
  21929. for( $i = 0 ; $i < $nc ; $i++ ) {
  21930. if ((!isset($table['wc'][$i]['wpercent']) || !$table['wc'][$i]['wpercent']) &&
  21931. (!isset($table['wc'][$i]['w']) || !$table['wc'][$i]['w'])) {
  21932. $table['wc'][$i]['wpercent'] = 1;
  21933. }
  21934. }
  21935. }
  21936. if ($sumpc) { // if any percents are set
  21937. $sumnonpc = (100 - $sumpc);
  21938. $sumpc = max($sumpc,100);
  21939. $miwleft = 0;
  21940. $miwleftcount = 0;
  21941. $miwsurplusnonpc = 0;
  21942. $maxcalcmiw = 0;
  21943. $mawleft = 0;
  21944. $mawleftcount = 0;
  21945. $mawsurplusnonpc = 0;
  21946. $maxcalcmaw = 0;
  21947. for( $i = 0 ; $i < $nc ; $i++ ) {
  21948. if (isset($table['wc'][$i]['wpercent'])) {
  21949. $maxcalcmiw = max($maxcalcmiw, ($table['wc'][$i]['miw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21950. $maxcalcmaw = max($maxcalcmaw, ($table['wc'][$i]['maw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  21951. }
  21952. else {
  21953. $miwleft += $table['wc'][$i]['miw'];
  21954. $mawleft += $table['wc'][$i]['maw'];
  21955. if (!isset($table['wc'][$i]['w'])) { $miwleftcount++; $mawleftcount++; }
  21956. }
  21957. }
  21958. if ($miwleft && $sumnonpc > 0) { $miwnon = $miwleft * 100 / $sumnonpc; }
  21959. if ($mawleft && $sumnonpc > 0) { $mawnon = $mawleft * 100 / $sumnonpc; }
  21960. if (($miwnon > $checkminwidth || $maxcalcmiw > $checkminwidth) && $this->keep_table_proportions) {
  21961. if ($miwnon > $maxcalcmiw) {
  21962. $miwsurplusnonpc = round((($miwnon * $sumnonpc / 100) - $miwleft),3);
  21963. $checkminwidth = $miwnon;
  21964. }
  21965. else { $checkminwidth = $maxcalcmiw; }
  21966. for( $i = 0 ; $i < $nc ; $i++ ) {
  21967. if (isset($table['wc'][$i]['wpercent'])) {
  21968. $newmiw = $checkminwidth * $table['wc'][$i]['wpercent']/100;
  21969. if ($table['wc'][$i]['miw'] < $newmiw) {
  21970. $table['wc'][$i]['miw'] = $newmiw;
  21971. }
  21972. $table['wc'][$i]['w'] = 1;
  21973. }
  21974. else if ($miwsurplusnonpc && !$table['wc'][$i]['w']) {
  21975. $table['wc'][$i]['miw'] += $miwsurplusnonpc / $miwleftcount;
  21976. }
  21977. }
  21978. }
  21979. if (($mawnon > $checkmaxwidth || $maxcalcmaw > $checkmaxwidth )) {
  21980. if ($mawnon > $maxcalcmaw) {
  21981. $mawsurplusnonpc = round((($mawnon * $sumnonpc / 100) - $mawleft),3);
  21982. $checkmaxwidth = $mawnon;
  21983. }
  21984. else { $checkmaxwidth = $maxcalcmaw; }
  21985. for( $i = 0 ; $i < $nc ; $i++ ) {
  21986. if (isset($table['wc'][$i]['wpercent'])) {
  21987. $newmaw = $checkmaxwidth * $table['wc'][$i]['wpercent']/100;
  21988. if ($table['wc'][$i]['maw'] < $newmaw) {
  21989. $table['wc'][$i]['maw'] = $newmaw;
  21990. }
  21991. $table['wc'][$i]['w'] = 1;
  21992. }
  21993. else if ($mawsurplusnonpc && !$table['wc'][$i]['w']) {
  21994. $table['wc'][$i]['maw'] += $mawsurplusnonpc / $mawleftcount;
  21995. }
  21996. if ($table['wc'][$i]['maw'] < $table['wc'][$i]['miw']) { $table['wc'][$i]['maw'] = $table['wc'][$i]['miw']; }
  21997. }
  21998. }
  21999. if ($checkminwidth > $checkmaxwidth) { $checkmaxwidth = $checkminwidth; }
  22000. }
  22001. }
  22002. if (isset($table['wpercent']) && $table['wpercent']) {
  22003. $checkminwidth *= (100 / $table['wpercent']);
  22004. $checkmaxwidth *= (100 / $table['wpercent']);
  22005. }
  22006. $checkminwidth += $tblbw ;
  22007. $checkmaxwidth += $tblbw ;
  22008. // Table['miw'] set by percent in first pass may be larger than sum of column miw
  22009. if ((isset($table['miw']) && $checkminwidth > $table['miw']) || !isset($table['miw'])) { $table['miw'] = $checkminwidth; }
  22010. if ((isset($table['maw']) && $checkmaxwidth > $table['maw']) || !isset($table['maw'])) { $table['maw'] = $checkmaxwidth; }
  22011. $table['tl'] = $totallength ;
  22012. if (!$this->tableCJK) {
  22013. if ($this->table_rotate) {
  22014. $mxw = $this->tbrot_maxw;
  22015. }
  22016. else {
  22017. $mxw = $this->blk[$this->blklvl]['inner_width'];
  22018. }
  22019. if(!isset($table['overflow'])) { $table['overflow'] = null; }
  22020. if ($table['overflow']=='visible') {
  22021. return array(0,0);
  22022. }
  22023. else if ($table['overflow']=='hidden' && !$this->table_rotate && !$this->ColActive && $checkminwidth > $mxw) {
  22024. $table['w'] = $table['miw'];
  22025. return array(0,0);
  22026. }
  22027. else if ($table['overflow']=='wrap') { return array(0,0); }
  22028. if (isset($table['w']) && $table['w'] ) {
  22029. if ($table['w'] >= $checkminwidth && $table['w'] <= $mxw) { $table['maw'] = $mxw = $table['w']; }
  22030. else if ($table['w'] >= $checkminwidth && $table['w'] > $mxw && $this->keep_table_proportions) { $checkminwidth = $table['w']; }
  22031. else {
  22032. unset($table['w']);
  22033. }
  22034. }
  22035. $ratio = $checkminwidth/$mxw;
  22036. if ($checkminwidth > $mxw) { return array(($ratio +0.001),$checkminwidth); } // 0.001 to allow for rounded numbers when resizing
  22037. }
  22038. unset($cs);
  22039. return array(0,0);
  22040. }
  22041. function _tableWidth(&$table){
  22042. $widthcols = &$table['wc'];
  22043. $numcols = $table['nc'];
  22044. $tablewidth = 0;
  22045. if ($table['borders_separate']) {
  22046. $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'];
  22047. }
  22048. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  22049. if ($table['level']>1 && isset($table['w'])) {
  22050. if (isset($table['wpercent']) && $table['wpercent']) {
  22051. $table['w'] = $temppgwidth = (($table['w']-$tblbw) * $table['wpercent'] / 100) + $tblbw ;
  22052. }
  22053. else {
  22054. $temppgwidth = $table['w'] ;
  22055. }
  22056. }
  22057. else if ($this->table_rotate) {
  22058. $temppgwidth = $this->tbrot_maxw;
  22059. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  22060. // then allow for this
  22061. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  22062. if ($enddiv/$temppgwidth <0.05) { $temppgwidth -= $enddiv; }
  22063. }
  22064. else {
  22065. if (isset($table['w']) && $table['w']< $this->blk[$this->blklvl]['inner_width']) {
  22066. $notfullwidth = 1;
  22067. $temppgwidth = $table['w'] ;
  22068. }
  22069. else if ($table['overflow']=='visible' && $table['level'] ==1) {
  22070. $temppgwidth = null;
  22071. }
  22072. else if ($table['overflow']=='hidden' && !$this->ColActive && isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width'] && $table['w']==$table['miw']) {
  22073. //$temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  22074. $temppgwidth = $table['w'] ;
  22075. }
  22076. else { $temppgwidth = $this->blk[$this->blklvl]['inner_width']; }
  22077. }
  22078. $totaltextlength = 0; // Added - to sum $table['l'][colno]
  22079. $totalatextlength = 0; // Added - to sum $table['l'][colno] for those columns where width not set
  22080. $percentages_set = 0;
  22081. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  22082. if (isset($widthcols[$i]['wpercent'])) { $tablewidth += $widthcols[$i]['maw']; $percentages_set = 1; }
  22083. else if (isset($widthcols[$i]['w'])) { $tablewidth += $widthcols[$i]['miw']; }
  22084. else { $tablewidth += $widthcols[$i]['maw']; }
  22085. $totaltextlength += $table['l'][$i];
  22086. }
  22087. if (!$totaltextlength) { $totaltextlength =1; }
  22088. $tablewidth += $tblbw; // Outer half of table borders
  22089. if ($tablewidth > $temppgwidth) {
  22090. $table['w'] = $temppgwidth;
  22091. }
  22092. // if any widths set as percentages and max width fits < page width
  22093. else if ($tablewidth < $temppgwidth && !isset($table['w']) && $percentages_set) {
  22094. $table['w'] = $table['maw'];
  22095. }
  22096. // if table width is set and is > allowed width
  22097. if (isset($table['w']) && $table['w'] > $temppgwidth) { $table['w'] = $temppgwidth; }
  22098. // IF the table width is now set - Need to distribute columns widths
  22099. if (isset($table['w'])) {
  22100. $wis = $wisa = 0;
  22101. $list = array();
  22102. $notsetlist = array();
  22103. for( $i = 0 ; $i < $numcols ; $i++ ) {
  22104. $wis += $widthcols[$i]['miw'];
  22105. if (!isset($widthcols[$i]['w']) || ($widthcols[$i]['w'] && $table['w'] > $temppgwidth && !$this->keep_table_proportions && !$notfullwidth )){
  22106. $list[] = $i;
  22107. $wisa += $widthcols[$i]['miw'];
  22108. $totalatextlength += $table['l'][$i];
  22109. }
  22110. }
  22111. if (!$totalatextlength) { $totalatextlength =1; }
  22112. // Allocate spare (more than col's minimum width) across the cols according to their approx total text length
  22113. // Do it by setting minimum width here
  22114. if ($table['w'] > $wis + $tblbw) {
  22115. // First set any cell widths set as percentages
  22116. if ($table['w'] < $temppgwidth || $this->keep_table_proportions) {
  22117. for($k=0;$k<$numcols;$k++) {
  22118. if (isset($widthcols[$k]['wpercent'])) {
  22119. $curr = $widthcols[$k]['miw'];
  22120. $widthcols[$k]['miw'] = ($table['w']-$tblbw) * $widthcols[$k]['wpercent']/100;
  22121. $wis += $widthcols[$k]['miw'] - $curr;
  22122. $wisa += $widthcols[$k]['miw'] - $curr;
  22123. }
  22124. }
  22125. }
  22126. // Now allocate surplus up to maximum width of each column
  22127. $surplus = 0; $ttl = 0; // number of surplus columns
  22128. if (!count($list)) {
  22129. $wi = ($table['w']-($wis + $tblbw)); // i.e. extra space to distribute
  22130. for($k=0;$k<$numcols;$k++) {
  22131. $spareratio = ($table['l'][$k] / $totaltextlength); // gives ratio to divide up free space
  22132. // Don't allocate more than Maximum required width - save rest in surplus
  22133. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  22134. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  22135. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  22136. }
  22137. else {
  22138. $notsetlist[] = $k;
  22139. $ttl += $table['l'][$k];
  22140. $widthcols[$k]['miw'] += ($wi * $spareratio);
  22141. }
  22142. }
  22143. }
  22144. else {
  22145. $wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra space to distribute
  22146. foreach ($list as $k) {
  22147. $spareratio = ($table['l'][$k] / $totalatextlength); // gives ratio to divide up free space
  22148. // Don't allocate more than Maximum required width - save rest in surplus
  22149. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  22150. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  22151. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  22152. }
  22153. else {
  22154. $notsetlist[] = $k;
  22155. $ttl += $table['l'][$k];
  22156. $widthcols[$k]['miw'] += ($wi * $spareratio);
  22157. }
  22158. }
  22159. }
  22160. // If surplus still left over apportion it across columns
  22161. if ($surplus) {
  22162. // if some are set only add to remaining - otherwise add to all of them
  22163. if (count($notsetlist) && count($notsetlist) < $numcols) {
  22164. foreach ($notsetlist AS $i) {
  22165. if ($ttl) $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl ;
  22166. }
  22167. }
  22168. // If some widths are defined, and others have been added up to their maxmum
  22169. else if (count($list) && count($list) < $numcols) {
  22170. foreach ($list AS $i) {
  22171. $widthcols[$i]['miw'] += $surplus / count($list) ;
  22172. }
  22173. }
  22174. else if ($numcols) { // If all columns
  22175. $ttl = array_sum($table['l']);
  22176. for ($i=0;$i<$numcols;$i++) {
  22177. $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl;
  22178. }
  22179. }
  22180. }
  22181. }
  22182. // This sets the columns all to minimum width (which has been increased above if appropriate)
  22183. for ($i=0;$i<$numcols;$i++) {
  22184. $widthcols[$i] = $widthcols[$i]['miw'];
  22185. }
  22186. // TABLE NOT WIDE ENOUGH EVEN FOR MINIMUM CONTENT WIDTH
  22187. // If sum of column widths set are too wide for table
  22188. $checktablewidth = 0;
  22189. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  22190. $checktablewidth += $widthcols[$i];
  22191. }
  22192. if ($checktablewidth > ($temppgwidth + 0.001 - $tblbw)) {
  22193. $usedup = 0; $numleft = 0;
  22194. for ($i=0;$i<$numcols;$i++) {
  22195. if ((isset($widthcols[$i]) && $widthcols[$i] > (($temppgwidth - $tblbw) / $numcols)) && (!isset($widthcols[$i]['w']))) {
  22196. $numleft++;
  22197. unset($widthcols[$i]);
  22198. }
  22199. else { $usedup += $widthcols[$i]; }
  22200. }
  22201. for ($i=0;$i<$numcols;$i++) {
  22202. if (!isset($widthcols[$i]) || !$widthcols[$i]) {
  22203. $widthcols[$i] = ((($temppgwidth - $tblbw) - $usedup)/ ($numleft));
  22204. }
  22205. }
  22206. }
  22207. }
  22208. else { //table has no width defined
  22209. $table['w'] = $tablewidth;
  22210. for ( $i = 0 ; $i < $numcols ; $i++) {
  22211. if (isset($widthcols[$i]['wpercent']) && $this->keep_table_proportions) { $colwidth = $widthcols[$i]['maw']; }
  22212. else if (isset($widthcols[$i]['w'])) { $colwidth = $widthcols[$i]['miw']; }
  22213. else { $colwidth = $widthcols[$i]['maw']; }
  22214. unset($widthcols[$i]);
  22215. $widthcols[$i] = $colwidth;
  22216. }
  22217. }
  22218. if ($table['overflow']=='visible' && $table['level'] ==1) {
  22219. if ($tablewidth > $this->blk[$this->blklvl]['inner_width']) {
  22220. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  22221. else { $fh = null; }
  22222. for ($j = 0 ; $j < $numcols; $j++) { //columns
  22223. for ($i = 0 ; $i < $table['nr']; $i++) { //rows
  22224. if (isset($table['cells'][$i][$j]) && $table['cells'][$i][$j]) {
  22225. if ($this->cacheTables) {
  22226. $cc = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22227. $colspan = $cc['colspan'];
  22228. }
  22229. else
  22230. $colspan = $table['cells'][$i][$j]['colspan'];
  22231. if ($colspan > 1) {
  22232. $w = 0;
  22233. for ($c = $j; $c < ($j + $colspan); $c++) {
  22234. $w += $widthcols[$c];
  22235. }
  22236. if ($w > $this->blk[$this->blklvl]['inner_width']) {
  22237. $diff = $w - ($this->blk[$this->blklvl]['inner_width'] - $tblbw);
  22238. for ($c = $j; $c < ($j + $colspan); $c++) {
  22239. $widthcols[$c] -= $diff * ($widthcols[$c]/$w);
  22240. }
  22241. $table['w'] -= $diff;
  22242. $table['csp'][$j] = $w - $diff;
  22243. }
  22244. }
  22245. }
  22246. }
  22247. }
  22248. if ($this->cacheTables) { fclose($fh); }
  22249. }
  22250. $pgNo = 0;
  22251. $currWc = 0;
  22252. for ($i = 0 ; $i < $numcols; $i++) { //columns
  22253. if (isset($table['csp'][$i])) {
  22254. $w = $table['csp'][$i];
  22255. unset($table['csp'][$i]);
  22256. }
  22257. else { $w = $widthcols[$i]; }
  22258. if (($currWc + $w + $tblbw) > $this->blk[$this->blklvl]['inner_width']) {
  22259. $pgNo++;
  22260. $currWc = $widthcols[$i] ;
  22261. }
  22262. else { $currWc += $widthcols[$i] ; }
  22263. $table['colPg'][$i] = $pgNo;
  22264. }
  22265. }
  22266. }
  22267. function _tableHeight(&$table){
  22268. $level = $table['level'];
  22269. $levelid = $table['levelid'];
  22270. $cells = &$table['cells'];
  22271. $numcols = $table['nc'];
  22272. $numrows = $table['nr'];
  22273. $listspan = array();
  22274. $checkmaxheight = 0;
  22275. $headerrowheight = 0;
  22276. $checkmaxheightplus = 0;
  22277. $headerrowheightplus = 0;
  22278. $firstrowheight = 0;
  22279. $footerrowheight = 0;
  22280. $footerrowheightplus = 0;
  22281. if ($this->table_rotate) {
  22282. $temppgheight = $this->tbrot_maxh;
  22283. $remainingpage = $this->tbrot_maxh;
  22284. }
  22285. else {
  22286. $temppgheight = ($this->h - $this->bMargin - $this->tMargin) - $this->kwt_height;
  22287. $remainingpage = ($this->h - $this->bMargin - $this->y) - $this->kwt_height;
  22288. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  22289. // then allow for this
  22290. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $table['margin']['B'];
  22291. if ($remainingpage > $enddiv && $enddiv/$remainingpage <0.05) { $remainingpage -= $enddiv; }
  22292. else if ($remainingpage == 0) { $remainingpage = 0.001; }
  22293. if ($temppgheight > $enddiv && $enddiv/$temppgheight <0.05) { $temppgheight -= $enddiv; }
  22294. else if ($temppgheight == 0) { $temppgheight = 0.001; }
  22295. }
  22296. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  22297. else { $fh = null; }
  22298. for( $i = 0 ; $i < $numrows ; $i++ ) { //rows
  22299. $heightrow = &$table['hr'][$i];
  22300. for( $j = 0 ; $j < $numcols ; $j++ ) { //columns
  22301. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  22302. if ($this->cacheTables) {
  22303. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22304. }
  22305. else
  22306. $c = &$cells[$i][$j];
  22307. if ($this->simpleTables){
  22308. if ($table['borders_separate']) { // NB twice border width
  22309. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w']) + ($c['padding']['L']+$c['padding']['R'])+$table['border_spacing_H'];
  22310. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w']) + ($c['padding']['T']+$c['padding']['B'])+$table['border_spacing_V'];
  22311. }
  22312. else {
  22313. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w'])/2 + ($c['padding']['L']+$c['padding']['R']);
  22314. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w'])/2 + ($c['padding']['T']+$c['padding']['B']);
  22315. }
  22316. }
  22317. else {
  22318. if ($this->packTableData) {
  22319. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  22320. }
  22321. else {
  22322. $bt = $c['border_details']['T']['w'];
  22323. $bb = $c['border_details']['B']['w'];
  22324. $br = $c['border_details']['R']['w'];
  22325. $bl = $c['border_details']['L']['w'];
  22326. }
  22327. if ($table['borders_separate']) { // NB twice border width
  22328. $extraWLR = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  22329. $extrh = $bt + $bb + $c['padding']['T'] + $c['padding']['B'] + $table['border_spacing_V'];
  22330. }
  22331. else {
  22332. $extraWLR = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  22333. $extrh = $bt/2 + $bb/2 + $c['padding']['T']+$c['padding']['B'];
  22334. }
  22335. }
  22336. if ($table['overflow']=='visible' && $level==1)
  22337. list($x,$cw) = $this->_splitTableGetWidth($table, $i,$j, $fh);
  22338. else
  22339. list($x,$cw) = $this->_tableGetWidth($table, $i,$j, $fh);
  22340. // Get CELL HEIGHT
  22341. // ++ extra parameter forces wrap to break word
  22342. if ($c['R'] && isset($c['textbuffer'])) { // mPDF 5.4.01
  22343. $str = '';
  22344. foreach($c['textbuffer'] AS $t) { $str .= $t[0].' '; }
  22345. $str = trim($str);
  22346. $s_fs = $this->FontSizePt;
  22347. $s_f = $this->FontFamily;
  22348. $s_st = $this->FontStyle;
  22349. $this->SetFont($c['textbuffer'][0][4],$c['textbuffer'][0][2],$c['textbuffer'][0][11] / $this->shrin_k,true,true);
  22350. $tempch = $this->GetStringWidth($str);
  22351. if ($c['R'] >= 45 && $c['R'] < 90) {
  22352. $tempch = ((sin(deg2rad($c['R']))) * $tempch ) + ((sin(deg2rad($c['R']))) * (($c['textbuffer'][0][11]/_MPDFK) / $this->shrin_k));
  22353. }
  22354. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  22355. $ch = ($tempch ) + $extrh ;
  22356. }
  22357. else {
  22358. if (isset($c['textbuffer'])) {
  22359. $tempch = $this->TableWordWrap(($cw-$extraWLR),1,$c['textbuffer'], $c['dfs']);
  22360. }
  22361. else { $tempch = 0; }
  22362. // Added cellpadding top and bottom. (Lineheight already adjusted to table_lineheight)
  22363. $ch = $tempch + $extrh ;
  22364. }
  22365. //If height is defined and it is bigger than calculated $ch then update values
  22366. if (isset($c['h']) && $c['h'] > $ch) {
  22367. $c['mih'] = $ch; //in order to keep valign working
  22368. $ch = $c['h'];
  22369. }
  22370. else $c['mih'] = $ch;
  22371. if ($this->cacheTables) {
  22372. $this->_cacheUpdateMtx($c, $fh, $table['cells'][$i][$j], 'mih');
  22373. }
  22374. if (isset($c['rowspan'])) $listspan[] = array($i,$j);
  22375. elseif ($heightrow < $ch) $heightrow = $ch;
  22376. // this is the extra used in _tableWrite to determine whether to trigger a page change
  22377. if ($table['borders_separate']) {
  22378. if ($i == ($numrows-1) || (isset($c['rowspan']) && ($i+$c['rowspan']) == ($numrows)) ) {
  22379. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  22380. }
  22381. else {
  22382. $extra = $table['border_spacing_V']/2;
  22383. }
  22384. }
  22385. else {
  22386. if (!$this->simpleTables){
  22387. $extra = $bb/2;
  22388. }
  22389. else if ($this->simpleTables){
  22390. $extra = $table['simple']['border_details']['B']['w'] /2;
  22391. }
  22392. }
  22393. if (isset($table['is_thead'][$i]) && $table['is_thead'][$i]) {
  22394. if ($j==0) {
  22395. $headerrowheight += $ch;
  22396. $headerrowheightplus += $ch+$extra;
  22397. }
  22398. }
  22399. else if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) {
  22400. if ($j==0) {
  22401. $footerrowheight += $ch;
  22402. $footerrowheightplus += $ch+$extra;
  22403. }
  22404. }
  22405. else {
  22406. $checkmaxheight = max($checkmaxheight,$ch);
  22407. $checkmaxheightplus = max($checkmaxheightplus,$ch+$extra);
  22408. }
  22409. if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($ch,$firstrowheight); }
  22410. unset($c);
  22411. }
  22412. }//end of columns
  22413. }//end of rows
  22414. $heightrow = &$table['hr'];
  22415. foreach ($listspan as $span) {
  22416. list($i,$j) = $span;
  22417. if ($this->cacheTables) {
  22418. $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22419. }
  22420. else
  22421. $c = &$cells[$i][$j];
  22422. $lr = $i + $c['rowspan'];
  22423. if ($lr > $numrows) $lr = $numrows;
  22424. $hs = $hsa = 0;
  22425. $list = array();
  22426. for($k=$i;$k<$lr;$k++) {
  22427. $hs += $heightrow[$k];
  22428. if (!isset($c['h'])) {
  22429. $list[] = $k;
  22430. $hsa += $heightrow[$k];
  22431. }
  22432. }
  22433. if ($table['borders_separate']) {
  22434. if ($i == ($numrows-1) || ($i+$c['rowspan']) == ($numrows) ) {
  22435. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  22436. }
  22437. else {
  22438. $extra = $table['border_spacing_V']/2;
  22439. }
  22440. }
  22441. else {
  22442. if (!$this->simpleTables){
  22443. if ($this->packTableData) {
  22444. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  22445. }
  22446. else {
  22447. $bb = $c['border_details']['B']['w'];
  22448. }
  22449. $extra = $bb/2;
  22450. }
  22451. else if ($this->simpleTables){
  22452. $extra = $table['simple']['border_details']['B']['w'] /2;
  22453. }
  22454. }
  22455. if (!empty($table['is_thead'][$i])) {
  22456. $headerrowheight = max($headerrowheight,$hs);
  22457. $headerrowheightplus = max($headerrowheightplus,$hs+$extra);
  22458. }
  22459. else if (!empty($table['is_tfoot'][$i])) {
  22460. $footerrowheight = max($footerrowheight,$hs);
  22461. $footerrowheightplus = max($footerrowheightplus,$hs+$extra);
  22462. }
  22463. else {
  22464. $checkmaxheight = max($checkmaxheight,$hs);
  22465. $checkmaxheightplus = max($checkmaxheightplus,$hs+$extra);
  22466. }
  22467. if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($hs,$firstrowheight); }
  22468. if ($c['mih'] > $hs) {
  22469. if (!$hs) {
  22470. for($k=$i;$k<$lr;$k++) $heightrow[$k] = $c['mih']/$c['rowspan'];
  22471. }
  22472. elseif (!count($list)) {
  22473. $hi = $c['mih'] - $hs;
  22474. for($k=$i;$k<$lr;$k++) $heightrow[$k] += ($heightrow[$k]/$hs)*$hi;
  22475. }
  22476. else {
  22477. $hi = $c['mih'] - $hsa;
  22478. foreach ($list as $k) $heightrow[$k] += ($heightrow[$k]/$hsa)*$hi;
  22479. }
  22480. }
  22481. unset($c);
  22482. // If rowspans overlap so that one or more rows do not have a height set...
  22483. // i.e. for one or more rows, the only cells (explicit) in that row have rowspan>1
  22484. // so heightrow is still == 0
  22485. if ($heightrow[$i]==0) {
  22486. // Get row extent to analyse above and below
  22487. $top = $i;
  22488. foreach ($listspan as $checkspan) {
  22489. list($cki,$ckj) = $checkspan;
  22490. if ($this->cacheTables) {
  22491. $c = $this->_uncacheCell($table['cells'][$cki][$ckj], '', $fh);
  22492. }
  22493. else
  22494. $c = &$cells[$cki][$ckj];
  22495. if (isset($c['rowspan']) && $c['rowspan']>1) {
  22496. if (($cki + $c['rowspan']-1) >= $i) { $top = min($top, $cki); }
  22497. }
  22498. }
  22499. $bottom = $i + $c['rowspan']-1;
  22500. // Check for overconstrained conditions
  22501. for ($k=$top; $k<=$bottom; $k++) {
  22502. // if ['hr'] for any of the others is also 0, then abort (too complicated)
  22503. if ($k != $i && $heightrow[$k]==0) { break(1); }
  22504. // check again that top and bottom are not crossed by rowspans - or abort (too complicated)
  22505. if ($k==$top) {
  22506. // ???? take account of colspan as well???
  22507. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22508. if (!isset($cells[$k][$m]) || $cells[$k][$m]==0) {
  22509. break(2);
  22510. }
  22511. }
  22512. }
  22513. else if ($k==$bottom) {
  22514. // ???? take account of colspan as well???
  22515. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22516. if ($this->cacheTables) {
  22517. $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh);
  22518. }
  22519. else
  22520. $c = &$cells[$k][$m];
  22521. if (isset($c['rowspan']) && $c['rowspan']>1) {
  22522. break(2);
  22523. }
  22524. }
  22525. }
  22526. }
  22527. // By columns add up col height using ['h'] if set or ['mih'] if not
  22528. // Intentionally do not substract border-spacing
  22529. $colH = array();
  22530. $extH = 0;
  22531. $newhr = array();
  22532. for( $m = 0 ; $m < $numcols ; $m++ ) { //columns
  22533. for ($k=$top; $k<=$bottom; $k++) {
  22534. if (isset($cells[$k][$m]) && $cells[$k][$m]!=0) {
  22535. if ($this->cacheTables) {
  22536. $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh);
  22537. }
  22538. else
  22539. $c = &$cells[$k][$m];
  22540. if (isset($c['h']) && $c['h']) {
  22541. $useh = $c['h'];
  22542. }
  22543. // ???? take account of colspan as well???
  22544. else {
  22545. $useh = $c['mih'];
  22546. }
  22547. $colH[$m] += $useh;
  22548. if (!isset($c['rowspan']) || $c['rowspan']<2) { $newhr[$k] = max($newhr[$k], $useh); }
  22549. }
  22550. }
  22551. $extH = max($tabH, $colH[$m]);
  22552. }
  22553. $newhr[$i] = $extH - array_sum($newhr);
  22554. for ($k=$top; $k<=$bottom; $k++) { $heightrow[$k] = $newhr[$k]; }
  22555. }
  22556. unset($c);
  22557. }
  22558. $table['h'] = array_sum($heightrow);
  22559. unset($heightrow);
  22560. if ($this->cacheTables) { fclose($fh); }
  22561. if ($table['borders_separate']) {
  22562. $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'];
  22563. }
  22564. else {
  22565. $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['max_cell_border_width']['T']/2 + $table['max_cell_border_width']['B']/2;
  22566. }
  22567. $maxrowheight = $checkmaxheightplus + $headerrowheightplus + $footerrowheightplus;
  22568. $maxfirstrowheight = $firstrowheight + $headerrowheightplus + $footerrowheightplus; // includes thead, 1st row and tfoot
  22569. return array($table['h'],$maxrowheight,$temppgheight,$remainingpage,$maxfirstrowheight);
  22570. }
  22571. function _tableGetWidth(&$table, $i,$j, $fh){
  22572. if ($this->cacheTables) {
  22573. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22574. }
  22575. else
  22576. $cell = &$table['cells'][$i][$j];
  22577. if ($cell) {
  22578. if (isset($cell['x0'])) { return array($cell['x0'], $cell['w0']); }
  22579. $x = 0;
  22580. $widthcols = &$table['wc'];
  22581. for( $k = 0 ; $k < $j ; $k++ ) $x += $widthcols[$k];
  22582. $w = $widthcols[$j];
  22583. if (isset($cell['colspan'])) {
  22584. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) $w += $widthcols[$k];
  22585. }
  22586. $cell['x0'] = $x;
  22587. $cell['w0'] = $w;
  22588. if ($this->cacheTables) {
  22589. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0');
  22590. }
  22591. return array($x, $w);
  22592. }
  22593. return array(0,0);
  22594. }
  22595. function _splitTableGetWidth(&$table, $i,$j, $fh){
  22596. if ($this->cacheTables) {
  22597. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22598. }
  22599. else
  22600. $cell = &$table['cells'][$i][$j];
  22601. if ($cell) {
  22602. if (isset($cell['x0'])) return array($cell['x0'], $cell['w0']);
  22603. $x = 0;
  22604. $widthcols = &$table['wc'];
  22605. $pg = $table['colPg'][$j];
  22606. for( $k = 0 ; $k < $j ; $k++ ) {
  22607. if ($table['colPg'][$k]==$pg) $x += $widthcols[$k];
  22608. }
  22609. $w = $widthcols[$j];
  22610. if (isset($cell['colspan'])) {
  22611. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) if ($table['colPg'][$k]==$pg) $w += $widthcols[$k];
  22612. }
  22613. $cell['x0'] = $x;
  22614. $cell['w0'] = $w;
  22615. if ($this->cacheTables) {
  22616. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0');
  22617. }
  22618. return array($x, $w);
  22619. }
  22620. return array(0,0);
  22621. }
  22622. function _tableGetHeight(&$table, $i,$j, $fh){
  22623. if ($this->cacheTables) {
  22624. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22625. }
  22626. else
  22627. $cell = &$table['cells'][$i][$j];
  22628. if ($cell){
  22629. if (isset($cell['y0'])) return array($cell['y0'], $cell['h0']);
  22630. $y = 0;
  22631. $heightrow = &$table['hr'];
  22632. for ($k=0;$k<$i;$k++) $y += $heightrow[$k];
  22633. $h = $heightrow[$i];
  22634. if (isset($cell['rowspan'])){
  22635. for ($k=$i+$cell['rowspan']-1;$k>$i;$k--)
  22636. $h += $heightrow[$k];
  22637. }
  22638. $cell['y0'] = $y;
  22639. $cell['h0'] = $h;
  22640. if ($this->cacheTables) {
  22641. $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'y0');
  22642. }
  22643. return array($y, $h);
  22644. }
  22645. return array(0,0);
  22646. }
  22647. function _tableGetMaxRowHeight($table, $row, $fh) {
  22648. if ($row==$table['nc']-1) { return $table['hr'][$row]; }
  22649. $maxrowheight = $table['hr'][$row];
  22650. for ($i=$row+1;$i<$table['nr'];$i++) {
  22651. $cellsset = 0;
  22652. for ($j=0;$j<$table['nc'];$j++) {
  22653. if ($this->cacheTables) {
  22654. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  22655. if ($cell) {
  22656. if (isset($cell['colspan'])) { $cellsset += $cell['colspan']; }
  22657. else $cellsset += 1;
  22658. }
  22659. }
  22660. else {
  22661. if ($table['cells'][$i][$j]) {
  22662. if (isset($table['cells'][$i][$j]['colspan'])) { $cellsset += $table['cells'][$i][$j]['colspan']; }
  22663. else $cellsset += 1;
  22664. }
  22665. }
  22666. }
  22667. if ($cellsset == $table['nc']) { return $maxrowheight; }
  22668. else { $maxrowheight += $table['hr'][$i]; }
  22669. }
  22670. return $maxrowheight;
  22671. }
  22672. // CHANGED TO ALLOW TABLE BORDER TO BE SPECIFIED CORRECTLY - added border_details
  22673. function _tableRect($x, $y, $w, $h, $bord=-1, $details=array(), $buffer=false, $bSeparate=false, $cort='cell', $tablecorner='', $bsv=0, $bsh=0) {
  22674. $cellBorderOverlay = array();
  22675. if ($bord==-1) { $this->Rect($x, $y, $w, $h); }
  22676. else if ($this->simpleTables && ($cort=='cell')) {
  22677. $this->SetLineWidth($details['L']['w']);
  22678. if ($details['L']['c']) {
  22679. $this->SetDColor($details['L']['c']);
  22680. }
  22681. else { $this->SetDColor($this->ConvertColor(0)); }
  22682. $this->SetLineJoin(0);
  22683. $this->Rect($x, $y, $w, $h);
  22684. }
  22685. else if ($bord){
  22686. if (!$bSeparate && $buffer) {
  22687. $priority = 'LRTB';
  22688. for($p=0;$p<strlen($priority);$p++) {
  22689. $side = $priority[$p];
  22690. $details['p'] = $side ;
  22691. $dom = 0;
  22692. if (isset($details[$side]['w'])) { $dom += ($details[$side]['w'] * 100000); }
  22693. if (isset($details[$side]['style'])) { $dom += (array_search($details[$side]['style'],$this->borderstyles)*100) ; }
  22694. if (isset($details[$side]['dom'])) { $dom += ($details[$side]['dom']*10); }
  22695. // Precedence to darker colours at joins
  22696. $coldom = 0;
  22697. if (isset($details[$side]['c']) && is_array($details[$side]['c'])) {
  22698. if ($details[$side]['c']{0}==3) { // RGB
  22699. $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);
  22700. }
  22701. } // 10 black - 0 white
  22702. if ($coldom) { $dom += $coldom; }
  22703. // Lastly precedence to RIGHT and BOTTOM cells at joins
  22704. if (isset($details['cellposdom'])) { $dom += $details['cellposdom']; }
  22705. $save = false;
  22706. if ($side == 'T' && $this->issetBorder($bord, _BORDER_TOP)) { $cbord = _BORDER_TOP; $save = true; }
  22707. else if ($side == 'L' && $this->issetBorder($bord, _BORDER_LEFT)) { $cbord = _BORDER_LEFT; $save = true; }
  22708. else if ($side == 'R' && $this->issetBorder($bord, _BORDER_RIGHT)) { $cbord = _BORDER_RIGHT; $save = true; }
  22709. else if ($side == 'B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { $cbord = _BORDER_BOTTOM; $save = true; }
  22710. if ($save) {
  22711. $this->cellBorderBuffer[] = pack("A16nCnda6A10d14",
  22712. str_pad(sprintf("%08.7f", $dom),16,"0",STR_PAD_LEFT),
  22713. $cbord,
  22714. ord($side),
  22715. $details[$side]['s'],
  22716. $details[$side]['w'],
  22717. $details[$side]['c'],
  22718. $details[$side]['style'],
  22719. $x, $y, $w, $h,
  22720. $details['mbw']['BL'],
  22721. $details['mbw']['BR'],
  22722. $details['mbw']['RT'],
  22723. $details['mbw']['RB'],
  22724. $details['mbw']['TL'],
  22725. $details['mbw']['TR'],
  22726. $details['mbw']['LT'],
  22727. $details['mbw']['LB'],
  22728. $details['cellposdom'],
  22729. 0
  22730. );
  22731. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset' || $details[$side]['style'] == 'double' ) {
  22732. $details[$side]['overlay'] = true;
  22733. $this->cellBorderBuffer[] = pack("A16nCnda6A10d14",
  22734. str_pad(sprintf("%08.7f", ($dom+4)),16,"0",STR_PAD_LEFT),
  22735. $cbord,
  22736. ord($side),
  22737. $details[$side]['s'],
  22738. $details[$side]['w'],
  22739. $details[$side]['c'],
  22740. $details[$side]['style'],
  22741. $x, $y, $w, $h,
  22742. $details['mbw']['BL'],
  22743. $details['mbw']['BR'],
  22744. $details['mbw']['RT'],
  22745. $details['mbw']['RB'],
  22746. $details['mbw']['TL'],
  22747. $details['mbw']['TR'],
  22748. $details['mbw']['LT'],
  22749. $details['mbw']['LB'],
  22750. $details['cellposdom'],
  22751. 1
  22752. );
  22753. }
  22754. }
  22755. }
  22756. return;
  22757. }
  22758. if (isset($details['p']) && strlen($details['p'])>1) { $priority = $details['p']; }
  22759. else { $priority='LTRB'; }
  22760. $Tw = 0;
  22761. $Rw = 0;
  22762. $Bw = 0;
  22763. $Lw = 0;
  22764. if (isset($details['T']['w'])) { $Tw = $details['T']['w']; }
  22765. if (isset($details['R']['w'])) { $Rw = $details['R']['w']; }
  22766. if (isset($details['B']['w'])) { $Bw = $details['B']['w']; }
  22767. if (isset($details['L']['w'])) { $Lw = $details['L']['w']; }
  22768. $x2 = $x + $w; $y2 = $y + $h;
  22769. $oldlinewidth = $this->LineWidth;
  22770. for($p=0;$p<strlen($priority);$p++) {
  22771. $side = $priority[$p];
  22772. $xadj = 0;
  22773. $xadj2 = 0;
  22774. $yadj = 0;
  22775. $yadj2 = 0;
  22776. $print = false;
  22777. if ($Tw && $side=='T' && $this->issetBorder($bord, _BORDER_TOP)) { // TOP
  22778. $ly1 = $y;
  22779. $ly2 = $y;
  22780. $lx1 = $x;
  22781. $lx2 = $x2;
  22782. $this->SetLineWidth($Tw);
  22783. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22784. if ($Tw > $Lw) $xadj = ($Tw - $Lw)/2;
  22785. if ($Tw < $Lw) $xadj = ($Tw + $Lw)/2;
  22786. }
  22787. else { $xadj = $Tw/2 - $bsh/2; }
  22788. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22789. if ($Tw > $Rw) $xadj2 = ($Tw - $Rw)/2;
  22790. if ($Tw < $Rw) $xadj2 = ($Tw + $Rw)/2;
  22791. }
  22792. else { $xadj2 = $Tw/2 - $bsh/2; }
  22793. if (!$bSeparate && $details['mbw']['TL']) {
  22794. $xadj = ($Tw - $details['mbw']['TL'])/2 ;
  22795. }
  22796. if (!$bSeparate && $details['mbw']['TR']) {
  22797. $xadj2 = ($Tw - $details['mbw']['TR'])/2;
  22798. }
  22799. $print = true;
  22800. }
  22801. if ($Lw && $side=='L' && $this->issetBorder($bord, _BORDER_LEFT)) { // LEFT
  22802. $ly1 = $y;
  22803. $ly2 = $y2;
  22804. $lx1 = $x;
  22805. $lx2 = $x;
  22806. $this->SetLineWidth($Lw);
  22807. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22808. if ($Lw > $Tw) $yadj = ($Lw - $Tw)/2;
  22809. if ($Lw < $Tw) $yadj = ($Lw + $Tw)/2;
  22810. }
  22811. else { $yadj = $Lw/2 - $bsv/2; }
  22812. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22813. if ($Lw > $Bw) $yadj2 = ($Lw - $Bw)/2;
  22814. if ($Lw < $Bw) $yadj2 = ($Lw + $Bw)/2;
  22815. }
  22816. else { $yadj2 = $Lw/2 - $bsv/2; }
  22817. if (!$bSeparate && $details['mbw']['LT']) {
  22818. $yadj = ($Lw - $details['mbw']['LT'])/2;
  22819. }
  22820. if (!$bSeparate && $details['mbw']['LB']) {
  22821. $yadj2 = ($Lw - $details['mbw']['LB'])/2;
  22822. }
  22823. $print = true;
  22824. }
  22825. if ($Rw && $side=='R' && $this->issetBorder($bord, _BORDER_RIGHT)) { // RIGHT
  22826. $ly1 = $y;
  22827. $ly2 = $y2;
  22828. $lx1 = $x2;
  22829. $lx2 = $x2;
  22830. $this->SetLineWidth($Rw);
  22831. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  22832. if ($Rw < $Tw) $yadj = ($Rw + $Tw)/2;
  22833. if ($Rw > $Tw) $yadj = ($Rw - $Tw)/2;
  22834. }
  22835. else { $yadj = $Rw/2 - $bsv/2; }
  22836. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  22837. if ($Rw > $Bw) $yadj2 = ($Rw - $Bw)/2;
  22838. if ($Rw < $Bw) $yadj2 = ($Rw + $Bw)/2;
  22839. }
  22840. else { $yadj2 = $Rw/2 - $bsv/2; }
  22841. if (!$bSeparate && $details['mbw']['RT']) {
  22842. $yadj = ($Rw - $details['mbw']['RT'])/2;
  22843. }
  22844. if (!$bSeparate && $details['mbw']['RB']) {
  22845. $yadj2 = ($Rw - $details['mbw']['RB'])/2;
  22846. }
  22847. $print = true;
  22848. }
  22849. if ($Bw && $side=='B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { // BOTTOM
  22850. $ly1 = $y2;
  22851. $ly2 = $y2;
  22852. $lx1 = $x;
  22853. $lx2 = $x2;
  22854. $this->SetLineWidth($Bw);
  22855. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  22856. if ($Bw > $Lw) $xadj = ($Bw - $Lw)/2;
  22857. if ($Bw < $Lw) $xadj = ($Bw + $Lw)/2;
  22858. }
  22859. else { $xadj = $Bw/2 - $bsh/2; }
  22860. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  22861. if ($Bw > $Rw) $xadj2 = ($Bw - $Rw)/2;
  22862. if ($Bw < $Rw) $xadj2 = ($Bw + $Rw)/2;
  22863. }
  22864. else { $xadj2 = $Bw/2 - $bsh/2; }
  22865. if (!$bSeparate && $details['mbw']['BL']) {
  22866. $xadj = ($Bw - $details['mbw']['BL'])/2;
  22867. }
  22868. if (!$bSeparate && $details['mbw']['BR']) {
  22869. $xadj2 = ($Bw - $details['mbw']['BR'])/2;
  22870. }
  22871. $print = true;
  22872. }
  22873. // Now draw line
  22874. if ($print) {
  22875. /*-- TABLES-ADVANCED-BORDERS --*/
  22876. if ($details[$side]['style'] == 'double') {
  22877. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22878. if ($details[$side]['c']) {
  22879. $this->SetDColor($details[$side]['c']);
  22880. }
  22881. else { $this->SetDColor($this->ConvertColor(0)); }
  22882. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22883. }
  22884. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22885. if ($bSeparate && $cort=='table') {
  22886. if ($side=='T') {
  22887. $xadj -= $this->LineWidth/2;
  22888. $xadj2 -= $this->LineWidth;
  22889. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22890. $xadj += $this->LineWidth/2;
  22891. }
  22892. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22893. $xadj2 += $this->LineWidth;
  22894. }
  22895. }
  22896. if ($side=='L') {
  22897. $yadj -= $this->LineWidth/2;
  22898. $yadj2 -= $this->LineWidth;
  22899. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22900. $yadj += $this->LineWidth/2;
  22901. }
  22902. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22903. $yadj2 += $this->LineWidth;
  22904. }
  22905. }
  22906. if ($side=='B') {
  22907. $xadj -= $this->LineWidth/2;
  22908. $xadj2 -= $this->LineWidth;
  22909. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22910. $xadj += $this->LineWidth/2;
  22911. }
  22912. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22913. $xadj2 += $this->LineWidth;
  22914. }
  22915. }
  22916. if ($side=='R') {
  22917. $yadj -= $this->LineWidth/2;
  22918. $yadj2 -= $this->LineWidth;
  22919. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22920. $yadj += $this->LineWidth/2;
  22921. }
  22922. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22923. $yadj2 += $this->LineWidth;
  22924. }
  22925. }
  22926. }
  22927. $this->SetLineWidth($this->LineWidth/3);
  22928. $tbcol = $this->ConvertColor(255);
  22929. for($l=0; $l <= $this->blklvl; $l++) {
  22930. if ($this->blk[$l]['bgcolor']) {
  22931. $tbcol = array($this->blk[$l]['bgcolorarray']);
  22932. }
  22933. }
  22934. if ($bSeparate) {
  22935. $cellBorderOverlay[] = array(
  22936. 'x' => $lx1 + $xadj,
  22937. 'y' => $ly1 + $yadj,
  22938. 'x2' => $lx2 - $xadj2,
  22939. 'y2' => $ly2 - $yadj2,
  22940. 'col' => $tbcol,
  22941. 'lw' => $this->LineWidth,
  22942. );
  22943. }
  22944. else {
  22945. $this->SetDColor($tbcol);
  22946. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22947. }
  22948. }
  22949. }
  22950. else if (isset($details[$side]['style']) && ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset')) {
  22951. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  22952. if ($details[$side]['c']) {
  22953. $this->SetDColor($details[$side]['c']);
  22954. }
  22955. else { $this->SetDColor($this->ConvertColor(0)); }
  22956. if ($details[$side]['style'] == 'outset' || $details[$side]['style'] == 'groove') {
  22957. $nc = $this->_darkenColor($details[$side]['c']);
  22958. $this->SetDColor($nc);
  22959. }
  22960. else if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22961. $nc = $this->_lightenColor($details[$side]['c']);
  22962. $this->SetDColor($nc);
  22963. }
  22964. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  22965. }
  22966. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  22967. if ($details[$side]['c']) {
  22968. $this->SetDColor($details[$side]['c']);
  22969. }
  22970. else { $this->SetDColor($this->ConvertColor(0)); }
  22971. $doubleadj = ($this->LineWidth)/3;
  22972. $this->SetLineWidth($this->LineWidth/2);
  22973. $xadj3 = $yadj3 = $wadj3 = $hadj3 = 0;
  22974. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  22975. $nc = $this->_darkenColor($details[$side]['c']);
  22976. if ($bSeparate && $cort=='table') {
  22977. if ($side=='T') {
  22978. $yadj3 = $this->LineWidth/2;
  22979. $xadj3 = -$this->LineWidth/2;
  22980. $wadj3 = $this->LineWidth;
  22981. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  22982. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  22983. }
  22984. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  22985. $wadj3 -= $this->LineWidth*2;
  22986. }
  22987. }
  22988. if ($side=='L') {
  22989. $xadj3 = $this->LineWidth/2;
  22990. $yadj3 = -$this->LineWidth/2;
  22991. $hadj3 = $this->LineWidth;
  22992. if ($this->issetBorder($bord, _BORDER_TOP)) {
  22993. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  22994. }
  22995. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  22996. $hadj3 -= $this->LineWidth*2;
  22997. }
  22998. }
  22999. if ($side=='B') {
  23000. $yadj3 = $this->LineWidth/2;
  23001. $xadj3 = -$this->LineWidth/2;
  23002. $wadj3 = $this->LineWidth;
  23003. }
  23004. if ($side=='R') {
  23005. $xadj3 = $this->LineWidth/2;
  23006. $yadj3 = -$this->LineWidth/2;
  23007. $hadj3 = $this->LineWidth;
  23008. }
  23009. }
  23010. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; $wadj3 = -$this->LineWidth*2; }
  23011. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; $hadj3 = -$this->LineWidth*2; }
  23012. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $wadj3 = $this->LineWidth/2; }
  23013. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $hadj3 = $this->LineWidth/2; }
  23014. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  23015. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  23016. }
  23017. else {
  23018. $nc = $this->_lightenColor($details[$side]['c']);
  23019. if ($bSeparate && $cort=='table') {
  23020. if ($side=='T') {
  23021. $yadj3 = $this->LineWidth/2;
  23022. $xadj3 = -$this->LineWidth/2;
  23023. $wadj3 = $this->LineWidth;
  23024. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  23025. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  23026. }
  23027. }
  23028. if ($side=='L') {
  23029. $xadj3 = $this->LineWidth/2;
  23030. $yadj3 = -$this->LineWidth/2;
  23031. $hadj3 = $this->LineWidth;
  23032. if ($this->issetBorder($bord, _BORDER_TOP)) {
  23033. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  23034. }
  23035. }
  23036. if ($side=='B') {
  23037. $yadj3 = $this->LineWidth/2;
  23038. $xadj3 = -$this->LineWidth/2;
  23039. $wadj3 = $this->LineWidth;
  23040. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  23041. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  23042. }
  23043. }
  23044. if ($side=='R') {
  23045. $xadj3 = $this->LineWidth/2;
  23046. $yadj3 = -$this->LineWidth/2;
  23047. $hadj3 = $this->LineWidth;
  23048. if ($this->issetBorder($bord, _BORDER_TOP)) {
  23049. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  23050. }
  23051. }
  23052. }
  23053. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  23054. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  23055. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  23056. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  23057. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; }
  23058. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; }
  23059. }
  23060. if ($bSeparate) {
  23061. $cellBorderOverlay[] = array(
  23062. 'x' => $lx1 + $xadj + $xadj3,
  23063. 'y' => $ly1 + $yadj + $yadj3,
  23064. 'x2' => $lx2 - $xadj2 + $xadj3 + $wadj3,
  23065. 'y2' => $ly2 - $yadj2 + $yadj3 + $hadj3,
  23066. 'col' => $nc,
  23067. 'lw' => $this->LineWidth,
  23068. );
  23069. }
  23070. else {
  23071. $this->SetDColor($nc);
  23072. $this->Line($lx1 + $xadj + $xadj3, $ly1 + $yadj + $yadj3, $lx2 - $xadj2 + $xadj3 + $wadj3, $ly2 - $yadj2 + $yadj3 + $hadj3);
  23073. }
  23074. }
  23075. }
  23076. else {
  23077. /*-- END TABLES-ADVANCED-BORDERS --*/
  23078. if ($details[$side]['style'] == 'dashed') {
  23079. $dashsize = 2; // final dash will be this + 1*linewidth
  23080. $dashsizek = 1.5; // ratio of Dash/Blank
  23081. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  23082. }
  23083. else if ($details[$side]['style'] == 'dotted') {
  23084. $this->SetLineJoin(1);
  23085. $this->SetLineCap(1);
  23086. $this->SetDash(0.001,($this->LineWidth*2));
  23087. }
  23088. if ($details[$side]['c']) {
  23089. $this->SetDColor($details[$side]['c']);
  23090. }
  23091. else { $this->SetDColor($this->ConvertColor(0)); }
  23092. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  23093. /*-- TABLES-ADVANCED-BORDERS --*/
  23094. }
  23095. /*-- END TABLES-ADVANCED-BORDERS --*/
  23096. // Reset Corners
  23097. $this->SetDash();
  23098. //BUTT style line cap
  23099. $this->SetLineCap(2);
  23100. }
  23101. }
  23102. if ($bSeparate && count($cellBorderOverlay)) {
  23103. foreach($cellBorderOverlay AS $cbo) {
  23104. $this->SetLineWidth($cbo['lw']);
  23105. $this->SetDColor($cbo['col']);
  23106. $this->Line($cbo['x'], $cbo['y'], $cbo['x2'], $cbo['y2']);
  23107. }
  23108. }
  23109. // $this->SetLineWidth($oldlinewidth);
  23110. // $this->SetDColor($this->ConvertColor(0));
  23111. }
  23112. }
  23113. /*-- TABLES --*/
  23114. /*-- TABLES-ADVANCED-BORDERS --*/
  23115. function _lightenColor($c) {
  23116. if (is_array($c)) { die('Color error in _lightencolor'); }
  23117. if ($c{0}==3 || $c{0}==5) { // RGB
  23118. list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255);
  23119. $l += ((1 - $l)*0.8);
  23120. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  23121. $ret = array(3,$r,$g,$b);
  23122. }
  23123. else if ($c{0}==4 || $c{0}==6) { // CMYK
  23124. $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)) );
  23125. }
  23126. else if ($c{0}==1) { // Grayscale
  23127. $ret = array(1,min(255,(ord($c{1})+32)));
  23128. }
  23129. $c = array_pad($ret, 6, 0);
  23130. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  23131. return $cstr;
  23132. }
  23133. function _darkenColor($c) {
  23134. if (is_array($c)) { die('Color error in _darkenColor'); }
  23135. if ($c{0}==3 || $c{0}==5) { // RGB
  23136. list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255);
  23137. $s *= 0.25;
  23138. $l *= 0.75;
  23139. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  23140. $ret = array(3,$r,$g,$b);
  23141. }
  23142. else if ($c{0}==4 || $c{0}==6) { // CMYK
  23143. $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)) );
  23144. }
  23145. else if ($c{0}==1) { // Grayscale
  23146. $ret = array(1,max(0,(ord($c{1})-32)));
  23147. }
  23148. $c = array_pad($ret, 6, 0);
  23149. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  23150. return $cstr;
  23151. }
  23152. /*-- END TABLES-ADVANCED-BORDERS --*/
  23153. function setBorder(&$var, $flag, $set = true) {
  23154. $flag = intval($flag);
  23155. if ($set) { $set = true; }
  23156. $var = intval($var);
  23157. $var = $set ? ($var | $flag) : ($var & ~$flag);
  23158. }
  23159. function issetBorder($var, $flag) {
  23160. $flag = intval($flag);
  23161. $var = intval($var);
  23162. return (($var & $flag) == $flag);
  23163. }
  23164. function _table2cellBorder(&$tableb, &$cbdb, &$cellb, $bval) {
  23165. if ($tableb && $tableb['w'] > $cbdb['w']) {
  23166. $cbdb = $tableb;
  23167. $this->setBorder($cellb, $bval);
  23168. }
  23169. else if ($tableb && $tableb['w'] == $cbdb['w']
  23170. && array_search($tableb['style'],$this->borderstyles) > array_search($cbdb['style'],$this->borderstyles)) {
  23171. $cbdb = $tableb;
  23172. $this->setBorder($cellb, $bval);
  23173. }
  23174. }
  23175. // FIX BORDERS ********************************************
  23176. function _fixTableBorders(&$table){
  23177. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23178. else { $fh = null; }
  23179. if (!$table['borders_separate'] && $table['border_details']['L']['w']) {
  23180. $table['max_cell_border_width']['L'] = $table['border_details']['L']['w'];
  23181. }
  23182. if (!$table['borders_separate'] && $table['border_details']['R']['w']) {
  23183. $table['max_cell_border_width']['R'] = $table['border_details']['R']['w'];
  23184. }
  23185. if (!$table['borders_separate'] && $table['border_details']['T']['w']) {
  23186. $table['max_cell_border_width']['T'] = $table['border_details']['T']['w'];
  23187. }
  23188. if (!$table['borders_separate'] && $table['border_details']['B']['w']) {
  23189. $table['max_cell_border_width']['B'] = $table['border_details']['B']['w'];
  23190. }
  23191. if ($this->simpleTables) { return; }
  23192. $cells = &$table['cells'];
  23193. $numcols = $table['nc'];
  23194. $numrows = $table['nr'];
  23195. /*-- TABLES-ADVANCED-BORDERS --*/
  23196. if (isset($table['topntail']) && $table['topntail']) { $tntborddet = $this->border_details($table['topntail']); }
  23197. if (isset($table['thead-underline']) && $table['thead-underline']) { $thuborddet = $this->border_details($table['thead-underline']); }
  23198. /*-- END TABLES-ADVANCED-BORDERS --*/
  23199. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23200. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  23201. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23202. if ($this->cacheTables) {
  23203. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23204. }
  23205. else
  23206. $cell = &$cells[$i][$j];
  23207. if ($this->packTableData) { // includes $this->cacheTables
  23208. $cbord = $this->_unpackCellBorder($cell['borderbin']);
  23209. }
  23210. else {
  23211. $cbord = &$cells[$i][$j];
  23212. }
  23213. if (!$cbord['border'] && isset($table['border']) && $table['border'] && $this->table_border_attr_set) {
  23214. $cbord['border'] = $table['border'];
  23215. $cbord['border_details'] = $table['border_details'];
  23216. }
  23217. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  23218. else { $ccolsp = 1; }
  23219. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  23220. else { $crowsp = 1; }
  23221. $cbord['border_details']['cellposdom'] = ((($i+1)/$numrows) / 10000 ) + ((($j+1)/$numcols) / 10 );
  23222. // Inherit Cell border from Table border
  23223. if ($this->table_border_css_set && !$table['borders_separate']) {
  23224. if ($i == 0) {
  23225. $this->_table2cellBorder($table['border_details']['T'], $cbord['border_details']['T'], $cbord['border'], _BORDER_TOP);
  23226. }
  23227. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  23228. $this->_table2cellBorder($table['border_details']['B'], $cbord['border_details']['B'], $cbord['border'], _BORDER_BOTTOM);
  23229. }
  23230. if ($j == 0) {
  23231. $this->_table2cellBorder($table['border_details']['L'], $cbord['border_details']['L'], $cbord['border'], _BORDER_LEFT);
  23232. }
  23233. if ($j == ($numcols-1) || ($j+$ccolsp) == ($numcols) ) {
  23234. $this->_table2cellBorder($table['border_details']['R'], $cbord['border_details']['R'], $cbord['border'], _BORDER_RIGHT);
  23235. }
  23236. }
  23237. /*-- TABLES-ADVANCED-BORDERS --*/
  23238. $fixbottom = true;
  23239. if (isset($table['topntail']) && $table['topntail']) {
  23240. if ($i == 0) {
  23241. $cbord['border_details']['T'] = $tntborddet;
  23242. $this->setBorder($cbord['border'], _BORDER_TOP);
  23243. }
  23244. if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) {
  23245. $cbord['border_details']['B'] = $tntborddet;
  23246. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23247. $fixbottom = false;
  23248. }
  23249. else if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']) {
  23250. if (!$table['borders_separate']) {
  23251. $cbord['border_details']['T'] = $tntborddet;
  23252. $this->setBorder($cbord['border'], _BORDER_TOP);
  23253. }
  23254. }
  23255. if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows']-1)) {
  23256. if (!$table['borders_separate']) {
  23257. $cbord['border_details']['B'] = $tntborddet;
  23258. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23259. $fixbottom = false;
  23260. }
  23261. }
  23262. else if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows'])) {
  23263. $cbord['border_details']['T'] = $tntborddet;
  23264. $this->setBorder($cbord['border'], _BORDER_TOP);
  23265. }
  23266. if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  23267. if (!$table['borders_separate']) {
  23268. $cbord['border_details']['T'] = $tntborddet;
  23269. $this->setBorder($cbord['border'], _BORDER_TOP);
  23270. }
  23271. }
  23272. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  23273. $cbord['border_details']['B'] = $tntborddet;
  23274. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23275. }
  23276. }
  23277. if (isset($table['thead-underline']) && $table['thead-underline']) {
  23278. if ($table['borders_separate']) {
  23279. if ($i == 0) {
  23280. $cbord['border_details']['B'] = $thuborddet;
  23281. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  23282. $fixbottom = false;
  23283. }
  23284. }
  23285. else {
  23286. if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) {
  23287. $cbord['border_details']['T'] = $thuborddet;
  23288. $this->setBorder($cbord['border'], _BORDER_TOP);
  23289. }
  23290. else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  23291. $cbord['border_details']['T'] = $thuborddet;
  23292. $this->setBorder($cbord['border'], _BORDER_TOP);
  23293. }
  23294. }
  23295. }
  23296. // Collapse Border - Algorithm for conflicting borders
  23297. // Hidden >> Width >> double>solid>dashed>dotted... >> style set on cell>table >> top/left>bottom/right
  23298. // Do not turn off border which is overridden
  23299. // Needed for page break for TOP/BOTTOM both to be defined in Collapsed borders
  23300. // Means it is painted twice. (Left/Right can still disable overridden border)
  23301. if (!$table['borders_separate']) {
  23302. if (($i < ($numrows-1) || ($i+$crowsp) < $numrows ) && $fixbottom ) { // Bottom
  23303. for ($cspi = 0; $cspi<$ccolsp; $cspi++) {
  23304. // already defined Top for adjacent cell below
  23305. if (isset($cells[($i+$crowsp)][$j+$cspi])) {
  23306. if ($this->packTableData) {
  23307. if ($this->cacheTables) {
  23308. $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j+$cspi], '', $fh);
  23309. }
  23310. else { $adjc = $cells[($i+$crowsp)][$j+$cspi]; }
  23311. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23312. }
  23313. else { $celladj =& $cells[($i+$crowsp)][$j+$cspi]; }
  23314. }
  23315. else { $celladj = false; }
  23316. if ($celladj && $celladj['border_details']['T']['s'] == 1) {
  23317. $csadj = $celladj['border_details']['T']['w'];
  23318. $csthis = $cbord['border_details']['B']['w'];
  23319. // Hidden
  23320. if ($cbord['border_details']['B']['style']=='hidden') {
  23321. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23322. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  23323. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  23324. }
  23325. else if ($celladj['border_details']['T']['style']=='hidden') {
  23326. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23327. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  23328. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  23329. }
  23330. // Width
  23331. else if ($csthis > $csadj) {
  23332. 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
  23333. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23334. $this->setBorder($cbord['border'] , _BORDER_BOTTOM);
  23335. }
  23336. }
  23337. else if ($csadj > $csthis) {
  23338. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  23339. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23340. $this->setBorder($celladj['border'] , _BORDER_TOP);
  23341. }
  23342. }
  23343. // double>solid>dashed>dotted...
  23344. else if (array_search($cbord['border_details']['B']['style'],$this->borderstyles) > array_search($celladj['border_details']['T']['style'],$this->borderstyles)) {
  23345. 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
  23346. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23347. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  23348. }
  23349. }
  23350. else if (array_search($celladj['border_details']['T']['style'],$this->borderstyles) > array_search($cbord['border_details']['B']['style'],$this->borderstyles)) {
  23351. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  23352. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23353. $this->setBorder($celladj['border'] , _BORDER_TOP);
  23354. }
  23355. }
  23356. // Style set on cell vs. table
  23357. else if ($celladj['border_details']['T']['dom'] > $cbord['border_details']['B']['dom']) {
  23358. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  23359. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  23360. $this->setBorder($celladj['border'] , _BORDER_TOP);
  23361. }
  23362. }
  23363. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  23364. else {
  23365. 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
  23366. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23367. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  23368. }
  23369. }
  23370. }
  23371. else if ($celladj) {
  23372. 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
  23373. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  23374. }
  23375. }
  23376. if ($celladj && $this->packTableData) {
  23377. $celladj['borderbin'] = $this->_packCellBorder($celladj);
  23378. unset($celladj['border']);
  23379. unset($celladj['border_details']);
  23380. }
  23381. if ($this->cacheTables) {
  23382. $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$crowsp][$j+$cspi]);
  23383. }
  23384. unset($celladj);
  23385. }
  23386. }
  23387. if ($j < ($numcols-1) || ($j+$ccolsp) < $numcols ) { // Right-Left
  23388. for ($cspi = 0; $cspi<$crowsp; $cspi++) {
  23389. // already defined Left for adjacent cell to R
  23390. if (isset($cells[($i+$cspi)][$j+$ccolsp])) {
  23391. if ($this->packTableData) {
  23392. if ($this->cacheTables) {
  23393. $adjc = $this->_uncacheCell($table['cells'][$i+$cspi][$j+$ccolsp], '', $fh);
  23394. }
  23395. else { $adjc = $cells[($i+$cspi)][$j+$ccolsp]; }
  23396. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23397. }
  23398. else { $celladj =& $cells[$i+$cspi][$j+$ccolsp]; }
  23399. }
  23400. else { $celladj = false; }
  23401. if ($celladj && $celladj['border_details']['L']['s'] == 1) {
  23402. $csadj = $celladj['border_details']['L']['w'];
  23403. $csthis = $cbord['border_details']['R']['w'];
  23404. // Hidden
  23405. if ($cbord['border_details']['R']['style']=='hidden') {
  23406. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23407. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23408. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  23409. }
  23410. else if ($celladj['border_details']['L']['style']=='hidden') {
  23411. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23412. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  23413. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23414. }
  23415. // Width
  23416. else if ($csthis > $csadj) {
  23417. 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
  23418. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23419. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  23420. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23421. }
  23422. }
  23423. else if ($csadj > $csthis) {
  23424. if ($crowsp < 2) { // don't overwrite this cell if it spans
  23425. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23426. $this->setBorder($cbord['border'] , _BORDER_RIGHT, false);
  23427. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  23428. }
  23429. }
  23430. // double>solid>dashed>dotted...
  23431. else if (array_search($cbord['border_details']['R']['style'],$this->borderstyles) > array_search($celladj['border_details']['L']['style'],$this->borderstyles)) {
  23432. 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
  23433. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23434. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  23435. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  23436. }
  23437. }
  23438. else if (array_search($celladj['border_details']['L']['style'],$this->borderstyles) > array_search($cbord['border_details']['R']['style'],$this->borderstyles)) {
  23439. if ($crowsp < 2) { // don't overwrite this cell if it spans
  23440. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23441. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  23442. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  23443. }
  23444. }
  23445. // Style set on cell vs. table
  23446. else if ($celladj['border_details']['L']['dom'] > $cbord['border_details']['R']['dom']) {
  23447. if ($crowsp < 2) { // don't overwrite this cell if it spans
  23448. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  23449. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  23450. }
  23451. }
  23452. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  23453. else {
  23454. 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
  23455. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23456. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  23457. }
  23458. }
  23459. }
  23460. else if ($celladj) {
  23461. // if right-cell border is not set
  23462. 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
  23463. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  23464. }
  23465. }
  23466. if ($celladj && $this->packTableData) {
  23467. $celladj['borderbin'] = $this->_packCellBorder($celladj);
  23468. unset($celladj['border']);
  23469. unset($celladj['border_details']);
  23470. }
  23471. if ($this->cacheTables) {
  23472. $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$cspi][$j+$ccolsp]);
  23473. }
  23474. unset($celladj);
  23475. }
  23476. }
  23477. }
  23478. // Set maximum cell border width meeting at LRTB edges of cell - used for extended cell border
  23479. // ['border_details']['mbw']['LT'] = meeting border width - Left border - Top end
  23480. if (!$table['borders_separate']) {
  23481. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $cbord['border_details']['L']['w']);
  23482. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $cbord['border_details']['R']['w']);
  23483. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $cbord['border_details']['T']['w']);
  23484. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $cbord['border_details']['B']['w']);
  23485. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $cbord['border_details']['L']['w']);
  23486. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $cbord['border_details']['R']['w']);
  23487. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $cbord['border_details']['T']['w']);
  23488. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $cbord['border_details']['B']['w']);
  23489. if (($i+$crowsp) < $numrows && isset($cells[$i+$crowsp][$j])) { // Has Bottom adjoining cell
  23490. if ($this->packTableData) {
  23491. if ($this->cacheTables) {
  23492. $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j], '', $fh);
  23493. }
  23494. else { $adjc = $cells[$i+$crowsp][$j]; }
  23495. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23496. }
  23497. else { $celladj =& $cells[$i+$crowsp][$j]; }
  23498. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['TL']);
  23499. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['TR']);
  23500. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['mbw']['LT']);
  23501. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['mbw']['RT']);
  23502. unset($celladj);
  23503. }
  23504. if (($j+$ccolsp) < $numcols && isset($cells[$i][$j+$ccolsp])) { // Has Right adjoining cell
  23505. if ($this->packTableData) {
  23506. if ($this->cacheTables) {
  23507. $adjc = $this->_uncacheCell($table['cells'][$i][$j+$ccolsp], '', $fh);
  23508. }
  23509. else { $adjc = $cells[$i][$j+$ccolsp]; }
  23510. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23511. }
  23512. else { $celladj =& $cells[$i][$j+$ccolsp]; }
  23513. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['LT']);
  23514. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['LB']);
  23515. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['mbw']['TL']);
  23516. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['mbw']['BL']);
  23517. unset($celladj);
  23518. }
  23519. if ($i > 0 && isset($cells[$i-1][$j]) && (($this->packTableData && $cells[$i-1][$j]['borderbin']) || $cells[$i-1][$j]['border'])) { // Has Top adjoining cell
  23520. if ($this->packTableData) {
  23521. if ($this->cacheTables) {
  23522. $adjc = $this->_uncacheCell($table['cells'][$i-1][$j], '', $fh);
  23523. }
  23524. else { $adjc = $cells[$i-1][$j]; }
  23525. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23526. }
  23527. else { $celladj =& $cells[$i-1][$j]; }
  23528. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['BL']);
  23529. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['BR']);
  23530. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['mbw']['LB']);
  23531. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['mbw']['RB']);
  23532. if ($celladj['border_details']['mbw']['BL']) {
  23533. $celladj['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['BL']);
  23534. }
  23535. if ($celladj['border_details']['mbw']['BR'] ) {
  23536. $celladj['border_details']['mbw']['BR'] = max($celladj['border_details']['mbw']['BR'], $cbord['border_details']['mbw']['TR']);
  23537. }
  23538. if ($this->packTableData) { $cells[$i-1][$j]['borderbin'] = $this->_packCellBorder($celladj); }
  23539. unset($celladj);
  23540. }
  23541. if ($j > 0 && isset($cells[$i][$j-1]) && (($this->packTableData && $cells[$i][$j-1]['borderbin']) || $cells[$i][$j-1]['border'])) { // Has Left adjoining cell
  23542. if ($this->packTableData) {
  23543. if ($this->cacheTables) {
  23544. $adjc = $this->_uncacheCell($table['cells'][$i][$j-1], '', $fh);
  23545. }
  23546. else { $adjc = $cells[$i][$j-1]; }
  23547. $celladj = $this->_unpackCellBorder($adjc['borderbin']);
  23548. }
  23549. else { $celladj =& $cells[$i][$j-1]; }
  23550. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['RT']);
  23551. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['RB']);
  23552. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['mbw']['BR']);
  23553. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['TR']);
  23554. if ($celladj['border_details']['mbw']['RT']) {
  23555. $celladj['border_details']['mbw']['RT'] = max($celladj['border_details']['mbw']['RT'], $cbord['border_details']['mbw']['LT']);
  23556. }
  23557. if ($celladj['border_details']['mbw']['RB']) {
  23558. $celladj['border_details']['mbw']['RB'] = max($celladj['border_details']['mbw']['RB'], $cbord['border_details']['mbw']['LB']);
  23559. }
  23560. if ($this->packTableData) { $cells[$i][$j-1]['borderbin'] = $this->_packCellBorder($celladj); }
  23561. unset($celladj);
  23562. }
  23563. // Update maximum cell border width at LRTB edges of table - used for overall table width
  23564. if ($j == 0 && $cbord['border_details']['L']['w']) {
  23565. $table['max_cell_border_width']['L'] = max($table['max_cell_border_width']['L'],$cbord['border_details']['L']['w']);
  23566. }
  23567. if (($j == ($numcols-1) || ($j+$ccolsp) == $numcols ) && $cbord['border_details']['R']['w']) {
  23568. $table['max_cell_border_width']['R'] = max($table['max_cell_border_width']['R'],$cbord['border_details']['R']['w']);
  23569. }
  23570. if ($i == 0 && $cbord['border_details']['T']['w']) {
  23571. $table['max_cell_border_width']['T'] = max($table['max_cell_border_width']['T'],$cbord['border_details']['T']['w']);
  23572. }
  23573. if (($i == ($numrows-1) || ($i+$crowsp) == $numrows ) && $cbord['border_details']['B']['w']) {
  23574. $table['max_cell_border_width']['B'] = max($table['max_cell_border_width']['B'],$cbord['border_details']['B']['w']);
  23575. }
  23576. }
  23577. /*-- END TABLES-ADVANCED-BORDERS --*/
  23578. if ($this->packTableData) { $cell['borderbin'] = $this->_packCellBorder($cbord); }
  23579. if ($this->cacheTables) {
  23580. $this->_cacheUpdateBorder($cell, $fh, $table['cells'][$i][$j]);
  23581. }
  23582. unset($cbord );
  23583. unset($cell );
  23584. }
  23585. }
  23586. }
  23587. if ($this->cacheTables) { fclose($fh); }
  23588. unset($cell );
  23589. }
  23590. // END FIX BORDERS ************************************************************************************
  23591. function _reverseTableDir(&$table) {
  23592. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23593. $cells = &$table['cells'];
  23594. $numcols = $table['nc'];
  23595. $numrows = $table['nr'];
  23596. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  23597. $row = array();
  23598. for( $j = ($numcols-1) ; $j >= 0 ; $j-- ) { //Columns
  23599. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23600. if ($this->cacheTables) {
  23601. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23602. }
  23603. else
  23604. $cell = &$cells[$i][$j];
  23605. $col = $numcols - $j - 1;
  23606. if (isset($cell['colspan']) && $cell['colspan'] > 1) { $col -= ($cell['colspan']-1); }
  23607. // Nested content
  23608. for ($n=0; $n < count($cell['textbuffer']); $n++) {
  23609. $t = $cell['textbuffer'][$n][0];
  23610. if (substr($t,0,19) == "\xbb\xa4\xactype=nestedtable") {
  23611. $objattr = $this->_getObjAttr($t);
  23612. $objattr['col'] = $col;
  23613. $cell['textbuffer'][$n][0] = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  23614. $this->table[($this->tableLevel+1)][$objattr['nestedcontent']]['nestedpos'][1] = $col;
  23615. if ($this->cacheTables) {
  23616. $this->_cacheUpdateTxB($cell, $fh, $table['cells'][$i][$j]);
  23617. }
  23618. }
  23619. }
  23620. $row[$col] = $cells[$i][$j];
  23621. unset($cell);
  23622. }
  23623. }
  23624. for($f=0; $f < $numcols; $f++) {
  23625. if (!isset($row[$f])) { $row[$f] = 0; }
  23626. }
  23627. $table['cells'][$i] = $row;
  23628. }
  23629. if ($this->cacheTables) { fclose($fh); }
  23630. }
  23631. function _tableWrite(&$table, $split=false, $startrow=0, $startcol=0, $splitpg=0, $rety = 0){
  23632. $level = $table['level'];
  23633. $levelid = $table['levelid'];
  23634. $cells = &$table['cells'];
  23635. $numcols = $table['nc'];
  23636. $numrows = $table['nr'];
  23637. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  23638. if (!$split || ($startrow==0 && $splitpg==0) || $startrow>0){
  23639. // TABLE TOP MARGIN
  23640. if ($table['margin']['T']) {
  23641. if (!$this->table_rotate && $level==1) {
  23642. $this->DivLn($table['margin']['T'],$this->blklvl,true,1); // collapsible
  23643. }
  23644. else {
  23645. $this->y += ($table['margin']['T']);
  23646. }
  23647. }
  23648. // Advance down page by half width of top border
  23649. if ($table['borders_separate']) {
  23650. if ($startrow>0 && (!isset($table['is_thead']) || count($table['is_thead'])==0))
  23651. $adv = $table['border_spacing_V']/2;
  23652. else
  23653. $adv = $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2;
  23654. }
  23655. else {
  23656. $adv = $table['max_cell_border_width']['T']/2;
  23657. }
  23658. if (!$this->table_rotate && $level==1) { $this->DivLn($adv); }
  23659. else { $this->y += $adv; }
  23660. }
  23661. if ($level==1) {
  23662. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'];
  23663. $x0 = $this->x;
  23664. $y0 = $this->y;
  23665. $right = $x0 + $this->blk[$this->blklvl]['inner_width'];
  23666. $outerfilled = $this->y; // Keep track of how far down the outer DIV bgcolor is painted (NB rowspans)
  23667. $this->outerfilled = $this->y;
  23668. $this->colsums = array();
  23669. }
  23670. else {
  23671. $x0 = $this->x;
  23672. $y0 = $this->y;
  23673. $right = $x0 + $table['w'];
  23674. }
  23675. if ($this->table_rotate) {
  23676. $temppgwidth = $this->tbrot_maxw;
  23677. $this->PageBreakTrigger = $pagetrigger = $y0 + ($this->blk[$this->blklvl]['inner_width']);
  23678. if ($level==1) {
  23679. $this->tbrot_y0 = $this->y - $adv - $table['margin']['T'] ;
  23680. $this->tbrot_x0 = $this->x;
  23681. $this->tbrot_w = $table['w'];
  23682. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  23683. else { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['max_cell_border_width']['T']; }
  23684. }
  23685. }
  23686. else {
  23687. $this->PageBreakTrigger = $pagetrigger = ($this->h - $this->bMargin);
  23688. if ($level==1) {
  23689. $temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  23690. if (isset($table['a']) and ($table['w'] < $this->blk[$this->blklvl]['inner_width'])) {
  23691. if ($table['a']=='C') { $x0 += ((($right-$x0) - $table['w'])/2); }
  23692. else if ($table['a']=='R') { $x0 = $right - $table['w']; }
  23693. }
  23694. }
  23695. else {
  23696. $temppgwidth = $table['w'];
  23697. }
  23698. }
  23699. if(!isset($table['overflow'])) { $table['overflow'] = null; }
  23700. if ($table['overflow']=='hidden' && $level==1 && !$this->table_rotate && !$this->ColActive) {
  23701. //Bounding rectangle to clip
  23702. $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);
  23703. $this->_out($this->tableClipPath);
  23704. }
  23705. else { $this->tableClipPath = ''; }
  23706. if ($table['borders_separate']) { $indent = $table['margin']['L'] + $table['border_details']['L']['w'] + $table['padding']['L'] + $table['border_spacing_H']/2; }
  23707. else { $indent = $table['margin']['L'] + $table['max_cell_border_width']['L']/2; }
  23708. $x0 += $indent;
  23709. $returny = 0;
  23710. $lastCol = 0;
  23711. $tableheader = array();
  23712. $tablefooter = array();
  23713. $tableheaderrowheight = 0;
  23714. $tablefooterrowheight = 0;
  23715. $footery = 0;
  23716. // mPD 3.0 Set the Page & Column where table starts
  23717. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  23718. $tablestartpage = 'EVEN';
  23719. }
  23720. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  23721. $tablestartpage = 'ODD';
  23722. }
  23723. else { $tablestartpage = ''; }
  23724. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; }
  23725. else { $tablestartcolumn = ''; }
  23726. if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); }
  23727. else { $fh = null; }
  23728. $y = $h = 0;
  23729. for( $i = 0; $i < $numrows ; $i++ ) { //Rows
  23730. if ($this->progressBar) { $this->UpdateProgressBar(7,intval(30 + ($i*40/$numrows)),' '); } // *PROGRESS-BAR*
  23731. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i] && $level==1) {
  23732. $tablefooterrowheight += $table['hr'][$i];
  23733. $tablefooter[$i][0]['trbackground-images'] = $table['trbackground-images'][$i];
  23734. $tablefooter[$i][0]['trgradients'] = $table['trgradients'][$i];
  23735. $tablefooter[$i][0]['trbgcolor'] = $table['bgcolor'][$i];
  23736. for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns
  23737. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23738. if ($this->cacheTables) {
  23739. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23740. }
  23741. else
  23742. $cell = &$cells[$i][$j];
  23743. if ($split) {
  23744. if ($table['colPg'][$j] != $splitpg) { continue; }
  23745. list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh);
  23746. $js = $j - $startcol;
  23747. }
  23748. else {
  23749. list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh);
  23750. $js = $j;
  23751. }
  23752. list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh);
  23753. $x += $x0;
  23754. $y += $y0;
  23755. //Get info of tfoot ==>> table footer
  23756. $tablefooter[$i][$js]['x'] = $x;
  23757. $tablefooter[$i][$js]['y'] = $y;
  23758. $tablefooter[$i][$js]['h'] = $h;
  23759. $tablefooter[$i][$js]['w'] = $w;
  23760. if (isset($cell['textbuffer'])) { $tablefooter[$i][$js]['textbuffer'] = $cell['textbuffer']; }
  23761. else { $tablefooter[$i][$js]['textbuffer'] = ''; }
  23762. $tablefooter[$i][$js]['a'] = $cell['a'];
  23763. $tablefooter[$i][$js]['R'] = $cell['R'];
  23764. $tablefooter[$i][$js]['va'] = $cell['va'];
  23765. $tablefooter[$i][$js]['mih'] = $cell['mih'];
  23766. $tablefooter[$i][$js]['gradient'] = $cell['gradient']; // *BACKGROUNDS*
  23767. $tablefooter[$i][$js]['background-image'] = $cell['background-image']; // *BACKGROUNDS*
  23768. //CELL FILL BGCOLOR
  23769. if (!$this->simpleTables){
  23770. if ($this->packTableData) {
  23771. $c = $this->_unpackCellBorder($cell['borderbin']);
  23772. $tablefooter[$i][$js]['border'] = $c['border'];
  23773. $tablefooter[$i][$js]['border_details'] = $c['border_details'];
  23774. }
  23775. else {
  23776. $tablefooter[$i][$js]['border'] = $cell['border'];
  23777. $tablefooter[$i][$js]['border_details'] = $cell['border_details'];
  23778. }
  23779. }
  23780. else if ($this->simpleTables){
  23781. $tablefooter[$i][$js]['border'] = $table['simple']['border'];
  23782. $tablefooter[$i][$js]['border_details'] = $table['simple']['border_details'];
  23783. }
  23784. $tablefooter[$i][$js]['bgcolor'] = $cell['bgcolor'];
  23785. $tablefooter[$i][$js]['padding'] = $cell['padding'];
  23786. $tablefooter[$i][$js]['rowspan'] = $cell['rowspan'];
  23787. $tablefooter[$i][$js]['colspan'] = $cell['colspan'];
  23788. }
  23789. }
  23790. }
  23791. }
  23792. if ($level==1) { $this->_out('___TABLE___BACKGROUNDS'.date('jY')); }
  23793. $tableheaderadj = 0;
  23794. $tablefooteradj = 0;
  23795. $tablestartpageno = $this->page;
  23796. //Draw Table Contents and Borders
  23797. for( $i = 0; $i < $numrows ; $i++ ) { //Rows
  23798. if ($split && $startrow > 0) {
  23799. $thnr = (isset($table['is_thead']) ? count($table['is_thead']) : 0);
  23800. if ($i >= $thnr && $i < $startrow) { continue; }
  23801. if ($i == $startrow){ $returny = $rety - $tableheaderrowheight; }
  23802. }
  23803. // Get Maximum row/cell height in row - including rowspan>1 + 1 overlapping
  23804. $maxrowheight = $this->_tableGetMaxRowHeight($table, $i, $fh);
  23805. $skippage = false;
  23806. $newpagestarted = false;
  23807. for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns
  23808. if ($split) {
  23809. if ($table['colPg'][$j] > $splitpg) { break; }
  23810. $lastCol = $j;
  23811. }
  23812. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  23813. if ($this->cacheTables) {
  23814. $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh);
  23815. }
  23816. else
  23817. $cell = &$cells[$i][$j];
  23818. if ($split) {
  23819. $lastCol = $j + (isset($cell['colspan']) ? ($cell['colspan']-1) : 0) ;
  23820. list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh);
  23821. }
  23822. else { list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh); }
  23823. list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh);
  23824. $x += $x0;
  23825. $y += $y0;
  23826. $y -= $returny;
  23827. if ($table['borders_separate']) {
  23828. if (!empty($tablefooter) || $i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) {
  23829. $extra = $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23830. //$extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  23831. }
  23832. else {
  23833. $extra = $table['border_spacing_V']/2;
  23834. }
  23835. }
  23836. else { $extra = $table['max_cell_border_width']['B']/2; }
  23837. 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 ) {
  23838. if (!$skippage) {
  23839. $finalSpread = true;
  23840. $firstSpread = true;
  23841. if ($split) {
  23842. for($t=$startcol; $t<$numcols; $t++) {
  23843. // Are there more columns to print on a next page?
  23844. if ($table['colPg'][$t] > $splitpg) {
  23845. $finalSpread = false;
  23846. break;
  23847. }
  23848. }
  23849. if ($startcol>0) { $firstSpread = false; }
  23850. }
  23851. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23852. $this->y = $y;
  23853. $ya = $this->y;
  23854. $this->TableHeaderFooter($tablefooter,$tablestartpage,$tablestartcolumn,'F',$level, $firstSpread, $finalSpread);
  23855. if ($this->table_rotate) {
  23856. $this->tbrot_h += $this->y - $ya ;
  23857. }
  23858. $tablefooteradj = $this->y - $ya ;
  23859. }
  23860. $y -= $y0;
  23861. $returny += $y;
  23862. $oldcolumn = $this->CurrCol;
  23863. if ($this->AcceptPageBreak()) {
  23864. $newpagestarted = true;
  23865. $this->y = $y + $y0;
  23866. // Move down to account for border-spacing or
  23867. // extra half border width in case page breaks in middle
  23868. if($i>0 && !$this->table_rotate && $level==1 && !$this->ColActive) {
  23869. if ($table['borders_separate']) {
  23870. $adv = $table['border_spacing_V']/2;
  23871. // If table footer
  23872. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  23873. $adv += ($table['padding']['B'] + $table['border_details']['B']['w']);
  23874. }
  23875. }
  23876. else {
  23877. $maxbwtop = 0;
  23878. $maxbwbottom = 0;
  23879. if (!$this->simpleTables){
  23880. if (!empty($tablefooter)) { $maxbwbottom = $table['max_cell_border_width']['B']; }
  23881. else {
  23882. $brow = $i-1;
  23883. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23884. if (isset($cells[$brow][$ctj]) && $cells[$brow][$ctj]) {
  23885. if ($this->cacheTables) {
  23886. $cadj = $this->_uncacheCell($table['cells'][$brow][$ctj], '', $fh);
  23887. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']);
  23888. }
  23889. else if ($this->packTableData) {
  23890. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$brow][$ctj]['borderbin']);
  23891. }
  23892. else {
  23893. $bb = $cells[$brow][$ctj]['border_details']['B']['w'];
  23894. }
  23895. $maxbwbottom = max($maxbwbottom , $bb);
  23896. }
  23897. }
  23898. }
  23899. if (!empty($tableheader)) { $maxbwtop = $table['max_cell_border_width']['T']; }
  23900. else {
  23901. $trow = $i-1;
  23902. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  23903. if (isset($cells[$trow][$ctj]) && $cells[$trow][$ctj]) {
  23904. if ($this->cacheTables) {
  23905. $cadj = $this->_uncacheCell($table['cells'][$trow][$ctj], '', $fh);
  23906. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']);
  23907. }
  23908. else if ($this->packTableData) {
  23909. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$trow][$ctj]['borderbin']);
  23910. }
  23911. else {
  23912. $bt = $cells[$trow][$ctj]['border_details']['T']['w'];
  23913. }
  23914. $maxbwtop = max($maxbwtop , $bt);
  23915. }
  23916. }
  23917. }
  23918. }
  23919. else if ($this->simpleTables){
  23920. $maxbwtop = $table['simple']['border_details']['T']['w'];
  23921. $maxbwbottom = $table['simple']['border_details']['B']['w'];
  23922. }
  23923. $adv = $maxbwbottom /2;
  23924. }
  23925. $this->y += $adv;
  23926. }
  23927. // Rotated table split over pages - needs this->y for borders/backgrounds
  23928. if($i>0 && $this->table_rotate && $level==1) {
  23929. // $this->y = $y0 + $this->tbrot_w;
  23930. }
  23931. if ($this->tableClipPath ) { $this->_out("Q"); }
  23932. $bx = $x0;
  23933. $by = $y0;
  23934. if ($table['borders_separate']) {
  23935. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  23936. if ($tablestartpageno != $this->page) { // IF already broken across a previous pagebreak
  23937. $by += $table['max_cell_border_width']['T']/2;
  23938. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  23939. }
  23940. else {
  23941. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  23942. }
  23943. }
  23944. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  23945. $by -= $tableheaderadj;
  23946. $bh = $this->y - $by + $tablefooteradj;
  23947. if (!$table['borders_separate']) { $bh -= $adv ; }
  23948. if ($split) {
  23949. $bw = 0;
  23950. for($t=$startcol; $t<$numcols; $t++) {
  23951. if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; }
  23952. if ($table['colPg'][$t] > $splitpg) { break; }
  23953. }
  23954. if ($table['borders_separate']) {
  23955. if ($firstSpread) {
  23956. $bw += $table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H'];
  23957. }
  23958. else {
  23959. $bx += ($table['padding']['L'] + $table['border_details']['L']['w']);
  23960. $bw += $table['border_spacing_H'];
  23961. }
  23962. if ($finalSpread) {
  23963. $bw += $table['padding']['R'] + $table['border_details']['R']['w']/2 + $table['border_spacing_H'];
  23964. }
  23965. }
  23966. }
  23967. else {
  23968. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  23969. }
  23970. // mPDF 5.4.16
  23971. if ($this->splitTableBorderWidth && ($this->keepColumns || !$this->ColActive) && empty($tablefooter) && $i > 0 && $table['border_details']['B']['w']) {
  23972. $prevDrawColor = $this->DrawColor;
  23973. $lw = $this->LineWidth;
  23974. $this->SetLineWidth($this->splitTableBorderWidth);
  23975. $this->SetDColor($table['border_details']['B']['c']);
  23976. $this->SetLineJoin(0);
  23977. $this->SetLineCap(0);
  23978. $blx = $bx;
  23979. $blw = $bw;
  23980. if (!$table['borders_separate']) {
  23981. $blx -= ($table['max_cell_border_width']['L']/2);
  23982. $blw += ($table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2);
  23983. }
  23984. $this->Line($blx,$this->y+($this->splitTableBorderWidth/2),$blx+$blw,$this->y+($this->splitTableBorderWidth/2));
  23985. $this->DrawColor = $prevDrawColor;
  23986. $this->_out($this->DrawColor);
  23987. $this->SetLineWidth($lw);
  23988. $this->SetLineJoin(2);
  23989. $this->SetLineCap(2);
  23990. }
  23991. if (!$this->ColActive && ($i > 0 || $j > 0)) {
  23992. if (isset($table['bgcolor'][-1])) {
  23993. $color = $this->ConvertColor($table['bgcolor'][-1]);
  23994. if ($color) {
  23995. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  23996. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  23997. }
  23998. }
  23999. /*-- BACKGROUNDS --*/
  24000. if (isset($table['gradient'])) {
  24001. $g = $this->grad->parseBackgroundGradient($table['gradient']);
  24002. if ($g) {
  24003. $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'=>'');
  24004. }
  24005. }
  24006. if (isset($table['background-image'])) {
  24007. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  24008. $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] );
  24009. if ($g) {
  24010. $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'=>'');
  24011. }
  24012. }
  24013. else {
  24014. $image_id = $table['background-image']['image_id'];
  24015. $orig_w = $table['background-image']['orig_w'];
  24016. $orig_h = $table['background-image']['orig_h'];
  24017. $x_pos = $table['background-image']['x_pos'];
  24018. $y_pos = $table['background-image']['y_pos'];
  24019. $x_repeat = $table['background-image']['x_repeat'];
  24020. $y_repeat = $table['background-image']['y_repeat'];
  24021. $resize = $table['background-image']['resize'];
  24022. $opacity = $table['background-image']['opacity'];
  24023. $itype = $table['background-image']['itype'];
  24024. $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);
  24025. }
  24026. }
  24027. /*-- END BACKGROUNDS --*/
  24028. }
  24029. // $this->AcceptPageBreak() has moved tablebuffer to $this->pages content
  24030. if ($this->tableBackgrounds) {
  24031. $s = $this->PrintTableBackgrounds();
  24032. if ($this->bufferoutput) {
  24033. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  24034. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer );
  24035. }
  24036. else {
  24037. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  24038. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]);
  24039. }
  24040. $this->tableBackgrounds = array();
  24041. }
  24042. if ($split) {
  24043. if ($i == 0 && $j == 0) { $y0 = -1; }
  24044. else if ($finalSpread) {
  24045. $splitpg = 0;
  24046. $startcol = 0;
  24047. $startrow = $i;
  24048. }
  24049. else {
  24050. $splitpg++;
  24051. $startcol = $t;
  24052. $returny -= $y;
  24053. }
  24054. return array(false, $startrow, $startcol, $splitpg, $returny, $y0);
  24055. }
  24056. $this->AddPage($this->CurOrientation);
  24057. $this->_out('___TABLE___BACKGROUNDS'.date('jY'));
  24058. if ($this->tableClipPath ) { $this->_out($this->tableClipPath); }
  24059. // Added to correct for OddEven Margins
  24060. $x= $x + $this->MarginCorrection;
  24061. $x0= $x0 + $this->MarginCorrection;
  24062. // mPDF 5.4.16
  24063. if ($this->splitTableBorderWidth && ($this->keepColumns || !$this->ColActive) && empty($tableheader) && $i > 0 && $table['border_details']['T']['w'] ) {
  24064. $prevDrawColor = $this->DrawColor;
  24065. $lw = $this->LineWidth;
  24066. $this->SetLineWidth($this->splitTableBorderWidth);
  24067. $this->SetDColor($table['border_details']['T']['c']);
  24068. $this->SetLineJoin(0);
  24069. $this->SetLineCap(0);
  24070. $blx += $this->MarginCorrection;
  24071. $this->Line($blx,$this->y-($this->splitTableBorderWidth/2),$blx+$blw,$this->y-($this->splitTableBorderWidth/2));
  24072. $this->DrawColor = $prevDrawColor;
  24073. $this->_out($this->DrawColor);
  24074. $this->SetLineWidth($lw);
  24075. $this->SetLineJoin(2);
  24076. $this->SetLineCap(2);
  24077. }
  24078. // Move down to account for half of top border-spacing or
  24079. // extra half border width in case page was broken in middle
  24080. if($i>0 && !$this->table_rotate && $level==1 && $table['headernrows']==0) {
  24081. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; }
  24082. else {
  24083. $maxbwtop = 0;
  24084. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  24085. if (isset($cells[$i][$ctj]) && $cells[$i][$ctj]) {
  24086. if (!$this->simpleTables){
  24087. if ($this->cacheTables) {
  24088. $celltj = $this->_uncacheCell($table['cells'][$i][$ctj], '', $fh);
  24089. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($celltj['borderbin']);
  24090. }
  24091. else if ($this->packTableData) {
  24092. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$i][$ctj]['borderbin']);
  24093. }
  24094. else {
  24095. $bt = $cells[$i][$ctj]['border_details']['T']['w'];
  24096. }
  24097. $maxbwtop = max($maxbwtop, $bt);
  24098. }
  24099. else if ($this->simpleTables){
  24100. $maxbwtop = max($maxbwtop, $table['simple']['border_details']['T']['w']);
  24101. }
  24102. }
  24103. }
  24104. $adv = $maxbwtop /2;
  24105. }
  24106. $this->y += $adv;
  24107. }
  24108. if ($this->table_rotate) {
  24109. $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'];
  24110. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  24111. else { $this->tbrot_h = $table['margin']['T'] + $table['max_cell_border_width']['T'] ; }
  24112. $this->tbrot_y0 = $this->y;
  24113. $pagetrigger = $y0 - $tableheaderadj + ($this->blk[$this->blklvl]['inner_width']);
  24114. }
  24115. else {
  24116. $pagetrigger = $this->PageBreakTrigger;
  24117. }
  24118. if ($this->kwt_saved && $level==1) {
  24119. $this->kwt_moved = true;
  24120. }
  24121. // Disable Table header repeat if Keep Block together
  24122. if (!$this->keep_block_together && !empty($tableheader)) {
  24123. $ya = $this->y;
  24124. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level);
  24125. if ($this->table_rotate) {
  24126. $this->tbrot_h = $this->y - $ya ;
  24127. }
  24128. $tableheaderadj = $this->y - $ya ;
  24129. }
  24130. else if ($i==0 && !$this->keep_block_together && !$this->table_rotate && $level==1 && !$this->ColActive) {
  24131. // Advance down page
  24132. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  24133. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  24134. if ($adv) {
  24135. if ($this->table_rotate) {
  24136. $this->y += ($adv);
  24137. }
  24138. else {
  24139. $this->DivLn($adv,$this->blklvl,true);
  24140. }
  24141. }
  24142. }
  24143. $outerfilled = 0;
  24144. $y = $y0 = $this->y;
  24145. }
  24146. /*-- COLUMNS --*/
  24147. // COLS
  24148. // COLUMN CHANGE
  24149. if ($this->CurrCol != $oldcolumn) {
  24150. // Added to correct for Columns
  24151. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  24152. $x0 += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  24153. if ($this->CurrCol == 0) { // just added a page - possibly with tableheader
  24154. $y0 = $this->y; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  24155. }
  24156. else {
  24157. $y0 = $this->y0; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  24158. }
  24159. $y = $y0;
  24160. $outerfilled = 0;
  24161. if ($this->CurrCol != 0 && ($this->keepColumns && $this->ColActive) && !empty($tableheader) && $i > 0 ) {
  24162. $this->x = $x;
  24163. $this->y = $y;
  24164. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level);
  24165. $y0 = $y=$this->y;
  24166. }
  24167. }
  24168. /*-- END COLUMNS --*/
  24169. }
  24170. $skippage = true;
  24171. }
  24172. $this->x = $x;
  24173. $this->y = $y;
  24174. if ($this->kwt_saved && $level==1) {
  24175. $this->printkwtbuffer();
  24176. $x0 = $x = $this->x;
  24177. $y0 = $y = $this->y;
  24178. $this->kwt_moved = false;
  24179. $this->kwt_saved = false;
  24180. }
  24181. // Set the Page & Column where table actually starts
  24182. if ($i==0 && $j==0 && $level==1) {
  24183. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  24184. $tablestartpage = 'EVEN';
  24185. }
  24186. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  24187. $tablestartpage = 'ODD';
  24188. }
  24189. else { $tablestartpage = ''; }
  24190. $tablestartpageno = $this->page;
  24191. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; } // *COLUMNS*
  24192. }
  24193. //ALIGN
  24194. $align = $cell['a'];
  24195. /*-- COLUMNS --*/
  24196. // If outside columns, this is done in PaintDivBB
  24197. if ($this->ColActive) {
  24198. //OUTER FILL BGCOLOR of DIVS
  24199. if ($this->blklvl > 0 && ($j==0) && !$this->table_rotate && $level==1) {
  24200. $firstblockfill = $this->GetFirstBlockFill();
  24201. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  24202. $divh = $maxrowheight;
  24203. // Last row
  24204. if (isset($cell['rowspan']) && (($i == $numrows-1 && $cell['rowspan']<2) || ($cell['rowspan']>1 && ($i + $cell['rowspan']-1) == $numrows-1))) {
  24205. if ($table['borders_separate']) {
  24206. $adv = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  24207. }
  24208. else {
  24209. $adv = $table['margin']['B'] + $table['max_cell_border_width']['B']/2;
  24210. }
  24211. $divh += $adv; //last row: fill bottom half of bottom border (y advanced at end)
  24212. }
  24213. if (($this->y + $divh) > $outerfilled ) { // if not already painted by previous rowspan
  24214. $bak_x = $this->x;
  24215. $bak_y = $this->y;
  24216. if ($outerfilled > $this->y) {
  24217. $divh = ($this->y + $divh) - $outerfilled;
  24218. $this->y = $outerfilled;
  24219. }
  24220. $this->DivLn($divh,-3,false);
  24221. $outerfilled = $this->y + $divh;
  24222. // Reset current block fill
  24223. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  24224. if ($bcor ) $this->SetFColor($bcor);
  24225. $this->x = $bak_x;
  24226. $this->y = $bak_y;
  24227. }
  24228. }
  24229. }
  24230. }
  24231. //TABLE BACKGROUND FILL BGCOLOR - for cellSpacing
  24232. if ($this->ColActive) {
  24233. if ($table['borders_separate']) {
  24234. $fill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0;
  24235. if ($fill) {
  24236. $color = $this->ConvertColor($fill);
  24237. if ($color) {
  24238. $xadj = ($table['border_spacing_H']/2);
  24239. $yadj = ($table['border_spacing_V']/2);
  24240. $wadj = $table['border_spacing_H'];
  24241. $hadj = $table['border_spacing_V'];
  24242. if ($i == 0) { // Top
  24243. $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  24244. $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ;
  24245. }
  24246. if ($j == 0) { // Left
  24247. $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  24248. $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ;
  24249. }
  24250. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows)) { // Bottom
  24251. $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ;
  24252. }
  24253. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right
  24254. $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ;
  24255. }
  24256. $this->SetFColor($color);
  24257. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  24258. }
  24259. }
  24260. }
  24261. }
  24262. /*-- END COLUMNS --*/
  24263. if ($table['empty_cells']!='hide' || !empty($cell['textbuffer']) || (isset($cell['nestedcontent']) && $cell['nestedcontent']) || !$table['borders_separate'] ) { $paintcell = true; }
  24264. else { $paintcell = false; }
  24265. //Set Borders
  24266. $bord = 0;
  24267. $bord_det = array();
  24268. if (!$this->simpleTables){
  24269. if ($this->packTableData) {
  24270. if ($cell['borderbin']) {
  24271. $c = $this->_unpackCellBorder($cell['borderbin']);
  24272. $bord = $c['border'];
  24273. $bord_det = $c['border_details'];
  24274. }
  24275. }
  24276. else if ($cell['border']) {
  24277. $bord = $cell['border'];
  24278. $bord_det = $cell['border_details'];
  24279. }
  24280. }
  24281. else if ($this->simpleTables){
  24282. if ($table['simple']['border']) {
  24283. $bord = $table['simple']['border'];
  24284. $bord_det = $table['simple']['border_details'];
  24285. }
  24286. }
  24287. //TABLE ROW OR CELL FILL BGCOLOR
  24288. $fill = 0;
  24289. if (isset($cell['bgcolor']) && $cell['bgcolor'] && $cell['bgcolor']!='transparent') {
  24290. $fill = $cell['bgcolor'];
  24291. $leveladj = 6;
  24292. }
  24293. else if (isset($table['bgcolor'][$i]) && $table['bgcolor'][$i] && $table['bgcolor'][$i]!='transparent') { // Row color
  24294. $fill = $table['bgcolor'][$i];
  24295. $leveladj = 3;
  24296. }
  24297. if ($fill && $paintcell) {
  24298. $color = $this->ConvertColor($fill);
  24299. if ($color) {
  24300. if ($table['borders_separate']) {
  24301. if ($this->ColActive) {
  24302. $this->SetFColor($color);
  24303. $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');
  24304. }
  24305. else {
  24306. $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);
  24307. }
  24308. }
  24309. else {
  24310. if ($this->ColActive) {
  24311. $this->SetFColor($color);
  24312. $this->Rect($x, $y, $w, $h, 'F');
  24313. }
  24314. else {
  24315. $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color);
  24316. }
  24317. }
  24318. }
  24319. }
  24320. /*-- BACKGROUNDS --*/
  24321. if (isset($cell['gradient']) && $cell['gradient'] && $paintcell){
  24322. $g = $this->grad->parseBackgroundGradient($cell['gradient']);
  24323. if ($g) {
  24324. if ($table['borders_separate']) {
  24325. $px = $x+ ($table['border_spacing_H']/2);
  24326. $py = $y+ ($table['border_spacing_V']/2);
  24327. $pw = $w- $table['border_spacing_H'];
  24328. $ph = $h- $table['border_spacing_V'];
  24329. }
  24330. else {
  24331. $px = $x;
  24332. $py = $y;
  24333. $pw = $w;
  24334. $ph = $h;
  24335. }
  24336. if ($this->ColActive) {
  24337. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  24338. }
  24339. else {
  24340. $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'=>'');
  24341. }
  24342. }
  24343. }
  24344. if (isset($cell['background-image']) && $paintcell) {
  24345. if ($cell['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $cell['background-image']['gradient'] )) {
  24346. $g = $this->grad->parseMozGradient( $cell['background-image']['gradient'] );
  24347. if ($g) {
  24348. if ($table['borders_separate']) {
  24349. $px = $x+ ($table['border_spacing_H']/2);
  24350. $py = $y+ ($table['border_spacing_V']/2);
  24351. $pw = $w- $table['border_spacing_H'];
  24352. $ph = $h- $table['border_spacing_V'];
  24353. }
  24354. else {
  24355. $px = $x;
  24356. $py = $y;
  24357. $pw = $w;
  24358. $ph = $h;
  24359. }
  24360. if ($this->ColActive) {
  24361. $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
  24362. }
  24363. else {
  24364. $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'=>'');
  24365. }
  24366. }
  24367. }
  24368. else if ($cell['background-image']['image_id']) { // Background pattern
  24369. $n = count($this->patterns)+1;
  24370. if ($table['borders_separate']) {
  24371. $px = $x+ ($table['border_spacing_H']/2);
  24372. $py = $y+ ($table['border_spacing_V']/2);
  24373. $pw = $w- $table['border_spacing_H'];
  24374. $ph = $h- $table['border_spacing_V'];
  24375. }
  24376. else {
  24377. $px = $x;
  24378. $py = $y;
  24379. $pw = $w;
  24380. $ph = $h;
  24381. }
  24382. if ($this->ColActive) {
  24383. 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']);
  24384. $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);
  24385. if ($cell['background-image']['opacity']>0 && $cell['background-image']['opacity']<1) { $opac = $this->SetAlpha($cell['background-image']['opacity'],'Normal',true); }
  24386. else { $opac = ''; }
  24387. $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));
  24388. }
  24389. else {
  24390. $image_id = $cell['background-image']['image_id'];
  24391. $orig_w = $cell['background-image']['orig_w'];
  24392. $orig_h = $cell['background-image']['orig_h'];
  24393. $x_pos = $cell['background-image']['x_pos'];
  24394. $y_pos = $cell['background-image']['y_pos'];
  24395. $x_repeat = $cell['background-image']['x_repeat'];
  24396. $y_repeat = $cell['background-image']['y_repeat'];
  24397. $resize = $cell['background-image']['resize'];
  24398. $opacity = $cell['background-image']['opacity'];
  24399. $itype = $cell['background-image']['itype'];
  24400. $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);
  24401. }
  24402. }
  24403. }
  24404. /*-- END BACKGROUNDS --*/
  24405. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  24406. else { $ccolsp = 1; }
  24407. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  24408. else { $crowsp = 1; }
  24409. // but still need to do this for repeated headers...
  24410. if (!$table['borders_separate'] && $this->tabletheadjustfinished && !$this->simpleTables){
  24411. if (isset($table['topntail']) && $table['topntail']) {
  24412. $bord_det['T'] = $this->border_details($table['topntail']);
  24413. $bord_det['T']['w'] /= $this->shrin_k;
  24414. $this->setBorder($bord, _BORDER_TOP);
  24415. }
  24416. if (isset($table['thead-underline']) && $table['thead-underline']) {
  24417. $bord_det['T'] = $this->border_details($table['thead-underline']);
  24418. $bord_det['T']['w'] /= $this->shrin_k;
  24419. $this->setBorder($bord, _BORDER_TOP);
  24420. }
  24421. }
  24422. //Get info of first row ==>> table header
  24423. //Use > 1 row if THEAD
  24424. if (isset($table['is_thead'][$i]) && $table['is_thead'][$i] && $level==1) {
  24425. if ($j==0) $tableheaderrowheight += $table['hr'][$i];
  24426. $tableheader[$i][0]['trbackground-images'] = (isset($table['trbackground-images'][$i]) ? $table['trbackground-images'][$i] : null);
  24427. $tableheader[$i][0]['trgradients'] = (isset($table['trgradients'][$i]) ? $table['trgradients'][$i] : null);
  24428. $tableheader[$i][0]['trbgcolor'] = (isset($table['bgcolor'][$i]) ? $table['bgcolor'][$i] : null);
  24429. $tableheader[$i][$j]['x'] = $x;
  24430. $tableheader[$i][$j]['y'] = $y;
  24431. $tableheader[$i][$j]['h'] = $h;
  24432. $tableheader[$i][$j]['w'] = $w;
  24433. if (isset($cell['textbuffer'])) { $tableheader[$i][$j]['textbuffer'] = $cell['textbuffer']; }
  24434. else { $tableheader[$i][$j]['textbuffer'] = ''; }
  24435. $tableheader[$i][$j]['a'] = $cell['a'];
  24436. $tableheader[$i][$j]['R'] = $cell['R'];
  24437. $tableheader[$i][$j]['va'] = $cell['va'];
  24438. $tableheader[$i][$j]['mih'] = $cell['mih'];
  24439. $tableheader[$i][$j]['gradient'] = (isset($cell['gradient']) ? $cell['gradient'] : null); // *BACKGROUNDS*
  24440. $tableheader[$i][$j]['background-image'] = (isset($cell['background-image']) ? $cell['background-image'] : null); // *BACKGROUNDS*
  24441. $tableheader[$i][$j]['rowspan'] = (isset($cell['rowspan']) ? $cell['rowspan'] : null);
  24442. $tableheader[$i][$j]['colspan'] = (isset($cell['colspan']) ? $cell['colspan'] : null);
  24443. $tableheader[$i][$j]['bgcolor'] = $cell['bgcolor'];
  24444. if (!$this->simpleTables){
  24445. $tableheader[$i][$j]['border'] = $bord;
  24446. $tableheader[$i][$j]['border_details'] = $bord_det;
  24447. }
  24448. else if ($this->simpleTables){
  24449. $tableheader[$i][$j]['border'] = $table['simple']['border'];
  24450. $tableheader[$i][$j]['border_details'] = $table['simple']['border_details'];
  24451. }
  24452. $tableheader[$i][$j]['padding'] = $cell['padding'];
  24453. }
  24454. // CELL BORDER
  24455. if ($bord || $bord_det) {
  24456. if ($table['borders_separate'] && $paintcell) {
  24457. $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']);
  24458. }
  24459. else if (!$table['borders_separate']) {
  24460. $this->_tableRect($x, $y, $w, $h, $bord, $bord_det, true, $table['borders_separate']); // true causes buffer
  24461. }
  24462. }
  24463. //VERTICAL ALIGN
  24464. if ($cell['R'] && INTVAL($cell['R']) > 0 && INTVAL($cell['R']) < 90 && isset($cell['va']) && $cell['va']!='B') { $cell['va']='B';}
  24465. if (!isset($cell['va']) || $cell['va']=='M') $this->y += ($h-$cell['mih'])/2;
  24466. elseif (isset($cell['va']) && $cell['va']=='B') $this->y += $h-$cell['mih'];
  24467. // NESTED CONTENT
  24468. // TEXT (and nested tables)
  24469. $this->divalign=$align;
  24470. $this->divwidth=$w;
  24471. if (!empty($cell['textbuffer'])) {
  24472. if ($level==1) {
  24473. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) {
  24474. if (preg_match('/{colsum([0-9]*)[_]*}/', $cell['textbuffer'][0][0], $m)) {
  24475. $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$j]);
  24476. $cell['textbuffer'][0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$cell['textbuffer'][0][0]);
  24477. }
  24478. }
  24479. else { $this->colsums[$j] += floatval(preg_replace('/^[^0-9\.\,]*/','',$cell['textbuffer'][0][0])); }
  24480. }
  24481. $opy = $this->y;
  24482. // mPDF ITERATION
  24483. if ($this->iterationCounter) {
  24484. foreach($cell['textbuffer'] AS $k=>$t) {
  24485. if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t[0], $m)) {
  24486. $vname = '__'.$m[1].'_';
  24487. if (!isset($this->$vname)) { $this->$vname = 1; }
  24488. else { $this->$vname++; }
  24489. $cell['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $cell['textbuffer'][$k][0]);
  24490. }
  24491. }
  24492. }
  24493. if ($cell['R']) {
  24494. $cellPtSize = $cell['textbuffer'][0][11] / $this->shrin_k;
  24495. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  24496. $cellFontHeight = ($cellPtSize/_MPDFK);
  24497. $opx = $this->x;
  24498. $angle = INTVAL($cell['R']);
  24499. // Only allow 45 to 89 degrees (when bottom-aligned) or exactly 90 or -90
  24500. if ($angle > 90) { $angle = 90; }
  24501. else if ($angle > 0 && $angle <45) { $angle = 45; }
  24502. else if ($angle < 0) { $angle = -90; }
  24503. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  24504. if (isset($cell['a']) && $cell['a']=='R') {
  24505. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($cell['padding']['R'] + ($table['border_spacing_H']/2));
  24506. }
  24507. else if (!isset($cell['a']) || $cell['a']=='C') {
  24508. $this->x += ($w/2) + ($offset);
  24509. }
  24510. else {
  24511. $this->x += ($offset) + ($cellFontHeight/3)+($cell['padding']['L'] +($table['border_spacing_H']/2));
  24512. }
  24513. $str = '';
  24514. foreach($cell['textbuffer'] AS $t) { $str .= $t[0].' '; }
  24515. $str = trim($str);
  24516. if (!isset($cell['va']) || $cell['va']=='M') {
  24517. $this->y -= ($h-$cell['mih'])/2; //Undo what was added earlier VERTICAL ALIGN
  24518. if ($angle > 0) { $this->y += (($h-$cell['mih'])/2) + $cell['padding']['T'] + ($cell['mih']-($cell['padding']['T'] + $cell['padding']['B'])); }
  24519. else if ($angle < 0) { $this->y += (($h-$cell['mih'])/2)+ ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24520. }
  24521. elseif (isset($cell['va']) && $cell['va']=='B') {
  24522. $this->y -= $h-$cell['mih']; //Undo what was added earlier VERTICAL ALIGN
  24523. if ($angle > 0) { $this->y += $h-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  24524. else if ($angle < 0) { $this->y += $h-$cell['mih'] + ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24525. }
  24526. elseif (isset($cell['va']) && $cell['va']=='T') {
  24527. if ($angle > 0) { $this->y += $cell['mih']-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  24528. else if ($angle < 0) { $this->y += ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  24529. }
  24530. $this->Rotate($angle,$this->x,$this->y);
  24531. $s_fs = $this->FontSizePt;
  24532. $s_f = $this->FontFamily;
  24533. $s_st = $this->FontStyle;
  24534. if (!empty($cell['textbuffer'][0][3])) { //Font Color
  24535. $cor = $cell['textbuffer'][0][3];
  24536. $this->SetTColor($cor);
  24537. }
  24538. $s_str = $this->strike;
  24539. $this->strike = $cell['textbuffer'][0][8]; //Strikethrough
  24540. $this->SetFont($cell['textbuffer'][0][4],$cell['textbuffer'][0][2],$cellPtSize,true,true);
  24541. $this->Text($this->x,$this->y,$str);
  24542. $this->Rotate(0);
  24543. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  24544. $this->SetTColor(0);
  24545. $this->strike = $s_str;
  24546. $this->x = $opx;
  24547. }
  24548. else {
  24549. if (!$this->simpleTables){
  24550. if ($bord_det) {
  24551. $btlw = $bord_det['L']['w'];
  24552. $btrw = $bord_det['R']['w'];
  24553. $bttw = $bord_det['T']['w'];
  24554. }
  24555. else {
  24556. $btlw = 0;
  24557. $btrw = 0;
  24558. $bttw = 0;
  24559. }
  24560. if ($table['borders_separate']) {
  24561. $xadj = $btlw + $cell['padding']['L'] +($table['border_spacing_H']/2);
  24562. $wadj = $btlw + $btrw + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  24563. $yadj = $bttw + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  24564. }
  24565. else {
  24566. $xadj = $btlw/2 + $cell['padding']['L'];
  24567. $wadj = ($btlw + $btrw)/2 + $cell['padding']['L'] + $cell['padding']['R'];
  24568. $yadj = $bttw/2 + $cell['padding']['T'];
  24569. }
  24570. }
  24571. else if ($this->simpleTables){
  24572. if ($table['borders_separate']) { // NB twice border width
  24573. $xadj = $table['simple']['border_details']['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2);
  24574. $wadj = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  24575. $yadj = $table['simple']['border_details']['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  24576. }
  24577. else {
  24578. $xadj = $table['simple']['border_details']['L']['w']/2 + $cell['padding']['L'];
  24579. $wadj = ($table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R'];
  24580. $yadj = $table['simple']['border_details']['T']['w']/2 + $cell['padding']['T'];
  24581. }
  24582. }
  24583. $this->divwidth=$w-$wadj;
  24584. if ($this->divwidth == 0) { $this->divwidth = 0.0001; }
  24585. $this->x += $xadj;
  24586. $this->y += $yadj;
  24587. $this->printbuffer($cell['textbuffer'],'',true);
  24588. }
  24589. $this->y = $opy;
  24590. }
  24591. /*-- BACKGROUNDS --*/
  24592. if (!$this->ColActive) {
  24593. if (isset($table['trgradients'][$i]) && ($j==0 || $table['borders_separate'])) {
  24594. $g = $this->grad->parseBackgroundGradient($table['trgradients'][$i]);
  24595. if ($g) {
  24596. $gx = $x0;
  24597. $gy = $y;
  24598. $gh = $h;
  24599. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24600. if ($table['borders_separate']) {
  24601. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24602. $s = '';
  24603. $clx = $x+ ($table['border_spacing_H']/2);
  24604. $cly = $y+ ($table['border_spacing_V']/2);
  24605. $clw = $w- $table['border_spacing_H'];
  24606. $clh = $h- $table['border_spacing_V'];
  24607. // Set clipping path
  24608. $s = ' q 0 w '; // Line width=0
  24609. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  24610. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24611. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24612. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24613. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24614. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24615. $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);
  24616. }
  24617. else {
  24618. $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'=>'');
  24619. }
  24620. }
  24621. }
  24622. if (isset($table['trbackground-images'][$i]) && ($j==0 || $table['borders_separate'])) {
  24623. if ($table['trbackground-images'][$i]['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['trbackground-images'][$i]['gradient'] )) {
  24624. $g = $this->grad->parseMozGradient( $table['trbackground-images'][$i]['gradient'] );
  24625. if ($g) {
  24626. $gx = $x0;
  24627. $gy = $y;
  24628. $gh = $h;
  24629. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24630. if ($table['borders_separate']) {
  24631. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24632. $s = '';
  24633. $clx = $x+ ($table['border_spacing_H']/2);
  24634. $cly = $y+ ($table['border_spacing_V']/2);
  24635. $clw = $w- $table['border_spacing_H'];
  24636. $clh = $h- $table['border_spacing_V'];
  24637. // Set clipping path
  24638. $s = ' q 0 w '; // Line width=0
  24639. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc
  24640. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24641. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24642. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24643. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24644. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24645. $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);
  24646. }
  24647. else {
  24648. $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'=>'');
  24649. }
  24650. }
  24651. }
  24652. else {
  24653. $image_id = $table['trbackground-images'][$i]['image_id'];
  24654. $orig_w = $table['trbackground-images'][$i]['orig_w'];
  24655. $orig_h = $table['trbackground-images'][$i]['orig_h'];
  24656. $x_pos = $table['trbackground-images'][$i]['x_pos'];
  24657. $y_pos = $table['trbackground-images'][$i]['y_pos'];
  24658. $x_repeat = $table['trbackground-images'][$i]['x_repeat'];
  24659. $y_repeat = $table['trbackground-images'][$i]['y_repeat'];
  24660. $resize = $table['trbackground-images'][$i]['resize'];
  24661. $opacity = $table['trbackground-images'][$i]['opacity'];
  24662. $itype = $table['trbackground-images'][$i]['itype'];
  24663. $clippath = '';
  24664. $gx = $x0;
  24665. $gy = $y;
  24666. $gh = $h;
  24667. $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24668. if ($table['borders_separate']) {
  24669. $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
  24670. $s = '';
  24671. $clx = $x + ($table['border_spacing_H']/2);
  24672. $cly = $y + ($table['border_spacing_V']/2);
  24673. $clw = $w - $table['border_spacing_H'];
  24674. $clh = $h - $table['border_spacing_V'];
  24675. // Set clipping path
  24676. $s = ' q 0 w '; // Line width=0
  24677. $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL
  24678. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL
  24679. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR
  24680. $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR
  24681. $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL
  24682. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  24683. $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);
  24684. }
  24685. else {
  24686. $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);
  24687. }
  24688. }
  24689. }
  24690. }
  24691. /*-- END BACKGROUNDS --*/
  24692. // TABLE BORDER - if separate
  24693. if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) {
  24694. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  24695. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  24696. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  24697. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  24698. $tbx = $x;
  24699. $tby = $y;
  24700. $tbw = $w;
  24701. $tbh = $h;
  24702. $tab_bord = 0;
  24703. $corner = '';
  24704. if ($i == 0) { // Top
  24705. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  24706. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  24707. $this->setBorder($tab_bord , _BORDER_TOP);
  24708. $corner .= 'T';
  24709. }
  24710. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows)) { // Bottom
  24711. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  24712. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  24713. $corner .= 'B';
  24714. }
  24715. if ($j == 0) { // Left
  24716. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  24717. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  24718. $this->setBorder($tab_bord , _BORDER_LEFT);
  24719. $corner .= 'L';
  24720. }
  24721. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols)) { // Right
  24722. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  24723. $this->setBorder($tab_bord , _BORDER_RIGHT);
  24724. $corner .= 'R';
  24725. }
  24726. $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'] );
  24727. }
  24728. unset($cell );
  24729. //Reset values
  24730. $this->Reset();
  24731. }//end of (if isset(cells)...)
  24732. }// end of columns
  24733. $newpagestarted = false;
  24734. $this->tabletheadjustfinished = false;
  24735. if ($this->ColActive && $i < $numrows-1 && $level==1) { $this->breakpoints[$this->CurrCol][] = $y + $h; } // *COLUMNS*
  24736. /*-- COLUMNS --*/
  24737. if ($this->ColActive) {
  24738. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24739. }
  24740. /*-- END COLUMNS --*/
  24741. if ($i == $numrows-1) { $this->y = $y + $h; } //last row jump (update this->y position)
  24742. if ($this->table_rotate && $level==1) {
  24743. $this->tbrot_h += $h;
  24744. }
  24745. }// end of rows
  24746. if ($this->progressBar) { $this->UpdateProgressBar(7,70,' '); } // *PROGRESS-BAR*
  24747. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  24748. if ($this->tableClipPath ) { $this->_out("Q"); }
  24749. $this->tableClipPath = '';
  24750. // Advance down page by half width of bottom border
  24751. if ($table['borders_separate']) { $this->y += $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; }
  24752. else { $this->y += $table['max_cell_border_width']['B']/2; }
  24753. 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; }
  24754. else if ($level==1) { $this->tbrot_h += $table['margin']['B'] + $table['max_cell_border_width']['B']/2; }
  24755. $bx = $x0;
  24756. $by = $y0;
  24757. if ($table['borders_separate']) {
  24758. $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2);
  24759. if ($tablestartpageno != $this->page) { // IF broken across page
  24760. $by += $table['max_cell_border_width']['T']/2;
  24761. if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); }
  24762. }
  24763. else if ($split && $startrow > 0 && empty($tableheader)) {
  24764. $by -= ($table['border_spacing_V']/2);
  24765. }
  24766. else {
  24767. $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2);
  24768. }
  24769. }
  24770. else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; }
  24771. $by -= $tableheaderadj;
  24772. $bh = $this->y - $by;
  24773. if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; }
  24774. if ($split) {
  24775. $bw = 0;
  24776. $finalSpread = true;
  24777. for($t=$startcol; $t<$numcols; $t++) {
  24778. if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; }
  24779. if ($table['colPg'][$t] > $splitpg) { $finalSpread = false; break; }
  24780. }
  24781. if ($startcol==0) { $firstSpread = true; }
  24782. else { $firstSpread = false; }
  24783. if ($table['borders_separate']) {
  24784. $bw += $table['border_spacing_H'];
  24785. if ($firstSpread) {
  24786. $bw += $table['padding']['L'] + $table['border_details']['L']['w'];
  24787. }
  24788. else {
  24789. $bx += ($table['padding']['L'] + $table['border_details']['L']['w']);
  24790. }
  24791. if ($finalSpread) {
  24792. $bw += $table['padding']['R'] + $table['border_details']['R']['w'];
  24793. }
  24794. }
  24795. }
  24796. else {
  24797. $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R'];
  24798. }
  24799. if (!$this->ColActive) {
  24800. if (isset($table['bgcolor'][-1])) {
  24801. $color = $this->ConvertColor($table['bgcolor'][-1]);
  24802. if ($color) {
  24803. $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color);
  24804. }
  24805. }
  24806. /*-- BACKGROUNDS --*/
  24807. if (isset($table['gradient'])) {
  24808. $g = $this->grad->parseBackgroundGradient($table['gradient']);
  24809. if ($g) {
  24810. $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'=>'');
  24811. }
  24812. }
  24813. if (isset($table['background-image'])) {
  24814. if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) {
  24815. $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] );
  24816. if ($g) {
  24817. $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'=>'');
  24818. }
  24819. }
  24820. else {
  24821. $image_id = $table['background-image']['image_id'];
  24822. $orig_w = $table['background-image']['orig_w'];
  24823. $orig_h = $table['background-image']['orig_h'];
  24824. $x_pos = $table['background-image']['x_pos'];
  24825. $y_pos = $table['background-image']['y_pos'];
  24826. $x_repeat = $table['background-image']['x_repeat'];
  24827. $y_repeat = $table['background-image']['y_repeat'];
  24828. $resize = $table['background-image']['resize'];
  24829. $opacity = $table['background-image']['opacity'];
  24830. $itype = $table['background-image']['itype'];
  24831. $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);
  24832. }
  24833. }
  24834. /*-- END BACKGROUNDS --*/
  24835. }
  24836. if ($this->tableBackgrounds && $level == 1) {
  24837. $s = $this->PrintTableBackgrounds();
  24838. if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  24839. $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->tablebuffer);
  24840. if ($level == 1) { $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->tablebuffer); }
  24841. }
  24842. else if ($this->bufferoutput) {
  24843. $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer);
  24844. if ($level == 1) { $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer ); }
  24845. }
  24846. else {
  24847. $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  24848. if ($level == 1) { $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]); }
  24849. }
  24850. $this->tableBackgrounds = array();
  24851. }
  24852. // TABLE BOTTOM MARGIN
  24853. if ($table['margin']['B']) {
  24854. if (!$this->table_rotate && $level==1) {
  24855. $this->DivLn($table['margin']['B'],$this->blklvl,true); // collapsible
  24856. }
  24857. else {
  24858. $this->y += ($table['margin']['B']);
  24859. }
  24860. }
  24861. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  24862. if ($this->cacheTables) { fclose($fh); }
  24863. if ($split) {
  24864. // Are there more columns to print on a next page?
  24865. if ($lastCol < $numcols-1) {
  24866. $splitpg++;
  24867. $startcol = $lastCol + 1;
  24868. return array(false, $startrow, $startcol, $splitpg, $returny, $y0);
  24869. }
  24870. else {
  24871. if ($this->cacheTables) {
  24872. unlink($table['cache']);
  24873. @unlink($table['cache'].'.bak');
  24874. }
  24875. return array(true,0,0,0);
  24876. }
  24877. }
  24878. if ($this->cacheTables) {
  24879. unlink($table['cache']);
  24880. @unlink($table['cache'].'.bak');
  24881. }
  24882. }//END OF FUNCTION _tableWrite()
  24883. /////////////////////////END OF TABLE CODE//////////////////////////////////
  24884. /*-- END TABLES --*/
  24885. function _putextgstates() {
  24886. for ($i = 1; $i <= count($this->extgstates); $i++) {
  24887. $this->_newobj();
  24888. $this->extgstates[$i]['n'] = $this->n;
  24889. $this->_out('<</Type /ExtGState');
  24890. foreach ($this->extgstates[$i]['parms'] as $k=>$v)
  24891. $this->_out('/'.$k.' '.$v);
  24892. $this->_out('>>');
  24893. $this->_out('endobj');
  24894. }
  24895. }
  24896. function _putocg() {
  24897. $this->_newobj();
  24898. $this->n_ocg_print=$this->n;
  24899. $this->_out('<</Type /OCG /Name '.$this->_textstring('print'));
  24900. $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
  24901. $this->_out('endobj');
  24902. $this->_newobj();
  24903. $this->n_ocg_view=$this->n;
  24904. $this->_out('<</Type /OCG /Name '.$this->_textstring('view'));
  24905. $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
  24906. $this->_out('endobj');
  24907. $this->_newobj();
  24908. $this->n_ocg_hidden=$this->n;
  24909. $this->_out('<</Type /OCG /Name '.$this->_textstring('hidden'));
  24910. $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /OFF>>>>>>');
  24911. $this->_out('endobj');
  24912. }
  24913. /*-- IMPORTS --*/
  24914. // from mPDFI
  24915. function _putimportedobjects() {
  24916. if (is_array($this->parsers) && count($this->parsers) > 0) {
  24917. foreach($this->parsers AS $filename => $p) {
  24918. $this->current_parser =& $this->parsers[$filename];
  24919. if (is_array($this->_obj_stack[$filename])) {
  24920. while($n = key($this->_obj_stack[$filename])) {
  24921. $nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c,$this->_obj_stack[$filename][$n][1]);
  24922. $this->_newobj($this->_obj_stack[$filename][$n][0]);
  24923. if ($nObj[0] == PDF_TYPE_STREAM) {
  24924. $this->pdf_write_value($nObj);
  24925. }
  24926. else {
  24927. $this->pdf_write_value($nObj[1]);
  24928. }
  24929. $this->_out('endobj');
  24930. $this->_obj_stack[$filename][$n] = null; // free memory
  24931. unset($this->_obj_stack[$filename][$n]);
  24932. reset($this->_obj_stack[$filename]);
  24933. }
  24934. }
  24935. }
  24936. }
  24937. }
  24938. function _putformxobjects() {
  24939. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  24940. reset($this->tpls);
  24941. foreach($this->tpls AS $tplidx => $tpl) {
  24942. $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
  24943. $this->_newobj();
  24944. $this->tpls[$tplidx]['n'] = $this->n;
  24945. $this->_out('<<'.$filter.'/Type /XObject');
  24946. $this->_out('/Subtype /Form');
  24947. $this->_out('/FormType 1');
  24948. // Left/Bottom/Right/Top
  24949. $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]',
  24950. $tpl['box']['x']*_MPDFK,
  24951. $tpl['box']['y']*_MPDFK,
  24952. ($tpl['box']['x'] + $tpl['box']['w'])*_MPDFK,
  24953. ($tpl['box']['y'] + $tpl['box']['h'])*_MPDFK )
  24954. );
  24955. if (isset($tpl['box']))
  24956. $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',-$tpl['box']['x']*_MPDFK, -$tpl['box']['y']*_MPDFK));
  24957. $this->_out('/Resources ');
  24958. if (isset($tpl['resources'])) {
  24959. $this->current_parser =& $tpl['parser'];
  24960. $this->pdf_write_value($tpl['resources']);
  24961. } else {
  24962. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  24963. if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
  24964. $this->_out('/Font <<');
  24965. foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
  24966. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  24967. $this->_out('>>');
  24968. }
  24969. if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
  24970. isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
  24971. {
  24972. $this->_out('/XObject <<');
  24973. if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
  24974. foreach($this->_res['tpl'][$tplidx]['images'] as $image)
  24975. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  24976. }
  24977. if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
  24978. foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $itpl)
  24979. $this->_out($this->tplprefix.$i.' '.$itpl['n'].' 0 R');
  24980. }
  24981. $this->_out('>>');
  24982. }
  24983. $this->_out('>>');
  24984. }
  24985. $this->_out('/Length '.strlen($p).' >>');
  24986. $this->_putstream($p);
  24987. $this->_out('endobj');
  24988. }
  24989. }
  24990. /*-- END IMPORTS --*/
  24991. function _putpatterns() {
  24992. for ($i = 1; $i <= count($this->patterns); $i++) {
  24993. $x = $this->patterns[$i]['x'];
  24994. $y = $this->patterns[$i]['y'];
  24995. $w = $this->patterns[$i]['w'];
  24996. $h = $this->patterns[$i]['h'];
  24997. $pgh = $this->patterns[$i]['pgh'];
  24998. $orig_w = $this->patterns[$i]['orig_w'];
  24999. $orig_h = $this->patterns[$i]['orig_h'];
  25000. $image_id = $this->patterns[$i]['image_id'];
  25001. $itype = $this->patterns[$i]['itype'];
  25002. if ($this->patterns[$i]['x_repeat']) { $x_repeat = true; }
  25003. else { $x_repeat = false; }
  25004. if ($this->patterns[$i]['y_repeat']) { $y_repeat = true; }
  25005. else { $y_repeat = false; }
  25006. $x_pos = $this->patterns[$i]['x_pos'];
  25007. if (stristr($x_pos ,'%') ) {
  25008. $x_pos += 0;
  25009. $x_pos /= 100;
  25010. $x_pos = ($w * $x_pos) - ($orig_w/_MPDFK * $x_pos);
  25011. }
  25012. $y_pos = $this->patterns[$i]['y_pos'];
  25013. if (stristr($y_pos ,'%') ) {
  25014. $y_pos += 0;
  25015. $y_pos /= 100;
  25016. $y_pos = ($h * $y_pos) - ($orig_h/_MPDFK * $y_pos);
  25017. }
  25018. $adj_x = ($x_pos + $x) *_MPDFK;
  25019. $adj_y = (($pgh - $y_pos - $y)*_MPDFK) - $orig_h ;
  25020. $img_obj = false;
  25021. if ($itype == 'svg' || $itype == 'wmf') {
  25022. foreach($this->formobjects AS $fo) {
  25023. if ($fo['i'] == $image_id) {
  25024. $img_obj = $fo['n'];
  25025. $fo_w = $fo['w'];
  25026. $fo_h = -$fo['h'];
  25027. $wmf_x = $fo['x'];
  25028. $wmf_y = $fo['y'];
  25029. break;
  25030. }
  25031. }
  25032. }
  25033. else {
  25034. foreach($this->images AS $img) {
  25035. if ($img['i'] == $image_id) { $img_obj = $img['n']; break; }
  25036. }
  25037. }
  25038. if (!$img_obj ) { echo "Problem: Image object not found for background pattern ".$img['i']; exit; }
  25039. $this->_newobj();
  25040. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  25041. if ($itype == 'svg' || $itype == 'wmf') {
  25042. $this->_out('/XObject <</FO'.$image_id.' '.$img_obj.' 0 R >>');
  25043. // ******* ADD ANY ExtGStates, Shading AND Fonts needed for the FormObject
  25044. // Set in classes/svg array['fo'] = true
  25045. // Required that _putshaders comes before _putpatterns in _putresources
  25046. // This adds any resources associated with any FormObject to every Formobject - overkill but works!
  25047. if (count($this->extgstates)) {
  25048. $this->_out('/ExtGState <<');
  25049. foreach($this->extgstates as $k=>$extgstate)
  25050. if (isset($extgstate['fo']) && $extgstate['fo']) {
  25051. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  25052. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  25053. }
  25054. $this->_out('>>');
  25055. }
  25056. /*-- BACKGROUNDS --*/
  25057. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  25058. $this->_out('/Shading <<');
  25059. foreach ($this->gradients as $id => $grad) {
  25060. if (isset($grad['fo']) && $grad['fo']) {
  25061. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  25062. }
  25063. }
  25064. $this->_out('>>');
  25065. }
  25066. /*-- END BACKGROUNDS --*/
  25067. $this->_out('/Font <<');
  25068. foreach($this->fonts as $font) {
  25069. if (!$font['used'] && $font['type']=='TTF') { continue; }
  25070. if (isset($font['fo']) && $font['fo']) {
  25071. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) {
  25072. foreach($font['n'] AS $k => $fid) {
  25073. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  25074. }
  25075. }
  25076. else {
  25077. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  25078. }
  25079. }
  25080. }
  25081. $this->_out('>>');
  25082. }
  25083. else {
  25084. $this->_out('/XObject <</I'.$image_id.' '.$img_obj.' 0 R >>');
  25085. }
  25086. $this->_out('>>');
  25087. $this->_out('endobj');
  25088. $this->_newobj();
  25089. $this->patterns[$i]['n'] = $this->n;
  25090. $this->_out('<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 2');
  25091. $this->_out('/Resources '. ($this->n-1) .' 0 R');
  25092. $this->_out(sprintf('/BBox [0 0 %.3F %.3F]',$orig_w,$orig_h));
  25093. if ($x_repeat) { $this->_out(sprintf('/XStep %.3F',$orig_w)); }
  25094. else { $this->_out(sprintf('/XStep %d',99999)); }
  25095. if ($y_repeat) { $this->_out(sprintf('/YStep %.3F',$orig_h)); }
  25096. else { $this->_out(sprintf('/YStep %d',99999)); }
  25097. if ($itype == 'svg' || $itype == 'wmf') {
  25098. $this->_out(sprintf('/Matrix [1 0 0 -1 %.3F %.3F]', $adj_x, ($adj_y+$orig_h)));
  25099. $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);
  25100. }
  25101. else {
  25102. $this->_out(sprintf('/Matrix [1 0 0 1 %.3F %.3F]',$adj_x,$adj_y));
  25103. $s = sprintf("q %.3F 0 0 %.3F 0 0 cm /I%d Do Q",$orig_w,$orig_h,$image_id);
  25104. }
  25105. if ($this->compress) {
  25106. $this->_out('/Filter /FlateDecode');
  25107. $s = gzcompress($s);
  25108. }
  25109. $this->_out('/Length '.strlen($s).'>>');
  25110. $this->_putstream($s);
  25111. $this->_out('endobj');
  25112. }
  25113. }
  25114. /*-- BACKGROUNDS --*/
  25115. function _putshaders() {
  25116. $maxid = count($this->gradients); //index for transparency gradients
  25117. foreach ($this->gradients as $id => $grad) {
  25118. if (($grad['type'] == 2 || $grad['type'] == 3) && empty($grad['is_mask'])) {
  25119. $this->_newobj();
  25120. $this->_out('<<');
  25121. $this->_out('/FunctionType 3');
  25122. $this->_out('/Domain [0 1]');
  25123. $fn = array();
  25124. $bd = array();
  25125. $en = array();
  25126. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  25127. $fn[] = ($this->n+1+$i).' 0 R';
  25128. $en[] = '0 1';
  25129. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  25130. }
  25131. $this->_out('/Functions ['.implode(' ',$fn).']');
  25132. $this->_out('/Bounds ['.implode(' ',$bd).']');
  25133. $this->_out('/Encode ['.implode(' ',$en).']');
  25134. $this->_out('>>');
  25135. $this->_out('endobj');
  25136. $f1 = $this->n;
  25137. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  25138. $this->_newobj();
  25139. $this->_out('<<');
  25140. $this->_out('/FunctionType 2');
  25141. $this->_out('/Domain [0 1]');
  25142. $this->_out('/C0 ['.$grad['stops'][$i]['col'].']');
  25143. $this->_out('/C1 ['.$grad['stops'][$i+1]['col'].']');
  25144. $this->_out('/N 1');
  25145. $this->_out('>>');
  25146. $this->_out('endobj');
  25147. }
  25148. }
  25149. if ($grad['type'] == 2 || $grad['type'] == 3) {
  25150. if (isset($grad['trans']) && $grad['trans']) {
  25151. $this->_newobj();
  25152. $this->_out('<<');
  25153. $this->_out('/FunctionType 3');
  25154. $this->_out('/Domain [0 1]');
  25155. $fn = array();
  25156. $bd = array();
  25157. $en = array();
  25158. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  25159. $fn[] = ($this->n+1+$i).' 0 R';
  25160. $en[] = '0 1';
  25161. if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); }
  25162. }
  25163. $this->_out('/Functions ['.implode(' ',$fn).']');
  25164. $this->_out('/Bounds ['.implode(' ',$bd).']');
  25165. $this->_out('/Encode ['.implode(' ',$en).']');
  25166. $this->_out('>>');
  25167. $this->_out('endobj');
  25168. $f2 = $this->n;
  25169. for($i=0; $i<(count($grad['stops'])-1); $i++) {
  25170. $this->_newobj();
  25171. $this->_out('<<');
  25172. $this->_out('/FunctionType 2');
  25173. $this->_out('/Domain [0 1]');
  25174. $this->_out(sprintf('/C0 [%.3F]', $grad['stops'][$i]['opacity']));
  25175. $this->_out(sprintf('/C1 [%.3F]', $grad['stops'][$i+1]['opacity']));
  25176. $this->_out('/N 1');
  25177. $this->_out('>>');
  25178. $this->_out('endobj');
  25179. }
  25180. }
  25181. }
  25182. if (empty($grad['is_mask'])) {
  25183. $this->_newobj();
  25184. $this->_out('<<');
  25185. $this->_out('/ShadingType '.$grad['type']);
  25186. if (isset($grad['colorspace'])) {
  25187. $this->_out('/ColorSpace /Device'.$grad['colorspace']); // Can use CMYK if all C0 and C1 above have 4 values
  25188. } else {
  25189. $this->_out('/ColorSpace /DeviceRGB');
  25190. }
  25191. if ($grad['type'] == 2) {
  25192. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  25193. $this->_out('/Function '.$f1.' 0 R');
  25194. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25195. $this->_out('>>');
  25196. }
  25197. else if ($grad['type'] == 3) {
  25198. //x0, y0, r0, x1, y1, r1
  25199. //at this this time radius of inner circle is 0
  25200. $ir = 0;
  25201. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  25202. $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]));
  25203. $this->_out('/Function '.$f1.' 0 R');
  25204. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25205. $this->_out('>>');
  25206. }
  25207. else if ($grad['type']==6) {
  25208. $this->_out('/BitsPerCoordinate 16');
  25209. $this->_out('/BitsPerComponent 8');
  25210. if ($grad['colorspace'] == 'CMYK') { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1 0 1]'); }
  25211. else if ($grad['colorspace'] == 'Gray') { $this->_out('/Decode[0 1 0 1 0 1]'); }
  25212. else { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]'); }
  25213. $this->_out('/BitsPerFlag 8');
  25214. $this->_out('/Length '.strlen($grad['stream']));
  25215. $this->_out('>>');
  25216. $this->_putstream($grad['stream']);
  25217. }
  25218. $this->_out('endobj');
  25219. }
  25220. $this->gradients[$id]['id'] = $this->n;
  25221. // set pattern object
  25222. $this->_newobj();
  25223. $out = '<< /Type /Pattern /PatternType 2';
  25224. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  25225. $out .= ' >>';
  25226. $out .= "\n".'endobj';
  25227. $this->_out($out);
  25228. $this->gradients[$id]['pattern'] = $this->n;
  25229. if (isset($grad['trans']) && $grad['trans']) {
  25230. // luminosity pattern
  25231. $transid = $id + $maxid;
  25232. $this->_newobj();
  25233. $this->_out('<<');
  25234. $this->_out('/ShadingType '.$grad['type']);
  25235. $this->_out('/ColorSpace /DeviceGray');
  25236. if ($grad['type'] == 2) {
  25237. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  25238. $this->_out('/Function '.$f2.' 0 R');
  25239. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25240. $this->_out('>>');
  25241. }
  25242. else if ($grad['type'] == 3) {
  25243. //x0, y0, r0, x1, y1, r1
  25244. //at this this time radius of inner circle is 0
  25245. $ir = 0;
  25246. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  25247. $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]));
  25248. $this->_out('/Function '.$f2.' 0 R');
  25249. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  25250. $this->_out('>>');
  25251. }
  25252. else if ($grad['type']==6) {
  25253. $this->_out('/BitsPerCoordinate 16');
  25254. $this->_out('/BitsPerComponent 8');
  25255. $this->_out('/Decode[0 1 0 1 0 1]');
  25256. $this->_out('/BitsPerFlag 8');
  25257. $this->_out('/Length '.strlen($grad['stream_trans']));
  25258. $this->_out('>>');
  25259. $this->_putstream($grad['stream_trans']);
  25260. }
  25261. $this->_out('endobj');
  25262. $this->gradients[$transid]['id'] = $this->n;
  25263. $this->_newobj();
  25264. $this->_out('<< /Type /Pattern /PatternType 2');
  25265. $this->_out('/Shading '.$this->gradients[$transid]['id'].' 0 R');
  25266. $this->_out('>>');
  25267. $this->_out('endobj');
  25268. $this->gradients[$transid]['pattern'] = $this->n;
  25269. $this->_newobj();
  25270. // Need to extend size of viewing box in case of transformations
  25271. $str = 'q /a0 gs /Pattern cs /p'.$transid.' scn -'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).' re f Q';
  25272. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  25273. $p=($this->compress) ? gzcompress($str) : $str;
  25274. $this->_out('<< /Type /XObject /Subtype /Form /FormType 1 '.$filter);
  25275. $this->_out('/Length '.strlen($p));
  25276. $this->_out('/BBox [-'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).']');
  25277. $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >>');
  25278. $this->_out('/Resources <<');
  25279. $this->_out('/ExtGState << /a0 << /ca 1 /CA 1 >> >>');
  25280. $this->_out('/Pattern << /p'.$transid.' '.$this->gradients[$transid]['pattern'].' 0 R >>');
  25281. $this->_out('>>');
  25282. $this->_out('>>');
  25283. $this->_putstream($p);
  25284. $this->_out('endobj');
  25285. $this->_newobj();
  25286. $this->_out('<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj');
  25287. $this->_newobj();
  25288. $this->_out('<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj');
  25289. if ($grad['fo']) { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id, 'fo'=>true); }
  25290. else { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id); }
  25291. }
  25292. }
  25293. }
  25294. /*-- END BACKGROUNDS --*/
  25295. function _putspotcolors() {
  25296. foreach($this->spotColors as $name=>$color) {
  25297. $this->_newobj();
  25298. $this->_out('[/Separation /'.str_replace(' ','#20',$name));
  25299. $this->_out('/DeviceCMYK <<');
  25300. $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  25301. $this->_out(sprintf('/C1 [%.3F %.3F %.3F %.3F] ',$color['c']/100,$color['m']/100,$color['y']/100,$color['k']/100));
  25302. $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  25303. $this->_out('endobj');
  25304. $this->spotColors[$name]['n']=$this->n;
  25305. }
  25306. }
  25307. function _putresources() {
  25308. if ($this->hasOC)
  25309. $this->_putocg();
  25310. $this->_putextgstates();
  25311. $this->_putspotcolors();
  25312. if ($this->progressBar) { $this->UpdateProgressBar(2,'40','Compiling Fonts'); } // *PROGRESS-BAR*
  25313. $this->_putfonts();
  25314. if ($this->progressBar) { $this->UpdateProgressBar(2,'50','Compiling Images'); } // *PROGRESS-BAR*
  25315. $this->_putimages();
  25316. $this->_putformobjects(); // *IMAGES-CORE*
  25317. /*-- IMPORTS --*/
  25318. if ($this->enableImports) {
  25319. $this->_putformxobjects();
  25320. $this->_putimportedobjects();
  25321. }
  25322. /*-- END IMPORTS --*/
  25323. /*-- BACKGROUNDS --*/
  25324. $this->_putshaders();
  25325. $this->_putpatterns();
  25326. /*-- END BACKGROUNDS --*/
  25327. //Resource dictionary
  25328. $this->offsets[2]=strlen($this->buffer);
  25329. $this->_out('2 0 obj');
  25330. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  25331. $this->_out('/Font <<');
  25332. foreach($this->fonts as $font) {
  25333. if (!$font['used'] && $font['type']=='TTF') { continue; }
  25334. if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) {
  25335. foreach($font['n'] AS $k => $fid) {
  25336. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  25337. }
  25338. }
  25339. else {
  25340. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  25341. }
  25342. }
  25343. $this->_out('>>');
  25344. if (count($this->spotColors)) {
  25345. $this->_out('/ColorSpace <<');
  25346. foreach($this->spotColors as $color)
  25347. $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  25348. $this->_out('>>');
  25349. }
  25350. if (count($this->extgstates)) {
  25351. $this->_out('/ExtGState <<');
  25352. foreach($this->extgstates as $k=>$extgstate)
  25353. if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R');
  25354. else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  25355. $this->_out('>>');
  25356. }
  25357. /*-- BACKGROUNDS --*/
  25358. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  25359. $this->_out('/Shading <<');
  25360. foreach ($this->gradients as $id => $grad) {
  25361. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  25362. }
  25363. $this->_out('>>');
  25364. /*
  25365. // ??? Not needed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  25366. $this->_out('/Pattern <<');
  25367. foreach ($this->gradients as $id => $grad) {
  25368. $this->_out('/P'.$id.' '.$grad['pattern'].' 0 R');
  25369. }
  25370. $this->_out('>>');
  25371. */
  25372. }
  25373. /*-- END BACKGROUNDS --*/
  25374. if(count($this->images) || count($this->formobjects) || ($this->enableImports && count($this->tpls))) {
  25375. $this->_out('/XObject <<');
  25376. foreach($this->images as $image)
  25377. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  25378. foreach($this->formobjects as $formobject)
  25379. $this->_out('/FO'.$formobject['i'].' '.$formobject['n'].' 0 R');
  25380. /*-- IMPORTS --*/
  25381. if ($this->enableImports && count($this->tpls)) {
  25382. foreach($this->tpls as $tplidx => $tpl) {
  25383. $this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R');
  25384. }
  25385. }
  25386. /*-- END IMPORTS --*/
  25387. $this->_out('>>');
  25388. }
  25389. /*-- BACKGROUNDS --*/
  25390. if (count($this->patterns)) {
  25391. $this->_out('/Pattern <<');
  25392. foreach($this->patterns as $k=>$patterns)
  25393. $this->_out('/P'.$k.' '.$patterns['n'].' 0 R');
  25394. $this->_out('>>');
  25395. }
  25396. /*-- END BACKGROUNDS --*/
  25397. if ($this->hasOC)
  25398. $this->_out('/Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R /OC3 '.$this->n_ocg_hidden.' 0 R>>');
  25399. $this->_out('>>');
  25400. $this->_out('endobj'); // end resource dictionary
  25401. $this->_putbookmarks(); // *BOOKMARKS*
  25402. if (isset($this->js) && $this->js) {
  25403. $this->_putjavascript();
  25404. }
  25405. /*-- ENCRYPTION --*/
  25406. if ($this->encrypted) {
  25407. $this->_newobj();
  25408. $this->enc_obj_id = $this->n;
  25409. $this->_out('<<');
  25410. $this->_putencryption();
  25411. $this->_out('>>');
  25412. $this->_out('endobj');
  25413. }
  25414. /*-- END ENCRYPTION --*/
  25415. }
  25416. function _putjavascript() {
  25417. $this->_newobj();
  25418. $this->n_js = $this->n;
  25419. $this->_out('<<');
  25420. $this->_out('/Names [(EmbeddedJS) '.(1 + $this->n).' 0 R ]');
  25421. $this->_out('>>');
  25422. $this->_out('endobj');
  25423. $this->_newobj();
  25424. $this->_out('<<');
  25425. $this->_out('/S /JavaScript');
  25426. $this->_out('/JS '.$this->_textstring($this->js));
  25427. $this->_out('>>');
  25428. $this->_out('endobj');
  25429. }
  25430. /*-- ENCRYPTION --*/
  25431. function _putencryption() {
  25432. $this->_out('/Filter /Standard');
  25433. if ($this->useRC128encryption) {
  25434. $this->_out('/V 2');
  25435. $this->_out('/R 3');
  25436. $this->_out('/Length 128');
  25437. }
  25438. else {
  25439. $this->_out('/V 1');
  25440. $this->_out('/R 2');
  25441. }
  25442. $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  25443. $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  25444. $this->_out('/P '.$this->Pvalue);
  25445. }
  25446. /*-- END ENCRYPTION --*/
  25447. function _puttrailer() {
  25448. $this->_out('/Size '.($this->n+1));
  25449. $this->_out('/Root '.$this->n.' 0 R');
  25450. $this->_out('/Info '.$this->InfoRoot.' 0 R');
  25451. /*-- ENCRYPTION --*/
  25452. if ($this->encrypted) {
  25453. $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  25454. $this->_out('/ID [<'.$this->uniqid.'> <'.$this->uniqid.'>]');
  25455. }
  25456. else {
  25457. /*-- END ENCRYPTION --*/
  25458. $uniqid = md5(time() . $this->buffer);
  25459. $this->_out('/ID [<'.$uniqid.'> <'.$uniqid.'>]');
  25460. /*-- ENCRYPTION --*/
  25461. }
  25462. /*-- END ENCRYPTION --*/
  25463. }
  25464. /*-- ENCRYPTION --*/
  25465. function SetProtection($permissions=array(),$user_pass='',$owner_pass=null, $length=40) {
  25466. $this->encrypted=false;
  25467. if (is_string($permissions) && strlen($permissions)>0) { $permissions = array($permissions); }
  25468. else if (!is_array($permissions)) { return 0; }
  25469. $this->last_rc4_key='';
  25470. $this->padding="\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
  25471. "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  25472. $options = array(
  25473. 'print' => 4, // bit 3
  25474. 'modify' => 8, // bit 4
  25475. 'copy' => 16, // bit 5
  25476. 'annot-forms' => 32, // bit 6
  25477. 'fill-forms' => 256, // bit 9
  25478. 'extract' => 512, // bit 10
  25479. 'assemble' => 1024,// bit 11
  25480. 'print-highres' => 2048 // bit 12
  25481. );
  25482. // bit 31 = 1073741824
  25483. // bit 32 = 2147483648
  25484. // bits 13-31 = 2147479552
  25485. // bits 13-32 = 4294963200 + 192 = 4294963392
  25486. $protection = 4294963392; // bits 7,8,13-32
  25487. foreach ($permissions as $permission) {
  25488. if (!isset($options[$permission]))
  25489. $this->Error('Incorrect permission: '.$permission);
  25490. if ($options[$permission] > 32) { $this->useRC128encryption = true; }
  25491. if (isset($options[$permission])) $protection += $options[$permission];
  25492. }
  25493. if ($length==128) { $this->useRC128encryption = true; }
  25494. if ($owner_pass === null)
  25495. $owner_pass = uniqid(rand());
  25496. $this->encrypted = true;
  25497. $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
  25498. }
  25499. // Compute key depending on object number where the encrypted data is stored
  25500. function _objectkey($n) {
  25501. if ($this->useRC128encryption)
  25502. $len = 16;
  25503. else
  25504. $len = 10;
  25505. return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,$len);
  25506. }
  25507. // RC4 is the standard encryption algorithm used in PDF format
  25508. function _RC4($key, $text) {
  25509. if ($this->last_rc4_key != $key) {
  25510. $k = str_repeat($key, 256/strlen($key)+1);
  25511. $rc4 = range(0,255);
  25512. $j = 0;
  25513. for ($i=0; $i<256; $i++){
  25514. $t = $rc4[$i];
  25515. $j = ($j + $t + ord($k[$i])) % 256;
  25516. $rc4[$i] = $rc4[$j];
  25517. $rc4[$j] = $t;
  25518. }
  25519. $this->last_rc4_key = $key;
  25520. $this->last_rc4_key_c = $rc4;
  25521. } else {
  25522. $rc4 = $this->last_rc4_key_c;
  25523. }
  25524. $len = strlen($text);
  25525. $a = 0;
  25526. $b = 0;
  25527. $out = '';
  25528. for ($i=0; $i<$len; $i++){
  25529. $a = ($a+1)%256;
  25530. $t= $rc4[$a];
  25531. $b = ($b+$t)%256;
  25532. $rc4[$a] = $rc4[$b];
  25533. $rc4[$b] = $t;
  25534. $k = $rc4[($rc4[$a]+$rc4[$b])%256];
  25535. $out.= chr(ord($text[$i]) ^ $k);
  25536. }
  25537. return $out;
  25538. }
  25539. // Get MD5 as binary string
  25540. function _md5_16($string) {
  25541. return pack('H*',md5($string));
  25542. }
  25543. // Compute O value
  25544. function _Ovalue($user_pass, $owner_pass) {
  25545. $tmp = $this->_md5_16($owner_pass);
  25546. if ($this->useRC128encryption) {
  25547. for ($i = 0; $i < 50; ++$i) {
  25548. $tmp = $this->_md5_16($tmp);
  25549. }
  25550. }
  25551. if ($this->useRC128encryption)
  25552. $keybytelen = (128 / 8);
  25553. else
  25554. $keybytelen = (40 / 8);
  25555. $owner_RC4_key = substr($tmp,0,$keybytelen);
  25556. $enc = $this->_RC4($owner_RC4_key, $user_pass);
  25557. if ($this->useRC128encryption) {
  25558. $len = strlen($owner_RC4_key);
  25559. for ($i = 1; $i <= 19; ++$i) {
  25560. $key = '';
  25561. for ($j = 0; $j < $len; ++$j) {
  25562. $key .= chr(ord($owner_RC4_key{$j}) ^ $i);
  25563. }
  25564. $enc = $this->_RC4($key, $enc);
  25565. }
  25566. }
  25567. return $enc;
  25568. }
  25569. // Compute U value
  25570. function _Uvalue() {
  25571. if ($this->useRC128encryption) {
  25572. $tmp = $this->_md5_16($this->padding.$this->_hexToString($this->uniqid));
  25573. $enc = $this->_RC4($this->encryption_key, $tmp);
  25574. $len = strlen($tmp);
  25575. for ($i=1; $i<=19; ++$i) {
  25576. $key = '';
  25577. for ($j=0; $j<$len; ++$j) {
  25578. $key .= chr(ord($this->encryption_key{$j}) ^ $i);
  25579. }
  25580. $enc = $this->_RC4($key, $enc);
  25581. }
  25582. $enc .= str_repeat("\x00", 16);
  25583. return substr($enc, 0, 32);
  25584. }
  25585. else {
  25586. return $this->_RC4($this->encryption_key, $this->padding);
  25587. }
  25588. }
  25589. // Compute encryption key
  25590. function _generateencryptionkey($user_pass, $owner_pass, $protection) {
  25591. // Pad passwords
  25592. $user_pass = substr($user_pass.$this->padding,0,32);
  25593. $owner_pass = substr($owner_pass.$this->padding,0,32);
  25594. $chars = 'ABCDEF1234567890';
  25595. $id = '';
  25596. for ($i=0; $i<32; $i++) { $id .= $chars{rand(0, 15)}; }
  25597. $this->uniqid = md5($id);
  25598. // Compute O value
  25599. $this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
  25600. // Compute encyption key
  25601. if ($this->useRC128encryption)
  25602. $keybytelen = (128/8);
  25603. else
  25604. $keybytelen = (40/8);
  25605. $prot = sprintf('%032b', $protection);
  25606. $perms = chr(bindec(substr($prot,24,8)));
  25607. $perms .= chr(bindec(substr($prot,16,8)));
  25608. $perms .= chr(bindec(substr($prot,8,8)));
  25609. $perms .= chr(bindec(substr($prot,0,8)));
  25610. $tmp = $this->_md5_16($user_pass.$this->Ovalue.$perms.$this->_hexToString($this->uniqid));
  25611. if ($this->useRC128encryption) {
  25612. for ($i=0; $i<50; ++$i) {
  25613. $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
  25614. }
  25615. }
  25616. $this->encryption_key = substr($tmp,0,$keybytelen);
  25617. // Compute U value
  25618. $this->Uvalue = $this->_Uvalue();
  25619. // Compute P value
  25620. $this->Pvalue = $protection;
  25621. }
  25622. function _hexToString($hs) {
  25623. $s = '';
  25624. $len = strlen($hs);
  25625. if (($len % 2) != 0) {
  25626. $hs .= '0';
  25627. ++$len;
  25628. }
  25629. for ($i = 0; $i < $len; $i += 2) {
  25630. $s .= chr(hexdec($hs{$i}.$hs{($i + 1)}));
  25631. }
  25632. return $s;
  25633. }
  25634. /*-- END ENCRYPTION --*/
  25635. //=========================================
  25636. /*-- BOOKMARKS --*/
  25637. // FROM class PDF_Bookmark
  25638. function Bookmark($txt,$level=0,$y=0) {
  25639. $txt = $this->purify_utf8_text($txt);
  25640. if ($this->text_input_as_HTML) {
  25641. $txt = $this->all_entities_to_utf8($txt);
  25642. }
  25643. if($y==-1) {
  25644. if (!$this->ColActive){ $y=$this->y; }
  25645. else { $y = $this->y0; } // If columns are on - mark top of columns
  25646. }
  25647. // else y is used as set, or =0 i.e. top of page
  25648. // DIRECTIONALITY RTL
  25649. $bmo = array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  25650. if ($this->keep_block_together) {
  25651. $this->ktBMoutlines[]= $bmo;
  25652. }
  25653. /*-- TABLES --*/
  25654. else if ($this->table_rotate) {
  25655. $this->tbrot_BMoutlines[]= $bmo;
  25656. }
  25657. else if ($this->kwt) {
  25658. $this->kwt_BMoutlines[]= $bmo;
  25659. }
  25660. /*-- END TABLES --*/
  25661. else if ($this->ColActive) { // *COLUMNS*
  25662. $this->col_BMoutlines[]= $bmo; // *COLUMNS*
  25663. } // *COLUMNS*
  25664. else {
  25665. $this->BMoutlines[]= $bmo;
  25666. }
  25667. }
  25668. function _putbookmarks()
  25669. {
  25670. $nb=count($this->BMoutlines);
  25671. if($nb==0)
  25672. return;
  25673. $lru=array();
  25674. $level=0;
  25675. foreach($this->BMoutlines as $i=>$o)
  25676. {
  25677. if($o['l']>0)
  25678. {
  25679. $parent=$lru[$o['l']-1];
  25680. //Set parent and last pointers
  25681. $this->BMoutlines[$i]['parent']=$parent;
  25682. $this->BMoutlines[$parent]['last']=$i;
  25683. if($o['l']>$level)
  25684. {
  25685. //Level increasing: set first pointer
  25686. $this->BMoutlines[$parent]['first']=$i;
  25687. }
  25688. }
  25689. else
  25690. $this->BMoutlines[$i]['parent']=$nb;
  25691. if($o['l']<=$level and $i>0)
  25692. {
  25693. //Set prev and next pointers
  25694. $prev=$lru[$o['l']];
  25695. $this->BMoutlines[$prev]['next']=$i;
  25696. $this->BMoutlines[$i]['prev']=$prev;
  25697. }
  25698. $lru[$o['l']]=$i;
  25699. $level=$o['l'];
  25700. }
  25701. //Outline items
  25702. $n=$this->n+1;
  25703. foreach($this->BMoutlines as $i=>$o)
  25704. {
  25705. $this->_newobj();
  25706. $this->_out('<</Title '.$this->_UTF16BEtextstring($o['t']));
  25707. $this->_out('/Parent '.($n+$o['parent']).' 0 R');
  25708. if(isset($o['prev']))
  25709. $this->_out('/Prev '.($n+$o['prev']).' 0 R');
  25710. if(isset($o['next']))
  25711. $this->_out('/Next '.($n+$o['next']).' 0 R');
  25712. if(isset($o['first']))
  25713. $this->_out('/First '.($n+$o['first']).' 0 R');
  25714. if(isset($o['last']))
  25715. $this->_out('/Last '.($n+$o['last']).' 0 R');
  25716. if (isset($this->pageDim[$o['p']]['h'])) { $h=$this->pageDim[$o['p']]['h']; }
  25717. else { $h = 0; }
  25718. $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.3F null]',1+2*($o['p']),($h-$o['y'])*_MPDFK));
  25719. if (isset($this->bookmarkStyles) && isset($this->bookmarkStyles[$o['l']])) {
  25720. // font style
  25721. $bms = $this->bookmarkStyles[$o['l']]['style'];
  25722. $style = 0;
  25723. if (strpos($bms,'B') !== false) { $style += 2; }
  25724. if (strpos($bms,'I') !== false) { $style += 1; }
  25725. $this->_out(sprintf('/F %d', $style));
  25726. // Colour
  25727. $col = $this->bookmarkStyles[$o['l']]['color'];
  25728. if (isset($col) && is_array($col) && count($col)==3) {
  25729. $this->_out(sprintf('/C [%.3F %.3F %.3F]', ($col[0]/255), ($col[1]/255), ($col[2]/255)));
  25730. }
  25731. }
  25732. $this->_out('/Count 0>>');
  25733. $this->_out('endobj');
  25734. }
  25735. //Outline root
  25736. $this->_newobj();
  25737. $this->OutlineRoot=$this->n;
  25738. $this->_out('<</Type /BMoutlines /First '.$n.' 0 R');
  25739. $this->_out('/Last '.($n+$lru[0]).' 0 R>>');
  25740. $this->_out('endobj');
  25741. }
  25742. /*-- END BOOKMARKS --*/
  25743. // *BOOKMARKS*
  25744. //======================================================
  25745. // DEPRACATED but included for backwards compatability
  25746. function startPageNums() {
  25747. }
  25748. //======================================================
  25749. /*-- TOC --*/
  25750. // ToC TABLE OF CONTENTS
  25751. // Initiate, and Mark a place for the Table of Contents to be inserted
  25752. function TOC($tocfont='', $tocfontsize=8, $tocindent=5, $resetpagenum='', $pagenumstyle='', $suppress='', $toc_orientation='', $TOCusePaging=true, $TOCuseLinking=false, $toc_id=0) {
  25753. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25754. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25755. $this->tocontents->TOC($tocfont, $tocfontsize, $tocindent, $resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $TOCusePaging, $TOCuseLinking, $toc_id);
  25756. }
  25757. function TOCpagebreakByArray($a) {
  25758. if (!is_array($a)) { $a = array(); }
  25759. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25760. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25761. $tocfont = (isset($a['tocfont']) ? $a['tocfont'] : (isset($a['font']) ? $a['font'] : ''));
  25762. $tocfontsize = (isset($a['tocfontsize']) ? $a['tocfontsize'] : (isset($a['font-size']) ? $a['font-size'] : ''));
  25763. $tocindent = (isset($a['tocindent']) ? $a['tocindent'] : (isset($a['indent']) ? $a['indent'] : ''));
  25764. $TOCusePaging = (isset($a['TOCusePaging']) ? $a['TOCusePaging'] : (isset($a['paging']) ? $a['paging'] : true));
  25765. $TOCuseLinking = (isset($a['TOCuseLinking']) ? $a['TOCuseLinking'] : (isset($a['links']) ? $a['links'] : ''));
  25766. $toc_orientation = (isset($a['toc_orientation']) ? $a['toc_orientation'] : (isset($a['toc-orientation']) ? $a['toc-orientation'] : ''));
  25767. $toc_mgl = (isset($a['toc_mgl']) ? $a['toc_mgl'] : (isset($a['toc-margin-left']) ? $a['toc-margin-left'] : ''));
  25768. $toc_mgr = (isset($a['toc_mgr']) ? $a['toc_mgr'] : (isset($a['toc-margin-right']) ? $a['toc-margin-right'] : ''));
  25769. $toc_mgt = (isset($a['toc_mgt']) ? $a['toc_mgt'] : (isset($a['toc-margin-top']) ? $a['toc-margin-top'] : ''));
  25770. $toc_mgb = (isset($a['toc_mgb']) ? $a['toc_mgb'] : (isset($a['toc-margin-bottom']) ? $a['toc-margin-bottom'] : ''));
  25771. $toc_mgh = (isset($a['toc_mgh']) ? $a['toc_mgh'] : (isset($a['toc-margin-header']) ? $a['toc-margin-header'] : ''));
  25772. $toc_mgf = (isset($a['toc_mgf']) ? $a['toc_mgf'] : (isset($a['toc-margin-footer']) ? $a['toc-margin-footer'] : ''));
  25773. $toc_ohname = (isset($a['toc_ohname']) ? $a['toc_ohname'] : (isset($a['toc-odd-header-name']) ? $a['toc-odd-header-name'] : ''));
  25774. $toc_ehname = (isset($a['toc_ehname']) ? $a['toc_ehname'] : (isset($a['toc-even-header-name']) ? $a['toc-even-header-name'] : ''));
  25775. $toc_ofname = (isset($a['toc_ofname']) ? $a['toc_ofname'] : (isset($a['toc-odd-footer-name']) ? $a['toc-odd-footer-name'] : ''));
  25776. $toc_efname = (isset($a['toc_efname']) ? $a['toc_efname'] : (isset($a['toc-even-footer-name']) ? $a['toc-even-footer-name'] : ''));
  25777. $toc_ohvalue = (isset($a['toc_ohvalue']) ? $a['toc_ohvalue'] : (isset($a['toc-odd-header-value']) ? $a['toc-odd-header-value'] : 0));
  25778. $toc_ehvalue = (isset($a['toc_ehvalue']) ? $a['toc_ehvalue'] : (isset($a['toc-even-header-value']) ? $a['toc-even-header-value'] : 0));
  25779. $toc_ofvalue = (isset($a['toc_ofvalue']) ? $a['toc_ofvalue'] : (isset($a['toc-odd-footer-value']) ? $a['toc-odd-footer-value'] : 0));
  25780. $toc_efvalue = (isset($a['toc_efvalue']) ? $a['toc_efvalue'] : (isset($a['toc-even-footer-value']) ? $a['toc-even-footer-value'] : 0));
  25781. $toc_preHTML = (isset($a['toc_preHTML']) ? $a['toc_preHTML'] : (isset($a['toc-preHTML']) ? $a['toc-preHTML'] : ''));
  25782. $toc_postHTML = (isset($a['toc_postHTML']) ? $a['toc_postHTML'] : (isset($a['toc-postHTML']) ? $a['toc-postHTML'] : ''));
  25783. $toc_bookmarkText = (isset($a['toc_bookmarkText']) ? $a['toc_bookmarkText'] : (isset($a['toc-bookmarkText']) ? $a['toc-bookmarkText'] : ''));
  25784. $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
  25785. $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
  25786. $suppress = (isset($a['suppress']) ? $a['suppress'] : '');
  25787. $orientation = (isset($a['orientation']) ? $a['orientation'] : '');
  25788. $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : ''));
  25789. $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : ''));
  25790. $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : ''));
  25791. $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : ''));
  25792. $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : ''));
  25793. $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : ''));
  25794. $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : ''));
  25795. $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : ''));
  25796. $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : ''));
  25797. $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : ''));
  25798. $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0));
  25799. $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0));
  25800. $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0));
  25801. $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0));
  25802. $toc_id = (isset($a['toc_id']) ? $a['toc_id'] : (isset($a['name']) ? $a['name'] : 0));
  25803. $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : ''));
  25804. $toc_pagesel = (isset($a['toc_pagesel']) ? $a['toc_pagesel'] : (isset($a['toc-pageselector']) ? $a['toc-pageselector'] : ''));
  25805. $sheetsize = (isset($a['sheetsize']) ? $a['sheetsize'] : (isset($a['sheet-size']) ? $a['sheet-size'] : ''));
  25806. $toc_sheetsize = (isset($a['toc_sheetsize']) ? $a['toc_sheetsize'] : (isset($a['toc-sheet-size']) ? $a['toc-sheet-size'] : ''));
  25807. $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);
  25808. }
  25809. 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='') {
  25810. if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); }
  25811. if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); }
  25812. //Start a new page
  25813. if($this->state==0) $this->AddPage();
  25814. if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) {
  25815. // Don't add a page
  25816. if ($this->page==1 && count($this->PageNumSubstitutions)==0) {
  25817. if (!$suppress) { $suppress = 'off'; }
  25818. if (!$resetpagenum) { $resetpagenum= 1; }
  25819. //$this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  25820. }
  25821. $this->PageNumSubstitutions[] = array('from'=>$this->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  25822. }
  25823. else {
  25824. $this->AddPage($orientation,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$sheetsize);
  25825. }
  25826. $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);
  25827. }
  25828. function TOC_Entry($txt, $level=0, $toc_id=0) {
  25829. $txt = $this->purify_utf8_text($txt);
  25830. if ($this->text_input_as_HTML) {
  25831. $txt = $this->all_entities_to_utf8($txt);
  25832. }
  25833. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  25834. if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  25835. $linkn = $this->AddLink();
  25836. $this->SetLink($linkn,$ily,$this->page);
  25837. /*-- RTL --*/
  25838. if ($this->biDirectional) {
  25839. $txt = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $txt );
  25840. }
  25841. /*-- END RTL --*/
  25842. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  25843. else if (!$toc_id) { $toc_id = 0; }
  25844. else { $toc_id = strtolower($toc_id); }
  25845. $btoc = array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  25846. if ($this->keep_block_together) {
  25847. $this->_kttoc[]= $btoc;
  25848. }
  25849. /*-- TABLES --*/
  25850. else if ($this->table_rotate) {
  25851. $this->tbrot_toc[]= $btoc;
  25852. }
  25853. else if ($this->kwt) {
  25854. $this->kwt_toc[]= $btoc;
  25855. }
  25856. /*-- END TABLES --*/
  25857. else if ($this->ColActive) { // *COLUMNS*
  25858. $this->col_toc[]= $btoc; // *COLUMNS*
  25859. } // *COLUMNS*
  25860. else {
  25861. $this->tocontents->_toc[]= $btoc;
  25862. }
  25863. }
  25864. /*-- END TOC --*/
  25865. //======================================================
  25866. function MovePages($target_page, $start_page, $end_page=-1) {
  25867. // move a page/pages EARLIER in the document
  25868. if ($end_page<1) { $end_page = $start_page; }
  25869. $n_toc = $end_page - $start_page + 1;
  25870. // Set/Update PageNumSubstitutions changes before moving anything
  25871. if (count($this->PageNumSubstitutions)) {
  25872. $tp_present = false;
  25873. $sp_present = false;
  25874. $ep_present = false;
  25875. foreach($this->PageNumSubstitutions AS $k=>$v) {
  25876. if ($this->PageNumSubstitutions[$k]['from']==$target_page) {
  25877. $tp_present = true;
  25878. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25879. $this->PageNumSubstitutions[$k]['suppress']='off';
  25880. }
  25881. }
  25882. if ($this->PageNumSubstitutions[$k]['from']==$start_page) {
  25883. $sp_present = true;
  25884. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25885. $this->PageNumSubstitutions[$k]['suppress']='off';
  25886. }
  25887. }
  25888. if ($this->PageNumSubstitutions[$k]['from']==($end_page+1)) {
  25889. $ep_present = true;
  25890. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  25891. $this->PageNumSubstitutions[$k]['suppress']='off';
  25892. }
  25893. }
  25894. }
  25895. if (!$tp_present) {
  25896. list($tp_type, $tp_suppress, $tp_reset) = $this->docPageSettings($target_page);
  25897. }
  25898. if (!$sp_present) {
  25899. list($sp_type, $sp_suppress, $sp_reset) = $this->docPageSettings($start_page);
  25900. }
  25901. if (!$ep_present) {
  25902. list($ep_type, $ep_suppress, $ep_reset) = $this->docPageSettings($start_page-1);
  25903. }
  25904. }
  25905. $last = array();
  25906. //store pages
  25907. for($i = $start_page;$i <= $end_page ;$i++)
  25908. $last[]=$this->pages[$i];
  25909. //move pages
  25910. for($i=$start_page - 1;$i>=($target_page);$i--) {
  25911. $this->pages[$i+$n_toc]=$this->pages[$i];
  25912. }
  25913. //Put toc pages at insert point
  25914. for($i = 0;$i < $n_toc;$i++) {
  25915. $this->pages[$target_page + $i]=$last[$i];
  25916. }
  25917. /*-- BOOKMARKS --*/
  25918. // Update Bookmarks
  25919. foreach($this->BMoutlines as $i=>$o) {
  25920. if($o['p']>=$target_page) {
  25921. $this->BMoutlines[$i]['p'] += $n_toc;
  25922. }
  25923. }
  25924. /*-- END BOOKMARKS --*/
  25925. // Update Page Links
  25926. if (count($this->PageLinks)) {
  25927. $newarr = array();
  25928. foreach($this->PageLinks as $i=>$o) {
  25929. foreach($this->PageLinks[$i] as $key => $pl) {
  25930. if (strpos($pl[4],'@')===0) {
  25931. $p=substr($pl[4],1);
  25932. if($p>=$start_page && $p<=$end_page) {
  25933. $this->PageLinks[$i][$key][4] = '@'.($p + ($target_page - $start_page));
  25934. }
  25935. else if($p>=$target_page && $p<$start_page) {
  25936. $this->PageLinks[$i][$key][4] = '@'.($p+$n_toc);
  25937. }
  25938. }
  25939. }
  25940. if($i>=$start_page && $i<=$end_page) {
  25941. $newarr[($i + ($target_page - $start_page))] = $this->PageLinks[$i];
  25942. }
  25943. else if($i>=$target_page && $i<$start_page) {
  25944. $newarr[($i + $n_toc)] = $this->PageLinks[$i];
  25945. }
  25946. else {
  25947. $newarr[$i] = $this->PageLinks[$i];
  25948. }
  25949. }
  25950. $this->PageLinks = $newarr;
  25951. }
  25952. // OrientationChanges
  25953. if (count($this->OrientationChanges)) {
  25954. $newarr = array();
  25955. foreach($this->OrientationChanges AS $p=>$v) {
  25956. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->OrientationChanges[$p]; }
  25957. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->OrientationChanges[$p]; }
  25958. else { $newarr[$p] = $this->OrientationChanges[$p]; }
  25959. }
  25960. ksort($newarr);
  25961. $this->OrientationChanges = $newarr;
  25962. }
  25963. // Page Dimensions
  25964. if (count($this->pageDim)) {
  25965. $newarr = array();
  25966. foreach($this->pageDim AS $p=>$v) {
  25967. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->pageDim[$p]; }
  25968. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->pageDim[$p]; }
  25969. else { $newarr[$p] = $this->pageDim[$p]; }
  25970. }
  25971. ksort($newarr);
  25972. $this->pageDim = $newarr;
  25973. }
  25974. // HTML Headers & Footers
  25975. if (count($this->saveHTMLHeader)) {
  25976. $newarr = array();
  25977. foreach($this->saveHTMLHeader AS $p=>$v) {
  25978. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLHeader[$p]; }
  25979. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLHeader[$p]; }
  25980. else { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  25981. }
  25982. ksort($newarr);
  25983. $this->saveHTMLHeader = $newarr;
  25984. }
  25985. if (count($this->saveHTMLFooter)) {
  25986. $newarr = array();
  25987. foreach($this->saveHTMLFooter AS $p=>$v) {
  25988. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLFooter[$p]; }
  25989. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLFooter[$p]; }
  25990. else { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  25991. }
  25992. ksort($newarr);
  25993. $this->saveHTMLFooter = $newarr;
  25994. }
  25995. // Update Internal Links
  25996. if (count($this->internallink)) {
  25997. foreach($this->internallink as $key=>$o) {
  25998. if($o['PAGE']>=$start_page && $o['PAGE']<=$end_page) {
  25999. $this->internallink[$key]['PAGE'] += ($target_page - $start_page);
  26000. }
  26001. else if($o['PAGE']>=$target_page && $o['PAGE']<$start_page) {
  26002. $this->internallink[$key]['PAGE'] += $n_toc;
  26003. }
  26004. }
  26005. }
  26006. // Update Links
  26007. if (count($this->links)) {
  26008. foreach($this->links as $key=>$o) {
  26009. if($o[0]>=$start_page && $o[0]<=$end_page) {
  26010. $this->links[$key][0] += ($target_page - $start_page);
  26011. }
  26012. if($o[0]>=$target_page && $o[0]<$start_page) {
  26013. $this->links[$key][0] += $n_toc;
  26014. }
  26015. }
  26016. }
  26017. // Update Form fields
  26018. if (count($this->form->forms)) {
  26019. foreach($this->form->forms as $key=>$f) {
  26020. if($f['page']>=$start_page && $f['page']<=$end_page) {
  26021. $this->form->forms[$key]['page'] += ($target_page - $start_page);
  26022. }
  26023. if($f['page']>=$target_page && $f['page']<$start_page) {
  26024. $this->form->forms[$key]['page'] += $n_toc;
  26025. }
  26026. }
  26027. }
  26028. /*-- ANNOTATIONS --*/
  26029. // Update Annotations
  26030. if (count($this->PageAnnots)) {
  26031. $newarr = array();
  26032. foreach($this->PageAnnots as $p=>$anno) {
  26033. if($p>=$start_page && $p<=$end_page) {
  26034. $np = $p + ($target_page - $start_page);
  26035. foreach($anno as $o) {
  26036. $newarr[$np][] = $o;
  26037. }
  26038. }
  26039. else if($p>=$target_page && $p<$start_page) {
  26040. $np = $p + $n_toc;
  26041. foreach($anno as $o) {
  26042. $newarr[$np][] = $o;
  26043. }
  26044. }
  26045. else {
  26046. $newarr[$p] = $this->PageAnnots[$p];
  26047. }
  26048. }
  26049. $this->PageAnnots = $newarr;
  26050. unset($newarr);
  26051. }
  26052. /*-- END ANNOTATIONS --*/
  26053. // Update PageNumSubstitutions
  26054. if (count($this->PageNumSubstitutions)) {
  26055. $newarr = array();
  26056. foreach($this->PageNumSubstitutions AS $k=>$v) {
  26057. if($this->PageNumSubstitutions[$k]['from']>=$start_page && $this->PageNumSubstitutions[$k]['from']<=$end_page) {
  26058. $this->PageNumSubstitutions[$k]['from'] += ($target_page - $start_page);
  26059. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  26060. }
  26061. else if($this->PageNumSubstitutions[$k]['from']>=$target_page && $this->PageNumSubstitutions[$k]['from']<$start_page) {
  26062. $this->PageNumSubstitutions[$k]['from'] += $n_toc;
  26063. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  26064. }
  26065. else {
  26066. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  26067. }
  26068. }
  26069. if (!$sp_present) {
  26070. $newarr[$target_page] = array('from'=>$target_page, 'suppress'=>$sp_suppress, 'reset'=>$sp_reset, 'type'=>$sp_type);
  26071. }
  26072. if (!$tp_present) {
  26073. $newarr[($target_page + $n_toc)] = array('from'=>($target_page+$n_toc), 'suppress'=>$tp_suppress, 'reset'=>$tp_reset, 'type'=>$tp_type);
  26074. }
  26075. if (!$ep_present && $end_page>count($this->pages)) {
  26076. $newarr[($end_page+1)] = array('from'=>($end_page+1), 'suppress'=>$ep_suppress, 'reset'=>$ep_reset, 'type'=>$ep_type);
  26077. }
  26078. ksort($newarr);
  26079. $this->PageNumSubstitutions = array();
  26080. foreach($newarr as $v) {
  26081. $this->PageNumSubstitutions[] = $v;
  26082. }
  26083. }
  26084. }
  26085. //======================================================
  26086. function DeletePages($start_page, $end_page=-1) {
  26087. // move a page/pages EARLIER in the document
  26088. if ($end_page<1) { $end_page = $start_page; }
  26089. $n_tod = $end_page - $start_page + 1;
  26090. $last_page = count($this->pages);
  26091. $n_atend = $last_page - $end_page + 1;
  26092. //move pages
  26093. for($i=0;$i<$n_atend;$i++) {
  26094. $this->pages[$start_page+$i]=$this->pages[$end_page+1+$i];
  26095. }
  26096. //delete pages
  26097. for($i = 0;$i < $n_tod ;$i++)
  26098. unset($this->pages[$last_page-$i]);
  26099. /*-- BOOKMARKS --*/
  26100. // Update Bookmarks
  26101. foreach($this->BMoutlines as $i=>$o) {
  26102. if($o['p']>=$end_page) { $this->BMoutlines[$i]['p'] -= $n_tod; }
  26103. else if($p<$start_page) { unset($this->BMoutlines[$i]); }
  26104. }
  26105. /*-- END BOOKMARKS --*/
  26106. // Update Page Links
  26107. if (count($this->PageLinks)) {
  26108. $newarr = array();
  26109. foreach($this->PageLinks as $i=>$o) {
  26110. foreach($this->PageLinks[$i] as $key => $pl) {
  26111. if (strpos($pl[4],'@')===0) {
  26112. $p=substr($pl[4],1);
  26113. if($p>$end_page) { $this->PageLinks[$i][$key][4] = '@'.($p - $n_tod); }
  26114. else if($p<$start_page) { unset($this->PageLinks[$i][$key]); }
  26115. }
  26116. }
  26117. if($i>$end_page) { $newarr[($i - $n_tod)] = $this->PageLinks[$i]; }
  26118. else if($p<$start_page) { $newarr[$i] = $this->PageLinks[$i]; }
  26119. }
  26120. $this->PageLinks = $newarr;
  26121. }
  26122. // OrientationChanges
  26123. if (count($this->OrientationChanges)) {
  26124. $newarr = array();
  26125. foreach($this->OrientationChanges AS $p=>$v) {
  26126. if($p>$end_page) { $newarr[($p - $t_tod)] = $this->OrientationChanges[$p]; }
  26127. else if($p<$start_page) { $newarr[$p] = $this->OrientationChanges[$p]; }
  26128. }
  26129. ksort($newarr);
  26130. $this->OrientationChanges = $newarr;
  26131. }
  26132. // Page Dimensions
  26133. if (count($this->pageDim)) {
  26134. $newarr = array();
  26135. foreach($this->pageDim AS $p=>$v) {
  26136. if($p>$end_page) { $newarr[($p - $n_tod)] = $this->pageDim[$p]; }
  26137. else if($p<$start_page) { $newarr[$p] = $this->pageDim[$p]; }
  26138. }
  26139. ksort($newarr);
  26140. $this->pageDim = $newarr;
  26141. }
  26142. // HTML Headers & Footers
  26143. if (count($this->saveHTMLHeader)) {
  26144. foreach($this->saveHTMLHeader AS $p=>$v) {
  26145. if($p>end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLHeader[$p]; }
  26146. else if($p<$start_page) { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  26147. }
  26148. ksort($newarr);
  26149. $this->saveHTMLHeader = $newarr;
  26150. }
  26151. if (count($this->saveHTMLFooter)) {
  26152. $newarr = array();
  26153. foreach($this->saveHTMLFooter AS $p=>$v) {
  26154. if($p>$end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLFooter[$p]; }
  26155. else if($p<$start_page) { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  26156. }
  26157. ksort($newarr);
  26158. $this->saveHTMLFooter = $newarr;
  26159. }
  26160. // Update Internal Links
  26161. foreach($this->internallink as $key=>$o) {
  26162. if($o['PAGE']>$end_page) { $this->internallink[$key]['PAGE'] -= $n_tod; }
  26163. else if($o['PAGE']<$start_page) { unset($this->internallink[$key]); }
  26164. }
  26165. // Update Links
  26166. foreach($this->links as $key=>$o) {
  26167. if($o[0]>$end_page) { $this->links[$key][0] -= $n_tod; }
  26168. else if($o[0]<$start_page) { unset($this->links[$key]); }
  26169. }
  26170. // Update Form fields
  26171. foreach($this->form->forms as $key=>$f) {
  26172. if($f['page']>$end_page) { $this->form->forms[$key]['page'] -= $n_tod; }
  26173. else if($f['page']<$start_page) { unset($this->form->forms[$key]); }
  26174. }
  26175. /*-- ANNOTATIONS --*/
  26176. // Update Annotations
  26177. if (count($this->PageAnnots)) {
  26178. $newarr = array();
  26179. foreach($this->PageAnnots as $p=>$anno) {
  26180. if($p>$end_page) { foreach($anno as $o) { $newarr[($p - $n_tod)][] = $o; } }
  26181. else if($p<$start_page) { $newarr[$p] = $this->PageAnnots[$p]; }
  26182. }
  26183. ksort($newarr);
  26184. $this->PageAnnots = $newarr;
  26185. }
  26186. /*-- END ANNOTATIONS --*/
  26187. // Update PageNumSubstitutions
  26188. foreach($this->PageNumSubstitutions AS $k=>$v) {
  26189. if($this->PageNumSubstitutions[$k]['from']>$end_page) { $this->PageNumSubstitutions[$k]['from'] -= $n_tod; }
  26190. else if($this->PageNumSubstitutions[$k]['from']<$start_page) { unset($this->PageNumSubstitutions[$k]); }
  26191. }
  26192. unset($newarr);
  26193. $this->page = count($this->pages);
  26194. }
  26195. //======================================================
  26196. /*-- INDEX --*/
  26197. // FROM class PDF_Ref == INDEX
  26198. function Reference($txt) {
  26199. $this->IndexEntry($txt);
  26200. }
  26201. function IndexEntry($txt, $xref='') {
  26202. if ($xref) {
  26203. $this->IndexEntrySee($txt,$xref);
  26204. return;
  26205. }
  26206. $txt = strip_tags($txt);
  26207. $txt = $this->purify_utf8_text($txt);
  26208. if ($this->text_input_as_HTML) {
  26209. $txt = $this->all_entities_to_utf8($txt);
  26210. }
  26211. if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  26212. $Present=0;
  26213. $size=sizeof($this->Reference);
  26214. if ($this->directionality == 'rtl') { // *RTL*
  26215. $txt = str_replace(':',' - ',$txt); // *RTL*
  26216. } // *RTL*
  26217. else { // *RTL*
  26218. $txt = str_replace(':',', ',$txt);
  26219. } // *RTL*
  26220. //Search the reference (AND Ref/PageNo) in the array
  26221. for ($i=0;$i<$size;$i++){
  26222. if ($this->keep_block_together) {
  26223. if (isset($this->ktReference[$i]['t']) && $this->ktReference[$i]['t']==$txt){
  26224. $Present=1;
  26225. if (!in_array($this->page,$this->ktReference[$i]['p'])) {
  26226. $this->ktReference[$i]['op'] = $this->page;
  26227. }
  26228. }
  26229. }
  26230. /*-- TABLES --*/
  26231. else if ($this->table_rotate) {
  26232. if (isset($this->tbrot_Reference[$i]['t']) && $this->tbrot_Reference[$i]['t']==$txt){
  26233. $Present=1;
  26234. if (!in_array($this->page,$this->tbrot_Reference[$i]['p'])) {
  26235. $this->tbrot_Reference[$i]['op'] = $this->page;
  26236. }
  26237. }
  26238. }
  26239. else if ($this->kwt) {
  26240. if (isset($this->kwt_Reference[$i]['t']) && $this->kwt_Reference[$i]['t']==$txt){
  26241. $Present=1;
  26242. if (!in_array($this->page,$this->kwt_Reference[$i]['p'])) {
  26243. $this->kwt_Reference[$i]['op'] = $this->page;
  26244. }
  26245. }
  26246. }
  26247. /*-- END TABLES --*/
  26248. /*-- COLUMNS --*/
  26249. else if ($this->ColActive) {
  26250. if (isset($this->col_Reference[$i]['t']) && $this->col_Reference[$i]['t']==$txt){
  26251. $Present=1;
  26252. if (!in_array($this->page,$this->col_Reference[$i]['p'])) {
  26253. $this->col_Reference[$i]['op'] = $this->page;
  26254. }
  26255. }
  26256. }
  26257. /*-- END COLUMNS --*/
  26258. else {
  26259. if (isset($this->Reference[$i]['t']) && $this->Reference[$i]['t']==$txt){
  26260. $Present=1;
  26261. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  26262. $this->Reference[$i]['p'][] = $this->page;
  26263. }
  26264. }
  26265. }
  26266. }
  26267. //If not found, add it
  26268. if ($Present==0) {
  26269. $opr = array('t'=>$txt, 'op'=>$this->page);
  26270. if ($this->keep_block_together) {
  26271. $this->ktReference[]= $opr;
  26272. }
  26273. /*-- TABLES --*/
  26274. else if ($this->table_rotate) {
  26275. $this->tbrot_Reference[]= $opr;
  26276. }
  26277. else if ($this->kwt) {
  26278. $this->kwt_Reference[]= $opr;
  26279. }
  26280. /*-- END TABLES --*/
  26281. /*-- COLUMNS --*/
  26282. else if ($this->ColActive) {
  26283. $this->col_Reference[]= $opr;
  26284. }
  26285. /*-- END COLUMNS --*/
  26286. else {
  26287. $this->Reference[]=array('t'=>$txt,'p'=>array($this->page));
  26288. }
  26289. }
  26290. }
  26291. // Added function to add a reference "Elephants. See Chickens"
  26292. function ReferenceSee($txta,$txtb) {
  26293. $this->IndexEntrySee($txta,$txtb);
  26294. }
  26295. function IndexEntrySee($txta,$txtb) {
  26296. $txta = strip_tags($txta);
  26297. $txtb = strip_tags($txtb);
  26298. $txta = $this->purify_utf8_text($txta);
  26299. $txtb = $this->purify_utf8_text($txtb);
  26300. if ($this->text_input_as_HTML) {
  26301. $txta = $this->all_entities_to_utf8($txta);
  26302. $txtb = $this->all_entities_to_utf8($txtb);
  26303. }
  26304. if ($this->usingCoreFont) {
  26305. $txta = mb_convert_encoding($txta,$this->mb_enc,'UTF-8');
  26306. $txtb = mb_convert_encoding($txtb,$this->mb_enc,'UTF-8');
  26307. }
  26308. if ($this->directionality == 'rtl') { // *RTL*
  26309. $txta = str_replace(':',' - ',$txta); // *RTL*
  26310. $txtb = str_replace(':',' - ',$txtb); // *RTL*
  26311. } // *RTL*
  26312. else { // *RTL*
  26313. $txta = str_replace(':',', ',$txta);
  26314. $txtb = str_replace(':',', ',$txtb);
  26315. } // *RTL*
  26316. $this->Reference[]=array('t'=>$txta.' - see '.$txtb,'p'=>array());
  26317. }
  26318. function CreateReference($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  26319. $this->CreateIndex($NbCol, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont, $divlettfont, $useLinking);
  26320. }
  26321. function CreateIndex($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  26322. if (!$reffontsize) { $reffontsize = $this->default_font_size; }
  26323. if (!$divlettfontsize) { $divlettfontsize = ($this->default_font_size * 1.8); }
  26324. if (!$reffont) { $reffont = $this->default_font; }
  26325. if (!$divlettfont) { $divlettfont = $reffont; }
  26326. if (!$linespacing) { $linespacing= $this->default_lineheight_correction; }
  26327. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  26328. $size=sizeof($this->Reference);
  26329. if ($size == 0) { return false; }
  26330. if ($NbCol<2) {
  26331. $NbCol = 1;
  26332. $colWidth = $this->pgwidth;
  26333. }
  26334. else {
  26335. $this->SetColumns($NbCol,'',$gap);
  26336. $colWidth = $this->ColWidth;
  26337. }
  26338. if ($this->directionality == 'rtl') { $align = 'R'; }
  26339. else { $align = 'L'; }
  26340. $lett = '';
  26341. if (!function_exists('cmp')) {
  26342. function cmp ($a, $b) {
  26343. return strnatcmp(strtolower($a['t']), strtolower($b['t']));
  26344. }
  26345. }
  26346. //Alphabetic sort of the references
  26347. usort($this->Reference, 'cmp');
  26348. $size=sizeof($this->Reference);
  26349. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26350. $divlettjuststarted = false;
  26351. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  26352. $last_lett = '';
  26353. for ($i=0;$i<$size;$i++){
  26354. if ($this->Reference[$i]['t']) {
  26355. if ($usedivletters) {
  26356. $lett = mb_strtoupper(mb_substr($this->Reference[$i]['t'],0,1,$this->mb_enc ),$this->mb_enc );
  26357. if ($lett != $last_lett) {
  26358. $save_bp = $this->breakpoints[$this->CurrCol]; // *COLUMNS*
  26359. $divlettjuststarted = true;
  26360. if ($i>0) {
  26361. $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; '));
  26362. }
  26363. else {
  26364. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; '));
  26365. }
  26366. $this->_saveTextBuffer($lett);
  26367. $this->CloseTag('DIV');
  26368. }
  26369. }
  26370. $this->OpenTag('DIV',array('STYLE'=>'text-indent: -'.$offset.'mm; line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  26371. /*-- RTL --*/
  26372. // Change Arabic + Persian. to Presentation Forms
  26373. if ($this->biDirectional) {
  26374. $this->Reference[$i]['t'] = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $this->Reference[$i]['t'] );
  26375. }
  26376. /*-- END RTL --*/
  26377. // Font-specific ligature substitution for Indic fonts
  26378. if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($this->Reference[$i]['t']); // *INDIC*
  26379. $this->_saveTextBuffer($this->Reference[$i]['t']);
  26380. $ppp = $this->Reference[$i]['p']; // = array of page numbers to point to
  26381. if (count($ppp)) {
  26382. sort($ppp);
  26383. $newarr = array();
  26384. $range_start = $ppp[0];
  26385. $range_end = 0;
  26386. if (!$this->usingCoreFont) { $spacer = "\xc2\xa0 "; }
  26387. else { $spacer = chr(160).' '; }
  26388. $this->_saveTextBuffer($spacer);
  26389. if ($this->directionality == 'rtl') { $sep = '.'; $joiner = '-'; }
  26390. else { $sep = ', '; $joiner = '-'; }
  26391. for ($zi=1;$zi<count($ppp);$zi++) {
  26392. // RTL - Each number separately
  26393. if ($this->directionality == 'rtl') {
  26394. /*-- RTL --*/
  26395. if ($zi<count($ppp)-1) {
  26396. $txt = $sep . $this->docPageNum($ppp[$zi]);
  26397. if ($useLinking) { $href = '@'.$ppp[$zi]; }
  26398. else { $href = ''; }
  26399. $this->_saveTextBuffer($txt, $href);
  26400. }
  26401. /*-- END RTL --*/
  26402. }
  26403. else if ($ppp[$zi] == ($ppp[($zi-1)]+1)) {
  26404. $range_end = $ppp[$zi];
  26405. }
  26406. else {
  26407. if ($range_end) {
  26408. if ($range_end == $range_start+1) {
  26409. if ($useLinking) { $href = '@'.$range_start; }
  26410. else { $href = ''; }
  26411. $txt = $this->docPageNum($range_start) . $sep;
  26412. $this->_saveTextBuffer($txt, $href);
  26413. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  26414. else { $href = ''; }
  26415. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  26416. $this->_saveTextBuffer($txt, $href);
  26417. }
  26418. else {
  26419. if ($useLinking) { $href = '@'.$range_start; }
  26420. else { $href = ''; }
  26421. }
  26422. }
  26423. else {
  26424. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  26425. else { $href = ''; }
  26426. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  26427. $this->_saveTextBuffer($txt, $href);
  26428. }
  26429. $range_start = $ppp[$zi];
  26430. $range_end = 0;
  26431. }
  26432. }
  26433. if ($range_end) {
  26434. if ($range_end == $range_start+1) {
  26435. if ($useLinking) { $href = '@'.$range_start; }
  26436. else { $href = ''; }
  26437. $txt = $this->docPageNum($range_start) . $sep;
  26438. $this->_saveTextBuffer($txt, $href);
  26439. if ($useLinking) { $href = '@'.$range_end; }
  26440. else { $href = ''; }
  26441. $txt = $this->docPageNum($range_end);
  26442. $this->_saveTextBuffer($txt, $href);
  26443. }
  26444. else {
  26445. if ($useLinking) { $href = '@'.$range_start; }
  26446. else { $href = ''; }
  26447. $txt = $this->docPageNum($range_start) . $joiner;
  26448. $this->_saveTextBuffer($txt, $href);
  26449. if ($useLinking) { $href = '@'.$range_end; }
  26450. else { $href = ''; }
  26451. $txt = $this->docPageNum($range_end);
  26452. $this->_saveTextBuffer($txt, $href);
  26453. }
  26454. }
  26455. else {
  26456. if ($useLinking) { $href = '@'.$ppp[(count($ppp)-1)]; }
  26457. else { $href = ''; }
  26458. $txt = $this->docPageNum($ppp[(count($ppp)-1)]);
  26459. $this->_saveTextBuffer($txt, $href);
  26460. }
  26461. }
  26462. }
  26463. $this->CloseTag('DIV');
  26464. if ($divlettjuststarted) { $this->breakpoints[$this->CurrCol] = $save_bp; } // *COLUMNS*
  26465. $divlettjuststarted = false;
  26466. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26467. $last_lett = $lett;
  26468. }
  26469. $this->CloseTag('DIV');
  26470. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  26471. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  26472. }
  26473. /*-- END INDEX --*/
  26474. function AcceptPageBreak() {
  26475. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  26476. /*-- COLUMNS --*/
  26477. if ($this->ColActive==1) {
  26478. if($this->CurrCol<$this->NbCol-1) {
  26479. //Go to the next column
  26480. $this->CurrCol++;
  26481. $this->SetCol($this->CurrCol);
  26482. $this->y=$this->y0;
  26483. $this->ChangeColumn=1; // Number (and direction) of columns changed +1, +2, -2 etc.
  26484. // DIRECTIONALITY RTL
  26485. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26486. //Stay on the page
  26487. return false;
  26488. }
  26489. else {
  26490. //Go back to the first column - NEW PAGE
  26491. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26492. $this->SetCol(0);
  26493. $this->y0 = $this->tMargin;
  26494. $this->ChangeColumn= -($this->NbCol-1);
  26495. // DIRECTIONALITY RTL
  26496. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26497. //Page break
  26498. return true;
  26499. }
  26500. }
  26501. /*-- END COLUMNS --*/
  26502. /*-- TABLES --*/
  26503. else if ($this->table_rotate) {
  26504. if ($this->tablebuffer) { $this->printtablebuffer(); }
  26505. return true;
  26506. }
  26507. /*-- END TABLES --*/
  26508. else { // *COLUMNS*
  26509. $this->ChangeColumn=0;
  26510. return $this->autoPageBreak;
  26511. } // *COLUMNS*
  26512. return $this->autoPageBreak;
  26513. }
  26514. //----------- COLUMNS ---------------------
  26515. /*-- COLUMNS --*/
  26516. function SetColumns($NbCol,$vAlign='',$gap=5) {
  26517. // NbCol = number of columns
  26518. // CurrCol = Number of the current column starting at 0
  26519. // Called externally to set columns on/off and number
  26520. // Integer 2 upwards sets columns on to that number
  26521. // Anything less than 2 turns columns off
  26522. if ($NbCol<2) { // SET COLUMNS OFF
  26523. if ($this->ColActive) {
  26524. $this->ColActive=0;
  26525. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26526. $this->NbCol=1;
  26527. $this->ResetMargins();
  26528. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  26529. $this->divwidth = 0;
  26530. $this->Ln();
  26531. }
  26532. $this->ColActive=0;
  26533. $this->columnbuffer = array();
  26534. $this->ColDetails = array();
  26535. $this->columnLinks = array();
  26536. $this->columnAnnots = array();
  26537. $this->columnForms = array();
  26538. $this->col_Reference = array();
  26539. $this->col_BMoutlines = array();
  26540. $this->col_toc = array();
  26541. $this->breakpoints = array();
  26542. }
  26543. else { // SET COLUMNS ON
  26544. if ($this->ColActive) {
  26545. $this->ColActive=0;
  26546. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26547. $this->ResetMargins();
  26548. }
  26549. if (isset($this->y) && $this->y>$this->tMargin) $this->Ln();
  26550. $this->NbCol=$NbCol;
  26551. $this->ColGap = $gap;
  26552. $this->divwidth = 0;
  26553. $this->ColActive=1;
  26554. $this->ColumnAdjust = true; // enables column height adjustment for the page
  26555. $this->columnbuffer = array();
  26556. $this->ColDetails = array();
  26557. $this->columnLinks = array();
  26558. $this->columnAnnots = array();
  26559. $this->columnForms = array();
  26560. $this->col_Reference = array();
  26561. $this->col_BMoutlines = array();
  26562. $this->col_toc = array();
  26563. $this->breakpoints = array();
  26564. if ((strtoupper($vAlign) == 'J') || (strtoupper($vAlign) == 'JUSTIFY')) { $vAlign = 'J'; }
  26565. else { $vAlign = ''; }
  26566. $this->colvAlign = $vAlign;
  26567. //Save the ordinate
  26568. $absL = $this->DeflMargin-($gap/2);
  26569. $absR = $this->DefrMargin-($gap/2);
  26570. $PageWidth = $this->w-$absL-$absR; // virtual pagewidth for calculation only
  26571. $ColWidth = (($PageWidth - ($gap * ($NbCol)))/$NbCol);
  26572. $this->ColWidth = $ColWidth;
  26573. /*-- RTL --*/
  26574. if ($this->directionality == 'rtl') {
  26575. for ($i=0;$i<$this->NbCol;$i++) {
  26576. $this->ColL[$i] = $absL + ($gap/2) + (($NbCol - ($i+1))*($PageWidth/$NbCol)) ;
  26577. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  26578. }
  26579. }
  26580. else {
  26581. /*-- END RTL --*/
  26582. for ($i=0;$i<$this->NbCol;$i++) {
  26583. $this->ColL[$i] = $absL + ($gap/2) + ($i* ($PageWidth/$NbCol) );
  26584. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  26585. }
  26586. } // *RTL*
  26587. $this->pgwidth = $ColWidth;
  26588. $this->SetCol(0);
  26589. $this->y0=$this->y;
  26590. }
  26591. $this->x = $this->lMargin;
  26592. }
  26593. function SetCol($CurrCol) {
  26594. // Used internally to set column by number: 0 is 1st column
  26595. //Set position on a column
  26596. $this->CurrCol=$CurrCol;
  26597. $x = $this->ColL[$CurrCol];
  26598. $xR = $this->ColR[$CurrCol]; // NB This is not R margin -> R pos
  26599. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  26600. $x += $this->MarginCorrection ;
  26601. $xR += $this->MarginCorrection ;
  26602. }
  26603. $this->SetMargins($x,($this->w - $xR),$this->tMargin);
  26604. }
  26605. function AddColumn() {
  26606. $this->NewColumn();
  26607. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  26608. }
  26609. function NewColumn() {
  26610. if ($this->ColActive==1) {
  26611. if($this->CurrCol<$this->NbCol-1) {
  26612. //Go to the next column
  26613. $this->CurrCol++;
  26614. $this->SetCol($this->CurrCol);
  26615. $this->y = $this->y0;
  26616. $this->ChangeColumn=1;
  26617. // DIRECTIONALITY RTL
  26618. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26619. //Stay on the page
  26620. }
  26621. else {
  26622. //Go back to the first column
  26623. //Page break
  26624. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  26625. $this->AddPage($this->CurOrientation);
  26626. $this->SetCol(0);
  26627. $this->y0 = $this->tMargin;
  26628. $this->ChangeColumn= -($this->NbCol-1);
  26629. // DIRECTIONALITY RTL
  26630. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  26631. }
  26632. $this->x = $this->lMargin;
  26633. }
  26634. else {
  26635. $this->AddPage($this->CurOrientation);
  26636. }
  26637. }
  26638. function printcolumnbuffer() {
  26639. // Columns ended (but page not ended) -> try to match all columns - unless disabled by using a custom column-break
  26640. if (!$this->ColActive && $this->ColumnAdjust && !$this->keepColumns) {
  26641. // Calculate adjustment to add to each column to calculate rel_y value
  26642. $this->ColDetails[0]['add_y'] = 0;
  26643. $last_col = 0;
  26644. // Recursively add previous column's height
  26645. for($i=1;$i<$this->NbCol;$i++) {
  26646. if (isset($this->ColDetails[$i]['bottom_margin']) && $this->ColDetails[$i]['bottom_margin']) { // If any entries in the column
  26647. $this->ColDetails[$i]['add_y'] = ($this->ColDetails[$i-1]['bottom_margin'] - $this->y0) + $this->ColDetails[$i-1]['add_y'];
  26648. $last_col = $i; // Last column actually printed
  26649. }
  26650. }
  26651. // Calculate value for each position sensitive entry as though for one column
  26652. foreach($this->columnbuffer AS $key=>$s) {
  26653. $t = $s['s'];
  26654. if ($t == 'ACROFORM') {
  26655. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26656. $this->columnbuffer[$key]['s'] = '';
  26657. }
  26658. else if (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) {
  26659. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26660. }
  26661. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) {
  26662. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26663. }
  26664. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) {
  26665. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26666. }
  26667. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) {
  26668. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26669. }
  26670. 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)) {
  26671. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26672. }
  26673. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) {
  26674. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  26675. }
  26676. }
  26677. foreach($this->internallink AS $key => $f) {
  26678. if (is_array($f) && isset($f['col'])) {
  26679. $this->internallink[$key]['rel_y'] = $f['Y'] + $this->ColDetails[$f['col']]['add_y'] - $this->y0;
  26680. }
  26681. }
  26682. $breaks = array();
  26683. foreach($this->breakpoints AS $c => $bpa) {
  26684. foreach($bpa AS $rely) {
  26685. $breaks[] = $rely + $this->ColDetails[$c]['add_y'] - $this->y0;
  26686. }
  26687. }
  26688. if (isset($this->ColDetails[$last_col]['bottom_margin'])) { $lcbm = $this->ColDetails[$last_col]['bottom_margin']; }
  26689. else { $lcbm = 0; }
  26690. $sum_h = $this->ColDetails[$last_col]['add_y'] + $lcbm - $this->y0;
  26691. //$sum_h = max($this->ColDetails[$last_col]['add_y'] + $this->ColDetails[$last_col]['bottom_margin'] - $this->y0, end($breaks));
  26692. $target_h = ($sum_h / $this->NbCol);
  26693. $cbr = array();
  26694. for($i=1;$i<$this->NbCol;$i++) {
  26695. $th = ($sum_h * $i / $this->NbCol);
  26696. foreach($breaks AS $bk=>$val) {
  26697. if ($val > $th) {
  26698. if (($val-$th) < ($th-$breaks[$bk-1])) { $cbr[$i-1] = $val; }
  26699. else { $cbr[$i-1] = $breaks[$bk-1]; }
  26700. break;
  26701. }
  26702. }
  26703. }
  26704. $cbr[($this->NbCol-1)] = $sum_h;
  26705. // Now update the columns - divide into columns of approximately equal value
  26706. $last_new_col = 0;
  26707. $yadj = 0; // mm
  26708. $xadj = 0;
  26709. $last_col_bottom = 0;
  26710. $lowest_bottom_y = 0;
  26711. $block_bottom = 0;
  26712. $newcolumn = 0;
  26713. foreach($this->columnbuffer AS $key=>$s) {
  26714. if (isset($s['rel_y'])) { // only process position sensitive data
  26715. if ($s['rel_y'] >= $cbr[$newcolumn]) {
  26716. $newcolumn++;
  26717. }
  26718. else {
  26719. $newcolumn = $last_new_col ;
  26720. }
  26721. $block_bottom = max($block_bottom,($s['rel_y']+$s['h']));
  26722. if ($this->directionality == 'rtl') { // *RTL*
  26723. $xadj = -(($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap)); // *RTL*
  26724. } // *RTL*
  26725. else { // *RTL*
  26726. $xadj = ($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap);
  26727. } // *RTL*
  26728. if ($last_new_col != $newcolumn) { // Added new column
  26729. $last_col_bottom = $this->columnbuffer[$key]['rel_y'];
  26730. $block_bottom = 0;
  26731. }
  26732. $yadj = ($s['rel_y'] - $s['y']) - ($last_col_bottom)+$this->y0;
  26733. // callback function in htmltoolkit
  26734. $t = $s['s'];
  26735. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->columnAdjustAdd('Td',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26736. $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);
  26737. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->columnAdjustAdd('l',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26738. $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);
  26739. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->columnAdjustAdd('draw',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t);
  26740. $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);
  26741. $this->columnbuffer[$key]['s'] = $t;
  26742. $this->columnbuffer[$key]['newcol'] = $newcolumn;
  26743. $this->columnbuffer[$key]['newy'] = $s['y'] + $yadj;
  26744. $last_new_col = $newcolumn;
  26745. $clb = $s['y'] + $yadj + $s['h'] ; // bottom_margin of current
  26746. 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; }
  26747. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26748. // Adjust LINKS
  26749. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26750. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26751. $this->PageLinks[$this->page][$ref][0] += ($xadj*_MPDFK);
  26752. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK);
  26753. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26754. }
  26755. // Adjust FORM FIELDS
  26756. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26757. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26758. $this->form->forms[$ref]['x'] += ($xadj);
  26759. $this->form->forms[$ref]['y'] += ($yadj);
  26760. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26761. }
  26762. /*-- ANNOTATIONS --*/
  26763. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26764. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26765. if ($this->PageAnnots[$this->page][$ref]['x'] < 0) {
  26766. $this->PageAnnots[$this->page][$ref]['x'] -= ($xadj);
  26767. }
  26768. else {
  26769. $this->PageAnnots[$this->page][$ref]['x'] += ($xadj);
  26770. }
  26771. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); // unlike PageLinks, Page annots has y values from top in mm
  26772. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26773. }
  26774. /*-- END ANNOTATIONS --*/
  26775. }
  26776. }
  26777. /*-- BOOKMARKS --*/
  26778. // Adjust Bookmarks
  26779. foreach($this->col_BMoutlines AS $v) {
  26780. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26781. }
  26782. /*-- END BOOKMARKS --*/
  26783. /*-- INDEX --*/
  26784. // Adjust Reference (index)
  26785. foreach($this->col_Reference AS $v) {
  26786. $Present=0;
  26787. //Search the reference (AND Ref/PageNo) in the array
  26788. for ($i=0;$i<count($this->Reference);$i++){
  26789. if ($this->Reference[$i]['t']==$v['t']){
  26790. $Present=1;
  26791. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26792. $this->Reference[$i]['p'][] = $v['op'];
  26793. }
  26794. }
  26795. }
  26796. if ($Present==0) {
  26797. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26798. }
  26799. }
  26800. /*-- END INDEX --*/
  26801. /*-- TOC --*/
  26802. // Adjust ToC
  26803. foreach($this->col_toc AS $v) {
  26804. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26805. $this->links[$v['link']][1] = $this->y0;
  26806. }
  26807. /*-- END TOC --*/
  26808. // Adjust column length to be equal
  26809. if ($this->colvAlign == 'J') {
  26810. foreach($this->columnbuffer AS $key=>$s) {
  26811. if (isset($s['rel_y'])) { // only process position sensitive data
  26812. // Set ratio to expand y values or heights
  26813. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) {
  26814. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26815. }
  26816. else { $ratio = 1; }
  26817. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26818. $yadj = ($s['newy'] - $this->y0) * ($ratio - 1);
  26819. // Adjust LINKS
  26820. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26821. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26822. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value
  26823. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26824. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26825. }
  26826. // Adjust FORM FIELDS
  26827. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26828. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26829. $this->form->forms[$ref]['x'] += ($xadj);
  26830. $this->form->forms[$ref]['y'] += ($yadj);
  26831. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26832. }
  26833. /*-- ANNOTATIONS --*/
  26834. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26835. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26836. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26837. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26838. }
  26839. /*-- END ANNOTATIONS --*/
  26840. }
  26841. }
  26842. }
  26843. foreach($this->internallink AS $key => $f) {
  26844. if (is_array($f) && isset($f['col'])) {
  26845. $last_col_bottom = 0;
  26846. for ($nbc=0; $nbc<$this->NbCol; $nbc++) {
  26847. if ($f['rel_y'] >= $cbr[$nbc]) { $last_col_bottom = $cbr[$nbc]; }
  26848. }
  26849. $yadj = ($f['rel_y'] - $f['Y']) - $last_col_bottom + $this->y0;
  26850. $f['Y'] += $yadj;
  26851. unset($f['col']);
  26852. unset($f['rel_y']);
  26853. $this->internallink[$key] = $f;
  26854. }
  26855. }
  26856. $last_col = -1;
  26857. $trans_on = false;
  26858. foreach($this->columnbuffer AS $key=>$s) {
  26859. if (isset($s['rel_y'])) { // only process position sensitive data
  26860. // Set ratio to expand y values or heights
  26861. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) {
  26862. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  26863. }
  26864. else { $ratio = 1; }
  26865. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26866. //Start Transformation
  26867. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26868. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26869. $trans_on = true;
  26870. }
  26871. }
  26872. // Now output the adjusted values
  26873. $this->pages[$this->page] .= $s['s']."\n";
  26874. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) { // only process position sensitive data
  26875. //Stop Transformation
  26876. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26877. $trans_on = false;
  26878. }
  26879. }
  26880. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; }
  26881. }
  26882. else { // if NOT $this->colvAlign == 'J'
  26883. // Now output the adjusted values
  26884. foreach($this->columnbuffer AS $s) {
  26885. $this->pages[$this->page] .= $s['s']."\n";
  26886. }
  26887. }
  26888. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  26889. }
  26890. // Columns not ended but new page -> align columns (can leave the columns alone - just tidy up the height)
  26891. else if ($this->colvAlign == 'J' && $this->ColumnAdjust && !$this->keepColumns) {
  26892. // calculate the lowest bottom margin
  26893. $lowest_bottom_y = 0;
  26894. foreach($this->columnbuffer AS $key=>$s) {
  26895. // Only process output data
  26896. $t = $s['s'];
  26897. 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)) ||
  26898. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  26899. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  26900. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  26901. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  26902. $clb = $s['y'] + $s['h'];
  26903. 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; }
  26904. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  26905. $this->columnbuffer[$key]['rel_y'] = $s['y']; // Marks position sensitive data to process later
  26906. if ($t == 'ACROFORM') { $this->columnbuffer[$key]['s'] = ''; }
  26907. }
  26908. }
  26909. // Adjust column length equal
  26910. foreach($this->columnbuffer AS $key=>$s) {
  26911. // Set ratio to expand y values or heights
  26912. if (isset($this->ColDetails[$s['col']]['max_bottom']) && $this->ColDetails[$s['col']]['max_bottom']) {
  26913. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26914. }
  26915. else { $ratio = 1; }
  26916. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26917. $yadj = ($s['y'] - $this->y0) * ($ratio - 1);
  26918. // Adjust LINKS
  26919. if (isset($s['rel_y'])) { // only process position sensitive data
  26920. // otherwise triggers for all entries in column buffer (.e.g. formatting) and makes below adjustments more than once
  26921. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26922. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26923. $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value
  26924. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  26925. unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26926. }
  26927. // Adjust FORM FIELDS
  26928. if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26929. $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26930. $this->form->forms[$ref]['x'] += ($xadj);
  26931. $this->form->forms[$ref]['y'] += ($yadj);
  26932. unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26933. }
  26934. /*-- ANNOTATIONS --*/
  26935. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  26936. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  26937. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  26938. unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
  26939. }
  26940. /*-- END ANNOTATIONS --*/
  26941. }
  26942. }
  26943. }
  26944. /*-- BOOKMARKS --*/
  26945. // Adjust Bookmarks
  26946. foreach($this->col_BMoutlines AS $v) {
  26947. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  26948. }
  26949. /*-- END BOOKMARKS --*/
  26950. /*-- INDEX --*/
  26951. // Adjust Reference (index)
  26952. foreach($this->col_Reference AS $v) {
  26953. $Present=0;
  26954. //Search the reference (AND Ref/PageNo) in the array
  26955. for ($i=0;$i<count($this->Reference);$i++){
  26956. if ($this->Reference[$i]['t']==$v['t']){
  26957. $Present=1;
  26958. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  26959. $this->Reference[$i]['p'][] = $v['op'];
  26960. }
  26961. }
  26962. }
  26963. if ($Present==0) {
  26964. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  26965. }
  26966. }
  26967. /*-- END INDEX --*/
  26968. /*-- TOC --*/
  26969. // Adjust ToC
  26970. foreach($this->col_toc AS $v) {
  26971. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  26972. $this->links[$v['link']][1] = $this->y0;
  26973. }
  26974. /*-- END TOC --*/
  26975. $trans_on = false;
  26976. foreach($this->columnbuffer AS $key=>$s) {
  26977. if (isset($s['rel_y'])) { // only process position sensitive data
  26978. // Set ratio to expand y values or heights
  26979. if ($this->ColDetails[$s['col']]['max_bottom']) {
  26980. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  26981. }
  26982. else { $ratio = 1; }
  26983. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26984. //Start Transformation
  26985. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  26986. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  26987. $trans_on = true;
  26988. }
  26989. }
  26990. // Now output the adjusted values
  26991. $this->pages[$this->page] .= $s['s']."\n";
  26992. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  26993. //Stop Transformation
  26994. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  26995. $trans_on = false; // mPDF 5.1.001
  26996. }
  26997. }
  26998. if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; }
  26999. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  27000. }
  27001. // Just reproduce the page as it was
  27002. else {
  27003. // If page has not ended but height adjustment was disabled by custom column-break - adjust y
  27004. $lowest_bottom_y = 0;
  27005. if (!$this->ColActive && (!$this->ColumnAdjust || $this->keepColumns)) {
  27006. // calculate the lowest bottom margin
  27007. foreach($this->columnbuffer AS $key=>$s) {
  27008. // Only process output data
  27009. $t = $s['s'];
  27010. 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)) ||
  27011. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  27012. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  27013. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  27014. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) {
  27015. $clb = $s['y'] + $s['h'];
  27016. if ($clb > $this->ColDetails[$s['col']]['max_bottom']) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; }
  27017. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  27018. }
  27019. }
  27020. }
  27021. foreach($this->columnbuffer AS $key=>$s) {
  27022. if ($s['s'] != 'ACROFORM')
  27023. $this->pages[$this->page] .= $s['s']."\n";
  27024. }
  27025. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  27026. /*-- INDEX --*/
  27027. // Output Reference (index)
  27028. foreach($this->col_Reference AS $v) {
  27029. $Present=0;
  27030. for ($i=0;$i<count($this->Reference);$i++){
  27031. if ($this->Reference[$i]['t']==$v['t']){
  27032. $Present=1;
  27033. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  27034. $this->Reference[$i]['p'][] = $v['op'];
  27035. }
  27036. }
  27037. }
  27038. if ($Present==0) {
  27039. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  27040. }
  27041. }
  27042. /*-- END INDEX --*/
  27043. /*-- BOOKMARKS --*/
  27044. // Output Bookmarks
  27045. foreach($this->col_BMoutlines AS $v) {
  27046. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  27047. }
  27048. /*-- END BOOKMARKS --*/
  27049. /*-- TOC --*/
  27050. // Output ToC
  27051. foreach($this->col_toc AS $v) {
  27052. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27053. }
  27054. /*-- END TOC --*/
  27055. }
  27056. foreach($this->internallink AS $key => $f) {
  27057. if (isset($this->internallink[$key]['col'])) unset($this->internallink[$key]['col']);
  27058. if (isset($this->internallink[$key]['rel_y'])) unset($this->internallink[$key]['rel_y']);
  27059. }
  27060. $this->columnbuffer = array();
  27061. $this->ColDetails = array();
  27062. $this->columnLinks = array();
  27063. $this->columnAnnots = array();
  27064. $this->columnForms = array();
  27065. $this->col_Reference = array();
  27066. $this->col_BMoutlines = array();
  27067. $this->col_toc = array();
  27068. $this->breakpoints = array();
  27069. }
  27070. /*-- END COLUMNS --*/
  27071. //==================================================================
  27072. /*-- TABLES --*/
  27073. function printcellbuffer() {
  27074. if (count($this->cellBorderBuffer )) {
  27075. sort($this->cellBorderBuffer);
  27076. foreach($this->cellBorderBuffer AS $cbb) {
  27077. $cba = unpack("A16dom/nbord/A1side/ns/dbw/a6ca/A10style/dx/dy/dw/dh/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd/dover/", $cbb);
  27078. $side = $cba['side'];
  27079. $details = array();
  27080. $details[$side]['dom'] = (float) $cba['dom'];
  27081. $details[$side]['s'] = $cba['s'];
  27082. $details[$side]['w'] = $cba['bw'];
  27083. $details[$side]['c'] = $cba['ca'];
  27084. $details[$side]['style'] = trim($cba['style']);
  27085. $details['mbw']['BL'] = $cba['mbl'];
  27086. $details['mbw']['BR'] = $cba['mbr'];
  27087. $details['mbw']['RT'] = $cba['mrt'];
  27088. $details['mbw']['RB'] = $cba['mrb'];
  27089. $details['mbw']['TL'] = $cba['mtl'];
  27090. $details['mbw']['TR'] = $cba['mtr'];
  27091. $details['mbw']['LT'] = $cba['mlt'];
  27092. $details['mbw']['LB'] = $cba['mlb'];
  27093. $details['cellposdom'] = $cba['cpd'];
  27094. $details['p'] = $side;
  27095. if ($cba['over']==1) { $details[$side]['overlay'] = true; }
  27096. else { $details[$side]['overlay'] = false; }
  27097. $this->_tableRect($cba['x'],$cba['y'],$cba['w'],$cba['h'],$cba['bord'],$details, false, false);
  27098. }
  27099. $this->cellBorderBuffer = array();
  27100. }
  27101. }
  27102. //==================================================================
  27103. function printtablebuffer() {
  27104. if (!$this->table_rotate) {
  27105. $this->pages[$this->page] .= $this->tablebuffer;
  27106. foreach($this->tbrot_Links AS $p => $l) {
  27107. foreach($l AS $v) {
  27108. $this->PageLinks[$p][] = $v;
  27109. }
  27110. }
  27111. $this->tbrot_Links = array();
  27112. /*-- ANNOTATIONS --*/
  27113. foreach($this->tbrot_Annots AS $p => $l) {
  27114. foreach($l AS $v) {
  27115. $this->PageAnnots[$p][] = $v;
  27116. }
  27117. }
  27118. $this->tbrot_Annots = array();
  27119. /*-- END ANNOTATIONS --*/
  27120. /*-- INDEX --*/
  27121. // Output Reference (index)
  27122. foreach($this->tbrot_Reference AS $v) {
  27123. $Present=0;
  27124. for ($i=0;$i<count($this->Reference);$i++){
  27125. if ($this->Reference[$i]['t']==$v['t']){
  27126. $Present=1;
  27127. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  27128. $this->Reference[$i]['p'][] = $v['op'];
  27129. }
  27130. }
  27131. }
  27132. if ($Present==0) {
  27133. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  27134. }
  27135. }
  27136. $this->tbrot_Reference = array();
  27137. /*-- END INDEX --*/
  27138. /*-- BOOKMARKS --*/
  27139. // Output Bookmarks
  27140. foreach($this->tbrot_BMoutlines AS $v) {
  27141. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  27142. }
  27143. $this->tbrot_BMoutlines = array();
  27144. /*-- END BOOKMARKS --*/
  27145. /*-- TOC --*/
  27146. // Output ToC
  27147. foreach($this->tbrot_toc AS $v) {
  27148. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27149. }
  27150. $this->tbrot_toc = array();
  27151. /*-- END TOC --*/
  27152. return;
  27153. }
  27154. // else if rotated
  27155. $lm = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'];
  27156. $pw = $this->blk[$this->blklvl]['inner_width'];
  27157. //Start Transformation
  27158. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  27159. if ($this->table_rotate > 1) { // clockwise
  27160. if ($this->tbrot_align == 'L') {
  27161. $xadj = $this->tbrot_h ; // align L (as is)
  27162. }
  27163. else if ($this->tbrot_align == 'R') {
  27164. $xadj = $lm-$this->tbrot_x0+($pw) ; // align R
  27165. }
  27166. else {
  27167. $xadj = $lm-$this->tbrot_x0+(($pw + $this->tbrot_h)/2) ; // align C
  27168. }
  27169. $yadj = 0;
  27170. }
  27171. else { // anti-clockwise
  27172. if ($this->tbrot_align == 'L') {
  27173. $xadj = 0 ; // align L (as is)
  27174. }
  27175. else if ($this->tbrot_align == 'R') {
  27176. $xadj = $lm-$this->tbrot_x0+($pw - $this->tbrot_h) ; // align R
  27177. }
  27178. else {
  27179. $xadj = $lm-$this->tbrot_x0+(($pw - $this->tbrot_h)/2) ; // align C
  27180. }
  27181. $yadj = $this->tbrot_w;
  27182. }
  27183. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  27184. $this->pages[$this->page] .= $this->transformRotate($this->table_rotate, $this->tbrot_x0 , $this->tbrot_y0 , true)."\n";
  27185. // Now output the adjusted values
  27186. $this->pages[$this->page] .= $this->tablebuffer;
  27187. foreach($this->tbrot_Links AS $p => $l) {
  27188. foreach($l AS $v) {
  27189. $w = $v[2]/_MPDFK;
  27190. $h = $v[3]/_MPDFK;
  27191. $ax = ($v[0]/_MPDFK) - $this->tbrot_x0;
  27192. $ay = (($this->hPt-$v[1])/_MPDFK) - $this->tbrot_y0;
  27193. if ($this->table_rotate > 1) { // clockwise
  27194. $bx = $this->tbrot_x0+$xadj-$ay-$h;
  27195. $by = $this->tbrot_y0+$yadj+$ax;
  27196. }
  27197. else {
  27198. $bx = $this->tbrot_x0+$xadj+$ay;
  27199. $by = $this->tbrot_y0+$yadj-$ax-$w;
  27200. }
  27201. $v[0] = $bx*_MPDFK;
  27202. $v[1] = ($this->h-$by)*_MPDFK;
  27203. $v[2] = $h*_MPDFK; // swap width and height
  27204. $v[3] = $w*_MPDFK;
  27205. $this->PageLinks[$p][] = $v;
  27206. }
  27207. }
  27208. $this->tbrot_Links = array();
  27209. foreach($this->internallink AS $key => $f) {
  27210. if (is_array($f) && isset($f['tbrot'])) {
  27211. $f['Y'] = $this->tbrot_y0;
  27212. $f['PAGE'] = $this->page;
  27213. unset($f['tbrot']);
  27214. $this->internallink[$key] = $f;
  27215. }
  27216. }
  27217. /*-- ANNOTATIONS --*/
  27218. foreach($this->tbrot_Annots AS $p => $l) {
  27219. foreach($l AS $v) {
  27220. $ax = abs($v['x']) - $this->tbrot_x0; // abs because -ve values are internally set and held for reference if annotMargin set
  27221. $ay = $v['y'] - $this->tbrot_y0;
  27222. if ($this->table_rotate > 1) { // clockwise
  27223. $bx = $this->tbrot_x0+$xadj-$ay;
  27224. $by = $this->tbrot_y0+$yadj+$ax;
  27225. }
  27226. else {
  27227. $bx = $this->tbrot_x0+$xadj+$ay;
  27228. $by = $this->tbrot_y0+$yadj-$ax;
  27229. }
  27230. if ($v['x'] < 0) {
  27231. $v['x'] = -$bx;
  27232. }
  27233. else {
  27234. $v['x'] = $bx;
  27235. }
  27236. $v['y'] = ($by);
  27237. $this->PageAnnots[$p][] = $v;
  27238. }
  27239. }
  27240. $this->tbrot_Annots = array();
  27241. /*-- END ANNOTATIONS --*/
  27242. /*-- BOOKMARKS --*/
  27243. // Adjust Bookmarks
  27244. foreach($this->tbrot_BMoutlines AS $v) {
  27245. $v['y'] = $this->tbrot_y0;
  27246. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  27247. }
  27248. /*-- END BOOKMARKS --*/
  27249. /*-- INDEX --*/
  27250. // Adjust Reference (index)
  27251. foreach($this->tbrot_Reference AS $v) {
  27252. $Present=0;
  27253. //Search the reference (AND Ref/PageNo) in the array
  27254. for ($i=0;$i<count($this->Reference);$i++){
  27255. if ($this->Reference[$i]['t']==$v['t']){
  27256. $Present=1;
  27257. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  27258. $this->Reference[$i]['p'][] = $this->page;
  27259. }
  27260. }
  27261. }
  27262. if ($Present==0) {
  27263. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  27264. }
  27265. }
  27266. /*-- END INDEX --*/
  27267. /*-- TOC --*/
  27268. // Adjust ToC - uses document page number
  27269. foreach($this->tbrot_toc AS $v) {
  27270. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27271. $this->links[$v['link']][1] = $this->tbrot_y0;
  27272. }
  27273. /*-- END TOC --*/
  27274. $this->tbrot_Reference = array();
  27275. $this->tbrot_BMoutlines = array();
  27276. $this->tbrot_toc = array();
  27277. //Stop Transformation
  27278. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  27279. $this->y = $this->tbrot_y0 + $this->tbrot_w;
  27280. $this->x = $this->lMargin;
  27281. $this->tablebuffer = '';
  27282. }
  27283. //==================================================================
  27284. // Keep-with-table This buffers contents of h1-6 to keep on page with table
  27285. function printkwtbuffer() {
  27286. if (!$this->kwt_moved) {
  27287. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  27288. foreach($this->kwt_Links AS $p => $l) {
  27289. foreach($l AS $v) {
  27290. $this->PageLinks[$p][] = $v;
  27291. }
  27292. }
  27293. $this->kwt_Links = array();
  27294. /*-- ANNOTATIONS --*/
  27295. foreach($this->kwt_Annots AS $p => $l) {
  27296. foreach($l AS $v) {
  27297. $this->PageAnnots[$p][] = $v;
  27298. }
  27299. }
  27300. $this->kwt_Annots = array();
  27301. /*-- END ANNOTATIONS --*/
  27302. /*-- INDEX --*/
  27303. // Output Reference (index)
  27304. foreach($this->kwt_Reference AS $v) {
  27305. $Present=0;
  27306. for ($i=0;$i<count($this->Reference);$i++){
  27307. if ($this->Reference[$i]['t']==$v['t']){
  27308. $Present=1;
  27309. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  27310. $this->Reference[$i]['p'][] = $v['op'];
  27311. }
  27312. }
  27313. }
  27314. if ($Present==0) {
  27315. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  27316. }
  27317. }
  27318. $this->kwt_Reference = array();
  27319. /*-- END INDEX --*/
  27320. /*-- BOOKMARKS --*/
  27321. // Output Bookmarks
  27322. foreach($this->kwt_BMoutlines AS $v) {
  27323. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  27324. }
  27325. $this->kwt_BMoutlines = array();
  27326. /*-- END BOOKMARKS --*/
  27327. /*-- TOC --*/
  27328. // Output ToC
  27329. foreach($this->kwt_toc AS $v) {
  27330. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27331. }
  27332. $this->kwt_toc = array();
  27333. /*-- END TOC --*/
  27334. return;
  27335. }
  27336. //Start Transformation
  27337. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  27338. $xadj = $this->lMargin - $this->kwt_x0 ;
  27339. //$yadj = $this->y - $this->kwt_y0 ;
  27340. $yadj = $this->tMargin - $this->kwt_y0 ;
  27341. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  27342. // Now output the adjusted values
  27343. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  27344. // Adjust hyperLinks
  27345. foreach($this->kwt_Links AS $p => $l) {
  27346. foreach($l AS $v) {
  27347. $bx = $this->kwt_x0+$xadj;
  27348. $by = $this->kwt_y0+$yadj;
  27349. $v[0] = $bx*_MPDFK;
  27350. $v[1] = ($this->h-$by)*_MPDFK;
  27351. $this->PageLinks[$p][] = $v;
  27352. }
  27353. }
  27354. foreach($this->internallink AS $key => $f) {
  27355. if (is_array($f) && isset($f['kwt'])) {
  27356. $f['Y'] += $yadj;
  27357. $f['PAGE'] = $this->page;
  27358. unset($f['kwt']);
  27359. $this->internallink[$key] = $f;
  27360. }
  27361. }
  27362. /*-- ANNOTATIONS --*/
  27363. foreach($this->kwt_Annots AS $p => $l) {
  27364. foreach($l AS $v) {
  27365. $bx = $this->kwt_x0+$xadj;
  27366. $by = $this->kwt_y0+$yadj;
  27367. if ($v['x'] < 0) {
  27368. $v['x'] = -$bx;
  27369. }
  27370. else {
  27371. $v['x'] = $bx;
  27372. }
  27373. $v['y'] = $by;
  27374. $this->PageAnnots[$p][] = $v;
  27375. }
  27376. }
  27377. /*-- END ANNOTATIONS --*/
  27378. /*-- BOOKMARKS --*/
  27379. // Adjust Bookmarks
  27380. foreach($this->kwt_BMoutlines AS $v) {
  27381. if ($v['y'] != 0) { $v['y'] += $yadj; }
  27382. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  27383. }
  27384. /*-- END BOOKMARKS --*/
  27385. /*-- INDEX --*/
  27386. // Adjust Reference (index)
  27387. foreach($this->kwt_Reference AS $v) {
  27388. $Present=0;
  27389. //Search the reference (AND Ref/PageNo) in the array
  27390. for ($i=0;$i<count($this->Reference);$i++){
  27391. if ($this->Reference[$i]['t']==$v['t']){
  27392. $Present=1;
  27393. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  27394. $this->Reference[$i]['p'][] = $this->page;
  27395. }
  27396. }
  27397. }
  27398. if ($Present==0) {
  27399. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  27400. }
  27401. }
  27402. /*-- END INDEX --*/
  27403. /*-- TOC --*/
  27404. // Adjust ToC
  27405. foreach($this->kwt_toc AS $v) {
  27406. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27407. $this->links[$v['link']][0] = $this->page;
  27408. $this->links[$v['link']][1] += $yadj;
  27409. }
  27410. /*-- END TOC --*/
  27411. $this->kwt_Links = array();
  27412. $this->kwt_Annots = array();
  27413. $this->kwt_Reference = array();
  27414. $this->kwt_BMoutlines = array();
  27415. $this->kwt_toc = array();
  27416. //Stop Transformation
  27417. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  27418. $this->kwt_buffer = array();
  27419. $this->y += $this->kwt_height;
  27420. }
  27421. /*-- END TABLES --*/
  27422. //==================================================================
  27423. function printfloatbuffer() {
  27424. if (count($this->floatbuffer)) {
  27425. $this->objectbuffer = $this->floatbuffer;
  27426. $this->printobjectbuffer(false);
  27427. $this->objectbuffer = array();
  27428. $this->floatbuffer = array();
  27429. $this->floatmargins = array();
  27430. }
  27431. }
  27432. //==================================================================
  27433. function printdivbuffer() {
  27434. $p1 = $this->blk[$this->blklvl]['startpage'];
  27435. $p2 = $this->page;
  27436. $bottom[$p1] = $this->ktBlock[$p1]['bottom_margin'];
  27437. $bottom[$p2] = $this->y; // $this->ktBlock[$p2]['bottom_margin'];
  27438. $top[$p1] = $this->kt_y00;
  27439. $top2 = $this->h;
  27440. foreach($this->divbuffer AS $key=>$s) {
  27441. if ($s['page'] == $p2) {
  27442. $top2 = MIN($s['y'], $top2);
  27443. }
  27444. }
  27445. $top[$p2] = $top2;
  27446. $height[$p1] = ($bottom[$p1] - $top[$p1]);
  27447. $height[$p2] = ($bottom[$p2] - $top[$p2]);
  27448. $xadj[$p1] = $this->MarginCorrection;
  27449. $yadj[$p1] = -($top[$p1] - $top[$p2]);
  27450. $xadj[$p2] = 0;
  27451. $yadj[$p2] = $height[$p1];
  27452. // Output without any transformation
  27453. 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) {
  27454. foreach($this->divbuffer AS $s) { $this->pages[$s['page']] .= $s['s']."\n"; }
  27455. foreach($this->ktLinks AS $p => $l) {
  27456. foreach($l AS $v) {
  27457. $this->PageLinks[$p][] = $v;
  27458. }
  27459. }
  27460. foreach($this->ktForms AS $key => $f) {
  27461. $this->form->forms[$f['n']] = $f;
  27462. }
  27463. /*-- ANNOTATIONS --*/
  27464. foreach($this->ktAnnots AS $p => $l) {
  27465. foreach($l AS $v) {
  27466. $this->PageAnnots[$p][] = $v;
  27467. }
  27468. }
  27469. /*-- END ANNOTATIONS --*/
  27470. /*-- INDEX --*/
  27471. // Adjust Reference (index)
  27472. foreach($this->ktReference AS $v) {
  27473. $Present=0;
  27474. //Search the reference (AND Ref/PageNo) in the array
  27475. for ($i=0;$i<count($this->Reference);$i++){
  27476. if ($this->Reference[$i]['t']==$v['t']){
  27477. $Present=1;
  27478. if (!in_array($p2,$this->Reference[$i]['p'])) {
  27479. $this->Reference[$i]['p'][] = $p2;
  27480. }
  27481. }
  27482. }
  27483. //If not found, add it
  27484. if ($Present==0) {
  27485. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  27486. }
  27487. }
  27488. /*-- END INDEX --*/
  27489. /*-- BOOKMARKS --*/
  27490. // Adjust Bookmarks
  27491. foreach($this->ktBMoutlines AS $v) {
  27492. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  27493. }
  27494. /*-- END BOOKMARKS --*/
  27495. /*-- TOC --*/
  27496. // Adjust ToC
  27497. foreach($this->_kttoc AS $v) {
  27498. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27499. }
  27500. /*-- END TOC --*/
  27501. $this->divbuffer = array();
  27502. $this->ktLinks = array();
  27503. $this->ktAnnots = array();
  27504. $this->ktForms = array();
  27505. $this->ktBlock = array();
  27506. $this->ktReference = array();
  27507. $this->ktBMoutlines = array();
  27508. $this->_kttoc = array();
  27509. $this->keep_block_together = 0;
  27510. return;
  27511. }
  27512. else {
  27513. $np = '';
  27514. $pre = '';
  27515. $ispre = true;
  27516. foreach($this->divbuffer AS $key=>$s) {
  27517. // callback function
  27518. $t = $s['s'];
  27519. $p = $s['page'];
  27520. if (preg_match('/(___PAGE___START'.date('jY').')/', $t)) { $ispre = false; }
  27521. else if (preg_match('/(___HEADER___MARKER'.date('jY').')/', $t)) {
  27522. $np .= $t."\n".$pre;
  27523. continue;
  27524. }
  27525. else {
  27526. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->blockAdjust('Td',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  27527. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->blockAdjust('re',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4')",$t);
  27528. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->blockAdjust('l',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  27529. $t = preg_replace('/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/e',"\$this->blockAdjust('img',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5')",$t);
  27530. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->blockAdjust('draw',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  27531. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) c/e',"\$this->blockAdjust('bezier',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  27532. }
  27533. if ($ispre) $pre .= $t."\n";
  27534. else $np .= $t."\n";
  27535. }
  27536. if ($ispre && $pre) $np = $pre ."\n". $np;
  27537. $this->pages[$this->page] .= $np;
  27538. // Adjust hyperLinks
  27539. foreach($this->ktLinks AS $p => $l) {
  27540. foreach($l AS $v) {
  27541. $v[0] += ($xadj[$p]*_MPDFK);
  27542. $v[1] -= ($yadj[$p]*_MPDFK);
  27543. $this->PageLinks[$p2][] = $v;
  27544. }
  27545. }
  27546. foreach($this->ktForms AS $key => $f) {
  27547. $p = $f['page'];
  27548. $f['x'] += ($xadj[$p]);
  27549. $f['y'] += ($yadj[$p]);
  27550. $f['page'] = $p2;
  27551. $this->form->forms[$f['n']] = $f;
  27552. }
  27553. foreach($this->internallink AS $key => $f) {
  27554. if (is_array($f) && isset($f['kt'])) {
  27555. $f['Y'] += ($yadj[$f['PAGE']]);
  27556. $f['PAGE'] = $p2;
  27557. unset($f['kt']);
  27558. $this->internallink[$key] = $f;
  27559. }
  27560. }
  27561. /*-- ANNOTATIONS --*/
  27562. foreach($this->ktAnnots AS $p => $l) {
  27563. foreach($l AS $v) {
  27564. if ($v['x']>0) { $v['x'] += $xadj[$p]; }
  27565. else if ($v['x']<0) { $v['x'] -= $xadj[$p]; }
  27566. $v['y'] += $yadj[$p];
  27567. $this->PageAnnots[$p2][] = $v;
  27568. }
  27569. }
  27570. /*-- END ANNOTATIONS --*/
  27571. /*-- BOOKMARKS --*/
  27572. // Adjust Bookmarks
  27573. foreach($this->ktBMoutlines AS $v) {
  27574. if ($v['y'] != 0) { $v['y'] += ($yadj[$v['p']]); }
  27575. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$p2);
  27576. }
  27577. /*-- END BOOKMARKS --*/
  27578. /*-- INDEX --*/
  27579. // Adjust Reference (index)
  27580. foreach($this->ktReference AS $v) {
  27581. $Present=0;
  27582. //Search the reference (AND Ref/PageNo) in the array
  27583. for ($i=0;$i<count($this->Reference);$i++){
  27584. if ($this->Reference[$i]['t']==$v['t']){
  27585. $Present=1;
  27586. if (!in_array($p2,$this->Reference[$i]['p'])) {
  27587. $this->Reference[$i]['p'][] = $p2;
  27588. }
  27589. }
  27590. }
  27591. //If not found, add it
  27592. if ($Present==0) {
  27593. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  27594. }
  27595. }
  27596. /*-- END INDEX --*/
  27597. /*-- TOC --*/
  27598. // Adjust ToC
  27599. foreach($this->_kttoc AS $v) {
  27600. $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$p2,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  27601. $this->links[$v['link']][0] = $p2;
  27602. $this->links[$v['link']][1] += $yadj[$v['p']];
  27603. }
  27604. /*-- END TOC --*/
  27605. $this->y = $top[$p2] + $height[$p1] + $height[$p2];
  27606. $this->x = $this->lMargin;
  27607. $this->divbuffer = array();
  27608. $this->ktLinks = array();
  27609. $this->ktAnnots = array();
  27610. $this->ktForms = array();
  27611. $this->ktBlock = array();
  27612. $this->ktReference = array();
  27613. $this->ktBMoutlines = array();
  27614. $this->_kttoc = array();
  27615. $this->keep_block_together = 0;
  27616. }
  27617. }
  27618. //==================================================================
  27619. // Added ELLIPSES and CIRCLES
  27620. function Circle($x,$y,$r,$style='S') {
  27621. $this->Ellipse($x,$y,$r,$r,$style);
  27622. }
  27623. function Ellipse($x,$y,$rx,$ry,$style='S') {
  27624. if($style=='F') { $op='f'; }
  27625. elseif($style=='FD' or $style=='DF') { $op='B'; }
  27626. else { $op='S'; }
  27627. $lx=4/3*(M_SQRT2-1)*$rx;
  27628. $ly=4/3*(M_SQRT2-1)*$ry;
  27629. $h=$this->h;
  27630. $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));
  27631. $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));
  27632. $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));
  27633. $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));
  27634. }
  27635. /*-- DIRECTW --*/
  27636. // Added adaptation of shaded_box = AUTOSIZE-TEXT
  27637. function AutosizeText($text,$w,$font,$style,$szfont=72) {
  27638. $text = $this->purify_utf8_text($text);
  27639. if ($this->text_input_as_HTML) {
  27640. $text = $this->all_entities_to_utf8($text);
  27641. }
  27642. if ($this->usingCoreFont) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  27643. $text = ' '.$text.' ';
  27644. $width = $this->ConvertSize($w);
  27645. $loop = 0;
  27646. while ( $loop == 0 ) {
  27647. $this->SetFont($font,$style,$szfont);
  27648. $sz = $this->GetStringWidth( $text );
  27649. if ( $sz > $w ) { $szfont --; }
  27650. else { $loop ++; }
  27651. }
  27652. $this->SetFont($font,$style,$szfont);
  27653. $this->Cell($w, 0, $text, 0, 0, "C");
  27654. }
  27655. /*-- END DIRECTW --*/
  27656. // ====================================================
  27657. // ====================================================
  27658. /*-- RTL --*/
  27659. function reverse_letters($str) {
  27660. $str = strtr($str, '{}[]()', '}{][)(');
  27661. return $this->mb_strrev($str, $this->mb_enc);
  27662. }
  27663. function magic_reverse_dir(&$chunk, $join=true, $dir) {
  27664. if ($this->usingCoreFont) { return 0; }
  27665. if ($this->biDirectional) {
  27666. // mPDF 5.4.05 Include PUA for non-indexed Arabic glyphs
  27667. $pregRTLchars = $this->pregRTLchars;
  27668. if ($this->CurrentFont['unAGlyphs']) { $pregRTLchars .= "\x{F500}-\x{F7FF}"; }
  27669. // Change Arabic + Persian. to Presentation Forms
  27670. if ($join) {
  27671. $chunk = preg_replace("/([".$pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $chunk );
  27672. }
  27673. $contains_rtl = false;
  27674. $all_rtl = true;
  27675. $initSpace = false;
  27676. $endSpace = false;
  27677. $nonDirchars = "\x{A0}\"\'\(\)\{\}\[\].,:\-=";
  27678. if (preg_match("/[".$pregRTLchars."]/u",$chunk)) { // Chunk contains RTL characters
  27679. if (preg_match("/^[ ]/",$chunk)) { $initSpace = true; $chunk = preg_replace("/^[ ]/",'',$chunk); }
  27680. if (preg_match("/[ ]$/",$chunk)) { $endSpace = true; $chunk = preg_replace("/[ ]$/",'',$chunk); }
  27681. if (preg_match("/[^".$pregRTLchars.$nonDirchars." ]/u",$chunk)) { // Chunk also contains LTR characters
  27682. $all_rtl = false;
  27683. if ($dir == 'rtl') {
  27684. $chunk = preg_replace("/([^".$pregRTLchars.$nonDirchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[^".$pregRTLchars.$nonDirchars."])/u","\\1\x07\\2",$chunk);
  27685. }
  27686. $chunk = preg_replace("/([".$pregRTLchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[".$pregRTLchars."])/u","\\1\x07\\2",$chunk);
  27687. $bits = explode(' ',$chunk);
  27688. foreach($bits AS $bitkey=>$bit) {
  27689. $bit = preg_replace("/\x07/"," ",$bit);
  27690. if (preg_match("/^[".$pregRTLchars.$nonDirchars." ]*$/u",$bit)) {
  27691. $bits[$bitkey] = $this->reverse_letters($bit);
  27692. }
  27693. else if (preg_match("/[".$pregRTLchars."]/u",$bit)) {
  27694. if ($dir == 'rtl') {
  27695. $bit = preg_replace("/([^".$pregRTLchars.$nonDirchars." ])([".$nonDirchars."]*[".$pregRTLchars."])/u","\\1\x07\\2",$bit );
  27696. $bit = preg_replace("/([".$pregRTLchars."][".$nonDirchars."]*)([^".$pregRTLchars.$nonDirchars." ])/u","\\1\x07\\2",$bit );
  27697. }
  27698. else {
  27699. $bit = preg_replace("/([^".$pregRTLchars." ][".$nonDirchars."]*)([".$pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27700. $bit = preg_replace("/([".$pregRTLchars." ])([".$nonDirchars."]*[^".$pregRTLchars." ])/u","\\1\x07\\2",$bit );
  27701. }
  27702. $sbits = explode("\x07",$bit );
  27703. foreach($sbits AS $sbitkey=>$sbit) {
  27704. $sbit = preg_replace("/\x07/","",$sbit);
  27705. if (preg_match("/^[".$pregRTLchars.$nonDirchars." ]*$/u",$sbit)) {
  27706. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27707. }
  27708. else if (preg_match("/[".$pregRTLchars."]/u",$sbit) && $dir=='rtl') {
  27709. $sbits[$sbitkey] = $this->reverse_letters($sbit);
  27710. }
  27711. else {
  27712. $sbits[$sbitkey] = $sbit;
  27713. }
  27714. }
  27715. if ($dir == 'rtl') { $sbits = array_reverse($sbits,false); }
  27716. $bits[$bitkey] = implode('',$sbits);
  27717. }
  27718. else if (preg_match("/[".$pregRTLchars."]/u",$bit) && $dir=='rtl') {
  27719. $bits[$bitkey] = $this->reverse_letters($bit);
  27720. }
  27721. else {
  27722. $bits[$bitkey] = $bit;
  27723. }
  27724. }
  27725. if ($dir == 'rtl') { $bits = array_reverse($bits,false); }
  27726. $chunk = implode(' ',$bits);
  27727. }
  27728. else { $chunk = $this->reverse_letters($chunk); }
  27729. $contains_rtl = true;
  27730. // Un-Reverse numerals back to ltr
  27731. $chunk = preg_replace("/([\x{0660}-\x{0669}]+)/ue", '$this->reverse_letters(\'\\1\')', $chunk );
  27732. if ($dir == 'rtl') {
  27733. if ($endSpace) { $chunk = ' '.$chunk; }
  27734. if ($initSpace) { $chunk .= ' '; }
  27735. }
  27736. else {
  27737. if ($initSpace) { $chunk = ' '.$chunk; }
  27738. if ($endSpace) { $chunk .= ' '; }
  27739. }
  27740. }
  27741. else { $all_rtl = false; }
  27742. if ($all_rtl) { return 2; }
  27743. else if ($contains_rtl) { return 1; }
  27744. else { return 0; }
  27745. }
  27746. return 0;
  27747. }
  27748. /*-- END RTL --*/
  27749. //
  27750. // ****************************
  27751. // ****************************
  27752. function SetSubstitutions() {
  27753. $subsarray = array();
  27754. @include(_MPDF_PATH.'includes/subs_win-1252.php');
  27755. $this->substitute = array();
  27756. foreach($subsarray AS $key => $val) {
  27757. $this->substitute[code2utf($key)] = $val;
  27758. }
  27759. }
  27760. function SubstituteChars($html) {
  27761. // only substitute characters between tags
  27762. if (count($this->substitute)) {
  27763. $a=preg_split('/(<.*?>)/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  27764. $html = '';
  27765. foreach($a as $i => $e) {
  27766. if($i%2==0) {
  27767. $e = strtr($e, $this->substitute);
  27768. }
  27769. $html .= $e;
  27770. }
  27771. }
  27772. return $html;
  27773. }
  27774. function SubstituteCharsSIP(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27775. if (preg_match("/^(.*?)([\x{20000}-\x{2FFFF}]+)(.*)/u", $writehtml_e, $m)) {
  27776. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27777. $font = $this->CurrentFont['sipext'];
  27778. if (!in_array($font, $this->available_unifonts)) { return 0; }
  27779. $writehtml_a[$writehtml_i] = $writehtml_e = $m[1];
  27780. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27781. $this->subPos = $writehtml_i;
  27782. return 4;
  27783. }
  27784. }
  27785. return 0;
  27786. }
  27787. // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font
  27788. function SubstituteCharsNonCore(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27789. if (mb_convert_encoding(mb_convert_encoding($writehtml_e, $this->mb_enc, "UTF-8"), "UTF-8", $this->mb_enc) == $writehtml_e) {
  27790. return 0;
  27791. }
  27792. $cw = &$this->CurrentFont['cw'];
  27793. $unicode = $this->UTF8StringToArray($writehtml_e, false);
  27794. $start = -1;
  27795. $end = 0;
  27796. $flag = 0;
  27797. $ftype = '';
  27798. $u = array();
  27799. if (!$this->subArrMB) {
  27800. include(_MPDF_PATH.'includes/subs_core.php');
  27801. $this->subArrMB['a'] = $aarr;
  27802. $this->subArrMB['s'] = $sarr;
  27803. $this->subArrMB['z'] = $zarr;
  27804. }
  27805. foreach($unicode AS $c => $char) {
  27806. 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)) {
  27807. if ($flag==0) { $start=$c; }
  27808. $flag=1;
  27809. $u[] = $char;
  27810. }
  27811. else if ($flag>0) { $end=$c-1; break; }
  27812. }
  27813. if ($flag>0 && !$end) { $end=count($unicode)-1; }
  27814. if ($start==-1) { return 0; }
  27815. // TRY IN BACKUP SUBS FONT
  27816. if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); }
  27817. foreach($this->backupSubsFont AS $bsfctr=>$bsf) {
  27818. if ($this->fonttrans[$bsf] == 'chelvetica' || $this->fonttrans[$bsf] == 'ctimes' || $this->fonttrans[$bsf] == 'ccourier') { continue; }
  27819. $font = $bsf;
  27820. unset($cw);
  27821. $cw = '';
  27822. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27823. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27824. else {
  27825. $prevFontFamily = $this->FontFamily;
  27826. $prevFontStyle = $this->currentfontstyle;
  27827. $prevFontSizePt = $this->FontSizePt;
  27828. $this->SetFont($bsf, '', '', false);
  27829. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27830. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27831. }
  27832. if (!$cw) { continue; }
  27833. $l = 0;
  27834. foreach($u AS $char) {
  27835. if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) {
  27836. $l++;
  27837. }
  27838. else {
  27839. if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font
  27840. $cont = mb_substr($writehtml_e, $start+1);
  27841. $writehtml_e = mb_substr($writehtml_e, 0, $start+1, 'UTF-8');
  27842. array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont));
  27843. $this->subPos = $writehtml_i+1;
  27844. return 2;
  27845. }
  27846. else { break; }
  27847. }
  27848. }
  27849. if ($l > 0) {
  27850. $patt = mb_substr($writehtml_e, $start, $l, 'UTF-8');
  27851. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27852. $writehtml_e = $m[1];
  27853. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27854. $this->subPos = $writehtml_i+3;
  27855. return 4;
  27856. }
  27857. }
  27858. }
  27859. unset($cw);
  27860. return 0;
  27861. }
  27862. function SubstituteCharsMB(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  27863. $cw = &$this->CurrentFont['cw'];
  27864. $unicode = $this->UTF8StringToArray($writehtml_e, false);
  27865. $start = -1;
  27866. $end = 0;
  27867. $flag = 0;
  27868. $ftype = '';
  27869. $u = array();
  27870. foreach($unicode AS $c => $char) {
  27871. if (($flag == 0 || $flag==2) && (!$this->_charDefined($cw,$char) || ($flag==2 && $char==32)) && $this->checkSIP && $char > 131071) { // Unicode Plane 2 (SIP)
  27872. if (in_array($this->FontFamily ,$this->available_CJK_fonts)) { return 0; }
  27873. if ($flag==0) { $start=$c; }
  27874. $flag=2;
  27875. $u[] = $char;
  27876. }
  27877. //else if (($flag == 0 || $flag==1) && $char != 173 && !$this->_charDefined($cw,$char) && ($char<1423 || ($char>3583 && $char < 11263))) {
  27878. else if (($flag == 0 || $flag==1) && $char != 173 && (!$this->_charDefined($cw,$char) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) {
  27879. if ($flag==0) { $start=$c; }
  27880. $flag=1;
  27881. $u[] = $char;
  27882. }
  27883. else if ($flag>0) { $end=$c-1; break; }
  27884. }
  27885. if ($flag>0 && !$end) { $end=count($unicode)-1; }
  27886. if ($start==-1) { return 0; }
  27887. if ($flag == 2) { // SIP
  27888. // Check if current CJK font has a ext-B related font
  27889. if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) {
  27890. $font = $this->CurrentFont['sipext'];
  27891. unset($cw);
  27892. $cw = '';
  27893. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27894. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27895. else {
  27896. $prevFontFamily = $this->FontFamily;
  27897. $prevFontStyle = $this->currentfontstyle;
  27898. $prevFontSizePt = $this->FontSizePt;
  27899. $this->SetFont($font, '', '', false);
  27900. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27901. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27902. }
  27903. if (!$cw) { return 0; }
  27904. $l = 0;
  27905. foreach($u AS $char) {
  27906. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27907. $l++;
  27908. }
  27909. else { break; }
  27910. }
  27911. if ($l > 0) {
  27912. $patt = mb_substr($writehtml_e, $start, $l);
  27913. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27914. $writehtml_e = $m[1];
  27915. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27916. $this->subPos = $writehtml_i+3;
  27917. return 4;
  27918. }
  27919. }
  27920. }
  27921. // Check Backup SIP font (defined in config_fonts.php)
  27922. if (isset($this->backupSIPFont) && $this->backupSIPFont) {
  27923. if ($this->currentfontfamily != $this->backupSIPFont) { $font = $this->backupSIPFont; }
  27924. else { unset($cw); return 0; }
  27925. unset($cw);
  27926. $cw = '';
  27927. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  27928. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  27929. else {
  27930. $prevFontFamily = $this->FontFamily;
  27931. $prevFontStyle = $this->currentfontstyle;
  27932. $prevFontSizePt = $this->FontSizePt;
  27933. $this->SetFont($this->backupSIPFont, '', '', false);
  27934. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  27935. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  27936. }
  27937. if (!$cw) { return 0; }
  27938. $l = 0;
  27939. foreach($u AS $char) {
  27940. if ($this->_charDefined($cw,$char) || $char > 131071) {
  27941. $l++;
  27942. }
  27943. else { break; }
  27944. }
  27945. if ($l > 0) {
  27946. $patt = mb_substr($writehtml_e, $start, $l);
  27947. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27948. $writehtml_e = $m[1];
  27949. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  27950. $this->subPos = $writehtml_i+3;
  27951. return 4;
  27952. }
  27953. }
  27954. }
  27955. return 0;
  27956. }
  27957. // FIRST TRY CORE FONTS
  27958. if (!$this->PDFA && !$this->PDFX) {
  27959. $repl = array();
  27960. if (!$this->subArrMB) {
  27961. include(_MPDF_PATH.'includes/subs_core.php');
  27962. $this->subArrMB['a'] = $aarr;
  27963. $this->subArrMB['s'] = $sarr;
  27964. $this->subArrMB['z'] = $zarr;
  27965. }
  27966. if (isset($this->subArrMB['a'][$u[0]])) {
  27967. $font = 'tta'; $ftype = 'C';
  27968. foreach($u AS $char) {
  27969. if ($this->subArrMB['a'][$char]) { $repl[] = $this->subArrMB['a'][$char]; }
  27970. else { break; }
  27971. }
  27972. }
  27973. else if (isset($this->subArrMB['z'][$u[0]])) {
  27974. $font = 'ttz'; $ftype = 'C';
  27975. foreach($u AS $char) {
  27976. if ($this->subArrMB['z'][$char]) { $repl[] = $this->subArrMB['z'][$char]; }
  27977. else { break; }
  27978. }
  27979. }
  27980. else if (isset($this->subArrMB['s'][$u[0]])) {
  27981. $font = 'tts'; $ftype = 'C';
  27982. foreach($u AS $char) {
  27983. if ($this->subArrMB['s'][$char]) { $repl[] = $this->subArrMB['s'][$char]; }
  27984. else { break; }
  27985. }
  27986. }
  27987. if ($ftype=='C') {
  27988. $patt = mb_substr($writehtml_e, $start, count($repl));
  27989. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  27990. $writehtml_e = $m[1];
  27991. array_splice($writehtml_a, $writehtml_i+1, 0, array($font, implode('|', $repl), '/'.$font, $m[3])); // e.g. <tts>
  27992. $this->subPos = $writehtml_i+3;
  27993. return 4;
  27994. }
  27995. return 0;
  27996. }
  27997. }
  27998. // FIND IN DEFAULT FONT - removed mPDF 5.0
  27999. // LASTLY TRY IN BACKUP SUBS FONT
  28000. if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); }
  28001. foreach($this->backupSubsFont AS $bsfctr=>$bsf) {
  28002. if ($this->currentfontfamily != $bsf) { $font = $bsf; }
  28003. else { continue; }
  28004. unset($cw);
  28005. $cw = '';
  28006. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  28007. else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); }
  28008. else {
  28009. $prevFontFamily = $this->FontFamily;
  28010. $prevFontStyle = $this->currentfontstyle;
  28011. $prevFontSizePt = $this->FontSizePt;
  28012. $this->SetFont($bsf, '', '', false);
  28013. $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat');
  28014. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false);
  28015. }
  28016. if (!$cw) { continue; }
  28017. $l = 0;
  28018. foreach($u AS $char) {
  28019. if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) { // Arabic and Indic
  28020. $l++;
  28021. }
  28022. else {
  28023. if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font
  28024. $cont = mb_substr($writehtml_e, $start+1);
  28025. $writehtml_e = mb_substr($writehtml_e, 0, $start+1);
  28026. array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont));
  28027. $this->subPos = $writehtml_i+1;
  28028. return 2;
  28029. }
  28030. else { break; }
  28031. }
  28032. }
  28033. if ($l > 0) {
  28034. $patt = mb_substr($writehtml_e, $start, $l);
  28035. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  28036. $writehtml_e = $m[1];
  28037. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  28038. $this->subPos = $writehtml_i+3;
  28039. return 4;
  28040. }
  28041. }
  28042. }
  28043. unset($cw);
  28044. return 0;
  28045. }
  28046. function setHiEntitySubstitutions() {
  28047. $entarr = array (
  28048. 'nbsp' => '160', 'iexcl' => '161', 'cent' => '162', 'pound' => '163', 'curren' => '164', 'yen' => '165', 'brvbar' => '166', 'sect' => '167',
  28049. 'uml' => '168', 'copy' => '169', 'ordf' => '170', 'laquo' => '171', 'not' => '172', 'shy' => '173', 'reg' => '174', 'macr' => '175',
  28050. 'deg' => '176', 'plusmn' => '177', 'sup2' => '178', 'sup3' => '179', 'acute' => '180', 'micro' => '181', 'para' => '182', 'middot' => '183',
  28051. 'cedil' => '184', 'sup1' => '185', 'ordm' => '186', 'raquo' => '187', 'frac14' => '188', 'frac12' => '189', 'frac34' => '190',
  28052. 'iquest' => '191', 'Agrave' => '192', 'Aacute' => '193', 'Acirc' => '194', 'Atilde' => '195', 'Auml' => '196', 'Aring' => '197',
  28053. 'AElig' => '198', 'Ccedil' => '199', 'Egrave' => '200', 'Eacute' => '201', 'Ecirc' => '202', 'Euml' => '203', 'Igrave' => '204',
  28054. 'Iacute' => '205', 'Icirc' => '206', 'Iuml' => '207', 'ETH' => '208', 'Ntilde' => '209', 'Ograve' => '210', 'Oacute' => '211',
  28055. 'Ocirc' => '212', 'Otilde' => '213', 'Ouml' => '214', 'times' => '215', 'Oslash' => '216', 'Ugrave' => '217', 'Uacute' => '218',
  28056. 'Ucirc' => '219', 'Uuml' => '220', 'Yacute' => '221', 'THORN' => '222', 'szlig' => '223', 'agrave' => '224', 'aacute' => '225',
  28057. 'acirc' => '226', 'atilde' => '227', 'auml' => '228', 'aring' => '229', 'aelig' => '230', 'ccedil' => '231', 'egrave' => '232',
  28058. 'eacute' => '233', 'ecirc' => '234', 'euml' => '235', 'igrave' => '236', 'iacute' => '237', 'icirc' => '238', 'iuml' => '239',
  28059. 'eth' => '240', 'ntilde' => '241', 'ograve' => '242', 'oacute' => '243', 'ocirc' => '244', 'otilde' => '245', 'ouml' => '246',
  28060. 'divide' => '247', 'oslash' => '248', 'ugrave' => '249', 'uacute' => '250', 'ucirc' => '251', 'uuml' => '252', 'yacute' => '253',
  28061. 'thorn' => '254', 'yuml' => '255', 'OElig' => '338', 'oelig' => '339', 'Scaron' => '352', 'scaron' => '353', 'Yuml' => '376',
  28062. 'fnof' => '402', 'circ' => '710', 'tilde' => '732', 'Alpha' => '913', 'Beta' => '914', 'Gamma' => '915', 'Delta' => '916',
  28063. 'Epsilon' => '917', 'Zeta' => '918', 'Eta' => '919', 'Theta' => '920', 'Iota' => '921', 'Kappa' => '922', 'Lambda' => '923',
  28064. 'Mu' => '924', 'Nu' => '925', 'Xi' => '926', 'Omicron' => '927', 'Pi' => '928', 'Rho' => '929', 'Sigma' => '931', 'Tau' => '932',
  28065. 'Upsilon' => '933', 'Phi' => '934', 'Chi' => '935', 'Psi' => '936', 'Omega' => '937', 'alpha' => '945', 'beta' => '946', 'gamma' => '947',
  28066. 'delta' => '948', 'epsilon' => '949', 'zeta' => '950', 'eta' => '951', 'theta' => '952', 'iota' => '953', 'kappa' => '954',
  28067. 'lambda' => '955', 'mu' => '956', 'nu' => '957', 'xi' => '958', 'omicron' => '959', 'pi' => '960', 'rho' => '961', 'sigmaf' => '962',
  28068. 'sigma' => '963', 'tau' => '964', 'upsilon' => '965', 'phi' => '966', 'chi' => '967', 'psi' => '968', 'omega' => '969',
  28069. 'thetasym' => '977', 'upsih' => '978', 'piv' => '982', 'ensp' => '8194', 'emsp' => '8195', 'thinsp' => '8201', 'zwnj' => '8204',
  28070. 'zwj' => '8205', 'lrm' => '8206', 'rlm' => '8207', 'ndash' => '8211', 'mdash' => '8212', 'lsquo' => '8216', 'rsquo' => '8217',
  28071. 'sbquo' => '8218', 'ldquo' => '8220', 'rdquo' => '8221', 'bdquo' => '8222', 'dagger' => '8224', 'Dagger' => '8225', 'bull' => '8226',
  28072. 'hellip' => '8230', 'permil' => '8240', 'prime' => '8242', 'Prime' => '8243', 'lsaquo' => '8249', 'rsaquo' => '8250', 'oline' => '8254',
  28073. 'frasl' => '8260', 'euro' => '8364', 'image' => '8465', 'weierp' => '8472', 'real' => '8476', 'trade' => '8482', 'alefsym' => '8501',
  28074. 'larr' => '8592', 'uarr' => '8593', 'rarr' => '8594', 'darr' => '8595', 'harr' => '8596', 'crarr' => '8629', 'lArr' => '8656',
  28075. 'uArr' => '8657', 'rArr' => '8658', 'dArr' => '8659', 'hArr' => '8660', 'forall' => '8704', 'part' => '8706', 'exist' => '8707',
  28076. 'empty' => '8709', 'nabla' => '8711', 'isin' => '8712', 'notin' => '8713', 'ni' => '8715', 'prod' => '8719', 'sum' => '8721',
  28077. 'minus' => '8722', 'lowast' => '8727', 'radic' => '8730', 'prop' => '8733', 'infin' => '8734', 'ang' => '8736', 'and' => '8743',
  28078. 'or' => '8744', 'cap' => '8745', 'cup' => '8746', 'int' => '8747', 'there4' => '8756', 'sim' => '8764', 'cong' => '8773',
  28079. 'asymp' => '8776', 'ne' => '8800', 'equiv' => '8801', 'le' => '8804', 'ge' => '8805', 'sub' => '8834', 'sup' => '8835', 'nsub' => '8836',
  28080. 'sube' => '8838', 'supe' => '8839', 'oplus' => '8853', 'otimes' => '8855', 'perp' => '8869', 'sdot' => '8901', 'lceil' => '8968',
  28081. 'rceil' => '8969', 'lfloor' => '8970', 'rfloor' => '8971', 'lang' => '9001', 'rang' => '9002', 'loz' => '9674', 'spades' => '9824',
  28082. 'clubs' => '9827', 'hearts' => '9829', 'diams' => '9830',
  28083. );
  28084. foreach($entarr AS $key => $val) {
  28085. $this->entsearch[] = '&'.$key.';';
  28086. $this->entsubstitute[] = code2utf($val);
  28087. }
  28088. }
  28089. function SubstituteHiEntities($html) {
  28090. // converts html_entities > ASCII 127 to unicode
  28091. // Leaves in particular &lt; to distinguish from tag marker
  28092. if (count($this->entsearch)) {
  28093. $html = str_replace($this->entsearch,$this->entsubstitute,$html);
  28094. }
  28095. return $html;
  28096. }
  28097. // Edited v1.2 Pass by reference; option to continue if invalid UTF-8 chars
  28098. function is_utf8(&$string) {
  28099. if ($string === mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
  28100. return true;
  28101. }
  28102. else {
  28103. if ($this->ignore_invalid_utf8) {
  28104. $string = mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") ;
  28105. return true;
  28106. }
  28107. else {
  28108. return false;
  28109. }
  28110. }
  28111. }
  28112. function purify_utf8($html,$lo=true) {
  28113. // For HTML
  28114. // Checks string is valid UTF-8 encoded
  28115. // converts html_entities > ASCII 127 to UTF-8
  28116. // Only exception - leaves low ASCII entities e.g. &lt; &amp; etc.
  28117. // Leaves in particular &lt; to distinguish from tag marker
  28118. if (!$this->is_utf8($html)) {
  28119. echo "<p><b>HTML contains invalid UTF-8 character(s)</b></p>";
  28120. while (mb_convert_encoding(mb_convert_encoding($html, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") != $html) {
  28121. $a = iconv('UTF-8', 'UTF-8', $html);
  28122. echo ($a);
  28123. $pos = $start = strlen($a);
  28124. $err = '';
  28125. while ( ord(substr($html,$pos,1)) > 128 ) {
  28126. $err .= '[[#'.ord(substr($html,$pos,1)).']]';
  28127. $pos++;
  28128. }
  28129. echo '<span style="color:red; font-weight:bold">'.$err.'</span>';
  28130. $html = substr($html, $pos);
  28131. }
  28132. echo $html;
  28133. $this->Error("");
  28134. }
  28135. $html = preg_replace("/\r/", "", $html );
  28136. // converts html_entities > ASCII 127 to UTF-8
  28137. // Leaves in particular &lt; to distinguish from tag marker
  28138. $html = $this->SubstituteHiEntities($html);
  28139. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  28140. // If $lo==true then includes ASCII < 128
  28141. $html = strcode2utf($html,$lo);
  28142. return ($html);
  28143. }
  28144. function purify_utf8_text($txt) {
  28145. // For TEXT
  28146. // Make sure UTF-8 string of characters
  28147. if (!$this->is_utf8($txt)) { $this->Error("Text contains invalid UTF-8 character(s)"); }
  28148. $txt = preg_replace("/\r/", "", $txt );
  28149. return ($txt);
  28150. }
  28151. function all_entities_to_utf8($txt) {
  28152. // converts txt_entities > ASCII 127 to UTF-8
  28153. // Leaves in particular &lt; to distinguish from tag marker
  28154. $txt = $this->SubstituteHiEntities($txt);
  28155. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  28156. $txt = strcode2utf($txt);
  28157. $txt = $this->lesser_entity_decode($txt);
  28158. return ($txt);
  28159. }
  28160. // ====================================================
  28161. /*-- BARCODES --*/
  28162. // UPC/EAN barcode
  28163. // EAN13, EAN8, UPCA, UPCE, ISBN, ISSN
  28164. // Accepts 12 or 13 digits with or without - hyphens
  28165. 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) {
  28166. if (empty($code)) {
  28167. return;
  28168. }
  28169. $codestr = $code;
  28170. $code = preg_replace('/\-/','',$code);
  28171. if (!class_exists('PDFBarcode', false)) {
  28172. include(_MPDF_PATH.'classes/barcode.php');
  28173. }
  28174. $this->barcode = new PDFBarcode();
  28175. if ($btype == 'ISSN' || $btype == 'ISBN') {
  28176. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  28177. }
  28178. else { $arrcode = $this->barcode->getBarcodeArray($code, $btype); }
  28179. if ($arrcode === false) { $this->Error('Error in barcode string: '.$codestr); }
  28180. if((($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') && strlen($code) == 12) || ($btype=='UPCA' && strlen($code) == 11)
  28181. || ($btype=='UPCE' && strlen($code) == 11) || ($btype=='EAN8' && strlen($code) == 7)) {
  28182. $code .= $arrcode['checkdigit'];
  28183. if (stristr($codestr,'-')) { $codestr .= '-' . $arrcode['checkdigit']; }
  28184. else { $codestr .= $arrcode['checkdigit']; }
  28185. }
  28186. if ($btype == 'ISBN') { $codestr = 'ISBN '.$codestr; }
  28187. if ($btype == 'ISSN') { $codestr = 'ISSN '.$codestr; }
  28188. if (empty($x)) {
  28189. $x = $this->x;
  28190. }
  28191. if (empty($y)) {
  28192. $y = $this->y;
  28193. }
  28194. // set foreground color
  28195. $prevDrawColor = $this->DrawColor;
  28196. $prevTextColor = $this->TextColor;
  28197. $prevFillColor = $this->FillColor;
  28198. $lw = $this->LineWidth;
  28199. $this->SetLineWidth(0.01);
  28200. $size /= $k; // in case resized in a table
  28201. $xres = $arrcode['nom-X'] * $size;
  28202. $llm = $arrcode['lightmL'] * $arrcode['nom-X'] * $size; // Left Light margin
  28203. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  28204. $bcw = ($arrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  28205. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28206. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  28207. $fbwi = $fbw - 2; // Full barcode width incl. light margins - 2mm - for isbn string
  28208. // cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf
  28209. $num_height = 3 * $size; // Height of numerals
  28210. $fbh = $arrcode['nom-H'] * $size * $height; // Full barcode height incl. numerals
  28211. $bch = $fbh - (1.5 * $size); // Barcode height of bars (3mm for numerals)
  28212. if (($btype=='EAN13' && $showtext) || $btype == 'ISSN' || $btype == 'ISBN') { // Add height for ISBN string + margin from top of bars
  28213. $tisbnm = 1.5 * $size; // Top margin between isbn (if shown) & bars
  28214. $codestr_fontsize = 2.1 * $size;
  28215. $paddingT += $codestr_fontsize + $tisbnm ;
  28216. }
  28217. $oh = $fbh + $paddingT + $paddingB; // Full overall height incl. user-defined padding
  28218. // PRINT border background color
  28219. $xpos = $x;
  28220. $ypos = $y;
  28221. if ($col) {
  28222. $this->SetDColor($col);
  28223. $this->SetTColor($col);
  28224. }
  28225. else {
  28226. $this->SetDColor($this->ConvertColor(0));
  28227. $this->SetTColor($this->ConvertColor(0));
  28228. }
  28229. if ($bgcol) {
  28230. $this->SetFColor($bgcol);
  28231. }
  28232. else { $this->SetFColor($this->ConvertColor(255)); }
  28233. if (!$bgcol && !$col) { // fn. called directly - not via HTML
  28234. if ($border) { $fillb = 'DF'; } else { $fillb = 'F'; }
  28235. $this->Rect($xpos, $ypos, $ow, $oh, $fillb);
  28236. }
  28237. // PRINT BARS
  28238. $xpos = $x + $paddingL + $llm ;
  28239. $ypos = $y + $paddingT;
  28240. if ($col) { $this->SetFColor($col); }
  28241. else { $this->SetFColor($this->ConvertColor(0)); }
  28242. if ($arrcode !== false) {
  28243. foreach ($arrcode["bcode"] AS $v) {
  28244. $bw = ($v["w"] * $xres);
  28245. if ($v["t"]) {
  28246. // draw a vertical bar
  28247. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  28248. }
  28249. $xpos += $bw;
  28250. }
  28251. }
  28252. // print text
  28253. $prevFontFamily = $this->FontFamily;
  28254. $prevFontStyle = $this->FontStyle;
  28255. $prevFontSizePt = $this->FontSizePt;
  28256. // ISBN string
  28257. if (($btype=='EAN13' && $showtext) || $btype=='ISBN' || $btype=='ISSN') {
  28258. if ($this->onlyCoreFonts) {
  28259. $this->SetFont('chelvetica');
  28260. }
  28261. else {
  28262. $this->SetFont('sans');
  28263. }
  28264. if ($bgcol) { $this->SetFColor($bgcol); }
  28265. else { $this->SetFColor($this->ConvertColor(255)); }
  28266. $this->x = $x + $paddingL + 1; // 1mm left margin (cf. $fbwi above)
  28267. // max width is $fbwi
  28268. $loop = 0;
  28269. while ( $loop == 0 ) {
  28270. $this->SetFontSize($codestr_fontsize*1.4*_MPDFK, false); // don't write
  28271. $sz = $this->GetStringWidth( $codestr );
  28272. if ($sz > $fbwi)
  28273. $codestr_fontsize -= 0.1;
  28274. else
  28275. $loop ++;
  28276. }
  28277. $this->SetFont('','',$codestr_fontsize*1.4*_MPDFK, true, true); // * 1.4 because font height is only 7/10 of given mm
  28278. // WORD SPACING
  28279. if ($fbwi > $sz) {
  28280. $xtra = $fbwi - $sz;
  28281. $charspacing = $xtra / (strlen($codestr)-1);
  28282. if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); }
  28283. }
  28284. $this->y = $y + $paddingT - ($codestr_fontsize ) - $tisbnm ;
  28285. $this->Cell($fbw , $codestr_fontsize, $codestr);
  28286. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  28287. }
  28288. // Bottom NUMERALS
  28289. if ($this->onlyCoreFonts) {
  28290. $this->SetFont('mono');
  28291. }
  28292. else {
  28293. if (in_array('ocrb',$this->available_unifonts)) { $this->SetFont('ocrb'); }
  28294. else { $this->SetFont('mono'); }
  28295. }
  28296. if (isset($this->CurrentFont['desc']['CapHeight'])) { $fh = (1000/$this->CurrentFont['desc']['CapHeight']); }
  28297. else if (isset($this->CurrentFont['desc']['Ascent'])) { $fh = (1000/$this->CurrentFont['desc']['Ascent']); }
  28298. else { $fh = 1.2; }
  28299. $charRO = '';
  28300. if ($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') {
  28301. $outerfontsize = 3; // Inner fontsize = 3
  28302. $outerp = $xres * 4;
  28303. $innerp = $xres * 2.5;
  28304. $textw = ($bcw*0.5) - $outerp - $innerp;
  28305. $chars = 6; // number of numerals in each half
  28306. $charLO = substr($code,0,1); // Left Outer
  28307. $charLI = substr($code,1,6); // Left Inner
  28308. $charRI = substr($code,7,6); // Right Inner
  28309. if (!$supplement) $charRO = '>'; // Right Outer
  28310. }
  28311. else if ($btype=='UPCA') {
  28312. $outerfontsize = 2.3; // Inner fontsize = 3
  28313. $outerp = $xres * 10;
  28314. $innerp = $xres * 2.5;
  28315. $textw = ($bcw*0.5) - $outerp - $innerp;
  28316. $chars = 5;
  28317. $charLO = substr($code,0,1); // Left Outer
  28318. $charLI = substr($code,1,5); // Left Inner
  28319. $charRI = substr($code,6,5); // Right Inner
  28320. $charRO = substr($code,11,1); // Right Outer
  28321. }
  28322. else if ($btype=='UPCE') {
  28323. $outerfontsize = 2.3; // Inner fontsize = 3
  28324. $outerp = $xres * 4;
  28325. $innerp = 0;
  28326. $textw = ($bcw*0.5) - $outerp - $innerp;
  28327. $chars = 3;
  28328. $upce_code = $arrcode['code'];
  28329. $charLO = substr($code,0,1); // Left Outer
  28330. $charLI = substr($upce_code,0,3); // Left Inner
  28331. $charRI = substr($upce_code,3,3); // Right Inner
  28332. $charRO = substr($code,11,1); // Right Outer
  28333. }
  28334. else if ($btype=='EAN8') {
  28335. $outerfontsize = 3; // Inner fontsize = 3
  28336. $outerp = $xres * 4;
  28337. $innerp = $xres * 2.5;
  28338. $textw = ($bcw*0.5) - $outerp - $innerp;
  28339. $chars = 4;
  28340. $charLO = '<'; // Left Outer
  28341. $charLI = substr($code,0,4); // Left Inner
  28342. $charRI = substr($code,4,4); // Right Inner
  28343. if (!$supplement) $charRO = '>'; // Right Outer
  28344. }
  28345. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28346. if (!$this->usingCoreFont) { $cw = $this->_getCharWidth($this->CurrentFont['cw'],32)*3*$fh*$size/1000; } // character width at 3mm
  28347. else { $cw = $this->_getCharWidth($this->CurrentFont['cw'],48)*3*$fh*$size/1000; } // 48 == char "0"
  28348. // Outer left character
  28349. $y_text = $y + $paddingT + $bch - ($num_height/2);
  28350. $y_text_outer = $y + $paddingT + $bch - ($num_height*($outerfontsize/3)/2);
  28351. $this->x = $x + $paddingL - ($cw*($outerfontsize/3)*0.1); // 0.1 is correction as char does not fill full width;
  28352. $this->y = $y_text_outer;
  28353. $this->Cell($cw, $num_height, $charLO );
  28354. // WORD SPACING for inner chars
  28355. $xtra = $textw - ($cw*$chars);
  28356. $charspacing = $xtra / ($chars-1);
  28357. if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); }
  28358. if ($bgcol) { $this->SetFColor($bgcol); }
  28359. else { $this->SetFColor($this->ConvertColor(255)); }
  28360. $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28361. // Inner left half characters
  28362. $this->x = $x + $paddingL + $llm + $outerp;
  28363. $this->y = $y_text;
  28364. $this->Cell($textw, $num_height, $charLI , 0, 0, '', 1);
  28365. // Inner right half characters
  28366. $this->x = $x + $paddingL + $llm + ($bcw*0.5) + $innerp;
  28367. $this->y = $y_text;
  28368. $this->Cell($textw, $num_height, $charRI , 0, 0, '', 1);
  28369. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  28370. // Outer Right character
  28371. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28372. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*($outerfontsize/3)*0.9); // 0.9 is correction as char does not fill full width
  28373. $this->y = $y_text_outer;
  28374. $this->Cell($cw*($outerfontsize/3), $num_height, $charRO , 0, 0, 'R');
  28375. if ($supplement) { // EAN-2 or -5 Supplement
  28376. // PRINT BARS
  28377. $supparrcode = $this->barcode->getBarcodeArray($supplement_code, 'EAN'.$supplement);
  28378. if ($supparrcode === false) { $this->Error('Error in barcode string (supplement): '.$codestr.' '.$supplement_code); }
  28379. if(strlen($supplement_code) != $supplement) {
  28380. $this->Error('Barcode supplement incorrect: '.$supplement_code);
  28381. }
  28382. $llm = $fbw - (($arrcode['lightmR'] - $supparrcode['sepM']) * $arrcode['nom-X'] * $size); // Left Light margin
  28383. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  28384. $bcw = ($supparrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  28385. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28386. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  28387. $bch = $fbh - (1.5 * $size) - ($num_height + 0.5); // Barcode height of bars (3mm for numerals)
  28388. $xpos = $x + $paddingL + $llm ;
  28389. $ypos = $y + $paddingT + $num_height + 0.5;
  28390. if ($col) { $this->SetFColor($col); }
  28391. else { $this->SetFColor($this->ConvertColor(0)); }
  28392. if ($supparrcode !== false) {
  28393. foreach ($supparrcode["bcode"] AS $v) {
  28394. $bw = ($v["w"] * $xres);
  28395. if ($v["t"]) {
  28396. // draw a vertical bar
  28397. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  28398. }
  28399. $xpos += $bw;
  28400. }
  28401. }
  28402. // Characters
  28403. if ($bgcol) { $this->SetFColor($bgcol); }
  28404. else { $this->SetFColor($this->ConvertColor(255)); }
  28405. $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28406. $this->x = $x + $paddingL + $llm;
  28407. $this->y = $y + $paddingT;
  28408. $this->Cell($bcw, $num_height, $supplement_code, 0, 0, 'C');
  28409. // Outer Right character (light margin)
  28410. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters)
  28411. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*0.9); // 0.9 is correction as char does not fill full width
  28412. $this->y = $y + $paddingT;
  28413. $this->Cell($cw*($outerfontsize/3), $num_height, '>', 0, 0, 'R');
  28414. }
  28415. // Restore **************
  28416. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  28417. $this->DrawColor = $prevDrawColor;
  28418. $this->TextColor = $prevTextColor;
  28419. $this->FillColor = $prevFillColor;
  28420. $this->SetLineWidth($lw);
  28421. $this->SetY($y);
  28422. }
  28423. // ====================================================
  28424. // POSTAL and OTHER barcodes
  28425. function WriteBarcode2($code, $x='', $y='', $size=1, $height=1, $bgcol=false, $col=false, $btype='IMB', $print_ratio='', $k=1) {
  28426. if (empty($code)) { return; }
  28427. if (!class_exists('PDFBarcode', false)) {
  28428. include(_MPDF_PATH.'classes/barcode.php');
  28429. }
  28430. $this->barcode = new PDFBarcode();
  28431. $arrcode = $this->barcode->getBarcodeArray($code, $btype, $print_ratio);
  28432. if ($arrcode === false) { $this->Error('Error in barcode string: '.$code); }
  28433. if (empty($x)) { $x = $this->x; }
  28434. if (empty($y)) { $y = $this->y; }
  28435. $prevDrawColor = $this->DrawColor;
  28436. $prevTextColor = $this->TextColor;
  28437. $prevFillColor = $this->FillColor;
  28438. $lw = $this->LineWidth;
  28439. $this->SetLineWidth(0.01);
  28440. $size /= $k; // in case resized in a table
  28441. $xres = $arrcode['nom-X'] * $size;
  28442. if ($btype == 'IMB' || $btype == 'RM4SCC' || $btype == 'KIX' || $btype == 'POSTNET' || $btype == 'PLANET') {
  28443. $llm = $arrcode['quietL'] / $k; // Left Quiet margin
  28444. $rlm = $arrcode['quietR'] / $k; // Right Quiet margin
  28445. $tlm = $blm = $arrcode['quietTB'] / $k;
  28446. $height=1; // Overrides
  28447. }
  28448. 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'))) {
  28449. $llm = $arrcode['lightmL'] * $xres; // Left Quiet margin
  28450. $rlm = $arrcode['lightmR'] * $xres; // Right Quiet margin
  28451. $tlm = $blm = $arrcode['lightTB'] * $xres * $height;
  28452. }
  28453. $bcw = ($arrcode["maxw"] * $xres);
  28454. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  28455. $bch = ($arrcode["nom-H"] * $size * $height);
  28456. $fbh = $bch + $tlm + $blm; // Full barcode height
  28457. // PRINT border background color
  28458. $xpos = $x;
  28459. $ypos = $y;
  28460. if ($col) {
  28461. $this->SetDColor($col);
  28462. $this->SetTColor($col);
  28463. }
  28464. else {
  28465. $this->SetDColor($this->ConvertColor(0));
  28466. $this->SetTColor($this->ConvertColor(0));
  28467. }
  28468. if ($bgcol) {
  28469. $this->SetFColor($bgcol);
  28470. }
  28471. else { $this->SetFColor($this->ConvertColor(255)); }
  28472. // PRINT BARS
  28473. if ($col) { $this->SetFColor($col); }
  28474. else { $this->SetFColor($this->ConvertColor(0)); }
  28475. $xpos = $x + $llm ;
  28476. if ($arrcode !== false) {
  28477. foreach ($arrcode["bcode"] AS $v) {
  28478. $bw = ($v["w"] * $xres);
  28479. if ($v["t"]) {
  28480. $ypos = $y + $tlm + ($bch * $v['p'] / $arrcode['maxh']);
  28481. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $bch / $arrcode['maxh']), 'F');
  28482. }
  28483. $xpos += $bw;
  28484. }
  28485. }
  28486. // PRINT BEARER BARS
  28487. if ($btype == 'I25B' || $btype == 'I25B+') {
  28488. $this->Rect($x, $y, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  28489. $this->Rect($x, $y+$tlm+$bch, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  28490. }
  28491. // Restore **************
  28492. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  28493. $this->DrawColor = $prevDrawColor;
  28494. $this->TextColor = $prevTextColor;
  28495. $this->FillColor = $prevFillColor;
  28496. $this->SetLineWidth($lw);
  28497. $this->SetY($y);
  28498. }
  28499. /*-- END BARCODES --*/
  28500. // ====================================================
  28501. // ====================================================
  28502. function StartTransform($returnstring=false) {
  28503. if ($returnstring) { return('q'); }
  28504. else { $this->_out('q'); }
  28505. }
  28506. function StopTransform($returnstring=false) {
  28507. if ($returnstring) { return('Q'); }
  28508. else { $this->_out('Q'); }
  28509. }
  28510. function transformScale($s_x, $s_y, $x='', $y='', $returnstring=false) {
  28511. if ($x === '') {
  28512. $x=$this->x;
  28513. }
  28514. if ($y === '') {
  28515. $y=$this->y;
  28516. }
  28517. if (($s_x == 0) OR ($s_y == 0)) {
  28518. $this->Error('Please do not use values equal to zero for scaling');
  28519. }
  28520. $y = ($this->h - $y) * _MPDFK;
  28521. $x *= _MPDFK;
  28522. //calculate elements of transformation matrix
  28523. $s_x /= 100;
  28524. $s_y /= 100;
  28525. $tm[0] = $s_x;
  28526. $tm[1] = 0;
  28527. $tm[2] = 0;
  28528. $tm[3] = $s_y;
  28529. $tm[4] = $x * (1 - $s_x);
  28530. $tm[5] = $y * (1 - $s_y);
  28531. //scale the coordinate system
  28532. if ($returnstring) { return($this->_transform($tm, true)); }
  28533. else { $this->_transform($tm); }
  28534. }
  28535. function transformTranslate($t_x, $t_y, $returnstring=false) {
  28536. //calculate elements of transformation matrix
  28537. $tm[0] = 1;
  28538. $tm[1] = 0;
  28539. $tm[2] = 0;
  28540. $tm[3] = 1;
  28541. $tm[4] = $t_x * _MPDFK;
  28542. $tm[5] = -$t_y * _MPDFK;
  28543. //translate the coordinate system
  28544. if ($returnstring) { return($this->_transform($tm, true)); }
  28545. else { $this->_transform($tm); }
  28546. }
  28547. function transformRotate($angle, $x='', $y='', $returnstring=false) {
  28548. if ($x === '') {
  28549. $x=$this->x;
  28550. }
  28551. if ($y === '') {
  28552. $y=$this->y;
  28553. }
  28554. $angle = -$angle;
  28555. $y = ($this->h - $y) * _MPDFK;
  28556. $x *= _MPDFK;
  28557. //calculate elements of transformation matrix
  28558. $tm[0] = cos(deg2rad($angle));
  28559. $tm[1] = sin(deg2rad($angle));
  28560. $tm[2] = -$tm[1];
  28561. $tm[3] = $tm[0];
  28562. $tm[4] = $x + $tm[1] * $y - $tm[0] * $x;
  28563. $tm[5] = $y - $tm[0] * $y - $tm[1] * $x;
  28564. //rotate the coordinate system around ($x,$y)
  28565. if ($returnstring) { return($this->_transform($tm, true)); }
  28566. else { $this->_transform($tm); }
  28567. }
  28568. function _transform($tm, $returnstring=false) {
  28569. if ($returnstring) { return(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  28570. else { $this->_out(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  28571. }
  28572. /*-- INDIC --*/
  28573. // INDIC ============================
  28574. // This conversion can only be done when font is set
  28575. function ConvertIndic(&$str) {
  28576. if (preg_match('/^ind_([a-z]{2})_/',$this->currentfontfamily, $m)) {
  28577. if (!class_exists('indic', false)) { include(_MPDF_PATH.'classes/indic.php'); }
  28578. if (empty($this->indic)) { $this->indic = new indic($this); }
  28579. $earr = $this->UTF8StringToArray($str, false);
  28580. $str = $this->indic->substituteIndic($earr, $m[1], $this->currentfontfamily);
  28581. }
  28582. }
  28583. /*-- END INDIC --*/
  28584. // AUTOFONT =========================
  28585. function AutoFont($html) {
  28586. if ($this->onlyCoreFonts) { return $html; }
  28587. $this->useLang = true;
  28588. if ($this->autoFontGroupSize == 1) { $extra = $this->pregASCIIchars1; }
  28589. else if ($this->autoFontGroupSize == 3) { $extra = $this->pregASCIIchars3; }
  28590. else { $extra = $this->pregASCIIchars2; }
  28591. $n = '';
  28592. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  28593. foreach($a as $i => $e) {
  28594. if($i%2==0) {
  28595. $e = strcode2utf($e);
  28596. $e = $this->lesser_entity_decode($e);
  28597. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28598. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28599. /*-- CJK-FONTS --*/
  28600. if ($this->autoFontGroups & AUTOFONT_CJK) {
  28601. $e = preg_replace("/([".$this->pregCJKchars.$extra."]*[".$this->pregCJKchars."][".$this->pregCJKchars.$extra."]*)/ue", '$this->replaceCJK(stripslashes(\'\\1\'))', $e);
  28602. }
  28603. /*-- END CJK-FONTS --*/
  28604. /*-- RTL --*/
  28605. if ($this->autoFontGroups & AUTOFONT_RTL) {
  28606. // HEBREW
  28607. $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);
  28608. // All Arabic
  28609. $e = preg_replace("/([".$this->pregARABICchars .$extra."]*[".$this->pregARABICchars ."][".$this->pregARABICchars .$extra."]*)/ue", '$this->replaceArabic(stripslashes(\'\\1\'))', $e);
  28610. }
  28611. /*-- END RTL --*/
  28612. /*-- INDIC --*/
  28613. // INDIC
  28614. if ($this->autoFontGroups & AUTOFONT_INDIC) {
  28615. // Bengali
  28616. $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);
  28617. // Devanagari (= script for Hindi, Nepali + Sindhi)
  28618. $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);
  28619. // Gujarati
  28620. $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);
  28621. // Malayalam
  28622. $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);
  28623. // Kannada
  28624. $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);
  28625. // Oriya
  28626. $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);
  28627. // Punjabi ?= Gurmuhki
  28628. $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);
  28629. // Tamil
  28630. $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);
  28631. // Telugu
  28632. $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);
  28633. }
  28634. /*-- END INDIC --*/
  28635. if ($this->autoFontGroups & AUTOFONT_THAIVIET) {
  28636. // THAI
  28637. $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);
  28638. // Vietnamese
  28639. $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);
  28640. }
  28641. $e = preg_replace('/[&]/','&amp;',$e);
  28642. $e = preg_replace('/[<]/','&lt;',$e);
  28643. $e = preg_replace('/[>]/','&gt;',$e);
  28644. $e = preg_replace("/(\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1)\s+/",' \\1',$e);
  28645. $e = preg_replace("/[ ]+(\xef\xbf\xb0\/span\xef\xbf\xb1)/",'\\1 ',$e);
  28646. $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);
  28647. $e = preg_replace("/\xef\xbf\xb0/",'<',$e);
  28648. $e = preg_replace("/\xef\xbf\xb1/",'>',$e);
  28649. $a[$i] = $e;
  28650. }
  28651. else {
  28652. $a[$i] = '<'.$e.'>';
  28653. }
  28654. }
  28655. $n = implode('',$a);
  28656. return $n;
  28657. }
  28658. /*-- CJK-FONTS --*/
  28659. function replaceCJK($str) {
  28660. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28661. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28662. if (preg_match("/[".$this->pregUHCchars."]/u", $str)) {
  28663. return "\xef\xbf\xb0span lang=\"ko\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28664. }
  28665. else if (preg_match("/[".$this->pregSJISchars."]/u", $str)) {
  28666. return "\xef\xbf\xb0span lang=\"ja\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28667. }
  28668. // if in Unicode Plane 2, probably HKCS (incl in BIG5) if not Japanese
  28669. else if (preg_match("/[\x{20000}-\x{2FFFF}]/u", $str)) {
  28670. return "\xef\xbf\xb0span lang=\"zh-HK\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28671. }
  28672. else{
  28673. return "\xef\xbf\xb0span lang=\"zh-CN\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  28674. }
  28675. return $str;
  28676. }
  28677. /*-- END CJK-FONTS --*/
  28678. /*-- RTL --*/
  28679. function replaceArabic($str) {
  28680. // PASHTO, SINDHI, URDU, ARABIC, PERSIAN
  28681. $persian = "\x{067E}\x{0686}\x{0698}\x{06AF}";
  28682. $urdu = "\x{0679}\x{0688}\x{0691}\x{06BA}\x{06BE}\x{06C1}\x{06D2}";
  28683. $pashto = "\x{067C}\x{0681}\x{0685}\x{0689}\x{0693}\x{0696}\x{069A}\x{06BC}\x{06D0}"; // ? and U+06AB, U+06CD
  28684. $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}";
  28685. // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  28686. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  28687. if (preg_match("/[".$this->pregNonARABICchars ."]/u", $str) ) {
  28688. if (preg_match("/[".$sindhi ."]/u", $str) ) {
  28689. return "\xef\xbf\xb0span lang=\"sd\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28690. }
  28691. else if (preg_match("/[".$urdu ."]/u", $str) ) {
  28692. return "\xef\xbf\xb0span lang=\"ur\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28693. }
  28694. else if (preg_match("/[".$pashto ."]/u", $str) ) {
  28695. return "\xef\xbf\xb0span lang=\"ps\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28696. }
  28697. else if (preg_match("/[".$persian ."]/u", $str) ) {
  28698. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28699. }
  28700. else {
  28701. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28702. }
  28703. }
  28704. if (preg_match("/[".$persian ."]/u", $str) ) {
  28705. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28706. }
  28707. else {
  28708. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  28709. }
  28710. return $str;
  28711. }
  28712. // ARABIC ===========================
  28713. // mPDF 5.4.08
  28714. function InitArabic() {
  28715. // JOIN TO FOLLOWING LETTER IN LOGICAL ORDER (i.e. AS INITIAL)
  28716. $this->arabPrevLink = "";
  28717. // U+060c; U+061b; U+061f; U+0626; U+0628;
  28718. $this->arabPrevLink .= "\xd8\x8c\xd8\x9b\xd8\x9f\xd8\xa6\xd8\xa8";
  28719. // U+062a; U+062b; U+062c; U+062d; U+062e;
  28720. $this->arabPrevLink .= "\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae";
  28721. // U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; U+0639; U+063a;
  28722. $this->arabPrevLink .= "\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba";
  28723. // U+0640; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; U+0647; U+0649; U+064a;
  28724. $this->arabPrevLink .= "\xd9\x80\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x89\xd9\x8a";
  28725. // U+0678; U+0679; U+067a; U+067b; U+067c; U+067d; U+067e; U+067f;
  28726. $this->arabPrevLink .= "\xd9\xb8\xd9\xb9\xd9\xba\xd9\xbb\xd9\xbc\xd9\xbd\xd9\xbe\xd9\xbf";
  28727. // U+0680; U+0681; U+0682; U+0683; U+0684; U+0685; U+0686; U+0687;
  28728. $this->arabPrevLink .= "\xda\x80\xda\x81\xda\x82\xda\x83\xda\x84\xda\x85\xda\x86\xda\x87";
  28729. // U+069a; U+069b; U+069c; U+069d; U+069e; U+069f;
  28730. $this->arabPrevLink .= "\xda\x9a\xda\x9b\xda\x9c\xda\x9d\xda\x9e\xda\x9f";
  28731. // U+06a0; U+06a1; U+06a2; U+06a3; U+06a4; U+06a5; U+06a6; U+06A7; U+06A8;
  28732. $this->arabPrevLink .= "\xda\xa0\xda\xa1\xda\xa2\xda\xa3\xda\xa4\xda\xa5\xda\xa6\xda\xa7\xda\xa8";
  28733. // U+06a9; U+06aa; U+06ab; U+06ac; U+06ad; U+06ae; U+06af;
  28734. $this->arabPrevLink .= "\xda\xa9\xda\xaa\xda\xab\xda\xac\xda\xad\xda\xae\xda\xaf";
  28735. // U+06b0; U+06b1; U+06b2; U+06b3; U+06b4; U+06b5; U+06b6; U+06b7; U+06b8; U+06b9;
  28736. $this->arabPrevLink .= "\xda\xb0\xda\xb1\xda\xb2\xda\xb3\xda\xb4\xda\xb5\xda\xb6\xda\xb7\xda\xb8\xda\xb9";
  28737. // U+06ba; U+06bb; U+06bc; U+06be; U+06bf;
  28738. $this->arabPrevLink .= "\xda\xba\xda\xbb\xda\xbc\xda\xbe\xda\xbf";
  28739. // U+06c1; U+06cc; U+06ce; U+06d0; U+06d1;
  28740. $this->arabPrevLink .= "\xdb\x81\xdb\x8c\xdb\x8e\xdb\x90\xdb\x91";
  28741. // JOIN TO PREVIOUS LETTER IN LOGICAL ORDER (i.e. AS FINAL FORM)
  28742. $this->arabNextLink = "";
  28743. // U+0622; U+0623; U+0624; U+0625; U+0626; U+0627; U+0628; U+0629;
  28744. $this->arabNextLink .= "\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa6\xd8\xa7\xd8\xa8\xd8\xa9";
  28745. // U+062A; U+062B; U+062C; U+062D; U+062E; U+062F;
  28746. $this->arabNextLink .= "\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf";
  28747. // U+0630; U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; U+0639; U+063A;
  28748. $this->arabNextLink .= "\xd8\xb0\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba";
  28749. // U+0640; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; U+0647; U+0648; U+0649; U+064A;
  28750. $this->arabNextLink .= "\xd9\x80\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x88\xd9\x89\xd9\x8a";
  28751. // U+0671; U+0672; U+0675; U+0676; U+0677; U+0678; U+0679;
  28752. $this->arabNextLink .= "\xd9\xb1\xd9\xb2\xd9\xb5\xd9\xb6\xd9\xb7\xd9\xb8\xd9\xb9";
  28753. // U+067A; U+067B; U+067C; U+067D; U+067E; U+067F;
  28754. $this->arabNextLink .= "\xd9\xba\xd9\xbb\xd9\xbc\xd9\xbd\xd9\xbe\xd9\xbf";
  28755. // U+0680; U+0681; U+0682; U+0683; U+0684; U+0685; U+0686; U+0687; U+0688; U+0689;
  28756. $this->arabNextLink .= "\xda\x80\xda\x81\xda\x82\xda\x83\xda\x84\xda\x85\xda\x86\xda\x87\xda\x88\xda\x89";
  28757. // U+068A; U+068B; U+068C; U+068D; U+068F;U+068F;
  28758. $this->arabNextLink .= "\xda\x8a\xda\x8b\xda\x8c\xda\x8d\xda\x8e\xda\x8f";
  28759. // U+0690; U+0691; U+0692; U+0693; U+0694; U+0695; U+0696; U+0697; U+0698; U+0699;
  28760. $this->arabNextLink .= "\xda\x90\xda\x91\xda\x92\xda\x93\xda\x94\xda\x95\xda\x96\xda\x97\xda\x98\xda\x99";
  28761. // U+069A; U+069B; U+069C; U+069D; U+069E; U+069F;
  28762. $this->arabNextLink .= "\xda\x9a\xda\x9b\xda\x9c\xda\x9d\xda\x9e\xda\x9f";
  28763. // U+06A0; U+06A1; U+06A2; U+06A3; U+06A4; U+06A5; U+06A6; U+06A7; U+06A8; U+06A9;
  28764. $this->arabNextLink .= "\xda\xa0\xda\xa1\xda\xa2\xda\xa3\xda\xa4\xda\xa5\xda\xa6\xda\xa7\xda\xa8\xda\xa9";
  28765. // U+06AA; U+06AB; U+06AC; U+06AD; U+06AE; U+06AF;
  28766. $this->arabNextLink .= "\xda\xaa\xda\xab\xda\xac\xda\xad\xda\xae\xda\xaf";
  28767. // U+06B0; U+06B1; U+06B2; U+06B3; U+06B4; U+06B5; U+06B6; U+06B7; U+06B8; U+06B9;
  28768. $this->arabNextLink .= "\xda\xb0\xda\xb1\xda\xb2\xda\xb3\xda\xb4\xda\xb5\xda\xb6\xda\xb7\xda\xb8\xda\xb9";
  28769. // U+06BA; U+06BB; U+06BC; U+06BE; U+06BF;
  28770. $this->arabNextLink .= "\xda\xba\xda\xbb\xda\xbc\xda\xbe\xda\xbf";
  28771. // U+06C0; U+06C1; U+06C2; U+06C3; U+06C4; U+06C5; U+06C6; U+06C7; U+06C8; U+06C9;
  28772. $this->arabNextLink .= "\xdb\x80\xdb\x81\xdb\x82\xdb\x83\xdb\x84\xdb\x85\xdb\x86\xdb\x87\xdb\x88\xdb\x89";
  28773. // U+06CA; U+06CB; U+06CC; U+06CD; U+06CE; U+06CF;
  28774. $this->arabNextLink .= "\xdb\x8a\xdb\x8b\xdb\x8c\xdb\x8d\xdb\x8e\xdb\x8f";
  28775. // U+06D0; U+06d1; U+06D2; U+06D3;
  28776. $this->arabNextLink .= "\xdb\x90\xdb\x91\xdb\x92\xdb\x93";
  28777. // VOWELS ++
  28778. // U+064b U+064c; U+064d; U+064e; U+064f; U+0650; U+0651; U+0652;
  28779. $this->arabVowels = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  28780. // Added chars that may not be vowels but should not interrupt joining
  28781. // U+0670; U+0653;
  28782. $this->arabVowels .= "\xd9\xb0\xd9\x93";
  28783. // ? should also add - U+615, 616, 617-61A, 653-65E, 6D6-6DC, 6DF-6E4, 6E7, 6E8, 6EA-6ED
  28784. // ISOLATED FORM :: FINAL :: INITIAL :: MEDIAL
  28785. // FB** - FE** = Arabic presentation Forms
  28786. // F5** F6** F7** = Private use area used by unAGlyphs in mPDF
  28787. $this->arabGlyphs = array(
  28788. "\xd8\x8c"=>array("\xd8\x8c", "\xd8\x8c", "\xd8\x8c", "\xd8\x8c"), /* 060C, 060C, 060C, 060C */
  28789. "\xd8\x9b"=>array("\xd8\x9b", "\xd8\x9b", "\xd8\x9b", "\xd8\x9b"), /* 061B, 061B, 061B, 061B */
  28790. "\xd8\x9f"=>array("\xd8\x9f", "\xd8\x9f", "\xd8\x9f", "\xd8\x9f"), /* 061F, 061F, 061F, 061F */
  28791. "\xd8\xa1"=>array("\xd8\xa1", "\xd8\xa1", "\xd8\xa1", "\xd8\xa1"), /* 0621, 0621, 0621, 0621 */
  28792. "\xd8\xa2"=>array("\xd8\xa2", "\xef\xba\x82", "\xd8\xa2", "\xef\xba\x82"), /* 0622, FE82, 0622, FE82 */
  28793. "\xd8\xa3"=>array("\xd8\xa3", "\xef\xba\x84", "\xd8\xa3", "\xef\xba\x84"), /* 0623, FE84, 0623, FE84 */
  28794. "\xd8\xa4"=>array("\xd8\xa4", "\xef\xba\x86", "\xd8\xa4", "\xef\xba\x86"), /* 0624, FE86, 0624, FE86 */
  28795. "\xd8\xa5"=>array("\xd8\xa5", "\xef\xba\x88", "\xd8\xa5", "\xef\xba\x88"), /* 0625, FE88, 0625, FE88 */
  28796. "\xd8\xa6"=>array("\xd8\xa6", "\xef\xba\x8a", "\xef\xba\x8b", "\xef\xba\x8c"), /* 0626, FE8A, FE8B, FE8C */
  28797. "\xd8\xa7"=>array("\xd8\xa7", "\xef\xba\x8e", "\xd8\xa7", "\xef\xba\x8e"), /* 0627, FE8E, 0627, FE8E */
  28798. "\xd8\xa8"=>array("\xd8\xa8", "\xef\xba\x90", "\xef\xba\x91", "\xef\xba\x92"), /* 0628, FE90, FE91, FE92 */
  28799. "\xd8\xa9"=>array("\xd8\xa9", "\xef\xba\x94", "\xd8\xa9", "\xef\xba\x94"), /* 0629, FE94, 0629, FE94 */
  28800. "\xd8\xaa"=>array("\xd8\xaa", "\xef\xba\x96", "\xef\xba\x97", "\xef\xba\x98"), /* 062A, FE96, FE97, FE98 */
  28801. "\xd8\xab"=>array("\xd8\xab", "\xef\xba\x9a", "\xef\xba\x9b", "\xef\xba\x9c"), /* 062B, FE9A, FE9B, FE9C */
  28802. "\xd8\xac"=>array("\xd8\xac", "\xef\xba\x9e", "\xef\xba\x9f", "\xef\xba\xa0"), /* 062C, FE9E, FE9F, FEA0 */
  28803. "\xd8\xad"=>array("\xd8\xad", "\xef\xba\xa2", "\xef\xba\xa3", "\xef\xba\xa4"), /* 062D, FEA2, FEA3, FEA4 */
  28804. "\xd8\xae"=>array("\xd8\xae", "\xef\xba\xa6", "\xef\xba\xa7", "\xef\xba\xa8"), /* 062E, FEA6, FEA7, FEA8 */
  28805. "\xd8\xaf"=>array("\xd8\xaf", "\xef\xba\xaa", "\xd8\xaf", "\xef\xba\xaa"), /* 062F, FEAA, 062F, FEAA */
  28806. "\xd8\xb0"=>array("\xd8\xb0", "\xef\xba\xac", "\xd8\xb0", "\xef\xba\xac"), /* 0630, FEAC, 0630, FEAC */
  28807. "\xd8\xb1"=>array("\xd8\xb1", "\xef\xba\xae", "\xd8\xb1", "\xef\xba\xae"), /* 0631, FEAE, 0631, FEAE */
  28808. "\xd8\xb2"=>array("\xd8\xb2", "\xef\xba\xb0", "\xd8\xb2", "\xef\xba\xb0"), /* 0632, FEB0, 0632, FEB0 */
  28809. "\xd8\xb3"=>array("\xd8\xb3", "\xef\xba\xb2", "\xef\xba\xb3", "\xef\xba\xb4"), /* 0633, FEB2, FEB3, FEB4 */
  28810. "\xd8\xb4"=>array("\xd8\xb4", "\xef\xba\xb6", "\xef\xba\xb7", "\xef\xba\xb8"), /* 0634, FEB6, FEB7, FEB8 */
  28811. "\xd8\xb5"=>array("\xd8\xb5", "\xef\xba\xba", "\xef\xba\xbb", "\xef\xba\xbc"), /* 0635, FEBA, FEBB, FEBC */
  28812. "\xd8\xb6"=>array("\xd8\xb6", "\xef\xba\xbe", "\xef\xba\xbf", "\xef\xbb\x80"), /* 0636, FEBE, FEBF, FEC0 */
  28813. "\xd8\xb7"=>array("\xd8\xb7", "\xef\xbb\x82", "\xef\xbb\x83", "\xef\xbb\x84"), /* 0637, FEC2, FEC3, FEC4 */
  28814. "\xd8\xb8"=>array("\xd8\xb8", "\xef\xbb\x86", "\xef\xbb\x87", "\xef\xbb\x88"), /* 0638, FEC6, FEC7, FEC8 */
  28815. "\xd8\xb9"=>array("\xd8\xb9", "\xef\xbb\x8a", "\xef\xbb\x8b", "\xef\xbb\x8c"), /* 0639, FECA, FECB, FECC */
  28816. "\xd8\xba"=>array("\xd8\xba", "\xef\xbb\x8e", "\xef\xbb\x8f", "\xef\xbb\x90"), /* 063A, FECE, FECF, FED0 */
  28817. "\xd9\x80"=>array("\xd9\x80", "\xd9\x80", "\xd9\x80", "\xd9\x80"), /* 0640, 0640, 0640, 0640 */
  28818. "\xd9\x81"=>array("\xd9\x81", "\xef\xbb\x92", "\xef\xbb\x93", "\xef\xbb\x94"), /* 0641, FED2, FED3, FED4 */
  28819. "\xd9\x82"=>array("\xd9\x82", "\xef\xbb\x96", "\xef\xbb\x97", "\xef\xbb\x98"), /* 0642, FED6, FED7, FED8 */
  28820. "\xd9\x83"=>array("\xd9\x83", "\xef\xbb\x9a", "\xef\xbb\x9b", "\xef\xbb\x9c"), /* 0643, FEDA, FEDB, FEDC */
  28821. "\xd9\x84"=>array("\xd9\x84", "\xef\xbb\x9e", "\xef\xbb\x9f", "\xef\xbb\xa0"), /* 0644, FEDE, FEDF, FEE0 */
  28822. "\xd9\x85"=>array("\xd9\x85", "\xef\xbb\xa2", "\xef\xbb\xa3", "\xef\xbb\xa4"), /* 0645, FEE2, FEE3, FEE4 */
  28823. "\xd9\x86"=>array("\xd9\x86", "\xef\xbb\xa6", "\xef\xbb\xa7", "\xef\xbb\xa8"), /* 0646, FEE6, FEE7, FEE8 */
  28824. "\xd9\x87"=>array("\xd9\x87", "\xef\xbb\xaa", "\xef\xbb\xab", "\xef\xbb\xac"), /* 0647, FEEA, FEEB, FEEC */
  28825. "\xd9\x88"=>array("\xd9\x88", "\xef\xbb\xae", "\xd9\x88", "\xef\xbb\xae"), /* 0648, FEEE, 0648, FEEE */
  28826. /* 0649 Alef Maksura should only appear at end of word (in Arabic) So Initial and medial are shown as isolated/final */
  28827. "\xd9\x89"=>array("\xd9\x89", "\xef\xbb\xb0", "\xd9\x89", "\xef\xbb\xb0"), /* 0649, FEF0, 0649, FEF0 */
  28828. /* 0649 Alef Maksura Initial and Medial forms as given in Unicode FBE8 and FBE9 for Uighur Kazakh (not in some fonts) */
  28829. "\xd9\x89"=>array("\xd9\x89", "\xef\xbb\xb0", "\xef\xaf\xa8", "\xef\xaf\xa9"), /* 0649, FEF0, FBE8, FBE9 not in most fonts */
  28830. "\xd9\x8a"=>array("\xd9\x8a", "\xef\xbb\xb2", "\xef\xbb\xb3", "\xef\xbb\xb4"), /* 064A, FEF2, FEF3, FEF4 */
  28831. "\xd9\x8b"=>array("\xd9\x8b", "\xd9\x8b", "\xd9\x8b", "\xd9\x8b"), /* 064B, 064B, 064B, 064B */
  28832. "\xd9\x8c"=>array("\xd9\x8c", "\xd9\x8c", "\xd9\x8c", "\xd9\x8c"), /* 064C, 064C, 064C, 064C */
  28833. "\xd9\x8d"=>array("\xd9\x8d", "\xd9\x8d", "\xd9\x8d", "\xd9\x8d"), /* 064D, 064D, 064D, 064D */
  28834. "\xd9\x8e"=>array("\xd9\x8e", "\xd9\x8e", "\xd9\x8e", "\xd9\x8e"), /* 064E, 064E, 064E, 064E */
  28835. "\xd9\x8f"=>array("\xd9\x8f", "\xd9\x8f", "\xd9\x8f", "\xd9\x8f"), /* 064F, 064F, 064F, 064F */
  28836. "\xd9\x90"=>array("\xd9\x90", "\xd9\x90", "\xd9\x90", "\xd9\x90"), /* 0650, 0650, 0650, 0650 */
  28837. "\xd9\x91"=>array("\xd9\x91", "\xd9\x91", "\xd9\x91", "\xd9\x91"), /* 0651, 0651, 0651, 0651 */
  28838. "\xd9\x92"=>array("\xd9\x92", "\xd9\x92", "\xd9\x92", "\xd9\x92"), /* 0652, 0652, 0652, 0652 */
  28839. "\xd9\xb1"=>array("\xd9\xb1", "\xef\xad\x91", "\xd9\xb1", "\xef\xad\x91"), /* 0671, FB51, 0671, FB51 */
  28840. "\xd9\xb2"=>array("\xd9\xb2", "\xef\x95\xb2", "\xd9\xb2", "\xef\x95\xb2"), /* 0672, F572, 0672, F572 */
  28841. "\xd9\xb5"=>array("\xd9\xb5", "\xef\x95\xb5", "\xd9\xb5", "\xef\x95\xb5"), /* 0675, F575, 0675, F575 */
  28842. "\xd9\xb8"=>array("\xd9\xb8", "\xef\x95\xb8", "\xef\xba\x8b", "\xef\xba\x8c"), /* 0678, F578, FE8B, FE8C ( as 0626 ) */
  28843. "\xd9\xb9"=>array("\xd9\xb9", "\xef\xad\xa7", "\xef\xad\xa8", "\xef\xad\xa9"), /* 0679, FB67, FB68, FB69 */
  28844. "\xd9\xba"=>array("\xd9\xba", "\xef\xad\x9f", "\xef\xad\xa0", "\xef\xad\xa1"), /* 067A, FB5F, FB60, FB61 */
  28845. "\xd9\xbb"=>array("\xd9\xbb", "\xef\xad\x93", "\xef\xad\x94", "\xef\xad\x95"), /* 067B, FB53, FB54, FB55 */
  28846. "\xd9\xbc"=>array("\xd9\xbc", "\xef\x95\xbc", "\xef\x99\xbc", "\xef\x9d\xbc"), /* 067C, F57C, F67C, F77C */
  28847. "\xd9\xbd"=>array("\xd9\xbd", "\xef\x95\xbd", "\xef\x99\xbd", "\xef\x9d\xbd"), /* 067D, F57D, F67D, F77D */
  28848. "\xd9\xbe"=>array("\xd9\xbe", "\xef\xad\x97", "\xef\xad\x98", "\xef\xad\x99"), /* 067E, FB57, FB58, FB59 */
  28849. "\xd9\xbf"=>array("\xd9\xbf", "\xef\xad\xa3", "\xef\xad\xa4", "\xef\xad\xa5"), /* 067F, FB63, FB64, FB65 */
  28850. "\xda\x80"=>array("\xda\x80", "\xef\xad\x9b", "\xef\xad\x9c", "\xef\xad\x9d"), /* 0680, FB5B, FB5C, FB5D */
  28851. "\xda\x81"=>array("\xda\x81", "\xef\x96\x81", "\xef\x9a\x81", "\xef\x9e\x81"), /* 0681, F581, F681, F781 */
  28852. "\xda\x82"=>array("\xda\x82", "\xef\x96\x82", "\xef\x9a\x82", "\xef\x9e\x82"), /* 0682, F582, F682, F782 */
  28853. "\xda\x83"=>array("\xda\x83", "\xef\xad\xb7", "\xef\xad\xb8", "\xef\xad\xb9"), /* 0683, FB77, FB78, FB79 */
  28854. "\xda\x84"=>array("\xda\x84", "\xef\xad\xb3", "\xef\xad\xb4", "\xef\xad\xb5"), /* 0684, FB73, FB74, FB75 */
  28855. "\xda\x85"=>array("\xda\x85", "\xef\x96\x85", "\xef\x9a\x85", "\xef\x9e\x85"), /* 0685, F585, F685, F785 */
  28856. "\xda\x86"=>array("\xda\x86", "\xef\xad\xbb", "\xef\xad\xbc", "\xef\xad\xbd"), /* 0686, FB7B, FB7C, FB7D */
  28857. "\xda\x87"=>array("\xda\x87", "\xef\xad\xbf", "\xef\xae\x80", "\xef\xae\x81"), /* 0687, FB7F, FB80, FB81 */
  28858. "\xda\x88"=>array("\xda\x88", "\xef\xae\x89", "\xda\x88", "\xda\x88"), /* 0688, FB89, 0688, 0688 */
  28859. "\xda\x89"=>array("\xda\x89", "\xef\x96\x89", "\xda\x89", "\xda\x89"), /* 0689, F589, 0689, 0689 */
  28860. "\xda\x91"=>array("\xda\x91", "\xef\xae\x8d", "\xda\x91", "\xef\xae\x8d"), /* 0691, FB8D, 0691, FB8D */
  28861. "\xda\x93"=>array("\xda\x93", "\xef\x96\x93", "\xda\x93", "\xda\x93"), /* 0693, F593, 0693, 0693 */
  28862. "\xda\x96"=>array("\xda\x96", "\xef\x96\x96", "\xda\x96", "\xda\x96"), /* 0696, F596, 0696, 0696 */
  28863. "\xda\x98"=>array("\xda\x98", "\xef\xae\x8b", "\xda\x98", "\xef\xae\x8b"), /* 0698, FB8B, 0698, FB8B */
  28864. "\xda\x9a"=>array("\xda\x9a", "\xef\x96\x9a", "\xef\x9a\x9a", "\xef\x9e\x9a"), /* 069A, F59A, F69A, F79A */
  28865. "\xda\x9b"=>array("\xda\x9b", "\xef\x96\x9b", "\xef\x9a\x9b", "\xef\x9e\x9b"), /* 069B, F59B, F69B, F79B */
  28866. "\xda\x9c"=>array("\xda\x9c", "\xef\x96\x9c", "\xef\x9a\x9c", "\xef\x9e\x9c"), /* 069C, F59C, F69C, F79C */
  28867. "\xda\x9d"=>array("\xda\x9d", "\xef\x96\x9d", "\xef\x9a\x9d", "\xef\x9e\x9d"), /* 069D, F59D, F69D, F79D */
  28868. "\xda\x9e"=>array("\xda\x9e", "\xef\x96\x9e", "\xef\x9a\x9e", "\xef\x9e\x9e"), /* 069E, F59E, F69E, F79E */
  28869. "\xda\xa0"=>array("\xda\xa0", "\xef\x96\xa0", "\xef\x9a\xa0", "\xef\x9e\xa0"), /* 06A0, F5A0, F6A0, F7A0 */
  28870. "\xda\xa1"=>array("\xda\xa1", "\xef\x96\xa1", "\xef\x9a\xa1", "\xef\x9e\xa1"), /* 06A1, F5A1, F6A1, F7A1 */
  28871. "\xda\xa2"=>array("\xda\xa2", "\xef\x96\xa2", "\xef\x9a\xa2", "\xef\x9e\xa2"), /* 06A2, F5A2, F6A2, F7A2 */
  28872. "\xda\xa3"=>array("\xda\xa3", "\xef\x96\xa3", "\xef\x9a\xa3", "\xef\x9e\xa3"), /* 06A3, F5A3, F6A3, F7A3 */
  28873. "\xda\xa4"=>array("\xda\xa4", "\xef\xad\xab", "\xef\xad\xac", "\xef\xad\xad"), /* 06A4, FB6B, FB6C, FB6D */
  28874. "\xda\xa5"=>array("\xda\xa5", "\xef\x96\xa5", "\xef\x9a\xa5", "\xef\x9e\xa5"), /* 06A5, F5A5, F6A5, F7A5 */
  28875. "\xda\xa6"=>array("\xda\xa6", "\xef\xad\xaf", "\xef\xad\xb0", "\xef\xad\xb1"), /* 06A6, FB6F, FB70, FB71 */
  28876. "\xda\xa9"=>array("\xda\xa9", "\xef\xae\x8f", "\xef\xae\x90", "\xef\xae\x91"), /* 06A9, FB8F, FB90, FB91 */
  28877. "\xda\xaa"=>array("\xda\xaa", "\xef\x96\xaa", "\xef\x9a\xaa", "\xef\x9e\xaa"), /* 06AA, F5AA, F6AA, F7AA */
  28878. "\xda\xab"=>array("\xda\xab", "\xef\x96\xab", "\xef\x9a\xab", "\xef\x9e\xab"), /* 06AB, F5AB, F6AB, F7AB */
  28879. "\xda\xac"=>array("\xda\xac", "\xef\x96\xac", "\xef\x9a\xac", "\xef\x9e\xac"), /* 06AC, F5AC, F6AC, F7AC */
  28880. "\xda\xad"=>array("\xda\xad", "\xef\xaf\x94", "\xef\xaf\x95", "\xef\xaf\x96"), /* 06AD, FBD4, FBD5, FBD6 */
  28881. "\xda\xae"=>array("\xda\xae", "\xef\x96\xae", "\xef\x9a\xae", "\xef\x9e\xae"), /* 06AE, F5AE, F6AE, F7AE */
  28882. "\xda\xaf"=>array("\xda\xaf", "\xef\xae\x93", "\xef\xae\x94", "\xef\xae\x95"), /* 06Af, FB93, FB94, FB95 */
  28883. "\xda\xb0"=>array("\xda\xb0", "\xef\x96\xb0", "\xef\x9a\xb0", "\xef\x9e\xb0"), /* 06B0, F5B0, F6B0, F7B0 */
  28884. "\xda\xb1"=>array("\xda\xb1", "\xef\xae\x9b", "\xef\xae\x9c", "\xef\xae\x9d"), /* 06B1, FB9B, FB9C, FB9D */
  28885. "\xda\xb2"=>array("\xda\xb2", "\xef\x96\xb2", "\xef\x9a\xb2", "\xef\x9e\xb2"), /* 06B2, F5B2, F6B2, F7B2 */
  28886. "\xda\xb3"=>array("\xda\xb3", "\xef\xae\x97", "\xef\xae\x98", "\xef\xae\x99"), /* 06B3, FB97, FB98, FB99 */
  28887. "\xda\xb4"=>array("\xda\xb4", "\xef\x96\xb4", "\xef\x9a\xb4", "\xef\x9e\xb4"), /* 06B4, F5B4, F6B4, F7B4 */
  28888. "\xda\xb5"=>array("\xda\xb5", "\xef\x96\xb5", "\xef\x9a\xb5", "\xef\x9e\xb5"), /* 06B5, F5B5, F6B5, F7B5 */
  28889. "\xda\xb6"=>array("\xda\xb6", "\xef\x96\xb6", "\xef\x9a\xb6", "\xef\x9e\xb6"), /* 06B6, F5B6, F6B6, F7B6 */
  28890. "\xda\xb7"=>array("\xda\xb7", "\xef\x96\xb7", "\xef\x9a\xb7", "\xef\x9e\xb7"), /* 06B7, F5B7, F6B7, F7B7 */
  28891. "\xda\xb8"=>array("\xda\xb8", "\xef\x96\xb8", "\xef\x9a\xb8", "\xef\x9e\xb8"), /* 06B8, F5B8, F6B8, F7B8 */
  28892. "\xda\xb9"=>array("\xda\xb9", "\xef\x96\xb9", "\xef\x9a\xb9", "\xef\x9e\xb9"), /* 06B9, F5B9, F6B9, F7B9 */
  28893. "\xda\xba"=>array("\xda\xba", "\xef\xae\x9f", "\xda\xba", "\xda\xba"), /* 06BA, FB9F, 06BA, 06BA */
  28894. "\xda\xbb"=>array("\xda\xbb", "\xef\xae\xa1", "\xef\xae\xa2", "\xef\xae\xa3"), /* 06BB, FBA1, FBA2, FBA3 */
  28895. "\xda\xbc"=>array("\xda\xbc", "\xef\x96\xbc", "\xef\x9a\xbc", "\xef\x9e\xbc"), /* 06BC, F5BC, F6BC, F7BC */
  28896. "\xda\xbe"=>array("\xda\xbe", "\xef\xae\xab", "\xef\xae\xac", "\xef\xae\xad"), /* 06BE, FBAB, FBAC, FBAD */
  28897. "\xda\xbf"=>array("\xda\xbf", "\xef\x96\xbf", "\xef\x9a\xbf", "\xef\x9e\xbf"), /* 06BF, F5BF, F6BF, F7BF */
  28898. "\xdb\x80"=>array("\xdb\x80", "\xef\xae\xa5", "\xdb\x80", "\xef\xae\xa5"), /* 06C0, FBA5, 06C0, FBA5 */
  28899. "\xdb\x81"=>array("\xdb\x81", "\xef\xae\xa7", "\xef\xae\xa8", "\xef\xae\xa9"), /* 06C1, FBA7, FBA8, FBA9 */
  28900. "\xdb\x8c"=>array("\xdb\x8c", "\xef\xaf\xbd", "\xef\xaf\xbe", "\xef\xaf\xbf"), /* 06CC, FBFD, FBFE, FBFF */
  28901. "\xdb\x8d"=>array("\xdb\x8d", "\xef\x97\x8d", "\xdb\x8d", "\xef\x97\x8d"), /* 06CD, F5CD, 06CD, F5CD */
  28902. "\xdb\x8e"=>array("\xdb\x8e", "\xef\x97\x8e", "\xef\x9b\x8e", "\xef\x9f\x8e"), /* 06CE, F5CE, F6CE, F7CE */
  28903. "\xdb\x90"=>array("\xdb\x90", "\xef\xaf\xa5", "\xef\xaf\xa6", "\xef\xaf\xa7"), /* 06D0, FBE5, FBE6, FBE7 */
  28904. "\xdb\x91"=>array("\xdb\x91", "\xef\x97\x91", "\xef\xad\x98", "\xef\xad\x99"), /* 06D1, F5D1, FB58, FB59 Fudge borrows from 067E */
  28905. "\xdb\x92"=>array("\xdb\x92", "\xef\xae\xaf", "\xdb\x92", "\xef\xae\xaf"), /* 06D2, FBAF, 06D2, FBAF */
  28906. "\xdb\x93"=>array("\xdb\x93", "\xef\xae\xb1", "\xdb\x93", "\xef\xae\xb1"), /* 06D3, FBB1, 06D3, FBB1 */
  28907. );
  28908. // LAM with ALEF ligatures (Mandatory ligatures)
  28909. // U+0644; U+0622; U+0644; U+0623; U+0644; U+0625; U+0644; U+0627;
  28910. $this->arabLigGlyphs = "\xd9\x84\xd8\xa2\xd9\x84\xd8\xa3\xd9\x84\xd8\xa5\xd9\x84\xd8\xa7";
  28911. $this->arabLigHex = 'FEF5FEF6FEF5FEF6FEF7FEF8FEF7FEF8FEF9FEFAFEF9FEFAFEFBFEFCFEFBFEFC';
  28912. }
  28913. // mPDF 5.4.08
  28914. function ArabJoin($str) {
  28915. if (!$this->arabGlyphs) { $this->InitArabic(); }
  28916. $crntChar = null;
  28917. $prevChar = null;
  28918. $nextChar = null;
  28919. $output = array();
  28920. $chars = preg_split('//u', $str);
  28921. $max = count($chars);
  28922. for ($i = $max - 1; $i >= 0; $i--) {
  28923. $crntChar = $chars[$i];
  28924. if ($i > 0){ $prevChar = $chars[$i - 1]; }
  28925. else{ $prevChar = NULL; }
  28926. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28927. $prevChar = $chars[$i - 2];
  28928. if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  28929. $prevChar = $chars[$i - 3];
  28930. }
  28931. }
  28932. if ($crntChar && mb_strpos($this->arabVowels, $crntChar, 0, 'utf-8') !== false) {
  28933. // If next_char = nextLink && prev_char = prevLink:
  28934. // Added && $prevchar (defined) else error on mb_strpos()
  28935. 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)) {
  28936. $output[] = $this->get_arab_glyphs($crntChar, 1); // <final> form
  28937. }
  28938. else {
  28939. $output[] = $this->get_arab_glyphs($crntChar, 0); // <isolated> form
  28940. }
  28941. continue;
  28942. }
  28943. // NB = &#x622 &#x623; &#x625; &#x627; &#x644;
  28944. if (isset($chars[$i + 1]) && in_array($chars[$i + 1], array("\xd8\xa2","\xd8\xa3","\xd8\xa5","\xd8\xa7")) && $crntChar == "\xd9\x84"){
  28945. continue;
  28946. }
  28947. if (ord($crntChar) < 128) {
  28948. $output[] = $crntChar;
  28949. $nextChar = $crntChar;
  28950. continue;
  28951. }
  28952. $form = 0;
  28953. if ($prevChar == "\xd9\x84" && ($crntChar == "\xd8\xa2" || $crntChar == "\xd8\xa3" || $crntChar == "\xd8\xa5" || $crntChar == "\xd8\xa7")) {
  28954. if ($chars[$i - 2] && mb_strpos($this->arabPrevLink, $chars[$i - 2], 0, 'utf-8') !== false) {
  28955. $form++; // <final> form
  28956. }
  28957. $pos = mb_strpos($this->arabLigGlyphs, ($prevChar . $crntChar), 0, 'utf-8');
  28958. $pos = $pos*8 + $form*4;
  28959. $pres = (mb_substr($this->arabLigHex, $pos, 4, 'utf-8'));
  28960. // If presentation forms for mandatory ligatures with diacritics not present (even if remapped from e.g. uni0644uni0625)
  28961. // try replacing with mandatory ligature Alef/lam isolated/final FEFB/FEFC + diacritic glyph
  28962. if (!$this->_charDefined($this->CurrentFont['cw'], hexdec($pres)) && $this->_charDefined($this->CurrentFont['cw'], hexdec('FEFB'))) {
  28963. if ($pres=='FEF5') { $output[] = strcode2utf('&#xFEFB;&#x0653;'); }
  28964. else if ($pres=='FEF6') { $output[] = strcode2utf('&#xFEFC;&#x0653;'); }
  28965. else if ($pres=='FEF7') { $output[] = strcode2utf('&#xFEFB;&#x0654;'); }
  28966. else if ($pres=='FEF8') { $output[] = strcode2utf('&#xFEFC;&#x0654;'); }
  28967. else if ($pres=='FEF9') { $output[] = strcode2utf('&#xFEFB;&#x0655;'); }
  28968. else if ($pres=='FEFA') { $output[] = strcode2utf('&#xFEFC;&#x0655;'); }
  28969. }
  28970. else {
  28971. $output[] = strcode2utf('&#x' . $pres . ';');
  28972. }
  28973. $nextChar = $prevChar;
  28974. continue;
  28975. }
  28976. if ($prevChar && mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false) {
  28977. $form++;
  28978. }
  28979. if ($nextChar && mb_strpos($this->arabNextLink, $nextChar, 0, 'utf-8') !== false) {
  28980. $form += 2;
  28981. }
  28982. $output[] = $this->get_arab_glyphs($crntChar, $form) ;
  28983. $nextChar = $crntChar;
  28984. }
  28985. $ra = array_reverse($output);
  28986. $s = implode($ra);
  28987. return $s;
  28988. }
  28989. // mPDF 5.4.08
  28990. function get_arab_glyphs($char, $type) {
  28991. if ($type>0 && isset($this->arabGlyphs[$char])) {
  28992. // If presentation form specified FB** - FE** = Arabic presentation Forms
  28993. if (preg_match("/[\x{FB50}-\x{FEFF}]/u",$this->arabGlyphs[$char][$type])) {
  28994. $unicode = $this->UTF8StringToArray($this->arabGlyphs[$char][$type], false);
  28995. if ($this->_charDefined($this->CurrentFont['cw'],$unicode[0])) { return $this->arabGlyphs[$char][$type]; }
  28996. else if (isset($this->CurrentFont['unAGlyphs'])) {
  28997. $uni = $this->UTF8StringToArray($char, false);
  28998. $pua = $uni[0] - 1536 + 62464 + 256*$type ;
  28999. if ($this->_charDefined($this->CurrentFont['cw'], $pua)) { return strcode2utf('&#x' . dechex($pua) . ';'); }
  29000. else return $char;
  29001. }
  29002. else return $char;
  29003. }
  29004. // If PUA form specified and unAGlphs font set F5** F6** F7** = Private use area used by unAGlyphs in mPDF
  29005. if (preg_match("/[\x{F500}-\x{F7FF}]/u",$this->arabGlyphs[$char][$type]) && isset($this->CurrentFont['unAGlyphs'])) {
  29006. $unicode = $this->UTF8StringToArray($this->arabGlyphs[$char][$type], false);
  29007. if ($this->_charDefined($this->CurrentFont['cw'],$unicode[0])) { return $this->arabGlyphs[$char][$type]; }
  29008. else return $char;
  29009. }
  29010. return $this->arabGlyphs[$char][$type];
  29011. }
  29012. else return $char;
  29013. }
  29014. /*-- END RTL --*/
  29015. //===========================
  29016. // Functions originally in htmltoolkit - moved mPDF 4.0
  29017. // Call-back function Used for usort in fn _tableWrite
  29018. function _cmpdom($a, $b) {
  29019. return ($a["dom"] < $b["dom"]) ? -1 : 1;
  29020. }
  29021. function mb_strrev($str, $enc = 'utf-8'){
  29022. $ch = array();
  29023. $ch = preg_split('//u',$str);
  29024. $revch = array_reverse($ch);
  29025. return implode('',$revch);
  29026. }
  29027. /*-- COLUMNS --*/
  29028. // Callback function from function printcolumnbuffer in mpdf
  29029. function columnAdjustAdd($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  29030. if ($type == 'Td') { // xpos,ypos
  29031. $a += ($xadj * $k);
  29032. $b -= ($yadj * $k);
  29033. return 'BT '.sprintf('%.3F %.3F',$a,$b).' Td';
  29034. }
  29035. else if ($type == 're') { // xpos,ypos,width,height
  29036. $a += ($xadj * $k);
  29037. $b -= ($yadj * $k);
  29038. return sprintf('%.3F %.3F %.3F %.3F',$a,$b,$c,$d).' re';
  29039. }
  29040. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  29041. $a += ($xadj * $k);
  29042. $b -= ($yadj * $k);
  29043. return sprintf('%.3F %.3F l',$a,$b);
  29044. }
  29045. else if ($type == 'img') { // width,height,xpos,ypos
  29046. $c += ($xadj * $k);
  29047. $d -= ($yadj * $k);
  29048. return sprintf('q %.3F 0 0 %.3F %.3F %.3F',$a,$b,$c,$d).' cm /'.$e;
  29049. }
  29050. else if ($type == 'draw') { // xpos,ypos
  29051. $a += ($xadj * $k);
  29052. $b -= ($yadj * $k);
  29053. return sprintf('%.3F %.3F m',$a,$b);
  29054. }
  29055. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  29056. $a += ($xadj * $k);
  29057. $b -= ($yadj * $k);
  29058. $c += ($xadj * $k);
  29059. $d -= ($yadj * $k);
  29060. $e += ($xadj * $k);
  29061. $f -= ($yadj * $k);
  29062. return sprintf('%.3F %.3F %.3F %.3F %.3F %.3F',$a,$b,$c,$d,$e,$f).' c';
  29063. }
  29064. }
  29065. /*-- END COLUMNS --*/
  29066. // Callback function from function printdivbuffer in mpdf - keeping block together on one page
  29067. function blockAdjust($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  29068. if ($type == 'Td') { // xpos,ypos
  29069. $a += ($xadj * $k);
  29070. $b -= ($yadj * $k);
  29071. return 'BT '.sprintf('%.3F %.3F',$a,$b).' Td';
  29072. }
  29073. else if ($type == 're') { // xpos,ypos,width,height
  29074. $a += ($xadj * $k);
  29075. $b -= ($yadj * $k);
  29076. return sprintf('%.3F %.3F %.3F %.3F',$a,$b,$c,$d).' re';
  29077. }
  29078. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  29079. $a += ($xadj * $k);
  29080. $b -= ($yadj * $k);
  29081. return sprintf('%.3F %.3F l',$a,$b);
  29082. }
  29083. else if ($type == 'img') { // width,height,xpos,ypos
  29084. $c += ($xadj * $k);
  29085. $d -= ($yadj * $k);
  29086. return sprintf('q %.3F 0 0 %.3F %.3F %.3F',$a,$b,$c,$d).' cm /'.$e;
  29087. }
  29088. else if ($type == 'draw') { // xpos,ypos
  29089. $a += ($xadj * $k);
  29090. $b -= ($yadj * $k);
  29091. return sprintf('%.3F %.3F m',$a,$b);
  29092. }
  29093. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  29094. $a += ($xadj * $k);
  29095. $b -= ($yadj * $k);
  29096. $c += ($xadj * $k);
  29097. $d -= ($yadj * $k);
  29098. $e += ($xadj * $k);
  29099. $f -= ($yadj * $k);
  29100. return sprintf('%.3F %.3F %.3F %.3F %.3F %.3F',$a,$b,$c,$d,$e,$f).' c';
  29101. }
  29102. }
  29103. function ConvertColor($color="#000000"){
  29104. $color = trim(strtolower($color));
  29105. $c = false;
  29106. if ($color=='transparent') { return false; }
  29107. else if ($color=='inherit') { return false; }
  29108. else if (isset($this->SVGcolors[$color])) $color = $this->SVGcolors[$color];
  29109. if (preg_match('/^[\d]+$/',$color)) { $c = (array(1,$color)); } // i.e. integer only
  29110. else if ($color[0] == '#') { //case of #nnnnnn or #nnn
  29111. $cor = preg_replace('/\s+.*/','',$color); // in case of Background: #CCC url() x-repeat etc.
  29112. if (strlen($cor) == 4) { // Turn #RGB into #RRGGBB
  29113. $cor = "#" . $cor[1] . $cor[1] . $cor[2] . $cor[2] . $cor[3] . $cor[3];
  29114. }
  29115. $r = hexdec(substr($cor, 1, 2));
  29116. $g = hexdec(substr($cor, 3, 2));
  29117. $b = hexdec(substr($cor, 5, 2));
  29118. $c = array(3,$r,$g,$b);
  29119. }
  29120. else if (preg_match('/(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\((.*?)\)/',$color,$m)) {
  29121. $type= $m[1];
  29122. $cores = explode(",", $m[2]);
  29123. $ncores = count($cores);
  29124. if (stristr($cores[0],'%') ) {
  29125. $cores[0] += 0;
  29126. if ($type=='rgb' || $type=='rgba') { $cores[0] = intval($cores[0]*255/100); }
  29127. }
  29128. if ($ncores>1 && stristr($cores[1],'%') ) {
  29129. $cores[1] += 0;
  29130. if ($type=='rgb' || $type=='rgba') { $cores[1] = intval($cores[1]*255/100); }
  29131. if ($type=='hsl' || $type=='hsla') { $cores[1] = $cores[1]/100; }
  29132. }
  29133. if ($ncores>2 && stristr($cores[2],'%') ) {
  29134. $cores[2] += 0;
  29135. if ($type=='rgb' || $type=='rgba') { $cores[2] = intval($cores[2]*255/100); }
  29136. if ($type=='hsl' || $type=='hsla') { $cores[2] = $cores[2]/100; }
  29137. }
  29138. if ($ncores>3 && stristr($cores[3],'%') ) {
  29139. $cores[3] += 0;
  29140. }
  29141. if ($type=='rgb') { $c = array(3,$cores[0],$cores[1],$cores[2]); }
  29142. else if ($type=='rgba') { $c = array(5,$cores[0],$cores[1],$cores[2],$cores[3]*100); }
  29143. else if ($type=='cmyk') { $c = array(4,$cores[0],$cores[1],$cores[2],$cores[3]); }
  29144. else if ($type=='cmyka') { $c = array(6,$cores[0],$cores[1],$cores[2],$cores[3],$cores[4]*100); }
  29145. else if ($type=='hsl' || $type=='hsla') {
  29146. $conv = $this->hsl2rgb($cores[0]/360,$cores[1],$cores[2]);
  29147. if ($type=='hsl') { $c = array(3,$conv[0],$conv[1],$conv[2]); }
  29148. else if ($type=='hsla') { $c = array(5,$conv[0],$conv[1],$conv[2],$cores[3]*100); }
  29149. }
  29150. else if ($type=='spot') {
  29151. $name = strtoupper(trim($cores[0]));
  29152. if(!isset($this->spotColors[$name])) $this->Error('Undefined spot color: '.$name);
  29153. $c = array(2,$this->spotColors[$name]['i'],$cores[1]);
  29154. }
  29155. }
  29156. // $this->restrictColorSpace
  29157. // 1 - allow GRAYSCALE only [convert CMYK/RGB->gray]
  29158. // 2 - allow RGB / SPOT COLOR / Grayscale [convert CMYK->RGB]
  29159. // 3 - allow CMYK / SPOT COLOR / Grayscale [convert RGB->CMYK]
  29160. if ($this->PDFA || $this->PDFX || $this->restrictColorSpace) {
  29161. if ($c[0]==1) { // GRAYSCALE
  29162. }
  29163. else if ($c[0]==2) { // SPOT COLOR
  29164. if (!isset($this->spotColorIDs[$c[1]])) { die('Error: Spot colour has not been defined - '.$this->spotColorIDs[$c[1]]); }
  29165. if ($this->PDFA) {
  29166. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "Spot color specified '".$this->spotColorIDs[$c[1]]."' (converted to process color)"; }
  29167. if ($this->restrictColorSpace!=3) {
  29168. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  29169. $c = $this->cmyk2rgb(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  29170. }
  29171. }
  29172. else if ($this->restrictColorSpace==1) {
  29173. $sp = $this->spotColors[$this->spotColorIDs[$c[1]]];
  29174. $c = $this->cmyk2gray(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k']));
  29175. }
  29176. }
  29177. else if ($c[0]==3) { // RGB
  29178. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  29179. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color specified '".$color."' (converted to CMYK)"; }
  29180. $c = $this->rgb2cmyk($c);
  29181. }
  29182. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  29183. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  29184. }
  29185. else if ($c[0]==4) { // CMYK
  29186. if ($this->PDFA && $this->restrictColorSpace!=3) {
  29187. if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "CMYK color specified '".$color."' (converted to RGB)"; }
  29188. $c = $this->cmyk2rgb($c);
  29189. }
  29190. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  29191. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  29192. }
  29193. else if ($c[0]==5) { // RGBa
  29194. if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  29195. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  29196. $c = $this->rgb2cmyk($c);
  29197. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  29198. }
  29199. else if ($this->PDFA && $this->restrictColorSpace!=3) {
  29200. if (!$this->PDFAauto) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  29201. $c = $this->rgb2cmyk($c);
  29202. $c = array(4, $c[1], $c[2], $c[3], $c[4]);
  29203. }
  29204. else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); }
  29205. else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); }
  29206. }
  29207. else if ($c[0]==6) { // CMYKa
  29208. if ($this->PDFA && $this->restrictColorSpace!=3) {
  29209. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to RGB without transparency)"; }
  29210. $c = $this->cmyk2rgb($c);
  29211. $c = array(3, $c[1], $c[2], $c[3]);
  29212. }
  29213. else if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) {
  29214. if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to CMYK without transparency)"; }
  29215. $c = $this->cmyk2rgb($c);
  29216. $c = array(3, $c[1], $c[2], $c[3]);
  29217. }
  29218. else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); }
  29219. else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); }
  29220. }
  29221. }
  29222. if (is_array($c)) {
  29223. $c = array_pad($c, 6, 0);
  29224. $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) );
  29225. }
  29226. return $cstr;
  29227. }
  29228. function rgb2gray($c) {
  29229. if (isset($c[4])) { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07)), ord(1), $c[4]); }
  29230. else { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07))); }
  29231. }
  29232. function cmyk2gray($c) {
  29233. $rgb = $this->cmyk2rgb($c);
  29234. return $this->rgb2gray($rgb);
  29235. }
  29236. function rgb2cmyk($c) {
  29237. $cyan = 1 - ($c[1] / 255);
  29238. $magenta = 1 - ($c[2] / 255);
  29239. $yellow = 1 - ($c[3] / 255);
  29240. $min = min($cyan, $magenta, $yellow);
  29241. if ($min == 1) {
  29242. if ($c[0]==5) { return array (6,100,100,100,100, $c[4]); }
  29243. else { return array (4,100,100,100,100); }
  29244. // For K-Black
  29245. //if ($c[0]==5) { return array (6,0,0,0,100, $c[4]); }
  29246. //else { return array (4,0,0,0,100); }
  29247. }
  29248. $K = $min;
  29249. $black = 1 - $K;
  29250. if ($c[0]==5) { return array (6,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100, $c[4]); }
  29251. else { return array (4,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100); }
  29252. }
  29253. function cmyk2rgb($c) {
  29254. $rgb = array();
  29255. $colors = 255 - ($c[4]*2.55);
  29256. $rgb[0] = intval($colors * (255 - ($c[1]*2.55))/255);
  29257. $rgb[1] = intval($colors * (255 - ($c[2]*2.55))/255);
  29258. $rgb[2] = intval($colors * (255 - ($c[3]*2.55))/255);
  29259. if ($c[0]==6) { return array (5,$rgb[0],$rgb[1],$rgb[2], $c[5]); }
  29260. else { return array (3,$rgb[0],$rgb[1],$rgb[2]); }
  29261. }
  29262. function rgb2hsl($var_r, $var_g, $var_b) {
  29263. $var_min = min($var_r,$var_g,$var_b);
  29264. $var_max = max($var_r,$var_g,$var_b);
  29265. $del_max = $var_max - $var_min;
  29266. $l = ($var_max + $var_min) / 2;
  29267. if ($del_max == 0) {
  29268. $h = 0;
  29269. $s = 0;
  29270. }
  29271. else {
  29272. if ($l < 0.5) { $s = $del_max / ($var_max + $var_min); }
  29273. else { $s = $del_max / (2 - $var_max - $var_min); }
  29274. $del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max;
  29275. $del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max;
  29276. $del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max;
  29277. if ($var_r == $var_max) { $h = $del_b - $del_g; }
  29278. elseif ($var_g == $var_max) { $h = (1 / 3) + $del_r - $del_b; }
  29279. elseif ($var_b == $var_max) { $h = (2 / 3) + $del_g - $del_r; };
  29280. if ($h < 0) { $h += 1; }
  29281. if ($h > 1) { $h -= 1; }
  29282. }
  29283. return array($h,$s,$l);
  29284. }
  29285. function hsl2rgb($h2,$s2,$l2) {
  29286. // Input is HSL value of complementary colour, held in $h2, $s, $l as fractions of 1
  29287. // Output is RGB in normal 255 255 255 format, held in $r, $g, $b
  29288. // Hue is converted using function hue_2_rgb, shown at the end of this code
  29289. if ($s2 == 0) {
  29290. $r = $l2 * 255;
  29291. $g = $l2 * 255;
  29292. $b = $l2 * 255;
  29293. }
  29294. else {
  29295. if ($l2 < 0.5) { $var_2 = $l2 * (1 + $s2); }
  29296. else { $var_2 = ($l2 + $s2) - ($s2 * $l2); }
  29297. $var_1 = 2 * $l2 - $var_2;
  29298. $r = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 + (1 / 3)));
  29299. $g = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2));
  29300. $b = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 - (1 / 3)));
  29301. }
  29302. return array($r,$g,$b);
  29303. }
  29304. function hue_2_rgb($v1,$v2,$vh) {
  29305. // Function to convert hue to RGB, called from above
  29306. if ($vh < 0) { $vh += 1; };
  29307. if ($vh > 1) { $vh -= 1; };
  29308. if ((6 * $vh) < 1) { return ($v1 + ($v2 - $v1) * 6 * $vh); };
  29309. if ((2 * $vh) < 1) { return ($v2); };
  29310. if ((3 * $vh) < 2) { return ($v1 + ($v2 - $v1) * ((2 / 3 - $vh) * 6)); };
  29311. return ($v1);
  29312. }
  29313. function _invertColor($cor) {
  29314. if ($cor[0]==3 || $cor[0]==5) { // RGB
  29315. return array(3, (255-$cor[1]), (255-$cor[2]), (255-$cor[3]));
  29316. }
  29317. else if ($cor[0]==4 || $cor[0]==6) { // CMYK
  29318. return array(4, (100-$cor[1]), (100-$cor[2]), (100-$cor[3]), (100-$cor[4]));
  29319. }
  29320. else if ($cor[0]==1) { // Grayscale
  29321. return array(1, (255-$cor[1]));
  29322. }
  29323. // Cannot cope with non-RGB colors at present
  29324. die('Error in _invertColor - trying to invert non-RGB color');
  29325. }
  29326. function _colAtoString($cor) {
  29327. $s = '';
  29328. if ($cor{0}==1) $s = 'rgb('.ord($cor{1}).','.ord($cor{1}).','.ord($cor{1}).')';
  29329. else if ($cor{0}==2) $s = 'spot('.ord($cor{1}).','.ord($cor{2}).')'; // SPOT COLOR
  29330. else if ($cor{0}==3) $s = 'rgb('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).')';
  29331. else if ($cor{0}==4) $s = 'cmyk('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.ord($cor{4}).')';
  29332. else if ($cor{0}==5) $s = 'rgba('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.sprintf('%0.2F',ord($cor{4})/100).')';
  29333. 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).')';
  29334. return $s;
  29335. }
  29336. function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){
  29337. // usefontsize - setfalse for e.g. margins - will ignore fontsize for % values
  29338. // Depends of maxsize value to make % work properly. Usually maxsize == pagewidth
  29339. // For text $maxsize = Fontsize
  29340. // Setting e.g. margin % will use maxsize (pagewidth) and em will use fontsize
  29341. //Identify size (remember: we are using 'mm' units here)
  29342. $size = trim(strtolower($size));
  29343. if ( $size == 'thin' ) $size = 1*(25.4/$this->dpi); //1 pixel width for table borders
  29344. elseif ( stristr($size,'px') ) $size *= (25.4/$this->dpi); //pixels
  29345. elseif ( stristr($size,'cm') ) $size *= 10; //centimeters
  29346. elseif ( stristr($size,'mm') ) $size += 0; //millimeters
  29347. elseif ( stristr($size,'pt') ) $size *= 25.4/72; //72 pts/inch
  29348. elseif ( stristr($size,'em') ) {
  29349. $size += 0; //make "0.83em" become simply "0.83"
  29350. if ($fontsize) { $size *= $fontsize; }
  29351. else { $size *= $maxsize; }
  29352. }
  29353. elseif ( stristr($size,'%') ) {
  29354. $size += 0; //make "90%" become simply "90"
  29355. if ($fontsize && $usefontsize) { $size *= $fontsize/100; }
  29356. else { $size *= $maxsize/100; }
  29357. }
  29358. elseif ( stristr($size,'in') ) $size *= 25.4; //inches
  29359. elseif ( stristr($size,'pc') ) $size *= 38.1/9; //PostScript picas
  29360. elseif ( stristr($size,'ex') ) { // Approximates "ex" as half of font height
  29361. $size += 0; //make "3.5ex" become simply "3.5"
  29362. if ($fontsize) { $size *= $fontsize/2; }
  29363. else { $size *= $maxsize/2; }
  29364. }
  29365. elseif ( $size == 'medium' ) $size = 3*(25.4/$this->dpi); //3 pixel width for table borders
  29366. elseif ( $size == 'thick' ) $size = 5*(25.4/$this->dpi); //5 pixel width for table borders
  29367. elseif ($size == 'xx-small') {
  29368. if ($fontsize) { $size *= $fontsize*0.7; }
  29369. else { $size *= $maxsize*0.7; }
  29370. }
  29371. elseif ($size == 'x-small') {
  29372. if ($fontsize) { $size *= $fontsize*0.77; }
  29373. else { $size *= $maxsize*0.77; }
  29374. }
  29375. elseif ($size == 'small') {
  29376. if ($fontsize) { $size *= $fontsize*0.86; }
  29377. else { $size *= $maxsize*0.86; }
  29378. }
  29379. elseif ($size == 'medium') {
  29380. if ($fontsize) { $size *= $fontsize; }
  29381. else { $size *= $maxsize; }
  29382. }
  29383. elseif ($size == 'large') {
  29384. if ($fontsize) { $size *= $fontsize*1.2; }
  29385. else { $size *= $maxsize*1.2; }
  29386. }
  29387. elseif ($size == 'x-large') {
  29388. if ($fontsize) { $size *= $fontsize*1.5; }
  29389. else { $size *= $maxsize*1.5; }
  29390. }
  29391. elseif ($size == 'xx-large') {
  29392. if ($fontsize) { $size *= $fontsize*2; }
  29393. else { $size *= $maxsize*2; }
  29394. }
  29395. else $size *= (25.4/$this->dpi); //nothing == px
  29396. return $size;
  29397. }
  29398. function lesser_entity_decode($html) {
  29399. //supports the most used entity codes (only does ascii safe characters)
  29400. //$html = str_replace("&nbsp;"," ",$html); // mPDF 5.3.59
  29401. $html = str_replace("&lt;","<",$html);
  29402. $html = str_replace("&gt;",">",$html);
  29403. $html = str_replace("&apos;","'",$html);
  29404. $html = str_replace("&quot;",'"',$html);
  29405. $html = str_replace("&amp;","&",$html);
  29406. return $html;
  29407. }
  29408. function AdjustHTML($html, $tabSpaces=8) {
  29409. //Try to make the html text more manageable (turning it into XHTML)
  29410. if (PHP_VERSION_ID < 50307) {
  29411. if (strlen($html) > 100000) {
  29412. if (PHP_VERSION_ID < 50200) $this->Error("The HTML code is more than 100,000 characters. You should use WriteHTML() with smaller string lengths.");
  29413. else ini_set("pcre.backtrack_limit","1000000");
  29414. }
  29415. }
  29416. /*-- ANNOTATIONS --*/
  29417. preg_match_all("/(<annotation.*?>)/si", $html, $m);
  29418. if (count($m[1])) {
  29419. for($i=0;$i<count($m[1]);$i++) {
  29420. $sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]);
  29421. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  29422. }
  29423. }
  29424. /*-- END ANNOTATIONS --*/
  29425. preg_match_all("/(<svg.*?<\/svg>)/si", $html, $svgi);
  29426. if (count($svgi[0])) {
  29427. for($i=0;$i<count($svgi[0]);$i++) {
  29428. $file = _MPDF_TEMP_PATH.'_tempSVG'.RAND(1,10000).'_'.$i.'.svg';
  29429. //Save to local file
  29430. file_put_contents($file, $svgi[0][$i]);
  29431. $html = str_replace($svgi[0][$i], '<img src="'.$file.'" />', $html); // mPDF 5.5.18
  29432. }
  29433. }
  29434. //Remove javascript code from HTML (should not appear in the PDF file)
  29435. $html = preg_replace('/<script.*?<\/script>/is','',$html);
  29436. //Remove special comments
  29437. $html = preg_replace('/<!--mpdf/i','',$html);
  29438. $html = preg_replace('/mpdf-->/i','',$html);
  29439. //Remove comments from HTML (should not appear in the PDF file)
  29440. $html = preg_replace('/<!--.*?-->/s','',$html);
  29441. $html = preg_replace('/\f/','',$html); //replace formfeed by nothing
  29442. $html = preg_replace('/\r/','',$html); //replace carriage return by nothing
  29443. // Well formed XHTML end tags
  29444. $html = preg_replace('/<(br|hr)\/>/i',"<\\1 />",$html);
  29445. // Get rid of empty <thead></thead>
  29446. $html = preg_replace('/<thead>\s*<\/thead>/i','',$html);
  29447. $html = preg_replace('/<tfoot>\s*<\/tfoot>/i','',$html);
  29448. $html = preg_replace('/<table[^>]*>\s*<\/table>/i','',$html);
  29449. $html = preg_replace('/<tr>\s*<\/tr>/i','',$html);
  29450. // Remove spaces at end of table cells
  29451. $html = preg_replace("/[ \n\r]+<\/t(d|h)/",'</t\\1',$html); // mPDF 5.5.09
  29452. $html = preg_replace("/[ ]*<dottab\s*[\/]*>[ ]*/",'<dottab />',$html);
  29453. // Concatenates any Substitute characters from symbols/dingbats
  29454. $html = str_replace('</tts><tts>','|',$html);
  29455. $html = str_replace('</ttz><ttz>','|',$html);
  29456. $html = str_replace('</tta><tta>','|',$html);
  29457. $html = preg_replace('/<br \/>\s*/is',"<br />",$html);
  29458. // Preserve '\n's in content between the tags <pre> and </pre>
  29459. if (preg_match('/<pre/',$html)) {
  29460. $html_a = preg_split('/(\<\/?pre[^\>]*\>)/', $html, -1, 2);
  29461. $h = array();
  29462. $c=0;
  29463. foreach($html_a AS $s) {
  29464. if ($c>1 && preg_match('/^<\/pre/i',$s)) { $c--; $s=preg_replace('/<\/pre/i','</innerpre',$s); }
  29465. else if ($c>0 && preg_match('/^<pre/i',$s)) { $c++; $s=preg_replace('/<pre/i','<innerpre',$s); }
  29466. else if (preg_match('/^<pre/i',$s)) { $c++; }
  29467. else if (preg_match('/^<\/pre/i',$s)) { $c--; }
  29468. array_push($h, $s);
  29469. }
  29470. $html = implode("", $h);
  29471. }
  29472. $thereispre = preg_match_all('#<pre(.*?)>(.*?)</pre>#si',$html,$temp);
  29473. // Preserve '\n's in content between the tags <textarea> and </textarea>
  29474. $thereistextarea = preg_match_all('#<textarea(.*?)>(.*?)</textarea>#si',$html,$temp2);
  29475. $html = preg_replace('/[\n]/',' ',$html); //replace linefeed by spaces
  29476. $html = preg_replace('/[\t]/',' ',$html); //replace tabs by spaces
  29477. // Converts < to &lt; when not a tag
  29478. $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
  29479. $html = preg_replace("/[ ]+/",' ',$html);
  29480. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  29481. $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html);
  29482. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
  29483. $html = preg_replace('/\/li>\s+<li/i','/li><li',$html);
  29484. $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
  29485. $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html);
  29486. $iterator = 0;
  29487. while($thereispre) //Recover <pre attributes>content</pre>
  29488. {
  29489. $temp[2][$iterator] = preg_replace("/^([^\n\t]*?)\t/me", "stripslashes('\\1') . str_repeat(' ', ( $tabSpaces - (mb_strlen(stripslashes('\\1')) % $tabSpaces)) )",$temp[2][$iterator]);
  29490. $temp[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp[2][$iterator]);
  29491. $temp[2][$iterator] = preg_replace('/\n/',"<br />",$temp[2][$iterator]);
  29492. $temp[2][$iterator] = str_replace('\\',"\\\\",$temp[2][$iterator]);
  29493. $html = preg_replace('#<pre(.*?)>(.*?)</pre>#si','<erp'.$temp[1][$iterator].'>'.$temp[2][$iterator].'</erp>',$html,1);
  29494. $thereispre--;
  29495. $iterator++;
  29496. }
  29497. $iterator = 0;
  29498. while($thereistextarea) //Recover <textarea attributes>content</textarea>
  29499. {
  29500. $temp2[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp2[2][$iterator]);
  29501. $temp2[2][$iterator] = str_replace('\\',"\\\\",$temp2[2][$iterator]); // mPDF 5.3.88
  29502. $html = preg_replace('#<textarea(.*?)>(.*?)</textarea>#si','<aeratxet'.$temp2[1][$iterator].'>'.trim($temp2[2][$iterator]) .'</aeratxet>',$html,1);
  29503. $thereistextarea--;
  29504. $iterator++;
  29505. }
  29506. //Restore original tag names
  29507. $html = str_replace("<erp","<pre",$html);
  29508. $html = str_replace("</erp>","</pre>",$html);
  29509. $html = str_replace("<aeratxet","<textarea",$html);
  29510. $html = str_replace("</aeratxet>","</textarea>",$html);
  29511. $html = str_replace("</innerpre","</pre",$html);
  29512. $html = str_replace("<innerpre","<pre",$html);
  29513. $html = preg_replace('/<textarea([^>]*)><\/textarea>/si','<textarea\\1> </textarea>',$html);
  29514. $html = preg_replace('/(<table[^>]*>)\s*(<caption)(.*?<\/caption>)(.*?<\/table>)/si','\\2 position="top"\\3\\1\\4\\2 position="bottom"\\3',$html); // *TABLES*
  29515. $html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html); // *TABLES*
  29516. $html = preg_replace("/\xbb\xa4\xac/", "\n", $html);
  29517. return $html;
  29518. }
  29519. /*-- LISTS --*/
  29520. function dec2other($num, $cp) {
  29521. $nstr = (string) $num;
  29522. $rnum = '';
  29523. for ($i=0;$i<strlen($nstr);$i++) {
  29524. if ($this->_charDefined($this->CurrentFont['cw'],$cp+intval($nstr[$i]))) { // contains arabic-indic numbers
  29525. $rnum .= code2utf($cp+intval($nstr[$i]));
  29526. }
  29527. else { $rnum .= $nstr[$i]; }
  29528. }
  29529. return $rnum;
  29530. }
  29531. function dec2alpha($valor,$toupper="true"){
  29532. // returns a string from A-Z to AA-ZZ to AAA-ZZZ
  29533. // OBS: A = 65 ASCII TABLE VALUE
  29534. if (($valor < 1) || ($valor > 18278)) return "?"; //supports 'only' up to 18278
  29535. $c1 = $c2 = $c3 = '';
  29536. if ($valor > 702) // 3 letters (up to 18278)
  29537. {
  29538. $c1 = 65 + floor(($valor-703)/676);
  29539. $c2 = 65 + floor((($valor-703)%676)/26);
  29540. $c3 = 65 + floor((($valor-703)%676)%26);
  29541. }
  29542. elseif ($valor > 26) // 2 letters (up to 702)
  29543. {
  29544. $c1 = (64 + (int)(($valor-1) / 26));
  29545. $c2 = (64 + (int)($valor % 26));
  29546. if ($c2 == 64) $c2 += 26;
  29547. }
  29548. else // 1 letter (up to 26)
  29549. {
  29550. $c1 = (64 + $valor);
  29551. }
  29552. $alpha = chr($c1);
  29553. if ($c2 != '') $alpha .= chr($c2);
  29554. if ($c3 != '') $alpha .= chr($c3);
  29555. if (!$toupper) $alpha = strtolower($alpha);
  29556. return $alpha;
  29557. }
  29558. function dec2roman($valor,$toupper=true){
  29559. //returns a string as a roman numeral
  29560. $r1=$r2=$r3=$r4='';
  29561. if (($valor >= 5000) || ($valor < 1)) return "?"; //supports 'only' up to 4999
  29562. $aux = (int)($valor/1000);
  29563. if ($aux!==0)
  29564. {
  29565. $valor %= 1000;
  29566. while($aux!==0)
  29567. {
  29568. $r1 .= "M";
  29569. $aux--;
  29570. }
  29571. }
  29572. $aux = (int)($valor/100);
  29573. if ($aux!==0)
  29574. {
  29575. $valor %= 100;
  29576. switch($aux){
  29577. case 3: $r2="C";
  29578. case 2: $r2.="C";
  29579. case 1: $r2.="C"; break;
  29580. case 9: $r2="CM"; break;
  29581. case 8: $r2="C";
  29582. case 7: $r2.="C";
  29583. case 6: $r2.="C";
  29584. case 5: $r2="D".$r2; break;
  29585. case 4: $r2="CD"; break;
  29586. default: break;
  29587. }
  29588. }
  29589. $aux = (int)($valor/10);
  29590. if ($aux!==0)
  29591. {
  29592. $valor %= 10;
  29593. switch($aux){
  29594. case 3: $r3="X";
  29595. case 2: $r3.="X";
  29596. case 1: $r3.="X"; break;
  29597. case 9: $r3="XC"; break;
  29598. case 8: $r3="X";
  29599. case 7: $r3.="X";
  29600. case 6: $r3.="X";
  29601. case 5: $r3="L".$r3; break;
  29602. case 4: $r3="XL"; break;
  29603. default: break;
  29604. }
  29605. }
  29606. switch($valor){
  29607. case 3: $r4="I";
  29608. case 2: $r4.="I";
  29609. case 1: $r4.="I"; break;
  29610. case 9: $r4="IX"; break;
  29611. case 8: $r4="I";
  29612. case 7: $r4.="I";
  29613. case 6: $r4.="I";
  29614. case 5: $r4="V".$r4; break;
  29615. case 4: $r4="IV"; break;
  29616. default: break;
  29617. }
  29618. $roman = $r1.$r2.$r3.$r4;
  29619. if (!$toupper) $roman = strtolower($roman);
  29620. return $roman;
  29621. }
  29622. /*-- END LISTS --*/
  29623. //===========================
  29624. /*-- IMPORTS --*/
  29625. function SetImportUse() {
  29626. $this->enableImports = true;
  29627. ini_set('auto_detect_line_endings',1);
  29628. require_once(_MPDF_PATH."mpdfi/pdf_context.php");
  29629. require_once(_MPDF_PATH."mpdfi/pdf_parser.php");
  29630. require_once(_MPDF_PATH."mpdfi/fpdi_pdf_parser.php");
  29631. }
  29632. // from mPDFI
  29633. function hex2str($hex) {
  29634. return pack("H*", str_replace(array("\r","\n"," "),"", $hex));
  29635. }
  29636. function str2hex($str) {
  29637. return current(unpack("H*",$str));
  29638. }
  29639. function pdf_write_value(&$value) {
  29640. switch ($value[0]) {
  29641. case PDF_TYPE_NUMERIC :
  29642. case PDF_TYPE_TOKEN :
  29643. // A numeric value or a token.
  29644. // Simply output them
  29645. $this->_out($value[1]." ", false);
  29646. break;
  29647. case PDF_TYPE_ARRAY :
  29648. // An array. Output the proper
  29649. // structure and move on.
  29650. $this->_out("[",false);
  29651. for ($i = 0; $i < count($value[1]); $i++) {
  29652. $this->pdf_write_value($value[1][$i]);
  29653. }
  29654. $this->_out("]");
  29655. break;
  29656. case PDF_TYPE_DICTIONARY :
  29657. // A dictionary.
  29658. $this->_out("<<",false);
  29659. reset ($value[1]);
  29660. while (list($k, $v) = each($value[1])) {
  29661. $this->_out($k . " ",false);
  29662. $this->pdf_write_value($v);
  29663. }
  29664. $this->_out(">>");
  29665. break;
  29666. case PDF_TYPE_OBJREF :
  29667. // An indirect object reference
  29668. // Fill the object stack if needed
  29669. $cpfn =& $this->current_parser->filename;
  29670. if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
  29671. $this->_newobj(false,true);
  29672. $this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  29673. $this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  29674. }
  29675. $objid = $this->_don_obj_stack[$cpfn][$value[1]][0];
  29676. $this->_out("{$objid} 0 R"); //{$value[2]}
  29677. break;
  29678. case PDF_TYPE_STRING :
  29679. if ($this->encrypted) {
  29680. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  29681. $value[1] = $this->_escape($value[1]);
  29682. }
  29683. // A string.
  29684. $this->_out('('.$value[1].')');
  29685. break;
  29686. case PDF_TYPE_STREAM :
  29687. // A stream. First, output the
  29688. // stream dictionary, then the
  29689. // stream data itself.
  29690. $this->pdf_write_value($value[1]);
  29691. if ($this->encrypted) {
  29692. $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
  29693. }
  29694. $this->_out("stream");
  29695. $this->_out($value[2][1]);
  29696. $this->_out("endstream");
  29697. break;
  29698. case PDF_TYPE_HEX :
  29699. if ($this->encrypted) {
  29700. $value[1] = $this->hex2str($value[1]);
  29701. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  29702. // remake hexstring of encrypted string
  29703. $value[1] = $this->str2hex($value[1]);
  29704. }
  29705. $this->_out("<".$value[1].">");
  29706. break;
  29707. case PDF_TYPE_NULL :
  29708. // The null object.
  29709. $this->_out("null");
  29710. break;
  29711. }
  29712. }
  29713. // ========== OVERWRITE SEARCH STRING IN A PDF FILE ================
  29714. function OverWrite($file_in, $search, $replacement, $dest="D", $file_out="mpdf" ) {
  29715. $pdf = file_get_contents($file_in);
  29716. if (!is_array($search)) {
  29717. $x = $search;
  29718. $search = array($x);
  29719. }
  29720. if (!is_array($replacement)) {
  29721. $x = $replacement;
  29722. $search = array($x);
  29723. }
  29724. if (!$this->onlyCoreFonts && !$this->usingCoreFont) {
  29725. foreach($search AS $k=>$val) {
  29726. $search[$k] = $this->UTF8ToUTF16BE($search[$k] , false);
  29727. $search[$k] = $this->_escape($search[$k]);
  29728. $replacement[$k] = $this->UTF8ToUTF16BE($replacement[$k], false);
  29729. $replacement[$k] = $this->_escape($replacement[$k]);
  29730. }
  29731. }
  29732. else {
  29733. foreach($replacement AS $k=>$val) {
  29734. $replacement[$k] = mb_convert_encoding($replacement[$k],$this->mb_enc,'utf-8');
  29735. $replacement[$k] = $this->_escape($replacement[$k]);
  29736. }
  29737. }
  29738. // Get xref into array
  29739. $xref = array();
  29740. preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s",$pdf,$m);
  29741. $xref_objid = $m[1];
  29742. preg_match_all('/(\d{10}) (\d{5}) (f|n)/',$m[2],$x);
  29743. for($i=0; $i<count($x[0]); $i++) {
  29744. $xref[] = array(intval($x[1][$i]), $x[2][$i], $x[3][$i]);
  29745. }
  29746. $changes = array();
  29747. preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s",$pdf,$m);
  29748. preg_match_all("/(\d+) 0 R /s",$m[1],$o);
  29749. $objlist = $o[1];
  29750. foreach($objlist AS $obj) {
  29751. if ($this->compress) {
  29752. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  29753. }
  29754. else {
  29755. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m);
  29756. }
  29757. $s = $m[2];
  29758. if (!$s) { continue; }
  29759. $oldlen = $m[1];
  29760. if ($this->encrypted) {
  29761. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  29762. }
  29763. if ($this->compress) {
  29764. $s = gzuncompress($s);
  29765. }
  29766. foreach($search AS $k=>$val) {
  29767. $s = str_replace($search[$k],$replacement[$k],$s);
  29768. }
  29769. if ($this->compress) {
  29770. $s = gzcompress($s);
  29771. }
  29772. if ($this->encrypted) {
  29773. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  29774. }
  29775. $newlen = strlen($s);
  29776. $changes[($xref[$obj+1][0])] = ($newlen - $oldlen) + (strlen($newlen) - strlen($oldlen ));
  29777. if ($this->compress) {
  29778. $newstr = ($obj+1) . " 0 obj\n<</Filter /FlateDecode /Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  29779. }
  29780. else {
  29781. $newstr = ($obj+1) . " 0 obj\n<</Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  29782. }
  29783. $pdf = str_replace($m[0],$newstr,$pdf);
  29784. }
  29785. // Update xref in PDF
  29786. krsort($changes);
  29787. $newxref = "xref\n0 ".$xref_objid."\n";
  29788. foreach($xref AS $v) {
  29789. foreach($changes AS $ck => $cv) {
  29790. if ($v[0] > $ck) { $v[0] += $cv; }
  29791. }
  29792. $newxref .= sprintf('%010d',$v[0]) . ' ' . $v[1] . ' ' .$v[2] . " \n";
  29793. }
  29794. $newxref .= "trailer";
  29795. $pdf = preg_replace("/xref\n0 \d+\n.*?\ntrailer/s",$newxref,$pdf);
  29796. // Update startxref in PDF
  29797. preg_match("/startxref\n(\d+)\n%%EOF/s", $pdf, $m);
  29798. $startxref = $m[1];
  29799. $startxref += array_sum($changes);
  29800. $pdf = preg_replace("/startxref\n(\d+)\n%%EOF/s","startxref\n".$startxref."\n%%EOF",$pdf);
  29801. // OUTPUT
  29802. switch($dest) {
  29803. case 'I':
  29804. //Send to standard output
  29805. if(isset($_SERVER['SERVER_NAME']))
  29806. {
  29807. //We send to a browser
  29808. Header('Content-Type: application/pdf');
  29809. Header('Content-Length: '.strlen($pdf));
  29810. Header('Content-disposition: inline; filename='.$file_out);
  29811. }
  29812. echo $pdf;
  29813. break;
  29814. case 'F':
  29815. //Save to local file
  29816. if (!$file_out) { $file_out = 'mpdf.pdf'; }
  29817. $f=fopen($file_out,'wb');
  29818. if(!$f) die('Unable to create output file: '.$file_out);
  29819. fwrite($f,$pdf,strlen($pdf));
  29820. fclose($f);
  29821. break;
  29822. case 'S':
  29823. //Return as a string
  29824. return $pdf;
  29825. case 'D':
  29826. default:
  29827. //Download file
  29828. if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  29829. Header('Content-Type: application/force-download');
  29830. else
  29831. Header('Content-Type: application/octet-stream');
  29832. Header('Content-Length: '.strlen($pdf));
  29833. Header('Content-disposition: attachment; filename='.$file_out);
  29834. echo $pdf;
  29835. break;
  29836. }
  29837. }
  29838. function GetTemplateSize($tplidx, $_w=0, $_h=0) {
  29839. if (!$this->tpls[$tplidx])
  29840. return false;
  29841. $w = $this->tpls[$tplidx]['box']['w'];
  29842. $h = $this->tpls[$tplidx]['box']['h'];
  29843. if ($_w == 0 and $_h == 0) {
  29844. $_w = $w;
  29845. $_h = $h;
  29846. }
  29847. if($_w==0)
  29848. $_w=$_h*$w/$h;
  29849. if($_h==0)
  29850. $_h=$_w*$h/$w;
  29851. return array("w" => $_w, "h" => $_h);
  29852. }
  29853. // Thumbnails
  29854. function Thumbnail($file, $npr=3, $spacing=10) { //$npr = number per row
  29855. $w = (($this->pgwidth + $spacing)/$npr) - $spacing;
  29856. $oldlinewidth = $this->LineWidth;
  29857. $this->SetLineWidth(0.02);
  29858. $this->SetDColor($this->ConvertColor(0));
  29859. $h = 0;
  29860. $maxh = 0;
  29861. $x = $_x = $this->lMargin;
  29862. $_y = $this->tMargin;
  29863. if ($this->y==0) { $y = $_y; } else { $y = $this->y; }
  29864. $pagecount = $this->SetSourceFile($file);
  29865. for ($n = 1; $n <= $pagecount; $n++) {
  29866. $tplidx = $this->ImportPage($n);
  29867. $size = $this->useTemplate($tplidx, $x, $y, $w);
  29868. $this->Rect($x, $y, $size['w'], $size['h']);
  29869. $h = max($h, $size['h']);
  29870. $maxh = max($h, $maxh);
  29871. if ($n % $npr == 0) {
  29872. if (($y + $h + $spacing + $maxh)>$this->PageBreakTrigger && $n != $pagecount) {
  29873. $this->AddPage();
  29874. $x = $_x;
  29875. $y = $_y;
  29876. }
  29877. else {
  29878. $y += $h+$spacing ;
  29879. $x = $_x;
  29880. $h = 0;
  29881. }
  29882. }
  29883. else {
  29884. $x += $w+$spacing ;
  29885. }
  29886. }
  29887. $this->SetLineWidth($oldlinewidth);
  29888. }
  29889. function SetSourceFile($filename) {
  29890. $this->current_filename = $filename;
  29891. $fn =& $this->current_filename;
  29892. if (!isset($this->parsers[$fn]))
  29893. // $this->parsers[$fn] =& new fpdi_pdf_parser($fn,$this);
  29894. $this->parsers[$fn] = new fpdi_pdf_parser($fn,$this);
  29895. if (!$this->parsers[$fn]->success) {
  29896. $this->Error($this->parsers[$fn]->errormsg); // Delete this line to return false on fail
  29897. return false;
  29898. }
  29899. $this->current_parser =& $this->parsers[$fn];
  29900. return $this->parsers[$fn]->getPageCount();
  29901. }
  29902. function ImportPage($pageno=1, $crop_x=null, $crop_y=null, $crop_w=0, $crop_h=0, $boxName='/CropBox') {
  29903. $fn =& $this->current_filename;
  29904. $parser =& $this->parsers[$fn];
  29905. $parser->setPageno($pageno);
  29906. $this->tpl++;
  29907. $this->tpls[$this->tpl] = array();
  29908. $tpl =& $this->tpls[$this->tpl];
  29909. $tpl['parser'] =& $parser;
  29910. $tpl['resources'] = $parser->getPageResources();
  29911. $tpl['buffer'] = $parser->getContent();
  29912. if (!in_array($boxName, $parser->availableBoxes))
  29913. return $this->Error(sprintf("Unknown box: %s", $boxName));
  29914. $pageboxes = $parser->getPageBoxes($pageno);
  29915. /**
  29916. * MediaBox
  29917. * CropBox: Default -> MediaBox
  29918. * BleedBox: Default -> CropBox
  29919. * TrimBox: Default -> CropBox
  29920. * ArtBox: Default -> CropBox
  29921. */
  29922. if (!isset($pageboxes[$boxName]) && ($boxName == "/BleedBox" || $boxName == "/TrimBox" || $boxName == "/ArtBox"))
  29923. $boxName = "/CropBox";
  29924. if (!isset($pageboxes[$boxName]) && $boxName == "/CropBox")
  29925. $boxName = "/MediaBox";
  29926. if (!isset($pageboxes[$boxName]))
  29927. return false;
  29928. $box = $pageboxes[$boxName];
  29929. $tpl['box'] = $box;
  29930. // To build an array that can be used by useTemplate()
  29931. $this->tpls[$this->tpl] = array_merge($this->tpls[$this->tpl],$box);
  29932. // An imported page will start at 0,0 everytime. Translation will be set in _putformxobjects()
  29933. $tpl['x'] = 0;
  29934. $tpl['y'] = 0;
  29935. $tpl['w'] = $tpl['box']['w'] ;
  29936. $tpl['h'] = $tpl['box']['h'] ;
  29937. if ($crop_w) { $tpl['box']['w'] = $crop_w; }
  29938. if ($crop_h) { $tpl['box']['h'] = $crop_h; }
  29939. if (isset($crop_x)) { $tpl['box']['x'] = $crop_x; }
  29940. if (isset($crop_y)) {$tpl['box']['y'] = $tpl['h'] - $crop_y - $crop_h ; }
  29941. $page =& $parser->pages[$parser->pageno];
  29942. // fix for rotated pages
  29943. $rotation = $parser->getPageRotation($pageno);
  29944. if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0 && $tpl['box']['w'] == $tpl['w']) {
  29945. $steps = $angle / 90;
  29946. $_w = $tpl['w'];
  29947. $_h = $tpl['h'];
  29948. $tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
  29949. $tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
  29950. if ($steps % 2 != 0) {
  29951. $x = $y = ($steps == 1 || $steps == -3) ? $tpl['h'] : $tpl['w'];
  29952. } else {
  29953. $x = $tpl['w'];
  29954. $y = $tpl['h'];
  29955. }
  29956. $cx=($x/2+$tpl['box']['x'])*_MPDFK;
  29957. $cy=($y/2+$tpl['box']['y'])*_MPDFK;
  29958. $angle*=-1;
  29959. $angle*=M_PI/180;
  29960. $c=cos($angle);
  29961. $s=sin($angle);
  29962. $tpl['box']['w'] = $tpl['w'] ;
  29963. $tpl['box']['h'] = $tpl['h'] ;
  29964. $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']);
  29965. }
  29966. return $this->tpl;
  29967. }
  29968. function UseTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
  29969. if (!isset($this->tpls[$tplidx]))
  29970. $this->Error("Template does not exist!");
  29971. if($this->state==0) { $this->AddPage(); }
  29972. $out = 'q 0 J 1 w 0 j 0 G'."\n"; // reset standard values
  29973. $x = $this->tpls[$tplidx]['x'];
  29974. $y = $this->tpls[$tplidx]['y'];
  29975. $w = $this->tpls[$tplidx]['w'];
  29976. $h = $this->tpls[$tplidx]['h'];
  29977. if ($_x == null) { $_x = $x; }
  29978. if ($_y == null) { $_y = $y; }
  29979. if ($_x === -1) { $_x = $this->x; }
  29980. if ($_y === -1) { $_y = $this->y; }
  29981. $wh = $this->getTemplateSize($tplidx,$_w,$_h);
  29982. $_w = $wh['w'];
  29983. $_h = $wh['h'];
  29984. $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";
  29985. $out .= $this->tplprefix.$tplidx." Do Q\n";
  29986. $s = array("w" => $_w, "h" => $_h);
  29987. $out .= "Q\n";
  29988. $this->pages[$this->page] = $out . $this->pages[$this->page];
  29989. return $s;
  29990. }
  29991. function SetPageTemplate($tplidx='') {
  29992. if (!isset($this->tpls[$tplidx])) {
  29993. $this->pageTemplate = '';
  29994. return false;
  29995. }
  29996. $this->pageTemplate = $tplidx;
  29997. }
  29998. function SetDocTemplate($file='', $continue=0) {
  29999. $this->docTemplate = $file;
  30000. $this->docTemplateContinue = $continue;
  30001. }
  30002. /*-- END IMPORTS --*/
  30003. /* ---------------------------------------------- */
  30004. /* ---------------------------------------------- */
  30005. /* ---------------------------------------------- */
  30006. /* ---------------------------------------------- */
  30007. /* ---------------------------------------------- */
  30008. // JAVASCRIPT
  30009. function _set_object_javascript ($string) {
  30010. $this->_newobj();
  30011. $this->_out('<<');
  30012. $this->_out('/S /JavaScript ');
  30013. $this->_out('/JS '.$this->_textstring($string));
  30014. $this->_out('>>');
  30015. $this->_out('endobj');
  30016. }
  30017. function SetJS($script) {
  30018. $this->js = $script;
  30019. }
  30020. }//end of Class
  30021. ?>