From df7ac13a2a9c2e3baee988a5ea7a8370dba8d3c2 Mon Sep 17 00:00:00 2001 From: Nicola Asuni Date: Thu, 13 Sep 2012 19:54:21 +0100 Subject: [PATCH] 5.9.186 (2012-09-13) - barcodes.php file was resynced. - Methods SetAbsX, SetAbsY, SetAbsXY where added to set the absolute pointer coordinates. - Method getCharBBox were added to get single character bounding box. - Signature of addTTFfont method was changed ( paramter was added). --- CHANGELOG.TXT | 9 ++++ README.TXT | 4 +- barcodes.php | 10 ++-- composer.json | 2 +- tcpdf.php | 125 ++++++++++++++++++++++++++++++++++++++++---------- 5 files changed, 119 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 306faf0..76febd2 100755 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -1,3 +1,12 @@ +5.9.186 (2012-09-13) + - barcodes.php file was resynced. + - Methods SetAbsX, SetAbsY, SetAbsXY where added to set the absolute pointer coordinates. + - Method getCharBBox were added to get single character bounding box. + - Signature of addTTFfont method was changed ($addcbbox paramter was added). + +5.9.185 (2012-09-12) + - Method _putfontwidths() was fixed. + 5.9.184 (2012-09-11) - A problem with EAN barcodes was fixed. diff --git a/README.TXT b/README.TXT index 87ada69..3ada350 100755 --- a/README.TXT +++ b/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 5.9.184 -Release date: 2012-09-11 +Version: 5.9.186 +Release date: 2012-09-13 Author: Nicola Asuni Copyright (c) 2002-2012: diff --git a/barcodes.php b/barcodes.php index c6c0172..a820d3f 100755 --- a/barcodes.php +++ b/barcodes.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf - * @version 1.0.024 + * @version 1.0.025 * @author Nicola Asuni */ class TCPDFBarcode { @@ -1452,7 +1452,7 @@ class TCPDFBarcode { $seq .= '010101'; // right guard bar } else { $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); - $half_len = ceil($len / 2); + $half_len = intval(ceil($len / 2)); if ($len == 8) { for ($i = 0; $i < $half_len; ++$i) { $seq .= $codes['A'][$code{$i}]; diff --git a/composer.json b/composer.json index 98f2213..4339708 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tcpdf/tcpdf", - "version": "5.9.184", + "version": "5.9.186", "homepage": "http://www.tcpdf.org/", "type": "library", "description": "TCPDF is a PHP class for generating PDF files on-the-fly without requiring external extensions.", diff --git a/tcpdf.php b/tcpdf.php index 18f3c7d..b4e634f 100755 --- a/tcpdf.php +++ b/tcpdf.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 5.9.184 + * @version 5.9.186 */ // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file. @@ -150,7 +151,7 @@ require_once(dirname(__FILE__).'/config/tcpdf_config.php'); * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.
* @package com.tecnick.tcpdf * @brief PHP class for generating PDF documents without requiring external extensions. - * @version 5.9.184 + * @version 5.9.186 * @author Nicola Asuni - info@tecnick.com */ class TCPDF { @@ -161,7 +162,7 @@ class TCPDF { * Current TCPDF version. * @private */ - private $tcpdf_version = '5.9.184'; + private $tcpdf_version = '5.9.186'; // Protected properties @@ -5039,7 +5040,7 @@ class TCPDF { } else { $w = 600; } - return ($w * $this->FontSize / 1000); + return $this->getAbsFontMeasure($w); } /** @@ -5295,9 +5296,13 @@ class TCPDF { } } } + // check if the array of characters bounding boxes is defined + if (!isset($cbbox)) { + $cbbox = array(); + } // initialize subsetchars to contain default ASCII values (0-255) $subsetchars = array_fill(0, 256, true); - $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars)); + $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) { // we are inside an XObject template $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts; @@ -5418,16 +5423,14 @@ class TCPDF { * @since 5.9.152 (2012-03-23) */ public function getFontBBox() { - $result = array(); + $fbbox = array(); if (isset($this->CurrentFont['desc']['FontBBox'])) { - $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1)); - foreach ($bbox as $v) { - $result[] = (intval($v) * $this->FontSize / 1000); - } + $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1)); + $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox); } else { // Find max width if (isset($this->CurrentFont['desc']['MaxWidth'])) { - $maxw = (intval($this->CurrentFont['desc']['MaxWidth']) * $this->FontSize / 1000); + $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth'])); } else { $maxw = 0; if (isset($this->CurrentFont['desc']['MissingWidth'])) { @@ -5445,11 +5448,34 @@ class TCPDF { if ($maxw == 0) { $maxw = 600; } - $maxw = ($maxw * $this->FontSize / 1000); + $maxw = $this->getAbsFontMeasure($maxw); } - $result = array(0, -$this->FontDescent, $maxw, $this->FontAscent); + $fbbox = array(0, -$this->FontDescent, $maxw, $this->FontAscent); } - return $result; + return $fbbox; + } + + /** + * Convert a relative font measure into absolute value. + * @param $s (int) Font measure. + * @return float Absolute measure. + * @since 5.9.186 (2012-09-13) + */ + public function getAbsFontMeasure($s) { + return ($s * $this->FontSize / 1000); + } + + /** + * Returns the glyph bounding box of the specified character in the current font in user units. + * @param $char (int) Input character code. + * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined. + * @since 5.9.186 (2012-09-13) + */ + public function getCharBBox($char) { + if (isset($this->CurrentFont['cbbox'][$char])) { + return array_map(array($this,'getAbsFontMeasure'), $this->CurrentFont['cbbox'][intval($char)]); + } + return false; } /** @@ -5468,7 +5494,7 @@ class TCPDF { if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) { $descent = (- $fontinfo['desc']['Descent'] * $size / 1000); } else { - $descent = 1.219 * 0.24 * $size; + $descent = (1.219 * 0.24 * $size); } return ($descent / $this->k); } @@ -8757,13 +8783,14 @@ class TCPDF { /** * Defines the abscissa of the current position. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL). - * @param $x (float) The value of the abscissa. + * @param $x (float) The value of the abscissa in user units. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis. * @public * @since 1.2 * @see GetX(), GetY(), SetY(), SetXY() */ public function SetX($x, $rtloff=false) { + $x = floatval($x); if (!$rtloff AND $this->rtl) { if ($x >= 0) { $this->x = $this->w - $x; @@ -8788,7 +8815,7 @@ class TCPDF { /** * Moves the current abscissa back to the left margin and sets the ordinate. * If the passed value is negative, it is relative to the bottom of the page. - * @param $y (float) The value of the ordinate. + * @param $y (float) The value of the ordinate in user units. * @param $resetx (bool) if true (default) reset the X position. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis. * @public @@ -8796,6 +8823,7 @@ class TCPDF { * @see GetX(), GetY(), SetY(), SetXY() */ public function SetY($y, $resetx=true, $rtloff=false) { + $y = floatval($y); if ($resetx) { //reset x if (!$rtloff AND $this->rtl) { @@ -8832,6 +8860,41 @@ class TCPDF { $this->SetX($x, $rtloff); } + /** + * Set the absolute X coordinate of the current pointer. + * @param $x (float) The value of the abscissa in user units. + * @public + * @since 5.9.186 (2012-09-13) + * @see setAbsX(), setAbsY(), SetAbsXY() + */ + public function SetAbsX($x) { + $this->x = floatval($x); + } + + /** + * Set the absolute Y coordinate of the current pointer. + * @param $y (float) (float) The value of the ordinate in user units. + * @public + * @since 5.9.186 (2012-09-13) + * @see setAbsX(), setAbsY(), SetAbsXY() + */ + public function SetAbsY($y) { + $this->y = floatval($y); + } + + /** + * Set the absolute X and Y coordinates of the current pointer. + * @param $x (float) The value of the abscissa in user units. + * @param $y (float) (float) The value of the ordinate in user units. + * @public + * @since 5.9.186 (2012-09-13) + * @see setAbsX(), setAbsY(), SetAbsXY() + */ + public function SetAbsXY($x, $y) { + $this->SetAbsX($x); + $this->SetAbsY($y); + } + /** * Ouput input data and compress it if possible. * @param $data (string) Data to output. @@ -10235,12 +10298,13 @@ class TCPDF { * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder. * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1). * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4. + * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file. * @return (string) TCPDF font name. * @author Nicola Asuni * @public * @since 5.9.123 (2010-09-30) */ - public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1) { + public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false) { if (!file_exists($fontfile)) { $this->Error('Could not find file: '.$fontfile.''); } @@ -10952,8 +11016,18 @@ class TCPDF { $fmetric['MissingWidth'] = $cw[0]; $fmetric['cw'] = ''; for ($cid = 0; $cid <= 65535; ++$cid) { - if (isset($ctg[$cid]) AND isset($cw[$ctg[$cid]])) { - $fmetric['cw'] .= ','.$cid.'=>'.$cw[$ctg[$cid]]; + if (isset($ctg[$cid])) { + if (isset($cw[$ctg[$cid]])) { + $fmetric['cw'] .= ','.$cid.'=>'.$cw[$ctg[$cid]]; + } + if ($addcbbox AND isset($indexToLoc[$ctg[$cid]])) { + $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[$cid]]); + $xMin = round($this->_getFWORD($font, $offset + 2)) * $urk; + $yMin = round($this->_getFWORD($font, $offset + 4)) * $urk; + $xMax = round($this->_getFWORD($font, $offset + 6)) * $urk; + $yMax = round($this->_getFWORD($font, $offset + 8)) * $urk; + $fmetric['cbbox'] .= ','.$cid.'=>array('.$xMin.','.$yMin.','.$xMax.','.$yMax.')'; + } } } } // end of true type @@ -11045,6 +11119,9 @@ class TCPDF { $pfile .= '\'MaxWidth\'=>'.$fmetric['MaxWidth'].','; $pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].''; $pfile .= ');'."\n"; + if (isset($fmetric['cbbox'])) { + $pfile .= '$cbbox=array('.substr($fmetric['cbbox'], 1).');'."\n"; + } $pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n"; $pfile .= '// --- EOF ---'."\n"; // store file @@ -11605,7 +11682,9 @@ class TCPDF { } else { $prevint = false; } - unset($range[$k]['interval']); + if (isset($range[$k]['interval'])) { + unset($range[$k]['interval']); + } --$nextk; } else { $prevint = false;