| Línea 1... |
Línea 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
//============================================================+
|
2 |
//============================================================+
|
| 3 |
// File name : tcpdf_fonts.php
|
3 |
// File name : tcpdf_fonts.php
|
| 4 |
// Version : 1.1.0
|
4 |
// Version : 1.1.1
|
| 5 |
// Begin : 2008-01-01
|
5 |
// Begin : 2008-01-01
|
| 6 |
// Last Update : 2014-12-10
|
6 |
// Last Update : 2024-12-23
|
| 7 |
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
|
7 |
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
|
| 8 |
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
|
8 |
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
|
| 9 |
// -------------------------------------------------------------------
|
9 |
// -------------------------------------------------------------------
|
| 10 |
// Copyright (C) 2008-2014 Nicola Asuni - Tecnick.com LTD
|
10 |
// Copyright (C) 2008-2025 Nicola Asuni - Tecnick.com LTD
|
| 11 |
//
|
11 |
//
|
| 12 |
// This file is part of TCPDF software library.
|
12 |
// This file is part of TCPDF software library.
|
| 13 |
//
|
13 |
//
|
| 14 |
// TCPDF is free software: you can redistribute it and/or modify it
|
14 |
// TCPDF is free software: you can redistribute it and/or modify it
|
| 15 |
// under the terms of the GNU Lesser General Public License as
|
15 |
// under the terms of the GNU Lesser General Public License as
|
| Línea 40... |
Línea 40... |
| 40 |
|
40 |
|
| 41 |
/**
|
41 |
/**
|
| 42 |
* @class TCPDF_FONTS
|
42 |
* @class TCPDF_FONTS
|
| 43 |
* Font methods for TCPDF library.
|
43 |
* Font methods for TCPDF library.
|
| 44 |
* @package com.tecnick.tcpdf
|
44 |
* @package com.tecnick.tcpdf
|
| 45 |
* @version 1.1.0
|
45 |
* @version 1.1.1
|
| 46 |
* @author Nicola Asuni - info@tecnick.com
|
46 |
* @author Nicola Asuni - info@tecnick.com
|
| 47 |
*/
|
47 |
*/
|
| Línea 48... |
Línea 48... |
| 48 |
class TCPDF_FONTS {
|
48 |
class TCPDF_FONTS {
|
| Línea 189... |
Línea 189... |
| 189 |
$fp = TCPDF_STATIC::fopenLocal($outpath.$fmetric['file'], 'wb');
|
189 |
$fp = TCPDF_STATIC::fopenLocal($outpath.$fmetric['file'], 'wb');
|
| 190 |
fwrite($fp, gzcompress($data));
|
190 |
fwrite($fp, gzcompress($data));
|
| 191 |
fclose($fp);
|
191 |
fclose($fp);
|
| 192 |
// get font info
|
192 |
// get font info
|
| 193 |
$fmetric['Flags'] = $flags;
|
193 |
$fmetric['Flags'] = $flags;
|
| 194 |
preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
|
194 |
preg_match ('#/FullName[\s]*+\(([^\)]*+)#', $font, $matches);
|
| 195 |
$fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
|
195 |
$fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
|
| 196 |
preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
|
196 |
preg_match('#/FontBBox[\s]*+{([^}]*+)#', $font, $matches);
|
| 197 |
$fmetric['bbox'] = trim($matches[1]);
|
197 |
$rawbvl = explode(' ', trim($matches[1]));
|
| - |
|
198 |
$bvl = [(int) $rawbvl[0], (int) $rawbvl[1], (int) $rawbvl[2], (int) $rawbvl[3]];
|
| 198 |
$bv = explode(' ', $fmetric['bbox']);
|
199 |
$fmetric['bbox'] = implode(' ', $bvl);
|
| 199 |
$fmetric['Ascent'] = intval($bv[3]);
|
200 |
$fmetric['Ascent'] = $bvl[3];
|
| 200 |
$fmetric['Descent'] = intval($bv[1]);
|
201 |
$fmetric['Descent'] = $bvl[1];
|
| 201 |
preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches);
|
202 |
preg_match('#/ItalicAngle[\s]*+([0-9\+\-]*+)#', $font, $matches);
|
| 202 |
$fmetric['italicAngle'] = intval($matches[1]);
|
203 |
$fmetric['italicAngle'] = intval($matches[1]);
|
| 203 |
if ($fmetric['italicAngle'] != 0) {
|
204 |
if ($fmetric['italicAngle'] != 0) {
|
| 204 |
$fmetric['Flags'] |= 64;
|
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 |
$fmetric['underlinePosition'] = intval($matches[1]);
|
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 |
$fmetric['underlineThickness'] = intval($matches[1]);
|
210 |
$fmetric['underlineThickness'] = intval($matches[1]);
|
| 210 |
preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches);
|
211 |
preg_match('#/isFixedPitch[\s]*+([^\s]*+)#', $font, $matches);
|
| 211 |
if ($matches[1] == 'true') {
|
212 |
if ($matches[1] == 'true') {
|
| 212 |
$fmetric['Flags'] |= 1;
|
213 |
$fmetric['Flags'] |= 1;
|
| 213 |
}
|
214 |
}
|
| 214 |
// get internal map
|
215 |
// get internal map
|
| 215 |
$imap = array();
|
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 |
foreach ($fmap as $v) {
|
218 |
foreach ($fmap as $v) {
|
| 218 |
$imap[$v[2]] = $v[1];
|
219 |
$imap[$v[2]] = $v[1];
|
| 219 |
}
|
220 |
}
|
| 220 |
}
|
221 |
}
|
| 221 |
// decrypt eexec encrypted part
|
222 |
// decrypt eexec encrypted part
|
| Línea 227... |
Línea 228... |
| 227 |
for ($i = 0; $i < $elen; ++$i) {
|
228 |
for ($i = 0; $i < $elen; ++$i) {
|
| 228 |
$chr = ord($encrypted[$i]);
|
229 |
$chr = ord($encrypted[$i]);
|
| 229 |
$eplain .= chr($chr ^ ($r >> 8));
|
230 |
$eplain .= chr($chr ^ ($r >> 8));
|
| 230 |
$r = ((($chr + $r) * $c1 + $c2) % 65536);
|
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 |
if ($matches[1] == 'true') {
|
234 |
if ($matches[1] == 'true') {
|
| 234 |
$fmetric['Flags'] |= 0x40000;
|
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 |
$fmetric['StemV'] = intval($matches[1]);
|
239 |
$fmetric['StemV'] = intval($matches[1]);
|
| 239 |
} else {
|
240 |
} else {
|
| 240 |
$fmetric['StemV'] = 70;
|
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 |
$fmetric['StemH'] = intval($matches[1]);
|
244 |
$fmetric['StemH'] = intval($matches[1]);
|
| 244 |
} else {
|
245 |
} else {
|
| 245 |
$fmetric['StemH'] = 30;
|
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 |
$bv = explode(' ', $matches[1]);
|
249 |
$bv = explode(' ', $matches[1]);
|
| 249 |
if (count($bv) >= 6) {
|
250 |
if (count($bv) >= 6) {
|
| 250 |
$v1 = intval($bv[2]);
|
251 |
$v1 = intval($bv[2]);
|
| 251 |
$v2 = intval($bv[4]);
|
252 |
$v2 = intval($bv[4]);
|
| 252 |
if ($v1 <= $v2) {
|
253 |
if ($v1 <= $v2) {
|
| Línea 263... |
Línea 264... |
| 263 |
} else {
|
264 |
} else {
|
| 264 |
$fmetric['XHeight'] = 450;
|
265 |
$fmetric['XHeight'] = 450;
|
| 265 |
$fmetric['CapHeight'] = 700;
|
266 |
$fmetric['CapHeight'] = 700;
|
| 266 |
}
|
267 |
}
|
| 267 |
// get the number of random bytes at the beginning of charstrings
|
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 |
$lenIV = intval($matches[1]);
|
270 |
$lenIV = intval($matches[1]);
|
| 270 |
} else {
|
271 |
} else {
|
| 271 |
$lenIV = 4;
|
272 |
$lenIV = 4;
|
| 272 |
}
|
273 |
}
|
| 273 |
$fmetric['Leading'] = 0;
|
274 |
$fmetric['Leading'] = 0;
|
| 274 |
// get charstring data
|
275 |
// get charstring data
|
| 275 |
$eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1));
|
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 |
if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
|
278 |
if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
|
| 278 |
$enc_map = TCPDF_FONT_DATA::$encmap[$enc];
|
279 |
$enc_map = TCPDF_FONT_DATA::$encmap[$enc];
|
| 279 |
} else {
|
280 |
} else {
|
| 280 |
$enc_map = false;
|
281 |
$enc_map = false;
|
| 281 |
}
|
282 |
}
|
| Línea 1778... |
Línea 1779... |
| 1778 |
* @since 4.5.037 (2009-04-07)
|
1779 |
* @since 4.5.037 (2009-04-07)
|
| 1779 |
* @public static
|
1780 |
* @public static
|
| 1780 |
*/
|
1781 |
*/
|
| 1781 |
public static function UTF8ArrayToUniArray($ta, $isunicode=true) {
|
1782 |
public static function UTF8ArrayToUniArray($ta, $isunicode=true) {
|
| 1782 |
if ($isunicode) {
|
1783 |
if ($isunicode) {
|
| 1783 |
return array_map(get_called_class().'::unichrUnicode', $ta);
|
1784 |
return array_map(static::class.'::unichrUnicode', $ta);
|
| 1784 |
}
|
1785 |
}
|
| 1785 |
return array_map(get_called_class().'::unichrASCII', $ta);
|
1786 |
return array_map(static::class.'::unichrASCII', $ta);
|
| 1786 |
}
|
1787 |
}
|
| Línea 1787... |
Línea 1788... |
| 1787 |
|
1788 |
|
| 1788 |
/**
|
1789 |
/**
|
| 1789 |
* Extract a slice of the $strarr array and return it as string.
|
1790 |
* Extract a slice of the $strarr array and return it as string.
|
| Línea 2000... |
Línea 2001... |
| 2000 |
public static function UTF8StringToArray($str, $isunicode, &$currentfont) {
|
2001 |
public static function UTF8StringToArray($str, $isunicode, &$currentfont) {
|
| 2001 |
$str = is_null($str) ? '' : $str;
|
2002 |
$str = is_null($str) ? '' : $str;
|
| 2002 |
if ($isunicode) {
|
2003 |
if ($isunicode) {
|
| 2003 |
// requires PCRE unicode support turned on
|
2004 |
// requires PCRE unicode support turned on
|
| 2004 |
$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
|
2005 |
$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
|
| 2005 |
$carr = array_map(get_called_class().'::uniord', $chars);
|
2006 |
$carr = array_map(static::class.'::uniord', $chars);
|
| 2006 |
} else {
|
2007 |
} else {
|
| 2007 |
$chars = str_split($str);
|
2008 |
$chars = str_split($str);
|
| 2008 |
$carr = array_map('ord', $chars);
|
2009 |
$carr = array_map('ord', $chars);
|
| 2009 |
}
|
2010 |
}
|
| 2010 |
if (is_array($currentfont['subsetchars']) && is_array($carr)) {
|
2011 |
if (is_array($currentfont['subsetchars']) && is_array($carr)) {
|