From 9dbf6cb21872aae5a77a71db34f29ea33eac8564 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?=
Date: Mon, 30 Sep 2013 14:21:53 +0200
Subject: [PATCH] Update TCPDF to 6.0.036
Full changelog:
6.0.036 (2013-09-29)
- Methods for registration bars and crop marks were extended to support registration color (see example n. 56).
- New default spot colors were added to tcpdf_colors.php, including the 'All' and 'None' special registration colors.
6.0.035 (2013-09-25)
- TCPDF_PARSER class was improved.
6.0.034 (2013-09-24)
- Bug #839 "Error in xref parsing in mixed newline chars" was fixed.
6.0.033 (2013-09-23)
- Bug fix related to PNG image transparency using GD library.
6.0.032 (2013-09-23)
- Bug #838 "Fatal error when imagick cannot handle the image, even though GD is available and can" was fixed.
6.0.031 (2013-09-18)
- Bug #836 "Optional EOL marker before endstream" was fixed.
- Some additional controls were added to avoid "division by zero" error with badly formatted input.
6.0.030 (2013-09-17)
- Bug #835 "PDF417 and Cyrilic simbols" was fixed.
6.0.029 (2013-09-15)
- Constants K_TCPDF_PARSER_THROW_EXCEPTION_ERROR and K_TCPDF_PARSER_IGNORE_DECODING_ERRORS where removed in favor of a new configuration array in the TCPDF_PARSER class.
- The TCPDF_PARSER class can now be configured using the new $cfg parameter.
6.0.028 (2013-09-15)
- A debug print_r was removed form tcpdf_parser.php.
- TCPDF_FILTERS class now throws an exception in case of error.
- TCPDF_PARSER class now throws an exception in case of error unless you define the constant K_TCPDF_PARSER_THROW_EXCEPTION_ERROR to false.
- The constant K_TCPDF_PARSER_IGNORE_DECODING_ERRORS can be set to tru eto ignore decoding errors on TCPDF_PARSER.
6.0.027 (2013-09-14)
- A bug in tcpdf_parser wen parsing hexadecimal strings was fixed.
- A bug in tcpdf_parser wen looking for statxref was fixed.
- A bug on RC4 encryption was fixed.
6.0.026 (2013-09-14)
- A bug in tcpdf_parser wen decoding streams was fixed.
6.0.025 (2013-09-04)
- A pregSplit() bug was fixed.
- Improved content loading from URLs.
- Improved font path loading.
---
libraries/tcpdf/README.TXT | 5 +-
libraries/tcpdf/include/tcpdf_colors.php | 21 +-
libraries/tcpdf/include/tcpdf_fonts.php | 28 +-
libraries/tcpdf/include/tcpdf_static.php | 90 +++-
libraries/tcpdf/tcpdf.php | 520 +++++++++++------------
5 files changed, 381 insertions(+), 283 deletions(-)
diff --git a/libraries/tcpdf/README.TXT b/libraries/tcpdf/README.TXT
index 5016cdb21a..2c79a62c9a 100644
--- a/libraries/tcpdf/README.TXT
+++ b/libraries/tcpdf/README.TXT
@@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076
------------------------------------------------------------
Name: TCPDF
-Version: 6.0.024
-Release date: 2013-09-02
+Version: 6.0.036
+Release date: 2013-09-29
Author: Nicola Asuni
Copyright (c) 2002-2013:
@@ -107,4 +107,5 @@ Third party fonts:
The binary files (.z) that begins with the prefix "ae" have been extracted from the Arabeyes.org collection (GNU-GPLv2).
Link : http://projects.arabeyes.org/
+
============================================================
diff --git a/libraries/tcpdf/include/tcpdf_colors.php b/libraries/tcpdf/include/tcpdf_colors.php
index 37b91f4d18..2369be6f0e 100644
--- a/libraries/tcpdf/include/tcpdf_colors.php
+++ b/libraries/tcpdf/include/tcpdf_colors.php
@@ -1,9 +1,9 @@
array( 0, 0, 0, 0, 'None'),
+ 'all' => array(100, 100, 100, 100, 'All'),
+ // standard CMYK colors
+ 'cyan' => array(100, 0, 0, 0, 'Cyan'),
+ 'magenta' => array( 0, 100, 0, 0, 'Magenta'),
+ 'yellow' => array( 0, 0, 100, 0, 'Yellow'),
+ 'key' => array( 0, 0, 0, 100, 'Key'),
+ // alias
+ 'white' => array( 0, 0, 0, 0, 'White'),
+ 'black' => array( 0, 0, 0, 100, 'Black'),
+ // standard RGB colors
+ 'red' => array( 0, 100, 100, 0, 'Red'),
+ 'green' => array(100, 0, 100, 0, 'Green'),
+ 'blue' => array(100, 100, 0, 0, 'Blue'),
// the following are just examples, fill the array with your own values
'mytcpdfblack' => array(0, 0, 0, 100, 'My TCPDF Black'),
'mytcpdfred' => array(30, 100, 90, 10, 'My TCPDF Red'),
diff --git a/libraries/tcpdf/include/tcpdf_fonts.php b/libraries/tcpdf/include/tcpdf_fonts.php
index 7aa94adcec..53f4eb5d60 100644
--- a/libraries/tcpdf/include/tcpdf_fonts.php
+++ b/libraries/tcpdf/include/tcpdf_fonts.php
@@ -1,9 +1,9 @@
* @param $unicode (array) array containing UTF-8 unicode values
diff --git a/libraries/tcpdf/include/tcpdf_static.php b/libraries/tcpdf/include/tcpdf_static.php
index b7a0ffc074..937deb0d18 100644
--- a/libraries/tcpdf/include/tcpdf_static.php
+++ b/libraries/tcpdf/include/tcpdf_static.php
@@ -1,9 +1,9 @@
* @package com.tecnick.tcpdf
* @author Nicola Asuni
- * @version 1.0.000
+ * @version 1.0.002
*/
/**
@@ -46,7 +46,7 @@
* Static methods used by the TCPDF class.
* @package com.tecnick.tcpdf
* @brief PHP class for generating PDF documents without requiring external extensions.
- * @version 1.0.000
+ * @version 1.0.002
* @author Nicola Asuni - info@tecnick.com
*/
class TCPDF_STATIC {
@@ -55,7 +55,7 @@ class TCPDF_STATIC {
* Current TCPDF version.
* @private static
*/
- private static $tcpdf_version = '6.0.024';
+ private static $tcpdf_version = '6.0.036';
/**
* String alias for total number of pages.
@@ -1428,7 +1428,7 @@ class TCPDF_STATIC {
* @public static
*/
public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) {
- if (function_exists('mcrypt_decrypt') AND ($out = @mcrypt_decrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
+ if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
// try to use mcrypt function if exist
return $out;
}
@@ -2748,12 +2748,88 @@ class TCPDF_STATIC {
$ret[] = "\n";
$subject = substr($subject, ($nl + 1));
}
- if (!empty($subject)) {
+ if (strlen($subject) > 0) {
$ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags));
}
return $ret;
}
+ /**
+ * Reads entire file into a string.
+ * The file can be also an URL.
+ * @param $file (string) Name of the file or URL to read.
+ * @return The function returns the read data or FALSE on failure.
+ * @author Nicola Asuni
+ * @since 6.0.025
+ * @public static
+ */
+ public static function fileGetContents($file) {
+ // array of possible alternative paths/URLs
+ $alt = array($file);
+ // replace URL relative path with full real server path
+ if ((strlen($file) > 1)
+ AND ($file[0] == '/')
+ AND ($file[1] != '/')
+ AND !empty($_SERVER['DOCUMENT_ROOT'])
+ AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
+ $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']);
+ if (($findroot === false) OR ($findroot > 1)) {
+ if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
+ $tmp = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$file;
+ } else {
+ $tmp = $_SERVER['DOCUMENT_ROOT'].$file;
+ }
+ $alt[] = htmlspecialchars_decode(urldecode($tmp));
+ }
+ }
+ // URL mode
+ $url = $file;
+ // check for missing protocol
+ if (preg_match('%^/{2}%', $url)) {
+ if (preg_match('%^([^:]+:)//%i', K_PATH_URL, $match)) {
+ $url = $match[1].str_replace(' ', '%20', $url);
+ $alt[] = $url;
+ }
+ }
+ $urldata = @parse_url($url);
+ if (!isset($urldata['query']) OR (strlen($urldata['query']) <= 0)) {
+ if (strpos($url, K_PATH_URL) === 0) {
+ // convert URL to full server path
+ $tmp = str_replace(K_PATH_URL, K_PATH_MAIN, $url);
+ $tmp = htmlspecialchars_decode(urldecode($tmp));
+ $alt[] = $tmp;
+ }
+ }
+ foreach ($alt as $f) {
+ $ret = @file_get_contents($f);
+ if (($ret === FALSE)
+ AND !ini_get('allow_url_fopen')
+ AND function_exists('curl_init')
+ AND preg_match('%^(https?|ftp)://%', $f)) {
+ // try to get remote file data using cURL
+ $cs = curl_init(); // curl session
+ curl_setopt($cs, CURLOPT_URL, $file);
+ curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
+ curl_setopt($cs, CURLOPT_FAILONERROR, true);
+ curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
+ if ((ini_get('open_basedir') == '') AND (!ini_get('safe_mode'))) {
+ curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);
+ }
+ curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
+ curl_setopt($cs, CURLOPT_TIMEOUT, 30);
+ curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, false);
+ curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF');
+ $ret = curl_exec($cs);
+ curl_close($cs);
+ }
+ if ($ret !== FALSE) {
+ break;
+ }
+ }
+ return $ret;
+ }
+
} // END OF TCPDF_STATIC CLASS
//============================================================+
diff --git a/libraries/tcpdf/tcpdf.php b/libraries/tcpdf/tcpdf.php
index 36739341c4..4d2e71235c 100644
--- a/libraries/tcpdf/tcpdf.php
+++ b/libraries/tcpdf/tcpdf.php
@@ -1,9 +1,9 @@
value attribute.
-// Patrick Benny for text stretch suggestion on Cell().
-// Johannes Güntert for JavaScript support.
-// Denis Van Nuffelen for Dynamic Form.
-// Jacek Czekaj for multibyte justification
-// Anthony Ferrara for the reintroduction of legacy image methods.
-// Sourceforge user 1707880 (hucste) for line-through mode.
-// Larry Stanbery for page groups.
-// Martin Hall-May for transparency.
-// Aaron C. Spike for Polycurve method.
-// Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
-// Moritz Wagner and Andreas Wurmser for graphic functions.
-// Andrew Whitehead for core fonts support.
-// Esteban Joël Marín for OpenType font conversion.
-// Teus Hagen for several suggestions and fixes.
-// Yukihiro Nakadaira for CID-0 CJK fonts fixes.
-// Kosmas Papachristos for some CSS improvements.
-// Marcel Partap for some fixes.
-// Won Kyu Park for several suggestions, fixes and patches.
-// Dominik Dzienia for QR-code support.
-// Laurent Minguet for some suggestions.
-// Christian Deligant for some suggestions and fixes.
-// Travis Harris for crop mark suggestion.
-// Aleksey Kuznetsov for some suggestions and text shadows.
-// Jim Hanlon for several suggestions and patches.
-// Anyone else that has reported a bug or sent a suggestion.
+// * PDF/A-1b support
//============================================================+
/**
@@ -139,7 +104,7 @@
* Tools to encode your unicode fonts are on fonts/utils directory.
* @package com.tecnick.tcpdf
* @author Nicola Asuni
- * @version 6.0.024
+ * @version 6.0.036
*/
// TCPDF configuration
@@ -163,7 +128,7 @@ require_once(dirname(__FILE__).'/include/tcpdf_static.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 6.0.024
+ * @version 6.0.036
* @author Nicola Asuni - info@tecnick.com
*/
class TCPDF {
@@ -2919,8 +2884,7 @@ class TCPDF {
}
/**
- * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
- * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
+ * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
* @param $msg (string) The error message
* @public
* @since 1.0
@@ -2928,8 +2892,7 @@ class TCPDF {
public function Error($msg) {
// unset all class variables
$this->_destroy(true);
- // exit program and print error
- if (!K_TCPDF_THROW_EXCEPTION_ERROR) {
+ if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
die('TCPDF ERROR: '.$msg);
} else {
throw new Exception('TCPDF ERROR: '.$msg);
@@ -3721,7 +3684,7 @@ class TCPDF {
public function setSpotColor($type, $name, $tint=100) {
$spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
if ($spotcolor === false) {
- $this->Error('Undefined spot color: '.$name.', you must add it on the spotcolors.php file.');
+ $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
}
$tint = (max(0, min(100, $tint)) / 100);
$pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
@@ -4275,33 +4238,22 @@ class TCPDF {
$fontdir .= '/';
}
}
- $missing_style = false; // true when the font style variation is missing
+ // true when the font style variation is missing
+ $missing_style = false;
// search and include font file
if (TCPDF_STATIC::empty_string($fontfile) OR (!@file_exists($fontfile))) {
// build a standard filenames for specified font
$tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
- // search files on various directories
- if (($fontdir !== false) AND @file_exists($fontdir.$tmp_fontfile)) {
- $fontfile = $fontdir.$tmp_fontfile;
- } elseif (@file_exists(TCPDF_FONTS::_getfontpath().$tmp_fontfile)) {
- $fontfile = TCPDF_FONTS::_getfontpath().$tmp_fontfile;
- } elseif (@file_exists($tmp_fontfile)) {
- $fontfile = $tmp_fontfile;
- } elseif (!TCPDF_STATIC::empty_string($style)) {
+ $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
+ if (TCPDF_STATIC::empty_string($fontfile)) {
$missing_style = true;
// try to remove the style part
$tmp_fontfile = str_replace(' ', '', $family).'.php';
- if (($fontdir !== false) AND @file_exists($fontdir.$tmp_fontfile)) {
- $fontfile = $fontdir.$tmp_fontfile;
- } elseif (@file_exists(TCPDF_FONTS::_getfontpath().$tmp_fontfile)) {
- $fontfile = TCPDF_FONTS::_getfontpath().$tmp_fontfile;
- } else {
- $fontfile = $tmp_fontfile;
- }
+ $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
}
}
// include font file
- if (@file_exists($fontfile)) {
+ if (!TCPDF_STATIC::empty_string($fontfile) AND (@file_exists($fontfile))) {
include($fontfile);
} else {
$this->Error('Could not include font definition file: '.$family.'');
@@ -4859,27 +4811,31 @@ class TCPDF {
}
reset($this->embeddedfiles);
foreach ($this->embeddedfiles as $filename => $filedata) {
- // update name tree
- $this->efnames[$filename] = $filedata['f'].' 0 R';
- // embedded file specification object
- $out = $this->_getobj($filedata['f'])."\n";
- $out .= '<_datastring($filename, $filedata['f']).' /EF <> >>';
- $out .= "\n".'endobj';
- $this->_out($out);
- // embedded file object
- $data = file_get_contents($filedata['file']);
- $filter = '';
- $rawsize = strlen($data);
- if ($this->compress) {
- $data = gzcompress($data);
- $filter = ' /Filter /FlateDecode';
+ $data = TCPDF_STATIC::fileGetContents($filedata['file']);
+ if ($data !== FALSE) {
+ $rawsize = strlen($data);
+ if ($rawsize > 0) {
+ // update name tree
+ $this->efnames[$filename] = $filedata['f'].' 0 R';
+ // embedded file specification object
+ $out = $this->_getobj($filedata['f'])."\n";
+ $out .= '<_datastring($filename, $filedata['f']).' /EF <> >>';
+ $out .= "\n".'endobj';
+ $this->_out($out);
+ // embedded file object
+ $filter = '';
+ if ($this->compress) {
+ $data = gzcompress($data);
+ $filter = ' /Filter /FlateDecode';
+ }
+ $stream = $this->_getrawstream($data, $filedata['n']);
+ $out = $this->_getobj($filedata['n'])."\n";
+ $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <> >>';
+ $out .= ' stream'."\n".$stream."\n".'endstream';
+ $out .= "\n".'endobj';
+ $this->_out($out);
+ }
}
- $stream = $this->_getrawstream($data, $filedata['n']);
- $out = $this->_getobj($filedata['n'])."\n";
- $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <> >>';
- $out .= ' stream'."\n".$stream."\n".'endstream';
- $out .= "\n".'endobj';
- $this->_out($out);
}
}
@@ -5390,7 +5346,7 @@ class TCPDF {
// get string width without spaces
$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;
+ $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) {
// word spacing is affected by stretching
$spacewidth /= ($this->font_stretching / 100);
@@ -6707,10 +6663,16 @@ class TCPDF {
if ($w <= 0) {
// set maximum width
$w = ($this->w - $this->lMargin - $this->rMargin);
+ if ($w <= 0) {
+ $w = 1;
+ }
}
if ($h <= 0) {
// set maximum height
$h = ($this->PageBreakTrigger - $this->tMargin);
+ if ($h <= 0) {
+ $h = 1;
+ }
}
// resize the block to be vertically contained on a single page or single column
if ($fitonpage OR $this->AutoPageBreak) {
@@ -6805,6 +6767,7 @@ class TCPDF {
// check page for no-write regions and adapt page margins if necessary
list($x, $y) = $this->checkPageRegions($h, $x, $y);
$exurl = ''; // external streams
+ $imsize = FALSE;
// check if we are passing an image as file or string
if ($file[0] === '@') {
// image from string
@@ -6823,30 +6786,9 @@ class TCPDF {
if (@file_exists($file)) {
// get image dimensions
$imsize = @getimagesize($file);
- } else {
- $imsize = FALSE;
}
if ($imsize === FALSE) {
- if (function_exists('curl_init')) {
- // try to get remote file data using cURL
- $cs = curl_init(); // curl session
- curl_setopt($cs, CURLOPT_URL, $file);
- curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
- curl_setopt($cs, CURLOPT_FAILONERROR, true);
- curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
- if ((ini_get('open_basedir') == '') AND (!ini_get('safe_mode'))) {
- curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);
- }
- curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt($cs, CURLOPT_TIMEOUT, 30);
- curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF');
- $imgdata = curl_exec($cs);
- curl_close($cs);
- } else {
- $imgdata = @file_get_contents($file);
- }
+ $imgdata = TCPDF_STATIC::fileGetContents($file);
}
}
if (isset($imgdata) AND ($imgdata !== FALSE)) {
@@ -7013,8 +6955,8 @@ class TCPDF {
return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
}
}
- if (!$info) {
- if (function_exists($gdfunction)) {
+ if (($info === false) AND function_exists($gdfunction)) {
+ try {
// GD library
$img = $gdfunction($file);
if ($resize) {
@@ -7035,42 +6977,49 @@ class TCPDF {
$info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality);
}
}
- } elseif (extension_loaded('imagick')) {
+ } catch(Exception $e) {
+ $info = false;
+ }
+ }
+ if (($info === false) AND extension_loaded('imagick')) {
+ try {
// ImageMagick library
$img = new Imagick();
if ($type == 'SVG') {
// get SVG file content
- $svgimg = file_get_contents($file);
- // get width and height
- $regs = array();
- if (preg_match('/