From 3fa01d8e990f67973bc65a6e5cc3c6b6995047e3 Mon Sep 17 00:00:00 2001 From: nicolaasuni Date: Wed, 20 Mar 2013 18:27:44 +0000 Subject: [PATCH] 6.0.003 (2013-03-20) - A bug related to non-unicode mode was fixed. --- CHANGELOG.TXT | 3 +++ README.TXT | 4 ++-- include/tcpdf_fonts.php | 39 ++++++++++++++++++++++++--------------- include/tcpdf_static.php | 4 ++-- tcpdf.php | 40 ++++++++++++++++++++-------------------- 5 files changed, 51 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index ee32350..120f727 100755 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -1,3 +1,6 @@ +6.0.003 (2013-03-20) + - A bug related to non-unicode mode was fixed. + 6.0.002 (2013-03-18) - _getFIXED call on tcpdf_fonts.php was fixed. diff --git a/README.TXT b/README.TXT index 3d8d5b2..0616333 100755 --- a/README.TXT +++ b/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 6.0.002 -Release date: 2013-03-18 +Version: 6.0.003 +Release date: 2013-03-20 Author: Nicola Asuni Copyright (c) 2002-2013: diff --git a/include/tcpdf_fonts.php b/include/tcpdf_fonts.php index 67ece18..16de474 100644 --- a/include/tcpdf_fonts.php +++ b/include/tcpdf_fonts.php @@ -1,9 +1,9 @@ = 0) { + return $char; + } } $bytes = array(); // array containing single character byte sequences $countbytes = 0; @@ -1817,29 +1819,36 @@ class TCPDF_FONTS { * Converts UTF-8 strings to codepoints array.
* Invalid byte sequences will be replaced with 0xFFFD (replacement character)
* @param $str (string) string to process. + * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise. * @param $currentfont (array) Reference to current font array. * @return array containing codepoints (UTF-8 characters values) * @author Nicola Asuni * @public static */ - public static function UTF8StringToArray($str, &$currentfont) { - // requires PCRE unicode support turned on - $uchars = preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY); - $uarr = array_map(array('self', 'uniord'), $uchars); - $currentfont['subsetchars'] += array_fill_keys($uarr, true); - return $uarr; + public static function UTF8StringToArray($str, $isunicode=true, &$currentfont) { + if ($isunicode) { + // requires PCRE unicode support turned on + $chars = preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY); + $carr = array_map(array('self', 'uniord'), $chars); + } else { + $chars = str_split($str); + $carr = array_map('ord', $chars); + } + $currentfont['subsetchars'] += array_fill_keys($carr, true); + return $carr; } /** * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.
* @param $str (string) string to process. + * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise. * @param $currentfont (array) Reference to current font array. * @return string * @since 3.2.000 (2008-06-23) * @public static */ - public static function UTF8ToLatin1($str, &$currentfont) { - $unicode = self::UTF8StringToArray($str, $currentfont); // array containing UTF-8 unicode values + public static function UTF8ToLatin1($str, $isunicode=true, &$currentfont) { + $unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values return self::UTF8ArrToLatin1($unicode); } @@ -1858,7 +1867,7 @@ class TCPDF_FONTS { if (!$isunicode) { return $str; // string is not in unicode } - $unicode = self::UTF8StringToArray($str, $currentfont); // array containing UTF-8 unicode values + $unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values return self::arrUTF8ToUTF16BE($unicode, $setbom); } @@ -1875,7 +1884,7 @@ class TCPDF_FONTS { * @public static */ public static function utf8StrRev($str, $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) { - return self::utf8StrArrRev(self::UTF8StringToArray($str, $currentfont), $str, $setbom, $forcertl, $isunicode, $currentfont); + return self::utf8StrArrRev(self::UTF8StringToArray($str, $isunicode, $currentfont), $str, $setbom, $forcertl, $isunicode, $currentfont); } /** diff --git a/include/tcpdf_static.php b/include/tcpdf_static.php index 0aed193..4a019bb 100644 --- a/include/tcpdf_static.php +++ b/include/tcpdf_static.php @@ -3,7 +3,7 @@ // File name : tcpdf_static.php // Version : 1.0.000 // Begin : 2002-08-03 -// Last Update : 2013-03-16 +// Last Update : 2013-03-20 // Author : Nicola Asuni - Tecnick.com LTD - Manor Coach House, Church Hill, Aldershot, Hants, GU12 4RQ, UK - www.tecnick.com - info@tecnick.com // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 // ------------------------------------------------------------------- @@ -55,7 +55,7 @@ class TCPDF_STATIC { * Current TCPDF version. * @private static */ - private static $tcpdf_version = '6.0.002'; + private static $tcpdf_version = '6.0.003'; /** * String alias for total number of pages. diff --git a/tcpdf.php b/tcpdf.php index e5a5550..1a7605b 100755 --- a/tcpdf.php +++ b/tcpdf.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 6.0.002 + * @version 6.0.003 */ if (!defined('K_TCPDF_EXTERNAL_CONFIG')) { @@ -168,7 +168,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.002 + * @version 6.0.003 * @author Nicola Asuni - info@tecnick.com */ class TCPDF { @@ -1859,7 +1859,7 @@ class TCPDF { * @param $unit (string) User measure unit. Possible values are:
A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat(). * @param $unicode (boolean) TRUE means that the input text is unicode (default = true) - * @param $encoding (string) Charset encoding; default is UTF-8. + * @param $encoding (string) Charset encoding (used only when converting back html entities); default is UTF-8. * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower). * @param $pdfa (boolean) If TRUE set the document to PDF/A mode. * @public @@ -4022,7 +4022,7 @@ class TCPDF { * @since 1.2 */ public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) { - return $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($s, $this->CurrentFont), $s, $this->tmprtl, $this->isunicode, $this->CurrentFont), $fontname, $fontstyle, $fontsize, $getarray); + return $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont), $s, $this->tmprtl, $this->isunicode, $this->CurrentFont), $fontname, $fontstyle, $fontsize, $getarray); } /** @@ -4126,7 +4126,7 @@ class TCPDF { */ public function GetNumChars($s) { if ($this->isUnicodeFont()) { - return count(TCPDF_FONTS::UTF8StringToArray($s, $this->CurrentFont)); + return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont)); } return strlen($s); } @@ -4643,7 +4643,7 @@ class TCPDF { public function isCharDefined($char, $font='', $style='') { if (is_string($char)) { // get character code - $char = TCPDF_FONTS::UTF8StringToArray($char, $this->CurrentFont); + $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont); $char = $char[0]; } if (TCPDF_STATIC::empty_string($font)) { @@ -4676,7 +4676,7 @@ class TCPDF { } $fontdata = $this->AddFont($font, $style); $fontinfo = $this->getFontBuffer($fontdata['fontkey']); - $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->CurrentFont); + $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont); foreach ($uniarr as $k => $chr) { if (!isset($fontinfo['cw'][$chr])) { // this character is missing on the selected font @@ -5251,9 +5251,9 @@ class TCPDF { $txt2 = $txt; if ($this->isunicode) { if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) { - $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->CurrentFont); + $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont); } else { - $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->CurrentFont); // array of UTF-8 unicode values + $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont); // replace thai chars (if any) if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) { @@ -6153,7 +6153,7 @@ class TCPDF { } $lines = 1; $sum = 0; - $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont); + $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont); $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true); $length = count($chars); $lastSeparator = -1; @@ -6298,7 +6298,7 @@ class TCPDF { // get a char width $chrwidth = $this->GetCharWidth(46); // dot character // get array of unicode values - $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->CurrentFont); + $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont); // calculate maximum width for a single character on string $chrw = $this->GetArrStringWidth($chars, '', '', 0, true); array_walk($chrw, array($this, 'getRawCharWidth')); @@ -7784,9 +7784,9 @@ class TCPDF { $u = '{'.$a.'}'; $alias['u'][] = TCPDF_STATIC::_escape($u); if ($this->isunicode) { - $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->CurrentFont)); + $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont)); $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont)); - $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->CurrentFont)); + $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont)); $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont)); } $alias['a'][] = TCPDF_STATIC::_escape($a); @@ -10236,7 +10236,7 @@ class TCPDF { 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->CurrentFont); + $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); @@ -10728,7 +10728,7 @@ class TCPDF { */ protected function _fixAES256Password($password) { $psw = ''; // password to be returned - $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont); + $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont); foreach ($psw_array as $c) { $psw .= TCPDF_FONTS::unichr($c, $this->isunicode); } @@ -21769,7 +21769,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: return $word; } if (isset($dictionary[$word_string])) { - return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->CurrentFont); + return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont); } // suround word with '_' characters $tmpword = array_merge(array(95), $word, array(95)); @@ -21780,7 +21780,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: for ($i = $charmin; $i <= $imax; ++$i) { $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode)); if (isset($patterns[$subword])) { - $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->CurrentFont); + $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont); $pattern_length = count($pattern); $digits = 1; for ($j = 0; $j < $pattern_length; ++$j) { @@ -21835,7 +21835,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns); } // get array of characters - $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->CurrentFont); + $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont); // for each char foreach ($unichars as $char) { if ((!$intag) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {