|
From: <be...@us...> - 2015-09-02 17:42:05
|
Revision: 13145
http://sourceforge.net/p/xoops/svn/13145
Author: beckmi
Date: 2015-09-02 17:42:02 +0000 (Wed, 02 Sep 2015)
Log Message:
-----------
TCPDF 6.2.11
Modified Paths:
--------------
XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/docs/changelog.txt
XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/tcpdf.php
XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/tcpdf_autoconfig.php
XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/tcpdf_barcodes_1d.php
XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/tcpdf_parser.php
Modified: XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/docs/changelog.txt
===================================================================
--- XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/docs/changelog.txt 2015-08-28 10:38:37 UTC (rev 13144)
+++ XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/docs/changelog.txt 2015-09-02 17:42:02 UTC (rev 13145)
@@ -1,8 +1,14 @@
=======================
-Changelog TCPDF_for_Xoops
+Changelog TCPDF_for_XOOPS
=======================
=======================
+Version 2.02 2015-09-02
+=======================
+- PHP TCPDF class has been updated (6.0.093 => 6.2.11) (mamba)
+ * see the TCPDF changelog for changes
+
+=======================
Version 2.01 2014-09-13
=======================
- PHP TCPDF class has been optmized and lightened (montuy337513/black_beard - Philodenelle)
Modified: XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/tcpdf.php
===================================================================
--- XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/tcpdf.php 2015-08-28 10:38:37 UTC (rev 13144)
+++ XoopsModules/modulepacks/x257basicmodulepack/trunk/xoops_lib/vendor/tcpdf/tcpdf.php 2015-09-02 17:42:02 UTC (rev 13145)
@@ -1,5 +1,5 @@
<?php
-if (!defined('XOOPS_ROOT_PATH')) die('XOOPS root path not defined');
+defined('XOOPS_ROOT_PATH') || die('Restricted access');
$DirTcpdf = __DIR__;
require_once($DirTcpdf.'/tcpdf_autoconfig.php');
require_once($DirTcpdf.'/include/tcpdf_font_data.php');
@@ -42,7 +42,7 @@
protected $FontFiles = array();
protected $diffs = array();
protected $images = array();
- protected $cached_files = array();
+ protected $svg_tag_depth = 0;
protected $PageAnnots = array();
protected $links = array();
protected $FontFamily;
@@ -168,7 +168,7 @@
protected $numimages = 0;
protected $imagekeys = array();
protected $bufferlen = 0;
- protected $diskcache = false;
+
protected $numfonts = 0;
protected $fontkeys = array();
protected $font_obj_ids = array();
@@ -320,15 +320,21 @@
$this->internal_encoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
+ // set file ID for trailer
+ $serformat = (is_array($format) ? json_encode($format) : $format);
+ $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
$this->font_obj_ids = array();
$this->page_obj_id = array();
$this->form_obj_id = array();
+ // set pdf/a mode
$this->pdfa_mode = $pdfa;
$this->force_srgb = false;
- $this->diskcache = $diskcache ? true : false;
+ // set language direction
$this->rtl = false;
$this->tmprtl = false;
+ // some checks
$this->_dochecks();
+ // initialization of properties
$this->isunicode = $unicode;
$this->page = 0;
$this->transfmrk[0] = array();
@@ -356,8 +362,10 @@
$this->TextColor = '0 g';
$this->ColorFlag = false;
$this->pdflayers = array();
+ // encryption values
$this->encrypted = false;
$this->last_enc_key = '';
+ // standard Unicode fonts
$this->CoreFonts = array(
'courier'=>'Courier',
'courierB'=>'Courier-Bold',
@@ -374,23 +382,33 @@
'symbol'=>'Symbol',
'zapfdingbats'=>'ZapfDingbats'
);
+ // set scale factor
$this->setPageUnit($unit);
+ // set page format and orientation
$this->setPageFormat($format, $orientation);
+ // page margins (1 cm)
$margin = 28.35 / $this->k;
$this->SetMargins($margin, $margin);
$this->clMargin = $this->lMargin;
$this->crMargin = $this->rMargin;
+ // internal cell padding
$cpadding = $margin / 10;
$this->setCellPaddings($cpadding, 0, $cpadding, 0);
+ // cell margins
$this->setCellMargins(0, 0, 0, 0);
+ // line width (0.2 mm)
$this->LineWidth = 0.57 / $this->k;
$this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
$this->linestyleCap = '0 J';
$this->linestyleJoin = '0 j';
$this->linestyleDash = '[] 0 d';
+ // automatic page break
$this->SetAutoPageBreak(true, (2 * $margin));
+ // full width display mode
$this->SetDisplayMode('fullwidth');
+ // compression
$this->SetCompression();
+ // set default PDF version number
$this->setPDFVersion();
$this->tcpdflink = true;
$this->encoding = $encoding;
@@ -401,11 +419,13 @@
$this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
$this->extgstates = array();
$this->setTextShadow();
+ // signature
$this->sign = false;
$this->tsa_timestamp = false;
$this->tsa_data = array();
$this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
$this->empty_signature_appearance = array();
+ // user's rights
$this->ur['enabled'] = false;
$this->ur['document'] = '/FullSave';
$this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
@@ -413,11 +433,15 @@
$this->ur['signature'] = '/Modify';
$this->ur['ef'] = '/Create/Delete/Modify/Import';
$this->ur['formex'] = '';
+ // set default JPEG quality
$this->jpeg_quality = 75;
+ // initialize some settings
TCPDF_FONTS::utf8Bidi(array(''), '', false, $this->isunicode, $this->CurrentFont);
+ // set default font
$this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
$this->setHeaderFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
$this->setFooterFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
+ // check if PCRE Unicode support is enabled
if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
// PCRE unicode support is turned ON
// \s : any whitespace character
@@ -431,18 +455,23 @@
$this->setSpacesRE('/[^\S\xa0]/');
}
$this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
- $serformat = (is_array($format) ? serialize($format) : $format);
- $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
+ // set document creation and modification timestamp
$this->doc_creation_timestamp = time();
$this->doc_modification_timestamp = $this->doc_creation_timestamp;
+ // get default graphic vars
$this->default_graphic_vars = $this->getGraphicVars();
$this->header_xobj_autoreset = false;
$this->custom_xmp = '';
+ // Call cleanup method after script execution finishes or exit() is called.
+ // NOTE: This will not be executed if the process is killed with a SIGTERM or SIGKILL signal.
+ register_shutdown_function(array($this, '_destroy'), true);
}
public function __destruct() {
+ // restore internal encoding
if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
mb_internal_encoding($this->internal_encoding);
}
+ // cleanup
$this->_destroy(true);
}
public function setPageUnit($unit) {
@@ -979,8 +1008,12 @@
$this->state = 1;
}
public function Close() {
- if ($this->state == 3) return'';
- if ($this->page == 0) $this->AddPage();
+ if ($this->state == 3) {
+ return;
+ }
+ if ($this->page == 0) {
+ $this->AddPage();
+ }
$this->endLayer();
if ($this->tcpdflink) {
// save current graphic settings
@@ -1011,7 +1044,9 @@
return '';
}
public function setPage($pnum, $resetmargins=false) {
- if (($pnum == $this->page) AND ($this->state == 2)) return;
+ if (($pnum == $this->page) AND ($this->state == 2)) {
+ return;
+ }
if (($pnum > 0) AND ($pnum <= $this->numpages)) {
$this->state = 2;
// save current graphic settings
@@ -1063,9 +1098,16 @@
$this->endPage(true);
}
public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
- if ($this->inxobj) return;
- if (!isset($this->original_lMargin) OR $keepmargins) $this->original_lMargin = $this->lMargin;
- if (!isset($this->original_rMargin) OR $keepmargins) $this->original_rMargin = $this->rMargin;
+ if ($this->inxobj) {
+ // we are inside an XObject template
+ return '';
+ }
+ if (!isset($this->original_lMargin) OR $keepmargins) {
+ $this->original_lMargin = $this->lMargin;
+ }
+ if (!isset($this->original_rMargin) OR $keepmargins) {
+ $this->original_rMargin = $this->rMargin;
+ }
// terminate previous page
$this->endPage();
// start new page
@@ -1073,34 +1115,46 @@
}
public function endPage($tocpage=false) {
// check if page is already closed
- if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) return;
+ if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
+ return '';
+ }
// print page footer
$this->setFooter();
// close page
$this->_endpage();
// mark page as closed
$this->pageopen[$this->page] = false;
- if ($tocpage) $this->tocpage = false;
+ if ($tocpage) {
+ $this->tocpage = false;
+ }
}
public function startPage($orientation='', $format='', $tocpage=false) {
- if ($tocpage) $this->tocpage = true;
+ if ($tocpage) {
+ $this->tocpage = true;
+ }
// move page numbers of documents to be attached
if ($this->tocpage) {
// move reference to unexistent pages (used for page attachments)
// adjust outlines
$tmpoutlines = $this->outlines;
foreach ($tmpoutlines as $key => $outline) {
- if (!$outline['f'] AND ($outline['p'] > $this->numpages)) $this->outlines[$key]['p'] = ($outline['p'] + 1);
+ if (!$outline['f'] AND ($outline['p'] > $this->numpages)) {
+ $this->outlines[$key]['p'] = ($outline['p'] + 1);
+ }
}
// adjust dests
$tmpdests = $this->dests;
foreach ($tmpdests as $key => $dest) {
- if (!$dest['f'] AND ($dest['p'] > $this->numpages)) $this->dests[$key]['p'] = ($dest['p'] + 1);
+ if (!$dest['f'] AND ($dest['p'] > $this->numpages)) {
+ $this->dests[$key]['p'] = ($dest['p'] + 1);
+ }
}
// adjust links
$tmplinks = $this->links;
foreach ($tmplinks as $key => $link) {
- if (!$link['f'] AND ($link['p'] > $this->numpages)) $this->links[$key]['p'] = ($link['p'] + 1);
+ if (!$link['f'] AND ($link['p'] > $this->numpages)) {
+ $this->links[$key]['p'] = ($link['p'] + 1);
+ }
}
}
if ($this->numpages > $this->page) {
@@ -1110,7 +1164,9 @@
return'';
}
// start a new page
- if ($this->state == 0) $this->Open();
+ if ($this->state == 0) {
+ $this->Open();
+ }
++$this->numpages;
$this->swapMargins($this->booklet);
// save current graphic settings
@@ -1142,7 +1198,9 @@
return '';
}
protected function setContentMark($page=0) {
- if ($page <= 0) $page = $this->page;
+ if ($page <= 0) {
+ $page = $this->page;
+ }
if (isset($this->footerlen[$page])) {
$this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
} else {
@@ -1176,7 +1234,7 @@
}
public function setHeaderMargin($hm=10) {
$this->header_margin = $hm;
- return'';
+ return '';
}
public function getHeaderMargin() {
return $this->header_margin;
@@ -1324,7 +1382,9 @@
}
}
protected function setHeader() {
- if (!$this->print_header OR ($this->state != 2)) return'';
+ if (!$this->print_header OR ($this->state != 2)) {
+ return'';
+ }
$this->InHeader = true;
$this->setGraphicVars($this->default_graphic_vars);
$temp_thead = $this->thead;
@@ -1358,7 +1418,9 @@
return '';
}
protected function setFooter() {
- if ($this->state != 2) return'';
+ if ($this->state != 2) {
+ return'';
+ }
$this->InFooter = true;
// save current graphic settings
$gvars = $this->getGraphicVars();
@@ -1409,7 +1471,10 @@
return (($this->InHeader === false) AND ($this->InFooter === false));
}
protected function setTableHeader() {
- if ($this->num_columns > 1) return'';
+ if ($this->num_columns > 1) {
+ // multi column mode
+ return'';
+ }
if (isset($this->theadMargins['top'])) {
// restore the original top-margin
$this->tMargin = $this->theadMargins['top'];
@@ -1448,9 +1513,13 @@
$this->writeHTML($this->thead, false, false, false, false, '');
$this->setGraphicVars($gvars);
// set new top margin to skip the table headers
- if (!isset($this->theadMargins['top'])) $this->theadMargins['top'] = $this->tMargin;
+ if (!isset($this->theadMargins['top'])) {
+ $this->theadMargins['top'] = $this->tMargin;
+ }
// store end of header position
- if (!isset($this->columns[0]['th'])) $this->columns[0]['th'] = array();
+ if (!isset($this->columns[0]['th'])) {
+ $this->columns[0]['th'] = array();
+ }
$this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
$this->tMargin = $this->y;
$this->pagedim[$this->page]['tm'] = $this->tMargin;
@@ -1535,7 +1604,9 @@
$k = isset($color[3]) ? $color[3] : -1;
// color name
$name = isset($color[4]) ? $color[4] : '';
- if ($c >= 0) return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
+ if ($c >= 0) {
+ return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
+ }
}
return '';
}
@@ -1550,10 +1621,18 @@
}
public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
// set default values
- if (!is_numeric($col1)) $col1 = 0;
- if (!is_numeric($col2)) $col2 = -1;
- if (!is_numeric($col3)) $col3 = -1;
- if (!is_numeric($col4)) $col4 = -1;
+ if (!is_numeric($col1)) {
+ $col1 = 0;
+ }
+ if (!is_numeric($col2)) {
+ $col2 = -1;
+ }
+ if (!is_numeric($col3)) {
+ $col3 = -1;
+ }
+ if (!is_numeric($col4)) {
+ $col4 = -1;
+ }
// set color by case
$suffix = '';
if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
@@ -1609,7 +1688,9 @@
}
$this->ColorFlag = ($this->FillColor != $this->TextColor);
if (($type != 'text') AND ($this->state == 2)) {
- if (!$ret) $this->_out($pdfcolor);
+ if (!$ret) {
+ $this->_out($pdfcolor);
+ }
return $pdfcolor;
}
return '';
@@ -1638,7 +1719,9 @@
$this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
}
// convert UTF-8 array to Latin1 if required
- if ($this->isunicode AND (!$this->isUnicodeFont())) $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
+ if ($this->isunicode AND (!$this->isUnicodeFont())) {
+ $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
+ }
$w = 0; // total width
$wa = array(); // array of characters widths
foreach ($sa as $ck => $char) {
@@ -1648,19 +1731,32 @@
$w += $cw;
}
// restore previous values
- if (!TCPDF_STATIC::empty_string($fontname)) $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
- if ($getarray) return $wa;
+ if (!TCPDF_STATIC::empty_string($fontname)) {
+ $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
+ }
+ if ($getarray) {
+ return $wa;
+ }
return $w;
}
public function GetCharWidth($char, $notlast=true) {
// get raw width
$chw = $this->getRawCharWidth($char);
- if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) $chw += $this->font_spacing;
- if ($this->font_stretching != 100) $chw *= ($this->font_stretching / 100);
+ if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
+ // increase/decrease font spacing
+ $chw += $this->font_spacing;
+ }
+ if ($this->font_stretching != 100) {
+ // fixed stretching mode
+ $chw *= ($this->font_stretching / 100);
+ }
return $chw;
}
public function getRawCharWidth($char) {
- if ($char == 173) return (0);
+ if ($char == 173) {
+ // SHY character will not be printed
+ return (0);
+ }
if (isset($this->CurrentFont['cw'][$char])) {
$w = $this->CurrentFont['cw'][$char];
} elseif (isset($this->CurrentFont['dw'])) {
@@ -1675,27 +1771,30 @@
return $this->getAbsFontMeasure($w);
}
public function GetNumChars($s) {
- if ($this->isUnicodeFont()) return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
+ if ($this->isUnicodeFont()) {
+ return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
+ }
return strlen($s);
}
protected function getFontsList() {
if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
while (($file = readdir($fontsdir)) !== false) {
- if (substr($file, -4) == '.php') array_push($this->fontlist, strtolower(basename($file, '.php')));
+ if (substr($file, -4) == '.php') {
+ array_push($this->fontlist, strtolower(basename($file, '.php')));
+ }
}
closedir($fontsdir);
}
}
- public function unichr($c) {
- return TCPDF_FONTS::unichr($c, $this->isunicode);
- }
- public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false) {
- return TCPDF_FONTS::addTTFfont($fontfile, $fonttype, $enc, $flags, $outpath, $platid, $encid, $addcbbox);
- }
+
public function AddFont($family, $style='', $fontfile='', $subset='default') {
$originalsize = $size1 = $size2 = 8;
- if ($subset === 'default') $subset = $this->font_subsetting;
- if ($this->pdfa_mode) $subset = false;
+ if ($subset === 'default') {
+ $subset = $this->font_subsetting;
+ }
+ if ($this->pdfa_mode) {
+ $subset = false;
+ }
if (TCPDF_STATIC::empty_string($family)) {
if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
$family = $this->FontFamily;
@@ -1714,9 +1813,16 @@
}
// normalize family name
$family = strtolower($family);
- if ((!$this->isunicode) AND ($family == 'arial')) $family = 'helvetica';
- if (($family == 'symbol') OR ($family == 'zapfdingbats')) $style = '';
- if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) $family = 'pdfa'.$family;
+ if ((!$this->isunicode) AND ($family == 'arial')) {
+ $family = 'helvetica';
+ }
+ if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
+ $style = '';
+ }
+ if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
+ // all fonts must be embedded
+ $family = 'pdfa'.$family;
+ }
$tempstyle = strtoupper($style);
$style = '';
// underline
@@ -1738,9 +1844,13 @@
$this->overline = false;
}
// bold
- if (strpos($tempstyle, 'B') !== false) $style .= 'B';
+ if (strpos($tempstyle, 'B') !== false) {
+ $style .= 'B';
+ }
// oblique
- if (strpos($tempstyle, 'I') !== false) $style .= 'I';
+ if (strpos($tempstyle, 'I') !== false) {
+ $style .= 'I';
+ }
$bistyle = $style;
$fontkey = $family.$style;
$font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
@@ -1748,7 +1858,10 @@
// check if the font has been already added
$fb = $this->getFontBuffer($fontkey);
if ($fb !== false) {
- if ($this->inxobj) $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
+ if ($this->inxobj) {
+ // we are inside an XObject template
+ $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
+ }
return $fontdata;
}
// get specified font directory (if any)
@@ -1779,23 +1892,39 @@
if (!TCPDF_STATIC::empty_string($fontfile) AND (@file_exists($fontfile))) {
include($fontfile);
} else {
- var_dump($fontfile);
+ //var_dump($fontfile);
$this->Error('Could not include font definition file: '.$family.'');
}
// check font parameters
- if ((!isset($type)) OR (!isset($cw)))$this->Error('The font definition file has a bad format: '.$fontfile.'');
+ if ((!isset($type)) OR (!isset($cw))) {
+ $this->Error('The font definition file has a bad format: '.$fontfile.'');
+ }
// SET default parameters
- if (!isset($file) OR TCPDF_STATIC::empty_string($file)) $file = '';
- if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) $enc = '';
+ if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
+ $file = '';
+ }
+ if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
+ $enc = '';
+ }
if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
$cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
$cidinfo['uni2cid'] = array();
}
- if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) $ctg = '';
- if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) $desc = array();
- if (!isset($up) OR TCPDF_STATIC::empty_string($up)) $up = -100;
- if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) $ut = 50;
- if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) $cw = array();
+ if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
+ $ctg = '';
+ }
+ if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
+ $desc = array();
+ }
+ if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
+ $up = -100;
+ }
+ if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
+ $ut = 50;
+ }
+ if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
+ $cw = array();
+ }
if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
// set default width
if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
@@ -1822,7 +1951,9 @@
$this->Error('Unknow font type: '.$type.'');
}
// set name if unset
- if (!isset($name) OR empty($name)) $name = $fontkey;
+ if (!isset($name) OR empty($name)) {
+ $name = $fontkey;
+ }
// create artificial font style variations if missing (only works with non-embedded fonts)
if (($type != 'core') AND $missing_style) {
// style variations
@@ -1853,11 +1984,16 @@
}
}
// check if the array of characters bounding boxes is defined
- if (!isset($cbbox)) $cbbox = array();
+ if (!isset($cbbox)) {
+ $cbbox = array();
+ }
// initialize subsetchars
$subsetchars = array_fill(0, 255, true);
$this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'cbbox' => $cbbox, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
- if ($this->inxobj) $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
+ if ($this->inxobj) {
+ // we are inside an XObject template
+ $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
+ }
if (isset($diff) AND (!empty($diff))) {
//Search existing encodings
$d = 0;
@@ -1896,7 +2032,9 @@
if ($size === null) {
$size = $this->FontSizePt;
}
- if ($size < 0) $size = 0;
+ if ($size < 0) {
+ $size = 0;
+ }
// try to add font (if not already added)
$fontdata = $this->AddFont($family, $style, $fontfile, $subset);
$this->FontFamily = $fontdata['family'];
@@ -1942,7 +2080,7 @@
}
}
public function getFontBBox() {
- //$fbbox = array();
+ $fbbox = array();
if (isset($this->CurrentFont['desc']['FontBBox'])) {
$tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
$fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
@@ -1961,7 +2099,7 @@
if (isset($this->CurrentFont['dw'])) {
$maxw = max($maxw, $this->CurrentFont['dw']);
}
- foreach ($this->CurrentFont['cw'] as $w) {
+ foreach ($this->CurrentFont['cw'] as $char => $w) {
$maxw = max($maxw, $w);
}
if ($maxw == 0) {
@@ -1977,8 +2115,14 @@
return ($s * $this->FontSize / 1000);
}
public function getCharBBox($char) {
- if (isset($this->CurrentFont['cbbox'][$char])) {
- return array_map(array($this,'getAbsFontMeasure'), $this->CurrentFont['cbbox'][intval($char)]);
+ $c = intval($char);
+ if (isset($this->CurrentFont['cw'][$c])) {
+ // glyph is defined ... use zero width & height for glyphs without outlines
+ $result = array(0,0,0,0);
+ if (isset($this->CurrentFont['cbbox'][$c])) {
+ $result = $this->CurrentFont['cbbox'][$c];
+ }
+ return array_map(array($this,'getAbsFontMeasure'), $result);
}
return false;
}
@@ -2084,8 +2228,12 @@
$this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
return'';
}
- if ($x === '') $x = $this->x;
- if ($y === '') $y = $this->y;
+ if ($x === '') {
+ $x = $this->x;
+ }
+ if ($y === '') {
+ $y = $this->y;
+ }
// check page for no-write regions and adapt page margins if necessary
list($x, $y) = $this->checkPageRegions($h, $x, $y);
// recalculate coordinates to account for graphic transformations
@@ -2135,7 +2283,9 @@
} else {
$page = $this->page;
}
- if (!isset($this->PageAnnots[$page])) $this->PageAnnots[$page] = array();
+ if (!isset($this->PageAnnots[$page])) {
+ $this->PageAnnots[$page] = array();
+ }
$this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
if (!$this->pdfa_mode) {
if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
@@ -2486,7 +2636,7 @@
// sara u, sara uu, pinthu
$lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
$output = array();
- for ($i = 0; $i < $numchars; ++$i) {
+ for ($i = 0; $i < $numchars; $i++) {
if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
$ch0 = $unicode[$i];
$ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
@@ -2593,9 +2743,17 @@
$align = '';
}
}
- if ($this->font_stretching != 100) $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
- if ($this->font_spacing != 0) $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
- if ($this->ColorFlag AND ($this->textrendermode < 4)) $s .= 'q '.$this->TextColor.' ';
+ if ($this->font_stretching != 100) {
+ // apply font stretching
+ $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
+ }
+ if ($this->font_spacing != 0) {
+ // increase/decrease font spacing
+ $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
+ }
+ if ($this->ColorFlag AND ($this->textrendermode < 4)) {
+ $s .= 'q '.$this->TextColor.' ';
+ }
// rendering mode
$s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
// count number of spaces
@@ -2608,16 +2766,22 @@
$width = $this->GetStringWidth(str_replace(' ', '', $txt));
// calculate average space width
$spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
- if ($this->font_stretching != 100) $spacewidth /= ($this->font_stretching / 100);
+ if ($this->font_stretching != 100) {
+ // word spacing is affected by stretching
+ $spacewidth /= ($this->font_stretching / 100);
+ }
// set word position to be used with TJ operator
$txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
- //$unicode_justification = true;
+ $unicode_justification = true;
} else {
// get string width
$width = $txwidth;
// new space width
$spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
- if ($this->font_stretching != 100) $spacewidth /= ($this->font_stretching / 100);
+ if ($this->font_stretching != 100) {
+ // word spacing (Tw) is affected by stretching
+ $spacewidth /= ($this->font_stretching / 100);
+ }
// set word spacing
$rs .= sprintf('BT %F Tw ET ', $spacewidth);
}
@@ -2685,21 +2849,39 @@
}
}
}
- if ($this->underline)$s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
- if ($this->linethrough) $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
- if ($this->overline) $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
- if ($this->ColorFlag AND ($this->textrendermode < 4)) $s .= ' Q';
- if ($link) $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
+ if ($this->underline) {
+ $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
+ }
+ if ($this->linethrough) {
+ $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
+ }
+ if ($this->overline) {
+ $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
+ }
+ if ($this->ColorFlag AND ($this->textrendermode < 4)) {
+ $s .= ' Q';
+ }
+ if ($link) {
+ $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
+ }
}
// output cell
if ($s) {
// output cell
$rs .= $s;
- if ($this->font_spacing != 0) $rs .= ' BT 0 Tc ET';
- if ($this->font_stretching != 100) $rs .= ' BT 100 Tz ET';
+ if ($this->font_spacing != 0) {
+ // reset font spacing mode
+ $rs .= ' BT 0 Tc ET';
+ }
+ if ($this->font_stretching != 100) {
+ // reset font stretching mode
+ $rs .= ' BT 100 Tz ET';
+ }
}
// reset word spacing
- if (!$this->isUnicodeFont() AND ($align == 'J')) $rs .= ' BT 0 Tw ET';
+ if (!$this->isUnicodeFont() AND ($align == 'J')) {
+ $rs .= ' BT 0 Tw ET';
+ }
// reset stretching and spacing
$this->font_stretching = $prev_font_stretching;
$this->font_spacing = $prev_font_spacing;
@@ -2740,8 +2922,12 @@
}
protected function getCellBorder($x, $y, $w, $h, $brd) {
$s = ''; // string to be returned
- if (empty($brd)) return $s;
- if ($brd == 1) $brd = array('LRTB' => true);
+ if (empty($brd)) {
+ return $s;
+ }
+ if ($brd == 1) {
+ $brd = array('LRTB' => true);
+ }
// calculate coordinates for border
$k = $this->k;
if ($this->rtl) {
@@ -3263,13 +3449,19 @@
return $nl;
}
public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
- if ($txt === NULL) return 0;
- if ($txt === '') return 1;
- if($autopadding) {}
+ if ($txt === NULL) {
+ return 0;
+ }
+ if ($txt === '') {
+ // empty string
+ return 1;
+ }
// adjust internal padding
$prev_cell_padding = $this->cell_padding;
$prev_lasth = $this->lasth;
- if (is_array($cellpadding)) $this->cell_padding = $cellpadding;
+ if (is_array($cellpadding)) {
+ $this->cell_padding = $cellpadding;
+ }
$this->adjustCellPadding($border);
if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
if ($this->rtl) {
@@ -3279,7 +3471,10 @@
}
}
$wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
- if ($reseth) $this->resetLastH();
+ if ($reseth) {
+ // reset row height
+ $this->resetLastH();
+ }
$lines = 1;
$sum = 0;
$chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
@@ -3328,7 +3523,9 @@
// adjust internal padding
$prev_cell_padding = $this->cell_padding;
$prev_lasth = $this->lasth;
- if (is_array($cellpadding)) $this->cell_padding = $cellpadding;
+ if (is_array($cellpadding)) {
+ $this->cell_padding = $cellpadding;
+ }
$this->adjustCellPadding($border);
$lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
$height = $this->getCellHeight(($lines * $this->FontSize), $autopadding);
@@ -3339,8 +3536,14 @@
public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
// check page for no-write regions and adapt page margins if necessary
list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
- if (strlen($txt) == 0) $txt = ' ';
- if ($margin === '') $margin = $this->cell_margin;
+ if (strlen($txt) == 0) {
+ // fix empty text
+ $txt = ' ';
+ }
+ if ($margin === '') {
+ // set default margins
+ $margin = $this->cell_margin;
+ }
// remove carriage returns
$s = str_replace("\r", '', $txt);
// check if string contains arabic text
@@ -3446,7 +3649,7 @@
if ($firstblock AND $this->isRTLTextDir()) {
$tmpstr = $this->stringRightTrim($tmpstr);
}
- // Skip newlines at the begining of a page or column
+ // Skip newlines at the beginning of a page or column
if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
$this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
}
@@ -3698,12 +3901,12 @@
switch ($align) {
case 'J':
case 'C': {
- //$w = $w;
+ $w = $w;
break;
}
case 'L': {
if ($this->rtl) {
- //$w = $w;
+ $w = $w;
} else {
$w = $l;
}
@@ -3713,7 +3916,7 @@
if ($this->rtl) {
$w = $l;
} else {
- //$w = $w;
+ $w = $w;
}
break;
}
@@ -3830,10 +4033,10 @@
if ($this->state != 2) {
return'';
}
- if ($x === '') {
+ if (strcmp($x, '') === 0) {
$x = $this->x;
}
- if ($y === '') {
+ if (strcmp($y, '') === 0) {
$y = $this->y;
}
// check page for no-write regions and adapt page margins if necessary
@@ -3863,7 +4066,7 @@
// get existing image data
$info = $this->getImageBuffer($file);
$imsize = array($info['w'], $info['h']);
- } elseif (strpos($file, '__tcpdf_img') === FALSE) {
+ } elseif (strpos($file, '__tcpdf_'.$this->file_id.'_img') === FALSE) {
$imgdata = TCPDF_STATIC::fileGetContents($file);
}
}
@@ -3871,8 +4074,8 @@
if (!empty($imgdata)) {
// copy image to cache
$original_file = $file;
- $file = TCPDF_STATIC::getObjFilename('img');
- $fp = fopen($file, 'w');
+ $file = TCPDF_STATIC::getObjFilename('img', $this->file_id);
+ $fp = TCPDF_STATIC::fopenLocal($file, 'w');
if (!$fp) {
$this->Error('Unable to write file: '.$file);
}
@@ -3883,8 +4086,6 @@
if ($imsize === FALSE) {
unlink($file);
$file = $original_file;
- } else {
- $this->cached_files[] = $file;
}
}
if ($imsize === FALSE) {
@@ -3898,7 +4099,7 @@
}
}
// file hash
- $filehash = md5($this->file_id.$file);
+ $filehash = md5($file);
// get original image width and height in pixels
list($pixw, $pixh) = $imsize;
// calculate image width and height on document
@@ -3988,18 +4189,18 @@
$newimage = false;
// get existing image data
$info = $this->getImageBuffer($file);
- if (strpos($file, '__tcpdf_imgmask_') === FALSE) {
+ if (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) {
// check if the newer image is larger
$oldsize = ($info['w'] * $info['h']);
if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
$newimage = true;
}
}
- } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_imgmask_') === FALSE)) {
+ } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)) {
// create temp image file (without alpha channel)
- $tempfile_plain = K_PATH_CACHE.'__tcpdf_imgmask_plain_'.$filehash;
+ $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
// create temp alpha file
- $tempfile_alpha = K_PATH_CACHE.'__tcpdf_imgmask_alpha_'.$filehash;
+ $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
// check for cached images
if (in_array($tempfile_plain, $this->imagekeys)) {
// get existing image data
@@ -4009,7 +4210,7 @@
if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
$newimage = true;
} else {
- //$newimage = false;
+ $newimage = false;
// embed mask image
$imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
// embed image, masked with previously embedded mask
@@ -4035,7 +4236,7 @@
if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
// TCPDF image functions
$info = TCPDF_IMAGES::$mtd($file);
- if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_imgmask_') === FALSE)
+ if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)
AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
}
@@ -4054,9 +4255,9 @@
$img = $imgr;
}
if (($type == 'gif') OR ($type == 'png')) {
- $info = TCPDF_IMAGES::_toPNG($img);
+ $info = TCPDF_IMAGES::_toPNG($img, TCPDF_STATIC::getObjFilename('img', $this->file_id));
} else {
- $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality);
+ $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality, TCPDF_STATIC::getObjFilename('img', $this->file_id));
}
}
} catch(Exception $e) {
@@ -4110,10 +4311,12 @@
} else {
$img->readImage($file);
}
- if ($resize) $img->resizeImage($neww, $newh, 10, 1, false);
+ if ($resize) {
+ $img->resizeImage($neww, $newh, 10, 1, false);
+ }
$img->setCompressionQuality($this->jpeg_quality);
$img->setImageFormat('jpeg');
- $tempname = TCPDF_STATIC::getObjFilename('img');
+ $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id);
$img->writeImage($tempname);
$info = TCPDF_IMAGES::_parsejpeg($tempname);
unlink($tempname);
@@ -4227,12 +4430,12 @@
protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
// create temp images
if (empty($filehash)) {
- $filehash = md5($this->file_id.$file);
+ $filehash = md5($file);
}
// create temp image file (without alpha channel)
- $tempfile_plain = K_PATH_CACHE.'__tcpdf_imgmask_plain_'.$filehash;
+ $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
// create temp alpha file
- $tempfile_alpha = K_PATH_CACHE.'__tcpdf_imgmask_alpha_'.$filehash;
+ $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
$parsed = false;
$parse_error = '';
// ImageMagick extension
@@ -4309,9 +4512,6 @@
$imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
// embed image, masked with previously embedded mask
$this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
- // remove temp files
- unlink($tempfile_alpha);
- unlink($tempfile_plain);
}
protected function getGDgamma($img, $c) {
if (!isset($this->gdgammacache['#'.$c])) {
@@ -4348,10 +4548,9 @@
$this->x = $this->lMargin + $cellpadding;
}
if (is_string($h)) {
- $this->y += $this->lasth;
- } else {
- $this->y += $h;
+ $h = $this->lasth;
}
+ $this->y += $h;
$this->newline = true;
}
public function GetX() {
@@ -4447,12 +4646,6 @@
$pdfdoc = $this->getBuffer();
// remove last newline
$pdfdoc = substr($pdfdoc, 0, -1);
- // Remove the original buffer
- if (isset($this->diskcache) AND $this->diskcache) {
- // remove buffer file from cache
- unlink($this->buffer);
- }
- unset($this->buffer);
// remove filler space
$byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
// define the ByteRange
@@ -4467,8 +4660,8 @@
$byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
$pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
// write the document to a temporary folder
- $tempdoc = TCPDF_STATIC::getObjFilename('doc');
- $f = fopen($tempdoc, 'wb');
+ $tempdoc = TCPDF_STATIC::getObjFilename('doc', $this->file_id);
+ $f = TCPDF_STATIC::fopenLocal($tempdoc, 'wb');
if (!$f) {
$this->Error('Unable to create temporary file: '.$tempdoc);
}
@@ -4476,22 +4669,19 @@
fwrite($f, $pdfdoc, $pdfdoc_length);
fclose($f);
// get digital signature via openssl library
- $tempsign = TCPDF_STATIC::getObjFilename('sig');
+ $tempsign = TCPDF_STATIC::getObjFilename('sig', $this->file_id);
if (empty($this->signature_data['extracerts'])) {
openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
} else {
openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']);
}
- unlink($tempdoc);
// read signature
$signature = file_get_contents($tempsign);
- unlink($tempsign);
// extract signature
$signature = substr($signature, $pdfdoc_length);
$signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
$tmparr = explode("\n\n", $signature);
$signature = $tmparr[1];
- unset($tmparr);
// decode signature
$signature = base64_decode(trim($signature));
// add TSA timestamp to signature
@@ -4499,8 +4689,6 @@
// convert signature to hex
$signature = current(unpack('H*', $signature));
$signature = str_pad($signature, $this->signature_max_length, '0');
- // disable disk caching
- $this->diskcache = false;
// Add signature to the document
$this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
$this->bufferlen = strlen($this->buffer);
@@ -4562,16 +4750,12 @@
case 'FI':
case 'FD': {
// save PDF to a local file
- if ($this->diskcache) {
- copy($this->buffer, $name);
- } else {
- $f = fopen($name, 'wb');
- if (!$f) {
- $this->Error('Unable to create output file: '.$name);
- }
- fwrite($f, $this->getBuffer(), $this->bufferlen);
- fclose($f);
+ $f = TCPDF_STATIC::fopenLocal($name, 'wb');
+ if (!$f) {
+ $this->Error('Unable to create output file: '.$name);
}
+ fwrite($f, $this->getBuffer(), $this->bufferlen);
+ fclose($f);
if ($dest == 'FI') {
// send headers to browser
header('Content-Type: application/pdf');
@@ -4632,25 +4816,19 @@
return '';
}
public function _destroy($destroyall=false, $preserve_objcopy=false) {
- if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!TCPDF_STATIC::empty_string($this->buffer))) {
- // remove buffer file from cache
- unlink($this->buffer);
- }
- if ($destroyall AND !empty($this->cached_files)) {
- // remove cached files
- foreach ($this->cached_files as $cachefile) {
- if (is_file($cachefile)) {
- unlink($cachefile);
- }
+ if ($destroyall AND !$preserve_objcopy) {
+ // remove all temporary files
+ $tmpfiles = glob(K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_*');
+ if (!empty($tmpfiles)) {
+ array_map('unlink', $tmpfiles);
}
- unset($this->cached_files);
}
$preserve = array(
+ 'file_id',
'internal_encoding',
'state',
'bufferlen',
'buffer',
- 'diskcache',
'cached_files',
'sign',
'signature_data',
@@ -4661,7 +4839,7 @@
);
foreach (array_keys(get_object_vars($this)) as $val) {
if ($destroyall OR !in_array($val, $preserve)) {
- if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
+ if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
unset($this->$val);
}
}
@@ -4678,7 +4856,7 @@
}
}
protected function getInternalPageNumberAliases($a= '') {
- //$alias = array();
+ $alias = array();
// build array of Unicode + ASCII variants (the order is important)
$alias = array('u' => array(), 'a' => array());
$u = '{'.$a.'}';
@@ -4879,10 +5057,6 @@
$this->_newobj();
$p = $this->_getrawstream($p);
$this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
- if ($this->diskcache) {
- // remove temporary files
- unlink($this->pages[$n]);
- }
}
//Pages root
$out = $this->_getobj(1)."\n";
@@ -4894,9 +5068,7 @@
$out .= "\n".'endobj';
$this->_out($out);
}
- protected function _putannotsrefs($n) {
- $this->_out($this->_getannotsrefs($n));
- }
+
protected function _getannotsrefs($n) {
if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
return '';
@@ -4961,7 +5133,7 @@
$annots .= ' /FT /Btn';
$annots .= ' /Kids [';
$defval = '';
- foreach ($this->radiobutton_groups[$n][$pl['txt']] as $data) {
+ foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
if (isset($data['kid'])) {
$annots .= ' '.$data['kid'].' 0 R';
if ($data['def'] !== 'Off') {
@@ -6288,13 +6460,13 @@
$dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
$doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
$doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
- $doccreationdate .= '+'.substr($dcdate, 15, 2).':'.substr($dcdate, 18, 2);
+ $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2);
$doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
// convert doc modification date format
$dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
$docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
$docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
- $docmoddate .= '+'.substr($dmdate, 15, 2).':'.substr($dmdate, 18, 2);
+ $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2);
$docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
$xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
$xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
@@ -6388,7 +6560,7 @@
// if required, add standard sRGB_IEC61966-2.1 blackscaled ICC colour profile
if ($this->pdfa_mode OR $this->force_srgb) {
$iccobj = $this->_newobj();
- $icc = file_get_contents(__DIR__.'/include/sRGB.icc');
+ $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
$filter = '';
if ($this->compress) {
$filter = ' /Filter /FlateDecode';
@@ -6543,7 +6715,7 @@
//$out .= ' /XFA ';
$out .= ' >>';
// signatures
- if ($this->sign AND isset($this->signature_data['cert_type'])
+ if ($this->sign AND isset($this->signature_data['cert_type'])
AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) {
if ($this->signature_data['cert_type'] > 0) {
$out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
@@ -6714,17 +6886,6 @@
$this->_out($o);
$this->_out('%%EOF');
$this->state = 3; // end-of-doc
- if ($this->diskcache) {
- // remove temporary files used for images
- foreach ($this->imagekeys as $key) {
- // remove temporary files
- unlink($this->images[$key]);
- }
- foreach ($this->fontkeys as $key) {
- // remove temporary files
- unlink($this->fonts[$key]);
- }
- }
}
protected function _beginpage($orientation='', $format='') {
++$this->page;
@@ -6844,17 +7005,6 @@
}
return $this->_datastring($s, $n);
}
- protected function _escapetext($s) {
- if ($this->isunicode) {
- if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
- $s = TCPDF_FONTS::UTF8ToLatin1($s, $this->isunicode, $this->CurrentFont);
- } else {
- //Convert string to UTF-16BE and reverse RTL language
- $s = TCPDF_FONTS::utf8StrRev($s, false, $this->tmprtl, $this->isunicode, $this->CurrentFont);
- }
- }
- return TCPDF_STATIC::_escape($s);
- }
protected function _getrawstream($s, $n=0) {
if ($n <= 0) {
// default to current object
@@ -6862,12 +7012,7 @@
}
return $this->_encrypt_data($n, $s);
}
- protected function _getstream($s, $n=0) {
- return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
- }
- protected function _putstream($s, $n=0) {
- $this->_out($this->_getstream($s, $n));
- }
+
protected function _out($s) {
if ($this->state == 2) {
if ($this->inxobj) {
@@ -6917,7 +7062,7 @@
return $this->buffer;
}
public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
- if (isset($url[1]) AND ($url[0] == '#')) {
+ if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
// convert url to internal link
$lnkdata = explode(',', $url);
if (isset($lnkdata[0]) ) {
@@ -7127,8 +7272,7 @@
}
protected function _UEvalue() {
$hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
- $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
- return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
+ return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
}
protected function _Ovalue() {
if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
@@ -7164,8 +7308,7 @@
protected function _OEvalue() {
$hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
- $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
- return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
+ return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
}
protected function _fixAES256Password($password) {
$psw = ''; // password to be returned
@@ -7204,8 +7347,7 @@
}
$perms .= 'adb'; // bytes 9-11
$perms .= 'nick'; // bytes 12-15
- $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
- $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
+ $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms);
} else { // RC4-40, RC4-128, AES-128
// Pad passwords
$this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
@@ -7243,22 +7385,20 @@
// envelope data
$envelope = $seed.$pkpermissions;
// write the envelope data to a temporary file
- $tempkeyfile = TCPDF_STATIC::getObjFilename('key');
- $f = fopen($tempkeyfile, 'wb');
+ $tempkeyfile = TCPDF_STATIC::getObjFilename('key', $this->file_id);
+ $f = TCPDF_STATIC::fopenLocal($tempkeyfile, 'wb');
if (!$f) {
$this->Error('Unable to create temporary key file: '.$tempkeyfile);
}
$envelope_length = strlen($envelope);
fwrite($f, $envelope, $envelope_length);
fclose($f);
- $tempencfile = TCPDF_STATIC::getObjFilename('enc');
+ $tempencfile = TCPDF_STATIC::getObjFilename('enc', $this->file_id);
if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
$this->Error('Unable to encrypt the file: '.$tempkeyfile);
}
- unlink($tempkeyfile);
// read encryption signature
$signature = file_get_contents($tempencfile, false, null, $envelope_length);
- unlink($tempencfile);
// extract signature
$signature = substr($signature, strpos($signature, 'Content-Disposition'));
$tmparr = explode("\n\n", $signature);
@@ -7297,7 +7437,7 @@
if (!function_exists('openssl_pkcs7_encrypt')) {
$this->Error('Public-Key Security requires openssl library.');
}
- // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
+ // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
$this->encryptdata['pubkey'] = true;
$this->encryptdata['Filter'] = 'Adobe.PubSec';
$this->encryptdata['StmF'] = 'DefaultCryptFilter';
@@ -7310,10 +7450,13 @@
$this->encryptdata['StrF'] = 'StdCF';
}
if ($mode > 1) { // AES
- if (!extension_loaded('mcrypt')) {
- $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
+ if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
+ $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
}
- if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
+ if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) {
+ $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
+ }
+ if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
$this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
}
if (($mode == 3) AND !function_exists('hash')) {
@@ -9847,14 +9990,14 @@
$out .= "\n".'endobj';
$this->_out($out);
}
- // set transparency fuctions
+ // set transparency functions
if ($grad['transparency']) {
$ft = $this->_newobj();
$out = '<<';
$out .= ' /FunctionType 3';
$out .= ' /Domain [0 1]';
$functions = '';
- //$i = 1;
+ $i = 1;
$num_cols = count($grad['colors']);
for ($i = 1; $i < $num_cols; ++$i) {
$functions .= ($ft + $i).' 0 R ';
@@ -10330,7 +10473,7 @@
if (TCPDF_STATIC::empty_string(trim($code))) {
return'';
}
- require_once(__DIR__.'/tcpdf_barcodes_1d.php');
+ require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
// save current graphic settings
$gvars = $this->getGraphicVars();
// create new barcode object
@@ -10624,7 +10767,7 @@
if (TCPDF_STATIC::empty_string(trim($code))) {
return'';
}
- require_once(__DIR__.'/tcpdf_barcodes_2d.php');
+ require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
// save current graphic settings
$gvars = $this->getGraphicVars();
// create new barcode object
@@ -10708,9 +10851,13 @@
$maxh = $maxw * $ratioHW;
}
}
- // set maximum dimesions
- if ($w > $maxw) $w = $maxw;
- if ($h > $maxh) $h = $maxh;
+ // set maximum dimensions
+ if ($w > $maxw) {
+ $w = $maxw;
+ }
+ if ($h > $maxh) {
+ $h = $maxh;
+ }
// set dimensions
if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
$w = ($cols + $hpad) * ($mw / $this->k);
@@ -11062,7 +11209,7 @@
return $border_spacing;
}
protected function getCSSFontSpacing($spacing, $parent=0) {
- //$val = 0; // value to be returned
+ $val = 0; // value to be returned
$spacing = trim($spacing);
switch ($spacing) {
case 'normal': {
@@ -11084,7 +11231,7 @@
return $val;
}
protected function getCSSFontStretching($stretch, $parent=100) {
- //$val = 100; // value to be returned
+ $val = 100; // value to be returned
$stretch = trim($stretch);
switch ($stretch) {
case 'ultra-condensed': {
@@ -11198,14 +11345,14 @@
$matches = array();
if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
if (isset($matches[1][0])) {
- $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
+ $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true));
}
$html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
}
// extract external CSS files
$matches = array();
if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
- foreach ($matches[1] as $link) {
+ foreach ($matches[1] as $key => $link) {
$type = array();
if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
$type = array();
@@ -11240,7 +11387,7 @@
}
}
// create a special tag to contain the CSS array (used for table content)
- $csstagarray = '<cssarray>'.htmlentities(serialize($css)).'</cssarray>';
+ $csstagarray = '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
// remove head and style blocks
$html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
$html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
@@ -11427,7 +11574,7 @@
if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
$dom[($dom[$key]['parent'])]['content'] = $csstagarray;
for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
- $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
+ $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
}
$key = $i;
// mark nested tables
@@ -11979,9 +12126,26 @@
}
return $spacestr;
}
- public function serializeTCPDFtagParameters($pararray) {
- return TCPDF_STATIC::serializeTCPDFtagParameters($pararray);
+
+ protected function getHashForTCPDFtagParams($data) {
+ return md5(strlen($data).$this->file_id.$data);
}
+
+
+ public function serializeTCPDFtagParameters($data) {
+ $encoded = urlencode(json_encode($data));
+ return $this->getHashForTCPDFtagParams($encoded).$encoded;
+ }
+
+
+ protected function unserializeTCPDFtagParameters($data) {
+ $hash = substr($data, 0, 32);
+ $encoded = substr($data, 32);
+ if ($hash != $this->getHashForTCPDFtagParams($encoded)) {
+ $this->Error('Invalid parameters');
+ }
+ return json_decode(urldecode($encoded), true);
+ }
public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
}
@@ -12306,7 +12470,9 @@
if (($key < ($maxel - 1)) AND (
($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
OR ($this->cell_height_ratio != $dom[$key]['line-height'])
- OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize) AND ($fontsize >= 0) AND ($curfontsize >= 0) AND ($fontsize != $curfontsize))
+ OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize)
+ AND ($fontsize >= 0) AND ($curfontsize >= 0)
+ AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
)) {
if ($this->page > $startlinepage) {
// fix lines splitted over two pages
@@ -12599,7 +12765,7 @@
$spacew = ($spacewidth * $ns);
}
$offset = $strpiece[2][1] + strlen($strpiece[2][0]);
- $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset);
+ $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset);
if ($epsposend !== null) {
$epsposend += strlen($this->epsmarker.'Q');
$epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
@@ -12958,7 +13124,7 @@
$cellh = 0;
}
if (isset($dom[$key]['content'])) {
- $cell_content = stripslashes($dom[$key]['content']);
+ $cell_content = $dom[$key]['content'];
} else {
$cell_content = ' ';
}
@@ -13051,7 +13217,7 @@
// inherit column width
$cellw = 0;
for ($i = 0; $i < $colspan; ++$i) {
- $cellw += $table_colwidths[($colid + $i)];
+ $cellw += (isset($table_colwidths[($colid + $i)]) ? $table_colwidths[($colid + $i)] : 0);
}
}
$cellw += (($colspan - 1) * $cellspacing['H']);
@@ -13525,7 +13691,7 @@
$this->lispacer = $prev_lispacer;
if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
$this->Ln($this->lasth);
- if ($this->y < $maxbottomliney) {
+ if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) {
$this->y = $maxbottomliney;
}
}
@@ -14155,7 +14321,7 @@
$tcpdf_method = $tag['attribute']['method'];
if (method_exists($this, $tcpdf_meth...
[truncated message content] |