← All changes
|
vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php
+151
-142
2.3.0
→
4.17.0
View file →
| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | //============================================================+ |
| 3 | 3 | // File name : tcpdf_fonts.php |
| 4 | -// Version : 1.1.0 | |
| 4 | +// Version : 1.1.1 | |
| 5 | 5 | // Begin : 2008-01-01 |
| 6 | -// Last Update : 2014-12-10 | |
| 6 | +// Last Update : 2024-12-23 | |
| 7 | 7 | // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - [email protected] |
| 8 | -// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html) | |
| 8 | +// License : GNU-LGPL v3 (https://www.gnu.org/copyleft/lesser.html) | |
| 9 | 9 | // ------------------------------------------------------------------- |
| 10 | -// Copyright (C) 2008-2014 Nicola Asuni - Tecnick.com LTD | |
| 10 | +// Copyright (C) 2008-2026 Nicola Asuni - Tecnick.com LTD | |
| 11 | 11 | // |
| 12 | 12 | // This file is part of TCPDF software library. |
| 13 | 13 | // |
| 14 | 14 | // TCPDF is free software: you can redistribute it and/or modify it |
| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 22 | 22 | // See the GNU Lesser General Public License for more details. |
| 23 | 23 | // |
| 24 | 24 | // You should have received a copy of the GNU Lesser General Public License |
| 25 | -// along with TCPDF. If not, see <http://www.gnu.org/licenses/>. | |
| 25 | +// along with TCPDF. If not, see <https://www.gnu.org/licenses/>. | |
| 26 | 26 | // |
| 27 | 27 | // See LICENSE.TXT file for more information. |
| 28 | 28 | // ------------------------------------------------------------------- |
| 29 | 29 | // |
| @@ -41,9 +41,9 @@ | ||
| 41 | 41 | /** |
| 42 | 42 | * @class TCPDF_FONTS |
| 43 | 43 | * Font methods for TCPDF library. |
| 44 | 44 | * @package com.tecnick.tcpdf |
| 45 | - * @version 1.1.0 | |
| 45 | + * @version 1.1.1 | |
| 46 | 46 | * @author Nicola Asuni - [email protected] |
| 47 | 47 | */ |
| 48 | 48 | class TCPDF_FONTS { |
| 49 | 49 | |
| @@ -54,24 +54,24 @@ | ||
| 54 | 54 | protected static $cache_uniord = array(); |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable). |
| 58 | - * @param $fontfile (string) Font file (full path). | |
| 59 | - * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional. | |
| 60 | - * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats. | |
| 61 | - * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font. | |
| 62 | - * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder. | |
| 63 | - * @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). | |
| 64 | - * @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. | |
| 65 | - * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file. | |
| 66 | - * @param $link (boolean) If true link to system font instead of copying the font data (not transportable) - Note: do not work with Type1 fonts. | |
| 67 | - * @return (string) TCPDF font name or boolean false in case of error. | |
| 58 | + * @param string $fontfile Font file (full path). | |
| 59 | + * @param string $fonttype Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional. | |
| 60 | + * @param string $enc Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats. | |
| 61 | + * @param int $flags Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font. | |
| 62 | + * @param string $outpath Output path for generated font files (must be writeable by the web server). Leave empty for default font folder. | |
| 63 | + * @param int $platid Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1). | |
| 64 | + * @param int $encid 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. | |
| 65 | + * @param boolean $addcbbox If true includes the character bounding box information on the php font file. | |
| 66 | + * @param boolean $link If true link to system font instead of copying the font data (not transportable) - Note: do not work with Type1 fonts. | |
| 67 | + * @return string|false TCPDF font name or boolean false in case of error. | |
| 68 | 68 | * @author Nicola Asuni |
| 69 | 69 | * @since 5.9.123 (2010-09-30) |
| 70 | 70 | * @public static |
| 71 | 71 | */ |
| 72 | 72 | public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false, $link=false) { |
| 73 | - if (!file_exists($fontfile)) { | |
| 73 | + if (!TCPDF_STATIC::file_exists($fontfile)) { | |
| 74 | 74 | // Could not find file |
| 75 | 75 | return false; |
| 76 | 76 | } |
| 77 | 77 | // font metrics |
| @@ -94,9 +94,9 @@ | ||
| 94 | 94 | if (empty($outpath)) { |
| 95 | 95 | $outpath = self::_getfontpath(); |
| 96 | 96 | } |
| 97 | 97 | // check if this font already exist |
| 98 | - if (@file_exists($outpath.$font_name.'.php')) { | |
| 98 | + if (@TCPDF_STATIC::file_exists($outpath.$font_name.'.php')) { | |
| 99 | 99 | // this font already exist (delete it from fonts folder to rebuild it) |
| 100 | 100 | return $font_name; |
| 101 | 101 | } |
| 102 | 102 | $fmetric['file'] = $font_name; |
| @@ -190,31 +190,32 @@ | ||
| 190 | 190 | fwrite($fp, gzcompress($data)); |
| 191 | 191 | fclose($fp); |
| 192 | 192 | // get font info |
| 193 | 193 | $fmetric['Flags'] = $flags; |
| 194 | - preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches); | |
| 194 | + preg_match ('#/FullName[\s]*+\(([^\)]*+)#', $font, $matches); | |
| 195 | 195 | $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]); |
| 196 | - preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches); | |
| 197 | - $fmetric['bbox'] = trim($matches[1]); | |
| 198 | - $bv = explode(' ', $fmetric['bbox']); | |
| 199 | - $fmetric['Ascent'] = intval($bv[3]); | |
| 200 | - $fmetric['Descent'] = intval($bv[1]); | |
| 201 | - preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches); | |
| 196 | + preg_match('#/FontBBox[\s]*+{([^}]*+)#', $font, $matches); | |
| 197 | + $rawbvl = explode(' ', trim($matches[1])); | |
| 198 | + $bvl = [(int) $rawbvl[0], (int) $rawbvl[1], (int) $rawbvl[2], (int) $rawbvl[3]]; | |
| 199 | + $fmetric['bbox'] = implode(' ', $bvl); | |
| 200 | + $fmetric['Ascent'] = $bvl[3]; | |
| 201 | + $fmetric['Descent'] = $bvl[1]; | |
| 202 | + preg_match('#/ItalicAngle[\s]*+([0-9\+\-]*+)#', $font, $matches); | |
| 202 | 203 | $fmetric['italicAngle'] = intval($matches[1]); |
| 203 | 204 | if ($fmetric['italicAngle'] != 0) { |
| 204 | 205 | $fmetric['Flags'] |= 64; |
| 205 | 206 | } |
| 206 | - preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches); | |
| 207 | + preg_match('#/UnderlinePosition[\s]*+([0-9\+\-]*+)#', $font, $matches); | |
| 207 | 208 | $fmetric['underlinePosition'] = intval($matches[1]); |
| 208 | - preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches); | |
| 209 | + preg_match('#/UnderlineThickness[\s]*+([0-9\+\-]*+)#', $font, $matches); | |
| 209 | 210 | $fmetric['underlineThickness'] = intval($matches[1]); |
| 210 | - preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches); | |
| 211 | + preg_match('#/isFixedPitch[\s]*+([^\s]*+)#', $font, $matches); | |
| 211 | 212 | if ($matches[1] == 'true') { |
| 212 | 213 | $fmetric['Flags'] |= 1; |
| 213 | 214 | } |
| 214 | 215 | // get internal map |
| 215 | 216 | $imap = array(); |
| 216 | - if (preg_match_all('#dup[\s]([0-9]+)[\s]*/([^\s]*)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) { | |
| 217 | + if (preg_match_all('#dup[\s]([0-9]+)[\s]*+/([^\s]*+)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) { | |
| 217 | 218 | foreach ($fmap as $v) { |
| 218 | 219 | $imap[$v[2]] = $v[1]; |
| 219 | 220 | } |
| 220 | 221 | } |
| @@ -228,24 +229,24 @@ | ||
| 228 | 229 | $chr = ord($encrypted[$i]); |
| 229 | 230 | $eplain .= chr($chr ^ ($r >> 8)); |
| 230 | 231 | $r = ((($chr + $r) * $c1 + $c2) % 65536); |
| 231 | 232 | } |
| 232 | - if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) { | |
| 233 | + if (preg_match('#/ForceBold[\s]*+([^\s]*+)#', $eplain, $matches) > 0) { | |
| 233 | 234 | if ($matches[1] == 'true') { |
| 234 | 235 | $fmetric['Flags'] |= 0x40000; |
| 235 | 236 | } |
| 236 | 237 | } |
| 237 | - if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) { | |
| 238 | + if (preg_match('#/StdVW[\s]*+\[([^\]]*+)#', $eplain, $matches) > 0) { | |
| 238 | 239 | $fmetric['StemV'] = intval($matches[1]); |
| 239 | 240 | } else { |
| 240 | 241 | $fmetric['StemV'] = 70; |
| 241 | 242 | } |
| 242 | - if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) { | |
| 243 | + if (preg_match('#/StdHW[\s]*+\[([^\]]*+)#', $eplain, $matches) > 0) { | |
| 243 | 244 | $fmetric['StemH'] = intval($matches[1]); |
| 244 | 245 | } else { |
| 245 | 246 | $fmetric['StemH'] = 30; |
| 246 | 247 | } |
| 247 | - if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) { | |
| 248 | + if (preg_match('#/BlueValues[\s]*+\[([^\]]*+)#', $eplain, $matches) > 0) { | |
| 248 | 249 | $bv = explode(' ', $matches[1]); |
| 249 | 250 | if (count($bv) >= 6) { |
| 250 | 251 | $v1 = intval($bv[2]); |
| 251 | 252 | $v2 = intval($bv[4]); |
| @@ -264,9 +265,9 @@ | ||
| 264 | 265 | $fmetric['XHeight'] = 450; |
| 265 | 266 | $fmetric['CapHeight'] = 700; |
| 266 | 267 | } |
| 267 | 268 | // get the number of random bytes at the beginning of charstrings |
| 268 | - if (preg_match('#/lenIV[\s]*([0-9]*)#', $eplain, $matches) > 0) { | |
| 269 | + if (preg_match('#/lenIV[\s]*+([\d]*+)#', $eplain, $matches) > 0) { | |
| 269 | 270 | $lenIV = intval($matches[1]); |
| 270 | 271 | } else { |
| 271 | 272 | $lenIV = 4; |
| 272 | 273 | } |
| @@ -272,9 +273,9 @@ | ||
| 272 | 273 | } |
| 273 | 274 | $fmetric['Leading'] = 0; |
| 274 | 275 | // get charstring data |
| 275 | 276 | $eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1)); |
| 276 | - preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER); | |
| 277 | + preg_match_all('#/([A-Za-z0-9\.]*+)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER); | |
| 277 | 278 | if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) { |
| 278 | 279 | $enc_map = TCPDF_FONT_DATA::$encmap[$enc]; |
| 279 | 280 | } else { |
| 280 | 281 | $enc_map = false; |
| @@ -556,8 +557,9 @@ | ||
| 556 | 557 | // get the the number of glyphs in the font. |
| 557 | 558 | $numGlyphs = TCPDF_STATIC::_getUSHORT($font, $offset); |
| 558 | 559 | // ---------- get CIDToGIDMap ---------- |
| 559 | 560 | $ctg = array(); |
| 561 | + $c = 0; | |
| 560 | 562 | foreach ($encodingTables as $enctable) { |
| 561 | 563 | // get only specified Platform ID and Encoding ID |
| 562 | 564 | if (($enctable['platformID'] == $platid) AND ($enctable['encodingID'] == $encid)) { |
| 563 | 565 | $offset = $table['cmap']['offset'] + $enctable['offset']; |
| @@ -919,10 +921,10 @@ | ||
| 919 | 921 | } |
| 920 | 922 | |
| 921 | 923 | /** |
| 922 | 924 | * Returs the checksum of a TTF table. |
| 923 | - * @param $table (string) table to check | |
| 924 | - * @param $length (int) length of table in bytes | |
| 925 | + * @param string $table table to check | |
| 926 | + * @param int $length length of table in bytes | |
| 925 | 927 | * @return int checksum |
| 926 | 928 | * @author Nicola Asuni |
| 927 | 929 | * @since 5.2.000 (2010-06-02) |
| 928 | 930 | * @public static |
| @@ -941,11 +943,11 @@ | ||
| 941 | 943 | } |
| 942 | 944 | |
| 943 | 945 | /** |
| 944 | 946 | * Returns a subset of the TrueType font data without the unused glyphs. |
| 945 | - * @param $font (string) TrueType font data. | |
| 946 | - * @param $subsetchars (array) Array of used characters (the glyphs to keep). | |
| 947 | - * @return (string) A subset of TrueType font data without the unused glyphs. | |
| 947 | + * @param string $font TrueType font data. | |
| 948 | + * @param array $subsetchars Array of used characters (the glyphs to keep). | |
| 949 | + * @return string A subset of TrueType font data without the unused glyphs. | |
| 948 | 950 | * @author Nicola Asuni |
| 949 | 951 | * @since 5.2.000 (2010-06-02) |
| 950 | 952 | * @public static |
| 951 | 953 | */ |
| @@ -955,8 +957,9 @@ | ||
| 955 | 957 | if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) { |
| 956 | 958 | // sfnt version must be 0x00010000 for TrueType version 1.0. |
| 957 | 959 | return $font; |
| 958 | 960 | } |
| 961 | + $c = 0; | |
| 959 | 962 | $offset += 4; |
| 960 | 963 | // get number of tables |
| 961 | 964 | $numTables = TCPDF_STATIC::_getUSHORT($font, $offset); |
| 962 | 965 | $offset += 2; |
| @@ -1148,9 +1151,9 @@ | ||
| 1148 | 1151 | } |
| 1149 | 1152 | $subsetglyphs[$g] = true; |
| 1150 | 1153 | } |
| 1151 | 1154 | } |
| 1152 | - } | |
| 1155 | + } | |
| 1153 | 1156 | break; |
| 1154 | 1157 | } |
| 1155 | 1158 | case 6: { // Format 6: Trimmed table mapping |
| 1156 | 1159 | $offset += 4; // skip length and version/language |
| @@ -1320,45 +1323,45 @@ | ||
| 1320 | 1323 | if ($tag == 'head') { |
| 1321 | 1324 | // set the checkSumAdjustment to 0 |
| 1322 | 1325 | $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12); |
| 1323 | 1326 | } |
| 1324 | - $pad = 4 - ($table[$tag]['length'] % 4); | |
| 1325 | - if ($pad != 4) { | |
| 1326 | - // the length of a table must be a multiple of four bytes | |
| 1327 | - $table[$tag]['length'] += $pad; | |
| 1328 | - $table[$tag]['data'] .= str_repeat("\x0", $pad); | |
| 1329 | - } | |
| 1330 | 1327 | $table[$tag]['offset'] = $offset; |
| 1331 | 1328 | $offset += $table[$tag]['length']; |
| 1329 | + $numPad = ($offset + 3 & ~3) - $offset; | |
| 1330 | + if($numPad > 0) { | |
| 1331 | + $table[$tag]['data'] .= str_repeat("\x0", $numPad); | |
| 1332 | + $offset += $numPad; | |
| 1333 | + } | |
| 1332 | 1334 | // check sum is not changed (so keep the following line commented) |
| 1333 | - //$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']); | |
| 1335 | + //$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length'] + $numPad); | |
| 1334 | 1336 | } else { |
| 1335 | 1337 | unset($table[$tag]); |
| 1336 | 1338 | } |
| 1337 | 1339 | } |
| 1338 | 1340 | // add loca |
| 1341 | + $table['loca'] = array(); | |
| 1339 | 1342 | $table['loca']['data'] = $loca; |
| 1340 | 1343 | $table['loca']['length'] = strlen($loca); |
| 1341 | - $pad = 4 - ($table['loca']['length'] % 4); | |
| 1342 | - if ($pad != 4) { | |
| 1343 | - // the length of a table must be a multiple of four bytes | |
| 1344 | - $table['loca']['length'] += $pad; | |
| 1345 | - $table['loca']['data'] .= str_repeat("\x0", $pad); | |
| 1346 | - } | |
| 1347 | 1344 | $table['loca']['offset'] = $offset; |
| 1348 | - $table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']); | |
| 1349 | 1345 | $offset += $table['loca']['length']; |
| 1346 | + $numPad = ($offset + 3 & ~3) - $offset; | |
| 1347 | + if($numPad > 0) { | |
| 1348 | + $table['loca']['data'] .= str_repeat("\x0", $numPad); | |
| 1349 | + $offset += $numPad; | |
| 1350 | + } | |
| 1351 | + $table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length'] + $numPad); | |
| 1350 | 1352 | // add glyf |
| 1353 | + $table['glyf'] = array(); | |
| 1351 | 1354 | $table['glyf']['data'] = $glyf; |
| 1352 | 1355 | $table['glyf']['length'] = strlen($glyf); |
| 1353 | - $pad = 4 - ($table['glyf']['length'] % 4); | |
| 1354 | - if ($pad != 4) { | |
| 1355 | - // the length of a table must be a multiple of four bytes | |
| 1356 | - $table['glyf']['length'] += $pad; | |
| 1357 | - $table['glyf']['data'] .= str_repeat("\x0", $pad); | |
| 1356 | + $table['glyf']['offset'] = $offset; | |
| 1357 | + $offset += $table['glyf']['length']; | |
| 1358 | + $numPad = ($offset + 3 & ~3) - $offset; | |
| 1359 | + if($numPad > 0) { | |
| 1360 | + $table['glyf']['data'] .= str_repeat("\x0", $numPad); | |
| 1361 | + $offset += $numPad; | |
| 1358 | 1362 | } |
| 1359 | - $table['glyf']['offset'] = $offset; | |
| 1360 | - $table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']); | |
| 1363 | + $table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length'] + $numPad); | |
| 1361 | 1364 | // rebuild font |
| 1362 | 1365 | $font = ''; |
| 1363 | 1366 | $font .= pack('N', 0x10000); // sfnt version |
| 1364 | 1367 | $numTables = count($table); |
| @@ -1380,17 +1383,17 @@ | ||
| 1380 | 1383 | $font .= $data['data']; |
| 1381 | 1384 | } |
| 1382 | 1385 | // set checkSumAdjustment on head table |
| 1383 | 1386 | $checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font)); |
| 1384 | - $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12); | |
| 1387 | + $font = substr($font, 0, $table['head']['offset'] + $offset + 4).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + $offset + 8); | |
| 1385 | 1388 | return $font; |
| 1386 | 1389 | } |
| 1387 | 1390 | |
| 1388 | 1391 | /** |
| 1389 | 1392 | * Outputs font widths |
| 1390 | - * @param $font (array) font data | |
| 1391 | - * @param $cidoffset (int) offset for CID values | |
| 1392 | - * @return PDF command string for font widths | |
| 1393 | + * @param array $font font data | |
| 1394 | + * @param int $cidoffset offset for CID values | |
| 1395 | + * @return string PDF command string for font widths | |
| 1393 | 1396 | * @author Nicola Asuni |
| 1394 | 1397 | * @since 4.4.000 (2008-12-07) |
| 1395 | 1398 | * @public static |
| 1396 | 1399 | */ |
| @@ -1494,12 +1497,12 @@ | ||
| 1494 | 1497 | |
| 1495 | 1498 | |
| 1496 | 1499 | /** |
| 1497 | 1500 | * Update the CIDToGIDMap string with a new value. |
| 1498 | - * @param $map (string) CIDToGIDMap. | |
| 1499 | - * @param $cid (int) CID value. | |
| 1500 | - * @param $gid (int) GID value. | |
| 1501 | - * @return (string) CIDToGIDMap. | |
| 1501 | + * @param string $map CIDToGIDMap. | |
| 1502 | + * @param int $cid CID value. | |
| 1503 | + * @param int $gid GID value. | |
| 1504 | + * @return string CIDToGIDMap. | |
| 1502 | 1505 | * @author Nicola Asuni |
| 1503 | 1506 | * @since 5.9.123 (2011-09-29) |
| 1504 | 1507 | * @public static |
| 1505 | 1508 | */ |
| @@ -1532,10 +1535,10 @@ | ||
| 1532 | 1535 | |
| 1533 | 1536 | |
| 1534 | 1537 | /** |
| 1535 | 1538 | * Return font full path |
| 1536 | - * @param $file (string) Font file name. | |
| 1537 | - * @param $fontdir (string) Font directory (set to false fto search on default directories) | |
| 1539 | + * @param string $file Font file name. | |
| 1540 | + * @param string $fontdir Font directory (set to false fto search on default directories) | |
| 1538 | 1541 | * @return string Font full path or empty string |
| 1539 | 1542 | * @author Nicola Asuni |
| 1540 | 1543 | * @since 6.0.025 |
| 1541 | 1544 | * @public static |
| @@ -1542,13 +1545,13 @@ | ||
| 1542 | 1545 | */ |
| 1543 | 1546 | public static function getFontFullPath($file, $fontdir=false) { |
| 1544 | 1547 | $fontfile = ''; |
| 1545 | 1548 | // search files on various directories |
| 1546 | - if (($fontdir !== false) AND @file_exists($fontdir.$file)) { | |
| 1549 | + if (($fontdir !== false) AND @TCPDF_STATIC::file_exists($fontdir.$file)) { | |
| 1547 | 1550 | $fontfile = $fontdir.$file; |
| 1548 | - } elseif (@file_exists(self::_getfontpath().$file)) { | |
| 1551 | + } elseif (@TCPDF_STATIC::file_exists(self::_getfontpath().$file)) { | |
| 1549 | 1552 | $fontfile = self::_getfontpath().$file; |
| 1550 | - } elseif (@file_exists($file)) { | |
| 1553 | + } elseif (@TCPDF_STATIC::file_exists($file)) { | |
| 1551 | 1554 | $fontfile = $file; |
| 1552 | 1555 | } |
| 1553 | 1556 | return $fontfile; |
| 1554 | 1557 | } |
| @@ -1557,10 +1560,10 @@ | ||
| 1557 | 1560 | |
| 1558 | 1561 | |
| 1559 | 1562 | /** |
| 1560 | 1563 | * Get a reference font size. |
| 1561 | - * @param $size (string) String containing font size value. | |
| 1562 | - * @param $refsize (float) Reference font size in points. | |
| 1564 | + * @param string $size String containing font size value. | |
| 1565 | + * @param float $refsize Reference font size in points. | |
| 1563 | 1566 | * @return float value in points |
| 1564 | 1567 | * @public static |
| 1565 | 1568 | */ |
| 1566 | 1569 | public static function getFontRefSize($size, $refsize=12) { |
| @@ -1656,15 +1659,16 @@ | ||
| 1656 | 1659 | |
| 1657 | 1660 | |
| 1658 | 1661 | /** |
| 1659 | 1662 | * Returns the unicode caracter specified by the value |
| 1660 | - * @param $c (int) UTF-8 value | |
| 1661 | - * @param $unicode (boolean) True if we are in unicode mode, false otherwise. | |
| 1662 | - * @return Returns the specified character. | |
| 1663 | + * @param int $c UTF-8 value | |
| 1664 | + * @param boolean $unicode True if we are in unicode mode, false otherwise. | |
| 1665 | + * @return string Returns the specified character. | |
| 1663 | 1666 | * @since 2.3.000 (2008-03-05) |
| 1664 | 1667 | * @public static |
| 1665 | 1668 | */ |
| 1666 | 1669 | public static function unichr($c, $unicode=true) { |
| 1670 | + $c = intval($c); | |
| 1667 | 1671 | if (!$unicode) { |
| 1668 | 1672 | return chr($c); |
| 1669 | 1673 | } elseif ($c <= 0x7F) { |
| 1670 | 1674 | // one byte |
| @@ -1684,10 +1688,10 @@ | ||
| 1684 | 1688 | } |
| 1685 | 1689 | |
| 1686 | 1690 | /** |
| 1687 | 1691 | * Returns the unicode caracter specified by UTF-8 value |
| 1688 | - * @param $c (int) UTF-8 value | |
| 1689 | - * @return Returns the specified character. | |
| 1692 | + * @param int $c UTF-8 value | |
| 1693 | + * @return string Returns the specified character. | |
| 1690 | 1694 | * @public static |
| 1691 | 1695 | */ |
| 1692 | 1696 | public static function unichrUnicode($c) { |
| 1693 | 1697 | return self::unichr($c, true); |
| @@ -1694,10 +1698,10 @@ | ||
| 1694 | 1698 | } |
| 1695 | 1699 | |
| 1696 | 1700 | /** |
| 1697 | 1701 | * Returns the unicode caracter specified by ASCII value |
| 1698 | - * @param $c (int) UTF-8 value | |
| 1699 | - * @return Returns the specified character. | |
| 1702 | + * @param int $c UTF-8 value | |
| 1703 | + * @return string Returns the specified character. | |
| 1700 | 1704 | * @public static |
| 1701 | 1705 | */ |
| 1702 | 1706 | public static function unichrASCII($c) { |
| 1703 | 1707 | return self::unichr($c, false); |
| @@ -1732,10 +1736,10 @@ | ||
| 1732 | 1736 | * U' = yyyyyyyyyyxxxxxxxxxx |
| 1733 | 1737 | * W1 = 110110yyyyyyyyyy |
| 1734 | 1738 | * W2 = 110111xxxxxxxxxx |
| 1735 | 1739 | * </pre> |
| 1736 | - * @param $unicode (array) array containing UTF-8 unicode values | |
| 1737 | - * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 1740 | + * @param array $unicode array containing UTF-8 unicode values | |
| 1741 | + * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 1738 | 1742 | * @return string |
| 1739 | 1743 | * @protected |
| 1740 | 1744 | * @author Nicola Asuni |
| 1741 | 1745 | * @since 2.1.000 (2008-01-08) |
| @@ -1768,28 +1772,28 @@ | ||
| 1768 | 1772 | } |
| 1769 | 1773 | |
| 1770 | 1774 | /** |
| 1771 | 1775 | * Convert an array of UTF8 values to array of unicode characters |
| 1772 | - * @param $ta (array) The input array of UTF8 values. | |
| 1773 | - * @param $isunicode (boolean) True for Unicode mode, false otherwise. | |
| 1774 | - * @return Return array of unicode characters | |
| 1776 | + * @param array $ta The input array of UTF8 values. | |
| 1777 | + * @param boolean $isunicode True for Unicode mode, false otherwise. | |
| 1778 | + * @return array Return array of unicode characters | |
| 1775 | 1779 | * @since 4.5.037 (2009-04-07) |
| 1776 | 1780 | * @public static |
| 1777 | 1781 | */ |
| 1778 | 1782 | public static function UTF8ArrayToUniArray($ta, $isunicode=true) { |
| 1779 | 1783 | if ($isunicode) { |
| 1780 | - return array_map(array('TCPDF_FONTS', 'unichrUnicode'), $ta); | |
| 1784 | + return array_map(static::class.'::unichrUnicode', $ta); | |
| 1781 | 1785 | } |
| 1782 | - return array_map(array('TCPDF_FONTS', 'unichrASCII'), $ta); | |
| 1786 | + return array_map(static::class.'::unichrASCII', $ta); | |
| 1783 | 1787 | } |
| 1784 | 1788 | |
| 1785 | 1789 | /** |
| 1786 | 1790 | * Extract a slice of the $strarr array and return it as string. |
| 1787 | - * @param $strarr (string) The input array of characters. | |
| 1788 | - * @param $start (int) the starting element of $strarr. | |
| 1789 | - * @param $end (int) first element that will not be returned. | |
| 1790 | - * @param $unicode (boolean) True if we are in unicode mode, false otherwise. | |
| 1791 | - * @return Return part of a string | |
| 1791 | + * @param string[] $strarr The input array of characters. | |
| 1792 | + * @param int $start the starting element of $strarr. | |
| 1793 | + * @param int $end first element that will not be returned. | |
| 1794 | + * @param boolean $unicode True if we are in unicode mode, false otherwise. | |
| 1795 | + * @return string Return part of a string | |
| 1792 | 1796 | * @public static |
| 1793 | 1797 | */ |
| 1794 | 1798 | public static function UTF8ArrSubString($strarr, $start='', $end='', $unicode=true) { |
| 1795 | 1799 | if (strlen($start) == 0) { |
| @@ -1806,12 +1810,12 @@ | ||
| 1806 | 1810 | } |
| 1807 | 1811 | |
| 1808 | 1812 | /** |
| 1809 | 1813 | * Extract a slice of the $uniarr array and return it as string. |
| 1810 | - * @param $uniarr (string) The input array of characters. | |
| 1811 | - * @param $start (int) the starting element of $strarr. | |
| 1812 | - * @param $end (int) first element that will not be returned. | |
| 1813 | - * @return Return part of a string | |
| 1814 | + * @param string[] $uniarr The input array of characters. | |
| 1815 | + * @param int $start the starting element of $strarr. | |
| 1816 | + * @param int $end first element that will not be returned. | |
| 1817 | + * @return string Return part of a string | |
| 1814 | 1818 | * @since 4.5.037 (2009-04-07) |
| 1815 | 1819 | * @public static |
| 1816 | 1820 | */ |
| 1817 | 1821 | public static function UniArrSubString($uniarr, $start='', $end='') { |
| @@ -1829,9 +1833,9 @@ | ||
| 1829 | 1833 | } |
| 1830 | 1834 | |
| 1831 | 1835 | /** |
| 1832 | 1836 | * Converts UTF-8 characters array to array of Latin1 characters array<br> |
| 1833 | - * @param $unicode (array) array containing UTF-8 unicode values | |
| 1837 | + * @param array $unicode array containing UTF-8 unicode values | |
| 1834 | 1838 | * @return array |
| 1835 | 1839 | * @author Nicola Asuni |
| 1836 | 1840 | * @since 4.8.023 (2010-01-15) |
| 1837 | 1841 | * @public static |
| @@ -1853,11 +1857,11 @@ | ||
| 1853 | 1857 | return $outarr; |
| 1854 | 1858 | } |
| 1855 | 1859 | |
| 1856 | 1860 | /** |
| 1857 | - * Converts UTF-8 characters array to array of Latin1 string<br> | |
| 1858 | - * @param $unicode (array) array containing UTF-8 unicode values | |
| 1859 | - * @return array | |
| 1861 | + * Converts UTF-8 characters array to Latin1 string<br> | |
| 1862 | + * @param array $unicode array containing UTF-8 unicode values | |
| 1863 | + * @return string | |
| 1860 | 1864 | * @author Nicola Asuni |
| 1861 | 1865 | * @since 4.8.023 (2010-01-15) |
| 1862 | 1866 | * @public static |
| 1863 | 1867 | */ |
| @@ -1880,10 +1884,10 @@ | ||
| 1880 | 1884 | |
| 1881 | 1885 | /** |
| 1882 | 1886 | * Converts UTF-8 character to integer value.<br> |
| 1883 | 1887 | * Uses the getUniord() method if the value is not cached. |
| 1884 | - * @param $uch (string) character string to process. | |
| 1885 | - * @return integer Unicode value | |
| 1888 | + * @param string $uch character string to process. | |
| 1889 | + * @return int Unicode value | |
| 1886 | 1890 | * @public static |
| 1887 | 1891 | */ |
| 1888 | 1892 | public static function uniord($uch) { |
| 1889 | 1893 | if (!isset(self::$cache_uniord[$uch])) { |
| @@ -1919,10 +1923,10 @@ | ||
| 1919 | 1923 | * %xF4 %x80-8F 2( UTF8-tail ) |
| 1920 | 1924 | * UTF8-tail = %x80-BF |
| 1921 | 1925 | * --------------------------------------------------------------------- |
| 1922 | 1926 | * </pre> |
| 1923 | - * @param $uch (string) character string to process. | |
| 1924 | - * @return integer Unicode value | |
| 1927 | + * @param string $uch character string to process. | |
| 1928 | + * @return int Unicode value | |
| 1925 | 1929 | * @author Nicola Asuni |
| 1926 | 1930 | * @public static |
| 1927 | 1931 | */ |
| 1928 | 1932 | public static function getUniord($uch) { |
| @@ -1986,38 +1990,43 @@ | ||
| 1986 | 1990 | |
| 1987 | 1991 | /** |
| 1988 | 1992 | * Converts UTF-8 strings to codepoints array.<br> |
| 1989 | 1993 | * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br> |
| 1990 | - * @param $str (string) string to process. | |
| 1991 | - * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise. | |
| 1992 | - * @param $currentfont (array) Reference to current font array. | |
| 1994 | + * @param string $str string to process. | |
| 1995 | + * @param boolean $isunicode True when the documetn is in Unicode mode, false otherwise. | |
| 1996 | + * @param array $currentfont Reference to current font array. | |
| 1993 | 1997 | * @return array containing codepoints (UTF-8 characters values) |
| 1994 | 1998 | * @author Nicola Asuni |
| 1995 | 1999 | * @public static |
| 1996 | 2000 | */ |
| 1997 | - public static function UTF8StringToArray($str, $isunicode=true, &$currentfont) { | |
| 2001 | + public static function UTF8StringToArray($str, $isunicode, &$currentfont) { | |
| 2002 | + $str = is_null($str) ? '' : $str; | |
| 1998 | 2003 | if ($isunicode) { |
| 1999 | 2004 | // requires PCRE unicode support turned on |
| 2000 | 2005 | $chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY); |
| 2001 | - $carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars); | |
| 2006 | + $carr = array_map(static::class.'::uniord', $chars); | |
| 2002 | 2007 | } else { |
| 2003 | 2008 | $chars = str_split($str); |
| 2004 | 2009 | $carr = array_map('ord', $chars); |
| 2005 | 2010 | } |
| 2006 | - $currentfont['subsetchars'] += array_fill_keys($carr, true); | |
| 2011 | + if (is_array($currentfont['subsetchars']) && is_array($carr)) { | |
| 2012 | + $currentfont['subsetchars'] += array_fill_keys($carr, true); | |
| 2013 | + } else { | |
| 2014 | + $currentfont['subsetchars'] = array_merge($currentfont['subsetchars'], $carr); | |
| 2015 | + } | |
| 2007 | 2016 | return $carr; |
| 2008 | 2017 | } |
| 2009 | 2018 | |
| 2010 | 2019 | /** |
| 2011 | 2020 | * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br> |
| 2012 | - * @param $str (string) string to process. | |
| 2013 | - * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise. | |
| 2014 | - * @param $currentfont (array) Reference to current font array. | |
| 2021 | + * @param string $str string to process. | |
| 2022 | + * @param boolean $isunicode True when the documetn is in Unicode mode, false otherwise. | |
| 2023 | + * @param array $currentfont Reference to current font array. | |
| 2015 | 2024 | * @return string |
| 2016 | 2025 | * @since 3.2.000 (2008-06-23) |
| 2017 | 2026 | * @public static |
| 2018 | 2027 | */ |
| 2019 | - public static function UTF8ToLatin1($str, $isunicode=true, &$currentfont) { | |
| 2028 | + public static function UTF8ToLatin1($str, $isunicode, &$currentfont) { | |
| 2020 | 2029 | $unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values |
| 2021 | 2030 | return self::UTF8ArrToLatin1($unicode); |
| 2022 | 2031 | } |
| 2023 | 2032 | |
| @@ -2022,18 +2031,18 @@ | ||
| 2022 | 2031 | } |
| 2023 | 2032 | |
| 2024 | 2033 | /** |
| 2025 | 2034 | * Converts UTF-8 strings to UTF16-BE.<br> |
| 2026 | - * @param $str (string) string to process. | |
| 2027 | - * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 2028 | - * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise. | |
| 2029 | - * @param $currentfont (array) Reference to current font array. | |
| 2035 | + * @param string $str string to process. | |
| 2036 | + * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 2037 | + * @param boolean $isunicode True when the documetn is in Unicode mode, false otherwise. | |
| 2038 | + * @param array $currentfont Reference to current font array. | |
| 2030 | 2039 | * @return string |
| 2031 | 2040 | * @author Nicola Asuni |
| 2032 | 2041 | * @since 1.53.0.TC005 (2005-01-05) |
| 2033 | 2042 | * @public static |
| 2034 | 2043 | */ |
| 2035 | - public static function UTF8ToUTF16BE($str, $setbom=false, $isunicode=true, &$currentfont) { | |
| 2044 | + public static function UTF8ToUTF16BE($str, $setbom, $isunicode, &$currentfont) { | |
| 2036 | 2045 | if (!$isunicode) { |
| 2037 | 2046 | return $str; // string is not in unicode |
| 2038 | 2047 | } |
| 2039 | 2048 | $unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values |
| @@ -2041,52 +2050,52 @@ | ||
| 2041 | 2050 | } |
| 2042 | 2051 | |
| 2043 | 2052 | /** |
| 2044 | 2053 | * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). |
| 2045 | - * @param $str (string) string to manipulate. | |
| 2046 | - * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 2047 | - * @param $forcertl (bool) if true forces RTL text direction | |
| 2048 | - * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise. | |
| 2049 | - * @param $currentfont (array) Reference to current font array. | |
| 2054 | + * @param string $str string to manipulate. | |
| 2055 | + * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 2056 | + * @param bool $forcertl if true forces RTL text direction | |
| 2057 | + * @param boolean $isunicode True if the document is in Unicode mode, false otherwise. | |
| 2058 | + * @param array $currentfont Reference to current font array. | |
| 2050 | 2059 | * @return string |
| 2051 | 2060 | * @author Nicola Asuni |
| 2052 | 2061 | * @since 2.1.000 (2008-01-08) |
| 2053 | 2062 | * @public static |
| 2054 | 2063 | */ |
| 2055 | - public static function utf8StrRev($str, $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) { | |
| 2064 | + public static function utf8StrRev($str, $setbom, $forcertl, $isunicode, &$currentfont) { | |
| 2056 | 2065 | return self::utf8StrArrRev(self::UTF8StringToArray($str, $isunicode, $currentfont), $str, $setbom, $forcertl, $isunicode, $currentfont); |
| 2057 | 2066 | } |
| 2058 | 2067 | |
| 2059 | 2068 | /** |
| 2060 | 2069 | * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). |
| 2061 | - * @param $arr (array) array of unicode values. | |
| 2062 | - * @param $str (string) string to manipulate (or empty value). | |
| 2063 | - * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 2064 | - * @param $forcertl (bool) if true forces RTL text direction | |
| 2065 | - * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise. | |
| 2066 | - * @param $currentfont (array) Reference to current font array. | |
| 2070 | + * @param array $arr array of unicode values. | |
| 2071 | + * @param string $str string to manipulate (or empty value). | |
| 2072 | + * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF) | |
| 2073 | + * @param bool $forcertl if true forces RTL text direction | |
| 2074 | + * @param boolean $isunicode True if the document is in Unicode mode, false otherwise. | |
| 2075 | + * @param array $currentfont Reference to current font array. | |
| 2067 | 2076 | * @return string |
| 2068 | 2077 | * @author Nicola Asuni |
| 2069 | 2078 | * @since 4.9.000 (2010-03-27) |
| 2070 | 2079 | * @public static |
| 2071 | 2080 | */ |
| 2072 | - public static function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) { | |
| 2081 | + public static function utf8StrArrRev($arr, $str, $setbom, $forcertl, $isunicode, &$currentfont) { | |
| 2073 | 2082 | return self::arrUTF8ToUTF16BE(self::utf8Bidi($arr, $str, $forcertl, $isunicode, $currentfont), $setbom); |
| 2074 | 2083 | } |
| 2075 | 2084 | |
| 2076 | 2085 | /** |
| 2077 | 2086 | * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). |
| 2078 | - * @param $ta (array) array of characters composing the string. | |
| 2079 | - * @param $str (string) string to process | |
| 2080 | - * @param $forcertl (bool) if 'R' forces RTL, if 'L' forces LTR | |
| 2081 | - * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise. | |
| 2082 | - * @param $currentfont (array) Reference to current font array. | |
| 2087 | + * @param array $ta array of characters composing the string. | |
| 2088 | + * @param string $str string to process | |
| 2089 | + * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR | |
| 2090 | + * @param boolean $isunicode True if the document is in Unicode mode, false otherwise. | |
| 2091 | + * @param array $currentfont Reference to current font array. | |
| 2083 | 2092 | * @return array of unicode chars |
| 2084 | 2093 | * @author Nicola Asuni |
| 2085 | 2094 | * @since 2.4.000 (2008-03-06) |
| 2086 | 2095 | * @public static |
| 2087 | 2096 | */ |
| 2088 | - public static function utf8Bidi($ta, $str='', $forcertl=false, $isunicode=true, &$currentfont) { | |
| 2097 | + public static function utf8Bidi($ta, $str, $forcertl, $isunicode, &$currentfont) { | |
| 2089 | 2098 | // paragraph embedding level |
| 2090 | 2099 | $pel = 0; |
| 2091 | 2100 | // max level |
| 2092 | 2101 | $maxlevel = 0; |