MPDF PHP
MPDF PHP
MPDF PHP
php
// ******************************************************************************
// Software: mPDF, Unicode-HTML Free PDF generator *
// Version: 6.1 based on *
// FPDF by Olivier PLATHEY *
// HTML2FPDF by Renato Coelho *
// Date: 2016-03-25 *
// Author: Ian Back <ianb@bpm1.com> *
// License: GPL *
// *
// Changes: See changelog.txt *
// ******************************************************************************
define('mPDF_VERSION', '6.1');
//Scale factor
define('_MPDFK', (72 / 25.4));
/* -- HTML-CSS -- */
define('_BORDER_ALL', 15);
define('_BORDER_TOP', 8);
define('_BORDER_RIGHT', 4);
define('_BORDER_BOTTOM', 2);
define('_BORDER_LEFT', 1);
/* -- END HTML-CSS -- */
// mPDF 6.0
// Used for $textvars - user settings via CSS
define('FD_UNDERLINE', 1); // font-decoration
define('FD_LINETHROUGH', 2);
define('FD_OVERLINE', 4);
define('FA_SUPERSCRIPT', 8); // font-(vertical)-align
define('FA_SUBSCRIPT', 16);
define('FT_UPPERCASE', 32); // font-transform
define('FT_LOWERCASE', 64);
define('FT_CAPITALIZE', 128);
define('FC_KERNING', 256); // font-(other)-controls
define('FC_SMALLCAPS', 512);
if (!defined('_MPDF_PATH')) {
define('_MPDF_PATH', dirname(preg_replace('/\\\\/', '/', __FILE__)) . '/');
}
if (!defined('_MPDF_URI')) {
define('_MPDF_URI', _MPDF_PATH);
}
require_once _MPDF_PATH . 'includes/functions.php';
require_once _MPDF_PATH . 'config_lang2fonts.php';
/* -- OTL -- */
require_once _MPDF_PATH . 'classes/indic.php'; // mPDF 6.0
require_once _MPDF_PATH . 'classes/myanmar.php'; // mPDF 6.0
require_once _MPDF_PATH . 'classes/sea.php'; // mPDF 6.0
/* -- END OTL -- */
if (!defined('_JPGRAPH_PATH')) {
define("_JPGRAPH_PATH", _MPDF_PATH . 'jpgraph/');
}
if (!defined('_MPDF_TEMP_PATH')) {
define("_MPDF_TEMP_PATH", _MPDF_PATH . 'tmp/');
}
if (!defined('_MPDF_TTFONTPATH')) {
define('_MPDF_TTFONTPATH', _MPDF_PATH . 'ttfonts/');
}
if (!defined('_MPDF_TTFONTDATAPATH')) {
define('_MPDF_TTFONTDATAPATH', _MPDF_PATH . 'ttfontdata/');
}
$errorlevel = error_reporting();
$errorlevel = error_reporting($errorlevel & ~E_NOTICE);
//error_reporting(E_ALL);
if (function_exists("date_default_timezone_set")) {
if (ini_get("date.timezone") == "") {
date_default_timezone_set("Europe/London");
}
}
if (!function_exists('mb_strlen')) {
throw new MpdfException('mPDF requires mb_string functions. Ensure that
mb_string extension is loaded.');
}
if (!defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 +
$version[2]));
}
class mPDF
{
///////////////////////////////
// EXTERNAL (PUBLIC) VARIABLES
// Define these in config.php
///////////////////////////////
var $useFixedNormalLineHeight; // mPDF 6
var $useFixedTextBaseline; // mPDF 6
var $adjustFontDescLineheight; // mPDF 6
var $interpolateImages; // mPDF 6
var $defaultPagebreakType; // mPDF 6 pagebreaktype
var $indexUseSubentries; // mPDF 6
var $CJKforceend;
var $h2bookmarks;
var $h2toc;
var $decimal_align;
var $margBuffer;
var $splitTableBorderWidth;
var $bookmarkStyles;
var $useActiveForms;
var $repackageTTF;
var $allowCJKorphans;
var $allowCJKoverflow;
var $useKerning;
var $restrictColorSpace;
var $bleedMargin;
var $crossMarkMargin;
var $cropMarkMargin;
var $cropMarkLength;
var $nonPrintMargin;
var $PDFX;
var $PDFXauto;
var $PDFA;
var $PDFAauto;
var $ICCProfile;
var $printers_info;
var $iterationCounter;
var $smCapsScale;
var $smCapsStretch;
var $backupSubsFont;
var $backupSIPFont;
var $debugfonts;
var $useAdobeCJK;
var $percentSubset;
var $maxTTFFilesize;
var $BMPonly;
var $tableMinSizePriority;
var $dpi;
var $watermarkImgAlphaBlend;
var $watermarkImgBehind;
var $justifyB4br;
var $packTableData;
var $pgsIns;
var $simpleTables;
var $enableImports;
var $debug;
var $showStats;
var $setAutoTopMargin;
var $setAutoBottomMargin;
var $autoMarginPadding;
var $collapseBlockMargins;
var $falseBoldWeight;
var $normalLineheight;
var $progressBar;
var $incrementFPR1;
var $incrementFPR2;
var $incrementFPR3;
var $incrementFPR4;
var $SHYlang;
var $SHYleftmin;
var $SHYrightmin;
var $SHYcharmin;
var $SHYcharmax;
var $SHYlanguages;
var $nbpgPrefix;
var $nbpgSuffix;
var $showImageErrors;
var $allow_output_buffering;
var $autoPadding;
var $useGraphs;
var $tabSpaces;
var $autoLangToFont;
var $watermarkTextAlpha;
var $watermarkImageAlpha;
var $watermark_size;
var $watermark_pos;
var $annotSize;
var $annotMargin;
var $annotOpacity;
var $title2annots;
var $keepColumns;
var $keep_table_proportions;
var $ignore_table_widths;
var $ignore_table_percents;
var $list_number_suffix;
var $forcePortraitHeaders;
var $forcePortraitMargins;
var $displayDefaultOrientation;
var $ignore_invalid_utf8;
var $allowedCSStags;
var $onlyCoreFonts;
var $allow_charset_conversion;
var $jSWord;
var $jSmaxChar;
var $jSmaxCharLast;
var $jSmaxWordLast;
var $max_colH_correction;
var $table_error_report;
var $table_error_report_param;
var $biDirectional;
var $text_input_as_HTML;
var $anchor2Bookmark;
var $shrink_tables_to_fit;
var $allow_html_optional_endtags;
var $img_dpi;
var $defaultheaderfontsize;
var $defaultheaderfontstyle;
var $defaultheaderline;
var $defaultfooterfontsize;
var $defaultfooterfontstyle;
var $defaultfooterline;
var $header_line_spacing;
var $footer_line_spacing;
var $pregCJKchars;
var $pregRTLchars;
var $pregCURSchars; // mPDF 6
var $mirrorMargins;
var $watermarkText;
var $watermarkImage;
var $showWatermarkText;
var $showWatermarkImage;
var $fontsizes;
//////////////////////
// CLASS OBJECTS
//////////////////////
var $otl; // mPDF 5.7.1
var $cssmgr;
var $grad;
var $bmp;
var $wmf;
var $tocontents;
var $mpdfform;
var $directw;
//////////////////////
// INTERNAL VARIABLES
//////////////////////
var $script2lang;
var $viet;
var $pashto;
var $urdu;
var $persian;
var $sindhi;
var $extrapagebreak; // mPDF 6 pagebreaktype
var $writingToC;
var $layers;
var $current_layer;
var $open_layer_pane;
var $decimal_offset;
var $inMeter;
var $CJKleading;
var $CJKfollowing;
var $CJKoverflow;
var $textshadow;
var $colsums;
var $spanborder;
var $spanborddet;
var $visibility;
var $useRC128encryption;
var $uniqid;
var $kerning;
var $fixedlSpacing;
var $minwSpacing;
var $lSpacingCSS;
var $wSpacingCSS;
var $spotColorIDs;
var $SVGcolors;
var $spotColors;
var $defTextColor;
var $defDrawColor;
var $defFillColor;
var $tableBackgrounds;
var $inlineDisplayOff;
var $kt_y00;
var $kt_p00;
var $upperCase;
var $checkSIP;
var $checkSMP;
var $checkCJK;
var $watermarkImgAlpha;
var $PDFAXwarnings;
var $MetadataRoot;
var $OutputIntentRoot;
var $InfoRoot;
var $current_filename;
var $parsers;
var $current_parser;
var $_obj_stack;
var $_don_obj_stack;
var $_current_obj_id;
var $tpls;
var $tpl;
var $tplprefix;
var $_res;
var $pdf_version;
var $noImageFile;
var $lastblockbottommargin;
var $baselineC;
var $fullImageHeight;
var $extraFontSubsets;
var $docTemplateStart; // Internal flag for page (page no. -1) that
docTemplate starts on
var $time0;
// Classes
var $indic;
var $barcode;
var $SHYpatterns;
var $loadedSHYpatterns;
var $loadedSHYdictionary;
var $SHYdictionary;
var $SHYdictionaryWords;
var $spanbgcolorarray;
var $default_font;
var $headerbuffer;
var $lastblocklevelchange;
var $nestedtablejustfinished;
var $linebreakjustfinished;
var $cell_border_dominance_L;
var $cell_border_dominance_R;
var $cell_border_dominance_T;
var $cell_border_dominance_B;
var $table_keep_together;
var $plainCell_properties;
var $shrin_k1;
var $outerfilled;
var $blockContext;
var $floatDivs;
var $patterns;
var $pageBackgrounds;
var $bodyBackgroundGradient;
var $bodyBackgroundImage;
var $bodyBackgroundColor;
var $angle;
var $gradients;
var $kwt_Reference;
var $kwt_BMoutlines;
var $kwt_toc;
var $tbrot_BMoutlines;
var $tbrot_toc;
var $col_BMoutlines;
var $col_toc;
var $currentGraphId;
var $graphs;
var $floatbuffer;
var $floatmargins;
var $bullet;
var $bulletarray;
var $currentLang;
var $default_lang;
var $default_available_fonts;
var $pageTemplate;
var $docTemplate;
var $docTemplateContinue;
var $arabGlyphs;
var $arabHex;
var $persianGlyphs;
var $persianHex;
var $arabVowels;
var $arabPrevLink;
var $arabNextLink;
var $ktAnnots;
var $tbrot_Annots;
var $kwt_Annots;
var $columnAnnots;
var $columnForms;
var $PageAnnots;
var $pageDim; // Keep track of page wxh for orientation changes - set in
_beginpage, used in _putannots
var $breakpoints;
var $tableLevel;
var $tbctr;
var $innermostTableLevel;
var $saveTableCounter;
var $cellBorderBuffer;
var $saveHTMLFooter_height;
var $saveHTMLFooterE_height;
var $firstPageBoxHeader;
var $firstPageBoxHeaderEven;
var $firstPageBoxFooter;
var $firstPageBoxFooterEven;
var $page_box;
var $use_kwt;
var $kwt;
var $kwt_height;
var $kwt_y0;
var $kwt_x0;
var $kwt_buffer;
var $kwt_Links;
var $kwt_moved;
var $kwt_saved;
var $PageNumSubstitutions;
var $table_borders_separate;
var $base_table_properties;
var $borderstyles;
var $blockjustfinished;
var $orig_bMargin;
var $orig_tMargin;
var $orig_lMargin;
var $orig_rMargin;
var $orig_hMargin;
var $orig_fMargin;
var $pageHTMLheaders;
var $pageHTMLfooters;
var $saveHTMLHeader;
var $saveHTMLFooter;
var $HTMLheaderPageLinks;
var $HTMLheaderPageAnnots;
var $HTMLheaderPageForms;
// List of ALL available CJK fonts (incl. styles) (Adobe add-ons) hw removed
var $available_CJK_fonts;
var $HTMLHeader;
var $HTMLFooter;
var $HTMLHeaderE;
var $HTMLFooterE;
var $bufferoutput;
// CJK fonts
var $Big5_widths;
var $GB_widths;
var $SJIS_widths;
var $UHC_widths;
// SetProtection
var $encrypted; // whether document is protected
var $Uvalue; // U entry in pdf document
var $Ovalue; // O entry in pdf document
var $Pvalue; // P entry in pdf document
var $encryption_key;
// Bookmark
var $BMoutlines;
var $OutlineRoot;
// INDEX
var $ColActive;
var $Reference;
var $CurrCol;
var $NbCol;
var $y0; //Top ordinate of columns
var $ColL;
var $ColWidth;
var $ColGap;
// COLUMNS
var $ColR;
var $ChangeColumn;
var $columnbuffer;
var $ColDetails;
var $columnLinks;
var $colvAlign;
// Substitutions
var $substitute; // Array of substitution strings e.g. <ttz>112</ttz>
var $entsearch; // Array of HTML entities (>ASCII 127) to substitute
var $entsubstitute; // Array of substitution decimal unicode for the Hi
entities
var $HREF;
var $pgwidth;
var $fontlist;
var $oldx;
var $oldy;
var $B;
var $I;
var $tdbegin;
var $table;
var $cell;
var $col;
var $row;
var $divbegin;
var $divwidth;
var $divheight;
var $spanbgcolor;
// mPDF 6 Lists
var $listcounter;
var $listlvl;
var $listtype;
var $listitem;
var $pjustfinished;
var $ignorefollowingspaces;
var $SMALL;
var $BIG;
var $dash_on;
var $dotted_on;
var $textbuffer;
var $currentfontstyle;
var $currentfontfamily;
var $currentfontsize;
var $colorarray;
var $bgcolorarray;
var $internallink;
var $enabledtags;
var $lineheight;
var $basepath;
var $textparam;
var $specialcontent;
var $selectoption;
var $objectbuffer;
// Table Rotation
var $table_rotate;
var $tbrot_maxw;
var $tbrot_maxh;
var $tablebuffer;
var $tbrot_align;
var $tbrot_Links;
var $tbrot_y0;
var $tbrot_x0;
var $tbrot_w;
var $tbrot_h;
var $mb_enc;
var $directionality;
var $tts;
var $ttz;
var $tta;
// TABLE
var $defaultTableAlign;
var $tablethead;
var $thead_font_weight;
var $thead_font_style;
var $thead_font_smCaps;
var $thead_valign_default;
var $thead_textalign_default;
var $tabletfoot;
var $tfoot_font_weight;
var $tfoot_font_style;
var $tfoot_font_smCaps;
var $tfoot_valign_default;
var $tfoot_textalign_default;
var $trow_text_rotate;
var $cellPaddingL;
var $cellPaddingR;
var $cellPaddingT;
var $cellPaddingB;
var $table_border_attr_set;
var $table_border_css_set;
var $ispre;
var $outerblocktags;
var $innerblocktags;
// **********************************
// **********************************
// **********************************
// **********************************
// **********************************
// **********************************
// **********************************
// **********************************
// **********************************
private $tag;
$this->time0 = microtime(true);
//Some checks
$this->_dochecks();
$this->writingToC = false;
$this->layers = array();
$this->current_layer = 0;
$this->open_layer_pane = false;
$this->visibility = 'visible';
//Initialization of properties
$this->spotColors = array();
$this->spotColorIDs = array();
$this->tableBackgrounds = array();
$this->uniqstr = '20110230'; // mPDF 5.7.2
$this->kt_y00 = '';
$this->kt_p00 = '';
$this->iterationCounter = false;
$this->BMPonly = array();
$this->page = 0;
$this->n = 2;
$this->buffer = '';
$this->objectbuffer = array();
$this->pages = array();
$this->OrientationChanges = array();
$this->state = 0;
$this->fonts = array();
$this->FontFiles = array();
$this->images = array();
$this->links = array();
$this->InFooter = false;
$this->processingFooter = false;
$this->processingHeader = false;
$this->lasth = 0;
$this->FontFamily = '';
$this->FontStyle = '';
$this->FontSizePt = 9;
$this->U = false;
// Small Caps
$this->upperCase = array();
$this->smCapsScale = 1;
$this->smCapsStretch = 100;
$this->margBuffer = 0;
$this->inMeter = false;
$this->decimal_offset = 0;
$this->ColorFlag = false;
$this->extgstates = array();
$this->mb_enc = 'windows-1252';
$this->directionality = 'ltr';
$this->defaultAlign = 'L';
$this->defaultTableAlign = 'L';
$this->fixedPosBlockSave = array();
$this->extraFontSubsets = 0;
$this->SHYpatterns = array();
$this->loadedSHYdictionary = false;
$this->SHYdictionary = array();
$this->SHYdictionaryWords = array();
$this->blockContext = 1;
$this->floatDivs = array();
$this->DisplayPreferences = '';
$this->kwt_Reference = array();
$this->kwt_BMoutlines = array();
$this->kwt_toc = array();
$this->tbrot_BMoutlines = array();
$this->tbrot_toc = array();
$this->col_BMoutlines = array();
$this->col_toc = array();
$this->graphs = array();
$this->pgsIns = array();
$this->PDFAXwarnings = array();
$this->inlineDisplayOff = false;
$this->lSpacingCSS = '';
$this->wSpacingCSS = '';
$this->fixedlSpacing = false;
$this->minwSpacing = 0;
$this->fullImageHeight = false;
$this->floatbuffer = array();
$this->floatmargins = array();
$this->formobjects = array(); // array of Form Objects for WMF
$this->InlineProperties = array();
$this->InlineAnnots = array();
$this->InlineBDF = array(); // mPDF 6
$this->InlineBDFctr = 0; // mPDF 6
$this->tbrot_Annots = array();
$this->kwt_Annots = array();
$this->columnAnnots = array();
$this->pageDim = array();
$this->breakpoints = array(); // used in columnbuffer
$this->tableLevel = 0;
$this->tbctr = array(); // counter for nested tables at each level
$this->page_box = array();
$this->show_marks = ''; // crop or cross marks
$this->kwt = false;
$this->kwt_height = 0;
$this->kwt_y0 = 0;
$this->kwt_x0 = 0;
$this->kwt_buffer = array();
$this->kwt_Links = array();
$this->kwt_moved = false;
$this->kwt_saved = false;
$this->PageNumSubstitutions = array();
$this->base_table_properties = array();
$this->borderstyles = array('inset', 'groove', 'outset', 'ridge',
'dotted', 'dashed', 'solid', 'double');
$this->tbrot_align = 'C';
$this->pageHTMLheaders = array();
$this->pageHTMLfooters = array();
$this->HTMLheaderPageLinks = array();
$this->HTMLheaderPageAnnots = array();
$this->HTMLheaderPageForms = array();
$this->columnForms = array();
$this->tbrotForms = array();
$this->useRC128encryption = false;
$this->uniqid = '';
$this->pageoutput = array();
$this->bufferoutput = false;
$this->encrypted = false; //whether document is protected
$this->BMoutlines = array();
$this->ColActive = 0; //Flag indicating that columns are on
(the index is being processed)
$this->Reference = array(); //Array containing the references
$this->CurrCol = 0; //Current column number
$this->ColL = array(0); // Array of Left pos of columns - absolute -
needs Margin correction for Odd-Even
$this->ColR = array(0); // Array of Right pos of columns - absolute
pos - needs Margin correction for Odd-Even
$this->ChangeColumn = 0;
$this->columnbuffer = array();
$this->ColDetails = array(); // Keeps track of some column details
$this->columnLinks = array(); // Cross references PageLinks
$this->substitute = array(); // Array of substitution strings e.g.
<ttz>112</ttz>
$this->entsearch = array(); // Array of HTML entities (>ASCII 127) to
substitute
$this->entsubstitute = array(); // Array of substitution decimal
unicode for the Hi entities
$this->lastoptionaltag = '';
$this->charset_in = '';
$this->blk = array();
$this->blklvl = 0;
$this->tts = false;
$this->ttz = false;
$this->tta = false;
$this->ispre = false;
$this->checkSIP = false;
$this->checkSMP = false;
$this->checkCJK = false;
$this->page_break_after_avoid = false;
$this->margin_bottom_collapse = false;
$this->tablethead = 0;
$this->tabletfoot = 0;
$this->table_border_attr_set = 0;
$this->table_border_css_set = 0;
$this->shrin_k = 1.0;
$this->shrink_this_table_to_fit = 0;
$this->MarginCorrection = 0;
$this->tabletheadjustfinished = false;
$this->usingCoreFont = false;
$this->charspacing = 0;
$this->autoPageBreak = true;
$this->margin_header = $mgh;
$this->margin_footer = $mgf;
$bmargin = $mgb;
$this->DeflMargin = $mgl;
$this->DefrMargin = $mgr;
$this->orig_tMargin = $mgt;
$this->orig_bMargin = $bmargin;
$this->orig_lMargin = $this->DeflMargin;
$this->orig_rMargin = $this->DefrMargin;
$this->orig_hMargin = $this->margin_header;
$this->orig_fMargin = $this->margin_footer;
if ($this->setAutoTopMargin == 'pad') {
$mgt += $this->margin_header;
}
if ($this->setAutoBottomMargin == 'pad') {
$mgb += $this->margin_footer;
}
$this->SetMargins($this->DeflMargin, $this->DefrMargin, $mgt); // sets
l r t margin
//Automatic page break
$this->SetAutoPageBreak($this->autoPageBreak, $bmargin); // sets $this-
>bMargin & PageBreakTrigger
//To make the function Footer() work - replaces {nb} with page number
$this->AliasNbPages();
$this->AliasNbPageGroups();
// Font data
require(_MPDF_PATH . 'config_fonts.php');
// check for a custom config file that can add/overwrite the default
config
if (defined('_MPDF_SYSTEM_TTFONTS_CONFIG') &&
file_exists(_MPDF_SYSTEM_TTFONTS_CONFIG)) {
require(_MPDF_SYSTEM_TTFONTS_CONFIG);
}
// Available fonts
$this->available_unifonts = array();
foreach ($this->fontdata AS $f => $fs) {
if (isset($fs['R']) && $fs['R']) {
$this->available_unifonts[] = $f;
}
if (isset($fs['B']) && $fs['B']) {
$this->available_unifonts[] = $f . 'B';
}
if (isset($fs['I']) && $fs['I']) {
$this->available_unifonts[] = $f . 'I';
}
if (isset($fs['BI']) && $fs['BI']) {
$this->available_unifonts[] = $f . 'BI';
}
}
$this->default_available_fonts = $this->available_unifonts;
$optcore = false;
$onlyCoreFonts = false;
if (preg_match('/([\-+])aCJK/i', $mode, $m)) {
$mode = preg_replace('/([\-+])aCJK/i', '', $mode); // mPDF 6
if ($m[1] == '+') {
$this->useAdobeCJK = true;
} else {
$this->useAdobeCJK = false;
}
}
if (strlen($mode) == 1) {
if ($mode == 's') {
$this->percentSubset = 100;
$mode = '';
} elseif ($mode == 'c') {
$onlyCoreFonts = true;
$mode = '';
}
} elseif (substr($mode, -2) == '-s') {
$this->percentSubset = 100;
$mode = substr($mode, 0, strlen($mode) - 2);
} elseif (substr($mode, -2) == '-c') {
$onlyCoreFonts = true;
$mode = substr($mode, 0, strlen($mode) - 2);
} elseif (substr($mode, -2) == '-x') {
$optcore = true;
$mode = substr($mode, 0, strlen($mode) - 2);
}
$this->onlyCoreFonts = $onlyCoreFonts;
if ($this->onlyCoreFonts) {
$this->setMBencoding('windows-1252'); // sets $this->mb_enc
} else {
$this->setMBencoding('UTF-8'); // sets $this->mb_enc
}
@mb_regex_encoding('UTF-8'); // required only for mb_ereg... and
mb_split functions
// Adobe CJK fonts
$this->available_CJK_fonts = array('gb', 'big5', 'sjis', 'uhc', 'gbB',
'big5B', 'sjisB', 'uhcB', 'gbI', 'big5I', 'sjisI', 'uhcI',
'gbBI', 'big5BI', 'sjisBI', 'uhcBI');
//Standard fonts
$this->CoreFonts = array('ccourier' => 'Courier', 'ccourierB' =>
'Courier-Bold', 'ccourierI' => 'Courier-Oblique', 'ccourierBI' => 'Courier-
BoldOblique',
'chelvetica' => 'Helvetica', 'chelveticaB' => 'Helvetica-Bold',
'chelveticaI' => 'Helvetica-Oblique', 'chelveticaBI' => 'Helvetica-BoldOblique',
'ctimes' => 'Times-Roman', 'ctimesB' => 'Times-Bold', 'ctimesI'
=> 'Times-Italic', 'ctimesBI' => 'Times-BoldItalic',
'csymbol' => 'Symbol', 'czapfdingbats' => 'ZapfDingbats');
$this->fontlist = array("ctimes", "ccourier", "chelvetica", "csymbol",
"czapfdingbats");
// Substitutions
$this->setHiEntitySubstitutions();
if ($this->onlyCoreFonts) {
$this->useSubstitutions = true;
$this->SetSubstitutions();
} else {
$this->useSubstitutions = false;
}
/* -- HTML-CSS -- */
if (!class_exists('cssmgr', false)) {
include(_MPDF_PATH . 'classes/cssmgr.php');
}
$this->cssmgr = new cssmgr($this);
// mPDF 6
if (file_exists(_MPDF_PATH . 'mpdf.css')) {
$css = file_get_contents(_MPDF_PATH . 'mpdf.css');
$this->cssmgr->ReadCSS('<style> ' . $css . ' </style>');
}
/* -- END HTML-CSS -- */
if ($default_font == '') {
if ($this->onlyCoreFonts) {
if (in_array(strtolower($this->defaultCSS['BODY']['FONT-
FAMILY']), $this->mono_fonts)) {
$default_font = 'ccourier';
} elseif (in_array(strtolower($this->defaultCSS['BODY']
['FONT-FAMILY']), $this->sans_fonts)) {
$default_font = 'chelvetica';
} else {
$default_font = 'ctimes';
}
} else {
$default_font = $this->defaultCSS['BODY']['FONT-FAMILY'];
}
}
if (!$default_font_size) {
$mmsize = $this->ConvertSize($this->defaultCSS['BODY']['FONT-
SIZE']);
$default_font_size = $mmsize * (_MPDFK);
}
if ($default_font) {
$this->SetDefaultFont($default_font);
}
if ($default_font_size) {
$this->SetDefaultFontSize($default_font_size);
}
$this->SetLineHeight(); // lineheight is in mm
$this->SetFColor($this->ConvertColor(255));
$this->HREF = '';
$this->oldy = -1;
$this->B = 0;
$this->I = 0;
// mPDF 6 Lists
$this->listlvl = 0;
$this->listtype = array();
$this->listitem = array();
$this->listcounter = array();
$this->tdbegin = false;
$this->table = array();
$this->cell = array();
$this->col = -1;
$this->row = -1;
$this->cellBorderBuffer = array();
$this->divbegin = false;
// mPDF 6
$this->cellTextAlign = '';
$this->cellLineHeight = '';
$this->cellLineStackingStrategy = '';
$this->cellLineStackingShift = '';
$this->divwidth = 0;
$this->divheight = 0;
$this->spanbgcolor = false;
$this->spanborder = false;
$this->spanborddet = array();
$this->blockjustfinished = false;
$this->ignorefollowingspaces = true; //in order to eliminate exceeding
left-side spaces
$this->dash_on = false;
$this->dotted_on = false;
$this->textshadow = '';
$this->currentfontfamily = '';
$this->currentfontsize = '';
$this->currentfontstyle = '';
$this->colorarray = ''; // mPDF 6
$this->spanbgcolorarray = ''; // mPDF 6
$this->textbuffer = array();
$this->internallink = array();
$this->basepath = "";
$this->SetBasePath('');
$this->textparam = array();
$this->specialcontent = '';
$this->selectoption = array();
/* -- IMPORTS -- */
$this->tpls = array();
$this->tpl = 0;
$this->tplprefix = "/TPL";
$this->res = array();
if ($this->enableImports) {
$this->SetImportUse();
}
/* -- END IMPORTS -- */
if ($this->progressBar) {
$this->StartProgressBarOutput($this->progressBar);
} // *PROGRESS-BAR*
$this->fwPt = $format[0];
$this->fhPt = $format[1];
} else {
if (!$format[0] || !$format[1]) {
throw new MpdfException('Invalid page format: ' .
$format[0] . ' ' . $format[1]);
}
$this->fwPt = $format[0] * _MPDFK;
$this->fhPt = $format[1] * _MPDFK;
}
$this->fw = $this->fwPt / _MPDFK;
$this->fh = $this->fhPt / _MPDFK;
//Page orientation
$orientation = strtolower($orientation);
if ($orientation == 'p' or $orientation == 'portrait') {
$orientation = 'P';
$this->wPt = $this->fwPt;
$this->hPt = $this->fhPt;
} elseif ($orientation == 'l' or $orientation == 'landscape') {
$orientation = 'L';
$this->wPt = $this->fhPt;
$this->hPt = $this->fwPt;
} else
throw new MpdfException('Incorrect orientation: ' .
$orientation);
$this->CurOrientation = $orientation;
function _getPageFormat($format)
{
switch (strtoupper($format)) {
case '4A0': {
$format = array(4767.87, 6740.79);
break;
}
case '2A0': {
$format = array(3370.39, 4767.87);
break;
}
case 'A0': {
$format = array(2383.94, 3370.39);
break;
}
case 'A1': {
$format = array(1683.78, 2383.94);
break;
}
case 'A2': {
$format = array(1190.55, 1683.78);
break;
}
case 'A3': {
$format = array(841.89, 1190.55);
break;
}
case 'A4': {
$format = array(595.28, 841.89);
break;
}
case 'A5': {
$format = array(419.53, 595.28);
break;
}
case 'A6': {
$format = array(297.64, 419.53);
break;
}
case 'A7': {
$format = array(209.76, 297.64);
break;
}
case 'A8': {
$format = array(147.40, 209.76);
break;
}
case 'A9': {
$format = array(104.88, 147.40);
break;
}
case 'A10': {
$format = array(73.70, 104.88);
break;
}
case 'B0': {
$format = array(2834.65, 4008.19);
break;
}
case 'B1': {
$format = array(2004.09, 2834.65);
break;
}
case 'B2': {
$format = array(1417.32, 2004.09);
break;
}
case 'B3': {
$format = array(1000.63, 1417.32);
break;
}
case 'B4': {
$format = array(708.66, 1000.63);
break;
}
case 'B5': {
$format = array(498.90, 708.66);
break;
}
case 'B6': {
$format = array(354.33, 498.90);
break;
}
case 'B7': {
$format = array(249.45, 354.33);
break;
}
case 'B8': {
$format = array(175.75, 249.45);
break;
}
case 'B9': {
$format = array(124.72, 175.75);
break;
}
case 'B10': {
$format = array(87.87, 124.72);
break;
}
case 'C0': {
$format = array(2599.37, 3676.54);
break;
}
case 'C1': {
$format = array(1836.85, 2599.37);
break;
}
case 'C2': {
$format = array(1298.27, 1836.85);
break;
}
case 'C3': {
$format = array(918.43, 1298.27);
break;
}
case 'C4': {
$format = array(649.13, 918.43);
break;
}
case 'C5': {
$format = array(459.21, 649.13);
break;
}
case 'C6': {
$format = array(323.15, 459.21);
break;
}
case 'C7': {
$format = array(229.61, 323.15);
break;
}
case 'C8': {
$format = array(161.57, 229.61);
break;
}
case 'C9': {
$format = array(113.39, 161.57);
break;
}
case 'C10': {
$format = array(79.37, 113.39);
break;
}
case 'RA0': {
$format = array(2437.80, 3458.27);
break;
}
case 'RA1': {
$format = array(1729.13, 2437.80);
break;
}
case 'RA2': {
$format = array(1218.90, 1729.13);
break;
}
case 'RA3': {
$format = array(864.57, 1218.90);
break;
}
case 'RA4': {
$format = array(609.45, 864.57);
break;
}
case 'SRA0': {
$format = array(2551.18, 3628.35);
break;
}
case 'SRA1': {
$format = array(1814.17, 2551.18);
break;
}
case 'SRA2': {
$format = array(1275.59, 1814.17);
break;
}
case 'SRA3': {
$format = array(907.09, 1275.59);
break;
}
case 'SRA4': {
$format = array(637.80, 907.09);
break;
}
case 'LETTER': {
$format = array(612.00, 792.00);
break;
}
case 'LEGAL': {
$format = array(612.00, 1008.00);
break;
}
case 'LEDGER': {
$format = array(1224.00, 792.00);
break;
}
case 'TABLOID': {
$format = array(792.00, 1224.00);
break;
}
case 'EXECUTIVE': {
$format = array(521.86, 756.00);
break;
}
case 'FOLIO': {
$format = array(612.00, 936.00);
break;
}
case 'B': {
$format = array(362.83, 561.26);
break;
} // 'B' format paperback size 128x198mm
case 'A': {
$format = array(314.65, 504.57);
break;
} // 'A' format paperback size 111x178mm
case 'DEMY': {
$format = array(382.68, 612.28);
break;
} // 'Demy' format paperback size 135x216mm
case 'ROYAL': {
$format = array(433.70, 663.30);
break;
} // 'Royal' format paperback size 153x234mm
default: {
$format = array(595.28, 841.89);
break;
}
}
return $format;
}
/* -- PROGRESS-BAR -- */
function StartProgressBarOutput($mode = 1)
{
// must be relative path, or URI (not a file system path)
if (!defined('_MPDF_URI')) {
$this->progressBar = false;
if ($this->debug) {
throw new MpdfException("You need to define _MPDF_URI to
use the progress bar!");
} else
return false;
}
$this->progressBar = $mode;
if ($this->progbar_altHTML) {
echo $this->progbar_altHTML;
} else {
echo '<html>
<head>
<title>mPDF File Progress</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="' . _MPDF_URI . 'progbar.css" />
</head>
<body>
<div class="main">
<div class="heading">' . $this->progbar_heading . '</div>
<div class="demo">
';
if ($this->progressBar == 2) {
echo ' <table width="100%"><tr><td style="width:
50%;">
<span class="barheading">Writing HTML code</span> <br/>
<div class="progressBar">
<div id="element1" class="innerBar"> </div>
</div>
<span class="code" id="box1"></span>
</td><td style="width: 50%;">
<span class="barheading">Autosizing elements</span> <br/>
<div class="progressBar">
<div id="element4" class="innerBar"> </div>
</div>
<span class="code" id="box4"></span>
<br/><br/>
<span class="barheading">Writing Tables</span> <br/>
<div class="progressBar">
<div id="element7" class="innerBar"> </div>
</div>
<span class="code" id="box7"></span>
</td></tr>
<tr><td><br /><br /></td><td></td></tr>
<tr><td style="width: 50%;">
';
}
echo ' <span class="barheading">Writing PDF
file</span> <br/>
<div class="progressBar">
<div id="element2" class="innerBar"> </div>
</div>
<span class="code" id="box2"></span>
';
if ($this->progressBar == 2) {
echo '
</td><td style="width: 50%;">
<span class="barheading">Memory usage</span> <br/>
<div class="progressBar">
<div id="element5" class="innerBar"> </div>
</div>
<span id="box5">0</span> ' . ini_get("memory_limit") . '<br />
<br/><br/>
<span class="barheading">Memory usage (peak)</span> <br/>
<div class="progressBar">
<div id="element6" class="innerBar"> </div>
</div>
<span id="box6">0</span> ' . ini_get("memory_limit") . '<br />
</td></tr>
</table>
';
}
echo ' <br/><br/>
<span id="box3"></span>
</div>
';
}
ob_flush();
flush();
}
if ($this->progressBar < 2) {
if ($el > 3) {
return;
} elseif ($el == 1) {
$el = 2;
}
}
echo '<script type="text/javascript">';
if ($val) {
echo ' document.getElementById(\'element' . $el .
'\').style.width=\'' . $val . '%\'; ';
}
if ($txt) {
echo ' document.getElementById(\'box' . $el .
'\').innerHTML=\'' . $txt . '\'; ';
}
if ($this->progressBar == 2) {
$m = round(memory_get_usage(true) / 1048576);
$m2 = round(memory_get_peak_usage(true) / 1048576);
$mem = $m * 100 / (ini_get("memory_limit") + 0);
$mem2 = $m2 * 100 / (ini_get("memory_limit") + 0);
echo ' document.getElementById(\'element5\').style.width=\'' .
$mem . '%\'; ';
echo ' document.getElementById(\'element6\').style.width=\'' .
$mem2 . '%\'; ';
echo ' document.getElementById(\'box5\').innerHTML=\'' . $m . 'MB
/ \'; ';
echo ' document.getElementById(\'box6\').innerHTML=\'' . $m2 .
'MB / \'; ';
}
echo '</script>' . "\n";
ob_flush();
flush();
}
/* -- END PROGRESS-BAR -- */
function RestrictUnicodeFonts($res)
{
// $res = array of (Unicode) fonts to restrict to: e.g. norasi|norasiB
- language specific
if (count($res)) { // Leave full list of available fonts if passed
blank array
$this->available_unifonts = $res;
} else {
$this->available_unifonts = $this->default_available_fonts;
}
if (count($this->available_unifonts) == 0) {
$this->available_unifonts[] = $this->default_available_fonts[0];
}
$this->available_unifonts = array_values($this->available_unifonts);
}
function setMBencoding($enc)
{
if ($this->mb_enc != $enc) {
$this->mb_enc = $enc;
mb_internal_encoding($this->mb_enc);
}
}
function ResetMargins()
{
//ReSet left, top margins
if (($this->forcePortraitHeaders || $this->forcePortraitMargins) &&
$this->DefOrientation == 'P' && $this->CurOrientation == 'L') {
if (($this->mirrorMargins) && (($this->page) % 2 == 0)) { // EVEN
$this->tMargin = $this->orig_rMargin;
$this->bMargin = $this->orig_lMargin;
} else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
$this->tMargin = $this->orig_lMargin;
$this->bMargin = $this->orig_rMargin;
}
$this->lMargin = $this->DeflMargin;
$this->rMargin = $this->DefrMargin;
$this->MarginCorrection = 0;
$this->PageBreakTrigger = $this->h - $this->bMargin;
} elseif (($this->mirrorMargins) && (($this->page) % 2 == 0)) { // EVEN
$this->lMargin = $this->DefrMargin;
$this->rMargin = $this->DeflMargin;
$this->MarginCorrection = $this->DefrMargin - $this->DeflMargin;
} else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
$this->lMargin = $this->DeflMargin;
$this->rMargin = $this->DefrMargin;
if ($this->mirrorMargins) {
$this->MarginCorrection = $this->DeflMargin - $this-
>DefrMargin;
}
}
$this->x = $this->lMargin;
}
function SetLeftMargin($margin)
{
//Set left margin
$this->lMargin = $margin;
if ($this->page > 0 and $this->x < $margin)
$this->x = $margin;
}
function SetTopMargin($margin)
{
//Set top margin
$this->tMargin = $margin;
}
function SetRightMargin($margin)
{
//Set right margin
$this->rMargin = $margin;
}
function SetCompression($compress)
{
//Set page compression
if (function_exists('gzcompress'))
$this->compress = $compress;
else
$this->compress = false;
}
function SetTitle($title)
{
//Title of document // Arrives as UTF-8
$this->title = $title;
}
function SetSubject($subject)
{
//Subject of document
$this->subject = $subject;
}
function SetAuthor($author)
{
//Author of document
$this->author = $author;
}
function SetKeywords($keywords)
{
//Keywords of document
$this->keywords = $keywords;
}
function SetCreator($creator)
{
//Creator of document
$this->creator = $creator;
}
function SetAnchor2Bookmark($x)
{
$this->anchor2Bookmark = $x;
}
function SetVisibility($v)
{
if (($this->PDFA || $this->PDFX) && $this->visibility != 'visible') {
$this->PDFAXwarnings[] = "Cannot set visibility to anything other
than full when using PDFA or PDFX";
return '';
} elseif (!$this->PDFA && !$this->PDFX)
$this->pdf_version = '1.5';
if ($this->visibility != 'visible') {
$this->_out('EMC');
$this->hasOC = intval($this->hasOC);
}
if ($v == 'printonly') {
$this->_out('/OC /OC1 BDC');
$this->hasOC = ($this->hasOC | 1);
} elseif ($v == 'screenonly') {
$this->_out('/OC /OC2 BDC');
$this->hasOC = ($this->hasOC | 2);
} elseif ($v == 'hidden') {
$this->_out('/OC /OC3 BDC');
$this->hasOC = ($this->hasOC | 4);
} elseif ($v != 'visible')
throw new MpdfException('Incorrect visibility: ' . $v);
$this->visibility = $v;
}
function Open()
{
//Begin document
if ($this->state == 0) {
// Was is function _begindoc()
// Start document
$this->state = 1;
$this->_out('%PDF-' . $this->pdf_version);
$this->_out('%' . chr(226) . chr(227) . chr(207) . chr(211)); //
4 chars > 128 to show binary file
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// DEPRACATED but included for backwards compatability
// Depracated - can use AddPage for all
function AddPages($a = '', $b = '', $c = '', $d = '', $e = '', $f = '', $g =
'', $h = '', $i = '', $j = '', $k = '', $l = '', $m = '', $n = '', $o = '', $p = 0,
$q = 0, $r = 0, $s = 0, $t = '', $u = '')
{
throw new MpdfException('function AddPages is depracated as of mPDF 6.
Please use AddPage or HTML code methods instead.');
}
function startPageNums()
{
throw new MpdfException('function startPageNums is depracated as of
mPDF 6.');
}
function SetAutoFont($a)
{
throw new MpdfException('function SetAutoFont is depracated as of mPDF
6. Please use autoScriptToLang instead. See config.php');
}
function Reference($a)
{
throw new MpdfException('function Reference is depracated as of mPDF 6.
Please use IndexEntry instead.');
}
function Close()
{
// Check old Aliases - now depracated mPDF 6
if (isset($this->UnvalidatedText)) {
throw new MpdfException('$mpdf->UnvalidatedText is depracated as
of mPDF 6. Please use $mpdf->watermarkText instead.');
}
if (isset($this->TopicIsUnvalidated)) {
throw new MpdfException('$mpdf->TopicIsUnvalidated is depracated
as of mPDF 6. Please use $mpdf->showWatermarkText instead.');
}
if (isset($this->AliasNbPg)) {
throw new MpdfException('$mpdf->AliasNbPg is depracated as of
mPDF 6. Please use $mpdf->aliasNbPg instead.');
}
if (isset($this->AliasNbPgGp)) {
throw new MpdfException('$mpdf->AliasNbPgGp is depracated as of
mPDF 6. Please use $mpdf->aliasNbPgGp instead.');
}
if (isset($this->BiDirectional)) {
throw new MpdfException('$mpdf->BiDirectional is depracated as of
mPDF 6. Please use $mpdf->biDirectional instead.');
}
if (isset($this->Anchor2Bookmark)) {
throw new MpdfException('$mpdf->Anchor2Bookmark is depracated as
of mPDF 6. Please use $mpdf->anchor2Bookmark instead.');
}
if (isset($this->KeepColumns)) {
throw new MpdfException('$mpdf->KeepColumns is depracated as of
mPDF 6. Please use $mpdf->keepColumns instead.');
}
if (isset($this->useOddEven)) {
throw new MpdfException('$mpdf->useOddEven is depracated as of
mPDF 6. Please use $mpdf->mirrorMargins instead.');
}
if (isset($this->useSubstitutionsMB)) {
throw new MpdfException('$mpdf->useSubstitutionsMB is depracated
as of mPDF 6. Please use $mpdf->useSubstitutions instead.');
}
if (isset($this->useLang)) {
throw new MpdfException('$mpdf->useLang is depracated as of mPDF
6. Please use $mpdf->autoLangToFont instead.');
}
if (isset($this->useAutoFont)) {
throw new MpdfException('$mpdf->useAutoFont is depracated. Please
use $mpdf->autoScriptToLang instead.');
}
if ($this->progressBar) {
$this->UpdateProgressBar(2, '2', 'Closing last page');
} // *PROGRESS-BAR*
//Terminate document
if ($this->state == 3)
return;
if ($this->page == 0)
$this->AddPage($this->CurOrientation);
if (count($this->cellBorderBuffer)) {
$this->printcellbuffer();
} // *TABLES*
if ($this->tablebuffer) {
$this->printtablebuffer();
} // *TABLES*
/* -- COLUMNS -- */
if ($this->ColActive) {
$this->SetColumns(0);
$this->ColActive = 0;
if (count($this->columnbuffer)) {
$this->printcolumnbuffer();
}
}
/* -- END COLUMNS -- */
// BODY Backgrounds
$s = '';
$s .= $this->PrintBodyBackgrounds();
$s .= $this->PrintPageBackgrounds();
$this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS' .
$this->uniqstr . ')/', "\n" . $s . "\n" . '\\1', $this->pages[$this->page]);
$this->pageBackgrounds = array();
if ($this->visibility != 'visible')
$this->SetVisibility('visible');
$this->EndLayer();
//Close document
$this->_enddoc();
}
/* -- BACKGROUNDS -- */
/* -- END BACKGROUNDS -- */
function PrintBodyBackgrounds()
{
$s = '';
$clx = 0;
$cly = 0;
$clw = $this->w;
$clh = $this->h;
// If using bleed and trim margins in paged media
if ($this->pageDim[$this->page]['outer_width_LR'] || $this-
>pageDim[$this->page]['outer_width_TB']) {
$clx = $this->pageDim[$this->page]['outer_width_LR'] - $this-
>pageDim[$this->page]['bleedMargin'];
$cly = $this->pageDim[$this->page]['outer_width_TB'] - $this-
>pageDim[$this->page]['bleedMargin'];
$clw = $this->w - 2 * $clx;
$clh = $this->h - 2 * $cly;
}
if ($this->bodyBackgroundColor) {
$s .= 'q ' . $this->SetFColor($this->bodyBackgroundColor, true) .
"\n";
if ($this->bodyBackgroundColor{0} == 5) { // RGBa
$s .= $this->SetAlpha(ord($this->bodyBackgroundColor{4}) /
100, 'Normal', true, 'F') . "\n";
} elseif ($this->bodyBackgroundColor{0} == 6) { // CMYKa
$s .= $this->SetAlpha(ord($this->bodyBackgroundColor{5}) /
100, 'Normal', true, 'F') . "\n";
}
$s .= sprintf('%.3F %.3F %.3F %.3F re f Q', ($clx * _MPDFK),
($cly * _MPDFK), $clw * _MPDFK, $clh * _MPDFK) . "\n";
}
/* -- BACKGROUNDS -- */
if ($this->bodyBackgroundGradient) {
$g = $this->grad->parseBackgroundGradient($this-
>bodyBackgroundGradient);
if ($g) {
$s .= $this->grad->Gradient($clx, $cly, $clw, $clh,
(isset($g['gradtype']) ? $g['gradtype'] : null), $g['stops'], $g['colorspace'],
$g['coords'], $g['extend'], true);
}
}
if ($this->bodyBackgroundImage) {
if (isset($this->bodyBackgroundImage['gradient']) && $this-
>bodyBackgroundImage['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|
radial)-gradient/', $this->bodyBackgroundImage['gradient'])) {
$g = $this->grad->parseMozGradient($this-
>bodyBackgroundImage['gradient']);
if ($g) {
$s .= $this->grad->Gradient($clx, $cly, $clw, $clh,
$g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true);
}
} elseif ($this->bodyBackgroundImage['image_id']) { // Background
pattern
$n = count($this->patterns) + 1;
// If using resize, uses TrimBox (not including the bleed)
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']);
function PrintPageBackgrounds($adjustmenty = 0)
{
$s = '';
ksort($this->pageBackgrounds);
foreach ($this->pageBackgrounds AS $bl => $pbs) {
foreach ($pbs AS $pb) {
if ((!isset($pb['image_id']) && !isset($pb['gradient'])) ||
isset($pb['shadowonly'])) { // Background colour or boxshadow
if ($pb['z-index'] > 0) {
$this->current_layer = $pb['z-index'];
$s .= "\n" . '/OCBZ-index /ZI' . $pb['z-index']
. ' BDC' . "\n";
}
if ($pb['visibility'] != 'visible') {
if ($pb['visibility'] == 'printonly')
$s .= '/OC /OC1 BDC' . "\n";
elseif ($pb['visibility'] == 'screenonly')
$s .= '/OC /OC2 BDC' . "\n";
elseif ($pb['visibility'] == 'hidden')
$s .= '/OC /OC3 BDC' . "\n";
}
// Box shadow
if (isset($pb['shadow']) && $pb['shadow']) {
$s .= $pb['shadow'] . "\n";
}
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= $pb['clippath'] . "\n";
}
$s .= 'q ' . $this->SetFColor($pb['col'], true) .
"\n";
if ($pb['col']{0} == 5) { // RGBa
$s .= $this->SetAlpha(ord($pb['col']{4}) / 100,
'Normal', true, 'F') . "\n";
} elseif ($pb['col']{0} == 6) { // CMYKa
$s .= $this->SetAlpha(ord($pb['col']{5}) / 100,
'Normal', true, 'F') . "\n";
}
$s .= sprintf('%.3F %.3F %.3F %.3F re f Q', $pb['x']
* _MPDFK, ($this->h - $pb['y']) * _MPDFK, $pb['w'] * _MPDFK, -$pb['h'] * _MPDFK) .
"\n";
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= 'Q' . "\n";
}
if ($pb['visibility'] != 'visible')
$s .= 'EMC' . "\n";
if ($pb['z-index'] > 0) {
$s .= "\n" . 'EMCBZ-index' . "\n";
$this->current_layer = 0;
}
}
}
/* -- BACKGROUNDS -- */
foreach ($pbs AS $pb) {
if ((isset($pb['gradient']) && $pb['gradient']) ||
(isset($pb['image_id']) && $pb['image_id'])) {
if ($pb['z-index'] > 0) {
$this->current_layer = $pb['z-index'];
$s .= "\n" . '/OCGZ-index /ZI' . $pb['z-index']
. ' BDC' . "\n";
}
if ($pb['visibility'] != 'visible') {
if ($pb['visibility'] == 'printonly')
$s .= '/OC /OC1 BDC' . "\n";
elseif ($pb['visibility'] == 'screenonly')
$s .= '/OC /OC2 BDC' . "\n";
elseif ($pb['visibility'] == 'hidden')
$s .= '/OC /OC3 BDC' . "\n";
}
}
if (isset($pb['gradient']) && $pb['gradient']) {
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= $pb['clippath'] . "\n";
}
$s .= $this->grad->Gradient($pb['x'], $pb['y'],
$pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'],
$pb['coords'], $pb['extend'], true);
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= 'Q' . "\n";
}
} elseif (isset($pb['image_id']) && $pb['image_id']) { //
Background Image
$pb['y'] -= $adjustmenty;
$pb['h'] += $adjustmenty;
$n = count($this->patterns) + 1;
list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this-
>_resizeBackgroundImage($pb['orig_w'], $pb['orig_h'], $pb['w'], $pb['h'],
$pb['resize'], $pb['x_repeat'], $pb['y_repeat'], $pb['bpa'], $pb['size']);
$this->patterns[$n] = array('x' => $pb['x'], 'y' =>
$pb['y'], 'w' => $pb['w'], 'h' => $pb['h'], 'pgh' => $this->h, 'image_id' =>
$pb['image_id'], 'orig_w' => $orig_w, 'orig_h' => $orig_h, 'x_pos' => $pb['x_pos'],
'y_pos' => $pb['y_pos'], 'x_repeat' => $x_repeat, 'y_repeat' => $y_repeat, 'itype'
=> $pb['itype'], 'bpa' => $pb['bpa']);
$x = $pb['x'] * _MPDFK;
$y = ($this->h - $pb['y']) * _MPDFK;
$w = $pb['w'] * _MPDFK;
$h = -$pb['h'] * _MPDFK;
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= $pb['clippath'] . "\n";
}
if ($this->writingHTMLfooter || $this-
>writingHTMLheader) { // Write each (tiles) image rather than use as a pattern
$iw = $pb['orig_w'] / _MPDFK;
$ih = $pb['orig_h'] / _MPDFK;
$w = $pb['w'];
$h = $pb['h'];
$x0 = $pb['x'];
$y0 = $pb['y'];
if ($size['w'] == 'contain') {
// Scale the image, while
preserving its intrinsic aspect ratio (if any), to the largest size such that both
its width and its height can fit inside the background positioning area.
// Same as resize==3
$ih = $ih * $pb['bpa']['w'] / $iw;
$iw = $pb['bpa']['w'];
if ($ih > $pb['bpa']['h']) {
$iw = $iw * $pb['bpa']['h'] /
$ih;
$ih = $pb['bpa']['h'];
}
} elseif ($size['w'] == 'cover') {
// Scale the image, while
preserving its intrinsic aspect ratio (if any), to the smallest size such that both
its width and its height can completely cover the background positioning area.
$ih = $ih * $pb['bpa']['w'] / $iw;
$iw = $pb['bpa']['w'];
if ($ih < $pb['bpa']['h']) {
$iw = $iw * $ih / $pb['bpa']
['h'];
$ih = $pb['bpa']['h'];
}
} else {
if (stristr($size['w'], '%')) {
$size['w'] += 0;
$size['w'] /= 100;
$size['w'] = ($pb['bpa']['w']
* $size['w']);
}
if (stristr($size['h'], '%')) {
$size['h'] += 0;
$size['h'] /= 100;
$size['h'] = ($pb['bpa']['h']
* $size['h']);
}
if ($size['w'] == 'auto' &&
$size['h'] == 'auto') {
$iw = $iw;
$ih = $ih;
} elseif ($size['w'] == 'auto' &&
$size['h'] != 'auto') {
$iw = $iw * $size['h'] / $ih;
$ih = $size['h'];
} elseif ($size['w'] != 'auto' &&
$size['h'] == 'auto') {
$ih = $ih * $size['w'] / $iw;
$iw = $size['w'];
} else {
$iw = $size['w'];
$ih = $size['h'];
}
}
}
// Number to repeat
if ($pb['x_repeat']) {
$nx = ceil($pb['w'] / $iw) + 1;
} else {
$nx = 1;
}
if ($pb['y_repeat']) {
$ny = ceil($pb['h'] / $ih) + 1;
} else {
$ny = 1;
}
$x_pos = $pb['x_pos'];
if (stristr($x_pos, '%')) {
$x_pos += 0;
$x_pos /= 100;
$x_pos = ($pb['bpa']['w'] * $x_pos) -
($iw * $x_pos);
}
$y_pos = $pb['y_pos'];
if (stristr($y_pos, '%')) {
$y_pos += 0;
$y_pos /= 100;
$y_pos = ($pb['bpa']['h'] * $y_pos) -
($ih * $y_pos);
}
if ($nx > 1) {
while ($x_pos > ($pb['x'] - $pb['bpa']
['x'])) {
$x_pos -= $iw;
}
}
if ($ny > 1) {
while ($y_pos > ($pb['y'] - $pb['bpa']
['y'])) {
$y_pos -= $ih;
}
}
for ($xi = 0; $xi < $nx; $xi++) {
for ($yi = 0; $yi < $ny; $yi++) {
$x = $x0 + $x_pos + ($iw * $xi);
$y = $y0 + $y_pos + ($ih * $yi);
if ($pb['opacity'] > 0 &&
$pb['opacity'] < 1) {
$opac = $this-
>SetAlpha($pb['opacity'], 'Normal', true);
} else {
$opac = '';
}
$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";
}
}
} else {
if (($pb['opacity'] > 0 || $pb['opacity'] ===
'0') && $pb['opacity'] < 1) {
$opac = $this->SetAlpha($pb['opacity'],
'Normal', true);
} else {
$opac = '';
}
$s .= sprintf('q /Pattern cs /P%d scn %s %.3F
%.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) . "\n";
}
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= 'Q' . "\n";
}
}
if ((isset($pb['gradient']) && $pb['gradient']) ||
(isset($pb['image_id']) && $pb['image_id'])) {
if ($pb['visibility'] != 'visible')
$s .= 'EMC' . "\n";
if ($pb['z-index'] > 0) {
$s .= "\n" . 'EMCGZ-index' . "\n";
$this->current_layer = 0;
}
}
}
/* -- END BACKGROUNDS -- */
}
return $s;
}
function PrintTableBackgrounds($adjustmenty = 0)
{
$s = '';
/* -- BACKGROUNDS -- */
ksort($this->tableBackgrounds);
foreach ($this->tableBackgrounds AS $bl => $pbs) {
foreach ($pbs AS $pb) {
if ((!isset($pb['gradient']) || !$pb['gradient']) && (!
isset($pb['image_id']) || !$pb['image_id'])) {
$s .= 'q ' . $this->SetFColor($pb['col'], true) .
"\n";
if ($pb['col']{0} == 5) { // RGBa
$s .= $this->SetAlpha(ord($pb['col']{4}) / 100,
'Normal', true, 'F') . "\n";
} elseif ($pb['col']{0} == 6) { // CMYKa
$s .= $this->SetAlpha(ord($pb['col']{5}) / 100,
'Normal', true, 'F') . "\n";
}
$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";
}
if (isset($pb['gradient']) && $pb['gradient']) {
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= $pb['clippath'] . "\n";
}
$s .= $this->grad->Gradient($pb['x'], $pb['y'],
$pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'],
$pb['coords'], $pb['extend'], true);
if (isset($pb['clippath']) && $pb['clippath']) {
$s .= 'Q' . "\n";
}
}
if (isset($pb['image_id']) && $pb['image_id']) { //
Background pattern
$pb['y'] -= $adjustmenty;
$pb['h'] += $adjustmenty;
$n = count($this->patterns) + 1;
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']);
$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']);
$x = $pb['x'] * _MPDFK;
$y = ($this->h - $pb['y']) * _MPDFK;
$w = $pb['w'] * _MPDFK;
$h = -$pb['h'] * _MPDFK;
// mPDF 5.7.3
if (($this->writingHTMLfooter || $this-
>writingHTMLheader) && (!isset($pb['clippath']) || $pb['clippath'] == '')) {
// Set clipping path
$pb['clippath'] = sprintf(' q 0 w %.3F %.3F m
%.3F %.3F l %.3F %.3F l %.3F %.3F l %.3F %.3F l W n ', $x, $y, $x, $y + $h, $x +
$w, $y + $h, $x + $w, $y, $x, $y);
}
// mPDF 5.7.3
if ($this->writingHTMLfooter || $this-
>writingHTMLheader) { // Write each (tiles) image rather than use as a pattern
$iw = $pb['orig_w'] / _MPDFK;
$ih = $pb['orig_h'] / _MPDFK;
$w = $pb['w'];
$h = $pb['h'];
$x0 = $pb['x'];
$y0 = $pb['y'];
if ($size['w'] == 'contain') {
// Scale the image, while
preserving its intrinsic aspect ratio (if any), to the largest size such that both
its width and its height can fit inside the background positioning area.
// Same as resize==3
$ih = $ih * $pb['bpa']['w'] / $iw;
$iw = $pb['bpa']['w'];
if ($ih > $pb['bpa']['h']) {
$iw = $iw * $pb['bpa']['h'] /
$ih;
$ih = $pb['bpa']['h'];
}
} elseif ($size['w'] == 'cover') {
// Scale the image, while
preserving its intrinsic aspect ratio (if any), to the smallest size such that both
its width and its height can completely cover the background positioning area.
$ih = $ih * $pb['bpa']['w'] / $iw;
$iw = $pb['bpa']['w'];
if ($ih < $pb['bpa']['h']) {
$iw = $iw * $ih / $pb['bpa']
['h'];
$ih = $pb['bpa']['h'];
}
} else {
if (stristr($size['w'], '%')) {
$size['w'] += 0;
$size['w'] /= 100;
$size['w'] = ($pb['bpa']['w']
* $size['w']);
}
if (stristr($size['h'], '%')) {
$size['h'] += 0;
$size['h'] /= 100;
$size['h'] = ($pb['bpa']['h']
* $size['h']);
}
if ($size['w'] == 'auto' &&
$size['h'] == 'auto') {
$iw = $iw;
$ih = $ih;
} elseif ($size['w'] == 'auto' &&
$size['h'] != 'auto') {
$iw = $iw * $size['h'] / $ih;
$ih = $size['h'];
} elseif ($size['w'] != 'auto' &&
$size['h'] == 'auto') {
$ih = $ih * $size['w'] / $iw;
$iw = $size['w'];
} else {
$iw = $size['w'];
$ih = $size['h'];
}
}
}
// Number to repeat
if (isset($pb['x_repeat']) && $pb['x_repeat'])
{
$nx = ceil($pb['w'] / $iw) + 1;
} else {
$nx = 1;
}
if (isset($pb['y_repeat']) && $pb['y_repeat'])
{
$ny = ceil($pb['h'] / $ih) + 1;
} else {
$ny = 1;
}
$x_pos = $pb['x_pos'];
if (stristr($x_pos, '%')) {
$x_pos += 0;
$x_pos /= 100;
$x_pos = ($pb['bpa']['w'] * $x_pos) -
($iw * $x_pos);
}
$y_pos = $pb['y_pos'];
if (stristr($y_pos, '%')) {
$y_pos += 0;
$y_pos /= 100;
$y_pos = ($pb['bpa']['h'] * $y_pos) -
($ih * $y_pos);
}
if ($nx > 1) {
while ($x_pos > ($pb['x'] - $pb['bpa']
['x'])) {
$x_pos -= $iw;
}
}
if ($ny > 1) {
while ($y_pos > ($pb['y'] - $pb['bpa']
['y'])) {
$y_pos -= $ih;
}
}
for ($xi = 0; $xi < $nx; $xi++) {
for ($yi = 0; $yi < $ny; $yi++) {
$x = $x0 + $x_pos + ($iw * $xi);
$y = $y0 + $y_pos + ($ih * $yi);
if ($pb['opacity'] > 0 &&
$pb['opacity'] < 1) {
$opac = $this-
>SetAlpha($pb['opacity'], 'Normal', true);
} else {
$opac = '';
}
$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";
}
}
} else {
if (($pb['opacity'] > 0 || $pb['opacity'] ===
'0') && $pb['opacity'] < 1) {
$opac = $this->SetAlpha($pb['opacity'],
'Normal', true);
} else {
$opac = '';
}
$s .= sprintf('q /Pattern cs /P%d scn %s %.3F
%.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) . "\n";
}
function BeginLayer($id)
{
if ($this->current_layer > 0)
$this->EndLayer();
if ($id < 1) {
return false;
}
if (!isset($this->layers[$id])) {
$this->layers[$id] = array('name' => 'Layer ' . ($id));
if (($this->PDFA || $this->PDFX)) {
$this->PDFAXwarnings[] = "Cannot use layers when using PDFA
or PDFX";
return '';
} elseif (!$this->PDFA && !$this->PDFX) {
$this->pdf_version = '1.5';
}
}
$this->current_layer = $id;
$this->_out('/OCZ-index /ZI' . $id . ' BDC');
$this->pageoutput[$this->page] = array();
}
function EndLayer()
{
if ($this->current_layer > 0) {
$this->_out('EMCZ-index');
$this->current_layer = 0;
}
}
function AddPageByArray($a)
{
if (!is_array($a)) {
$a = array();
}
$orientation = (isset($a['orientation']) ? $a['orientation'] : '');
$condition = (isset($a['condition']) ? $a['condition'] :
(isset($a['type']) ? $a['type'] : ''));
$resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
$pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
$suppress = (isset($a['suppress']) ? $a['suppress'] : '');
$mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ?
$a['margin-left'] : ''));
$mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ?
$a['margin-right'] : ''));
$mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ?
$a['margin-top'] : ''));
$mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ?
$a['margin-bottom'] : ''));
$mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ?
$a['margin-header'] : ''));
$mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ?
$a['margin-footer'] : ''));
$ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-
name']) ? $a['odd-header-name'] : ''));
$ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-
name']) ? $a['even-header-name'] : ''));
$ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-
name']) ? $a['odd-footer-name'] : ''));
$efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-
name']) ? $a['even-footer-name'] : ''));
$ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-
header-value']) ? $a['odd-header-value'] : 0));
$ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-
header-value']) ? $a['even-header-value'] : 0));
$ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-
footer-value']) ? $a['odd-footer-value'] : 0));
$efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-
footer-value']) ? $a['even-footer-value'] : 0));
$pagesel = (isset($a['pagesel']) ? $a['pagesel'] :
(isset($a['pageselector']) ? $a['pageselector'] : ''));
$newformat = (isset($a['newformat']) ? $a['newformat'] :
(isset($a['sheet-size']) ? $a['sheet-size'] : ''));
// mPDF 6 pagebreaktype
function _preForcedPagebreak($pagebreaktype)
{
if ($pagebreaktype == 'cloneall') {
// Close any open block tags
$arr = array();
$ai = 0;
for ($b = $this->blklvl; $b > 0; $b--) {
$this->tag->CloseTag($this->blk[$b]['tag'], $arr, $ai);
}
if ($this->blklvl == 0 && !empty($this->textbuffer)) { //Output
previously buffered content
$this->printbuffer($this->textbuffer, 1);
$this->textbuffer = array();
}
} elseif ($pagebreaktype == 'clonebycss') {
// Close open block tags whilst box-decoration-break==clone
$arr = array();
$ai = 0;
for ($b = $this->blklvl; $b > 0; $b--) {
if (isset($this->blk[$b]['box_decoration_break']) && $this-
>blk[$b]['box_decoration_break'] == 'clone') {
$this->tag->CloseTag($this->blk[$b]['tag'], $arr,
$ai);
} else {
if ($b == $this->blklvl && !empty($this->textbuffer))
{ //Output previously buffered content
$this->printbuffer($this->textbuffer, 1);
$this->textbuffer = array();
}
break;
}
}
} elseif (!empty($this->textbuffer)) { //Output previously buffered
content
$this->printbuffer($this->textbuffer, 1);
$this->textbuffer = array();
}
}
// mPDF 6 pagebreaktype
function _postForcedPagebreak($pagebreaktype, $startpage, $save_blk,
$save_blklvl)
{
if ($pagebreaktype == 'cloneall') {
$this->blk = array();
$this->blk[0] = $save_blk[0];
// Re-open block tags
$this->blklvl = 0;
$arr = array();
$i = 0;
for ($b = 1; $b <= $save_blklvl; $b++) {
$this->tag->OpenTag($save_blk[$b]['tag'], $save_blk[$b]
['attr'], $arr, $i);
}
} elseif ($pagebreaktype == 'clonebycss') {
$this->blk = array();
$this->blk[0] = $save_blk[0];
// Don't re-open tags for lowest level elements - so need to do
some adjustments
for ($b = 1; $b <= $this->blklvl; $b++) {
$this->blk[$b] = $save_blk[$b];
$this->blk[$b]['startpage'] = 0;
$this->blk[$b]['y0'] = $this->y; // ?? $this->tMargin
if (($this->page - $startpage) % 2) {
if (isset($this->blk[$b]['x0'])) {
$this->blk[$b]['x0'] += $this-
>MarginCorrection;
} else {
$this->blk[$b]['x0'] = $this->MarginCorrection;
}
}
//for Float DIV
$this->blk[$b]['marginCorrected'][$this->page] = true;
}
/* -- CSS-FLOAT -- */
// Float DIV
// Cannot do with columns on, or if any change in page
orientation/margins etc.
// If next page already exists - i.e background /headers and footers
already written
if ($this->state > 0 && $this->page < count($this->pages)) {
$bak_cml = $this->cMarginL;
$bak_cmr = $this->cMarginR;
$bak_dw = $this->divwidth;
// Paint Div Border if necessary
if ($this->blklvl > 0) {
$save_tr = $this->table_rotate; // *TABLES*
$this->table_rotate = 0; // *TABLES*
if ($this->y == $this->blk[$this->blklvl]['y0']) {
$this->blk[$this->blklvl]['startpage'] ++;
}
if (($this->y > $this->blk[$this->blklvl]['y0']) || $this-
>flowingBlockAttr['is_table']) {
$toplvl = $this->blklvl;
} else {
$toplvl = $this->blklvl - 1;
}
$sy = $this->y;
for ($bl = 1; $bl <= $toplvl; $bl++) {
$this->PaintDivBB('pagebottom', 0, $bl);
}
$this->y = $sy;
$this->table_rotate = $save_tr; // *TABLES*
}
$s = $this->PrintPageBackgrounds();
$this->printfloatbuffer();
$bak_cml = $this->cMarginL;
$bak_cmr = $this->cMarginR;
$bak_dw = $this->divwidth;
$bak_lh = $this->lineheight;
if ($this->visibility != 'visible')
$this->SetVisibility('visible');
$this->EndLayer();
if ($this->visibility != 'visible')
$this->SetVisibility('visible');
$this->EndLayer();
// BODY Backgrounds
if ($this->page > 0) {
$s = '';
$s .= $this->PrintBodyBackgrounds();
$s .= $this->PrintPageBackgrounds();
$this->pages[$this->page] = preg_replace('/
(___BACKGROUND___PATTERNS' . $this->uniqstr . ')/', "\n" . $s . "\n" . '\\1',
$this->pages[$this->page]);
$this->pageBackgrounds = array();
}
$save_kt = $this->keep_block_together;
$this->keep_block_together = 0;
$save_cols = false;
/* -- COLUMNS -- */
if ($this->ColActive) {
$save_cols = true;
$save_nbcol = $this->NbCol; // other values of gap and vAlign
will not change by setting Columns off
$this->SetColumns(0);
}
/* -- END COLUMNS -- */
$family = $this->FontFamily;
$style = $this->FontStyle;
$size = $this->FontSizePt;
$this->ColumnAdjust = true; // enables column height adjustment for the
page
$lw = $this->LineWidth;
$dc = $this->DrawColor;
$fc = $this->FillColor;
$tc = $this->TextColor;
$cf = $this->ColorFlag;
if ($this->page > 0) {
//Page footer
$this->InFooter = true;
$this->Reset();
$this->pageoutput[$this->page] = array();
$this->Footer();
//Close page
$this->_endpage();
}
// Tiling Patterns
$this->_out('___PAGE___START' . $this->uniqstr);
$this->_out('___BACKGROUND___PATTERNS' . $this->uniqstr);
$this->_out('___HEADER___MARKER' . $this->uniqstr);
$this->pageBackgrounds = array();
//Set colors
$this->DrawColor = $dc;
if ($dc != $this->defDrawColor)
$this->_out($dc);
$this->FillColor = $fc;
if ($fc != $this->defFillColor)
$this->_out($fc);
$this->TextColor = $tc;
$this->ColorFlag = $cf;
//Page header
$this->Header();
//Restore colors
if ($this->DrawColor != $dc) {
$this->DrawColor = $dc;
$this->_out($dc);
}
if ($this->FillColor != $fc) {
$this->FillColor = $fc;
$this->_out($fc);
}
$this->TextColor = $tc;
$this->ColorFlag = $cf;
$this->InFooter = false;
if ($save_layer > 0)
$this->BeginLayer($save_layer);
if ($save_vis != 'visible')
$this->SetVisibility($save_vis);
/* -- COLUMNS -- */
if ($save_cols) {
// Restore columns
$this->SetColumns($save_nbcol, $this->colvAlign, $this->ColGap);
}
if ($this->ColActive) {
$this->SetCol(0);
}
/* -- END COLUMNS -- */
$this->keep_block_together = $save_kt;
$this->cMarginL = $bak_cml;
$this->cMarginR = $bak_cmr;
$this->divwidth = $bak_dw;
$this->lineheight = $bak_lh;
}
function PageNo()
{
//Get current page number
return $this->page;
}
function AddSpotColorsFromFile($file)
{
$colors = @file($file);
if (!$colors) {
throw new MpdfException("Cannot load spot colors file - " .
$file);
}
foreach ($colors AS $sc) {
list($name, $c, $m, $y, $k) = preg_split("/\t/", $sc);
$c = intval($c);
$m = intval($m);
$y = intval($y);
$k = intval($k);
$this->AddSpotColor($name, $c, $m, $y, $k);
}
}
function GetCharWidthCore($c)
{
//Get width of a single character in the current Core font
$c = (string) $c;
$w = 0;
// Soft Hyphens chr(173)
if ($c == chr(173) && $this->FontFamily != 'csymbol' && $this-
>FontFamily != 'czapfdingbats') {
return 0;
} elseif (($this->textvar & FC_SMALLCAPS) && isset($this-
>upperCase[ord($c)])) { // mPDF 5.7.1
$charw = $this->CurrentFont['cw'][chr($this-
>upperCase[ord($c)])];
if ($charw !== false) {
$charw = $charw * $this->smCapsScale * $this->smCapsStretch
/ 100;
$w+=$charw;
}
} elseif (isset($this->CurrentFont['cw'][$c])) {
$w += $this->CurrentFont['cw'][$c];
} elseif (isset($this->CurrentFont['cw'][ord($c)])) {
$w += $this->CurrentFont['cw'][ord($c)];
}
$w *= ($this->FontSize / 1000);
if ($this->minwSpacing || $this->fixedlSpacing) {
if ($c == ' ')
$nb_spaces = 1;
else
$nb_spaces = 0;
$w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing);
}
return ($w);
}
return ($w);
}
function SetLineWidth($width)
{
//Set line width
$this->LineWidth = $width;
$lwout = (sprintf('%.3F w', $width * _MPDFK));
if ($this->page > 0 && ((isset($this->pageoutput[$this->page]
['LineWidth']) && $this->pageoutput[$this->page]['LineWidth'] != $lwout) || !
isset($this->pageoutput[$this->page]['LineWidth']))) {
$this->_out($lwout);
}
$this->pageoutput[$this->page]['LineWidth'] = $lwout;
}
function Arrow($x1, $y1, $x2, $y2, $headsize = 3, $fill = 'B', $angle = 25)
{
//F == fill //S == stroke //B == stroke and fill
// angle = splay of arrowhead - 1 - 89 degrees
if ($fill == 'F')
$fill = 'f';
elseif ($fill == 'FD' or $fill == 'DF' or $fill == 'B')
$fill = 'B';
else
$fill = 'S';
$a = atan2(($y2 - $y1), ($x2 - $x1));
$b = $a + deg2rad($angle);
$c = $a - deg2rad($angle);
$x3 = $x2 - ($headsize * cos($b));
$y3 = $this->h - ($y2 - ($headsize * sin($b)));
$x4 = $x2 - ($headsize * cos($c));
$y4 = $this->h - ($y2 - ($headsize * sin($c)));
$s = '';
$s.=sprintf('%.3F %.3F m %.3F %.3F l S', $x1 * _MPDFK, ($this->h - $y1)
* _MPDFK, $x5 * _MPDFK, $y5 * _MPDFK);
$this->_out($s);
$s = '';
$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);
$s.=$fill;
$this->_out($s);
}
/* -- CJK-FONTS -- */
if (in_array($family, $this->available_CJK_fonts)) {
if (empty($this->Big5_widths)) {
require(_MPDF_PATH . 'includes/CJKdata.php');
}
$this->AddCJKFont($family); // don't need to add style
return;
}
/* -- END CJK-FONTS -- */
if ($this->usingCoreFont) {
throw new MpdfException("mPDF Error - problem with Font
management");
}
$stylekey = $style;
if (!$style) {
$stylekey = 'R';
}
if (!isset($this->fontdata[$family][$stylekey]) || !$this-
>fontdata[$family][$stylekey]) {
throw new MpdfException('mPDF Error - Font is not supported - ' .
$family . ' ' . $style);
}
$name = '';
$originalsize = 0;
$sip = false;
$smp = false;
$useOTL = 0; // mPDF 5.7.1
$fontmetrics = ''; // mPDF 6
$haskerninfo = false;
$haskernGPOS = false;
$hassmallcapsGSUB = false;
$BMPselected = false;
$GSUBScriptLang = array();
$GSUBFeatures = array();
$GSUBLookups = array();
$GPOSScriptLang = array();
$GPOSFeatures = array();
$GPOSLookups = array();
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey . '.mtx.php')) {
include(_MPDF_TTFONTDATAPATH . $fontkey . '.mtx.php');
}
$ttffile = '';
if (defined('_MPDF_SYSTEM_TTFONTS')) {
$ttffile = _MPDF_SYSTEM_TTFONTS . $this->fontdata[$family]
[$stylekey];
if (!file_exists($ttffile)) {
$ttffile = '';
}
}
if (!$ttffile) {
$ttffile = _MPDF_TTFONTPATH . $this->fontdata[$family]
[$stylekey];
if (!file_exists($ttffile)) {
throw new MpdfException("mPDF Error - cannot find TTF
TrueType font file - " . $ttffile);
}
}
$ttfstat = stat($ttffile);
if (isset($this->fontdata[$family]['TTCfontID'][$stylekey])) {
$TTCfontID = $this->fontdata[$family]['TTCfontID'][$stylekey];
} else {
$TTCfontID = 0;
}
$BMPonly = false;
if (in_array($family, $this->BMPonly)) {
$BMPonly = true;
}
$regenerate = false;
if ($BMPonly && !$BMPselected) {
$regenerate = true;
} elseif (!$BMPonly && $BMPselected) {
$regenerate = true;
}
// mPDF 5.7.1
if (isset($this->fontdata[$family]['useOTL']) && $this-
>fontdata[$family]['useOTL'] && $useOTL != $this->fontdata[$family]['useOTL']) {
$regenerate = true;
$useOTL = $this->fontdata[$family]['useOTL'];
} elseif ((!isset($this->fontdata[$family]['useOTL']) || !$this-
>fontdata[$family]['useOTL']) && $useOTL) {
$regenerate = true;
$useOTL = 0;
}
if (_FONT_DESCRIPTOR != $fontmetrics) {
$regenerate = true;
} // mPDF 6
if (!isset($name) || $originalsize != $ttfstat['size'] || $regenerate)
{
if (!class_exists('TTFontFile', false)) {
include(_MPDF_PATH . 'classes/ttfontsuni.php');
}
$ttf = new TTFontFile();
$ttf->getMetrics($ttffile, $fontkey, $TTCfontID, $this-
>debugfonts, $BMPonly, $useOTL); // mPDF 5.7.1
$cw = $ttf->charWidths;
$kerninfo = $ttf->kerninfo;
if ($kerninfo)
$haskerninfo = true;
$haskernGPOS = $ttf->haskernGPOS;
$hassmallcapsGSUB = $ttf->hassmallcapsGSUB;
$name = preg_replace('/[ ()]/', '', $ttf->fullName);
$sip = $ttf->sipset;
$smp = $ttf->smpset;
// mPDF 6
$GSUBScriptLang = $ttf->GSUBScriptLang;
$GSUBFeatures = $ttf->GSUBFeatures;
$GSUBLookups = $ttf->GSUBLookups;
$rtlPUAstr = $ttf->rtlPUAstr;
$GPOSScriptLang = $ttf->GPOSScriptLang;
$GPOSFeatures = $ttf->GPOSFeatures;
$GPOSLookups = $ttf->GPOSLookups;
$glyphIDtoUni = $ttf->glyphIDtoUni;
$desc = array(
'CapHeight' => round($ttf->capHeight),
'XHeight' => round($ttf->xHeight),
'FontBBox' => '[' . round($ttf->bbox[0]) . " " .
round($ttf->bbox[1]) . " " . round($ttf->bbox[2]) . " " . round($ttf->bbox[3]) .
']', /* FontBBox from head table */
// mPDF 5.7.1
if (isset($this->fontdata[$family]['useOTL'])) {
$s.='$useOTL=' . $this->fontdata[$family]['useOTL'] . ';' .
"\n";
} else
$s.='$useOTL=0x0000;' . "\n";
if ($rtlPUAstr) {
$s.='$rtlPUAstr=\'' . $rtlPUAstr . "';\n";
} else
$s.='$rtlPUAstr=\'\';' . "\n";
if (count($GSUBScriptLang)) {
$s.='$GSUBScriptLang=' . var_export($GSUBScriptLang,
true) . ";\n";
}
if (count($GSUBFeatures)) {
$s.='$GSUBFeatures=' . var_export($GSUBFeatures, true) .
";\n";
}
if (count($GSUBLookups)) {
$s.='$GSUBLookups=' . var_export($GSUBLookups, true) .
";\n";
}
if (count($GPOSScriptLang)) {
$s.='$GPOSScriptLang=' . var_export($GPOSScriptLang,
true) . ";\n";
}
if (count($GPOSFeatures)) {
$s.='$GPOSFeatures=' . var_export($GPOSFeatures, true) .
";\n";
}
if (count($GPOSLookups)) {
$s.='$GPOSLookups=' . var_export($GPOSLookups, true) .
";\n";
}
if ($kerninfo) {
$s.='$kerninfo=' . var_export($kerninfo, true) . ";\n";
}
$s.="?>";
if (is_writable(dirname(_MPDF_TTFONTDATAPATH . 'x'))) {
$fh = fopen(_MPDF_TTFONTDATAPATH . $fontkey . '.mtx.php',
"w");
fwrite($fh, $s, strlen($s));
fclose($fh);
$fh = fopen(_MPDF_TTFONTDATAPATH . $fontkey . '.cw.dat',
"wb");
fwrite($fh, $cw, strlen($cw));
fclose($fh);
// mPDF 5.7.1
$fh = fopen(_MPDF_TTFONTDATAPATH . $fontkey . '.gid.dat',
"wb");
fwrite($fh, $glyphIDtoUni, strlen($glyphIDtoUni));
fclose($fh);
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey . '.cgm'))
unlink(_MPDF_TTFONTDATAPATH . $fontkey . '.cgm');
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey . '.z'))
unlink(_MPDF_TTFONTDATAPATH . $fontkey . '.z');
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey .
'.cw127.php'))
unlink(_MPDF_TTFONTDATAPATH . $fontkey .
'.cw127.php');
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey . '.cw'))
unlink(_MPDF_TTFONTDATAPATH . $fontkey . '.cw');
}
elseif ($this->debugfonts) {
throw new MpdfException('Cannot write to the font caching
directory - ' . _MPDF_TTFONTDATAPATH);
}
unset($ttf);
} else {
$cw = '';
$glyphIDtoUni = '';
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey . '.cw.dat'))
$cw = file_get_contents(_MPDF_TTFONTDATAPATH . $fontkey .
'.cw.dat');
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey . '.gid.dat'))
$glyphIDtoUni = file_get_contents(_MPDF_TTFONTDATAPATH .
$fontkey . '.gid.dat');
}
/* -- OTL -- */
// mPDF 5.7.1
// Use OTL OpenType Table Layout - GSUB
if (isset($this->fontdata[$family]['useOTL']) && ($this-
>fontdata[$family]['useOTL'])) {
if (!class_exists('otl', false)) {
include(_MPDF_PATH . 'classes/otl.php');
}
if (empty($this->otl)) {
$this->otl = new otl($this);
}
}
/* -- END OTL -- */
$i = count($this->fonts) + $this->extraFontSubsets + 1;
if ($sip || $smp) {
$this->fonts[$fontkey] = array('i' => $i, 'type' => $type, 'name'
=> $name, 'desc' => $desc, 'panose' => $panose, 'unitsPerEm' => $unitsPerEm, 'up'
=> $up, 'ut' => $ut, 'strs' => $strs, 'strp' => $strp, 'cw' => $cw, 'ttffile' =>
$ttffile, 'fontkey' => $fontkey, 'subsets' => array(0 => range(0, 127)),
'subsetfontids' => array($i), 'used' => false, 'sip' => $sip, 'sipext' => $sipext,
'smp' => $smp, 'TTCfontID' => $TTCfontID, 'useOTL' => (isset($this-
>fontdata[$family]['useOTL']) ? $this->fontdata[$family]['useOTL'] : false),
'useKashida' => (isset($this->fontdata[$family]['useKashida']) ? $this-
>fontdata[$family]['useKashida'] : false), 'GSUBScriptLang' => $GSUBScriptLang,
'GSUBFeatures' => $GSUBFeatures, 'GSUBLookups' => $GSUBLookups, 'GPOSScriptLang' =>
$GPOSScriptLang, 'GPOSFeatures' => $GPOSFeatures, 'GPOSLookups' => $GPOSLookups,
'rtlPUAstr' => $rtlPUAstr, 'glyphIDtoUni' => $glyphIDtoUni, 'haskerninfo' =>
$haskerninfo, 'haskernGPOS' => $haskernGPOS, 'hassmallcapsGSUB' =>
$hassmallcapsGSUB); // mPDF 5.7.1 // mPDF 6
} else {
$ss = array();
for ($s = 32; $s < 128; $s++) {
$ss[$s] = $s;
}
$this->fonts[$fontkey] = array('i' => $i, 'type' => $type, 'name'
=> $name, 'desc' => $desc, 'panose' => $panose, 'unitsPerEm' => $unitsPerEm, 'up'
=> $up, 'ut' => $ut, 'strs' => $strs, 'strp' => $strp, 'cw' => $cw, 'ttffile' =>
$ttffile, 'fontkey' => $fontkey, 'subset' => $ss, 'used' => false, 'sip' => $sip,
'sipext' => $sipext, 'smp' => $smp, 'TTCfontID' => $TTCfontID, 'useOTL' =>
(isset($this->fontdata[$family]['useOTL']) ? $this->fontdata[$family]['useOTL'] :
false), 'useKashida' => (isset($this->fontdata[$family]['useKashida']) ? $this-
>fontdata[$family]['useKashida'] : false), 'GSUBScriptLang' => $GSUBScriptLang,
'GSUBFeatures' => $GSUBFeatures, 'GSUBLookups' => $GSUBLookups, 'GPOSScriptLang' =>
$GPOSScriptLang, 'GPOSFeatures' => $GPOSFeatures, 'GPOSLookups' => $GPOSLookups,
'rtlPUAstr' => $rtlPUAstr, 'glyphIDtoUni' => $glyphIDtoUni, 'haskerninfo' =>
$haskerninfo, 'haskernGPOS' => $haskernGPOS, 'hassmallcapsGSUB' =>
$hassmallcapsGSUB); // mPDF 5.7.1 // mPDF 6
}
if ($haskerninfo) {
$this->fonts[$fontkey]['kerninfo'] = $kerninfo;
}
$this->FontFiles[$fontkey] = array('length1' => $originalsize, 'type'
=> "TTF", 'ttffile' => $ttffile, 'sip' => $sip, 'smp' => $smp);
unset($cw);
}
// mPDF 5.7.1
if ($style) {
$style = strtoupper($style);
if ($style == 'IB')
$style = 'BI';
}
if ($size == 0)
$size = $this->FontSizePt;
$stylekey = $style;
if (!$stylekey) {
$stylekey = "R";
}
if (!$found) {
// set first available font
$fs = $this->available_unifonts[0];
preg_match('/^([a-z_0-9\-]+)([BI]{0,2})
$/', $fs, $fas); // Allow "-"
// with requested style if possible
$ws = $fas[1] . $style;
if (in_array($ws, $this-
>available_unifonts)) {
$family = $fas[1]; // leave $style
as is
} elseif (in_array($fas[1], $this-
>available_unifonts)) {
// or without style
$family = $fas[1];
$style = '';
} else {
// or with the style specified
$family = $fas[1];
$style = $fas[2];
}
}
}
$fontkey = $family . $style;
}
}
// try to add font (if not already added)
$this->AddFont($family, $style);
//Select it
$this->FontFamily = $family;
$this->FontStyle = $style;
$this->FontSizePt = $size;
$this->FontSize = $size / _MPDFK;
$this->CurrentFont = &$this->fonts[$fontkey];
if ($write) {
$fontout = (sprintf('BT /F%d %.3F Tf ET', $this-
>CurrentFont['i'], $this->FontSizePt));
if ($this->page > 0 && ((isset($this->pageoutput[$this-
>page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !
isset($this->pageoutput[$this->page]['Font']))) {
$this->_out($fontout);
}
$this->pageoutput[$this->page]['Font'] = $fontout;
}
if (!isset($this->CoreFonts[$fontkey])) {
if (in_array($family, $this->serif_fonts)) {
$family = 'ctimes';
} elseif (in_array($family, $this->mono_fonts)) {
$family = 'ccourier';
} else {
$family = 'chelvetica';
}
$this->usingCoreFont = true;
$fontkey = $family . $style;
}
if (!isset($this->fonts[$fontkey])) {
// STANDARD CORE FONTS
if (isset($this->CoreFonts[$fontkey])) {
//Load metric file
$file = $family;
if ($family == 'ctimes' || $family == 'chelvetica' ||
$family == 'ccourier') {
$file.=strtolower($style);
}
$file.='.php';
include(_MPDF_PATH . 'font/' . $file);
if (!isset($cw)) {
throw new MpdfException('Could not include font
metric file');
}
$i = count($this->fonts) + $this->extraFontSubsets +
1;
$this->fonts[$fontkey] = array('i' => $i, 'type' =>
'core', 'name' => $this->CoreFonts[$fontkey], 'desc' => $desc, 'up' => $up, 'ut' =>
$ut, 'cw' => $cw);
if ($this->useKerning && isset($kerninfo)) {
$this->fonts[$fontkey]['kerninfo'] = $kerninfo;
}
} else {
throw new MpdfException('mPDF error - Font not
defined');
}
}
//Test if font is already selected
if (($this->FontFamily == $family) AND ( $this->FontStyle ==
$style) AND ( $this->FontSizePt == $size) && !$forcewrite) {
return $family;
}
//Select it
$this->FontFamily = $family;
$this->FontStyle = $style;
$this->FontSizePt = $size;
$this->FontSize = $size / _MPDFK;
$this->CurrentFont = &$this->fonts[$fontkey];
if ($write) {
$fontout = (sprintf('BT /F%d %.3F Tf ET', $this-
>CurrentFont['i'], $this->FontSizePt));
if ($this->page > 0 && ((isset($this->pageoutput[$this-
>page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !
isset($this->pageoutput[$this->page]['Font']))) {
$this->_out($fontout);
}
$this->pageoutput[$this->page]['Font'] = $fontout;
}
// Added - currentfont (lowercase) used in HTML2PDF
$this->currentfontfamily = $family;
$this->currentfontsize = $size;
$this->currentfontstyle = $style;
}
return $family;
}
function AddLink()
{
//Create a new internal link
$n = count($this->links) + 1;
$this->links[$n] = array(0, 0);
return $n;
}
if ($this->writingHTMLheader || $this->writingHTMLfooter) {
$this->HTMLheaderPageLinks[] = $l;
return;
}
//Put a link on the page
$this->PageLinks[$this->page][] = $l;
// Save cross-reference to Column buffer
$ref = count($this->PageLinks[$this->page]) - 1; // *COLUMNS*
$this->columnLinks[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)]
= $ref; // *COLUMNS*
}
if ($this->ColorFlag)
$s.=$this->TextColor . ' ';
$this->CurrentFont['used'] = true;
if ($this->usingCoreFont) {
$txt2 = str_replace(chr(160), chr(32), $txt);
} else {
$txt2 = str_replace(chr(194) . chr(160), chr(32), $txt);
}
$px = $x;
$py = $y;
if ($coordsys != 'SVG') {
$px = $x * _MPDFK;
$py = ($this->h - $y) * _MPDFK;
}
// IF NOT corefonts [AND NO wordspacing] AND NOT SIP/SMP AND NOT SmCaps
AND NOT Kerning AND NOT OTL
// Just output text
elseif (!$this->usingCoreFont && !($textvar & FC_SMALLCAPS) && !
($textvar & FC_KERNING) && !(isset($this->CurrentFont['useOTL']) && ($this-
>CurrentFont['useOTL'] & 0xFF) && !empty($OTLdata['GPOSinfo']))) {
// IF SIP/SMP
if ($this->CurrentFont['sip'] || $this->CurrentFont['smp']) {
$txt2 = $this->UTF8toSubset($txt2);
$s .=sprintf('BT ' . $aix . ' %s Tj ET', $px, $py, $txt2);
}
// NOT SIP/SMP
else {
$txt2 = $this->UTF8ToUTF16BE($txt2, false);
$txt2 = $this->_escape($txt2);
$s .=sprintf('BT ' . $aix . ' (%s) Tj ET', $px, $py,
$txt2);
}
}
// IF NOT corefonts [AND IS wordspacing] AND NOT SIP AND NOT SmCaps AND
NOT Kerning AND NOT OTL
// Not required here (cf. Cell() )
// ELSE (IF SmCaps || Kerning || OTL) [corefonts or not corefonts; SIP
or SMP or BMP]
else {
$s .= $this->applyGPOSpdf($txt2, $aix, $px, $py, $OTLdata,
$textvar);
}
/* * ************** END ************************ */
$s .= ' ';
if ($return) {
return $s . " \n";
}
$this->_out($s);
}
/* -- DIRECTW -- */
// DIRECTIONALITY
if (preg_match("/([" . $this->pregRTLchars . "])/u", $txt)) {
$this->biDirectional = true;
} // *OTL*
$textvar = 0;
$save_OTLtags = $this->OTLtags;
$this->OTLtags = array();
if ($this->useKerning) {
if ($this->CurrentFont['haskernGPOS']) {
$this->OTLtags['Plus'] .= ' kern';
} else {
$textvar = ($textvar | FC_KERNING);
}
}
/* -- OTL -- */
// Use OTL OpenType Table Layout - GSUB & GPOS
if (isset($this->CurrentFont['useOTL']) && $this-
>CurrentFont['useOTL']) {
$txt = $this->otl->applyOTL($txt, $this->CurrentFont['useOTL']);
$OTLdata = $this->otl->OTLdata;
}
/* -- END OTL -- */
$this->OTLtags = $save_OTLtags;
$textvar = 0;
$save_OTLtags = $this->OTLtags;
$this->OTLtags = array();
if ($this->useKerning) {
if ($this->CurrentFont['haskernGPOS']) {
$this->OTLtags['Plus'] .= ' kern';
} else {
$textvar = ($textvar | FC_KERNING);
}
}
/* -- OTL -- */
// Use OTL OpenType Table Layout - GSUB & GPOS
if (isset($this->CurrentFont['useOTL']) && $this-
>CurrentFont['useOTL']) {
$txt = $this->otl->applyOTL($txt, $this->CurrentFont['useOTL']);
$OTLdata = $this->otl->OTLdata;
}
/* -- END OTL -- */
$this->OTLtags = $save_OTLtags;
/* -- END DIRECTW -- */
function ResetSpacing()
{
if ($this->ws != 0) {
$this->_out('BT 0 Tw ET');
}
$this->ws = 0;
if ($this->charspacing != 0) {
$this->_out('BT 0 Tc ET');
}
$this->charspacing = 0;
}
// WORD SPACING
function GetJspacing($nc, $ns, $w, $inclCursive, &$cOTLdata)
{
$kashida_present = false;
$kashida_space = 0;
if ($w > 0 && $inclCursive && isset($this->CurrentFont['useKashida'])
&& $this->CurrentFont['useKashida'] && !empty($cOTLdata)) {
for ($c = 0; $c < count($cOTLdata); $c++) {
for ($i = 0; $i < strlen($cOTLdata[$c]['group']); $i++) {
if (isset($cOTLdata[$c]['GPOSinfo'][$i]['kashida'])
&& $cOTLdata[$c]['GPOSinfo'][$i]['kashida'] > 0) {
$kashida_present = true;
break 2;
}
}
}
}
if ($kashida_present) {
$k_ctr = 0; // Number of kashida points
$k_total = 0; // Total of kashida values (priority)
// Reset word
$max_kashida_in_word = 0;
$last_kashida_in_word = -1;
if ($cOTLdata[$c]['group']{$i} == 'S') {
// Save from last word
if ($max_kashida_in_word) {
$k_ctr++;
$k_total = $max_kashida_in_word;
}
// Reset word
$max_kashida_in_word = 0;
$last_kashida_in_word = -1;
}
if (isset($cOTLdata[$c]['GPOSinfo'][$i]['kashida'])
&& $cOTLdata[$c]['GPOSinfo'][$i]['kashida'] > 0) {
if ($max_kashida_in_word) {
if ($cOTLdata[$c]['GPOSinfo'][$i]
['kashida'] > $max_kashida_in_word) {
$max_kashida_in_word =
$cOTLdata[$c]['GPOSinfo'][$i]['kashida'];
$cOTLdata[$c]['GPOSinfo']
[$last_kashida_in_word]['kashida'] = 0;
$last_kashida_in_word = $i;
} else {
$cOTLdata[$c]['GPOSinfo'][$i]
['kashida'] = 0;
}
} else {
$max_kashida_in_word = $cOTLdata[$c]
['GPOSinfo'][$i]['kashida'];
$last_kashida_in_word = $i;
}
}
}
}
// Save from last word
if ($max_kashida_in_word) {
$k_ctr++;
$k_total = $max_kashida_in_word;
}
$kashida_space = $w * $kashida_space_ratio;
$ws = 0;
$charspacing = 0;
$ww = $this->jSWord;
$ncx = $nc - 1;
if ($nc == 0) {
return array(0, 0, 0);
}
// Only word spacing allowed / possible
elseif ($this->fixedlSpacing !== false || $inclCursive) {
if ($ns) {
$ws = $w / $ns;
}
} elseif ($nc == 1) {
$charspacing = $w;
} elseif (!$ns) {
$charspacing = $w / ($ncx );
if (($this->jSmaxChar > 0) && ($charspacing > $this->jSmaxChar))
{
$charspacing = $this->jSmaxChar;
}
} elseif ($ns == ($ncx )) {
$charspacing = $w / $ns;
} else {
if ($this->usingCoreFont) {
$cs = ($w * (1 - $this->jSWord)) / ($ncx );
if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
$cs = $this->jSmaxChar;
$ww = 1 - (($cs * ($ncx )) / $w);
}
$charspacing = $cs;
$ws = ($w * ($ww) ) / $ns;
} else {
$cs = ($w * (1 - $this->jSWord)) / ($ncx - $ns);
if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
$cs = $this->jSmaxChar;
$ww = 1 - (($cs * ($ncx - $ns)) / $w);
}
$charspacing = $cs;
$ws = (($w * ($ww) ) / $ns) - $charspacing;
}
}
return array($charspacing, $ws, $kashida_space);
}
$oldcolumn = $this->CurrCol;
// Automatic page break
// Allows PAGE-BREAK-AFTER = avoid to work
if (isset($this->blk[$this->blklvl])) {
$bottom = $this->blk[$this->blklvl]['padding_bottom'] + $this-
>blk[$this->blklvl]['margin_bottom'];
} else {
$bottom = 0;
}
if (!$this->tableLevel && (($this->y + $this->divheight > $this-
>PageBreakTrigger) || ($this->y + $h > $this->PageBreakTrigger) ||
($this->y + ($h * 2) + $bottom > $this->PageBreakTrigger &&
$this->blk[$this->blklvl]['page_break_after_avoid'])) and ! $this->InFooter and
$this->AcceptPageBreak()) { // mPDF 5.7.2
$x = $this->x; //Current X position
// WORD SPACING
$ws = $this->ws; //Word Spacing
$charspacing = $this->charspacing; //Character Spacing
$this->ResetSpacing();
$this->AddPage($this->CurOrientation);
// Added to correct for OddEven Margins
$x += $this->MarginCorrection;
if ($currentx) {
$currentx += $this->MarginCorrection;
}
$this->x = $x;
// WORD SPACING
$this->SetSpacing($charspacing, $ws);
}
if ($w == 0)
$w = $this->w - $this->rMargin - $this->x;
$s = '';
if ($fill == 1 && $this->FillColor) {
if ((isset($this->pageoutput[$this->page]['FillColor']) && $this-
>pageoutput[$this->page]['FillColor'] != $this->FillColor) || !isset($this-
>pageoutput[$this->page]['FillColor'])) {
$s .= $this->FillColor . ' ';
}
$this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
}
if ($txt != '') {
if ($exactWidth)
$stringWidth = $w;
else
$stringWidth = $this->GetStringWidth($txt, true, $OTLdata,
$textvar) + ( $this->charspacing * mb_strlen($txt, $this->mb_enc) / _MPDFK ) +
( $this->ws * mb_substr_count($txt, ' ', $this->mb_enc) / _MPDFK );
if ($this->ColorFlag)
$s .='q ' . $this->TextColor . ' ';
// OUTLINE
if (isset($this->textparam['outline-s']) && $this-
>textparam['outline-s'] && !($textvar & FC_SMALLCAPS)) { // mPDF 5.7.1
$s .=' ' . sprintf('%.3F w', $this->LineWidth * _MPDFK) . '
';
$s .=" $this->DrawColor ";
$s .=" 2 Tr ";
} elseif ($this->falseBoldWeight && strpos($this->ReqFontStyle,
"B") !== false && strpos($this->FontStyle, "B") === false && !($textvar &
FC_SMALLCAPS)) { // can't use together with OUTLINE or Small Caps // mPDF
5.7.1 ??? why not with SmallCaps ???
$s .= ' 2 Tr 1 J 1 j ';
$s .= ' ' . sprintf('%.3F w', ($this->FontSize / 130) *
_MPDFK * $this->falseBoldWeight) . ' ';
$tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0
0 0 RG
if ($this->FillColor != $tc) {
$s .= ' ' . $tc . ' ';
} // stroke (outline) = same colour as text(fill)
} else {
$s .=" 0 Tr ";
}
// IF NOT corefonts AND IS wordspacing AND NOT SIP AND NOT SmCaps
AND NOT Kerning AND NOT OTL
// Output text word by word with an adjustment to the
intercharacter spacing for SPACEs to form word spacing
// IF multibyte - Tw has no effect - need to do word spacing
using an adjustment before each space
elseif (!$this->usingCoreFont && $this->ws && !((isset($this-
>CurrentFont['sip']) && $this->CurrentFont['sip']) || (isset($this-
>CurrentFont['smp']) && $this->CurrentFont['smp'])) && !($textvar & FC_SMALLCAPS)
&& !($textvar & FC_KERNING) && !(isset($this->CurrentFont['useOTL']) && ($this-
>CurrentFont['useOTL'] & 0xFF) && (!empty($OTLdata['GPOSinfo']) ||
(strpos($OTLdata['group'], 'M') !== false && $this->charspacing)) )) {
$space = " ";
$space = $this->UTF8ToUTF16BE($space, false);
$space = $this->_escape($space);
$sub .=sprintf('BT ' . $aix . ' %.3F Tc [', $px, $py,
$this->charspacing);
$t = explode(' ', $txt2);
$numt = count($t);
for ($i = 0; $i < $numt; $i++) {
$tx = $t[$i];
$tx = $this->UTF8ToUTF16BE($tx, false);
$tx = $this->_escape($tx);
$sub .=sprintf('(%s) ', $tx);
if (($i + 1) < $numt) {
$adj = -($this->ws) * 1000 / $this->FontSizePt;
$sub .=sprintf('%d(%s) ', $adj, $space);
}
}
$sub .='] TJ ';
$sub .=' ET';
}
if ($this->shrin_k > 1) {
$shrin_k = $this->shrin_k;
} else {
$shrin_k = 1;
}
// UNDERLINE
if ($textvar & FD_UNDERLINE) { // mPDF 5.7.1 // mPDF 6
// mPDF 5.7.3 inline text-decoration parameters
$c = $this->textparam['u-decoration']['color'];
if ($this->FillColor != $c) {
$sub .= ' ' . $c . ' ';
}
// mPDF 5.7.3 inline text-decoration parameters
$decorationfontkey = $this->textparam['u-decoration']
['fontkey'];
$decorationfontsize = $this->textparam['u-decoration']
['fontsize'] / $shrin_k;
if (isset($this->fonts[$decorationfontkey]['ut']) && $this-
>fonts[$decorationfontkey]['ut']) {
$ut = $this->fonts[$decorationfontkey]['ut'] / 1000 *
$decorationfontsize;
} else {
$ut = 60 / 1000 * $decorationfontsize;
}
if (isset($this->fonts[$decorationfontkey]['up']) && $this-
>fonts[$decorationfontkey]['up']) {
$up = $this->fonts[$decorationfontkey]['up'];
} else {
$up = -100;
}
$adjusty = (-$up / 1000 * $decorationfontsize) + $ut / 2;
$ubaseline = $glyphYorigin - $this->textparam['u-
decoration']['baseline'] / $shrin_k;
$olw = $this->LineWidth;
$sub .=' ' . (sprintf(' %.3F w 0 j 0 J ', $ut * _MPDFK));
$sub .=' ' . $this->_dounderline($this->x + $dx, $this->y +
$ubaseline + $adjusty, $txt, $OTLdata, $textvar);
$sub .=' ' . (sprintf(' %.3F w 2 j 2 J ', $olw * _MPDFK));
if ($this->FillColor != $c) {
$sub .= ' ' . $this->FillColor . ' ';
}
}
// STRIKETHROUGH
if ($textvar & FD_LINETHROUGH) { // mPDF 5.7.1 // mPDF 6
// mPDF 5.7.3 inline text-decoration parameters
$c = $this->textparam['s-decoration']['color'];
if ($this->FillColor != $c) {
$sub .= ' ' . $c . ' ';
}
// mPDF 5.7.3 inline text-decoration parameters
$decorationfontkey = $this->textparam['s-decoration']
['fontkey'];
$decorationfontsize = $this->textparam['s-decoration']
['fontsize'] / $shrin_k;
// Use yStrikeoutSize from OS/2 if available
if (isset($this->fonts[$decorationfontkey]['strs']) &&
$this->fonts[$decorationfontkey]['strs']) {
$ut = $this->fonts[$decorationfontkey]['strs'] / 1000
* $decorationfontsize;
}
// else use underlineThickness from post if available
elseif (isset($this->fonts[$decorationfontkey]['ut']) &&
$this->fonts[$decorationfontkey]['ut']) {
$ut = $this->fonts[$decorationfontkey]['ut'] / 1000 *
$decorationfontsize;
} else {
$ut = 50 / 1000 * $decorationfontsize;
}
// Use yStrikeoutPosition from OS/2 if available
if (isset($this->fonts[$decorationfontkey]['strp']) &&
$this->fonts[$decorationfontkey]['strp']) {
$up = $this->fonts[$decorationfontkey]['strp'];
$adjusty = (-$up / 1000 * $decorationfontsize);
}
// else use a fraction ($this->baselineS) of CapHeight
else {
if (isset($this->fonts[$decorationfontkey]['desc']
['CapHeight']) && $this->fonts[$decorationfontkey]['desc']['CapHeight']) {
$ch = $this->fonts[$decorationfontkey]['desc']
['CapHeight'];
} else {
$ch = 700;
}
$adjusty = (-$ch / 1000 * $decorationfontsize) *
$this->baselineS;
}
// TEXT SHADOW
if ($this->textshadow) { // First to process is last in CSS
comma separated shadows
foreach ($this->textshadow AS $ts) {
$s .= ' q ';
$s .= $this->SetTColor($ts['col'], true) . "\n";
if ($ts['col']{0} == 5 && ord($ts['col']{4}) < 100) {
// RGBa
$s .= $this->SetAlpha(ord($ts['col']{4}) / 100,
'Normal', true, 'F') . "\n";
} elseif ($ts['col']{0} == 6 && ord($ts['col']{5}) <
100) { // CMYKa
$s .= $this->SetAlpha(ord($ts['col']{5}) / 100,
'Normal', true, 'F') . "\n";
} elseif ($ts['col']{0} == 1 && $ts['col']{2} == 1 &&
ord($ts['col']{3}) < 100) { // Gray
$s .= $this->SetAlpha(ord($ts['col']{3}) / 100,
'Normal', true, 'F') . "\n";
}
$s .= sprintf(' 1 0 0 1 %.4F %.4F cm', $ts['x'] *
_MPDFK, -$ts['y'] * _MPDFK) . "\n";
$s .= $sub;
$s .= ' Q ';
}
}
$s .= $sub;
// COLOR
if ($this->ColorFlag)
$s .=' Q';
// LINK
if ($link != '') {
$this->Link($this->x, $boxtop, $w, $boxheight, $link);
}
}
if ($s)
$this->_out($s);
// WORD SPACING
if ($this->ws && !$this->usingCoreFont) {
$this->_out(sprintf('BT %.3F Tc ET', $this->charspacing));
}
$this->lasth = $h;
if (strpos($txt, "\n") !== false)
$ln = 1; // cell recognizes \n from <BR> tag
if ($ln > 0) {
//Go to next line
$this->y += $h;
if ($ln == 1) {
//Move to next line
if ($currentx != 0) {
$this->x = $currentx;
} else {
$this->x = $this->lMargin;
}
}
} else
$this->x+=$w;
}
if ($sipset) {
$fontid = $last_fontid = $original_fontid = $this-
>CurrentFont['subsetfontids'][0];
} else {
$fontid = $last_fontid = $original_fontid = $this-
>CurrentFont['i'];
}
$SmallCapsON = false; // state: uppercase/not
$lastSmallCapsON = false; // state: uppercase/not
$last_fontsize = $fontsize = $this->FontSizePt;
$last_fontstretch = $fontstretch = 100;
$groupBreak = false;
$unicode = $this->UTF8StringToArray($txt);
$XshiftBefore = 0;
$XshiftAfter = 0;
$lastYPlacement = 0;
if ($sipset) {
// mPDF 6 DELETED ********
// $txt= preg_replace('/'.preg_quote($this-
>aliasNbPg,'/').'/', chr(7), $txt); // ? Need to adjust OTL info
// $txt= preg_replace('/'.preg_quote($this-
>aliasNbPgGp,'/').'/', chr(8), $txt); // ? Need to adjust OTL info
$tj = '<';
} else {
$tj = '(';
}
if (!isset($GPOSinfo[$i]['wDir']) || $GPOSinfo[$i]
['wDir'] != 'RTL') {
if (isset($GPOSinfo[$i]['BaseWidth'])) {
$GPOSinfo[$i]['XPlacement'] -=
$GPOSinfo[$i]['BaseWidth'];
}
}
// ...applyGPOSpdf...
// XAdvance from GPOS - Convert to PDF Text space
(thousandths of a unit );
if (((isset($GPOSinfo[$i]['wDir']) && $GPOSinfo[$i]['wDir']
!= 'RTL') || !isset($GPOSinfo[$i]['wDir'])) && isset($GPOSinfo[$i]['XAdvanceL']) &&
$GPOSinfo[$i]['XAdvanceL']) {
$XshiftAfter += $GPOSinfo[$i]['XAdvanceL'] * 1000 /
$this->CurrentFont['unitsPerEm'];
} elseif (isset($GPOSinfo[$i]['wDir']) && $GPOSinfo[$i]
['wDir'] == 'RTL' && isset($GPOSinfo[$i]['XAdvanceR']) && $GPOSinfo[$i]
['XAdvanceR']) {
$XshiftAfter += $GPOSinfo[$i]['XAdvanceR'] * 1000 /
$this->CurrentFont['unitsPerEm'];
}
}
// Character & Word spacing - if NOT OTL
else {
$XshiftAfter += $charspacing;
if ($c == 32) {
$XshiftAfter += $wordspacing;
}
}
if ($YPlacement != $lastYPlacement) {
$groupBreak = true;
}
// Small-Caps
if ($smcaps) {
if (isset($this->upperCase[$c])) {
$c = $this->upperCase[$c];
//$this->CurrentFont['subset'][$this->upperCase[$c]]
= $this->upperCase[$c]; // add the CAP to subset
$SmallCapsON = true;
// For $sipset
if (!$lastSmallCapsON) { // Turn ON SmallCaps
$groupBreak = true;
$fontstretch = $this->smCapsStretch;
$fontsize = $this->FontSizePt * $this-
>smCapsScale;
}
} else {
$SmallCapsON = false;
if ($lastSmallCapsON) { // Turn OFF SmallCaps
$groupBreak = true;
$fontstretch = 100;
$fontsize = $this->FontSizePt;
}
}
}
// Kashida
if ($kashida) {
$c = 0x0640; // add the Tatweel U+0640
if (isset($this->CurrentFont['subset'])) {
$this->CurrentFont['subset'][$c] = $c;
}
$kashida *= 1000 / $this->FontSizePt;
$tatw = $this->_getCharWidth($this->CurrentFont['cw'],
0x0640);
if ($sipset) {
$tj .= '>] TJ ';
} else {
$tj .= ')] TJ ';
}
if ($fontid != $last_fontid || $fontsize != $last_fontsize)
{
$tj .= sprintf(' /F%d %.3F Tf ', $fontid, $fontsize);
}
if ($fontstretch != $last_fontstretch) {
$tj .= sprintf('%d Tz ', $fontstretch);
}
$tj .= sprintf('%.3F Ts ', $YPlacement);
if ($sipset) {
$tj .= '[<';
} else {
$tj .= '[(';
}
$lastYPlacement = $YPlacement;
}
// Finish up
if ($sipset) {
$tj .= '>';
if ($XshiftAfter) {
$tj .= sprintf('%d', (-$XshiftAfter));
}
if ($last_fontid != $original_fontid) {
$tj .= '] TJ ';
$tj .= sprintf(' /F%d %.3F Tf ', $original_fontid,
$fontsize);
$tj .= '[';
}
$tj = preg_replace('/([^\\\])<>/', '\\1 ', $tj);
} else {
$tj .= ')';
if ($XshiftAfter) {
$tj .= sprintf('%d', (-$XshiftAfter));
}
if ($last_fontid != $original_fontid) {
$tj .= '] TJ ';
$tj .= sprintf(' /F%d %.3F Tf ', $original_fontid,
$fontsize);
$tj .= '[';
}
$tj = preg_replace('/([^\\\])\(\)/', '\\1 ', $tj);
}
return $s;
}
$tj = '(';
$unicode = $this->UTF8StringToArray($tx);
for ($ti = 0; $ti < count($unicode); $ti++) {
if ($ti > 0 && isset($this->CurrentFont['kerninfo']
[$unicode[($ti - 1)]][$unicode[$ti]])) {
$kern = -$this->CurrentFont['kerninfo']
[$unicode[($ti - 1)]][$unicode[$ti]];
$tj .= sprintf(')%d(', $kern);
}
$tc = code2utf($unicode[$ti]);
$tc = $this->UTF8ToUTF16BE($tc, false);
$tj .= $this->_escape($tc);
}
$tj .= ')';
$s.=sprintf(' %.3F Tc [%s] TJ', $this->charspacing, $tj);
return $s;
}
$rows = 0;
$start_y = $this->y;
if (!$this->usingCoreFont) {
$inclCursive = false;
if (preg_match("/([" . $this->pregCURSchars . "])/u", $s)) {
$inclCursive = true;
}
while ($i < $nb) {
//Get next character
$c = mb_substr($s, $i, 1, $this->mb_enc);
if ($c == "\n") {
//Explicit line break
// WORD SPACING
$this->ResetSpacing();
$tmp = rtrim(mb_substr($s, $j, $i - $j, $this-
>mb_enc));
$tmpOTLdata = false;
/* -- OTL -- */
if (isset($OTLdata)) {
$tmpOTLdata = $this->otl-
>sliceOTLdata($OTLdata, $j, $i - $j);
$this->otl->trimOTLdata($tmpOTLdata, false,
true);
$this->magic_reverse_dir($tmp, $directionality,
$tmpOTLdata);
}
/* -- END OTL -- */
$this->Cell($w, $h, $tmp, $b, 2, $align, $fill,
$link, 0, 0, 0, 'M', 0, false, $tmpOTLdata);
if ($maxrows != false && isset($this->mpdfform) &&
($this->y - $start_y) / $h > $maxrows) {
return false;
}
$i++;
$sep = -1;
$j = $i;
$l = 0;
$ns = 0;
$nl++;
if ($border and $nl == 2)
$b = $b2;
continue;
}
if ($c == " ") {
$sep = $i;
$ls = $l;
$ns++;
}
$l += $this->GetCharWidthNonCore($c);
else {
$l += $this->GetCharWidthCore($c);
if ($l > $wmax) {
//Automatic line break
if ($sep == -1) {
if ($i == $j)
$i++;
// WORD SPACING
$this->ResetSpacing();
$this->Cell($w, $h, substr($s, $j, $i - $j),
$b, 2, $align, $fill, $link);
}
else {
if ($align == 'J') {
$tmp = rtrim(substr($s, $j, $sep - $j));
/////////////////////////////////////////
/
// JUSTIFY J using Unicode fonts (Word
spacing doesn't work)
// WORD SPACING NON_UNICODE/CJK
// Change NON_BREAKING SPACE to spaces so
they are 'spaced' properly
$tmp = str_replace(chr(160), chr(32),
$tmp);
$len_ligne = $this->GetStringWidth($tmp);
$nb_carac = strlen($tmp);
$nb_spaces = substr_count($tmp, ' ');
$tmpOTLdata = array();
list($charspacing, $ws, $kashida) =
$this->GetJspacing($nb_carac, $nb_spaces, ((($wmax) - $len_ligne) * _MPDFK), false,
$tmpOTLdata);
$this->SetSpacing($charspacing, $ws);
/////////////////////////////////////////
/
}
$this->Cell($w, $h, substr($s, $j, $sep - $j),
$b, 2, $align, $fill, $link);
$i = $sep + 1;
}
if ($maxrows != false && isset($this->mpdfform) &&
($this->y - $start_y) / $h > $maxrows) {
return false;
}
$sep = -1;
$j = $i;
$l = 0;
$ns = 0;
$nl++;
if ($border and $nl == 2)
$b = $b2;
} else
$i++;
}
//Last chunk
// WORD SPACING
$this->ResetSpacing();
}
//Last chunk
if ($border and is_int(strpos($border, 'B')))
$b.='B';
if (!$this->usingCoreFont) {
$tmp = rtrim(mb_substr($s, $j, $i - $j, $this->mb_enc));
$tmpOTLdata = false;
/* -- OTL -- */
if (isset($OTLdata)) {
$tmpOTLdata = $this->otl->sliceOTLdata($OTLdata, $j, $i -
$j);
$this->otl->trimOTLdata($tmpOTLdata, false, true);
$this->magic_reverse_dir($tmp, $directionality,
$tmpOTLdata);
}
/* -- END OTL -- */
$this->Cell($w, $h, $tmp, $b, 2, $align, $fill, $link, 0, 0, 0,
'M', 0, false, $tmpOTLdata);
} else {
$this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align,
$fill, $link);
}
$this->x = $this->lMargin;
}
/* -- DIRECTW -- */
function Write($h, $txt, $currentx = 0, $link = '', $directionality = 'ltr',
$align = '')
{
if (!class_exists('directw', false)) {
include(_MPDF_PATH . 'classes/directw.php');
}
if (empty($this->directw)) {
$this->directw = new directw($this);
}
$this->directw->Write($h, $txt, $currentx, $link, $directionality,
$align);
}
/* -- END DIRECTW -- */
/* -- HTML-CSS -- */
function saveInlineProperties()
{
$saved = array();
$saved['family'] = $this->FontFamily;
$saved['style'] = $this->FontStyle;
$saved['sizePt'] = $this->FontSizePt;
$saved['size'] = $this->FontSize;
$saved['HREF'] = $this->HREF;
$saved['textvar'] = $this->textvar; // mPDF 5.7.1
$saved['OTLtags'] = $this->OTLtags; // mPDF 5.7.1
$saved['textshadow'] = $this->textshadow;
$saved['linewidth'] = $this->LineWidth;
$saved['drawcolor'] = $this->DrawColor;
$saved['textparam'] = $this->textparam;
$saved['lSpacingCSS'] = $this->lSpacingCSS;
$saved['wSpacingCSS'] = $this->wSpacingCSS;
$saved['I'] = $this->I;
$saved['B'] = $this->B;
$saved['colorarray'] = $this->colorarray;
$saved['bgcolorarray'] = $this->spanbgcolorarray;
$saved['border'] = $this->spanborddet;
$saved['color'] = $this->TextColor;
$saved['bgcolor'] = $this->FillColor;
$saved['lang'] = $this->currentLang;
$saved['fontLanguageOverride'] = $this->fontLanguageOverride; // mPDF
5.7.1
$saved['display_off'] = $this->inlineDisplayOff;
return $saved;
}
function restoreInlineProperties(&$saved)
{
$FontFamily = $saved['family'];
$this->FontStyle = $saved['style'];
$this->FontSizePt = $saved['sizePt'];
$this->FontSize = $saved['size'];
$this->currentLang = $saved['lang'];
$this->fontLanguageOverride = $saved['fontLanguageOverride']; // mPDF
5.7.1
$this->HREF = $saved['HREF'];
$this->textvar = $saved['textvar']; // mPDF 5.7.1
$this->OTLtags = $saved['OTLtags']; // mPDF 5.7.1
$this->textshadow = $saved['textshadow'];
$this->LineWidth = $saved['linewidth'];
$this->DrawColor = $saved['drawcolor'];
$this->textparam = $saved['textparam'];
$this->inlineDisplayOff = $saved['display_off'];
$this->lSpacingCSS = $saved['lSpacingCSS'];
if (($this->lSpacingCSS || $this->lSpacingCSS === '0') &&
strtoupper($this->lSpacingCSS) != 'NORMAL') {
$this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,
$this->FontSize);
} else {
$this->fixedlSpacing = false;
}
$this->wSpacingCSS = $saved['wSpacingCSS'];
if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') {
$this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,
$this->FontSize);
} else {
$this->minwSpacing = 0;
}
$this->currentfontstyle = $saved['style'];
$this->currentfontsize = $saved['sizePt'];
$this->SetStylesArray(array('B' => $saved['B'], 'I' =>
$saved['I'])); // mPDF 5.7.1
$this->TextColor = $saved['color'];
$this->FillColor = $saved['bgcolor'];
$this->colorarray = $saved['colorarray'];
$cor = $saved['colorarray'];
if ($cor)
$this->SetTColor($cor);
$this->spanbgcolorarray = $saved['bgcolorarray'];
$cor = $saved['bgcolorarray'];
if ($cor)
$this->SetFColor($cor);
$this->spanborddet = $saved['border'];
}
// Used when ColActive for tables - updated to return first block with
background fill OR borders
function GetFirstBlockFill()
{
// Returns the first blocklevel that uses a bgcolor fill
$startfill = 0;
for ($i = 1; $i <= $this->blklvl; $i++) {
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']) {
$startfill = $i;
break;
}
}
return $startfill;
}
//-------------------------FLOWING
BLOCK------------------------------------//
//The following functions were originally written by Damon
Kohler //
//--------------------------------------------------------------------------/
/
function saveFont()
{
$saved = array();
$saved['family'] = $this->FontFamily;
$saved['style'] = $this->FontStyle;
$saved['sizePt'] = $this->FontSizePt;
$saved['size'] = $this->FontSize;
$saved['curr'] = &$this->CurrentFont;
$saved['lang'] = $this->currentLang; // mPDF 6
$saved['color'] = $this->TextColor;
$saved['spanbgcolor'] = $this->spanbgcolor;
$saved['spanbgcolorarray'] = $this->spanbgcolorarray;
$saved['bord'] = $this->spanborder;
$saved['border'] = $this->spanborddet;
$saved['HREF'] = $this->HREF;
$saved['textvar'] = $this->textvar; // mPDF 5.7.1
$saved['textshadow'] = $this->textshadow;
$saved['linewidth'] = $this->LineWidth;
$saved['drawcolor'] = $this->DrawColor;
$saved['textparam'] = $this->textparam;
$saved['ReqFontStyle'] = $this->ReqFontStyle;
$saved['fixedlSpacing'] = $this->fixedlSpacing;
$saved['minwSpacing'] = $this->minwSpacing;
return $saved;
}
$this->FontFamily = $saved['family'];
$this->FontStyle = $saved['style'];
$this->FontSizePt = $saved['sizePt'];
$this->FontSize = $saved['size'];
$this->CurrentFont = &$saved['curr'];
$this->currentLang = $saved['lang']; // mPDF 6
$this->TextColor = $saved['color'];
$this->spanbgcolor = $saved['spanbgcolor'];
$this->spanbgcolorarray = $saved['spanbgcolorarray'];
$this->spanborder = $saved['bord'];
$this->spanborddet = $saved['border'];
$this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore
ColorFlag as well
$this->HREF = $saved['HREF'];
$this->fixedlSpacing = $saved['fixedlSpacing'];
$this->minwSpacing = $saved['minwSpacing'];
$this->textvar = $saved['textvar']; // mPDF 5.7.1
$this->textshadow = $saved['textshadow'];
$this->LineWidth = $saved['linewidth'];
$this->DrawColor = $saved['drawcolor'];
$this->textparam = $saved['textparam'];
if ($write) {
$this->SetFont($saved['family'], $saved['style'],
$saved['sizePt'], true, true); // force output
$fontout = (sprintf('BT /F%d %.3F Tf ET', $this-
>CurrentFont['i'], $this->FontSizePt));
if ($this->page > 0 && ((isset($this->pageoutput[$this->page]
['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this-
>pageoutput[$this->page]['Font']))) {
$this->_out($fontout);
}
$this->pageoutput[$this->page]['Font'] = $fontout;
} else
$this->SetFont($saved['family'], $saved['style'],
$saved['sizePt'], false);
$this->ReqFontStyle = $saved['ReqFontStyle'];
}
$this->flowingBlockAttr['newblock'] = $newblock;
$this->flowingBlockAttr['valign'] = 'M';
$this->flowingBlockAttr['blockdir'] = $blockdir;
$this->flowingBlockAttr['cOTLdata'] = array(); // mPDF 5.7.1
$this->flowingBlockAttr['lastBidiText'] = ''; // mPDF 5.7.1
if (!empty($this->otl)) {
$this->otl->lastBidiStrongType = '';
} // *OTL*
}
$hanger = '';
// Always right trim!
// Right trim last content and adjust width if needed to justify
(later)
if (isset($content[count($content) - 1]) && preg_match('/[ ]+$/',
$content[count($content) - 1], $m)) {
$strip = strlen($m[0]);
$content[count($content) - 1] = substr($content[count($content) -
1], 0, (strlen($content[count($content) - 1]) - $strip));
/* -- OTL -- */
if (isset($this->CurrentFont['useOTL']) && $this-
>CurrentFont['useOTL']) {
$this->otl->trimOTLdata($cOTLdata[count($cOTLdata) - 1],
false, true);
}
/* -- END OTL -- */
}
// COLS
$oldcolumn = $this->CurrCol;
/* -- TABLES -- */
if ($is_table) {
$ipaddingL = 0;
$ipaddingR = 0;
$paddingL = 0;
$paddingR = 0;
} else {
/* -- END TABLES -- */
$ipaddingL = $this->blk[$this->blklvl]['padding_left'];
$ipaddingR = $this->blk[$this->blklvl]['padding_right'];
$paddingL = ($ipaddingL * _MPDFK);
$paddingR = ($ipaddingR * _MPDFK);
$this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
$this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
$lineBox = array();
if (isset($font[count($font) - 1])) {
$lastfontreqstyle = (isset($font[count($font) - 1]
['ReqFontStyle']) ? $font[count($font) - 1]['ReqFontStyle'] : '');
$lastfontstyle = (isset($font[count($font) - 1]['style']) ?
$font[count($font) - 1]['style'] : '');
} else {
$lastfontreqstyle = null;
$lastfontstyle = null;
}
if ($blockdir == 'ltr' && strpos($lastfontreqstyle, "I") !== false &&
strpos($lastfontstyle, "I") === false) { // Artificial italic
$lastitalic = $this->FontSize * 0.15 * _MPDFK;
} else {
$lastitalic = 0;
}
// PAGEBREAK
if (!$is_table && ($this->y + $check_h) > ($this->PageBreakTrigger +
$buff) and ! $this->InFooter and $this->AcceptPageBreak()) {
$bak_x = $this->x; //Current X position
// WORD SPACING
$ws = $this->ws; //Word Spacing
$charspacing = $this->charspacing; //Character Spacing
$this->ResetSpacing();
$this->AddPage($this->CurOrientation);
$this->x = $bak_x;
// Added to correct for OddEven Margins
$currentx += $this->MarginCorrection;
$this->x += $this->MarginCorrection;
// WORD SPACING
$this->SetSpacing($charspacing, $ws);
}
/* -- COLUMNS -- */
// COLS
// COLUMN CHANGE
if ($this->CurrCol != $oldcolumn) {
$currentx += $this->ChangeColumn * ($this->ColWidth + $this-
>ColGap);
$this->x += $this->ChangeColumn * ($this->ColWidth + $this-
>ColGap);
$oldcolumn = $this->CurrCol;
}
// TOP MARGIN
if ($newblock && ($blockstate == 1 || $blockstate == 3) && ($this-
>blk[$this->blklvl]['margin_top']) && $lineCount == 0 && !$is_table) {
$this->DivLn($this->blk[$this->blklvl]['margin_top'], $this-
>blklvl - 1, true, $this->blk[$this->blklvl]['margin_collapse']);
if ($this->ColActive) {
$this->breakpoints[$this->CurrCol][] = $this->y;
} // *COLUMNS*
}
// Paragraph INDENT
$WidthCorrection = 0;
if (($newblock) && ($blockstate == 1 || $blockstate == 3) &&
isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!
$is_table) && ($align != 'C')) {
$ti = $this->ConvertSize($this->blk[$this->blklvl]
['text_indent'], $this->blk[$this->blklvl]['inner_width'], $this->blk[$this-
>blklvl]['InlineProperties']['size'], false); // mPDF 5.7.4
$WidthCorrection = ($ti * _MPDFK);
}
// DIRECTIONALITY RTL
$chunkorder = range(0, count($content) - 1); // mPDF 6
/* -- OTL -- */
// mPDF 6
if ($blockdir == 'rtl' || $this->biDirectional) {
$this->otl->_bidiReorder($chunkorder, $content, $cOTLdata,
$blockdir);
// From this point on, $content and $cOTLdata may contain
more elements (and re-ordered) compared to
// $this->objectbuffer and $font ($chunkorder contains the
mapping)
}
/* -- END OTL -- */
// Remove any XAdvance from OTL data at end of line
// And correct for XPlacement on last character
// BIDI is applied
foreach ($chunkorder AS $aord => $k) {
if (count($cOTLdata)) {
$this->restoreFont($font[$k], false);
// ...FinishFlowingBlock...
if ($aord == count($chunkorder) - 1 &&
isset($cOTLdata[$aord]['group'])) { // Last chunk on line
$nGPOS = strlen($cOTLdata[$aord]['group']) - 1;
// Last character
if (isset($cOTLdata[$aord]['GPOSinfo'][$nGPOS]
['XAdvanceL']) || isset($cOTLdata[$aord]['GPOSinfo'][$nGPOS]['XAdvanceR'])) {
if (isset($cOTLdata[$aord]['GPOSinfo']
[$nGPOS]['XAdvanceL'])) {
$w = $cOTLdata[$aord]['GPOSinfo']
[$nGPOS]['XAdvanceL'] * 1000 / $this->CurrentFont['unitsPerEm'];
} else {
$w = $cOTLdata[$aord]['GPOSinfo']
[$nGPOS]['XAdvanceR'] * 1000 / $this->CurrentFont['unitsPerEm'];
}
$w *= ($this->FontSize / 1000);
$contentWidth -= $w * _MPDFK;
$cOTLdata[$aord]['GPOSinfo'][$nGPOS]
['XAdvanceL'] = 0;
$cOTLdata[$aord]['GPOSinfo'][$nGPOS]
['XAdvanceR'] = 0;
}
$empty /= _MPDFK;
if (!$is_table) {
$this->maxPosR = max($this->maxPosR, ($this->w - $this-
>rMargin - $this->blk[$this->blklvl]['outer_right_margin'] - $empty));
$this->maxPosL = min($this->maxPosL, ($this->lMargin +
$this->blk[$this->blklvl]['outer_left_margin'] + $empty));
}
$arraysize = count($chunkorder);
if (!$is_table) {
$this->DivLn($stackHeight, $this->blklvl, false);
} // false -> don't advance y
// Paragraph INDENT
$WidthCorrection = 0;
if (($newblock) && ($blockstate == 1 || $blockstate == 3) &&
isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!
$is_table) && ($align != 'C')) {
$ti = $this->ConvertSize($this->blk[$this->blklvl]
['text_indent'], $this->blk[$this->blklvl]['inner_width'], $this->blk[$this-
>blklvl]['InlineProperties']['size'], false); // mPDF 5.7.4
if ($blockdir != 'rtl') {
$this->x += $ti;
} // mPDF 6
}
$this->SetSpacing(($this->fixedlSpacing * _MPDFK) +
$jcharspacing, ($this->fixedlSpacing + $this->minwSpacing) * _MPDFK + $jws);
$this->fixedlSpacing = false;
$this->minwSpacing = 0;
$save_vis = $this->visibility;
if (isset($this->textparam['visibility']) && $this-
>textparam['visibility'] && $this->textparam['visibility'] != $this->visibility) {
$this->SetVisibility($this->textparam['visibility']);
}
if (isset($this->objectbuffer[$k])) {
if ($this->objectbuffer[$k]['type'] == 'dottab') {
$this->objectbuffer[$k]['OUTER-WIDTH']
+=$empty;
$this->objectbuffer[$k]['OUTER-WIDTH'] +=$this-
>objectbuffer[$k]['outdent'];
}
// LIST MARKERS // mPDF 6 Lists
if ($this->objectbuffer[$k]['type'] == 'image' &&
isset($this->objectbuffer[$k]['listmarker']) && $this->objectbuffer[$k]
['listmarker'] && $this->objectbuffer[$k]['listmarkerposition'] == 'outside') {
// do nothing
} else {
$stringWidth = $this->objectbuffer[$k]['OUTER-
WIDTH'];
}
}
if ($stringWidth == 0) {
$stringWidth = 0.000001;
}
if ($aord == $arraysize - 1) { // mPDF 5.7
// mPDF 5.7.1
if ($this->checkCJK && $CJKoverflow && $align == 'J'
&& $this->allowCJKoverflow && $hanger && $this->CJKforceend) {
// force-end overhang
$this->Cell($stringWidth, $stackHeight, $chunk,
'', 0, '', $fill, $this->HREF, $currentx, 0, 0, 'M', $fill, true,
(isset($cOTLdata[$aord]) ? $cOTLdata[$aord] : false), $this->textvar,
(isset($lineBox[$k]) ? $lineBox[$k] : false)); // mPDF 5.7.1
$this->Cell($this->GetStringWidth($hanger),
$stackHeight, $hanger, '', 1, '', $fill, $this->HREF, $currentx, 0, 0, 'M', $fill,
true, (isset($cOTLdata[$aord]) ? $cOTLdata[$aord] : false), $this->textvar,
(isset($lineBox[$k]) ? $lineBox[$k] : false)); // mPDF 5.7.1
} else {
$this->Cell($stringWidth, $stackHeight, $chunk,
'', 1, '', $fill, $this->HREF, $currentx, 0, 0, 'M', $fill, true,
(isset($cOTLdata[$aord]) ? $cOTLdata[$aord] : false), $this->textvar,
(isset($lineBox[$k]) ? $lineBox[$k] : false)); // mPDF 5.7.1
}
} else
$this->Cell($stringWidth, $stackHeight, $chunk, '',
0, '', $fill, $this->HREF, 0, 0, 0, 'M', $fill, true, (isset($cOTLdata[$aord]) ?
$cOTLdata[$aord] : false), $this->textvar, (isset($lineBox[$k]) ? $lineBox[$k] :
false)); //first or middle part // mPDF 5.7.1
if (!empty($this->spanborddet)) {
if (strpos($contentB[$k], 'R') !== false && $aord !=
$arraysize - 1)
$this->x += $this->spanborddet['R']['w'];
}
// *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK
BGCOLOR ***************** //
if (isset($spanfill) && $spanfill) {
$fill = $save_fill;
$spanfill = 0;
if ($fill) {
$this->SetFColor($bcor);
}
}
if (isset($this->textparam['visibility']) && $this-
>textparam['visibility'] && $this->visibility != $save_vis) {
$this->SetVisibility($save_vis);
}
}
$this->printobjectbuffer($is_table, $blockdir);
$this->objectbuffer = array();
$this->ResetSpacing();
} // END IF CONTENT
/* -- CSS-IMAGE-FLOAT -- */
// Update values if set to skipline
if ($this->floatmargins) {
$this->_advanceFloatMargins();
}
if ($this->ColActive) {
$this->breakpoints[$this->CurrCol][] = $this->y;
} // *COLUMNS*
}
// BOTTOM MARGIN
if (($endofblock) && ($blockstate > 1) && ($this->blk[$this->blklvl]
['margin_bottom']) && (!$is_table)) {
if ($this->y + $this->blk[$this->blklvl]['margin_bottom'] <
$this->PageBreakTrigger and ! $this->InFooter) {
$this->DivLn($this->blk[$this->blklvl]['margin_bottom'],
$this->blklvl - 1, true, $this->blk[$this->blklvl]['margin_collapse']);
if ($this->ColActive) {
$this->breakpoints[$this->CurrCol][] = $this->y;
} // *COLUMNS*
}
}
// Reset lineheight
$stackHeight = $this->divheight;
}
// HR
if ($objattr['type'] == 'hr') {
$this->SetDColor($objattr['color']);
switch ($objattr['align']) {
case 'C':
$empty = $objattr['OUTER-WIDTH'] -
$objattr['INNER-WIDTH'];
$empty /= 2;
$x += $empty;
break;
case 'R':
$empty = $objattr['OUTER-WIDTH'] -
$objattr['INNER-WIDTH'];
$x += $empty;
break;
}
$oldlinewidth = $this->LineWidth;
$this->SetLineWidth($objattr['linewidth'] / $k);
$this->y += ($objattr['linewidth'] / 2) +
$objattr['margin_top'] / $k;
$this->Line($x, $this->y, $x + $objattr['INNER-WIDTH'],
$this->y);
$this->SetLineWidth($oldlinewidth);
$this->SetDColor($this->ConvertColor(0));
}
// IMAGE
if ($objattr['type'] == 'image') {
// mPDF 5.7.3 TRANSFORMS
if (isset($objattr['transform'])) {
$this->_out("\n" . '% BTR'); // Begin Transform
}
if (isset($objattr['z-index']) && $objattr['z-index'] > 0
&& $this->current_layer == 0) {
$this->BeginLayer($objattr['z-index']);
}
if (isset($objattr['visibility']) && $objattr['visibility']
!= 'visible' && $objattr['visibility']) {
$this->SetVisibility($objattr['visibility']);
}
if (isset($objattr['opacity'])) {
$this->SetAlpha($objattr['opacity']);
}
$obiw = $objattr['INNER-WIDTH'];
$obih = $objattr['INNER-HEIGHT'];
$sx = $objattr['INNER-WIDTH'] * _MPDFK /
$objattr['orig_w'];
$sy = abs($objattr['INNER-HEIGHT']) * _MPDFK /
abs($objattr['orig_h']);
$sx = ($objattr['INNER-WIDTH'] * _MPDFK /
$objattr['orig_w']);
$sy = ($objattr['INNER-HEIGHT'] * _MPDFK /
$objattr['orig_h']);
$rotate = 0;
if (isset($objattr['ROTATE'])) {
$rotate = $objattr['ROTATE'];
}
if ($rotate == 90) {
// Clockwise
$obiw = $objattr['INNER-HEIGHT'];
$obih = $objattr['INNER-WIDTH'];
$tr = $this->transformTranslate(0, -$objattr['INNER-
WIDTH'], true);
$tr .= ' ' . $this->transformRotate(90,
$objattr['INNER-X'], ($objattr['INNER-Y'] + $objattr['INNER-WIDTH']), true);
$sx = $obiw * _MPDFK / $objattr['orig_h'];
$sy = $obih * _MPDFK / $objattr['orig_w'];
} elseif ($rotate == -90 || $rotate == 270) {
// AntiClockwise
$obiw = $objattr['INNER-HEIGHT'];
$obih = $objattr['INNER-WIDTH'];
$tr = $this->transformTranslate($objattr['INNER-
WIDTH'], ($objattr['INNER-HEIGHT'] - $objattr['INNER-WIDTH']), true);
$tr .= ' ' . $this->transformRotate(-90,
$objattr['INNER-X'], ($objattr['INNER-Y'] + $objattr['INNER-WIDTH']), true);
$sx = $obiw * _MPDFK / $objattr['orig_h'];
$sy = $obih * _MPDFK / $objattr['orig_w'];
} elseif ($rotate == 180) {
// Mirror
$tr = $this->transformTranslate($objattr['INNER-
WIDTH'], -$objattr['INNER-HEIGHT'], true);
$tr .= ' ' . $this->transformRotate(180,
$objattr['INNER-X'], ($objattr['INNER-Y'] + $objattr['INNER-HEIGHT']), true);
} else {
$tr = '';
}
$tr = trim($tr);
if ($tr) {
$tr .= ' ';
}
$gradmask = '';
/* -- BACKGROUNDS -- */
if (isset($objattr['GRADIENT-MASK'])) {
$g = $this->grad-
>parseMozGradient($objattr['GRADIENT-MASK']);
if ($g) {
$dummy = $this->grad->Gradient($objattr['INNER-
X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'],
$g['coords'], $g['extend'], true, true);
$gradmask = '/TGS' . count($this->gradients) .
' gs ';
}
}
/* -- END BACKGROUNDS -- */
/* -- IMAGES-WMF -- */
if (isset($objattr['itype']) && $objattr['itype'] == 'wmf')
{
$outstring = sprintf('q ' . $tr . $tr2 . '%.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']); // mPDF 5.7.3 TRANSFORMS
} else
/* -- END IMAGES-WMF -- */
if (isset($objattr['itype']) && $objattr['itype'] == 'svg')
{
$outstring = sprintf('q ' . $tr . $tr2 . '%.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']); // mPDF 5.7.3 TRANSFORMS
} else {
$outstring = sprintf("q " . $tr . $tr2 . "%.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']); // mPDF 5.7.3 TRANSFORMS
}
$this->_out($outstring);
// LINK
if (isset($objattr['link']))
$this->Link($objattr['INNER-X'], $objattr['INNER-Y'],
$objattr['INNER-WIDTH'], $objattr['INNER-HEIGHT'], $objattr['link']);
if (isset($objattr['opacity'])) {
$this->SetAlpha(1);
}
/* -- BARCODES -- */
// BARCODE
if ($objattr['type'] == 'barcode') {
$bgcol = $this->ConvertColor(255);
if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
$bgcol = $objattr['bgcolor'];
}
$col = $this->ConvertColor(0);
if (isset($objattr['color']) && $objattr['color']) {
$col = $objattr['color'];
}
$this->SetFColor($bgcol);
$this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'],
$objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
$this->SetFColor($this->ConvertColor(255));
if (isset($objattr['BORDER-WIDTH'])) {
$this->PaintImgBorder($objattr, $is_table);
}
if ($objattr['btype'] == 'EAN13' || $objattr['btype'] ==
'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' ||
$objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
$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'], (isset($objattr['bsupp_code']) ? $objattr['bsupp_code'] : ''),
$k);
}
// QR-code
elseif ($objattr['btype'] == 'QR') {
if (!class_exists('QRcode', false)) {
include(_MPDF_PATH .
'qrcode/qrcode.class.php');
}
$this->qrcode = new QRcode($objattr['code'],
$objattr['errorlevel']);
$this->qrcode->displayFPDF($this, $objattr['INNER-
X'], $objattr['INNER-Y'], $objattr['bsize'] * 25, array(255, 255, 255), array(0, 0,
0));
} else {
$this->WriteBarcode2($objattr['code'],
$objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'],
$bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k);
}
}
/* -- END BARCODES -- */
// TEXT CIRCLE
if ($objattr['type'] == 'textcircle') {
$bgcol = '';
if (isset($objattr['bgcolor']) && $objattr['bgcolor']) {
$bgcol = $objattr['bgcolor'];
}
$col = $this->ConvertColor(0);
if (isset($objattr['color']) && $objattr['color']) {
$col = $objattr['color'];
}
$this->SetTColor($col);
$this->SetFColor($bgcol);
if ($bgcol)
$this->Rect($objattr['BORDER-X'], $objattr['BORDER-
Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
$this->SetFColor($this->ConvertColor(255));
if (isset($objattr['BORDER-WIDTH'])) {
$this->PaintImgBorder($objattr, $is_table);
}
if (!class_exists('directw', false)) {
include(_MPDF_PATH . 'classes/directw.php');
}
if (empty($this->directw)) {
$this->directw = new directw($this);
}
if (isset($objattr['top-text'])) {
$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'], (isset($objattr['divider']) ? $objattr['divider'] : ''));
}
if (isset($objattr['bottom-text'])) {
$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'], (isset($objattr['divider']) ? $objattr['divider'] : ''));
}
}
$this->ResetSpacing();
if ($objattr['listmarkerposition'] == 'inside') {
$adjx = $size / 2;
if ($objattr['dir'] == 'rtl') {
$adjx += $objattr['offset'];
}
$this->x += $adjx;
} else {
$adjx = $objattr['offset'];
$adjx += $size / 2;
if ($objattr['dir'] == 'rtl') {
$this->x += $adjx;
} else {
$this->x -= $adjx;
}
}
$yadj = $objattr['lineBox']['glyphYorigin'];
if (isset($this->CurrentFont['desc']['XHeight']) &&
$this->CurrentFont['desc']['XHeight']) {
$xh = $this->CurrentFont['desc']['XHeight'];
} else {
$xh = 500;
}
$yadj -= ($this->FontSize * $xh / 1000) * 0.625; //
Vertical height of bullet (centre) from baseline= XHeight * 0.625
$this->y += $yadj;
/* -- FORMS -- */
// TEXT/PASSWORD INPUT
if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'TEXT'
|| $objattr['subtype'] == 'PASSWORD')) {
$this->mpdfform->print_ob_text($objattr, $w, $h, $texto,
$rtlalign, $k, $blockdir);
}
// TEXTAREA
if ($objattr['type'] == 'textarea') {
$this->mpdfform->print_ob_textarea($objattr, $w, $h,
$texto, $rtlalign, $k, $blockdir);
}
// SELECT
if ($objattr['type'] == 'select') {
$this->mpdfform->print_ob_select($objattr, $w, $h, $texto,
$rtlalign, $k, $blockdir);
}
// INPUT/BUTTON as IMAGE
if ($objattr['type'] == 'input' && $objattr['subtype'] ==
'IMAGE') {
$this->mpdfform->print_ob_imageinput($objattr, $w, $h,
$texto, $rtlalign, $k, $blockdir);
}
// BUTTON
if ($objattr['type'] == 'input' && ($objattr['subtype'] ==
'SUBMIT' || $objattr['subtype'] == 'RESET' || $objattr['subtype'] == 'BUTTON')) {
$this->mpdfform->print_ob_button($objattr, $w, $h, $texto,
$rtlalign, $k, $blockdir);
}
// CHECKBOX
if ($objattr['type'] == 'input' && ($objattr['subtype'] ==
'CHECKBOX')) {
$this->mpdfform->print_ob_checkbox($objattr, $w, $h,
$texto, $rtlalign, $k, $blockdir, $x, $y);
}
// RADIO
if ($objattr['type'] == 'input' && ($objattr['subtype'] ==
'RADIO')) {
$this->mpdfform->print_ob_radio($objattr, $w, $h, $texto,
$rtlalign, $k, $blockdir, $x, $y);
}
/* -- END FORMS -- */
}
$this->SetFont($save_currentfontfamily, $save_currentfontstyle,
$save_currentfontsize);
$this->y = $save_y;
$this->x = $save_x;
unset($content);
}
// mPDF 6
// Get previous character and move pointers
function _moveToPrevChar(&$contentctr, &$charctr, $content)
{
$lastchar = false;
$charctr--;
while ($charctr < 0) { // go back to previous $content[]
$contentctr--;
if ($contentctr < 0) {
return false;
}
if ($this->usingCoreFont) {
$charctr = strlen($content[$contentctr]) - 1;
} else {
$charctr = mb_strlen($content[$contentctr], $this->mb_enc)
- 1;
}
}
if ($this->usingCoreFont) {
$lastchar = $content[$contentctr][$charctr];
} else {
$lastchar = mb_substr($content[$contentctr], $charctr, 1, $this-
>mb_enc);
}
return $lastchar;
}
$newblock = $this->flowingBlockAttr['newblock'];
$blockdir = $this->flowingBlockAttr['blockdir'];
$CJKoverflow = false;
$Oikomi = false; // mPDF 6
$hanger = '';
// COLS
$oldcolumn = $this->CurrCol;
if ($this->ColActive && !$is_table) {
$this->breakpoints[$this->CurrCol][] = $this->y;
} // *COLUMNS*
/* -- TABLES -- */
if ($is_table) {
$ipaddingL = 0;
$ipaddingR = 0;
$paddingL = 0;
$paddingR = 0;
$cpaddingadjustL = 0;
$cpaddingadjustR = 0;
// Added mPDF 3.0
$fpaddingR = 0;
$fpaddingL = 0;
} else {
/* -- END TABLES -- */
$ipaddingL = $this->blk[$this->blklvl]['padding_left'];
$ipaddingR = $this->blk[$this->blklvl]['padding_right'];
$paddingL = ($ipaddingL * _MPDFK);
$paddingR = ($ipaddingR * _MPDFK);
$this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
$cpaddingadjustL = -$this->cMarginL;
$this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
$cpaddingadjustR = -$this->cMarginR;
// Added mPDF 3.0 Float DIV
$fpaddingR = 0;
$fpaddingL = 0;
/* -- CSS-FLOAT -- */
if (count($this->floatDivs)) {
list($l_exists, $r_exists, $l_max, $r_max, $l_width,
$r_width) = $this->GetFloatDivInfo($this->blklvl);
if ($r_exists) {
$fpaddingR = $r_width;
}
if ($l_exists) {
$fpaddingL = $l_width;
}
}
/* -- END CSS-FLOAT -- */
if ($this->usingCoreFont) {
$clen = strlen($s);
} else {
$clen = mb_strlen($s, $this->mb_enc);
}
if ($i == 0) {
$cw += $lbw * _MPDFK;
$contentB[(count($contentB) - 1)] .= 'L';
}
if ($i == ($clen - 1)) {
$cw += $rbw * _MPDFK;
$contentB[(count($contentB) - 1)] .= 'R';
}
if ($c == ' ') {
$currContent .= $c;
$contentWidth += $cw;
continue;
}
// Paragraph INDENT
$WidthCorrection = 0;
if (($newblock) && ($blockstate == 1 || $blockstate == 3) &&
isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!
$is_table) && ($align != 'C')) {
$ti = $this->ConvertSize($this->blk[$this->blklvl]
['text_indent'], $this->blk[$this->blklvl]['inner_width'], $this->blk[$this-
>blklvl]['InlineProperties']['size'], false); // mPDF 5.7.4
$WidthCorrection = ($ti * _MPDFK);
}
// OUTDENT
foreach ($this->objectbuffer AS $k => $objattr) { // mPDF 6
DOTTAB
if ($objattr['type'] == 'dottab') {
$WidthCorrection -= ($objattr['outdent'] * _MPDFK);
break;
}
}
/* -- CSS-IMAGE-FLOAT -- */
// If float exists at this level
if (isset($this->floatmargins['R']) && $usey <= $this-
>floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this-
>floatmargins['R']['skipline']) {
$fpaddingR += $this->floatmargins['R']['w'];
}
if (isset($this->floatmargins['L']) && $usey <= $this-
>floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this-
>floatmargins['L']['skipline']) {
$fpaddingL += $this->floatmargins['L']['w'];
}
/* -- END CSS-IMAGE-FLOAT -- */
// mPDF 6
// New line-breaking algorithm
/////////////////////
// LINE BREAKING
/////////////////////
$breakfound = false;
$contentctr = count($content) - 1;
if ($this->usingCoreFont) {
$charctr = strlen($currContent);
} else {
$charctr = mb_strlen($currContent, $this->mb_enc);
}
$checkchar = $c;
$prevchar = $this->_getPrevChar($contentctr, $charctr,
$content);
/* -- CJK-FONTS -- */
/////////////////////
// 1) CJK Overflowing a) punctuation or b) Oikomi
/////////////////////
// Next character ($c) is suitable to add as overhanging or
squeezed punctuation, or Oikomi
if ($CJKoverflow || $Oikomi) { // If flag already set
$CJKoverflow = false;
$Oikomi = false;
$breakfound = true;
}
if (!$this->usingCoreFont && !$breakfound && $this-
>checkCJK) {
// Get next/following character (in this chunk)
$followingchar = '';
if ($i < ($clen - 1)) {
if ($this->usingCoreFont) {
$followingchar = $s[$i + 1];
} else {
$followingchar = mb_substr($s, $i + 1, 1,
$this->mb_enc);
}
}
/////////////////////
// 1a) Overflow punctuation
/////////////////////
if (preg_match("/[" . $this->pregCJKchars . "]/u",
$prevchar) && preg_match("/[" . $this->CJKoverflow . "]/u", $checkchar) && $this-
>allowCJKorphans) {
// add character onto this line
$currContent .= $c;
$contentWidth += $cw;
$CJKoverflow = true; // Set flag
continue;
}
/////////////////////
// 1b) Try squeezing another character(s) onto this
line = Oikomi, if character cannot end line
// or next character cannot start line (and not
splitting CJK numerals)
/////////////////////
// NB otherwise it move lastchar(s) to next line to
keep $c company = Oidashi, which is done below in standard way
elseif (preg_match("/[" . $this->pregCJKchars .
"]/u", $checkchar) && $this->allowCJKorphans &&
(preg_match("/[" . $this->CJKleading . "]/u",
$followingchar) || preg_match("/[" . $this->CJKfollowing . "]/u", $checkchar)) &&
!preg_match("/[" . $this->CJKleading . "]/u",
$checkchar) && !preg_match("/[" . $this->CJKfollowing . "]/u", $followingchar) &&
!(preg_match("/[0-9\x{ff10}-\x{ff19}]/u",
$followingchar) && preg_match("/[0-9\x{ff10}-\x{ff19}]/u", $checkchar))) {
// add character onto this line
$currContent .= $c;
$contentWidth += $cw;
$Oikomi = true; // Set flag
continue;
}
}
/* -- END CJK-FONTS -- */
/* -- HYPHENATION -- */
/////////////////////
// AUTOMATIC HYPHENATION
// 2) Automatic hyphen in current word (does not cross
tags)
/////////////////////
if (isset($this->textparam['hyphens']) && $this-
>textparam['hyphens'] == 1) {
$currWord = '';
// Look back and ahead to get current word
for ($ac = $charctr - 1; $ac >= 0; $ac--) {
if ($this->usingCoreFont) {
$addc = substr($currContent, $ac, 1);
} else {
$addc = mb_substr($currContent, $ac, 1,
$this->mb_enc);
}
if ($addc == ' ') {
break;
}
$currWord = $addc . $currWord;
}
$start = $ac + 1;
for ($ac = $i; $ac < ($clen - 1); $ac++) {
if ($this->usingCoreFont) {
$addc = substr($s, $ac, 1);
} else {
$addc = mb_substr($s, $ac, 1, $this-
>mb_enc);
}
if ($addc == ' ') {
break;
}
$currWord .= $addc;
}
$ptr = $this->hyphenateWord($currWord, $charctr -
$start);
if ($ptr > -1) {
$breakfound = array($contentctr, $start + $ptr,
$contentctr, $start + $ptr, 'hyphen');
}
}
/* -- END HYPHENATION -- */
$checkchar = $prevchar;
}
// Next cache the part which will start the next line
if ($this->usingCoreFont) {
$savedPreContent[] =
substr($content[$cutcontentctr], $cutcharctr);
} else {
$savedPreContent[] =
mb_substr($content[$cutcontentctr], $cutcharctr,
mb_strlen($content[$cutcontentctr]), $this->mb_enc);
}
$savedPreContentB[] = preg_replace('/L/', '',
$contentB[$cutcontentctr]);
$savedPreFont[] = $font[$cutcontentctr];
/* -- OTL -- */
if (!empty($sOTLdata)) {
$savedPreOTLdata[] = $this->otl-
>splitOTLdata($cOTLdata[$cutcontentctr], $cutcharctr, $cutcharctr);
}
/* -- END OTL -- */
if (!empty($sOTLdata)) {
$savedPreOTLdata[] = $this->otl-
>splitOTLdata($cOTLdata[(count($cOTLdata) - 1)], mb_strlen($currContent, $this-
>mb_enc));
}
if ($type == 'hyphen') {
$currContent .= '-';
if (!empty($cOTLdata[(count($cOTLdata) - 1)]))
{
$cOTLdata[(count($cOTLdata) - 1)]
['char_data'][] = array('bidi_class' => 9, 'uni' => 45);
$cOTLdata[(count($cOTLdata) - 1)]
['group'] .= 'C';
}
}
$savedContent = '';
$savedContentB = '';
$savedFont = array();
$savedOTLdata = array();
}
// If no line-break opportunity found - split at current
position
// or - Next character ($c) is suitable to add as
overhanging or squeezed punctuation, or Oikomi, as set above by:
// 1) CJK Overflowing a) punctuation or b) Oikomi
// in which case $breakfound==1 and NOT array
if (!is_array($breakfound)) {
$savedFont = $this->saveFont();
if (!empty($sOTLdata)) {
$savedOTLdata = $this->otl-
>splitOTLdata($cOTLdata[(count($cOTLdata) - 1)], mb_strlen($currContent, $this-
>mb_enc));
}
}
$lineBox = array();
$this->_setInlineBlockHeights($lineBox, $stackHeight,
$content, $font, $is_table);
$inclCursive = false;
foreach ($content as $k => $chunk) {
if (isset($this->objectbuffer[$k]) && $this-
>objectbuffer[$k]) {
// LIST MARKERS
if ($this->objectbuffer[$k]['type'] == 'image'
&& isset($this->objectbuffer[$k]['listmarker']) && $this->objectbuffer[$k]
['listmarker']) {
if ($this->objectbuffer[$k]
['listmarkerposition'] != 'outside') {
$contentWidth += $this-
>objectbuffer[$k]['OUTER-WIDTH'] * _MPDFK;
}
} else {
$contentWidth += $this->objectbuffer[$k]
['OUTER-WIDTH'] * _MPDFK;
}
} elseif (!isset($this->objectbuffer[$k]) ||
(isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
$this->restoreFont($font[$k], false);
if ($this->checkCJK && $k == count($content) -
1 && $CJKoverflow && $align == 'J' && $this->allowCJKoverflow && $this-
>CJKforceend) {
// force-end overhang
$hanger = mb_substr($chunk,
mb_strlen($chunk, $this->mb_enc) - 1, 1, $this->mb_enc);
// Probably ought to do something with
char_data and GPOS in cOTLdata...
$content[$k] = $chunk = mb_substr($chunk,
0, mb_strlen($chunk, $this->mb_enc) - 1, $this->mb_enc);
}
$contentWidth += $this->GetStringWidth($chunk,
true, (isset($cOTLdata[$k]) ? $cOTLdata[$k] : false), $this->textvar) * _MPDFK; //
mPDF 5.7.1
if (!empty($this->spanborddet)) {
if (isset($this->spanborddet['L']['w'])
&& strpos($contentB[$k], 'L') !== false)
$contentWidth += $this-
>spanborddet['L']['w'] * _MPDFK;
if (isset($this->spanborddet['R']['w'])
&& strpos($contentB[$k], 'R') !== false)
$contentWidth += $this-
>spanborddet['R']['w'] * _MPDFK;
}
}
}
$lastfontreqstyle = (isset($font[count($font) - 1]
['ReqFontStyle']) ? $font[count($font) - 1]['ReqFontStyle'] : '');
$lastfontstyle = (isset($font[count($font) - 1]['style']) ?
$font[count($font) - 1]['style'] : '');
if ($blockdir == 'ltr' && strpos($lastfontreqstyle, "I") !
== false && strpos($lastfontstyle, "I") === false) { // Artificial italic
$lastitalic = $this->FontSize * 0.15 * _MPDFK;
} else {
$lastitalic = 0;
}
/* -- END OTL -- */
// Remove any XAdvance from OTL data at end of line
foreach ($chunkorder AS $aord => $k) {
if (count($cOTLdata)) {
$this->restoreFont($font[$k], false);
// ...WriteFlowingBlock...
if ($aord == count($chunkorder) - 1 &&
isset($cOTLdata[$aord]['group'])) { // Last chunk on line
$nGPOS = strlen($cOTLdata[$aord]
['group']) - 1; // Last character
if (isset($cOTLdata[$aord]
['GPOSinfo'][$nGPOS]['XAdvanceL']) || isset($cOTLdata[$aord]['GPOSinfo'][$nGPOS]
['XAdvanceR'])) {
if (isset($cOTLdata[$aord]
['GPOSinfo'][$nGPOS]['XAdvanceL'])) {
$w = $cOTLdata[$aord]
['GPOSinfo'][$nGPOS]['XAdvanceL'] * 1000 / $this->CurrentFont['unitsPerEm'];
} else {
$w = $cOTLdata[$aord]
['GPOSinfo'][$nGPOS]['XAdvanceR'] * 1000 / $this->CurrentFont['unitsPerEm'];
}
$w *= ($this->FontSize /
1000);
$contentWidth -= $w * _MPDFK;
$cOTLdata[$aord]['GPOSinfo']
[$nGPOS]['XAdvanceL'] = 0;
$cOTLdata[$aord]['GPOSinfo']
[$nGPOS]['XAdvanceR'] = 0;
}
// JUSTIFICATION J
$jcharspacing = 0;
$jws = 0;
$nb_carac = 0;
$nb_spaces = 0;
$jkashida = 0;
// if it's justified, we need to find the char/word
spacing (or if hanger $this->CJKforceend)
if (($align == 'J' && !$CJKoverflow) ||
(($contentWidth + $lastitalic > $maxWidth - $WidthCorrection - (($this->cMarginL +
$this->cMarginR) * _MPDFK) - ($paddingL + $paddingR + (($fpaddingL + $fpaddingR) *
_MPDFK) ) + 0.001) && (!$CJKoverflow || ($CJKoverflow && !$this-
>allowCJKoverflow))) || $CJKoverflow && $align == 'J' && $this->allowCJKoverflow &&
$hanger && $this->CJKforceend) { // 0.001 is to correct for deviations converting
mm=>pts
// JUSTIFY J (Use character spacing)
// WORD SPACING
foreach ($chunkorder AS $aord => $k) { // mPDF
5.7
$chunk = $content[$aord];
if (!isset($this->objectbuffer[$k]) ||
(isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
$nb_carac += mb_strlen($chunk,
$this->mb_enc);
$nb_spaces +=
mb_substr_count($chunk, ' ', $this->mb_enc);
// Use GPOS OTL
if (isset($this-
>CurrentFont['useOTL']) && ($this->CurrentFont['useOTL'] & 0xFF)) {
if (isset($cOTLdata[$aord]
['group']) && $cOTLdata[$aord]['group']) {
$nb_carac -=
substr_count($cOTLdata[$aord]['group'], 'M');
}
}
} else {
$nb_carac ++;
} // mPDF 6 allow spacing for inline
object
}
// GetJSpacing adds kashida spacing to GPOSinfo
if appropriate for Font
list($jcharspacing, $jws, $jkashida) = $this-
>GetJspacing($nb_carac, $nb_spaces, ($maxWidth - $lastitalic - $contentWidth -
$WidthCorrection - (($this->cMarginL + $this->cMarginR) * _MPDFK) - ($paddingL +
$paddingR + (($fpaddingL + $fpaddingR) * _MPDFK) )), $inclCursive, $cOTLdata);
}
// WORD SPACING
$empty = $maxWidth - $lastitalic - $WidthCorrection -
$contentWidth - (($this->cMarginL + $this->cMarginR) * _MPDFK) - ($paddingL +
$paddingR + (($fpaddingL + $fpaddingR) * _MPDFK) );
// PAGEBREAK
// 'If' below used in order to fix "first-line of
other page with justify on" bug
if (!$is_table && ($this->y + $check_h) > $this-
>PageBreakTrigger and ! $this->InFooter and $this->AcceptPageBreak()) {
$bak_x = $this->x; //Current X position
// WORD SPACING
$ws = $this->ws; //Word Spacing
$charspacing = $this->charspacing; //Character
Spacing
$this->ResetSpacing();
$this->AddPage($this->CurOrientation);
$this->x = $bak_x;
// Added to correct for OddEven Margins
$currentx += $this->MarginCorrection;
$this->x += $this->MarginCorrection;
// WORD SPACING
$this->SetSpacing($charspacing, $ws);
}
/* -- COLUMNS -- */
// COLS
// COLUMN CHANGE
if ($this->CurrCol != $oldcolumn) {
$currentx += $this->ChangeColumn * ($this-
>ColWidth + $this->ColGap);
$this->x += $this->ChangeColumn * ($this-
>ColWidth + $this->ColGap);
$oldcolumn = $this->CurrCol;
}
// TOP MARGIN
if (($newblock) && ($blockstate == 1 || $blockstate
== 3) && ($this->blk[$this->blklvl]['margin_top']) && ($lineCount == 1) && (!
$is_table)) {
$this->DivLn($this->blk[$this->blklvl]
['margin_top'], $this->blklvl - 1, true, $this->blk[$this->blklvl]
['margin_collapse']);
if ($this->ColActive) {
$this->breakpoints[$this->CurrCol][] =
$this->y;
} // *COLUMNS*
}
$arraysize = count($chunkorder);
// Paragraph INDENT
if (isset($this->blk[$this->blklvl]['text_indent'])
&& ($newblock) && ($blockstate == 1 || $blockstate == 3) && ($lineCount == 1) && (!
$is_table) && ($blockdir != 'rtl') && ($align != 'C')) {
$ti = $this->ConvertSize($this->blk[$this-
>blklvl]['text_indent'], $this->blk[$this->blklvl]['inner_width'], $this-
>blk[$this->blklvl]['InlineProperties']['size'], false); // mPDF 5.7.4
$this->x += $ti;
}
if ($this->objectbuffer[$k]['type'] ==
'listmarker') {
$this->objectbuffer[$k]['lineBox']
= $lineBox[-1]; // Block element details for glyph-origin
}
$yadj = $this->y - $this-
>objectbuffer[$k]['OUTER-Y'];
if ($this->objectbuffer[$k]['type'] ==
'dottab') { // mPDF 6 DOTTAB
$this->objectbuffer[$k]['lineBox']
= $lineBox[$k]; // element details for glyph-origin
}
if ($this->objectbuffer[$k]['type'] !=
'dottab') { // mPDF 6 DOTTAB
$yadj += $lineBox[$k]['top'];
}
$this->objectbuffer[$k]['OUTER-Y'] +=
$yadj;
$this->objectbuffer[$k]['BORDER-Y'] +=
$yadj;
$this->objectbuffer[$k]['INNER-Y'] +=
$yadj;
}
$this->SetSpacing(($this->fixedlSpacing *
_MPDFK) + $jcharspacing, ($this->fixedlSpacing + $this->minwSpacing) * _MPDFK +
$jws);
// Now unset these values so they don't
influence GetStringwidth below or in fn. Cell
$this->fixedlSpacing = false;
$this->minwSpacing = 0;
$save_vis = $this->visibility;
if (isset($this->textparam['visibility']) &&
$this->textparam['visibility'] && $this->textparam['visibility'] != $this-
>visibility) {
$this->SetVisibility($this-
>textparam['visibility']);
}
// *********** SPAN BACKGROUND COLOR
***************** //
if ($this->spanbgcolor) {
$cor = $this->spanbgcolorarray;
$this->SetFColor($cor);
$save_fill = $fill;
$spanfill = 1;
$fill = 1;
}
if (!empty($this->spanborddet)) {
if (strpos($contentB[$k], 'L') !== false)
$this->x += (isset($this-
>spanborddet['L']['w']) ? $this->spanborddet['L']['w'] : 0);
if (strpos($contentB[$k], 'L') === false)
$this->spanborddet['L']['s'] =
$this->spanborddet['L']['w'] = 0;
if (strpos($contentB[$k], 'R') === false)
$this->spanborddet['R']['s'] =
$this->spanborddet['R']['w'] = 0;
}
// WORD SPACING
// StringWidth this time includes any kashida
spacing
$stringWidth = $this->GetStringWidth($chunk,
true, (isset($cOTLdata[$aord]) ? $cOTLdata[$aord] : false), $this->textvar, true);
$stringWidth += ( $this->ws *
mb_substr_count($chunk, ' ', $this->mb_enc) / _MPDFK );
if (isset($this->objectbuffer[$k])) {
// LIST MARKERS // mPDF 6 Lists
if ($this->objectbuffer[$k]['type'] ==
'image' && isset($this->objectbuffer[$k]['listmarker']) && $this->objectbuffer[$k]
['listmarker'] && $this->objectbuffer[$k]['listmarkerposition'] == 'outside') {
$stringWidth = 0;
} else {
$stringWidth = $this-
>objectbuffer[$k]['OUTER-WIDTH'];
}
}
if ($stringWidth == 0) {
$stringWidth = 0.000001;
}
if ($aord == $arraysize - 1) {
$stringWidth -= ( $this->charspacing /
_MPDFK );
if ($this->checkCJK && $CJKoverflow &&
$align == 'J' && $this->allowCJKoverflow && $hanger && $this->CJKforceend) {
// force-end overhang
$this->Cell($stringWidth,
$stackHeight, $chunk, '', 0, '', $fill, $this->HREF, $currentx, 0, 0, 'M', $fill,
true, (isset($cOTLdata[$aord]) ? $cOTLdata[$aord] : false), $this->textvar,
(isset($lineBox[$k]) ? $lineBox[$k] : false));
$this->Cell($this-
>GetStringWidth($hanger), $stackHeight, $hanger, '', 1, '', $fill, $this->HREF,
$currentx, 0, 0, 'M', $fill, true, (isset($cOTLdata[$aord]) ? $cOTLdata[$aord] :
false), $this->textvar, (isset($lineBox[$k]) ? $lineBox[$k] : false));
} else {
$this->Cell($stringWidth,
$stackHeight, $chunk, '', 1, '', $fill, $this->HREF, $currentx, 0, 0, 'M', $fill,
true, (isset($cOTLdata[$aord]) ? $cOTLdata[$aord] : false), $this->textvar,
(isset($lineBox[$k]) ? $lineBox[$k] : false)); //mono-style line or last part
(skips line)
}
} else
$this->Cell($stringWidth, $stackHeight,
$chunk, '', 0, '', $fill, $this->HREF, 0, 0, 0, 'M', $fill, true,
(isset($cOTLdata[$aord]) ? $cOTLdata[$aord] : false), $this->textvar,
(isset($lineBox[$k]) ? $lineBox[$k] : false)); //first or middle part
if (!empty($this->spanborddet)) {
if (strpos($contentB[$k], 'R') !== false
&& $aord != $arraysize - 1)
$this->x += $this->spanborddet['R']
['w'];
}
// *********** SPAN BACKGROUND COLOR OFF -
RESET BLOCK BGCOLOR ***************** //
if (isset($spanfill) && $spanfill) {
$fill = $save_fill;
$spanfill = 0;
if ($fill) {
$this->SetFColor($bcor);
}
}
if (isset($this->textparam['visibility']) &&
$this->textparam['visibility'] && $this->visibility != $save_vis) {
$this->SetVisibility($save_vis);
}
}
} elseif ($table_draft) {
$this->y += $stackHeight;
}
if (!$is_table) {
$this->maxPosR = max($this->maxPosR, ($this->w -
$this->rMargin - $this->blk[$this->blklvl]['outer_right_margin']));
$this->maxPosL = min($this->maxPosL, ($this->lMargin
+ $this->blk[$this->blklvl]['outer_left_margin']));
}
if (!$table_draft)
$this->printobjectbuffer($is_table, $blockdir);
$this->objectbuffer = array();
/* -- CSS-IMAGE-FLOAT -- */
// Update values if set to skipline
if ($this->floatmargins) {
$this->_advanceFloatMargins();
}
/* -- END CSS-IMAGE-FLOAT -- */
// Reset lineheight
$stackHeight = $this->divheight;
$valign = 'M';
$font = array();
$content = array();
$contentB = array();
$cOTLdata = array(); // mPDF 5.7.1
$contentWidth = 0;
if (!empty($savedObj)) {
$this->objectbuffer[] = $savedObj;
$font[] = $savedFont;
$content[] = '';
$contentB[] = '';
$cOTLdata[] = array(); // mPDF 5.7.1
$contentWidth += $savedObj['OUTER-WIDTH'] * _MPDFK;
}
if (count($savedPreContent) > 0) {
for ($ix = count($savedPreContent) - 1; $ix >= 0;
$ix--) {
$font[] = $savedPreFont[$ix];
$content[] = $savedPreContent[$ix];
$contentB[] = $savedPreContentB[$ix];
if (!empty($sOTLdata)) {
$cOTLdata[] = $savedPreOTLdata[$ix];
}
$this->restoreFont($savedPreFont[$ix]);
$lbw = $rbw = 0; // Border widths
if (!empty($this->spanborddet)) {
$lbw = (isset($this->spanborddet['L']
['w']) ? $this->spanborddet['L']['w'] : 0);
$rbw = (isset($this->spanborddet['R']
['w']) ? $this->spanborddet['R']['w'] : 0);
}
if ($ix > 0) {
$contentWidth += $this-
>GetStringWidth($savedPreContent[$ix], true, (isset($savedPreOTLdata[$ix]) ?
$savedPreOTLdata[$ix] : false), $this->textvar) * _MPDFK; // mPDF 5.7.1
if (strpos($savedPreContentB[$ix], 'L') !
== false)
$contentWidth += $lbw;
if (strpos($savedPreContentB[$ix], 'R') !
== false)
$contentWidth += $rbw;
}
}
$savedPreContent = array();
$savedPreContentB = array();
$savedPreOTLdata = array(); // mPDF 5.7.1
$savedPreFont = array();
$content[(count($content) - 1)] .= $c;
}
else {
$font[] = $savedFont;
$content[] = $savedContent . $c;
$contentB[] = $savedContentB;
$cOTLdata[] = $savedOTLdata; // mPDF 5.7.1
}
/* -- CJK-FONTS -- */
// CJK - strip CJK space at start of line
//   = \xe3\x80\x80 = CJK space
if ($this->checkCJK && $currContent == "\xe3\x80\x80") {
$currContent = '';
if (isset($this->CurrentFont['useOTL']) && $this-
>CurrentFont['useOTL']) {
$this->otl-
>trimOTLdata($cOTLdata[count($cOTLdata) - 1], true, false); // left trim U+3000
}
}
/* -- END CJK-FONTS -- */
unset($content);
unset($contentB);
}
//----------------------END OF FLOWING
BLOCK------------------------------------//
/* -- CSS-IMAGE-FLOAT -- */
// Update values if set to skipline
function _advanceFloatMargins()
{
// Update floatmargins - L
if (isset($this->floatmargins['L']) && $this->floatmargins['L']
['skipline'] && $this->floatmargins['L']['y0'] != $this->y) {
$yadj = $this->y - $this->floatmargins['L']['y0'];
$this->floatmargins['L']['y0'] = $this->y;
$this->floatmargins['L']['y1'] += $yadj;
// Unset values
$this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] =
false;
$this->floatmargins['L']['skipline'] = false;
$this->floatmargins['L']['id'] = '';
}
// Update floatmargins - R
if (isset($this->floatmargins['R']) && $this->floatmargins['R']
['skipline'] && $this->floatmargins['R']['y0'] != $this->y) {
$yadj = $this->y - $this->floatmargins['R']['y0'];
$this->floatmargins['R']['y0'] = $this->y;
$this->floatmargins['R']['y1'] += $yadj;
/* -- END CSS-IMAGE-FLOAT -- */
/* -- END HTML-CSS -- */
function _SetTextRendering($mode)
{
if (!(($mode == 0) || ($mode == 1) || ($mode == 2)))
throw new MpdfException("Text rendering mode should be 0, 1 or 2
(value : $mode)");
$tr = ($mode . ' Tr');
if ($this->page > 0 && ((isset($this->pageoutput[$this->page]
['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !
isset($this->pageoutput[$this->page]['TextRendering']))) {
$this->_out($tr);
}
$this->pageoutput[$this->page]['TextRendering'] = $tr;
}
/* -- WATERMARK -- */
if ($watermark) {
$maxw = $this->w;
$maxh = $this->h;
// Size = D PF or array
if (is_array($this->watermark_size)) {
$w = $this->watermark_size[0];
$h = $this->watermark_size[1];
} elseif (!is_string($this->watermark_size)) {
$maxw -= $this->watermark_size * 2;
$maxh -= $this->watermark_size * 2;
$w = $maxw;
$h = abs($w * $info['h'] / $info['w']);
if ($h > $maxh) {
$h = $maxh;
$w = abs($h * $info['w'] / $info['h']);
}
} elseif ($this->watermark_size == 'F') {
if ($this->ColActive) {
$maxw = $this->w - ($this->DeflMargin + $this-
>DefrMargin);
} else {
$maxw = $this->pgwidth;
}
$maxh = $this->h - ($this->tMargin + $this->bMargin);
$w = $maxw;
$h = abs($w * $info['h'] / $info['w']);
if ($h > $maxh) {
$h = $maxh;
$w = abs($h * $info['w'] / $info['h']);
}
} elseif ($this->watermark_size == 'P') { // Default P
$w = $maxw;
$h = abs($w * $info['h'] / $info['w']);
if ($h > $maxh) {
$h = $maxh;
$w = abs($h * $info['w'] / $info['h']);
}
}
// Automatically resize to maximum dimensions of page if too
large
if ($w > $maxw) {
$w = $maxw;
$h = abs($w * $info['h'] / $info['w']);
}
if ($h > $maxh) {
$h = $maxh;
$w = abs($h * $info['w'] / $info['h']);
}
// Position
if (is_array($this->watermark_pos)) {
$x = $this->watermark_pos[0];
$y = $this->watermark_pos[1];
} elseif ($this->watermark_pos == 'F') { // centred on printable
area
if ($this->ColActive) { // *COLUMNS*
if (($this->mirrorMargins) && (($this->page) % 2 ==
0)) {
$xadj = $this->DeflMargin - $this->DefrMargin;
} // *COLUMNS*
else {
$xadj = 0;
} // *COLUMNS*
$x = ($this->DeflMargin - $xadj + ($this->w - ($this-
>DeflMargin + $this->DefrMargin)) / 2) - ($w / 2); // *COLUMNS*
} // *COLUMNS*
else { // *COLUMNS*
$x = ($this->lMargin + ($this->pgwidth) / 2) - ($w /
2);
} // *COLUMNS*
$y = ($this->tMargin + ($this->h - ($this->tMargin + $this-
>bMargin)) / 2) - ($h / 2);
} else { // default P - centred on whole page
$x = ($this->w / 2) - ($w / 2);
$y = ($this->h / 2) - ($h / 2);
}
/* -- IMAGES-WMF -- */
if ($info['type'] == 'wmf') {
$sx = $w * _MPDFK / $info['w'];
$sy = -$h * _MPDFK / $info['h'];
$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']);
} else
/* -- END IMAGES-WMF -- */
if ($info['type'] == 'svg') {
$sx = $w * _MPDFK / $info['w'];
$sy = -$h * _MPDFK / $info['h'];
$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']);
} else {
$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']);
}
if ($this->watermarkImgBehind) {
$outstring = $this->watermarkImgAlpha . "\n" . $outstring .
"\n" . $this->SetAlpha(1, 'Normal', true) . "\n";
$this->pages[$this->page] = preg_replace('/
(___BACKGROUND___PATTERNS' . $this->uniqstr . ')/', "\n" . $outstring . "\n" .
'\\1', $this->pages[$this->page]);
} else {
$this->_out($outstring);
}
return 0;
} // end of IF watermark
/* -- END WATERMARK -- */
if ($constrain) {
// Automatically resize to maximum dimensions of page if too
large
if (isset($this->blk[$this->blklvl]['inner_width']) && $this-
>blk[$this->blklvl]['inner_width']) {
$maxw = $this->blk[$this->blklvl]['inner_width'];
} else {
$maxw = $this->pgwidth;
}
if ($w > $maxw) {
$w = $maxw;
$h = abs($w * $info['h'] / $info['w']);
}
if ($h > $this->h - ($this->tMargin + $this->bMargin + 1)) { //
see below - +10 to avoid drawing too close to border of page
$h = $this->h - ($this->tMargin + $this->bMargin + 1);
if ($this->fullImageHeight) {
$h = $this->fullImageHeight;
}
$w = abs($h * $info['w'] / $info['h']);
}
$changedpage = false;
$oldcolumn = $this->CurrCol;
//Avoid drawing out of the page.
if ($y + $h > $this->PageBreakTrigger and ! $this->InFooter and
$this->AcceptPageBreak()) {
$this->AddPage($this->CurOrientation);
// Added to correct for OddEven Margins
$x = $x + $this->MarginCorrection;
$y = $this->tMargin; // mPDF 5.7.3
$changedpage = true;
}
/* -- COLUMNS -- */
// COLS
// COLUMN CHANGE
if ($this->CurrCol != $oldcolumn) {
$y = $this->y0;
$x += $this->ChangeColumn * ($this->ColWidth + $this-
>ColGap);
$this->x += $this->ChangeColumn * ($this->ColWidth + $this-
>ColGap);
}
/* -- END COLUMNS -- */
} // end of IF constrain
/* -- IMAGES-WMF -- */
if ($info['type'] == 'wmf') {
$sx = $w * _MPDFK / $info['w'];
$sy = -$h * _MPDFK / $info['h'];
$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']);
} else
/* -- END IMAGES-WMF -- */
if ($info['type'] == 'svg') {
$sx = $w * _MPDFK / $info['w'];
$sy = -$h * _MPDFK / $info['h'];
$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']);
} else {
$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']);
}
if ($paint) {
$this->_out($outstring);
if ($link)
$this->Link($x, $y, $w, $h, $link);
$sizesarray['IMAGE_ID'] = $info['i'];
$sizesarray['itype'] = $info['type'];
$sizesarray['set-dpi'] = (isset($info['set-dpi']) ? $info['set-dpi'] :
0);
return $sizesarray;
}
//=============================================================
//=============================================================
//=============================================================
//=============================================================
//=============================================================
/* -- HTML-CSS -- */
function _getObjAttr($t)
{
$c = explode("\xbb\xa4\xac", $t, 2);
$c = explode(",", $c[1], 2);
foreach ($c as $v) {
$v = explode("=", $v, 2);
$sp[$v[0]] = $v[1];
}
return (unserialize($sp['objattr']));
}
if (!isset($objattr['vertical-align'])) {
if ($objattr['type'] == 'select') {
$objattr['vertical-align'] = 'M';
} else {
$objattr['vertical-align'] = 'BS';
}
} // mPDF 6
if ($type == 'image') {
// Automatically resize to width remaining
if ($w > ($widthLeft + 0.0001) && !$is_table) { // mPDF 5.7.4
0.0001 to allow for rounding errors when w==maxWidth
$w = $widthLeft;
$h = abs($w * $info['h'] / $info['w']);
}
$img_w = $w - $extraWidth;
$img_h = $h - $extraHeight;
if ($type == 'textarea') {
// Automatically resize to width remaining
if ($w > $widthLeft && !$is_table) {
$w = $widthLeft;
}
// This used to resize height to maximum remaining on page ? why.
Causes problems when in table and causing a new column
// if (($y + $h > $this->PageBreakTrigger) && !$this-
>InFooter) {
// $h=$this->h - $y - $this->bMargin;
// }
}
if ($type == 'hr') {
if ($is_table) {
$objattr['INNER-WIDTH'] = $maxWidth * $objattr['W-PERCENT']
/ 100;
$objattr['width'] = $objattr['INNER-WIDTH'];
$w = $maxWidth;
} else {
if ($w > $maxWidth) {
$w = $maxWidth;
}
$objattr['INNER-WIDTH'] = $w;
$w = $maxWidth;
}
}
if (!isset($objattr['BORDER-Y'])) {
$objattr['BORDER-Y'] = 0;
}
if (!isset($objattr['BORDER-X'])) {
$objattr['BORDER-X'] = 0;
}
if (!isset($objattr['INNER-Y'])) {
$objattr['INNER-Y'] = 0;
}
if (!isset($objattr['INNER-X'])) {
$objattr['INNER-X'] = 0;
}
/* -- END HTML-CSS -- */
//=============================================================
//=============================================================
//=============================================================
//=============================================================
//=============================================================
function SetLineJoin($mode = 0)
{
$s = sprintf('%d j', $mode);
if ($this->page > 0 && ((isset($this->pageoutput[$this->page]
['LineJoin']) && $this->pageoutput[$this->page]['LineJoin'] != $s) || !isset($this-
>pageoutput[$this->page]['LineJoin']))) {
$this->_out($s);
}
$this->pageoutput[$this->page]['LineJoin'] = $s;
}
function SetLineCap($mode = 2)
{
$s = sprintf('%d J', $mode);
if ($this->page > 0 && ((isset($this->pageoutput[$this->page]
['LineCap']) && $this->pageoutput[$this->page]['LineCap'] != $s) || !isset($this-
>pageoutput[$this->page]['LineCap']))) {
$this->_out($s);
}
$this->pageoutput[$this->page]['LineCap'] = $s;
}
function SetDisplayPreferences($preferences)
{
// String containing any or none of
/HideMenubar/HideToolbar/HideWindowUI/DisplayDocTitle/CenterWindow/FitWindow
$this->DisplayPreferences .= $preferences;
}
/* -- HTML-CSS -- */
// mPDF 6 Columns
// if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f",
$this->y0)) && ($this->ColActive) && $this->CurrCol == 0) { return; } // *COLUMNS*
if ($collapsible && (sprintf("%0.4f", $this->y) == sprintf("%0.4f",
$this->y0)) && ($this->ColActive)) {
return;
} // *COLUMNS*
// Still use this method if columns or keep-with-table, as it allows
repositioning later
// otherwise, now uses PaintDivBB()
if (!$this->ColActive && !$this->kwt) {
if ($move_y && !$this->ColActive) {
$this->y += $h;
}
return;
}
if ($level == -3) {
$level = $this->blklvl;
}
$firstblockfill = $this->GetFirstBlockFill();
if ($firstblockfill && $this->blklvl > 0 && $this->blklvl >=
$firstblockfill) {
$last_x = 0;
$last_w = 0;
$last_fc = $this->FillColor;
$bak_x = $this->x;
$bak_h = $this->divheight;
$this->divheight = 0; // Temporarily turn off divheight - as
Cell() uses it to check for PageBreak
for ($blvl = $firstblockfill; $blvl <= $level; $blvl++) {
$this->x = $this->lMargin + $this->blk[$blvl]
['outer_left_margin'];
// mPDF 6
if ($this->blk[$blvl]['bgcolor']) {
$this->SetFColor($this->blk[$blvl]['bgcolorarray']);
}
if ($last_x != ($this->lMargin + $this->blk[$blvl]
['outer_left_margin']) || ($last_w != $this->blk[$blvl]['width']) || $last_fc !=
$this->FillColor || (isset($this->blk[$blvl]['border_top']['s']) && $this-
>blk[$blvl]['border_top']['s']) || (isset($this->blk[$blvl]['border_bottom']['s'])
&& $this->blk[$blvl]['border_bottom']['s']) || (isset($this->blk[$blvl]
['border_left']['s']) && $this->blk[$blvl]['border_left']['s']) || (isset($this-
>blk[$blvl]['border_right']['s']) && $this->blk[$blvl]['border_right']['s'])) {
$x = $this->x;
$this->Cell(($this->blk[$blvl]['width']), $h, '', '',
0, '', 1);
$this->x = $x;
if (!$this->keep_block_together && !$this-
>writingHTMLheader && !$this->writingHTMLfooter) {
// $state = 0 normal; 1 top; 2 bottom; 3 top
and bottom
if ($blvl == $this->blklvl) {
$this->PaintDivLnBorder($state, $blvl,
$h);
} else {
$this->PaintDivLnBorder(0, $blvl, $h);
}
}
}
$last_x = $this->lMargin + $this->blk[$blvl]
['outer_left_margin'];
$last_w = $this->blk[$blvl]['width'];
$last_fc = $this->FillColor;
}
// Reset current block fill
if (isset($this->blk[$this->blklvl]['bgcolorarray'])) {
$bcor = $this->blk[$this->blklvl]['bgcolorarray'];
$this->SetFColor($bcor);
}
$this->x = $bak_x;
$this->divheight = $bak_h;
}
if ($move_y) {
$this->y += $h;
}
}
/* -- END HTML-CSS -- */
function SetX($x)
{
//Set x position
if ($x >= 0)
$this->x = $x;
else
$this->x = $this->w + $x;
}
function SetY($y)
{
//Set y position and reset x
$this->x = $this->lMargin;
if ($y >= 0)
$this->y = $y;
else
$this->y = $this->h + $y;
}
if ($this->showStats) {
echo '<div>Compiled in ' . sprintf('%.2F', (microtime(true) -
$this->time0)) . ' seconds (total)</div>';
echo '<div>Peak Memory usage ' .
number_format((memory_get_peak_usage(true) / (1024 * 1024)), 2) . ' MB</div>';
echo '<div>PDF file size ' . number_format((strlen($this->buffer)
/ 1024)) . ' kB</div>';
echo '<div>Number of fonts ' . count($this->fonts) . '</div>';
exit;
}
if (is_bool($dest))
$dest = $dest ? 'D' : 'F';
$dest = strtoupper($dest);
if ($dest == '') {
if ($name == '') {
$name = 'mpdf.pdf';
$dest = 'I';
} else {
$dest = 'F';
}
}
/* -- PROGRESS-BAR -- */
if ($this->progressBar && ($dest == 'D' || $dest == 'I')) {
if ($name == '') {
$name = 'mpdf.pdf';
}
$tempfile = '_tempPDF' . uniqid(rand(1, 100000), true);
//Save to local file
$f = fopen(_MPDF_TEMP_PATH . $tempfile . '.pdf', 'wb');
if (!$f)
throw new MpdfException('Unable to create temporary output
file: ' . $tempfile . '.pdf');
fwrite($f, $this->buffer, strlen($this->buffer));
fclose($f);
$this->UpdateProgressBar(3, '', 'Finished');
document.body.appendChild(form);
form.submit();
</script>
</div>
</body>
</html>';
exit;
}
else {
if ($this->progressBar) {
$this->UpdateProgressBar(3, '', 'Finished');
}
/* -- END PROGRESS-BAR -- */
switch ($dest) {
case 'I':
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;
}
//Send to standard output
if (PHP_SAPI != 'cli') {
//We send to a browser
header('Content-Type: application/pdf');
if (headers_sent())
throw new MpdfException('Some data has
already been output to browser, can\'t send PDF file');
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR
empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
// don't use length if server using
compression
header('Content-Length: ' . strlen($this-
>buffer));
}
header('Content-disposition: inline;
filename="' . $name . '"');
header('Cache-Control: public, must-revalidate,
max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00
GMT');
header('Last-Modified: ' . gmdate('D, d M Y
H:i:s') . ' GMT');
}
echo $this->buffer;
break;
case 'D':
//Download file
header('Content-Description: File Transfer');
if (headers_sent())
throw new MpdfException('Some data has already
been output to browser, can\'t send PDF file');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: public, must-revalidate, max-
age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') .
' GMT');
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream',
false);
header('Content-Type: application/download', false);
header('Content-Type: application/pdf', false);
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR
empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
// don't use length if server using compression
header('Content-Length: ' . strlen($this-
>buffer));
}
header('Content-disposition: attachment;
filename="' . $name . '"');
echo $this->buffer;
break;
case 'F':
//Save to local file
$f = fopen($name, 'wb');
if (!$f)
throw new MpdfException('Unable to create
output file: ' . $name);
fwrite($f, $this->buffer, strlen($this->buffer));
fclose($f);
break;
case 'S':
//Return as a string
return $this->buffer;
default:
throw new MpdfException('Incorrect output
destination: ' . $dest);
}
} // *PROGRESS-BAR*
//=====================================================================
=================================
// DELETE OLD TMP FILES - Housekeeping
// Delete any files in tmp/ directory that are >1 hrs old
$interval = 3600;
if ($handle = @opendir(preg_replace('/\/$/', '', _MPDF_TEMP_PATH)))
{ // mPDF 5.7.3
while (false !== ($file = readdir($handle))) {
if (($file != "..") && ($file != ".") && !is_dir($file) &&
((filemtime(_MPDF_TEMP_PATH . $file) + $interval) < time()) && (substr($file, 0, 1)
!== '.') && ($file != 'dummy.txt')) { // mPDF 5.7.3
unlink(_MPDF_TEMP_PATH . $file);
}
}
closedir($handle);
}
//=====================================================================
=========================================
return '';
}
//
*****************************************************************************
//
*
// Protected methods
*
//
*
//
*****************************************************************************
function _dochecks()
{
//Check for locale-related bug
if (1.1 == 1)
throw new MpdfException('Don\'t alter the locale before including
mPDF');
//Check for decimal separator
if (sprintf('%.1f', 1.0) != '1.0')
setlocale(LC_NUMERIC, 'C');
$mqr = ini_get("magic_quotes_runtime");
if ($mqr) {
throw new MpdfException('mPDF requires magic_quotes_runtime to be
turned off e.g. by using ini_set("magic_quotes_runtime", 0);');
}
}
function _puthtmlheaders()
{
$this->state = 2;
$nb = $this->page;
for ($n = 1; $n <= $nb; $n++) {
if ($this->mirrorMargins && $n % 2 == 0) {
$OE = 'E';
} // EVEN
else {
$OE = 'O';
}
$this->page = $n;
$pn = $this->docPageNum($n);
if ($pn)
$pnstr = $this->pagenumPrefix . $pn . $this->pagenumSuffix;
else {
$pnstr = '';
}
$pnt = $this->docPageNumTotal($n);
if ($pnt)
$pntstr = $this->nbpgPrefix . $pnt . $this->nbpgSuffix;
else {
$pntstr = '';
}
if (isset($this->saveHTMLHeader[$n][$OE])) {
$html = $this->saveHTMLHeader[$n][$OE]['html'];
$this->lMargin = $this->saveHTMLHeader[$n][$OE]['ml'];
$this->rMargin = $this->saveHTMLHeader[$n][$OE]['mr'];
$this->tMargin = $this->saveHTMLHeader[$n][$OE]['mh'];
$this->bMargin = $this->saveHTMLHeader[$n][$OE]['mf'];
$this->margin_header = $this->saveHTMLHeader[$n][$OE]
['mh'];
$this->margin_footer = $this->saveHTMLHeader[$n][$OE]
['mf'];
$this->w = $this->saveHTMLHeader[$n][$OE]['pw'];
$this->h = $this->saveHTMLHeader[$n][$OE]['ph'];
$rotate = (isset($this->saveHTMLHeader[$n][$OE]
['rotate']) ? $this->saveHTMLHeader[$n][$OE]['rotate'] : null);
$this->Reset();
$this->pageoutput[$n] = array();
$this->pgwidth = $this->w - $this->lMargin - $this-
>rMargin;
$this->x = $this->lMargin;
$this->y = $this->margin_header;
$html = str_replace('{PAGENO}', $pnstr, $html);
$html = str_replace($this->aliasNbPgGp, $pntstr, $html); //
{nbpg}
$html = str_replace($this->aliasNbPg, $nb, $html); // {nb}
$html = preg_replace_callback('/\{DATE\s+(.*?)\}/',
array($this, 'date_callback'), $html); // mPDF 5.7
$this->HTMLheaderPageLinks = array();
$this->HTMLheaderPageAnnots = array();
$this->HTMLheaderPageForms = array();
$this->pageBackgrounds = array();
$this->writingHTMLheader = true;
$this->WriteHTML($html, 4); // parameter 4 saves output to
$this->headerbuffer
$this->writingHTMLheader = false;
$this->Reset();
$this->pageoutput[$n] = array();
$s = $this->PrintPageBackgrounds();
$this->headerbuffer = $s . $this->headerbuffer;
$os = '';
if ($rotate) {
$os .= sprintf('q 0 -1 1 0 0 %.3F cm ', ($this->w *
_MPDFK));
// To rotate the other way i.e. Header to left of
page:
//$os .= sprintf('q 0 1 -1 0 %.3F %.3F cm ',($this-
>h*_MPDFK), (($this->rMargin - $this->lMargin )*_MPDFK));
}
$os .= $this->headerbuffer;
if ($rotate) {
$os .= ' Q' . "\n";
}
$lks = $this->HTMLheaderPageLinks;
foreach ($lks AS $lk) {
if ($rotate) {
$lw = $lk[2];
$lh = $lk[3];
$lk[2] = $lh;
$lk[3] = $lw; // swap width and height
$ax = $lk[0] / _MPDFK;
$ay = $lk[1] / _MPDFK;
$bx = $ay - ($lh / _MPDFK);
$by = $this->w - $ax;
$lk[0] = $bx * _MPDFK;
$lk[1] = ($this->h - $by) * _MPDFK - $lw;
}
$this->PageLinks[$n][] = $lk;
}
/* -- FORMS -- */
foreach ($this->HTMLheaderPageForms AS $f) {
$this->mpdfform->forms[$f['n']] = $f;
}
/* -- END FORMS -- */
}
if (isset($this->saveHTMLFooter[$n][$OE])) {
$html = $this->saveHTMLFooter[$this->page][$OE]['html'];
$this->lMargin = $this->saveHTMLFooter[$n][$OE]['ml'];
$this->rMargin = $this->saveHTMLFooter[$n][$OE]['mr'];
$this->tMargin = $this->saveHTMLFooter[$n][$OE]['mh'];
$this->bMargin = $this->saveHTMLFooter[$n][$OE]['mf'];
$this->margin_header = $this->saveHTMLFooter[$n][$OE]
['mh'];
$this->margin_footer = $this->saveHTMLFooter[$n][$OE]
['mf'];
$this->w = $this->saveHTMLFooter[$n][$OE]['pw'];
$this->h = $this->saveHTMLFooter[$n][$OE]['ph'];
$rotate = (isset($this->saveHTMLFooter[$n][$OE]
['rotate']) ? $this->saveHTMLFooter[$n][$OE]['rotate'] : null);
$this->Reset();
$this->pageoutput[$n] = array();
$this->pgwidth = $this->w - $this->lMargin - $this-
>rMargin;
$this->x = $this->lMargin;
$top_y = $this->y = $this->h - $this->margin_footer;
$this->HTMLheaderPageLinks = array();
$this->HTMLheaderPageAnnots = array();
$this->HTMLheaderPageForms = array();
$this->pageBackgrounds = array();
$this->writingHTMLfooter = true;
$this->InFooter = true;
$this->WriteHTML($html, 4); // parameter 4 saves output to
$this->headerbuffer
$this->InFooter = false;
$this->Reset();
$this->pageoutput[$n] = array();
$s = $this->PrintPageBackgrounds(-$adj);
$this->headerbuffer = $s . $this->headerbuffer;
$this->writingHTMLfooter = false; // mPDF 5.7.3 (moved
after PrintPageBackgrounds so can adjust position of images in footer)
$os = '';
$os .= $this->StartTransform(true) . "\n";
if ($rotate) {
$os .= sprintf('q 0 -1 1 0 0 %.3F cm ', ($this->w *
_MPDFK));
// To rotate the other way i.e. Header to left of
page:
//$os .= sprintf('q 0 1 -1 0 %.3F %.3F cm ',($this-
>h*_MPDFK), (($this->rMargin - $this->lMargin )*_MPDFK));
}
$os .= $this->transformTranslate(0, $adj, true) . "\n";
$os .= $this->headerbuffer;
if ($rotate) {
$os .= ' Q' . "\n";
}
$os .= $this->StopTransform(true) . "\n";
// Writes over the page background but behind any other
output on page
$os = preg_replace('/\\\\/', '\\\\\\\\', $os);
$this->pages[$n] = preg_replace('/(___HEADER___MARKER' .
$this->uniqstr . ')/', "\n" . $os . "\n" . '\\1', $this->pages[$n]);
$lks = $this->HTMLheaderPageLinks;
foreach ($lks AS $lk) {
$lk[1] -= $adj * _MPDFK;
if ($rotate) {
$lw = $lk[2];
$lh = $lk[3];
$lk[2] = $lh;
$lk[3] = $lw; // swap width and height
function _putpages()
{
$nb = $this->page;
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
if ($this->DefOrientation == 'P') {
$defwPt = $this->fwPt;
$defhPt = $this->fhPt;
} else {
$defwPt = $this->fhPt;
$defhPt = $this->fwPt;
}
$annotid = (3 + 2 * $nb);
// Active Forms
$totaladdnum = 0;
for ($n = 1; $n <= $nb; $n++) {
if (isset($this->PageLinks[$n])) {
$totaladdnum += count($this->PageLinks[$n]);
}
/* -- ANNOTATIONS -- */
if (isset($this->PageAnnots[$n])) {
foreach ($this->PageAnnots[$n] as $k => $pl) {
if (!empty($pl['opt']['popup']) || !empty($pl['opt']
['file'])) {
$totaladdnum += 2;
} else {
$totaladdnum++;
}
}
}
/* -- END ANNOTATIONS -- */
/* -- FORMS -- */
if (count($this->mpdfform->forms) > 0) {
$this->mpdfform->countPageForms($n, $totaladdnum);
}
/* -- END FORMS -- */
}
/* -- FORMS -- */
// Make a note in the radio button group of the obj_id it will have
$ctr = 0;
if (count($this->mpdfform->form_radio_groups)) {
foreach ($this->mpdfform->form_radio_groups AS $name => $frg) {
$this->mpdfform->form_radio_groups[$name]['obj_id'] =
$annotid + $totaladdnum + $ctr;
$ctr++;
}
}
/* -- END FORMS -- */
//Page
$this->_newobj();
$this->_out('<</Type /Page');
$this->_out('/Parent 1 0 R');
if (isset($this->OrientationChanges[$n])) {
$this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]', $hPt,
$wPt));
//If BleedBox is defined, it must be larger than the
TrimBox, but smaller than the MediaBox
$bleedMargin = $this->pageDim[$n]['bleedMargin'] * _MPDFK;
if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
$x0 = $owidthPt_TB - $bleedMargin;
$y0 = $owidthPt_LR - $bleedMargin;
$x1 = $hPt - $owidthPt_TB + $bleedMargin;
$y1 = $wPt - $owidthPt_LR + $bleedMargin;
$this->_out(sprintf('/BleedBox [%.3F %.3F %.3F
%.3F]', $x0, $y0, $x1, $y1));
}
$this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]',
$owidthPt_TB, $owidthPt_LR, ($hPt - $owidthPt_TB), ($wPt - $owidthPt_LR)));
if (isset($this->OrientationChanges[$n]) && $this-
>displayDefaultOrientation) {
if ($this->DefOrientation == 'P') {
$this->_out('/Rotate 270');
} else {
$this->_out('/Rotate 90');
}
}
}
//elseif($wPt != $defwPt || $hPt != $defhPt) {
else {
$this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]', $wPt,
$hPt));
$bleedMargin = $this->pageDim[$n]['bleedMargin'] * _MPDFK;
if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) {
$x0 = $owidthPt_LR - $bleedMargin;
$y0 = $owidthPt_TB - $bleedMargin;
$x1 = $wPt - $owidthPt_LR + $bleedMargin;
$y1 = $hPt - $owidthPt_TB + $bleedMargin;
$this->_out(sprintf('/BleedBox [%.3F %.3F %.3F
%.3F]', $x0, $y0, $x1, $y1));
}
$this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]',
$owidthPt_LR, $owidthPt_TB, ($wPt - $owidthPt_LR), ($hPt - $owidthPt_TB)));
}
$this->_out('/Resources 2 0 R');
$annotsnum = 0;
$embeddedfiles = array(); // mPDF 5.7.2 /EmbeddedFiles
if (isset($this->PageLinks[$n])) {
$annotsnum += count($this->PageLinks[$n]);
}
/* -- ANNOTATIONS -- */
if (isset($this->PageAnnots[$n])) {
foreach ($this->PageAnnots[$n] as $k => $pl) {
if (!empty($pl['opt']['file'])) {
$embeddedfiles[$annotsnum + 1] = true;
} // mPDF 5.7.2 /EmbeddedFiles
if (!empty($pl['opt']['popup']) || !empty($pl['opt']
['file'])) {
$annotsnum += 2;
} else {
$annotsnum++;
}
$this->PageAnnots[$n][$k]['pageobj'] = $this->n;
}
}
/* -- END ANNOTATIONS -- */
/* -- FORMS -- */
// Active Forms
$formsnum = 0;
if (count($this->mpdfform->forms) > 0) {
foreach ($this->mpdfform->forms as $val) {
if ($val['page'] == $n)
$formsnum++;
}
}
/* -- END FORMS -- */
if ($annotsnum || $formsnum) {
$s = '/Annots [ ';
for ($i = 0; $i < $annotsnum; $i++) {
if (!isset($embeddedfiles[$i])) {
$s .= ($annotid + $i) . ' 0 R ';
} // mPDF 5.7.2 /EmbeddedFiles
}
$annotid += $annotsnum;
/* -- FORMS -- */
if (count($this->mpdfform->forms) > 0) {
$this->mpdfform->addFormIds($n, $s, $annotid);
}
/* -- END FORMS -- */
$s .= '] ';
$this->_out($s);
}
//Page content
$this->_newobj();
$p = ($this->compress) ? gzcompress($thispage) : $thispage;
$this->_out('<<' . $filter . '/Length ' . strlen($p) . '>>');
$this->_putstream($p);
$this->_out('endobj');
}
$this->_putannots(); // mPDF 5.7.2
//Pages root
$this->offsets[1] = strlen($this->buffer);
$this->_out('1 0 obj');
$this->_out('<</Type /Pages');
$kids = '/Kids [';
for ($i = 0; $i < $nb; $i++)
$kids.=(3 + 2 * $i) . ' 0 R ';
$this->_out($kids . ']');
$this->_out('/Count ' . $nb);
$this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]', $defwPt, $defhPt));
$this->_out('>>');
$this->_out('endobj');
}
function _putannots()
{ // mPDF 5.7.2
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
$nb = $this->page;
for ($n = 1; $n <= $nb; $n++) {
$annotobjs = array();
if (isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n])
|| count($this->mpdfform->forms) > 0) {
$wPt = $this->pageDim[$n]['w'] * _MPDFK;
$hPt = $this->pageDim[$n]['h'] * _MPDFK;
//Links
if (isset($this->PageLinks[$n])) {
foreach ($this->PageLinks[$n] as $key => $pl) {
$this->_newobj();
$annot = '';
$rect = sprintf('%.3F %.3F %.3F %.3F', $pl[0],
$pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]);
$annot .= '<</Type /Annot /Subtype /Link /Rect
[' . $rect . ']';
$annot .= ' /Contents ' . $this-
>_UTF16BEtextstring($pl[4]);
$annot .= ' /NM ' . $this-
>_textstring(sprintf('%04u-%04u', $n, $key));
$annot .= ' /M ' . $this->_textstring('D:' .
date('YmdHis'));
$annot .= ' /Border [0 0 0]';
// Use this (instead of /Border) to specify
border around link
// $annot .= ' /BS <</W 1'; //
Width on points; 0 = no line
// $annot .= ' /S /D'; //
style - [S]olid, [D]ashed, [B]eveled, [I]nset, [U]nderline
// $annot .= ' /D [3 2]'; //
Dash array - if dashed
// $annot .= ' >>';
// $annot .= ' /C [1 0 0]'; //
Color RGB
if ($this->PDFA || $this->PDFX) {
$annot .= ' /F 28';
}
if (strpos($pl[4], '@') === 0) {
$p = substr($pl[4], 1);
// $h=isset($this-
>OrientationChanges[$p]) ? $wPt : $hPt;
$htarg = $this->pageDim[$p]['h'] *
_MPDFK;
$annot.=sprintf(' /Dest [%d 0 R /XYZ 0
%.3F null]>>', 1 + 2 * $p, $htarg);
} elseif (is_string($pl[4])) {
$annot .= ' /A <</S /URI /URI ' . $this-
>_textstring($pl[4]) . '>> >>';
} else {
$l = $this->links[$pl[4]];
// may not be set if #link points to non-
existent target
if (isset($this->pageDim[$l[0]]['h'])) {
$htarg = $this->pageDim[$l[0]]['h']
* _MPDFK;
} else {
$htarg = $this->h * _MPDFK;
} // doesn't really matter
$annot.=sprintf(' /Dest [%d 0 R /XYZ 0
%.3F null]>>', 1 + 2 * $l[0], $htarg - $l[1] * _MPDFK);
}
$this->_out($annot);
$this->_out('endobj');
}
}
/* -- ANNOTATIONS -- */
if (isset($this->PageAnnots[$n])) {
foreach ($this->PageAnnots[$n] as $key => $pl) {
if ($pl['opt']['file']) {
$FileAttachment = true;
} else {
$FileAttachment = false;
}
$this->_newobj();
$annot = '';
$pl['opt'] = array_change_key_case($pl['opt'],
CASE_LOWER);
$x = $pl['x'];
if ($this->annotMargin <> 0 || $x == 0 || $x <
0) { // Odd page
$x = ($wPt / _MPDFK) - $this-
>annotMargin;
}
$w = $h = 0;
$a = $x * _MPDFK;
$b = $hPt - ($pl['y'] * _MPDFK);
$annot .= '<</Type /Annot ';
if ($FileAttachment) {
$annot .= '/Subtype /FileAttachment ';
// Need to set a size for FileAttachment
icons
if ($pl['opt']['icon'] == 'Paperclip') {
$w = 8.235;
$h = 20;
} // 7,17
elseif ($pl['opt']['icon'] == 'Tag') {
$w = 20;
$h = 16;
} elseif ($pl['opt']['icon'] == 'Graph')
{
$w = 20;
$h = 20;
} else {
$w = 14;
$h = 20;
} // PushPin
$f = $pl['opt']['file'];
$f = preg_replace('/^.*\//', '', $f);
$f = preg_replace('/[^a-zA-Z0-9._]/', '',
$f);
$annot .= '/FS <</Type /Filespec /F (' .
$f . ')';
$annot .= '/EF <</F ' . ($this->n + 1) .
' 0 R>>';
$annot .= '>>';
} else {
$annot .= '/Subtype /Text';
$w = 20;
$h = 20; // mPDF 6
}
$rect = sprintf('%.3F %.3F %.3F %.3F', $a, $b -
$h, $a + $w, $b);
$annot .= ' /Rect [' . $rect . ']';
if ($FileAttachment) {
$file = @file_get_contents($pl['opt']
['file']);
if (!$file) {
throw new MpdfException('mPDF
Error: Cannot access file attachment - ' . $pl['opt']['file']);
}
$filestream = gzcompress($file);
$this->_newobj();
$this->_out('<</Type /EmbeddedFile');
$this->_out('/Length ' .
strlen($filestream));
$this->_out('/Filter /FlateDecode');
$this->_out('>>');
$this->_putstream($filestream);
$this->_out('endobj');
} elseif (!empty($pl['opt']['popup'])) {
$this->_newobj();
$annot = '';
if (is_array($pl['opt']['popup']) &&
isset($pl['opt']['popup'][0])) {
$x = $pl['opt']['popup'][0] *
_MPDFK;
} else {
$x = $pl['x'] * _MPDFK;
}
if (is_array($pl['opt']['popup']) &&
isset($pl['opt']['popup'][1])) {
$y = $hPt - ($pl['opt']['popup'][1]
* _MPDFK);
} else {
$y = $hPt - ($pl['y'] * _MPDFK);
}
if (is_array($pl['opt']['popup']) &&
isset($pl['opt']['popup'][2])) {
$w = $pl['opt']['popup'][2] *
_MPDFK;
} else {
$w = 180;
}
if (is_array($pl['opt']['popup']) &&
isset($pl['opt']['popup'][3])) {
$h = $pl['opt']['popup'][3] *
_MPDFK;
} else {
$h = 120;
}
$rect = sprintf('%.3F %.3F %.3F %.3F',
$x, $y - $h, $x + $w, $y);
$annot .= '<</Type /Annot /Subtype /Popup
/Rect [' . $rect . ']';
$annot .= ' /M ' . $this-
>_textstring('D:' . date('YmdHis'));
if ($this->PDFA || $this->PDFX) {
$annot .= ' /F 28';
}
$annot .= ' /Parent ' . ($this->n - 1) .
' 0 R';
$annot .= '>>';
$this->_out($annot);
$this->_out('endobj');
}
}
}
/* -- END ANNOTATIONS -- */
/* -- FORMS -- */
// Active Forms
if (count($this->mpdfform->forms) > 0) {
$this->mpdfform->_putFormItems($n, $hPt);
}
/* -- END FORMS -- */
}
}
/* -- FORMS -- */
// Active Forms - Radio Button Group entries
// Output Radio Button Group form entries (radio_on_obj_id already
determined)
if (count($this->mpdfform->form_radio_groups)) {
$this->mpdfform->_putRadioItems($n);
}
/* -- END FORMS -- */
}
/* -- ANNOTATIONS -- */
if ($this->PDFA || $this->PDFX) {
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)";
}
$x = ($this->w) - $this->rMargin * 0.66;
}
if (!$this->annotMargin) {
$y -= $this->FontSize / 2;
}
$an = array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'
=> $icon, 'T' => $author, 'Subj' => $subject, 'C' => $colarray, 'CA' => $opacity,
'popup' => $popup, 'file' => $file));
function _putfonts()
{
$nf = $this->n;
foreach ($this->FontFiles as $fontkey => $info) {
// TrueType embedded
if (isset($info['type']) && $info['type'] == 'TTF' && !
$info['sip'] && !$info['smp']) {
$used = true;
$asSubset = false;
foreach ($this->fonts AS $k => $f) {
if (isset($f['fontkey']) && $f['fontkey'] == $fontkey
&& $f['type'] == 'TTF') {
$used = $f['used'];
if ($used) {
$nChars = (ord($f['cw'][0]) << 8) +
ord($f['cw'][1]);
$usage = intval(count($f['subset']) * 100
/ $nChars);
$fsize = $info['length1'];
// Always subset the very large TTF files
if ($fsize > ($this->maxTTFFilesize *
1024)) {
$asSubset = true;
} elseif ($usage < $this->percentSubset)
{
$asSubset = true;
}
}
if ($this->PDFA || $this->PDFX)
$asSubset = false;
$this->fonts[$k]['asSubset'] = $asSubset;
break;
}
}
if ($used && !$asSubset) {
//Font file embedding
$this->_newobj();
$this->FontFiles[$fontkey]['n'] = $this->n;
$font = '';
$originalsize = $info['length1'];
if ($this->repackageTTF || $this->fonts[$fontkey]
['TTCfontID'] > 0 || $this->fonts[$fontkey]['useOTL'] > 0) { // mPDF 5.7.1
// First see if there is a cached compressed
file
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey
. '.ps.z')) {
$f = fopen(_MPDF_TTFONTDATAPATH .
$fontkey . '.ps.z', 'rb');
if (!$f) {
throw new MpdfException('Font
file .ps.z not found');
}
while (!feof($f)) {
$font .= fread($f, 2048);
}
fclose($f);
include(_MPDF_TTFONTDATAPATH . $fontkey .
'.ps.php'); // sets $originalsize (of repackaged font)
} else {
if (!class_exists('TTFontFile', false)) {
include(_MPDF_PATH .
'classes/ttfontsuni.php');
}
$ttf = new TTFontFile();
$font = $ttf->repackageTTF($this-
>FontFiles[$fontkey]['ttffile'], $this->fonts[$fontkey]['TTCfontID'], $this-
>debugfonts, $this->fonts[$fontkey]['useOTL']); // mPDF 5.7.1
$originalsize = strlen($font);
$font = gzcompress($font);
unset($ttf);
if
(is_writable(dirname(_MPDF_TTFONTDATAPATH . 'x'))) {
$fh = fopen(_MPDF_TTFONTDATAPATH .
$fontkey . '.ps.z', "wb");
fwrite($fh, $font, strlen($font));
fclose($fh);
$fh = fopen(_MPDF_TTFONTDATAPATH .
$fontkey . '.ps.php', "wb");
$len = "<?php \n";
$len.='$originalsize=' .
$originalsize . ";\n";
$len.="?>";
fwrite($fh, $len, strlen($len));
fclose($fh);
}
}
} else {
// First see if there is a cached compressed
file
if (file_exists(_MPDF_TTFONTDATAPATH . $fontkey
. '.z')) {
$f = fopen(_MPDF_TTFONTDATAPATH .
$fontkey . '.z', 'rb');
if (!$f) {
throw new MpdfException('Font file
not found');
}
while (!feof($f)) {
$font .= fread($f, 2048);
}
fclose($f);
} else {
$f = fopen($this->FontFiles[$fontkey]
['ttffile'], 'rb');
if (!$f) {
throw new MpdfException('Font file
not found');
}
while (!feof($f)) {
$font .= fread($f, 2048);
}
fclose($f);
$font = gzcompress($font);
if
(is_writable(dirname(_MPDF_TTFONTDATAPATH . 'x'))) {
$fh = fopen(_MPDF_TTFONTDATAPATH .
$fontkey . '.z', "wb");
fwrite($fh, $font, strlen($font));
fclose($fh);
}
}
}
$nfonts = count($this->fonts);
$fctr = 1;
foreach ($this->fonts as $k => $font) {
//Font objects
$type = $font['type'];
$name = $font['name'];
if ((!isset($font['used']) || !$font['used']) && $type == 'TTF')
{
continue;
}
if ($this->progressBar) {
$this->UpdateProgressBar(2, intval($fctr * 100 / $nfonts),
'Writing Fonts');
$fctr++;
} // *PROGRESS-BAR*
if (isset($font['asSubset'])) {
$asSubset = $font['asSubset'];
} else {
$asSubset = '';
}
/* -- CJK-FONTS -- */
if ($type == 'Type0') { // = Adobe CJK Fonts
$this->fonts[$k]['n'] = $this->n + 1;
$this->_newobj();
$this->_out('<</Type /Font');
$this->_putType0($font);
} else
/* -- END CJK-FONTS -- */
if ($type == 'core') {
//Standard font
$this->fonts[$k]['n'] = $this->n + 1;
if ($this->PDFA || $this->PDFX) {
throw new MpdfException('Core fonts are not allowed
in PDF/A1-b or PDFX/1-a files (Times, Helvetica, Courier etc.)');
}
$this->_newobj();
$this->_out('<</Type /Font');
$this->_out('/BaseFont /' . $name);
$this->_out('/Subtype /Type1');
if ($name != 'Symbol' && $name != 'ZapfDingbats') {
$this->_out('/Encoding /WinAnsiEncoding');
}
$this->_out('>>');
$this->_out('endobj');
}
// TrueType embedded SUBSETS for SIP (CJK extB containing
Supplementary Ideographic Plane 2)
// Or Unicode Plane 1 - Supplementary Multilingual Plane
elseif ($type == 'TTF' && ($font['sip'] || $font['smp'])) {
if (!$font['used']) {
continue;
}
$ssfaid = "AA";
if (!class_exists('TTFontFile', false)) {
include(_MPDF_PATH . 'classes/ttfontsuni.php');
}
$ttf = new TTFontFile();
for ($sfid = 0; $sfid < count($font['subsetfontids']);
$sfid++) {
$this->fonts[$k]['n'][$sfid] = $this->n + 1; // NB
an array for subset
$subsetname = 'MPDF' . $ssfaid . '+' . $font['name'];
$ssfaid++;
$subset = $font['subsets'][$sfid];
unset($subset[0]);
$ttfontstream = $ttf->makeSubsetSIP($font['ttffile'],
$subset, $font['TTCfontID'], $this->debugfonts, $font['useOTL']); // mPDF 5.7.1
$ttfontsize = strlen($ttfontstream);
$fontstream = gzcompress($ttfontstream);
$widthstring = '';
$toUnistring = '';
//Widths
$this->_newobj();
$this->_out('[' . $widthstring . ']');
$this->_out('endobj');
//Descriptor
$this->_newobj();
$s = '<</Type /FontDescriptor /FontName /' .
$subsetname . "\n";
foreach ($font['desc'] as $kd => $v) {
if ($kd == 'Flags') {
$v = $v | 4;
$v = $v & ~32;
} // SYMBOLIC font flag
$s.=' /' . $kd . ' ' . $v . "\n";
}
$s.='/FontFile2 ' . ($this->n + 2) . ' 0 R';
$this->_out($s . '>>');
$this->_out('endobj');
// ToUnicode
$this->_newobj();
$toUni = "/CIDInit /ProcSet findresource begin\n";
$toUni .= "12 dict begin\n";
$toUni .= "begincmap\n";
$toUni .= "/CIDSystemInfo\n";
$toUni .= "<</Registry (Adobe)\n";
$toUni .= "/Ordering (UCS)\n";
$toUni .= "/Supplement 0\n";
$toUni .= ">> def\n";
$toUni .= "/CMapName /Adobe-Identity-UCS def\n";
$toUni .= "/CMapType 2 def\n";
$toUni .= "1 begincodespacerange\n";
$toUni .= "<00> <FF>\n";
//$toUni .= sprintf("<00> <%02s>\n",
strtoupper(dechex(count($font['subsets'][$sfid])-1)));
$toUni .= "endcodespacerange\n";
$toUni .= count($font['subsets'][$sfid]) . "
beginbfchar\n";
$toUni .= $toUnistring;
$toUni .= "endbfchar\n";
$toUni .= "endcmap\n";
$toUni .= "CMapName currentdict /CMap defineresource
pop\n";
$toUni .= "end\n";
$toUni .= "end\n";
$this->_out('<</Length ' . (strlen($toUni)) . '>>');
$this->_putstream($toUni);
$this->_out('endobj');
//Font file
$this->_newobj();
$this->_out('<</Length ' . strlen($fontstream));
$this->_out('/Filter /FlateDecode');
$this->_out('/Length1 ' . $ttfontsize);
$this->_out('>>');
$this->_putstream($fontstream);
$this->_out('endobj');
} // foreach subset
unset($ttf);
}
// TrueType embedded SUBSETS or FULL
elseif ($type == 'TTF') {
$this->fonts[$k]['n'] = $this->n + 1;
if ($asSubset) {
$ssfaid = "A";
if (!class_exists('TTFontFile', false)) {
include(_MPDF_PATH . 'classes/ttfontsuni.php');
}
$ttf = new TTFontFile();
$fontname = 'MPDFA' . $ssfaid . '+' . $font['name'];
$subset = $font['subset'];
unset($subset[0]);
$ttfontstream = $ttf->makeSubset($font['ttffile'],
$subset, $font['TTCfontID'], $this->debugfonts, $font['useOTL']);
$ttfontsize = strlen($ttfontstream);
$fontstream = gzcompress($ttfontstream);
$codeToGlyph = $ttf->codeToGlyph;
unset($codeToGlyph[0]);
} else {
$fontname = $font['name'];
}
// Type0 Font
// A composite font - a font composed of other fonts,
organized hierarchically
$this->_newobj();
$this->_out('<</Type /Font');
$this->_out('/Subtype /Type0');
$this->_out('/BaseFont /' . $fontname . '');
$this->_out('/Encoding /Identity-H');
$this->_out('/DescendantFonts [' . ($this->n + 1) . ' 0
R]');
$this->_out('/ToUnicode ' . ($this->n + 2) . ' 0 R');
$this->_out('>>');
$this->_out('endobj');
// CIDFontType2
// A CIDFont whose glyph descriptions are based on TrueType
font technology
$this->_newobj();
$this->_out('<</Type /Font');
$this->_out('/Subtype /CIDFontType2');
$this->_out('/BaseFont /' . $fontname . '');
$this->_out('/CIDSystemInfo ' . ($this->n + 2) . ' 0 R');
$this->_out('/FontDescriptor ' . ($this->n + 3) . ' 0 R');
if (isset($font['desc']['MissingWidth'])) {
$this->_out('/DW ' . $font['desc']['MissingWidth'] .
'');
}
// ToUnicode
$this->_newobj();
$toUni = "/CIDInit /ProcSet findresource begin\n";
$toUni .= "12 dict begin\n";
$toUni .= "begincmap\n";
$toUni .= "/CIDSystemInfo\n";
$toUni .= "<</Registry (Adobe)\n";
$toUni .= "/Ordering (UCS)\n";
$toUni .= "/Supplement 0\n";
$toUni .= ">> def\n";
$toUni .= "/CMapName /Adobe-Identity-UCS def\n";
$toUni .= "/CMapType 2 def\n";
$toUni .= "1 begincodespacerange\n";
$toUni .= "<0000> <FFFF>\n";
$toUni .= "endcodespacerange\n";
$toUni .= "1 beginbfrange\n";
$toUni .= "<0000> <FFFF> <0000>\n";
$toUni .= "endbfrange\n";
$toUni .= "endcmap\n";
$toUni .= "CMapName currentdict /CMap defineresource
pop\n";
$toUni .= "end\n";
$toUni .= "end\n";
$this->_out('<</Length ' . (strlen($toUni)) . '>>');
$this->_putstream($toUni);
$this->_out('endobj');
// CIDSystemInfo dictionary
$this->_newobj();
$this->_out('<</Registry (Adobe)');
$this->_out('/Ordering (UCS)');
$this->_out('/Supplement 0');
$this->_out('>>');
$this->_out('endobj');
// Font descriptor
$this->_newobj();
$this->_out('<</Type /FontDescriptor');
$this->_out('/FontName /' . $fontname);
foreach ($font['desc'] as $kd => $v) {
if ($asSubset && $kd == 'Flags') {
$v = $v | 4;
$v = $v & ~32;
} // SYMBOLIC font flag
$this->_out(' /' . $kd . ' ' . $v);
}
if ($font['panose']) {
$this->_out(' /Style << /Panose <' .
$font['panose'] . '> >>');
}
if ($asSubset) {
$this->_out('/FontFile2 ' . ($this->n + 2) . ' 0 R');
} elseif ($font['fontkey']) {
// obj ID of a stream containing a TrueType font
program
$this->_out('/FontFile2 ' . $this-
>FontFiles[$font['fontkey']]['n'] . ' 0 R');
}
$this->_out('>>');
$this->_out('endobj');
// Embed CIDToGIDMap
// A specification of the mapping from CIDs to glyph
indices
if ($asSubset) {
$cidtogidmap = '';
$cidtogidmap = str_pad('', 256 * 256 * 2, "\x00");
foreach ($codeToGlyph as $cc => $glyph) {
$cidtogidmap[$cc * 2] = chr($glyph >> 8);
$cidtogidmap[$cc * 2 + 1] = chr($glyph & 0xFF);
}
$cidtogidmap = gzcompress($cidtogidmap);
} else {
// First see if there is a cached CIDToGIDMapfile
$cidtogidmap = '';
if (file_exists(_MPDF_TTFONTDATAPATH .
$font['fontkey'] . '.cgm')) {
$f = fopen(_MPDF_TTFONTDATAPATH .
$font['fontkey'] . '.cgm', 'rb');
while (!feof($f)) {
$cidtogidmap .= fread($f, 2048);
}
fclose($f);
} else {
if (!class_exists('TTFontFile', false)) {
include(_MPDF_PATH .
'classes/ttfontsuni.php');
}
$ttf = new TTFontFile();
$charToGlyph = $ttf->getCTG($font['ttffile'],
$font['TTCfontID'], $this->debugfonts, $font['useOTL']);
$cidtogidmap = str_pad('', 256 * 256 * 2,
"\x00");
foreach ($charToGlyph as $cc => $glyph) {
$cidtogidmap[$cc * 2] = chr($glyph >> 8);
$cidtogidmap[$cc * 2 + 1] = chr($glyph &
0xFF);
}
unset($ttf);
$cidtogidmap = gzcompress($cidtogidmap);
if (is_writable(dirname(_MPDF_TTFONTDATAPATH .
'x'))) {
$fh = fopen(_MPDF_TTFONTDATAPATH .
$font['fontkey'] . '.cgm', "wb");
fwrite($fh, $cidtogidmap,
strlen($cidtogidmap));
fclose($fh);
}
}
}
$this->_newobj();
$this->_out('<</Length ' . strlen($cidtogidmap) . '');
$this->_out('/Filter /FlateDecode');
$this->_out('>>');
$this->_putstream($cidtogidmap);
$this->_out('endobj');
//Font file
if ($asSubset) {
$this->_newobj();
$this->_out('<</Length ' . strlen($fontstream));
$this->_out('/Filter /FlateDecode');
$this->_out('/Length1 ' . $ttfontsize);
$this->_out('>>');
$this->_putstream($fontstream);
$this->_out('endobj');
unset($ttf);
}
} else {
throw new MpdfException('Unsupported font type: ' . $type .
' (' . $name . ')');
}
}
}
function _putfontranges(&$range)
{
// optimize ranges
$prevk = -1;
$nextk = -1;
$prevint = false;
foreach ($range as $k => $ws) {
$cws = count($ws);
if (($k == $nextk) AND ( !$prevint) AND ( (!
isset($ws['interval'])) OR ( $cws < 4))) {
if (isset($range[$k]['interval'])) {
unset($range[$k]['interval']);
}
$range[$prevk] = array_merge($range[$prevk], $range[$k]);
unset($range[$k]);
} else {
$prevk = $k;
}
$nextk = $k + $cws;
if (isset($ws['interval'])) {
if ($cws > 3) {
$prevint = true;
} else {
$prevint = false;
}
unset($range[$k]['interval']);
--$nextk;
} else {
$prevint = false;
}
}
// output data
$w = '';
foreach ($range as $k => $ws) {
if (count(array_count_values($ws)) == 1) {
// interval mode is more compact
$w .= ' ' . $k . ' ' . ($k + count($ws) - 1) . ' ' .
$ws[0];
} else {
// range mode
$w .= ' ' . $k . ' [ ' . implode(' ', $ws) . ' ]' . "\n";
}
}
return '/W [' . $w . ' ]';
}
/* -- CJK-FONTS -- */
//Font descriptor
$this->_newobj();
$s = '<</Type /FontDescriptor /FontName /' . $font['name'];
foreach ($font['desc'] as $k => $v) {
if ($k != 'Style') {
$s .= ' /' . $k . ' ' . $v . '';
}
}
$this->_out($s . '>>');
$this->_out('endobj');
}
/* -- END CJK-FONTS -- */
function _putimages()
{
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
reset($this->images);
while (list($file, $info) = each($this->images)) {
$this->_newobj();
$this->images[$file]['n'] = $this->n;
$this->_out('<</Type /XObject');
$this->_out('/Subtype /Image');
$this->_out('/Width ' . $info['w']);
$this->_out('/Height ' . $info['h']);
if (isset($info['interpolation']) && $info['interpolation']) {
$this->_out('/Interpolate true'); // mPDF 6 - image
interpolation shall be performed by a conforming reader
}
if (isset($info['masked'])) {
$this->_out('/SMask ' . ($this->n - 1) . ' 0 R');
}
// set color space
$icc = false;
if (isset($info['icc']) AND ( $info['icc'] !== false)) {
// ICC Colour Space
$icc = true;
$this->_out('/ColorSpace [/ICCBased ' . ($this->n + 1) . '
0 R]');
} elseif ($info['cs'] == 'Indexed') {
if ($this->PDFX || ($this->PDFA && $this-
>restrictColorSpace == 3)) {
throw new MpdfException("PDFA1-b and PDFX/1-a files
do not permit using mixed colour space (" . $file . ").");
}
$this->_out('/ColorSpace [/Indexed /DeviceRGB ' .
(strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]');
} else {
$this->_out('/ColorSpace /' . $info['cs']);
if ($info['cs'] == 'DeviceCMYK') {
if ($this->PDFA && $this->restrictColorSpace != 3) {
throw new MpdfException("PDFA1-b does not
permit Images using mixed colour space (" . $file . ").");
}
if ($info['type'] == 'jpg') {
$this->_out('/Decode [1 0 1 0 1 0 1 0]');
}
} elseif ($info['cs'] == 'DeviceRGB' && ($this->PDFX ||
($this->PDFA && $this->restrictColorSpace == 3))) {
throw new MpdfException("PDFA1-b and PDFX/1-a files
do not permit using mixed colour space (" . $file . ").");
}
}
$this->_out('/BitsPerComponent ' . $info['bpc']);
if (isset($info['f']) && $info['f']) {
$this->_out('/Filter /' . $info['f']);
}
if (isset($info['parms'])) {
$this->_out($info['parms']);
}
if (isset($info['trns']) and is_array($info['trns'])) {
$trns = '';
for ($i = 0; $i < count($info['trns']); $i++)
$trns.=$info['trns'][$i] . ' ' . $info['trns'][$i] .
' ';
$this->_out('/Mask [' . $trns . ']');
}
$this->_out('/Length ' . strlen($info['data']) . '>>');
$this->_putstream($info['data']);
unset($this->images[$file]['data']);
$this->_out('endobj');
function _putinfo()
{
$this->_out('/Producer ' . $this->_UTF16BEtextstring('mPDF ' .
mPDF_VERSION));
if (!empty($this->title))
$this->_out('/Title ' . $this->_UTF16BEtextstring($this->title));
if (!empty($this->subject))
$this->_out('/Subject ' . $this->_UTF16BEtextstring($this-
>subject));
if (!empty($this->author))
$this->_out('/Author ' . $this->_UTF16BEtextstring($this-
>author));
if (!empty($this->keywords))
$this->_out('/Keywords ' . $this->_UTF16BEtextstring($this-
>keywords));
if (!empty($this->creator))
$this->_out('/Creator ' . $this->_UTF16BEtextstring($this-
>creator));
$z = date('O'); // +0200
$offset = substr($z, 0, 3) . "'" . substr($z, 3, 2) . "'";
$this->_out('/CreationDate ' . $this->_textstring(date('YmdHis') .
$offset));
$this->_out('/ModDate ' . $this->_textstring(date('YmdHis') .
$offset));
if ($this->PDFX) {
$this->_out('/Trapped/False');
$this->_out('/GTS_PDFXVersion(PDF/X-1a:2003)');
}
}
function _putmetadata()
{
$this->_newobj();
$this->MetadataRoot = $this->n;
$Producer = 'mPDF ' . mPDF_VERSION;
$z = date('O'); // +0200
$offset = substr($z, 0, 3) . ':' . substr($z, 3, 2);
$CreationDate = date('Y-m-d\TH:i:s') . $offset; // 2006-03-10T10:47:26-
05:00 2006-06-19T09:05:17Z
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0,
0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0,
0xffff));
// DC elements
$m .= ' <rdf:Description rdf:about="uuid:' . $uuid . '"
xmlns:dc="http://purl.org/dc/elements/1.1/">' . "\n";
$m .= ' <dc:format>application/pdf</dc:format>' . "\n";
if (!empty($this->title)) {
$m .= ' <dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">' . $this->title . '</rdf:li>
</rdf:Alt>
</dc:title>' . "\n";
}
if (!empty($this->keywords)) {
$m .= ' <dc:subject>
<rdf:Bag>
<rdf:li>' . $this->keywords . '</rdf:li>
</rdf:Bag>
</dc:subject>' . "\n";
}
if (!empty($this->subject)) {
$m .= ' <dc:description>
<rdf:Alt>
<rdf:li xml:lang="x-default">' . $this->subject . '</rdf:li>
</rdf:Alt>
</dc:description>' . "\n";
}
if (!empty($this->author)) {
$m .= ' <dc:creator>
<rdf:Seq>
<rdf:li>' . $this->author . '</rdf:li>
</rdf:Seq>
</dc:creator>' . "\n";
}
$m .= ' </rdf:Description>' . "\n";
function _putoutputintent()
{
$this->_newobj();
$this->OutputIntentRoot = $this->n;
$this->_out('<</Type /OutputIntent');
if ($this->PDFA) {
$this->_out('/S /GTS_PDFA1');
if ($this->ICCProfile) {
$this->_out('/Info (' . preg_replace('/_/', ' ', $this-
>ICCProfile) . ')');
$this->_out('/OutputConditionIdentifier (Custom)');
$this->_out('/OutputCondition ()');
} else {
$this->_out('/Info (sRGB IEC61966-2.1)');
$this->_out('/OutputConditionIdentifier (sRGB IEC61966-
2.1)');
$this->_out('/OutputCondition ()');
}
$this->_out('/DestOutputProfile ' . ($this->n + 1) . ' 0 R');
} elseif ($this->PDFX) { // always a CMYK profile
$this->_out('/S /GTS_PDFX');
if ($this->ICCProfile) {
$this->_out('/Info (' . preg_replace('/_/', ' ', $this-
>ICCProfile) . ')');
$this->_out('/OutputConditionIdentifier (Custom)');
$this->_out('/OutputCondition ()');
$this->_out('/DestOutputProfile ' . ($this->n + 1) . ' 0
R');
} else {
$this->_out('/Info (CGATS TR 001)');
$this->_out('/OutputConditionIdentifier (CGATS TR 001)');
$this->_out('/OutputCondition (CGATS TR 001 (SWOP))');
$this->_out('/RegistryName (http://www.color.org)');
}
}
$this->_out('>>');
$this->_out('endobj');
$this->_newobj();
if ($this->ICCProfile)
$s = file_get_contents(_MPDF_PATH . 'iccprofiles/' . $this-
>ICCProfile . '.icc');
else
$s = file_get_contents(_MPDF_PATH . 'iccprofiles/sRGB_IEC61966-2-
1.icc');
if ($this->compress) {
$s = gzcompress($s);
}
$this->_out('<<');
if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace == 3)) {
$this->_out('/N 4');
} else {
$this->_out('/N 3');
}
if ($this->compress)
$this->_out('/Filter /FlateDecode ');
$this->_out('/Length ' . strlen($s) . '>>');
$this->_putstream($s);
$this->_out('endobj');
}
function _putcatalog()
{
$this->_out('/Type /Catalog');
$this->_out('/Pages 1 0 R');
if ($this->ZoomMode == 'fullpage')
$this->_out('/OpenAction [3 0 R /Fit]');
elseif ($this->ZoomMode == 'fullwidth')
$this->_out('/OpenAction [3 0 R /FitH null]');
elseif ($this->ZoomMode == 'real')
$this->_out('/OpenAction [3 0 R /XYZ null null 1]');
elseif (!is_string($this->ZoomMode))
$this->_out('/OpenAction [3 0 R /XYZ null null ' . ($this-
>ZoomMode / 100) . ']');
else
$this->_out('/OpenAction [3 0 R /XYZ null null null]');
if ($this->LayoutMode == 'single')
$this->_out('/PageLayout /SinglePage');
elseif ($this->LayoutMode == 'continuous')
$this->_out('/PageLayout /OneColumn');
elseif ($this->LayoutMode == 'twoleft')
$this->_out('/PageLayout /TwoColumnLeft');
elseif ($this->LayoutMode == 'tworight')
$this->_out('/PageLayout /TwoColumnRight');
elseif ($this->LayoutMode == 'two') {
if ($this->mirrorMargins) {
$this->_out('/PageLayout /TwoColumnRight');
} else {
$this->_out('/PageLayout /TwoColumnLeft');
}
}
/* -- BOOKMARKS -- */
if (count($this->BMoutlines) > 0) {
$this->_out('/Outlines ' . $this->OutlineRoot . ' 0 R');
$this->_out('/PageMode /UseOutlines');
}
/* -- END BOOKMARKS -- */
if (is_int(strpos($this->DisplayPreferences, 'FullScreen')))
$this->_out('/PageMode /FullScreen');
// Metadata
if ($this->PDFA || $this->PDFX) {
$this->_out('/Metadata ' . $this->MetadataRoot . ' 0 R');
}
// OutputIntents
if ($this->PDFA || $this->PDFX || $this->ICCProfile) {
$this->_out('/OutputIntents [' . $this->OutputIntentRoot . ' 0
R]');
}
/* -- FORMS -- */
if (count($this->mpdfform->forms) > 0) {
$this->mpdfform->_putFormsCatalog();
}
/* -- END FORMS -- */
if (isset($this->js)) {
$this->_out('/Names << /JavaScript ' . ($this->n_js) . ' 0 R >>
');
}
if ($this->hasOC || count($this->layers)) {
$p = $v = $h = $l = $loff = $lall = $as = '';
if ($this->hasOC) {
if (($this->hasOC & 1) == 1)
$p = $this->n_ocg_print . ' 0 R';
if (($this->hasOC & 2) == 2)
$v = $this->n_ocg_view . ' 0 R';
if (($this->hasOC & 4) == 4)
$h = $this->n_ocg_hidden . ' 0 R';
$as = "<</Event /Print /OCGs [$p $v $h] /Category
[/Print]>> <</Event /View /OCGs [$p $v $h] /Category [/View]>>";
}
if (count($this->layers)) {
foreach ($this->layers as $k => $layer) {
if (strtolower($this->layerDetails[$k]['state']) ==
'hidden') {
$loff .= $layer['n'] . ' 0 R ';
} else {
$l .= $layer['n'] . ' 0 R ';
}
$lall .= $layer['n'] . ' 0 R ';
}
}
$this->_out("/OCProperties <</OCGs [$p $v $h $lall] /D <</ON [$p
$l] /OFF [$v $h $loff] ");
$this->_out("/Order [$v $p $h $lall] ");
if ($as)
$this->_out("/AS [$as] ");
$this->_out(">>>>");
}
}
function _enddoc()
{
if ($this->progressBar) {
$this->UpdateProgressBar(2, '10', 'Writing Headers & Footers');
} // *PROGRESS-BAR*
$this->_puthtmlheaders();
if ($this->progressBar) {
$this->UpdateProgressBar(2, '20', 'Writing Pages');
} // *PROGRESS-BAR*
// Remove references to unused fonts (usually default font)
foreach ($this->fonts as $fk => $font) {
if (isset($font['type']) && $font['type'] == 'TTF' && !
$font['used']) {
if ($font['sip'] || $font['smp']) {
foreach ($font['subsetfontids'] AS $k => $fid) {
foreach ($this->pages AS $pn => $page) {
$this->pages[$pn] = preg_replace('/\s\/F'
. $fid . ' \d[\d.]* Tf\s/is', ' ', $this->pages[$pn]);
}
}
} else {
foreach ($this->pages AS $pn => $page) {
$this->pages[$pn] = preg_replace('/\s\/F' .
$font['i'] . ' \d[\d.]* Tf\s/is', ' ', $this->pages[$pn]);
}
}
}
}
if (count($this->layers)) {
foreach ($this->pages AS $pn => $page) {
preg_match_all('/\/OCZ-index \/ZI(\d+) BDC(.*?)(EMCZ)-
index/is', $this->pages[$pn], $m1);
preg_match_all('/\/OCBZ-index \/ZI(\d+) BDC(.*?)(EMCBZ)-
index/is', $this->pages[$pn], $m2);
preg_match_all('/\/OCGZ-index \/ZI(\d+) BDC(.*?)(EMCGZ)-
index/is', $this->pages[$pn], $m3);
$m = array();
for ($i = 0; $i < 4; $i++) {
$m[$i] = array_merge($m1[$i], $m2[$i], $m3[$i]);
}
if (count($m[0])) {
$sortarr = array();
for ($i = 0; $i < count($m[0]); $i++) {
$key = $m[1][$i] * 2;
if ($m[3][$i] == 'EMCZ')
$key +=2; // background first then
gradient then normal
elseif ($m[3][$i] == 'EMCGZ')
$key +=1;
$sortarr[$i] = $key;
}
asort($sortarr);
foreach ($sortarr AS $i => $k) {
$this->pages[$pn] = str_replace($m[0][$i], '',
$this->pages[$pn]);
$this->pages[$pn] .= "\n" . $m[0][$i] . "\n";
}
$this->pages[$pn] = preg_replace('/\/OC[BG]{0,1}Z-
index \/ZI(\d+) BDC/is', '/OC /ZI\\1 BDC ', $this->pages[$pn]);
$this->pages[$pn] = preg_replace('/EMC[BG]{0,1}Z-
index/is', 'EMC', $this->pages[$pn]);
}
}
}
$this->_putpages();
if ($this->progressBar) {
$this->UpdateProgressBar(2, '30', 'Writing document resources');
} // *PROGRESS-BAR*
$this->_putresources();
//Info
$this->_newobj();
$this->InfoRoot = $this->n;
$this->_out('<<');
if ($this->progressBar) {
$this->UpdateProgressBar(2, '80', 'Writing document info');
} // *PROGRESS-BAR*
$this->_putinfo();
$this->_out('>>');
$this->_out('endobj');
// METADATA
if ($this->PDFA || $this->PDFX) {
$this->_putmetadata();
}
// OUTPUTINTENT
if ($this->PDFA || $this->PDFX || $this->ICCProfile) {
$this->_putoutputintent();
}
//Catalog
$this->_newobj();
$this->_out('<<');
if ($this->progressBar) {
$this->UpdateProgressBar(2, '90', 'Writing document catalog');
} // *PROGRESS-BAR*
$this->_putcatalog();
$this->_out('>>');
$this->_out('endobj');
//Cross-ref
$o = strlen($this->buffer);
$this->_out('xref');
$this->_out('0 ' . ($this->n + 1));
$this->_out('0000000000 65535 f ');
for ($i = 1; $i <= $this->n; $i++)
$this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
//Trailer
$this->_out('trailer');
$this->_out('<<');
$this->_puttrailer();
$this->_out('>>');
$this->_out('startxref');
$this->_out($o);
$this->buffer .= '%%EOF';
$this->state = 3;
/* -- IMPORTS -- */
function _beginpage($orientation, $mgl = '', $mgr = '', $mgt = '', $mgb = '',
$mgh = '', $mgf = '', $ohname = '', $ehname = '', $ofname = '', $efname = '',
$ohvalue = 0, $ehvalue = 0, $ofvalue = 0, $efvalue = 0, $pagesel = '', $newformat =
'')
{
if (!($pagesel && $this->page == 1 && (sprintf("%0.4f", $this->y) ==
sprintf("%0.4f", $this->tMargin)))) {
$this->page++;
$this->pages[$this->page] = '';
}
$this->state = 2;
$resetHTMLHeadersrequired = false;
if ($newformat) {
$this->_setPageSize($newformat, $orientation);
}
/* -- CSS-PAGE -- */
// Paged media (page-box)
if ($pagesel || (isset($this->page_box['using']) && $this-
>page_box['using'])) {
if ($pagesel || $this->page == 1) {
$first = true;
} else {
$first = false;
}
if ($this->mirrorMargins && ($this->page % 2 == 0)) {
$oddEven = 'E';
} else {
$oddEven = 'O';
}
if ($pagesel) {
$psel = $pagesel;
} elseif ($this->page_box['current']) {
$psel = $this->page_box['current'];
} else {
$psel = '';
}
list($orientation, $mgl, $mgr, $mgt, $mgb, $mgh, $mgf, $hname,
$fname, $bg, $resetpagenum, $pagenumstyle, $suppress, $marks, $newformat) = $this-
>SetPagedMediaCSS($psel, $first, $oddEven);
if ($this->mirrorMargins && ($this->page % 2 == 0)) {
if ($hname) {
$ehvalue = 1;
$ehname = $hname;
} else {
$ehvalue = -1;
}
if ($fname) {
$efvalue = 1;
$efname = $fname;
} else {
$efvalue = -1;
}
} else {
if ($hname) {
$ohvalue = 1;
$ohname = $hname;
} else {
$ohvalue = -1;
}
if ($fname) {
$ofvalue = 1;
$ofname = $fname;
} else {
$ofvalue = -1;
}
}
if ($resetpagenum || $pagenumstyle || $suppress) {
$this->PageNumSubstitutions[] = array('from' => ($this-
>page), 'reset' => $resetpagenum, 'type' => $pagenumstyle, 'suppress' =>
$suppress);
}
// PAGED MEDIA - CROP / CROSS MARKS from @PAGE
$this->show_marks = $marks;
// Background color
if (isset($bg['BACKGROUND-COLOR'])) {
$cor = $this->ConvertColor($bg['BACKGROUND-COLOR']);
if ($cor) {
$this->bodyBackgroundColor = $cor;
}
} else {
$this->bodyBackgroundColor = false;
}
/* -- BACKGROUNDS -- */
if (isset($bg['BACKGROUND-GRADIENT'])) {
$this->bodyBackgroundGradient = $bg['BACKGROUND-GRADIENT'];
} else {
$this->bodyBackgroundGradient = false;
}
// Tiling Patterns
if (isset($bg['BACKGROUND-IMAGE']) && $bg['BACKGROUND-IMAGE']) {
$ret = $this->SetBackground($bg, $this->pgwidth);
if ($ret) {
$this->bodyBackgroundImage = $ret;
}
} else {
$this->bodyBackgroundImage = false;
}
/* -- END BACKGROUNDS -- */
$this->page_box['current'] = $psel;
$this->page_box['using'] = true;
}
/* -- END CSS-PAGE -- */
//Page orientation
if (!$orientation)
$orientation = $this->DefOrientation;
else {
$orientation = strtoupper(substr($orientation, 0, 1));
if ($orientation != $this->DefOrientation)
$this->OrientationChanges[$this->page] = true;
}
if ($orientation != $this->CurOrientation || $newformat) {
//Change orientation
if ($orientation == 'P') {
$this->wPt = $this->fwPt;
$this->hPt = $this->fhPt;
$this->w = $this->fw;
$this->h = $this->fh;
if (($this->forcePortraitHeaders || $this-
>forcePortraitMargins) && $this->DefOrientation == 'P') {
$this->tMargin = $this->orig_tMargin;
$this->bMargin = $this->orig_bMargin;
$this->DeflMargin = $this->orig_lMargin;
$this->DefrMargin = $this->orig_rMargin;
$this->margin_header = $this->orig_hMargin;
$this->margin_footer = $this->orig_fMargin;
} else {
$resetHTMLHeadersrequired = true;
}
} else {
$this->wPt = $this->fhPt;
$this->hPt = $this->fwPt;
$this->w = $this->fh;
$this->h = $this->fw;
if (($this->forcePortraitHeaders || $this-
>forcePortraitMargins) && $this->DefOrientation == 'P') {
$this->tMargin = $this->orig_lMargin;
$this->bMargin = $this->orig_rMargin;
$this->DeflMargin = $this->orig_bMargin;
$this->DefrMargin = $this->orig_tMargin;
$this->margin_header = $this->orig_hMargin;
$this->margin_footer = $this->orig_fMargin;
} else {
$resetHTMLHeadersrequired = true;
}
}
$this->CurOrientation = $orientation;
$this->ResetMargins();
$this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
$this->PageBreakTrigger = $this->h - $this->bMargin;
}
$this->pageDim[$this->page]['w'] = $this->w;
$this->pageDim[$this->page]['h'] = $this->h;
$this->pageDim[$this->page]['outer_width_LR'] = isset($this-
>page_box['outer_width_LR']) ? $this->page_box['outer_width_LR'] : 0;
$this->pageDim[$this->page]['outer_width_TB'] = isset($this-
>page_box['outer_width_TB']) ? $this->page_box['outer_width_TB'] : 0;
if (!isset($this->page_box['outer_width_LR']) && !isset($this-
>page_box['outer_width_TB'])) {
$this->pageDim[$this->page]['bleedMargin'] = 0;
} elseif ($this->bleedMargin <= $this->page_box['outer_width_LR'] &&
$this->bleedMargin <= $this->page_box['outer_width_TB']) {
$this->pageDim[$this->page]['bleedMargin'] = $this->bleedMargin;
} else {
$this->pageDim[$this->page]['bleedMargin'] = min($this-
>page_box['outer_width_LR'], $this->page_box['outer_width_TB']) - 0.01;
}
$this->ResetMargins();
$this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
$this->SetAutoPageBreak($this->autoPageBreak, $this->bMargin);
$this->x = $this->lMargin;
$this->y = $this->tMargin;
$this->FontFamily = '';
$this->x = $this->lMargin;
$this->y = $this->tMargin;
}
// mPDF 6
function _setAutoHeaderHeight(&$htmlh)
{
if ($this->setAutoTopMargin == 'pad') {
if (isset($htmlh['h']) && $htmlh['h']) {
$h = $htmlh['h'];
} // 5.7.3
else {
$h = 0;
}
$this->tMargin = $this->margin_header + $h + $this->orig_tMargin;
} elseif ($this->setAutoTopMargin == 'stretch') {
if (isset($htmlh['h']) && $htmlh['h']) {
$h = $htmlh['h'];
} // 5.7.3
else {
$h = 0;
}
$this->tMargin = max($this->orig_tMargin, $this->margin_header +
$h + $this->autoMarginPadding);
}
}
// mPDF 6
function _setAutoFooterHeight(&$htmlf)
{
if ($this->setAutoBottomMargin == 'pad') {
if (isset($htmlf['h']) && $htmlf['h']) {
$h = $htmlf['h'];
} // 5.7.3
else {
$h = 0;
}
$this->bMargin = $this->margin_footer + $h + $this->orig_bMargin;
$this->PageBreakTrigger = $this->h - $this->bMargin;
} elseif ($this->setAutoBottomMargin == 'stretch') {
if (isset($htmlf['h']) && $htmlf['h']) {
$h = $htmlf['h'];
} // 5.7.3
else {
$h = 0;
}
$this->bMargin = max($this->orig_bMargin, $this->margin_footer +
$h + $this->autoMarginPadding);
$this->PageBreakTrigger = $this->h - $this->bMargin;
}
}
function _endpage()
{
/* -- CSS-IMAGE-FLOAT -- */
$this->printfloatbuffer();
/* -- END CSS-IMAGE-FLOAT -- */
if ($this->visibility != 'visible')
$this->SetVisibility('visible');
$this->EndLayer();
//End of page contents
$this->state = 1;
}
$ppUx = 0;
if ($orig_srcpath && isset($this->images[$orig_srcpath])) {
$file = $orig_srcpath;
return $this->images[$orig_srcpath];
}
if (isset($this->images[$file])) {
return $this->images[$file];
} elseif ($orig_srcpath && isset($this->formobjects[$orig_srcpath])) {
$file = $orig_srcpath;
return $this->formobjects[$file];
} elseif (isset($this->formobjects[$file])) {
return $this->formobjects[$file];
}
// Save re-trying image URL's which have already failed
elseif ($firsttime && isset($this->failedimages[$file])) {
return $this->_imageError($file, $firsttime, '');
}
if (empty($data)) {
$type = '';
$data = '';
// JPEG
if ($type == 'jpeg' || $type == 'jpg') {
$hdr = $this->_jpgHeaderFromString($data);
if (!$hdr) {
return $this->_imageError($file, $firsttime, 'Error parsing
JPG header');
}
$a = $this->_jpgDataFromHeader($hdr);
$channels = intval($a[4]);
$j = strpos($data, 'JFIF');
if ($j) {
//Read resolution
$unitSp = ord(substr($data, ($j + 7), 1));
if ($unitSp > 0) {
$ppUx = $this->_twobytes2int(substr($data, ($j + 8),
2)); // horizontal pixels per meter, usually set to zero
if ($unitSp == 2) { // = dots per cm (if == 1 set as
dpi)
$ppUx = round($ppUx / 10 * 25.4);
}
}
}
if ($a[2] == 'DeviceCMYK' && (($this->PDFA && $this-
>restrictColorSpace != 3) || $this->restrictColorSpace == 2)) {
// convert to RGB image
if (!function_exists("gd_info")) {
throw new MpdfException("JPG image may not use CMYK
color space (" . $file . ").");
}
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.)";
}
$im = @imagecreatefromstring($data);
if ($im) {
$tempfile = _MPDF_TEMP_PATH . '_tempImgPNG' .
md5($file) . RAND(1, 10000) . '.png';
imageinterlace($im, false);
$check = @imagepng($im, $tempfile);
if (!$check) {
return $this->_imageError($file, $firsttime,
'Error creating temporary file (' . $tempfile . ') whilst using GD library to parse
JPG(CMYK) image');
}
$info = $this->_getImage($tempfile, false);
if (!$info) {
return $this->_imageError($file, $firsttime,
'Error parsing temporary file (' . $tempfile . ') created with GD library to parse
JPG(CMYK) image');
}
imagedestroy($im);
unlink($tempfile);
$info['type'] = 'jpg';
if ($firsttime) {
$info['i'] = count($this->images) + 1;
$info['interpolation'] = $interpolation; //
mPDF 6
$this->images[$file] = $info;
}
return $info;
} else {
return $this->_imageError($file, $firsttime, 'Error
creating GD image file from JPG(CMYK) image');
}
} elseif ($a[2] == 'DeviceRGB' && ($this->PDFX || $this-
>restrictColorSpace == 3)) {
// Convert to CMYK image stream - nominally returned as
type='png'
$info = $this->_convImage($data, $a[2], 'DeviceCMYK',
$a[0], $a[1], $ppUx, false);
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.)";
}
} elseif (($a[2] == 'DeviceRGB' || $a[2] == 'DeviceCMYK') &&
$this->restrictColorSpace == 1) {
// Convert to Grayscale image stream - nominally returned
as type='png'
$info = $this->_convImage($data, $a[2], 'DeviceGray',
$a[0], $a[1], $ppUx, false);
} else {
$info = array('w' => $a[0], 'h' => $a[1], 'cs' => $a[2],
'bpc' => $a[3], 'f' => 'DCTDecode', 'data' => $data, 'type' => 'jpg', 'ch' =>
$channels, 'icc' => $icc);
if ($ppUx) {
$info['set-dpi'] = $ppUx;
}
}
if (!$info) {
return $this->_imageError($file, $firsttime, 'Error parsing
or converting JPG image');
}
if ($firsttime) {
$info['i'] = count($this->images) + 1;
$info['interpolation'] = $interpolation; // mPDF 6
$this->images[$file] = $info;
}
return $info;
}
// PNG
elseif ($type == 'png') {
//Check signature
if (substr($data, 0, 8) != chr(137) . 'PNG' . chr(13) . chr(10) .
chr(26) . chr(10)) {
return $this->_imageError($file, $firsttime, 'Error parsing
PNG identifier');
}
//Read header chunk
if (substr($data, 12, 4) != 'IHDR') {
return $this->_imageError($file, $firsttime, 'Incorrect PNG
file (no IHDR block found)');
}
$j = strpos($data, 'pHYs');
if ($j) {
//Read resolution
$unitSp = ord(substr($data, ($j + 12), 1));
if ($unitSp == 1) {
$ppUx = $this->_fourbytes2int(substr($data, ($j + 4),
4)); // horizontal pixels per meter, usually set to zero
$ppUx = round($ppUx / 1000 * 25.4);
}
}
// http://www.libpng.org/pub/png/spec/1.2/PNG-Encoders.html
// "If the source file's gamma value is greater than 1.0,
it is probably a display system exponent,..."
// ("..and you should use its reciprocal for the PNG
gamma.")
//if ($gAMA > 1) { $gAMA = 1/$gAMA; }
// (Some) Applications seem to ignore it... appearing how
it was probably intended
// Test Case - image(s) on
http://www.w3.org/TR/CSS21/intro.html - PNG has gAMA set as 1.45454
// Probably unintentional as mentioned above and should be
0.45454 which is 1 / 2.2
// Tested on Windows PC
// Firefox and Opera display gray as 234 (correct, but
looks wrong)
// IE9 and Safari display gray as 193 (incorrect but looks
right)
// See test different gamma chunks at
http://www.libpng.org/pub/png/pngsuite-all-good.html
}
if ($gAMA) {
$gamma_correction = 1 / $gAMA;
}
if (!$im) {
return $this->_imageError($file, $firsttime, 'Error
creating GD image from PNG file (' . $errpng . ')');
}
$w = imagesx($im);
$h = imagesy($im);
if ($im) {
$tempfile = _MPDF_TEMP_PATH . '_tempImgPNG' .
md5($file) . RAND(1, 10000) . '.png';
// mPDF 6
if ($colspace == 'Indexed') { // generate Alpha
channel values from tRNS
//Read transparency info
$transparency = '';
$p = strpos($data, 'tRNS');
if ($p) {
$n = $this-
>_fourbytes2int(substr($data, ($p - 4), 4));
$transparency = substr($data, ($p +
4), $n);
// ord($transparency{$index}) = the
alpha value for that index
// generate alpha channel
for ($ypx = 0; $ypx < $h; ++$ypx) {
for ($xpx = 0; $xpx < $w; ++
$xpx) {
$colorindex =
imagecolorat($im, $xpx, $ypx);
if ($colorindex >= $n) {
$alpha = 255;
} else {
$alpha =
ord($transparency{$colorindex});
} // 0-255
if ($alpha > 0) {
return $info;
} else { // No alpha/transparency set (but cannot
read directly because e.g. bit-depth != 8, interlaced etc)
// ICC profile
$icc = false;
$p = strpos($data, 'iCCP');
if ($p && $colspace == "Indexed") { // Cannot
have ICC profile and Indexed together
$p += 4;
$n = $this->_fourbytes2int(substr($data,
($p - 8), 4));
$nullsep = strpos(substr($data, $p, 80),
chr(0));
$icc = substr($data, ($p + $nullsep + 2),
($n - ($nullsep + 2)));
$icc = @gzuncompress($icc); // Ignored if
fails
if ($icc) {
if (substr($icc, 36, 4) != 'acsp')
{
$icc = false;
} // invalid ICC profile
else {
$input = substr($icc, 16, 4);
$output = substr($icc, 20,
4);
// Ignore Color profiles for
conversion to other colorspaces e.g. CMYK/Lab
if ($input != 'RGB ' ||
$output != 'XYZ ') {
$icc = false;
}
}
}
// Convert to RGB colorspace so can use
ICC Profile
if ($icc) {
imagepalettetotruecolor($im);
$colspace = 'DeviceRGB';
$channels = 3;
}
}
if ($gamma_correction) {
imagegammacorrect($im, $gamma_correction,
2.2);
} // mPDF 6 Gamma correction
imagealphablending($im, false);
imagesavealpha($im, false);
imageinterlace($im, false);
if (!is_writable(_MPDF_TEMP_PATH)) { // mPDF
5.7.2
ob_start();
$check = @imagepng($im);
if (!$check) {
return $this->_imageError($file,
$firsttime, 'Error creating temporary image object whilst using GD library to parse
PNG image');
}
$this->_tempimg = ob_get_contents();
$this->_tempimglnk = 'var:_tempimg';
ob_end_clean();
$info = $this->_getImage($this-
>_tempimglnk, false);
if (!$info) {
return $this->_imageError($file,
$firsttime, 'Error parsing temporary file image object created with GD library to
parse PNG image');
}
imagedestroy($im);
} else {
$check = @imagepng($im, $tempfile);
if (!$check) {
return $this->_imageError($file,
$firsttime, 'Failed to create temporary image file (' . $tempfile . ') parsing PNG
image (' . $errpng . ')');
}
imagedestroy($im);
$info = $this->_getImage($tempfile,
false);
unlink($tempfile);
if (!$info) {
return $this->_imageError($file,
$firsttime, 'Error parsing temporary file (' . $tempfile . ') created with GD
library to parse PNG image');
}
}
if ($ppUx) {
$info['set-dpi'] = $ppUx;
}
$info['type'] = 'png';
if ($firsttime) {
$info['i'] = count($this->images) + 1;
$info['interpolation'] =
$interpolation; // mPDF 6
if ($icc) {
$info['ch'] = $channels;
$info['icc'] = $icc;
}
$this->images[$file] = $info;
}
return $info;
}
}
} else { // PNG image with no need to convert alph channels, bpc
<> 8 etc.
$parms = '/DecodeParms <</Predictor 15 /Colors ' .
$channels . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . '>>';
//Scan chunks looking for palette, transparency and image
data
$pal = '';
$trns = '';
$pngdata = '';
$icc = false;
$p = 33;
do {
$n = $this->_fourbytes2int(substr($data, $p, 4));
$p += 4;
$type = substr($data, $p, 4);
$p += 4;
if ($type == 'PLTE') {
//Read palette
$pal = substr($data, $p, $n);
$p += $n;
$p += 4;
} elseif ($type == 'tRNS') {
//Read transparency info
$t = substr($data, $p, $n);
$p += $n;
if ($ct == 0)
$trns = array(ord(substr($t, 1, 1)));
elseif ($ct == 2)
$trns = array(ord(substr($t, 1, 1)),
ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
else {
$pos = strpos($t, chr(0));
if (is_int($pos))
$trns = array($pos);
}
$p += 4;
}
elseif ($type == 'IDAT') {
$pngdata.=substr($data, $p, $n);
$p += $n;
$p += 4;
} elseif ($type == 'iCCP') {
$nullsep = strpos(substr($data, $p, 80),
chr(0));
$icc = substr($data, ($p + $nullsep + 2), ($n -
($nullsep + 2)));
$icc = @gzuncompress($icc); // Ignored if fails
if ($icc) {
if (substr($icc, 36, 4) != 'acsp') {
$icc = false;
} // invalid ICC profile
else {
$input = substr($icc, 16, 4);
$output = substr($icc, 20, 4);
// Ignore Color profiles for
conversion to other colorspaces e.g. CMYK/Lab
if ($input != 'RGB ' || $output !=
'XYZ ') {
$icc = false;
}
}
}
$p += $n;
$p += 4;
} elseif ($type == 'IEND') {
break;
} elseif (preg_match('/[a-zA-Z]{4}/', $type)) {
$p += $n + 4;
} else {
return $this->_imageError($file, $firsttime,
'Error parsing PNG image data');
}
} while ($n);
if (!$pngdata) {
return $this->_imageError($file, $firsttime, 'Error
parsing PNG image data - no IDAT data found');
}
if ($colspace == 'Indexed' && empty($pal)) {
return $this->_imageError($file, $firsttime, 'Error
parsing PNG image data - missing colour palette');
}
$info = array('w' => $w, 'h' => $h, 'cs' => $colspace,
'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' =>
$trns, 'data' => $pngdata, 'ch' => $channels, 'icc' => $icc);
$info['type'] = 'png';
if ($ppUx) {
$info['set-dpi'] = $ppUx;
}
}
if (!$info) {
return $this->_imageError($file, $firsttime, 'Error parsing
or converting PNG image');
}
if ($firsttime) {
$info['i'] = count($this->images) + 1;
$info['interpolation'] = $interpolation; // mPDF 6
$this->images[$file] = $info;
}
return $info;
}
// GIF
elseif ($type == 'gif') {
if (function_exists('gd_info')) {
$gd = gd_info();
} else {
$gd = array();
}
if (isset($gd['GIF Read Support']) && $gd['GIF Read Support']) {
$im = @imagecreatefromstring($data);
if ($im) {
$tempfile = _MPDF_TEMP_PATH . '_tempImgPNG' .
md5($file) . RAND(1, 10000) . '.png';
imagealphablending($im, false);
imagesavealpha($im, false);
imageinterlace($im, false);
if (!is_writable($tempfile)) {
ob_start();
$check = @imagepng($im);
if (!$check) {
return $this->_imageError($file,
$firsttime, 'Error creating temporary image object whilst using GD library to parse
GIF image');
}
$this->_tempimg = ob_get_contents();
$this->_tempimglnk = 'var:_tempimg';
ob_end_clean();
$info = $this->_getImage($this->_tempimglnk,
false);
if (!$info) {
return $this->_imageError($file,
$firsttime, 'Error parsing temporary file image object created with GD library to
parse GIF image');
}
imagedestroy($im);
} else {
$check = @imagepng($im, $tempfile);
if (!$check) {
return $this->_imageError($file,
$firsttime, 'Error creating temporary file (' . $tempfile . ') whilst using GD
library to parse GIF image');
}
$info = $this->_getImage($tempfile, false);
if (!$info) {
return $this->_imageError($file,
$firsttime, 'Error parsing temporary file (' . $tempfile . ') created with GD
library to parse GIF image');
}
imagedestroy($im);
unlink($tempfile);
}
$info['type'] = 'gif';
if ($firsttime) {
$info['i'] = count($this->images) + 1;
$info['interpolation'] = $interpolation; //
mPDF 6
$this->images[$file] = $info;
}
return $info;
} else {
return $this->_imageError($file, $firsttime, 'Error
creating GD image file from GIF image');
}
}
if (!class_exists('gif', false)) {
include_once(_MPDF_PATH . 'classes/gif.php');
}
$gif = new CGIF();
$h = 0;
$w = 0;
$gif->loadFile($data, 0);
$trns = '';
if (isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans &&
($nColors > 0)) {
$trns = array($gif->m_img->m_nTrans);
}
$gifdata = $gif->m_img->m_data;
$w = $gif->m_gfh->m_nWidth;
$h = $gif->m_gfh->m_nHeight;
$gif->ClearData();
/* -- IMAGES-BMP -- */
// BMP (Windows Bitmap)
elseif ($type == 'bmp') {
if (!class_exists('bmp', false)) {
include(_MPDF_PATH . 'classes/bmp.php');
}
if (empty($this->bmp)) {
$this->bmp = new bmp($this);
}
$info = $this->bmp->_getBMPimage($data, $file);
if (isset($info['error'])) {
return $this->_imageError($file, $firsttime,
$info['error']);
}
if ($firsttime) {
$info['i'] = count($this->images) + 1;
$info['interpolation'] = $interpolation; // mPDF 6
$this->images[$file] = $info;
}
return $info;
}
/* -- END IMAGES-BMP -- */
/* -- IMAGES-WMF -- */
// WMF
elseif ($type == 'wmf') {
if (!class_exists('wmf', false)) {
include(_MPDF_PATH . 'classes/wmf.php');
}
if (empty($this->wmf)) {
$this->wmf = new wmf($this);
}
$wmfres = $this->wmf->_getWMFimage($data);
if ($wmfres[0] == 0) {
if ($wmfres[1]) {
return $this->_imageError($file, $firsttime,
$wmfres[1]);
}
return $this->_imageError($file, $firsttime, 'Error parsing
WMF image');
}
$info = array('x' => $wmfres[2][0], 'y' => $wmfres[2][1], 'w' =>
$wmfres[3][0], 'h' => $wmfres[3][1], 'data' => $wmfres[1]);
$info['i'] = count($this->formobjects) + 1;
$info['type'] = 'wmf';
$this->formobjects[$file] = $info;
return $info;
}
/* -- END IMAGES-WMF -- */
//==============================================================
function _convImage(&$data, $colspace, $targetcs, $w, $h, $dpi, $mask,
$gamma_correction = false, $pngcolortype = false)
{ // mPDF 5.7.2 Gamma correction
if ($this->PDFA || $this->PDFX) {
$mask = false;
}
$im = @imagecreatefromstring($data);
$info = array();
$bpc = ord(substr($data, 24, 1));
if ($im) {
$imgdata = '';
$mimgdata = '';
$minfo = array();
if ($gamma_correction) {
imagegammacorrect($im, $gamma_correction, 2.2);
} // mPDF 6 Gamma correction
//Read transparency info
$trns = array();
$trnsrgb = false;
if (!$this->PDFA && !$this->PDFX && !$mask) { // mPDF 6 added
NOT mask
$p = strpos($data, 'tRNS');
if ($p) {
$n = $this->_fourbytes2int(substr($data, ($p - 4),
4));
$t = substr($data, ($p + 4), $n);
if ($colspace == 'DeviceGray') { // ct===0
$trns = array($this->_trnsvalue(substr($t, 0,
2), $bpc));
} elseif ($colspace == 'DeviceRGB') { // ct==2
$trns[0] = $this->_trnsvalue(substr($t, 0, 2),
$bpc);
$trns[1] = $this->_trnsvalue(substr($t, 2, 2),
$bpc);
$trns[2] = $this->_trnsvalue(substr($t, 4, 2),
$bpc);
$trnsrgb = $trns;
if ($targetcs == 'DeviceCMYK') {
$col = $this->rgb2cmyk(array(3, $trns[0],
$trns[1], $trns[2]));
$c1 = intval($col[1] * 2.55);
$c2 = intval($col[2] * 2.55);
$c3 = intval($col[3] * 2.55);
$c4 = intval($col[4] * 2.55);
$trns = array($c1, $c2, $c3, $c4);
} elseif ($targetcs == 'DeviceGray') {
$c = intval(($trns[0] * .21) + ($trns[1]
* .71) + ($trns[2] * .07));
$trns = array($c);
}
} else { // Indexed
$pos = strpos($t, chr(0));
if (is_int($pos)) {
$pal = imagecolorsforindex($im, $pos);
$r = $pal['red'];
$g = $pal['green'];
$b = $pal['blue'];
$trns = array($r, $g, $b); // ****
$trnsrgb = $trns;
if ($targetcs == 'DeviceCMYK') {
$col = $this->rgb2cmyk(array(3, $r,
$g, $b));
$c1 = intval($col[1] * 2.55);
$c2 = intval($col[2] * 2.55);
$c3 = intval($col[3] * 2.55);
$c4 = intval($col[4] * 2.55);
$trns = array($c1, $c2, $c3, $c4);
} elseif ($targetcs == 'DeviceGray') {
$c = intval(($r * .21) + ($g * .71)
+ ($b * .07));
$trns = array($c);
}
}
}
}
}
for ($i = 0; $i < $h; $i++) {
for ($j = 0; $j < $w; $j++) {
$rgb = imagecolorat($im, $j, $i);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if ($colspace == 'Indexed') {
$pal = imagecolorsforindex($im, $rgb);
$r = $pal['red'];
$g = $pal['green'];
$b = $pal['blue'];
}
if ($targetcs == 'DeviceCMYK') {
$col = $this->rgb2cmyk(array(3, $r, $g, $b));
$c1 = intval($col[1] * 2.55);
$c2 = intval($col[2] * 2.55);
$c3 = intval($col[3] * 2.55);
$c4 = intval($col[4] * 2.55);
if ($trnsrgb) {
// original pixel was not set as
transparent but processed color does match
if ($trnsrgb != array($r, $g, $b) &&
$trns == array($c1, $c2, $c3, $c4)) {
if ($c4 == 0) {
$c4 = 1;
} else {
$c4--;
}
}
}
$imgdata .= chr($c1) . chr($c2) . chr($c3) .
chr($c4);
} elseif ($targetcs == 'DeviceGray') {
$c = intval(($r * .21) + ($g * .71) + ($b * .
07));
if ($trnsrgb) {
// original pixel was not set as
transparent but processed color does match
if ($trnsrgb != array($r, $g, $b) &&
$trns == array($c)) {
if ($c == 0) {
$c = 1;
} else {
$c--;
}
}
}
$imgdata .= chr($c);
} elseif ($targetcs == 'DeviceRGB') {
$imgdata .= chr($r) . chr($g) . chr($b);
}
}
}
if ($targetcs == 'DeviceGray') {
$ncols = 1;
} elseif ($targetcs == 'DeviceRGB') {
$ncols = 3;
} elseif ($targetcs == 'DeviceCMYK') {
$ncols = 4;
}
$imgdata = gzcompress($imgdata);
$info = array('w' => $w, 'h' => $h, 'cs' => $targetcs, 'bpc' =>
8, 'f' => 'FlateDecode', 'data' => $imgdata, 'type' => 'png',
'parms' => '/DecodeParms <</Colors ' . $ncols . '
/BitsPerComponent 8 /Columns ' . $w . '>>');
if ($dpi) {
$info['set-dpi'] = $dpi;
}
if ($mask) {
$mimgdata = gzcompress($mimgdata);
$minfo = array('w' => $w, 'h' => $h, 'cs' => 'DeviceGray',
'bpc' => 8, 'f' => 'FlateDecode', 'data' => $mimgdata, 'type' => 'png',
'parms' => '/DecodeParms <</Colors ' . $ncols . '
/BitsPerComponent 8 /Columns ' . $w . '>>');
if ($dpi) {
$minfo['set-dpi'] = $dpi;
}
$tempfile = '_tempImgPNG' . md5($data) . RAND(1, 10000) .
'.png';
$imgmask = count($this->images) + 1;
$minfo['i'] = $imgmask;
$this->images[$tempfile] = $minfo;
$info['masked'] = $imgmask;
} elseif ($trns) {
$info['trns'] = $trns;
}
imagedestroy($im);
}
return $info;
}
function _fourbytes2int($s)
{
//Read a 4-byte integer from string
return (ord($s[0]) << 24) + (ord($s[1]) << 16) + (ord($s[2]) << 8) +
ord($s[3]);
}
function _twobytes2int($s)
{ // equivalent to _get_ushort
//Read a 2-byte integer from string
return (ord(substr($s, 0, 1)) << 8) + ord(substr($s, 1, 1));
}
function _jpgHeaderFromString(&$data)
{
$p = 4;
$p += $this->_twobytes2int(substr($data, $p, 2)); // Length of initial
marker block
$marker = substr($data, $p, 2);
while ($marker != chr(255) . chr(192) && $marker != chr(255) . chr(194)
&& $p < strlen($data)) {
// Start of frame marker (FFC0) or (FFC2) mPDF 4.4.004
$p += ($this->_twobytes2int(substr($data, $p + 2, 2))) + 2; //
Length of marker block
$marker = substr($data, $p, 2);
}
if ($marker != chr(255) . chr(192) && $marker != chr(255) . chr(194)) {
return false;
}
return substr($data, $p + 2, 10);
}
function _jpgDataFromHeader($hdr)
{
$bpc = ord(substr($hdr, 2, 1));
if (!$bpc) {
$bpc = 8;
}
$h = $this->_twobytes2int(substr($hdr, 3, 2));
$w = $this->_twobytes2int(substr($hdr, 5, 2));
$channels = ord(substr($hdr, 7, 1));
if ($channels == 3) {
$colspace = 'DeviceRGB';
} elseif ($channels == 4) {
$colspace = 'DeviceCMYK';
} else {
$colspace = 'DeviceGray';
}
return array($w, $h, $colspace, $bpc, $channels);
}
//==============================================================
function _imageTypeFromString(&$data)
{
$type = '';
if (substr($data, 6, 4) == 'JFIF' || substr($data, 6, 4) == 'Exif' ||
substr($data, 0, 2) == chr(255) . chr(216)) { // 0xFF 0xD8 // mpDF 5.7.2
$type = 'jpeg';
} elseif (substr($data, 0, 6) == "GIF87a" || substr($data, 0, 6) ==
"GIF89a") {
$type = 'gif';
} elseif (substr($data, 0, 8) == chr(137) . 'PNG' . chr(13) . chr(10) .
chr(26) . chr(10)) {
$type = 'png';
}
/* -- IMAGES-WMF -- */ elseif (substr($data, 0, 4) == chr(215) .
chr(205) . chr(198) . chr(154)) {
$type = 'wmf';
}
/* -- END IMAGES-WMF -- */ elseif (preg_match('/<svg.*<\/svg>/is',
$data)) {
$type = 'svg';
}
// BMP images
elseif (substr($data, 0, 2) == "BM") {
$type = 'bmp';
}
return $type;
}
//==============================================================
// Moved outside WMF as also needed for SVG
function _putformobjects()
{
reset($this->formobjects);
while (list($file, $info) = each($this->formobjects)) {
$this->_newobj();
$this->formobjects[$file]['n'] = $this->n;
$this->_out('<</Type /XObject');
$this->_out('/Subtype /Form');
$this->_out('/Group ' . ($this->n + 1) . ' 0 R');
$this->_out('/BBox [' . $info['x'] . ' ' . $info['y'] . ' ' .
($info['w'] + $info['x']) . ' ' . ($info['h'] + $info['y']) . ']');
if ($this->compress)
$this->_out('/Filter /FlateDecode');
$data = ($this->compress) ? gzcompress($info['data']) :
$info['data'];
$this->_out('/Length ' . strlen($data) . '>>');
$this->_putstream($data);
unset($this->formobjects[$file]['data']);
$this->_out('endobj');
// Required for SVG transparency (opacity) to work
$this->_newobj();
$this->_out('<</Type /Group');
$this->_out('/S /Transparency');
$this->_out('>>');
$this->_out('endobj');
}
}
function _freadint($f)
{
//Read a 4-byte integer from file
$i = ord(fread($f, 1)) << 24;
$i+=ord(fread($f, 1)) << 16;
$i+=ord(fread($f, 1)) << 8;
$i+=ord(fread($f, 1));
return $i;
}
function _UTF16BEtextstring($s)
{
$s = $this->UTF8ToUTF16BE($s, true);
/* -- ENCRYPTION -- */
if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
}
/* -- END ENCRYPTION -- */
return '(' . $this->_escape($s) . ')';
}
function _textstring($s)
{
/* -- ENCRYPTION -- */
if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
}
/* -- END ENCRYPTION -- */
return '(' . $this->_escape($s) . ')';
}
function _escape($s)
{
// the chr(13) substitution fixes the Bugs item #1421290.
return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\',
chr(13) => '\r'));
}
function _putstream($s)
{
/* -- ENCRYPTION -- */
if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s);
}
/* -- END ENCRYPTION -- */
$this->_out('stream');
$this->_out($s);
$this->_out('endstream');
}
/* -- WATERMARK -- */
// add a watermark
function watermark($texte, $angle = 45, $fontsize = 96, $alpha = 0.2)
{
if ($this->PDFA || $this->PDFX) {
throw new MpdfException('PDFA and PDFX do not permit
transparency, so mPDF does not allow Watermarks!');
}
if (!$this->watermark_font) {
$this->watermark_font = $this->default_font;
}
$this->SetFont($this->watermark_font, "B", $fontsize, false); // Don't
output
$texte = $this->purify_utf8_text($texte);
if ($this->text_input_as_HTML) {
$texte = $this->all_entities_to_utf8($texte);
}
if ($this->usingCoreFont) {
$texte = mb_convert_encoding($texte, $this->mb_enc, 'UTF-8');
}
// DIRECTIONALITY
if (preg_match("/([" . $this->pregRTLchars . "])/u", $texte)) {
$this->biDirectional = true;
} // *OTL*
$textvar = 0;
$save_OTLtags = $this->OTLtags;
$this->OTLtags = array();
if ($this->useKerning) {
if ($this->CurrentFont['haskernGPOS']) {
$this->OTLtags['Plus'] .= ' kern';
} else {
$textvar = ($textvar | FC_KERNING);
}
}
/* -- OTL -- */
// Use OTL OpenType Table Layout - GSUB & GPOS
if (isset($this->CurrentFont['useOTL']) && $this-
>CurrentFont['useOTL']) {
$texte = $this->otl->applyOTL($texte, $this-
>CurrentFont['useOTL']);
$OTLdata = $this->otl->OTLdata;
}
/* -- END OTL -- */
$this->OTLtags = $save_OTLtags;
$this->SetAlpha($alpha);
$this->SetTColor($this->ConvertColor(0));
$szfont = $fontsize;
$loop = 0;
$maxlen = (min($this->w, $this->h) ); // sets max length of text as 7/8
width/height of page
while ($loop == 0) {
$this->SetFont($this->watermark_font, "B", $szfont, false); //
Don't output
$offset = ((sin(deg2rad($angle))) * ($szfont / _MPDFK));
$this->SetAlpha(1);
}
// From Invoice
function RoundedRect($x, $y, $w, $h, $r, $style = '')
{
$hp = $this->h;
if ($style == 'F')
$op = 'f';
elseif ($style == 'FD' or $style == 'DF')
$op = 'B';
else
$op = 'S';
$MyArc = 4 / 3 * (sqrt(2) - 1);
$this->_out(sprintf('%.3F %.3F m', ($x + $r) * _MPDFK, ($hp - $y) *
_MPDFK));
$xc = $x + $w - $r;
$yc = $y + $r;
$this->_out(sprintf('%.3F %.3F l', $xc * _MPDFK, ($hp - $y) * _MPDFK));
//====================================================
/* -- DIRECTW -- */
function Shaded_box($text, $font = '', $fontstyle = 'B', $szfont = '', $width
= '70%', $style = 'DF', $radius = 2.5, $fill = '#FFFFFF', $color = '#000000', $pad
= 2)
{
// F (shading - no line),S (line, no shading),DF (both)
if (!class_exists('directw', false)) {
include(_MPDF_PATH . 'classes/directw.php');
}
if (empty($this->directw)) {
$this->directw = new directw($this);
}
$this->directw->Shaded_box($text, $font, $fontstyle, $szfont, $width,
$style, $radius, $fill, $color, $pad);
}
/* -- END DIRECTW -- */
// ====================================================
// ====================================================
/* -- CJK-FONTS -- */
function AddCJKFont($family)
{
if ($this->PDFA || $this->PDFX) {
throw new MpdfException("Adobe CJK fonts cannot be embedded in
mPDF (required for PDFA1-b and PDFX/1-a).");
}
if ($family == 'big5') {
$this->AddBig5Font();
} elseif ($family == 'gb') {
$this->AddGBFont();
} elseif ($family == 'sjis') {
$this->AddSJISFont();
} elseif ($family == 'uhc') {
$this->AddUHCFont();
}
}
function AddBig5Font()
{
//Add Big5 font with proportional Latin
$family = 'big5';
$name = 'MSungStd-Light-Acro';
$cw = $this->Big5_widths;
$CMap = 'UniCNS-UTF16-H';
$registry = array('ordering' => 'CNS1', 'supplement' => 4);
$desc = array(
'Ascent' => 880,
'Descent' => -120,
'CapHeight' => 880,
'Flags' => 6,
'FontBBox' => '[-160 -249 1015 1071]',
'ItalicAngle' => 0,
'StemV' => 93,
);
$this->AddCIDFont($family, '', $name, $cw, $CMap, $registry, $desc);
$this->AddCIDFont($family, 'B', $name . ',Bold', $cw, $CMap, $registry,
$desc);
$this->AddCIDFont($family, 'I', $name . ',Italic', $cw, $CMap,
$registry, $desc);
$this->AddCIDFont($family, 'BI', $name . ',BoldItalic', $cw, $CMap,
$registry, $desc);
}
function AddGBFont()
{
//Add GB font with proportional Latin
$family = 'gb';
$name = 'STSongStd-Light-Acro';
$cw = $this->GB_widths;
$CMap = 'UniGB-UTF16-H';
$registry = array('ordering' => 'GB1', 'supplement' => 4);
$desc = array(
'Ascent' => 880,
'Descent' => -120,
'CapHeight' => 737,
'Flags' => 6,
'FontBBox' => '[-25 -254 1000 880]',
'ItalicAngle' => 0,
'StemV' => 58,
'Style' => '<< /Panose <000000000400000000000000> >>',
);
$this->AddCIDFont($family, '', $name, $cw, $CMap, $registry, $desc);
$this->AddCIDFont($family, 'B', $name . ',Bold', $cw, $CMap, $registry,
$desc);
$this->AddCIDFont($family, 'I', $name . ',Italic', $cw, $CMap,
$registry, $desc);
$this->AddCIDFont($family, 'BI', $name . ',BoldItalic', $cw, $CMap,
$registry, $desc);
}
function AddSJISFont()
{
//Add SJIS font with proportional Latin
$family = 'sjis';
$name = 'KozMinPro-Regular-Acro';
$cw = $this->SJIS_widths;
$CMap = 'UniJIS-UTF16-H';
$registry = array('ordering' => 'Japan1', 'supplement' => 5);
$desc = array(
'Ascent' => 880,
'Descent' => -120,
'CapHeight' => 740,
'Flags' => 6,
'FontBBox' => '[-195 -272 1110 1075]',
'ItalicAngle' => 0,
'StemV' => 86,
'XHeight' => 502,
);
$this->AddCIDFont($family, '', $name, $cw, $CMap, $registry, $desc);
$this->AddCIDFont($family, 'B', $name . ',Bold', $cw, $CMap, $registry,
$desc);
$this->AddCIDFont($family, 'I', $name . ',Italic', $cw, $CMap,
$registry, $desc);
$this->AddCIDFont($family, 'BI', $name . ',BoldItalic', $cw, $CMap,
$registry, $desc);
}
function AddUHCFont()
{
//Add UHC font with proportional Latin
$family = 'uhc';
$name = 'HYSMyeongJoStd-Medium-Acro';
$cw = $this->UHC_widths;
$CMap = 'UniKS-UTF16-H';
$registry = array('ordering' => 'Korea1', 'supplement' => 2);
$desc = array(
'Ascent' => 880,
'Descent' => -120,
'CapHeight' => 720,
'Flags' => 6,
'FontBBox' => '[-28 -148 1001 880]',
'ItalicAngle' => 0,
'StemV' => 60,
'Style' => '<< /Panose <000000000600000000000000> >>',
);
$this->AddCIDFont($family, '', $name, $cw, $CMap, $registry, $desc);
$this->AddCIDFont($family, 'B', $name . ',Bold', $cw, $CMap, $registry,
$desc);
$this->AddCIDFont($family, 'I', $name . ',Italic', $cw, $CMap,
$registry, $desc);
$this->AddCIDFont($family, 'BI', $name . ',BoldItalic', $cw, $CMap,
$registry, $desc);
}
/* -- END CJK-FONTS -- */
/////////////////////////////////////////////////////////////////////////////
/
/////////////////////////////////////////////////////////////////////////////
/
/////////////////////////////////////////////////////////////////////////////
/
/////////////////////////////////////////////////////////////////////////////
/
/////////////////////////////////////////////////////////////////////////////
/
/////////////////////////////////////////////////////////////////////////////
/
/////////////////////////////////////////////////////////////////////////////
/
function SetDefaultFont($font)
{
// Disallow embedded fonts to be used as defaults in PDFA
if ($this->PDFA || $this->PDFX) {
if (strtolower($font) == 'ctimes') {
$font = 'serif';
}
if (strtolower($font) == 'ccourier') {
$font = 'monospace';
}
if (strtolower($font) == 'chelvetica') {
$font = 'sans-serif';
}
}
$font = $this->SetFont($font); // returns substituted font if necessary
$this->default_font = $font;
$this->original_default_font = $font;
if (!$this->watermark_font) {
$this->watermark_font = $font;
} // *WATERMARK*
$this->defaultCSS['BODY']['FONT-FAMILY'] = $font;
$this->cssmgr->CSS['BODY']['FONT-FAMILY'] = $font;
}
function SetDefaultFontSize($fontsize)
{
$this->default_font_size = $fontsize;
$this->original_default_font_size = $fontsize;
$this->SetFontSize($fontsize);
$this->defaultCSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
$this->cssmgr->CSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
}
$this->SetMargins($this->DeflMargin, $this->DefrMargin,
$this->tMargin);
}
$this->directionality = 'rtl';
$this->defaultAlign = 'R';
$this->defaultTableAlign = 'R';
} else {
/* -- END OTL -- */
$this->directionality = 'ltr';
$this->defaultAlign = 'L';
$this->defaultTableAlign = 'L';
} // *OTL*
$this->cssmgr->CSS['BODY']['DIRECTION'] = $this->directionality;
}
if ($this->shrin_k > 1) {
$shrin_k = $this->shrin_k;
} else {
$shrin_k = 1;
}
$leading = 0;
if ($CSSlineheight == 'N') {
$lh = $this->_getNormalLineheight($fontdesc);
$lineheight = ($fontsize * $lh);
$leading += $linegap; // specified in hhea or sTypo in OpenType
tables ****************************************
} elseif (preg_match('/mm/', $CSSlineheight)) {
$lineheight = (($CSSlineheight + 0.0) / $shrin_k);
} // convert to number
// ??? If lineheight is a factor e.g. 1.3 ?? use factor x 1em or ? use
'normal' lineheight * factor ******************************
// Could depend on value for $text_height - a draft CSS value as set
above for now
elseif ($CSSlineheight > 0) {
$lineheight = ($fontsize * $CSSlineheight);
} else {
$lineheight = ($fontsize * $this->normalLineheight);
}
return $ypos;
}
$ypos = array();
$bordypos = array();
$bgypos = array();
if ($is_table) {
// FOR TABLE
$fontsize = $this->FontSize;
$fontkey = $this->FontFamily . $this->FontStyle;
$fontdesc = $this->fonts[$fontkey]['desc'];
$CSSlineheight = $this->cellLineHeight;
$line_stacking_strategy = $this->cellLineStackingStrategy; //
inline-line-height [default] | block-line-height | max-height | grid-height
$line_stacking_shift = $this->cellLineStackingShift; //
consider-shifts [default] | disregard-shifts
} else {
// FOR BLOCK FONT
$fontsize = $this->blk[$this->blklvl]['InlineProperties']
['size'];
$fontkey = $this->blk[$this->blklvl]['InlineProperties']
['family'] . $this->blk[$this->blklvl]['InlineProperties']['style'];
$fontdesc = $this->fonts[$fontkey]['desc'];
$CSSlineheight = $this->blk[$this->blklvl]['line_height'];
// inline-line-height | block-line-height | max-height | grid-
height
$line_stacking_strategy = (isset($this->blk[$this->blklvl]
['line_stacking_strategy']) ? $this->blk[$this->blklvl]['line_stacking_strategy'] :
'inline-line-height');
// consider-shifts | disregard-shifts
$line_stacking_shift = (isset($this->blk[$this->blklvl]
['line_stacking_shift']) ? $this->blk[$this->blklvl]['line_stacking_shift'] :
'consider-shifts');
}
$boxLineHeight = $this->_computeLineheight($CSSlineheight, $fontsize);
// for the block element - always taking the block EXTENDED progression
including leading - which may be negative
if ($line_stacking_strategy == 'block-line-height') {
$topy = $ypos[-1]['exttop'];
$bottomy = $ypos[-1]['extbottom'];
} else {
$topy = 0;
$bottomy = 0;
}
if (isset($font[$k]['textparam']['text-baseline']) &&
$font[$k]['textparam']['text-baseline'] != 0) {
$ypos[$k]['baseline-shift'] = $font[$k]['textparam']
['text-baseline'];
}
// ADJUST $ypos => lineBox using $stackHeight; lineBox are all offsets
from the top of stackHeight in mm
// and SET IMAGE OFFSETS
$lineBox[-1]['boxtop'] = $topy - $ypos[-1]['boxtop'];
$lineBox[-1]['boxbottom'] = $topy - $ypos[-1]['boxbottom'];
// $lineBox[-1]['exttop'] = $topy - $ypos[-1]['exttop'];
// $lineBox[-1]['extbottom'] = $topy - $ypos[-1]['extbottom'];
$lineBox[-1]['glyphYorigin'] = $topy - $ypos[-1]['glyphYorigin'];
$lineBox[-1]['baseline-shift'] = $ypos[-1]['baseline-shift'];
if (substr($path, 0, 1) == '#') {
return;
}
if (preg_match('@^(mailto|tel|fax):.*@i', $path)) {
return;
}
if (substr($path, 0, 3) == "../") { //It is a Relative Link
$backtrackamount = substr_count($path, "../");
$maxbacktrack = substr_count($basepath, "/") - 3;
$filepath = str_replace("../", '', $path);
$path = $basepath;
//If it is an invalid relative link, then make it go to directory
root
if ($backtrackamount > $maxbacktrack)
$backtrackamount = $maxbacktrack;
//Backtrack some directories
for ($i = 0; $i < $backtrackamount + 1; $i++)
$path = substr($path, 0, strrpos($path, "/"));
$path = $path . "/" . $filepath; //Make it an absolute path
}
elseif (strpos($path, ":/") === false || strpos($path, ":/") > 10)
{ //It is a Local Link
if (substr($path, 0, 1) == "/") {
$tr = parse_url($basepath);
// mPDF 5.7.2
$root = '';
if (!empty($tr['scheme'])) {
$root .= $tr['scheme'] . '://';
}
$root .= isset($tr['host']) ? $tr['host'] : '';
$root .= ((isset($tr['port']) && $tr['port']) ? (':' .
$tr['port']) : ''); // mPDF 5.7.3
$path = $root . $path;
} else {
$path = $basepath . $path;
}
}
//Do nothing if it is an Absolute Link
}
// mPDF 6
function _getStyledNumber($ppgno, $type, $listmarker = false)
{
if ($listmarker) {
$reverse = true; // Reverse RTL numerals (Hebrew) when using
for list
$checkfont = true; // Using list - font is set, so check if
character is available
} else {
$reverse = false; // For pagenumbers, RTL numerals (Hebrew) will
get reversed later by bidi
$checkfont = false; // For pagenumbers - font is not set, so no
check
}
$lowertype = strtolower($type);
if ($lowertype == 'upper-latin' || $lowertype == 'upper-alpha' || $type
== 'A') {
$ppgno = $this->dec2alpha($ppgno, true);
} elseif ($lowertype == 'lower-latin' || $lowertype == 'lower-alpha' ||
$type == 'a') {
$ppgno = $this->dec2alpha($ppgno, false);
} elseif ($lowertype == 'upper-roman' || $type == 'I') {
$ppgno = $this->dec2roman($ppgno, true);
} elseif ($lowertype == 'lower-roman' || $type == 'i') {
$ppgno = $this->dec2roman($ppgno, false);
} elseif ($lowertype == 'hebrew') {
$ppgno = $this->dec2hebrew($ppgno, $reverse);
} elseif (preg_match('/(arabic-indic|bengali|devanagari|gujarati|
gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu|cambodian|khmer|
lao)/i', $lowertype, $m)) {
switch ($m[1]) { //Format type
case 'arabic-indic': $cp = 0x0660;
break;
case 'persian':
case 'urdu': $cp = 0x06F0;
break;
case 'bengali': $cp = 0x09E6;
break;
case 'devanagari': $cp = 0x0966;
break;
case 'gujarati': $cp = 0x0AE6;
break;
case 'gurmukhi': $cp = 0x0A66;
break;
case 'kannada': $cp = 0x0CE6;
break;
case 'malayalam': $cp = 0x0D66;
break;
case 'oriya': $cp = 0x0B66;
break;
case 'telugu': $cp = 0x0C66;
break;
case 'tamil': $cp = 0x0BE6;
break;
case 'thai': $cp = 0x0E50;
break;
case 'khmer':
case 'cambodian': $cp = 0x17E0;
break;
case 'lao': $cp = 0x0ED0;
break;
}
$ppgno = $this->dec2other($ppgno, $cp, $checkfont);
} elseif ($lowertype == 'cjk-decimal') {
$ppgno = $this->dec2cjk($ppgno);
}
return $ppgno;
}
function docPageSettings($num = 0)
{
// Returns current type (numberstyle), suppression state for this page
number;
// reset is only returned if set for this page number
if ($num < 1) {
$num = $this->page;
}
$type = $this->defaultPageNumStyle; // set default Page Number Style
$ppgno = $num;
$suppress = 0;
$offset = 0;
$reset = '';
foreach ($this->PageNumSubstitutions AS $psarr) {
if ($num >= $psarr['from']) {
if ($psarr['reset']) {
if ($psarr['reset'] > 1) {
$offset = $psarr['reset'] - 1;
}
$ppgno = $num - $psarr['from'] + 1 + $offset;
}
if ($psarr['type']) {
$type = $psarr['type'];
}
if (strtoupper($psarr['suppress']) == 'ON' ||
$psarr['suppress'] == 1) {
$suppress = 1;
} elseif (strtoupper($psarr['suppress']) == 'OFF') {
$suppress = 0;
}
}
if ($num == $psarr['from']) {
$reset = $psarr['reset'];
}
}
if ($suppress) {
$suppress = 'on';
} else {
$suppress = 'off';
}
return array($type, $suppress, $reset);
}
function RestartDocTemplate()
{
$this->docTemplateStart = $this->page;
}
//Page header
function Header($content = '')
{
$this->cMarginL = 0;
$this->cMarginR = 0;
/* -- TABLES -- */
$y = $this->y;
/* -- COLUMNS -- */
// If outside columns, this is done in PaintDivBB
if ($this->ColActive) {
//OUTER FILL BGCOLOR of DIVS
if ($this->blklvl > 0) {
$firstblockfill = $this->GetFirstBlockFill();
if ($firstblockfill && $this->blklvl >=
$firstblockfill) {
$divh = $content[$i][0]['h'];
$bak_x = $this->x;
$this->DivLn($divh, -3, false);
// Reset current block fill
$bcor = $this->blk[$this->blklvl]
['bgcolorarray'];
$this->SetFColor($bcor);
$this->x = $bak_x;
}
}
}
/* -- END COLUMNS -- */
$colctr = 0;
foreach ($content[$i] as $tablehf) {
$colctr++;
$y = $tablehf['y'] - $topy;
$this->y = $y;
//Set some cell values
$x = $tablehf['x'];
if (($this->mirrorMargins) && ($tablestartpage ==
'ODD') && (($this->page) % 2 == 0)) { // EVEN
$x = $x + $this->MarginCorrection;
} elseif (($this->mirrorMargins) && ($tablestartpage
== 'EVEN') && (($this->page) % 2 == 1)) { // ODD
$x = $x + $this->MarginCorrection;
}
/* -- COLUMNS -- */
// Added to correct for Columns
if ($this->ColActive) {
if ($this->directionality == 'rtl') { // *OTL*
$x -= ($this->CurrCol -
$tablestartcolumn) * ($this->ColWidth + $this->ColGap); // *OTL*
} // *OTL*
else { // *OTL*
$x += ($this->CurrCol -
$tablestartcolumn) * ($this->ColWidth + $this->ColGap);
} // *OTL*
}
/* -- END COLUMNS -- */
if ($colctr == 1) {
$x0 = $x;
}
// mPDF ITERATION
if ($this->iterationCounter) {
foreach ($tablehf['textbuffer'] AS $k => $t) {
if (!is_array($t[0]) && preg_match('/
{iteration ([a-zA-Z0-9_]+)}/', $t[0], $m)) {
$vname = '__' . $m[1] . '_';
if (!isset($this->$vname)) {
$this->$vname = 1;
} else {
$this->$vname++;
}
$tablehf['textbuffer'][$k][0] =
preg_replace('/{iteration ' . $m[1] . '}/', $this->$vname, $tablehf['textbuffer']
[$k][0]);
}
}
}
$w = $tablehf['w'];
$h = $tablehf['h'];
$va = $tablehf['va'];
$R = $tablehf['R'];
$direction = $tablehf['direction'];
$mih = $tablehf['mih'];
$border = $tablehf['border'];
$border_details = $tablehf['border_details'];
$padding = $tablehf['padding'];
$this->tabletheadjustfinished = true;
$textbuffer = $tablehf['textbuffer'];
//Align
$align = $tablehf['a'];
$this->cellTextAlign = $align;
$this->cellLineHeight = $tablehf['cellLineHeight'];
$this->cellLineStackingStrategy =
$tablehf['cellLineStackingStrategy'];
$this->cellLineStackingShift =
$tablehf['cellLineStackingShift'];
$this->x = $x;
if ($this->ColActive) {
if ($table['borders_separate']) {
$tablefill = isset($table['bgcolor'][-1])
? $table['bgcolor'][-1] : 0;
if ($tablefill) {
$color = $this-
>ConvertColor($tablefill);
if ($color) {
$xadj =
($table['border_spacing_H'] / 2);
$yadj =
($table['border_spacing_V'] / 2);
$wadj =
$table['border_spacing_H'];
$hadj =
$table['border_spacing_V'];
if ($i == $firstrow && $horf
== 'H') { // Top
$yadj +=
$table['padding']['T'] + $table['border_details']['T']['w'];
$hadj +=
$table['padding']['T'] + $table['border_details']['T']['w'];
}
if (($i == ($lastrow) ||
(isset($tablehf['rowspan']) && ($i + $tablehf['rowspan']) == ($lastrow + 1)) || (!
isset($tablehf['rowspan']) && ($i + 1) == ($lastrow + 1))) && $horf == 'F') { //
Bottom
$hadj +=
$table['padding']['B'] + $table['border_details']['B']['w'];
}
if ($colctr == 1) { // Left
$xadj +=
$table['padding']['L'] + $table['border_details']['L']['w'];
$wadj +=
$table['padding']['L'] + $table['border_details']['L']['w'];
}
if ($colctr ==
count($content[$i])) { // Right
$wadj +=
$table['padding']['R'] + $table['border_details']['R']['w'];
}
$this->SetFColor($color);
$this->Rect($x - $xadj, $y -
$yadj, $w + $wadj, $h + $hadj, 'F');
}
}
}
}
if ($table['empty_cells'] != 'hide' || !
empty($textbuffer) || !$table['borders_separate']) {
$paintcell = true;
} else {
$paintcell = false;
}
//Vertical align
if ($R && INTVAL($R) > 0 && isset($va) && $va != 'B')
{
$va = 'B';
}
/* -- BACKGROUNDS -- */
if (isset($tablehf['gradient']) &&
$tablehf['gradient'] && $paintcell) {
$g = $this->grad-
>parseBackgroundGradient($tablehf['gradient']);
if ($g) {
if ($table['borders_separate']) {
$px = $x +
($table['border_spacing_H'] / 2);
$py = $y +
($table['border_spacing_V'] / 2);
$pw = $w -
$table['border_spacing_H'];
$ph = $h -
$table['border_spacing_V'];
} else {
$px = $x;
$py = $y;
$pw = $w;
$ph = $h;
}
if ($this->ColActive) {
$this->grad->Gradient($px, $py,
$pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
} else {
$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' => '');
}
}
}
if (isset($tablehf['background-image']) &&
$paintcell) {
if ($tablehf['background-image']['gradient'] &&
preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $tablehf['background-
image']['gradient'])) {
$g = $this->grad-
>parseMozGradient($tablehf['background-image']['gradient']);
if ($g) {
if ($table['borders_separate']) {
$px = $x +
($table['border_spacing_H'] / 2);
$py = $y +
($table['border_spacing_V'] / 2);
$pw = $w -
$table['border_spacing_H'];
$ph = $h -
$table['border_spacing_V'];
} else {
$px = $x;
$py = $y;
$pw = $w;
$ph = $h;
}
if ($this->ColActive) {
$this->grad->Gradient($px,
$py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'],
$g['extend']);
} else {
$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' => '');
}
}
} elseif ($tablehf['background-image']
['image_id']) { // Background pattern
$n = count($this->patterns) + 1;
if ($table['borders_separate']) {
$px = $x +
($table['border_spacing_H'] / 2);
$py = $y +
($table['border_spacing_V'] / 2);
$pw = $w -
$table['border_spacing_H'];
$ph = $h -
$table['border_spacing_V'];
} else {
$px = $x;
$py = $y;
$pw = $w;
$ph = $h;
}
if ($this->ColActive) {
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']);
$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']);
if ($tablehf['background-image']
['opacity'] > 0 && $tablehf['background-image']['opacity'] < 1) {
$opac = $this-
>SetAlpha($tablehf['background-image']['opacity'], 'Normal', true);
} else {
$opac = '';
}
$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));
} else {
$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']);
}
}
}
/* -- END BACKGROUNDS -- */
//Cell Border
if ($table['borders_separate'] && $paintcell &&
$border) {
$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']);
} elseif ($paintcell && $border) {
$this->_tableRect($x, $y, $w, $h, $border,
$border_details, true, $table['borders_separate']); // true causes buffer
}
if ($R) {
$cellPtSize = $textbuffer[0][11] / $this-
>shrin_k;
if (!$cellPtSize) {
$cellPtSize = $this-
>default_font_size;
}
$cellFontHeight = ($cellPtSize / _MPDFK);
$opx = $this->x;
$opy = $this->y;
$angle = INTVAL($R);
// Only allow 45 - 90 degrees (when
bottom-aligned) or -90
if ($angle > 90) {
$angle = 90;
} elseif ($angle > 0 && (isset($va) &&
$va != 'B')) {
$angle = 90;
} elseif ($angle > 0 && $angle < 45) {
$angle = 45;
} elseif ($angle < 0) {
$angle = -90;
}
$offset = ((sin(deg2rad($angle))) * 0.37
* $cellFontHeight);
if (isset($align) && $align == 'R') {
$this->x += ($w) + ($offset) -
($cellFontHeight / 3) - ($padding['R'] + $border_details['R']['w']);
} elseif (!isset($align) || $align ==
'C') {
$this->x += ($w / 2) + ($offset);
} else {
$this->x += ($offset) +
($cellFontHeight / 3) + ($padding['L'] + $border_details['L']['w']);
}
$str = '';
foreach ($tablehf['textbuffer'] AS $t) {
$str .= $t[0] . ' ';
}
$str = rtrim($str);
$this->magic_reverse_dir($str, $this-
>directionality, $textbuffer[0][18]);
$this->Text($this->x, $this->y, $str,
$textbuffer[0][18], $textbuffer[0][8]); // textvar
$this->Rotate(0);
$this->SetFont($s_f, $s_st, $s_fs, true,
true);
$this->SetTColor(0);
$this->x = $opx;
$this->y = $opy;
} else {
if ($table['borders_separate']) { // NB
twice border width
$xadj = $border_details['L']['w'] +
$padding['L'] + ($table['border_spacing_H'] / 2);
$wadj = $border_details['L']['w'] +
$border_details['R']['w'] + $padding['L'] + $padding['R'] +
$table['border_spacing_H'];
$yadj = $border_details['T']['w'] +
$padding['T'] + ($table['border_spacing_H'] / 2);
} else {
$xadj = $border_details['L']['w'] /
2 + $padding['L'];
$wadj = ($border_details['L']['w']
+ $border_details['R']['w']) / 2 + $padding['L'] + $padding['R'];
$yadj = $border_details['T']['w'] /
2 + $padding['T'];
}
$this->divwidth = $w - ($wadj);
$this->x += $xadj;
$this->y += $yadj;
$this->printbuffer($textbuffer, '', true,
false, $direction);
}
}
$textbuffer = array();
/* -- BACKGROUNDS -- */
if (!$this->ColActive) {
if (isset($content[$i][0]['trgradients']) &&
($colctr == 1 || $table['borders_separate'])) {
$g = $this->grad-
>parseBackgroundGradient($content[$i][0]['trgradients']);
if ($g) {
$gx = $x0;
$gy = $y;
$gh = $h;
$gw = $table['w'] -
($table['max_cell_border_width']['L'] / 2) - ($table['max_cell_border_width']
['R'] / 2) - $table['margin']['L'] - $table['margin']['R'];
if ($table['borders_separate']) {
$gw -= ($table['padding']
['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] +
$table['border_details']['R']['w'] + $table['border_spacing_H']);
$clx = $x +
($table['border_spacing_H'] / 2);
$cly = $y +
($table['border_spacing_V'] / 2);
$clw = $w -
$table['border_spacing_H'];
$clh = $h -
$table['border_spacing_V'];
// Set clipping path
$s = $this-
>_setClippingPath($clx, $cly, $clw, $clh); // mPDF 6
$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);
} else {
$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' => '');
}
}
}
if (isset($content[$i][0]['trbackground-
images']) && ($colctr == 1 || $table['borders_separate'])) {
if ($content[$i][0]['trbackground-
images']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-
gradient/', $content[$i][0]['trbackground-images']['gradient'])) {
$g = $this->grad-
>parseMozGradient($content[$i][0]['trbackground-images']['gradient']);
if ($g) {
$gx = $x0;
$gy = $y;
$gh = $h;
$gw = $table['w'] -
($table['max_cell_border_width']['L'] / 2) - ($table['max_cell_border_width']
['R'] / 2) - $table['margin']['L'] - $table['margin']['R'];
if
($table['borders_separate']) {
$gw -=
($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']
['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
$clx = $x +
($table['border_spacing_H'] / 2);
$cly = $y +
($table['border_spacing_V'] / 2);
$clw = $w -
$table['border_spacing_H'];
$clh = $h -
$table['border_spacing_V'];
// Set clipping path
$s = $this-
>_setClippingPath($clx, $cly, $clw, $clh); // mPDF 6
$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);
} else {
$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' => '');
}
}
} else {
$image_id = $content[$i][0]
['trbackground-images']['image_id'];
$orig_w = $content[$i][0]
['trbackground-images']['orig_w'];
$orig_h = $content[$i][0]
['trbackground-images']['orig_h'];
$x_pos = $content[$i][0]
['trbackground-images']['x_pos'];
$y_pos = $content[$i][0]
['trbackground-images']['y_pos'];
$x_repeat = $content[$i][0]
['trbackground-images']['x_repeat'];
$y_repeat = $content[$i][0]
['trbackground-images']['y_repeat'];
$resize = $content[$i][0]
['trbackground-images']['resize'];
$opacity = $content[$i][0]
['trbackground-images']['opacity'];
$itype = $content[$i][0]
['trbackground-images']['itype'];
$clippath = '';
$gx = $x0;
$gy = $y;
$gh = $h;
$gw = $table['w'] -
($table['max_cell_border_width']['L'] / 2) - ($table['max_cell_border_width']
['R'] / 2) - $table['margin']['L'] - $table['margin']['R'];
if ($table['borders_separate']) {
$gw -= ($table['padding']
['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] +
$table['border_details']['R']['w'] + $table['border_spacing_H']);
$clx = $x +
($table['border_spacing_H'] / 2);
$cly = $y +
($table['border_spacing_V'] / 2);
$clw = $w -
$table['border_spacing_H'];
$clh = $h -
$table['border_spacing_V'];
// Set clipping path
$s = $this-
>_setClippingPath($clx, $cly, $clw, $clh); // mPDF 6
$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);
} else {
$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);
}
}
}
}
/* -- END BACKGROUNDS -- */
/* -- END TABLES -- */
$height = 0;
if (is_array($header) && isset($header['html']) && $header['html']) {
$Hhtml = $header['html'];
if ($this->setAutoTopMargin) {
if (isset($header['h'])) {
$height = $header['h'];
} else {
$height = $this->_gethtmlheight($Hhtml);
}
}
} elseif (!is_array($header) && $header) {
$Hhtml = $header;
if ($this->setAutoTopMargin) {
$height = $this->_gethtmlheight($Hhtml);
}
} else {
$Hhtml = '';
}
if ($OE != 'E') {
$OE = 'O';
}
if ($OE == 'E') {
if ($Hhtml) {
$this->HTMLHeaderE['html'] = $Hhtml;
$this->HTMLHeaderE['h'] = $height;
} else {
$this->HTMLHeaderE = '';
}
} else {
if ($Hhtml) {
$this->HTMLHeader['html'] = $Hhtml;
$this->HTMLHeader['h'] = $height;
} else {
$this->HTMLHeader = '';
}
}
if (!$this->mirrorMargins && $OE == 'E') {
return;
}
if ($Hhtml == '') {
return;
}
if ($this->setAutoTopMargin == 'pad') {
$this->tMargin = $this->margin_header + $height + $this-
>orig_tMargin;
if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) {
$this->saveHTMLHeader[$this->page][$OE]['mt'] = $this-
>tMargin;
}
} elseif ($this->setAutoTopMargin == 'stretch') {
$this->tMargin = max($this->orig_tMargin, $this->margin_header +
$height + $this->autoMarginPadding);
if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) {
$this->saveHTMLHeader[$this->page][$OE]['mt'] = $this-
>tMargin;
}
}
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();
}
}
if ($OE != 'E') {
$OE = 'O';
}
if ($OE == 'E') {
if ($Fhtml) {
$this->HTMLFooterE['html'] = $Fhtml;
$this->HTMLFooterE['h'] = $height;
} else {
$this->HTMLFooterE = '';
}
} else {
if ($Fhtml) {
$this->HTMLFooter['html'] = $Fhtml;
$this->HTMLFooter['h'] = $height;
} else {
$this->HTMLFooter = '';
}
}
if (!$this->mirrorMargins && $OE == 'E') {
return;
}
if ($Fhtml == '') {
return false;
}
if ($this->setAutoBottomMargin == 'pad') {
$this->bMargin = $this->margin_footer + $height + $this-
>orig_bMargin;
$this->PageBreakTrigger = $this->h - $this->bMargin;
if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) {
$this->saveHTMLHeader[$this->page][$OE]['mb'] = $this-
>bMargin;
}
} elseif ($this->setAutoBottomMargin == 'stretch') {
$this->bMargin = max($this->orig_bMargin, $this->margin_footer +
$height + $this->autoMarginPadding);
$this->PageBreakTrigger = $this->h - $this->bMargin;
if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) {
$this->saveHTMLHeader[$this->page][$OE]['mb'] = $this-
>bMargin;
}
}
}
function _getHtmlHeight($html)
{
$save_state = $this->state;
if ($this->state == 0) {
$this->AddPage($this->CurOrientation);
}
$this->state = 2;
$this->Reset();
$this->pageoutput[$this->page] = array();
$save_x = $this->x;
$save_y = $this->y;
$this->x = $this->lMargin;
$this->y = $this->margin_header;
$html = str_replace('{PAGENO}', $this->pagenumPrefix . $this-
>docPageNum($this->page) . $this->pagenumSuffix, $html);
$html = str_replace($this->aliasNbPgGp, $this->nbpgPrefix . $this-
>docPageNumTotal($this->page) . $this->nbpgSuffix, $html);
$html = str_replace($this->aliasNbPg, $this->page, $html);
$html = preg_replace_callback('/\{DATE\s+(.*?)\}/', array($this,
'date_callback'), $html); // mPDF 5.7
$this->HTMLheaderPageLinks = array();
$this->HTMLheaderPageAnnots = array();
$this->HTMLheaderPageForms = array();
$savepb = $this->pageBackgrounds;
$this->writingHTMLheader = true;
$this->WriteHTML($html, 4); // parameter 4 saves output to $this-
>headerbuffer
$this->writingHTMLheader = false;
$h = ($this->y - $this->margin_header);
$this->Reset();
// mPDF 5.7.2 - Clear in case Float used in Header/Footer
$this->blk[0]['blockContext'] = 0;
$this->blk[0]['float_endpos'] = 0;
$this->pageoutput[$this->page] = array();
$this->headerbuffer = '';
$this->pageBackgrounds = $savepb;
$this->x = $save_x;
$this->y = $save_y;
$this->state = $save_state;
if ($save_state == 0) {
unset($this->pages[1]);
$this->page = 0;
}
return $h;
}
function writeHTMLFooters()
{
// mPDF 6
function _shareHeaderFooterWidth($cl, $cc, $cr)
{ // mPDF 6
$l = mb_strlen($cl, 'UTF-8');
$c = mb_strlen($cc, 'UTF-8');
$r = mb_strlen($cr, 'UTF-8');
$s = max($l, $r);
$tw = $c + 2 * $s;
if ($tw > 0) {
return array(intval($s * 100 / $tw), intval($c * 100 / $tw),
intval($s * 100 / $tw));
} else {
return array(33, 33, 33);
}
}
// mPDF 6
// Create an HTML header/footer from array (non-HTML header/footer)
function _createHTMLheaderFooter($arr, $hf)
{
$lContent = (isset($arr['L']['content']) ? $arr['L']['content'] : '');
$cContent = (isset($arr['C']['content']) ? $arr['C']['content'] : '');
$rContent = (isset($arr['R']['content']) ? $arr['R']['content'] : '');
list($lw, $cw, $rw) = $this->_shareHeaderFooterWidth($lContent,
$cContent, $rContent);
if ($hf == 'H') {
$valign = 'bottom';
$vpadding = '0 0 ' . $this->header_line_spacing . 'em 0';
} else {
$valign = 'top';
$vpadding = '' . $this->footer_line_spacing . 'em 0 0 0';
}
if ($this->directionality == 'rtl') { // table columns get reversed so
need different text-alignment
$talignL = 'right';
$talignR = 'left';
} else {
$talignL = 'left';
$talignR = 'right';
}
$html = '<table width="100%" style="border-collapse: collapse; margin:
0; vertical-align: ' . $valign . '; color: #000000; ';
if (isset($arr['line']) && $arr['line']) {
$html .= ' border-' . $valign . ': 0.1mm solid #000000;';
}
$html .= '">';
$html .= '<tr>';
$html .= '<td width="' . $lw . '%" style="padding: ' . $vpadding . ';
text-align: ' . $talignL . '; ';
if (isset($arr['L']['font-family'])) {
$html .= ' font-family: ' . $arr['L']['font-family'] . ';';
}
if (isset($arr['L']['color'])) {
$html .= ' color: ' . $arr['L']['color'] . ';';
}
if (isset($arr['L']['font-size'])) {
$html .= ' font-size: ' . $arr['L']['font-size'] . 'pt;';
}
if (isset($arr['L']['font-style'])) {
if ($arr['L']['font-style'] == 'B' || $arr['L']['font-style'] ==
'BI') {
$html .= ' font-weight: bold;';
}
if ($arr['L']['font-style'] == 'I' || $arr['L']['font-style'] ==
'BI') {
$html .= ' font-style: italic;';
}
}
$html .= '">' . $lContent . '</td>';
$html .= '<td width="' . $cw . '%" style="padding: ' . $vpadding . ';
text-align: center; ';
if (isset($arr['C']['font-family'])) {
$html .= ' font-family: ' . $arr['C']['font-family'] . ';';
}
if (isset($arr['C']['color'])) {
$html .= ' color: ' . $arr['C']['color'] . ';';
}
if (isset($arr['C']['font-size'])) {
$html .= ' font-size: ' . $arr['L']['font-size'] . 'pt;';
}
if (isset($arr['C']['font-style'])) {
if ($arr['C']['font-style'] == 'B' || $arr['C']['font-style'] ==
'BI') {
$html .= ' font-weight: bold;';
}
if ($arr['C']['font-style'] == 'I' || $arr['C']['font-style'] ==
'BI') {
$html .= ' font-style: italic;';
}
}
$html .= '">' . $cContent . '</td>';
$html .= '<td width="' . $rw . '%" style="padding: ' . $vpadding . ';
text-align: ' . $talignR . '; ';
if (isset($arr['R']['font-family'])) {
$html .= ' font-family: ' . $arr['R']['font-family'] . ';';
}
if (isset($arr['R']['color'])) {
$html .= ' color: ' . $arr['R']['color'] . ';';
}
if (isset($arr['R']['font-size'])) {
$html .= ' font-size: ' . $arr['R']['font-size'] . 'pt;';
}
if (isset($arr['R']['font-style'])) {
if ($arr['R']['font-style'] == 'B' || $arr['R']['font-style'] ==
'BI') {
$html .= ' font-weight: bold;';
}
if ($arr['R']['font-style'] == 'I' || $arr['R']['font-style'] ==
'BI') {
$html .= ' font-style: italic;';
}
}
$html .= '">' . $rContent . '</td>';
$html .= '</tr></table>';
return $html;
}
function DefHeaderByName($name, $arr)
{
if (!$name) {
$name = '_nonhtmldefault';
}
$html = $this->_createHTMLheaderFooter($arr, 'H');
$this->pageHTMLheaders[$name]['html'] = $html;
$this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html);
}
$this->pageHTMLfooters[$name]['html'] = $html;
$this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html);
}
$this->pageHTMLheaders[$name]['html'] = $html;
$this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html);
}
$this->pageHTMLfooters[$name]['html'] = $html;
$this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html);
}
function SetHTMLHeaderByName($name, $side = 'O', $write = false)
{
if (!$name) {
$name = '_default';
}
$this->SetHTMLHeader($this->pageHTMLheaders[$name], $side, $write);
}
if ($side == 'E') {
$this->SetHTMLHeader($evenhtml, 'E', $write);
} elseif ($side == 'O') {
$this->SetHTMLHeader($oddhtml, 'O', $write);
} else {
$this->SetHTMLHeader($oddhtml, 'O', $write);
$this->SetHTMLHeader($evenhtml, 'E', $write);
}
}
if (isset($odd))
$oddhtml = $this->_createHTMLheaderFooter($odd, 'F');
if (isset($even))
$evenhtml = $this->_createHTMLheaderFooter($even, 'F');
}
/* -- HTMLfooterS-FOOTERS -- */
if ($side == 'E') {
$this->SetHTMLfooter($evenhtml, 'E');
} elseif ($side == 'O') {
$this->SetHTMLfooter($oddhtml, 'O');
} else {
$this->SetHTMLfooter($oddhtml, 'O');
$this->SetHTMLfooter($evenhtml, 'E');
}
/* -- END HTMLfooterS-FOOTERS -- */
}
/* -- WATERMARK -- */
/* -- END WATERMARK -- */
//Page footer
function Footer()
{
/* -- CSS-PAGE -- */
// PAGED MEDIA - CROP / CROSS MARKS from @PAGE
if ($this->show_marks == 'CROP' || $this->show_marks == 'CROPCROSS') {
// Show TICK MARKS
$this->SetLineWidth(0.1); // = 0.1 mm
$this->SetDColor($this->ConvertColor(0));
$l = $this->cropMarkLength;
$m = $this->cropMarkMargin; // Distance of crop mark from margin
$b = $this->nonPrintMargin; // Non-printable border at edge of
paper sheet
$ax1 = $b;
$bx = $this->page_box['outer_width_LR'] - $m;
$ax = max($ax1, $bx - $l);
$cx1 = $this->w - $b;
$dx = $this->w - $this->page_box['outer_width_LR'] + $m;
$cx = min($cx1, $dx + $l);
$ay1 = $b;
$by = $this->page_box['outer_width_TB'] - $m;
$ay = max($ay1, $by - $l);
$cy1 = $this->h - $b;
$dy = $this->h - $this->page_box['outer_width_TB'] + $m;
$cy = min($cy1, $dy + $l);
if ($this->printers_info) {
$hd = date('Y-m-d H:i') . ' Page ' . $this->page . ' of
{nb}';
$this->SetTColor($this->ConvertColor(0));
$this->SetFont('arial', '', 7.5, true, true);
$this->x = $this->page_box['outer_width_LR'] + 1.5;
$this->y = 1;
$this->Cell($headerpgwidth, $this->FontSize, $hd, 0, 0,
'L', 0, '', 0, 0, 0, 'M');
$this->SetFont($this->default_font, '', $this-
>original_default_font_size);
}
}
if ($this->show_marks == 'CROSS' || $this->show_marks == 'CROPCROSS') {
$this->SetLineWidth(0.1); // = 0.1 mm
$this->SetDColor($this->ConvertColor(0));
$l = 14 / 2; // longer length of the cross line (half)
$w = 6 / 2; // shorter width of the cross line (half)
$r = 1.2; // radius of circle
$m = $this->crossMarkMargin; // Distance of cross mark from
margin
$x1 = $this->page_box['outer_width_LR'] - $m;
$x2 = $this->w - $this->page_box['outer_width_LR'] + $m;
$y1 = $this->page_box['outer_width_TB'] - $m;
$y2 = $this->h - $this->page_box['outer_width_TB'] + $m;
// Left
$this->Circle($x1, $this->h / 2, $r, 'S');
$this->Line($x1 - $w, $this->h / 2, $x1 + $w, $this->h / 2);
$this->Line($x1, $this->h / 2 - $l, $x1, $this->h / 2 + $l);
// Right
$this->Circle($x2, $this->h / 2, $r, 'S');
$this->Line($x2 - $w, $this->h / 2, $x2 + $w, $this->h / 2);
$this->Line($x2, $this->h / 2 - $l, $x2, $this->h / 2 + $l);
// Top
$this->Circle($this->w / 2, $y1, $r, 'S');
$this->Line($this->w / 2, $y1 - $w, $this->w / 2, $y1 + $w);
$this->Line($this->w / 2 - $l, $y1, $this->w / 2 + $l, $y1);
// Bottom
$this->Circle($this->w / 2, $y2, $r, 'S');
$this->Line($this->w / 2, $y2 - $w, $this->w / 2, $y2 + $w);
$this->Line($this->w / 2 - $l, $y2, $this->w / 2 + $l, $y2);
}
/* -- END CSS-PAGE -- */
// mPDF 6
// If @page set non-HTML headers/footers named, they were not read
until later in the HTML code - so now set them
if ($this->page == 1) {
if ($this->firstPageBoxHeader) {
if (isset($this->pageHTMLheaders[$this-
>firstPageBoxHeader])) {
$this->HTMLHeader = $this->pageHTMLheaders[$this-
>firstPageBoxHeader];
}
$this->Header();
}
if ($this->firstPageBoxFooter) {
if (isset($this->pageHTMLfooters[$this-
>firstPageBoxFooter])) {
$this->HTMLFooter = $this->pageHTMLfooters[$this-
>firstPageBoxFooter];
}
}
$this->firstPageBoxHeader = '';
$this->firstPageBoxFooter = '';
}
/* -- WATERMARK -- */
if (($this->watermarkText) && ($this->showWatermarkText)) {
$this->watermark($this->watermarkText, 45, 120, $this-
>watermarkTextAlpha); // Watermark text
}
if (($this->watermarkImage) && ($this->showWatermarkImage)) {
$this->watermarkImg($this->watermarkImage, $this-
>watermarkImageAlpha); // Watermark image
}
/* -- END WATERMARK -- */
}
/* -- HYPHENATION -- */
///////////////////
///////////////////
// HYPHENATION
///////////////////
///////////////////
// Word hyphenation
// mPDF 6
function hyphenateWord($word, $currptr)
{
// Do everything inside this function in utf-8
// Don't hyphenate web addresses
if (preg_match('/^(http:|www\.)/', $word)) {
return -1;
}
$ptr = -1;
// Get dictionary
if (!$this->loadedSHYdictionary) {
if (file_exists(_MPDF_PATH . 'patterns/dictionary.txt')) {
$this->SHYdictionary = file(_MPDF_PATH .
'patterns/dictionary.txt', FILE_SKIP_EMPTY_LINES);
foreach ($this->SHYdictionary as $entry) {
$entry = trim($entry);
$poss = array();
$offset = 0;
$p = true;
$wl = mb_strlen($entry, 'UTF-8');
while ($offset < $wl) {
$p = mb_strpos($entry, '/', $offset, 'UTF-8');
if ($p !== false) {
$poss[] = $p - count($poss);
} else {
break;
}
$offset = $p + 1;
}
if (count($poss)) {
$this->SHYdictionaryWords[str_replace('/', '',
mb_strtolower($entry))] = $poss;
}
}
}
$this->loadedSHYdictionary = true;
}
if (!in_array($this->SHYlang, $this->SHYlanguages)) {
return -1;
}
// If no pattern loaded or not the best one
if (count($this->SHYpatterns) < 1 || ($this->loadedSHYpatterns &&
$this->loadedSHYpatterns != $this->SHYlang)) {
include(_MPDF_PATH . "patterns/" . $this->SHYlang . ".php");
$patterns = explode(' ', $patterns);
$new_patterns = array();
for ($i = 0; $i < count($patterns); $i++) {
$value = $patterns[$i];
$new_patterns[preg_replace('/[0-9]/', '', $value)] =
$value;
}
$this->SHYpatterns = $new_patterns;
$this->loadedSHYpatterns = $this->SHYlang;
}
if ($this->usingCoreFont) {
$word = mb_convert_encoding($word, 'UTF-8', $this->mb_enc);
}
$prepre = '';
$postpost = '';
$startpunctuation =
"\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f";
$endpunctuation =
"\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb";
$preprelen = mb_strlen($prepre);
if (isset($this->SHYdictionaryWords[mb_strtolower($word)])) {
foreach ($this->SHYdictionaryWords[mb_strtolower($word)] AS $i) {
if (($i + $preprelen) >= $currptr) {
break;
}
$ptr = $i + $preprelen;
$success = true;
}
}
if (!$success) {
$text_word = '_' . $word . '_';
$word_length = mb_strlen($text_word, 'UTF-8');
$text_word = mb_strtolower($text_word, 'UTF-8');
$hyphenated_word = array();
$numb3rs = array('0' => true, '1' => true, '2' => true, '3' =>
true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' =>
true);
for ($position = 0; $position <= ($word_length - $this-
>SHYcharmin); $position++) {
$maxwins = min(($word_length - $position), $this-
>SHYcharmax);
for ($win = $this->SHYcharmin; $win <= $maxwins; $win++) {
if (isset($this->SHYpatterns[mb_substr($text_word,
$position, $win, 'UTF-8')])) {
$pattern = $this-
>SHYpatterns[mb_substr($text_word, $position, $win, 'UTF-8')];
$digits = 1;
$pattern_length = mb_strlen($pattern, 'UTF-8');
for ($i = 0; $i < $pattern_length; $i++) {
$char = $pattern[$i];
if (isset($numb3rs[$char])) {
$zero = ($i == 0) ? $position - 1 :
$position + $i - $digits;
if (!isset($hyphenated_word[$zero])
|| $hyphenated_word[$zero] != $char)
$hyphenated_word[$zero] =
$char;
$digits++;
}
}
}
}
}
for ($i = $this->SHYleftmin; $i <= (mb_strlen($word, 'UTF-8') -
$this->SHYrightmin); $i++) {
if (isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2
!= 0) {
if (($i + $preprelen) > $currptr) {
break;
}
$ptr = $i + $preprelen;
}
}
}
return $ptr;
}
/* -- END HYPHENATION -- */
/* -- HTML-CSS -- */
///////////////////
/// HTML parser ///
///////////////////
function WriteHTML($html, $sub = 0, $init = true, $close = true)
{
// $sub - 0 = default; 1=headerCSS only; 2=HTML body (parts) only; 3 -
HTML parses only
// 4 - writes HTML headers/Fixed pos DIVs - stores in buffer - for
single page only
// $close - if false Leaves buffers etc. in current state, so that it
can continue a block etc.
// $init - Clears and sets buffers to Top level block etc.
if ($this->progressBar) {
$this->UpdateProgressBar(1, 0, 'Parsing CSS & Headers');
} // *PROGRESS-BAR*
if ($init) {
$this->headerbuffer = '';
$this->textbuffer = array();
$this->fixedPosBlockSave = array();
}
if ($sub == 1) {
$html = '<style> ' . $html . ' </style>';
} // stylesheet only
if ($this->allow_charset_conversion) {
if ($sub < 1) {
$this->ReadCharset($html);
}
if ($this->charset_in && $sub != 4) {
$success = iconv($this->charset_in, 'UTF-8//TRANSLIT',
$html);
if ($success) {
$html = $success;
}
}
}
$html = $this->purify_utf8($html, false);
if ($init) {
$this->blklvl = 0;
$this->lastblocklevelchange = 0;
$this->blk = array();
$this->initialiseBlock($this->blk[0]);
$this->blk[0]['width'] = & $this->pgwidth;
$this->blk[0]['inner_width'] = & $this->pgwidth;
$this->blk[0]['blockContext'] = $this->blockContext;
}
$zproperties = array();
if ($sub < 2) {
$this->ReadMetaTags($html);
if (preg_match('/<base[^>]*href=["\']([^"\'>]*)["\']/i', $html,
$m)) {
$this->SetBasePath($m[1]);
}
$html = $this->cssmgr->ReadCSS($html);
if (preg_match('/<html [^>]*dir=[\'\"]\s*rtl\s*[\'\"]/ism',
$html)) {
$zproperties['DIRECTION'] = 'rtl';
}
// allow in-line CSS for body tag to be parsed // Get <body> tag
inline CSS
if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism', $html, $m) ||
preg_match('/<body([^>]*)>(.*)$/ism', $html, $m)) {
$html = $m[2];
// Changed to allow style="background: url('bg.jpg')"
if (preg_match('/style=[\"](.*?)[\"]/ism', $m[1], $mm) ||
preg_match('/style=[\'](.*?)[\']/ism', $m[1], $mm)) {
$zproperties = $this->cssmgr->readInlineCSS($mm[1]);
}
if (preg_match('/dir=[\'\"]\s*rtl\s*[\'\"]/ism', $m[1])) {
$zproperties['DIRECTION'] = 'rtl';
}
if (isset($html_lang) && $html_lang) {
$zproperties['LANG'] = $html_lang;
}
if ($this->autoLangToFont && !$this->onlyCoreFonts &&
preg_match('/lang=[\'\"](.*?)[\'\"]/ism', $m[1], $mm)) {
$zproperties['LANG'] = $mm[1];
}
}
}
$properties = $this->cssmgr->MergeCSS('BLOCK', 'BODY', '');
if ($zproperties) {
$properties = $this->cssmgr-
>array_merge_recursive_unique($properties, $zproperties);
}
$this->blk[0]['InlineProperties'] = $this->saveInlineProperties();
if ($sub == 1) {
return '';
}
if (!isset($this->cssmgr->CSS['BODY'])) {
$this->cssmgr->CSS['BODY'] = array();
}
/* -- BACKGROUNDS -- */
if (isset($properties['BACKGROUND-GRADIENT'])) {
$this->bodyBackgroundGradient = $properties['BACKGROUND-
GRADIENT'];
}
/* -- CSS-PAGE -- */
// If page-box is set
if ($this->state == 0 && ((isset($this->cssmgr->CSS['@PAGE']) && $this-
>cssmgr->CSS['@PAGE']) || (isset($this->cssmgr->CSS['@PAGE>>PSEUDO>>FIRST']) &&
$this->cssmgr->CSS['@PAGE>>PSEUDO>>FIRST']))) { // mPDF 5.7.3
$this->page_box['current'] = '';
$this->page_box['using'] = true;
list($pborientation, $pbmgl, $pbmgr, $pbmgt, $pbmgb, $pbmgh,
$pbmgf, $hname, $fname, $bg, $resetpagenum, $pagenumstyle, $suppress, $marks,
$newformat) = $this->SetPagedMediaCSS('', false, 'O');
$this->DefOrientation = $this->CurOrientation = $pborientation;
$this->orig_lMargin = $this->DeflMargin = $pbmgl;
$this->orig_rMargin = $this->DefrMargin = $pbmgr;
$this->orig_tMargin = $this->tMargin = $pbmgt;
$this->orig_bMargin = $this->bMargin = $pbmgb;
$this->orig_hMargin = $this->margin_header = $pbmgh;
$this->orig_fMargin = $this->margin_footer = $pbmgf;
list($pborientation, $pbmgl, $pbmgr, $pbmgt, $pbmgb, $pbmgh,
$pbmgf, $hname, $fname, $bg, $resetpagenum, $pagenumstyle, $suppress, $marks,
$newformat) = $this->SetPagedMediaCSS('', true, 'O'); // first page
$this->show_marks = $marks;
if ($hname)
$this->firstPageBoxHeader = $hname;
if ($fname)
$this->firstPageBoxFooter = $fname;
}
/* -- END CSS-PAGE -- */
$parseonly = false;
$this->bufferoutput = false;
if ($sub == 3) {
$parseonly = true;
// Close any open block tags
$arr = array();
$ai = 0;
for ($b = $this->blklvl; $b > 0; $b--) {
$this->tag->CloseTag($this->blk[$b]['tag'], $arr, $ai);
}
// Output any text left in buffer
if (count($this->textbuffer)) {
$this->printbuffer($this->textbuffer);
}
$this->textbuffer = array();
} elseif ($sub == 4) {
// Close any open block tags
$arr = array();
$ai = 0;
for ($b = $this->blklvl; $b > 0; $b--) {
$this->tag->CloseTag($this->blk[$b]['tag'], $arr, $ai);
}
// Output any text left in buffer
if (count($this->textbuffer)) {
$this->printbuffer($this->textbuffer);
}
$this->bufferoutput = true;
$this->textbuffer = array();
$this->headerbuffer = '';
$properties = $this->cssmgr->MergeCSS('BLOCK', 'BODY', '');
$this->setCSS($properties, '', 'BODY');
}
mb_internal_encoding('UTF-8');
if ($this->autoScriptToLang) {
$html = $this->markScriptToLang($html);
}
preg_match_all('/<htmlpageheader([^>]*)>(.*?)<\/htmlpageheader>/si',
$html, $h);
for ($i = 0; $i < count($h[1]); $i++) {
if (preg_match('/name=[\'|\"](.*?)[\'|\"]/', $h[1][$i], $n)) {
$this->pageHTMLheaders[$n[1]]['html'] = $h[2][$i];
$this->pageHTMLheaders[$n[1]]['h'] = $this-
>_gethtmlheight($h[2][$i]);
}
}
preg_match_all('/<htmlpagefooter([^>]*)>(.*?)<\/htmlpagefooter>/si',
$html, $f);
for ($i = 0; $i < count($f[1]); $i++) {
if (preg_match('/name=[\'|\"](.*?)[\'|\"]/', $f[1][$i], $n)) {
$this->pageHTMLfooters[$n[1]]['html'] = $f[2][$i];
$this->pageHTMLfooters[$n[1]]['h'] = $this-
>_gethtmlheight($f[2][$i]);
}
}
$html = str_replace('<?', '< ', $html); //Fix '<?XML' bug from HTML
code generated by MS Word
$this->checkSIP = false;
$this->checkSMP = false;
$this->checkCJK = false;
if ($this->onlyCoreFonts) {
$html = $this->SubstituteChars($html);
} else {
if (preg_match("/([" . $this->pregRTLchars . "])/u", $html)) {
$this->biDirectional = true;
} // *OTL*
if (preg_match("/([\x{20000}-\x{2FFFF}])/u", $html)) {
$this->checkSIP = true;
}
if (preg_match("/([\x{10000}-\x{1FFFF}])/u", $html)) {
$this->checkSMP = true;
}
/* -- CJK-FONTS -- */
if (preg_match("/([" . $this->pregCJKchars . "])/u", $html)) {
$this->checkCJK = true;
}
/* -- END CJK-FONTS -- */
}
if ($this->mb_enc) {
mb_internal_encoding($this->mb_enc);
}
$pbc = 0;
if ($this->progressBar) {
$this->UpdateProgressBar(1, 0);
} // *PROGRESS-BAR*
$this->subPos = -1;
$cnt = count($a);
for ($i = 0; $i < $cnt; $i++) {
$e = $a[$i];
if ($i % 2 == 0) {
//TEXT
if ($this->blk[$this->blklvl]['hide']) {
continue;
}
if ($this->inlineDisplayOff) {
continue;
}
if ($this->inMeter) {
continue;
}
if ($this->inFixedPosBlock) {
$this->fixedPosBlock .= $e;
continue;
} // *CSS-POSITION*
if (strlen($e) == 0) {
continue;
}
$e = strcode2utf($e);
$e = $this->lesser_entity_decode($e);
if ($this->usingCoreFont) {
// If core font is selected in document which is not
onlyCoreFonts - substitute with non-core font
if ($this->useSubstitutions && !$this->onlyCoreFonts
&& $this->subPos < $i && !$this->specialcontent) {
$cnt += $this->SubstituteCharsNonCore($a, $i,
$e);
}
// CONVERT ENCODING
$e = mb_convert_encoding($e, $this->mb_enc, 'UTF-8');
if ($this->textvar & FT_UPPERCASE) {
$e = mb_strtoupper($e, $this->mb_enc);
} // mPDF 5.7.1
elseif ($this->textvar & FT_LOWERCASE) {
$e = mb_strtolower($e, $this->mb_enc);
} // mPDF 5.7.1
elseif ($this->textvar & FT_CAPITALIZE) {
$e = mb_convert_case($e, MB_CASE_TITLE, "UTF-
8");
} // mPDF 5.7.1
} else {
if ($this->checkSIP && $this->CurrentFont['sipext']
&& $this->subPos < $i && (!$this->specialcontent || !$this->useActiveForms)) {
$cnt += $this->SubstituteCharsSIP($a, $i, $e);
}
/* -- OTL -- */
// Use OTL OpenType Table Layout - GSUB & GPOS
if (isset($this->CurrentFont['useOTL']) && $this-
>CurrentFont['useOTL'] && (!$this->specialcontent || !$this->useActiveForms)) {
$e = $this->otl->applyOTL($e, $this-
>CurrentFont['useOTL']);
$this->OTLdata = $this->otl->OTLdata;
$this->otl->removeChar($e, $this->OTLdata,
"\xef\xbb\xbf"); // Remove ZWNBSP (also Byte order mark FEFF)
}
/* -- END OTL -- */ else { // *OTL*
// removes U+200E/U+200F LTR and RTL mark and
U+200C/U+200D Zero-width Joiner and Non-joiner
$e = preg_replace("/
[\xe2\x80\x8c\xe2\x80\x8d\xe2\x80\x8e\xe2\x80\x8f]/u", '', $e);
$e = preg_replace("/[\xef\xbb\xbf]/u", '', $e);
// Remove ZWNBSP (also Byte order mark FEFF)
} // *OTL*
}
if (($this->tts) || ($this->ttz) || ($this->tta)) {
$es = explode('|', $e);
$e = '';
foreach ($es AS $val) {
$e .= chr($val);
}
}
// FORM ELEMENTS
if ($this->specialcontent) {
/* -- FORMS -- */
//SELECT tag (form element)
if ($this->specialcontent == "type=select") {
$e = ltrim($e);
if (!empty($this->OTLdata)) {
$this->otl->trimOTLdata($this->OTLdata,
true, false);
} // *OTL*
$stringwidth = $this->GetStringWidth($e);
if (!isset($this->selectoption['MAXWIDTH']) ||
$stringwidth > $this->selectoption['MAXWIDTH']) {
$this->selectoption['MAXWIDTH'] =
$stringwidth;
}
if (!isset($this->selectoption['SELECTED']) ||
$this->selectoption['SELECTED'] == '') {
$this->selectoption['SELECTED'] = $e;
if (!empty($this->OTLdata)) {
$this->selectoption['SELECTED-
OTLDATA'] = $this->OTLdata;
} // *OTL*
}
// Active Forms
if (isset($this->selectoption['ACTIVE']) &&
$this->selectoption['ACTIVE']) {
$this->selectoption['ITEMS'][] =
array('exportValue' => $this->selectoption['currentVAL'], 'content' => $e,
'selected' => $this->selectoption['currentSEL']);
}
$this->OTLdata = array();
}
// TEXTAREA
else {
$objattr = unserialize($this->specialcontent);
$objattr['text'] = $e;
$objattr['OTLdata'] = $this->OTLdata;
$this->OTLdata = array();
$te = "\xbb\xa4\xactype=textarea,objattr=" .
serialize($objattr) . "\xbb\xa4\xac";
if ($this->tdbegin) {
$this->_saveCellTextBuffer($te, $this-
>HREF);
} else {
$this->_saveTextBuffer($te, $this->HREF);
}
}
/* -- END FORMS -- */
}
// TABLE
elseif ($this->tableLevel) {
/* -- TABLES -- */
if ($this->tdbegin) {
if (($this->ignorefollowingspaces) && !$this-
>ispre) {
$e = ltrim($e);
if (!empty($this->OTLdata)) {
$this->otl->trimOTLdata($this-
>OTLdata, true, false);
} // *OTL*
}
if ($e || $e === '0') {
if ($this->blockjustfinished && $this-
>cell[$this->row][$this->col]['s'] > 0) {
$this->_saveCellTextBuffer("\n");
if (!isset($this->cell[$this->row]
[$this->col]['maxs'])) {
$this->cell[$this->row]
[$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
} elseif ($this->cell[$this->row]
[$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
$this->cell[$this->row]
[$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
}
$this->cell[$this->row][$this->col]
['s'] = 0; // reset
}
$this->blockjustfinished = false;
if (!isset($this->cell[$this->row][$this-
>col]['R']) || !$this->cell[$this->row][$this->col]['R']) {
if (isset($this->cell[$this->row]
[$this->col]['s'])) {
$this->cell[$this->row]
[$this->col]['s'] += $this->GetStringWidth($e, false, $this->OTLdata, $this-
>textvar);
} else {
$this->cell[$this->row]
[$this->col]['s'] = $this->GetStringWidth($e, false, $this->OTLdata, $this-
>textvar);
}
if (!empty($this->spanborddet)) {
$this->cell[$this->row]
[$this->col]['s'] += (isset($this->spanborddet['L']['w']) ? $this->spanborddet['L']
['w'] : 0) + (isset($this->spanborddet['R']['w']) ? $this->spanborddet['R']['w'] :
0);
}
}
$this->_saveCellTextBuffer($e, $this-
>HREF);
if (substr($this->cell[$this->row][$this-
>col]['a'], 0, 1) == 'D') {
$dp = $this-
>decimal_align[substr($this->cell[$this->row][$this->col]['a'], 0, 2)];
$s = preg_split('/' .
preg_quote($dp, '/') . '/', $e, 2); // ? needs to be /u if not core
$s0 = $this->GetStringWidth($s[0],
false);
if (isset($s[1]) && $s[1]) {
$s1 = $this-
>GetStringWidth(($s[1] . $dp), false);
} else
$s1 = 0;
if (!isset($this->table[$this-
>tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]
['maxs0'])) {
$this->table[$this-
>tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs0']
= $s0;
} else {
$this->table[$this-
>tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs0']
= max($s0, $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]
['decimal_align'][$this->col]['maxs0']);
}
if (!isset($this->table[$this-
>tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]
['maxs1'])) {
$this->table[$this-
>tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs1']
= $s1;
} else {
$this->table[$this-
>tableLevel][$this->tbctr[$this->tableLevel]]['decimal_align'][$this->col]['maxs1']
= max($s1, $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]
['decimal_align'][$this->col]['maxs1']);
}
}
/* -- CSS-POSITION -- */
// mPDF 6
if ($this->inFixedPosBlock) {
if (in_array($endtag, $this->outerblocktags) ||
in_array($endtag, $this->innerblocktags)) {
$this->fixedPosBlockDepth--;
}
if ($this->fixedPosBlockDepth == 0) {
$this->fixedPosBlockSave[] = array($this-
>fixedPosBlock, $this->fixedPosBlockBBox, $this->page);
$this->fixedPosBlock = '';
$this->inFixedPosBlock = false;
continue;
}
$this->fixedPosBlock .= '<' . $e . '>';
continue;
}
/* -- END CSS-POSITION -- */
// mPDF 6
// Correct for tags where HTML5 specifies optional
end tags (see also OpenTag() )
if ($this->allow_html_optional_endtags && !
$parseonly) {
if (isset($this->blk[$this->blklvl]['tag'])) {
$closed = false;
// li end tag may be omitted if there is
no more content in the parent element
if (!$closed && $this->blk[$this->blklvl]
['tag'] == 'LI' && $endtag != 'LI' && (in_array($endtag, $this->outerblocktags) ||
in_array($endtag, $this->innerblocktags))) {
$this->tag->CloseTag('LI', $a, $i);
$closed = true;
}
// dd end tag may be omitted if there is
no more content in the parent element
if (!$closed && $this->blk[$this->blklvl]
['tag'] == 'DD' && $endtag != 'DD' && (in_array($endtag, $this->outerblocktags) ||
in_array($endtag, $this->innerblocktags))) {
$this->tag->CloseTag('DD', $a, $i);
$closed = true;
}
// p end tag may be omitted if there is
no more content in the parent element and the parent element is not an A element
[??????]
if (!$closed && $this->blk[$this->blklvl]
['tag'] == 'P' && $endtag != 'P' && (in_array($endtag, $this->outerblocktags) ||
in_array($endtag, $this->innerblocktags))) {
$this->tag->CloseTag('P', $a, $i);
$closed = true;
}
// option end tag may be omitted if there
is no more content in the parent element
if (!$closed && $this->blk[$this->blklvl]
['tag'] == 'OPTION' && $endtag != 'OPTION' && (in_array($endtag, $this-
>outerblocktags) || in_array($endtag, $this->innerblocktags))) {
$this->tag->CloseTag('OPTION', $a,
$i);
$closed = true;
}
}
/* -- TABLES -- */
// Check for Table tags where HTML specifies
optional end tags,
if ($endtag == 'TABLE') {
if ($this->lastoptionaltag == 'THEAD' ||
$this->lastoptionaltag == 'TBODY' || $this->lastoptionaltag == 'TFOOT') {
$this->tag->CloseTag($this-
>lastoptionaltag, $a, $i);
}
if ($this->lastoptionaltag == 'TR') {
$this->tag->CloseTag('TR', $a, $i);
}
if ($this->lastoptionaltag == 'TD' ||
$this->lastoptionaltag == 'TH') {
$this->tag->CloseTag($this-
>lastoptionaltag, $a, $i);
$this->tag->CloseTag('TR', $a, $i);
}
}
if ($endtag == 'THEAD' || $endtag == 'TBODY' ||
$endtag == 'TFOOT') {
if ($this->lastoptionaltag == 'TR') {
$this->tag->CloseTag('TR', $a, $i);
}
if ($this->lastoptionaltag == 'TD' ||
$this->lastoptionaltag == 'TH') {
$this->tag->CloseTag($this-
>lastoptionaltag, $a, $i);
$this->tag->CloseTag('TR', $a, $i);
}
}
if ($endtag == 'TR') {
if ($this->lastoptionaltag == 'TD' ||
$this->lastoptionaltag == 'TH') {
$this->tag->CloseTag($this-
>lastoptionaltag, $a, $i);
}
}
/* -- END TABLES -- */
}
// mPDF 6
if ($this->blk[$this->blklvl]['hide']) {
if (in_array($endtag, $this->outerblocktags) ||
in_array($endtag, $this->innerblocktags)) {
unset($this->blk[$this->blklvl]);
$this->blklvl--;
}
continue;
}
// mPDF 6
$this->tag->CloseTag($endtag, $a, $i); // mPDF 6
} else { // OPENING TAG
if ($this->blk[$this->blklvl]['hide']) {
if (strpos($e, ' ')) {
$te = strtoupper(substr($e, 0, strpos($e,
' ')));
} else {
$te = strtoupper($e);
}
// mPDF 6
if ($te == 'THEAD' || $te == 'TBODY' || $te ==
'TFOOT' || $te == 'TR' || $te == 'TD' || $te == 'TH') {
$this->lastoptionaltag = $te;
}
if (in_array($te, $this->outerblocktags) ||
in_array($te, $this->innerblocktags)) {
$this->blklvl++;
$this->blk[$this->blklvl]['hide'] = true;
$this->blk[$this->blklvl]['tag'] =
$te; // mPDF 6
}
continue;
}
/* -- CSS-POSITION -- */
if ($this->inFixedPosBlock) {
if (strpos($e, ' ')) {
$te = strtoupper(substr($e, 0, strpos($e,
' ')));
} else {
$te = strtoupper($e);
}
$this->fixedPosBlock .= '<' . $e . '>';
if (in_array($te, $this->outerblocktags) ||
in_array($te, $this->innerblocktags)) {
$this->fixedPosBlockDepth++;
}
continue;
}
/* -- END CSS-POSITION -- */
$regexp = '|=\'(.*?)\'|s'; // eliminate single
quotes, if any
$e = preg_replace($regexp, "=\"\$1\"", $e);
// changes anykey=anyvalue to anykey="anyvalue" (only
do this inside [some] tags)
if (substr($e, 0, 10) != 'pageheader' && substr($e,
0, 10) != 'pagefooter' && substr($e, 0, 12) != 'tocpagebreak' && substr($e, 0,
10) != 'indexentry' && substr($e, 0, 8) != 'tocentry') { // mPDF 6 (ZZZ99H)
$regexp = '| (\\w+?)=([^\\s>"]+)|si';
$e = preg_replace($regexp, " \$1=\"\$2\"", $e);
}
$e = preg_replace('/ (\\S+?)\s*=\s*"/i', " \\1=\"",
$e);
if ($close) {
/* -- CSS-FLOAT -- */
// If ended with a float, need to move to end page
$currpos = $this->page * 1000 + $this->y;
if (isset($this->blk[$this->blklvl]['float_endpos']) && $this-
>blk[$this->blklvl]['float_endpos'] > $currpos) {
$old_page = $this->page;
$new_page = intval($this->blk[$this->blklvl]
['float_endpos'] / 1000);
if ($old_page != $new_page) {
$s = $this->PrintPageBackgrounds();
// Writes after the marker so not overwritten later
by page background etc.
$this->pages[$this->page] = preg_replace('/
(___BACKGROUND___PATTERNS' . $this->uniqstr . ')/', '\\1' . "\n" . $s . "\n",
$this->pages[$this->page]);
$this->pageBackgrounds = array();
$this->page = $new_page;
$this->ResetMargins();
$this->Reset();
$this->pageoutput[$this->page] = array();
}
$this->y = (($this->blk[$this->blklvl]['float_endpos'] *
1000) % 1000000) / 1000; // mod changes operands to integers before processing
}
/* -- END CSS-FLOAT -- */
/* -- CSS-IMAGE-FLOAT -- */
$this->printfloatbuffer();
/* -- END CSS-IMAGE-FLOAT -- */
$this->bufferoutput = false;
/* -- CSS-POSITION -- */
if (count($this->fixedPosBlockSave) && $sub != 4) {
foreach ($this->fixedPosBlockSave AS $fpbs) {
$old_page = $this->page;
$this->page = $fpbs[2];
$this->WriteFixedPosHTML($fpbs[0], 0, 0, 100, 100,
'auto', $fpbs[1]); // 0,0,10,10 are overwritten by bbox
$this->page = $old_page;
}
$this->fixedPosBlockSave = array();
}
/* -- END CSS-POSITION -- */
}
}
/* -- CSS-POSITION -- */
$overflow = strtolower($overflow);
if ($this->state == 0) {
$this->AddPage($this->CurOrientation);
}
$save_y = $this->y;
$save_x = $this->x;
$this->fullImageHeight = $this->h;
$save_cols = false;
/* -- COLUMNS -- */
if ($this->ColActive) {
$save_cols = true;
$save_nbcol = $this->NbCol; // other values of gap and vAlign
will not change by setting Columns off
$this->SetColumns(0);
}
/* -- END COLUMNS -- */
$save_annots = $this->title2annots; // *ANNOTATIONS*
$this->writingHTMLheader = true; // a FIX to stop pagebreaks etc.
$this->writingHTMLfooter = true;
$this->InFooter = true; // suppresses autopagebreaks
$save_bgs = $this->pageBackgrounds;
$checkinnerhtml = preg_replace('/\s/', '', $html);
if (!empty($bounding)) {
// $cont_ containing block = full physical page (position:
absolute) or page inside margins (position: fixed)
// $bbox_ Bounding box is the <div> which is positioned
absolutely/fixed
//
top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken
from bounding
// font*[family/size/style/weight]/line-
height/text*[align/decoration/transform/indent]/color are transferred to $inner
// as an enclosing <div> (after having checked ID/CLASS)
// $x, $y, $w, $h are inside of $bbox_ = containing box for
$inner_
// $inner_ InnerHTML is the contents of that block to be output
$tag = $bounding[0];
$attr = $bounding[1];
$orig_x0 = $bounding[2];
$orig_y0 = $bounding[3];
// As in WriteHTML() initialising
$this->blklvl = 0;
$this->lastblocklevelchange = 0;
$this->blk = array();
$this->initialiseBlock($this->blk[0]);
$this->blk[0]['blockContext'] = $this->blockContext;
if (isset($p['COLOR'])) {
$css .= 'color: ' . strtolower($p['COLOR']) . '; ';
}
if (isset($p['Z-INDEX'])) {
$css .= 'z-index: ' . $p['Z-INDEX'] . '; ';
}
if ($css) {
$html = '<div style="' . $css . '">' . $html . '</div>';
}
// Copy over (only) the properties to set for border and
background
$pb = array();
$pb['MARGIN-TOP'] = (isset($p['MARGIN-TOP']) ? $p['MARGIN-TOP'] :
'');
$pb['MARGIN-RIGHT'] = (isset($p['MARGIN-RIGHT']) ? $p['MARGIN-
RIGHT'] : '');
$pb['MARGIN-BOTTOM'] = (isset($p['MARGIN-BOTTOM']) ? $p['MARGIN-
BOTTOM'] : '');
$pb['MARGIN-LEFT'] = (isset($p['MARGIN-LEFT']) ? $p['MARGIN-
LEFT'] : '');
$pb['PADDING-TOP'] = (isset($p['PADDING-TOP']) ? $p['PADDING-
TOP'] : '');
$pb['PADDING-RIGHT'] = (isset($p['PADDING-RIGHT']) ? $p['PADDING-
RIGHT'] : '');
$pb['PADDING-BOTTOM'] = (isset($p['PADDING-BOTTOM']) ?
$p['PADDING-BOTTOM'] : '');
$pb['PADDING-LEFT'] = (isset($p['PADDING-LEFT']) ? $p['PADDING-
LEFT'] : '');
$pb['BORDER-TOP'] = (isset($p['BORDER-TOP']) ? $p['BORDER-TOP'] :
'');
$pb['BORDER-RIGHT'] = (isset($p['BORDER-RIGHT']) ? $p['BORDER-
RIGHT'] : '');
$pb['BORDER-BOTTOM'] = (isset($p['BORDER-BOTTOM']) ? $p['BORDER-
BOTTOM'] : '');
$pb['BORDER-LEFT'] = (isset($p['BORDER-LEFT']) ? $p['BORDER-
LEFT'] : '');
if (isset($p['BORDER-TOP-LEFT-RADIUS-H'])) {
$pb['BORDER-TOP-LEFT-RADIUS-H'] = $p['BORDER-TOP-LEFT-
RADIUS-H'];
}
if (isset($p['BORDER-TOP-LEFT-RADIUS-V'])) {
$pb['BORDER-TOP-LEFT-RADIUS-V'] = $p['BORDER-TOP-LEFT-
RADIUS-V'];
}
if (isset($p['BORDER-TOP-RIGHT-RADIUS-H'])) {
$pb['BORDER-TOP-RIGHT-RADIUS-H'] = $p['BORDER-TOP-RIGHT-
RADIUS-H'];
}
if (isset($p['BORDER-TOP-RIGHT-RADIUS-V'])) {
$pb['BORDER-TOP-RIGHT-RADIUS-V'] = $p['BORDER-TOP-RIGHT-
RADIUS-V'];
}
if (isset($p['BORDER-BOTTOM-LEFT-RADIUS-H'])) {
$pb['BORDER-BOTTOM-LEFT-RADIUS-H'] = $p['BORDER-BOTTOM-
LEFT-RADIUS-H'];
}
if (isset($p['BORDER-BOTTOM-LEFT-RADIUS-V'])) {
$pb['BORDER-BOTTOM-LEFT-RADIUS-V'] = $p['BORDER-BOTTOM-
LEFT-RADIUS-V'];
}
if (isset($p['BORDER-BOTTOM-RIGHT-RADIUS-H'])) {
$pb['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $p['BORDER-BOTTOM-
RIGHT-RADIUS-H'];
}
if (isset($p['BORDER-BOTTOM-RIGHT-RADIUS-V'])) {
$pb['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $p['BORDER-BOTTOM-
RIGHT-RADIUS-V'];
}
if (isset($p['BACKGROUND-COLOR'])) {
$pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR'];
}
if (isset($p['BOX-SHADOW'])) {
$pb['BOX-SHADOW'] = $p['BOX-SHADOW'];
}
/* -- BACKGROUNDS -- */
if (isset($p['BACKGROUND-IMAGE'])) {
$pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE'];
}
if (isset($p['BACKGROUND-IMAGE-RESIZE'])) {
$pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-
RESIZE'];
}
if (isset($p['BACKGROUND-IMAGE-OPACITY'])) {
$pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-
OPACITY'];
}
if (isset($p['BACKGROUND-REPEAT'])) {
$pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT'];
}
if (isset($p['BACKGROUND-POSITION'])) {
$pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION'];
}
if (isset($p['BACKGROUND-GRADIENT'])) {
$pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT'];
}
if (isset($p['BACKGROUND-SIZE'])) {
$pb['BACKGROUND-SIZE'] = $p['BACKGROUND-SIZE'];
}
if (isset($p['BACKGROUND-ORIGIN'])) {
$pb['BACKGROUND-ORIGIN'] = $p['BACKGROUND-ORIGIN'];
}
if (isset($p['BACKGROUND-CLIP'])) {
$pb['BACKGROUND-CLIP'] = $p['BACKGROUND-CLIP'];
}
/* -- END BACKGROUNDS -- */
//===============================================================
=
$bbox_br = $this->blk[1]['border_right']['w'];
$bbox_bl = $this->blk[1]['border_left']['w'];
$bbox_bt = $this->blk[1]['border_top']['w'];
$bbox_bb = $this->blk[1]['border_bottom']['w'];
$bbox_pr = $this->blk[1]['padding_right'];
$bbox_pl = $this->blk[1]['padding_left'];
$bbox_pt = $this->blk[1]['padding_top'];
$bbox_pb = $this->blk[1]['padding_bottom'];
$bbox_mr = $this->blk[1]['margin_right'];
if (isset($p['MARGIN-RIGHT']) && strtolower($p['MARGIN-RIGHT'])
== 'auto') {
$bbox_mr = 'auto';
}
$bbox_ml = $this->blk[1]['margin_left'];
if (isset($p['MARGIN-LEFT']) && strtolower($p['MARGIN-LEFT']) ==
'auto') {
$bbox_ml = 'auto';
}
$bbox_mt = $this->blk[1]['margin_top'];
if (isset($p['MARGIN-TOP']) && strtolower($p['MARGIN-TOP']) ==
'auto') {
$bbox_mt = 'auto';
}
$bbox_mb = $this->blk[1]['margin_bottom'];
if (isset($p['MARGIN-BOTTOM']) && strtolower($p['MARGIN-BOTTOM'])
== 'auto') {
$bbox_mb = 'auto';
}
if (isset($p['LEFT']) && strtolower($p['LEFT']) != 'auto') {
$bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this-
>FontSize, false);
} else {
$bbox_left = 'auto';
}
if (isset($p['TOP']) && strtolower($p['TOP']) != 'auto') {
$bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this-
>FontSize, false);
} else {
$bbox_top = 'auto';
}
if (isset($p['RIGHT']) && strtolower($p['RIGHT']) != 'auto') {
$bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w,
$this->FontSize, false);
} else {
$bbox_right = 'auto';
}
if (isset($p['BOTTOM']) && strtolower($p['BOTTOM']) != 'auto') {
$bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h,
$this->FontSize, false);
} else {
$bbox_bottom = 'auto';
}
if (isset($p['WIDTH']) && strtolower($p['WIDTH']) != 'auto') {
$inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this-
>FontSize, false);
} else {
$inner_w = 'auto';
}
if (isset($p['HEIGHT']) && strtolower($p['HEIGHT']) != 'auto') {
$inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this-
>FontSize, false);
} else {
$inner_h = 'auto';
}
// If bottom or right pos are set and not left / top - save this
to adjust rotated block later
if ($rotate == 90 || $rotate == -90) { // mPDF 6
if ($bbox_left === 'auto' && $bbox_right !== 'auto') {
$rot_rpos = $bbox_right;
} else {
$rot_rpos = false;
}
if ($bbox_top === 'auto' && $bbox_bottom !== 'auto') {
$rot_bpos = $bbox_bottom;
} else {
$rot_bpos = false;
}
}
//===============================================================
=
if ($checkinnerhtml == '' && $inner_h === 'auto') {
$inner_h = 0.0001;
}
if ($checkinnerhtml == '' && $inner_w === 'auto') {
$inner_w = 2 * $this->GetCharWidth('W', false);
}
//===============================================================
=
// Algorithm from CSS2.1 See
http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height
// mPD 5.3.14
// Special case (not CSS) if all not specified, centre vertically
on page
$bbox_top_orig = '';
if ($bbox_top === 'auto' && $inner_h === 'auto' && $bbox_bottom
=== 'auto' && $bbox_mt === 'auto' && $bbox_mb === 'auto') {
$bbox_top_orig = $bbox_top;
if ($bbox_mt === 'auto') {
$bbox_mt = 0;
}
if ($bbox_mb === 'auto') {
$bbox_mb = 0;
}
$bbox_top = $orig_y0 - $bbox_mt - $cont_y;
// solve for $bbox_bottom when content_h known -
$inner_h=='auto' && $bbox_bottom=='auto'
}
// mPD 5.3.14
elseif ($bbox_top === 'auto' && $inner_h === 'auto' &&
$bbox_bottom === 'auto') {
$bbox_top_orig = $bbox_top = $orig_y0 - $cont_y;
if ($bbox_mt === 'auto') {
$bbox_mt = 0;
}
if ($bbox_mb === 'auto') {
$bbox_mb = 0;
}
// solve for $bbox_bottom when content_h known -
$inner_h=='auto' && $bbox_bottom=='auto'
} elseif ($bbox_top !== 'auto' && $inner_h !== 'auto' &&
$bbox_bottom !== 'auto') {
if ($bbox_mt === 'auto' && $bbox_mb === 'auto') {
$x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt -
$inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
$bbox_mt = $bbox_mb = ($x / 2);
} elseif ($bbox_mt === 'auto') {
$bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt
- $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
} elseif ($bbox_mb === 'auto') {
$bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt
- $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
} else {
$bbox_bottom = $cont_h - $bbox_top - $bbox_mt -
$bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
}
} else {
if ($bbox_mt === 'auto') {
$bbox_mt = 0;
}
if ($bbox_mb === 'auto') {
$bbox_mb = 0;
}
if ($bbox_top === 'auto' && $inner_h === 'auto' &&
$bbox_bottom !== 'auto') {
// solve for $bbox_top when content_h known -
$inner_h=='auto' && $bbox_top =='auto'
} elseif ($bbox_top === 'auto' && $bbox_bottom === 'auto'
&& $inner_h !== 'auto') {
$bbox_top = $orig_y0 - $bbox_mt - $cont_y;
$bbox_bottom = $cont_h - $bbox_top - $bbox_mt -
$bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
} elseif ($inner_h === 'auto' && $bbox_bottom === 'auto' &&
$bbox_top !== 'auto') {
// solve for $bbox_bottom when content_h known -
$inner_h=='auto' && $bbox_bottom=='auto'
} elseif ($bbox_top === 'auto' && $inner_h !== 'auto' &&
$bbox_bottom !== 'auto') {
$bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt
- $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
} elseif ($inner_h === 'auto' && $bbox_top !== 'auto' &&
$bbox_bottom !== 'auto') {
$inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt
- $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
} elseif ($bbox_bottom === 'auto' && $bbox_top !== 'auto'
&& $inner_h !== 'auto') {
$bbox_bottom = $cont_h - $bbox_top - $bbox_mt -
$bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
}
}
//===============================================================
=
//===============================================================
=
/* -- BACKGROUNDS -- */
if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) {
$ret = $this->SetBackground($pb, $this->blk[1]
['inner_width']);
if ($ret) {
$this->blk[1]['background-image'] = $ret;
}
}
/* -- END BACKGROUNDS -- */
//===============================================================
=
$y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
$h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt -
$bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
$x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
$w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl -
$bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
// Set (temporary) values for x y w h to do first paint, if
values are auto
if ($inner_h === 'auto' && $bbox_top === 'auto') {
$y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt;
$h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb +
$bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
} elseif ($inner_h === 'auto' && $bbox_bottom === 'auto') {
$y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
$h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt
+ $bbox_bb + $bbox_pt + $bbox_pb);
}
if ($inner_w === 'auto' && $bbox_left === 'auto') {
$x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl;
$w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr +
$bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
} elseif ($inner_w === 'auto' && $bbox_right === 'auto') {
$x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
$w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl
+ $bbox_br + $bbox_pl + $bbox_pr);
}
$bbox_y = $cont_y + $bbox_top + $bbox_mt;
$bbox_x = $cont_x + $bbox_left + $bbox_ml;
$saved_block1 = $this->blk[1];
unset($p);
unset($pb);
//===============================================================
=
if ($inner_w === 'auto') { // do a first write
$this->lMargin = $x;
$this->rMargin = $this->w - $w - $x;
// SET POSITION & FONT VALUES
$this->pgwidth = $this->w - $this->lMargin - $this-
>rMargin;
$this->pageoutput[$this->page] = array();
$this->x = $x;
$this->y = $y;
$this->HTMLheaderPageLinks = array();
$this->HTMLheaderPageAnnots = array();
$this->HTMLheaderPageForms = array();
$this->pageBackgrounds = array();
$this->maxPosR = 0;
$this->maxPosL = $this->w; // For RTL
$this->WriteHTML($html, 4);
$inner_w = $this->maxPosR - $this->lMargin;
if ($bbox_right === 'auto') {
$bbox_right = $cont_w - $bbox_left - $bbox_ml -
$bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
} elseif ($bbox_left === 'auto') {
$bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl
- $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
$bbox_x = $cont_x + $bbox_left + $bbox_ml;
$inner_x = $bbox_x + $bbox_bl + $bbox_pl;
$x = $inner_x;
}
$w = $inner_w;
$bbox_y = $cont_y + $bbox_top + $bbox_mt;
$bbox_x = $cont_x + $bbox_left + $bbox_ml;
}
if ($this->progressBar) {
$this->UpdateProgressBar(4, intval(100 / ($ratio /
$target)), ('Auto-sizing fixed-position block: ' . $bpcctr++));
} // *PROGRESS-BAR*
$this->x = $x;
$this->y = $y;
//================================================================
$this->pages[$this->page] .= '___BEFORE_BORDERS___';
$block_s = $this->PrintPageBackgrounds(); // Save to print later inside
clipping path
$this->pageBackgrounds = array();
//================================================================
//================================================================
if (!empty($bounding)) {
// WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the
bottom
// Re-instate saved $this->blk[1]
$this->blk[1] = $saved_block1;
$s = $this->PrintPageBackgrounds();
$s = $rot_start . $s . $rot_end;
$this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n"
. $s . "\n", $this->pages[$this->page]);
$this->pageBackgrounds = array();
$this->_out($rot_start);
// Clipping Output
if ($overflow == 'hidden') {
//Bounding rectangle to clip
$clip_y1 = $this->y;
if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) >
($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) {
$clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h +
$bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb);
}
//$op = 'W* n'; // Clipping
$op = 'W n'; // Clipping alternative mode
$this->_out("q");
$ch = $clip_y1 - $y;
$this->_out(sprintf('%.3F %.3F %.3F %.3F re %s', $x * _MPDFK,
($this->h - $y) * _MPDFK, $w * _MPDFK, -$ch * _MPDFK, $op));
if (!empty($block_s)) {
$tmp = "q\n" . sprintf('%.3F %.3F %.3F %.3F re %s', $x *
_MPDFK, ($this->h - $y) * _MPDFK, $w * _MPDFK, -$ch * _MPDFK, $op);
$tmp .= "\n" . $block_s . "\nQ";
$block_s = $tmp;
}
}
if (!empty($block_s)) {
if ($shrink_f != 1) { // i.e. autofit has resized the box
$tmp = "q\n" . $this->transformScale(($shrink_f * 100),
($shrink_f * 100), $x, $y, true);
$tmp .= "\n" . $block_s . "\nQ";
$block_s = $tmp;
}
$this->_out($block_s);
}
$this->_out($this->headerbuffer);
if ($overflow == 'hidden') {
//End clipping
$this->_out("Q");
}
$this->_out($rot_end);
// Page Links
foreach ($this->HTMLheaderPageLinks AS $lk) {
if ($rotate) {
$tmp = $lk[2]; // Switch h - w
$lk[2] = $lk[3];
$lk[3] = $tmp;
// Restore
$this->headerbuffer = '';
$this->HTMLheaderPageLinks = array();
$this->HTMLheaderPageAnnots = array();
$this->HTMLheaderPageForms = array();
$this->pageBackgrounds = $save_bgs;
$this->writingHTMLheader = false;
$this->writingHTMLfooter = false;
$this->fullImageHeight = false;
$this->ResetMargins();
$this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
$this->SetXY($save_x, $save_y);
$this->title2annots = $save_annots; // *ANNOTATIONS*
$this->InFooter = false; // turns back on autopagebreaks
$this->pageoutput[$this->page] = array();
$this->pageoutput[$this->page]['Font'] = '';
/* -- COLUMNS -- */
if ($save_cols) {
$this->SetColumns($save_nbcol, $this->colvAlign, $this->ColGap);
}
/* -- END COLUMNS -- */
}
/* -- END CSS-POSITION -- */
function initialiseBlock(&$blk)
{
$blk['margin_top'] = 0;
$blk['margin_left'] = 0;
$blk['margin_bottom'] = 0;
$blk['margin_right'] = 0;
$blk['padding_top'] = 0;
$blk['padding_left'] = 0;
$blk['padding_bottom'] = 0;
$blk['padding_right'] = 0;
$blk['border_top']['w'] = 0;
$blk['border_left']['w'] = 0;
$blk['border_bottom']['w'] = 0;
$blk['border_right']['w'] = 0;
$blk['direction'] = 'ltr';
$blk['hide'] = false;
$blk['outer_left_margin'] = 0;
$blk['outer_right_margin'] = 0;
$blk['cascadeCSS'] = array();
$blk['block-align'] = false;
$blk['bgcolor'] = false;
$blk['page_break_after_avoid'] = false;
$blk['keep_block_together'] = false;
$blk['float'] = false;
$blk['line_height'] = '';
$blk['margin_collapse'] = false;
}
function border_details($bd)
{
$prop = preg_split('/\s+/', trim($bd));
if (isset($this->blk[$this->blklvl]['inner_width'])) {
$refw = $this->blk[$this->blklvl]['inner_width'];
} elseif (isset($this->blk[$this->blklvl - 1]['inner_width'])) {
$refw = $this->blk[$this->blklvl - 1]['inner_width'];
} else {
$refw = $this->w;
}
if (count($prop) == 1) {
$bsize = $this->ConvertSize($prop[0], $refw, $this->FontSize,
false);
if ($bsize > 0) {
return array('s' => 1, 'w' => $bsize, 'c' => $this-
>ConvertColor(0), 'style' => 'solid');
} else {
return array('w' => 0, 's' => 0);
}
} elseif (count($prop) == 2) {
// 1px solid
if (in_array($prop[1], $this->borderstyles) || $prop[1] == 'none'
|| $prop[1] == 'hidden') {
$prop[2] = '';
}
// solid #000000
elseif (in_array($prop[0], $this->borderstyles) || $prop[0] ==
'none' || $prop[0] == 'hidden') {
$prop[0] = '';
$prop[1] = $prop[0];
$prop[2] = $prop[1];
}
// 1px #000000
else {
$prop[1] = '';
$prop[2] = $prop[1];
}
} elseif (count($prop) == 3) {
// Change #000000 1px solid to 1px solid #000000 (proper)
if (substr($prop[0], 0, 1) == '#') {
$tmp = $prop[0];
$prop[0] = $prop[1];
$prop[1] = $prop[2];
$prop[2] = $tmp;
}
// Change solid #000000 1px to 1px solid #000000 (proper)
elseif (substr($prop[0], 1, 1) == '#') {
$tmp = $prop[1];
$prop[0] = $prop[2];
$prop[1] = $prop[0];
$prop[2] = $tmp;
}
// Change solid 1px #000000 to 1px solid #000000 (proper)
elseif (in_array($prop[0], $this->borderstyles) || $prop[0] ==
'none' || $prop[0] == 'hidden') {
$tmp = $prop[0];
$prop[0] = $prop[1];
$prop[1] = $tmp;
}
} else {
return array();
}
// Size
$bsize = $this->ConvertSize($prop[0], $refw, $this->FontSize, false);
//color
$coul = $this->ConvertColor($prop[2]); // returns array
// Style
$prop[1] = strtolower($prop[1]);
if (in_array($prop[1], $this->borderstyles) && $bsize > 0) {
$on = 1;
} elseif ($prop[1] == 'hidden') {
$on = 1;
$bsize = 0;
$coul = '';
} elseif ($prop[1] == 'none') {
$on = 0;
$bsize = 0;
$coul = '';
} else {
$on = 0;
$bsize = 0;
$coul = '';
$prop[1] = '';
}
return array('s' => $on, 'w' => $bsize, 'c' => $coul, 'style' =>
$prop[1]);
}
/* -- END HTML-CSS -- */
/* -- BORDER-RADIUS -- */
$x = $a - $px;
$y = $b - $py;
// Check if Falls within ellipse of border radius
if (( (($x + $added) * ($x + $added)) / ($a * $a) + (($y + $added) *
($y + $added)) / ($b * $b) ) <= 1) {
return false;
}
$t = atan2($y, $x);
/* -- END BORDER-RADIUS -- */
/* -- HTML-CSS -- */
/* -- CSS-PAGE -- */
// If right/Odd page
if (isset($this->cssmgr->CSS['@PAGE>>PSEUDO>>RIGHT']) && $side == 'R')
{
$zp = $this->cssmgr->CSS['@PAGE>>PSEUDO>>RIGHT'];
} else {
$zp = array();
}
if (isset($zp['SIZE'])) {
unset($zp['SIZE']);
}
if (isset($zp['SHEET-SIZE'])) {
unset($zp['SHEET-SIZE']);
}
// Disallow margin-left or -right on :LEFT or :RIGHT
if (isset($zp['MARGIN-LEFT'])) {
unset($zp['MARGIN-LEFT']);
}
if (isset($zp['MARGIN-RIGHT'])) {
unset($zp['MARGIN-RIGHT']);
}
if (is_array($zp) && !empty($zp)) {
$p = array_merge($p, $zp);
}
// If left/Even page
if (isset($this->cssmgr->CSS['@PAGE>>PSEUDO>>LEFT']) && $side == 'L') {
$zp = $this->cssmgr->CSS['@PAGE>>PSEUDO>>LEFT'];
} else {
$zp = array();
}
if (isset($zp['SIZE'])) {
unset($zp['SIZE']);
}
if (isset($zp['SHEET-SIZE'])) {
unset($zp['SHEET-SIZE']);
}
// Disallow margin-left or -right on :LEFT or :RIGHT
if (isset($zp['MARGIN-LEFT'])) {
unset($zp['MARGIN-LEFT']);
}
if (isset($zp['MARGIN-RIGHT'])) {
unset($zp['MARGIN-RIGHT']);
}
if (is_array($zp) && !empty($zp)) {
$p = array_merge($p, $zp);
}
// If first page
if (isset($this->cssmgr->CSS['@PAGE>>PSEUDO>>FIRST']) && $first) {
$zp = $this->cssmgr->CSS['@PAGE>>PSEUDO>>FIRST'];
} else {
$zp = array();
}
if (isset($zp['SIZE'])) {
unset($zp['SIZE']);
}
if (isset($zp['SHEET-SIZE'])) {
unset($zp['SHEET-SIZE']);
}
// Disallow margin-left or -right on :FIRST // mPDF 5.7.3
if (isset($zp['MARGIN-LEFT'])) {
unset($zp['MARGIN-LEFT']);
}
if (isset($zp['MARGIN-RIGHT'])) {
unset($zp['MARGIN-RIGHT']);
}
if (is_array($zp) && !empty($zp)) {
$p = array_merge($p, $zp);
}
// If named page
if ($name) {
if (isset($this->cssmgr->CSS['@PAGE>>NAMED>>' . $name])) {
$zp = $this->cssmgr->CSS['@PAGE>>NAMED>>' . $name];
} else {
$zp = array();
}
if (is_array($zp) && !empty($zp)) {
$p = array_merge($p, $zp);
}
$newformat = '';
if (isset($p['MARKS'])) {
if (preg_match('/cross/i', $p['MARKS']) && preg_match('/crop/i',
$p['MARKS'])) {
$marks = 'CROPCROSS';
} elseif (strtoupper($p['MARKS']) == 'CROP') {
$marks = 'CROP';
} elseif (strtoupper($p['MARKS']) == 'CROSS') {
$marks = 'CROSS';
}
}
if (isset($p['MARGIN-LEFT'])) {
$mgl = $this->ConvertSize($p['MARGIN-LEFT'], $pgw) +
$outer_width_LR;
}
if (isset($p['MARGIN-RIGHT'])) {
$mgr = $this->ConvertSize($p['MARGIN-RIGHT'], $pgw) +
$outer_width_LR;
}
if (isset($p['MARGIN-BOTTOM'])) {
$mgb = $this->ConvertSize($p['MARGIN-BOTTOM'], $pgh) +
$outer_width_TB;
}
if (isset($p['MARGIN-TOP'])) {
$mgt = $this->ConvertSize($p['MARGIN-TOP'], $pgh) +
$outer_width_TB;
}
if (isset($p['MARGIN-HEADER'])) {
$mgh = $this->ConvertSize($p['MARGIN-HEADER'], $pgh) +
$outer_width_TB;
}
if (isset($p['MARGIN-FOOTER'])) {
$mgf = $this->ConvertSize($p['MARGIN-FOOTER'], $pgh) +
$outer_width_TB;
}
/* -- END CSS-PAGE -- */
/* -- CSS-FLOAT -- */
/* -- END CSS-FLOAT -- */
$objattr = array();
$objattr['margin_top'] = 0;
$objattr['margin_bottom'] = 0;
$objattr['margin_left'] = 0;
$objattr['margin_right'] = 0;
$objattr['padding_top'] = 0;
$objattr['padding_bottom'] = 0;
$objattr['padding_left'] = 0;
$objattr['padding_right'] = 0;
$objattr['width'] = 0;
$objattr['height'] = 0;
$objattr['border_top']['w'] = 0;
$objattr['border_bottom']['w'] = 0;
$objattr['border_left']['w'] = 0;
$objattr['border_right']['w'] = 0;
$objattr['visibility'] = 'visible';
$srcpath = $listitemimage;
$orig_srcpath = $listitemimage;
$objattr['orig_h'] = $info['h'];
$objattr['orig_w'] = $info['w'];
/* -- IMAGES-WMF -- */
if ($info['type'] == 'wmf') {
$objattr['wmf_x'] = $info['x'];
$objattr['wmf_y'] = $info['y'];
} else
/* -- END IMAGES-WMF -- */
if ($info['type'] == 'svg') {
$objattr['wmf_x'] = $info['x'];
$objattr['wmf_y'] = $info['y'];
}
$objattr['height'] = $h;
$objattr['width'] = $w;
$objattr['image_height'] = $h;
$objattr['image_width'] = $w;
$objattr['dir'] = (isset($this->blk[$this->blklvl]
['direction']) ? $this->blk[$this->blklvl]['direction'] : 'ltr');
$objattr['listmarker'] = true;
$objattr['listmarkerposition'] = $listitemposition;
$e = "\xbb\xa4\xactype=image,objattr=" . serialize($objattr) .
"\xbb\xa4\xac";
$this->_saveTextBuffer($e);
if ($listitemposition == 'inside') {
$e = $spacer;
$this->_saveTextBuffer($e);
}
}
// SYMBOL (needs new font)
elseif ($listitemtype == 'disc' || $listitemtype == 'circle' ||
$listitemtype == 'square') {
$objattr = array();
$objattr['type'] = 'listmarker';
$objattr['listmarkerposition'] = $listitemposition;
$objattr['width'] = 0;
$size = $this->ConvertSize($this->list_symbol_size, $this-
>FontSize);
$objattr['size'] = $size;
$objattr['offset'] = $this->ConvertSize($this-
>list_marker_offset, $this->FontSize);
if ($listitemposition == 'inside') {
$objattr['width'] = $size + $objattr['offset'];
}
$objattr['height'] = $this->FontSize;
$objattr['vertical-align'] = 'T';
$objattr['text'] = '';
$objattr['dir'] = (isset($this->blk[$this->blklvl]
['direction']) ? $this->blk[$this->blklvl]['direction'] : 'ltr');
$objattr['bullet'] = $listitemtype;
$objattr['colorarray'] = $this->colorarray;
$objattr['fontfamily'] = $this->FontFamily;
$objattr['fontsize'] = $this->FontSize;
$objattr['fontsizept'] = $this->FontSizePt;
$objattr['fontstyle'] = $this->FontStyle;
$e = "\xbb\xa4\xactype=listmarker,objattr=" . serialize($objattr)
. "\xbb\xa4\xac";
$this->listitem = $this->_saveTextBuffer($e, '', '', true); //
true returns array
// if ($listitemposition == 'inside') {
// $e = $spacer;
// $this->_saveTextBuffer($e);
// }
}
// SYMBOL 2 (needs new font)
elseif (preg_match('/U\+([a-fA-F0-9]+)/i', $listitemtype, $m)) {
if ($this->_charDefined($this->CurrentFont['cw'], hexdec($m[1])))
{
$list_item_marker = codeHex2utf($m[1]);
} else {
$list_item_marker = '-';
}
if (preg_match('/rgb\(.*?\)/', $listitemtype, $m)) {
$list_item_color = $this->ConvertColor($m[0]);
} else {
$list_item_color = '';
}
if ($listitemposition == 'inside') {
$e = $list_item_marker . $spacer;
$this->_saveTextBuffer($e);
} else {
$objattr = array();
$objattr['type'] = 'listmarker';
$objattr['width'] = 0;
$objattr['height'] = $this->FontSize;
$objattr['vertical-align'] = 'T';
$objattr['text'] = $list_item_marker;
$objattr['dir'] = (isset($this->blk[$this->blklvl]
['direction']) ? $this->blk[$this->blklvl]['direction'] : 'ltr');
$objattr['colorarray'] = $this->colorarray;
$objattr['fontfamily'] = $this->FontFamily;
$objattr['fontsize'] = $this->FontSize;
$objattr['fontsizept'] = $this->FontSizePt;
$objattr['fontstyle'] = $this->FontStyle;
$e = "\xbb\xa4\xactype=listmarker,objattr=" .
serialize($objattr) . "\xbb\xa4\xac";
$this->listitem = $this->_saveTextBuffer($e, '', '', true);
// true returns array
}
// RESET COLOR
$this->colorarray = $save_colorarray;
}
// TEXT
else {
$counter = $this->listcounter[$this->listlvl];
if ($listitemtype == 'none') {
return;
}
$num = $this->_getStyledNumber($counter, $listitemtype, true);
if ($listitemposition == 'inside') {
$e = $num . $this->list_number_suffix . $spacer;
$this->_saveTextBuffer($e);
} else {
if (isset($this->blk[$this->blklvl]['direction']) && $this-
>blk[$this->blklvl]['direction'] == 'rtl') {
// REPLACE MIRRORED RTL $this->list_number_suffix
e.g. ) -> ( (NB could use UCDN::$mirror_pairs)
$m = strtr($this->list_number_suffix, ")]}", "([{") .
$num;
} else {
$m = $num . $this->list_number_suffix;
}
$objattr = array();
$objattr['type'] = 'listmarker';
$objattr['width'] = 0;
$objattr['height'] = $this->FontSize;
$objattr['vertical-align'] = 'T';
$objattr['text'] = $m;
$objattr['dir'] = (isset($this->blk[$this->blklvl]
['direction']) ? $this->blk[$this->blklvl]['direction'] : 'ltr');
$objattr['colorarray'] = $this->colorarray;
$objattr['fontfamily'] = $this->FontFamily;
$objattr['fontsize'] = $this->FontSize;
$objattr['fontsizept'] = $this->FontSizePt;
$objattr['fontstyle'] = $this->FontStyle;
$e = "\xbb\xa4\xactype=listmarker,objattr=" .
serialize($objattr) . "\xbb\xa4\xac";
// mPDF Lists
function _getListMarkerWidth(&$currblk, &$a, &$i)
{
$blt_width = 0;
switch ($currblk['list_style_type']) {
case 'decimal':
case '1':
$blt_width = $this->GetStringWidth(str_repeat('5',
strlen($maxnum)) . $this->list_number_suffix);
break;
case 'none':
$blt_width = 0;
break;
case 'upper-alpha':
case 'upper-latin':
case 'A':
$maxnumA = $this->dec2alpha($maxnum, true);
if ($maxnum < 13) {
$blt_width = $this->GetStringWidth('D' . $this-
>list_number_suffix);
} else {
$blt_width = $this->GetStringWidth(str_repeat('W',
strlen($maxnumA)) . $this->list_number_suffix);
}
break;
case 'lower-alpha':
case 'lower-latin':
case 'a':
$maxnuma = $this->dec2alpha($maxnum, false);
if ($maxnum < 13) {
$blt_width = $this->GetStringWidth('b' . $this-
>list_number_suffix);
} else {
$blt_width = $this->GetStringWidth(str_repeat('m',
strlen($maxnuma)) . $this->list_number_suffix);
}
break;
case 'upper-roman':
case 'I':
if ($maxnum > 87) {
$bbit = 87;
} elseif ($maxnum > 86) {
$bbit = 86;
} elseif ($maxnum > 37) {
$bbit = 38;
} elseif ($maxnum > 36) {
$bbit = 37;
} elseif ($maxnum > 27) {
$bbit = 28;
} elseif ($maxnum > 26) {
$bbit = 27;
} elseif ($maxnum > 17) {
$bbit = 18;
} elseif ($maxnum > 16) {
$bbit = 17;
} elseif ($maxnum > 7) {
$bbit = 8;
} elseif ($maxnum > 6) {
$bbit = 7;
} elseif ($maxnum > 3) {
$bbit = 4;
} else {
$bbit = $maxnum;
}
$maxlnum = $this->dec2roman($bbit, true);
$blt_width = $this->GetStringWidth($maxlnum . $this-
>list_number_suffix);
break;
case 'lower-roman':
case 'i':
if ($maxnum > 87) {
$bbit = 87;
} elseif ($maxnum > 86) {
$bbit = 86;
} elseif ($maxnum > 37) {
$bbit = 38;
} elseif ($maxnum > 36) {
$bbit = 37;
} elseif ($maxnum > 27) {
$bbit = 28;
} elseif ($maxnum > 26) {
$bbit = 27;
} elseif ($maxnum > 17) {
$bbit = 18;
} elseif ($maxnum > 16) {
$bbit = 17;
} elseif ($maxnum > 7) {
$bbit = 8;
} elseif ($maxnum > 6) {
$bbit = 7;
} elseif ($maxnum > 3) {
$bbit = 4;
} else {
$bbit = $maxnum;
}
$maxlnum = $this->dec2roman($bbit, false);
$blt_width = $this->GetStringWidth($maxlnum . $this-
>list_number_suffix);
break;
case 'disc':
case 'circle':
case 'square':
$size = $this->ConvertSize($this->list_symbol_size, $this-
>FontSize);
$offset = $this->ConvertSize($this->list_marker_offset,
$this->FontSize);
$blt_width = $size + $offset;
break;
case 'arabic-indic':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x0660), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'persian':
case 'urdu':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x06F0), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'bengali':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x09E6), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'devanagari':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x0966), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'gujarati':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x0AE6), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'gurmukhi':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x0A66), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'kannada':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x0CE6), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'malayalam':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(6, 0x0D66), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'oriya':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x0B66), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'telugu':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(3, 0x0C66), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'tamil':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(9, 0x0BE6), strlen($maxnum)) . $this->list_number_suffix);
break;
case 'thai':
$blt_width = $this->GetStringWidth(str_repeat($this-
>dec2other(5, 0x0E50), strlen($maxnum)) . $this->list_number_suffix);
break;
default:
$blt_width = $this->GetStringWidth(str_repeat('5',
strlen($maxnum)) . $this->list_number_suffix);
break;
}
/* -- END TABLES -- */
if (!$is_table) {
$this->SetLineHeight($this->FontSizePt, $this->blk[$this->blklvl]
['line_height']);
}
$this->divheight = $this->lineheight;
$old_height = $this->divheight;
$array_size = count($arrayaux);
/* -- TABLES -- */
if ($objattr['type'] == 'nestedtable') {
if ($objattr['nestedcontent']) {
$level = $objattr['level'];
$table = &$this->table[$level]
[$objattr['table']];
if ($table_draft) {
$this->y += $this->table[($level + 1)]
[$objattr['nestedcontent']]['h']; // nested table height
$this->finishFlowingBlock(false,
'nestedtable');
} else {
$cell = &$table['cells'][$objattr['row']]
[$objattr['col']];
$this->finishFlowingBlock(false,
'nestedtable');
$save_dw = $this->divwidth;
$save_buffer = $this->cellBorderBuffer;
$this->cellBorderBuffer = array();
$ncx = $this->x;
list($dummyx, $w) = $this-
>_tableGetWidth($table, $objattr['row'], $objattr['col']);
$ntw = $this->table[($level + 1)]
[$objattr['nestedcontent']]['w']; // nested table width
if (!$this->simpleTables) {
if ($this->packTableData) {
list($bt, $br, $bb, $bl) =
$this->_getBorderWidths($cell['borderbin']);
} else {
$br = $cell['border_details']
['R']['w'];
$bl = $cell['border_details']
['L']['w'];
}
if ($table['borders_separate']) {
$innerw = $w - $bl - $br -
$cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
} else {
$innerw = $w - $bl / 2 -
$br / 2 - $cell['padding']['L'] - $cell['padding']['R'];
}
} elseif ($this->simpleTables) {
if ($table['borders_separate']) {
$innerw = $w -
$table['simple']['border_details']['L']['w'] - $table['simple']['border_details']
['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] -
$table['border_spacing_H'];
} else {
$innerw = $w -
$table['simple']['border_details']['L']['w'] / 2 - $table['simple']
['border_details']['R']['w'] / 2 - $cell['padding']['L'] - $cell['padding']['R'];
}
}
if ($cell['a'] == 'C' || $this-
>table[($level + 1)][$objattr['nestedcontent']]['a'] == 'C') {
$ncx += ($innerw - $ntw) / 2;
} elseif ($cell['a'] == 'R' || $this-
>table[($level + 1)][$objattr['nestedcontent']]['a'] == 'R') {
$ncx += $innerw - $ntw;
}
$this->x = $ncx;
$this->_tableWrite($this->table[($level +
1)][$objattr['nestedcontent']]);
$this->cellBorderBuffer = $save_buffer;
$this->x = $bak_x;
$this->divwidth = $save_dw;
}
$this->newFlowingBlock($this->divwidth, $this-
>divheight, $align, $is_table, $blockstate, false, $blockdir, $table_draft);
}
} else {
/* -- END TABLES -- */
if ($is_table) { // *TABLES*
$maxWidth = $this->divwidth; // *TABLES*
} // *TABLES*
else { // *TABLES*
$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']);
} // *TABLES*
/* -- CSS-IMAGE-FLOAT -- */
// If float (already) exists at this level
if (isset($this->floatmargins['R']) && $this->y <=
$this->floatmargins['R']['y1'] && $this->y >= $this->floatmargins['R']['y0']) {
$maxWidth -= $this->floatmargins['R']['w'];
}
if (isset($this->floatmargins['L']) && $this->y <=
$this->floatmargins['L']['y1'] && $this->y >= $this->floatmargins['L']['y0']) {
$maxWidth -= $this->floatmargins['L']['w'];
}
/* -- END CSS-IMAGE-FLOAT -- */
list($skipln) = $this->inlineObject($objattr['type'],
'', $this->y, $objattr, $this->lMargin, ($this->flowingBlockAttr['contentWidth'] /
_MPDFK), $maxWidth, $this->flowingBlockAttr['height'], false, $is_table);
// 1 -> New line needed because of width
// -1 -> Will fit width on line but NEW PAGE REQUIRED
because of height
// -2 -> Will not fit on line therefore needs new
line but thus NEW PAGE REQUIRED
$iby = $this->y;
$oldpage = $this->page;
$oldcol = $this->CurrCol;
if (($skipln == 1 || $skipln == -2) && !
isset($objattr['float'])) {
$this->finishFlowingBlock(false,
$objattr['type']);
$this->newFlowingBlock($this->divwidth, $this-
>divheight, $align, $is_table, $blockstate, false, $blockdir, $table_draft);
}
if (!$table_draft) {
$thispage = $this->page;
if ($this->CurrCol != $oldcol) {
$changedcol = true;
} else {
$changedcol = false;
}
$this->AddPage($this->CurOrientation);
/* -- CSS-IMAGE-FLOAT -- */
if ($objattr['type'] == 'image' &&
isset($objattr['float'])) {
$fy = $this->y;
if ($objattr['float'] == 'R') {
$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']);
} elseif ($objattr['float'] == 'L') {
$fx = $this->lMargin + ($this->blk[$this-
>blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] +
$this->blk[$this->blklvl]['padding_left']);
}
$w = $objattr['width'];
$h = abs($objattr['height']);
if ($objattr['itype'] == 'wmf' ||
$objattr['itype'] == 'svg') {
$file = $objattr['file'];
$info = $this->formobjects[$file];
} else {
$file = $objattr['file'];
$info = $this->images[$file];
}
$img_w = $w - $extraWidth;
$img_h = $h - $extraHeight;
if ($objattr['border_left']['w']) {
$objattr['BORDER-WIDTH'] = $img_w +
(($objattr['border_left']['w'] + $objattr['border_right']['w']) / 2);
$objattr['BORDER-HEIGHT'] = $img_h +
(($objattr['border_top']['w'] + $objattr['border_bottom']['w']) / 2);
$objattr['BORDER-X'] = $fx +
$objattr['margin_left'] + (($objattr['border_left']['w']) / 2);
$objattr['BORDER-Y'] = $fy +
$objattr['margin_top'] + (($objattr['border_top']['w']) / 2);
}
$objattr['INNER-WIDTH'] = $img_w;
$objattr['INNER-HEIGHT'] = $img_h;
$objattr['INNER-X'] = $fx +
$objattr['margin_left'] + ($objattr['border_left']['w']);
$objattr['INNER-Y'] = $fy +
$objattr['margin_top'] + ($objattr['border_top']['w']);
$objattr['ID'] = $info['i'];
$objattr['OUTER-WIDTH'] = $w;
$objattr['OUTER-HEIGHT'] = $h;
$objattr['OUTER-X'] = $fx;
$objattr['OUTER-Y'] = $fy;
if ($objattr['float'] == 'R') {
// If R float already exists at this
level
$this->floatmargins['R']['skipline'] =
false;
if (isset($this->floatmargins['R']['y1'])
&& $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
$this->WriteFlowingBlock($vetor[0],
$vetor[18]); // mPDF 5.7.1
}
// If L float already exists at this
level
elseif (isset($this->floatmargins['L']
['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']
['y1']) {
// Final check distance between
floats is not now too narrow to fit text
$mw = 2 * $this->GetCharWidth('W',
false);
if (($this->blk[$this->blklvl]
['inner_width'] - $w - $this->floatmargins['L']['w']) < $mw) {
$this-
>WriteFlowingBlock($vetor[0], $vetor[18]); // mPDF 5.7.1
} else {
$this->floatmargins['R']['x']
= $fx;
$this->floatmargins['R']['w']
= $w;
$this->floatmargins['R']
['y0'] = $fy;
$this->floatmargins['R']
['y1'] = $fy + $h;
if ($skipln == 1) {
$this->floatmargins['R']
['skipline'] = true;
$this->floatmargins['R']
['id'] = count($this->floatbuffer) + 0;
$objattr['skipline'] =
true;
}
$this->floatbuffer[] =
$objattr;
}
} else {
$this->floatmargins['R']['x'] =
$fx;
$this->floatmargins['R']['w'] = $w;
$this->floatmargins['R']['y0'] =
$fy;
$this->floatmargins['R']['y1'] =
$fy + $h;
if ($skipln == 1) {
$this->floatmargins['R']
['skipline'] = true;
$this->floatmargins['R']
['id'] = count($this->floatbuffer) + 0;
$objattr['skipline'] = true;
}
$this->floatbuffer[] = $objattr;
}
} elseif ($objattr['float'] == 'L') {
// If L float already exists at this
level
$this->floatmargins['L']['skipline'] =
false;
if (isset($this->floatmargins['L']['y1'])
&& $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
$this->floatmargins['L']
['skipline'] = false;
$this->WriteFlowingBlock($vetor[0],
$vetor[18]); // mPDF 5.7.1
}
// If R float already exists at this
level
elseif (isset($this->floatmargins['R']
['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']
['y1']) {
// Final check distance between
floats is not now too narrow to fit text
$mw = 2 * $this->GetCharWidth('W',
false);
if (($this->blk[$this->blklvl]
['inner_width'] - $w - $this->floatmargins['R']['w']) < $mw) {
$this-
>WriteFlowingBlock($vetor[0], $vetor[18]); // mPDF 5.7.1
} else {
$this->floatmargins['L']['x']
= $fx + $w;
$this->floatmargins['L']['w']
= $w;
$this->floatmargins['L']
['y0'] = $fy;
$this->floatmargins['L']
['y1'] = $fy + $h;
if ($skipln == 1) {
$this->floatmargins['L']
['skipline'] = true;
$this->floatmargins['L']
['id'] = count($this->floatbuffer) + 0;
$objattr['skipline'] =
true;
}
$this->floatbuffer[] =
$objattr;
}
} else {
$this->floatmargins['L']['x'] = $fx
+ $w;
$this->floatmargins['L']['w'] = $w;
$this->floatmargins['L']['y0'] =
$fy;
$this->floatmargins['L']['y1'] =
$fy + $h;
if ($skipln == 1) {
$this->floatmargins['L']
['skipline'] = true;
$this->floatmargins['L']
['id'] = count($this->floatbuffer) + 0;
$objattr['skipline'] = true;
}
$this->floatbuffer[] = $objattr;
}
}
} else {
/* -- END CSS-IMAGE-FLOAT -- */
$this->WriteFlowingBlock($vetor[0],
(isset($vetor[18]) ? $vetor[18] : NULL)); // mPDF 5.7.1
/* -- CSS-IMAGE-FLOAT -- */
}
/* -- END CSS-IMAGE-FLOAT -- */
} // *TABLES*
} // END If special content
else { //THE text
if ($this->tableLevel) {
$paint_ht_corr = 0;
} // To move the y up when new column/page started if div
border needed
else {
$paint_ht_corr = $this->blk[$this->blklvl]
['border_top']['w'];
}
/* -- COLUMNS -- */
// COLS
// OR COLUMN CHANGE
if ($this->CurrCol != $oldcolumn) {
if ($this->directionality == 'rtl') { // *OTL*
$bak_x -= ($this->CurrCol - $oldcolumn) *
($this->ColWidth + $this->ColGap); // *OTL*
} // *OTL*
else { // *OTL*
$bak_x += ($this->CurrCol - $oldcolumn) *
($this->ColWidth + $this->ColGap);
} // *OTL*
$this->x = $bak_x;
$oldcolumn = $this->CurrCol;
$y = $this->y0 - $paint_ht_corr;
$this->oldy = $this->y0 - $paint_ht_corr;
$old_height = 0;
}
/* -- END COLUMNS -- */
}
// RESETTING VALUES
$this->SetTColor($this->ConvertColor(0));
$this->SetDColor($this->ConvertColor(0));
$this->SetFColor($this->ConvertColor(255));
$this->colorarray = '';
$this->spanbgcolorarray = '';
$this->spanbgcolor = false;
$this->spanborder = false;
$this->spanborddet = array();
$this->HREF = '';
$this->textparam = array();
$this->SetTextOutline();
$this->currentfontfamily = '';
$this->currentfontsize = '';
$this->currentfontstyle = '';
$this->currentLang = $this->default_lang; // mPDF 6
$this->RestrictUnicodeFonts($this->default_available_fonts); //
mPDF 6
/* -- TABLES -- */
if ($this->tableLevel) {
$this->SetLineHeight('', $this->table[1][1]
['cellLineHeight']); // *TABLES*
} else
/* -- END TABLES -- */
if (isset($this->blk[$this->blklvl]['line_height']) && $this-
>blk[$this->blklvl]['line_height']) {
$this->SetLineHeight('', $this->blk[$this->blklvl]
['line_height']); // sets default line height
}
$this->ResetStyles();
$this->lSpacingCSS = '';
$this->wSpacingCSS = '';
$this->fixedlSpacing = false;
$this->minwSpacing = 0;
$this->SetDash();
$this->dash_on = false;
$this->dotted_on = false;
}//end of for(i=0;i<arraysize;i++)
$this->Reset(); // mPDF 6
// PAINT DIV BORDER // DISABLED IN COLUMNS AS DOESN'T WORK WHEN
BROKEN ACROSS COLS??
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)) {
$bottom_y = $this->y; // Does not include Bottom Margin
if (isset($this->blk[$this->blklvl]['startpage']) && $this-
>blk[$this->blklvl]['startpage'] != $this->page && $blockstate != 1) {
$this->PaintDivBB('pagetop', $blockstate);
} elseif ($blockstate != 1) {
$this->PaintDivBB('', $blockstate);
}
$this->y = $bottom_y;
$this->x = $bak_x;
}
// Reset Font
$this->SetFontSize($this->default_font_size, false);
if ($table_draft) {
$ch = $this->y - $bak_y;
$this->y = $bak_y;
$this->x = $bak_x;
return $ch;
}
}
function _setBorderLine($b, $k = 1)
{
$this->SetLineWidth($b['w'] / $k);
$this->SetDColor($b['c']);
if ($b['c'][0] == 5) { // RGBa
$this->SetAlpha(ord($b['c'][4]) / 100, 'Normal', false, 'S') .
"\n"; // mPDF 5.7.2
} elseif ($b['c'][0] == 6) { // CMYKa
$this->SetAlpha(ord($b['c'][5]) / 100, 'Normal', false, 'S') .
"\n"; // mPDF 5.7.2
}
}
if (isset($this->blk[$blvl]['x0'])) {
$x0 = $this->blk[$blvl]['x0'];
} // left
if (isset($this->blk[$blvl]['y1'])) {
$y1 = $this->blk[$blvl]['y1'];
} // bottom
// Added mPDF 3.0 Float DIV - ensures backgrounds/borders are drawn to
bottom of page
if ($y1 == 0) {
if ($divider == 'pagebottom') {
$y1 = $this->h - $this->bMargin;
} else {
$y1 = $this->y;
}
}
if (isset($this->blk[$blvl]['y0'])) {
$y0 = $this->blk[$blvl]['y0'];
}
$h = $y1 - $y0;
$w = $this->blk[$blvl]['width'];
$x1 = $x0 + $w;
$brTL_H = 0;
$brTL_V = 0;
$brTR_H = 0;
$brTR_V = 0;
$brBL_H = 0;
$brBL_V = 0;
$brBR_H = 0;
$brBR_V = 0;
$brset = false;
/* -- BORDER-RADIUS -- */
if (isset($this->blk[$blvl]['border_radius_TL_H'])) {
$brTL_H = $this->blk[$blvl]['border_radius_TL_H'];
$brset = true;
}
if (isset($this->blk[$blvl]['border_radius_TL_V'])) {
$brTL_V = $this->blk[$blvl]['border_radius_TL_V'];
$brset = true;
}
if (isset($this->blk[$blvl]['border_radius_TR_H'])) {
$brTR_H = $this->blk[$blvl]['border_radius_TR_H'];
$brset = true;
}
if (isset($this->blk[$blvl]['border_radius_TR_V'])) {
$brTR_V = $this->blk[$blvl]['border_radius_TR_V'];
$brset = true;
}
if (isset($this->blk[$blvl]['border_radius_BR_H'])) {
$brBR_H = $this->blk[$blvl]['border_radius_BR_H'];
$brset = true;
}
if (isset($this->blk[$blvl]['border_radius_BR_V'])) {
$brBR_V = $this->blk[$blvl]['border_radius_BR_V'];
$brset = true;
}
if (isset($this->blk[$blvl]['border_radius_BL_H'])) {
$brBL_H = $this->blk[$blvl]['border_radius_BL_H'];
$brset = true;
}
if (isset($this->blk[$blvl]['border_radius_BL_V'])) {
$brBL_V = $this->blk[$blvl]['border_radius_BL_V'];
$brset = true;
}
// CHECK FOR radii that sum to > width or height of div ********
$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));
if ($f < 1) {
$brTL_H *= $f;
$brTL_V *= $f;
$brTR_H *= $f;
$brTR_V *= $f;
$brBL_H *= $f;
$brBL_V *= $f;
$brBR_H *= $f;
$brBR_V *= $f;
}
/* -- END BORDER-RADIUS -- */
$tbcol = $this->ConvertColor(255);
for ($l = 0; $l <= $blvl; $l++) {
if ($this->blk[$l]['bgcolor']) {
$tbcol = $this->blk[$l]['bgcolorarray'];
}
}
// BORDERS
if (isset($this->blk[$blvl]['y0']) && $this->blk[$blvl]['y0']) {
$y0 = $this->blk[$blvl]['y0'];
}
$h = $y1 - $y0;
$w = $this->blk[$blvl]['width'];
$legend = '';
$legbreakL = 0;
$legbreakR = 0;
// BORDER LEGEND
if (isset($this->blk[$blvl]['border_legend']) && $this-
>blk[$blvl]['border_legend']) {
$legend = $this->blk[$blvl]['border_legend']; // Same
structure array as textbuffer
$txt = $legend[0] = ltrim($legend[0]);
if (!empty($legend[18])) {
$this->otl->trimOTLdata($legend[18], true, false);
} // *OTL*
//Set font, size, style, color
$this->SetFont($legend[4], $legend[2], $legend[11]);
if (isset($legend[3]) && $legend[3]) {
$cor = $legend[3];
$this->SetTColor($cor);
}
$stringWidth = $this->GetStringWidth($txt, true,
$legend[18], $legend[8]);
$save_x = $this->x;
$save_y = $this->y;
$save_currentfontfamily = $this->FontFamily;
$save_currentfontsize = $this->FontSizePt;
$save_currentfontstyle = $this->FontStyle;
$this->y = $y0 - $this->FontSize / 2 + $this->blk[$blvl]
['border_top']['w'] / 2;
$this->x = $x0 + $this->blk[$blvl]['padding_left'] + $this-
>blk[$blvl]['border_left']['w'];
// Set the distance from the border line to the text ? make
configurable variable
$gap = 0.2 * $this->FontSize;
$legbreakL = $this->x - $gap;
$legbreakR = $this->x + $stringWidth + $gap;
$this->magic_reverse_dir($txt, $this->blk[$blvl]
['direction'], $legend[18]);
$fill = '';
$this->Cell($stringWidth, $this->FontSize, $txt, '', 0,
'C', $fill, '', 0, 0, 0, 'M', $fill, false, $legend[18], $legend[8]);
// Reset
$this->x = $save_x;
$this->y = $save_y;
$this->SetFont($save_currentfontfamily,
$save_currentfontstyle, $save_currentfontsize);
$this->SetTColor($this->ConvertColor(0));
}
$this->_setBorderLine($tbd);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$legbreakL -= $border_top / 2; // because line cap
different
$legbreakR += $border_top / 2;
$this->_setDashBorder($tbd['style'], $divider,
$continuingpage, 'T');
}
/* -- BORDER-RADIUS -- */ elseif (($brTL_V && $brTL_H) ||
($brTR_V && $brTR_H) || $tbd['style'] == 'solid' || $tbd['style'] == 'double') {
$this->SetLineJoin(0);
$this->SetLineCap(0);
}
$s = '';
if ($brTR_H && $brTR_V) {
$s .= ($this->_EllipseArc($x0 + $w - $brTR_H, $y0 +
$brTR_V, $brTR_H - $border_top / 2, $brTR_V - $border_top / 2, 1, 2, true)) . "\n";
} else
/* -- END BORDER-RADIUS -- */
if ($tbd['style'] == 'solid' || $tbd['style'] == 'double')
{
$s .= (sprintf('%.3F %.3F m ', ($x0 + $w) * _MPDFK,
($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F m ', ($x0 + $w -
($border_top / 2)) * _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) .
"\n";
}
/* -- BORDER-RADIUS -- */
if ($brTL_H && $brTL_V) {
if ($legend) {
if ($legbreakR < ($x0 + $w - $brTR_H)) {
$s .= (sprintf('%.3F %.3F l ', $legbreakR
* _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
}
if ($legbreakL > ($x0 + $brTL_H )) {
$s .= (sprintf('%.3F %.3F m ', $legbreakL
* _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
$s .= (sprintf('%.3F %.3F l ', ($x0 +
$brTL_H ) * _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK) . "\n");
} else {
$s .= (sprintf('%.3F %.3F m ', ($x0 +
$brTL_H ) * _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
}
} else {
$s .= (sprintf('%.3F %.3F l ', ($x0 + $brTL_H )
* _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
}
$s .= ($this->_EllipseArc($x0 + $brTL_H, $y0 +
$brTL_V, $brTL_H - $border_top / 2, $brTL_V - $border_top / 2, 2, 1)) . "\n";
} else {
/* -- END BORDER-RADIUS -- */
if ($legend) {
if ($legbreakR < ($x0 + $w)) {
$s .= (sprintf('%.3F %.3F l ', $legbreakR
* _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
}
if ($legbreakL > ($x0)) {
$s .= (sprintf('%.3F %.3F m ', $legbreakL
* _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
if ($tbd['style'] == 'solid' ||
$tbd['style'] == 'double') {
$s .= (sprintf('%.3F %.3F l ',
($x0) * _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F l ', ($x0
+ ($border_top / 2)) * _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) .
"\n";
}
} elseif ($tbd['style'] == 'solid' ||
$tbd['style'] == 'double') {
$s .= (sprintf('%.3F %.3F m ', ($x0) *
_MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F m ', ($x0 +
$border_top / 2) * _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) .
"\n";
}
} elseif ($tbd['style'] == 'solid' || $tbd['style']
== 'double') {
$s .= (sprintf('%.3F %.3F l ', ($x0) * _MPDFK,
($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F l ', ($x0 +
($border_top / 2)) * _MPDFK, ($this->h - ($y0 + ($border_top / 2))) * _MPDFK)) .
"\n";
}
/* -- BORDER-RADIUS -- */
}
/* -- END BORDER-RADIUS -- */
$s .= 'S' . "\n";
$this->_out($s);
if ($tbd['style'] == 'double') {
$this->SetLineWidth($tbd['w'] / 3);
$this->SetDColor($tbcol);
$this->_out($s);
}
if (!$brset && $tbd['style'] != 'dotted' && $tbd['style'] !
= 'dashed') {
$this->_out('Q');
}
$this->_setBorderLine($tbd);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$this->_setDashBorder($tbd['style'], $divider,
$continuingpage, 'B');
}
/* -- BORDER-RADIUS -- */ elseif (($brBL_V && $brBL_H) ||
($brBR_V && $brBR_H) || $tbd['style'] == 'solid' || $tbd['style'] == 'double') {
$this->SetLineJoin(0);
$this->SetLineCap(0);
}
$s = '';
if ($brBL_H && $brBL_V) {
$s .= ($this->_EllipseArc($x0 + $brBL_H, $y0 + $h -
$brBL_V, $brBL_H - $border_bottom / 2, $brBL_V - $border_bottom / 2, 3, 2, true)) .
"\n";
} else
/* -- END BORDER-RADIUS -- */
if ($tbd['style'] == 'solid' || $tbd['style'] == 'double')
{
$s .= (sprintf('%.3F %.3F m ', ($x0) * _MPDFK,
($this->h - ($y0 + $h - ($border_bottom / 2))) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F m ', ($x0 + ($border_bottom
/ 2)) * _MPDFK, ($this->h - ($y0 + $h - ($border_bottom / 2))) * _MPDFK)) . "\n";
}
/* -- BORDER-RADIUS -- */
if ($brBR_H && $brBR_V) {
$s .= (sprintf('%.3F %.3F l ', ($x0 + $w -
($border_bottom / 2) - $brBR_H ) * _MPDFK, ($this->h - ($y0 + $h -
($border_bottom / 2))) * _MPDFK)) . "\n";
$s .= ($this->_EllipseArc($x0 + $w - $brBR_H, $y0 +
$h - $brBR_V, $brBR_H - $border_bottom / 2, $brBR_V - $border_bottom / 2, 4, 1)) .
"\n";
} else
/* -- END BORDER-RADIUS -- */
if ($tbd['style'] == 'solid' || $tbd['style'] == 'double')
{
$s .= (sprintf('%.3F %.3F l ', ($x0 + $w) * _MPDFK,
($this->h - ($y0 + $h - ($border_bottom / 2))) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F l ', ($x0 + $w -
($border_bottom / 2)) * _MPDFK, ($this->h - ($y0 + $h - ($border_bottom / 2))) *
_MPDFK)) . "\n";
}
$s .= 'S' . "\n";
$this->_out($s);
if ($tbd['style'] == 'double') {
$this->SetLineWidth($tbd['w'] / 3);
$this->SetDColor($tbcol);
$this->_out($s);
}
if (!$brset && $tbd['style'] != 'dotted' && $tbd['style'] !
= 'dashed') {
$this->_out('Q');
}
if ($this->blk[$blvl]['border_left']) {
$tbd = $this->blk[$blvl]['border_left'];
if (isset($tbd['s']) && $tbd['s']) {
if (!$brset && $tbd['style'] != 'dotted' && $tbd['style'] !
= 'dashed') {
$this->_out('q');
$this->SetLineWidth(0);
$this->_out(sprintf('%.3F %.3F m ', ($x0) * _MPDFK,
($this->h - ($y0)) * _MPDFK));
$this->_out(sprintf('%.3F %.3F l ', ($x0 +
$border_left) * _MPDFK, ($this->h - ($y0 + $border_top)) * _MPDFK));
$this->_out(sprintf('%.3F %.3F l ', ($x0 +
$border_left) * _MPDFK, ($this->h - ($y0 + $h - $border_bottom)) * _MPDFK));
$this->_out(sprintf('%.3F %.3F l ', ($x0) * _MPDFK,
($this->h - ($y0 + $h)) * _MPDFK));
$this->_out(' h W n '); // Ends path no-op & Sets the
clipping path
}
$this->_setBorderLine($tbd);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$this->_setDashBorder($tbd['style'], $divider,
$continuingpage, 'L');
}
/* -- BORDER-RADIUS -- */ elseif (($brTL_V && $brTL_H) ||
($brBL_V && $brBL_H) || $tbd['style'] == 'solid' || $tbd['style'] == 'double') {
$this->SetLineJoin(0);
$this->SetLineCap(0);
}
$s = '';
if ($brTL_V && $brTL_H) {
$s .= ($this->_EllipseArc($x0 + $brTL_H, $y0 +
$brTL_V, $brTL_H - $border_left / 2, $brTL_V - $border_left / 2, 2, 2, true)) .
"\n";
} else
/* -- END BORDER-RADIUS -- */
if ($tbd['style'] == 'solid' || $tbd['style'] == 'double')
{
$s .= (sprintf('%.3F %.3F m ', ($x0 + ($border_left /
2)) * _MPDFK, ($this->h - ($y0)) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F m ', ($x0 + ($border_left /
2)) * _MPDFK, ($this->h - ($y0 + ($border_left / 2))) * _MPDFK)) . "\n";
}
/* -- BORDER-RADIUS -- */
if ($brBL_V && $brBL_H) {
$s .= (sprintf('%.3F %.3F l ', ($x0 + ($border_left /
2)) * _MPDFK, ($this->h - ($y0 + $h - ($border_left / 2) - $brBL_V) ) * _MPDFK)) .
"\n";
$s .= ($this->_EllipseArc($x0 + $brBL_H, $y0 + $h -
$brBL_V, $brBL_H - $border_left / 2, $brBL_V - $border_left / 2, 3, 1)) . "\n";
} else
/* -- END BORDER-RADIUS -- */
if ($tbd['style'] == 'solid' || $tbd['style'] == 'double')
{
$s .= (sprintf('%.3F %.3F l ', ($x0 + ($border_left /
2)) * _MPDFK, ($this->h - ($y0 + $h) ) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F l ', ($x0 + ($border_left /
2)) * _MPDFK, ($this->h - ($y0 + $h - ($border_left / 2)) ) * _MPDFK)) . "\n";
}
$s .= 'S' . "\n";
$this->_out($s);
if ($tbd['style'] == 'double') {
$this->SetLineWidth($tbd['w'] / 3);
$this->SetDColor($tbcol);
$this->_out($s);
}
if (!$brset && $tbd['style'] != 'dotted' && $tbd['style'] !
= 'dashed') {
$this->_out('Q');
}
$this->_setBorderLine($tbd);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$this->_setDashBorder($tbd['style'], $divider,
$continuingpage, 'R');
}
/* -- BORDER-RADIUS -- */ elseif (($brTR_V && $brTR_H) ||
($brBR_V && $brBR_H) || $tbd['style'] == 'solid' || $tbd['style'] == 'double') {
$this->SetLineJoin(0);
$this->SetLineCap(0);
}
$s = '';
if ($brBR_V && $brBR_H) {
$s .= ($this->_EllipseArc($x0 + $w - $brBR_H, $y0 +
$h - $brBR_V, $brBR_H - $border_right / 2, $brBR_V - $border_right / 2, 4, 2,
true)) . "\n";
} else
/* -- END BORDER-RADIUS -- */
if ($tbd['style'] == 'solid' || $tbd['style'] == 'double')
{
$s .= (sprintf('%.3F %.3F m ', ($x0 + $w -
($border_right / 2)) * _MPDFK, ($this->h - ($y0 + $h)) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F m ', ($x0 + $w -
($border_right / 2)) * _MPDFK, ($this->h - ($y0 + $h - ($border_right / 2))) *
_MPDFK)) . "\n";
}
/* -- BORDER-RADIUS -- */
if ($brTR_V && $brTR_H) {
$s .= (sprintf('%.3F %.3F l ', ($x0 + $w -
($border_right / 2)) * _MPDFK, ($this->h - ($y0 + ($border_right / 2) + $brTR_V) )
* _MPDFK)) . "\n";
$s .= ($this->_EllipseArc($x0 + $w - $brTR_H, $y0 +
$brTR_V, $brTR_H - $border_right / 2, $brTR_V - $border_right / 2, 1, 1)) . "\n";
} else
/* -- END BORDER-RADIUS -- */
if ($tbd['style'] == 'solid' || $tbd['style'] == 'double')
{
$s .= (sprintf('%.3F %.3F l ', ($x0 + $w -
($border_right / 2)) * _MPDFK, ($this->h - ($y0) ) * _MPDFK)) . "\n";
} else {
$s .= (sprintf('%.3F %.3F l ', ($x0 + $w -
($border_right / 2)) * _MPDFK, ($this->h - ($y0 + ($border_right / 2)) ) * _MPDFK))
. "\n";
}
$s .= 'S' . "\n";
$this->_out($s);
if ($tbd['style'] == 'double') {
$this->SetLineWidth($tbd['w'] / 3);
$this->SetDColor($tbcol);
$this->_out($s);
}
if (!$brset && $tbd['style'] != 'dotted' && $tbd['style'] !
= 'dashed') {
$this->_out('Q');
}
$this->SetDash();
$this->y = $save_y;
// BACKGROUNDS are disabled in columns/kbt/headers - messes up the
repositioning in printcolumnbuffer
if ($this->ColActive || $this->kwt || $this->keep_block_together) {
return;
}
$bgx0 = $x0;
$bgx1 = $x1;
$bgy0 = $y0;
$bgy1 = $y1;
// Blur edges
$mag = 0.551784; // Bezier Control magic number for 4-part
spline for circle/ellipse
$mag2 = 0.551784; // Bezier Control magic number to fill in
edge of blurred rectangle
$d1 = $sh['spread'] + $sh['blur'] / 2;
$d2 = $sh['spread'] - $sh['blur'] / 2;
$bl = $sh['blur'];
$x00 = $x0 - $d1;
$y00 = $y0 - $d1;
$w00 = $w + $d1 * 2;
$h00 = $h + $d1 * 2;
// RIGHT
$p1x = $x00 + $w00; // control point only matches p3
preceding
$p1y = $y00 + $d1 + $brbgTR_V;
$p2x = $x00 + $w00 - $bl; // control point only matches p4
preceding
$p2y = $y00 + $d1 + $brbgTR_V;
$p3x = $x00 + $w00 - $bl;
$p3y = $y00 + $h00 - $d1 - $brbgBR_V;
$p4x = $x00 + $w00;
$p4c1x = $p4x - $bl / 2;
$p4y = $y00 + $h00 - $d1 - $brbgBR_V;
if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) {
$p1y = $y00 + $bl;
$p2y = $y00 + $bl;
}
if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) {
$p3y = $y00 + $h00 - $bl;
$p4y = $y00 + $h00 - $bl;
}
// BOTTOM
$p1x = $x00 + $w00 - $d1 - $brbgBR_H; // control point only
matches p3 preceding
$p1y = $y00 + $h00;
$p2x = $x00 + $w00 - $d1 - $brbgBR_H; // control point only
matches p4 preceding
$p2y = $y00 + $h00 - $bl;
$p3x = $x00 + $d1 + $brbgBL_H;
$p3y = $y00 + $h00 - $bl;
$p4x = $x00 + $d1 + $brbgBL_H;
$p4y = $y00 + $h00;
$p4c1y = $p4y - $bl / 2;
if ($bl)
$shadow .= $this->grad->CoonsPatchMesh($x00, $y00,
$w00, $h00, $patch_array, $x00, $x00 + $w00, $y00, $y00 + $h00, $colspace, true);
if ($sh['x'] || $sh['y'])
$shadow .= ' Q' . "\n"; // Shadow Offset
$shadow .= ' Q' . "\n"; // Ends path no-op & Sets the
clipping path
}
}
$s .= ' W n '; // Ends path no-op & Sets the clipping path
if ($this->blk[$blvl]['bgcolor']) {
$this->pageBackgrounds[$blvl][] = array('x' => $x0, 'y' => $y0,
'w' => $w, 'h' => $h, 'col' => $this->blk[$blvl]['bgcolorarray'], 'clippath' => $s,
'visibility' => $this->visibility, 'shadow' => $shadow, 'z-index' => $this-
>current_layer);
} elseif ($shadow) {
$this->pageBackgrounds[$blvl][] = array('shadowonly' => true,
'col' => '', 'clippath' => '', 'visibility' => $this->visibility, 'shadow' =>
$shadow, 'z-index' => $this->current_layer);
}
/* -- BACKGROUNDS -- */
if (isset($this->blk[$blvl]['gradient'])) {
$g = $this->grad->parseBackgroundGradient($this->blk[$blvl]
['gradient']);
if ($g) {
$gx = $x0;
$gy = $y0;
$this->pageBackgrounds[$blvl][] = array('gradient' => true,
'x' => $gx, 'y' => $gy, 'w' => $w, 'h' => $h, 'gradtype' => $g['type'], 'stops' =>
$g['stops'], 'colorspace' => $g['colorspace'], 'coords' => $g['coords'], 'extend'
=> $g['extend'], 'clippath' => $s, 'visibility' => $this->visibility, 'z-index' =>
$this->current_layer);
}
}
if (isset($this->blk[$blvl]['background-image'])) {
if (isset($this->blk[$blvl]['background-image']['gradient']) &&
$this->blk[$blvl]['background-image']['gradient'] && preg_match('/(-
moz-)*(repeating-)*(linear|radial)-gradient/', $this->blk[$blvl]['background-
image']['gradient'])) {
$g = $this->grad->parseMozGradient($this->blk[$blvl]
['background-image']['gradient']);
if ($g) {
$gx = $x0;
$gy = $y0;
// origin specifies the background-positioning-area
(bpa)
if ($this->blk[$blvl]['background-image']['origin']
== 'padding-box') {
$gx += $this->blk[$blvl]['border_left']['w'];
$w -= ($this->blk[$blvl]['border_left']['w'] +
$this->blk[$blvl]['border_right']['w']);
if ($this->blk[$blvl]['border_top'] && $divider
!= 'pagetop' && !$continuingpage) {
$gy += $this->blk[$blvl]['border_top']
['w'];
}
if ($this->blk[$blvl]['border_bottom'] &&
$blockstate != 1 && $divider != 'pagebottom') {
$gy1 = $y1 - $this->blk[$blvl]
['border_bottom']['w'];
} else {
$gy1 = $y1;
}
$h = $gy1 - $gy;
} elseif ($this->blk[$blvl]['background-image']
['origin'] == 'content-box') {
$gx += $this->blk[$blvl]['border_left']['w'] +
$this->blk[$blvl]['padding_left'];
$w -= ($this->blk[$blvl]['border_left']['w'] +
$this->blk[$blvl]['padding_left'] + $this->blk[$blvl]['border_right']['w'] + $this-
>blk[$blvl]['padding_right']);
if ($this->blk[$blvl]['border_top'] && $divider
!= 'pagetop' && !$continuingpage) {
$gy += $this->blk[$blvl]['border_top']
['w'] + $this->blk[$blvl]['padding_top'];
}
if ($this->blk[$blvl]['border_bottom'] &&
$blockstate != 1 && $divider != 'pagebottom') {
$gy1 = $y1 - ($this->blk[$blvl]
['border_bottom']['w'] + $this->blk[$blvl]['padding_bottom']);
} else {
$gy1 = $y1 - $this->blk[$blvl]
['padding_bottom'];
}
$h = $gy1 - $gy;
}
if (isset($this->blk[$blvl]['background-image']
['size']['w']) && $this->blk[$blvl]['background-image']['size']['w']) {
$size = $this->blk[$blvl]['background-image']
['size'];
if ($size['w'] != 'contain' && $size['w'] !=
'cover') {
if (stristr($size['w'], '%')) {
$size['w'] += 0;
$size['w'] /= 100;
$w *= $size['w'];
} elseif ($size['w'] != 'auto') {
$w = $size['w'];
}
if (stristr($size['h'], '%')) {
$size['h'] += 0;
$size['h'] /= 100;
$h *= $size['h'];
} elseif ($size['h'] != 'auto') {
$h = $size['h'];
}
}
}
$this->pageBackgrounds[$blvl][] = array('gradient' =>
true, 'x' => $gx, 'y' => $gy, 'w' => $w, 'h' => $h, 'gradtype' => $g['type'],
'stops' => $g['stops'], 'colorspace' => $g['colorspace'], 'coords' => $g['coords'],
'extend' => $g['extend'], 'clippath' => $s, 'visibility' => $this->visibility, 'z-
index' => $this->current_layer);
}
} else {
$image_id = $this->blk[$blvl]['background-image']
['image_id'];
$orig_w = $this->blk[$blvl]['background-image']['orig_w'];
$orig_h = $this->blk[$blvl]['background-image']['orig_h'];
$x_pos = $this->blk[$blvl]['background-image']['x_pos'];
$y_pos = $this->blk[$blvl]['background-image']['y_pos'];
$x_repeat = $this->blk[$blvl]['background-image']
['x_repeat'];
$y_repeat = $this->blk[$blvl]['background-image']
['y_repeat'];
$resize = $this->blk[$blvl]['background-image']['resize'];
$opacity = $this->blk[$blvl]['background-image']
['opacity'];
$itype = $this->blk[$blvl]['background-image']['itype'];
$size = $this->blk[$blvl]['background-image']['size'];
// origin specifies the background-positioning-area (bpa)
$bpa = array('x' => $x0, 'y' => $y0, 'w' => $w, 'h' => $h);
if ($this->blk[$blvl]['background-image']['origin'] ==
'padding-box') {
$bpa['x'] = $x0 + $this->blk[$blvl]['border_left']
['w'];
$bpa['w'] = $w - ($this->blk[$blvl]['border_left']
['w'] + $this->blk[$blvl]['border_right']['w']);
if ($this->blk[$blvl]['border_top'] && $divider !=
'pagetop' && !$continuingpage) {
$bpa['y'] = $y0 + $this->blk[$blvl]
['border_top']['w'];
} else {
$bpa['y'] = $y0;
}
if ($this->blk[$blvl]['border_bottom'] && $blockstate
!= 1 && $divider != 'pagebottom') {
$bpay = $y1 - $this->blk[$blvl]
['border_bottom']['w'];
} else {
$bpay = $y1;
}
$bpa['h'] = $bpay - $bpa['y'];
} elseif ($this->blk[$blvl]['background-image']['origin']
== 'content-box') {
$bpa['x'] = $x0 + $this->blk[$blvl]['border_left']
['w'] + $this->blk[$blvl]['padding_left'];
$bpa['w'] = $w - ($this->blk[$blvl]['border_left']
['w'] + $this->blk[$blvl]['padding_left'] + $this->blk[$blvl]['border_right']['w']
+ $this->blk[$blvl]['padding_right']);
if ($this->blk[$blvl]['border_top'] && $divider !=
'pagetop' && !$continuingpage) {
$bpa['y'] = $y0 + $this->blk[$blvl]
['border_top']['w'] + $this->blk[$blvl]['padding_top'];
} else {
$bpa['y'] = $y0 + $this->blk[$blvl]
['padding_top'];
}
if ($this->blk[$blvl]['border_bottom'] && $blockstate
!= 1 && $divider != 'pagebottom') {
$bpay = $y1 - ($this->blk[$blvl]
['border_bottom']['w'] + $this->blk[$blvl]['padding_bottom']);
} else {
$bpay = $y1 - $this->blk[$blvl]
['padding_bottom'];
}
$bpa['h'] = $bpay - $bpa['y'];
}
$this->pageBackgrounds[$blvl][] = array('x' => $x0, 'y' =>
$y0, 'w' => $w, 'h' => $h, 'image_id' => $image_id, 'orig_w' => $orig_w, 'orig_h'
=> $orig_h, 'x_pos' => $x_pos, 'y_pos' => $y_pos, 'x_repeat' => $x_repeat,
'y_repeat' => $y_repeat, 'clippath' => $s, 'resize' => $resize, 'opacity' =>
$opacity, 'itype' => $itype, 'visibility' => $this->visibility, 'z-index' => $this-
>current_layer, 'size' => $size, 'bpa' => $bpa);
}
}
/* -- END BACKGROUNDS -- */
// Float DIV
$this->blk[$blvl]['bb_painted'][$this->page] = true;
}
/* -- BORDER-RADIUS -- */
function _EllipseArc($x0, $y0, $rx, $ry, $seg = 1, $part = false, $start =
false)
{ // Anticlockwise segment 1-4 TR-TL-BL-BR (part=1 or 2)
$s = '';
if ($rx < 0) {
$rx = 0;
}
if ($ry < 0) {
$ry = 0;
}
$rx *= _MPDFK;
$ry *= _MPDFK;
$astart = 0;
if ($seg == 1) { // Top Right
$afinish = 90;
$nSeg = 4;
} elseif ($seg == 2) { // Top Left
$afinish = 180;
$nSeg = 8;
} elseif ($seg == 3) { // Bottom Left
$afinish = 270;
$nSeg = 12;
} else { // Bottom Right
$afinish = 360;
$nSeg = 16;
}
$astart = deg2rad((float) $astart);
$afinish = deg2rad((float) $afinish);
$totalAngle = $afinish - $astart;
$dt = $totalAngle / $nSeg; // segment angle
$dtm = $dt / 3;
$x0 *= _MPDFK;
$y0 = ($this->h - $y0) * _MPDFK;
$t1 = $astart;
$a0 = $x0 + ($rx * cos($t1));
$b0 = $y0 + ($ry * sin($t1));
$c0 = -$rx * sin($t1);
$d0 = $ry * cos($t1);
$op = false;
for ($i = 1; $i <= $nSeg; $i++) {
// Draw this bit of the total curve
$t1 = ($i * $dt) + $astart;
$a1 = $x0 + ($rx * cos($t1));
$b1 = $y0 + ($ry * sin($t1));
$c1 = -$rx * sin($t1);
$d1 = $ry * cos($t1);
if ($i > ($nSeg - 4) && (!$part || ($part == 1 && $i <= $nSeg -
2) || ($part == 2 && $i > $nSeg - 2))) {
if ($start && !$op) {
$s .= sprintf('%.3F %.3F m ', $a0, $b0);
}
$s .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($a0 +
($c0 * $dtm)), ($b0 + ($d0 * $dtm)), ($a1 - ($c1 * $dtm)), ($b1 - ($d1 * $dtm)),
$a1, $b1);
$op = true;
}
$a0 = $a1;
$b0 = $b1;
$c0 = $c1;
$d0 = $d1;
}
return $s;
}
/* -- END BORDER-RADIUS -- */
$save_y = $this->y;
$w = $this->blk[$blvl]['width'];
$x0 = $this->x; // left
$y0 = $this->y; // top
$x1 = $this->x + $w; // bottom
$y1 = $this->y + $h; // bottom
// BORDERS
if ($objattr['border_top']) {
$tbd = $objattr['border_top'];
if (!empty($tbd['s'])) {
$this->_setBorderLine($tbd, $k);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$this->_setDashBorder($tbd['style'], '', '', 'T');
}
$this->Line($x0, $y0, $x0 + $w, $y0);
// Reset Corners and Dash off
$this->SetLineJoin(2);
$this->SetLineCap(2);
$this->SetDash();
}
}
if ($objattr['border_left']) {
$tbd = $objattr['border_left'];
if (!empty($tbd['s'])) {
$this->_setBorderLine($tbd, $k);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$this->_setDashBorder($tbd['style'], '', '', 'L');
}
$this->Line($x0, $y0, $x0, $y0 + $h);
// Reset Corners and Dash off
$this->SetLineJoin(2);
$this->SetLineCap(2);
$this->SetDash();
}
}
if ($objattr['border_right']) {
$tbd = $objattr['border_right'];
if (!empty($tbd['s'])) {
$this->_setBorderLine($tbd, $k);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$this->_setDashBorder($tbd['style'], '', '', 'R');
}
$this->Line($x0 + $w, $y0, $x0 + $w, $y0 + $h);
// Reset Corners and Dash off
$this->SetLineJoin(2);
$this->SetLineCap(2);
$this->SetDash();
}
}
if ($objattr['border_bottom']) {
$tbd = $objattr['border_bottom'];
if (!empty($tbd['s'])) {
$this->_setBorderLine($tbd, $k);
if ($tbd['style'] == 'dotted' || $tbd['style'] == 'dashed')
{
$this->_setDashBorder($tbd['style'], '', '', 'B');
}
$this->Line($x0, $y0 + $h, $x0 + $w, $y0 + $h);
// Reset Corners and Dash off
$this->SetLineJoin(2);
$this->SetLineCap(2);
$this->SetDash();
}
}
$this->SetDash();
$this->SetAlpha(1);
}
/* -- END HTML-CSS -- */
function Reset()
{
$this->SetTColor($this->ConvertColor(0));
$this->SetDColor($this->ConvertColor(0));
$this->SetFColor($this->ConvertColor(255));
$this->SetAlpha(1);
$this->colorarray = '';
$this->spanbgcolorarray = '';
$this->spanbgcolor = false;
$this->spanborder = false;
$this->spanborddet = array();
$this->ResetStyles();
$this->HREF = '';
$this->textparam = array();
$this->SetTextOutline();
$this->currentfontfamily = '';
$this->currentfontsize = '';
$this->currentfontstyle = '';
/* -- TABLES -- */
if ($this->tableLevel && isset($this->table[1][1]['cellLineHeight'])) {
$this->SetLineHeight('', $this->table[1][1]
['cellLineHeight']); // *TABLES*
} else
/* -- END TABLES -- */
if (isset($this->blk[$this->blklvl]['line_height']) && $this-
>blk[$this->blklvl]['line_height']) {
$this->SetLineHeight('', $this->blk[$this->blklvl]
['line_height']); // sets default line height
}
$this->lSpacingCSS = '';
$this->wSpacingCSS = '';
$this->fixedlSpacing = false;
$this->minwSpacing = 0;
$this->SetDash(); //restore to no dash
$this->dash_on = false;
$this->dotted_on = false;
$this->divwidth = 0;
$this->divheight = 0;
$this->cellTextAlign = '';
$this->cellLineHeight = '';
$this->cellLineStackingStrategy = '';
$this->cellLineStackingShift = '';
$this->oldy = -1;
$bodystyle = array();
if (isset($this->cssmgr->CSS['BODY']['FONT-STYLE'])) {
$bodystyle['FONT-STYLE'] = $this->cssmgr->CSS['BODY']['FONT-
STYLE'];
}
if (isset($this->cssmgr->CSS['BODY']['FONT-WEIGHT'])) {
$bodystyle['FONT-WEIGHT'] = $this->cssmgr->CSS['BODY']['FONT-
WEIGHT'];
}
if (isset($this->cssmgr->CSS['BODY']['COLOR'])) {
$bodystyle['COLOR'] = $this->cssmgr->CSS['BODY']['COLOR'];
}
if (isset($bodystyle)) {
$this->setCSS($bodystyle, 'BLOCK', 'BODY');
}
}
/* -- HTML-CSS -- */
function ReadMetaTags($html)
{
// changes anykey=anyvalue to anykey="anyvalue" (only do this when this
happens inside tags)
$regexp = '/ (\\w+?)=([^\\s>"]+)/si';
$html = preg_replace($regexp, " \$1=\"\$2\"", $html);
if (preg_match('/<title>(.*?)<\/title>/si', $html, $m)) {
$this->SetTitle($m[1]);
}
preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|
content)="([^>]*?)".*?>/si', $html, $aux);
$firstattr = $aux[1];
$secondattr = $aux[3];
for ($i = 0; $i < count($aux[0]); $i++) {
function ReadCharset($html)
{
// Charset conversion
if ($this->allow_charset_conversion) {
if (preg_match('/<head.*charset=([^\'\"\s]*).*<\/head>/si',
$html, $m)) {
if (strtoupper($m[1]) != 'UTF-8') {
$this->charset_in = strtoupper($m[1]);
}
}
}
}
// Set font size first so that e.g. MARGIN 0.83em works on font size
for this element
if (isset($arrayaux['FONT-SIZE'])) {
$v = $arrayaux['FONT-SIZE'];
if (is_numeric($v[0])) {
if ($type == 'BLOCK' && $this->blklvl > 0 && isset($this-
>blk[$this->blklvl - 1]['InlineProperties']) && isset($this->blk[$this->blklvl - 1]
['InlineProperties']['size'])) {
$mmsize = $this->ConvertSize($v, $this->blk[$this-
>blklvl - 1]['InlineProperties']['size']);
} elseif ($type == 'TABLECELL') {
$mmsize = $this->ConvertSize($v, $this-
>default_font_size / _MPDFK);
} else {
$mmsize = $this->ConvertSize($v, $this->FontSize);
}
$this->SetFontSize($mmsize * (_MPDFK), false); //Get size
in points (pt)
} else {
$v = strtoupper($v);
if (isset($this->fontsizes[$v])) {
$this->SetFontSize($this->fontsizes[$v] * $this-
>default_font_size, false);
}
}
if ($tag == 'BODY') {
$this->SetDefaultFontSize($this->FontSizePt);
}
}
// mPDF 6
if (isset($arrayaux['LANG']) && $arrayaux['LANG']) {
if ($this->autoLangToFont && !$this->usingCoreFont) {
if ($arrayaux['LANG'] != $this->default_lang &&
$arrayaux['LANG'] != 'UTF-8') {
list ($coreSuitable, $mpdf_pdf_unifont) =
GetLangOpts($arrayaux['LANG'], $this->useAdobeCJK, $this->fontdata);
if ($mpdf_pdf_unifont) {
$arrayaux['FONT-FAMILY'] = $mpdf_pdf_unifont;
}
if ($tag == 'BODY') {
$this->default_lang = $arrayaux['LANG'];
}
}
}
$this->currentLang = $arrayaux['LANG'];
}
if ($tag == 'BODY') {
$this->SetDefaultFont($fonttype);
}
$this->SetFont($fonttype, $this->currentfontstyle, 0, false);
} else {
$this->SetFont($this->currentfontfamily, $this->currentfontstyle,
0, false);
}
// PADDING
case 'PADDING-TOP':
$this->blk[$this->blklvl]['padding_top'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'PADDING-BOTTOM':
$this->blk[$this->blklvl]['padding_bottom'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'PADDING-LEFT':
if (($tag == 'UL' || $tag == 'OL') && $v ==
'auto') {
$this->blk[$this->blklvl]['padding_left']
= 'auto';
break;
}
$this->blk[$this->blklvl]['padding_left'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'PADDING-RIGHT':
if (($tag == 'UL' || $tag == 'OL') && $v ==
'auto') {
$this->blk[$this->blklvl]
['padding_right'] = 'auto';
break;
}
$this->blk[$this->blklvl]['padding_right'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
// MARGINS
case 'MARGIN-TOP':
$tmp = $this->ConvertSize($v, $this-
>blk[$prevlevel]['inner_width'], $this->FontSize, false);
if (isset($this->blk[$this->blklvl]
['lastbottommargin'])) {
if ($tmp > $this->blk[$this->blklvl]
['lastbottommargin']) {
$tmp -= $this->blk[$this->blklvl]
['lastbottommargin'];
} else {
$tmp = 0;
}
}
$this->blk[$this->blklvl]['margin_top'] = $tmp;
break;
case 'MARGIN-BOTTOM':
$this->blk[$this->blklvl]['margin_bottom'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'MARGIN-LEFT':
$this->blk[$this->blklvl]['margin_left'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'MARGIN-RIGHT':
$this->blk[$this->blklvl]['margin_right'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
/* -- BORDER-RADIUS -- */
case 'BORDER-TOP-LEFT-RADIUS-H':
$this->blk[$this->blklvl]['border_radius_TL_H']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'BORDER-TOP-LEFT-RADIUS-V':
$this->blk[$this->blklvl]['border_radius_TL_V']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'BORDER-TOP-RIGHT-RADIUS-H':
$this->blk[$this->blklvl]['border_radius_TR_H']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'BORDER-TOP-RIGHT-RADIUS-V':
$this->blk[$this->blklvl]['border_radius_TR_V']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'BORDER-BOTTOM-LEFT-RADIUS-H':
$this->blk[$this->blklvl]['border_radius_BL_H']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'BORDER-BOTTOM-LEFT-RADIUS-V':
$this->blk[$this->blklvl]['border_radius_BL_V']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'BORDER-BOTTOM-RIGHT-RADIUS-H':
$this->blk[$this->blklvl]['border_radius_BR_H']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
case 'BORDER-BOTTOM-RIGHT-RADIUS-V':
$this->blk[$this->blklvl]['border_radius_BR_V']
= $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false);
break;
/* -- END BORDER-RADIUS -- */
case 'BOX-SHADOW':
$bs = $this->cssmgr->setCSSboxshadow($v);
if ($bs) {
$this->blk[$this->blklvl]['box_shadow'] =
$bs;
}
break;
case 'BACKGROUND-CLIP':
if (strtoupper($v) == 'PADDING-BOX') {
$this->blk[$this->blklvl]
['background_clip'] = 'padding-box';
} elseif (strtoupper($v) == 'CONTENT-BOX') {
$this->blk[$this->blklvl]
['background_clip'] = 'content-box';
}
break;
case 'PAGE-BREAK-AFTER':
if (strtoupper($v) == 'AVOID') {
$this->blk[$this->blklvl]
['page_break_after_avoid'] = true;
} elseif (strtoupper($v) == 'ALWAYS' ||
strtoupper($v) == 'LEFT' || strtoupper($v) == 'RIGHT') {
$this->blk[$this->blklvl]
['page_break_after'] = strtoupper($v);
}
break;
// mPDF 6 pagebreaktype
case 'BOX-DECORATION-BREAK':
if (strtoupper($v) == 'CLONE') {
$this->blk[$this->blklvl]
['box_decoration_break'] = 'clone';
} elseif (strtoupper($v) == 'SLICE') {
$this->blk[$this->blklvl]
['box_decoration_break'] = 'slice';
}
break;
case 'WIDTH':
if (strtoupper($v) != 'AUTO') {
$this->blk[$this->blklvl]
['css_set_width'] = $this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'],
$this->FontSize, false);
}
break;
// mPDF 6 Lists
// LISTS
case 'LIST-STYLE-TYPE':
$this->blk[$this->blklvl]['list_style_type'] =
strtolower($v);
break;
case 'LIST-STYLE-IMAGE':
$this->blk[$this->blklvl]['list_style_image'] =
strtolower($v);
break;
case 'LIST-STYLE-POSITION':
$this->blk[$this->blklvl]
['list_style_position'] = strtolower($v);
break;
}//end of switch($k)
}
case 'TEXT-INDENT':
// Computed value - to inherit
$this->blk[$this->blklvl]['text_indent'] =
$this->ConvertSize($v, $this->blk[$prevlevel]['inner_width'], $this->FontSize,
false) . 'mm';
break;
case 'LINE-HEIGHT':
$this->blk[$this->blklvl]['line_height'] =
$this->fixLineheight($v);
if (!$this->blk[$this->blklvl]['line_height'])
{
$this->blk[$this->blklvl]['line_height']
= 'N';
} // mPDF 6
break;
// mPDF 6
case 'LINE-STACKING-STRATEGY':
$this->blk[$this->blklvl]
['line_stacking_strategy'] = strtolower($v);
break;
case 'LINE-STACKING-SHIFT':
$this->blk[$this->blklvl]
['line_stacking_shift'] = strtolower($v);
break;
/* -- BACKGROUNDS -- */
case 'BACKGROUND-GRADIENT':
if ($type == 'BLOCK') {
$this->blk[$this->blklvl]['gradient'] =
$v;
}
break;
/* -- END BACKGROUNDS -- */
case 'DIRECTION':
if ($v) {
$this->blk[$this->blklvl]['direction'] =
strtolower($v);
}
break;
}//end of switch($k)
}
if ($type != 'TABLECELL') {
// FOR INLINE and BLOCK
switch ($k) {
case 'TEXT-ALIGN': //left right center justify
if (strtoupper($v) == 'NOJUSTIFY' && $this-
>blk[$this->blklvl]['align'] == "J") {
$this->blk[$this->blklvl]['align'] = "";
}
break;
// bgcolor only - to stay consistent with original
html2fpdf
case 'BACKGROUND':
case 'BACKGROUND-COLOR':
$cor = $this->ConvertColor($v);
if ($cor) {
if ($tag == 'BODY') {
$this->bodyBackgroundColor = $cor;
} elseif ($type == 'INLINE') {
$this->spanbgcolorarray = $cor;
$this->spanbgcolor = true;
$spanbgset = true;
} else {
$this->blk[$this->blklvl]
['bgcolorarray'] = $cor;
$this->blk[$this->blklvl]
['bgcolor'] = true;
}
} elseif ($type != 'INLINE') {
if ($this->ColActive) {
$this->blk[$this->blklvl]
['bgcolorarray'] = $this->blk[$prevlevel]['bgcolorarray'];
$this->blk[$this->blklvl]
['bgcolor'] = $this->blk[$prevlevel]['bgcolor'];
}
}
break;
// FOR ALL
switch ($k) {
case 'LETTER-SPACING':
$this->lSpacingCSS = $v;
if (($this->lSpacingCSS || $this->lSpacingCSS ===
'0') && strtoupper($this->lSpacingCSS) != 'NORMAL') {
$this->fixedlSpacing = $this-
>ConvertSize($this->lSpacingCSS, $this->FontSize);
}
break;
case 'WORD-SPACING':
$this->wSpacingCSS = $v;
if ($this->wSpacingCSS && strtoupper($this-
>wSpacingCSS) != 'NORMAL') {
$this->minwSpacing = $this->ConvertSize($this-
>wSpacingCSS, $this->FontSize);
}
break;
case 'FONT-KERNING':
if (strtoupper($v) == 'NORMAL' || (strtoupper($v) ==
'AUTO' && $this->useKerning)) {
/* -- OTL -- */
if ($this->CurrentFont['haskernGPOS']) {
if (isset($this->OTLtags['Plus'])) {
$this->OTLtags['Plus'] .= ' kern';
} else {
$this->OTLtags['Plus'] = ' kern';
}
}
/* -- END OTL -- */ else { // *OTL*
$this->textvar = ($this->textvar |
FC_KERNING);
} // *OTL*
} elseif (strtoupper($v) == 'NONE' || (strtoupper($v)
== 'AUTO' && !$this->useKerning)) {
if (isset($this->OTLtags['Plus']))
$this->OTLtags['Plus'] =
str_replace('kern', '', $this->OTLtags['Plus']); // *OTL*
if (isset($this->OTLtags['FFPlus']))
$this->OTLtags['FFPlus'] =
preg_replace('/kern[\d]*/', '', $this->OTLtags['FFPlus']);
$this->textvar = ($this->textvar &
~FC_KERNING);
}
break;
/* -- OTL -- */
case 'FONT-LANGUAGE-OVERRIDE':
$v = strtoupper($v);
if (strpos($v, 'NORMAL') !== false) {
$this->fontLanguageOverride = '';
} else {
$this->fontLanguageOverride = trim($v);
}
break;
case 'FONT-VARIANT-POSITION':
if (isset($this->OTLtags['Plus']))
$this->OTLtags['Plus'] =
str_replace(array('sups', 'subs'), '', $this->OTLtags['Plus']);
switch (strtoupper($v)) {
case 'SUPER':
$this->OTLtags['Plus'] .= ' sups';
break;
case 'SUB':
$this->OTLtags['Plus'] .= ' subs';
break;
case 'NORMAL':
break;
}
break;
case 'FONT-VARIANT-CAPS':
$v = strtoupper($v);
if (!isset($this->OTLtags['Plus'])) {
$this->OTLtags['Plus'] = '';
}
$this->OTLtags['Plus'] = str_replace(array('c2sc',
'smcp', 'c2pc', 'pcap', 'unic', 'titl'), '', $this->OTLtags['Plus']);
$this->textvar = ($this->textvar &
~FC_SMALLCAPS); // ?????????????? <small-caps>
if (strpos($v, 'ALL-SMALL-CAPS') !== false) {
$this->OTLtags['Plus'] .= ' c2sc smcp';
} elseif (strpos($v, 'SMALL-CAPS') !== false) {
if (isset($this-
>CurrentFont['hassmallcapsGSUB']) && $this->CurrentFont['hassmallcapsGSUB']) {
$this->OTLtags['Plus'] .= ' smcp';
} else {
$this->textvar = ($this->textvar |
FC_SMALLCAPS);
}
} elseif (strpos($v, 'ALL-PETITE-CAPS') !== false) {
$this->OTLtags['Plus'] .= ' c2pc pcap';
} elseif (strpos($v, 'PETITE-CAPS') !== false) {
$this->OTLtags['Plus'] .= ' pcap';
} elseif (strpos($v, 'UNICASE') !== false) {
$this->OTLtags['Plus'] .= ' unic';
} elseif (strpos($v, 'TITLING-CAPS') !== false) {
$this->OTLtags['Plus'] .= ' titl';
}
break;
case 'FONT-VARIANT-LIGATURES':
$v = strtoupper($v);
if (!isset($this->OTLtags['Plus'])) {
$this->OTLtags['Plus'] = '';
}
if (!isset($this->OTLtags['Minus'])) {
$this->OTLtags['Minus'] = '';
}
if (strpos($v, 'NORMAL') !== false) {
$this->OTLtags['Minus'] =
str_replace(array('liga', 'clig', 'calt'), '', $this->OTLtags['Minus']);
$this->OTLtags['Plus'] =
str_replace(array('dlig', 'hlig'), '', $this->OTLtags['Plus']);
} elseif (strpos($v, 'NONE') !== false) {
$this->OTLtags['Minus'] .= ' liga clig calt';
$this->OTLtags['Plus'] =
str_replace(array('dlig', 'hlig'), '', $this->OTLtags['Plus']);
}
if (strpos($v, 'NO-COMMON-LIGATURES') !== false) {
$this->OTLtags['Minus'] .= ' liga clig';
} elseif (strpos($v, 'COMMON-LIGATURES') !== false) {
$this->OTLtags['Minus'] =
str_replace(array('liga', 'clig'), '', $this->OTLtags['Minus']);
}
if (strpos($v, 'NO-CONTEXTUAL') !== false) {
$this->OTLtags['Minus'] .= ' calt';
} elseif (strpos($v, 'CONTEXTUAL') !== false) {
$this->OTLtags['Minus'] = str_replace('calt',
'', $this->OTLtags['Minus']);
}
if (strpos($v, 'NO-DISCRETIONARY-LIGATURES') !==
false) {
$this->OTLtags['Plus'] = str_replace('dlig',
'', $this->OTLtags['Plus']);
} elseif (strpos($v, 'DISCRETIONARY-LIGATURES') !==
false) {
$this->OTLtags['Plus'] .= ' dlig';
}
if (strpos($v, 'NO-HISTORICAL-LIGATURES') !== false)
{
$this->OTLtags['Plus'] = str_replace('hlig',
'', $this->OTLtags['Plus']);
} elseif (strpos($v, 'HISTORICAL-LIGATURES') !==
false) {
$this->OTLtags['Plus'] .= ' hlig';
}
break;
case 'FONT-VARIANT-NUMERIC':
$v = strtoupper($v);
if (!isset($this->OTLtags['Plus'])) {
$this->OTLtags['Plus'] = '';
}
if (strpos($v, 'NORMAL') !== false) {
$this->OTLtags['Plus'] =
str_replace(array('ordn', 'zero', 'lnum', 'onum', 'pnum', 'tnum', 'frac', 'afrc'),
'', $this->OTLtags['Plus']);
}
if (strpos($v, 'ORDINAL') !== false) {
$this->OTLtags['Plus'] .= ' ordn';
}
if (strpos($v, 'SLASHED-ZERO') !== false) {
$this->OTLtags['Plus'] .= ' zero';
}
if (strpos($v, 'LINING-NUMS') !== false) {
$this->OTLtags['Plus'] .= ' lnum';
$this->OTLtags['Plus'] = str_replace('onum',
'', $this->OTLtags['Plus']);
} elseif (strpos($v, 'OLDSTYLE-NUMS') !== false) {
$this->OTLtags['Plus'] .= ' onum';
$this->OTLtags['Plus'] = str_replace('lnum',
'', $this->OTLtags['Plus']);
}
if (strpos($v, 'PROPORTIONAL-NUMS') !== false) {
$this->OTLtags['Plus'] .= ' pnum';
$this->OTLtags['Plus'] = str_replace('tnum',
'', $this->OTLtags['Plus']);
} elseif (strpos($v, 'TABULAR-NUMS') !== false) {
$this->OTLtags['Plus'] .= ' tnum';
$this->OTLtags['Plus'] = str_replace('pnum',
'', $this->OTLtags['Plus']);
}
if (strpos($v, 'DIAGONAL-FRACTIONS') !== false) {
$this->OTLtags['Plus'] .= ' frac';
$this->OTLtags['Plus'] = str_replace('afrc',
'', $this->OTLtags['Plus']);
} elseif (strpos($v, 'STACKED-FRACTIONS') !== false)
{
$this->OTLtags['Plus'] .= ' afrc';
$this->OTLtags['Plus'] = str_replace('frac',
'', $this->OTLtags['Plus']);
}
break;
case 'FONT-FEATURE-SETTINGS':
$v = strtolower($v);
if (strpos($v, 'normal') !== false) {
$this->OTLtags['FFMinus'] = '';
$this->OTLtags['FFPlus'] = '';
} else {
if (!isset($this->OTLtags['FFPlus'])) {
$this->OTLtags['FFPlus'] = '';
}
if (!isset($this->OTLtags['FFMinus'])) {
$this->OTLtags['FFMinus'] = '';
}
$tags = preg_split('/[,]/', $v);
foreach ($tags AS $t) {
if (preg_match('/[\"\']([a-zA-Z0-9]{4})
[\"\']\s*(on|off|\d*){0,1}/', $t, $m)) {
if ($m[2] == 'off' || $m[2] ===
'0') {
if (strpos($this-
>OTLtags['FFMinus'], $m[1]) === false) {
$this-
>OTLtags['FFMinus'] .= ' ' . $m[1];
}
$this->OTLtags['FFPlus'] =
preg_replace('/' . $m[1] . '[\d]*/', '', $this->OTLtags['FFPlus']);
} else {
if ($m[2] == 'on') {
$m[2] = '1';
}
if (strpos($this-
>OTLtags['FFPlus'], $m[1]) === false) {
$this->OTLtags['FFPlus']
.= ' ' . $m[1] . $m[2];
}
$this->OTLtags['FFMinus'] =
str_replace($m[1], '', $this->OTLtags['FFMinus']);
}
}
}
}
break;
/* -- END OTL -- */
case 'TEXT-SHADOW':
$ts = $this->cssmgr->setCSStextshadow($v);
if ($ts) {
$this->textshadow = $ts;
}
break;
case 'HYPHENS':
if (strtoupper($v) == 'NONE') {
$this->textparam['hyphens'] = 2;
} elseif (strtoupper($v) == 'AUTO') {
$this->textparam['hyphens'] = 1;
} elseif (strtoupper($v) == 'MANUAL') {
$this->textparam['hyphens'] = 0;
}
break;
case 'TEXT-OUTLINE':
if (strtoupper($v) == 'NONE') {
$this->textparam['outline-s'] = false;
}
break;
case 'TEXT-OUTLINE-WIDTH':
case 'OUTLINE-WIDTH':
switch (strtoupper($v)) {
case 'THIN': $v = '0.03em';
break;
case 'MEDIUM': $v = '0.05em';
break;
case 'THICK': $v = '0.07em';
break;
}
$w = $this->ConvertSize($v, $this->FontSize, $this-
>FontSize);
if ($w) {
$this->textparam['outline-WIDTH'] = $w;
$this->textparam['outline-s'] = true;
} else {
$this->textparam['outline-s'] = false;
}
break;
case 'TEXT-OUTLINE-COLOR':
case 'OUTLINE-COLOR':
if (strtoupper($v) == 'INVERT') {
if ($this->colorarray) {
$cor = $this->colorarray;
$this->textparam['outline-COLOR'] =
$this->_invertColor($cor);
} else {
$this->textparam['outline-COLOR'] =
$this->ConvertColor(255);
}
} else {
$cor = $this->ConvertColor($v);
if ($cor) {
$this->textparam['outline-COLOR'] = $cor;
}
}
break;
/* -- END HTML-CSS -- */
function ResetStyles()
{
foreach (array('B', 'I') as $s) {
$this->$s = false;
}
$this->currentfontstyle = '';
$this->SetFont('', '', 0, false);
}
$line = $chunk[0];
$OTLdata = (isset($chunk[18]) ? $chunk[18] : NULL);
// mPDF ITERATION
if ($this->iterationCounter)
$line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/',
'\\1', $line);
if ($line == "\n") {
$acclength = 0; // mPDF 6 (accumulated length across > 1
chunk)
continue;
}
$line = trim($line);
if (!empty($OTLdata)) {
$this->otl->trimOTLdata($OTLdata, true, true);
} // *OTL*
// SET FONT SIZE/STYLE from $chunk[n]
// FONTSIZE
if (isset($chunk[11]) and $chunk[11] != '') {
if ($this->shrin_k) {
$this->SetFontSize($chunk[11] / $this->shrin_k,
false);
} else {
$this->SetFontSize($chunk[11], false);
}
}
// FONTFAMILY
if (isset($chunk[4]) and $chunk[4] != '') {
$font = $this->SetFont($chunk[4], $this->FontStyle, 0,
false);
}
// B I
if (isset($chunk[2]) and $chunk[2] != '') {
$this->SetStyles($chunk[2]);
}
// mPDF 6
// If overflow==wrap ($checkletter) OR (No word breaks and
contains CJK)
if ($checkletter || (!preg_match('/(\xe2\x80\x8b| )/',
trim($line)) && preg_match("/([" . $this->pregCJKchars . "])/u", $line) )) {
if (preg_match("/([" . $this->pregCJKchars . "])/u",
$line)) {
$checkCJK = true;
} else {
$checkCJK = false;
}
// mPDF 6
if ($checkCJK) {
if (preg_match("/[" . $this->CJKleading .
"]/u", $letter) && $k > 0) {
$letter = $letters[$k - 1] . $letter;
}
if (preg_match("/[" . $this->CJKfollowing .
"]/u", $letter) && $k < (count($letters) - 1)) {
$letter = $letter . $letters[$k + 1];
}
}
// mPDF 6
if (count($words) == 1 && substr($chunk[0], 0, 1) !=
' ') {
$acclength += $wordwidth;
} elseif (count($words) > 1 && $k == 0 &&
substr($chunk[0], 0, 1) != ' ') {
$acclength += $wordwidth;
} else {
$acclength = $wordwidth;
}
$acclongest = max($acclongest, $acclength);
if (count($words) == 1 && substr($chunk[0], -1, 1) ==
' ') {
$acclength = 0;
} elseif (count($words) > 1 && ($k != (count($words)
- 1) || substr($chunk[0], -1, 1) == ' ')) {
$acclength = 0;
}
$table['padding']['T'] /= $k;
$table['padding']['R'] /= $k;
$table['padding']['B'] /= $k;
$table['padding']['L'] /= $k;
$table['margin']['T'] /= $k;
$table['margin']['R'] /= $k;
$table['margin']['B'] /= $k;
$table['margin']['L'] /= $k;
$table['border_details']['T']['w'] /= $k;
$table['border_details']['R']['w'] /= $k;
$table['border_details']['B']['w'] /= $k;
$table['border_details']['L']['w'] /= $k;
if (isset($table['max_cell_border_width']['T']))
$table['max_cell_border_width']['T'] /= $k;
if (isset($table['max_cell_border_width']['R']))
$table['max_cell_border_width']['R'] /= $k;
if (isset($table['max_cell_border_width']['B']))
$table['max_cell_border_width']['B'] /= $k;
if (isset($table['max_cell_border_width']['L']))
$table['max_cell_border_width']['L'] /= $k;
if ($this->simpleTables) {
$table['simple']['border_details']['T']['w'] /= $k;
$table['simple']['border_details']['R']['w'] /= $k;
$table['simple']['border_details']['B']['w'] /= $k;
$table['simple']['border_details']['L']['w'] /= $k;
}
$table['miw'] /= $k;
$table['maw'] /= $k;
if (isset($table['decimal_align'][$j]['maxs0']) &&
$table['decimal_align'][$j]['maxs0']) {
$table['decimal_align'][$j]['maxs0'] /= $k;
}
if (isset($table['decimal_align'][$j]['maxs1']) &&
$table['decimal_align'][$j]['maxs1']) {
$table['decimal_align'][$j]['maxs1'] /= $k;
}
function read_short(&$fh)
{
$s = fread($fh, 2);
$a = (ord($s[0]) << 8) + ord($s[1]);
if ($a & (1 << 15)) {
$a = ($a - (1 << 16));
}
return $a;
}
function _packCellBorder($cell)
{
if (!is_array($cell) || !isset($cell)) {
return '';
}
if (!$this->packTableData) {
return $cell;
}
// = 186 bytes
$bindata = pack("nnda6A10nnda6A10nnda6A10nnda6A10nd9", $cell['border'],
$cell['border_details']['R']['s'], $cell['border_details']['R']['w'],
$cell['border_details']['R']['c'], $cell['border_details']['R']['style'],
$cell['border_details']['R']['dom'], $cell['border_details']['L']['s'],
$cell['border_details']['L']['w'], $cell['border_details']['L']['c'],
$cell['border_details']['L']['style'], $cell['border_details']['L']['dom'],
$cell['border_details']['T']['s'], $cell['border_details']['T']['w'],
$cell['border_details']['T']['c'], $cell['border_details']['T']['style'],
$cell['border_details']['T']['dom'], $cell['border_details']['B']['s'],
$cell['border_details']['B']['w'], $cell['border_details']['B']['c'],
$cell['border_details']['B']['style'], $cell['border_details']['B']['dom'],
$cell['border_details']['mbw']['BL'], $cell['border_details']['mbw']['BR'],
$cell['border_details']['mbw']['RT'], $cell['border_details']['mbw']['RB'],
$cell['border_details']['mbw']['TL'], $cell['border_details']['mbw']['TR'],
$cell['border_details']['mbw']['LT'], $cell['border_details']['mbw']['LB'],
(isset($cell['border_details']['cellposdom']) ? $cell['border_details']
['cellposdom'] : 0)
);
return $bindata;
}
function _getBorderWidths($bindata)
{
if (!$bindata) {
return array(0, 0, 0, 0);
}
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']);
}
$bd =
unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10ts
t/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd",
$bindata);
$cell['border_details']['R']['w'] = $bd['rw'];
$cell['border_details']['L']['w'] = $bd['lw'];
$cell['border_details']['T']['w'] = $bd['tw'];
$cell['border_details']['B']['w'] = $bd['bw'];
return array($bd['tw'], $bd['rw'], $bd['bw'], $bd['lw']);
}
function _unpackCellBorder($bindata)
{
if (!$bindata) {
return array();
}
if (!$this->packTableData) {
return $bindata;
}
$bd =
unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10ts
t/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd",
$bindata);
$cell['border'] = $bd['bord'];
$cell['border_details']['R']['s'] = $bd['rs'];
$cell['border_details']['R']['w'] = $bd['rw'];
$cell['border_details']['R']['c'] = str_pad($bd['rca'], 6, "\x00");
$cell['border_details']['R']['style'] = trim($bd['rst']);
$cell['border_details']['R']['dom'] = $bd['rd'];
$cell['border_details']['L']['s'] = $bd['ls'];
$cell['border_details']['L']['w'] = $bd['lw'];
$cell['border_details']['L']['c'] = str_pad($bd['lca'], 6, "\x00");
$cell['border_details']['L']['style'] = trim($bd['lst']);
$cell['border_details']['L']['dom'] = $bd['ld'];
$cell['border_details']['T']['s'] = $bd['ts'];
$cell['border_details']['T']['w'] = $bd['tw'];
$cell['border_details']['T']['c'] = str_pad($bd['tca'], 6, "\x00");
$cell['border_details']['T']['style'] = trim($bd['tst']);
$cell['border_details']['T']['dom'] = $bd['td'];
$cell['border_details']['B']['s'] = $bd['bs'];
$cell['border_details']['B']['w'] = $bd['bw'];
$cell['border_details']['B']['c'] = str_pad($bd['bca'], 6, "\x00");
$cell['border_details']['B']['style'] = trim($bd['bst']);
$cell['border_details']['B']['dom'] = $bd['bd'];
$cell['border_details']['mbw']['BL'] = $bd['mbl'];
$cell['border_details']['mbw']['BR'] = $bd['mbr'];
$cell['border_details']['mbw']['RT'] = $bd['mrt'];
$cell['border_details']['mbw']['RB'] = $bd['mrb'];
$cell['border_details']['mbw']['TL'] = $bd['mtl'];
$cell['border_details']['mbw']['TR'] = $bd['mtr'];
$cell['border_details']['mbw']['LT'] = $bd['mlt'];
$cell['border_details']['mbw']['LB'] = $bd['mlb'];
$cell['border_details']['cellposdom'] = $bd['cpd'];
return($cell);
}
$nc = $table['nc'];
$nr = $table['nr'];
$listspan = array();
if ($table['borders_separate']) {
$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'];
} else {
$tblbw = $table['max_cell_border_width']['L'] / 2 +
$table['max_cell_border_width']['R'] / 2 + $table['margin']['L'] + $table['margin']
['R'];
}
// ADDED table['l'][colno]
// = total length of text approx (using $c['s']) in that column - used
to approximately distribute col widths in _tableWidth
//
for ($j = 0; $j < $nc; $j++) { //columns
$wc = &$table['wc'][$j];
for ($i = 0; $i < $nr; $i++) { //rows
if (isset($cs[$i][$j]) && $cs[$i][$j]) {
$c = &$cs[$i][$j];
if ($this->simpleTables) {
if ($table['borders_separate']) { // NB twice
border width
$extrcw = $table['simple']
['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] +
$c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
} else {
$extrcw = $table['simple']
['border_details']['L']['w'] / 2 + $table['simple']['border_details']['R']['w'] / 2
+ $c['padding']['L'] + $c['padding']['R'];
}
} else {
if ($this->packTableData) {
list($bt, $br, $bb, $bl) = $this-
>_getBorderWidths($c['borderbin']);
} else {
$br = $c['border_details']['R']['w'];
$bl = $c['border_details']['L']['w'];
}
if ($table['borders_separate']) { // NB twice
border width
$extrcw = $bl + $br + $c['padding']['L']
+ $c['padding']['R'] + $table['border_spacing_H'];
} else {
$extrcw = $bl / 2 + $br / 2 +
$c['padding']['L'] + $c['padding']['R'];
}
}
$c['absmiw'] = $mw;
if ($firstpass) {
if (isset($table['l'][$j])) {
$table['l'][$j] += $c['miw'];
} else {
$table['l'][$j] = $c['miw'];
}
}
}
if ($c['miw'] > $wc['miw']) {
$wc['miw'] = $c['miw'];
}
if ($wc['miw'] > $wc['maw']) {
$wc['maw'] = $wc['miw'];
}
continue;
}
if ($firstpass) {
if (isset($c['s'])) {
$c['s'] += $extrcw;
}
if (isset($c['maxs'])) {
$c['maxs'] += $extrcw;
}
if (isset($c['nestedmiw'])) {
$c['nestedmiw'] += $extrcw;
}
if (isset($c['nestedmaw'])) {
$c['nestedmaw'] += $extrcw;
}
}
$checkminwidth = 0;
$checkmaxwidth = 0;
$totallength = 0;
// If sum of widths as % >= 100% and not all columns are set
// Set a nominal width of 1% for unset columns
if ($sumpc >= 100 && $notset) {
for ($i = 0; $i < $nc; $i++) {
if ((!isset($table['wc'][$i]['wpercent']) || !
$table['wc'][$i]['wpercent']) &&
(!isset($table['wc'][$i]['w']) || !$table['wc']
[$i]['w'])) {
$table['wc'][$i]['wpercent'] = 1;
}
}
}
$checkminwidth += $tblbw;
$checkmaxwidth += $tblbw;
// mPDF 6
if ($this->table_rotate) {
$mxw = $this->tbrot_maxw;
} else {
$mxw = $this->blk[$this->blklvl]['inner_width'];
}
if (!isset($table['overflow'])) {
$table['overflow'] = null;
}
if ($table['overflow'] == 'visible') {
return array(0, 0);
} elseif ($table['overflow'] == 'hidden' && !$this->table_rotate && !
$this->ColActive && $checkminwidth > $mxw) {
$table['w'] = $table['miw'];
return array(0, 0);
}
//elseif ($table['overflow']=='wrap') { return array(0,0); } //
mPDF 6
function _tableWidth(&$table)
{
$widthcols = &$table['wc'];
$numcols = $table['nc'];
$tablewidth = 0;
if ($table['borders_separate']) {
$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'];
} else {
$tblbw = $table['max_cell_border_width']['L'] / 2 +
$table['max_cell_border_width']['R'] / 2 + $table['margin']['L'] + $table['margin']
['R'];
}
// Allocate spare (more than col's minimum width) across the cols
according to their approx total text length
// Do it by setting minimum width here
if ($table['w'] > $wis + $tblbw) {
// First set any cell widths set as percentages
if ($table['w'] < $temppgwidth || $this-
>keep_table_proportions) {
for ($k = 0; $k < $numcols; $k++) {
if (isset($widthcols[$k]['wpercent'])) {
$curr = $widthcols[$k]['miw'];
$widthcols[$k]['miw'] = ($table['w'] -
$tblbw) * $widthcols[$k]['wpercent'] / 100;
$wis += $widthcols[$k]['miw'] - $curr;
$wisa += $widthcols[$k]['miw'] - $curr;
}
}
}
// Now allocate surplus up to maximum width of each column
$surplus = 0;
$ttl = 0; // number of surplus columns
if (!count($list)) {
$wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra
space to distribute
for ($k = 0; $k < $numcols; $k++) {
$spareratio = ($table['l'][$k] /
$totaltextlength); // gives ratio to divide up free space
// Don't allocate more than Maximum required
width - save rest in surplus
if ($widthcols[$k]['miw'] + ($wi * $spareratio)
>= $widthcols[$k]['maw']) { // mPDF 5.7.3
$surplus += ($wi * $spareratio) -
($widthcols[$k]['maw'] - $widthcols[$k]['miw']);
$widthcols[$k]['miw'] = $widthcols[$k]
['maw'];
} else {
$notsetlist[] = $k;
$ttl += $table['l'][$k];
$widthcols[$k]['miw'] += ($wi *
$spareratio);
}
}
} else {
$wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra
space to distribute
foreach ($list as $k) {
$spareratio = ($table['l'][$k] /
$totalatextlength); // gives ratio to divide up free space
// Don't allocate more than Maximum required
width - save rest in surplus
if ($widthcols[$k]['miw'] + ($wi * $spareratio)
>= $widthcols[$k]['maw']) { // mPDF 5.7.3
$surplus += ($wi * $spareratio) -
($widthcols[$k]['maw'] - $widthcols[$k]['miw']);
$widthcols[$k]['miw'] = $widthcols[$k]
['maw'];
} else {
$notsetlist[] = $k;
$ttl += $table['l'][$k];
$widthcols[$k]['miw'] += ($wi *
$spareratio);
}
}
}
// If surplus still left over apportion it across columns
if ($surplus) {
// if some are set only add to remaining - otherwise
add to all of them
if (count($notsetlist) && count($notsetlist) <
$numcols) {
foreach ($notsetlist AS $i) {
if ($ttl)
$widthcols[$i]['miw'] += $surplus *
$table['l'][$i] / $ttl;
}
}
// If some widths are defined, and others have been
added up to their maxmum
elseif (count($list) && count($list) < $numcols) {
foreach ($list AS $i) {
$widthcols[$i]['miw'] += $surplus /
count($list);
}
} elseif ($numcols) { // If all columns
$ttl = array_sum($table['l']);
for ($i = 0; $i < $numcols; $i++) {
$widthcols[$i]['miw'] += $surplus *
$table['l'][$i] / $ttl;
}
}
}
}
// This sets the columns all to minimum width (which has been
increased above if appropriate)
for ($i = 0; $i < $numcols; $i++) {
$widthcols[$i] = $widthcols[$i]['miw'];
}
function _tableHeight(&$table)
{
$level = $table['level'];
$levelid = $table['levelid'];
$cells = &$table['cells'];
$numcols = $table['nc'];
$numrows = $table['nr'];
$listspan = array();
$checkmaxheight = 0;
$headerrowheight = 0;
$checkmaxheightplus = 0;
$headerrowheightplus = 0;
$firstrowheight = 0;
$footerrowheight = 0;
$footerrowheightplus = 0;
if ($this->table_rotate) {
$temppgheight = $this->tbrot_maxh;
$remainingpage = $this->tbrot_maxh;
} else {
$temppgheight = ($this->h - $this->bMargin - $this->tMargin) -
$this->kwt_height;
$remainingpage = ($this->h - $this->bMargin - $this->y) - $this-
>kwt_height;
if ($this->simpleTables) {
if ($table['borders_separate']) { // NB twice
border width
$extraWLR = ($table['simple']
['border_details']['L']['w'] + $table['simple']['border_details']['R']['w']) +
($c['padding']['L'] + $c['padding']['R']) + $table['border_spacing_H'];
$extrh = ($table['simple']
['border_details']['T']['w'] + $table['simple']['border_details']['B']['w']) +
($c['padding']['T'] + $c['padding']['B']) + $table['border_spacing_V'];
} else {
$extraWLR = ($table['simple']
['border_details']['L']['w'] + $table['simple']['border_details']['R']['w']) / 2 +
($c['padding']['L'] + $c['padding']['R']);
$extrh = ($table['simple']
['border_details']['T']['w'] + $table['simple']['border_details']['B']['w']) / 2 +
($c['padding']['T'] + $c['padding']['B']);
}
} else {
if ($this->packTableData) {
list($bt, $br, $bb, $bl) = $this-
>_getBorderWidths($c['borderbin']);
} else {
$bt = $c['border_details']['T']['w'];
$bb = $c['border_details']['B']['w'];
$br = $c['border_details']['R']['w'];
$bl = $c['border_details']['L']['w'];
}
if ($table['borders_separate']) { // NB twice
border width
$extraWLR = $bl + $br + $c['padding']
['L'] + $c['padding']['R'] + $table['border_spacing_H'];
$extrh = $bt + $bb + $c['padding']['T'] +
$c['padding']['B'] + $table['border_spacing_V'];
} else {
$extraWLR = $bl / 2 + $br / 2 +
$c['padding']['L'] + $c['padding']['R'];
$extrh = $bt / 2 + $bb / 2 +
$c['padding']['T'] + $c['padding']['B'];
}
}
$heightrow = &$table['hr'];
foreach ($listspan as $span) {
list($i, $j) = $span;
$c = &$cells[$i][$j];
$lr = $i + $c['rowspan'];
if ($lr > $numrows)
$lr = $numrows;
$hs = $hsa = 0;
$list = array();
for ($k = $i; $k < $lr; $k++) {
$hs += $heightrow[$k];
// mPDF 6
$sh = false; // specified height
for ($m = 0; $m < $numcols; $m++) { //columns
$tc = &$cells[$k][$m];
if (isset($tc['rowspan'])) {
continue;
}
if (isset($tc['h'])) {
$sh = true;
break;
}
}
if (!$sh) {
$list[] = $k;
}
}
if ($table['borders_separate']) {
if ($i == ($numrows - 1) || ($i + $c['rowspan']) ==
($numrows)) {
$extra = $table['margin']['B'] + $table['padding']
['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V'] / 2;
} else {
$extra = $table['border_spacing_V'] / 2;
}
} else {
if (!$this->simpleTables) {
if ($this->packTableData) {
list($bt, $br, $bb, $bl) = $this-
>_getBorderWidths($c['borderbin']);
} else {
$bb = $c['border_details']['B']['w'];
}
$extra = $bb / 2;
} elseif ($this->simpleTables) {
$extra = $table['simple']['border_details']['B']['w']
/ 2;
}
}
if (!empty($table['is_thead'][$i])) {
$headerrowheight = max($headerrowheight, $hs);
$headerrowheightplus = max($headerrowheightplus, $hs +
$extra);
} elseif (!empty($table['is_tfoot'][$i])) {
$footerrowheight = max($footerrowheight, $hs);
$footerrowheightplus = max($footerrowheightplus, $hs +
$extra);
} else {
$checkmaxheight = max($checkmaxheight, $hs);
$checkmaxheightplus = max($checkmaxheightplus, $hs +
$extra);
}
if ($this->tableLevel == 1 && $i == (isset($table['headernrows'])
? $table['headernrows'] : 0)) {
$firstrowheight = max($hs, $firstrowheight);
}
$table['h'] = array_sum($heightrow);
unset($heightrow);
if ($table['borders_separate']) {
$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'];
} else {
$table['h'] += $table['margin']['T'] + $table['margin']['B'] +
$table['max_cell_border_width']['T'] / 2 + $table['max_cell_border_width']['B'] /
2;
}
if ($bord == -1) {
$this->Rect($x, $y, $w, $h);
} elseif ($this->simpleTables && ($cort == 'cell')) {
$this->SetLineWidth($details['L']['w']);
if ($details['L']['c']) {
$this->SetDColor($details['L']['c']);
} else {
$this->SetDColor($this->ConvertColor(0));
}
$this->SetLineJoin(0);
$this->Rect($x, $y, $w, $h);
} elseif ($bord) {
if (!$bSeparate && $buffer) {
$priority = 'LRTB';
for ($p = 0; $p < strlen($priority); $p++) {
$side = $priority[$p];
$details['p'] = $side;
$dom = 0;
if (isset($details[$side]['w'])) {
$dom += ($details[$side]['w'] * 100000);
}
if (isset($details[$side]['style'])) {
$dom += (array_search($details[$side]['style'],
$this->borderstyles) * 100);
}
if (isset($details[$side]['dom'])) {
$dom += ($details[$side]['dom'] * 10);
}
$save = false;
if ($side == 'T' && $this->issetBorder($bord,
_BORDER_TOP)) {
$cbord = _BORDER_TOP;
$save = true;
} elseif ($side == 'L' && $this->issetBorder($bord,
_BORDER_LEFT)) {
$cbord = _BORDER_LEFT;
$save = true;
} elseif ($side == 'R' && $this->issetBorder($bord,
_BORDER_RIGHT)) {
$cbord = _BORDER_RIGHT;
$save = true;
} elseif ($side == 'B' && $this->issetBorder($bord,
_BORDER_BOTTOM)) {
$cbord = _BORDER_BOTTOM;
$save = true;
}
if ($save) {
$this->cellBorderBuffer[] =
pack("A16nCnda6A10d14", str_pad(sprintf("%08.7f", $dom), 16, "0", STR_PAD_LEFT),
$cbord, ord($side), $details[$side]['s'], $details[$side]['w'], $details[$side]
['c'], $details[$side]['style'], $x, $y, $w, $h, $details['mbw']['BL'],
$details['mbw']['BR'], $details['mbw']['RT'], $details['mbw']['RB'],
$details['mbw']['TL'], $details['mbw']['TR'], $details['mbw']['LT'],
$details['mbw']['LB'], $details['cellposdom'], 0
);
if ($details[$side]['style'] == 'ridge' ||
$details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' ||
$details[$side]['style'] == 'outset' || $details[$side]['style'] == 'double') {
$details[$side]['overlay'] = true;
$this->cellBorderBuffer[] =
pack("A16nCnda6A10d14", str_pad(sprintf("%08.7f", ($dom + 4)), 16, "0",
STR_PAD_LEFT), $cbord, ord($side), $details[$side]['s'], $details[$side]['w'],
$details[$side]['c'], $details[$side]['style'], $x, $y, $w, $h, $details['mbw']
['BL'], $details['mbw']['BR'], $details['mbw']['RT'], $details['mbw']['RB'],
$details['mbw']['TL'], $details['mbw']['TR'], $details['mbw']['LT'],
$details['mbw']['LB'], $details['cellposdom'], 1
);
}
}
}
return;
}
$x2 = $x + $w;
$y2 = $y + $h;
$oldlinewidth = $this->LineWidth;
$this->SetLineWidth($this->LineWidth /
3);
$tbcol = $this->ConvertColor(255);
for ($l = 0; $l <= $this->blklvl; $l++) {
if ($this->blk[$l]['bgcolor']) {
$tbcol = ($this->blk[$l]
['bgcolorarray']);
}
}
if ($bSeparate) {
$cellBorderOverlay[] = array(
'x' => $lx1 + $xadj,
'y' => $ly1 + $yadj,
'x2' => $lx2 - $xadj2,
'y2' => $ly2 - $yadj2,
'col' => $tbcol,
'lw' => $this->LineWidth,
);
} else {
$this->SetDColor($tbcol);
$this->Line($lx1 + $xadj, $ly1 +
$yadj, $lx2 - $xadj2, $ly2 - $yadj2);
}
}
} elseif (isset($details[$side]['style']) &&
($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' ||
$details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset')) {
if (!isset($details[$side]['overlay']) || !
$details[$side]['overlay'] || $bSeparate) {
if ($details[$side]['c']) {
$this->SetDColor($details[$side]
['c']);
} else {
$this->SetDColor($this-
>ConvertColor(0));
}
if ($details[$side]['style'] == 'outset'
|| $details[$side]['style'] == 'groove') {
$nc = $this-
>_darkenColor($details[$side]['c']);
$this->SetDColor($nc);
} elseif ($details[$side]['style'] ==
'ridge' || $details[$side]['style'] == 'inset') {
$nc = $this-
>_lightenColor($details[$side]['c']);
$this->SetDColor($nc);
}
$this->Line($lx1 + $xadj, $ly1 + $yadj,
$lx2 - $xadj2, $ly2 - $yadj2);
}
if ((isset($details[$side]['overlay']) &&
$details[$side]['overlay']) || $bSeparate) {
if ($details[$side]['c']) {
$this->SetDColor($details[$side]
['c']);
} else {
$this->SetDColor($this-
>ConvertColor(0));
}
$doubleadj = ($this->LineWidth) / 3;
$this->SetLineWidth($this->LineWidth /
2);
$xadj3 = $yadj3 = $wadj3 = $hadj3 = 0;
if ($details[$side]['style'] == 'ridge'
|| $details[$side]['style'] == 'inset') {
$nc = $this-
>_darkenColor($details[$side]['c']);
if ($bSeparate) {
$cellBorderOverlay[] = array(
'x' => $lx1 + $xadj + $xadj3,
'y' => $ly1 + $yadj + $yadj3,
'x2' => $lx2 - $xadj2 +
$xadj3 + $wadj3,
'y2' => $ly2 - $yadj2 +
$yadj3 + $hadj3,
'col' => $nc,
'lw' => $this->LineWidth,
);
} else {
$this->SetDColor($nc);
$this->Line($lx1 + $xadj + $xadj3,
$ly1 + $yadj + $yadj3, $lx2 - $xadj2 + $xadj3 + $wadj3, $ly2 - $yadj2 + $yadj3 +
$hadj3);
}
}
} else {
/* -- END TABLES-ADVANCED-BORDERS -- */
if ($details[$side]['style'] == 'dashed') {
$dashsize = 2; // final dash will be this
+ 1*linewidth
$dashsizek = 1.5; // ratio of Dash/Blank
$this->SetDash($dashsize, ($dashsize /
$dashsizek) + ($this->LineWidth * 2));
} elseif ($details[$side]['style'] == 'dotted')
{
$this->SetLineJoin(1);
$this->SetLineCap(1);
$this->SetDash(0.001, ($this->LineWidth *
2));
}
if ($details[$side]['c']) {
$this->SetDColor($details[$side]['c']);
} else {
$this->SetDColor($this->ConvertColor(0));
}
$this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 -
$xadj2, $ly2 - $yadj2);
/* -- TABLES-ADVANCED-BORDERS -- */
}
/* -- END TABLES-ADVANCED-BORDERS -- */
// Reset Corners
$this->SetDash();
//BUTT style line cap
$this->SetLineCap(2);
}
}
// $this->SetLineWidth($oldlinewidth);
// $this->SetDColor($this->ConvertColor(0));
}
}
/* -- TABLES -- */
/* -- TABLES-ADVANCED-BORDERS -- */
function _lightenColor($c)
{
if (is_array($c)) {
throw new MpdfException('Color error in _lightencolor');
}
if ($c{0} == 3 || $c{0} == 5) { // RGB
list($h, $s, $l) = $this->rgb2hsl(ord($c{1}) / 255, ord($c{2}) /
255, ord($c{3}) / 255);
$l += ((1 - $l) * 0.8);
list($r, $g, $b) = $this->hsl2rgb($h, $s, $l);
$ret = array(3, $r, $g, $b);
} elseif ($c{0} == 4 || $c{0} == 6) { // CMYK
$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)));
} elseif ($c{0} == 1) { // Grayscale
$ret = array(1, min(255, (ord($c{1}) + 32)));
}
$c = array_pad($ret, 6, 0);
$cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] &
0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF));
return $cstr;
}
function _darkenColor($c)
{
if (is_array($c)) {
throw new MpdfException('Color error in _darkenColor');
}
if ($c{0} == 3 || $c{0} == 5) { // RGB
list($h, $s, $l) = $this->rgb2hsl(ord($c{1}) / 255, ord($c{2}) /
255, ord($c{3}) / 255);
$s *= 0.25;
$l *= 0.75;
list($r, $g, $b) = $this->hsl2rgb($h, $s, $l);
$ret = array(3, $r, $g, $b);
} elseif ($c{0} == 4 || $c{0} == 6) { // CMYK
$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)));
} elseif ($c{0} == 1) { // Grayscale
$ret = array(1, max(0, (ord($c{1}) - 32)));
}
$c = array_pad($ret, 6, 0);
$cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] &
0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF));
return $cstr;
}
/* -- END TABLES-ADVANCED-BORDERS -- */
// mPDF 5.7.3
if (!$cbord['border'] && $cbord['border'] !== 0 &&
isset($table['border']) && $table['border'] && $this->table_border_attr_set) {
$cbord['border'] = $table['border'];
$cbord['border_details'] =
$table['border_details'];
}
$cbord['border_details']['cellposdom'] = ((($i + 1) /
$numrows) / 10000 ) + ((($j + 1) / $numcols) / 10 );
// Inherit Cell border from Table border
if ($this->table_border_css_set && !
$table['borders_separate']) {
if ($i == 0) {
$this-
>_table2cellBorder($table['border_details']['T'], $cbord['border_details']['T'],
$cbord['border'], _BORDER_TOP);
}
if ($i == ($numrows - 1) || ($i + $crowsp) ==
($numrows)) {
$this-
>_table2cellBorder($table['border_details']['B'], $cbord['border_details']['B'],
$cbord['border'], _BORDER_BOTTOM);
}
if ($j == 0) {
$this-
>_table2cellBorder($table['border_details']['L'], $cbord['border_details']['L'],
$cbord['border'], _BORDER_LEFT);
}
if ($j == ($numcols - 1) || ($j + $ccolsp) ==
($numcols)) {
$this-
>_table2cellBorder($table['border_details']['R'], $cbord['border_details']['R'],
$cbord['border'], _BORDER_RIGHT);
}
}
/* -- TABLES-ADVANCED-BORDERS -- */
$fixbottom = true;
if (isset($table['topntail']) && $table['topntail'])
{
if ($i == 0) {
$cbord['border_details']['T'] =
$tntborddet;
$this->setBorder($cbord['border'],
_BORDER_TOP);
}
if ($this->tableLevel == 1 &&
$table['headernrows'] > 0 && $i == $table['headernrows'] - 1) {
$cbord['border_details']['B'] =
$tntborddet;
$this->setBorder($cbord['border'],
_BORDER_BOTTOM);
$fixbottom = false;
} elseif ($this->tableLevel == 1 &&
$table['headernrows'] > 0 && $i == $table['headernrows']) {
if (!$table['borders_separate']) {
$cbord['border_details']['T'] =
$tntborddet;
$this->setBorder($cbord['border'],
_BORDER_TOP);
}
}
if ($this->tableLevel == 1 &&
$table['footernrows'] > 0 && $i == ($numrows - $table['footernrows'] - 1)) {
if (!$table['borders_separate']) {
$cbord['border_details']['B'] =
$tntborddet;
$this->setBorder($cbord['border'],
_BORDER_BOTTOM);
$fixbottom = false;
}
} elseif ($this->tableLevel == 1 &&
$table['footernrows'] > 0 && $i == ($numrows - $table['footernrows'])) {
$cbord['border_details']['T'] =
$tntborddet;
$this->setBorder($cbord['border'],
_BORDER_TOP);
}
if ($this->tabletheadjustfinished) { // $this-
>tabletheadjustfinished called from tableheader
if (!$table['borders_separate']) {
$cbord['border_details']['T'] =
$tntborddet;
$this->setBorder($cbord['border'],
_BORDER_TOP);
}
}
if ($i == ($numrows - 1) || ($i + $crowsp) ==
($numrows)) {
$cbord['border_details']['B'] =
$tntborddet;
$this->setBorder($cbord['border'],
_BORDER_BOTTOM);
}
}
if (isset($table['thead-underline']) &&
$table['thead-underline']) {
if ($table['borders_separate']) {
if ($i == 0) {
$cbord['border_details']['B'] =
$thuborddet;
$this->setBorder($cbord['border'],
_BORDER_BOTTOM);
$fixbottom = false;
}
} else {
if ($this->tableLevel == 1 &&
$table['headernrows'] > 0 && $i == $table['headernrows'] - 1) {
$cbord['border_details']['T'] =
$thuborddet;
$this->setBorder($cbord['border'],
_BORDER_TOP);
} elseif ($this->tabletheadjustfinished)
{ // $this->tabletheadjustfinished called from tableheader
$cbord['border_details']['T'] =
$thuborddet;
$this->setBorder($cbord['border'],
_BORDER_TOP);
}
}
}
$celladj['border_details']['T'] = $cbord['border_details']['B'];
$this-
>setBorder($celladj['border'], _BORDER_TOP, false);
$this-
>setBorder($cbord['border'], _BORDER_BOTTOM, false);
} elseif
($celladj['border_details']['T']['style'] == 'hidden') {
$cbord['border_details']
['B'] = $celladj['border_details']['T'];
$this-
>setBorder($cbord['border'], _BORDER_BOTTOM, false);
$this-
>setBorder($celladj['border'], _BORDER_TOP, false);
}
// Width
elseif ($csthis > $csadj) {
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
$celladj['border_details']['T'] = $cbord['border_details']['B'];
$this-
>setBorder($cbord['border'], _BORDER_BOTTOM);
}
} elseif ($csadj > $csthis) {
if ($ccolsp < 2) { //
don't overwrite this cell if it spans
$cbord['border_details']['B'] = $celladj['border_details']['T'];
$this-
>setBorder($celladj['border'], _BORDER_TOP);
}
}
//
double>solid>dashed>dotted...
elseif
(array_search($cbord['border_details']['B']['style'], $this->borderstyles) >
array_search($celladj['border_details']['T']['style'], $this->borderstyles)) {
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
$celladj['border_details']['T'] = $cbord['border_details']['B'];
$this-
>setBorder($cbord['border'], _BORDER_BOTTOM);
}
} elseif
(array_search($celladj['border_details']['T']['style'], $this->borderstyles) >
array_search($cbord['border_details']['B']['style'], $this->borderstyles)) {
if ($ccolsp < 2) { //
don't overwrite this cell if it spans
$cbord['border_details']['B'] = $celladj['border_details']['T'];
$this-
>setBorder($celladj['border'], _BORDER_TOP);
}
}
$cbord['border_details']['B'] = $celladj['border_details']['T'];
$this-
>setBorder($celladj['border'], _BORDER_TOP);
}
}
// Style set on cell vs.
table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
else {
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
$celladj['border_details']['T'] = $cbord['border_details']['B'];
$this-
>setBorder($cbord['border'], _BORDER_BOTTOM);
}
}
} elseif ($celladj) {
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
$celladj['border_details']['T'] = $cbord['border_details']['B'];
}
}
// mPDF 5.7.4
if ($celladj && $this-
>packTableData) {
$cells[$i + $crowsp][$j +
$cspi]['borderbin'] = $this->_packCellBorder($celladj);
}
unset($celladj);
}
}
$celladj['border_details']['L'] = $cbord['border_details']['R'];
$this-
>setBorder($celladj['border'], _BORDER_LEFT, false);
$this-
>setBorder($cbord['border'], _BORDER_RIGHT, false);
} elseif
($celladj['border_details']['L']['style'] == 'hidden') {
$cbord['border_details']
['R'] = $celladj['border_details']['L'];
$this-
>setBorder($cbord['border'], _BORDER_RIGHT, false);
$this-
>setBorder($celladj['border'], _BORDER_LEFT, false);
}
// Width
elseif ($csthis > $csadj) {
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
$celladj['border_details']['L'] = $cbord['border_details']['R'];
$this-
>setBorder($cbord['border'], _BORDER_RIGHT);
$this-
>setBorder($celladj['border'], _BORDER_LEFT, false);
}
} elseif ($csadj > $csthis) {
if ($crowsp < 2) { //
don't overwrite this cell if it spans
$cbord['border_details']['R'] = $celladj['border_details']['L'];
$this-
>setBorder($cbord['border'], _BORDER_RIGHT, false);
$this-
>setBorder($celladj['border'], _BORDER_LEFT);
}
}
//
double>solid>dashed>dotted...
elseif
(array_search($cbord['border_details']['R']['style'], $this->borderstyles) >
array_search($celladj['border_details']['L']['style'], $this->borderstyles)) {
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
$celladj['border_details']['L'] = $cbord['border_details']['R'];
$this-
>setBorder($celladj['border'], _BORDER_LEFT, false);
$this-
>setBorder($cbord['border'], _BORDER_RIGHT);
}
} elseif
(array_search($celladj['border_details']['L']['style'], $this->borderstyles) >
array_search($cbord['border_details']['R']['style'], $this->borderstyles)) {
if ($crowsp < 2) { //
don't overwrite this cell if it spans
$cbord['border_details']['R'] = $celladj['border_details']['L'];
$this-
>setBorder($cbord['border'], _BORDER_RIGHT, false);
$this-
>setBorder($celladj['border'], _BORDER_LEFT);
}
}
$cbord['border_details']['R'] = $celladj['border_details']['L'];
$this-
>setBorder($celladj['border'], _BORDER_LEFT);
}
}
// Style set on cell vs.
table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
else {
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
$celladj['border_details']['L'] = $cbord['border_details']['R'];
$this-
>setBorder($cbord['border'], _BORDER_RIGHT);
}
}
} elseif ($celladj) {
// if right-cell border is
not set
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
$celladj['border_details']['L'] = $cbord['border_details']['R'];
}
}
// mPDF 5.7.4
if ($celladj && $this-
>packTableData) {
$cells[$i + $cspi][$j +
$ccolsp]['borderbin'] = $this->_packCellBorder($celladj);
}
unset($celladj);
}
}
}
if ($celladj['border_details']['mbw']
['BL']) {
$celladj['border_details']['mbw']
['BL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']
['mbw']['BL']);
}
if ($celladj['border_details']['mbw']
['BR']) {
$celladj['border_details']['mbw']
['BR'] = max($celladj['border_details']['mbw']['BR'], $cbord['border_details']
['mbw']['TR']);
}
if ($this->packTableData) {
$cells[$i - 1][$j]['borderbin'] =
$this->_packCellBorder($celladj);
}
unset($celladj);
}
if ($j > 0 && isset($cells[$i][$j - 1]) &&
(($this->packTableData && $cells[$i][$j - 1]['borderbin']) || $cells[$i][$j - 1]
['border'])) { // Has Left adjoining cell
if ($this->packTableData) {
$adjc = $cells[$i][$j - 1];
$celladj = $this-
>_unpackCellBorder($adjc['borderbin']);
} else {
$celladj = & $cells[$i][$j - 1];
}
$cbord['border_details']['mbw']['LT'] =
max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['T']['w'],
$celladj['border_details']['mbw']['RT']);
$cbord['border_details']['mbw']['LB'] =
max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['B']['w'],
$celladj['border_details']['mbw']['RB']);
$cbord['border_details']['mbw']['BL'] =
max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['mbw']
['BR']);
$cbord['border_details']['mbw']['TL'] =
max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']
['TR']);
if ($celladj['border_details']['mbw']
['RT']) {
$celladj['border_details']['mbw']
['RT'] = max($celladj['border_details']['mbw']['RT'], $cbord['border_details']
['mbw']['LT']);
}
if ($celladj['border_details']['mbw']
['RB']) {
$celladj['border_details']['mbw']
['RB'] = max($celladj['border_details']['mbw']['RB'], $cbord['border_details']
['mbw']['LB']);
}
if ($this->packTableData) {
$cells[$i][$j - 1]['borderbin'] =
$this->_packCellBorder($celladj);
}
unset($celladj);
}
if ($this->packTableData) {
$cell['borderbin'] = $this-
>_packCellBorder($cbord);
}
unset($cbord);
unset($cell);
}
}
}
unset($cell);
}
function _reverseTableDir(&$table)
{
$cells = &$table['cells'];
$numcols = $table['nc'];
$numrows = $table['nr'];
for ($i = 0; $i < $numrows; $i++) { //Rows
$row = array();
for ($j = ($numcols - 1); $j >= 0; $j--) { //Columns
if (isset($cells[$i][$j]) && $cells[$i][$j]) {
$cell = &$cells[$i][$j];
$col = $numcols - $j - 1;
if (isset($cell['colspan']) && $cell['colspan'] > 1)
{
$col -= ($cell['colspan'] - 1);
}
// Nested content
if (isset($cell['textbuffer'])) {
for ($n = 0; $n < count($cell['textbuffer']);
$n++) {
$t = $cell['textbuffer'][$n][0];
if (substr($t, 0, 19) ==
"\xbb\xa4\xactype=nestedtable") {
$objattr = $this->_getObjAttr($t);
$objattr['col'] = $col;
$cell['textbuffer'][$n][0] =
"\xbb\xa4\xactype=nestedtable,objattr=" . serialize($objattr) . "\xbb\xa4\xac";
$this->table[($this->tableLevel +
1)][$objattr['nestedcontent']]['nestedpos'][1] = $col;
}
}
}
$row[$col] = $cells[$i][$j];
unset($cell);
}
}
for ($f = 0; $f < $numcols; $f++) {
if (!isset($row[$f])) {
$row[$f] = 0;
}
}
$table['cells'][$i] = $row;
}
}
$cells = &$table['cells'];
$numcols = $table['nc'];
$numrows = $table['nr'];
$maxbwtop = 0;
if ($this->ColActive && $level == 1) {
$this->breakpoints[$this->CurrCol][] = $this->y;
} // *COLUMNS*
if ($level == 1) {
$this->x = $this->lMargin + $this->blk[$this->blklvl]
['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this-
>blk[$this->blklvl]['border_left']['w'];
$x0 = $this->x;
$y0 = $this->y;
$right = $x0 + $this->blk[$this->blklvl]['inner_width'];
$outerfilled = $this->y; // Keep track of how far down the outer
DIV bgcolor is painted (NB rowspans)
$this->outerfilled = $this->y;
$this->colsums = array();
} else {
$x0 = $this->x;
$y0 = $this->y;
$right = $x0 + $table['w'];
}
if ($this->table_rotate) {
$temppgwidth = $this->tbrot_maxw;
$this->PageBreakTrigger = $pagetrigger = $y0 + ($this->blk[$this-
>blklvl]['inner_width']);
if ($level == 1) {
$this->tbrot_y0 = $this->y - $adv - $table['margin']['T'];
$this->tbrot_x0 = $this->x;
$this->tbrot_w = $table['w'];
if ($table['borders_separate']) {
$this->tbrot_h = $table['margin']['T'] +
$table['padding']['T'] + $table['border_details']['T']['w'] +
$table['border_spacing_V'] / 2;
} else {
$this->tbrot_h = $table['margin']['T'] +
$table['padding']['T'] + $table['max_cell_border_width']['T'];
}
}
} else {
$this->PageBreakTrigger = $pagetrigger = ($this->h - $this-
>bMargin);
if ($level == 1) {
$temppgwidth = $this->blk[$this->blklvl]['inner_width'];
if (isset($table['a']) and ( $table['w'] < $this-
>blk[$this->blklvl]['inner_width'])) {
if ($table['a'] == 'C') {
$x0 += ((($right - $x0) - $table['w']) / 2);
} elseif ($table['a'] == 'R') {
$x0 = $right - $table['w'];
}
}
} else {
$temppgwidth = $table['w'];
}
}
if (!isset($table['overflow'])) {
$table['overflow'] = null;
}
if ($table['overflow'] == 'hidden' && $level == 1 && !$this-
>table_rotate && !$this->ColActive) {
//Bounding rectangle to clip
$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);
$this->_out($this->tableClipPath);
} else {
$this->tableClipPath = '';
}
if ($table['borders_separate']) {
$indent = $table['margin']['L'] + $table['border_details']['L']
['w'] + $table['padding']['L'] + $table['border_spacing_H'] / 2;
} else {
$indent = $table['margin']['L'] + $table['max_cell_border_width']
['L'] / 2;
}
$x0 += $indent;
$returny = 0;
$lastCol = 0;
$tableheader = array();
$tablefooter = array();
$tableheaderrowheight = 0;
$tablefooterrowheight = 0;
$footery = 0;
// mPD 3.0 Set the Page & Column where table starts
if (($this->mirrorMargins) && (($this->page) % 2 == 0)) { // EVEN
$tablestartpage = 'EVEN';
} elseif (($this->mirrorMargins) && (($this->page) % 2 == 1)) { // ODD
$tablestartpage = 'ODD';
} else {
$tablestartpage = '';
}
if ($this->ColActive) {
$tablestartcolumn = $this->CurrCol;
} else {
$tablestartcolumn = '';
}
$y = $h = 0;
for ($i = 0; $i < $numrows; $i++) { //Rows
if ($this->progressBar) {
$this->UpdateProgressBar(7, intval(30 + ($i * 40 /
$numrows)), ' ');
} // *PROGRESS-BAR*
if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i] &&
$level == 1) {
$tablefooterrowheight += $table['hr'][$i];
$tablefooter[$i][0]['trbackground-images'] =
$table['trbackground-images'][$i];
$tablefooter[$i][0]['trgradients'] = $table['trgradients']
[$i];
$tablefooter[$i][0]['trbgcolor'] = $table['bgcolor'][$i];
for ($j = $startcol; $j < $numcols; $j++) { //Columns
if (isset($cells[$i][$j]) && $cells[$i][$j]) {
$cell = &$cells[$i][$j];
if ($split) {
if ($table['colPg'][$j] != $splitpg) {
continue;
}
list($x, $w) = $this-
>_splitTableGetWidth($table, $i, $j);
$js = $j - $startcol;
} else {
list($x, $w) = $this-
>_tableGetWidth($table, $i, $j);
$js = $j;
}
if ($level == 1) {
$this->_out('___TABLE___BACKGROUNDS' . $this->uniqstr);
}
$tableheaderadj = 0;
$tablefooteradj = 0;
$tablestartpageno = $this->page;
if ($table['borders_separate']) {
if (!empty($tablefooter) || $i == ($numrows -
1) || (isset($cell['rowspan']) && ($i + $cell['rowspan']) == $numrows) || (!
isset($cell['rowspan']) && ($i + 1) == $numrows)) {
$extra = $table['padding']['B'] +
$table['border_details']['B']['w'] + $table['border_spacing_V'] / 2;
//$extra = $table['margin']['B'] +
$table['padding']['B'] + $table['border_details']['B']['w'] +
$table['border_spacing_V']/2;
} else {
$extra = $table['border_spacing_V'] / 2;
}
} else {
$extra = $table['max_cell_border_width']['B'] /
2;
}
if (!$skippage) {
$finalSpread = true;
$firstSpread = true;
if ($split) {
for ($t = $startcol; $t < $numcols;
$t++) {
// Are there more columns to
print on a next page?
if ($table['colPg'][$t] >
$splitpg) {
$finalSpread = false;
break;
}
}
if ($startcol > 0) {
$firstSpread = false;
}
}
if (($this->keepColumns || !$this-
>ColActive) && !empty($tablefooter) && $i > 0) {
$this->y = $y;
$ya = $this->y;
$this-
>TableHeaderFooter($tablefooter, $tablestartpage, $tablestartcolumn, 'F', $level,
$firstSpread, $finalSpread);
if ($this->table_rotate) {
$this->tbrot_h += $this->y -
$ya;
}
$tablefooteradj = $this->y - $ya;
}
$y -= $y0;
$returny += $y;
$oldcolumn = $this->CurrCol;
if ($this->AcceptPageBreak()) {
$newpagestarted = true;
$this->y = $y + $y0;
if ($this->packTableData) {
} else {
$bb = $cells[$brow][$ctj]['border_details']['B']['w'];
if ($this->packTableData) {
} else {
$bt = $cells[$trow][$ctj]['border_details']['T']['w'];
if ($this->tableClipPath) {
$this->_out("Q");
}
$bx = $x0;
$by = $y0;
if ($table['borders_separate']) {
$bx -= ($table['padding']
['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H'] / 2);
if ($tablestartpageno !=
$this->page) { // IF already broken across a previous pagebreak
$by +=
$table['max_cell_border_width']['T'] / 2;
if (empty($tableheader))
{
$by -=
($table['border_spacing_V'] / 2);
}
} else {
$by -=
($table['padding']['T'] + $table['border_details']['T']['w'] +
$table['border_spacing_V'] / 2);
}
} elseif ($tablestartpageno !=
$this->page && !empty($tableheader)) {
$by += $maxbwtop / 2;
}
$by -= $tableheaderadj;
$bh = $this->y - $by +
$tablefooteradj;
if (!$table['borders_separate']) {
$bh -= $adv;
}
if ($split) {
$bw = 0;
for ($t = $startcol; $t <
$numcols; $t++) {
if ($table['colPg'][$t]
== $splitpg) {
$bw +=
$table['wc'][$t];
}
if ($table['colPg'][$t]
> $splitpg) {
break;
}
}
if
($table['borders_separate']) {
if ($firstSpread) {
$bw +=
$table['padding']['L'] + $table['border_details']['L']['w'] +
$table['border_spacing_H'];
} else {
$bx +=
($table['padding']['L'] + $table['border_details']['L']['w']);
$bw +=
$table['border_spacing_H'];
}
if ($finalSpread) {
$bw +=
$table['padding']['R'] + $table['border_details']['R']['w'] / 2 +
$table['border_spacing_H'];
}
}
} else {
$bw = $table['w'] -
($table['max_cell_border_width']['L'] / 2) - ($table['max_cell_border_width']
['R'] / 2) - $table['margin']['L'] - $table['margin']['R'];
}
if ($this->splitTableBorderWidth &&
($this->keepColumns || !$this->ColActive) && empty($tablefooter) && $i > 0 &&
$table['border_details']['B']['w']) {
$prevDrawColor = $this-
>DrawColor;
$lw = $this->LineWidth;
$this->SetLineWidth($this-
>splitTableBorderWidth);
$this-
>SetDColor($table['border_details']['B']['c']);
$this->SetLineJoin(0);
$this->SetLineCap(0);
$blx = $bx;
$blw = $bw;
if (!
$table['borders_separate']) {
$blx -=
($table['max_cell_border_width']['L'] / 2);
$blw +=
($table['max_cell_border_width']['L'] / 2 + $table['max_cell_border_width']['R'] /
2);
}
$this->Line($blx, $this->y +
($this->splitTableBorderWidth / 2), $blx + $blw, $this->y + ($this-
>splitTableBorderWidth / 2));
$this->DrawColor =
$prevDrawColor;
$this->_out($this-
>DrawColor);
$this->SetLineWidth($lw);
$this->SetLineJoin(2);
$this->SetLineCap(2);
}
/* -- BACKGROUNDS -- */
if
(isset($table['gradient'])) {
$g = $this->grad-
>parseBackgroundGradient($table['gradient']);
if ($g) {
$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' => '');
}
}
if (isset($table['background-
image'])) {
if ($table['background-
image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-
gradient/', $table['background-image']['gradient'])) {
$g = $this->grad-
>parseMozGradient($table['background-image']['gradient']);
if ($g) {
$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' => '');
}
} else {
$image_id =
$table['background-image']['image_id'];
$orig_w =
$table['background-image']['orig_w'];
$orig_h =
$table['background-image']['orig_h'];
$x_pos =
$table['background-image']['x_pos'];
$y_pos =
$table['background-image']['y_pos'];
$x_repeat =
$table['background-image']['x_repeat'];
$y_repeat =
$table['background-image']['y_repeat'];
$resize =
$table['background-image']['resize'];
$opacity =
$table['background-image']['opacity'];
$itype =
$table['background-image']['itype'];
$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);
}
}
/* -- END BACKGROUNDS -- */
}
// $this->AcceptPageBreak() has
moved tablebuffer to $this->pages content
if ($this->tableBackgrounds) {
$s = $this-
>PrintTableBackgrounds();
if ($this->bufferoutput) {
$this->headerbuffer =
preg_replace('/(___TABLE___BACKGROUNDS' . $this->uniqstr . ')/', '\\1' . "\n" .
$s . "\n", $this->headerbuffer);
$this->headerbuffer =
preg_replace('/(___TABLE___BACKGROUNDS' . $this->uniqstr . ')/', " ", $this-
>headerbuffer);
} else {
$this->pages[$this-
>page] = preg_replace('/(___TABLE___BACKGROUNDS' . $this->uniqstr . ')/', '\\1' .
"\n" . $s . "\n", $this->pages[$this->page]);
$this->pages[$this-
>page] = preg_replace('/(___TABLE___BACKGROUNDS' . $this->uniqstr . ')/', " ",
$this->pages[$this->page]);
}
$this->tableBackgrounds =
array();
}
if ($split) {
if ($i == 0 && $j == 0) {
$y0 = -1;
} elseif ($finalSpread) {
$splitpg = 0;
$startcol = 0;
$startrow = $i;
} else {
$splitpg++;
$startcol = $t;
$returny -= $y;
}
return array(false,
$startrow, $startcol, $splitpg, $returny, $y0);
}
$this->AddPage($this-
>CurOrientation);
$this-
>_out('___TABLE___BACKGROUNDS' . $this->uniqstr);
if ($this->tableClipPath) {
$this->_out($this-
>tableClipPath);
}
if ($this->splitTableBorderWidth &&
($this->keepColumns || !$this->ColActive) && empty($tableheader) && $i > 0 &&
$table['border_details']['T']['w']) {
$prevDrawColor = $this-
>DrawColor;
$lw = $this->LineWidth;
$this->SetLineWidth($this-
>splitTableBorderWidth);
$this-
>SetDColor($table['border_details']['T']['c']);
$this->SetLineJoin(0);
$this->SetLineCap(0);
$blx += $this-
>MarginCorrection;
$this->Line($blx, $this->y -
($this->splitTableBorderWidth / 2), $blx + $blw, $this->y - ($this-
>splitTableBorderWidth / 2));
$this->DrawColor =
$prevDrawColor;
$this->_out($this-
>DrawColor);
$this->SetLineWidth($lw);
$this->SetLineJoin(2);
$this->SetLineCap(2);
}
$bt = $cells[$i][$ctj]['border_details']['T']['w'];
}
if ($this->table_rotate) {
$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'];
if
($table['borders_separate']) {
$this->tbrot_h =
$table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w']
+ $table['border_spacing_V'] / 2;
} else {
$this->tbrot_h =
$table['margin']['T'] + $table['max_cell_border_width']['T'];
}
$this->tbrot_y0 = $this->y;
$pagetrigger = $y0 -
$tableheaderadj + ($this->blk[$this->blklvl]['inner_width']);
} else {
$pagetrigger = $this-
>PageBreakTrigger;
}
if (!empty($tableheader)) {
$ya = $this->y;
$this-
>TableHeaderFooter($tableheader, $tablestartpage, $tablestartcolumn, 'H', $level);
if ($this->table_rotate) {
$this->tbrot_h = $this-
>y - $ya;
}
$tableheaderadj = $this->y -
$ya;
} elseif ($i == 0 && !$this-
>table_rotate && $level == 1 && !$this->ColActive) {
// Advance down page
if
($table['borders_separate']) {
$adv =
$table['border_spacing_V'] / 2 + $table['border_details']['T']['w'] +
$table['padding']['T'];
} else {
$adv =
$table['max_cell_border_width']['T'] / 2;
}
if ($adv) {
if ($this->table_rotate)
{
$this->y +=
($adv);
} else {
$this->DivLn($adv,
$this->blklvl, true);
}
}
}
$outerfilled = 0;
$y = $y0 = $this->y;
}
/* -- COLUMNS -- */
// COLS
// COLUMN CHANGE
if ($this->CurrCol != $oldcolumn) {
// Added to correct for Columns
$x += $this->ChangeColumn * ($this-
>ColWidth + $this->ColGap);
$x0 += $this->ChangeColumn *
($this->ColWidth + $this->ColGap);
if ($this->CurrCol == 0) { // just
added a page - possibly with tableheader
$y0 = $this->y; // this->y0
is global used by Columns - $y0 is internal to tablewrite
} else {
$y0 = $this->y0; // this->y0
is global used by Columns - $y0 is internal to tablewrite
}
$y = $y0;
$outerfilled = 0;
if ($this->CurrCol != 0 && ($this-
>keepColumns && $this->ColActive) && !empty($tableheader) && $i > 0) {
$this->x = $x;
$this->y = $y;
$this-
>TableHeaderFooter($tableheader, $tablestartpage, $tablestartcolumn, 'H', $level);
$y0 = $y = $this->y;
}
}
/* -- END COLUMNS -- */
}
$skippage = true;
}
$this->x = $x;
$this->y = $y;
//ALIGN
$align = $cell['a'];
/* -- COLUMNS -- */
// If outside columns, this is done in PaintDivBB
if ($this->ColActive) {
//OUTER FILL BGCOLOR of DIVS
if ($this->blklvl > 0 && ($j == 0) && !$this-
>table_rotate && $level == 1) {
$firstblockfill = $this-
>GetFirstBlockFill();
if ($firstblockfill && $this->blklvl >=
$firstblockfill) {
$divh = $maxrowheight;
// Last row
if ((!isset($cell['rowspan']) && $i
== $numrows - 1) || (isset($cell['rowspan']) && (($i == $numrows - 1 &&
$cell['rowspan'] < 2) || ($cell['rowspan'] > 1 && ($i + $cell['rowspan'] - 1) ==
$numrows - 1)))) {
if
($table['borders_separate']) {
$adv = $table['margin']
['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] +
$table['border_spacing_V'] / 2;
} else {
$adv = $table['margin']
['B'] + $table['max_cell_border_width']['B'] / 2;
}
$divh += $adv; //last row:
fill bottom half of bottom border (y advanced at end)
}
$this->DivLn($divh, -3,
false);
$outerfilled = $this->y +
$divh;
// Reset current block fill
$bcor = $this->blk[$this-
>blklvl]['bgcolorarray'];
if ($bcor)
$this->SetFColor($bcor);
$this->x = $bak_x;
$this->y = $bak_y;
}
}
}
}
if ($table['empty_cells'] != 'hide' || !
empty($cell['textbuffer']) || (isset($cell['nestedcontent']) &&
$cell['nestedcontent']) || !$table['borders_separate']) {
$paintcell = true;
} else {
$paintcell = false;
}
//Set Borders
$bord = 0;
$bord_det = array();
if (!$this->simpleTables) {
if ($this->packTableData) {
$c = $this-
>_unpackCellBorder($cell['borderbin']);
$bord = $c['border'];
$bord_det = $c['border_details'];
} else {
$bord = $cell['border'];
$bord_det = $cell['border_details'];
}
} elseif ($this->simpleTables) {
$bord = $table['simple']['border'];
$bord_det = $table['simple']['border_details'];
}
/* -- BACKGROUNDS -- */
if (isset($cell['gradient']) && $cell['gradient'] &&
$paintcell) {
$g = $this->grad-
>parseBackgroundGradient($cell['gradient']);
if ($g) {
if ($table['borders_separate']) {
$px = $x +
($table['border_spacing_H'] / 2);
$py = $y +
($table['border_spacing_V'] / 2);
$pw = $w -
$table['border_spacing_H'];
$ph = $h -
$table['border_spacing_V'];
} else {
$px = $x;
$py = $y;
$pw = $w;
$ph = $h;
}
if ($this->ColActive) {
$this->grad->Gradient($px, $py,
$pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']);
} else {
$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' => '');
}
}
}
$tableheader[$i][$j]['va'] = $cell['va'];
$tableheader[$i][$j]['mih'] = $cell['mih'];
$tableheader[$i][$j]['gradient'] =
(isset($cell['gradient']) ? $cell['gradient'] : null); // *BACKGROUNDS*
$tableheader[$i][$j]['background-image'] =
(isset($cell['background-image']) ? $cell['background-image'] : null); //
*BACKGROUNDS*
$tableheader[$i][$j]['rowspan'] =
(isset($cell['rowspan']) ? $cell['rowspan'] : null);
$tableheader[$i][$j]['colspan'] =
(isset($cell['colspan']) ? $cell['colspan'] : null);
$tableheader[$i][$j]['bgcolor'] =
$cell['bgcolor'];
if (!$this->simpleTables) {
$tableheader[$i][$j]['border'] = $bord;
$tableheader[$i][$j]['border_details'] =
$bord_det;
} elseif ($this->simpleTables) {
$tableheader[$i][$j]['border'] =
$table['simple']['border'];
$tableheader[$i][$j]['border_details'] =
$table['simple']['border_details'];
}
$tableheader[$i][$j]['padding'] =
$cell['padding'];
if (isset($cell['direction']))
$tableheader[$i][$j]['direction'] =
$cell['direction'];
if (isset($cell['cellLineHeight']))
$tableheader[$i][$j]['cellLineHeight'] =
$cell['cellLineHeight'];
if (isset($cell['cellLineStackingStrategy']))
$tableheader[$i][$j]
['cellLineStackingStrategy'] = $cell['cellLineStackingStrategy'];
if (isset($cell['cellLineStackingShift']))
$tableheader[$i][$j]
['cellLineStackingShift'] = $cell['cellLineStackingShift'];
}
// CELL BORDER
if ($bord) {
if ($table['borders_separate'] && $paintcell) {
$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']);
} elseif (!$table['borders_separate']) {
$this->_tableRect($x, $y, $w, $h, $bord,
$bord_det, true, $table['borders_separate']); // true causes buffer
}
}
//VERTICAL ALIGN
if ($cell['R'] && INTVAL($cell['R']) > 0 &&
INTVAL($cell['R']) < 90 && isset($cell['va']) && $cell['va'] != 'B') {
$cell['va'] = 'B';
}
if (!isset($cell['va']) || $cell['va'] == 'M')
$this->y += ($h - $cell['mih']) / 2;
elseif (isset($cell['va']) && $cell['va'] == 'B')
$this->y += $h - $cell['mih'];
// NESTED CONTENT
// TEXT (and nested tables)
$this->divwidth = $w;
if (!empty($cell['textbuffer'])) {
$this->cellTextAlign = $align;
$this->cellLineHeight =
$cell['cellLineHeight'];
$this->cellLineStackingStrategy =
$cell['cellLineStackingStrategy'];
$this->cellLineStackingShift =
$cell['cellLineStackingShift'];
if ($level == 1) {
if (isset($table['is_tfoot'][$i]) &&
$table['is_tfoot'][$i]) {
if (preg_match('/{colsum([0-9]*)
[_]*}/', $cell['textbuffer'][0][0], $m)) {
$rep = sprintf("%01." .
intval($m[1]) . "f", $this->colsums[$j]);
$cell['textbuffer'][0][0] =
preg_replace('/{colsum[0-9_]*}/', $rep, $cell['textbuffer'][0][0]);
}
} elseif (!isset($table['is_thead'][$i]))
{
if (isset($this->colsums[$j])) {
$this->colsums[$j] +=
floatval(preg_replace('/^[^0-9\.\,]*/', '', $cell['textbuffer'][0][0]));
} else {
$this->colsums[$j] =
floatval(preg_replace('/^[^0-9\.\,]*/', '', $cell['textbuffer'][0][0]));
}
}
}
$opy = $this->y;
// mPDF ITERATION
if ($this->iterationCounter) {
foreach ($cell['textbuffer'] AS $k => $t)
{
if (preg_match('/{iteration ([a-zA-
Z0-9_]+)}/', $t[0], $m)) {
$vname = '__' . $m[1] . '_';
if (!isset($this->$vname)) {
$this->$vname = 1;
} else {
$this->$vname++;
}
$cell['textbuffer'][$k][0] =
preg_replace('/{iteration ' . $m[1] . '}/', $this->$vname, $cell['textbuffer'][$k]
[0]);
}
}
}
if ($cell['R']) {
$cellPtSize = $cell['textbuffer'][0]
[11] / $this->shrin_k;
if (!$cellPtSize) {
$cellPtSize = $this-
>default_font_size;
}
$cellFontHeight = ($cellPtSize / _MPDFK);
$opx = $this->x;
$angle = INTVAL($cell['R']);
// Only allow 45 to 89 degrees (when
bottom-aligned) or exactly 90 or -90
if ($angle > 90) {
$angle = 90;
} elseif ($angle > 0 && $angle < 45) {
$angle = 45;
} elseif ($angle < 0) {
$angle = -90;
}
$offset = ((sin(deg2rad($angle))) * 0.37
* $cellFontHeight);
if (isset($cell['a']) && $cell['a'] ==
'R') {
$this->x += ($w) + ($offset) -
($cellFontHeight / 3) - ($cell['padding']['R'] + ($table['border_spacing_H'] / 2));
} elseif (!isset($cell['a']) ||
$cell['a'] == 'C') {
$this->x += ($w / 2) + ($offset);
} else {
$this->x += ($offset) +
($cellFontHeight / 3) + ($cell['padding']['L'] + ($table['border_spacing_H'] / 2));
}
$str = '';
foreach ($cell['textbuffer'] AS $t) {
$str .= $t[0] . ' ';
}
$str = rtrim($str);
if (!isset($cell['va']) || $cell['va'] ==
'M') {
$this->y -= ($h - $cell['mih']) /
2; //Undo what was added earlier VERTICAL ALIGN
if ($angle > 0) {
$this->y += (($h -
$cell['mih']) / 2) + $cell['padding']['T'] + ($cell['mih'] - ($cell['padding']['T']
+ $cell['padding']['B']));
} elseif ($angle < 0) {
$this->y += (($h -
$cell['mih']) / 2) + ($cell['padding']['T'] + ($table['border_spacing_V'] / 2));
}
} elseif (isset($cell['va']) &&
$cell['va'] == 'B') {
$this->y -= $h - $cell['mih'];
//Undo what was added earlier VERTICAL ALIGN
if ($angle > 0) {
$this->y += $h -
($cell['padding']['B'] + ($table['border_spacing_V'] / 2));
} elseif ($angle < 0) {
$this->y += $h - $cell['mih']
+ ($cell['padding']['T'] + ($table['border_spacing_V'] / 2));
}
} elseif (isset($cell['va']) &&
$cell['va'] == 'T') {
if ($angle > 0) {
$this->y += $cell['mih'] -
($cell['padding']['B'] + ($table['border_spacing_V'] / 2));
} elseif ($angle < 0) {
$this->y += ($cell['padding']
['T'] + ($table['border_spacing_V'] / 2));
}
}
$this->Rotate($angle, $this->x, $this-
>y);
$s_fs = $this->FontSizePt;
$s_f = $this->FontFamily;
$s_st = $this->FontStyle;
if (!empty($cell['textbuffer'][0][3]))
{ //Font Color
$cor = $cell['textbuffer'][0][3];
$this->SetTColor($cor);
}
$this->SetFont($cell['textbuffer'][0][4],
$cell['textbuffer'][0][2], $cellPtSize, true, true);
$this->magic_reverse_dir($str, $this-
>directionality, $cell['textbuffer'][0][18]);
$this->Text($this->x, $this->y, $str,
$cell['textbuffer'][0][18], $cell['textbuffer'][0][8]); // textvar
$this->Rotate(0);
$this->SetFont($s_f, $s_st, $s_fs, true,
true);
$this->SetTColor(0);
$this->x = $opx;
} else {
if (!$this->simpleTables) {
if ($bord_det) {
$btlw = $bord_det['L']['w'];
$btrw = $bord_det['R']['w'];
$bttw = $bord_det['T']['w'];
} else {
$btlw = 0;
$btrw = 0;
$bttw = 0;
}
if ($table['borders_separate']) {
$xadj = $btlw +
$cell['padding']['L'] + ($table['border_spacing_H'] / 2);
$wadj = $btlw + $btrw +
$cell['padding']['L'] + $cell['padding']['R'] + $table['border_spacing_H'];
$yadj = $bttw +
$cell['padding']['T'] + ($table['border_spacing_H'] / 2);
} else {
$xadj = $btlw / 2 +
$cell['padding']['L'];
$wadj = ($btlw + $btrw) / 2 +
$cell['padding']['L'] + $cell['padding']['R'];
$yadj = $bttw / 2 +
$cell['padding']['T'];
}
} elseif ($this->simpleTables) {
if ($table['borders_separate'])
{ // NB twice border width
$xadj = $table['simple']
['border_details']['L']['w'] + $cell['padding']['L'] +
($table['border_spacing_H'] / 2);
$wadj = $table['simple']
['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] +
$cell['padding']['L'] + $cell['padding']['R'] + $table['border_spacing_H'];
$yadj = $table['simple']
['border_details']['T']['w'] + $cell['padding']['T'] +
($table['border_spacing_H'] / 2);
} else {
$xadj = $table['simple']
['border_details']['L']['w'] / 2 + $cell['padding']['L'];
$wadj = ($table['simple']
['border_details']['L']['w'] + $table['simple']['border_details']['R']['w']) / 2 +
$cell['padding']['L'] + $cell['padding']['R'];
$yadj = $table['simple']
['border_details']['T']['w'] / 2 + $cell['padding']['T'];
}
}
$this->decimal_offset = 0;
if (substr($cell['a'], 0, 1) == 'D') {
if (isset($cell['colspan']) &&
$cell['colspan'] > 1) {
$this->cellTextAlign =
$c['a'] = substr($cell['a'], 2, 1);
} else {
$smax =
$table['decimal_align'][$j]['maxs0'];
$d_content =
$table['decimal_align'][$j]['maxs0'] + $table['decimal_align'][$j]['maxs1'];
$this->decimal_offset =
$smax;
$extra = ($w - $d_content -
$wadj);
if ($extra > 0) {
if (substr($cell['a'],
2, 1) == 'R') {
$this-
>decimal_offset += $extra;
} elseif
(substr($cell['a'], 2, 1) == 'C') {
$this-
>decimal_offset += ($extra) / 2;
}
}
}
}
$this->divwidth = $w - $wadj;
if ($this->divwidth == 0) {
$this->divwidth = 0.0001;
}
$this->x += $xadj;
$this->y += $yadj;
$this->printbuffer($cell['textbuffer'],
'', true, false, $cell['direction']);
}
$this->y = $opy;
}
/* -- BACKGROUNDS -- */
if (!$this->ColActive) {
if (isset($table['trgradients'][$i]) && ($j ==
0 || $table['borders_separate'])) {
$g = $this->grad-
>parseBackgroundGradient($table['trgradients'][$i]);
if ($g) {
$gx = $x0;
$gy = $y;
$gh = $h;
$gw = $table['w'] -
($table['max_cell_border_width']['L'] / 2) - ($table['max_cell_border_width']
['R'] / 2) - $table['margin']['L'] - $table['margin']['R'];
if ($table['borders_separate']) {
$gw -= ($table['padding']
['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] +
$table['border_details']['R']['w'] + $table['border_spacing_H']);
$clx = $x +
($table['border_spacing_H'] / 2);
$cly = $y +
($table['border_spacing_V'] / 2);
$clw = $w -
$table['border_spacing_H'];
$clh = $h -
$table['border_spacing_V'];
// Set clipping path
$s = $this-
>_setClippingPath($clx, $cly, $clw, $clh); // mPDF 6
$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);
} else {
$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' => '');
}
}
}
if (isset($table['trbackground-images'][$i]) &&
($j == 0 || $table['borders_separate'])) {
if (isset($table['trbackground-images']
[$i]['gradient']) && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',
$table['trbackground-images'][$i]['gradient'])) {
$g = $this->grad-
>parseMozGradient($table['trbackground-images'][$i]['gradient']);
if ($g) {
$gx = $x0;
$gy = $y;
$gh = $h;
$gw = $table['w'] -
($table['max_cell_border_width']['L'] / 2) - ($table['max_cell_border_width']
['R'] / 2) - $table['margin']['L'] - $table['margin']['R'];
if
($table['borders_separate']) {
$gw -=
($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']
['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']);
$clx = $x +
($table['border_spacing_H'] / 2);
$cly = $y +
($table['border_spacing_V'] / 2);
$clw = $w -
$table['border_spacing_H'];
$clh = $h -
$table['border_spacing_V'];
// Set clipping path
$s = $this-
>_setClippingPath($clx, $cly, $clw, $clh); // mPDF 6
$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);
} else {
$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' => '');
}
}
} else {
$image_id = $table['trbackground-
images'][$i]['image_id'];
$orig_w = $table['trbackground-
images'][$i]['orig_w'];
$orig_h = $table['trbackground-
images'][$i]['orig_h'];
$x_pos = $table['trbackground-
images'][$i]['x_pos'];
$y_pos = $table['trbackground-
images'][$i]['y_pos'];
$x_repeat = $table['trbackground-
images'][$i]['x_repeat'];
$y_repeat = $table['trbackground-
images'][$i]['y_repeat'];
$resize = $table['trbackground-
images'][$i]['resize'];
$opacity = $table['trbackground-
images'][$i]['opacity'];
$itype = $table['trbackground-
images'][$i]['itype'];
$clippath = '';
$gx = $x0;
$gy = $y;
$gh = $h;
$gw = $table['w'] -
($table['max_cell_border_width']['L'] / 2) - ($table['max_cell_border_width']
['R'] / 2) - $table['margin']['L'] - $table['margin']['R'];
if ($table['borders_separate']) {
$gw -= ($table['padding']
['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] +
$table['border_details']['R']['w'] + $table['border_spacing_H']);
$clx = $x +
($table['border_spacing_H'] / 2);
$cly = $y +
($table['border_spacing_V'] / 2);
$clw = $w -
$table['border_spacing_H'];
$clh = $h -
$table['border_spacing_V'];
// Set clipping path
$s = $this-
>_setClippingPath($clx, $cly, $clw, $clh); // mPDF 6
$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);
} else {
$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);
}
}
}
}
/* -- END BACKGROUNDS -- */
$corner = '';
if ($i == 0) { // Top
$tby -= $halfspaceT +
($table['border_details']['T']['w'] / 2);
$tbh += $halfspaceT +
($table['border_details']['T']['w'] / 2);
$this->setBorder($tab_bord, _BORDER_TOP);
$corner .= 'T';
}
if ($i == ($numrows - 1) ||
(isset($cell['rowspan']) && ($i + $cell['rowspan']) == $numrows)) { // Bottom
$tbh += $halfspaceB +
($table['border_details']['B']['w'] / 2);
$this->setBorder($tab_bord,
_BORDER_BOTTOM);
$corner .= 'B';
}
if ($j == 0) { // Left
$tbx -= $halfspaceL +
($table['border_details']['L']['w'] / 2);
$tbw += $halfspaceL +
($table['border_details']['L']['w'] / 2);
$this->setBorder($tab_bord,
_BORDER_LEFT);
$corner .= 'L';
}
if ($j == ($numcols - 1) ||
(isset($cell['colspan']) && ($j + $cell['colspan']) == $numcols)) { // Right
$tbw += $halfspaceR +
($table['border_details']['R']['w'] / 2);
$this->setBorder($tab_bord,
_BORDER_RIGHT);
$corner .= 'R';
}
$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']);
}
unset($cell);
//Reset values
$this->Reset();
}//end of (if isset(cells)...)
}// end of columns
$newpagestarted = false;
$this->tabletheadjustfinished = false;
/* -- COLUMNS -- */
if ($this->ColActive) {
if (!$this->table_keep_together && $i < $numrows - 1 &&
$level == 1) {
$this->breakpoints[$this->CurrCol][] = $y + $h;
} // mPDF 6
if (count($this->cellBorderBuffer)) {
$this->printcellbuffer();
}
}
/* -- END COLUMNS -- */
if ($i == $numrows - 1) {
$this->y = $y + $h;
} //last row jump (update this->y position)
if ($this->table_rotate && $level == 1) {
$this->tbrot_h += $h;
}
}// end of rows
if ($this->progressBar) {
$this->UpdateProgressBar(7, 70, ' ');
} // *PROGRESS-BAR*
if (count($this->cellBorderBuffer)) {
$this->printcellbuffer();
}
if ($this->tableClipPath) {
$this->_out("Q");
}
$this->tableClipPath = '';
$bx = $x0;
$by = $y0;
if ($table['borders_separate']) {
$bx -= ($table['padding']['L'] + $table['border_details']['L']
['w'] + $table['border_spacing_H'] / 2);
if ($tablestartpageno != $this->page) { // IF broken across page
$by += $table['max_cell_border_width']['T'] / 2;
if (empty($tableheader)) {
$by -= ($table['border_spacing_V'] / 2);
}
} elseif ($split && $startrow > 0 && empty($tableheader)) {
$by -= ($table['border_spacing_V'] / 2);
} else {
$by -= ($table['padding']['T'] + $table['border_details']
['T']['w'] + $table['border_spacing_V'] / 2);
}
} elseif ($tablestartpageno != $this->page && !empty($tableheader)) {
$by += $maxbwtop / 2;
}
$by -= $tableheaderadj;
$bh = $this->y - $by;
if (!$table['borders_separate']) {
$bh -= $table['max_cell_border_width']['B'] / 2;
}
if ($split) {
$bw = 0;
$finalSpread = true;
for ($t = $startcol; $t < $numcols; $t++) {
if ($table['colPg'][$t] == $splitpg) {
$bw += $table['wc'][$t];
}
if ($table['colPg'][$t] > $splitpg) {
$finalSpread = false;
break;
}
}
if ($startcol == 0) {
$firstSpread = true;
} else {
$firstSpread = false;
}
if ($table['borders_separate']) {
$bw += $table['border_spacing_H'];
if ($firstSpread) {
$bw += $table['padding']['L'] +
$table['border_details']['L']['w'];
} else {
$bx += ($table['padding']['L'] +
$table['border_details']['L']['w']);
}
if ($finalSpread) {
$bw += $table['padding']['R'] +
$table['border_details']['R']['w'];
}
}
} else {
$bw = $table['w'] - ($table['max_cell_border_width']['L'] / 2) -
($table['max_cell_border_width']['R'] / 2) - $table['margin']['L'] -
$table['margin']['R'];
}
if (!$this->ColActive) {
if (isset($table['bgcolor'][-1])) {
$color = $this->ConvertColor($table['bgcolor'][-1]);
if ($color) {
$this->tableBackgrounds[$level * 9][] =
array('gradient' => false, 'x' => $bx, 'y' => $by, 'w' => $bw, 'h' => $bh, 'col' =>
$color);
}
}
/* -- BACKGROUNDS -- */
if (isset($table['gradient'])) {
$g = $this->grad-
>parseBackgroundGradient($table['gradient']);
if ($g) {
$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' => '');
}
}
if (isset($table['background-image'])) {
if (isset($table['background-image']['gradient']) &&
$table['background-image']['gradient'] && preg_match('/(-
moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']
['gradient'])) {
$g = $this->grad-
>parseMozGradient($table['background-image']['gradient']);
if ($g) {
$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' => '');
}
} else {
$image_id = $table['background-image']['image_id'];
$orig_w = $table['background-image']['orig_w'];
$orig_h = $table['background-image']['orig_h'];
$x_pos = $table['background-image']['x_pos'];
$y_pos = $table['background-image']['y_pos'];
$x_repeat = $table['background-image']['x_repeat'];
$y_repeat = $table['background-image']['y_repeat'];
$resize = $table['background-image']['resize'];
$opacity = $table['background-image']['opacity'];
$itype = $table['background-image']['itype'];
$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);
}
}
/* -- END BACKGROUNDS -- */
}
if ($split) {
// Are there more columns to print on a next page?
if ($lastCol < $numcols - 1) {
$splitpg++;
$startcol = $lastCol + 1;
return array(false, $startrow, $startcol, $splitpg,
$returny, $y0);
} else {
return array(true, 0, 0, 0, false, false);
}
}
}
function _putextgstates()
{
for ($i = 1; $i <= count($this->extgstates); $i++) {
$this->_newobj();
$this->extgstates[$i]['n'] = $this->n;
$this->_out('<</Type /ExtGState');
foreach ($this->extgstates[$i]['parms'] as $k => $v)
$this->_out('/' . $k . ' ' . $v);
$this->_out('>>');
$this->_out('endobj');
}
}
function _putocg()
{
if ($this->hasOC) {
$this->_newobj();
$this->n_ocg_print = $this->n;
$this->_out('<</Type /OCG /Name ' . $this->_textstring('Print
only'));
$this->_out('/Usage <</Print <</PrintState /ON>> /View
<</ViewState /OFF>>>>>>');
$this->_out('endobj');
$this->_newobj();
$this->n_ocg_view = $this->n;
$this->_out('<</Type /OCG /Name ' . $this->_textstring('Screen
only'));
$this->_out('/Usage <</Print <</PrintState /OFF>> /View
<</ViewState /ON>>>>>>');
$this->_out('endobj');
$this->_newobj();
$this->n_ocg_hidden = $this->n;
$this->_out('<</Type /OCG /Name ' . $this-
>_textstring('Hidden'));
$this->_out('/Usage <</Print <</PrintState /OFF>> /View
<</ViewState /OFF>>>>>>');
$this->_out('endobj');
}
if (count($this->layers)) {
ksort($this->layers);
foreach ($this->layers as $id => $layer) {
$this->_newobj();
$this->layers[$id]['n'] = $this->n;
if (isset($this->layerDetails[$id]['name']) && $this-
>layerDetails[$id]['name']) {
$name = $this->layerDetails[$id]['name'];
} else {
$name = $layer['name'];
}
$this->_out('<</Type /OCG /Name ' . $this-
>_UTF16BEtextstring($name) . '>>');
$this->_out('endobj');
}
}
}
/* -- IMPORTS -- */
// from mPDFI
function _putimportedobjects()
{
if (is_array($this->parsers) && count($this->parsers) > 0) {
foreach ($this->parsers AS $filename => $p) {
$this->current_parser = $this->parsers[$filename];
if (is_array($this->_obj_stack[$filename])) {
while ($n = key($this->_obj_stack[$filename])) {
$nObj = $this->current_parser-
>resolveObject($this->_obj_stack[$filename][$n][1]);
$this->_newobj($this->_obj_stack[$filename][$n]
[0]);
if ($nObj[0] == pdf_parser::TYPE_STREAM) {
$this->pdf_write_value($nObj);
} else {
$this->pdf_write_value($nObj[1]);
}
$this->_out('endobj');
$this->_obj_stack[$filename][$n] = null; //
free memory
unset($this->_obj_stack[$filename][$n]);
reset($this->_obj_stack[$filename]);
}
}
}
}
}
function _putformxobjects()
{
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
reset($this->tpls);
foreach ($this->tpls AS $tplidx => $tpl) {
$p = ($this->compress) ? gzcompress($tpl['buffer']) :
$tpl['buffer'];
$this->_newobj();
$this->tpls[$tplidx]['n'] = $this->n;
$this->_out('<<' . $filter . '/Type /XObject');
$this->_out('/Subtype /Form');
$this->_out('/FormType 1');
// Left/Bottom/Right/Top
$this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', $tpl['box']
['x'] * _MPDFK, $tpl['box']['y'] * _MPDFK, ($tpl['box']['x'] + $tpl['box']['w']) *
_MPDFK, ($tpl['box']['y'] + $tpl['box']['h']) * _MPDFK)
);
if (isset($tpl['box']))
$this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]', -
$tpl['box']['x'] * _MPDFK, -$tpl['box']['y'] * _MPDFK));
$this->_out('/Resources ');
if (isset($tpl['resources'])) {
$this->current_parser = $tpl['parser'];
$this->pdf_write_value($tpl['resources']);
} else {
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC
/ImageI]');
if (isset($this->_res['tpl'][$tplidx]['fonts']) &&
count($this->_res['tpl'][$tplidx]['fonts'])) {
$this->_out('/Font <<');
foreach ($this->_res['tpl'][$tplidx]['fonts'] as
$font)
$this->_out('/F' . $font['i'] . ' ' .
$font['n'] . ' 0 R');
$this->_out('>>');
}
if (isset($this->_res['tpl'][$tplidx]['images']) &&
count($this->_res['tpl'][$tplidx]['images']) ||
isset($this->_res['tpl'][$tplidx]['tpls']) &&
count($this->_res['tpl'][$tplidx]['tpls'])) {
$this->_out('/XObject <<');
if (isset($this->_res['tpl'][$tplidx]['images']) &&
count($this->_res['tpl'][$tplidx]['images'])) {
foreach ($this->_res['tpl'][$tplidx]['images']
as $image)
$this->_out('/I' . $image['i'] . ' ' .
$image['n'] . ' 0 R');
}
if (isset($this->_res['tpl'][$tplidx]['tpls']) &&
count($this->_res['tpl'][$tplidx]['tpls'])) {
foreach ($this->_res['tpl'][$tplidx]['tpls'] as
$i => $itpl)
$this->_out($this->tplprefix . $i . ' ' .
$itpl['n'] . ' 0 R');
}
$this->_out('>>');
}
$this->_out('>>');
}
/* -- END IMPORTS -- */
function _putpatterns()
{
for ($i = 1; $i <= count($this->patterns); $i++) {
$x = $this->patterns[$i]['x'];
$y = $this->patterns[$i]['y'];
$w = $this->patterns[$i]['w'];
$h = $this->patterns[$i]['h'];
$pgh = $this->patterns[$i]['pgh'];
$orig_w = $this->patterns[$i]['orig_w'];
$orig_h = $this->patterns[$i]['orig_h'];
$image_id = $this->patterns[$i]['image_id'];
$itype = $this->patterns[$i]['itype'];
if (isset($this->patterns[$i]['bpa'])) {
$bpa = $this->patterns[$i]['bpa'];
} // background positioning area
else {
$bpa = array();
}
if ($this->patterns[$i]['x_repeat']) {
$x_repeat = true;
} else {
$x_repeat = false;
}
if ($this->patterns[$i]['y_repeat']) {
$y_repeat = true;
} else {
$y_repeat = false;
}
$x_pos = $this->patterns[$i]['x_pos'];
if (stristr($x_pos, '%')) {
$x_pos += 0;
$x_pos /= 100;
if (isset($bpa['w']) && $bpa['w'])
$x_pos = ($bpa['w'] * $x_pos) - ($orig_w / _MPDFK *
$x_pos);
else
$x_pos = ($w * $x_pos) - ($orig_w / _MPDFK * $x_pos);
}
$y_pos = $this->patterns[$i]['y_pos'];
if (stristr($y_pos, '%')) {
$y_pos += 0;
$y_pos /= 100;
if (isset($bpa['h']) && $bpa['h'])
$y_pos = ($bpa['h'] * $y_pos) - ($orig_h / _MPDFK *
$y_pos);
else
$y_pos = ($h * $y_pos) - ($orig_h / _MPDFK * $y_pos);
}
if (isset($bpa['x']) && $bpa['x'])
$adj_x = ($x_pos + $bpa['x']) * _MPDFK;
else
$adj_x = ($x_pos + $x) * _MPDFK;
if (isset($bpa['y']) && $bpa['y'])
$adj_y = (($pgh - $y_pos - $bpa['y']) * _MPDFK) - $orig_h;
else
$adj_y = (($pgh - $y_pos - $y) * _MPDFK) - $orig_h;
$img_obj = false;
if ($itype == 'svg' || $itype == 'wmf') {
foreach ($this->formobjects AS $fo) {
if ($fo['i'] == $image_id) {
$img_obj = $fo['n'];
$fo_w = $fo['w'];
$fo_h = -$fo['h'];
$wmf_x = $fo['x'];
$wmf_y = $fo['y'];
break;
}
}
} else {
foreach ($this->images AS $img) {
if ($img['i'] == $image_id) {
$img_obj = $img['n'];
break;
}
}
}
if (!$img_obj) {
echo "Problem: Image object not found for background
pattern " . $img['i'];
exit;
}
$this->_newobj();
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
if ($itype == 'svg' || $itype == 'wmf') {
$this->_out('/XObject <</FO' . $image_id . ' ' . $img_obj .
' 0 R >>');
// ******* ADD ANY ExtGStates, Shading AND Fonts needed for
the FormObject
// Set in classes/svg array['fo'] = true
// Required that _putshaders comes before _putpatterns in
_putresources
// This adds any resources associated with any FormObject
to every Formobject - overkill but works!
if (count($this->extgstates)) {
$this->_out('/ExtGState <<');
foreach ($this->extgstates as $k => $extgstate)
if (isset($extgstate['fo']) &&
$extgstate['fo']) {
if (isset($extgstate['trans']))
$this->_out('/' .
$extgstate['trans'] . ' ' . $extgstate['n'] . ' 0 R');
else
$this->_out('/GS' . $k . ' ' .
$extgstate['n'] . ' 0 R');
}
$this->_out('>>');
}
/* -- BACKGROUNDS -- */
if (isset($this->gradients) AND ( count($this->gradients) >
0)) {
$this->_out('/Shading <<');
foreach ($this->gradients as $id => $grad) {
if (isset($grad['fo']) && $grad['fo']) {
$this->_out('/Sh' . $id . ' ' .
$grad['id'] . ' 0 R');
}
}
$this->_out('>>');
}
/* -- END BACKGROUNDS -- */
$this->_out('/Font <<');
foreach ($this->fonts as $font) {
if (!$font['used'] && $font['type'] == 'TTF') {
continue;
}
if (isset($font['fo']) && $font['fo']) {
if ($font['type'] == 'TTF' && ($font['sip'] ||
$font['smp'])) {
foreach ($font['n'] AS $k => $fid) {
$this->_out('/F' .
$font['subsetfontids'][$k] . ' ' . $font['n'][$k] . ' 0 R');
}
} else {
$this->_out('/F' . $font['i'] . ' ' .
$font['n'] . ' 0 R');
}
}
}
$this->_out('>>');
} else {
$this->_out('/XObject <</I' . $image_id . ' ' . $img_obj .
' 0 R >>');
}
$this->_out('>>');
$this->_out('endobj');
$this->_newobj();
$this->patterns[$i]['n'] = $this->n;
$this->_out('<< /Type /Pattern /PatternType 1 /PaintType 1
/TilingType 2');
$this->_out('/Resources ' . ($this->n - 1) . ' 0 R');
if ($this->compress) {
$this->_out('/Filter /FlateDecode');
$s = gzcompress($s);
}
$this->_out('/Length ' . strlen($s) . '>>');
$this->_putstream($s);
$this->_out('endobj');
}
}
/* -- BACKGROUNDS -- */
function _putshaders()
{
$maxid = count($this->gradients); //index for transparency gradients
foreach ($this->gradients as $id => $grad) {
if (($grad['type'] == 2 || $grad['type'] == 3) &&
empty($grad['is_mask'])) {
$this->_newobj();
$this->_out('<<');
$this->_out('/FunctionType 3');
$this->_out('/Domain [0 1]');
$fn = array();
$bd = array();
$en = array();
for ($i = 0; $i < (count($grad['stops']) - 1); $i++) {
$fn[] = ($this->n + 1 + $i) . ' 0 R';
$en[] = '0 1';
if ($i > 0) {
$bd[] = sprintf('%.3F', $grad['stops'][$i]
['offset']);
}
}
$this->_out('/Functions [' . implode(' ', $fn) . ']');
$this->_out('/Bounds [' . implode(' ', $bd) . ']');
$this->_out('/Encode [' . implode(' ', $en) . ']');
$this->_out('>>');
$this->_out('endobj');
$f1 = $this->n;
for ($i = 0; $i < (count($grad['stops']) - 1); $i++) {
$this->_newobj();
$this->_out('<<');
$this->_out('/FunctionType 2');
$this->_out('/Domain [0 1]');
$this->_out('/C0 [' . $grad['stops'][$i]['col'] .
']');
$this->_out('/C1 [' . $grad['stops'][$i + 1]['col'] .
']');
$this->_out('/N 1');
$this->_out('>>');
$this->_out('endobj');
}
}
if ($grad['type'] == 2 || $grad['type'] == 3) {
if (isset($grad['trans']) && $grad['trans']) {
$this->_newobj();
$this->_out('<<');
$this->_out('/FunctionType 3');
$this->_out('/Domain [0 1]');
$fn = array();
$bd = array();
$en = array();
for ($i = 0; $i < (count($grad['stops']) - 1); $i++)
{
$fn[] = ($this->n + 1 + $i) . ' 0 R';
$en[] = '0 1';
if ($i > 0) {
$bd[] = sprintf('%.3F', $grad['stops']
[$i]['offset']);
}
}
$this->_out('/Functions [' . implode(' ', $fn) .
']');
$this->_out('/Bounds [' . implode(' ', $bd) . ']');
$this->_out('/Encode [' . implode(' ', $en) . ']');
$this->_out('>>');
$this->_out('endobj');
$f2 = $this->n;
for ($i = 0; $i < (count($grad['stops']) - 1); $i++)
{
$this->_newobj();
$this->_out('<<');
$this->_out('/FunctionType 2');
$this->_out('/Domain [0 1]');
$this->_out(sprintf('/C0 [%.3F]',
$grad['stops'][$i]['opacity']));
$this->_out(sprintf('/C1 [%.3F]',
$grad['stops'][$i + 1]['opacity']));
$this->_out('/N 1');
$this->_out('>>');
$this->_out('endobj');
}
}
}
if (empty($grad['is_mask'])) {
$this->_newobj();
$this->_out('<<');
$this->_out('/ShadingType ' . $grad['type']);
if (isset($grad['colorspace'])) {
$this->_out('/ColorSpace /Device' .
$grad['colorspace']); // Can use CMYK if all C0 and C1 above have 4 values
} else {
$this->_out('/ColorSpace /DeviceRGB');
}
if ($grad['type'] == 2) {
$this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]',
$grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
$this->_out('/Function ' . $f1 . ' 0 R');
$this->_out('/Extend [' . $grad['extend'][0] . ' ' .
$grad['extend'][1] . '] ');
$this->_out('>>');
} elseif ($grad['type'] == 3) {
//x0, y0, r0, x1, y1, r1
//at this this time radius of inner circle is 0
$ir = 0;
if (isset($grad['coords'][5]) && $grad['coords'][5])
{
$ir = $grad['coords'][5];
}
$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]));
$this->_out('/Function ' . $f1 . ' 0 R');
$this->_out('/Extend [' . $grad['extend'][0] . ' ' .
$grad['extend'][1] . '] ');
$this->_out('>>');
} elseif ($grad['type'] == 6) {
$this->_out('/BitsPerCoordinate 16');
$this->_out('/BitsPerComponent 8');
if ($grad['colorspace'] == 'CMYK') {
$this->_out('/Decode[0 1 0 1 0 1 0 1 0 1 0
1]');
} elseif ($grad['colorspace'] == 'Gray') {
$this->_out('/Decode[0 1 0 1 0 1]');
} else {
$this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]');
}
$this->_out('/BitsPerFlag 8');
$this->_out('/Length ' . strlen($grad['stream']));
$this->_out('>>');
$this->_putstream($grad['stream']);
}
$this->_out('endobj');
}
$this->gradients[$id]['id'] = $this->n;
$this->gradients[$id]['pattern'] = $this->n;
if (isset($grad['trans']) && $grad['trans']) {
// luminosity pattern
$transid = $id + $maxid;
$this->_newobj();
$this->_out('<<');
$this->_out('/ShadingType ' . $grad['type']);
$this->_out('/ColorSpace /DeviceGray');
if ($grad['type'] == 2) {
$this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]',
$grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
$this->_out('/Function ' . $f2 . ' 0 R');
$this->_out('/Extend [' . $grad['extend'][0] . ' ' .
$grad['extend'][1] . '] ');
$this->_out('>>');
} elseif ($grad['type'] == 3) {
//x0, y0, r0, x1, y1, r1
//at this this time radius of inner circle is 0
$ir = 0;
if (isset($grad['coords'][5]) && $grad['coords'][5])
{
$ir = $grad['coords'][5];
}
$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]));
$this->_out('/Function ' . $f2 . ' 0 R');
$this->_out('/Extend [' . $grad['extend'][0] . ' ' .
$grad['extend'][1] . '] ');
$this->_out('>>');
} elseif ($grad['type'] == 6) {
$this->_out('/BitsPerCoordinate 16');
$this->_out('/BitsPerComponent 8');
$this->_out('/Decode[0 1 0 1 0 1]');
$this->_out('/BitsPerFlag 8');
$this->_out('/Length ' .
strlen($grad['stream_trans']));
$this->_out('>>');
$this->_putstream($grad['stream_trans']);
}
$this->_out('endobj');
$this->gradients[$transid]['id'] = $this->n;
$this->_newobj();
$this->_out('<< /Type /Pattern /PatternType 2');
$this->_out('/Shading ' . $this->gradients[$transid]
['id'] . ' 0 R');
$this->_out('>>');
$this->_out('endobj');
$this->gradients[$transid]['pattern'] = $this->n;
$this->_newobj();
// Need to extend size of viewing box in case of
transformations
$str = 'q /a0 gs /Pattern cs /p' . $transid . ' scn -' .
($this->wPt / 2) . ' -' . ($this->hPt / 2) . ' ' . (2 * $this->wPt) . ' ' . (2 *
$this->hPt) . ' re f Q';
$filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
$p = ($this->compress) ? gzcompress($str) : $str;
$this->_out('<< /Type /XObject /Subtype /Form /FormType 1 '
. $filter);
$this->_out('/Length ' . strlen($p));
$this->_out('/BBox [-' . ($this->wPt / 2) . ' -' . ($this-
>hPt / 2) . ' ' . (2 * $this->wPt) . ' ' . (2 * $this->hPt) . ']');
$this->_out('/Group << /Type /Group /S /Transparency /CS
/DeviceGray >>');
$this->_out('/Resources <<');
$this->_out('/ExtGState << /a0 << /ca 1 /CA 1 >> >>');
$this->_out('/Pattern << /p' . $transid . ' ' . $this-
>gradients[$transid]['pattern'] . ' 0 R >>');
$this->_out('>>');
$this->_out('>>');
$this->_putstream($p);
$this->_out('endobj');
$this->_newobj();
$this->_out('<< /Type /Mask /S /Luminosity /G ' . ($this->n
- 1) . ' 0 R >>' . "\n" . 'endobj');
$this->_newobj();
$this->_out('<< /Type /ExtGState /SMask ' . ($this->n -
1) . ' 0 R /AIS false >>' . "\n" . 'endobj');
if (isset($grad['fo']) && $grad['fo']) {
$this->extgstates[] = array('n' => $this->n, 'trans'
=> 'TGS' . $id, 'fo' => true);
} else {
$this->extgstates[] = array('n' => $this->n, 'trans'
=> 'TGS' . $id);
}
}
}
}
/* -- END BACKGROUNDS -- */
function _putspotcolors()
{
foreach ($this->spotColors as $name => $color) {
$this->_newobj();
$this->_out('[/Separation /' . str_replace(' ', '#20', $name));
$this->_out('/DeviceCMYK <<');
$this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
$this->_out(sprintf('/C1 [%.3F %.3F %.3F %.3F] ', $color['c'] /
100, $color['m'] / 100, $color['y'] / 100, $color['k'] / 100));
$this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
$this->_out('endobj');
$this->spotColors[$name]['n'] = $this->n;
}
}
function _putresources()
{
if ($this->hasOC || count($this->layers))
$this->_putocg();
$this->_putextgstates();
$this->_putspotcolors();
if ($this->progressBar) {
$this->UpdateProgressBar(2, '40', 'Compiling Fonts');
} // *PROGRESS-BAR*
$this->_putfonts();
if ($this->progressBar) {
$this->UpdateProgressBar(2, '50', 'Compiling Images');
} // *PROGRESS-BAR*
$this->_putimages();
$this->_putformobjects(); // *IMAGES-CORE*
/* -- IMPORTS -- */
if ($this->enableImports) {
$this->_putformxobjects();
$this->_putimportedobjects();
}
/* -- END IMPORTS -- */
/* -- BACKGROUNDS -- */
$this->_putshaders();
$this->_putpatterns();
/* -- END BACKGROUNDS -- */
//Resource dictionary
$this->offsets[2] = strlen($this->buffer);
$this->_out('2 0 obj');
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
$this->_out('/Font <<');
foreach ($this->fonts as $font) {
if (isset($font['type']) && $font['type'] == 'TTF' && !
$font['used']) {
continue;
}
if (isset($font['type']) && $font['type'] == 'TTF' &&
($font['sip'] || $font['smp'])) {
foreach ($font['n'] AS $k => $fid) {
$this->_out('/F' . $font['subsetfontids'][$k] . ' ' .
$font['n'][$k] . ' 0 R');
}
} else {
$this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
}
}
$this->_out('>>');
if (count($this->spotColors)) {
$this->_out('/ColorSpace <<');
foreach ($this->spotColors as $color)
$this->_out('/CS' . $color['i'] . ' ' . $color['n'] . ' 0
R');
$this->_out('>>');
}
if (count($this->extgstates)) {
$this->_out('/ExtGState <<');
foreach ($this->extgstates as $k => $extgstate)
if (isset($extgstate['trans']))
$this->_out('/' . $extgstate['trans'] . ' ' .
$extgstate['n'] . ' 0 R');
else
$this->_out('/GS' . $k . ' ' . $extgstate['n'] . ' 0
R');
$this->_out('>>');
}
/* -- BACKGROUNDS -- */
if ((isset($this->gradients) AND ( count($this->gradients) > 0)) ||
($this->enableImports && count($this->tpls))) { // mPDF 5.7.3
$this->_out('/Shading <<');
foreach ($this->gradients as $id => $grad) {
$this->_out('/Sh' . $id . ' ' . $grad['id'] . ' 0 R');
}
// mPDF 5.7.3
// If a shading dictionary is in an object (tpl) imported from
another PDF, it needs to be included
// in the document resources, as well as the object resources
// Otherwise get an error in some PDF viewers
if ($this->enableImports && count($this->tpls)) {
foreach ($this->tpls as $tplidx => $tpl) {
if (isset($tpl['resources'])) {
$this->current_parser = $tpl['parser'];
reset($tpl['resources'][1]);
while (list($k, $v) = each($tpl['resources']
[1])) {
if ($k == '/Shading') {
while (list($k2, $v2) =
each($v[1])) {
$this->_out($k2 . " ",
false);
$this->pdf_write_value($v2);
}
}
}
}
}
}
$this->_out('>>');
/*
// ??? Not needed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$this->_out('/Pattern <<');
foreach ($this->gradients as $id => $grad) {
$this->_out('/P'.$id.' '.$grad['pattern'].' 0 R');
}
$this->_out('>>');
*/
}
/* -- END BACKGROUNDS -- */
/* -- BACKGROUNDS -- */
if (count($this->patterns)) {
$this->_out('/Pattern <<');
foreach ($this->patterns as $k => $patterns)
$this->_out('/P' . $k . ' ' . $patterns['n'] . ' 0 R');
$this->_out('>>');
}
/* -- END BACKGROUNDS -- */
if ($this->hasOC || count($this->layers)) {
$this->_out('/Properties <<');
if ($this->hasOC) {
$this->_out('/OC1 ' . $this->n_ocg_print . ' 0 R /OC2 ' .
$this->n_ocg_view . ' 0 R /OC3 ' . $this->n_ocg_hidden . ' 0 R ');
}
if (count($this->layers)) {
foreach ($this->layers as $id => $layer)
$this->_out('/ZI' . $id . ' ' . $layer['n'] . ' 0
R');
}
$this->_out('>>');
}
$this->_out('>>');
$this->_out('endobj'); // end resource dictionary
$this->_putbookmarks(); // *BOOKMARKS*
/* -- ENCRYPTION -- */
if ($this->encrypted) {
$this->_newobj();
$this->enc_obj_id = $this->n;
$this->_out('<<');
$this->_putencryption();
$this->_out('>>');
$this->_out('endobj');
}
/* -- END ENCRYPTION -- */
}
function _putjavascript()
{
$this->_newobj();
$this->n_js = $this->n;
$this->_out('<<');
$this->_out('/Names [(EmbeddedJS) ' . (1 + $this->n) . ' 0 R ]');
$this->_out('>>');
$this->_out('endobj');
$this->_newobj();
$this->_out('<<');
$this->_out('/S /JavaScript');
$this->_out('/JS ' . $this->_textstring($this->js));
$this->_out('>>');
$this->_out('endobj');
}
/* -- ENCRYPTION -- */
function _putencryption()
{
$this->_out('/Filter /Standard');
if ($this->useRC128encryption) {
$this->_out('/V 2');
$this->_out('/R 3');
$this->_out('/Length 128');
} else {
$this->_out('/V 1');
$this->_out('/R 2');
}
$this->_out('/O (' . $this->_escape($this->Ovalue) . ')');
$this->_out('/U (' . $this->_escape($this->Uvalue) . ')');
$this->_out('/P ' . $this->Pvalue);
}
/* -- END ENCRYPTION -- */
function _puttrailer()
{
$this->_out('/Size ' . ($this->n + 1));
$this->_out('/Root ' . $this->n . ' 0 R');
$this->_out('/Info ' . $this->InfoRoot . ' 0 R');
/* -- ENCRYPTION -- */
if ($this->encrypted) {
$this->_out('/Encrypt ' . $this->enc_obj_id . ' 0 R');
$this->_out('/ID [<' . $this->uniqid . '> <' . $this->uniqid .
'>]');
} else {
/* -- END ENCRYPTION -- */
$uniqid = md5(time() . $this->buffer);
$this->_out('/ID [<' . $uniqid . '> <' . $uniqid . '>]');
/* -- ENCRYPTION -- */
}
/* -- END ENCRYPTION -- */
}
/* -- ENCRYPTION -- */
$options = array(
'print' => 4, // bit 3
'modify' => 8, // bit 4
'copy' => 16, // bit 5
'annot-forms' => 32, // bit 6
'fill-forms' => 256, // bit 9
'extract' => 512, // bit 10
'assemble' => 1024, // bit 11
'print-highres' => 2048 // bit 12
);
// bit 31 = 1073741824
// bit 32 = 2147483648
// bits 13-31 = 2147479552
// bits 13-32 = 4294963200 + 192 = 4294963392
$protection = 4294963392; // bits 7,8,13-32
foreach ($permissions as $permission) {
if (!isset($options[$permission]))
throw new MpdfException('Incorrect permission: ' .
$permission);
if ($options[$permission] > 32) {
$this->useRC128encryption = true;
}
if (isset($options[$permission]))
$protection += $options[$permission];
}
if ($length == 128) {
$this->useRC128encryption = true;
}
if ($owner_pass === null)
$owner_pass = uniqid(rand());
$this->encrypted = true;
$this->_generateencryptionkey($user_pass, $owner_pass, $protection);
}
// Compute key depending on object number where the encrypted data is stored
function _objectkey($n)
{
if ($this->useRC128encryption)
$len = 16;
else
$len = 10;
return substr($this->_md5_16($this->encryption_key . pack('VXxx', $n)),
0, $len);
}
$len = strlen($text);
$a = 0;
$b = 0;
$out = '';
for ($i = 0; $i < $len; $i++) {
$a = ($a + 1) % 256;
$t = $rc4[$a];
$b = ($b + $t) % 256;
$rc4[$a] = $rc4[$b];
$rc4[$b] = $t;
$k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
$out.= chr(ord($text[$i]) ^ $k);
}
return $out;
}
// Compute O value
function _Ovalue($user_pass, $owner_pass)
{
$tmp = $this->_md5_16($owner_pass);
if ($this->useRC128encryption) {
for ($i = 0; $i < 50; ++$i) {
$tmp = $this->_md5_16($tmp);
}
}
if ($this->useRC128encryption)
$keybytelen = (128 / 8);
else
$keybytelen = (40 / 8);
$owner_RC4_key = substr($tmp, 0, $keybytelen);
$enc = $this->_RC4($owner_RC4_key, $user_pass);
if ($this->useRC128encryption) {
$len = strlen($owner_RC4_key);
for ($i = 1; $i <= 19; ++$i) {
$key = '';
for ($j = 0; $j < $len; ++$j) {
$key .= chr(ord($owner_RC4_key{$j}) ^ $i);
}
$enc = $this->_RC4($key, $enc);
}
}
return $enc;
}
// Compute U value
function _Uvalue()
{
if ($this->useRC128encryption) {
$tmp = $this->_md5_16($this->padding . $this->_hexToString($this-
>uniqid));
$enc = $this->_RC4($this->encryption_key, $tmp);
$len = strlen($tmp);
for ($i = 1; $i <= 19; ++$i) {
$key = '';
for ($j = 0; $j < $len; ++$j) {
$key .= chr(ord($this->encryption_key{$j}) ^ $i);
}
$enc = $this->_RC4($key, $enc);
}
$enc .= str_repeat("\x00", 16);
return substr($enc, 0, 32);
} else {
return $this->_RC4($this->encryption_key, $this->padding);
}
}
function _hexToString($hs)
{
$s = '';
$len = strlen($hs);
if (($len % 2) != 0) {
$hs .= '0';
++$len;
}
for ($i = 0; $i < $len; $i += 2) {
$s .= chr(hexdec($hs{$i} . $hs{($i + 1)}));
}
return $s;
}
/* -- END ENCRYPTION -- */
//=========================================
/* -- BOOKMARKS -- */
// FROM class PDF_Bookmark
function _putbookmarks()
{
$nb = count($this->BMoutlines);
if ($nb == 0)
return;
$bmo = $this->BMoutlines;
$this->BMoutlines = array();
$lastlevel = -1;
for ($i = 0; $i < count($bmo); $i++) {
if ($bmo[$i]['l'] > 0) {
while ($bmo[$i]['l'] - $lastlevel > 1) { // If jump down
more than one level, insert a new entry
$new = $bmo[$i];
$new['t'] = "[" . $new['t'] . "]"; // Put [] around
text/title to highlight
$new['l'] = $lastlevel + 1;
$lastlevel++;
$this->BMoutlines[] = $new;
}
}
$this->BMoutlines[] = $bmo[$i];
$lastlevel = $bmo[$i]['l'];
}
$nb = count($this->BMoutlines);
$lru = array();
$level = 0;
foreach ($this->BMoutlines as $i => $o) {
if ($o['l'] > 0) {
$parent = $lru[$o['l'] - 1];
//Set parent and last pointers
$this->BMoutlines[$i]['parent'] = $parent;
$this->BMoutlines[$parent]['last'] = $i;
if ($o['l'] > $level) {
//Level increasing: set first pointer
$this->BMoutlines[$parent]['first'] = $i;
}
} else {
$this->BMoutlines[$i]['parent'] = $nb;
}
if ($o['l'] <= $level and $i > 0) {
//Set prev and next pointers
$prev = $lru[$o['l']];
$this->BMoutlines[$prev]['next'] = $i;
$this->BMoutlines[$i]['prev'] = $prev;
}
$lru[$o['l']] = $i;
$level = $o['l'];
}
//Outline items
$n = $this->n + 1;
foreach ($this->BMoutlines as $i => $o) {
$this->_newobj();
$this->_out('<</Title ' . $this->_UTF16BEtextstring($o['t']));
$this->_out('/Parent ' . ($n + $o['parent']) . ' 0 R');
if (isset($o['prev']))
$this->_out('/Prev ' . ($n + $o['prev']) . ' 0 R');
if (isset($o['next']))
$this->_out('/Next ' . ($n + $o['next']) . ' 0 R');
if (isset($o['first']))
$this->_out('/First ' . ($n + $o['first']) . ' 0 R');
if (isset($o['last']))
$this->_out('/Last ' . ($n + $o['last']) . ' 0 R');
if (isset($this->pageDim[$o['p']]['h'])) {
$h = $this->pageDim[$o['p']]['h'];
} else {
$h = 0;
}
$this->_out('/Count 0>>');
$this->_out('endobj');
}
//Outline root
$this->_newobj();
$this->OutlineRoot = $this->n;
$this->_out('<</Type /BMoutlines /First ' . $n . ' 0 R');
$this->_out('/Last ' . ($n + $lru[0]) . ' 0 R>>');
$this->_out('endobj');
}
/* -- END BOOKMARKS -- */
//======================================================
/* -- TOC -- */
// ToC TABLE OF CONTENTS
// Initiate, and Mark a place for the Table of Contents to be inserted
function TOC($tocfont = '', $tocfontsize = 0, $tocindent = 0, $resetpagenum =
'', $pagenumstyle = '', $suppress = '', $toc_orientation = '', $TOCusePaging =
true, $TOCuseLinking = false, $toc_id = 0, $tocoutdent = '')
{
if (!class_exists('tocontents', false)) {
include(_MPDF_PATH . 'classes/tocontents.php');
}
if (empty($this->tocontents)) {
$this->tocontents = new tocontents($this);
}
$this->tocontents->TOC($tocfont, $tocfontsize, $tocindent,
$resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $TOCusePaging,
$TOCuseLinking, $toc_id, $tocoutdent);
}
function TOCpagebreakByArray($a)
{
if (!is_array($a)) {
$a = array();
}
if (!class_exists('tocontents', false)) {
include(_MPDF_PATH . 'classes/tocontents.php');
}
if (empty($this->tocontents)) {
$this->tocontents = new tocontents($this);
}
$tocoutdent = (isset($a['tocoutdent']) ? $a['tocoutdent'] :
(isset($a['outdent']) ? $a['outdent'] : ''));
$TOCusePaging = (isset($a['TOCusePaging']) ? $a['TOCusePaging'] :
(isset($a['paging']) ? $a['paging'] : true));
$TOCuseLinking = (isset($a['TOCuseLinking']) ? $a['TOCuseLinking'] :
(isset($a['links']) ? $a['links'] : ''));
$toc_orientation = (isset($a['toc_orientation']) ?
$a['toc_orientation'] : (isset($a['toc-orientation']) ? $a['toc-orientation'] :
''));
$toc_mgl = (isset($a['toc_mgl']) ? $a['toc_mgl'] : (isset($a['toc-
margin-left']) ? $a['toc-margin-left'] : ''));
$toc_mgr = (isset($a['toc_mgr']) ? $a['toc_mgr'] : (isset($a['toc-
margin-right']) ? $a['toc-margin-right'] : ''));
$toc_mgt = (isset($a['toc_mgt']) ? $a['toc_mgt'] : (isset($a['toc-
margin-top']) ? $a['toc-margin-top'] : ''));
$toc_mgb = (isset($a['toc_mgb']) ? $a['toc_mgb'] : (isset($a['toc-
margin-bottom']) ? $a['toc-margin-bottom'] : ''));
$toc_mgh = (isset($a['toc_mgh']) ? $a['toc_mgh'] : (isset($a['toc-
margin-header']) ? $a['toc-margin-header'] : ''));
$toc_mgf = (isset($a['toc_mgf']) ? $a['toc_mgf'] : (isset($a['toc-
margin-footer']) ? $a['toc-margin-footer'] : ''));
$toc_ohname = (isset($a['toc_ohname']) ? $a['toc_ohname'] :
(isset($a['toc-odd-header-name']) ? $a['toc-odd-header-name'] : ''));
$toc_ehname = (isset($a['toc_ehname']) ? $a['toc_ehname'] :
(isset($a['toc-even-header-name']) ? $a['toc-even-header-name'] : ''));
$toc_ofname = (isset($a['toc_ofname']) ? $a['toc_ofname'] :
(isset($a['toc-odd-footer-name']) ? $a['toc-odd-footer-name'] : ''));
$toc_efname = (isset($a['toc_efname']) ? $a['toc_efname'] :
(isset($a['toc-even-footer-name']) ? $a['toc-even-footer-name'] : ''));
$toc_ohvalue = (isset($a['toc_ohvalue']) ? $a['toc_ohvalue'] :
(isset($a['toc-odd-header-value']) ? $a['toc-odd-header-value'] : 0));
$toc_ehvalue = (isset($a['toc_ehvalue']) ? $a['toc_ehvalue'] :
(isset($a['toc-even-header-value']) ? $a['toc-even-header-value'] : 0));
$toc_ofvalue = (isset($a['toc_ofvalue']) ? $a['toc_ofvalue'] :
(isset($a['toc-odd-footer-value']) ? $a['toc-odd-footer-value'] : 0));
$toc_efvalue = (isset($a['toc_efvalue']) ? $a['toc_efvalue'] :
(isset($a['toc-even-footer-value']) ? $a['toc-even-footer-value'] : 0));
$toc_preHTML = (isset($a['toc_preHTML']) ? $a['toc_preHTML'] :
(isset($a['toc-preHTML']) ? $a['toc-preHTML'] : ''));
$toc_postHTML = (isset($a['toc_postHTML']) ? $a['toc_postHTML'] :
(isset($a['toc-postHTML']) ? $a['toc-postHTML'] : ''));
$toc_bookmarkText = (isset($a['toc_bookmarkText']) ?
$a['toc_bookmarkText'] : (isset($a['toc-bookmarkText']) ? $a['toc-bookmarkText'] :
''));
$resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : '');
$pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : '');
$suppress = (isset($a['suppress']) ? $a['suppress'] : '');
$orientation = (isset($a['orientation']) ? $a['orientation'] : '');
$mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ?
$a['margin-left'] : ''));
$mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ?
$a['margin-right'] : ''));
$mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ?
$a['margin-top'] : ''));
$mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ?
$a['margin-bottom'] : ''));
$mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ?
$a['margin-header'] : ''));
$mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ?
$a['margin-footer'] : ''));
$ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-
name']) ? $a['odd-header-name'] : ''));
$ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-
name']) ? $a['even-header-name'] : ''));
$ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-
name']) ? $a['odd-footer-name'] : ''));
$efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-
name']) ? $a['even-footer-name'] : ''));
$ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-
header-value']) ? $a['odd-header-value'] : 0));
$ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-
header-value']) ? $a['even-header-value'] : 0));
$ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-
footer-value']) ? $a['odd-footer-value'] : 0));
$efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-
footer-value']) ? $a['even-footer-value'] : 0));
$toc_id = (isset($a['toc_id']) ? $a['toc_id'] : (isset($a['name']) ?
$a['name'] : 0));
$pagesel = (isset($a['pagesel']) ? $a['pagesel'] :
(isset($a['pageselector']) ? $a['pageselector'] : ''));
$toc_pagesel = (isset($a['toc_pagesel']) ? $a['toc_pagesel'] :
(isset($a['toc-pageselector']) ? $a['toc-pageselector'] : ''));
$sheetsize = (isset($a['sheetsize']) ? $a['sheetsize'] :
(isset($a['sheet-size']) ? $a['sheet-size'] : ''));
$toc_sheetsize = (isset($a['toc_sheetsize']) ? $a['toc_sheetsize'] :
(isset($a['toc-sheet-size']) ? $a['toc-sheet-size'] : ''));
if (strtoupper($toc_id) == 'ALL') {
$toc_id = '_mpdf_all';
} elseif (!$toc_id) {
$toc_id = 0;
} else {
$toc_id = strtolower($toc_id);
}
$btoc = array('t' => $txt, 'l' => $level, 'p' => $this->page, 'link' =>
$linkn, 'toc_id' => $toc_id);
if ($this->keep_block_together) {
// do nothing
}
/* -- TABLES -- */ elseif ($this->table_rotate) {
$this->tbrot_toc[] = $btoc;
} elseif ($this->kwt) {
$this->kwt_toc[] = $btoc;
}
/* -- END TABLES -- */ elseif ($this->ColActive) { // *COLUMNS*
$this->col_toc[] = $btoc; // *COLUMNS*
} // *COLUMNS*
else {
$this->tocontents->_toc[] = $btoc;
}
}
/* -- END TOC -- */
//======================================================
function MovePages($target_page, $start_page, $end_page = -1)
{
// move a page/pages EARLIER in the document
if ($end_page < 1) {
$end_page = $start_page;
}
$n_toc = $end_page - $start_page + 1;
// Set/Update PageNumSubstitutions changes before moving anything
if (count($this->PageNumSubstitutions)) {
$tp_present = false;
$sp_present = false;
$ep_present = false;
foreach ($this->PageNumSubstitutions AS $k => $v) {
if ($this->PageNumSubstitutions[$k]['from'] ==
$target_page) {
$tp_present = true;
if ($this->PageNumSubstitutions[$k]['suppress'] !=
'on' && $this->PageNumSubstitutions[$k]['suppress'] != 1) {
$this->PageNumSubstitutions[$k]['suppress'] =
'off';
}
}
if ($this->PageNumSubstitutions[$k]['from'] == $start_page)
{
$sp_present = true;
if ($this->PageNumSubstitutions[$k]['suppress'] !=
'on' && $this->PageNumSubstitutions[$k]['suppress'] != 1) {
$this->PageNumSubstitutions[$k]['suppress'] =
'off';
}
}
if ($this->PageNumSubstitutions[$k]['from'] == ($end_page +
1)) {
$ep_present = true;
if ($this->PageNumSubstitutions[$k]['suppress'] !=
'on' && $this->PageNumSubstitutions[$k]['suppress'] != 1) {
$this->PageNumSubstitutions[$k]['suppress'] =
'off';
}
}
}
if (!$tp_present) {
list($tp_type, $tp_suppress, $tp_reset) = $this-
>docPageSettings($target_page);
}
if (!$sp_present) {
list($sp_type, $sp_suppress, $sp_reset) = $this-
>docPageSettings($start_page);
}
if (!$ep_present) {
list($ep_type, $ep_suppress, $ep_reset) = $this-
>docPageSettings($start_page - 1);
}
}
$last = array();
//store pages
for ($i = $start_page; $i <= $end_page; $i++)
$last[] = $this->pages[$i];
//move pages
for ($i = $start_page - 1; $i >= ($target_page); $i--) {
$this->pages[$i + $n_toc] = $this->pages[$i];
}
//Put toc pages at insert point
for ($i = 0; $i < $n_toc; $i++) {
$this->pages[$target_page + $i] = $last[$i];
}
/* -- BOOKMARKS -- */
// Update Bookmarks
foreach ($this->BMoutlines as $i => $o) {
if ($o['p'] >= $target_page) {
$this->BMoutlines[$i]['p'] += $n_toc;
}
}
/* -- END BOOKMARKS -- */
// OrientationChanges
if (count($this->OrientationChanges)) {
$newarr = array();
foreach ($this->OrientationChanges AS $p => $v) {
if ($p >= $start_page && $p <= $end_page) {
$newarr[($p + ($target_page - $start_page))] = $this-
>OrientationChanges[$p];
} elseif ($p >= $target_page && $p < $start_page) {
$newarr[$p + $n_toc] = $this->OrientationChanges[$p];
} else {
$newarr[$p] = $this->OrientationChanges[$p];
}
}
ksort($newarr);
$this->OrientationChanges = $newarr;
}
// Page Dimensions
if (count($this->pageDim)) {
$newarr = array();
foreach ($this->pageDim AS $p => $v) {
if ($p >= $start_page && $p <= $end_page) {
$newarr[($p + ($target_page - $start_page))] = $this-
>pageDim[$p];
} elseif ($p >= $target_page && $p < $start_page) {
$newarr[$p + $n_toc] = $this->pageDim[$p];
} else {
$newarr[$p] = $this->pageDim[$p];
}
}
ksort($newarr);
$this->pageDim = $newarr;
}
// Update Links
if (count($this->links)) {
foreach ($this->links as $key => $o) {
if ($o[0] >= $start_page && $o[0] <= $end_page) {
$this->links[$key][0] += ($target_page -
$start_page);
}
if ($o[0] >= $target_page && $o[0] < $start_page) {
$this->links[$key][0] += $n_toc;
}
}
}
/* -- ANNOTATIONS -- */
// Update Annotations
if (count($this->PageAnnots)) {
$newarr = array();
foreach ($this->PageAnnots as $p => $anno) {
if ($p >= $start_page && $p <= $end_page) {
$np = $p + ($target_page - $start_page);
foreach ($anno as $o) {
$newarr[$np][] = $o;
}
} elseif ($p >= $target_page && $p < $start_page) {
$np = $p + $n_toc;
foreach ($anno as $o) {
$newarr[$np][] = $o;
}
} else {
$newarr[$p] = $this->PageAnnots[$p];
}
}
$this->PageAnnots = $newarr;
unset($newarr);
}
/* -- END ANNOTATIONS -- */
// Update PageNumSubstitutions
if (count($this->PageNumSubstitutions)) {
$newarr = array();
foreach ($this->PageNumSubstitutions AS $k => $v) {
if ($this->PageNumSubstitutions[$k]['from'] >= $start_page
&& $this->PageNumSubstitutions[$k]['from'] <= $end_page) {
$this->PageNumSubstitutions[$k]['from'] +=
($target_page - $start_page);
$newarr[$this->PageNumSubstitutions[$k]['from']] =
$this->PageNumSubstitutions[$k];
} elseif ($this->PageNumSubstitutions[$k]['from'] >=
$target_page && $this->PageNumSubstitutions[$k]['from'] < $start_page) {
$this->PageNumSubstitutions[$k]['from'] += $n_toc;
$newarr[$this->PageNumSubstitutions[$k]['from']] =
$this->PageNumSubstitutions[$k];
} else {
$newarr[$this->PageNumSubstitutions[$k]['from']] =
$this->PageNumSubstitutions[$k];
}
}
if (!$sp_present) {
$newarr[$target_page] = array('from' => $target_page,
'suppress' => $sp_suppress, 'reset' => $sp_reset, 'type' => $sp_type);
}
if (!$tp_present) {
$newarr[($target_page + $n_toc)] = array('from' =>
($target_page + $n_toc), 'suppress' => $tp_suppress, 'reset' => $tp_reset, 'type'
=> $tp_type);
}
if (!$ep_present && $end_page > count($this->pages)) {
$newarr[($end_page + 1)] = array('from' => ($end_page + 1),
'suppress' => $ep_suppress, 'reset' => $ep_reset, 'type' => $ep_type);
}
ksort($newarr);
$this->PageNumSubstitutions = array();
foreach ($newarr as $v) {
$this->PageNumSubstitutions[] = $v;
}
}
}
//======================================================
function DeletePages($start_page, $end_page = -1)
{
// move a page/pages EARLIER in the document
if ($end_page < 1) {
$end_page = $start_page;
}
$n_tod = $end_page - $start_page + 1;
$last_page = count($this->pages);
$n_atend = $last_page - $end_page + 1;
//move pages
for ($i = 0; $i < $n_atend; $i++) {
$this->pages[$start_page + $i] = $this->pages[$end_page + 1 +
$i];
}
//delete pages
for ($i = 0; $i < $n_tod; $i++)
unset($this->pages[$last_page - $i]);
/* -- BOOKMARKS -- */
// Update Bookmarks
foreach ($this->BMoutlines as $i => $o) {
if ($o['p'] >= $end_page) {
$this->BMoutlines[$i]['p'] -= $n_tod;
} elseif ($p < $start_page) {
unset($this->BMoutlines[$i]);
}
}
/* -- END BOOKMARKS -- */
// OrientationChanges
if (count($this->OrientationChanges)) {
$newarr = array();
foreach ($this->OrientationChanges AS $p => $v) {
if ($p > $end_page) {
$newarr[($p - $t_tod)] = $this-
>OrientationChanges[$p];
} elseif ($p < $start_page) {
$newarr[$p] = $this->OrientationChanges[$p];
}
}
ksort($newarr);
$this->OrientationChanges = $newarr;
}
// Page Dimensions
if (count($this->pageDim)) {
$newarr = array();
foreach ($this->pageDim AS $p => $v) {
if ($p > $end_page) {
$newarr[($p - $n_tod)] = $this->pageDim[$p];
} elseif ($p < $start_page) {
$newarr[$p] = $this->pageDim[$p];
}
}
ksort($newarr);
$this->pageDim = $newarr;
}
// Update Links
foreach ($this->links as $key => $o) {
if ($o[0] > $end_page) {
$this->links[$key][0] -= $n_tod;
} elseif ($o[0] < $start_page) {
unset($this->links[$key]);
}
}
/* -- ANNOTATIONS -- */
// Update Annotations
if (count($this->PageAnnots)) {
$newarr = array();
foreach ($this->PageAnnots as $p => $anno) {
if ($p > $end_page) {
foreach ($anno as $o) {
$newarr[($p - $n_tod)][] = $o;
}
} elseif ($p < $start_page) {
$newarr[$p] = $this->PageAnnots[$p];
}
}
ksort($newarr);
$this->PageAnnots = $newarr;
}
/* -- END ANNOTATIONS -- */
// Update PageNumSubstitutions
foreach ($this->PageNumSubstitutions AS $k => $v) {
if ($this->PageNumSubstitutions[$k]['from'] > $end_page) {
$this->PageNumSubstitutions[$k]['from'] -= $n_tod;
} elseif ($this->PageNumSubstitutions[$k]['from'] < $start_page)
{
unset($this->PageNumSubstitutions[$k]);
}
}
unset($newarr);
$this->page = count($this->pages);
}
//======================================================
/* -- INDEX -- */
// FROM class PDF_Ref == INDEX
if ($usedivletters) {
if ($indexCollationGroup) {
require_once(_MPDF_PATH . 'collations/' .
$indexCollationGroup . '.php');
} else {
$collation = array();
}
for ($i = 0; $i < $size; $i++) {
if ($this->Reference[$i]['uf']) {
$l = mb_substr($this->Reference[$i]['uf'], 0, 1,
'UTF-8');
if (isset($this->indexCollationGroup) && $this-
>indexCollationGroup) {
$uni = $this->UTF8StringToArray($l);
$ucode = $uni[0];
if (isset($collation[$ucode])) {
$this->Reference[$i]['d'] =
code2utf($collation[$ucode]);
} else {
$this->Reference[$i]['d'] =
mb_strtolower($l, 'UTF-8');
}
} else {
$this->Reference[$i]['d'] = mb_strtolower($l,
'UTF-8');
}
}
}
}
if (!function_exists('cmp')) {
$lett = '';
$last_lett = '';
$mainentry = '';
for ($i = 0; $i < $size; $i++) {
if ($this->Reference[$i]['t']) {
if ($usedivletters) {
$lett = $this->Reference[$i]['d'];
if ($lett != $last_lett) {
$html .= '<div class="mpdf_index_letter">' .
$lett . '</div>';
}
}
$txt = $this->Reference[$i]['t'];
$txt = $subEntryInset;
$e = $sub; // Only replace first
one
} else {
$e = preg_replace('/[:]/',
$subEntrySeparator, $e, 1); // Only replace first one
}
$marker = true; // Don't replace any more
once the subentry marker has been found
}
}
$txt .= $e;
}
if (!$marker) {
$mainentry = strip_tags($txt);
}
$html .= $spacer;
if ($useLinking) {
$html .= '<a
class="mpdf_index_link" href="@' . $ppp[$zi - 1] . '">';
}
$html .= $this-
>docPageNum($ppp[$zi - 1]);
if ($useLinking) {
$html .= '</a>';
}
$html .= $sep;
}
} else {
if ($useLinking) {
$html .= '<a
class="mpdf_index_link" href="@' . $ppp[$zi - 1] . '">';
}
$html .= $this->docPageNum($ppp[$zi
- 1]);
if ($useLinking) {
$html .= '</a>';
}
$html .= $sep;
}
$range_start = $ppp[$zi];
$range_end = 0;
}
}
if ($range_end) {
if ($useLinking) {
$html .= '<a class="mpdf_index_link"
href="@' . $range_start . '">';
}
$html .= $this->docPageNum($range_start);
if ($range_end == $range_start + 1) {
if ($useLinking) {
$html .= '</a>';
}
$html .= $sep;
if ($useLinking) {
$html .= '<a
class="mpdf_index_link" href="@' . $range_end . '">';
}
$html .= $this->docPageNum($range_end);
if ($useLinking) {
$html .= '</a>';
}
} else {
$html .= $joiner;
$html .= $this->docPageNum($range_end);
if ($useLinking) {
$html .= '</a>';
}
}
} else {
if ($useLinking) {
$html .= '<a class="mpdf_index_link"
href="@' . $ppp[(count($ppp) - 1)] . '">';
}
$html .= $this->docPageNum($ppp[(count($ppp) -
1)]);
if ($useLinking) {
$html .= '</a>';
}
}
}
}
$html .= '</div>';
$last_lett = $lett;
}
$html .= '</div>';
$save_fpb = $this->fixedPosBlockSave;
$this->WriteHTML($html);
$this->fixedPosBlockSave = $save_fpb;
function AcceptPageBreak()
{
if (count($this->cellBorderBuffer)) {
$this->printcellbuffer();
} // *TABLES*
/* -- COLUMNS -- */
if ($this->ColActive == 1) {
if ($this->CurrCol < $this->NbCol - 1) {
//Go to the next column
$this->CurrCol++;
$this->SetCol($this->CurrCol);
$this->y = $this->y0;
$this->ChangeColumn = 1; // Number (and direction) of
columns changed +1, +2, -2 etc.
// DIRECTIONALITY RTL
if ($this->directionality == 'rtl') {
$this->ChangeColumn = -($this->ChangeColumn);
} // *OTL*
//Stay on the page
return false;
} else {
//Go back to the first column - NEW PAGE
if (count($this->columnbuffer)) {
$this->printcolumnbuffer();
}
$this->SetCol(0);
$this->y0 = $this->tMargin;
$this->ChangeColumn = -($this->NbCol - 1);
// DIRECTIONALITY RTL
if ($this->directionality == 'rtl') {
$this->ChangeColumn = -($this->ChangeColumn);
} // *OTL*
//Page break
return true;
}
}
/* -- END COLUMNS -- */
/* -- TABLES -- */ elseif ($this->table_rotate) {
if ($this->tablebuffer) {
$this->printtablebuffer();
}
return true;
}
/* -- END TABLES -- */ else { // *COLUMNS*
$this->ChangeColumn = 0;
return $this->autoPageBreak;
} // *COLUMNS*
return $this->autoPageBreak;
}
if ($this->directionality == 'rtl') {
for ($i = 0; $i < $this->NbCol; $i++) {
$this->ColL[$i] = $absL + ($gap / 2) + (($NbCol - ($i
+ 1)) * ($PageWidth / $NbCol));
$this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB
This is not R margin -> R pos
}
} else {
/* -- END OTL -- */
for ($i = 0; $i < $this->NbCol; $i++) {
$this->ColL[$i] = $absL + ($gap / 2) + ($i *
($PageWidth / $NbCol) );
$this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB
This is not R margin -> R pos
}
} // *OTL*
$this->pgwidth = $ColWidth;
$this->SetCol(0);
$this->y0 = $this->y;
}
$this->x = $this->lMargin;
}
function SetCol($CurrCol)
{
// Used internally to set column by number: 0 is 1st column
//Set position on a column
$this->CurrCol = $CurrCol;
$x = $this->ColL[$CurrCol];
$xR = $this->ColR[$CurrCol]; // NB This is not R margin -> R pos
if (($this->mirrorMargins) && (($this->page) % 2 == 0)) { // EVEN
$x += $this->MarginCorrection;
$xR += $this->MarginCorrection;
}
$this->SetMargins($x, ($this->w - $xR), $this->tMargin);
}
function AddColumn()
{
$this->NewColumn();
$this->ColumnAdjust = false; // disables all column height adjustment
for the page.
}
function NewColumn()
{
if ($this->ColActive == 1) {
if ($this->CurrCol < $this->NbCol - 1) {
//Go to the next column
$this->CurrCol++;
$this->SetCol($this->CurrCol);
$this->y = $this->y0;
$this->ChangeColumn = 1;
// DIRECTIONALITY RTL
if ($this->directionality == 'rtl') {
$this->ChangeColumn = -($this->ChangeColumn);
} // *OTL*
//Stay on the page
} else {
//Go back to the first column
//Page break
if (count($this->columnbuffer)) {
$this->printcolumnbuffer();
}
$this->AddPage($this->CurOrientation);
$this->SetCol(0);
$this->y0 = $this->tMargin;
$this->ChangeColumn = -($this->NbCol - 1);
// DIRECTIONALITY RTL
if ($this->directionality == 'rtl') {
$this->ChangeColumn = -($this->ChangeColumn);
} // *OTL*
}
$this->x = $this->lMargin;
} else {
$this->AddPage($this->CurOrientation);
}
}
function printcolumnbuffer()
{
// Columns ended (but page not ended) -> try to match all columns -
unless disabled by using a custom column-break
if (!$this->ColActive && $this->ColumnAdjust && !$this->keepColumns) {
// Calculate adjustment to add to each column to calculate rel_y
value
$this->ColDetails[0]['add_y'] = 0;
$last_col = 0;
// Recursively add previous column's height
for ($i = 1; $i < $this->NbCol; $i++) {
if (isset($this->ColDetails[$i]['bottom_margin']) && $this-
>ColDetails[$i]['bottom_margin']) { // If any entries in the column
$this->ColDetails[$i]['add_y'] = ($this-
>ColDetails[$i - 1]['bottom_margin'] - $this->y0) + $this->ColDetails[$i - 1]
['add_y'];
$last_col = $i; // Last column actually printed
}
}
$breaks = array();
foreach ($this->breakpoints AS $c => $bpa) {
foreach ($bpa AS $rely) {
$breaks[] = $rely + $this->ColDetails[$c]['add_y'] -
$this->y0;
}
}
if (isset($this->ColDetails[$last_col]['bottom_margin'])) {
$lcbm = $this->ColDetails[$last_col]['bottom_margin'];
} else {
$lcbm = 0;
}
$sum_h = $this->ColDetails[$last_col]['add_y'] + $lcbm - $this-
>y0;
//$sum_h = max($this->ColDetails[$last_col]['add_y'] + $this-
>ColDetails[$last_col]['bottom_margin'] - $this->y0, end($breaks));
$target_h = ($sum_h / $this->NbCol);
$cbr = array();
for ($i = 1; $i < $this->NbCol; $i++) {
$th = ($sum_h * $i / $this->NbCol);
foreach ($breaks AS $bk => $val) {
if ($val > $th) {
if (($val - $th) < ($th - $breaks[$bk - 1])) {
$cbr[$i - 1] = $val;
} else {
$cbr[$i - 1] = $breaks[$bk - 1];
}
break;
}
}
}
$cbr[($this->NbCol - 1)] = $sum_h;
// mPDF 6
// Avoid outputing with 1st column empty
if (isset($cbr[0]) && $cbr[0] == 0) {
for ($i = 0; $i < $this->NbCol - 1; $i++) {
$cbr[$i] = $cbr[$i + 1];
}
}
// mPDF 5.7+
$t = $this->columnAdjustPregReplace('Td', $xadj,
$yadj, '/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/', $t);
$t = $this->columnAdjustPregReplace('re', $xadj,
$yadj, '/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/', $t);
$t = $this->columnAdjustPregReplace('l', $xadj,
$yadj, '/(\d+\.\d\d+) (\d+\.\d\d+) l/', $t);
$t = $this->columnAdjustPregReplace('img', $xadj,
$yadj, '/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/',
$t);
$t = $this->columnAdjustPregReplace('draw', $xadj,
$yadj, '/(\d+\.\d\d+) (\d+\.\d\d+) m/', $t);
$t = $this->columnAdjustPregReplace('bezier', $xadj,
$yadj, '/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+)
(\d+\.\d\d+) c/', $t);
$this->columnbuffer[$key]['s'] = $t;
$this->columnbuffer[$key]['newcol'] = $newcolumn;
$this->columnbuffer[$key]['newy'] = $s['y'] + $yadj;
$last_new_col = $newcolumn;
$clb = $s['y'] + $yadj + $s['h']; // bottom_margin of
current
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;
}
if ($clb > $lowest_bottom_y) {
$lowest_bottom_y = $clb;
}
// Adjust LINKS
if (isset($this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])];
$this->PageLinks[$this->page][$ref][0] +=
($xadj * _MPDFK);
$this->PageLinks[$this->page][$ref][1] -=
($yadj * _MPDFK);
unset($this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
// Adjust FORM FIELDS
if (isset($this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])];
$this->mpdfform->forms[$ref]['x'] += ($xadj);
$this->mpdfform->forms[$ref]['y'] += ($yadj);
unset($this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
/* -- ANNOTATIONS -- */
if (isset($this->columnAnnots[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this->columnAnnots[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])];
if ($this->PageAnnots[$this->page][$ref]['x'] <
0) {
$this->PageAnnots[$this->page][$ref]['x']
-= ($xadj);
} else {
$this->PageAnnots[$this->page][$ref]['x']
+= ($xadj);
}
$this->PageAnnots[$this->page][$ref]['y'] +=
($yadj); // unlike PageLinks, Page annots has y values from top in mm
unset($this->columnAnnots[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
/* -- END ANNOTATIONS -- */
}
}
/* -- BOOKMARKS -- */
// Adjust Bookmarks
foreach ($this->col_BMoutlines AS $v) {
$this->BMoutlines[] = array('t' => $v['t'], 'l' => $v['l'],
'y' => $this->y0, 'p' => $v['p']);
}
/* -- END BOOKMARKS -- */
/* -- TOC -- */
// Adjust ToC
foreach ($this->col_toc AS $v) {
$this->tocontents->_toc[] = array('t' => $v['t'], 'l' =>
$v['l'], 'p' => $v['p'], 'link' => $v['link'], 'toc_id' => $v['toc_id']);
$this->links[$v['link']][1] = $this->y0;
}
/* -- END TOC -- */
// Adjust LINKS
if (isset($this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this-
>columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
$this->PageLinks[$this->page][$ref]
[1] -= ($yadj * _MPDFK); // y value
$this->PageLinks[$this->page][$ref]
[3] *= $ratio; // height
unset($this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
// Adjust FORM FIELDS
if (isset($this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this-
>columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
$this->mpdfform->forms[$ref]['x']
+= ($xadj);
$this->mpdfform->forms[$ref]['y']
+= ($yadj);
unset($this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
/* -- ANNOTATIONS -- */
if (isset($this->columnAnnots[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this-
>columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
$this->PageAnnots[$this->page]
[$ref]['y'] += ($yadj);
unset($this-
>columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]);
}
/* -- END ANNOTATIONS -- */
}
}
}
foreach ($this->internallink AS $key => $f) {
if (is_array($f) && isset($f['col'])) {
$last_col_bottom = 0;
for ($nbc = 0; $nbc < $this->NbCol; $nbc++) {
if ($f['rel_y'] >= $cbr[$nbc]) {
$last_col_bottom = $cbr[$nbc];
}
}
$yadj = ($f['rel_y'] - $f['Y']) -
$last_col_bottom + $this->y0;
$f['Y'] += $yadj;
unset($f['col']);
unset($f['rel_y']);
$this->internallink[$key] = $f;
}
}
$last_col = -1;
$trans_on = false;
foreach ($this->columnbuffer AS $key => $s) {
if (isset($s['rel_y'])) { // only process position
sensitive data
// Set ratio to expand y values or heights
if (isset($this->ColDetails[$s['newcol']]
['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this-
>ColDetails[$s['newcol']]['max_bottom'] != $this->y0) {
$ratio = ($lowest_bottom_y - ($this->y0))
/ ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
} else {
$ratio = 1;
}
if (($ratio > 1) && ($ratio <= $this-
>max_colH_correction)) {
//Start Transformation
$this->pages[$this->page] .= $this-
>StartTransform(true) . "\n";
$this->pages[$this->page] .= $this-
>transformScale(100, $ratio * 100, $x = '', $this->y0, true) . "\n";
$trans_on = true;
}
}
// Now output the adjusted values
$this->pages[$this->page] .= $s['s'] . "\n";
if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <=
$this->max_colH_correction)) { // only process position sensitive data
//Stop Transformation
$this->pages[$this->page] .= $this-
>StopTransform(true) . "\n";
$trans_on = false;
}
}
if ($trans_on) {
$this->pages[$this->page] .= $this-
>StopTransform(true) . "\n";
}
} else { // if NOT $this->colvAlign == 'J'
// Now output the adjusted values
foreach ($this->columnbuffer AS $s) {
$this->pages[$this->page] .= $s['s'] . "\n";
}
}
if ($lowest_bottom_y > 0) {
$this->y = $lowest_bottom_y;
}
}
// Columns not ended but new page -> align columns (can leave the
columns alone - just tidy up the height)
elseif ($this->colvAlign == 'J' && $this->ColumnAdjust && !$this-
>keepColumns) {
// calculate the lowest bottom margin
$lowest_bottom_y = 0;
foreach ($this->columnbuffer AS $key => $s) {
// Only process output data
$t = $s['s'];
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)) ||
(preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/', $t)) ||
(preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+
(\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/', $t)) ||
(preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/', $t)) ||
(preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+
\d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/', $t))) {
// Adjust LINKS
if (isset($s['rel_y'])) { // only process position
sensitive data
// otherwise triggers for all entries in column
buffer (.e.g. formatting) and makes below adjustments more than once
if (isset($this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])];
$this->PageLinks[$this->page][$ref][1] -=
($yadj * _MPDFK); // y value
$this->PageLinks[$this->page][$ref][3] *=
$ratio; // height
unset($this->columnLinks[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
// Adjust FORM FIELDS
if (isset($this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])];
$this->mpdfform->forms[$ref]['x'] +=
($xadj);
$this->mpdfform->forms[$ref]['y'] +=
($yadj);
unset($this->columnForms[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
/* -- ANNOTATIONS -- */
if (isset($this->columnAnnots[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])])) {
$ref = $this->columnAnnots[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])];
$this->PageAnnots[$this->page][$ref]['y']
+= ($yadj);
unset($this->columnAnnots[$s['col']]
[INTVAL($s['x'])][INTVAL($s['y'])]);
}
/* -- END ANNOTATIONS -- */
}
}
}
/* -- BOOKMARKS -- */
// Adjust Bookmarks
foreach ($this->col_BMoutlines AS $v) {
$this->BMoutlines[] = array('t' => $v['t'], 'l' => $v['l'],
'y' => $this->y0, 'p' => $v['p']);
}
/* -- END BOOKMARKS -- */
/* -- TOC -- */
// Adjust ToC
foreach ($this->col_toc AS $v) {
$this->tocontents->_toc[] = array('t' => $v['t'], 'l' =>
$v['l'], 'p' => $v['p'], 'link' => $v['link'], 'toc_id' => $v['toc_id']);
$this->links[$v['link']][1] = $this->y0;
}
/* -- END TOC -- */
$trans_on = false;
foreach ($this->columnbuffer AS $key => $s) {
if (isset($s['rel_y'])) { // only process position
sensitive data
// Set ratio to expand y values or heights
if ($this->ColDetails[$s['col']]['max_bottom']) {
$ratio = ($lowest_bottom_y - ($this->y0)) /
($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
} else {
$ratio = 1;
}
if (($ratio > 1) && ($ratio <= $this-
>max_colH_correction)) {
//Start Transformation
$this->pages[$this->page] .= $this-
>StartTransform(true) . "\n";
$this->pages[$this->page] .= $this-
>transformScale(100, $ratio * 100, $x = '', $this->y0, true) . "\n";
$trans_on = true;
}
}
// Now output the adjusted values
$this->pages[$this->page] .= $s['s'] . "\n";
if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this-
>max_colH_correction)) {
//Stop Transformation
$this->pages[$this->page] .= $this-
>StopTransform(true) . "\n";
$trans_on = false;
}
}
if ($trans_on) {
$this->pages[$this->page] .= $this->StopTransform(true) .
"\n";
}
if ($lowest_bottom_y > 0) {
$this->y = $lowest_bottom_y;
}
}
$this->columnbuffer = array();
$this->ColDetails = array();
$this->columnLinks = array();
$this->columnAnnots = array();
$this->columnForms = array();
$this->col_BMoutlines = array();
$this->col_toc = array();
$this->breakpoints = array();
}
// mPDF 5.7+
function columnAdjustPregReplace($type, $xadj, $yadj, $pattern, $subject)
{
preg_match($pattern, $subject, $matches);
if (!count($matches)) {
return $subject;
}
if (!isset($matches[3])) {
$matches[3] = 0;
}
if (!isset($matches[4])) {
$matches[4] = 0;
}
if (!isset($matches[5])) {
$matches[5] = 0;
}
if (!isset($matches[6])) {
$matches[6] = 0;
}
return str_replace($matches[0], $this->columnAdjustAdd($type, _MPDFK,
$xadj, $yadj, $matches[1], $matches[2], $matches[3], $matches[4], $matches[5],
$matches[6]), $subject);
}
/* -- END COLUMNS -- */
//==================================================================
/* -- TABLES -- */
function printcellbuffer()
{
if (count($this->cellBorderBuffer)) {
sort($this->cellBorderBuffer);
foreach ($this->cellBorderBuffer AS $cbb) {
$cba =
unpack("A16dom/nbord/A1side/ns/dbw/a6ca/A10style/dx/dy/dw/dh/dmbl/dmbr/dmrt/dmrb/dm
tl/dmtr/dmlt/dmlb/dcpd/dover/", $cbb);
$side = $cba['side'];
$color = str_pad($cba['ca'], 6, "\x00");
$details = array();
$details[$side]['dom'] = (float) $cba['dom'];
$details[$side]['s'] = $cba['s'];
$details[$side]['w'] = $cba['bw'];
$details[$side]['c'] = $color;
$details[$side]['style'] = trim($cba['style']);
$details['mbw']['BL'] = $cba['mbl'];
$details['mbw']['BR'] = $cba['mbr'];
$details['mbw']['RT'] = $cba['mrt'];
$details['mbw']['RB'] = $cba['mrb'];
$details['mbw']['TL'] = $cba['mtl'];
$details['mbw']['TR'] = $cba['mtr'];
$details['mbw']['LT'] = $cba['mlt'];
$details['mbw']['LB'] = $cba['mlb'];
$details['cellposdom'] = $cba['cpd'];
$details['p'] = $side;
if ($cba['over'] == 1) {
$details[$side]['overlay'] = true;
} else {
$details[$side]['overlay'] = false;
}
$this->_tableRect($cba['x'], $cba['y'], $cba['w'],
$cba['h'], $cba['bord'], $details, false, false);
}
$this->cellBorderBuffer = array();
}
}
//==================================================================
function printtablebuffer()
{
if (!$this->table_rotate) {
$this->pages[$this->page] .= $this->tablebuffer;
foreach ($this->tbrot_Links AS $p => $l) {
foreach ($l AS $v) {
$this->PageLinks[$p][] = $v;
}
}
$this->tbrot_Links = array();
/* -- ANNOTATIONS -- */
foreach ($this->tbrot_Annots AS $p => $l) {
foreach ($l AS $v) {
$this->PageAnnots[$p][] = $v;
}
}
$this->tbrot_Annots = array();
/* -- END ANNOTATIONS -- */
/* -- BOOKMARKS -- */
// Output Bookmarks
foreach ($this->tbrot_BMoutlines AS $v) {
$this->BMoutlines[] = array('t' => $v['t'], 'l' => $v['l'],
'y' => $v['y'], 'p' => $v['p']);
}
$this->tbrot_BMoutlines = array();
/* -- END BOOKMARKS -- */
/* -- TOC -- */
// Output ToC
foreach ($this->tbrot_toc AS $v) {
$this->tocontents->_toc[] = array('t' => $v['t'], 'l' =>
$v['l'], 'p' => $v['p'], 'link' => $v['link'], 'toc_id' => $v['toc_id']);
}
$this->tbrot_toc = array();
/* -- END TOC -- */
return;
}
// elseif rotated
$lm = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] +
$this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]
['padding_left'];
$pw = $this->blk[$this->blklvl]['inner_width'];
//Start Transformation
$this->pages[$this->page] .= $this->StartTransform(true) . "\n";
/* -- BOOKMARKS -- */
// Adjust Bookmarks
foreach ($this->tbrot_BMoutlines AS $v) {
$v['y'] = $this->tbrot_y0;
$this->BMoutlines[] = array('t' => $v['t'], 'l' => $v['l'], 'y'
=> $v['y'], 'p' => $this->page);
}
/* -- END BOOKMARKS -- */
/* -- TOC -- */
$this->tbrot_BMoutlines = array();
$this->tbrot_toc = array();
//Stop Transformation
$this->pages[$this->page] .= $this->StopTransform(true) . "\n";
$this->tablebuffer = '';
}
//==================================================================
// Keep-with-table This buffers contents of h1-6 to keep on page with table
function printkwtbuffer()
{
if (!$this->kwt_moved) {
foreach ($this->kwt_buffer AS $s) {
$this->pages[$this->page] .= $s['s'] . "\n";
}
foreach ($this->kwt_Links AS $p => $l) {
foreach ($l AS $v) {
$this->PageLinks[$p][] = $v;
}
}
$this->kwt_Links = array();
/* -- ANNOTATIONS -- */
foreach ($this->kwt_Annots AS $p => $l) {
foreach ($l AS $v) {
$this->PageAnnots[$p][] = $v;
}
}
$this->kwt_Annots = array();
/* -- END ANNOTATIONS -- */
/* -- INDEX -- */
// Output Reference (index)
foreach ($this->kwt_Reference AS $v) {
$Present = 0;
for ($i = 0; $i < count($this->Reference); $i++) {
if ($this->Reference[$i]['t'] == $v['t']) {
$Present = 1;
if (!in_array($v['op'], $this->Reference[$i]
['p'])) {
$this->Reference[$i]['p'][] = $v['op'];
}
}
}
if ($Present == 0) {
$this->Reference[] = array('t' => $v['t'], 'p' =>
array($v['op']));
}
}
$this->kwt_Reference = array();
/* -- END INDEX -- */
/* -- BOOKMARKS -- */
// Output Bookmarks
foreach ($this->kwt_BMoutlines AS $v) {
$this->BMoutlines[] = array('t' => $v['t'], 'l' => $v['l'],
'y' => $v['y'], 'p' => $v['p']);
}
$this->kwt_BMoutlines = array();
/* -- END BOOKMARKS -- */
/* -- TOC -- */
// Output ToC
foreach ($this->kwt_toc AS $v) {
$this->tocontents->_toc[] = array('t' => $v['t'], 'l' =>
$v['l'], 'p' => $v['p'], 'link' => $v['link'], 'toc_id' => $v['toc_id']);
}
$this->kwt_toc = array();
/* -- END TOC -- */
//Start Transformation
$this->pages[$this->page] .= $this->StartTransform(true) . "\n";
$xadj = $this->lMargin - $this->kwt_x0;
//$yadj = $this->y - $this->kwt_y0 ;
$yadj = $this->tMargin - $this->kwt_y0;
// Adjust hyperLinks
foreach ($this->kwt_Links AS $p => $l) {
foreach ($l AS $v) {
$bx = $this->kwt_x0 + $xadj;
$by = $this->kwt_y0 + $yadj;
$v[0] = $bx * _MPDFK;
$v[1] = ($this->h - $by) * _MPDFK;
$this->PageLinks[$p][] = $v;
}
}
foreach ($this->internallink AS $key => $f) {
if (is_array($f) && isset($f['kwt'])) {
$f['Y'] += $yadj;
$f['PAGE'] = $this->page;
unset($f['kwt']);
$this->internallink[$key] = $f;
}
}
/* -- ANNOTATIONS -- */
foreach ($this->kwt_Annots AS $p => $l) {
foreach ($l AS $v) {
$bx = $this->kwt_x0 + $xadj;
$by = $this->kwt_y0 + $yadj;
if ($v['x'] < 0) {
$v['x'] = -$bx;
} else {
$v['x'] = $bx;
}
$v['y'] = $by;
$this->PageAnnots[$p][] = $v;
}
}
/* -- END ANNOTATIONS -- */
/* -- BOOKMARKS -- */
// Adjust Bookmarks
foreach ($this->kwt_BMoutlines AS $v) {
if ($v['y'] != 0) {
$v['y'] += $yadj;
}
$this->BMoutlines[] = array('t' => $v['t'], 'l' => $v['l'], 'y'
=> $v['y'], 'p' => $this->page);
}
/* -- END BOOKMARKS -- */
/* -- INDEX -- */
/* -- TOC -- */
// Adjust ToC
foreach ($this->kwt_toc AS $v) {
$this->tocontents->_toc[] = array('t' => $v['t'], 'l' => $v['l'],
'p' => $this->page, 'link' => $v['link'], 'toc_id' => $v['toc_id']);
$this->links[$v['link']][0] = $this->page;
$this->links[$v['link']][1] += $yadj;
}
/* -- END TOC -- */
$this->kwt_Links = array();
$this->kwt_Annots = array();
$this->kwt_Reference = array();
$this->kwt_BMoutlines = array();
$this->kwt_toc = array();
//Stop Transformation
$this->pages[$this->page] .= $this->StopTransform(true) . "\n";
$this->kwt_buffer = array();
$this->y += $this->kwt_height;
$this->pageoutput[$this->page] = array(); // mPDF 6
}
/* -- END TABLES -- */
//==================================================================
function printfloatbuffer()
{
if (count($this->floatbuffer)) {
$this->objectbuffer = $this->floatbuffer;
$this->printobjectbuffer(false);
$this->objectbuffer = array();
$this->floatbuffer = array();
$this->floatmargins = array();
}
}
//==================================================================
//==================================================================
// Added ELLIPSES and CIRCLES
function Circle($x, $y, $r, $style = 'S')
{
$this->Ellipse($x, $y, $r, $r, $style);
}
/* -- DIRECTW -- */
$text = $this->purify_utf8_text($text);
if ($this->text_input_as_HTML) {
$text = $this->all_entities_to_utf8($text);
}
if ($this->usingCoreFont) {
$text = mb_convert_encoding($text, $this->mb_enc, 'UTF-8');
}
// DIRECTIONALITY
if (preg_match("/([" . $this->pregRTLchars . "])/u", $text)) {
$this->biDirectional = true;
} // *OTL*
$textvar = 0;
$save_OTLtags = $this->OTLtags;
$this->OTLtags = array();
if ($this->useKerning) {
if ($this->CurrentFont['haskernGPOS']) {
$this->OTLtags['Plus'] .= ' kern';
} else {
$textvar = ($textvar | FC_KERNING);
}
}
/* -- OTL -- */
// Use OTL OpenType Table Layout - GSUB & GPOS
if (isset($this->CurrentFont['useOTL']) && $this-
>CurrentFont['useOTL']) {
$text = $this->otl->applyOTL($text, $this-
>CurrentFont['useOTL']);
$OTLdata = $this->otl->OTLdata;
}
/* -- END OTL -- */
$this->OTLtags = $save_OTLtags;
$this->magic_reverse_dir($text, $this->directionality, $OTLdata);
$width = $this->ConvertSize($w);
$loop = 0;
while ($loop == 0) {
$this->SetFont($font, $style, $szfont, false);
$sz = $this->GetStringWidth($text, true, $OTLdata, $textvar);
if ($sz > $w) {
$szfont --;
} else {
$loop ++;
}
}
$this->SetFont($font, $style, $szfont, true, true);
$this->Cell($w, 0, $text, 0, 0, "C", 0, '', 0, 0, 0, 'M', 0, false,
$OTLdata, $textvar);
}
/* -- END DIRECTW -- */
// ====================================================
// ====================================================
$is_strong = false;
if (empty($chunkOTLdata)) {
$this->getBasicOTLdata($chunkOTLdata, $unicode,
$is_strong);
}
return $rtl_content;
}
/* -- END OTL -- */
return 0;
}
/* -- OTL -- */
/* -- END OTL -- */
//
// ****************************
// ****************************
function SetSubstitutions()
{
$subsarray = array();
@include(_MPDF_PATH . 'includes/subs_win-1252.php');
$this->substitute = array();
foreach ($subsarray AS $key => $val) {
$this->substitute[code2utf($key)] = $val;
}
}
function SubstituteChars($html)
{
// only substitute characters between tags
if (count($this->substitute)) {
$a = preg_split('/(<.*?>)/ms', $html, -1,
PREG_SPLIT_DELIM_CAPTURE);
$html = '';
foreach ($a as $i => $e) {
if ($i % 2 == 0) {
$e = strtr($e, $this->substitute);
}
$html .= $e;
}
}
return $html;
}
$prevFontFamily = $this->FontFamily;
$prevFontStyle = $this->currentfontstyle;
$prevFontSizePt = $this->FontSizePt;
$this->SetFont($bsf, '', '', false);
$cw = @file_get_contents(_MPDF_TTFONTDATAPATH . $font .
'.cw.dat');
$this->SetFont($prevFontFamily, $prevFontStyle,
$prevFontSizePt, false);
}
if (!$cw) {
continue;
}
$l = 0;
foreach ($u AS $char) {
if ($char == 173 || $this->_charDefined($cw, $char) ||
($char > 1536 && $char < 1791) || ($char > 2304 && $char < 3455 )) {
$l++;
} else {
if ($l == 0 && $bsfctr == (count($this-
>backupSubsFont) - 1)) { // Not found even in last backup font
$cont = mb_substr($writehtml_e, $start + 1);
$writehtml_e = mb_substr($writehtml_e, 0,
$start + 1, 'UTF-8');
array_splice($writehtml_a, $writehtml_i + 1, 0,
array('', $cont));
$this->subPos = $writehtml_i + 1;
return 2;
} else {
break;
}
}
}
if ($l > 0) {
$patt = mb_substr($writehtml_e, $start, $l, 'UTF-8');
if (preg_match("/(.*?)(" . preg_quote($patt, '/') . ")
(.*)/u", $writehtml_e, $m)) {
$writehtml_e = $m[1];
array_splice($writehtml_a, $writehtml_i + 1, 0,
array('span style="font-family: ' . $font . '"', $m[2], '/span', $m[3]));
$this->subPos = $writehtml_i + 3;
return 4;
}
}
}
unset($cw);
return 0;
}
unset($cw);
return 0;
}
function setHiEntitySubstitutions()
{
$entarr = array(
'nbsp' => '160', 'iexcl' => '161', 'cent' => '162', 'pound' =>
'163', 'curren' => '164', 'yen' => '165', 'brvbar' => '166', 'sect' => '167',
'uml' => '168', 'copy' => '169', 'ordf' => '170', 'laquo' =>
'171', 'not' => '172', 'shy' => '173', 'reg' => '174', 'macr' => '175',
'deg' => '176', 'plusmn' => '177', 'sup2' => '178', 'sup3' =>
'179', 'acute' => '180', 'micro' => '181', 'para' => '182', 'middot' => '183',
'cedil' => '184', 'sup1' => '185', 'ordm' => '186', 'raquo' =>
'187', 'frac14' => '188', 'frac12' => '189', 'frac34' => '190',
'iquest' => '191', 'Agrave' => '192', 'Aacute' => '193', 'Acirc'
=> '194', 'Atilde' => '195', 'Auml' => '196', 'Aring' => '197',
'AElig' => '198', 'Ccedil' => '199', 'Egrave' => '200', 'Eacute'
=> '201', 'Ecirc' => '202', 'Euml' => '203', 'Igrave' => '204',
'Iacute' => '205', 'Icirc' => '206', 'Iuml' => '207', 'ETH' =>
'208', 'Ntilde' => '209', 'Ograve' => '210', 'Oacute' => '211',
'Ocirc' => '212', 'Otilde' => '213', 'Ouml' => '214', 'times' =>
'215', 'Oslash' => '216', 'Ugrave' => '217', 'Uacute' => '218',
'Ucirc' => '219', 'Uuml' => '220', 'Yacute' => '221', 'THORN' =>
'222', 'szlig' => '223', 'agrave' => '224', 'aacute' => '225',
'acirc' => '226', 'atilde' => '227', 'auml' => '228', 'aring' =>
'229', 'aelig' => '230', 'ccedil' => '231', 'egrave' => '232',
'eacute' => '233', 'ecirc' => '234', 'euml' => '235', 'igrave' =>
'236', 'iacute' => '237', 'icirc' => '238', 'iuml' => '239',
'eth' => '240', 'ntilde' => '241', 'ograve' => '242', 'oacute' =>
'243', 'ocirc' => '244', 'otilde' => '245', 'ouml' => '246',
'divide' => '247', 'oslash' => '248', 'ugrave' => '249', 'uacute'
=> '250', 'ucirc' => '251', 'uuml' => '252', 'yacute' => '253',
'thorn' => '254', 'yuml' => '255', 'OElig' => '338', 'oelig' =>
'339', 'Scaron' => '352', 'scaron' => '353', 'Yuml' => '376',
'fnof' => '402', 'circ' => '710', 'tilde' => '732', 'Alpha' =>
'913', 'Beta' => '914', 'Gamma' => '915', 'Delta' => '916',
'Epsilon' => '917', 'Zeta' => '918', 'Eta' => '919', 'Theta' =>
'920', 'Iota' => '921', 'Kappa' => '922', 'Lambda' => '923',
'Mu' => '924', 'Nu' => '925', 'Xi' => '926', 'Omicron' => '927',
'Pi' => '928', 'Rho' => '929', 'Sigma' => '931', 'Tau' => '932',
'Upsilon' => '933', 'Phi' => '934', 'Chi' => '935', 'Psi' =>
'936', 'Omega' => '937', 'alpha' => '945', 'beta' => '946', 'gamma' => '947',
'delta' => '948', 'epsilon' => '949', 'zeta' => '950', 'eta' =>
'951', 'theta' => '952', 'iota' => '953', 'kappa' => '954',
'lambda' => '955', 'mu' => '956', 'nu' => '957', 'xi' => '958',
'omicron' => '959', 'pi' => '960', 'rho' => '961', 'sigmaf' => '962',
'sigma' => '963', 'tau' => '964', 'upsilon' => '965', 'phi' =>
'966', 'chi' => '967', 'psi' => '968', 'omega' => '969',
'thetasym' => '977', 'upsih' => '978', 'piv' => '982', 'ensp' =>
'8194', 'emsp' => '8195', 'thinsp' => '8201', 'zwnj' => '8204',
'zwj' => '8205', 'lrm' => '8206', 'rlm' => '8207', 'ndash' =>
'8211', 'mdash' => '8212', 'lsquo' => '8216', 'rsquo' => '8217',
'sbquo' => '8218', 'ldquo' => '8220', 'rdquo' => '8221', 'bdquo'
=> '8222', 'dagger' => '8224', 'Dagger' => '8225', 'bull' => '8226',
'hellip' => '8230', 'permil' => '8240', 'prime' => '8242',
'Prime' => '8243', 'lsaquo' => '8249', 'rsaquo' => '8250', 'oline' => '8254',
'frasl' => '8260', 'euro' => '8364', 'image' => '8465', 'weierp'
=> '8472', 'real' => '8476', 'trade' => '8482', 'alefsym' => '8501',
'larr' => '8592', 'uarr' => '8593', 'rarr' => '8594', 'darr' =>
'8595', 'harr' => '8596', 'crarr' => '8629', 'lArr' => '8656',
'uArr' => '8657', 'rArr' => '8658', 'dArr' => '8659', 'hArr' =>
'8660', 'forall' => '8704', 'part' => '8706', 'exist' => '8707',
'empty' => '8709', 'nabla' => '8711', 'isin' => '8712', 'notin'
=> '8713', 'ni' => '8715', 'prod' => '8719', 'sum' => '8721',
'minus' => '8722', 'lowast' => '8727', 'radic' => '8730', 'prop'
=> '8733', 'infin' => '8734', 'ang' => '8736', 'and' => '8743',
'or' => '8744', 'cap' => '8745', 'cup' => '8746', 'int' =>
'8747', 'there4' => '8756', 'sim' => '8764', 'cong' => '8773',
'asymp' => '8776', 'ne' => '8800', 'equiv' => '8801', 'le' =>
'8804', 'ge' => '8805', 'sub' => '8834', 'sup' => '8835', 'nsub' => '8836',
'sube' => '8838', 'supe' => '8839', 'oplus' => '8853', 'otimes'
=> '8855', 'perp' => '8869', 'sdot' => '8901', 'lceil' => '8968',
'rceil' => '8969', 'lfloor' => '8970', 'rfloor' => '8971', 'lang'
=> '9001', 'rang' => '9002', 'loz' => '9674', 'spades' => '9824',
'clubs' => '9827', 'hearts' => '9829', 'diams' => '9830',
);
foreach ($entarr AS $key => $val) {
$this->entsearch[] = '&' . $key . ';';
$this->entsubstitute[] = code2utf($val);
}
}
function SubstituteHiEntities($html)
{
// converts html_entities > ASCII 127 to unicode
// Leaves in particular < to distinguish from tag marker
if (count($this->entsearch)) {
$html = str_replace($this->entsearch, $this->entsubstitute,
$html);
}
return $html;
}
function purify_utf8_text($txt)
{
// For TEXT
// Make sure UTF-8 string of characters
if (!$this->is_utf8($txt)) {
throw new MpdfException("Text contains invalid UTF-8
character(s)");
}
return ($txt);
}
function all_entities_to_utf8($txt)
{
// converts txt_entities > ASCII 127 to UTF-8
// Leaves in particular < to distinguish from tag marker
$txt = $this->SubstituteHiEntities($txt);
$txt = $this->lesser_entity_decode($txt);
return ($txt);
}
// ====================================================
/* -- BARCODES -- */
// UPC/EAN barcode
// EAN13, EAN8, UPCA, UPCE, ISBN, ISSN
// Accepts 12 or 13 digits with or without - hyphens
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)
{
if (empty($code)) {
return;
}
$codestr = $code;
$code = preg_replace('/\-/', '', $code);
if (!class_exists('PDFBarcode', false)) {
include(_MPDF_PATH . 'classes/barcode.php');
}
$this->barcode = new PDFBarcode();
if ($btype == 'ISSN' || $btype == 'ISBN') {
$arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
} else {
$arrcode = $this->barcode->getBarcodeArray($code, $btype);
}
if (empty($x)) {
$x = $this->x;
}
if (empty($y)) {
$y = $this->y;
}
// set foreground color
$prevDrawColor = $this->DrawColor;
$prevTextColor = $this->TextColor;
$prevFillColor = $this->FillColor;
$lw = $this->LineWidth;
$this->SetLineWidth(0.01);
$fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
$ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-
defined padding
$fbwi = $fbw - 2; // Full barcode width incl. light margins - 2mm - for
isbn string
// cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it
right.pdf
$num_height = 3 * $size; // Height of numerals
$fbh = $arrcode['nom-H'] * $size * $height; // Full barcode height
incl. numerals
$bch = $fbh - (1.5 * $size); // Barcode height of bars (3mm for
numerals)
// PRINT BARS
$xpos = $x + $paddingL + $llm;
$ypos = $y + $paddingT;
if ($col) {
$this->SetFColor($col);
} else {
$this->SetFColor($this->ConvertColor(0));
}
if ($arrcode !== false) {
foreach ($arrcode["bcode"] AS $v) {
$bw = ($v["w"] * $xres);
if ($v["t"]) {
// draw a vertical bar
$this->Rect($xpos, $ypos, $bw, $bch, 'F');
}
$xpos += $bw;
}
}
// print text
$prevFontFamily = $this->FontFamily;
$prevFontStyle = $this->FontStyle;
$prevFontSizePt = $this->FontSizePt;
// ISBN string
if (($btype == 'EAN13' && $showtext) || $btype == 'ISBN' || $btype ==
'ISSN') {
if ($this->onlyCoreFonts) {
$this->SetFont('chelvetica');
} else {
$this->SetFont('sans');
}
if ($bgcol) {
$this->SetFColor($bgcol);
} else {
$this->SetFColor($this->ConvertColor(255));
}
$this->x = $x + $paddingL + 1; // 1mm left margin (cf. $fbwi
above)
// max width is $fbwi
$loop = 0;
while ($loop == 0) {
$this->SetFontSize($codestr_fontsize * 1.4 * _MPDFK,
false); // don't write
$sz = $this->GetStringWidth($codestr);
if ($sz > $fbwi)
$codestr_fontsize -= 0.1;
else
$loop ++;
}
$this->SetFont('', '', $codestr_fontsize * 1.4 * _MPDFK, true,
true); // * 1.4 because font height is only 7/10 of given mm
// WORD SPACING
if ($fbwi > $sz) {
$xtra = $fbwi - $sz;
$charspacing = $xtra / (strlen($codestr) - 1);
if ($charspacing) {
$this->_out(sprintf('BT %.3F Tc ET', $charspacing *
_MPDFK));
}
}
$this->y = $y + $paddingT - ($codestr_fontsize ) - $tisbnm;
$this->Cell($fbw, $codestr_fontsize, $codestr);
if ($charspacing) {
$this->_out('BT 0 Tc ET');
}
}
// Bottom NUMERALS
// mPDF 5.7.4
if ($this->onlyCoreFonts) {
$this->SetFont('ccourier');
$fh = 1.3;
} else {
$this->SetFont('ocrb');
$fh = 1.06;
}
$charRO = '';
if ($btype == 'EAN13' || $btype == 'ISBN' || $btype == 'ISSN') {
$outerfontsize = 3; // Inner fontsize = 3
$outerp = $xres * 4;
$innerp = $xres * 2.5;
$textw = ($bcw * 0.5) - $outerp - $innerp;
$chars = 6; // number of numerals in each half
$charLO = substr($code, 0, 1); // Left Outer
$charLI = substr($code, 1, 6); // Left Inner
$charRI = substr($code, 7, 6); // Right Inner
if (!$supplement)
$charRO = '>'; // Right Outer
}
elseif ($btype == 'UPCA') {
$outerfontsize = 2.3; // Inner fontsize = 3
$outerp = $xres * 10;
$innerp = $xres * 2.5;
$textw = ($bcw * 0.5) - $outerp - $innerp;
$chars = 5;
$charLO = substr($code, 0, 1); // Left Outer
$charLI = substr($code, 1, 5); // Left Inner
$charRI = substr($code, 6, 5); // Right Inner
$charRO = substr($code, 11, 1); // Right Outer
} elseif ($btype == 'UPCE') {
$outerfontsize = 2.3; // Inner fontsize = 3
$outerp = $xres * 4;
$innerp = 0;
$textw = ($bcw * 0.5) - $outerp - $innerp;
$chars = 3;
$upce_code = $arrcode['code'];
$charLO = substr($code, 0, 1); // Left Outer
$charLI = substr($upce_code, 0, 3); // Left Inner
$charRI = substr($upce_code, 3, 3); // Right Inner
$charRO = substr($code, 11, 1); // Right Outer
} elseif ($btype == 'EAN8') {
$outerfontsize = 3; // Inner fontsize = 3
$outerp = $xres * 4;
$innerp = $xres * 2.5;
$textw = ($bcw * 0.5) - $outerp - $innerp;
$chars = 4;
$charLO = '<'; // Left Outer
$charLI = substr($code, 0, 4); // Left Inner
$charRI = substr($code, 4, 4); // Right Inner
if (!$supplement)
$charRO = '>'; // Right Outer
}
$this->SetFontSize(($outerfontsize / 3) * 3 * $fh * $size * _MPDFK); //
3mm numerals (FontSize is larger to account for space above/below characters)
if (!$this->usingCoreFont) {
$cw = $this->_getCharWidth($this->CurrentFont['cw'], 32) * 3 *
$fh * $size / 1000;
} // character width at 3mm
else {
$cw = 600 * 3 * $fh * $size / 1000;
} // mPDF 5.7.4
// Outer left character
$y_text = $y + $paddingT + $bch - ($num_height / 2);
$y_text_outer = $y + $paddingT + $bch - ($num_height *
($outerfontsize / 3) / 2);
if ($bgcol) {
$this->SetFColor($bgcol);
} else {
$this->SetFColor($this->ConvertColor(255));
}
if ($charspacing) {
$this->_out('BT 0 Tc ET');
}
// Characters
if ($bgcol) {
$this->SetFColor($bgcol);
} else {
$this->SetFColor($this->ConvertColor(255));
}
$this->SetFontSize(3 * $fh * $size * _MPDFK); // 3mm numerals
(FontSize is larger to account for space above/below characters)
$this->x = $x + $paddingL + $llm;
$this->y = $y + $paddingT;
$this->Cell($bcw, $num_height, $supplement_code, 0, 0, 'C');
// Restore **************
$this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
$this->DrawColor = $prevDrawColor;
$this->TextColor = $prevTextColor;
$this->FillColor = $prevFillColor;
$this->SetLineWidth($lw);
$this->SetY($y);
}
// ====================================================
// POSTAL and OTHER barcodes
function WriteBarcode2($code, $x = '', $y = '', $size = 1, $height = 1,
$bgcol = false, $col = false, $btype = 'IMB', $print_ratio = '', $k = 1)
{
if (empty($code)) {
return;
}
if (!class_exists('PDFBarcode', false)) {
include(_MPDF_PATH . 'classes/barcode.php');
}
$this->barcode = new PDFBarcode();
$arrcode = $this->barcode->getBarcodeArray($code, $btype,
$print_ratio);
// PRINT BARS
if ($col) {
$this->SetFColor($col);
} else {
$this->SetFColor($this->ConvertColor(0));
}
$xpos = $x + $llm;
/* -- END BARCODES -- */
// ====================================================
// ====================================================
// AUTOFONT =========================
function markScriptToLang($html)
{
if ($this->onlyCoreFonts) {
return $html;
}
// sets $this->script2lang
if (empty($this->script2lang)) {
include(_MPDF_PATH . 'config_script2lang.php');
}
$n = '';
$a = preg_split('/<(.*?)>/ms', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($a as $i => $e) {
if ($i % 2 == 0) {
//ignore if in Textarea
if ($i > 0 && strtolower(substr($a[$i - 1], 1, 8)) ==
'textarea') {
$a[$i] = $e;
continue;
}
$e = strcode2utf($e);
$e = $this->lesser_entity_decode($e);
$scriptblock = 0;
$scriptblocks = array();
$scriptblocks[0] = 0;
$chardata = array();
$subchunk = 0;
$charctr = 0;
foreach ($earr as $char) {
$ucd_record = UCDN::get_ucd_record($char);
$sbl = $ucd_record[6];
$chardata[$subchunk][$charctr]['script'] = $sbl;
$chardata[$subchunk][$charctr]['uni'] = $char;
$charctr++;
}
$o = '';
for ($sch = 0; $sch <= $subchunk; $sch++) {
if (isset($chardata[$sch])) {
$s = '';
for ($j = 0; $j < count($chardata[$sch]); $j++)
{
$s.=code2utf($chardata[$sch][$j]['uni']);
}
// ZZZ99 Undo lesser_entity_decode as above -
but only for <>&
$s = str_replace("&", "&", $s);
$s = str_replace("<", "<", $s);
$s = str_replace(">", ">", $s);
// Check Vietnamese if Latin script - even if
Basescript
if ($scriptblocks[$sch] == UCDN::SCRIPT_LATIN
&& $this->autoVietnamese && preg_match("/([" . $this->viet . "])/u", $s)) {
$o .= '<span lang="vi"
class="lang_vi">' . $s . '</span>';
}
// Check Arabic for different languages if
Arabic script - even if Basescript
elseif ($scriptblocks[$sch] ==
UCDN::SCRIPT_ARABIC && $this->autoArabic) {
if (preg_match("/[" . $this->sindhi .
"]/u", $s)) {
$o .= '<span lang="sd"
class="lang_sd">' . $s . '</span>';
} elseif (preg_match("/[" . $this->urdu .
"]/u", $s)) {
$o .= '<span lang="ur"
class="lang_ur">' . $s . '</span>';
} elseif (preg_match("/[" . $this->pashto
. "]/u", $s)) {
$o .= '<span lang="ps"
class="lang_ps">' . $s . '</span>';
} elseif (preg_match("/[" . $this-
>persian . "]/u", $s)) {
$o .= '<span lang="fa"
class="lang_fa">' . $s . '</span>';
} elseif ($this->baseScript !=
UCDN::SCRIPT_ARABIC && isset($this->script2lang[$scriptblocks[$sch]])) {
$o .= '<span lang="' . $this-
>script2lang[$scriptblocks[$sch]] . '" class="lang_' . $this-
>script2lang[$scriptblocks[$sch]] . '">' . $s . '</span>';
} else {
// Just output chars
$o .= $s;
}
}
// Identify Script block if not Basescript, and
mark up as language
elseif ($scriptblocks[$sch] > 0 &&
$scriptblocks[$sch] != $this->baseScript && isset($this-
>script2lang[$scriptblocks[$sch]])) {
// Encase in <span>
$o .= '<span lang="' . $this-
>script2lang[$scriptblocks[$sch]] . '" class="lang_' . $this-
>script2lang[$scriptblocks[$sch]] . '">';
$o .= $s;
$o .= '</span>';
} else {
// Just output chars
$o .= $s;
}
}
}
$a[$i] = $o;
} else {
$a[$i] = '<' . $e . '>';
}
}
$n = implode('', $a);
return $n;
}
//===========================
// Functions
// Call-back function Used for usort in fn _tableWrite
/* -- COLUMNS -- */
/* -- END COLUMNS -- */
$color = trim(strtolower($color));
$c = false;
$cstr = '';
if ($color == 'transparent') {
return false;
} elseif ($color == 'inherit') {
return false;
} elseif (isset($this->SVGcolors[$color]))
$color = $this->SVGcolors[$color];
if (!isset($cache[$color])) {
if (preg_match('/^[\d]+$/', $color)) {
$c = (array(1, $color));
} // i.e. integer only
elseif ($color[0] == '#') { //case of #nnnnnn or #nnn
$cor = preg_replace('/\s+.*/', '', $color); // in case of
Background: #CCC url() x-repeat etc.
if (strlen($cor) == 4) { // Turn #RGB into #RRGGBB
$cor = "#" . $cor[1] . $cor[1] . $cor[2] . $cor[2] .
$cor[3] . $cor[3];
}
$r = hexdec(substr($cor, 1, 2));
$g = hexdec(substr($cor, 3, 2));
$b = hexdec(substr($cor, 5, 2));
$c = array(3, $r, $g, $b);
} elseif (preg_match('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|
cmyk|hsla|hsl|spot)\((.*?)\)/', $color, $m)) {
$type = $m[1];
$cores = explode(",", $m[2]);
$ncores = count($cores);
if (stristr($cores[0], '%')) {
$cores[0] += 0;
if ($type == 'rgb' || $type == 'rgba') {
$cores[0] = intval($cores[0] * 255 / 100);
}
}
if ($ncores > 1 && stristr($cores[1], '%')) {
$cores[1] += 0;
if ($type == 'rgb' || $type == 'rgba') {
$cores[1] = intval($cores[1] * 255 / 100);
}
if ($type == 'hsl' || $type == 'hsla') {
$cores[1] = $cores[1] / 100;
}
}
if ($ncores > 2 && stristr($cores[2], '%')) {
$cores[2] += 0;
if ($type == 'rgb' || $type == 'rgba') {
$cores[2] = intval($cores[2] * 255 / 100);
}
if ($type == 'hsl' || $type == 'hsla') {
$cores[2] = $cores[2] / 100;
}
}
if ($ncores > 3 && stristr($cores[3], '%')) {
$cores[3] += 0;
}
if ($type == 'rgb') {
$c = array(3, $cores[0], $cores[1], $cores[2]);
} elseif ($type == 'rgba') {
$c = array(5, $cores[0], $cores[1], $cores[2],
$cores[3] * 100);
} elseif ($type == 'cmyk' || $type == 'device-cmyk') {
$c = array(4, $cores[0], $cores[1], $cores[2],
$cores[3]);
} elseif ($type == 'cmyka' || $type == 'device-cmyka') {
$c = array(6, $cores[0], $cores[1], $cores[2],
$cores[3], $cores[4] * 100);
} elseif ($type == 'hsl' || $type == 'hsla') {
$conv = $this->hsl2rgb($cores[0] / 360, $cores[1],
$cores[2]);
if ($type == 'hsl') {
$c = array(3, $conv[0], $conv[1], $conv[2]);
} elseif ($type == 'hsla') {
$c = array(5, $conv[0], $conv[1], $conv[2],
$cores[3] * 100);
}
} elseif ($type == 'spot') {
$name = strtoupper(trim($cores[0]));
if (!isset($this->spotColors[$name])) {
if (isset($cores[5])) {
$this->AddSpotColor($cores[0], $cores[2],
$cores[3], $cores[4], $cores[5]);
} else {
throw new MpdfException('Undefined spot
color: ' . $name);
}
}
$c = array(2, $this->spotColors[$name]['i'],
$cores[1]);
}
}
//
$this->restrictColorSpace
//
1 - allow GRAYSCALE only [convert CMYK/RGB->gray]
//
2 - allow RGB / SPOT COLOR / Grayscale [convert CMYK->RGB]
//
3 - allow CMYK / SPOT COLOR / Grayscale [convert RGB->CMYK]
if
($this->PDFA || $this->PDFX || $this->restrictColorSpace) {
if ($c[0] == 1) { // GRAYSCALE
} elseif ($c[0] == 2) { // SPOT COLOR
if (!isset($this->spotColorIDs[$c[1]])) {
throw new MpdfException('Error: Spot colour has
not been defined - ' . $this->spotColorIDs[$c[1]]);
}
if ($this->PDFA) {
if ($this->PDFA && !$this->PDFAauto) {
$this->PDFAXwarnings[] = "Spot color
specified '" . $this->spotColorIDs[$c[1]] . "' (converted to process color)";
}
if ($this->restrictColorSpace != 3) {
$sp = $this->spotColors[$this-
>spotColorIDs[$c[1]]];
$c = $this->cmyk2rgb(array(4, $sp['c'],
$sp['m'], $sp['y'], $sp['k']));
}
} elseif ($this->restrictColorSpace == 1) {
$sp = $this->spotColors[$this-
>spotColorIDs[$c[1]]];
$c = $this->cmyk2gray(array(4, $sp['c'],
$sp['m'], $sp['y'], $sp['k']));
}
}
// RGB
elseif ($c[0] == 3) {
if ($this->PDFX || ($this->PDFA && $this-
>restrictColorSpace == 3)) {
if (($this->PDFA && !$this->PDFAauto) ||
($this->PDFX && !$this->PDFXauto)) {
$this->PDFAXwarnings[] = "RGB color
specified '" . $color . "' (converted to CMYK)";
}
$c = $this->rgb2cmyk($c);
} elseif ($this->restrictColorSpace == 1) {
$c = $this->rgb2gray($c);
} elseif ($this->restrictColorSpace == 3) {
$c = $this->rgb2cmyk($c);
}
}
// CMYK
elseif ($c[0] == 4) {
if ($this->PDFA && $this->restrictColorSpace != 3) {
if ($this->PDFA && !$this->PDFAauto) {
$this->PDFAXwarnings[] = "CMYK color
specified '" . $color . "' (converted to RGB)";
}
$c = $this->cmyk2rgb($c);
} elseif ($this->restrictColorSpace == 1) {
$c = $this->cmyk2gray($c);
} elseif ($this->restrictColorSpace == 2) {
$c = $this->cmyk2rgb($c);
}
}
// RGBa
elseif ($c[0] == 5) {
if ($this->PDFX || ($this->PDFA && $this-
>restrictColorSpace == 3)) {
if (($this->PDFA && !$this->PDFAauto) ||
($this->PDFX && !$this->PDFXauto)) {
$this->PDFAXwarnings[] = "RGB color with
transparency specified '" . $color . "' (converted to CMYK without transparency)";
}
$c = $this->rgb2cmyk($c);
$c = array(4, $c[1], $c[2], $c[3], $c[4]);
} elseif ($this->PDFA && $this->restrictColorSpace !=
3) {
if (!$this->PDFAauto) {
$this->PDFAXwarnings[] = "RGB color with
transparency specified '" . $color . "' (converted to RGB without transparency)";
}
$c = $this->rgb2cmyk($c);
$c = array(4, $c[1], $c[2], $c[3], $c[4]);
} elseif ($this->restrictColorSpace == 1) {
$c = $this->rgb2gray($c);
} elseif ($this->restrictColorSpace == 3) {
$c = $this->rgb2cmyk($c);
}
}
// CMYKa
elseif ($c[0] == 6) {
if ($this->PDFA && $this->restrictColorSpace != 3) {
if (($this->PDFA && !$this->PDFAauto) ||
($this->PDFX && !$this->PDFXauto)) {
$this->PDFAXwarnings[] = "CMYK color with
transparency specified '" . $color . "' (converted to RGB without transparency)";
}
$c = $this->cmyk2rgb($c);
$c = array(3, $c[1], $c[2], $c[3]);
} elseif ($this->PDFX || ($this->PDFA && $this-
>restrictColorSpace == 3)) {
if (($this->PDFA && !$this->PDFAauto) ||
($this->PDFX && !$this->PDFXauto)) {
$this->PDFAXwarnings[] = "CMYK color with
transparency specified '" . $color . "' (converted to CMYK without transparency)";
}
$c = $this->cmyk2rgb($c);
$c = array(3, $c[1], $c[2], $c[3]);
} elseif ($this->restrictColorSpace == 1) {
$c = $this->cmyk2gray($c);
} elseif ($this->restrictColorSpace == 2) {
$c = $this->cmyk2rgb($c);
}
}
}
if (is_array($c)) {
$c = array_pad($c, 6, 0);
$cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] &
0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF));
}
$cache[$color] = $cstr;
}
return $cache[$color];
}
function rgb2gray($c)
{
if (isset($c[4])) {
return array(1, (($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07)),
ord(1), $c[4]);
} else {
return array(1, (($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07)));
}
}
function cmyk2gray($c)
{
$rgb = $this->cmyk2rgb($c);
return $this->rgb2gray($rgb);
}
function rgb2cmyk($c)
{
$cyan = 1 - ($c[1] / 255);
$magenta = 1 - ($c[2] / 255);
$yellow = 1 - ($c[3] / 255);
$min = min($cyan, $magenta, $yellow);
if ($min == 1) {
if ($c[0] == 5) {
return array(6, 100, 100, 100, 100, $c[4]);
} else {
return array(4, 100, 100, 100, 100);
}
// For K-Black
//if ($c[0]==5) { return array (6,0,0,0,100, $c[4]); }
//else { return array (4,0,0,0,100); }
}
$K = $min;
$black = 1 - $K;
if ($c[0] == 5) {
return array(6, ($cyan - $K) * 100 / $black, ($magenta - $K) *
100 / $black, ($yellow - $K) * 100 / $black, $K * 100, $c[4]);
} else {
return array(4, ($cyan - $K) * 100 / $black, ($magenta - $K) *
100 / $black, ($yellow - $K) * 100 / $black, $K * 100);
}
}
function cmyk2rgb($c)
{
$rgb = array();
$colors = 255 - ($c[4] * 2.55);
$rgb[0] = intval($colors * (255 - ($c[1] * 2.55)) / 255);
$rgb[1] = intval($colors * (255 - ($c[2] * 2.55)) / 255);
$rgb[2] = intval($colors * (255 - ($c[3] * 2.55)) / 255);
if ($c[0] == 6) {
return array(5, $rgb[0], $rgb[1], $rgb[2], $c[5]);
} else {
return array(3, $rgb[0], $rgb[1], $rgb[2]);
}
}
function _invertColor($cor)
{
if ($cor[0] == 3 || $cor[0] == 5) { // RGB
return array(3, (255 - $cor[1]), (255 - $cor[2]), (255 -
$cor[3]));
} elseif ($cor[0] == 4 || $cor[0] == 6) { // CMYK
return array(4, (100 - $cor[1]), (100 - $cor[2]), (100 -
$cor[3]), (100 - $cor[4]));
} elseif ($cor[0] == 1) { // Grayscale
return array(1, (255 - $cor[1]));
}
// Cannot cope with non-RGB colors at present
throw new MpdfException('Error in _invertColor - trying to invert non-
RGB color');
}
function _colAtoString($cor)
{
$s = '';
if ($cor{0} == 1)
$s = 'rgb(' . ord($cor{1}) . ',' . ord($cor{1}) . ',' .
ord($cor{1}) . ')';
elseif ($cor{0} == 2)
$s = 'spot(' . ord($cor{1}) . ',' . ord($cor{2}) . ')'; // SPOT
COLOR
elseif ($cor{0} == 3)
$s = 'rgb(' . ord($cor{1}) . ',' . ord($cor{2}) . ',' .
ord($cor{3}) . ')';
elseif ($cor{0} == 4)
$s = 'cmyk(' . ord($cor{1}) . ',' . ord($cor{2}) . ',' .
ord($cor{3}) . ',' . ord($cor{4}) . ')';
elseif ($cor{0} == 5)
$s = 'rgba(' . ord($cor{1}) . ',' . ord($cor{2}) . ',' .
ord($cor{3}) . ',' . sprintf('%0.2F', ord($cor{4}) / 100) . ')';
elseif ($cor{0} == 6)
$s = 'cmyka(' . ord($cor{1}) . ',' . ord($cor{2}) . ',' .
ord($cor{3}) . ',' . ord($cor{4}) . ',' . sprintf('%0.2F', ord($cor{5}) / 100) .
')';
return $s;
}
// @CM 2016-12-11
// Strip the number from the $size for the calculation
$number = preg_replace("/[^0-9\.]/", "", $size);
//dumpr($number);
if ($size == 'thin') {
$number = 1 * (25.4 / $this->dpi); //1 pixel width for table
borders
} elseif (stristr($size, 'px')) {
$number *= (25.4 / $this->dpi); //pixels
} elseif (stristr($size, 'cm')) {
$number *= 10; //centimeters
} elseif (stristr($size, 'mm')) {
$number += 0; //millimeters
} elseif (stristr($size, 'pt')) {
$number *= 25.4 / 72; //72 pts/inch
} elseif (stristr($size, 'rem')) {
//$number += 0; //make "0.83rem" become simply "0.83"
$number *= ($this->default_font_size / _MPDFK);
} elseif (stristr($size, 'em')) {
//$number += 0; //make "0.83em" become simply "0.83"
if ($fontsize) {
$number *= $fontsize;
} else {
$number *= $maxsize;
}
} elseif (stristr($size, '%')) {
//$number += 0; //make "90%" become simply "90"
if ($fontsize && $usefontsize) {
$number *= $fontsize / 100;
} else {
$number *= $maxsize / 100;
}
} elseif (stristr($size, 'in')) {
$number *= 25.4; //inches
} elseif (stristr($size, 'pc')) {
$number *= 38.1 / 9; //PostScript picas
} elseif (stristr($size, 'ex')) { // Approximates "ex" as half of
font height
//$number += 0; //make "3.5ex" become simply "3.5"
if ($fontsize) {
$number *= $maxsize / 2;
}
} elseif ($size == 'medium') {
$number = 3 * (25.4 / $this->dpi); //3 pixel width for table
borders
} elseif ($size == 'thick') {
$number = 5 * (25.4 / $this->dpi); //5 pixel width for table
borders
} elseif ($size == 'xx-small') {
if ($fontsize) {
$number *= $fontsize * 0.7;
} else {
$number *= $maxsize * 0.7;
}
} elseif ($size == 'x-small') {
if ($fontsize) {
$number *= $fontsize * 0.77;
} else {
$number *= $maxsize * 0.77;
}
} elseif ($size == 'small') {
if ($fontsize) {
$number *= $fontsize * 0.86;
} else {
$number *= $maxsize * 0.86;
}
} elseif ($size == 'medium') {
if ($fontsize) {
$number *= $fontsize;
} else {
$number *= $maxsize;
}
} elseif ($size == 'large') {
if ($fontsize) {
$number *= $fontsize * 1.2;
} else {
$number *= $maxsize * 1.2;
}
} elseif ($size == 'x-large') {
if ($fontsize) {
$number *= $fontsize * 1.5;
} else {
$number *= $maxsize * 1.5;
}
} elseif ($size == 'xx-large') {
if ($fontsize) {
$number *= $fontsize * 2;
} else {
$number *= $maxsize * 2;
}
} else {
$number *= (25.4 / $this->dpi); //nothing == px
}
return $number;
}
function lesser_entity_decode($html)
{
//supports the most used entity codes (only does ascii safe characters)
$html = str_replace("<", "<", $html);
$html = str_replace(">", ">", $html);
/* -- ANNOTATIONS -- */
preg_match_all("/(<annotation.*?>)/si", $html, $m);
if (count($m[1])) {
for ($i = 0; $i < count($m[1]); $i++) {
$sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]);
$html = preg_replace('/' . preg_quote($m[1][$i], '/') .
'/si', $sub, $html);
}
}
/* -- END ANNOTATIONS -- */
//Remove javascript code from HTML (should not appear in the PDF file)
$html = preg_replace('/<script.*?<\/script>/is', '', $html);
//Remove comments from HTML (should not appear in the PDF file)
$html = preg_replace('/<!--.*?-->/s', '', $html);
$iterator = 0;
while ($thereispre) { //Recover <pre attributes>content</pre>
$temp[2][$iterator] = preg_replace('/<([^!\/a-zA-Z_:])/',
'<\\1', $temp[2][$iterator]); // mPDF 5.7.2 // mPDF 5.7.3
$temp[2][$iterator] = preg_replace_callback("/^([^\n\t]*?)\t/m",
array($this, 'tabs2spaces_callback'), $temp[2][$iterator]); // mPDF 5.7+
$temp[2][$iterator] = preg_replace('/\t/', str_repeat(" ",
$tabSpaces), $temp[2][$iterator]);
$html = preg_replace('/<textarea([^>]*)><\/textarea>/si',
'<textarea\\1> </textarea>', $html);
$html = preg_replace('/(<table[^>]*>)\s*(<caption)(.*?<\/caption>)(.*?
<\/table>)/si', '\\2 position="top"\\3\\1\\4\\2 position="bottom"\\3', $html); //
*TABLES*
$html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?
<\/\\1>\s*<table)/si', '<\\1\\2 keep-with-table="1"\\3', $html); // *TABLES*
$html = preg_replace("/\xbb\xa4\xac/", "\n", $html);
// mPDF 5.7+
function tabs2spaces_callback($matches)
{
return (stripslashes($matches[1]) . str_repeat(' ', $this->tabSpaces -
(mb_strlen(stripslashes($matches[1])) % $this->tabSpaces)));
}
// mPDF 5.7+
function date_callback($matches)
{
return date($matches[1]);
}
function dec2cjk($num)
{
$nstr = (string) $num;
$rnum = '';
$glyphs = array(0x3007, 0x4E00, 0x4E8C, 0x4E09, 0x56DB, 0x4E94, 0x516D,
0x4E03, 0x516B, 0x4E5D);
for ($i = 0; $i < strlen($nstr); $i++) {
$rnum .= code2utf($glyphs[intval($nstr[$i])]);
}
return $rnum;
}
// mPDF 6
function dec2hebrew($in, $reverse = false)
{
// reverse is used when called from Lists, as these do not pass through
bidi-algorithm
$i = intval($in); // I initially be the counter value
$s = ''; // S initially be the empty string
//and glyph list initially be the list of additive tuples.
$additive_nums = array(400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30,
20, 19, 18, 17, 16, 15, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
$additive_glyphs = array(0x05EA, 0x05E9, 0x05E8, 0x05E7, 0x05E6,
0x05E4, 0x05E2, 0x05E1, 0x05E0, 0x05DE, 0x05DC, 0x05DB,
array(0x05D9, 0x05D8), array(0x05D9, 0x05D7), array(0x05D9,
0x05D6), array(0x05D8, 0x05D6), array(0x05D8, 0x05D5), 0x05D9,
0x05D8, 0x05D7, 0x05D6, 0x05D5, 0x05D4, 0x05D3, 0x05D2, 0x05D1,
0x05D0);
/* NB This system manually specifies the values for 19-15 to force the
correct display of 15 and 16, which are commonly
rewritten to avoid a close resemblance to the Tetragrammaton. */
// This function only works up to 1,000
if ($i > 999) {
return $in;
} // return as initial numeric string
// If I is initially 0, and there is an additive tuple with a weight of
0, append that tuple's counter glyph to S and return S.
if ($i == 0) {
return '0';
}
// Pop the first additive tuple from the glyph list. This is the
current tuple.
$ct = $additive_nums[$t];
// Append the current tuple's counter glyph to S x floor( I /
current tuple's weight ) times (this may be 0).
$n = floor($i / $ct);
for ($j = 0; $j < $n; $j++) {
if (is_array($additive_glyphs[$t])) {
foreach ($additive_glyphs[$t] AS $ag) {
if ($reverse) {
$s = code2utf($ag) . $s;
} else {
$s .= code2utf($ag);
}
}
} else {
if ($reverse) {
$s = code2utf($additive_glyphs[$t]) . $s;
} else {
$s .= code2utf($additive_glyphs[$t]);
}
}
$i -= ($ct * $n);
}
if ($i == 0) {
return $s;
}
}
return $in; // return as initial string
}
//===========================
/* -- IMPORTS -- */
function SetImportUse()
{
if (!class_exists('fpdi_pdf_parser')) {
throw new MpdfException('Class fpdi_pdf_parser not found. Please
run composer update or require setasign/fpdi 1.6.* manually');
}
$this->enableImports = true;
}
// from mPDFI
function hex2str($hex)
{
return pack("H*", str_replace(array("\r", "\n", " "), "", $hex));
}
function str2hex($str)
{
return current(unpack("H*", $str));
}
function pdf_write_value(&$value)
{
switch ($value[0]) {
case pdf_parser::TYPE_TOKEN:
$this->_out($value[1] . ' ', false);
break;
case pdf_parser::TYPE_NUMERIC:
case pdf_parser::TYPE_REAL:
if (is_float($value[1]) && $value[1] != 0) {
$this->_out(rtrim(rtrim(sprintf('%F', $value[1]), '0'),
'.') . ' ', false);
} else {
$this->_out($value[1] . ' ', false);
}
break;
case pdf_parser::TYPE_ARRAY :
// An array. Output the proper
// structure and move on.
$this->_out("[", false);
for ($i = 0; $i < count($value[1]); $i++) {
$this->pdf_write_value($value[1][$i]);
}
$this->_out("]");
break;
case pdf_parser::TYPE_DICTIONARY :
// A dictionary.
$this->_out("<<", false);
reset($value[1]);
while (list($k, $v) = each($value[1])) {
$this->_out($k . ' ',false);
$this->pdf_write_value($v);
}
$this->_out(">>");
break;
case pdf_parser::TYPE_OBJREF :
// An indirect object reference
// Fill the object stack if needed
$cpfn = $this->current_parser->filename;
if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
$this->_newobj(false, true);
$this->_obj_stack[$cpfn][$value[1]] = array($this->n,
$value);
$this->_don_obj_stack[$cpfn][$value[1]] =
array($this->n, $value);
}
$objid = $this->_don_obj_stack[$cpfn][$value[1]][0];
$this->_out("{$objid} 0 R"); //{$value[2]}
break;
case pdf_parser::TYPE_STRING :
if ($this->encrypted) {
$value[1] = $this->_RC4($this->_objectkey($this-
>_current_obj_id), $value[1]);
$value[1] = $this->_escape($value[1]);
}
// A string.
$this->_out('(' . $value[1] . ')');
break;
case pdf_parser::TYPE_STREAM :
// A stream. First, output the
// stream dictionary, then the
// stream data itself.
$this->pdf_write_value($value[1]);
if ($this->encrypted) {
$value[2][1] = $this->_RC4($this->_objectkey($this-
>_current_obj_id), $value[2][1]);
}
$this->_out("stream");
$this->_out($value[2][1]);
$this->_out("endstream");
break;
case pdf_parser::TYPE_HEX :
if ($this->encrypted) {
$value[1] = $this->hex2str($value[1]);
$value[1] = $this->_RC4($this->_objectkey($this-
>_current_obj_id), $value[1]);
// remake hexstring of encrypted string
$value[1] = $this->str2hex($value[1]);
}
$this->_out("<" . $value[1] . ">");
break;
case pdf_parser::TYPE_BOOLEAN :
$this->_out($value[1] ? 'true' : 'false');
break;
case pdf_parser::TYPE_NULL :
// The null object.
$this->_out("null");
break;
}
}
if (!is_array($search)) {
$x = $search;
$search = array($x);
}
if (!is_array($replacement)) {
$x = $replacement;
$replacement = array($x); // mPDF 5.7.4
}
$changes = array();
preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s",
$pdf, $m);
preg_match_all("/(\d+) 0 R /s", $m[1], $o);
$objlist = $o[1];
foreach ($objlist AS $obj) {
if ($this->compress) {
preg_match("/" . ($obj + 1) . " 0
obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length
(\d+)>>\nstream\n(.*?)\nendstream\n/s", $pdf, $m);
} else {
preg_match("/" . ($obj + 1) . " 0 obj\n<<\s*\/Length
(\d+)>>\nstream\n(.*?)\nendstream\n/s", $pdf, $m);
}
$s = $m[2];
if (!$s) {
continue;
}
$oldlen = $m[1];
if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($obj + 1), $s);
}
if ($this->compress) {
$s = gzuncompress($s);
}
foreach ($search AS $k => $val) {
$s = str_replace($search[$k], $replacement[$k], $s);
}
if ($this->compress) {
$s = gzcompress($s);
}
if ($this->encrypted) {
$s = $this->_RC4($this->_objectkey($obj + 1), $s);
}
$newlen = strlen($s);
$changes[($xref[$obj + 1][0])] = ($newlen - $oldlen) +
(strlen($newlen) - strlen($oldlen));
if ($this->compress) {
$newstr = ($obj + 1) . " 0 obj\n<</Filter /FlateDecode
/Length " . $newlen . ">>\nstream\n" . $s . "\nendstream\n";
} else {
$newstr = ($obj + 1) . " 0 obj\n<</Length " . $newlen .
">>\nstream\n" . $s . "\nendstream\n";
}
$pdf = str_replace($m[0], $newstr, $pdf);
}
// OUTPUT
switch ($dest) {
case 'I':
//Send to standard output
if (isset($_SERVER['SERVER_NAME'])) {
//We send to a browser
Header('Content-Type: application/pdf');
Header('Content-Length: ' . strlen($pdf));
Header('Content-disposition: inline; filename=' .
$file_out);
}
echo $pdf;
break;
case 'F':
//Save to local file
if (!$file_out) {
$file_out = 'mpdf.pdf';
}
$f = fopen($file_out, 'wb');
if (!$f)
throw new MpdfException('Unable to create output
file: ' . $file_out);
fwrite($f, $pdf, strlen($pdf));
fclose($f);
break;
case 'S':
//Return as a string
return $pdf;
case 'D':
default:
//Download file
if (isset($_SERVER['HTTP_USER_AGENT']) and
strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
Header('Content-Type: application/force-download');
else
Header('Content-Type: application/octet-stream');
Header('Content-Length: ' . strlen($pdf));
Header('Content-disposition: attachment; filename=' .
$file_out);
echo $pdf;
break;
}
}
if ($this->y == 0) {
$y = $_y;
} else {
$y = $this->y;
}
$pagecount = $this->SetSourceFile($file);
if ($n % $npr == 0) {
if (($y + $h + $spacing + $maxh) > $this->PageBreakTrigger
&& $n != $pagecount) {
$this->AddPage();
$x = $_x;
$y = $_y;
} else {
$y += $h + $spacing;
$x = $_x;
$h = 0;
}
} else {
$x += $w + $spacing;
}
}
$this->SetLineWidth($oldlinewidth);
}
function SetSourceFile($filename)
{
$this->current_filename = $filename;
$fn = $this->current_filename;
if (!isset($this->parsers[$fn])) {
// $this->parsers[$fn] =& new fpdi_pdf_parser($fn,$this);
try {
$this->parsers[$fn] = new fpdi_pdf_parser($fn, $this);
} catch (Exception $e) {
throw new MpdfException($e->getMessage()); // Delete this
line to return false on fail
return false;
}
}
$this->current_parser = $this->parsers[$fn];
return $this->parsers[$fn]->getPageCount();
}
$this->tpl++;
$this->tpls[$this->tpl] = array();
$tpl = & $this->tpls[$this->tpl];
$tpl['parser'] = $parser;
$tpl['resources'] = $parser->getPageResources();
$tpl['buffer'] = $parser->getContent();
if (!in_array($boxName, $parser->availableBoxes)) {
throw new MpdfException(sprintf("Unknown box: %s", $boxName));
}
/**
* MediaBox
* CropBox: Default -> MediaBox
* BleedBox: Default -> CropBox
* TrimBox: Default -> CropBox
* ArtBox: Default -> CropBox
*/
if (!isset($pageboxes[$boxName]) && ($boxName == "/BleedBox" ||
$boxName == "/TrimBox" || $boxName == "/ArtBox")) {
$boxName = "/CropBox";
}
if (!isset($pageboxes[$boxName])) {
return false;
}
$box = $pageboxes[$boxName];
$tpl['box'] = $box;
// To build an array that can be used by useTemplate()
$this->tpls[$this->tpl] = array_merge($this->tpls[$this->tpl], $box);
// An imported page will start at 0,0 everytime. Translation will be
set in _putformxobjects()
$tpl['x'] = 0;
$tpl['y'] = 0;
$tpl['w'] = $tpl['box']['w'];
$tpl['h'] = $tpl['box']['h'];
if ($crop_w) {
$tpl['box']['w'] = $crop_w;
}
if ($crop_h) {
$tpl['box']['h'] = $crop_h;
}
if (isset($crop_x)) {
$tpl['box']['x'] = $crop_x;
}
if (isset($crop_y)) {
$tpl['box']['y'] = $tpl['h'] - $crop_y - $crop_h;
}
$_w = $tpl['w'];
$_h = $tpl['h'];
$tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
$tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
if ($steps % 2 != 0) {
$x = $y = ($steps == 1 || $steps == -3) ? $tpl['h'] :
$tpl['w'];
} else {
$x = $tpl['w'];
$y = $tpl['h'];
}
$cx = ($x / 2 + $tpl['box']['x']) * _MPDFK;
$cy = ($y / 2 + $tpl['box']['y']) * _MPDFK;
$angle*=-1;
$angle*=M_PI / 180;
$c = cos($angle);
$s = sin($angle);
$tpl['box']['w'] = $tpl['w'];
$tpl['box']['h'] = $tpl['h'];
$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']);
}
return $this->tpl;
}
if ($this->state == 0) {
$this->AddPage();
}
if ($_x == null) {
$_x = $x;
}
if ($_y == null) {
$_y = $y;
}
/* ---------------------------------------------- */
/* ---------------------------------------------- */
/* ---------------------------------------------- */
/* ---------------------------------------------- */
/* ---------------------------------------------- */
// JAVASCRIPT
function _set_object_javascript($string)
{
$this->_newobj();
$this->_out('<<');
$this->_out('/S /JavaScript ');
$this->_out('/JS ' . $this->_textstring($string));
$this->_out('>>');
$this->_out('endobj');
}
function SetJS($script)
{
$this->js = $script;
}