Skip to content

Commit a0a02ef

Browse files
committed
Add some addTTFfont fixes from tc-lib-pdf-font
1 parent aab43ab commit a0a02ef

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

CHANGELOG.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Escape error message.
44
- Use strict time-constant function to compare TCPDF-tag hashes.
55
- Add K_CURLOPTS config array to set custom cURL options (NOTE: some defaults have changed).
6+
- Add some addTTFfont fixes from tc-lib-pdf-font.
67

78

89
6.7.8 (2024-12-13)

include/tcpdf_fonts.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22
//============================================================+
33
// File name : tcpdf_fonts.php
4-
// Version : 1.1.0
4+
// Version : 1.1.1
55
// Begin : 2008-01-01
6-
// Last Update : 2014-12-10
6+
// Last Update : 2024-12-23
77
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - [email protected]
88
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
99
// -------------------------------------------------------------------
10-
// Copyright (C) 2008-2014 Nicola Asuni - Tecnick.com LTD
10+
// Copyright (C) 2008-2024 Nicola Asuni - Tecnick.com LTD
1111
//
1212
// This file is part of TCPDF software library.
1313
//
@@ -42,7 +42,7 @@
4242
* @class TCPDF_FONTS
4343
* Font methods for TCPDF library.
4444
* @package com.tecnick.tcpdf
45-
* @version 1.1.0
45+
* @version 1.1.1
4646
* @author Nicola Asuni - [email protected]
4747
*/
4848
class TCPDF_FONTS {
@@ -191,29 +191,30 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
191191
fclose($fp);
192192
// get font info
193193
$fmetric['Flags'] = $flags;
194-
preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
194+
preg_match ('#/FullName[\s]*+\(([^\)]*+)#', $font, $matches);
195195
$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);
202203
$fmetric['italicAngle'] = intval($matches[1]);
203204
if ($fmetric['italicAngle'] != 0) {
204205
$fmetric['Flags'] |= 64;
205206
}
206-
preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches);
207+
preg_match('#/UnderlinePosition[\s]*+([0-9\+\-]*+)#', $font, $matches);
207208
$fmetric['underlinePosition'] = intval($matches[1]);
208-
preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches);
209+
preg_match('#/UnderlineThickness[\s]*+([0-9\+\-]*+)#', $font, $matches);
209210
$fmetric['underlineThickness'] = intval($matches[1]);
210-
preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches);
211+
preg_match('#/isFixedPitch[\s]*+([^\s]*+)#', $font, $matches);
211212
if ($matches[1] == 'true') {
212213
$fmetric['Flags'] |= 1;
213214
}
214215
// get internal map
215216
$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) {
217218
foreach ($fmap as $v) {
218219
$imap[$v[2]] = $v[1];
219220
}
@@ -229,22 +230,22 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
229230
$eplain .= chr($chr ^ ($r >> 8));
230231
$r = ((($chr + $r) * $c1 + $c2) % 65536);
231232
}
232-
if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) {
233+
if (preg_match('#/ForceBold[\s]*+([^\s]*+)#', $eplain, $matches) > 0) {
233234
if ($matches[1] == 'true') {
234235
$fmetric['Flags'] |= 0x40000;
235236
}
236237
}
237-
if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
238+
if (preg_match('#/StdVW[\s]*+\[([^\]]*+)#', $eplain, $matches) > 0) {
238239
$fmetric['StemV'] = intval($matches[1]);
239240
} else {
240241
$fmetric['StemV'] = 70;
241242
}
242-
if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
243+
if (preg_match('#/StdHW[\s]*+\[([^\]]*+)#', $eplain, $matches) > 0) {
243244
$fmetric['StemH'] = intval($matches[1]);
244245
} else {
245246
$fmetric['StemH'] = 30;
246247
}
247-
if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
248+
if (preg_match('#/BlueValues[\s]*+\[([^\]]*+)#', $eplain, $matches) > 0) {
248249
$bv = explode(' ', $matches[1]);
249250
if (count($bv) >= 6) {
250251
$v1 = intval($bv[2]);
@@ -265,15 +266,15 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
265266
$fmetric['CapHeight'] = 700;
266267
}
267268
// 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) {
269270
$lenIV = intval($matches[1]);
270271
} else {
271272
$lenIV = 4;
272273
}
273274
$fmetric['Leading'] = 0;
274275
// get charstring data
275276
$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);
277278
if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
278279
$enc_map = TCPDF_FONT_DATA::$encmap[$enc];
279280
} else {

0 commit comments

Comments
 (0)