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
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-2024 Nicola Asuni - Tecnick.com LTD
11
11
//
12
12
// This file is part of TCPDF software library.
13
13
//
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 {
@@ -191,29 +191,30 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
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
}
@@ -229,22 +230,22 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
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 ]);
@@ -265,15 +266,15 @@ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $
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
}
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 {
0 commit comments