OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* ttpost.c */ | 3 /* ttpost.c */ |
4 /* */ | 4 /* */ |
5 /* Postcript name table processing for TrueType and OpenType fonts */ | 5 /* Postcript name table processing for TrueType and OpenType fonts */ |
6 /* (body). */ | 6 /* (body). */ |
7 /* */ | 7 /* */ |
8 /* Copyright 1996-2003, 2006-2010, 2013, 2014 by */ | 8 /* Copyright 1996-2015 by */ |
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
10 /* */ | 10 /* */ |
11 /* This file is part of the FreeType project, and may only be used, */ | 11 /* This file is part of the FreeType project, and may only be used, */ |
12 /* modified, and distributed under the terms of the FreeType project */ | 12 /* modified, and distributed under the terms of the FreeType project */ |
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
14 /* this file you indicate that you have read the license and */ | 14 /* this file you indicate that you have read the license and */ |
15 /* understand and accept it fully. */ | 15 /* understand and accept it fully. */ |
16 /* */ | 16 /* */ |
17 /***************************************************************************/ | 17 /***************************************************************************/ |
18 | 18 |
(...skipping 26 matching lines...) Expand all Loading... |
45 | 45 |
46 | 46 |
47 /* If this configuration macro is defined, we rely on the `PSNames' */ | 47 /* If this configuration macro is defined, we rely on the `PSNames' */ |
48 /* module to grab the glyph names. */ | 48 /* module to grab the glyph names. */ |
49 | 49 |
50 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES | 50 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES |
51 | 51 |
52 | 52 |
53 #include FT_SERVICE_POSTSCRIPT_CMAPS_H | 53 #include FT_SERVICE_POSTSCRIPT_CMAPS_H |
54 | 54 |
55 #define MAC_NAME( x ) ( (FT_String*)psnames->macintosh_name( x ) ) | 55 #define MAC_NAME( x ) (FT_String*)psnames->macintosh_name( (FT_UInt)(x) ) |
56 | 56 |
57 | 57 |
58 #else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ | 58 #else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ |
59 | 59 |
60 | 60 |
61 /* Otherwise, we ignore the `PSNames' module, and provide our own */ | 61 /* Otherwise, we ignore the `PSNames' module, and provide our own */ |
62 /* table of Mac names. Thus, it is possible to build a version of */ | 62 /* table of Mac names. Thus, it is possible to build a version of */ |
63 /* FreeType without the Type 1 driver & PSNames module. */ | 63 /* FreeType without the Type 1 driver & PSNames module. */ |
64 | 64 |
65 #define MAC_NAME( x ) ( (FT_String*)tt_post_default_names[x] ) | 65 #define MAC_NAME( x ) (FT_String*)tt_post_default_names[x] |
66 | 66 |
67 /* the 258 default Mac PS glyph names; see file `tools/glnames.py' */ | 67 /* the 258 default Mac PS glyph names; see file `tools/glnames.py' */ |
68 | 68 |
69 static const FT_String* const tt_post_default_names[258] = | 69 static const FT_String* const tt_post_default_names[258] = |
70 { | 70 { |
71 /* 0 */ | 71 /* 0 */ |
72 ".notdef", ".null", "nonmarkingreturn", "space", "exclam", | 72 ".notdef", ".null", "nonmarkingreturn", "space", "exclam", |
73 "quotedbl", "numbersign", "dollar", "percent", "ampersand", | 73 "quotedbl", "numbersign", "dollar", "percent", "ampersand", |
74 /* 10 */ | 74 /* 10 */ |
75 "quotesingle", "parenleft", "parenright", "asterisk", "plus", | 75 "quotesingle", "parenleft", "parenright", "asterisk", "plus", |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 "Ccaron", "ccaron", "dcroat", | 148 "Ccaron", "ccaron", "dcroat", |
149 }; | 149 }; |
150 | 150 |
151 | 151 |
152 #endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ | 152 #endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ |
153 | 153 |
154 | 154 |
155 static FT_Error | 155 static FT_Error |
156 load_format_20( TT_Face face, | 156 load_format_20( TT_Face face, |
157 FT_Stream stream, | 157 FT_Stream stream, |
158 FT_Long post_limit ) | 158 FT_ULong post_limit ) |
159 { | 159 { |
160 FT_Memory memory = stream->memory; | 160 FT_Memory memory = stream->memory; |
161 FT_Error error; | 161 FT_Error error; |
162 | 162 |
163 FT_Int num_glyphs; | 163 FT_Int num_glyphs; |
164 FT_UShort num_names; | 164 FT_UShort num_names; |
165 | 165 |
166 FT_UShort* glyph_indices = 0; | 166 FT_UShort* glyph_indices = NULL; |
167 FT_Char** name_strings = 0; | 167 FT_Char** name_strings = NULL; |
168 | 168 |
169 | 169 |
170 if ( FT_READ_USHORT( num_glyphs ) ) | 170 if ( FT_READ_USHORT( num_glyphs ) ) |
171 goto Exit; | 171 goto Exit; |
172 | 172 |
173 /* UNDOCUMENTED! The number of glyphs in this table can be smaller */ | 173 /* UNDOCUMENTED! The number of glyphs in this table can be smaller */ |
174 /* than the value in the maxp table (cf. cyberbit.ttf). */ | 174 /* than the value in the maxp table (cf. cyberbit.ttf). */ |
175 | 175 |
176 /* There already exist fonts which have more than 32768 glyph names */ | 176 /* There already exist fonts which have more than 32768 glyph names */ |
177 /* in this table, so the test for this threshold has been dropped. */ | 177 /* in this table, so the test for this threshold has been dropped. */ |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 break; | 236 break; |
237 else | 237 else |
238 { | 238 { |
239 FT_TRACE6(( "load_format_20: %d byte left in post table\n", | 239 FT_TRACE6(( "load_format_20: %d byte left in post table\n", |
240 post_limit - FT_STREAM_POS() )); | 240 post_limit - FT_STREAM_POS() )); |
241 | 241 |
242 if ( FT_READ_BYTE( len ) ) | 242 if ( FT_READ_BYTE( len ) ) |
243 goto Fail1; | 243 goto Fail1; |
244 } | 244 } |
245 | 245 |
246 if ( (FT_Int)len > post_limit || | 246 if ( len > post_limit || |
247 FT_STREAM_POS() > post_limit - (FT_Int)len ) | 247 FT_STREAM_POS() > post_limit - len ) |
248 { | 248 { |
| 249 FT_Int d = (FT_Int)post_limit - (FT_Int)FT_STREAM_POS(); |
| 250 |
| 251 |
249 FT_ERROR(( "load_format_20:" | 252 FT_ERROR(( "load_format_20:" |
250 " exceeding string length (%d)," | 253 " exceeding string length (%d)," |
251 " truncating at end of post table (%d byte left)\n", | 254 " truncating at end of post table (%d byte left)\n", |
252 len, post_limit - FT_STREAM_POS() )); | 255 len, d )); |
253 len = FT_MAX( 0, post_limit - FT_STREAM_POS() ); | 256 len = (FT_UInt)FT_MAX( 0, d ); |
254 } | 257 } |
255 | 258 |
256 if ( FT_NEW_ARRAY( name_strings[n], len + 1 ) || | 259 if ( FT_NEW_ARRAY( name_strings[n], len + 1 ) || |
257 FT_STREAM_READ( name_strings[n], len ) ) | 260 FT_STREAM_READ( name_strings[n], len ) ) |
258 goto Fail1; | 261 goto Fail1; |
259 | 262 |
260 name_strings[n][len] = '\0'; | 263 name_strings[n][len] = '\0'; |
261 } | 264 } |
262 | 265 |
263 if ( n < num_names ) | 266 if ( n < num_names ) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 FT_FREE( glyph_indices ); | 303 FT_FREE( glyph_indices ); |
301 | 304 |
302 Exit: | 305 Exit: |
303 return error; | 306 return error; |
304 } | 307 } |
305 | 308 |
306 | 309 |
307 static FT_Error | 310 static FT_Error |
308 load_format_25( TT_Face face, | 311 load_format_25( TT_Face face, |
309 FT_Stream stream, | 312 FT_Stream stream, |
310 FT_Long post_limit ) | 313 FT_ULong post_limit ) |
311 { | 314 { |
312 FT_Memory memory = stream->memory; | 315 FT_Memory memory = stream->memory; |
313 FT_Error error; | 316 FT_Error error; |
314 | 317 |
315 FT_Int num_glyphs; | 318 FT_Int num_glyphs; |
316 FT_Char* offset_table = 0; | 319 FT_Char* offset_table = NULL; |
317 | 320 |
318 FT_UNUSED( post_limit ); | 321 FT_UNUSED( post_limit ); |
319 | 322 |
320 | 323 |
321 /* UNDOCUMENTED! This value appears only in the Apple TT specs. */ | 324 /* UNDOCUMENTED! This value appears only in the Apple TT specs. */ |
322 if ( FT_READ_USHORT( num_glyphs ) ) | 325 if ( FT_READ_USHORT( num_glyphs ) ) |
323 goto Exit; | 326 goto Exit; |
324 | 327 |
325 /* check the number of glyphs */ | 328 /* check the number of glyphs */ |
326 if ( num_glyphs > face->max_profile.numGlyphs || num_glyphs > 258 ) | 329 if ( num_glyphs > face->max_profile.numGlyphs || num_glyphs > 258 ) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } | 373 } |
371 | 374 |
372 | 375 |
373 static FT_Error | 376 static FT_Error |
374 load_post_names( TT_Face face ) | 377 load_post_names( TT_Face face ) |
375 { | 378 { |
376 FT_Stream stream; | 379 FT_Stream stream; |
377 FT_Error error; | 380 FT_Error error; |
378 FT_Fixed format; | 381 FT_Fixed format; |
379 FT_ULong post_len; | 382 FT_ULong post_len; |
380 FT_Long post_limit; | 383 FT_ULong post_limit; |
381 | 384 |
382 | 385 |
383 /* get a stream for the face's resource */ | 386 /* get a stream for the face's resource */ |
384 stream = face->root.stream; | 387 stream = face->root.stream; |
385 | 388 |
386 /* seek to the beginning of the PS names table */ | 389 /* seek to the beginning of the PS names table */ |
387 error = face->goto_table( face, TTAG_post, stream, &post_len ); | 390 error = face->goto_table( face, TTAG_post, stream, &post_len ); |
388 if ( error ) | 391 if ( error ) |
389 goto Exit; | 392 goto Exit; |
390 | 393 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 543 |
541 | 544 |
542 if ( !names->loaded ) | 545 if ( !names->loaded ) |
543 { | 546 { |
544 error = load_post_names( face ); | 547 error = load_post_names( face ); |
545 if ( error ) | 548 if ( error ) |
546 goto End; | 549 goto End; |
547 } | 550 } |
548 | 551 |
549 if ( idx < (FT_UInt)table->num_glyphs ) /* paranoid checking */ | 552 if ( idx < (FT_UInt)table->num_glyphs ) /* paranoid checking */ |
550 { | 553 *PSname = MAC_NAME( (FT_Int)idx + table->offsets[idx] ); |
551 idx += table->offsets[idx]; | |
552 *PSname = MAC_NAME( idx ); | |
553 } | |
554 } | 554 } |
555 | 555 |
556 /* nothing to do for format == 0x00030000L */ | 556 /* nothing to do for format == 0x00030000L */ |
557 | 557 |
558 End: | 558 End: |
559 return FT_Err_Ok; | 559 return FT_Err_Ok; |
560 } | 560 } |
561 | 561 |
562 | 562 |
563 /* END */ | 563 /* END */ |
OLD | NEW |